comparison win/dw.c @ 2138:55263d21b399

Win: Add function for drawing titlebar text while in dark mode... Previously the top left of the titlebar did not draw. This is where the code to draw the menu button will go.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 09 Jul 2020 09:27:05 +0000
parents e780c68cf5b1
children b1521c8f7861
comparison
equal deleted inserted replaced
2137:e780c68cf5b1 2138:55263d21b399
214 HPAINTBUFFER (WINAPI *_BeginBufferedPaint)(HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc) = 0; 214 HPAINTBUFFER (WINAPI *_BeginBufferedPaint)(HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc) = 0;
215 HRESULT (WINAPI *_BufferedPaintSetAlpha)(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha) = 0; 215 HRESULT (WINAPI *_BufferedPaintSetAlpha)(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha) = 0;
216 HRESULT (WINAPI *_DrawThemeTextEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwFlags, LPRECT pRect, const DTTOPTS *pOptions) = 0; 216 HRESULT (WINAPI *_DrawThemeTextEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwFlags, LPRECT pRect, const DTTOPTS *pOptions) = 0;
217 HRESULT (WINAPI *_EndBufferedPaint)(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget) = 0; 217 HRESULT (WINAPI *_EndBufferedPaint)(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget) = 0;
218 HRESULT (WINAPI *_CloseThemeData)(HTHEME hTheme) = 0; 218 HRESULT (WINAPI *_CloseThemeData)(HTHEME hTheme) = 0;
219 HRESULT (WINAPI *_GetThemeSysFont)(HTHEME hTheme, int iFontId, LOGFONTW *plf) = 0;
219 BOOL _dw_composition = FALSE; 220 BOOL _dw_composition = FALSE;
220 COLORREF _dw_transparencykey = RGB(200,201,202); 221 COLORREF _dw_transparencykey = RGB(200,201,202);
221 HANDLE hdwm = 0; 222 HANDLE hdwm = 0;
222 #endif 223 #endif
223 /* Aero related but separate functions and handles */ 224 /* Aero related but separate functions and handles */
813 _DW_DARK_MODE_ENABLED = _DW_ShouldAppsUseDarkMode(); 814 _DW_DARK_MODE_ENABLED = _DW_ShouldAppsUseDarkMode();
814 } 815 }
815 } 816 }
816 } 817 }
817 818
819 /* Return a margins struct based on the calculated window rect */
818 MARGINS _dw_rect_to_margins(RECT rect) 820 MARGINS _dw_rect_to_margins(RECT rect)
819 { 821 {
820 MARGINS mar = { rect.left, rect.right, rect.top, rect.bottom }; 822 /* Left, Right, Top, Bottom */
823 MARGINS mar = { 1, 1, rect.top, 1 }, none = {0};
821 824
822 return mar; 825 if(_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC & _DW_DARK_MODE_ENABLED)
826 return mar;
827 return none;
823 } 828 }
824 829
825 BOOL _CanThemeWindow(HWND window) 830 BOOL _CanThemeWindow(HWND window)
826 { 831 {
827 TCHAR tmpbuf[100] = {0}; 832 TCHAR tmpbuf[100] = {0};
902 { 907 {
903 AllowDarkModeForWindow(window, _DW_DARK_MODE_ENABLED); 908 AllowDarkModeForWindow(window, _DW_DARK_MODE_ENABLED);
904 SendMessageW(window, WM_THEMECHANGED, 0, 0); 909 SendMessageW(window, WM_THEMECHANGED, 0, 0);
905 } 910 }
906 return TRUE; 911 return TRUE;
912 }
913
914 #define RECTWIDTH(rc) (rc.right - rc.left)
915 #define RECTHEIGHT(rc) (rc.bottom - rc.top)
916
917 /* Our function to draw the titlebar in dark mode */
918 void _DW_DrawDarkModeTitleBar(HWND hWnd, HDC hdc)
919 {
920 if(_OpenThemeData && _CloseThemeData && _DrawThemeTextEx && _GetThemeSysFont)
921 {
922 HTHEME hTheme = _OpenThemeData(NULL, L"CompositedWindow::Window");
923 RECT rcClient;
924
925 GetClientRect(hWnd, &rcClient);
926
927 if(hTheme)
928 {
929 HDC hdcPaint = CreateCompatibleDC(hdc);
930
931 if(hdcPaint)
932 {
933 int cx = RECTWIDTH(rcClient);
934 int cy = RECTHEIGHT(rcClient);
935
936 /* Define the BITMAPINFO structure used to draw text.
937 * Note that biHeight is negative. This is done because
938 * DrawThemeTextEx() needs the bitmap to be in top-to-bottom
939 * order.
940 */
941 BITMAPINFO dib = { 0 };
942 dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
943 dib.bmiHeader.biWidth = cx;
944 dib.bmiHeader.biHeight = -cy;
945 dib.bmiHeader.biPlanes = 1;
946 dib.bmiHeader.biBitCount = 32;
947 dib.bmiHeader.biCompression = BI_RGB;
948
949 HBITMAP hbm = CreateDIBSection(hdc, &dib, DIB_RGB_COLORS, NULL, NULL, 0);
950 if (hbm)
951 {
952 HBITMAP hbmOld = (HBITMAP)SelectObject(hdcPaint, hbm);
953 LOGFONT lgFont;
954 HFONT hFontOld = NULL;
955 RECT rcPaint = rcClient;
956 TCHAR *tempbuf;
957 int len;
958
959 /* Setup the theme drawing options. */
960 DTTOPTS DttOpts = {sizeof(DTTOPTS)};
961 DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
962 DttOpts.iGlowSize = 15;
963
964 /* Select a font. */
965 if(_GetThemeSysFont(hTheme, 801 /*TMT_CAPTIONFONT*/, &lgFont) == S_OK)
966 {
967 HFONT hFont = CreateFontIndirect(&lgFont);
968 hFontOld = (HFONT)SelectObject(hdcPaint, hFont);
969 }
970
971 /* Draw the title. */
972 len = GetWindowTextLength(hWnd) + 1;
973 if((tempbuf = _alloca(len * sizeof(TCHAR))))
974 GetWindowText(hWnd, tempbuf, len);
975 rcPaint.top += 8;
976 rcPaint.right -= 125;
977 rcPaint.left += 8;
978 rcPaint.bottom = 50;
979 _DrawThemeTextEx(hTheme,
980 hdcPaint,
981 0, 0,
982 tempbuf ? tempbuf : TEXT("<no title>"),
983 -1,
984 DT_LEFT | DT_WORD_ELLIPSIS,
985 &rcPaint,
986 &DttOpts);
987
988 /* Blit text to the frame. */
989 BitBlt(hdc, 0, 0, cx, cy, hdcPaint, 0, 0, SRCCOPY);
990
991 SelectObject(hdcPaint, hbmOld);
992 if(hFontOld)
993 {
994 SelectObject(hdcPaint, hFontOld);
995 }
996 DeleteObject(hbm);
997 }
998 DeleteDC(hdcPaint);
999 }
1000 _CloseThemeData(hTheme);
1001 }
1002 }
907 } 1003 }
908 #endif 1004 #endif
909 1005
910 /* Special wrappers for GetSysColor*() since they currently don't support 1006 /* Special wrappers for GetSysColor*() since they currently don't support
911 * dark mode, we will have to return modified colors when dark mode is enabled. 1007 * dark mode, we will have to return modified colors when dark mode is enabled.
2273 { 2369 {
2274 PAINTSTRUCT ps; 2370 PAINTSTRUCT ps;
2275 DWExpose exp; 2371 DWExpose exp;
2276 int (DWSIGNAL *exposefunc)(HWND, DWExpose *, void *) = tmp->signalfunction; 2372 int (DWSIGNAL *exposefunc)(HWND, DWExpose *, void *) = tmp->signalfunction;
2277 2373
2374 #ifdef DARK_MODE_TITLEBAR_MENU
2375 if(_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED && GetParent(hWnd) == HWND_DESKTOP)
2376 {
2377 HDC hdc = BeginPaint(hWnd, &ps);
2378 _DW_DrawDarkModeTitleBar(hWnd, hdc);
2379 EndPaint(hWnd, &ps);
2380 }
2381 #endif
2278 if ( hWnd == tmp->window ) 2382 if ( hWnd == tmp->window )
2279 { 2383 {
2280 BeginPaint(hWnd, &ps); 2384 BeginPaint(hWnd, &ps);
2281 exp.x = ps.rcPaint.left; 2385 exp.x = ps.rcPaint.left;
2282 exp.y = ps.rcPaint.top; 2386 exp.y = ps.rcPaint.top;
2621 _DW_DARK_MODE_ENABLED = _DW_ShouldAppsUseDarkMode(); 2725 _DW_DARK_MODE_ENABLED = _DW_ShouldAppsUseDarkMode();
2622 2726
2623 RefreshTitleBarThemeColor(hWnd); 2727 RefreshTitleBarThemeColor(hWnd);
2624 _dw_set_child_window_theme(hWnd, 0); 2728 _dw_set_child_window_theme(hWnd, 0);
2625 EnumChildWindows(hWnd, _dw_set_child_window_theme, 0); 2729 EnumChildWindows(hWnd, _dw_set_child_window_theme, 0);
2730 #ifdef DARK_MODE_TITLEBAR_MENU
2731 if(_DW_DARK_MODE_SUPPORTED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED)
2732 SetMenu(hWnd, NULL);
2733 else
2734 {
2735 HMENU menu = (HMENU)dw_window_get_data(hWnd, "_dw_menu");
2736 SetMenu(hWnd, menu);
2737 }
2738 #endif
2626 } 2739 }
2627 } 2740 }
2628 break; 2741 break;
2629 #endif 2742 #endif
2630 #ifdef AEROGLASS1 2743 #ifdef AEROGLASS1
4440 _DwmSetWindowAttribute = (HRESULT (WINAPI *)(HWND, DWORD, LPCVOID, DWORD))GetProcAddress(hdwm, "DwmSetWindowAttribute"); 4553 _DwmSetWindowAttribute = (HRESULT (WINAPI *)(HWND, DWORD, LPCVOID, DWORD))GetProcAddress(hdwm, "DwmSetWindowAttribute");
4441 _DwmDefWindowProc = (BOOL (WINAPI *)(HWND, UINT, WPARAM, LPARAM, LRESULT *))GetProcAddress(hdwm, "DwmDefWindowProc"); 4554 _DwmDefWindowProc = (BOOL (WINAPI *)(HWND, UINT, WPARAM, LPARAM, LRESULT *))GetProcAddress(hdwm, "DwmDefWindowProc");
4442 if((_DwmIsCompositionEnabled = (HRESULT (WINAPI *)(BOOL *))GetProcAddress(hdwm, "DwmIsCompositionEnabled"))) 4555 if((_DwmIsCompositionEnabled = (HRESULT (WINAPI *)(BOOL *))GetProcAddress(hdwm, "DwmIsCompositionEnabled")))
4443 _DwmIsCompositionEnabled(&_dw_composition); 4556 _DwmIsCompositionEnabled(&_dw_composition);
4444 _OpenThemeData = (HTHEME (WINAPI *)(HWND, LPCWSTR))GetProcAddress(huxtheme, "OpenThemeData"); 4557 _OpenThemeData = (HTHEME (WINAPI *)(HWND, LPCWSTR))GetProcAddress(huxtheme, "OpenThemeData");
4558 _GetThemeSysFont = (HRESULT (WINAPI *)(HTHEME, int, LOGFONTW *))GetProcAddress(huxtheme, "GetThemeSysFont");
4445 _BeginBufferedPaint = (HPAINTBUFFER (WINAPI *)(HDC, const RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *))GetProcAddress(huxtheme, "BeginBufferedPaint"); 4559 _BeginBufferedPaint = (HPAINTBUFFER (WINAPI *)(HDC, const RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *))GetProcAddress(huxtheme, "BeginBufferedPaint");
4446 _BufferedPaintSetAlpha = (HRESULT (WINAPI *)(HPAINTBUFFER, const RECT *, BYTE))GetProcAddress(huxtheme, "BufferedPaintSetAlpha"); 4560 _BufferedPaintSetAlpha = (HRESULT (WINAPI *)(HPAINTBUFFER, const RECT *, BYTE))GetProcAddress(huxtheme, "BufferedPaintSetAlpha");
4447 _DrawThemeTextEx = (HRESULT (WINAPI *)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const DTTOPTS *))GetProcAddress(huxtheme, "DrawThemeTextEx"); 4561 _DrawThemeTextEx = (HRESULT (WINAPI *)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const DTTOPTS *))GetProcAddress(huxtheme, "DrawThemeTextEx");
4448 _EndBufferedPaint = (HRESULT (WINAPI *)(HPAINTBUFFER, BOOL))GetProcAddress(huxtheme, "EndBufferedPaint"); 4562 _EndBufferedPaint = (HRESULT (WINAPI *)(HPAINTBUFFER, BOOL))GetProcAddress(huxtheme, "EndBufferedPaint");
4449 _CloseThemeData = (HRESULT (WINAPI *)(HTHEME))GetProcAddress(huxtheme, "CloseThemeData"); 4563 _CloseThemeData = (HRESULT (WINAPI *)(HTHEME))GetProcAddress(huxtheme, "CloseThemeData");
6123 6237
6124 SetMenuInfo( (HMENU)tmp, &mi ); 6238 SetMenuInfo( (HMENU)tmp, &mi );
6125 6239
6126 dw_window_set_data(location, "_dw_menu", (void *)tmp); 6240 dw_window_set_data(location, "_dw_menu", (void *)tmp);
6127 6241
6242 #ifdef DARK_MODE_TITLEBAR_MENU
6243 if(!(_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED))
6244 #endif
6128 SetMenu(location, (HMENU)tmp); 6245 SetMenu(location, (HMENU)tmp);
6129 return location; 6246 return location;
6130 } 6247 }
6131 6248
6132 /* 6249 /*