KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_aui_art_providers.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <wx/aui/aui.h>
21#include <wx/aui/framemanager.h>
22#include <wx/aui/auibook.h>
23#include <wx/bitmap.h>
24#include <wx/dc.h>
25#include <wx/settings.h>
26
27#include <kiplatform/ui.h>
28#include <pgm_base.h>
32#include <gal/color4d.h>
33
34#if wxCHECK_VERSION( 3, 3, 0 )
35wxSize WX_AUI_TOOLBAR_ART::GetToolSize( wxReadOnlyDC& aDc, wxWindow* aWindow,
36 const wxAuiToolBarItem& aItem )
37#else
38wxSize WX_AUI_TOOLBAR_ART::GetToolSize( wxDC& aDc, wxWindow* aWindow,
39 const wxAuiToolBarItem& aItem )
40#endif
41{
42 // Based on the upstream wxWidgets implementation, but simplified for our application
43 int size = aWindow->FromDIP( Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size );
44
45 int width = size;
46 int height = size;
47
48 if( ( m_flags & wxAUI_TB_TEXT ) && !aItem.GetLabel().empty() )
49 {
50 aDc.SetFont( m_font );
51 int tx, ty;
52
53 if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
54 {
55 aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &ty );
56 height += ty;
57
58 if( !aItem.GetLabel().empty() )
59 {
60 aDc.GetTextExtent( aItem.GetLabel(), &tx, &ty );
61 width = wxMax( width, tx + aWindow->FromDIP( 6 ) );
62 }
63 }
64 else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT )
65 {
66 width += aWindow->FromDIP( 3 ); // space between left border and bitmap
67 width += aWindow->FromDIP( 3 ); // space between bitmap and text
68
69 if( !aItem.GetLabel().empty() )
70 {
71 aDc.GetTextExtent( aItem.GetLabel(), &tx, &ty );
72 width += tx;
73 height = wxMax( height, ty );
74 }
75 }
76 }
77
78 if( aItem.HasDropDown() )
79 {
80 int dropdownWidth = GetElementSize( wxAUI_TBART_DROPDOWN_SIZE );
81 width += dropdownWidth + aWindow->FromDIP( 4 );
82 }
83
84 return wxSize( width, height );
85}
86
87
88void WX_AUI_TOOLBAR_ART::DrawButton( wxDC& aDc, wxWindow* aWindow, const wxAuiToolBarItem& aItem,
89 const wxRect& aRect )
90{
91 // Based on upstream implementation
92 int bmpX = 0, bmpY = 0;
93 int textX = 0, textY = 0;
94
95 const wxBitmap& bmp = aItem.GetCurrentBitmapFor( aWindow );
96 const wxSize bmpSize = bmp.IsOk() ? bmp.GetLogicalSize() : wxSize( 0, 0 );
97
98 if( ( m_flags & wxAUI_TB_TEXT ) && !aItem.GetLabel().empty() )
99 {
100 aDc.SetFont( m_font );
101
102 int textWidth = 0, textHeight = 0;
103 int tx, ty;
104
105 aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &textHeight );
106 aDc.GetTextExtent( aItem.GetLabel(), &textWidth, &ty );
107
108 if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
109 {
110 bmpX = aRect.x + ( aRect.width / 2 ) - ( bmpSize.x / 2 );
111
112 bmpY = aRect.y + ( ( aRect.height - textHeight ) / 2 ) - ( bmpSize.y / 2 );
113
114 textX = aRect.x + ( aRect.width / 2 ) - ( textWidth / 2 ) + 1;
115 textY = aRect.y + aRect.height - textHeight - 1;
116 }
117 else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT )
118 {
119 bmpX = aRect.x + aWindow->FromDIP( 3 );
120
121 bmpY = aRect.y + ( aRect.height / 2 ) - ( bmpSize.y / 2 );
122
123 textX = bmpX + aWindow->FromDIP( 3 ) + bmpSize.x;
124 textY = aRect.y + ( aRect.height / 2 ) - ( textHeight / 2 );
125 }
126 }
127 else
128 {
129 bmpX = aRect.x + ( aRect.width / 2 ) - ( bmpSize.x / 2 );
130 bmpY = aRect.y + ( aRect.height / 2 ) - ( bmpSize.y / 2 );
131 }
132
133 bool isThemeDark = KIPLATFORM::UI::IsDarkTheme();
134
135 if( !( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED ) )
136 {
137 if( aItem.GetState() & wxAUI_BUTTON_STATE_PRESSED )
138 {
139 aDc.SetPen( wxPen( m_highlightColour ) );
140 aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 20 : 150 ) ) );
141 aDc.DrawRectangle( aRect );
142 }
143 else if( ( aItem.GetState() & wxAUI_BUTTON_STATE_HOVER ) || aItem.IsSticky() )
144 {
145 aDc.SetPen( wxPen( m_highlightColour ) );
146 aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 40 : 170 ) ) );
147
148 // draw an even lighter background for checked item hovers (since
149 // the hover background is the same color as the check background)
150 if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
151 aDc.SetBrush(
152 wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 50 : 180 ) ) );
153
154 aDc.DrawRectangle( aRect );
155 }
156 else if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
157 {
158 // it's important to put this code in an else statement after the
159 // hover, otherwise hovers won't draw properly for checked items
160 aDc.SetPen( wxPen( m_highlightColour ) );
161 aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 40 : 170 ) ) );
162 aDc.DrawRectangle( aRect );
163 }
164 }
165
166 if( bmp.IsOk() )
167 aDc.DrawBitmap( bmp, bmpX, bmpY, true );
168
169 // set the item's text color based on if it is disabled
170 aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
171
172 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
173 {
174 aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
175 }
176
177 if( ( m_flags & wxAUI_TB_TEXT ) && !aItem.GetLabel().empty() )
178 {
179 aDc.DrawText( aItem.GetLabel(), textX, textY );
180 }
181}
182
183
185{
186#ifdef __WXOSX__
187 // Use a slightly stronger highlight colour over grey toolbar backgrounds
188 KIGFX::COLOR4D highlight( m_highlightColour );
189 m_highlightColour = highlight.Saturate( 0.6 ).ToColour();
190#endif
191}
192
193
195{
196 wxAuiDefaultToolBarArt::UpdateColoursFromSystem();
198}
199
200
201class ToolbarCommandCapture : public wxEvtHandler
202{
203public:
205 int GetCommandId() const { return m_lastId; }
206
207 bool ProcessEvent( wxEvent& evt ) override
208 {
209 if( evt.GetEventType() == wxEVT_MENU )
210 {
211 m_lastId = evt.GetId();
212 return true;
213 }
214
215 if( GetNextHandler() )
216 return GetNextHandler()->ProcessEvent( evt );
217
218 return false;
219 }
220
221private:
223};
224
225
226int WX_AUI_TOOLBAR_ART::ShowDropDown( wxWindow* wnd, const wxAuiToolBarItemArray& items )
227{
228 wxMenu menuPopup;
229 bool skipNextSeparator = true;
230
231 size_t i, count = items.GetCount();
232 for( i = 0; i < count; ++i )
233 {
234 wxAuiToolBarItem& item = items.Item( i );
235
236 if( item.GetKind() == wxITEM_SEPARATOR )
237 {
238 if( !skipNextSeparator )
239 {
240 menuPopup.AppendSeparator();
241 skipNextSeparator = true;
242 }
243 }
244 else if( item.GetKind() == wxITEM_NORMAL || item.GetKind() == wxITEM_CHECK || item.GetKind() == wxITEM_RADIO )
245 {
246 wxString text = item.GetShortHelp();
247
248 if( text.empty() )
249 text = item.GetLabel();
250
251 if( text.empty() )
252 text = wxT( " " );
253
254 wxString firstLine = text.BeforeFirst( '\n' );
255 wxString accel;
256 wxString label = firstLine.BeforeFirst( '\t', &accel );
257
258 text = label;
259
260 if( !accel.empty() )
261 {
262 // Remove brackets from accelerator string so it's recognized
263 if( accel.starts_with( "(" ) && accel.ends_with( ")" ) )
264 accel = accel.Mid( 1, accel.size() - 2 );
265
266 text << "\t" << accel;
267 }
268
269 bool checked = item.GetState() & wxAUI_BUTTON_STATE_CHECKED;
270 wxItemKind menuKind = wxITEM_NORMAL;
271
272 if( ( item.GetKind() == wxITEM_CHECK || item.GetKind() == wxITEM_RADIO ) && checked )
273 menuKind = static_cast<wxItemKind>( item.GetKind() );
274
275 wxMenuItem* m = new wxMenuItem( &menuPopup, item.GetId(), text, item.GetShortHelp(), menuKind );
276
277 if( !m->IsCheckable() )
278 m->SetBitmap( item.GetBitmapBundle() );
279
280 menuPopup.Append( m );
281
282 if( m->IsCheckable() )
283 m->Check( checked );
284
285 skipNextSeparator = false;
286 }
287 }
288
289 // find out where to put the popup menu of window items
290 wxPoint pt = ::wxGetMousePosition();
291 pt = wnd->ScreenToClient( pt );
292
293 // find out the screen coordinate at the bottom of the tab ctrl
294 wxRect cli_rect = wnd->GetClientRect();
295 pt.y = cli_rect.y + cli_rect.height;
296
298 wnd->PushEventHandler( cc );
299 wnd->PopupMenu( &menuPopup, pt );
300 int command = cc->GetCommandId();
301 wnd->PopEventHandler( true );
302
303 return command;
304}
305
306
308 wxAuiDefaultDockArt()
309{
310#if defined( _WIN32 )
311 // Use normal control font, wx likes to use "small"
312 m_captionFont = *wxNORMAL_FONT;
313
314 // Increase the box the caption rests in size a bit
315 m_captionSize = ( wxNORMAL_FONT->GetPointSize() * 7 ) / 4 + 6;
316#endif
317
318 SetColour( wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR,
319 wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
320 SetColour( wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR,
321 wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
322
323 // Turn off the ridiculous looking gradient
324 m_gradientType = wxAUI_GRADIENT_NONE;
325}
326
327
328void WX_AUI_TAB_ART::DrawTab( wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect,
329 int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect,
330 int* x_extent )
331{
332 PANEL_NOTEBOOK_BASE* panel = dynamic_cast<PANEL_NOTEBOOK_BASE*>( page.window );
333
334 if( panel && !panel->GetClosable() )
335 close_button_state = wxAUI_BUTTON_STATE_HIDDEN;
336
337 return wxAuiGenericTabArt::DrawTab( dc, wnd, page, in_rect, close_button_state, out_tab_rect,
338 out_button_rect, x_extent );
339}
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
wxColour ToColour() const
Definition color4d.cpp:225
COLOR4D & Saturate(double aFactor)
Saturates the color to a given factor (in HSV model)
Definition color4d.cpp:517
bool ProcessEvent(wxEvent &evt) override
void DrawTab(wxDC &dc, wxWindow *wnd, const wxAuiNotebookPage &page, const wxRect &in_rect, int close_button_state, wxRect *out_tab_rect, wxRect *out_button_rect, int *x_extent) override
void UpdateColoursFromSystem() override
wxSize GetToolSize(wxDC &aDc, wxWindow *aWindow, const wxAuiToolBarItem &aItem) override
int ShowDropDown(wxWindow *wnd, const wxAuiToolBarItemArray &items) override
void DrawButton(wxDC &aDc, wxWindow *aWindow, const wxAuiToolBarItem &aItem, const wxRect &aRect) override
Unfortunately we need to re-implement this to actually be able to control the size.
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:48
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE