00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "a2dprec.h"
00012
00013 #ifdef __BORLANDC__
00014 #pragma hdrstop
00015 #endif
00016
00017 #include <string.h>
00018 #include <stdlib.h>
00019
00020 #include "wx/editor/fontdlg.h"
00021 #include "wx/canvas/canglob.h"
00022 #include "wx/artbase/drawer2d.h"
00023 #include "wx/canvas/canvas.h"
00024 #include "wx/canvas/canprim.h"
00025 #include "wx/canvas/polygon.h"
00026 #include "wx/canvas/candoc.h"
00027
00028
00029
00030
00031
00032
00033
00034 enum
00035 {
00036 wxID_PATHLIST = wxID_HIGHEST + 1,
00037 wxID_PATHEDIT,
00038 wxID_PATHBUTTON
00039 };
00040
00041 IMPLEMENT_DYNAMIC_CLASS(a2dFontSearchPathDialog, wxDialog)
00042
00043 BEGIN_EVENT_TABLE(a2dFontSearchPathDialog, wxDialog)
00044 EVT_BUTTON( wxID_NEW, a2dFontSearchPathDialog::OnAdd )
00045 EVT_BUTTON( wxID_DELETE, a2dFontSearchPathDialog::OnDelete )
00046 EVT_BUTTON( wxID_OK, a2dFontSearchPathDialog::OnOK )
00047 EVT_BUTTON( wxID_PATHBUTTON, a2dFontSearchPathDialog::OnPathButton )
00048 EVT_LISTBOX( wxID_PATHLIST, a2dFontSearchPathDialog::OnListBox )
00049 EVT_TEXT(wxID_PATHEDIT, a2dFontSearchPathDialog::OnText)
00050 END_EVENT_TABLE()
00051
00052 a2dFontSearchPathDialog::a2dFontSearchPathDialog( wxWindow *parent )
00053 : wxDialog(parent, -1, _("Font Search Path"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
00054 {
00055 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
00056
00057 wxArrayString paths;
00058 wxPathList& pathlist = a2dGlobals->GetFontPathList();
00059 #if wxCHECK_VERSION(2,7,0)
00060 for (wxPathList::iterator node = pathlist.begin(); node != pathlist.end(); node++ )
00061 #else
00062 for ( wxPathList::compatibility_iterator node = pathlist.GetFirst(); node; node = node->GetNext() )
00063 #endif
00064 paths.Add( node->GetData() );
00065 m_listbox = new wxListBox( this, wxID_PATHLIST, wxDefaultPosition, wxDefaultSize, paths );
00066 topsizer->Add( m_listbox, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 10 );
00067
00068 wxBoxSizer *editsizer = new wxBoxSizer( wxHORIZONTAL );
00069 m_textctrl = new wxTextCtrl( this, wxID_PATHEDIT, wxT("") );
00070 editsizer->Add( m_textctrl, 1, wxEXPAND, 0 );
00071 m_button = new wxButton( this, wxID_PATHBUTTON, wxT("..."), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
00072 editsizer->Add( m_button, 0, wxEXPAND, 0 );
00073 topsizer->Add( editsizer, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 10 );
00074
00075 wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
00076
00077 wxBoxSizer *adddelsizer = new wxBoxSizer( wxHORIZONTAL );
00078 adddelsizer->Add( new wxButton( this, wxID_NEW, _("Add") ), 0, wxRIGHT, 10 );
00079 adddelsizer->Add( new wxButton( this, wxID_DELETE, _("Delete") ), 0, 0, 0 );
00080 buttonsizer->Add(adddelsizer, 1, wxRIGHT | wxEXPAND, 30);
00081
00082 buttonsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxRIGHT, 10 );
00083 buttonsizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, 0, 0 );
00084 topsizer->Add(buttonsizer, 0, wxLEFT|wxBOTTOM|wxRIGHT | wxEXPAND, 10);
00085
00086 SetSizer( topsizer );
00087 topsizer->SetSizeHints( this );
00088 }
00089
00090 a2dFontSearchPathDialog::~a2dFontSearchPathDialog()
00091 {
00092 }
00093
00094 void a2dFontSearchPathDialog::OnAdd( wxCommandEvent& WXUNUSED(event) )
00095 {
00096 m_listbox->Append( m_textctrl->GetValue() );
00097 }
00098
00099 void a2dFontSearchPathDialog::OnPathButton( wxCommandEvent& WXUNUSED(event) )
00100 {
00101 const wxString& dir = wxDirSelector( _("Choose a folder") );
00102 if ( !dir.empty() )
00103 m_textctrl->SetValue( dir );
00104 }
00105
00106 void a2dFontSearchPathDialog::OnDelete( wxCommandEvent& WXUNUSED(event) )
00107 {
00108 int idx = m_listbox->GetSelection();
00109 if ( idx != wxNOT_FOUND )
00110 m_listbox->Delete( idx );
00111 m_textctrl->SetValue( wxT("") );
00112 }
00113
00114 void a2dFontSearchPathDialog::OnListBox( wxCommandEvent& WXUNUSED(event) )
00115 {
00116 int idx = m_listbox->GetSelection();
00117 m_textctrl->SetValue( m_listbox->GetStringSelection() );
00118 m_listbox->SetSelection( idx );
00119 }
00120
00121 void a2dFontSearchPathDialog::OnOK( wxCommandEvent& event )
00122 {
00123 wxPathList& pathlist = a2dGlobals->GetFontPathList();
00124 pathlist.Clear();
00125 for (unsigned int i = 0; i < m_listbox->GetCount(); i++ )
00126 pathlist.Add( m_listbox->GetString(i) );
00127 #if wxCHECK_VERSION(2,7,0)
00128 AcceptAndClose();
00129 #else
00130 wxDialog::OnOK( event );
00131 #endif
00132 }
00133
00134 void a2dFontSearchPathDialog::OnText( wxCommandEvent& WXUNUSED(event) )
00135 {
00136 m_listbox->SetSelection( wxNOT_FOUND );
00137 }
00138
00139
00140
00141
00142
00143 enum
00144 {
00145 wxID_FONTTYPE_LIST = wxID_HIGHEST + 1,
00146 wxID_FONTNAME_LIST,
00147 wxID_FONTSTYLE_LIST,
00148 wxID_FONTSIZE_EDIT,
00149 wxID_FONTSIZE_LIST,
00150 wxID_FONT_SEARCHPATH,
00151 wxID_FONTTYPE_OK,
00152 wxID_ALIGN_TL, wxID_ALIGN_T, wxID_ALIGN_TR,
00153 wxID_ALIGN_L, wxID_ALIGN_C, wxID_ALIGN_R,
00154 wxID_ALIGN_BL, wxID_ALIGN_B, wxID_ALIGN_BR,
00155 wxID_CHECK_ALIGN
00156 };
00157
00158 IMPLEMENT_DYNAMIC_CLASS(a2dFontDialog, wxDialog)
00159
00160 BEGIN_EVENT_TABLE(a2dFontDialog, wxDialog)
00161 EVT_LISTBOX( wxID_FONTTYPE_LIST, a2dFontDialog::OnChangeFontType )
00162 EVT_LISTBOX( wxID_FONTNAME_LIST, a2dFontDialog::OnChangeFontName )
00163 EVT_LISTBOX( wxID_FONTSTYLE_LIST, a2dFontDialog::OnChangeFontStyle )
00164 EVT_LISTBOX( wxID_FONTSIZE_LIST, a2dFontDialog::OnChangeFontSizeList )
00165 EVT_TEXT(wxID_FONTSIZE_EDIT, a2dFontDialog::OnChangeFontSize)
00166 EVT_BUTTON( wxID_FONT_SEARCHPATH, a2dFontDialog::OnSearchPath )
00167 EVT_BUTTON( wxID_ALIGN_TL, a2dFontDialog::OnAlignment )
00168 EVT_BUTTON( wxID_ALIGN_T, a2dFontDialog::OnAlignment )
00169 EVT_BUTTON( wxID_ALIGN_TR, a2dFontDialog::OnAlignment )
00170 EVT_BUTTON( wxID_ALIGN_L, a2dFontDialog::OnAlignment )
00171 EVT_BUTTON( wxID_ALIGN_C, a2dFontDialog::OnAlignment )
00172 EVT_BUTTON( wxID_ALIGN_R, a2dFontDialog::OnAlignment )
00173 EVT_BUTTON( wxID_ALIGN_BL, a2dFontDialog::OnAlignment )
00174 EVT_BUTTON( wxID_ALIGN_B, a2dFontDialog::OnAlignment )
00175 EVT_BUTTON( wxID_ALIGN_BR, a2dFontDialog::OnAlignment )
00176 EVT_CHECKBOX( wxID_CHECK_ALIGN, a2dFontDialog::OnAlignment )
00177 EVT_SIZE( a2dFontDialog::OnSize )
00178 END_EVENT_TABLE()
00179
00180 a2dFontDialog::a2dFontDialog(wxWindow *parent, const a2dFont& currentfont )
00181 : wxDialog(parent, -1, _("Choose Font"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
00182 {
00183 m_currentinfo = currentfont.GetFontInfo();
00184
00185
00186 m_alignment = 0;
00187
00188 m_viewscale = 1.0;
00189 m_alignment = wxTOP | wxLEFT | wxBBOX;
00190 m_fonts.DeleteContents(true);
00191 a2dFont::GetInfoList( m_fonts );
00192
00193 wxBoxSizer *propsizer = new wxBoxSizer( wxHORIZONTAL );
00194 wxBoxSizer *panelsizer = new wxBoxSizer( wxVERTICAL );
00195 wxBoxSizer *sizesizer = new wxBoxSizer( wxVERTICAL );
00196
00197 wxBoxSizer *typesizer = new wxBoxSizer( wxVERTICAL );
00198 typesizer->Add( new wxStaticText( this, -1, _("Type") ), 0, 0, 0 );
00199 wxArrayString types;
00200 types.Add( _("* (All types)") );
00201 for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
00202 {
00203 wxString type = m_fonts.Item(i)->GetData()->GetType();
00204 size_t j;
00205 for ( j = 0; j < types.GetCount(); j++ )
00206 {
00207 if ( types.Item(j) == type )
00208 break;
00209 }
00210 if ( j == types.GetCount() )
00211 types.Add( type );
00212 }
00213 m_typelist = new wxListBox( this, wxID_FONTTYPE_LIST, wxDefaultPosition, wxDefaultSize, types, wxLB_SORT );
00214 typesizer->Add( m_typelist, 1, wxEXPAND, 0);
00215 propsizer->Add( typesizer, 1, wxALL | wxEXPAND, 10 );
00216
00217 wxBoxSizer *fontsizer = new wxBoxSizer( wxVERTICAL );
00218 fontsizer->Add( new wxStaticText( this, -1, _("Font") ), 0, 0, 0 );
00219 wxArrayString fontnames;
00220 m_fontlist = new wxListBox( this, wxID_FONTNAME_LIST, wxDefaultPosition, wxDefaultSize, fontnames, wxLB_SORT );
00221 fontsizer->Add( m_fontlist, 1, wxEXPAND, 0);
00222 propsizer->Add( fontsizer, 2, wxALL | wxEXPAND, 10 );
00223
00224 wxBoxSizer *stylesizer = new wxBoxSizer( wxVERTICAL );
00225 stylesizer->Add( new wxStaticText( this, -1, _("Style") ), 0, wxLEFT|wxRIGHT|wxTOP, 5 );
00226 wxArrayString styles;
00227 m_stylelist = new wxListBox(this, wxID_FONTSTYLE_LIST, wxDefaultPosition, wxDefaultSize, styles, wxLB_SORT );
00228 stylesizer->Add(m_stylelist, 1, wxLEFT|wxRIGHT|wxBOTTOM | wxEXPAND, 5);
00229 propsizer->Add(stylesizer, 1, wxALL | wxEXPAND, 5);
00230
00231 sizesizer->Add( new wxStaticText( this, -1, _("Size") ), 0, wxLEFT|wxRIGHT|wxTOP, 5 );
00232 wxArrayString sizes;
00233 sizes.Add( wxT("1.0") );
00234 sizes.Add( wxT("2.0") );
00235 sizes.Add( wxT("5.0") );
00236 sizes.Add( wxT("10.0") );
00237 sizes.Add( wxT("20.0") );
00238 sizes.Add( wxT("50.0") );
00239 sizes.Add( wxT("100.0") );
00240 sizes.Add( wxT("200.0") );
00241 sizes.Add( wxT("500.0") );
00242 m_sizelist = new wxListBox(this, wxID_FONTSIZE_LIST, wxDefaultPosition, wxDefaultSize, sizes );
00243 m_sizeedit = new wxTextCtrl( this, wxID_FONTSIZE_EDIT, wxT("50.0") );
00244 wxString sizetext;
00245 sizetext.Printf( wxT("%f"), m_currentinfo.GetSize() );
00246 m_sizeedit->SetValue( sizetext );
00247
00248 sizesizer->Add( m_sizeedit, 0, wxLEFT|wxRIGHT | wxEXPAND, 5 );
00249 sizesizer->Add(m_sizelist, 1, wxLEFT|wxRIGHT|wxBOTTOM | wxEXPAND, 5);
00250
00251 propsizer->Add(sizesizer, 1, wxALL | wxEXPAND, 5);
00252 panelsizer->Add(propsizer, 2, wxALL | wxEXPAND, 5);
00253
00254 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
00255
00256 wxBoxSizer *alignsizer = new wxBoxSizer( wxVERTICAL );
00257 alignsizer->Add( new wxStaticText( this, -1, _("Alignment") ), 0, wxLEFT|wxRIGHT|wxTOP, 5 );
00258 wxGridSizer *alignsizer2 = new wxGridSizer( 3 );
00259 #ifdef __WXMSW__
00260
00261 wxButton* button;
00262 wxFont font(12, wxDECORATIVE, wxNORMAL, wxNORMAL, false, wxT("WingDings") );
00263 button = new wxButton( this, wxID_ALIGN_TL, wxT("\xeb"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00264 button->SetFont(font);
00265 alignsizer2->Add( button, 0, 0, 0 );
00266 button = new wxButton( this, wxID_ALIGN_T, wxT("\xe9"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00267 button->SetFont(font);
00268 alignsizer2->Add( button, 0, 0, 0 );
00269 button = new wxButton( this, wxID_ALIGN_TR, wxT("\xec"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00270 button->SetFont(font);
00271 alignsizer2->Add( button, 0, 0, 0 );
00272 button = new wxButton( this, wxID_ALIGN_L, wxT("\xe7"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00273 button->SetFont(font);
00274 alignsizer2->Add( button, 0, 0, 0 );
00275 button = new wxButton( this, wxID_ALIGN_C, wxT("\x6c"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00276 button->SetFont(font);
00277 alignsizer2->Add( button, 0, 0, 0 );
00278 button = new wxButton( this, wxID_ALIGN_R, wxT("\xe8"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00279 button->SetFont(font);
00280 alignsizer2->Add( button, 0, 0, 0 );
00281 button = new wxButton( this, wxID_ALIGN_BL, wxT("\xed"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00282 button->SetFont(font);
00283 alignsizer2->Add( button, 0, 0, 0 );
00284 button = new wxButton( this, wxID_ALIGN_B, wxT("\xea"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00285 button->SetFont(font);
00286 alignsizer2->Add( button, 0, 0, 0 );
00287 button = new wxButton( this, wxID_ALIGN_BR, wxT("\xee"), wxDefaultPosition, wxSize(32, 32), wxBU_EXACTFIT );
00288 button->SetFont(font);
00289 alignsizer2->Add( button, 0, 0, 0 );
00290 #else // __WXMSW__
00291 alignsizer2->Add(new wxButton( this, wxID_ALIGN_TL, wxT(""), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00292 alignsizer2->Add(new wxButton( this, wxID_ALIGN_T, wxT("^"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00293 alignsizer2->Add(new wxButton( this, wxID_ALIGN_TR, wxT(""), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00294 alignsizer2->Add(new wxButton( this, wxID_ALIGN_L, wxT("<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00295 alignsizer2->Add(new wxButton( this, wxID_ALIGN_C, wxT("o"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00296 alignsizer2->Add(new wxButton( this, wxID_ALIGN_R, wxT(">"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00297 alignsizer2->Add(new wxButton( this, wxID_ALIGN_BL, wxT(""), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00298 alignsizer2->Add(new wxButton( this, wxID_ALIGN_B, wxT("v"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00299 alignsizer2->Add(new wxButton( this, wxID_ALIGN_BR, wxT(""), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ), 1, wxEXPAND, 0 );
00300 #endif // __WXMSW__
00301 alignsizer->Add(alignsizer2, 0, wxALL | wxEXPAND, 5);
00302 m_aligncheck = new wxCheckBox( this, wxID_CHECK_ALIGN, _("Align on bbox") );
00303
00304
00305 alignsizer->Add( m_aligncheck, 0, 0 );
00306 bottomsizer->Add(alignsizer, 0, wxALL | wxEXPAND, 5);
00307
00308 m_canvas = new a2dCanvas( this, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER );
00309 m_canvas->SetYaxis( true );
00310 m_canvas->SetScaleOnResize( false );
00311 a2dCanvasDocument* root = m_canvas->GetCanvasDocument();
00312 m_canvastext = new a2dText( _T("ABCDEFGabcdefg12345") );
00313 m_canvastext->SetPosXY(0.0, 0.0);
00314 m_canvastext->SetFill( *a2dTRANSPARENT_FILL );
00315 m_canvastext->SetStroke( *wxBLACK );
00316 root->Append(m_canvastext);
00317 m_canvasline1 = new a2dSLine(0.0, 0.0, 1.0, 0.0);
00318 m_canvasline1->SetStroke( wxColour(0xc0, 0xc0, 0xc0 ), 1 );
00319 root->Append(m_canvasline1);
00320 m_canvasline2 = new a2dSLine(0.0, 0.0, 0.0, 1.0);
00321 m_canvasline2->SetStroke( wxColour(0xc0, 0xc0, 0xc0 ), 1 );
00322 root->Append(m_canvasline2);
00323 root->SetCanvasDocumentRecursive();
00324 bottomsizer->Add(m_canvas, 1, wxALL | wxEXPAND, 5);
00325
00326 panelsizer->Add(bottomsizer, 1, wxALL | wxEXPAND, 5);
00327
00328 wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
00329 buttonsizer->Add( new wxButton( this, wxID_FONT_SEARCHPATH, _("Search Path") ), 0, wxALL, 5 );
00330 buttonsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxALL, 5 );
00331 buttonsizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxALL, 5 );
00332 panelsizer->Add(buttonsizer, 0, wxALL | wxEXPAND, 5);
00333
00334 if ( m_typelist->GetCount() )
00335 {
00336 int idx = 0;
00337 idx = m_typelist->FindString( m_currentinfo.GetType() );
00338 if (idx == wxNOT_FOUND)
00339 idx = 0;
00340 m_typelist->SetSelection(idx);
00341 }
00342 wxCommandEvent dummy;
00343 OnChangeFontType( dummy );
00344
00345 SetSizer( panelsizer );
00346 panelsizer->SetSizeHints( this );
00347 }
00348
00349 const a2dFont& a2dFontDialog::GetFontData() const
00350 {
00351 return m_font;
00352 }
00353
00354 a2dFontDialog::~a2dFontDialog()
00355 {
00356 }
00357
00358 void a2dFontDialog::OnChangeFontType(wxCommandEvent& event)
00359 {
00360 wxString type = m_typelist->GetStringSelection();
00361 wxString oldname = m_fontlist->GetStringSelection();
00362
00363 while ( m_fontlist->GetCount() )
00364 m_fontlist->Delete( 0 );
00365
00366 wxArrayString fonts;
00367 for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
00368 {
00369 wxString fonttype = m_fonts.Item(i)->GetData()->GetType();
00370 if (fonttype == type || type == _("* (All types)") )
00371 {
00372 wxString fontname = m_fonts.Item(i)->GetData()->GetName();
00373 size_t j;
00374 for ( j = 0; j < fonts.GetCount(); j++ )
00375 {
00376 if ( fonts.Item(j) == fontname )
00377 break;
00378 }
00379 if ( j == fonts.GetCount() )
00380 fonts.Add( fontname );
00381 }
00382 }
00383 m_fontlist->Append( fonts );
00384
00385 if ( m_fontlist->GetCount() )
00386 {
00387 int idx;
00388 idx = m_fontlist->FindString( m_currentinfo.GetName() );
00389 if( idx == -1 )
00390 idx = m_fontlist->FindString( oldname );
00391 if (idx == wxNOT_FOUND)
00392 idx = 0;
00393 m_fontlist->SetSelection(idx);
00394 }
00395 OnChangeFontName( event );
00396 }
00397
00398 void a2dFontDialog::OnChangeFontName(wxCommandEvent& event)
00399 {
00400 wxString type = m_typelist->GetStringSelection();
00401 wxString name = m_fontlist->GetStringSelection();
00402 wxString oldstyle = m_stylelist->GetStringSelection();
00403
00404 while ( m_stylelist->GetCount() )
00405 m_stylelist->Delete( 0 );
00406
00407 wxArrayString fonts;
00408 for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
00409 {
00410 wxString fontname = m_fonts.Item(i)->GetData()->GetName();
00411 wxString fonttype = m_fonts.Item(i)->GetData()->GetType();
00412 if ((fonttype == type || type == _("* (All types)") )
00413 && fontname == name )
00414 {
00415 wxString fontstyle = m_fonts.Item(i)->GetData()->GetStyle();
00416 size_t j;
00417 for ( j = 0; j < fonts.GetCount(); j++ )
00418 {
00419 if ( fonts.Item(j) == fontstyle )
00420 break;
00421 }
00422 if ( j == fonts.GetCount() )
00423 fonts.Add( fontstyle );
00424 }
00425 }
00426 m_stylelist->Append( fonts );
00427
00428 if ( m_stylelist->GetCount() )
00429 {
00430 int idx;
00431 idx = m_fontlist->FindString( m_currentinfo.GetStyle() );
00432 if( idx == -1 )
00433 idx = m_stylelist->FindString( oldstyle );
00434 if (idx == wxNOT_FOUND)
00435 idx = m_stylelist->FindString( _("Normal") );
00436 if (idx == wxNOT_FOUND)
00437 idx = m_stylelist->FindString( _("Regular") );
00438 if (idx == wxNOT_FOUND)
00439 idx = 0;
00440 m_stylelist->SetSelection(idx);
00441 }
00442 OnChangeFontStyle( event );
00443 }
00444
00445 void a2dFontDialog::OnChangeFontStyle(wxCommandEvent& event)
00446 {
00447 OnChangeFont(event);
00448 }
00449
00450 void a2dFontDialog::OnChangeFontSize( wxCommandEvent& event )
00451 {
00452 m_sizelist->SetSelection( wxNOT_FOUND );
00453 OnChangeFont( event );
00454 }
00455
00456 void a2dFontDialog::OnChangeFontSizeList( wxCommandEvent& event )
00457 {
00458 int idx = m_sizelist->GetSelection();
00459 m_sizeedit->SetValue( m_sizelist->GetStringSelection() );
00460 m_sizelist->SetSelection( idx );
00461 OnChangeFont(event);
00462 }
00463
00464 void a2dFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event) )
00465 {
00466 wxString type = m_typelist->GetStringSelection();
00467 wxString name = m_fontlist->GetStringSelection();
00468 wxString style = m_stylelist->GetStringSelection();
00469
00470 wxArrayString fonts;
00471 for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
00472 {
00473 wxString fonttype = m_fonts.Item(i)->GetData()->GetType();
00474 wxString fontname = m_fonts.Item(i)->GetData()->GetName();
00475 wxString fontstyle = m_fonts.Item(i)->GetData()->GetStyle();
00476 if ((fonttype == type || type == _("* (All types)") )
00477 && fontname == name && fontstyle == style)
00478 {
00479 double size;
00480 m_sizeedit->GetValue().ToDouble( &size );
00481 a2dFontInfo fontinfo = *m_fonts.Item(i)->GetData();
00482
00483
00484
00485 fontinfo.SetSize( size );
00486 m_font = a2dFont::CreateFont( fontinfo );
00487 m_canvastext->SetFont( m_font );
00488 m_canvastext->SetPending( true );
00489 a2dBoundingBox bbox = m_canvastext->GetCalculatedBoundingBox(1);
00490
00491 m_canvasline1->SetPosXY12( -2.0 * bbox.GetWidth(), 0.0, 2.0 * bbox.GetWidth(), 0.0 );
00492 m_canvasline2->SetPosXY12( 0.0, -2.0 * bbox.GetWidth(), 0.0, 2.0 * bbox.GetWidth() );
00493
00494
00495 a2dBoundingBox bboxnew = bbox;
00496 bboxnew.Enlarge( bbox.GetHeight() / 6.0 );
00497 if (m_alignment & wxLEFT)
00498 bboxnew.Translate( -bbox.GetHeight() / 8.0, 0.0 );
00499 if (m_alignment & wxRIGHT)
00500 bboxnew.Translate( bbox.GetHeight() / 8.0, 0.0 );
00501
00502 if (m_alignment & wxBOTTOM)
00503 bboxnew.Translate( 0.0, -bbox.GetHeight() / 8.0 );
00504 if (m_alignment & wxTOP )
00505 bboxnew.Translate( 0.0, bbox.GetHeight() / 8.0 );
00506
00507 if (m_alignment & wxBBOX)
00508 m_canvastext->SetFill( wxColour( 0xf0, 0xf0, 0xff ) );
00509 else
00510 m_canvastext->SetFill( *a2dTRANSPARENT_FILL );
00511
00512 m_canvas->SetMappingWidthHeight (bboxnew.GetMinX(), bboxnew.GetMinY(),
00513 bboxnew.GetWidth(), bboxnew.GetHeight(), false);
00514 m_canvas->Refresh();
00515 break;
00516 }
00517 }
00518 }
00519
00520 void a2dFontDialog::OnSearchPath(wxCommandEvent& event)
00521 {
00522 a2dFontSearchPathDialog dlg;
00523 if ( dlg.ShowModal() == wxID_OK )
00524 {
00525 m_fonts.Clear();
00526 a2dFont::GetInfoList( m_fonts );
00527
00528 wxString oldtype = m_typelist->GetStringSelection();
00529
00530 while ( m_typelist->GetCount() )
00531 m_typelist->Delete( 0 );
00532 wxArrayString types;
00533 types.Add( _("* (All types)") );
00534 for ( size_t i = 0; i < m_fonts.GetCount(); i++ )
00535 {
00536 wxString type = m_fonts.Item(i)->GetData()->GetType();
00537 size_t j;
00538 for ( j = 0; j < types.GetCount(); j++ )
00539 {
00540 if ( types.Item(j) == type )
00541 break;
00542 }
00543 if ( j == types.GetCount() )
00544 types.Add( type );
00545 }
00546 m_typelist->Append( types );
00547
00548 if ( m_typelist->GetCount() )
00549 {
00550 int idx = m_typelist->FindString( oldtype );
00551 if (idx == wxNOT_FOUND)
00552 idx = 0;
00553 m_typelist->SetSelection(idx);
00554 }
00555 OnChangeFontType( event );
00556 }
00557 }
00558
00559 void a2dFontDialog::OnAlignment(wxCommandEvent& event)
00560 {
00561 switch( event.GetId() )
00562 {
00563 case wxID_ALIGN_TL: m_alignment = wxTOP | wxLEFT; break;
00564 case wxID_ALIGN_T: m_alignment = wxTOP; break;
00565 case wxID_ALIGN_TR: m_alignment = wxTOP | wxRIGHT; break;
00566 case wxID_ALIGN_L: m_alignment = wxLEFT; break;
00567 case wxID_ALIGN_C: m_alignment = wxCENTRE; break;
00568 case wxID_ALIGN_R: m_alignment = wxRIGHT; break;
00569 case wxID_ALIGN_BL: m_alignment = wxBOTTOM | wxLEFT; break;
00570 case wxID_ALIGN_B: m_alignment = wxBOTTOM; break;
00571 case wxID_ALIGN_BR: m_alignment = wxBOTTOM | wxRIGHT; break;
00572 default: ;
00573 }
00574 if ( m_aligncheck->IsChecked() )
00575 m_alignment |= wxBBOX;
00576 else
00577 m_alignment &= ~wxBBOX;
00578
00579 OnChangeFont( event );
00580 }
00581
00582 void a2dFontDialog::OnSize(wxSizeEvent& event)
00583 {
00584 event.Skip();
00585
00586 a2dBoundingBox bbox = m_canvastext->GetCalculatedBoundingBox(1);
00587
00588 a2dBoundingBox bboxnew = bbox;
00589 bboxnew.Enlarge( bbox.GetHeight() / 6.0 );
00590 if (m_alignment & wxLEFT)
00591 bboxnew.Translate( -bbox.GetHeight() / 8.0, 0.0 );
00592 if (m_alignment & wxRIGHT)
00593 bboxnew.Translate( bbox.GetHeight() / 8.0, 0.0 );
00594
00595 if (m_alignment & wxBOTTOM)
00596 bboxnew.Translate( 0.0, -bbox.GetHeight() / 8.0 );
00597 if (m_alignment & wxTOP )
00598 bboxnew.Translate( 0.0, bbox.GetHeight() / 8.0 );
00599
00600 if (m_alignment & wxBBOX)
00601 m_canvastext->SetFill( wxColour( 0xf0, 0xf0, 0xff ) );
00602 else
00603 m_canvastext->SetFill( *a2dTRANSPARENT_FILL );
00604
00605 m_canvas->SetMappingWidthHeight (bboxnew.GetMinX(), bboxnew.GetMinY(),
00606 bboxnew.GetWidth(), bboxnew.GetHeight(), false);
00607 m_canvas->Refresh();
00608 }