wxArt2D
fontdlg.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 //-----------------------------------------------------------------------------
28 // a2dFontSearchPathDialog
29 //-----------------------------------------------------------------------------
30 
31 enum
32 {
33  wxID_PATHLIST = wxID_HIGHEST + 1,
34  wxID_PATHEDIT,
35  wxID_PATHBUTTON
36 };
37 
38 IMPLEMENT_DYNAMIC_CLASS( a2dFontSearchPathDialog, wxDialog )
39 
40 BEGIN_EVENT_TABLE( a2dFontSearchPathDialog, wxDialog )
41  EVT_BUTTON( wxID_NEW, a2dFontSearchPathDialog::OnAdd )
42  EVT_BUTTON( wxID_DELETE, a2dFontSearchPathDialog::OnDelete )
43  EVT_BUTTON( wxID_OK, a2dFontSearchPathDialog::OnOK )
44  EVT_BUTTON( wxID_PATHBUTTON, a2dFontSearchPathDialog::OnPathButton )
45  EVT_LISTBOX( wxID_PATHLIST, a2dFontSearchPathDialog::OnListBox )
46  EVT_TEXT( wxID_PATHEDIT, a2dFontSearchPathDialog::OnText )
47 END_EVENT_TABLE()
48 
49 a2dFontSearchPathDialog::a2dFontSearchPathDialog( wxWindow* parent )
50  : wxDialog( parent, -1, _( "Font Search Path" ), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
51 {
52  wxBoxSizer* topsizer = new wxBoxSizer( wxVERTICAL );
53 
54  wxArrayString paths;
55  wxPathList& pathlist = a2dGlobals->GetFontPathList();
56 #if wxCHECK_VERSION(2,7,0)
57  for ( wxPathList::iterator node = pathlist.begin(); node != pathlist.end(); node++ )
58 #else
59  for ( wxPathList::compatibility_iterator node = pathlist.GetFirst(); node; node = node->GetNext() )
60 #endif
61  paths.Add( node->GetData() );
62  m_listbox = new wxListBox( this, wxID_PATHLIST, wxDefaultPosition, wxDefaultSize, paths );
63  topsizer->Add( m_listbox, 1, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 10 );
64 
65  wxBoxSizer* editsizer = new wxBoxSizer( wxHORIZONTAL );
66  m_textctrl = new wxTextCtrl( this, wxID_PATHEDIT, wxT( "" ) );
67  editsizer->Add( m_textctrl, 1, wxEXPAND, 0 );
68  m_button = new wxButton( this, wxID_PATHBUTTON, wxT( "..." ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
69  editsizer->Add( m_button, 0, wxEXPAND, 0 );
70  topsizer->Add( editsizer, 0, wxBOTTOM | wxLEFT | wxRIGHT | wxEXPAND, 10 );
71 
72  wxBoxSizer* buttonsizer = new wxBoxSizer( wxHORIZONTAL );
73 
74  wxBoxSizer* adddelsizer = new wxBoxSizer( wxHORIZONTAL );
75  adddelsizer->Add( new wxButton( this, wxID_NEW, _( "Add" ) ), 0, wxRIGHT, 10 );
76  adddelsizer->Add( new wxButton( this, wxID_DELETE, _( "Delete" ) ), 0, 0, 0 );
77  buttonsizer->Add( adddelsizer, 1, wxRIGHT | wxEXPAND, 30 );
78 
79  buttonsizer->Add( new wxButton( this, wxID_OK, _( "OK" ) ), 0, wxRIGHT, 10 );
80  buttonsizer->Add( new wxButton( this, wxID_CANCEL, _( "Cancel" ) ), 0, 0, 0 );
81  topsizer->Add( buttonsizer, 0, wxLEFT | wxBOTTOM | wxRIGHT | wxEXPAND, 10 );
82 
83  SetSizer( topsizer );
84  topsizer->SetSizeHints( this );
85 }
86 
88 {
89 }
90 
91 void a2dFontSearchPathDialog::OnAdd( wxCommandEvent& WXUNUSED( event ) )
92 {
93  m_listbox->Append( m_textctrl->GetValue() );
94 }
95 
96 void a2dFontSearchPathDialog::OnPathButton( wxCommandEvent& WXUNUSED( event ) )
97 {
98  const wxString& dir = wxDirSelector( _( "Choose a folder" ) );
99  if ( !dir.empty() )
100  m_textctrl->SetValue( dir );
101 }
102 
103 void a2dFontSearchPathDialog::OnDelete( wxCommandEvent& WXUNUSED( event ) )
104 {
105  int idx = m_listbox->GetSelection();
106  if ( idx != wxNOT_FOUND )
107  m_listbox->Delete( idx );
108  m_textctrl->SetValue( wxT( "" ) );
109 }
110 
111 void a2dFontSearchPathDialog::OnListBox( wxCommandEvent& WXUNUSED( event ) )
112 {
113  int idx = m_listbox->GetSelection();
114  m_textctrl->SetValue( m_listbox->GetStringSelection() );
115  m_listbox->SetSelection( idx );
116 }
117 
118 void a2dFontSearchPathDialog::OnOK( wxCommandEvent& event )
119 {
120  wxPathList& pathlist = a2dGlobals->GetFontPathList();
121  pathlist.Clear();
122  for ( unsigned int i = 0; i < m_listbox->GetCount(); i++ )
123  pathlist.Add( m_listbox->GetString( i ) );
124 #if wxCHECK_VERSION(2,7,0)
125  AcceptAndClose();
126 #else
127  wxDialog::OnOK( event );
128 #endif
129 }
130 
131 void a2dFontSearchPathDialog::OnText( wxCommandEvent& WXUNUSED( event ) )
132 {
133  m_listbox->SetSelection( wxNOT_FOUND );
134 }
135 
136 //-----------------------------------------------------------------------------
137 // a2dTextPropDlg
138 //-----------------------------------------------------------------------------
139 
140 enum
141 {
142  wxID_FONTTYPE_LIST = wxID_HIGHEST + 1,
143  wxID_FONTNAME_LIST,
144  wxID_FONTSTYLE_LIST,
145  wxID_FONTSIZE_EDIT,
146  wxID_FONTSIZE_LIST,
147  wxID_FONT_SEARCHPATH,
148  wxID_FONTTYPE_OK,
149  wxID_ALIGN_TL, wxID_ALIGN_T, wxID_ALIGN_TR,
150  wxID_ALIGN_L, wxID_ALIGN_C, wxID_ALIGN_R,
151  wxID_ALIGN_BL, wxID_ALIGN_B, wxID_ALIGN_BR,
152  wxID_CHECK_ALIGN,
153  wxID_CHECK_FRAME,
154  wxID_CHECK_BACKGROUND
155 };
156 
157 IMPLEMENT_DYNAMIC_CLASS( a2dTextPropDlg, wxDialog )
158 
159 BEGIN_EVENT_TABLE( a2dTextPropDlg, wxDialog )
160  EVT_LISTBOX( wxID_FONTTYPE_LIST, a2dTextPropDlg::OnChangeFontType )
161  EVT_LISTBOX( wxID_FONTNAME_LIST, a2dTextPropDlg::OnChangeFontName )
162  EVT_LISTBOX( wxID_FONTSTYLE_LIST, a2dTextPropDlg::OnChangeFontStyle )
163  EVT_LISTBOX( wxID_FONTSIZE_LIST, a2dTextPropDlg::OnChangeFontSizeList )
164  EVT_TEXT( wxID_FONTSIZE_EDIT, a2dTextPropDlg::OnChangeFontSize )
165  EVT_BUTTON( wxID_FONT_SEARCHPATH, a2dTextPropDlg::OnSearchPath )
166  EVT_BUTTON( wxID_ALIGN_TL, a2dTextPropDlg::OnAlignment )
167  EVT_BUTTON( wxID_ALIGN_T, a2dTextPropDlg::OnAlignment )
168  EVT_BUTTON( wxID_ALIGN_TR, a2dTextPropDlg::OnAlignment )
169  EVT_BUTTON( wxID_ALIGN_L, a2dTextPropDlg::OnAlignment )
170  EVT_BUTTON( wxID_ALIGN_C, a2dTextPropDlg::OnAlignment )
171  EVT_BUTTON( wxID_ALIGN_R, a2dTextPropDlg::OnAlignment )
172  EVT_BUTTON( wxID_ALIGN_BL, a2dTextPropDlg::OnAlignment )
173  EVT_BUTTON( wxID_ALIGN_B, a2dTextPropDlg::OnAlignment )
174  EVT_BUTTON( wxID_ALIGN_BR, a2dTextPropDlg::OnAlignment )
175  EVT_CHECKBOX( wxID_CHECK_ALIGN, a2dTextPropDlg::OnAlignment )
176  EVT_CHECKBOX( wxID_CHECK_FRAME, a2dTextPropDlg::OnAlignment )
177  EVT_CHECKBOX( wxID_CHECK_BACKGROUND, a2dTextPropDlg::OnAlignment )
178  EVT_SIZE( a2dTextPropDlg::OnSize )
179 END_EVENT_TABLE()
180 
181 a2dTextPropDlg::a2dTextPropDlg( wxWindow* parent, const a2dFont& currentfont, unsigned int textflags, int alignment )
182  : wxDialog( parent, -1, _( "Choose Font" ), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
183 {
184  m_currentinfo = currentfont.GetFontInfo();
185  m_font = *a2dDEFAULT_CANVASFONT;
186  m_textflags = textflags;
187  m_alignment = alignment;
188  m_viewscale = 1.0;
189  m_fonts.DeleteContents( true );
190  a2dFont::GetInfoList( m_fonts );
191 
192  wxBoxSizer* propsizer = new wxBoxSizer( wxHORIZONTAL );
193  wxBoxSizer* panelsizer = new wxBoxSizer( wxVERTICAL );
194  wxBoxSizer* sizesizer = new wxBoxSizer( wxVERTICAL );
195 
196  wxBoxSizer* typesizer = new wxBoxSizer( wxVERTICAL );
197  typesizer->Add( new wxStaticText( this, -1, _( "Type" ) ), 0, 0, 0 );
198  wxArrayString types;
199  types.Add( _( "* (All types)" ) );
200  for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
201  {
202  wxString type = m_fonts.Item( i )->GetData()->GetType();
203  size_t j;
204  for ( j = 0; j < types.GetCount(); j++ )
205  {
206  if ( types.Item( j ) == type )
207  break;
208  }
209  if ( j == types.GetCount() )
210  types.Add( type );
211  }
212  m_typelist = new wxListBox( this, wxID_FONTTYPE_LIST, wxDefaultPosition, wxDefaultSize, types, wxLB_SORT );
213  typesizer->Add( m_typelist, 1, wxEXPAND, 0 );
214  propsizer->Add( typesizer, 1, wxALL | wxEXPAND, 10 );
215 
216  wxBoxSizer* fontsizer = new wxBoxSizer( wxVERTICAL );
217  fontsizer->Add( new wxStaticText( this, -1, _( "Font" ) ), 0, 0, 0 );
218  wxArrayString fontnames;
219  m_fontlist = new wxListBox( this, wxID_FONTNAME_LIST, wxDefaultPosition, wxDefaultSize, fontnames, wxLB_SORT );
220  fontsizer->Add( m_fontlist, 1, wxEXPAND, 0 );
221  propsizer->Add( fontsizer, 2, wxALL | wxEXPAND, 10 );
222 
223  wxBoxSizer* stylesizer = new wxBoxSizer( wxVERTICAL );
224  stylesizer->Add( new wxStaticText( this, -1, _( "Style" ) ), 0, wxLEFT | wxRIGHT | wxTOP, 5 );
225  wxArrayString styles;
226  m_stylelist = new wxListBox( this, wxID_FONTSTYLE_LIST, wxDefaultPosition, wxDefaultSize, styles, wxLB_SORT );
227  stylesizer->Add( m_stylelist, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
228  propsizer->Add( stylesizer, 1, wxALL | wxEXPAND, 5 );
229 
230  sizesizer->Add( new wxStaticText( this, -1, _( "Size" ) ), 0, wxLEFT | wxRIGHT | wxTOP, 5 );
231  wxArrayString sizes;
232  sizes.Add( wxT( "1.0" ) );
233  sizes.Add( wxT( "2.0" ) );
234  sizes.Add( wxT( "5.0" ) );
235  sizes.Add( wxT( "10.0" ) );
236  sizes.Add( wxT( "20.0" ) );
237  sizes.Add( wxT( "50.0" ) );
238  sizes.Add( wxT( "100.0" ) );
239  sizes.Add( wxT( "200.0" ) );
240  sizes.Add( wxT( "500.0" ) );
241  m_sizelist = new wxListBox( this, wxID_FONTSIZE_LIST, wxDefaultPosition, wxDefaultSize, sizes );
242  m_sizeedit = new wxTextCtrl( this, wxID_FONTSIZE_EDIT, wxT( "50.0" ) );
243  wxString sizetext;
244  sizetext.Printf( wxT( "%f" ), m_currentinfo.GetSize() );
245  m_sizeedit->SetValue( sizetext );
246 
247  sizesizer->Add( m_sizeedit, 0, wxLEFT | wxRIGHT | wxEXPAND, 5 );
248  sizesizer->Add( m_sizelist, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
249 
250  propsizer->Add( sizesizer, 1, wxALL | wxEXPAND, 5 );
251  panelsizer->Add( propsizer, 2, wxALL | wxEXPAND, 5 );
252 
253  wxBoxSizer* bottomsizer = new wxBoxSizer( wxHORIZONTAL );
254 
255  wxBoxSizer* alignsizer = new wxBoxSizer( wxVERTICAL );
256  alignsizer->Add( new wxStaticText( this, -1, _( "Alignment" ) ), 0, wxLEFT | wxRIGHT | wxTOP, 5 );
257  wxGridSizer* alignsizer2 = new wxGridSizer( 3 );
258 #ifdef __WXMSW__
259  // use wingdings font for graphical representation of arrows on windows
260  wxButton* button;
261  wxFont font( 12, wxDECORATIVE, wxNORMAL, wxNORMAL, false, wxT( "WingDings" ) );
262  button = new wxButton( this, wxID_ALIGN_TL, wxT( "\xeb" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
263  button->SetFont( font );
264  alignsizer2->Add( button, 0, 0, 0 );
265  button = new wxButton( this, wxID_ALIGN_T, wxT( "\xe9" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
266  button->SetFont( font );
267  alignsizer2->Add( button, 0, 0, 0 );
268  button = new wxButton( this, wxID_ALIGN_TR, wxT( "\xec" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
269  button->SetFont( font );
270  alignsizer2->Add( button, 0, 0, 0 );
271  button = new wxButton( this, wxID_ALIGN_L, wxT( "\xe7" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
272  button->SetFont( font );
273  alignsizer2->Add( button, 0, 0, 0 );
274  button = new wxButton( this, wxID_ALIGN_C, wxT( "\x6c" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
275  button->SetFont( font );
276  alignsizer2->Add( button, 0, 0, 0 );
277  button = new wxButton( this, wxID_ALIGN_R, wxT( "\xe8" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
278  button->SetFont( font );
279  alignsizer2->Add( button, 0, 0, 0 );
280  button = new wxButton( this, wxID_ALIGN_BL, wxT( "\xed" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
281  button->SetFont( font );
282  alignsizer2->Add( button, 0, 0, 0 );
283  button = new wxButton( this, wxID_ALIGN_B, wxT( "\xea" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
284  button->SetFont( font );
285  alignsizer2->Add( button, 0, 0, 0 );
286  button = new wxButton( this, wxID_ALIGN_BR, wxT( "\xee" ), wxDefaultPosition, wxSize( 32, 32 ), wxBU_EXACTFIT );
287  button->SetFont( font );
288  alignsizer2->Add( button, 0, 0, 0 );
289 #else // __WXMSW__
290  alignsizer2->Add( new wxButton( this, wxID_ALIGN_TL, wxT( "" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
291  alignsizer2->Add( new wxButton( this, wxID_ALIGN_T, wxT( "^" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
292  alignsizer2->Add( new wxButton( this, wxID_ALIGN_TR, wxT( "" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
293  alignsizer2->Add( new wxButton( this, wxID_ALIGN_L, wxT( "<" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
294  alignsizer2->Add( new wxButton( this, wxID_ALIGN_C, wxT( "o" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
295  alignsizer2->Add( new wxButton( this, wxID_ALIGN_R, wxT( ">" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
296  alignsizer2->Add( new wxButton( this, wxID_ALIGN_BL, wxT( "" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
297  alignsizer2->Add( new wxButton( this, wxID_ALIGN_B, wxT( "v" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
298  alignsizer2->Add( new wxButton( this, wxID_ALIGN_BR, wxT( "" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
299 #endif // __WXMSW__
300  alignsizer->Add( alignsizer2, 0, wxALL | wxEXPAND, 5 );
301  m_aligncheck = new wxCheckBox( this, wxID_CHECK_ALIGN, _( "Align on bbox" ) );
302  m_aligncheck->SetValue( (m_alignment & wxBASELINE) > 0 );
303  alignsizer->Add( m_aligncheck, 0, 0 );
304 
305  m_textframe = new wxCheckBox( this, wxID_CHECK_FRAME, _( "Frame around text" ) );
306  m_textframe->SetValue( (m_textflags & a2dText::a2dCANOBJTEXT_FRAME) > 0 );
307  alignsizer->Add( m_textframe, 0, 0 );
308 
309  m_textbackground = new wxCheckBox( this, wxID_CHECK_BACKGROUND, _( "Fill text background" ) );
310  m_textbackground->SetValue( (m_textflags & a2dText::a2dCANOBJTEXT_BACKGROUND) > 0 );
311  alignsizer->Add( m_textbackground, 0, 0 );
312 
313  bottomsizer->Add( alignsizer, 0, wxALL | wxEXPAND, 5 );
314 
315  m_canvas = new a2dCanvas( this, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER );
316  m_canvas->SetYaxis( true );
317  m_canvas->SetScaleOnResize( false );
318  a2dCanvasObject* root = m_canvas->GetDrawing()->GetRootObject();
319  m_canvastext = new a2dText( _T( "ABCDEFGabcdefg12345" ) );
320  m_canvastext->SetPosXY( 0.0, 0.0 );
321  m_canvastext->SetFill( *a2dTRANSPARENT_FILL );
322  m_canvastext->SetStroke( *wxBLACK );
323  root->Append( m_canvastext );
324  m_canvasline1 = new a2dSLine( 0.0, 0.0, 1.0, 0.0 );
325  m_canvasline1->SetStroke( wxColour( 0xc0, 0xc0, 0xc0 ), 1 );
326  root->Append( m_canvasline1 );
327  m_canvasline2 = new a2dSLine( 0.0, 0.0, 0.0, 1.0 );
328  m_canvasline2->SetStroke( wxColour( 0xc0, 0xc0, 0xc0 ), 1 );
329  root->Append( m_canvasline2 );
330  bottomsizer->Add( m_canvas, 1, wxALL | wxEXPAND, 5 );
331 
332  panelsizer->Add( bottomsizer, 1, wxALL | wxEXPAND, 5 );
333 
334  wxBoxSizer* buttonsizer = new wxBoxSizer( wxHORIZONTAL );
335  buttonsizer->Add( new wxButton( this, wxID_FONT_SEARCHPATH, _( "Search Path" ) ), 0, wxALL, 5 );
336  buttonsizer->Add( new wxButton( this, wxID_OK, _( "OK" ) ), 0, wxALL, 5 );
337  buttonsizer->Add( new wxButton( this, wxID_CANCEL, _( "Cancel" ) ), 0, wxALL, 5 );
338  panelsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 );
339 
340  if ( m_typelist->GetCount() )
341  {
342  int idx = 0;
343  idx = m_typelist->FindString( m_currentinfo.GetType() );
344  if ( idx == wxNOT_FOUND )
345  idx = 0;
346  m_typelist->SetSelection( idx );
347  }
348 
349  wxCommandEvent dummy;
350  OnChangeFontType( dummy );
351 
352  SetSizer( panelsizer );
353  panelsizer->SetSizeHints( this );
354 }
355 
357 {
358  return m_font;
359 }
360 
362 {
363 }
364 
365 void a2dTextPropDlg::OnChangeFontType( wxCommandEvent& event )
366 {
367  wxString type = m_typelist->GetStringSelection();
368  wxString oldname = m_fontlist->GetStringSelection();
369 
370  while ( m_fontlist->GetCount() )
371  m_fontlist->Delete( 0 );
372 
373  wxArrayString fonts;
374  for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
375  {
376  wxString fonttype = m_fonts.Item( i )->GetData()->GetType();
377  if ( fonttype == type || type == _( "* (All types)" ) )
378  {
379  wxString fontname = m_fonts.Item( i )->GetData()->GetName();
380  size_t j;
381  for ( j = 0; j < fonts.GetCount(); j++ )
382  {
383  if ( fonts.Item( j ) == fontname )
384  break;
385  }
386  if ( j == fonts.GetCount() )
387  fonts.Add( fontname );
388  }
389  }
390  m_fontlist->Append( fonts );
391 
392  if ( m_fontlist->GetCount() )
393  {
394  int idx;
395  idx = m_fontlist->FindString( m_currentinfo.GetName() );
396  if( idx == -1 )
397  idx = m_fontlist->FindString( oldname );
398  if ( idx == wxNOT_FOUND )
399  idx = 0;
400  m_fontlist->SetSelection( idx );
401  }
402  OnChangeFontName( event );
403 }
404 
405 void a2dTextPropDlg::OnChangeFontName( wxCommandEvent& event )
406 {
407  wxString type = m_typelist->GetStringSelection();
408  wxString name = m_fontlist->GetStringSelection();
409  wxString oldstyle = m_stylelist->GetStringSelection();
410 
411  while ( m_stylelist->GetCount() )
412  m_stylelist->Delete( 0 );
413 
414  wxArrayString fonts;
415  for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
416  {
417  wxString fontname = m_fonts.Item( i )->GetData()->GetName();
418  wxString fonttype = m_fonts.Item( i )->GetData()->GetType();
419  if ( ( fonttype == type || type == _( "* (All types)" ) )
420  && fontname == name )
421  {
422  wxString fontstyle = m_fonts.Item( i )->GetData()->GetStyle();
423  size_t j;
424  for ( j = 0; j < fonts.GetCount(); j++ )
425  {
426  if ( fonts.Item( j ) == fontstyle )
427  break;
428  }
429  if ( j == fonts.GetCount() )
430  fonts.Add( fontstyle );
431  }
432  }
433  m_stylelist->Append( fonts );
434 
435  if ( m_stylelist->GetCount() )
436  {
437  int idx;
438  idx = m_fontlist->FindString( m_currentinfo.GetStyle() );
439  if( idx == -1 )
440  idx = m_stylelist->FindString( oldstyle );
441  if ( idx == wxNOT_FOUND )
442  idx = m_stylelist->FindString( _( "Normal" ) );
443  if ( idx == wxNOT_FOUND )
444  idx = m_stylelist->FindString( _( "Regular" ) );
445  if ( idx == wxNOT_FOUND )
446  idx = 0;
447  m_stylelist->SetSelection( idx );
448  }
449  OnChangeFontStyle( event );
450 }
451 
452 void a2dTextPropDlg::OnChangeFontStyle( wxCommandEvent& event )
453 {
454  OnChangeFont();
455 }
456 
457 void a2dTextPropDlg::OnChangeFontSize( wxCommandEvent& event )
458 {
459  m_sizelist->SetSelection( wxNOT_FOUND );
460  OnChangeFont();
461 }
462 
463 void a2dTextPropDlg::OnChangeFontSizeList( wxCommandEvent& event )
464 {
465  int idx = m_sizelist->GetSelection();
466  m_sizeedit->SetValue( m_sizelist->GetStringSelection() );
467  m_sizelist->SetSelection( idx );
468  OnChangeFont();
469 }
470 
472 {
473  wxString type = m_typelist->GetStringSelection();
474  wxString name = m_fontlist->GetStringSelection();
475  wxString style = m_stylelist->GetStringSelection();
476 
477  wxArrayString fonts;
478  for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
479  {
480  wxString fonttype = m_fonts.Item( i )->GetData()->GetType();
481  wxString fontname = m_fonts.Item( i )->GetData()->GetName();
482  wxString fontstyle = m_fonts.Item( i )->GetData()->GetStyle();
483  if ( ( fonttype == type || type == _( "* (All types)" ) )
484  && fontname == name && fontstyle == style )
485  {
486  double size;
487  m_sizeedit->GetValue().ToDouble( &size );
488  a2dFontInfo fontinfo = *m_fonts.Item( i )->GetData();
489 
490  //! \todo alignment
491  // fontinfo.SetAlignment( m_alignment );
492  fontinfo.SetSize( size );
493  m_font = a2dFont::CreateFont( fontinfo );
495  m_canvastext->SetPending( true );
499 
500  m_canvasline1->SetPosXY12( -2.0 * bbox.GetWidth(), 0.0, 2.0 * bbox.GetWidth(), 0.0 );
501  m_canvasline2->SetPosXY12( 0.0, -2.0 * bbox.GetWidth(), 0.0, 2.0 * bbox.GetWidth() );
502 
503  // To have some better visual feedback of alignment, move the text around a little.
504  a2dBoundingBox bboxnew = bbox;
505  bboxnew.Enlarge( bbox.GetHeight() / 6.0 );
506  if ( m_alignment & wxMINX )
507  bboxnew.Translate( -bbox.GetHeight() / 8.0, 0.0 );
508  if ( m_alignment & wxMAXX )
509  bboxnew.Translate( bbox.GetHeight() / 8.0, 0.0 );
510 
511  if ( m_alignment & wxMINY )
512  bboxnew.Translate( 0.0, -bbox.GetHeight() / 8.0 );
513  if ( m_alignment & wxMAXY )
514  bboxnew.Translate( 0.0, bbox.GetHeight() / 8.0 );
515 
516  if ( m_alignment & wxBASELINE )
517  m_canvastext->SetFill( wxColour( 0xf0, 0xf0, 0xff ) );
518  if ( m_alignment & wxBASELINE_CONTRA )
519  m_canvastext->SetFill( wxColour( 0xf0, 0xff, 0x00 ) );
520  else
522 
523  m_canvas->SetMappingWidthHeight ( bboxnew.GetMinX(), bboxnew.GetMinY(),
524  bboxnew.GetWidth(), bboxnew.GetHeight(), false );
525  m_canvas->Refresh();
526  break;
527  }
528  }
529 }
530 
531 void a2dTextPropDlg::OnSearchPath( wxCommandEvent& event )
532 {
534  if ( dlg.ShowModal() == wxID_OK )
535  {
536  m_fonts.Clear();
538 
539  wxString oldtype = m_typelist->GetStringSelection();
540 
541  while ( m_typelist->GetCount() )
542  m_typelist->Delete( 0 );
543  wxArrayString types;
544  types.Add( _( "* (All types)" ) );
545  for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
546  {
547  wxString type = m_fonts.Item( i )->GetData()->GetType();
548  size_t j;
549  for ( j = 0; j < types.GetCount(); j++ )
550  {
551  if ( types.Item( j ) == type )
552  break;
553  }
554  if ( j == types.GetCount() )
555  types.Add( type );
556  }
557  m_typelist->Append( types );
558 
559  if ( m_typelist->GetCount() )
560  {
561  int idx = m_typelist->FindString( oldtype );
562  if ( idx == wxNOT_FOUND )
563  idx = 0;
564  m_typelist->SetSelection( idx );
565  }
566  OnChangeFontType( event );
567  }
568 }
569 
570 void a2dTextPropDlg::OnAlignment( wxCommandEvent& event )
571 {
572  switch( event.GetId() )
573  {
574  case wxID_ALIGN_TL: m_alignment = wxMAXY | wxMINX; break;
575  case wxID_ALIGN_T: m_alignment = wxMAXY; break;
576  case wxID_ALIGN_TR: m_alignment = wxMAXY | wxMAXX; break;
577  case wxID_ALIGN_L: m_alignment = wxMAXX; break;
578  case wxID_ALIGN_C: m_alignment = wxMIDX | wxMIDY; break;
579  case wxID_ALIGN_R: m_alignment = wxMAXX; break;
580  case wxID_ALIGN_BL: m_alignment = wxMINY | wxMINX; break;
581  case wxID_ALIGN_B: m_alignment = wxMINY; break;
582  case wxID_ALIGN_BR: m_alignment = wxMINY | wxMAXX; break;
583  default: ;
584  }
585  if ( m_aligncheck->IsChecked() )
586  m_alignment |= wxBASELINE;
587  else
588  m_alignment |= wxBASELINE_CONTRA;
589 
590  if ( m_textframe->IsChecked() )
592  else
593  m_textflags &= ~a2dText::a2dCANOBJTEXT_FRAME;
594 
595  if ( m_textbackground->IsChecked() )
597  else
598  m_textflags &= ~a2dText::a2dCANOBJTEXT_BACKGROUND;
599 
600  OnChangeFont();
601 }
602 
603 void a2dTextPropDlg::OnSize( wxSizeEvent& event )
604 {
605  event.Skip();
606 
608  // To have some better visual feedback of alignment, move the text around a little.
609  a2dBoundingBox bboxnew = bbox;
610  bboxnew.Enlarge( bbox.GetHeight() / 6.0 );
611  if ( m_alignment & wxMINX )
612  bboxnew.Translate( -bbox.GetHeight() / 8.0, 0.0 );
613  if ( m_alignment & wxMAXX )
614  bboxnew.Translate( bbox.GetHeight() / 8.0, 0.0 );
615 
616  if ( m_alignment & wxMINY )
617  bboxnew.Translate( 0.0, -bbox.GetHeight() / 8.0 );
618  if ( m_alignment & wxMAXY )
619  bboxnew.Translate( 0.0, bbox.GetHeight() / 8.0 );
620 
621  if ( m_alignment & wxBASELINE )
622  m_canvastext->SetFill( wxColour( 0xf0, 0xf0, 0xff ) );
623  if ( m_alignment & wxBASELINE_CONTRA )
624  m_canvastext->SetFill( wxColour( 0xf0, 0xff, 0x00 ) );
625  else
627 
628  m_canvas->SetMappingWidthHeight ( bboxnew.GetMinX(), bboxnew.GetMinY(),
629  bboxnew.GetWidth(), bboxnew.GetHeight(), false );
630  m_canvas->Refresh();
631 }
double GetHeight() const
returns height of the boundingbox
Definition: bbox.cpp:334
virtual ~a2dTextPropDlg()
Destructor.
Definition: fontdlg.cpp:361
all basic primitives derived from a2dCanvasObject
const wxString & GetName() const
Get name of font, e.g. Arial.
Definition: stylebase.h:717
void OnPathButton(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:96
void SetAlignment(int alignment)
Set the position of the anchor point w.r.t the text.
Definition: cantext.h:294
Display a font selection dialog.
Definition: fontdlg.h:67
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
wxTextCtrl * m_textctrl
User interface object.
Definition: fontdlg.h:54
~a2dFontSearchPathDialog()
Destructor.
Definition: fontdlg.cpp:87
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 OnListBox(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:111
void OnChangeFontType(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:365
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
int m_alignment
Font alignment.
Definition: fontdlg.h:146
virtual void SetPending(bool pending)
set this object pending for update
Definition: canobj.cpp:2585
a2dGlobal * a2dGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: artglob.cpp:34
void OnChangeFontSize(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:457
wxTextCtrl * m_sizeedit
User interface object.
Definition: fontdlg.h:161
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
wxListBox * m_sizelist
User interface object.
Definition: fontdlg.h:163
a2dCanvas uses a2dCanvasView for displaying a view on a a2dCanvasDocument.
wxListBox * m_stylelist
User interface object.
Definition: fontdlg.h:159
a2dSLine * m_canvasline1
Horizontal line to indicate alignment.
Definition: fontdlg.h:175
wxListBox * m_listbox
User interface object.
Definition: fontdlg.h:52
a2dText * m_canvastext
Displayed text.
Definition: fontdlg.h:173
void OnDelete(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:103
a2dText is an abstract base class.
Definition: cantext.h:93
wxListBox * m_typelist
User interface object.
Definition: fontdlg.h:155
const a2dBoundingBox & Translate(a2dPoint2D &)
translate with given vector
Definition: bbox.cpp:370
double GetMinX() const
get minimum X of the boundingbox
Definition: bbox.cpp:304
a2dPathList & GetFontPathList()
Path for Fonts.
Definition: artglob.h:149
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 OnAdd(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:91
void SetFont(const a2dFont &font, double lineSpaceFactor=0.1)
set font for text
Definition: cantext.cpp:527
static void GetInfoList(a2dFontInfoList &list)
Append fonts of this type to the list.
Definition: stylebase.cpp:3156
a2dCanvas * m_canvas
User interface object.
Definition: fontdlg.h:171
wxCheckBox * m_aligncheck
User interface object.
Definition: fontdlg.h:165
void OnText(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:131
void OnChangeFont()
User interface event handler.
Definition: fontdlg.cpp:471
a2dSLine
Definition: canprim.h:987
void OnChangeFontName(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:405
static a2dFont CreateFont(const a2dFontInfo &info, bool force=false)
Create the font from a fontinfo description.
Definition: stylebase.cpp:3163
void OnSearchPath(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:531
wxListBox * m_fontlist
User interface object.
Definition: fontdlg.h:157
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
Contains graphical drawing context specific classes. a2dDrawer2D and derived classes are used for dra...
void OnSize(wxSizeEvent &event)
User interface event handler.
Definition: fontdlg.cpp:603
const a2dFont * a2dDEFAULT_CANVASFONT
global a2dFont stock object for default font
void SetSize(double size)
Set size of the font.
Definition: stylebase.h:735
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 OnChangeFontSizeList(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:463
void OnOK(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:118
a2dFont m_font
Selected font.
Definition: fontdlg.h:140
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
all polygon and polyline a2dCanvasObject are here.
unsigned int m_textflags
contains several text flags.
Definition: fontdlg.h:149
double GetMinY() const
get minimum Y of the boundingbox
Definition: bbox.cpp:310
a2dSLine * m_canvasline2
Vertical line to indicate alignment.
Definition: fontdlg.h:177
void Append(a2dCanvasObject *obj)
append a a2dCanvasObject to the childobjects
Definition: canobj.cpp:6224
void OnChangeFontStyle(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:452
const a2dFont & GetFontData() const
Returns the font.
Definition: fontdlg.cpp:356
a2dFontInfoList m_fonts
Font enumeration list.
Definition: fontdlg.h:142
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
const a2dFill * a2dTRANSPARENT_FILL
global a2dFill stock object for TRANSPARENT filling
general canvas module declarations and classes
void OnAlignment(wxCommandEvent &event)
User interface event handler.
Definition: fontdlg.cpp:570
fontdlg.cpp Source File -- Sun Oct 12 2014 17:04:19 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation