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 m_textCtrl->EmptyUndoBuffer();
146
150
153
154 switch( m_currentText->GetHorizJustify() )
155 {
159 }
160
161 switch( m_currentText->GetVertJustify() )
162 {
163 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
166 }
167
169 m_vertical->Check();
170 else
172
173 if( m_currentText->GetWidth() >= 0 )
174 {
175 m_borderCheckbox->SetValue( true );
177 }
178 else
179 {
180 m_borderCheckbox->SetValue( false );
181
182 m_borderWidth.Enable( false );
183 m_borderColorLabel->Enable( false );
184 m_borderColorSwatch->Enable( false );
185 m_borderStyleLabel->Enable( false );
186 m_borderStyleCombo->Enable( false );
187 }
188
190
191 int style = static_cast<int>( m_currentText->GetStroke().GetPlotStyle() );
192
193 if( style == -1 )
194 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
195 else if( style < (int) lineTypeNames.size() )
196 m_borderStyleCombo->SetSelection( style );
197 else
198 wxFAIL_MSG( "Line type not found in the type lookup map" );
199
200 m_filledCtrl->SetValue( m_currentText->IsFilled() );
202
205
207 m_CommonUnit->SetValue( m_currentText->GetUnit() == 0 );
208 m_CommonConvert->SetValue( m_currentText->GetConvert() == 0 );
209
210 return true;
211}
212
213
215{
217 {
218 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
219 btn->Check( false );
220 }
221}
222
223
225{
227 {
228 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
229 btn->Check( false );
230 }
231}
232
233
235{
236 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
237 {
238 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
239 btn->Check( false );
240 }
241}
242
243
245{
246 if( !wxDialog::TransferDataFromWindow() )
247 return false;
248
249 wxString text = m_textCtrl->GetValue();
250
251#ifdef __WXMAC__
252 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
253 text.Replace( wxS( "\r" ), wxS( "\n" ) );
254#elif defined( __WINDOWS__ )
255 // On Windows, a new line is coded as \r\n. We use only \n in kicad files and in
256 // drawing routines so strip the \r char.
257 text.Replace( wxS( "\r" ), wxS( "" ) );
258#endif
259
261
264
266 {
268 m_italic->IsChecked() ) );
269 }
270
271 if( m_bold->IsChecked() != m_currentText->IsBold() )
272 {
273 if( m_bold->IsChecked() )
274 {
275 m_currentText->SetBold( true );
277 }
278 else
279 {
280 m_currentText->SetBold( false );
281 m_currentText->SetTextThickness( 0 ); // Use default pen width
282 }
283 }
284
287
288 if( m_hAlignRight->IsChecked() )
290 else if( m_hAlignCenter->IsChecked() )
292 else
294
297 else if( m_vAlignCenter->IsChecked() )
299 else
301
302 if( m_vertical->IsChecked() )
304 else
306
308
309 if( m_borderCheckbox->GetValue() )
310 stroke.SetWidth( std::max( (long long int) 0, m_borderWidth.GetValue() ) );
311 else
312 stroke.SetWidth( -1 );
313
314 auto it = lineTypeNames.begin();
315 std::advance( it, m_borderStyleCombo->GetSelection() );
316
317 if( it == lineTypeNames.end() )
319 else
320 stroke.SetPlotStyle( it->first );
321
323
324 m_currentText->SetStroke( stroke );
325
327 : FILL_T::NO_FILL );
329
331
332 if( !m_CommonUnit->GetValue() )
334 else
336
337 if( !m_CommonConvert->GetValue() )
339 else
341
342 // Record settings used for next time:
344 tools->SetLastTextAngle( m_currentText->GetTextAngle() );
345 tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
346 tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
347
349
350 return true;
351}
352
353
355{
357}
358
359
361{
364
365 event.Skip();
366}
367
368
370{
371 bool border = m_borderCheckbox->GetValue();
372
373 if( border && m_borderWidth.GetValue() < 0 )
375
376 m_borderWidth.Enable( border );
377 m_borderColorLabel->Enable( border );
378 m_borderColorSwatch->Enable( border );
379 m_borderStyleLabel->Enable( border );
380 m_borderStyleCombo->Enable( border );
381}
382
383
385{
386 bool fill = m_filledCtrl->GetValue();
387
388 m_fillColorLabel->Enable( fill );
389 m_fillColorSwatch->Enable( fill );
390}
391
392
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:106
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
int GetWidth() const
Definition: eda_shape.h:109
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:204
COLOR4D GetTextColor() const
Definition: eda_text.h:205
bool IsItalic() const
Definition: eda_text.h:130
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
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:188
int GetTextWidth() const
Definition: eda_text.h:199
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:248
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:149
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:133
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:152
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:1649
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:419
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:420
@ 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