KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_bitmap_combobox.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <wx/odcombo.h>
22#include <wx/textctrl.h>
23
24WX_BITMAP_COMBOBOX::WX_BITMAP_COMBOBOX( wxWindow* parent, wxWindowID id, const wxString& value,
25 const wxPoint& pos, const wxSize& size, int n,
26 const wxString choices[], long style,
27 const wxValidator& validator, const wxString& name ) :
28 wxBitmapComboBox( parent, id, value, pos, size, n, choices, style, validator, name )
29{
30}
31
32
33#ifdef __WXMAC__
34void WX_BITMAP_COMBOBOX::DoShowPopup( const wxRect& aRect, int aFlags )
35{
36 wxBitmapComboBox::DoShowPopup( aRect, aFlags );
37 holdPopupMouseCapture();
38}
39
40
41void WX_BITMAP_COMBOBOX::holdPopupMouseCapture()
42{
43 wxComboPopup* popup = GetPopupControl();
44 wxWindow* list = popup ? popup->GetControl() : nullptr;
45 wxWindow* popupWindow = GetPopupWindow();
46
47 if( !list || !popupWindow || popupWindow == m_hookedPopupWindow )
48 return;
49
50 m_hookedPopupWindow = popupWindow;
51
52 // Deliberately not skipped, so that wxPopupTransientWindow's own idle handler never runs
53 popupWindow->Bind( wxEVT_IDLE,
54 [list]( wxIdleEvent& )
55 {
56 // CaptureMouse() asserts on anything already in the capture stack, so
57 // test the stack rather than just the top of it
58 if( list->IsShownOnScreen() && !wxWindow::GetCapture() )
59 list->CaptureMouse();
60 } );
61}
62#endif
63
64
66{
67 wxSize size = wxBitmapComboBox::DoGetBestSize();
68
69#ifdef __WXGTK__
70 wxSize bmpSize = GetBitmapSize();
71
72 if( bmpSize.y > 0 )
73 {
74 // wxBitmapComboBox::DoGetBestSize on GTK only adjusts the height when the bitmap is
75 // taller than the text (GetCharHeight). When the text is taller, it skips the bitmap
76 // adjustment entirely. But on some GTK themes (Plasma/Breeze), the cell renderer
77 // padding around the bitmap means the combo still needs extra height beyond what the
78 // text-only calculation provides. Ensure the combo is at least tall enough for the
79 // bitmap plus the non-content overhead (borders, frame, focus ring).
80 int overhead = size.y - GetCharHeight();
81 size.y = std::max( size.y, bmpSize.y + overhead + 4 );
82 }
83
84 if( bmpSize.x > 0 )
85 {
86 // The width calculation in wxBitmapComboBox::DoGetBestSize on GTK is derived from the
87 // text-only wxComboBox best size and does not account for the pixbuf cell renderer.
88 // Add the bitmap width plus padding to prevent horizontal clipping.
89 size.x += bmpSize.x + 4;
90 }
91
92#if !wxCHECK_VERSION( 3, 2, 9 )
93 // wxWidgets had a bug on GTK where the wxBitmapComboBox doesn't scale correctly with fontsize.
94 // Fixed upstream in wxWidgets 3.2.9: https://github.com/wxWidgets/wxWidgets/issues/25468
95 wxTextCtrl dummyCtrl( m_parent, wxID_ANY );
96 int dummyWidth = 100;
97
98 size.y = std::max( size.y, dummyCtrl.GetBestHeight( dummyWidth ) + 4 );
99#endif
100#endif
101
102 return size;
103}
104
105
const char * name
wxSize DoGetBestSize() const override
WX_BITMAP_COMBOBOX(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=NULL, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxASCII_STR(wxBitmapComboBoxNameStr))
JSON_SCHEMA_VALIDATOR validator(schema)