void ZLApplicationWindow::refreshToolbar() {
	const ZLToolbar::ItemVector &items = application().toolbar().items();
	bool canAddSeparator = false;
	ZLToolbar::ItemPtr lastSeparator = 0;
	for (ZLToolbar::ItemVector::const_iterator it = items.begin(); it != items.end(); ++it) {
		if ((*it)->isSeparator()) {
			if (canAddSeparator) {
				lastSeparator = *it;
				canAddSeparator = false;
			} else {
				setToolbarItemState(*it, false, true);
			}
		} else {
			ZLToolbar::ButtonItem &button = (ZLToolbar::ButtonItem&)**it;
			const std::string &id = button.actionId();

			const bool visible = application().isActionVisible(id);
			const bool enabled = application().isActionEnabled(id);

			if (visible) {
				if (!lastSeparator.isNull()) {
					setToolbarItemState(lastSeparator, true, true);
					lastSeparator = 0;
				}
				canAddSeparator = true;
			}
			setToolbarItemState(*it, visible, enabled);
		}
	}
	if (!lastSeparator.isNull()) {
		setToolbarItemState(lastSeparator, false, true);
	}
}
void ZLWin32ApplicationWindow::runPopup(const NMTOOLBAR &nmToolbar) {
	Toolbar &tb = toolbar(isFullscreen() ? FULLSCREEN_TOOLBAR : WINDOW_TOOLBAR);
	if (tb.hwnd == 0) {
		return;
	}
	ZLToolbar::ItemPtr item = tb.TBItemByActionCode[nmToolbar.iItem];
	if (!item.isNull()) {
		const ZLToolbar::MenuButtonItem &button =
			(const ZLToolbar::MenuButtonItem&)*item;
		shared_ptr<ZLPopupData> popupData = button.popupData();
		if (!popupData.isNull()) {
			const int count = popupData->count();
			if (count != 0) {
				myPopupMenu = new ZLWin32PopupMenu(myMainWindow);
				for (int i = 0; i < count; ++i) {
					myPopupMenu->addItem(popupData->text(i), 0, true);
				}
				POINT p;
				p.x = nmToolbar.rcButton.left;
				p.y = nmToolbar.rcButton.bottom + 6;
				ClientToScreen(myMainWindow, &p);
				int code = myPopupMenu->run(p);
				if (code > 0) {
					popupData->run(code - 1);
				}
				myPopupMenu.reset();
			}
		}
	}
}
Esempio n. 3
0
void ZLWin32ApplicationWindow::processChevron(const NMREBARCHEVRON &chevron) {
	RECT toolbarRect;
	GetClientRect(myWindowToolbar.hwnd, &toolbarRect);

	HIMAGELIST imageList = (HIMAGELIST)SendMessage(myWindowToolbar.hwnd, TB_GETIMAGELIST, 0, 0);
	int imageIndex = 0;

	const int len = SendMessage(myWindowToolbar.hwnd, TB_BUTTONCOUNT, 0, 0);
	int index = 0;
	for (; index < len; ++index) {
		TBBUTTON info;
		SendMessage(myWindowToolbar.hwnd, TB_GETBUTTON, index, (LPARAM)&info);
		if ((info.fsState & TBSTATE_HIDDEN) == 0) {
			RECT rect;
			SendMessage(myWindowToolbar.hwnd, TB_GETITEMRECT, index, (LPARAM)&rect);
			if (rect.right > toolbarRect.right) {
				break;
			}
		}
		if (info.idCommand > -100) {
			++imageIndex;
		}
	}

	myPopupMenu = new ZLWin32PopupMenu(myMainWindow);
	for (; index < len; ++index) {
		TBBUTTON info;
		SendMessage(myWindowToolbar.hwnd, TB_GETBUTTON, index, (LPARAM)&info);
		if ((info.fsState & TBSTATE_HIDDEN) == 0) {
			ZLToolbar::ItemPtr item = myWindowToolbar.TBItemByActionCode[info.idCommand];
			if (!item.isNull()) {
				const ZLToolbar::AbstractButtonItem &button =
					(const ZLToolbar::AbstractButtonItem&)*item;
				myPopupMenu->addItem(
					"  " + button.tooltip(),
					ImageList_GetIcon(imageList, imageIndex, ILD_NORMAL),
					info.fsState & TBSTATE_ENABLED,
					info.idCommand
				);
			} else if (info.idCommand >= -200) /* is a separator */ {
				myPopupMenu->addSeparator();
			}
		}
		if (info.idCommand > -100) {
			++imageIndex;
		}
	}
	POINT p;
	p.x = chevron.rc.right - 2;
	p.y = chevron.rc.bottom;
	ClientToScreen(myMainWindow, &p);
	onToolbarButtonRelease(myPopupMenu->run(p, true));
	myPopupMenu.reset();
}
void ZLWin32ApplicationWindow::setTooltip(TOOLTIPTEXT &tooltip) {
	Toolbar &tb = toolbar(isFullscreen() ? FULLSCREEN_TOOLBAR : WINDOW_TOOLBAR);
	if (tb.hwnd == 0) {
		return;
	}
	ZLToolbar::ItemPtr item = tb.TBItemByActionCode[tooltip.hdr.idFrom];
	if (!item.isNull()) {
		const ZLToolbar::AbstractButtonItem &button =
			(const ZLToolbar::AbstractButtonItem&)*item;
		ZLUnicodeUtil::Ucs2String tooltipBuffer;
		::createNTWCHARString(tooltipBuffer, button.tooltip());
		size_t length = std::max(tooltipBuffer.size(), (size_t)80);
		memcpy((char*)tooltip.szText, (char*)::wchar(tooltipBuffer), 2 * length);
		tooltip.uFlags = TTF_DI_SETITEM;
	}
}
Esempio n. 5
0
void ZLApplicationWindow::refreshToolbar(ToolbarType type) {
	const ZLToolbar::ItemVector &items = application().toolbar(type).items();
	bool canAddSeparator = false;
	ZLToolbar::ItemPtr lastSeparator = 0;
	for (ZLToolbar::ItemVector::const_iterator it = items.begin(); it != items.end(); ++it) {
		switch ((*it)->type()) {
			case ZLToolbar::Item::TEXT_FIELD:
			case ZLToolbar::Item::COMBO_BOX:
			case ZLToolbar::Item::SEARCH_FIELD:
			case ZLToolbar::Item::PLAIN_BUTTON:
			case ZLToolbar::Item::MENU_BUTTON:
				{
					ZLToolbar::ActionItem &button = (ZLToolbar::ActionItem&)**it;
					const std::string &id = button.actionId();
        
					const bool visible = application().isActionVisible(id);
					const bool enabled = application().isActionEnabled(id);
        
					if (visible) {
						if (!lastSeparator.isNull()) {
							setToolbarItemState(lastSeparator, true, true);
							lastSeparator = 0;
						}
						canAddSeparator = true;
					}
					setToolbarItemState(*it, visible, enabled);
				}
				break;
			case ZLToolbar::Item::TOGGLE_BUTTON:
				{
					ZLToolbar::ToggleButtonItem &button = (ZLToolbar::ToggleButtonItem&)**it;
					const std::string &id = button.actionId();
        
					const bool visible = application().isActionVisible(id);
					const bool enabled = application().isActionEnabled(id);
        
					if (visible) {
						if (!lastSeparator.isNull()) {
							setToolbarItemState(lastSeparator, true, true);
							lastSeparator = 0;
						}
						canAddSeparator = true;
					}
					/*
					if (!enabled && button.isPressed()) {
						button.buttonGroup().press(0);
						//application().doAction(group->UnselectAllButtonsActionId);
						myToggleButtonLock = true;
						setToggleButtonState(button);
						myToggleButtonLock = false;
					}
					*/
					setToolbarItemState(*it, visible, enabled);
					setToggleButtonState(button);
				}
				break;
			case ZLToolbar::Item::SEPARATOR:
				if (canAddSeparator) {
					lastSeparator = *it;
					canAddSeparator = false;
				} else {
					setToolbarItemState(*it, false, true);
				}
				break;
			case ZLToolbar::Item::FILL_SEPARATOR:
				if (canAddSeparator) {
					lastSeparator = *it;
					canAddSeparator = false;
				} else if (lastSeparator != 0) {
					setToolbarItemState(lastSeparator, false, true);
					lastSeparator = *it;
				} else {
					setToolbarItemState(*it, false, true);
				}
				break;
		}
	}
	if (!lastSeparator.isNull()) {
		setToolbarItemState(lastSeparator, false, true);
	}
}