KiCad PCB EDA Suite
dialog_lib_textbox_properties.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) 2022 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 2
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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <symbol_edit_frame.h>
27#include <widgets/font_choice.h>
29#include <base_units.h>
30#include <general.h>
32#include <lib_textbox.h>
33#include <confirm.h>
35#include <string_utils.h>
36#include <scintilla_tricks.h>
39#include <gr_text.h>
40
42 LIB_TEXTBOX* aTextBox ) :
44 m_frame( aParent ),
45 m_currentText( aTextBox ),
46 m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
47 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits ),
48 m_scintillaTricks( nullptr ),
49 m_helpWindow( nullptr )
50{
51 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
52 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
53
54 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
55 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
56
57 for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
58 m_borderStyleCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) );
59
61
62 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
63 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
64
65 m_textCtrl->SetEOLMode( wxSTC_EOL_LF );
66
67 m_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrl, wxT( "{}" ), false,
68 [this]()
69 {
70 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
71 } );
72
73 m_textEntrySizer->AddGrowableRow( 0 );
74
75 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
76 m_textColorSwatch->SetSwatchBackground( schematicBackground );
77
79
81
86
88
96
103
105
110
112
114 Layout();
115
124
125 // Now all widgets have the size fixed, call FinishDialogSettings
127}
128
129
131{
132 delete m_scintillaTricks;
133
134 if( m_helpWindow )
135 m_helpWindow->Destroy();
136}
137
138
140{
141 if( !wxDialog::TransferDataToWindow() )
142 return false;
143
144 m_textCtrl->SetValue( m_currentText->GetText() );
145
149
152
153 switch( m_currentText->GetHorizJustify() )
154 {
158 }
159
160 switch( m_currentText->GetVertJustify() )
161 {
162 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
165 }
166
168 m_vertical->Check();
169 else
171
172 if( m_currentText->GetWidth() >= 0 )
173 {
174 m_borderCheckbox->SetValue( true );
176 }
177 else
178 {
179 m_borderCheckbox->SetValue( false );
180
181 m_borderWidth.Enable( false );
182 m_borderColorLabel->Enable( false );
183 m_borderColorSwatch->Enable( false );
184 m_borderStyleLabel->Enable( false );
185 m_borderStyleCombo->Enable( false );
186 }
187
189
190 int style = static_cast<int>( m_currentText->GetStroke().GetPlotStyle() );
191
192 if( style == -1 )
193 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
194 else if( style < (int) lineTypeNames.size() )
195 m_borderStyleCombo->SetSelection( style );
196 else
197 wxFAIL_MSG( "Line type not found in the type lookup map" );
198
199 m_filledCtrl->SetValue( m_currentText->IsFilled() );
201
204
206 m_CommonUnit->SetValue( m_currentText->GetUnit() == 0 );
207 m_CommonConvert->SetValue( m_currentText->GetConvert() == 0 );
208
209 return true;
210}
211
212
214{
216 {
217 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
218 btn->Check( false );
219 }
220}
221
222
224{
226 {
227 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
228 btn->Check( false );
229 }
230}
231
232
234{
235 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
236 {
237 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
238 btn->Check( false );
239 }
240}
241
242
244{
245 if( !wxDialog::TransferDataFromWindow() )
246 return false;
247
248 wxString text = m_textCtrl->GetValue();
249
250#ifdef __WXMAC__
251 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
252 text.Replace( "\r", "\n" );
253#elif defined( __WINDOWS__ )
254 // On Windows, a new line is coded as \r\n. We use only \n in kicad files and in
255 // drawing routines so strip the \r char.
256 text.Replace( "\r", "" );
257#endif
258
260
263
265 {
267 m_italic->IsChecked() ) );
268 }
269
270 if( m_bold->IsChecked() != m_currentText->IsBold() )
271 {
272 if( m_bold->IsChecked() )
273 {
274 m_currentText->SetBold( true );
276 }
277 else
278 {
279 m_currentText->SetBold( false );
280 m_currentText->SetTextThickness( 0 ); // Use default pen width
281 }
282 }
283
286
287 if( m_hAlignRight->IsChecked() )
289 else if( m_hAlignCenter->IsChecked() )
291 else
293
296 else if( m_vAlignCenter->IsChecked() )
298 else
300
301 if( m_vertical->IsChecked() )
303 else
305
307
308 if( m_borderCheckbox->GetValue() )
309 stroke.SetWidth( std::max( (long long int) 0, m_borderWidth.GetValue() ) );
310 else
311 stroke.SetWidth( -1 );
312
313 auto it = lineTypeNames.begin();
314 std::advance( it, m_borderStyleCombo->GetSelection() );
315
316 if( it == lineTypeNames.end() )
318 else
319 stroke.SetPlotStyle( it->first );
320
322
323 m_currentText->SetStroke( stroke );
324
326 : FILL_T::NO_FILL );
328
330
331 if( !m_CommonUnit->GetValue() )
333 else
335
336 if( !m_CommonConvert->GetValue() )
338 else
340
341 // Record settings used for next time:
343 tools->SetLastTextAngle( m_currentText->GetTextAngle() );
344 tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
345 tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
346
348
349 return true;
350}
351
352
354{
356}
357
358
360{
363
364 event.Skip();
365}
366
367
369{
370 bool border = m_borderCheckbox->GetValue();
371
372 if( border && m_borderWidth.GetValue() < 0 )
374
375 m_borderWidth.Enable( border );
376 m_borderColorLabel->Enable( border );
377 m_borderColorSwatch->Enable( border );
378 m_borderStyleLabel->Enable( border );
379 m_borderStyleCombo->Enable( border );
380}
381
382
384{
385 bool fill = m_filledCtrl->GetValue();
386
387 m_fillColorLabel->Enable( fill );
388 m_fillColorSwatch->Enable( fill );
389}
390
391
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
@ text_align_right
@ text_valign_top
@ text_align_left
@ text_valign_center
@ text_vertical
@ text_align_center
@ text_horizontal
@ text_valign_bottom
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:41
void SetIsRadioButton()
bool IsChecked() const
void SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
void Check(bool aCheck=true)
Check the control.
void SetIsSeparator()
Render button as a toolbar separator.
void SetIsCheckButton()
Setup the control as a two-state button (checked or unchecked).
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
Class DIALOG_LIB_TEXTBOX_PROPERTIES_BASE.
DIALOG_LIB_TEXTBOX_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_TEXTBOX *aTextBox)
void OnFormattingHelp(wxHyperlinkEvent &aEvent) override
void onBorderChecked(wxCommandEvent &event) override
void onVAlignButton(wxCommandEvent &aEvent)
void onFillChecked(wxCommandEvent &event) override
void onHAlignButton(wxCommandEvent &aEvent)
void onTextAngleButton(wxCommandEvent &aEvent)
void onMultiLineTCLostFocus(wxFocusEvent &event) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool IsFilled() const
Definition: eda_shape.h:90
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:104
COLOR4D GetFillColor() const
Definition: eda_shape.h:103
int GetWidth() const
Definition: eda_shape.h:107
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:194
COLOR4D GetTextColor() const
Definition: eda_text.h:195
bool IsItalic() const
Definition: eda_text.h:120
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:117
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
KIFONT::FONT * GetFont() const
Definition: eda_text.h:178
int GetTextWidth() const
Definition: eda_text.h:189
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:248
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:139
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:185
void SetBold(bool aBold)
Definition: eda_text.cpp:209
bool IsBold() const
Definition: eda_text.h:123
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:142
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:347
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:193
void SetItalic(bool aItalic)
Definition: eda_text.cpp:201
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:331
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:240
bool HaveFontSelection() const
Definition: font_choice.cpp:88
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:67
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
bool IsPrivate() const
Definition: lib_item.h:279
int GetUnit() const
Definition: lib_item.h:273
void SetPrivate(bool aPrivate)
Definition: lib_item.h:278
int GetConvert() const
Definition: lib_item.h:276
void SetConvert(int aConvert)
Definition: lib_item.h:275
void SetUnit(int aUnit)
Definition: lib_item.h:272
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:52
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:53
SYMBOL_EDITOR_SETTINGS * libeditconfig() const
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:1638
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
void SetWidth(int aWidth)
Definition: stroke_params.h:99
void SetColor(const KIGFX::COLOR4D &aColor)
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
SYMBOL_EDITOR_DRAWING_TOOLS.
The symbol library editor main window.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
This file is part of the common library.
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:408
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:409
@ FILLED_WITH_COLOR
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:376
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP