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/textctrl.h>
22
23WX_BITMAP_COMBOBOX::WX_BITMAP_COMBOBOX( wxWindow* parent, wxWindowID id, const wxString& value,
24 const wxPoint& pos, const wxSize& size, int n,
25 const wxString choices[], long style,
26 const wxValidator& validator, const wxString& name ) :
27 wxBitmapComboBox( parent, id, value, pos, size, n, choices, style, validator, name )
28{
29}
30
31
33{
34 wxSize size = wxBitmapComboBox::DoGetBestSize();
35
36#ifdef __WXGTK__
37 wxSize bmpSize = GetBitmapSize();
38
39 if( bmpSize.y > 0 )
40 {
41 // wxBitmapComboBox::DoGetBestSize on GTK only adjusts the height when the bitmap is
42 // taller than the text (GetCharHeight). When the text is taller, it skips the bitmap
43 // adjustment entirely. But on some GTK themes (Plasma/Breeze), the cell renderer
44 // padding around the bitmap means the combo still needs extra height beyond what the
45 // text-only calculation provides. Ensure the combo is at least tall enough for the
46 // bitmap plus the non-content overhead (borders, frame, focus ring).
47 int overhead = size.y - GetCharHeight();
48 size.y = std::max( size.y, bmpSize.y + overhead + 4 );
49 }
50
51 if( bmpSize.x > 0 )
52 {
53 // The width calculation in wxBitmapComboBox::DoGetBestSize on GTK is derived from the
54 // text-only wxComboBox best size and does not account for the pixbuf cell renderer.
55 // Add the bitmap width plus padding to prevent horizontal clipping.
56 size.x += bmpSize.x + 4;
57 }
58
59#if !wxCHECK_VERSION( 3, 2, 9 )
60 // wxWidgets had a bug on GTK where the wxBitmapComboBox doesn't scale correctly with fontsize.
61 // Fixed upstream in wxWidgets 3.2.9: https://github.com/wxWidgets/wxWidgets/issues/25468
62 wxTextCtrl dummyCtrl( m_parent, wxID_ANY );
63 int dummyWidth = 100;
64
65 size.y = std::max( size.y, dummyCtrl.GetBestHeight( dummyWidth ) + 4 );
66#endif
67#endif
68
69 return size;
70}
71
72
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))