Example #1
0
//This is used to make the toolbar reflect the current state of
//the document (enable, disable, set font values etc
bool EV_BeOSToolbar::refreshToolbar(AV_View * pView, AV_ChangeMask mask) {
	const EV_Toolbar_ActionSet * pToolbarActionSet;
	pToolbarActionSet = m_pBeOSApp->getToolbarActionSet();

	UT_ASSERT(pToolbarActionSet);
	int oldstate, perform_update = 0;
	
	UT_uint32 nrLabelItemsInLayout = m_pToolbarLayout->getLayoutItemCount();
	
	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);

		AV_ChangeMask maskOfInterest = pAction->getChangeMaskOfInterest();
		
		if ((maskOfInterest & mask) == 0)   //If this item doesn't care about
			continue;						// changes of this type, skip it...

		switch (pLayoutItem->getToolbarLayoutFlags()) {
		case EV_TLF_Normal: {
				const char * szState = 0;
				EV_Toolbar_ItemState tis = pAction->getToolbarItemState(pView,&szState);

				switch (pAction->getItemType())	
				{
				case EV_TBIT_ColorFore:
				case EV_TBIT_ColorBack:
				case EV_TBIT_PushButton: 
				{
					bool bGrayed = EV_TIS_ShouldBeGray(tis);

//					UT_DEBUGMSG(("refreshToolbar: PushButton [%s] is %s\n", 
//						m_pToolbarLabelSet->getLabel(id)->getToolbarLabel(), 
//						((bGrayed) ? "disabled" : "enabled"))); 
					tb_item_t * item = m_pTBView->FindItemByID(id);
					if (item) {
						oldstate = item->state;
						item->state = (bGrayed) ? 0 : ENABLED_MASK;
						perform_update |= (oldstate == item->state) ? 0 : 1; 
						if(perform_update) {
							m_pTBView->LockLooper();
							m_pTBView->Invalidate(item->rect);
							m_pTBView->UnlockLooper();
						}
					}
				}
				break;
			
				case EV_TBIT_GroupButton:
//					DPRINTF(printf("Ref Group->Toggle Button \n"));
				case EV_TBIT_ToggleButton: 
				{
					bool bGrayed = EV_TIS_ShouldBeGray(tis);
					bool bToggled = EV_TIS_ShouldBeToggled(tis);

											
//					UT_DEBUGMSG(("refreshToolbar: ToggleBut [%s] is %s and %s\n", 
//						m_pToolbarLabelSet->getLabel(id)->getToolbarLabel(), 
//						((bGrayed) ? "disabled" : "enabled"), 
//						((bToggled) ? "pressed" : "not pressed")));

					tb_item_t * item = m_pTBView->FindItemByID(id);
					if (item) {
						oldstate = item->state;
						item->state = ((bGrayed) ? 0 : ENABLED_MASK) |
						              ((bToggled) ? PRESSED_MASK : 0);
						perform_update |= (oldstate == item->state) ? 0 : 1; 
						if(perform_update)
	        			{
							m_pTBView->LockLooper();
							m_pTBView->Invalidate(item->rect);
							m_pTBView->UnlockLooper();
						}	
																															                                    
					}				
				}
				break;

				case EV_TBIT_ComboBox: {
//					bool bGrayed = EV_TIS_ShouldBeGray(tis);
					bool bString = EV_TIS_ShouldUseString(tis);
						
//					UT_DEBUGMSG(("refreshToolbar: ComboBox [%s] is %s \n", 
//					 	m_pToolbarLabelSet->getLabel(id)->getToolbarLabel(),  
//						((bString) ? szState : "no state")));

					tb_item_t * item = m_pTBView->FindItemByID(id);
					if (item && bString) {
						BPopUpMenu *popup;
						UT_ASSERT(item->menu);
						popup = (BPopUpMenu*)item->menu->Menu();
						UT_ASSERT(popup);
						BMenuItem *mnuitem = popup->FindItem(szState);
						if (mnuitem) 
						{
//							printf("Can't find menu item %s \n", szState);
//							if (!(mnuitem = popup->FindItem("Dutch801 Rm BT")))
//								break;
							//Send a message to fix that
							/*
							char *buffer = "Dutch801 Rm BT";
							toolbarEvent(id, 
								(UT_UCSChar *)buffer, strlen(buffer));
							*/
							mnuitem->SetMarked(true);							
						}
					}			

				}
				break;

				case EV_TBIT_EditText:
				case EV_TBIT_DropDown:
				case EV_TBIT_StaticLabel:
				case EV_TBIT_Spacer:
					DPRINTF(printf("refreshToolbar: Update Text, DropDown, Label, Spacer \n"));
					break;
				case EV_TBIT_BOGUS:
				default:
					//KNORR!!
					//UT_ASSERT(0);
					break;
				}
			}
			break;
			
		case EV_TLF_Spacer:
			break;
			
		default:
			//KNORR!!
			//UT_ASSERT(0);
			break;
		}
	}

#if 1
//TF I can't remember why I put this in, but it doesn't 
//seem to be needed now and is contributing in a big way
//to the slowdown of the drag updates.

//TF Note ... without this we don't get updated properly
//when a button state changes.  Instead put in hooks
//that only update us as required.
#endif
	return true;
}