KiCad PCB EDA Suite
Loading...
Searching...
No Matches
layer_box_selector.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 (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2014-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <wx/dcmemory.h>
27#include <wx/odcombo.h>
28#include <wx/menuitem.h>
29#include <wx/settings.h>
30
31#include <dpi_scaling_common.h>
32#include <layer_ids.h>
34#include "kiplatform/ui.h"
35
36
38{
39 m_layerhotkeys = true;
40}
41
42
44{
45 m_layerhotkeys = value;
46 return m_layerhotkeys;
47}
48
49
50LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos,
51 const wxSize& size, int n, const wxString choices[] ) :
52 wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
54{
55#ifdef __WXMAC__
56 GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
57 nullptr, this );
58#endif
59}
60
61
63{
64#ifdef __WXMAC__
65 GetParent()->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
66 nullptr, this );
67#endif
68}
69
70
72{
73 if( GetSelection() < 0 )
74 return UNDEFINED_LAYER;
75
76 return (int)(intptr_t) GetClientData( GetSelection() );
77}
78
79
81{
82 for( int i = 0; i < (int) GetCount(); i++ )
83 {
84 if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
85 {
86 if( GetSelection() != i ) // Element (i) is not selected
87 {
88 SetSelection( i );
89 return i;
90 }
91 else
92 {
93 return i; // If element already selected; do nothing
94 }
95 }
96 }
97
98 // Not Found
99 SetSelection( -1 );
100 return -1;
101}
102
103
104#ifdef __WXMAC__
105
106void LAYER_BOX_SELECTOR::onKeyDown( wxKeyEvent& aEvent )
107{
108 if( aEvent.GetKeyCode() == WXK_ESCAPE && IsPopupShown() )
109 {
110 Dismiss();
111 return;
112 }
113
114 aEvent.Skip();
115}
116
117
118void LAYER_BOX_SELECTOR::OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags) const
119{
120 if( ( flags & wxODCB_PAINTING_CONTROL ) && !IsEnabled() )
121 {
122 wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
123 wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
124
126 bgCol = bgCol.ChangeLightness( 106 );
127 else
128 bgCol = bgCol.ChangeLightness( 160 );
129
130 dc.SetTextForeground( fgCol );
131 dc.SetBrush( bgCol );
132 dc.SetPen( bgCol );
133 dc.DrawRectangle( rect.Inflate( 1, 1 ) );
134 dc.SetClippingRegion( rect );
135 return;
136 }
137
138 wxBitmapComboBox::OnDrawBackground( dc, rect, item, flags );
139}
140
141#endif
LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=nullptr)
int SetLayerSelection(int layer)
Base class to build a layer list.
bool SetLayersHotkeys(bool value)
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: wxgtk/ui.cpp:48