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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <wx/dcmemory.h>
23#include <wx/odcombo.h>
24#include <wx/menuitem.h>
25#include <wx/settings.h>
26
27#include <dpi_scaling_common.h>
28#include <layer_ids.h>
30#include "kiplatform/ui.h"
31
32
37
38
40{
41 m_layerhotkeys = value;
42 return m_layerhotkeys;
43}
44
45
46LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos,
47 const wxSize& size, int n, const wxString choices[] ) :
48 wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
50{
51#ifdef __WXMAC__
52 GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
53 nullptr, this );
54#endif
55}
56
57
59{
60#ifdef __WXMAC__
61 GetParent()->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
62 nullptr, this );
63#endif
64}
65
66
68{
69 if( GetSelection() < 0 )
70 return UNDEFINED_LAYER;
71
72 return (int)(intptr_t) GetClientData( GetSelection() );
73}
74
75
77{
78 for( int i = 0; i < (int) GetCount(); i++ )
79 {
80 if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
81 {
82 if( GetSelection() != i ) // Element (i) is not selected
83 {
84 SetSelection( i );
85 return i;
86 }
87 else
88 {
89 return i; // If element already selected; do nothing
90 }
91 }
92 }
93
94 // Not Found
95 SetSelection( -1 );
96 return -1;
97}
98
99
100#ifdef __WXMAC__
101
102void LAYER_BOX_SELECTOR::onKeyDown( wxKeyEvent& aEvent )
103{
104 if( aEvent.GetKeyCode() == WXK_ESCAPE && IsPopupShown() )
105 {
106 Dismiss();
107 return;
108 }
109
110 aEvent.Skip();
111}
112
113
114void LAYER_BOX_SELECTOR::OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags) const
115{
116 if( ( flags & wxODCB_PAINTING_CONTROL ) && !IsEnabled() )
117 {
118 wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
119 wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
120
122 bgCol = bgCol.ChangeLightness( 106 );
123 else
124 bgCol = bgCol.ChangeLightness( 160 );
125
126 dc.SetTextForeground( fgCol );
127 dc.SetBrush( bgCol );
128 dc.SetPen( bgCol );
129 dc.DrawRectangle( rect.Inflate( 1, 1 ) );
130 dc.SetClippingRegion( rect );
131 return;
132 }
133
134 wxBitmapComboBox::OnDrawBackground( dc, rect, item, flags );
135}
136
137#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)
bool SetLayersHotkeys(bool value)
@ UNDEFINED_LAYER
Definition layer_ids.h:57
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:50