Esempio n. 1
0
bool EV_QtToolbar::synthesize(void)
{
	// create a Qt toolbar from the info provided.
	const EV_Toolbar_ActionSet * pToolbarActionSet = m_pQtApp->getToolbarActionSet();
	UT_ASSERT(pToolbarActionSet);

	XAP_Toolbar_ControlFactory * pFactory = m_pQtApp->getControlFactory();
	UT_ASSERT(pFactory);

	UT_uint32 nrLabelItemsInLayout = m_pToolbarLayout->getLayoutItemCount();
	UT_ASSERT(nrLabelItemsInLayout > 0);

	m_wToolbar = new QToolBar();
	UT_ASSERT(m_wToolbar);

	Qt::ToolButtonStyle style = getStyle();
	m_wToolbar->setToolButtonStyle(style);

	for (UT_uint32 k=0; (k < nrLabelItemsInLayout); k++)
	{
		EV_Toolbar_LayoutItem * pLayoutItem = m_pToolbarLayout->getLayoutItem(k);
		UT_continue_if_fail(pLayoutItem);

		XAP_Toolbar_Id id = pLayoutItem->getToolbarId();
		EV_Toolbar_Action * pAction = pToolbarActionSet->getAction(id);
		UT_ASSERT(pAction);
		EV_Toolbar_Label * pLabel = m_pToolbarLabelSet->getLabel(id);
		UT_ASSERT(pLabel);

		const char * szToolTip = pLabel->getToolTip();
		if (!szToolTip || !*szToolTip)
			szToolTip = pLabel->getStatusMsg();		

		switch (pLayoutItem->getToolbarLayoutFlags())
		{
			case EV_TLF_Normal:
			{
				switch (pAction->getItemType())
				{
					case EV_TBIT_PushButton:
					{
						UT_ASSERT(g_ascii_strcasecmp(pLabel->getIconName(),"NoIcon")!=0);
						if(pAction->getToolbarId() != AP_TOOLBAR_ID_INSERT_TABLE)
						{
							const char *icon_name = pLabel->getIconName();
							QPixmap		pixmap;
							pixmap = abi_pixmap_from_toolbar_id (icon_name);
							if(!pixmap.isNull())
							{
								QIcon icon(pixmap);
								QString str = "";
								QPushButton *item = new QPushButton(icon, str);
								m_wToolbar->addWidget(item);
							}
						}
						else
						{
							const char *icon_name = pLabel->getIconName();
							QPixmap		pixmap;
							pixmap = abi_pixmap_from_toolbar_id (icon_name);
							if(!pixmap.isNull())
							{
								QIcon icon(pixmap);
								QString str = "";
								QPushButton *item = new QPushButton(icon, str);
								m_wToolbar->addWidget(item);
							}
						}

						break;
					}
					case EV_TBIT_ToggleButton:
					case EV_TBIT_GroupButton:
					{
						UT_ASSERT(g_ascii_strcasecmp(pLabel->getIconName(),"NoIcon")!=0);
						const char *icon_name = pLabel->getIconName();
						QPixmap		pixmap;
						pixmap = abi_pixmap_from_toolbar_id (icon_name);
						if(!pixmap.isNull())
						{
							QIcon icon(pixmap);					
							QString str = "";
							QPushButton *item = new QPushButton(icon, str);
							item->setCheckable(true);
							m_wToolbar->addWidget(item);
						}
						break;
					}
					case EV_TBIT_EditText:
					{
						break;
					}
					case EV_TBIT_DropDown:
					{
						break;
					}
					case EV_TBIT_ComboBox:
					{
						EV_Toolbar_Control * pControl = pFactory->getControl(this, id);
						UT_ASSERT(pControl);

						QComboBox *combo;
						bool isFontCombo = false;
						if(id == AP_TOOLBAR_ID_FMT_SIZE) 
						{
							combo = new QComboBox();
						}
						else if(id == AP_TOOLBAR_ID_FMT_FONT)
						{
							isFontCombo = true;
							combo = new QFontComboBox();
							QString str = "AbiFontCombo";
							combo->setAccessibleName(str); 
						}
						else if(id == AP_TOOLBAR_ID_ZOOM) 
						{
							combo = new QComboBox();
							QString str = "AbiZoomCombo";
							combo->setAccessibleName(str); 
						}
						else if(id == AP_TOOLBAR_ID_FMT_STYLE) 
						{
							combo = new QComboBox();
							QString str = "AbiStyleCombo";
							combo->setAccessibleName(str); 
						}
						else
						{
							UT_ASSERT(0);
						}

						// populate it
						if (pControl) 
						{
							pControl->populate();
							const UT_GenericVector<const char*> * v = pControl->getContents();
							UT_ASSERT(v);
							gint items = v->getItemCount();	
							if (isFontCombo) 
							{
								for (gint m=0; m < items; m++) 
								{
									QString str = v->getNthItem(m);
									combo->addItem(str);
								}	
							}
							else
							{
								for (gint m=0; m < items; m++) 
								{
									const char * sz = v->getNthItem(m);
									std::string sLoc;
									if (id == AP_TOOLBAR_ID_FMT_STYLE)
									{
										pt_PieceTable::s_getLocalisedStyleName(sz, sLoc);
										sz = sLoc.c_str();
									}
									QString str = sz;
									combo->addItem(str);
								}	
							}
						}

						m_wToolbar->addWidget(combo);

						// for now, we never repopulate, so can just toss it
						DELETEP(pControl);
						break;
					}
					case EV_TBIT_ColorFore:
					case EV_TBIT_ColorBack:
					{

						UT_ASSERT (g_ascii_strcasecmp(pLabel->getIconName(),"NoIcon") != 0);
						QComboBox *combo;

						if (pAction->getItemType() == EV_TBIT_ColorFore) 
						{
							// TODO Some icon implementation
							const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
							std::string sClear;
							pSS->getValueUTF8(XAP_STRING_ID_TB_ClearForeground,sClear);	
							combo = new QComboBox();
							QString str = sClear.c_str();		
							combo->setAccessibleName(str); 				
						}
						else
						{
							// TODO Some icon implementation
							const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
							std::string sClear;
							pSS->getValueUTF8(XAP_STRING_ID_TB_ClearForeground,sClear);	
							combo = new QComboBox();
							QString str = sClear.c_str();		
							combo->setAccessibleName(str); 								
						}
						m_wToolbar->addWidget(combo);
						break;
					}
					case EV_TBIT_StaticLabel:
					{
						// TODO do these...
						break;
					}
					case EV_TBIT_Spacer:
					{
						break;
					}
#ifdef ENABLE_MENUBUTTON
					case EV_TBIT_MenuButton:
					{
						break;
					}
#endif
					case EV_TBIT_BOGUS:
					default:
					{
						break;
					}
				}
				break;
			}
			case EV_TLF_Spacer:
			{
				m_wToolbar->addSeparator();
				break;
			}
			default:
			{
				UT_ASSERT(0);
			}
		}
	}

	QMainWindow * wTopLevel = static_cast<XAP_QtFrameImpl *>(m_pFrame->getFrameImpl())->getTopLevel();
	wTopLevel->addToolBar(m_wToolbar);
	wTopLevel->show();
	return true;
}
Esempio n. 2
0
// This is used to do the initial toolbar creation
bool EV_BeOSToolbar::synthesize(void) 
{
	//Add the toolbar(s) beneath the menus ...
	be_Window 	*pBWin = NULL;

	if (!m_pBeOSFrame) 
		return false;
	
	pBWin = (be_Window *)m_pBeOSFrame->getTopLevelWindow();
	UT_ASSERT(pBWin);
	
	ToolbarView *tb = new ToolbarView(this, "Toolbar", 
		 			  B_WILL_DRAW | B_FRAME_EVENTS); 
	tb->SetExplicitMaxSize(BSize(B_SIZE_UNSET, 32));
	m_pTBView = tb;
	pBWin->AddChild(tb);
	
	// create a toolbar from the info provided.
	const EV_Toolbar_ActionSet * pToolbarActionSet = m_pBeOSApp->getToolbarActionSet();
	UT_ASSERT(pToolbarActionSet);

	XAP_Toolbar_ControlFactory * pFactory = m_pBeOSApp->getControlFactory();
	UT_ASSERT(pFactory);
	
	UT_uint32 nrLabelItemsInLayout = m_pToolbarLayout->getLayoutItemCount();
	UT_ASSERT(nrLabelItemsInLayout > 0);

	// Allow the user to control if we show text or icons or both ...
#if 0
	const XML_Char * szValue = NULL;
	m_pBeOSApp->getPrefsValue(XAP_PREF_KEY_ToolbarAppearance,&szValue);
	UT_ASSERT((szValue) && (*szValue));

	GtkToolbarStyle style = GTK_TOOLBAR_ICONS;
	if (UT_XML_stricmp(szValue,"icon")==0)
		style = GTK_TOOLBAR_ICONS;
	else if (UT_XML_stricmp(szValue,"text")==0)
		style = GTK_TOOLBAR_TEXT;
	else if (UT_XML_stricmp(szValue,"both")==0)
		style = GTK_TOOLBAR_BOTH;         
#endif

	for (UT_uint32 k=0; (k < nrLabelItemsInLayout); k++)
	{
		EV_Toolbar_LayoutItem * pLayoutItem = m_pToolbarLayout->getLayoutItem(k);
		UT_ASSERT(pLayoutItem);

		XAP_Toolbar_Id id = pLayoutItem->getToolbarId();
		EV_Toolbar_Action * pAction = pToolbarActionSet->getAction(id);
		UT_ASSERT(pAction);
		EV_Toolbar_Label * pLabel = m_pToolbarLabelSet->getLabel(id);
		UT_ASSERT(pLabel);

		switch (pLayoutItem->getToolbarLayoutFlags()) {
		case EV_TLF_Normal: {
			const char * szToolTip = pLabel->getToolTip();
			if (!szToolTip || !*szToolTip)
				szToolTip = pLabel->getStatusMsg();
				
			switch (pAction->getItemType()) {
			case EV_TBIT_ColorFore:
			case EV_TBIT_ColorBack: {
				UT_ASSERT(UT_stricmp(pLabel->getIconName(),"NoIcon")!=0);
				BBitmap * bitmap = m_pBeOSToolbarIcons->GetIconBitmap(pLabel->getIconName());
				tb->AddItem(bitmap, NULL, id, szToolTip);
			}
			break;

			case EV_TBIT_PushButton: {
				DPRINTF(printf("EVTOOLBAR: Push button \n"));
				UT_ASSERT(UT_stricmp(pLabel->getIconName(),"NoIcon")!=0);
				BBitmap * bitmap = m_pBeOSToolbarIcons->GetIconBitmap(pLabel->getIconName());
				//UT_ASSERT(bitmap);
				//Add the bitmap to the toolbar
				tb->AddItem(bitmap, NULL, id , szToolTip);
			}
			break;

			case EV_TBIT_GroupButton:
				DPRINTF(printf("EVTOOLBAR: Group Button \n"));
			case EV_TBIT_ToggleButton: {
				DPRINTF(printf("EVTOOLBAR: Toggle button \n"));
				UT_ASSERT(UT_stricmp(pLabel->getIconName(),"NoIcon")!=0);

				BBitmap * bitmap = m_pBeOSToolbarIcons->GetIconBitmap(pLabel->getIconName());
				//UT_ASSERT(bitmap);
				//Add the bitmap to the toolbar
				tb->AddItem(bitmap, NULL, id , szToolTip);
			}
			break;
			
			case EV_TBIT_ComboBox: {
				DPRINTF(printf("EVTOOLBAR: Combo Box \n"));
				EV_Toolbar_Control * pControl = pFactory->getControl(this, id);
				UT_ASSERT(pControl);
		
				//Add a combo type box ...
				BPopUpMenu *popupmenu = new BPopUpMenu(""); 
				UT_ASSERT(popupmenu);
		 	
				// populate it
				int iWidth = 100;
				if (pControl) {
					iWidth = pControl->getPixelWidth();
					pControl->populate();

					const UT_GenericVector<const char*> * v = pControl->getContents();
					UT_ASSERT(v);
					if (v) {
						UT_uint32 items = v->getItemCount();
						for (UT_uint32 m=0; m < items; m++) {
							char * sz = (char *)v->getNthItem(m);
							BMessage *togo = new BMessage('ddwn');
							togo->AddInt32("id", id);
							togo->AddInt32("item", m);  
							BMenuItem *newmenu = new BMenuItem(sz, togo);
							UT_ASSERT(newmenu);
							newmenu->SetTarget(tb);
							popupmenu->AddItem(newmenu);							
							
						}
					}
				}
				//Stick it in the menu						         
				tb->AddItem(popupmenu, iWidth, id);

			}
			break;

			case EV_TBIT_EditText:
			case EV_TBIT_DropDown:
			case EV_TBIT_StaticLabel:
			case EV_TBIT_Spacer:
				break;

					
			case EV_TBIT_BOGUS:
			default:
				UT_ASSERT(0);
				break;
			}
		}
		break;
			
		case EV_TLF_Spacer:	{
			tb->AddSeperator();
			break;
		}
		
		default:
			UT_ASSERT(0);
		}
	}
	return true;
}