wxArt2D
fontdlg2.cpp
1 /*! \file editor/src/fontdlg.cpp
2  \author Erik van der Wal
3 
4  Copyright: 2000-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: fontdlg.cpp,v 1.19 2008/08/02 13:46:07 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #include <string.h>
18 #include <stdlib.h>
19 
20 #include "wx/canvas/fontdlg.h"
21 #include "wx/canvas/canglob.h"
22 #include "wx/artbase/drawer2d.h"
23 #include "wx/canvas/canvas.h"
24 #include "wx/canvas/canprim.h"
25 #include "wx/canvas/polygon.h"
26 
27 #include <wx/tglbtn.h>
28 #include <wx/valnum.h>
29 
30 // XPM images:
31 //------------
32 
33 #include "../../art/resources/AlignTR.xpm" // AlignTR_xpm
34 #include "../../art/resources/AlignTRPressed.xpm" // AlignTRPressed_xpm
35 #include "../../art/resources/AlignT.xpm" // AlignT_xpm
36 #include "../../art/resources/AlignTPressed.xpm" // AlignTPressed_xpm
37 #include "../../art/resources/AlignTL.xpm" // AlignTL_xpm
38 #include "../../art/resources/AlignTLPressed.xpm" // AlignTLPressed_xpm
39 #include "../../art/resources/AlignR.xpm" // AlignR_xpm
40 #include "../../art/resources/AlignRPressed.xpm" // AlignRPressed_xpm
41 #include "../../art/resources/AlignC.xpm" // AlignC_xpm
42 #include "../../art/resources/AlignCPressed.xpm" // AlignCPressed_xpm
43 #include "../../art/resources/AlignL.xpm" // AlignL_xpm
44 #include "../../art/resources/AlignLPressed.xpm" // AlignLPressed_xpm
45 #include "../../art/resources/AlignBR.xpm" // AlignBR_xpm
46 #include "../../art/resources/AlignBRPressed.xpm" // AlignBRPressed_xpm
47 #include "../../art/resources/AlignB.xpm" // AlignB_xpm
48 #include "../../art/resources/AlignBPressed.xpm" // AlignBPressed_xpm
49 #include "../../art/resources/AlignBL.xpm" // AlignBL_xpm
50 #include "../../art/resources/AlignBLPressed.xpm" // AlignBLPressed_xpm
51 
52 
53 //===========================================================================
54 // a2dTextPropDlgExt
55 //===========================================================================
56 
57 enum
58 {
59  ID_STROKECOLOR_BOX = wxID_HIGHEST + 1,
60  ID_FILL_BOX,
61  wxID_FONTTYPE_LIST,
62  wxID_FONTNAME_LIST,
63  wxID_FONTSTYLE_LIST,
64  wxID_FONTSIZE_EDIT,
65  wxID_FONTSIZE_LIST,
66  wxID_FONT_SEARCHPATH,
67  wxID_FONTTYPE_OK,
68  wxID_ALIGN_TL, wxID_ALIGN_T, wxID_ALIGN_TR,
69  wxID_ALIGN_L, wxID_ALIGN_C, wxID_ALIGN_R,
70  wxID_ALIGN_BL, wxID_ALIGN_B, wxID_ALIGN_BR,
71  wxID_CHECK_ALIGN,
72  wxID_CHECK_FRAME,
73  wxID_CHECK_BACKGROUND
74 };
75 
76 #define a2dSHOW_ALL_SETTINGS
77 #define MAXSIZE 300
78 
79 //--------------------------------------------------------
80 // Event Table:
81 //--------------------------------------------------------
82 BEGIN_EVENT_TABLE( a2dTextPropDlgExt, wxDialog )
83  //Stroke + Fill
84  EVT_INIT_DIALOG(a2dTextPropDlgExt::OnInitDialog)
85  EVT_BUTTON(wxID_OK, a2dTextPropDlgExt::OnOk)
86  EVT_COMBOBOX(ID_STROKECOLOR_BOX, a2dTextPropDlgExt::OnColourChange)
87  EVT_COMBOBOX(ID_FILL_BOX, a2dTextPropDlgExt::OnColourChange)
88  //Font
89  EVT_LISTBOX( wxID_FONTTYPE_LIST, a2dTextPropDlgExt::OnChangeFontType )
90  EVT_LISTBOX( wxID_FONTNAME_LIST, a2dTextPropDlgExt::OnChangeFontName )
91  EVT_LISTBOX( wxID_FONTSTYLE_LIST, a2dTextPropDlgExt::OnChangeFontStyle )
92  EVT_LISTBOX( wxID_FONTSIZE_LIST, a2dTextPropDlgExt::OnChangeFontSizeList )
93  EVT_TEXT( wxID_FONTSIZE_EDIT, a2dTextPropDlgExt::OnChangeFontSize )
94  EVT_BUTTON( wxID_FONT_SEARCHPATH, a2dTextPropDlgExt::OnSearchPath )
95  EVT_TOGGLEBUTTON( wxID_ALIGN_TL, a2dTextPropDlgExt::OnAlignment )
96  EVT_TOGGLEBUTTON( wxID_ALIGN_T, a2dTextPropDlgExt::OnAlignment )
97  EVT_TOGGLEBUTTON( wxID_ALIGN_TR, a2dTextPropDlgExt::OnAlignment )
98  EVT_TOGGLEBUTTON( wxID_ALIGN_L, a2dTextPropDlgExt::OnAlignment )
99  EVT_TOGGLEBUTTON( wxID_ALIGN_C, a2dTextPropDlgExt::OnAlignment )
100  EVT_TOGGLEBUTTON( wxID_ALIGN_R, a2dTextPropDlgExt::OnAlignment )
101  EVT_TOGGLEBUTTON( wxID_ALIGN_BL, a2dTextPropDlgExt::OnAlignment )
102  EVT_TOGGLEBUTTON( wxID_ALIGN_B, a2dTextPropDlgExt::OnAlignment )
103  EVT_TOGGLEBUTTON( wxID_ALIGN_BR, a2dTextPropDlgExt::OnAlignment )
104  EVT_CHECKBOX( wxID_CHECK_ALIGN, a2dTextPropDlgExt::OnAlignment )
105  EVT_CHECKBOX( wxID_CHECK_FRAME, a2dTextPropDlgExt::OnTextflags )
106  EVT_CHECKBOX( wxID_CHECK_BACKGROUND, a2dTextPropDlgExt::OnTextflags )
107  EVT_SIZE( a2dTextPropDlgExt::OnSize )
108 END_EVENT_TABLE()
109 //--------------------------------------------------------
110 
111 a2dTextPropDlgExt::a2dTextPropDlgExt( a2dHabitat* habitat, wxWindow *parent, bool bGlobal, bool bFill, a2dFontInfoList *fontlist, bool bAllowLayerStyle)
112  : wxDialog( parent, -1, (bGlobal) ? _("Global Font") : _("Font"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ), m_bFill(bFill), m_UnitsScale(1), m_CustomColors(), m_ExtStroke(), m_ExtFill(), m_ExtFont()
113 {
114  m_habitat = habitat;
115  m_fonts=fontlist;
116 
117  //map all possible styles to make them translatable
118  m_styles[ wxT( "Medium" ) ] = _( "Medium" );
119  m_styles[ wxT( "Medium Italic" ) ] = _( "Medium Italic" );
120  m_styles[ wxT( "Regular" ) ] = _( "Regular" );
121  m_styles[ wxT( "Italic" ) ] = _( "Italic" );
122  m_styles[ wxT( "Bold" ) ] = _( "Bold" );
123  m_styles[ wxT( "Bold Oblique" ) ] = _( "Bold Oblique" );
124  m_styles[ wxT( "Bold Italic" ) ] = _( "Bold Italic" );
125  m_styles[ wxT( "Light" ) ] = _( "Light" );
126  m_styles[ wxT( "Light Italic" ) ] = _( "Light Italic" );
127  m_styles[ wxT( "Black" ) ] = _( "Black" );
128  m_styles[ wxT( "Black Italic" ) ] = _( "Black Italic" );
129  m_styles[ wxT( "Narrow" ) ] = _( "Narrow" );
130  m_styles[ wxT( "Roman" ) ] = _( "Roman" );
131  m_styles[ wxT( "Condensed" ) ] = _( "Condensed" );
132  m_styles[ wxT( "Condensed Italic" ) ] = _( "Condensed Italic" );
133  m_styles[ wxT( "Condensed Bold" ) ] = _( "Condensed Bold" );
134  m_styles[ wxT( "Condensed Oblique" ) ] = _( "Condensed Oblique" );
135  m_styles[ wxT( "Condensed Bold Italic" ) ] = _( "Condensed Bold Italic" );
136  m_styles[ wxT( "Condensed Bold Oblique" ) ] = _( "Condensed Bold Oblique" );
137  m_styles[ wxT( "Poster Compressed" ) ] = _( "Poster Compressed" );
138  m_styles[ wxT( "ExtraLight" ) ] = _( "ExtraLight" );
139  m_styles[ wxT( "Oblique" ) ] = _( "Oblique" );
140  m_styles[ wxT( "Book" ) ] = _( "Book" );
141  m_styles[ wxT( "Demi" ) ] = _( "Demi" );
142  m_styles[ wxT( "Demi Oblique" ) ] = _( "Demi Oblique" );
143  m_styles[ wxT( "Demibold" ) ] = _( "Demibold" );
144  m_styles[ wxT( "Demibold Italic" ) ] = _( "Demibold Italic" );
145  m_styles[ wxT( "Demibold Roman" ) ] = _( "Demibold Roman" );
146  m_styles[ wxT( "Semilight" ) ] = _( "Semilight" );
147  m_styles[ wxT( "Semibold" ) ] = _( "Semibold" );
148  m_styles[ wxT( "Pixel Pen" ) ] = _( "Pixel Pen" );
149  m_styles[ wxT( "Normalized Pen" ) ] = _( "Normalized Pen" );
150  m_styles[ wxT( " 2% of height" ) ] = _( " 2% of height" );
151  m_styles[ wxT( " 5% of height" ) ] = _( " 5% of height" );
152  m_styles[ wxT( " 7% of height" ) ] = _( " 7% of height" );
153  m_styles[ wxT( "10% of height" ) ] = _( "10% of height" );
154  m_styles[ wxT( "15% of height" ) ] = _( "15% of height" );
155  m_styles[ wxT( "20% of height" ) ] = _( "20% of height" );
156 
157  CreateControls(bAllowLayerStyle);
158 }
159 
160 void a2dTextPropDlgExt::CreateControls(bool bAllowLayerStyle)
161 {
162  m_pTopSizer = new wxBoxSizer(wxVERTICAL);
163  this->SetSizer(m_pTopSizer);
164 
165  //----------------------------
166  // font
167  //----------------------------
168 
169  m_viewscale = 1.0;
170 
171  wxBoxSizer* propsizer = new wxBoxSizer( wxHORIZONTAL );
172  wxBoxSizer* sizesizer = new wxBoxSizer( wxVERTICAL );
173 
174  //Sizer to get correct width of type+border+name
175  wxBoxSizer* getwidthsizer_l;
176  getwidthsizer_l = new wxBoxSizer( wxHORIZONTAL );
177 
178  //Type
179  wxBoxSizer* typesizer = new wxBoxSizer( wxVERTICAL );
180  wxStaticText* typetext = new wxStaticText( this, -1, _( "Type:" ) );
181  typesizer->Add( typetext , 0, wxLEFT | wxRIGHT | wxTOP, 5 );
182  wxArrayString types;
183  types.Add( _( "* (All types)" ) );
184  for ( size_t i = 0; i < m_fonts->GetCount(); i++ )
185  {
186  wxString type = m_fonts->Item( i )->GetData()->GetType();
187  size_t j;
188  for ( j = 0; j < types.GetCount(); j++ )
189  {
190  if ( types.Item( j ) == type )
191  break;
192  }
193  if ( j == types.GetCount() )
194  types.Add( type );
195  }
196  m_typelist = new wxListBox( this, wxID_FONTTYPE_LIST, wxDefaultPosition, wxDefaultSize, types, wxLB_SORT | wxLB_ALWAYS_SB );
197  typesizer->Add( m_typelist, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
198  getwidthsizer_l->Add( typesizer, 0, wxALL | wxEXPAND, 5 );
199 #ifndef a2dSHOW_ALL_SETTINGS
200  typetext->Hide(); // not changable by user
201  m_typelist->Hide(); // not changable by user
202 #endif // a2dSHOW_ALL_SETTINGS
203 
204  //Font
205  wxBoxSizer* fontsizer = new wxBoxSizer( wxVERTICAL );
206  fontsizer->Add( new wxStaticText( this, -1, _( "Font:" ) ), 0, wxLEFT | wxRIGHT | wxTOP, 5 );
207  wxArrayString fonts = GetFontList( a2dDEFAULT_FONTTYPE );
208  m_fontlist = new wxListBox( this, wxID_FONTNAME_LIST, wxDefaultPosition, wxDefaultSize, fonts, wxLB_SORT | wxLB_ALWAYS_SB );
209  m_fontlist->SetMinSize( m_fontlist->GetSize() );
210  fontsizer->Add( m_fontlist, 1, wxLEFT | wxRIGHT | wxBOTTOM| wxEXPAND , 5 );
211  getwidthsizer_l->Add( fontsizer, 0, wxALL | wxEXPAND, 5 );
212 
213  propsizer->Add( getwidthsizer_l, 0, wxEXPAND, 0 );
214 
215  //Sizer to get correct width of style+border+textsize
216  wxBoxSizer* getwidthsizer_r;
217  getwidthsizer_r = new wxBoxSizer( wxHORIZONTAL );
218 
219  //Style
220  wxBoxSizer* stylesizer = new wxBoxSizer( wxVERTICAL );
221  stylesizer->Add( new wxStaticText( this, -1, _( "Style:" ) ), 0, wxLEFT | wxRIGHT | wxTOP, 5 );
222  wxString longeststyle = GetLongestStyle();
223  wxArrayString styles;
224  styles.Add( longeststyle );
225  m_stylelist = new wxListBox( this, wxID_FONTSTYLE_LIST, wxDefaultPosition, wxSize( -1,-1 ), styles, wxLB_SORT | wxLB_ALWAYS_SB );
226  m_stylelist->SetMinSize( m_stylelist->GetSize() );
227  stylesizer->Add( m_stylelist, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
228  getwidthsizer_r->Add( stylesizer, 0, wxALL | wxEXPAND, 5 );
229 
230  //Size
231  wxFloatingPointValidator<float> val( 1, NULL, wxNUM_VAL_DEFAULT );
232  val.SetRange( 1, MAXSIZE );
233 
234  sizesizer->Add( new wxStaticText( this, -1, _( "Size:" ) ), 0, wxLEFT | wxRIGHT | wxTOP, 5 );
235  wxArrayString sizes;
236  for(float i=5 ; i<=12 ; i++)
237  sizes.Add( wxString::Format("%.0f", i) );
238  for(float i=14 ; i<=28 ; i=i+2)
239  sizes.Add( wxString::Format("%.0f", i) );
240  sizes.Add( wxString::Format("%.0f", 36.0) );
241  sizes.Add( wxString::Format("%.0f", 48.0) );
242  sizes.Add( wxString::Format("%.0f", 72.0) );
243  m_sizelist = new wxListBox( this, wxID_FONTSIZE_LIST, wxDefaultPosition, wxDefaultSize, sizes, wxLB_ALWAYS_SB );
244  m_sizeedit = new wxTextCtrl( this, wxID_FONTSIZE_EDIT, wxT( "" ), wxDefaultPosition, wxDefaultSize, 0, val );
245  m_sizeedit->SetMinSize( wxSize(70, -1) );
246  sizesizer->Add( m_sizeedit, 0, wxLEFT | wxRIGHT | wxEXPAND, 5 );
247  sizesizer->Add( m_sizelist, 1, wxLEFT | wxRIGHT | wxBOTTOM| wxEXPAND , 5 );
248  getwidthsizer_r->Add( sizesizer, 0, wxALL | wxEXPAND, 5 );
249 
250  propsizer->Add( getwidthsizer_r, 0, wxEXPAND, 0 );
251 
252  m_pTopSizer->Add( propsizer, 1, wxALL | wxEXPAND, 5 );
253  getwidthsizer_r->Layout(); //to get correct size of listctrls
254  getwidthsizer_l->Layout(); //to get correct size of listctrls
255 
256  wxBoxSizer* bottomsizer = new wxBoxSizer( wxHORIZONTAL );
257 
258  //----------------------------
259  // Alignment + Sample
260  //----------------------------
261  wxStaticBoxSizer* pStaticBoxSizerAlignment = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Alignment:") ), wxVERTICAL ); //<de>_("Ausrichtung"));
262  wxGridSizer* alignsizer2 = new wxGridSizer( 3 );
263  m_pAlignTL_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_TL, wxBitmap(AlignTL_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
264  alignsizer2->Add( m_pAlignTL_Bt, 0, 0, 0 );
265  m_pAlignT_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_T, wxBitmap(AlignT_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
266  alignsizer2->Add( m_pAlignT_Bt, 0, 0, 0 );
267  m_pAlignTR_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_TR, wxBitmap(AlignTR_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
268  alignsizer2->Add( m_pAlignTR_Bt, 0, 0, 0 );
269  m_pAlignL_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_L, wxBitmap(AlignL_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
270  alignsizer2->Add( m_pAlignL_Bt, 0, 0, 0 );
271  m_pAlignC_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_C, wxBitmap(AlignC_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
272  alignsizer2->Add( m_pAlignC_Bt, 0, 0, 0 );
273  m_pAlignR_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_R, wxBitmap(AlignR_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
274  alignsizer2->Add( m_pAlignR_Bt, 0, 0, 0 );
275  m_pAlignBL_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_BL, wxBitmap(AlignBL_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
276  alignsizer2->Add( m_pAlignBL_Bt, 0, 0, 0 );
277  m_pAlignB_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_B, wxBitmap(AlignB_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
278  alignsizer2->Add( m_pAlignB_Bt, 0, 0, 0 );
279  m_pAlignBR_Bt = new wxBitmapToggleButton(this, wxID_ALIGN_BR, wxBitmap(AlignBR_xpm), wxDefaultPosition, wxSize(24, 24), wxBU_EXACTFIT);
280  alignsizer2->Add( m_pAlignBR_Bt, 0, 0, 0 );
281 
282  //Align on bbox
283  pStaticBoxSizerAlignment->Add( alignsizer2, 0, wxALL | wxEXPAND, 5 );
284  m_aligncheck = new wxCheckBox( this, wxID_CHECK_ALIGN, _( "Align on bbox" ) );
285  pStaticBoxSizerAlignment->Add( m_aligncheck, 0, 0 );
286  bottomsizer->Add( pStaticBoxSizerAlignment, 0, wxALL | wxEXPAND, 5 );
287 #ifndef a2dSHOW_ALL_SETTINGS
288  m_aligncheck->Hide(); // not changable by user
289 #endif // a2dSHOW_ALL_SETTINGS
290 
291 
292  //Sample
293  wxStaticBoxSizer* pStaticBoxSizerPreview = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Sample:") ), wxVERTICAL ); //<de>_("Vorschau"));
294  m_canvas = new a2dCanvas( this, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER );
295  m_canvas->SetYaxis( true );
296  m_canvas->SetScaleOnResize( false );
297  a2dCanvasObject* root = m_canvas->GetDrawing()->GetRootObject();
298  m_canvastext = new a2dText( _T( "AaBbCc12" ) );
299  m_canvastext->SetPosXY( 0.0, 0.0 );
300  m_canvastext->SetFill( *a2dTRANSPARENT_FILL );
301  m_canvastext->SetStroke( *wxBLACK );
302  root->Append( m_canvastext );
303  m_canvasline1 = new a2dSLine( 0.0, 0.0, 1.0, 0.0 );
304  m_canvasline1->SetStroke( wxColour( 0xc0, 0xc0, 0xc0 ), 1 );
305  root->Append( m_canvasline1 );
306  m_canvasline2 = new a2dSLine( 0.0, 0.0, 0.0, 1.0 );
307  m_canvasline2->SetStroke( wxColour( 0xc0, 0xc0, 0xc0 ), 1 );
308  root->Append( m_canvasline2 );
309  pStaticBoxSizerPreview->Add( m_canvas, 1, wxALL | wxEXPAND, 5 );
310  bottomsizer->Add(pStaticBoxSizerPreview, 1, wxALL | wxEXPAND, 5 );
311 
312  m_pTopSizer->Add( bottomsizer, 0, wxALL | wxEXPAND, 5 );
313 
314 
315  //----------------------------
316  // colours:
317  //----------------------------
318  wxBoxSizer* coloursizer;
319  coloursizer = new wxBoxSizer( wxHORIZONTAL );
320 
321  int spacerwidth=10;
322 
323  //Textcolour
324  wxBoxSizer* textcoloursizer;
325  textcoloursizer = new wxBoxSizer( wxVERTICAL );
326  wxStaticText* pStrokeColorTxt = new wxStaticText( this, wxID_ANY, wxT("Textcolour:"), wxDefaultPosition, wxDefaultSize, 0 );
327  textcoloursizer->Add( pStrokeColorTxt, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 5 );
328  m_pStrokeColorBox = new a2dColorComboBox(this, ID_STROKECOLOR_BOX, false, &m_CustomColors);
329  m_pStrokeColorBox->SetMinSize( wxSize( getwidthsizer_l->GetMinSize().GetWidth()-spacerwidth*2, -1) );
330  textcoloursizer->Add( m_pStrokeColorBox, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
331 
332  //Frame around text
333  m_textframe = new wxCheckBox( this, wxID_CHECK_FRAME, _( "Frame around text" ) );
334  textcoloursizer->Add( m_textframe, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
335 #ifndef a2dSHOW_ALL_SETTINGS
336  m_textframe->Hide(); // not changable by user
337 #endif // a2dSHOW_ALL_SETTINGS
338 
339  coloursizer->Add( textcoloursizer, 0, 0, 0 );
340 
341  coloursizer->Add( spacerwidth, 0, 0, 0, 5 );
342 
343  //Backgroundcolour
344  wxBoxSizer* backgroundcoloursizer;
345  backgroundcoloursizer = new wxBoxSizer( wxVERTICAL );
346  wxStaticText* pFillColorTxt = new wxStaticText( this, wxID_ANY, wxT("Backgroundcolour:"), wxDefaultPosition, wxDefaultSize, 0 );
347  backgroundcoloursizer->Add( pFillColorTxt, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 5 );
348  m_pFillBox = new a2dFillComboBox(this, ID_FILL_BOX, bAllowLayerStyle, &m_CustomColors);
349  m_pFillBox->SetMinSize( wxSize( getwidthsizer_r->GetMinSize().GetWidth()-spacerwidth*2, -1) );
350  if(!m_bFill) m_pFillBox->Disable();
351  backgroundcoloursizer->Add( m_pFillBox, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
352 
353  //Fill text background
354  m_textbackground = new wxCheckBox( this, wxID_CHECK_BACKGROUND, _( "Fill text background" ) );
355  backgroundcoloursizer->Add( m_textbackground, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
356 #ifndef a2dSHOW_ALL_SETTINGS
357  m_textbackground->Hide(); // not changable by user
358 #endif // a2dSHOW_ALL_SETTINGS
359 
360  coloursizer->Add( backgroundcoloursizer, 0, 0, 0 );
361 
362  m_pTopSizer->Add( coloursizer, 0, wxALL, 10 );
363 
364  wxBoxSizer* buttonsizer = new wxBoxSizer( wxHORIZONTAL );
365 #ifdef a2dSHOW_ALL_SETTINGS
366  buttonsizer->Add( new wxButton( this, wxID_FONT_SEARCHPATH, _( "Search Path" ) ), 0, wxALL, 5 ); // not changable by user
367 #endif // a2dSHOW_ALL_SETTINGS
368  buttonsizer->Add( new wxButton( this, wxID_OK, _( "OK" ) ), 0, wxALL, 5 );
369  buttonsizer->Add( new wxButton( this, wxID_CANCEL, _( "Cancel" ) ), 0, wxALL, 5 );
370  m_pTopSizer->Add( buttonsizer, 0, wxALL|wxALIGN_RIGHT, 5 );
371 }
372 
373 void a2dTextPropDlgExt::OnInitDialog(wxInitDialogEvent& event)
374 {
375  // -- set default stroke properties --
376  a2dStroke defaultStroke(*wxBLACK, 0.3, a2dSTROKE_SOLID);
377  defaultStroke.SetJoin(wxJOIN_MITER);
378  defaultStroke.SetCap(wxCAP_BUTT);
379  m_ExtStroke.SetDefault(defaultStroke);
380  //------------------------------------
381 
382  // data to dialog
383  UpdateStrokeData(false);
384 
385  if(m_bFill && m_ExtFill.IsValid())
386  m_pFillBox->SetFill(m_ExtFill.Get());
387 
388  // data to dialog
389  UpdateFontData();
390 
391  GetSizer()->SetSizeHints(this);
392 
393  Centre();
394 }
395 
396 void a2dTextPropDlgExt::UpdateStrokeData(bool bGetFromDlg)
397 {
398  if(bGetFromDlg)
399  {
400  if(m_pStrokeColorBox->IsColorSelected())
401  m_ExtStroke.SetColor(m_pStrokeColorBox->GetColor());
402  }
403  else
404  {
405  if(m_ExtStroke.HasEditableStyle())
406  {
407  m_pStrokeColorBox->Enable();
408  if(m_ExtStroke.IsColorValid())
409  m_pStrokeColorBox->SetColor(m_ExtStroke.GetColor());
410  }
411  else
412  {
413  m_pStrokeColorBox->Disable();
414  m_pStrokeColorBox->SetSelection(-1);
415  }
416  }
417 }
418 
419 void a2dTextPropDlgExt::UpdateFontData()
420 {
421  //update size
422  if(m_ExtFont.IsSizeValid())
423  {
424  wxString sizetext;
425  double size = ( ( m_ExtFont.GetFont().GetFontInfo().GetSize() * m_UnitsScale ) / 25.4 ) * 72; //convert from world size (1/100 mm) to font size (1/72 inch)
426  int remainder = int( ( size+0.05 ) *10 ) % 10; // calc remainder to find out if necessary to show decimal places
427  if( remainder != 0 )
428  sizetext.Printf( wxT( "%.1f" ), size );
429  else
430  sizetext.Printf( wxT( "%.0f" ), size );
431 
432  m_sizeedit->SetValue( sizetext );
433  int itemnr = m_sizelist->FindString( sizetext );
434  m_sizelist->SetSelection( itemnr );
435  if( itemnr != -1 )
436  m_sizelist->SetFirstItem( itemnr ); //workaround because EnsureVisible() is not implemented on msw (otherwise selected element is never visible)
437  }
438 
439  //update type
440  if(m_ExtFont.IsTypeValid())
441  {
442  if ( m_typelist->GetCount() )
443  {
444  int idx = 0;
445  idx = m_typelist->FindString( m_ExtFont.GetFont().GetFontInfo().GetType() );
446  if ( idx == wxNOT_FOUND )
447  idx = 0;
448  m_typelist->SetSelection( idx );
449  }
450  }
451 
452  if(m_ExtFont.IsAlignmentValid())
453  {
454  //update alignment
455  SetAlignment( m_ExtFont.GetAlignment() );
456 
457  //update align on bbox checkbox
458  m_aligncheck->SetValue( ( m_ExtFont.GetAlignment() & wxBASELINE ) > 0 );
459  }
460 
461  if(m_ExtFont.IsTextflagsValid())
462  {
463  //update textframe checkbox
464  m_textframe->SetValue( ( m_ExtFont.GetTextFlags() & a2dText::a2dCANOBJTEXT_FRAME ) > 0 );
465 
466  //update background checkbox
467  m_textbackground->SetValue( ( m_ExtFont.GetTextFlags() & a2dText::a2dCANOBJTEXT_BACKGROUND ) > 0 );
468  }
469 
470  if(m_ExtFont.IsNameValid())
471  {
472  //update font
473  wxString oldname = m_fontlist->GetStringSelection();
474 
475  if ( m_fontlist->GetCount() )
476  {
477  int idx;
478  idx = m_fontlist->FindString( m_ExtFont.GetFont().GetFontInfo().GetName() );
479  if( idx == -1 )
480  idx = m_fontlist->FindString( oldname );
481  if ( idx == wxNOT_FOUND )
482  idx = 0;
483  m_fontlist->SetSelection( idx );
484  if( idx != -1 )
485  m_fontlist->SetFirstItem( idx ); //workaround because EnsureVisible() is not implemented on msw (otherwise selected element is never visible)
486  }
487  }
488 
489  //update the rest
490  wxCommandEvent dummy;
491  if( m_ExtFont.GetFont().GetFontInfo().GetType() != a2dDEFAULT_FONTTYPE ) //when type different to initialized-defaulttype, refill box
492  OnChangeFontType( dummy );
493  else
494  OnChangeFontName( dummy );
495 }
496 
497 void a2dTextPropDlgExt::OnOk(wxCommandEvent& event)
498 {
499  if(m_FontFound == false)
500  {
501  // ----------if no style selected, get only name and size-------------
502  wxString type = m_typelist->GetStringSelection();
503  wxString name = m_fontlist->GetStringSelection();
504  wxString style;
505  wxStringToStringHashMap::const_iterator it;
506  for( it = m_styles.begin(); it != m_styles.end(); ++it )
507  {
508  if( it->second == m_stylelist->GetStringSelection() )
509  {
510  style = it->first;
511  break;
512  }
513  }
514  wxArrayString fonts;
515  for ( size_t i = 0; i < m_fonts->GetCount(); i++ )
516  {
517  wxString fonttype = m_fonts->Item( i )->GetData()->GetType();
518  wxString fontname = m_fonts->Item( i )->GetData()->GetName();
519  wxString fontstyle = m_fonts->Item( i )->GetData()->GetStyle();
520  if ( ( fonttype == type || type == _( "* (All types)" ) ) // Special case: when style is invalid and font is selected
521  && fontname == name )
522  {
523  double size;
524  m_sizeedit->GetValue().ToDouble( &size );
525  a2dFontInfo fontinfo = *m_fonts->Item( i )->GetData();
526 
527  if( size < 1 || size > MAXSIZE ) // size out of range?
528  size = ( ( m_ExtFont.GetFont().GetFontInfo().GetSize() * m_UnitsScale ) / 25.4 ) * 72; //convert from world size (1/100 mm) to font size (1/72 inch)
529 
530  int round = float ( ( ( ( ( size ) / 72 ) * 25.4 ) / m_UnitsScale ) + 0.5 ); //convert from font size (1/72 inch) to world size (1/100 mm)
531  fontinfo.SetSize( round );
532  m_ExtFont.SetFont( a2dFont::CreateFont( fontinfo ) );
533  m_ExtFont.SetStyleValidity( false );
534  }
535  }
536  // -------------------------------------------------------------------
537  }
538 
539  UpdateStrokeData(true);
540 
541  if(m_bFill && m_pFillBox->IsFillSelected())
542  m_ExtFill.Set(m_pFillBox->GetFill());
543 
544  EndModal(wxID_OK);
545 }
546 
547 void a2dTextPropDlgExt::OnChangeFontType( wxCommandEvent& event )
548 {
549  wxString type = m_typelist->GetStringSelection();
550  wxString oldname = m_fontlist->GetStringSelection();
551 
552  while ( m_fontlist->GetCount() )
553  m_fontlist->Delete( 0 );
554 
555  m_fontlist->Append( GetFontList( type ) );
556 
557  if ( m_fontlist->GetCount() )
558  {
559  int idx;
560  idx = m_fontlist->FindString( m_ExtFont.GetFont().GetFontInfo().GetName() );
561  if( idx == -1 )
562  idx = m_fontlist->FindString( oldname );
563  if ( idx == wxNOT_FOUND )
564  idx = 0;
565  m_fontlist->SetSelection( idx );
566  }
567 
568  OnChangeFontName( event );
569 }
570 
571 void a2dTextPropDlgExt::OnChangeFontName( wxCommandEvent& event )
572 {
573  wxString type = m_typelist->GetStringSelection();
574  wxString name = m_fontlist->GetStringSelection();
575  wxString oldstyle;
576  wxStringToStringHashMap::const_iterator it;
577  for( it = m_styles.begin(); it != m_styles.end(); ++it )
578  {
579  if( it->second == m_stylelist->GetStringSelection() )
580  {
581  oldstyle = it->first;
582  break;
583  }
584  }
585 
586  while ( m_stylelist->GetCount() )
587  m_stylelist->Delete( 0 );
588 
589  if( name != "" ) //only when font selected
590  {
591  m_ExtFont.SetName(name);
592  wxArrayString fonts;
593  for ( size_t i = 0; i < m_fonts->GetCount(); i++ )
594  {
595  wxString fontname = m_fonts->Item( i )->GetData()->GetName();
596  wxString fonttype = m_fonts->Item( i )->GetData()->GetType();
597  wxString fontstyle = m_fonts->Item( i )->GetData()->GetStyle();
598 
599  if ( ( fonttype == type || type == _( "* (All types)" ) )
600  && fontname == name )
601  {
602  size_t j;
603  wxStringToStringHashMap::const_iterator it = m_styles.find( fontstyle );
604  if( it != m_styles.end())
605  {
606  for ( j = 0; j < fonts.GetCount(); j++ )
607  {
608  if ( fonts.Item( j ) == it->second )
609  break;
610  }
611  if ( j == fonts.GetCount() )
612  {
613  fonts.Add( it->second );
614  }
615  }
616  else
617  wxFAIL_MSG( wxString::Format("Fontstyle \"%s\" is unknown.", fontstyle) );
618  }
619  }
620 
621  m_stylelist->Append( fonts );
622  }
623  else //when no font selected -> only insert common styles
624  {
625  wxArrayString mapped_styles, common_styles = m_ExtFont.GetCommonStyle();
626 
627  for( int i=0; i < common_styles.GetCount(); i++ )
628  {
629  wxStringToStringHashMap::const_iterator it = m_styles.find( common_styles[i] );
630  if( it != m_styles.end())
631  {
632  mapped_styles.Add( it->second );
633  }
634  }
635  m_stylelist->Append( mapped_styles );
636  }
637 
638 
639  if ( m_stylelist->GetCount() )
640  {
641  if( m_ExtFont.IsStyleValid() )
642  {
643  int idx;
644 
645  wxStringToStringHashMap::const_iterator it = m_styles.find( m_ExtFont.GetFont().GetFontInfo().GetStyle() );
646  if( it != m_styles.end())
647  idx = m_stylelist->FindString( it->second );
648  else
649  {
650  wxFAIL_MSG( wxString::Format("Fontstyle \"%s\" is unknown.", m_ExtFont.GetFont().GetFontInfo().GetStyle()) );
651  idx = -1;
652  }
653 
654  if( idx != wxNOT_FOUND )
655  {
656  m_stylelist->SetSelection( idx );
657  m_ExtFont.SetStyle( m_ExtFont.GetFont().GetFontInfo().GetStyle() );
658  }
659  }
660  }
661  OnChangeFont();
662 }
663 
664 void a2dTextPropDlgExt::OnChangeFontStyle( wxCommandEvent& event )
665 {
666  wxStringToStringHashMap::const_iterator it;
667  for( it = m_styles.begin(); it != m_styles.end(); ++it )
668  {
669  if( it->second == m_stylelist->GetStringSelection() )
670  {
671  m_ExtFont.SetStyle( it->first );
672  break;
673  }
674  }
675 
676  OnChangeFont();
677 }
678 
679 void a2dTextPropDlgExt::OnChangeFontSize( wxCommandEvent& event )
680 {
681  m_sizelist->SetSelection( wxNOT_FOUND );
682  OnChangeFont();
683 }
684 
685 void a2dTextPropDlgExt::OnChangeFontSizeList( wxCommandEvent& event )
686 {
687  int idx = m_sizelist->GetSelection();
688  m_sizeedit->SetValue( m_sizelist->GetStringSelection() );
689  m_sizelist->SetSelection( idx );
690 
691  double size;
692  m_sizelist->GetStringSelection().ToDouble( &size );
693  int round = float ( ( ( ( ( size ) / 72 ) * 25.4 ) / m_UnitsScale ) + 0.5 ); //convert from font size (1/72 inch) to world size (1/100 mm)
694  m_ExtFont.SetSize( round );
695  OnChangeFont();
696 }
697 
699 {
700  wxString type = m_typelist->GetStringSelection();
701  wxString name = m_fontlist->GetStringSelection();
702  wxString style;
703  wxStringToStringHashMap::const_iterator it;
704  for( it = m_styles.begin(); it != m_styles.end(); ++it )
705  {
706  if( it->second == m_stylelist->GetStringSelection() )
707  {
708  style = it->first;
709  break;
710  }
711  }
712 
713  wxArrayString fonts;
714  m_FontFound = false;
715 
716  bool use_temp_font = false;
717  a2dFontInfo valid_font, temp_font;
718  for ( size_t i = 0; i < m_fonts->GetCount(); i++ )
719  {
720  wxString fonttype = m_fonts->Item( i )->GetData()->GetType();
721  wxString fontname = m_fonts->Item( i )->GetData()->GetName();
722  wxString fontstyle = m_fonts->Item( i )->GetData()->GetStyle();
723  if ( ( fonttype == type || type == _( "* (All types)" ) )
724  && fontname == name && fontstyle == style )
725  {
726  valid_font = *m_fonts->Item( i )->GetData();
727  m_FontFound = true;
728  break;
729  }
730 
731  if ( ( fonttype == type || type == _( "* (All types)" ) )
732  && fontname == name && style == wxT("") )
733  {
734  if ( !use_temp_font || fontstyle == wxT("Regular"))
735  {
736  use_temp_font = true;
737  temp_font = *m_fonts->Item( i )->GetData();
738  }
739  }
740  }
741 
742  //-------------------Prepare sample------------------------
743 
744  double size;
745  m_sizeedit->GetValue().ToDouble( &size );
746  if( size < 1 || size > MAXSIZE ) // size out of range?
747  size = ( ( m_ExtFont.GetFont().GetFontInfo().GetSize() * m_UnitsScale ) / 25.4 ) * 72; //convert from world size (1/100 mm) to font size (1/72 inch)
748 
749  // Prepare font for sample
750  if( m_FontFound )
751  {
752  int round = float ( ( ( ( ( size ) / 72 ) * 25.4 ) / m_UnitsScale ) + 0.5 ); //convert from font size (1/72 inch) to world size (1/100 mm)
753  valid_font.SetSize( round );
754  m_ExtFont.SetFont( a2dFont::CreateFont( valid_font ) );
755 
756  m_canvastext->SetFont( m_ExtFont.GetFont() );
757  }
758  else
759  {
760  if( use_temp_font )
761  {
762  int round = float ( ( ( ( ( size ) / 72 ) * 25.4 ) / m_UnitsScale ) + 0.5 ); //convert from font size (1/72 inch) to world size (1/100 mm)
763  temp_font.SetSize( ( ( ( size ) / 72 ) * 25.4 ) / round );
764  m_canvastext->SetFont( a2dFont::CreateFont( temp_font ) );
765  }
766  else
767  m_canvastext->SetFont( m_habitat->GetTextTemplateObject()->GetFont() );
768  }
769 
770  m_canvastext->SetPending( true );
771 
772  // Prepare alignment and textflags for sample
773  if( m_ExtFont.IsAlignmentValid() )
774  {
775  m_canvastext->SetAlignment( m_ExtFont.GetAlignment() );
776  m_canvastext->SetTextFlags( m_ExtFont.GetTextFlags() );
777  }
778  else
779  {
780  m_canvastext->SetAlignment( wxMAXY | wxMINX | wxBASELINE_CONTRA );
782  }
783 
784  // Prepare stroke for sample
785  if( m_pStrokeColorBox->IsColorSelected() )
786  m_canvastext->SetStroke( m_pStrokeColorBox->GetColor() );
787  else // if mixed and not the same colour, set wxBLACK as default
788  m_canvastext->SetStroke( wxColour( *wxBLACK ) );
789 
790  a2dBoundingBox bbox = m_canvastext->GetCalculatedBoundingBox( 1 );
791  RepaintSample();
792  //------------------------------------------------------------
793 
794 }
795 
796 void a2dTextPropDlgExt::OnSearchPath( wxCommandEvent& event )
797 {
799  if ( dlg.ShowModal() == wxID_OK )
800  {
801  m_fonts->Clear();
802  a2dFont::GetInfoList( *m_fonts );
803 
804  wxString oldtype = m_typelist->GetStringSelection();
805 
806  while ( m_typelist->GetCount() )
807  m_typelist->Delete( 0 );
808  wxArrayString types;
809  types.Add( _( "* (All types)" ) );
810  for ( size_t i = 0; i < m_fonts->GetCount(); i++ )
811  {
812  wxString type = m_fonts->Item( i )->GetData()->GetType();
813  size_t j;
814  for ( j = 0; j < types.GetCount(); j++ )
815  {
816  if ( types.Item( j ) == type )
817  break;
818  }
819  if ( j == types.GetCount() )
820  types.Add( type );
821  }
822  m_typelist->Append( types );
823 
824  if ( m_typelist->GetCount() )
825  {
826  int idx = m_typelist->FindString( oldtype );
827  if ( idx == wxNOT_FOUND )
828  idx = 0;
829  m_typelist->SetSelection( idx );
830  }
831  OnChangeFontType( event );
832  }
833 }
834 
835 void a2dTextPropDlgExt::OnAlignment( wxCommandEvent& event )
836 {
837  switch( event.GetId() )
838  {
839  case wxID_ALIGN_TL: m_ExtFont.SetAlignment( wxMAXY | wxMINX ); break;
840  case wxID_ALIGN_T: m_ExtFont.SetAlignment( wxMAXY ); break;
841  case wxID_ALIGN_TR: m_ExtFont.SetAlignment( wxMAXY | wxMAXX ); break;
842  case wxID_ALIGN_L: m_ExtFont.SetAlignment( wxMINX ); break;
843  case wxID_ALIGN_C: m_ExtFont.SetAlignment( wxMIDX | wxMIDY ); break;
844  case wxID_ALIGN_R: m_ExtFont.SetAlignment( wxMAXX ); break;
845  case wxID_ALIGN_BL: m_ExtFont.SetAlignment( wxMINY | wxMINX ); break;
846  case wxID_ALIGN_B: m_ExtFont.SetAlignment( wxMINY ); break;
847  case wxID_ALIGN_BR: m_ExtFont.SetAlignment( wxMINY | wxMAXX ); break;
848  default: ;
849  }
850 
851  if ( m_aligncheck->IsChecked() )
852  {
853  m_ExtFont.SetAlignment( m_ExtFont.GetAlignment() | wxBASELINE );
854  m_ExtFont.SetAlignment( m_ExtFont.GetAlignment() & ~wxBASELINE_CONTRA );
855  }
856  else
857  {
858  m_ExtFont.SetAlignment( m_ExtFont.GetAlignment() | wxBASELINE_CONTRA );
859  m_ExtFont.SetAlignment( m_ExtFont.GetAlignment() & ~wxBASELINE );
860  }
861 
862  SetAlignment( m_ExtFont.GetAlignment() );
863 
864  OnChangeFont();
865 }
866 
867 void a2dTextPropDlgExt::OnTextflags( wxCommandEvent& event )
868 {
869  if ( m_textframe->IsChecked() )
870  m_ExtFont.SetTextFlags( m_ExtFont.GetTextFlags() | a2dText::a2dCANOBJTEXT_FRAME );
871  else
872  m_ExtFont.SetTextFlags( m_ExtFont.GetTextFlags() & ~a2dText::a2dCANOBJTEXT_FRAME );
873 
874  if ( m_textbackground->IsChecked() )
875  m_ExtFont.SetTextFlags( m_ExtFont.GetTextFlags() | a2dText::a2dCANOBJTEXT_BACKGROUND );
876  else
877  m_ExtFont.SetTextFlags( m_ExtFont.GetTextFlags() & ~a2dText::a2dCANOBJTEXT_BACKGROUND );
878 
879  OnChangeFont();
880 }
881 
882 void a2dTextPropDlgExt::OnSize( wxSizeEvent& event )
883 {
884  event.Skip();
885  RepaintSample();
886 }
887 
888 void a2dTextPropDlgExt::OnColourChange( wxCommandEvent& event )
889 {
890  OnChangeFont();
891 }
892 
893 // Returns a list of fonts for the given type
894 wxArrayString a2dTextPropDlgExt::GetFontList(wxString type)
895 {
896  wxArrayString fonts;
897  for ( size_t i = 0; i < m_fonts->GetCount(); i++ )
898  {
899  wxString fonttype = m_fonts->Item( i )->GetData()->GetType();
900  if ( fonttype == type || type == _( "* (All types)" ) )
901  {
902  wxString fontname = m_fonts->Item( i )->GetData()->GetName();
903  size_t j;
904  for ( j = 0; j < fonts.GetCount(); j++ )
905  {
906  if ( fonts.Item( j ) == fontname )
907  break;
908  }
909  if ( j == fonts.GetCount() )
910  fonts.Add( fontname );
911  }
912  }
913  return fonts;
914 }
915 
916 // Returns the longest style-string of all fonts (needed to initialize the size of style-listbox)
917 wxString a2dTextPropDlgExt::GetLongestStyle()
918 {
919  wxString longeststyle = "";
920  for ( size_t i = 0; i < m_fonts->GetCount(); i++ )
921  {
922  wxString fontname = m_fonts->Item( i )->GetData()->GetName();
923  wxString fonttype = m_fonts->Item( i )->GetData()->GetType();
924  wxString fontstyle = m_fonts->Item( i )->GetData()->GetStyle();
925 
926  wxStringToStringHashMap::const_iterator it = m_styles.find( fontstyle );
927  if( it != m_styles.end())
928  {
929  if( it->second.Length() > longeststyle.Length() ) //find out longest style-string to initialize listbox with correct width
930  longeststyle = it->second;
931  }
932  }
933  return longeststyle;
934 }
935 
936 void a2dTextPropDlgExt::RepaintSample()
937 {
938  a2dBoundingBox bbox = m_canvastext->GetCalculatedBoundingBox( 1 );
939 
940  m_canvasline1->SetPosXY12( -2.0 * bbox.GetWidth(), 0.0, 2.0 * bbox.GetWidth(), 0.0 );
941  m_canvasline2->SetPosXY12( 0.0, -2.0 * bbox.GetWidth(), 0.0, 2.0 * bbox.GetWidth() );
942 
943  // To have some better visual feedback of alignment, move the text around a little.
944  a2dBoundingBox bboxnew = bbox;
945  bboxnew.Enlarge( bbox.GetHeight() / 6.0 );
946  if ( m_ExtFont.GetAlignment() & wxMINX )
947  bboxnew.Translate( -bbox.GetHeight() / 8.0, 0.0 );
948  if ( m_ExtFont.GetAlignment() & wxMAXX )
949  bboxnew.Translate( bbox.GetHeight() / 8.0, 0.0 );
950 
951  if ( m_ExtFont.GetAlignment() & wxMINY )
952  bboxnew.Translate( 0.0, -bbox.GetHeight() / 8.0 );
953  if ( m_ExtFont.GetAlignment() & wxMAXY )
954  bboxnew.Translate( 0.0, bbox.GetHeight() / 8.0 );
955 
956  if( m_pFillBox->GetFill().IsNoFill() ) // if mixed and not the same colour, set a2dTRANSPARENT_FILL as default
957  m_canvastext->SetFill( *a2dTRANSPARENT_FILL );
958  else
959  {
960  if ( m_ExtFont.GetAlignment() & wxBASELINE )
961  m_canvastext->SetFill( m_pFillBox->GetFill() );
962  if ( m_ExtFont.GetAlignment() & wxBASELINE_CONTRA )
963  m_canvastext->SetFill( m_pFillBox->GetFill() );
964  else
965  m_canvastext->SetFill( *a2dTRANSPARENT_FILL );
966  }
967 
968  m_canvas->SetMappingWidthHeight ( bboxnew.GetMinX(), bboxnew.GetMinY(),
969  bboxnew.GetWidth(), bboxnew.GetHeight(), false );
970  m_canvas->Refresh();
971 }
972 
973 // Sets the correct alignment button
974 void a2dTextPropDlgExt::SetAlignment(int align)
975 {
976  switch(align & 15)
977  {
978  case wxMAXY | wxMINX:
979  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTLPressed_xpm));
980  m_pAlignTL_Bt->SetValue(true);
981  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
982  m_pAlignT_Bt->SetValue(false);
983  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
984  m_pAlignTR_Bt->SetValue(false);
985  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
986  m_pAlignL_Bt->SetValue(false);
987  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
988  m_pAlignC_Bt->SetValue(false);
989  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
990  m_pAlignR_Bt->SetValue(false);
991  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
992  m_pAlignBL_Bt->SetValue(false);
993  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
994  m_pAlignB_Bt->SetValue(false);
995  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
996  m_pAlignBR_Bt->SetValue(false);
997  break;
998  case wxMAXY:
999  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1000  m_pAlignTL_Bt->SetValue(false);
1001  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignTPressed_xpm));
1002  m_pAlignT_Bt->SetValue(true);
1003  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1004  m_pAlignTR_Bt->SetValue(false);
1005  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1006  m_pAlignL_Bt->SetValue(false);
1007  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1008  m_pAlignC_Bt->SetValue(false);
1009  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1010  m_pAlignR_Bt->SetValue(false);
1011  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1012  m_pAlignBL_Bt->SetValue(false);
1013  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1014  m_pAlignB_Bt->SetValue(false);
1015  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1016  m_pAlignBR_Bt->SetValue(false);
1017  break;
1018  case wxMAXY | wxMAXX:
1019  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1020  m_pAlignTL_Bt->SetValue(false);
1021  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1022  m_pAlignT_Bt->SetValue(false);
1023  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTRPressed_xpm));
1024  m_pAlignTR_Bt->SetValue(true);
1025  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1026  m_pAlignL_Bt->SetValue(false);
1027  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1028  m_pAlignC_Bt->SetValue(false);
1029  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1030  m_pAlignR_Bt->SetValue(false);
1031  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1032  m_pAlignBL_Bt->SetValue(false);
1033  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1034  m_pAlignB_Bt->SetValue(false);
1035  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1036  m_pAlignBR_Bt->SetValue(false);
1037  break;
1038  case wxMINX:
1039  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1040  m_pAlignTL_Bt->SetValue(false);
1041  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1042  m_pAlignT_Bt->SetValue(false);
1043  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1044  m_pAlignTR_Bt->SetValue(false);
1045  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignLPressed_xpm));
1046  m_pAlignL_Bt->SetValue(true);
1047  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1048  m_pAlignC_Bt->SetValue(false);
1049  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1050  m_pAlignR_Bt->SetValue(false);
1051  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1052  m_pAlignBL_Bt->SetValue(false);
1053  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1054  m_pAlignB_Bt->SetValue(false);
1055  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1056  m_pAlignBR_Bt->SetValue(false);
1057  break;
1058  case wxMIDX | wxMIDY:
1059  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1060  m_pAlignTL_Bt->SetValue(false);
1061  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1062  m_pAlignT_Bt->SetValue(false);
1063  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1064  m_pAlignTR_Bt->SetValue(false);
1065  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1066  m_pAlignL_Bt->SetValue(false);
1067  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignCPressed_xpm));
1068  m_pAlignC_Bt->SetValue(true);
1069  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1070  m_pAlignR_Bt->SetValue(false);
1071  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1072  m_pAlignBL_Bt->SetValue(false);
1073  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1074  m_pAlignB_Bt->SetValue(false);
1075  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1076  m_pAlignBR_Bt->SetValue(false);
1077  break;
1078  case wxMAXX:
1079  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1080  m_pAlignTL_Bt->SetValue(false);
1081  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1082  m_pAlignT_Bt->SetValue(false);
1083  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1084  m_pAlignTR_Bt->SetValue(false);
1085  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1086  m_pAlignL_Bt->SetValue(false);
1087  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1088  m_pAlignC_Bt->SetValue(false);
1089  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignRPressed_xpm));
1090  m_pAlignR_Bt->SetValue(true);
1091  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1092  m_pAlignBL_Bt->SetValue(false);
1093  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1094  m_pAlignB_Bt->SetValue(false);
1095  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1096  m_pAlignBR_Bt->SetValue(false);
1097  break;
1098  case wxMINY | wxMINX:
1099  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1100  m_pAlignTL_Bt->SetValue(false);
1101  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1102  m_pAlignT_Bt->SetValue(false);
1103  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1104  m_pAlignTR_Bt->SetValue(false);
1105  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1106  m_pAlignL_Bt->SetValue(false);
1107  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1108  m_pAlignC_Bt->SetValue(false);
1109  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1110  m_pAlignR_Bt->SetValue(false);
1111  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBLPressed_xpm));
1112  m_pAlignBL_Bt->SetValue(true);
1113  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1114  m_pAlignB_Bt->SetValue(false);
1115  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1116  m_pAlignBR_Bt->SetValue(false);
1117  break;
1118  case wxMINY:
1119  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1120  m_pAlignTL_Bt->SetValue(false);
1121  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1122  m_pAlignT_Bt->SetValue(false);
1123  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1124  m_pAlignTR_Bt->SetValue(false);
1125  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1126  m_pAlignL_Bt->SetValue(false);
1127  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1128  m_pAlignC_Bt->SetValue(false);
1129  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1130  m_pAlignR_Bt->SetValue(false);
1131  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1132  m_pAlignBL_Bt->SetValue(false);
1133  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignBPressed_xpm));
1134  m_pAlignB_Bt->SetValue(true);
1135  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1136  m_pAlignBR_Bt->SetValue(false);
1137  break;
1138  case wxMINY | wxMAXX:
1139  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1140  m_pAlignTL_Bt->SetValue(false);
1141  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1142  m_pAlignT_Bt->SetValue(false);
1143  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1144  m_pAlignTR_Bt->SetValue(false);
1145  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1146  m_pAlignL_Bt->SetValue(false);
1147  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1148  m_pAlignC_Bt->SetValue(false);
1149  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1150  m_pAlignR_Bt->SetValue(false);
1151  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1152  m_pAlignBL_Bt->SetValue(false);
1153  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1154  m_pAlignB_Bt->SetValue(false);
1155  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBRPressed_xpm));
1156  m_pAlignBR_Bt->SetValue(true);
1157  break;
1158  default:
1159  m_pAlignTL_Bt->SetBitmap(wxBitmap(AlignTL_xpm));
1160  m_pAlignTL_Bt->SetValue(false);
1161  m_pAlignT_Bt->SetBitmap(wxBitmap(AlignT_xpm));
1162  m_pAlignT_Bt->SetValue(false);
1163  m_pAlignTR_Bt->SetBitmap(wxBitmap(AlignTR_xpm));
1164  m_pAlignTR_Bt->SetValue(false);
1165  m_pAlignL_Bt->SetBitmap(wxBitmap(AlignL_xpm));
1166  m_pAlignL_Bt->SetValue(false);
1167  m_pAlignC_Bt->SetBitmap(wxBitmap(AlignC_xpm));
1168  m_pAlignC_Bt->SetValue(false);
1169  m_pAlignR_Bt->SetBitmap(wxBitmap(AlignR_xpm));
1170  m_pAlignR_Bt->SetValue(false);
1171  m_pAlignBL_Bt->SetBitmap(wxBitmap(AlignBL_xpm));
1172  m_pAlignBL_Bt->SetValue(false);
1173  m_pAlignB_Bt->SetBitmap(wxBitmap(AlignB_xpm));
1174  m_pAlignB_Bt->SetValue(false);
1175  m_pAlignBR_Bt->SetBitmap(wxBitmap(AlignBR_xpm));
1176  m_pAlignBR_Bt->SetValue(false);
1177  break;
1178  };
1179 }
1180 
1181 
1182 wxUint32 a2dSetTextChanges( a2dTextChanges& returned, a2dCanvasObjectList* objects, a2dCanvasObjectFlagsMask mask, a2dLayers* layersetup )
1183 {
1184  int nr = 0;
1185  forEachIn( a2dCanvasObjectList, objects )
1186  {
1187  a2dCanvasObject* obj = *iter;
1188  a2dText* text = wxDynamicCast( obj, a2dText );
1189 
1190  if ( obj->GetFixedStyle() || obj->GetRelease() || !obj->CheckMask( mask ) || !text )
1191  continue;
1192 
1193  obj->SetBin2( true );
1194 
1195  a2dFont font = text->GetFont();
1196 
1197  if ( !nr )
1198  {
1199  returned.Set( font, text->GetTextFlags(), text->GetAlignment(), text->GetWrongLoad() );
1200  }
1201  else
1202  returned.Mix( font, text->GetTextFlags(), text->GetAlignment() );
1203 
1204  // when font not existing, set name and style invalide that nothing is selected in dialog
1205  if( text->GetWrongLoad() )
1206  {
1207  returned.SetNameValidity( false );
1208  returned.SetStyleValidity( false );
1209  }
1210  nr++;
1211  }
1212  return nr;
1213 }
double GetHeight() const
returns height of the boundingbox
Definition: bbox.cpp:334
all basic primitives derived from a2dCanvasObject
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
void OnChangeFontSize(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:679
const wxString & GetName() const
Get name of font, e.g. Arial.
Definition: stylebase.h:717
bool GetWrongLoad() const
Get flag if text couldn&#39;t be loadad from file.
Definition: cantext.h:184
void SetAlignment(int alignment)
Set the position of the anchor point w.r.t the text.
Definition: cantext.h:294
Font info class, used as a single element for enumerating fonts.
Definition: stylebase.h:686
disable background drawing
Definition: cantext.h:109
void SetPosXY12(double x1, double y1, double x2, double y2, bool afterinversion=true)
sets both positions of line
Definition: canprim.cpp:3932
void OnChangeFontSizeList(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:685
void OnSearchPath(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:796
void OnColourChange(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:888
a2dCanvasObject * GetRootObject() const
get the root object, which holds the objects in the document
Definition: drawing.h:521
double GetSize() const
Get size of the font.
Definition: stylebase.h:727
allow draw a frame rect around a text
Definition: cantext.h:111
void Enlarge(const double Marge)
enlarge with the given amount
Definition: bbox.cpp:162
void OnChangeFont()
User interface event handler.
Definition: fontdlg2.cpp:698
void OnAlignment(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:835
a2dBoundingBox GetCalculatedBoundingBox(int nChildLevels)
Like GetBbox, but it always calculcates the bounding box from scratch.
Definition: canobj.cpp:5072
Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
Definition: stylebase.h:779
virtual void SetPending(bool pending)
set this object pending for update
Definition: canobj.cpp:2585
bool IsNoFill() const
Definition: stylebase.h:273
void SetSize(double size)
Set the size.
Definition: cantext.h:608
void SetYaxis(bool up)
set if the Yaxis goes up or down
Definition: canvas.cpp:1011
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
a2dCanvas uses a2dCanvasView for displaying a view on a a2dCanvasDocument.
a2dFont GetFont() const
get font for text
Definition: cantext.h:251
wxUint64 a2dCanvasObjectFlagsMask
mask flags for a2dCanvasObject
Definition: candefs.h:152
a2dText is an abstract base class.
Definition: cantext.h:93
const wxString & GetType() const
Get type of font, e.g. Freetype or Stroke.
Definition: stylebase.h:712
const a2dBoundingBox & Translate(a2dPoint2D &)
translate with given vector
Definition: bbox.cpp:370
void SetName(wxString name)
Set the font name.
Definition: cantext.h:598
double GetMinX() const
get minimum X of the boundingbox
Definition: bbox.cpp:304
void OnTextflags(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:867
void SetMappingWidthHeight(double vx1, double vy1, double width, double height, bool scrollbars)
Give the virtual size to be displayed, the mappingmatrix will be calculated.
Definition: canvas.cpp:503
void SetFont(const a2dFont &font, double lineSpaceFactor=0.1)
set font for text
Definition: cantext.cpp:527
#define forEachIn(listtype, list)
easy iteration for a2dlist
Definition: a2dlist.h:111
static void GetInfoList(a2dFontInfoList &list)
Append fonts of this type to the list.
Definition: stylebase.cpp:3156
a2dSLine
Definition: canprim.h:987
void OnChangeFontName(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:571
void SetStyle(wxString style)
Set the font style.
Definition: cantext.h:588
static a2dFont CreateFont(const a2dFontInfo &info, bool force=false)
Create the font from a fontinfo description.
Definition: stylebase.cpp:3163
bool CheckMask(a2dCanvasObjectFlagsMask mask) const
Compares all flags in object to the given mask and return true is the same.
Definition: canobj.cpp:2665
void SetScaleOnResize(bool val)
set if the drawing should be resclaed on a window resize
Definition: canvas.h:207
defines common settinsg for a habitat for a set of a2dCameleons.
Definition: canglob.h:439
unsigned int GetTextFlags() const
Get the text flags.
Definition: cantext.h:195
Display a dialog to edit the font search path.
Definition: fontdlg.h:30
a2dCanvas is used to display one of the a2dCanvasObjects which are part of a a2dCanvasDocument object...
Definition: canvas.h:68
bool GetFixedStyle() const
Get object fixed style setting.
Definition: canobj.h:1590
Contains graphical drawing context specific classes. a2dDrawer2D and derived classes are used for dra...
void SetSize(double size)
Set size of the font.
Definition: stylebase.h:735
void SetStroke(const wxColour &strokecolor, double width=0, a2dStrokeStyle style=a2dSTROKE_SOLID)
Set a stroke for the object which will be used instead of the layer stroke.
Definition: canobj.cpp:2924
void SetTextFlags(unsigned int textflags)
Set the text flags.
Definition: cantext.h:618
bool GetRelease() const
get release flag
Definition: gen.h:1350
void SetTextFlags(unsigned int textflags)
Set the text flags.
Definition: cantext.h:193
dialog for choosing fonts
double GetWidth() const
returns width of the boundingbox
Definition: bbox.cpp:328
const wxString & GetStyle() const
Get style of font, e.g. Bold.
Definition: stylebase.h:722
void SetPosXY(double x, double y, bool restrict=false)
set position to x,y
Definition: canobj.cpp:1624
A list used for enumerating fonts.
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
all polygon and polyline a2dCanvasObject are here.
double GetMinY() const
get minimum Y of the boundingbox
Definition: bbox.cpp:310
int GetAlignment() const
Get the position of the anchor point w.r.t the text.
Definition: cantext.h:304
const a2dFontInfo & GetFontInfo() const
Get fontinfo of the font.
Definition: stylebase.cpp:2901
void OnSize(wxSizeEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:882
void SetAlignment(int alignment)
Set the position of the anchor point w.r.t the text.
Definition: cantext.h:625
void Append(a2dCanvasObject *obj)
append a a2dCanvasObject to the childobjects
Definition: canobj.cpp:6224
a2dText * GetTextTemplateObject()
set template for line object
Definition: canglob.h:920
void OnChangeFontType(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:547
void SetFill(const a2dFill &fill)
Set a fill for the object which will be used instead of the layer fill.
Definition: canobj.cpp:2874
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
Refresh window.
Definition: canvas.cpp:265
void OnChangeFontStyle(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg2.cpp:664
const a2dFill * a2dTRANSPARENT_FILL
global a2dFill stock object for TRANSPARENT filling
general canvas module declarations and classes
fontdlg2.cpp Source File -- Sun Oct 12 2014 17:04:20 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation