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(); } } } }
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; } }
void ZLGtkApplicationWindow::setToolbarItemState(ZLToolbar::ItemPtr item, bool visible, bool enabled) { std::map<const ZLToolbar::Item*,GtkToolItem*>::const_iterator it = myAbstractToGtk.find(&*item); if (it == myAbstractToGtk.end()) { return; } GtkToolItem *toolItem = it->second; gtk_tool_item_set_visible_horizontal(toolItem, visible); /* * Not sure, but looks like gtk_widget_set_sensitive(WIDGET, false) * does something strange if WIDGET is already insensitive. */ bool alreadyEnabled = (GTK_WIDGET_STATE(toolItem) & GTK_STATE_INSENSITIVE) == 0; if (enabled != alreadyEnabled) { gtk_widget_set_sensitive(GTK_WIDGET(toolItem), enabled); } if (item->type() == ZLToolbar::Item::MENU_BUTTON) { updatePopupData( GTK_MENU_TOOL_BUTTON(toolItem), ((ZLToolbar::MenuButtonItem&)*item).popupData() ); } }
void ZLGtkApplicationWindow::addToolbarItem(ZLToolbar::ItemPtr item) { GtkToolItem *gtkItem = 0; switch (item->type()) { case ZLToolbar::Item::TEXT_FIELD: case ZLToolbar::Item::COMBO_BOX: { const ZLToolbar::ParameterItem ¶meterItem = (const ZLToolbar::ParameterItem&)*item; GtkEntryParameter *parameter = new GtkEntryParameter(*this, parameterItem); addVisualParameter(parameterItem.parameterId(), parameter); gtkItem = parameter->createToolItem(); gtk_tool_item_set_tooltip(gtkItem, myToolbar->tooltips, parameterItem.tooltip().c_str(), 0); } break; case ZLToolbar::Item::PLAIN_BUTTON: case ZLToolbar::Item::TOGGLE_BUTTON: case ZLToolbar::Item::MENU_BUTTON: gtkItem = createGtkToolButton((ZLToolbar::AbstractButtonItem&)*item); break; case ZLToolbar::Item::SEPARATOR: gtkItem = gtk_separator_tool_item_new(); gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(gtkItem), false); break; } if (gtkItem != 0) { gtk_toolbar_insert(myToolbar, gtkItem, -1); myAbstractToGtk[&*item] = gtkItem; myGtkToAbstract[gtkItem] = item; gtk_widget_show_all(GTK_WIDGET(gtkItem)); } }
void ZLbadaApplicationWindow::setToolbarItemState(ZLToolbar::ItemPtr item, bool visible, bool enabled) { // AppLog("setToolbarItemState "); /* QAction *action = myActions[&*item]; if (action != 0) { action->setEnabled(enabled); action->setVisible(visible); }*/ switch (item->type()) { default: break; case ZLToolbar::Item::MENU_BUTTON: //AppLog("MENU_BUTTON "); /*{ ZLToolbar::MenuButtonItem &buttonItem = (ZLToolbar::MenuButtonItem&)*item; shared_ptr<ZLPopupData> data = buttonItem.popupData(); if (!data.isNull() && (data->id() != myPopupIdMap[&buttonItem])) { myPopupIdMap[&buttonItem] = data->id(); QToolButton *button = myMenuButtons[&buttonItem]; QMenu *menu = button->menu(); menu->clear(); const size_t count = data->count(); for (size_t i = 0; i < count; ++i) { menu->addAction(new ZLQtRunPopupAction(menu, data, i)); } }*/ break; } }
void ZLQtApplicationWindow::addToolbarItem(ZLToolbar::ItemPtr item) { if (item->isSeparator()) { myToolbarActions[item] = myToolbar->addSeparator(); } else { ZLToolbar::ButtonItem& buttonItem = (ZLToolbar::ButtonItem&)*item; QAction *action = getAction(buttonItem.actionId()); ZLQtToolbarButton *button = new ZLQtToolbarButton(buttonItem.iconName(), myToolbar); button->setToolTip(::qtString(buttonItem.tooltip())); connect(button, SIGNAL(clicked()), action, SLOT(onActivated())); myToolbarActions[item] = myToolbar->addWidget(button); } }
void ZLbadaApplicationWindow::addToolbarItem(ZLToolbar::ItemPtr item) { //QToolBar *tb = toolbar(type(*item)); //QAction *action = 0; AppLog("addToolbarItem "); switch (item->type()) { case ZLToolbar::Item::PLAIN_BUTTON: case ZLToolbar::Item::TOGGLE_BUTTON: // AppLog("TOGGLE_BUTTON ");//,(ZLToolbar::AbstractButtonItem&)*item.tooltip().c_str()); //action = new ZLQtToolBarAction(this, (ZLToolbar::AbstractButtonItem&)*item); //tb->addAction(action); break; case ZLToolbar::Item::MENU_BUTTON: { // AppLog("MENU_BUTTON "); /*ZLToolbar::MenuButtonItem &buttonItem = (ZLToolbar::MenuButtonItem&)*item; QToolButton *button = new QToolButton(tb); button->setFocusPolicy(Qt::NoFocus); button->setDefaultAction(new ZLQtToolBarAction(this, buttonItem)); button->setMenu(new QMenu(button)); button->setPopupMode(QToolButton::MenuButtonPopup); action = tb->addWidget(button); myMenuButtons[&buttonItem] = button; shared_ptr<ZLPopupData> popupData = buttonItem.popupData(); myPopupIdMap[&buttonItem] = popupData.isNull() ? (size_t)-1 : (popupData->id() - 1);*/ break; } case ZLToolbar::Item::TEXT_FIELD: case ZLToolbar::Item::SEARCH_FIELD: { // AppLog("SEARCH_FIELD "); /* ZLToolbar::ParameterItem &textFieldItem = (ZLToolbar::ParameterItem&)*item; LineEditParameter *para = new LineEditParameter(tb, *this, textFieldItem); addVisualParameter(textFieldItem.parameterId(), para); action = para->action();*/ break; } case ZLToolbar::Item::SEPARATOR: // AppLog("SEPARATOR "); //action = tb->addSeparator(); break; } //if (action != 0) { // myActions[&*item] = action; //} }
void MyMenuBar::setItemState(ZLToolbar::ItemPtr item, bool visible, bool enabled) { switch (item->type()) { case ZLToolbar::Item::PLAIN_BUTTON: case ZLToolbar::Item::TOGGLE_BUTTON: case ZLToolbar::Item::MENU_BUTTON: { ZLToolbar::AbstractButtonItem &button = (ZLToolbar::AbstractButtonItem&)*item; const std::string &id = button.actionId(); std::map<std::string,int> ::const_iterator iter = myActionIndices.find(id); int actionIndex = (iter != myActionIndices.end()) ? iter->second : 0; if (visible) { if ((actionIndex == 0) || (idAt(myIndex) != actionIndex)) { ToolBarButton *tbButton = myButtons[id]; if (actionIndex == 0) { tbButton = new ToolBarButton(myWindow, button); myButtons[id] = tbButton; actionIndex = myActionIndices.size() + 1; myActionIndices[id] = actionIndex; } insertItem(tbButton->pixmap(), tbButton, SLOT(doActionSlot()), 0, actionIndex, myIndex); } setItemEnabled(actionIndex, enabled); ++myIndex; } else { if ((actionIndex != 0) && (idAt(myIndex) == actionIndex)) { removeItem(actionIndex); } } break; } /* case ZLToolbar::Item::OPTION_ENTRY: if (idAt(myIndex) < 10001) { shared_ptr<ZLOptionEntry> entry = ((ZLToolbar::OptionEntryItem&)*item).entry(); if (entry->isVisible()) { ZLOptionView *view = createViewByEntry("", "", entry); view->setVisible(true); } } else { ++myIndex; } break; */ case ZLToolbar::Item::SEPARATOR: break; } }
void ZLQtApplicationWindow::addToolbarItem(ZLToolbar::ItemPtr item) { switch (item->type()) { case ZLToolbar::Item::TEXT_FIELD: myItemToWidgetMap[&*item] = new LineEditParameter(myToolBar, *this, (ZLToolbar::TextFieldItem&)*item); break; case ZLToolbar::Item::PLAIN_BUTTON: case ZLToolbar::Item::MENU_BUTTON: case ZLToolbar::Item::TOGGLE_BUTTON: myItemToWidgetMap[&*item] = new ZLQtToolButton(*this, (ZLToolbar::AbstractButtonItem&)*item); break; case ZLToolbar::Item::SEPARATOR: myToolBar->addSeparator(); myItemToWidgetMap[&*item] = (QWidget*)myToolBar->children()->getLast(); break; } }
void ZLQtApplicationWindow::setToolbarItemState(ZLToolbar::ItemPtr item, bool visible, bool enabled) { QWidget *widget = myItemToWidgetMap[&*item]; if (widget == 0) { return; } widget->setEnabled(enabled); widget->setShown(visible); switch (item->type()) { default: break; case ZLToolbar::Item::MENU_BUTTON: { ZLToolbar::MenuButtonItem &menuButtonItem = (ZLToolbar::MenuButtonItem&)*item; shared_ptr<ZLPopupData> data = menuButtonItem.popupData(); if (data && (data->id() != myPopupIdMap[&menuButtonItem])) { myPopupIdMap[&menuButtonItem] = data->id(); ((ZLQtPopupMenu*)((QToolButton*)widget)->popup())->reset(data); } break; } } }
void ZLWin32ApplicationWindow::setToolbarItemState(ZLToolbar::ItemPtr item, bool visible, bool enabled) { Toolbar &tb = toolbar(type(*item)); if (tb.hwnd == 0) { return; } const ZLToolbar::Item::Type type = item->type(); switch (type) { case ZLToolbar::Item::TEXT_FIELD: case ZLToolbar::Item::COMBO_BOX: { const ZLToolbar::ParameterItem &textFieldItem = (const ZLToolbar::ParameterItem&)*item; HWND handle = myParameters[tb.ParameterCodeById[textFieldItem.actionId()]]; if (handle != 0) { const int idCommand = tb.ParameterCodeById[textFieldItem.actionId()]; PostMessage(tb.hwnd, TB_SETSTATE, idCommand, visible ? 0 : TBSTATE_HIDDEN); ShowWindow(handle, visible ? SW_SHOW : SW_HIDE); PostMessage(handle, EM_SETREADONLY, !enabled, 0); } break; } case ZLToolbar::Item::PLAIN_BUTTON: case ZLToolbar::Item::MENU_BUTTON: case ZLToolbar::Item::TOGGLE_BUTTON: { ZLToolbar::AbstractButtonItem &buttonItem = (ZLToolbar::AbstractButtonItem&)*item; LPARAM state = (visible ? 0 : TBSTATE_HIDDEN) | (enabled ? TBSTATE_ENABLED : 0); const int idCommand = tb.ActionCodeById[buttonItem.actionId()]; PostMessage(tb.hwnd, TB_SETSTATE, (WPARAM)idCommand, state); break; } case ZLToolbar::Item::SEPARATOR: PostMessage(tb.hwnd, TB_SETSTATE, tb.SeparatorNumbers[item], visible ? 0 : TBSTATE_HIDDEN); break; } }
void ZLWin32ApplicationWindow::addToolbarItem(ZLToolbar::ItemPtr item) { if (myRebar == 0) { createWindowToolbar(); } Toolbar &tb = toolbar(type(*item)); if (tb.hwnd == 0) { myFloatingToolbarItems.push_back(item); return; } TBBUTTON button; button.fsState = TBSTATE_ENABLED; const ZLToolbar::Item::Type type = item->type(); switch (type) { case ZLToolbar::Item::TEXT_FIELD: case ZLToolbar::Item::COMBO_BOX: { const ZLToolbar::ParameterItem &textFieldItem = (ZLToolbar::ParameterItem&)*item; button.idCommand = -200 + tb.ParameterCodeById.size(); tb.ParameterCodeById[textFieldItem.actionId()] = button.idCommand; button.iBitmap = I_IMAGENONE; button.fsStyle = TBSTYLE_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT; button.fsState = 0; tb.TBItemByActionCode[button.idCommand] = item; break; } case ZLToolbar::Item::PLAIN_BUTTON: case ZLToolbar::Item::MENU_BUTTON: case ZLToolbar::Item::TOGGLE_BUTTON: { const ZLToolbar::AbstractButtonItem &buttonItem = (const ZLToolbar::AbstractButtonItem&)*item; std::string imageFileName = ZLibrary::ApplicationImageDirectory() + ZLibrary::FileNameDelimiter + buttonItem.iconName() + ".ico"; ZLFile file(imageFileName); ZLUnicodeUtil::Ucs2String wPath; HICON bitmap = (HICON)LoadImageW(0, ::wchar(::createNTWCHARString(wPath, file.path())), IMAGE_ICON, IconSize, IconSize, LR_LOADFROMFILE); ImageList_AddIcon((HIMAGELIST)SendMessage(tb.hwnd, TB_GETIMAGELIST, 0, 0), bitmap); button.iBitmap = tb.ActionCodeById.size(); button.fsStyle = TBSTYLE_BUTTON; if (type == ZLToolbar::Item::MENU_BUTTON) { button.fsStyle |= TBSTYLE_DROPDOWN; } else if (type == ZLToolbar::Item::TOGGLE_BUTTON) { button.fsStyle |= TBSTYLE_CHECK; } const int actionCode = tb.ActionCodeById.size() + 1; tb.ActionCodeById[buttonItem.actionId()] = actionCode; button.idCommand = actionCode; tb.TBItemByActionCode[button.idCommand] = item; button.dwData = 0; button.iString = 0; break; } case ZLToolbar::Item::SEPARATOR: { button.idCommand = -100 - tb.SeparatorNumbers.size(); tb.SeparatorNumbers[item] = button.idCommand; button.iBitmap = 6; button.fsStyle = TBSTYLE_SEP; break; } } SendMessage(tb.hwnd, TB_ADDBUTTONS, 1, (LPARAM)&button); switch (type) { default: break; case ZLToolbar::Item::TEXT_FIELD: case ZLToolbar::Item::COMBO_BOX: { const ZLToolbar::ParameterItem &textFieldItem = (ZLToolbar::ParameterItem&)*item; TBBUTTONINFO buttonInfo; buttonInfo.cbSize = sizeof(TBBUTTONINFO); buttonInfo.dwMask = TBIF_SIZE; buttonInfo.cx = 10 + 8 * textFieldItem.maxWidth(); if (type == ZLToolbar::Item::COMBO_BOX) { buttonInfo.cx += 15; } SendMessage(tb.hwnd, TB_SETBUTTONINFO, button.idCommand, (LPARAM)&buttonInfo); TextEditParameter *parameter = new TextEditParameter(application(), myMainWindow, tb.hwnd, button.idCommand, textFieldItem); addVisualParameter(textFieldItem.parameterId(), parameter); myParameters[button.idCommand] = parameter->handle(); break; } } }
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); } }