// Uses the theme to draw the border and fill for something like a wxTextCtrl void wxRendererXP::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) { wxUxThemeHandle hTheme(win, L"EDIT"); if ( !hTheme ) { m_rendererNative.DrawTextCtrl(win,dc,rect,flags); return; } wxColour fill; wxColour bdr; COLORREF cref; wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, ETS_NORMAL, TMT_FILLCOLOR, &cref); fill = wxRGBToColour(cref); int etsState; if ( flags & wxCONTROL_DISABLED ) etsState = ETS_DISABLED; else etsState = ETS_NORMAL; wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, etsState, TMT_BORDERCOLOR, &cref); bdr = wxRGBToColour(cref); dc.SetPen( bdr ); dc.SetBrush( fill ); dc.DrawRectangle(rect); }
// Uses the theme to draw the border and fill for something like a wxTextCtrl void wxRendererMSW::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) { wxColour fill; wxColour bdr; COLORREF cref; #if wxUSE_UXTHEME wxUxThemeHandle hTheme(win, L"EDIT"); if (hTheme) { wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, ETS_NORMAL, TMT_FILLCOLOR, &cref); fill = wxRGBToColour(cref); int etsState; if ( flags & wxCONTROL_DISABLED ) etsState = ETS_DISABLED; else etsState = ETS_NORMAL; wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, etsState, TMT_BORDERCOLOR, &cref); bdr = wxRGBToColour(cref); } else #endif { fill = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); bdr = *wxBLACK; } dc.SetPen( bdr ); dc.SetBrush( fill ); dc.DrawRectangle(rect); }
int wxColourDialog::ShowModal() { // initialize the struct used by Windows CHOOSECOLOR chooseColorStruct; memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR)); size_t i; // and transfer data from m_colourData to it COLORREF custColours[16]; for ( i = 0; i < WXSIZEOF(custColours); i++ ) { if ( m_colourData.GetCustomColour(i).IsOk() ) custColours[i] = wxColourToRGB(m_colourData.GetCustomColour(i)); else custColours[i] = RGB(255,255,255); } chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR); if ( m_parent ) chooseColorStruct.hwndOwner = GetHwndOf(m_parent); chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.GetColour()); chooseColorStruct.lpCustColors = custColours; chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK; chooseColorStruct.lCustData = (LPARAM)this; chooseColorStruct.lpfnHook = wxColourDialogHookProc; if ( m_colourData.GetChooseFull() ) chooseColorStruct.Flags |= CC_FULLOPEN; // do show the modal dialog if ( !::ChooseColor(&chooseColorStruct) ) { // 0 error means the dialog was simply cancelled, i.e. no real error // occurred const DWORD err = CommDlgExtendedError(); if ( err ) wxLogError(_("Colour selection dialog failed with error %0lx."), err); return wxID_CANCEL; } // transfer the values chosen by user back into m_colourData for ( i = 0; i < WXSIZEOF(custColours); i++ ) { wxRGBToColour(m_colourData.m_custColours[i], custColours[i]); } wxRGBToColour(m_colourData.GetColour(), chooseColorStruct.rgbResult); // this doesn't seem to work (contrary to what MSDN implies) on current // Windows versions: CC_FULLOPEN is never set on return if it wasn't // initially set and vice versa //m_colourData.SetChooseFull((chooseColorStruct.Flags & CC_FULLOPEN) != 0); return wxID_OK; }
int wxColourDialog::ShowModal() { CHOOSECOLOR chooseColorStruct; COLORREF custColours[16]; memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR)); int i; for (i = 0; i < 16; i++) { if (m_colourData.m_custColours[i].Ok()) custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]); else custColours[i] = RGB(255,255,255); } chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR); if ( m_parent ) chooseColorStruct.hwndOwner = GetHwndOf(m_parent); chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.m_dataColour); chooseColorStruct.lpCustColors = custColours; chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK; chooseColorStruct.lCustData = (LPARAM)this; chooseColorStruct.lpfnHook = wxColourDialogHookProc; if (m_colourData.GetChooseFull()) chooseColorStruct.Flags |= CC_FULLOPEN; // Do the modal dialog bool success = ::ChooseColor(&(chooseColorStruct)) != 0; // Try to highlight the correct window (the parent) if (GetParent()) { HWND hWndParent = (HWND) GetParent()->GetHWND(); if (hWndParent) ::BringWindowToTop(hWndParent); } // Restore values for (i = 0; i < 16; i++) { wxRGBToColour(m_colourData.m_custColours[i], custColours[i]); } wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult); return success ? wxID_OK : wxID_CANCEL; }
void wxComboCtrl::OnThemeChange() { // there doesn't seem to be any way to get the text colour using themes // API: TMT_TEXTCOLOR doesn't work neither for EDIT nor COMBOBOX SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); #if wxUSE_UXTHEME wxUxThemeEngine * const theme = wxUxThemeEngine::GetIfActive(); if ( theme ) { // NB: use EDIT, not COMBOBOX (the latter works in XP but not Vista) wxUxThemeHandle hTheme(this, L"EDIT"); COLORREF col; HRESULT hr = theme->GetThemeColor ( hTheme, EP_EDITTEXT, ETS_NORMAL, TMT_FILLCOLOR, &col ); if ( SUCCEEDED(hr) ) { SetBackgroundColour(wxRGBToColour(col)); // skip the call below return; } wxLogApiError(_T("GetThemeColor(EDIT, ETS_NORMAL, TMT_FILLCOLOR)"), hr); } #endif SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); }
WXMainToolbar(wxFrame *parent) { m_tb = wxXmlResource::Get()->LoadToolBar(parent, "toolbar"); m_idUpdate = XRCID("toolbar_update"); #ifdef __WXGTK3__ gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(Toolbar())), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); SetIcon(0 , "document-open-symbolic"); SetIcon(1 , "document-save-symbolic"); SetIcon(3 , "poedit-validate-symbolic"); SetIcon(4 , "poedit-update-symbolic"); SetIcon(6 , "sidebar-symbolic"); #endif #ifdef __WXMSW__ // De-uglify the toolbar a bit on Windows 10: if (IsWindows10OrGreater()) { if (wxUxThemeIsActive()) { wxUxThemeHandle hTheme(m_tb, L"ExplorerMenu::Toolbar"); m_tb->SetBackgroundColour(wxRGBToColour(::GetThemeSysColor(hTheme, COLOR_WINDOW))); } unsigned padding = PX(4); ::SendMessage((HWND) m_tb->GetHWND(), TB_SETPADDING, 0, MAKELPARAM(padding, padding)); } m_tb->SetDoubleBuffered(true); #endif }
ManagerFrame::ManagerFrame() : wxFrame(NULL, -1, _("Poedit - Catalogs manager"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE, "manager") { #if defined(__WXGTK__) wxIconBundle appicons; appicons.AddIcon(wxArtProvider::GetIcon("poedit", wxART_FRAME_ICON, wxSize(16,16))); appicons.AddIcon(wxArtProvider::GetIcon("poedit", wxART_FRAME_ICON, wxSize(32,32))); appicons.AddIcon(wxArtProvider::GetIcon("poedit", wxART_FRAME_ICON, wxSize(48,48))); SetIcons(appicons); #elif defined(__WXMSW__) SetIcons(wxIconBundle(wxStandardPaths::Get().GetResourcesDir() + "\\Resources\\Poedit.ico")); #endif ms_instance = this; auto tb = wxXmlResource::Get()->LoadToolBar(this, "manager_toolbar"); (void)tb; #ifdef __WXMSW__ // De-uglify the toolbar a bit on Windows 10: if (IsWindows10OrGreater()) { const wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); if (theme) { wxUxThemeHandle hTheme(tb, L"ExplorerMenu::Toolbar"); tb->SetBackgroundColour(wxRGBToColour(theme->GetThemeSysColor(hTheme, COLOR_WINDOW))); } } #endif wxPanel *panel = wxXmlResource::Get()->LoadPanel(this, "manager_panel"); m_listPrj = XRCCTRL(*panel, "prj_list", wxListBox); m_listCat = XRCCTRL(*panel, "prj_files", wxListCtrl); m_splitter = XRCCTRL(*panel, "manager_splitter", wxSplitterWindow); wxImageList *list = new wxImageList(PX(16), PX(16)); list->Add(wxArtProvider::GetBitmap("poedit-status-cat-no")); list->Add(wxArtProvider::GetBitmap("poedit-status-cat-mid")); list->Add(wxArtProvider::GetBitmap("poedit-status-cat-ok")); m_listCat->AssignImageList(list, wxIMAGE_LIST_SMALL); m_curPrj = -1; int last = (int)wxConfig::Get()->Read("manager_last_selected", (long)0); // FIXME: do this in background (here and elsewhere) UpdateListPrj(last); if (m_listPrj->GetCount() > 0) UpdateListCat(last); RestoreWindowState(this, wxSize(PX(400), PX(300))); m_splitter->SetSashPosition((int)wxConfig::Get()->Read("manager_splitter", PX(200))); }
void wxMenuItem::GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const { #if wxUSE_UXTHEME wxUxThemeEngine* theme = MenuDrawData::GetUxThemeEngine(); if ( theme ) { wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU"); if ( stat & wxODDisabled) { wxRGBToColour(colText, theme->GetThemeSysColor(hTheme, COLOR_GRAYTEXT)); } else { colText = GetTextColour(); if ( !colText.IsOk() ) wxRGBToColour(colText, theme->GetThemeSysColor(hTheme, COLOR_MENUTEXT)); } if ( stat & wxODSelected ) { wxRGBToColour(colBack, theme->GetThemeSysColor(hTheme, COLOR_HIGHLIGHT)); } else { colBack = GetBackgroundColour(); if ( !colBack.IsOk() ) wxRGBToColour(colBack, theme->GetThemeSysColor(hTheme, COLOR_MENU)); } } else #endif // wxUSE_UXTHEME { wxOwnerDrawn::GetColourToUse(stat, colText, colBack); } }
wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) { if ( index == wxSYS_COLOUR_LISTBOXTEXT) { // there is no standard colour with this index, map to another one index = wxSYS_COLOUR_WINDOWTEXT; } else if ( index == wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT) { // there is no standard colour with this index, map to another one index = wxSYS_COLOUR_HIGHLIGHTTEXT; } else if ( index == wxSYS_COLOUR_LISTBOX ) { // there is no standard colour with this index, map to another one index = wxSYS_COLOUR_WINDOW; } else if ( index > wxSYS_COLOUR_BTNHIGHLIGHT ) { // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR if ( index == wxSYS_COLOUR_MENUBAR ) { BOOL isFlat ; if ( SystemParametersInfo( SPI_GETFLATMENU , 0 ,&isFlat, 0 ) ) { if ( !isFlat ) index = wxSYS_COLOUR_MENU ; } } } COLORREF colSys = ::GetSysColor(index); wxColour ret = wxRGBToColour(colSys); wxASSERT(ret.IsOk()); return ret; }
static HBITMAP GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask) { #if wxUSE_IMAGE wxBitmap bitmapWithMask; #endif // wxUSE_IMAGE HBITMAP hbmpMask; wxMask *pMask; bool deleteMask = false; if ( mask.IsOk() ) { hbmpMask = GetHbitmapOf(mask); pMask = NULL; } else { pMask = bitmap.GetMask(); #if wxUSE_IMAGE // check if we don't have alpha in this bitmap -- we can create a mask // from it (and we need to do it for the older systems which don't // support 32bpp bitmaps natively) if ( !pMask ) { wxImage img(bitmap.ConvertToImage()); if ( img.HasAlpha() ) { img.ConvertAlphaToMask(); bitmapWithMask = wxBitmap(img); pMask = bitmapWithMask.GetMask(); } } #endif // wxUSE_IMAGE if ( !pMask ) { // use the light grey count as transparent: the trouble here is // that the light grey might have been changed by Windows behind // our back, so use the standard colour map to get its real value wxCOLORMAP *cmap = wxGetStdColourMap(); wxColour col; wxRGBToColour(col, cmap[wxSTD_COL_BTNFACE].from); pMask = new wxMask(bitmap, col); deleteMask = true; } hbmpMask = (HBITMAP)pMask->GetMaskBitmap(); } // windows mask convention is opposite to the wxWidgets one HBITMAP hbmpMaskInv = wxInvertMask(hbmpMask); if ( deleteMask ) { delete pMask; } return hbmpMaskInv; }
int wxFontDialog::ShowModal() { // It should be OK to always use GDI simulations DWORD flags = CF_SCREENFONTS /* | CF_NOSIMULATIONS */ ; LOGFONT logFont; CHOOSEFONT chooseFontStruct; wxZeroMemory(chooseFontStruct); chooseFontStruct.lStructSize = sizeof(CHOOSEFONT); if ( m_parent ) chooseFontStruct.hwndOwner = GetHwndOf(m_parent); chooseFontStruct.lpLogFont = &logFont; if ( m_fontData.m_initialFont.IsOk() ) { flags |= CF_INITTOLOGFONTSTRUCT; wxFillLogFont(&logFont, &m_fontData.m_initialFont); } if ( m_fontData.m_fontColour.IsOk() ) { chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.m_fontColour); } // CF_ANSIONLY flag is obsolete for Win32 if ( !m_fontData.GetAllowSymbols() ) { flags |= CF_SELECTSCRIPT; logFont.lfCharSet = ANSI_CHARSET; } if ( m_fontData.GetEnableEffects() ) flags |= CF_EFFECTS; if ( m_fontData.GetShowHelp() ) flags |= CF_SHOWHELP; if ( m_fontData.m_minSize != 0 || m_fontData.m_maxSize != 0 ) { chooseFontStruct.nSizeMin = m_fontData.m_minSize; chooseFontStruct.nSizeMax = m_fontData.m_maxSize; flags |= CF_LIMITSIZE; } chooseFontStruct.Flags = flags; if ( ChooseFont(&chooseFontStruct) != 0 ) { wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors); m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont); m_fontData.EncodingInfo().facename = logFont.lfFaceName; m_fontData.EncodingInfo().charset = logFont.lfCharSet; return wxID_OK; } else { DWORD dwErr = CommDlgExtendedError(); if ( dwErr != 0 ) { wxLogError(_("Common dialog failed with error code %0lx."), dwErr); } //else: it was just cancelled return wxID_CANCEL; } }
// Windows only: attempts to get colour for UX theme page background wxColour wxNotebook::GetThemeBackgroundColour() const { #if wxUSE_UXTHEME if (wxUxThemeEngine::Get()) { wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB"); if (hTheme) { // This is total guesswork. // See PlatformSDK\Include\Tmschema.h for values. // JACS: can also use 9 (TABP_PANE) COLORREF themeColor; bool success = (S_OK == wxUxThemeEngine::Get()->GetThemeColor( hTheme, 10 /* TABP_BODY */, 1 /* NORMAL */, 3821 /* FILLCOLORHINT */, &themeColor)); if (!success) return GetBackgroundColour(); /* [DS] Workaround for WindowBlinds: Some themes return a near black theme color using FILLCOLORHINT, this makes notebook pages have an ugly black background and makes text (usually black) unreadable. Retry again with FILLCOLOR. This workaround potentially breaks appearance of some themes, but in practice it already fixes some themes. */ if (themeColor == 1) { wxUxThemeEngine::Get()->GetThemeColor( hTheme, 10 /* TABP_BODY */, 1 /* NORMAL */, 3802 /* FILLCOLOR */, &themeColor); } wxColour colour = wxRGBToColour(themeColor); // Under Vista, the tab background colour is reported incorrectly. // So for the default theme at least, hard-code the colour to something // that will blend in. static int s_AeroStatus = -1; if (s_AeroStatus == -1) { WCHAR szwThemeFile[1024]; WCHAR szwThemeColor[256]; if (S_OK == wxUxThemeEngine::Get()->GetCurrentThemeName(szwThemeFile, 1024, szwThemeColor, 256, NULL, 0)) { wxString themeFile(szwThemeFile), themeColor(szwThemeColor); if (themeFile.Find(wxT("Aero")) != -1 && themeColor == wxT("NormalColor")) s_AeroStatus = 1; else s_AeroStatus = 0; } else s_AeroStatus = 0; } if (s_AeroStatus == 1) colour = wxColour(255, 255, 255); return colour; } } #endif // wxUSE_UXTHEME return GetBackgroundColour(); }
wxRichToolTipPopup(wxWindow* parent, const wxString& title, const wxString& message, const wxIcon& icon, wxTipKind tipKind, const wxFont& titleFont_) : m_timer(this) { Create(parent, wxFRAME_SHAPED); wxBoxSizer* const sizerTitle = new wxBoxSizer(wxHORIZONTAL); if ( icon.IsOk() ) { sizerTitle->Add(new wxStaticBitmap(this, wxID_ANY, icon), wxSizerFlags().Centre().Border(wxRIGHT)); } //else: Simply don't show any icon. wxStaticText* const labelTitle = new wxStaticText(this, wxID_ANY, ""); labelTitle->SetLabelText(title); wxFont titleFont(titleFont_); if ( !titleFont.IsOk() ) { // Determine the appropriate title font for the current platform. titleFont = labelTitle->GetFont(); #ifdef __WXMSW__ // When using themes MSW tooltips use larger bluish version of the // normal font. wxUxThemeEngine* const theme = GetTooltipTheme(); if ( theme ) { titleFont.MakeLarger(); COLORREF c; if ( FAILED(theme->GetThemeColor ( wxUxThemeHandle(parent, L"TOOLTIP"), TTP_BALLOONTITLE, 0, TMT_TEXTCOLOR, &c )) ) { // Use the standard value of this colour as fallback. c = 0x993300; } labelTitle->SetForegroundColour(wxRGBToColour(c)); } else #endif // __WXMSW__ { // Everything else, including "classic" MSW look uses just the // bold version of the base font. titleFont.MakeBold(); } } labelTitle->SetFont(titleFont); sizerTitle->Add(labelTitle, wxSizerFlags().Centre()); wxBoxSizer* const sizerTop = new wxBoxSizer(wxVERTICAL); sizerTop->Add(sizerTitle, wxSizerFlags().DoubleBorder(wxLEFT|wxRIGHT|wxTOP)); // Use a spacer as we don't want to have a double border between the // elements, just a simple one will do. sizerTop->AddSpacer(wxSizerFlags::GetDefaultBorder()); wxTextSizerWrapper wrapper(this); wxSizer* sizerText = wrapper.CreateSizer(message, -1 /* No wrapping */); #ifdef __WXMSW__ if ( icon.IsOk() && GetTooltipTheme() ) { // Themed tooltips under MSW align the text with the title, not // with the icon, so use a helper horizontal sizer in this case. wxBoxSizer* const sizerTextIndent = new wxBoxSizer(wxHORIZONTAL); sizerTextIndent->AddSpacer(icon.GetWidth()); sizerTextIndent->Add(sizerText, wxSizerFlags().Border(wxLEFT).Centre()); sizerText = sizerTextIndent; } #endif // !__WXMSW__ sizerTop->Add(sizerText, wxSizerFlags().DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM) .Centre()); SetSizer(sizerTop); const int offsetY = SetTipShapeAndSize(tipKind, GetBestSize()); if ( offsetY > 0 ) { // Offset our contents by the tip height to make it appear in the // main rectangle. sizerTop->PrependSpacer(offsetY); } Layout(); }
void SetBackgroundColours(wxColour colStart, wxColour colEnd) { if ( !colStart.IsOk() ) { // Determine the best colour(s) to use on our own. #ifdef __WXMSW__ wxUxThemeEngine* const theme = GetTooltipTheme(); if ( theme ) { wxUxThemeHandle hTheme(GetParent(), L"TOOLTIP"); COLORREF c1, c2; if ( FAILED(theme->GetThemeColor ( hTheme, TTP_BALLOONTITLE, 0, TMT_GRADIENTCOLOR1, &c1 )) || FAILED(theme->GetThemeColor ( hTheme, TTP_BALLOONTITLE, 0, TMT_GRADIENTCOLOR2, &c2 )) ) { c1 = 0xffffff; c2 = 0xf0e5e4; } colStart = wxRGBToColour(c1); colEnd = wxRGBToColour(c2); } else #endif // __WXMSW__ { colStart = wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK); } } if ( colEnd.IsOk() ) { // Use gradient-filled background bitmap. const wxSize size = GetClientSize(); wxBitmap bmp(size); { wxMemoryDC dc(bmp); dc.Clear(); dc.GradientFillLinear(size, colStart, colEnd, wxDOWN); } SetBackgroundBitmap(bmp); } else // Use solid colour. { SetBackgroundColour(colStart); } }