wxArt2D
fontdlg.h
Go to the documentation of this file.
1 /*! \file wx/canvas/fontdlg.h
2  \brief dialog for choosing fonts
3  \author Erik van der Wal
4 
5  Copyright: 2000-2004 (c) Klaas Holwerda
6 
7  Licence: wxWidgets Licence
8 
9  RCS-ID: $Id: fontdlg.h,v 1.7 2008/07/30 21:54:02 titato Exp $
10 */
11 
12 #ifndef __FONTDLG_H__
13 #define __FONTDLG_H__
14 
15 #include "wx/artbase/stylebase.h"
16 #include "wx/canvas/cantext.h"
17 #include "wx/canvas/sttool.h"
18 
19 class wxListBox;
20 class wxTextCtrl;
21 class wxCheckBox;
22 class a2dCanvas;
23 class a2dText;
24 class a2dSLine;
25 
26 //! Display a dialog to edit the font search path.
27 /*! \class a2dFontSearchPathDialog fontdlg.h editor/fontdlg.h
28  \ingroup textrelated
29 */
30 class A2DCANVASDLLEXP a2dFontSearchPathDialog : public wxDialog
31 {
32 public:
33  //! Constructor.
34  a2dFontSearchPathDialog( wxWindow* parent = NULL );
35  //! Destructor.
37 protected:
38  //! User interface event handler.
39  void OnAdd( wxCommandEvent& event );
40  //! User interface event handler.
41  void OnDelete( wxCommandEvent& event );
42  //! User interface event handler.
43  void OnListBox( wxCommandEvent& event );
44  //! User interface event handler.
45  void OnPathButton( wxCommandEvent& event );
46  //! User interface event handler.
47  void OnText( wxCommandEvent& event );
48  //! User interface event handler.
49  void OnOK( wxCommandEvent& event );
50 protected:
51  //! User interface object.
52  wxListBox* m_listbox;
53  //! User interface object.
54  wxTextCtrl* m_textctrl;
55  //! User interface object.
56  wxButton* m_button;
57 private:
58  DECLARE_EVENT_TABLE()
59  DECLARE_DYNAMIC_CLASS( a2dFontSearchPathDialog )
60 };
61 
62 //! Display a font selection dialog.
63 /*! \class a2dTextPropDlg fontdlg.h editor/fontdlg.h
64  \todo EW: Font scaling in the selection dialog. Now it is always scaled to fit in the window, but how to handle font sizes (eg. 0.000001 to 100000) in a consistent way? Maybe do the scaling in magnitudes of 10?
65  \ingroup textrelated
66 */
67 class A2DCANVASDLLEXP a2dTextPropDlg : public wxDialog
68 {
69 public:
70  //! Constructor.
71  a2dTextPropDlg( wxWindow* parent = NULL, const a2dFont& currentfont = *a2dDEFAULT_CANVASFONT, unsigned int textflags = a2dText::a2dCANVASTEXT_DEFAULTFLAGS, int alignment = a2dDEFAULT_ALIGNMENT );
72  //! Destructor.
73  virtual ~a2dTextPropDlg();
74 
75  //! Returns the font.
76  const a2dFont& GetFontData() const;
77 
78  //! Set the position of the anchor point w.r.t the text.
79  /*! \param alignment sets the direction of the anchor point. The direction can be set like e.g.
80  wxMINX | wxMINY, meaning a specific corner of the boundingbox.
81  Not specifying either a horizontal or vertical position will default to the centre. So only
82  specifying wxMINX corresponds to the left and middle Y of bbox position.
83  If Yaxis is up in a view, use wxBASELINE to have text origin start at (x,y).
84  If Yaxis is down in a view, use wxBASELINE_CONTRA to have text origin start at (x,y).
85  <!-- view picture using monospaced font -->
86  \code
87  +-----^-----+ wxMAXY
88  | # |
89  | # |
90  | #### #### |
91  |# # # #|
92  +-####-#---#+ wxBASELINE
93  | # |
94  | ### |
95  +-----v-----+ wxMINY
96  wxMINX wxMAXX
97  \endcode
98  */
99  inline void SetAlignment( int alignment )
100  {
101  m_alignment = alignment;
102  OnChangeFont();
103  }
104  //! Get the position of the anchor point w.r.t the text
105  /*! \return The alignment setting.
106  */
107  inline int GetAlignment() const
108  { return m_alignment; }
109 
110  //! Set the text flags
111  inline void SetTextFlags( unsigned int textflags )
112  {
113  m_textflags = textflags;
114  OnChangeFont();
115  }
116  //! Get the text flags
117  inline unsigned int GetTextFlags() const { return m_textflags; }
118 
119  //! User interface event handler.
120  void OnChangeFont();
121  //! User interface event handler.
122  void OnChangeFontType( wxCommandEvent& event );
123  //! User interface event handler.
124  void OnChangeFontName( wxCommandEvent& event );
125  //! User interface event handler.
126  void OnChangeFontStyle( wxCommandEvent& event );
127  //! User interface event handler.
128  void OnChangeFontSize( wxCommandEvent& event );
129  //! User interface event handler.
130  void OnChangeFontSizeList( wxCommandEvent& event );
131  //! User interface event handler.
132  void OnSearchPath( wxCommandEvent& event );
133  //! User interface event handler.
134  void OnAlignment( wxCommandEvent& event );
135  //! User interface event handler.
136  void OnSize( wxSizeEvent& event );
137 
138 protected:
139  //! Selected font.
141  //! Font enumeration list.
143  //! Scale at which the font is viewed.
144  double m_viewscale;
145  //! Font alignment
147 
148  //! contains several text flags.
149  unsigned int m_textflags;
150 
151  // used initially to select current font.
152  a2dFontInfo m_currentinfo;
153 
154  //! User interface object.
155  wxListBox* m_typelist;
156  //! User interface object.
157  wxListBox* m_fontlist;
158  //! User interface object.
159  wxListBox* m_stylelist;
160  //! User interface object.
161  wxTextCtrl* m_sizeedit;
162  //! User interface object.
163  wxListBox* m_sizelist;
164  //! User interface object.
165  wxCheckBox* m_aligncheck;
166 
167  wxCheckBox* m_textframe;
168  wxCheckBox* m_textbackground;
169 
170  //! User interface object.
172  //! Displayed text
174  //! Horizontal line to indicate alignment
176  //! Vertical line to indicate alignment
178 
179 private:
180  DECLARE_EVENT_TABLE()
181  DECLARE_DYNAMIC_CLASS( a2dTextPropDlg )
182 };
183 
184 #include "wx/canvas/styledialg.h"
185 
186 //===========================================================================
187 // a2dTextPropDlgExt - dialog for defining font and style on an a2dCanvasObject:
188 //===========================================================================
189 class wxBitmapToggleButton; // forward declaration
190 
191 #define a2dDEFAULT_FONTTYPE wxT("Freetype font")
192 
193 /*! Extended font dialog for selection of text objects
194 
195  Create the list of fonts (stored in a2dTextChanges) and filter them
196  <code>
197  const int TNumFonts = 16;
198  const wxString TFonts[TNumFonts] = { wxT("Arial"), wxT("Comic Sans MS"), wxT("Georgia"), wxT("Impact"), wxT("Lucida Sans"), wxT("Palatino Linotype"), wxT("Tahoma"), wxT("Times New Roman"), wxT("Trebuchet MS"), wxT("Verdana"), wxT("Liberation Sans"), wxT("Liberation Serif"), wxT("Liberation Mono"), wxT("DejaVu Sans"), wxT("DejaVu Sans Mono"), wxT("DejaVu Serif") };
199  wxArrayString filterlist(TNumFonts, TFonts);
200 
201  a2dTextChanges::InitialiseFontList(filterlist, DEFAULT_FONTTYPE); // create the list of available fonts
202  //a2dTextChanges::InitialiseFontList(); // create the list of available fonts
203  </code>
204 */
205 class a2dTextPropDlgExt : public wxDialog
206 {
207 public:
208  // bGlobal ... global settings (show info in title bar)
209  // bFill ... enable fill combobox
210  // fontlist ... list of all available fonts (from a2dFont::GetInfoList( a2dFontInfoList& list ))
211  // bAllowLayerStyle ... allows selection for using layer style
212  a2dTextPropDlgExt( a2dHabitat* habitat, wxWindow *parent, bool bGlobal, bool bFill, a2dFontInfoList *fontlist, bool bAllowLayerStyle = false);
213 
214  // Number that defines the physical dimension (in millimeters) of document units.
215  void SetUnitsScale(double scale) { m_UnitsScale = scale; }
216 
217  void SetCustomColors(const a2dCustomColors& colors) { m_CustomColors = colors; }
218  const a2dCustomColors& a2dGetCustomColors() const { return m_CustomColors; }
219 
220  const a2dExtStroke& GetExtStroke() const { return m_ExtStroke; }
221  void SetExtStroke(const a2dExtStroke& extStroke) { m_ExtStroke = extStroke; }
222 
223  const a2dExtFill& GetExtFill() const { return m_ExtFill; }
224  void SetExtFill(const a2dExtFill& extFill) { m_ExtFill = extFill; }
225 
226  const a2dTextChanges& GetExtFont() const { return m_ExtFont; }
227  void SetExtFont(const a2dTextChanges& extFont) { m_ExtFont = extFont; }
228 
229  //! User interface event handler.
230  void OnChangeFont();
231  //! User interface event handler.
232  void OnChangeFontType( wxCommandEvent& event );
233  //! User interface event handler.
234  void OnChangeFontName( wxCommandEvent& event );
235  //! User interface event handler.
236  void OnChangeFontStyle( wxCommandEvent& event );
237  //! User interface event handler.
238  void OnChangeFontSize( wxCommandEvent& event );
239  //! User interface event handler.
240  void OnChangeFontSizeList( wxCommandEvent& event );
241  //! User interface event handler.
242  void OnSearchPath( wxCommandEvent& event );
243  //! User interface event handler.
244  void OnAlignment( wxCommandEvent& event );
245  //! User interface event handler.
246  void OnTextflags( wxCommandEvent& event );
247  //! User interface event handler.
248  void OnSize( wxSizeEvent& event );
249  //! User interface event handler.
250  void OnColourChange( wxCommandEvent& event );
251 
252 private:
253  void CreateControls(bool bAllowLayerStyle);
254  void UpdateStrokeData(bool bGetFromDlg);
255  void UpdateFontData();
256  //// Sets the correct alignment button
257  void SetAlignment(int align);
258  // Returns a list of fonts for the given type
259  wxArrayString GetFontList(wxString type);
260  // Returns the longest style-string of all fonts (needed to initialize the size of style-listbox)
261  wxString GetLongestStyle();
262  void RepaintSample();
263 
264  //========================================================
265  // Event handler:
266  //--------------------------------------------------------
267  void OnInitDialog(wxInitDialogEvent& event);
268  void OnOk(wxCommandEvent& event);
269 
270  DECLARE_EVENT_TABLE()
271 
272 private:
273  bool m_bFill;
274  double m_UnitsScale;
275  bool m_FontFound;
276  wxStringToStringHashMap m_styles;
277  a2dCustomColors m_CustomColors;
278  a2dExtStroke m_ExtStroke;
279  a2dExtFill m_ExtFill;
280  a2dTextChanges m_ExtFont;
281 
282  wxBoxSizer* m_pTopSizer;
283  a2dColorComboBox *m_pStrokeColorBox;
284  a2dFillComboBox *m_pFillBox;
285  wxBitmapToggleButton *m_pAlignTR_Bt;
286  wxBitmapToggleButton *m_pAlignT_Bt;
287  wxBitmapToggleButton *m_pAlignTL_Bt;
288  wxBitmapToggleButton *m_pAlignR_Bt;
289  wxBitmapToggleButton *m_pAlignC_Bt;
290  wxBitmapToggleButton *m_pAlignL_Bt;
291  wxBitmapToggleButton *m_pAlignBR_Bt;
292  wxBitmapToggleButton *m_pAlignB_Bt;
293  wxBitmapToggleButton *m_pAlignBL_Bt;
294 
295  //a2dFontInfoList m_fonts;
296  a2dFontInfoList *m_fonts;
297  //! Scale at which the font is viewed.
298  double m_viewscale;
299 
300  //! User interface object.
301  wxListBox* m_typelist;
302  //! User interface object.
303  wxListBox* m_fontlist;
304  //! User interface object.
305  wxListBox* m_stylelist;
306  //! User interface object.
307  wxTextCtrl* m_sizeedit;
308  //! User interface object.
309  wxListBox* m_sizelist;
310  //! User interface object.
311  wxCheckBox* m_aligncheck;
312  //! User interface object.
313  wxCheckBox* m_textframe;
314  //! User interface object.
315  wxCheckBox* m_textbackground;
316  //! User interface object.
317  a2dCanvas* m_canvas;
318  //! Displayed text
319  a2dText* m_canvastext;
320  //! Horizontal line to indicate alignment
321  a2dSLine* m_canvasline1;
322  //! Vertical line to indicate alignment
323  a2dSLine* m_canvasline2;
324 
325  a2dHabitat* m_habitat;
326 };
327 
328 extern wxUint32 a2dSetTextChanges( a2dTextChanges& returned, a2dCanvasObjectList* objects, a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::SELECTED, a2dLayers* layersetup = NULL );
329 
330 #endif // __FONTDLG_H__
a2dText derived from a2dCanvasObject, holds multiline text
Display a font selection dialog.
Definition: fontdlg.h:67
Stroke and fill base classes.
Font info class, used as a single element for enumerating fonts.
Definition: stylebase.h:686
wxTextCtrl * m_textctrl
User interface object.
Definition: fontdlg.h:54
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
wxTextCtrl * m_sizeedit
User interface object.
Definition: fontdlg.h:161
wxListBox * m_sizelist
User interface object.
Definition: fontdlg.h:163
wxListBox * m_stylelist
User interface object.
Definition: fontdlg.h:159
a2dSLine * m_canvasline1
Horizontal line to indicate alignment.
Definition: fontdlg.h:175
void SetAlignment(int alignment)
Set the position of the anchor point w.r.t the text.
Definition: fontdlg.h:99
wxListBox * m_listbox
User interface object.
Definition: fontdlg.h:52
wxUint64 a2dCanvasObjectFlagsMask
mask flags for a2dCanvasObject
Definition: candefs.h:152
a2dText * m_canvastext
Displayed text.
Definition: fontdlg.h:173
a2dText is an abstract base class.
Definition: cantext.h:93
wxListBox * m_typelist
User interface object.
Definition: fontdlg.h:155
unsigned int GetTextFlags() const
Get the text flags.
Definition: fontdlg.h:117
a2dCanvas * m_canvas
User interface object.
Definition: fontdlg.h:171
wxCheckBox * m_aligncheck
User interface object.
Definition: fontdlg.h:165
a2dSLine
Definition: canprim.h:987
static const a2dCanvasObjectFlagsMask SELECTED
Definition: candefs.h:180
defines common settinsg for a habitat for a set of a2dCameleons.
Definition: canglob.h:439
int GetAlignment() const
Get the position of the anchor point w.r.t the text.
Definition: fontdlg.h:107
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
wxButton * m_button
User interface object.
Definition: fontdlg.h:56
const a2dFont * a2dDEFAULT_CANVASFONT
global a2dFont stock object for default font
void SetTextFlags(unsigned int textflags)
Set the text flags.
Definition: fontdlg.h:111
double m_viewscale
Scale at which the font is viewed.
Definition: fontdlg.h:144
a2dFont m_font
Selected font.
Definition: fontdlg.h:140
A list used for enumerating fonts.
unsigned int m_textflags
contains several text flags.
Definition: fontdlg.h:149
a2dSLine * m_canvasline2
Vertical line to indicate alignment.
Definition: fontdlg.h:177
stack based tools controller and tools for drawing and editing.
a2dFontInfoList m_fonts
Font enumeration list.
Definition: fontdlg.h:142
fontdlg.h Source File -- Sun Oct 12 2014 17:04:19 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation