2 * Copyright (c) 2005 Massachusetts Institute of Technology
3 * Copyright (c) 2007 Secure Endpoints Inc.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 HWND khui_hwnd_standard_toolbar;
34 khui_ilist * ilist_toolbar;
36 void khui_init_toolbar(void) {
37 ilist_toolbar = khui_create_ilist(KHUI_TOOLBAR_IMAGE_WIDTH, KHUI_TOOLBAR_IMAGE_HEIGHT, KHUI_TOOLBAR_MAX_BTNS, 5, 0);
40 void khui_exit_toolbar(void) {
41 khui_delete_ilist(ilist_toolbar);
44 LRESULT khm_toolbar_notify(LPNMHDR notice) {
45 switch(notice->code) {
48 LPNMTBGETINFOTIP git = (LPNMTBGETINFOTIP) notice;
53 a = khui_find_action(cmd);
57 StringCchCopy(git->pszText, git->cchTextMax, a->caption);
58 } else if (a->tooltip) {
59 StringCchCopy(git->pszText, git->cchTextMax, a->tooltip);
60 } else if (a->is_caption) {
61 wchar_t buf[INFOTIPSIZE];
64 LoadString(khm_hInstance, a->is_caption,
65 buf, ARRAYLENGTH(buf));
67 StringCchCopy(git->pszText, git->cchTextMax, buf);
69 StringCchCopy(git->pszText, git->cchTextMax, L"");
72 StringCchCopy(git->pszText,
79 case TBN_HOTITEMCHANGE:
81 LPNMTBHOTITEM hi = (LPNMTBHOTITEM) notice;
83 if (hi->dwFlags & HICF_LEAVING) {
84 khm_statusbar_set_part(KHUI_SBPART_INFO, NULL, L"");
91 a = khui_find_action(cmd);
97 StringCbCopy(buf, sizeof(buf), a->tooltip);
98 else if (a->is_tooltip) {
99 LoadString(khm_hInstance, a->is_tooltip,
100 buf, ARRAYLENGTH(buf));
104 khm_statusbar_set_part(KHUI_SBPART_INFO, NULL, buf);
111 LPNMTOOLBAR nmtb = (LPNMTOOLBAR) notice;
114 GetWindowRect(khui_hwnd_standard_toolbar, &r);
115 if (nmtb->iItem == KHUI_ACTION_DESTROY_CRED) {
116 khm_menu_show_panel(KHUI_MENU_DESTROY_CRED,
117 r.left + nmtb->rcButton.left,
118 r.top + nmtb->rcButton.bottom);
119 } else if (nmtb->iItem == KHUI_ACTION_RENEW_CRED) {
120 khm_menu_show_panel(KHUI_MENU_RENEW_CRED,
121 r.left + nmtb->rcButton.left,
122 r.top + nmtb->rcButton.bottom);
124 return TBDDRET_NODEFAULT;
127 return TBDDRET_DEFAULT;
133 LPNMTBCUSTOMDRAW nmcd = (LPNMTBCUSTOMDRAW) notice;
134 if(nmcd->nmcd.dwDrawStage == CDDS_PREPAINT) {
135 return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTERASE;
136 } else if(nmcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT) {
137 return CDRF_NOTIFYPOSTPAINT;
138 } else if(nmcd->nmcd.dwDrawStage == CDDS_ITEMPOSTPAINT) {
139 /* draw the actual icon */
146 khui_find_action((int) nmcd->nmcd.dwItemSpec);
148 if(!act || !act->ib_normal)
149 return CDRF_DODEFAULT;
151 if((act->state & KHUI_ACTIONSTATE_DISABLED) &&
153 ibmp = act->ib_disabled;
154 } else if(act->ib_hot &&
155 ((nmcd->nmcd.uItemState & CDIS_HOT) ||
156 (nmcd->nmcd.uItemState & CDIS_SELECTED))){
159 ibmp = act->ib_normal;
162 iidx = khui_ilist_lookup_id(ilist_toolbar, ibmp);
164 hbmp = LoadImage(khm_hInstance,
165 MAKEINTRESOURCE(ibmp),
167 KHUI_TOOLBAR_IMAGE_WIDTH,
168 KHUI_TOOLBAR_IMAGE_HEIGHT, 0);
170 khui_ilist_add_masked_id(ilist_toolbar,
172 KHUI_TOOLBAR_BGCOLOR,
178 return CDRF_DODEFAULT;
180 CopyRect(&r, &(nmcd->nmcd.rc));
181 r.left += ((r.bottom - r.top) -
182 KHUI_TOOLBAR_IMAGE_HEIGHT) / 2;
183 r.top += ((r.bottom - r.top) -
184 KHUI_TOOLBAR_IMAGE_HEIGHT) / 2;
186 r.left += ((r.right - r.left) -
187 KHUI_TOOLBAR_IMAGE_WIDTH) / 2;
189 khui_ilist_draw(ilist_toolbar,
196 return CDRF_DODEFAULT;
204 void khui_add_action_to_toolbar(HWND tb, khui_action *a, int opt, HIMAGELIST hiList) {
205 wchar_t buf[MAX_RES_STRING] = L"";
210 ZeroMemory(&bn,sizeof(bn));
212 if(opt & KHUI_TOOLBAR_ADD_SEP) {
213 bn.fsStyle = BTNS_SEP;
226 bn.fsStyle = BTNS_BUTTON;
228 if(opt & KHUI_TOOLBAR_VARSIZE) {
229 bn.fsStyle |= BTNS_AUTOSIZE;
232 if(opt & KHUI_TOOLBAR_ADD_TEXT) {
234 if((opt & KHUI_TOOLBAR_ADD_LONGTEXT) ==
235 KHUI_TOOLBAR_ADD_LONGTEXT) {
241 LoadString(khm_hInstance,
243 buf, ARRAYLENGTH(buf));
244 buf[wcslen(buf) + 1] = L'\0';
245 idx_caption = (int) SendMessage(tb,
249 #if (_WIN32_IE >= 0x0501)
250 bn.fsStyle |= BTNS_SHOWTEXT;
252 bn.iString = idx_caption;
256 if(opt & KHUI_TOOLBAR_ADD_DROPDOWN) {
257 bn.fsStyle |= BTNS_DROPDOWN;
260 if((opt & KHUI_TOOLBAR_ADD_BITMAP) && a->ib_normal) {
261 bn.fsStyle |= TBSTYLE_CUSTOMERASE;
262 bn.iBitmap = khui_tb_blank;
264 #if (_WIN32_IE >= 0x0501)
265 bn.iBitmap = I_IMAGENONE;
269 bn.idCommand = a->cmd;
271 if(a->state & KHUI_ACTIONSTATE_DISABLED) {
274 bn.fsState = TBSTATE_ENABLED;
277 if(a->state & KHUI_ACTIONSTATE_CHECKED) {
278 bn.fsState |= TBSTATE_CHECKED;
294 void khm_update_standard_toolbar(void)
297 khui_action_ref * aref;
300 def = khui_find_menu(KHUI_TOOLBAR_STANDARD);
304 while(aref && aref->action != KHUI_MENU_END) {
305 if(aref->action == KHUI_MENU_SEP) {
310 act = khui_find_action(aref->action);
314 enable = !(act->state & KHUI_ACTIONSTATE_DISABLED);
315 SendMessage(khui_hwnd_standard_toolbar,
318 MAKELPARAM(enable, 0));
325 void khm_create_standard_toolbar(HWND rebar) {
333 khui_action_ref * aref;
336 def = khui_find_menu(KHUI_TOOLBAR_STANDARD);
345 hwtb = CreateWindowEx(0 ,
357 (HMENU) NULL, khm_hInstance,
367 #if (_WIN32_IE >= 0x0501)
368 SendMessage(hwtb, TB_SETEXTENDEDSTYLE, 0,
369 TBSTYLE_EX_MIXEDBUTTONS | TBSTYLE_EX_DRAWDDARROWS);
372 hiList = ImageList_Create(
373 KHUI_TOOLBAR_IMAGE_WIDTH,
374 KHUI_TOOLBAR_IMAGE_HEIGHT,
376 (int) khui_action_list_length(def->items),
379 hbm_blank = LoadImage(khm_hInstance,
380 MAKEINTRESOURCE(IDB_TB_BLANK),
382 KHUI_TOOLBAR_IMAGE_WIDTH,
383 KHUI_TOOLBAR_IMAGE_HEIGHT, 0);
384 idx_blank = ImageList_AddMasked(hiList, hbm_blank, RGB(0,0,0));
386 khui_hwnd_standard_toolbar = hwtb;
387 khui_tb_blank = idx_blank;
389 def = khui_find_menu(KHUI_TOOLBAR_STANDARD);
401 MAKELONG(KHUI_TOOLBAR_IMAGE_WIDTH,KHUI_TOOLBAR_IMAGE_HEIGHT));
411 MAKELONG(KHUI_TOOLBAR_IMAGE_WIDTH,KHUI_TOOLBAR_IMAGE_HEIGHT));
413 while(aref && aref->action != KHUI_MENU_END) {
414 if(aref->action == KHUI_MENU_SEP) {
415 khui_add_action_to_toolbar(hwtb,
417 KHUI_TOOLBAR_ADD_SEP,
420 act = khui_find_action(aref->action);
421 khui_add_action_to_toolbar(hwtb,
423 KHUI_TOOLBAR_ADD_BITMAP |
424 ((aref->flags & KHUI_ACTIONREF_SUBMENU)?
425 KHUI_TOOLBAR_ADD_DROPDOWN: 0),
442 ZeroMemory(&rbi, sizeof(rbi));
444 rbi.cbSize = sizeof(rbi);
455 rbi.hwndChild = hwtb;
457 rbi.wID = KHUI_TOOLBAR_STANDARD;
459 rbi.cxMinChild = sz.cx;
460 rbi.cyMinChild = sz.cy;
461 rbi.cyChild = rbi.cyMinChild;
462 rbi.cyMaxChild = rbi.cyMinChild;
463 rbi.cyIntegral = rbi.cyMinChild;
465 rbi.cxIdeal = rbi.cx;