Mercurial > dwindows
comparison win/dw.c @ 1722:d9849833e535
Toolbar based bitmap buttons are now functional on Windows.
They don't look exactly the way I want in all circumstances though...
More work still needed... compile with -DTOOLBAR to test.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 14 May 2012 19:24:27 +0000 |
parents | 8c98c8525918 |
children | d55227360864 |
comparison
equal
deleted
inserted
replaced
1721:8c98c8525918 | 1722:d9849833e535 |
---|---|
755 #ifdef TOOLBAR | 755 #ifdef TOOLBAR |
756 /* Bitmap Buttons */ | 756 /* Bitmap Buttons */ |
757 else if(_tcsnicmp(tmpbuf, TOOLBARCLASSNAME, _tcslen(TOOLBARCLASSNAME)+1) == 0) | 757 else if(_tcsnicmp(tmpbuf, TOOLBARCLASSNAME, _tcslen(TOOLBARCLASSNAME)+1) == 0) |
758 { | 758 { |
759 HIMAGELIST imlist = (HIMAGELIST)SendMessage(handle, TB_GETIMAGELIST, 0, 0); | 759 HIMAGELIST imlist = (HIMAGELIST)SendMessage(handle, TB_GETIMAGELIST, 0, 0); |
760 | |
761 SendMessage(handle, TB_SETIMAGELIST, 0, 0); | |
760 | 762 |
761 if(imlist) | 763 if(imlist) |
762 ImageList_Destroy(imlist); | 764 ImageList_Destroy(imlist); |
763 } | 765 } |
764 #endif | 766 #endif |
2160 { | 2162 { |
2161 result = listboxselectfunc(tmp->window, dw_listbox_selected(tmp->window), tmp->data); | 2163 result = listboxselectfunc(tmp->window, dw_listbox_selected(tmp->window), tmp->data); |
2162 tmp = NULL; | 2164 tmp = NULL; |
2163 } | 2165 } |
2164 } | 2166 } |
2167 #ifdef TOOLBAR | |
2168 else if (message == BN_CLICKED && tmp->message == WM_COMMAND && tmp->window == (HWND)mp2) | |
2169 { | |
2170 result = clickfunc(tmp->window, tmp->data); | |
2171 tmp = NULL; | |
2172 } | |
2173 #endif | |
2165 else if (tmp->id && passthru == tmp->id) | 2174 else if (tmp->id && passthru == tmp->id) |
2166 { | 2175 { |
2167 HMENU hwndmenu = GetMenu(hWnd), menuowner = _menu_owner((HMENU)tmp->window); | 2176 HMENU hwndmenu = GetMenu(hWnd), menuowner = _menu_owner((HMENU)tmp->window); |
2168 | 2177 |
2169 if (menuowner == hwndmenu || !menuowner) | 2178 if (menuowner == hwndmenu || !menuowner) |
6130 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 6139 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
6131 dw_window_set_font(tmp, DefaultFont); | 6140 dw_window_set_font(tmp, DefaultFont); |
6132 return tmp; | 6141 return tmp; |
6133 } | 6142 } |
6134 | 6143 |
6135 /* | 6144 /* Internal function to create a toolbar based button */ |
6136 * Create a new bitmap button window (widget) to be packed. | 6145 HWND _create_toolbar(char *text, ULONG id, HICON icon, HBITMAP hbitmap) |
6137 * Parameters: | |
6138 * text: Bubble help text to be displayed. | |
6139 * id: An ID of a bitmap in the resource file. | |
6140 */ | |
6141 HWND API dw_bitmapbutton_new(char *text, ULONG id) | |
6142 { | 6146 { |
6143 HWND tmp; | 6147 HWND tmp; |
6144 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | |
6145 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0); | |
6146 #ifdef TOOLBAR | |
6147 HIMAGELIST imlist; | 6148 HIMAGELIST imlist; |
6148 BITMAP bmi = { 0 }; | 6149 BITMAP bmi = { 0 }; |
6149 TBBUTTON tbButtons[] = { | 6150 TBBUTTON tbButtons[] = { |
6150 { MAKELONG(0, 0), id, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0} | 6151 { MAKELONG(0, 0), id, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0} |
6151 }; | 6152 }; |
6152 | 6153 |
6153 /* Get the bitmap from either the icon or bitmap itself */ | 6154 /* Get the bitmap from either the icon or bitmap itself */ |
6154 if(!icon) | 6155 if(hbitmap) |
6155 { | 6156 { |
6156 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | |
6157 | |
6158 GetObject(hbitmap, sizeof(BITMAP), &bmi); | 6157 GetObject(hbitmap, sizeof(BITMAP), &bmi); |
6159 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLORDDB | ILC_MASK, 1, 0); | 6158 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32, 1, 0); |
6160 ImageList_Add(imlist, hbitmap, NULL); | 6159 ImageList_Add(imlist, hbitmap, NULL); |
6161 } | 6160 } |
6162 else | 6161 else if(icon) |
6163 { | 6162 { |
6164 ICONINFO iconinfo; | 6163 ICONINFO iconinfo; |
6165 | 6164 |
6166 GetIconInfo(icon, &iconinfo); | 6165 GetIconInfo(icon, &iconinfo); |
6167 GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bmi); | 6166 GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bmi); |
6168 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLORDDB | ILC_MASK, 1, 0); | 6167 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32 | ILC_MASK, 1, 0); |
6169 ImageList_AddIcon(imlist, icon); | 6168 ImageList_AddIcon(imlist, icon); |
6170 } | 6169 } |
6170 else | |
6171 return 0; | |
6171 | 6172 |
6172 /* Create the toolbar */ | 6173 /* Create the toolbar */ |
6173 tmp = CreateWindowEx(0L, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | CCS_NORESIZE | CCS_NOPARENTALIGN, | 6174 tmp = CreateWindowEx(0L, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_AUTOSIZE | CCS_NORESIZE | |
6174 0, 0, 100, 30, DW_HWND_OBJECT, (HMENU)id, DWInstance, NULL); | 6175 CCS_NOPARENTALIGN | CCS_NODIVIDER, 0, 0, 100, 30, DW_HWND_OBJECT, (HMENU)id, DWInstance, NULL); |
6175 | 6176 |
6176 cinfo->fore = cinfo->back = -1; | |
6177 | |
6178 /* Insert the single bitmap and button into the toolbar */ | 6177 /* Insert the single bitmap and button into the toolbar */ |
6179 SendMessage(tmp, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); | 6178 SendMessage(tmp, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); |
6179 SendMessage(tmp, TB_SETPADDING, 0, 0); | |
6180 SendMessage(tmp, TB_SETIMAGELIST, 0, (LPARAM)imlist); | 6180 SendMessage(tmp, TB_SETIMAGELIST, 0, (LPARAM)imlist); |
6181 SendMessage(tmp, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)imlist); | |
6181 SendMessage(tmp, TB_ADDBUTTONS, 1, (LONG) &tbButtons); | 6182 SendMessage(tmp, TB_ADDBUTTONS, 1, (LONG) &tbButtons); |
6182 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | |
6183 | 6183 |
6184 _create_tooltip(tmp, text); | 6184 _create_tooltip(tmp, text); |
6185 return tmp; | |
6186 } | |
6187 | |
6188 /* | |
6189 * Create a new bitmap button window (widget) to be packed. | |
6190 * Parameters: | |
6191 * text: Bubble help text to be displayed. | |
6192 * id: An ID of a bitmap in the resource file. | |
6193 */ | |
6194 HWND API dw_bitmapbutton_new(char *text, ULONG id) | |
6195 { | |
6196 HWND tmp; | |
6197 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | |
6198 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0); | |
6199 HBITMAP hbitmap = icon ? 0 : LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | |
6200 #ifdef TOOLBAR | |
6201 tmp = _create_toolbar(text, id, icon, hbitmap); | |
6202 | |
6203 cinfo->fore = cinfo->back = -1; | |
6204 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | |
6185 #else | 6205 #else |
6186 HBITMAP hbitmap = icon ? 0 : LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | |
6187 | 6206 |
6188 tmp = CreateWindow(BUTTONCLASSNAME, | 6207 tmp = CreateWindow(BUTTONCLASSNAME, |
6189 NULL, | 6208 NULL, |
6190 WS_CHILD | BS_PUSHBUTTON | | 6209 WS_CHILD | BS_PUSHBUTTON | |
6191 WS_VISIBLE | WS_CLIPCHILDREN | | 6210 WS_VISIBLE | WS_CLIPCHILDREN | |
6245 } | 6264 } |
6246 #else | 6265 #else |
6247 windowtype = _dw_get_image_handle(filename, &hicon, &hbitmap); | 6266 windowtype = _dw_get_image_handle(filename, &hicon, &hbitmap); |
6248 #endif | 6267 #endif |
6249 | 6268 |
6269 #ifdef TOOLBAR | |
6270 tmp = _create_toolbar(text, id, hicon, hbitmap); | |
6271 | |
6272 cinfo->fore = cinfo->back = -1; | |
6273 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | |
6274 #else | |
6250 tmp = CreateWindow( BUTTONCLASSNAME, | 6275 tmp = CreateWindow( BUTTONCLASSNAME, |
6251 NULL, | 6276 NULL, |
6252 windowtype | WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN | WS_VISIBLE, | 6277 windowtype | WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN | WS_VISIBLE, |
6253 0,0,0,0, | 6278 0,0,0,0, |
6254 DW_HWND_OBJECT, | 6279 DW_HWND_OBJECT, |
6269 } | 6294 } |
6270 else if (hbitmap) | 6295 else if (hbitmap) |
6271 { | 6296 { |
6272 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); | 6297 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); |
6273 } | 6298 } |
6299 #endif | |
6274 return tmp; | 6300 return tmp; |
6275 } | 6301 } |
6276 | 6302 |
6277 /* | 6303 /* |
6278 * Create a new bitmap button window (widget) to be packed from data. | 6304 * Create a new bitmap button window (widget) to be packed from data. |
6327 } | 6353 } |
6328 _unlink( file ); | 6354 _unlink( file ); |
6329 free( file ); | 6355 free( file ); |
6330 } | 6356 } |
6331 | 6357 |
6358 #ifdef TOOLBAR | |
6359 tmp = _create_toolbar(text, id, hicon, hbitmap); | |
6360 | |
6361 cinfo->fore = cinfo->back = -1; | |
6362 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | |
6363 #else | |
6332 tmp = CreateWindow( BUTTONCLASSNAME, | 6364 tmp = CreateWindow( BUTTONCLASSNAME, |
6333 NULL, | 6365 NULL, |
6334 WS_CHILD | BS_PUSHBUTTON | | 6366 WS_CHILD | BS_PUSHBUTTON | |
6335 windowtype | WS_CLIPCHILDREN | | 6367 windowtype | WS_CLIPCHILDREN | |
6336 WS_VISIBLE, | 6368 WS_VISIBLE, |
6353 } | 6385 } |
6354 else if( hbitmap ) | 6386 else if( hbitmap ) |
6355 { | 6387 { |
6356 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); | 6388 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); |
6357 } | 6389 } |
6390 #endif | |
6358 return tmp; | 6391 return tmp; |
6359 } | 6392 } |
6360 | 6393 |
6361 /* | 6394 /* |
6362 * Create a new spinbutton window (widget) to be packed. | 6395 * Create a new spinbutton window (widget) to be packed. |