WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd) { if ( !IsThisEnabled() ) return MSWControlColorDisabled(hDC); return wxChoiceBase::MSWControlColor(hDC, hWnd); }
void Sidebar::RefreshContent() { if (!IsShown()) return; auto item = m_selectedItem; if (!IsThisEnabled()) item = nullptr; wxWindowUpdateLocker lock(this); for (auto& b: m_blocks) b->SetItem(item); Layout(); }
wxAnyButton::State wxAnyButton::GTKGetCurrentState() const { if ( !IsThisEnabled() ) return m_bitmaps[State_Disabled].IsOk() ? State_Disabled : State_Normal; if ( m_isPressed && m_bitmaps[State_Pressed].IsOk() ) return State_Pressed; if ( m_isCurrent && m_bitmaps[State_Current].IsOk() ) return State_Current; if ( HasFocus() && m_bitmaps[State_Focused].IsOk() ) return State_Focused; return State_Normal; }
void wxBitmapButton::OnSetBitmap() { wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") ); InvalidateBestSize(); wxBitmap the_one; if (!IsThisEnabled()) the_one = GetBitmapDisabled(); else if (m_isSelected) the_one = GetBitmapPressed(); else if (HasFocus()) the_one = GetBitmapFocus(); if (!the_one.IsOk()) { the_one = GetBitmapLabel(); if (!the_one.IsOk()) return; } GdkBitmap *mask = NULL; if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap(); GtkWidget *child = BUTTON_CHILD(m_widget); if (child == NULL) { // initial bitmap GtkWidget *pixmap; pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask); gtk_widget_show(pixmap); gtk_container_add(GTK_CONTAINER(m_widget), pixmap); } else { // subsequent bitmaps GtkPixmap *pixmap = GTK_PIXMAP(child); gtk_pixmap_set(pixmap, the_one.GetPixmap(), mask); } }
void wxComboCtrl::OnPaintEvent( wxPaintEvent& WXUNUSED(event) ) { // TODO: Convert drawing in this function to Windows API Code wxSize sz = GetClientSize(); wxDC* dcPtr = wxAutoBufferedPaintDCFactory(this); wxDC& dc = *dcPtr; const wxRect& rectButton = m_btnArea; wxRect rectTextField = m_tcArea; // FIXME: Either SetBackgroundColour or GetBackgroundColour // doesn't work under Vista, so here's a temporary // workaround. // In the theme-less rendering code below, this fixes incorrect // background on read-only comboboxes (they are gray, but should be // white). wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); #if wxUSE_UXTHEME const bool isEnabled = IsThisEnabled(); wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); HDC hDc = GetHdcOf(*impl); HWND hWnd = GetHwndOf(this); wxUxThemeHandle hTheme(this, L"COMBOBOX"); #endif // wxUSE_UXTHEME wxRect borderRect(0,0,sz.x,sz.y); if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE ) { borderRect = m_tcArea; borderRect.Inflate(1); } int drawButFlags = 0; #if wxUSE_UXTHEME if ( hTheme ) { const bool useVistaComboBox = ::wxGetWinVersion() >= wxWinVersion_Vista; RECT rFull; wxCopyRectToRECT(borderRect, rFull); RECT rButton; wxCopyRectToRECT(rectButton, rButton); RECT rBorder; wxCopyRectToRECT(borderRect, rBorder); bool isNonStdButton = (m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE) || (m_iFlags & wxCC_IFLAG_HAS_NONSTANDARD_BUTTON); // // Get some states for themed drawing int butState; if ( !isEnabled ) { butState = CBXS_DISABLED; } // Vista will display the drop-button as depressed always // when the popup window is visilbe else if ( (m_btnState & wxCONTROL_PRESSED) || (useVistaComboBox && !IsPopupWindowState(Hidden)) ) { butState = CBXS_PRESSED; } else if ( m_btnState & wxCONTROL_CURRENT ) { butState = CBXS_HOT; } else { butState = CBXS_NORMAL; } int comboBoxPart = 0; // For XP, use the 'default' part RECT* rUseForBg = &rBorder; bool drawFullButton = false; int bgState = butState; const bool isFocused = (FindFocus() == GetMainWindowOfCompositeControl()) ? true : false; if ( useVistaComboBox ) { // Draw the entire control as a single button? if ( !isNonStdButton ) { if ( HasFlag(wxCB_READONLY) ) drawFullButton = true; } if ( drawFullButton ) { comboBoxPart = CP_READONLY; rUseForBg = &rFull; // It should be safe enough to update this flag here. m_iFlags |= wxCC_FULL_BUTTON; } else { comboBoxPart = CP_BORDER; m_iFlags &= ~wxCC_FULL_BUTTON; if ( isFocused ) bgState = CBB_FOCUSED; else bgState = CBB_NORMAL; } } // // Draw parent's background, if necessary RECT* rUseForTb = NULL; if ( ::IsThemeBackgroundPartiallyTransparent( hTheme, comboBoxPart, bgState ) ) rUseForTb = &rFull; else if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE ) rUseForTb = &rButton; if ( rUseForTb ) ::DrawThemeParentBackground( hWnd, hDc, rUseForTb ); // // Draw the control background (including the border) if ( m_widthCustomBorder > 0 ) { ::DrawThemeBackground( hTheme, hDc, comboBoxPart, bgState, rUseForBg, NULL ); } else { // No border. We can't use theme, since it cannot be relied on // to deliver borderless drawing, even with DrawThemeBackgroundEx. dc.SetBrush(bgCol); dc.SetPen(bgCol); dc.DrawRectangle(borderRect); } // // Draw the drop-button if ( !isNonStdButton ) { drawButFlags = Button_BitmapOnly; int butPart = CP_DROPDOWNBUTTON; if ( useVistaComboBox ) { if ( drawFullButton ) { // We need to alter the button style slightly before // drawing the actual button (but it was good above // when background etc was done). if ( butState == CBXS_HOT || butState == CBXS_PRESSED ) butState = CBXS_NORMAL; } if ( m_btnSide == wxRIGHT ) butPart = CP_DROPDOWNBUTTONRIGHT; else butPart = CP_DROPDOWNBUTTONLEFT; } ::DrawThemeBackground( hTheme, hDc, butPart, butState, &rButton, NULL ); } else if ( useVistaComboBox && (m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE) ) { // We'll do this, because DrawThemeParentBackground // doesn't seem to be reliable on Vista. drawButFlags |= Button_PaintBackground; } } else #endif { // Windows 2000 and earlier drawButFlags = Button_PaintBackground; dc.SetBrush(bgCol); dc.SetPen(bgCol); dc.DrawRectangle(borderRect); } // Button rendering (may only do the bitmap on button, depending on the flags) DrawButton( dc, rectButton, drawButFlags ); // Paint required portion of the custom image on the control if ( (!m_text || m_widthCustomPaint) ) { wxASSERT( m_widthCustomPaint >= 0 ); // this is intentionally here to allow drawed rectangle's // right edge to be hidden if ( m_text ) rectTextField.width = m_widthCustomPaint; dc.SetFont( GetFont() ); dc.SetClippingRegion(rectTextField); if ( m_popupInterface ) m_popupInterface->PaintComboControl(dc,rectTextField); else wxComboPopup::DefaultPaintComboControl(this,dc,rectTextField); } delete dcPtr; }
// draw focus background on area in a way typical on platform void wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const { #if wxUSE_UXTHEME wxUxThemeHandle hTheme(this, L"COMBOBOX"); #endif wxSize sz = GetClientSize(); bool isEnabled; bool doDrawFocusRect; // also selected // For smaller size control (and for disabled background) use less spacing int focusSpacingX; int focusSpacingY; if ( !(flags & wxCONTROL_ISSUBMENU) ) { // Drawing control isEnabled = IsThisEnabled(); doDrawFocusRect = ShouldDrawFocus(); #if wxUSE_UXTHEME // Windows-style: for smaller size control (and for disabled background) use less spacing if ( hTheme ) { // WinXP Theme focusSpacingX = isEnabled ? 2 : 1; focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1; } else #endif { // Classic Theme if ( isEnabled ) { focusSpacingX = 1; focusSpacingY = 1; } else { focusSpacingX = 0; focusSpacingY = 0; } } } else { // Drawing a list item isEnabled = true; // they are never disabled doDrawFocusRect = flags & wxCONTROL_SELECTED ? true : false; focusSpacingX = 0; focusSpacingY = 0; } // Set the background sub-rectangle for selection, disabled etc wxRect selRect(rect); selRect.y += focusSpacingY; selRect.height -= (focusSpacingY*2); int wcp = 0; if ( !(flags & wxCONTROL_ISSUBMENU) ) wcp += m_widthCustomPaint; selRect.x += wcp + focusSpacingX; selRect.width -= wcp + (focusSpacingX*2); wxColour fgCol; wxColour bgCol; bool doDrawDottedEdge = false; bool doDrawSelRect = true; // TODO: doDrawDottedEdge = true when focus has arrived to control via tab. // (and other cases which are not that apparent). if ( isEnabled ) { // If popup is hidden and this control is focused, // then draw the focus-indicator (selbgcolor background etc.). if ( doDrawFocusRect ) { // NB: We can't really use XP visual styles to get TMT_TEXTCOLOR since // it is not properly defined for combo boxes. Instead, they expect // you to use DrawThemeText. // // Here is, however, sample code how to get theme colours: // // COLORREF cref; // theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_NORMAL,TMT_TEXTCOLOR,&cref); // dc.SetTextForeground( wxRGBToColour(cref) ); if ( (m_iFlags & wxCC_FULL_BUTTON) && !(flags & wxCONTROL_ISSUBMENU) ) { // Vista style read-only combo fgCol = GetForegroundColour(); bgCol = GetBackgroundColour(); doDrawSelRect = false; doDrawDottedEdge = true; } else { fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); } } else { fgCol = GetForegroundColour(); bgCol = GetBackgroundColour(); doDrawSelRect = false; } } else { fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); } dc.SetTextForeground(fgCol); dc.SetBrush(bgCol); if ( doDrawSelRect ) { dc.SetPen(bgCol); dc.DrawRectangle(selRect); } if ( doDrawDottedEdge ) wxMSWDrawFocusRect(dc, selRect); // Don't clip exactly to the selection rectangle so we can draw // to the non-selected area in front of it. wxRect clipRect(rect.x,rect.y, (selRect.x+selRect.width)-rect.x-1,rect.height); dc.SetClippingRegion(clipRect); }