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 &parameterItem = (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 ZLQtApplicationWindow::addToolbarItem(ZLToolbar::ItemPtr item) {
	QToolBar *tb = toolbar(type(*item));
	QAction *action = 0;

	switch (item->type()) {
		case ZLToolbar::Item::PLAIN_BUTTON:
		case ZLToolbar::Item::TOGGLE_BUTTON:
			action = new ZLQtToolBarAction(this, (ZLToolbar::AbstractButtonItem&)*item);
			tb->addAction(action);
			break;
		case ZLToolbar::Item::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:
		{
			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:
			action = tb->addSeparator();
			break;
	}

	if (action != 0) {
		myActions[&*item] = action;
	}
}
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;
		}
	}
}