1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtextsymboldlg.h
4 // Author: Julian Smart
6 // Created: 10/5/2006 3:11:58 PM
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _RICHTEXTSYMBOLDLG_H_
13 #define _RICHTEXTSYMBOLDLG_H_
19 #include "wx/dialog.h"
20 #include "wx/vscroll.h"
23 * Forward declarations
26 ////@begin forward declarations
27 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
;
28 class WXDLLIMPEXP_CORE wxComboBox
;
29 class WXDLLIMPEXP_CORE wxStaticText
;
30 class WXDLLIMPEXP_CORE wxTextCtrl
;
31 ////@end forward declarations
43 #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE (wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX)
44 #define SYMBOL_WXSYMBOLPICKERDIALOG_TITLE _("Symbols")
45 #define SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME ID_SYMBOLPICKERDIALOG
46 #define SYMBOL_WXSYMBOLPICKERDIALOG_SIZE wxSize(400, 300)
47 #define SYMBOL_WXSYMBOLPICKERDIALOG_POSITION wxDefaultPosition
50 * wxSymbolPickerDialog class declaration
53 class WXDLLIMPEXP_RICHTEXT wxSymbolPickerDialog
: public wxDialog
55 DECLARE_DYNAMIC_CLASS( wxSymbolPickerDialog
)
60 wxSymbolPickerDialog( );
61 wxSymbolPickerDialog( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
62 wxWindow
* parent
, wxWindowID id
= SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME
, const wxString
& caption
= SYMBOL_WXSYMBOLPICKERDIALOG_TITLE
, const wxPoint
& pos
= SYMBOL_WXSYMBOLPICKERDIALOG_POSITION
, const wxSize
& size
= SYMBOL_WXSYMBOLPICKERDIALOG_SIZE
, long style
= SYMBOL_WXSYMBOLPICKERDIALOG_STYLE
);
65 bool Create( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
66 wxWindow
* parent
, wxWindowID id
= SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME
, const wxString
& caption
= SYMBOL_WXSYMBOLPICKERDIALOG_TITLE
, const wxPoint
& pos
= SYMBOL_WXSYMBOLPICKERDIALOG_POSITION
, const wxSize
& size
= SYMBOL_WXSYMBOLPICKERDIALOG_SIZE
, long style
= SYMBOL_WXSYMBOLPICKERDIALOG_STYLE
);
68 /// Initialises members variables
71 /// Creates the controls and sizers
72 void CreateControls();
74 /// Update the display
75 void UpdateSymbolDisplay(bool updateSymbolList
= true, bool showAtSubset
= true);
77 /// Respond to symbol selection
78 void OnSymbolSelected( wxCommandEvent
& event
);
81 void SetUnicodeMode(bool unicodeMode
);
83 /// Show at the current subset selection
86 /// Get the selected symbol character
87 int GetSymbolChar() const;
89 /// Is there a selection?
90 bool HasSelection() const { return !m_symbol
.IsEmpty(); }
92 /// Specifying normal text?
93 bool UseNormalFont() const { return m_fontName
.IsEmpty(); }
96 virtual bool TransferDataToWindow();
98 ////@begin wxSymbolPickerDialog event handler declarations
100 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT
101 void OnFontCtrlSelected( wxCommandEvent
& event
);
103 #if defined(__UNICODE__)
104 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET
105 void OnSubsetSelected( wxCommandEvent
& event
);
108 #if defined(__UNICODE__)
109 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM
110 void OnFromUnicodeSelected( wxCommandEvent
& event
);
113 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXOS2__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
114 /// wxEVT_UPDATE_UI event handler for wxID_OK
115 void OnOkUpdate( wxUpdateUIEvent
& event
);
118 #if defined(__WXMAC__)
119 /// wxEVT_UPDATE_UI event handler for wxID_OK
120 void OnOkUpdate( wxUpdateUIEvent
& event
);
123 ////@end wxSymbolPickerDialog event handler declarations
125 ////@begin wxSymbolPickerDialog member function declarations
127 wxString
GetFontName() const { return m_fontName
; }
128 void SetFontName(wxString value
) { m_fontName
= value
; }
130 wxString
GetSymbol() const { return m_symbol
; }
131 void SetSymbol(wxString value
) { m_symbol
= value
; }
133 bool GetFromUnicode() const { return m_fromUnicode
; }
134 void SetFromUnicode(bool value
) { m_fromUnicode
= value
; }
136 wxString
GetNormalTextFontName() const { return m_normalTextFontName
; }
137 void SetNormalTextFontName(wxString value
) { m_normalTextFontName
= value
; }
139 /// Retrieves bitmap resources
140 wxBitmap
GetBitmapResource( const wxString
& name
);
142 /// Retrieves icon resources
143 wxIcon
GetIconResource( const wxString
& name
);
144 ////@end wxSymbolPickerDialog member function declarations
146 /// Should we show tooltips?
147 static bool ShowToolTips();
149 ////@begin wxSymbolPickerDialog member variables
150 wxComboBox
* m_fontCtrl
;
151 #if defined(__UNICODE__)
152 wxComboBox
* m_subsetCtrl
;
154 wxSymbolListCtrl
* m_symbolsCtrl
;
155 wxStaticText
* m_symbolStaticCtrl
;
156 wxTextCtrl
* m_characterCodeCtrl
;
157 #if defined(__UNICODE__)
158 wxComboBox
* m_fromUnicodeCtrl
;
163 wxString m_normalTextFontName
;
164 /// Control identifiers
166 ID_SYMBOLPICKERDIALOG
= 10600,
167 ID_SYMBOLPICKERDIALOG_FONT
= 10602,
168 ID_SYMBOLPICKERDIALOG_SUBSET
= 10605,
169 ID_SYMBOLPICKERDIALOG_LISTCTRL
= 10608,
170 ID_SYMBOLPICKERDIALOG_CHARACTERCODE
= 10601,
171 ID_SYMBOLPICKERDIALOG_FROM
= 10603
173 ////@end wxSymbolPickerDialog member variables
179 * The scrolling symbol list.
182 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
: public wxVScrolledWindow
185 // constructors and such
186 // ---------------------
188 // default constructor, you must call Create() later
189 wxSymbolListCtrl() { Init(); }
191 // normal constructor which calls Create() internally
192 wxSymbolListCtrl(wxWindow
*parent
,
193 wxWindowID id
= wxID_ANY
,
194 const wxPoint
& pos
= wxDefaultPosition
,
195 const wxSize
& size
= wxDefaultSize
,
197 const wxString
& name
= wxPanelNameStr
)
201 (void)Create(parent
, id
, pos
, size
, style
, name
);
204 // really creates the control and sets the initial number of items in it
205 // (which may be changed later with SetItemCount())
207 // returns true on success or false if the control couldn't be created
208 bool Create(wxWindow
*parent
,
209 wxWindowID id
= wxID_ANY
,
210 const wxPoint
& pos
= wxDefaultPosition
,
211 const wxSize
& size
= wxDefaultSize
,
213 const wxString
& name
= wxPanelNameStr
);
215 // dtor does some internal cleanup
216 virtual ~wxSymbolListCtrl();
222 // set the current font
223 virtual bool SetFont(const wxFont
& font
);
225 // set Unicode/ASCII mode
226 void SetUnicodeMode(bool unicodeMode
);
228 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
229 int GetSelection() const;
231 // is this item selected?
232 bool IsSelected(int item
) const;
234 // is this item the current one?
235 bool IsCurrentItem(int item
) const { return item
== m_current
; }
237 // get the margins around each cell
238 wxPoint
GetMargins() const { return m_ptMargins
; }
240 // get the background colour of selected cells
241 const wxColour
& GetSelectionBackground() const { return m_colBgSel
; }
246 // set the selection to the specified item, if it is wxNOT_FOUND the
247 // selection is unset
248 void SetSelection(int selection
);
250 // make this item visible
251 void EnsureVisible(int item
);
253 // set the margins: horizontal margin is the distance between the window
254 // border and the item contents while vertical margin is half of the
255 // distance between items
257 // by default both margins are 0
258 void SetMargins(const wxPoint
& pt
);
259 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
262 void SetCellSize(const wxSize
& sz
) { m_cellSize
= sz
; }
263 const wxSize
& GetCellSize() const { return m_cellSize
; }
265 // change the background colour of the selected cells
266 void SetSelectionBackground(const wxColour
& col
);
268 virtual wxVisualAttributes
GetDefaultAttributes() const
270 return GetClassDefaultAttributes(GetWindowVariant());
273 static wxVisualAttributes
274 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
276 // Get min/max symbol values
277 int GetMinSymbolValue() const { return m_minSymbolValue
; }
278 int GetMaxSymbolValue() const { return m_maxSymbolValue
; }
280 // Respond to size change
281 void OnSize(wxSizeEvent
& event
);
285 // draws a line of symbols
286 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
288 // gets the line height
289 virtual wxCoord
OnGetLineHeight(size_t line
) const;
292 void OnPaint(wxPaintEvent
& event
);
293 void OnKeyDown(wxKeyEvent
& event
);
294 void OnLeftDown(wxMouseEvent
& event
);
295 void OnLeftDClick(wxMouseEvent
& event
);
297 // common part of all ctors
300 // send the wxEVT_COMMAND_LISTBOX_SELECTED event
301 void SendSelectedEvent();
303 // change the current item (in single selection listbox it also implicitly
304 // changes the selection); current may be wxNOT_FOUND in which case there
305 // will be no current item any more
307 // return true if the current item changed, false otherwise
308 bool DoSetCurrent(int current
);
310 // flags for DoHandleItemClick
313 ItemClick_Shift
= 1, // item shift-clicked
314 ItemClick_Ctrl
= 2, // ctrl
315 ItemClick_Kbd
= 4 // item selected from keyboard
318 // common part of keyboard and mouse handling processing code
319 void DoHandleItemClick(int item
, int flags
);
321 // calculate line number from symbol value
322 int SymbolValueToLineNumber(int item
);
324 // initialise control from current min/max values
325 void SetupCtrl(bool scrollToSelection
= true);
328 int HitTest(const wxPoint
& pt
);
331 // the current item or wxNOT_FOUND
337 // the selection bg colour
341 wxBitmap
* m_doubleBuffer
;
346 // minimum and maximum symbol value
347 int m_minSymbolValue
;
349 // minimum and maximum symbol value
350 int m_maxSymbolValue
;
352 // number of items per line
353 int m_symbolsPerLine
;
355 // Unicode/ASCII mode
358 DECLARE_EVENT_TABLE()
359 DECLARE_NO_COPY_CLASS(wxSymbolListCtrl
)
360 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl
)
364 // _RICHTEXTSYMBOLDLG_H_