KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
58 m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmap( lineStyleDesc.bitmap ) );
59
61
62 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
63 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
64
65 m_textCtrl->SetEOLMode( wxSTC_EOL_LF );
66
67#ifdef _WIN32
68 // Without this setting, on Windows, some esoteric unicode chars create display issue
69 // in a wxStyledTextCtrl.
70 // for SetTechnology() info, see https://www.scintilla.org/ScintillaDoc.html#SCI_SETTECHNOLOGY
71 m_textCtrl->SetTechnology(wxSTC_TECHNOLOGY_DIRECTWRITE);
72#endif
73
74 m_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrl, wxT( "{}" ), false,
75 [this]( wxKeyEvent& aEvent )
76 {
77 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
78 } );
79
80 m_textEntrySizer->AddGrowableRow( 0 );
81
82 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
83 m_textColorSwatch->SetSwatchBackground( schematicBackground );
84
86
88
90 m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
92 m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
93
95
97 m_hAlignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
99 m_hAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
101 m_hAlignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
103
105 m_vAlignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
107 m_vAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
109 m_vAlignBottom->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_bottom ) );
110
112
114 m_horizontal->SetBitmap( KiBitmapBundle( BITMAPS::text_horizontal ) );
116 m_vertical->SetBitmap( KiBitmapBundle( BITMAPS::text_vertical ) );
117
119
121 Layout();
122
131
132 // Now all widgets have the size fixed, call FinishDialogSettings
134}
135
136
138{
139 delete m_scintillaTricks;
140
141 if( m_helpWindow )
142 m_helpWindow->Destroy();
143}
144
145
147{
148 if( !wxDialog::TransferDataToWindow() )
149 return false;
150
152
153 m_textCtrl->SetValue( m_currentText->GetText() );
154 m_textCtrl->EmptyUndoBuffer();
155
159
162
163 switch( m_currentText->GetHorizJustify() )
164 {
168 }
169
170 switch( m_currentText->GetVertJustify() )
171 {
172 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
175 }
176
178 m_vertical->Check();
179 else
181
182 if( m_currentText->GetWidth() >= 0 )
183 {
184 m_borderCheckbox->SetValue( true );
186 }
187 else
188 {
189 m_borderCheckbox->SetValue( false );
190
191 m_borderWidth.Enable( false );
192 m_borderColorLabel->Enable( false );
193 m_borderColorSwatch->Enable( false );
194 m_borderStyleLabel->Enable( false );
195 m_borderStyleCombo->Enable( false );
196 }
197
199
200 int style = static_cast<int>( m_currentText->GetStroke().GetLineStyle() );
201
202 if( style == -1 )
203 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
204 else if( style < (int) lineTypeNames.size() )
205 m_borderStyleCombo->SetSelection( style );
206 else
207 wxFAIL_MSG( "Line type not found in the type lookup map" );
208
209 m_filledCtrl->SetValue( m_currentText->IsFilled() );
211
214
216 m_CommonUnit->SetValue(
217 symbol && symbol->GetUnitCount() > 1 && m_currentText->GetUnit() == 0 );
218 m_CommonUnit->Enable( symbol && symbol->GetUnitCount() > 1 );
219 m_CommonConvert->SetValue( m_currentText->GetConvert() == 0 );
220
221 return true;
222}
223
224
226{
228 {
229 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
230 btn->Check( false );
231 }
232}
233
234
236{
238 {
239 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
240 btn->Check( false );
241 }
242}
243
244
246{
247 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
248 {
249 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
250 btn->Check( false );
251 }
252}
253
254
256{
257 if( !wxDialog::TransferDataFromWindow() )
258 return false;
259
260 wxString text = m_textCtrl->GetValue();
261
262#ifdef __WXMAC__
263 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
264 text.Replace( wxS( "\r" ), wxS( "\n" ) );
265#elif defined( __WINDOWS__ )
266 // On Windows, a new line is coded as \r\n. We use only \n in kicad files and in
267 // drawing routines so strip the \r char.
268 text.Replace( wxS( "\r" ), wxS( "" ) );
269#endif
270
272
275
277 {
279 m_italic->IsChecked() ) );
280 }
281
282 if( m_bold->IsChecked() != m_currentText->IsBold() )
283 {
284 if( m_bold->IsChecked() )
285 {
286 m_currentText->SetBold( true );
288 }
289 else
290 {
291 m_currentText->SetBold( false );
292 m_currentText->SetTextThickness( 0 ); // Use default pen width
293 }
294 }
295
298
299 if( m_hAlignRight->IsChecked() )
301 else if( m_hAlignCenter->IsChecked() )
303 else
305
308 else if( m_vAlignCenter->IsChecked() )
310 else
312
313 if( m_vertical->IsChecked() )
315 else
317
319
320 if( m_borderCheckbox->GetValue() )
321 stroke.SetWidth( std::max( (long long int) 0, m_borderWidth.GetValue() ) );
322 else
323 stroke.SetWidth( -1 );
324
325 auto it = lineTypeNames.begin();
326 std::advance( it, m_borderStyleCombo->GetSelection() );
327
328 if( it == lineTypeNames.end() )
329 stroke.SetLineStyle( LINE_STYLE::DEFAULT );
330 else
331 stroke.SetLineStyle( it->first );
332
334
335 m_currentText->SetStroke( stroke );
336
337 m_currentText->SetFillMode( m_filledCtrl->GetValue() ? FILL_T::FILLED_WITH_COLOR
338 : FILL_T::NO_FILL );
340
342
343 if( !m_CommonUnit->GetValue() )
345 else
347
348 if( !m_CommonConvert->GetValue() )
350 else
352
353 // Record settings used for next time:
355 tools->SetLastTextAngle( m_currentText->GetTextAngle() );
356 tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
357 tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
358
360
361 return true;
362}
363
364
366{
368}
369
370
372{
375
376 event.Skip();
377}
378
379
381{
382 bool border = m_borderCheckbox->GetValue();
383
384 if( border && m_borderWidth.GetValue() < 0 )
386
387 m_borderWidth.Enable( border );
388 m_borderColorLabel->Enable( border );
389 m_borderColorSwatch->Enable( border );
390 m_borderStyleLabel->Enable( border );
391 m_borderStyleCombo->Enable( border );
392}
393
394
396{
397 bool fill = m_filledCtrl->GetValue();
398
399 m_fillColorLabel->Enable( fill );
400 m_fillColorSwatch->Enable( fill );
401}
402
403
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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:104
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 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).
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
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
virtual 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:226
COLOR4D GetTextColor() const
Definition: eda_text.h:227
void SetTextSize(VECTOR2I aNewSize)
Definition: eda_text.cpp:358
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
KIFONT::FONT * GetFont() const
Definition: eda_text.h:207
int GetTextWidth() const
Definition: eda_text.h:221
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:260
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:197
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsBold() const
Definition: eda_text.h:144
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:163
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:342
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:252
bool HaveFontSelection() const
Definition: font_choice.cpp:94
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:73
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:342
int GetUnit() const
Definition: lib_item.h:336
void SetPrivate(bool aPrivate)
Definition: lib_item.h:341
int GetConvert() const
Definition: lib_item.h:339
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:202
void SetConvert(int aConvert)
Definition: lib_item.h:338
void SetUnit(int aUnit)
Definition: lib_item.h:335
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:57
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:58
Define a library symbol object.
Definition: lib_symbol.h:99
int GetUnitCount() const override
For items with units, return the number of units.
SYMBOL_EDITOR_SETTINGS * libeditconfig() const
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:2050
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:81
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:95
void SetWidth(int aWidth)
Definition: stroke_params.h:92
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:98
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
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:55
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:433
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:434
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:382
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
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
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588