sync with trunk r46493
[reactos.git] / base / applications / rapps / toolbar.c
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/toolbar.c
5 * PURPOSE: ToolBar functions
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 */
8
9 #include "rapps.h"
10
11 #define TOOLBAR_HEIGHT 24
12
13 HWND hToolBar;
14 HWND hSearchBar;
15
16 static WCHAR szInstallBtn[MAX_STR_LEN];
17 static WCHAR szUninstallBtn[MAX_STR_LEN];
18 static WCHAR szModifyBtn[MAX_STR_LEN];
19
20 /* Toolbar buttons */
21 static const TBBUTTON Buttons[] =
22 { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
23 { 0, ID_INSTALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0, (INT_PTR)szInstallBtn},
24 { 1, ID_UNINSTALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0, (INT_PTR)szUninstallBtn},
25 { 2, ID_MODIFY, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0, (INT_PTR)szModifyBtn},
26 { 5, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},
27 { 3, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0, 0},
28 { 5, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},
29 { 4, ID_SETTINGS, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0, 0},
30 { 5, ID_EXIT, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0, 0}
31 };
32
33
34 VOID
35 ToolBarOnGetDispInfo(LPTOOLTIPTEXT lpttt)
36 {
37 UINT idButton = (UINT)lpttt->hdr.idFrom;
38
39 switch (idButton)
40 {
41 case ID_EXIT:
42 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
43 break;
44
45 case ID_INSTALL:
46 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_INSTALL);
47 break;
48
49 case ID_UNINSTALL:
50 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_UNINSTALL);
51 break;
52
53 case ID_MODIFY:
54 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_MODIFY);
55 break;
56
57 case ID_SETTINGS:
58 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_SETTINGS);
59 break;
60
61 case ID_REFRESH:
62 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
63 break;
64 }
65 }
66
67 VOID
68 AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex)
69 {
70 HANDLE hImage;
71
72 if (!(hImage = LoadImage(hInst,
73 MAKEINTRESOURCE(ImageIndex),
74 IMAGE_ICON,
75 TOOLBAR_HEIGHT,
76 TOOLBAR_HEIGHT,
77 0)))
78 {
79 /* TODO: Error message */
80 }
81
82 ImageList_AddIcon(hImageList, hImage);
83 DeleteObject(hImage);
84 }
85
86 HIMAGELIST
87 InitImageList(VOID)
88 {
89 HIMAGELIST hImageList;
90
91 /* Create the toolbar icon image list */
92 hImageList = ImageList_Create(TOOLBAR_HEIGHT,//GetSystemMetrics(SM_CXSMICON),
93 TOOLBAR_HEIGHT,//GetSystemMetrics(SM_CYSMICON),
94 ILC_MASK | GetSystemColorDepth(),
95 1,
96 1);
97 if (!hImageList)
98 {
99 /* TODO: Error message */
100 return NULL;
101 }
102
103 AddImageToImageList(hImageList, IDI_INSTALL);
104 AddImageToImageList(hImageList, IDI_UNINSTALL);
105 AddImageToImageList(hImageList, IDI_MODIFY);
106 AddImageToImageList(hImageList, IDI_REFRESH);
107 AddImageToImageList(hImageList, IDI_SETTINGS);
108 AddImageToImageList(hImageList, IDI_EXIT);
109
110 return hImageList;
111 }
112
113 static
114 BOOL
115 CreateSearchBar(VOID)
116 {
117 WCHAR szBuf[MAX_STR_LEN];
118
119 hSearchBar = CreateWindowExW(WS_EX_CLIENTEDGE,
120 L"Edit",
121 NULL,
122 WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOVSCROLL,
123 0,
124 5,
125 200,
126 22,
127 hToolBar,
128 (HMENU)0,
129 hInst,
130 0);
131
132 SendMessageW(hSearchBar, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
133
134 LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, sizeof(szBuf) / sizeof(WCHAR));
135 SetWindowTextW(hSearchBar, szBuf);
136
137 SetParent(hSearchBar, hToolBar);
138
139 return TRUE;
140 }
141
142 BOOL
143 CreateToolBar(HWND hwnd)
144 {
145 INT NumButtons = sizeof(Buttons) / sizeof(Buttons[0]);
146 HIMAGELIST hImageList;
147
148 LoadStringW(hInst, IDS_INSTALL, szInstallBtn, sizeof(szInstallBtn) / sizeof(WCHAR));
149 LoadStringW(hInst, IDS_UNINSTALL, szUninstallBtn, sizeof(szUninstallBtn) / sizeof(WCHAR));
150 LoadStringW(hInst, IDS_MODIFY, szModifyBtn, sizeof(szModifyBtn) / sizeof(WCHAR));
151
152 hToolBar = CreateWindowExW(0,
153 TOOLBARCLASSNAMEW,
154 NULL,
155 WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_LIST,
156 0, 0, 0, 0,
157 hwnd,
158 0,
159 hInst,
160 NULL);
161
162 if (!hToolBar)
163 {
164 /* TODO: Show error message */
165 return FALSE;
166 }
167
168 SendMessageW(hToolBar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS);
169 SendMessageW(hToolBar, TB_BUTTONSTRUCTSIZE, sizeof(Buttons[0]), 0);
170
171 hImageList = InitImageList();
172
173 if (!hImageList)
174 {
175 /* TODO: Show error message */
176 return FALSE;
177 }
178
179 ImageList_Destroy((HIMAGELIST)SendMessageW(hToolBar,
180 TB_SETIMAGELIST,
181 0,
182 (LPARAM)hImageList));
183
184 SendMessageW(hToolBar, TB_ADDBUTTONS, NumButtons, (LPARAM)Buttons);
185
186 CreateSearchBar();
187
188 return TRUE;
189 }