comparison win/dw.c @ 1727:38a0e75bc59c

Since toolbars need to have a bitmap to add a button, if toolbar based buttons fail, fallback to classic bitmap buttons which can be empty. Also disable visual styles on toolbar based buttons initially and reenabling theming when the DW_BS_NOBORDER style is applied.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 May 2012 06:13:35 +0000
parents a02ce34692f0
children aa2bd0d8bf27
comparison
equal deleted inserted replaced
1726:a02ce34692f0 1727:38a0e75bc59c
205 #endif 205 #endif
206 206
207 #ifdef AEROGLASS 207 #ifdef AEROGLASS
208 HRESULT (WINAPI *_DwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS *pMarInset) = 0; 208 HRESULT (WINAPI *_DwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS *pMarInset) = 0;
209 HRESULT (WINAPI *_DwmIsCompositionEnabled)(BOOL *pfEnabled) = 0; 209 HRESULT (WINAPI *_DwmIsCompositionEnabled)(BOOL *pfEnabled) = 0;
210 HTHEME (WINAPI *_OpenThemeData)(HWND hwnd, LPCWSTR pszClassList); 210 HTHEME (WINAPI *_OpenThemeData)(HWND hwnd, LPCWSTR pszClassList) = 0;
211 HPAINTBUFFER (WINAPI *_BeginBufferedPaint)(HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc); 211 HPAINTBUFFER (WINAPI *_BeginBufferedPaint)(HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc) = 0;
212 HRESULT (WINAPI *_BufferedPaintSetAlpha)(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha); 212 HRESULT (WINAPI *_BufferedPaintSetAlpha)(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha) = 0;
213 HRESULT (WINAPI *_DrawThemeTextEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwFlags, LPRECT pRect, const DTTOPTS *pOptions); 213 HRESULT (WINAPI *_DrawThemeTextEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwFlags, LPRECT pRect, const DTTOPTS *pOptions) = 0;
214 HRESULT (WINAPI *_EndBufferedPaint)(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget); 214 HRESULT (WINAPI *_EndBufferedPaint)(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget) = 0;
215 HRESULT (WINAPI *_CloseThemeData)(HTHEME hTheme); 215 HRESULT (WINAPI *_CloseThemeData)(HTHEME hTheme) = 0;
216 HRESULT (WINAPI *_SetWindowTheme)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) = 0;
216 BOOL _dw_composition = FALSE; 217 BOOL _dw_composition = FALSE;
217 COLORREF _dw_transparencykey = RGB(200,201,202); 218 COLORREF _dw_transparencykey = RGB(200,201,202);
218 HANDLE hdwm = 0, huxtheme = 0; 219 HANDLE hdwm = 0, huxtheme = 0;
219 #endif 220 #endif
220 221
4072 _BeginBufferedPaint = (HPAINTBUFFER (WINAPI *)(HDC, const RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *))GetProcAddress(huxtheme, "BeginBufferedPaint"); 4073 _BeginBufferedPaint = (HPAINTBUFFER (WINAPI *)(HDC, const RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *))GetProcAddress(huxtheme, "BeginBufferedPaint");
4073 _BufferedPaintSetAlpha = (HRESULT (WINAPI *)(HPAINTBUFFER, const RECT *, BYTE))GetProcAddress(huxtheme, "BufferedPaintSetAlpha"); 4074 _BufferedPaintSetAlpha = (HRESULT (WINAPI *)(HPAINTBUFFER, const RECT *, BYTE))GetProcAddress(huxtheme, "BufferedPaintSetAlpha");
4074 _DrawThemeTextEx = (HRESULT (WINAPI *)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const DTTOPTS *))GetProcAddress(huxtheme, "DrawThemeTextEx"); 4075 _DrawThemeTextEx = (HRESULT (WINAPI *)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const DTTOPTS *))GetProcAddress(huxtheme, "DrawThemeTextEx");
4075 _EndBufferedPaint = (HRESULT (WINAPI *)(HPAINTBUFFER, BOOL))GetProcAddress(huxtheme, "EndBufferedPaint"); 4076 _EndBufferedPaint = (HRESULT (WINAPI *)(HPAINTBUFFER, BOOL))GetProcAddress(huxtheme, "EndBufferedPaint");
4076 _CloseThemeData = (HRESULT (WINAPI *)(HTHEME))GetProcAddress(huxtheme, "CloseThemeData"); 4077 _CloseThemeData = (HRESULT (WINAPI *)(HTHEME))GetProcAddress(huxtheme, "CloseThemeData");
4078 _SetWindowTheme = (HRESULT (WINAPI *)(HWND, LPCWSTR, LPCWSTR ))GetProcAddress(huxtheme, "SetWindowTheme");
4077 } 4079 }
4078 /* In case of error close the library if needed */ 4080 /* In case of error close the library if needed */
4079 else if(hdwm) 4081 else if(hdwm)
4080 { 4082 {
4081 FreeLibrary(hdwm); 4083 FreeLibrary(hdwm);
6232 6234
6233 /* Create the toolbar */ 6235 /* Create the toolbar */
6234 tmp = CreateWindowEx(0L, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_AUTOSIZE | CCS_NORESIZE | 6236 tmp = CreateWindowEx(0L, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_AUTOSIZE | CCS_NORESIZE |
6235 CCS_NOPARENTALIGN | CCS_NODIVIDER, 0, 0, 100, 30, DW_HWND_OBJECT, (HMENU)id, DWInstance, NULL); 6237 CCS_NOPARENTALIGN | CCS_NODIVIDER, 0, 0, 100, 30, DW_HWND_OBJECT, (HMENU)id, DWInstance, NULL);
6236 6238
6239 #ifdef AEROGLASS
6240 /* Disable visual styles by default */
6241 if(_SetWindowTheme)
6242 _SetWindowTheme(tmp, TEXT(""), TEXT(""));
6243 #endif
6244
6237 /* Insert the single bitmap and button into the toolbar */ 6245 /* Insert the single bitmap and button into the toolbar */
6238 SendMessage(tmp, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); 6246 SendMessage(tmp, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
6239 SendMessage(tmp, TB_SETBUTTONSIZE, 0, MAKELPARAM(bmi.bmWidth, bmi.bmHeight)); 6247 SendMessage(tmp, TB_SETBUTTONSIZE, 0, MAKELPARAM(bmi.bmWidth, bmi.bmHeight));
6240 SendMessage(tmp, TB_SETPADDING, 0, 0); 6248 SendMessage(tmp, TB_SETPADDING, 0, 0);
6241 SendMessage(tmp, TB_SETIMAGELIST, 0, (LPARAM)imlist); 6249 SendMessage(tmp, TB_SETIMAGELIST, 0, (LPARAM)imlist);
6257 HWND tmp; 6265 HWND tmp;
6258 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6266 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
6259 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0); 6267 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0);
6260 HBITMAP hbitmap = icon ? 0 : LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); 6268 HBITMAP hbitmap = icon ? 0 : LoadBitmap(DWInstance, MAKEINTRESOURCE(id));
6261 #ifdef TOOLBAR 6269 #ifdef TOOLBAR
6262 tmp = _create_toolbar(text, id, icon, hbitmap); 6270 if(tmp = _create_toolbar(text, id, icon, hbitmap))
6263 6271 {
6264 cinfo->fore = cinfo->back = -1; 6272 cinfo->fore = cinfo->back = -1;
6265 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 6273 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6266 #else 6274 return tmp;
6275 }
6276 #endif
6267 6277
6268 tmp = CreateWindow(BUTTONCLASSNAME, 6278 tmp = CreateWindow(BUTTONCLASSNAME,
6269 NULL, 6279 NULL,
6270 WS_CHILD | BS_PUSHBUTTON | 6280 WS_CHILD | BS_PUSHBUTTON |
6271 WS_VISIBLE | WS_CLIPCHILDREN | 6281 WS_VISIBLE | WS_CLIPCHILDREN |
6289 } 6299 }
6290 else if(hbitmap) 6300 else if(hbitmap)
6291 { 6301 {
6292 SendMessage(tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); 6302 SendMessage(tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap);
6293 } 6303 }
6294 #endif
6295 return tmp; 6304 return tmp;
6296 } 6305 }
6297 6306
6298 /* 6307 /*
6299 * Create a new bitmap button window (widget) to be packed from a file. 6308 * Create a new bitmap button window (widget) to be packed from a file.
6326 #else 6335 #else
6327 windowtype = _dw_get_image_handle(filename, &hicon, &hbitmap); 6336 windowtype = _dw_get_image_handle(filename, &hicon, &hbitmap);
6328 #endif 6337 #endif
6329 6338
6330 #ifdef TOOLBAR 6339 #ifdef TOOLBAR
6331 tmp = _create_toolbar(text, id, hicon, hbitmap); 6340 if(tmp = _create_toolbar(text, id, hicon, hbitmap))
6332 6341 {
6333 cinfo->fore = cinfo->back = -1; 6342 cinfo->fore = cinfo->back = -1;
6334 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 6343 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6335 #else 6344 return tmp;
6345 }
6346 #endif
6336 tmp = CreateWindow( BUTTONCLASSNAME, 6347 tmp = CreateWindow( BUTTONCLASSNAME,
6337 NULL, 6348 NULL,
6338 windowtype | WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN | WS_VISIBLE, 6349 windowtype | WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN | WS_VISIBLE,
6339 0,0,0,0, 6350 0,0,0,0,
6340 DW_HWND_OBJECT, 6351 DW_HWND_OBJECT,
6355 } 6366 }
6356 else if (hbitmap) 6367 else if (hbitmap)
6357 { 6368 {
6358 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); 6369 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap);
6359 } 6370 }
6360 #endif
6361 return tmp; 6371 return tmp;
6362 } 6372 }
6363 6373
6364 /* 6374 /*
6365 * Create a new bitmap button window (widget) to be packed from data. 6375 * Create a new bitmap button window (widget) to be packed from data.
6415 _unlink( file ); 6425 _unlink( file );
6416 free( file ); 6426 free( file );
6417 } 6427 }
6418 6428
6419 #ifdef TOOLBAR 6429 #ifdef TOOLBAR
6420 tmp = _create_toolbar(text, id, hicon, hbitmap); 6430 if(tmp = _create_toolbar(text, id, hicon, hbitmap))
6421 6431 {
6422 cinfo->fore = cinfo->back = -1; 6432 cinfo->fore = cinfo->back = -1;
6423 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 6433 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6424 #else 6434 return tmp;
6435 }
6436 #endif
6425 tmp = CreateWindow( BUTTONCLASSNAME, 6437 tmp = CreateWindow( BUTTONCLASSNAME,
6426 NULL, 6438 NULL,
6427 WS_CHILD | BS_PUSHBUTTON | 6439 WS_CHILD | BS_PUSHBUTTON |
6428 windowtype | WS_CLIPCHILDREN | 6440 windowtype | WS_CLIPCHILDREN |
6429 WS_VISIBLE, 6441 WS_VISIBLE,
6446 } 6458 }
6447 else if( hbitmap ) 6459 else if( hbitmap )
6448 { 6460 {
6449 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); 6461 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap);
6450 } 6462 }
6451 #endif
6452 return tmp; 6463 return tmp;
6453 } 6464 }
6454 6465
6455 /* 6466 /*
6456 * Create a new spinbutton window (widget) to be packed. 6467 * Create a new spinbutton window (widget) to be packed.
7604 ULONG thisstyle = (TBSTYLE_FLAT | TBSTYLE_TRANSPARENT); 7615 ULONG thisstyle = (TBSTYLE_FLAT | TBSTYLE_TRANSPARENT);
7605 7616
7606 if(mask & DW_BS_NOBORDER) 7617 if(mask & DW_BS_NOBORDER)
7607 { 7618 {
7608 SetWindowLong(handle, GWL_STYLE, (style & DW_BS_NOBORDER) ? (currentstyle | thisstyle) : (currentstyle & ~thisstyle)); 7619 SetWindowLong(handle, GWL_STYLE, (style & DW_BS_NOBORDER) ? (currentstyle | thisstyle) : (currentstyle & ~thisstyle));
7620
7621 #ifdef AEROGLASS
7622 /* Enable or disable visual themese */
7623 if(_SetWindowTheme)
7624 _SetWindowTheme(handle, (style & DW_BS_NOBORDER) ? NULL : TEXT(""), (style & DW_BS_NOBORDER) ? NULL : TEXT(""));
7625 #endif
7609 return; 7626 return;
7610 } 7627 }
7611 } 7628 }
7612 #endif 7629 #endif
7613 7630