void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col) { m_canvas->SetTextFont(font); if ( col.IsOk() ) m_canvas->SetColour(col); m_canvas->Refresh(); m_textctrl->SetFont(font); if ( col.IsOk() ) m_textctrl->SetForegroundColour(col); m_textctrl->Refresh(); // update the state of the bold/italic/underlined menu items wxMenuBar *mbar = GetMenuBar(); if ( mbar ) { mbar->Check(Font_Light, font.GetWeight() == wxFONTWEIGHT_LIGHT); mbar->Check(Font_Bold, font.GetWeight() == wxFONTWEIGHT_BOLD); mbar->Check(Font_Italic, font.GetStyle() == wxFONTSTYLE_ITALIC); #ifndef __WXMSW__ mbar->Check(Font_Slant, font.GetStyle() == wxFONTSTYLE_SLANT); #endif mbar->Check(Font_Underlined, font.GetUnderlined()); mbar->Check(Font_Strikethrough, font.GetStrikethrough()); } }
WXHBRUSH wxControl::DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) { HDC hdc = (HDC)pDC; WXHBRUSH hbr = 0; if ( !colBg.IsOk() ) { if ( wxWindow *win = wxFindWinFromHandle(hWnd) ) hbr = win->MSWGetBgBrush(pDC); // if the control doesn't have any bg colour, foreground colour will be // ignored as the return value would be 0 -- so forcefully give it a // non default background brush in this case if ( !hbr && m_hasFgCol ) colBg = GetBackgroundColour(); } // use the background colour override if a valid colour is given: this is // used when the control is disabled to grey it out and also if colBg was // set just above if ( colBg.IsOk() ) { wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBg); hbr = (WXHBRUSH)brush->GetResourceHandle(); } // always set the foreground colour if we changed the background, whether // m_hasFgCol is true or not: if it true, we must do it, of course, but // even if it isn't, we must set the default foreground explicitly as by // default just the simple black is used if ( hbr ) { ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); } // finally also set the background colour for text drawing: without this, // the text in an edit control is drawn using the default background even // if we return a valid brush if ( colBg.IsOk() || m_hasBgCol ) { if ( !colBg.IsOk() ) colBg = GetBackgroundColour(); ::SetBkColor(hdc, wxColourToRGB(colBg)); } return hbr; }
void wxMenu::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; if (!col.IsOk()) return; if (m_menuWidget) wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col); if (m_buttonWidget) wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { wxMenuItem* item = node->GetData(); if (item->GetButtonWidget()) { // This crashes because it uses gadgets // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col); } if (item->GetSubMenu()) item->GetSubMenu()->SetForegroundColour((wxColour&) col); } }
// Call ParseInner() preserving background colour and mode after any // changes done by it. void CallParseInnerWithBg(const wxHtmlTag& tag, const wxColour& colBg) { const wxColour oldbackclr = m_WParser->GetActualBackgroundColor(); const int oldbackmode = m_WParser->GetActualBackgroundMode(); if ( colBg.IsOk() ) { m_WParser->SetActualBackgroundColor(colBg); m_WParser->SetActualBackgroundMode(wxBRUSHSTYLE_SOLID); m_WParser->GetContainer()->InsertCell( new wxHtmlColourCell(colBg, wxHTML_CLR_BACKGROUND) ); } ParseInner(tag); if ( oldbackmode != m_WParser->GetActualBackgroundMode() || oldbackclr != m_WParser->GetActualBackgroundColor() ) { m_WParser->SetActualBackgroundMode(oldbackmode); m_WParser->SetActualBackgroundColor(oldbackclr); m_WParser->GetContainer()->InsertCell( new wxHtmlColourCell(oldbackclr, oldbackmode == wxBRUSHSTYLE_TRANSPARENT ? wxHTML_CLR_TRANSPARENT_BACKGROUND : wxHTML_CLR_BACKGROUND) ); } }
bool wxVListBox::DoDrawSolidBackground(const wxColour& col, wxDC& dc, const wxRect& rect, size_t n) const { if ( !col.IsOk() ) return false; // we need to render selected and current items differently const bool isSelected = IsSelected(n), isCurrent = IsCurrent(n); if ( isSelected || isCurrent ) { if ( isSelected ) { dc.SetBrush(wxBrush(col, wxBRUSHSTYLE_SOLID)); } else // !selected { dc.SetBrush(*wxTRANSPARENT_BRUSH); } dc.SetPen(*(isCurrent ? wxBLACK_PEN : wxTRANSPARENT_PEN)); dc.DrawRectangle(rect); } //else: do nothing for the normal items return true; }
wxColour FRLayoutConfig::getReadonlyColour() { static wxColour colourReadOnly; if (!colourReadOnly.IsOk()) { // first try to compute a colour that is between "white" and "gray" // (but use the actual system colours instead of hard-coded values) wxColour clWnd(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); int r1 = clWnd.Red(), g1 = clWnd.Green(), b1 = clWnd.Blue(); wxColour clBtn = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); int r2 = clBtn.Red(), g2 = clBtn.Green(), b2 = clBtn.Blue(); int distance = abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2); if (distance >= 72) { // start at 50 %, and use progressively lighter colours for larger // distances between white and gray int scale = (distance >= 192) ? distance / 64 : 2; colourReadOnly.Set(r1 + (r2 - r1) / scale, g1 + (g2 - g1) / scale, b1 + (b2 - b1) / scale); } else { // wxSYS_COLOUR_WINDOW and wxSYS_COLOUR_BTNFACE are too similar // compute a darker shade of wxSYS_COLOUR_WINDOW RgbHsvConversion rgbhsv(clWnd); rgbhsv.setValue(std::max(0.0, rgbhsv.getValue() - 0.05)); colourReadOnly = rgbhsv.getColour(); } } return colourReadOnly; }
void wxMSWOwnerDrawnButtonBase::MSWMakeOwnerDrawnIfNecessary(const wxColour& colFg) { // The only way to change the checkbox foreground colour when using // themes is to owner draw it. if ( wxUxThemeEngine::GetIfActive() ) MSWMakeOwnerDrawn(colFg.IsOk()); }
RgbHsvConversion::RgbHsvConversion(const wxColour& colour) { redM = colour.Red() / 255.0; greenM = colour.Green() / 255.0; blueM = colour.Blue() / 255.0; rgbValidM = colour.IsOk(); hueM = 0.0; satM = 0.0; valM = 0.0; hsvValidM = false; }
bool wxCheckBox::SetForegroundColour(const wxColour& colour) { if ( !wxCheckBoxBase::SetForegroundColour(colour) ) return false; // the only way to change the checkbox foreground colour under Windows XP // is to owner draw it if ( wxUxThemeEngine::GetIfActive() ) MSWMakeOwnerDrawn(colour.IsOk()); return true; }
wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit, const wxString& caption, wxColourData *ptrData) { // contains serialized representation of wxColourData used the last time // the dialog was shown: we want to reuse it the next time in order to show // the same custom colours to the user (and we can't just have static // wxColourData itself because it's a GUI object and so should be destroyed // before GUI shutdown and doing it during static cleanup is too late) static wxString s_strColourData; wxColourData data; if ( !ptrData ) { ptrData = &data; if ( !s_strColourData.empty() ) { if ( !data.FromString(s_strColourData) ) { wxFAIL_MSG( "bug in wxColourData::FromString()?" ); } #ifdef __WXMSW__ // we don't get back the "choose full" flag value from the native // dialog and so we can't preserve it between runs, so we decide to // always use it as it seems better than not using it (user can // just ignore the extra controls in the dialog but having to click // a button each time to show them would be very annoying data.SetChooseFull(true); #endif // __WXMSW__ } } if ( colInit.IsOk() ) { ptrData->SetColour(colInit); } wxColour colRet; wxColourDialog dialog(parent, ptrData); if (!caption.empty()) dialog.SetTitle(caption); if ( dialog.ShowModal() == wxID_OK ) { *ptrData = dialog.GetColourData(); colRet = ptrData->GetColour(); s_strColourData = ptrData->ToString(); } //else: leave colRet invalid return colRet; }
void wxGCDCImpl::SetTextForeground( const wxColour &col ) { wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") ); // don't set m_textForegroundColour to an invalid colour as we'd crash // later then (we use m_textForegroundColour.GetColor() without checking // in a few places) if ( col.IsOk() ) { m_textForegroundColour = col; m_graphicContext->SetFont( m_font, m_textForegroundColour ); } }
virtual void DrawTab(wxDC &dc, wxWindow *wnd, const wxAuiNotebookPage &page, const wxRect &rect, int close_button_state, wxRect *out_tab_rect, wxRect *out_button_rect, int *x_extent) { wxColour const tint = m_pNotebook->GetTabColour(page.window); if (tint.IsOk()) { #if !defined(__WXGTK__) || !defined(wxHAS_NATIVE_TABART) wxColour const baseOrig = m_baseColour; wxColour const activeOrig = m_activeColour; wxColour const base( wxColour::AlphaBlend(tint.Red(), baseOrig.Red(), tint.Alpha() / 255.0f), wxColour::AlphaBlend(tint.Green(), baseOrig.Green(), tint.Alpha() / 255.0f), wxColour::AlphaBlend(tint.Blue(), baseOrig.Blue(), tint.Alpha() / 255.0f)); wxColour const active( wxColour::AlphaBlend(tint.Red(), activeOrig.Red(), tint.Alpha() / 255.0f), wxColour::AlphaBlend(tint.Green(), activeOrig.Green(), tint.Alpha() / 255.0f), wxColour::AlphaBlend(tint.Blue(), activeOrig.Blue(), tint.Alpha() / 255.0f)); m_baseColour = base; m_activeColour = active; wxAuiDefaultTabArt::DrawTab(dc, wnd, page, rect, close_button_state, out_tab_rect, out_button_rect, x_extent); m_baseColour = baseOrig; m_activeColour = baseOrig; #else wxRect tab_rect; if (!out_tab_rect) { out_tab_rect = &tab_rect; } wxAuiDefaultTabArt::DrawTab(dc, wnd, page, rect, close_button_state, out_tab_rect, out_button_rect, x_extent); wxMemoryDC *mdc = dynamic_cast<wxMemoryDC*>(&dc); if (mdc) { wxGraphicsContext *gc = wxGraphicsContext::Create(*mdc); if (gc) { gc->SetBrush(wxBrush(tint)); gc->DrawRectangle(out_tab_rect->x, out_tab_rect->y, out_tab_rect->width, out_tab_rect->height); delete gc; } } #endif } else { wxAuiDefaultTabArt::DrawTab(dc, wnd, page, rect, close_button_state, out_tab_rect, out_button_rect, x_extent); } }
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); } }
bool wxMenuBar::SetForegroundColour(const wxColour& col) { if (!wxWindowBase::SetForegroundColour(col)) return false; if (!col.IsOk()) return false; if (m_mainWidget) wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col); return true; }
/***************************************************** ** ** DcPainter --- setPenColor ** ******************************************************/ void DcPainter::setPenColor( const wxColour &c ) { if ( ! c.IsOk() ) { wxLogError( wxT( "pen color not okay, using default pen" )); setDefaultPen(); } else { wxPen currentPen = dc->GetPen(); if ( currentPen.IsOk() ) { dc->SetPen( wxPen( c, currentPen.GetWidth(), currentPen.GetStyle() )); } else dc->SetPen( wxPen( c, 1, wxSOLID )); } }
wxObject * MaxBannerWindowXmlHandler::DoCreateResource() { XRC_MAKE_INSTANCE(banner, MaxBannerWindow) banner->Create(m_parentAsWindow, GetID(), GetDirection(wxS("direction")), GetPosition(), GetSize(), GetStyle(wxS("style")), GetName()); banner->MaxBind(CB_PREF(wx_wxbannerwindow_wxBannerWindow__xrcNew)(banner)); SetupWindow(banner); const wxColour colStart = GetColour(wxS("gradient-start")); const wxColour colEnd = GetColour(wxS("gradient-end")); if ( colStart.IsOk() || colEnd.IsOk() ) { if ( !colStart.IsOk() || !colEnd.IsOk() ) { ReportError ( "Both start and end gradient colours must be " "specified if either one is." ); } else { banner->SetGradient(colStart, colEnd); } } wxBitmap bitmap = GetBitmap(); if ( bitmap.IsOk() ) { if ( colStart.IsOk() || colEnd.IsOk() ) { ReportError ( "Gradient colours are ignored by wxBannerWindow " "if the background bitmap is specified." ); } banner->SetBitmap(bitmap); } banner->SetText(GetText(wxS("title")), GetText(wxS("message"))); return banner; }
// Change a widget's foreground and background colours. void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) { if (!foregroundColour.IsOk()) return; // When should we specify the foreground, if it's calculated // by wxComputeColours? // Solution: say we start with the default (computed) foreground colour. // If we call SetForegroundColour explicitly for a control or window, // then the foreground is changed. // Therefore SetBackgroundColour computes the foreground colour, and // SetForegroundColour changes the foreground colour. The ordering is // important. XtVaSetValues ((Widget) widget, XmNforeground, foregroundColour.AllocColour(XtDisplay((Widget) widget)), NULL); }
void wxDoChangeBackgroundColour(WXWidget widget, const wxColour& backgroundColour, bool changeArmColour) { if (!backgroundColour.IsOk()) return; wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, NULL); XtVaSetValues ((Widget) widget, XmNbackground, g_itemColors[wxBACK_INDEX].pixel, XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel, XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel, XmNforeground, g_itemColors[wxFORE_INDEX].pixel, NULL); if (changeArmColour) XtVaSetValues ((Widget) widget, XmNarmColor, g_itemColors[wxSELE_INDEX].pixel, NULL); }
void wxMenu::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; if (!col.IsOk()) return; if (m_menuWidget) wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col); if (m_buttonWidget) wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col); for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { wxMenuItem* item = node->GetData(); if (item->GetButtonWidget()) { // This crashes because it uses gadgets // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col); } if (item->GetSubMenu()) item->GetSubMenu()->SetForegroundColour((wxColour&) col); } }
bool wxMenuBar::SetForegroundColour(const wxColour& col) { if (!wxWindowBase::SetForegroundColour(col)) return false; if (!col.IsOk()) return false; if (m_mainWidget) wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col); size_t menuCount = GetMenuCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (size_t i = 0; i < menuCount; i++) m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col); return true; }
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); } }
WXHBRUSH wxControl::DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) { HDC hdc = (HDC)pDC; WXHBRUSH hbr = 0; if ( !colBg.IsOk() ) { wxWindow *win = wxFindWinFromHandle( hWnd ); if ( !win ) { // If this HWND doesn't correspond to a wxWindow, it still might be // one of its children for which we need to set the background // brush, e.g. this is the case for the EDIT control that is part // of wxComboBox. Check for this by asking the parent if it has it: HWND parent = ::GetParent(hWnd); if ( parent ) { wxWindow *winParent = wxFindWinFromHandle( parent ); if( winParent && winParent->ContainsHWND( hWnd ) ) win = winParent; } } if ( win ) hbr = win->MSWGetBgBrush(pDC); // if the control doesn't have any bg colour, foreground colour will be // ignored as the return value would be 0 -- so forcefully give it a // non default background brush in this case if ( !hbr && m_hasFgCol ) colBg = GetBackgroundColour(); } // use the background colour override if a valid colour is given: this is // used when the control is disabled to grey it out and also if colBg was // set just above if ( colBg.IsOk() ) { wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBg); hbr = (WXHBRUSH)brush->GetResourceHandle(); } // always set the foreground colour if we changed the background, whether // m_hasFgCol is true or not: if it true, we must do it, of course, but // even if it isn't, we must set the default foreground explicitly as by // default just the simple black is used if ( hbr ) { ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); } // finally also set the background colour for text drawing: without this, // the text in an edit control is drawn using the default background even // if we return a valid brush if ( colBg.IsOk() || m_hasBgCol ) { if ( !colBg.IsOk() ) colBg = GetBackgroundColour(); ::SetBkColor(hdc, wxColourToRGB(colBg)); } return hbr; }