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/vscroll.h"
22 * Forward declarations
25 ////@begin forward declarations
26 class wxSymbolListCtrl
;
27 ////@end forward declarations
39 #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX
40 #define SYMBOL_WXSYMBOLPICKERDIALOG_TITLE _("Symbols")
41 #define SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME ID_SYMBOLPICKERDIALOG
42 #define SYMBOL_WXSYMBOLPICKERDIALOG_SIZE wxSize(400, 300)
43 #define SYMBOL_WXSYMBOLPICKERDIALOG_POSITION wxDefaultPosition
46 * wxSymbolPickerDialog class declaration
49 class WXDLLIMPEXP_RICHTEXT wxSymbolPickerDialog
: public wxDialog
51 DECLARE_DYNAMIC_CLASS( wxSymbolPickerDialog
)
56 wxSymbolPickerDialog( );
57 wxSymbolPickerDialog( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
58 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
);
61 bool Create( 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
);
64 /// Initialises members variables
67 /// Creates the controls and sizers
68 void CreateControls();
70 /// Update the display
71 void UpdateSymbolDisplay(bool updateSymbolList
= true, bool showAtSubset
= true);
73 /// Respond to symbol selection
74 void OnSymbolSelected( wxCommandEvent
& event
);
77 void SetUnicodeMode(bool unicodeMode
);
79 /// Show at the current subset selection
82 /// Get the selected symbol character
83 int GetSymbolChar() const;
85 /// Is there a selection?
86 bool HasSelection() const { return !m_symbol
.IsEmpty(); }
88 /// Specifying normal text?
89 bool UseNormalFont() const { return m_fontName
.IsEmpty(); }
92 virtual bool TransferDataToWindow();
94 ////@begin wxSymbolPickerDialog event handler declarations
96 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT
97 void OnFontCtrlSelected( wxCommandEvent
& event
);
99 #if defined(__UNICODE__)
100 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET
101 void OnSubsetSelected( wxCommandEvent
& event
);
104 #if defined(__UNICODE__)
105 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM
106 void OnFromUnicodeSelected( wxCommandEvent
& event
);
109 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXOS2__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
110 /// wxEVT_UPDATE_UI event handler for wxID_OK
111 void OnOkUpdate( wxUpdateUIEvent
& event
);
114 #if defined(__WXMAC__)
115 /// wxEVT_UPDATE_UI event handler for wxID_OK
116 void OnOkUpdate( wxUpdateUIEvent
& event
);
119 ////@end wxSymbolPickerDialog event handler declarations
121 ////@begin wxSymbolPickerDialog member function declarations
123 wxString
GetFontName() const { return m_fontName
; }
124 void SetFontName(wxString value
) { m_fontName
= value
; }
126 wxString
GetSymbol() const { return m_symbol
; }
127 void SetSymbol(wxString value
) { m_symbol
= value
; }
129 bool GetFromUnicode() const { return m_fromUnicode
; }
130 void SetFromUnicode(bool value
) { m_fromUnicode
= value
; }
132 wxString
GetNormalTextFontName() const { return m_normalTextFontName
; }
133 void SetNormalTextFontName(wxString value
) { m_normalTextFontName
= value
; }
135 /// Retrieves bitmap resources
136 wxBitmap
GetBitmapResource( const wxString
& name
);
138 /// Retrieves icon resources
139 wxIcon
GetIconResource( const wxString
& name
);
140 ////@end wxSymbolPickerDialog member function declarations
142 /// Should we show tooltips?
143 static bool ShowToolTips();
145 ////@begin wxSymbolPickerDialog member variables
146 wxComboBox
* m_fontCtrl
;
147 #if defined(__UNICODE__)
148 wxComboBox
* m_subsetCtrl
;
150 wxSymbolListCtrl
* m_symbolsCtrl
;
151 wxStaticText
* m_symbolStaticCtrl
;
152 wxTextCtrl
* m_characterCodeCtrl
;
153 #if defined(__UNICODE__)
154 wxComboBox
* m_fromUnicodeCtrl
;
159 wxString m_normalTextFontName
;
160 /// Control identifiers
162 ID_SYMBOLPICKERDIALOG
= 10600,
163 ID_SYMBOLPICKERDIALOG_FONT
= 10602,
164 ID_SYMBOLPICKERDIALOG_SUBSET
= 10605,
165 ID_SYMBOLPICKERDIALOG_LISTCTRL
= 10608,
166 ID_SYMBOLPICKERDIALOG_CHARACTERCODE
= 10601,
167 ID_SYMBOLPICKERDIALOG_FROM
= 10603
169 ////@end wxSymbolPickerDialog member variables
175 * The scrolling symbol list.
178 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
: public wxVScrolledWindow
181 // constructors and such
182 // ---------------------
184 // default constructor, you must call Create() later
185 wxSymbolListCtrl() { Init(); }
187 // normal constructor which calls Create() internally
188 wxSymbolListCtrl(wxWindow
*parent
,
189 wxWindowID id
= wxID_ANY
,
190 const wxPoint
& pos
= wxDefaultPosition
,
191 const wxSize
& size
= wxDefaultSize
,
193 const wxString
& name
= wxPanelNameStr
)
197 (void)Create(parent
, id
, pos
, size
, style
, name
);
200 // really creates the control and sets the initial number of items in it
201 // (which may be changed later with SetItemCount())
203 // returns true on success or false if the control couldn't be created
204 bool Create(wxWindow
*parent
,
205 wxWindowID id
= wxID_ANY
,
206 const wxPoint
& pos
= wxDefaultPosition
,
207 const wxSize
& size
= wxDefaultSize
,
209 const wxString
& name
= wxPanelNameStr
);
211 // dtor does some internal cleanup
212 virtual ~wxSymbolListCtrl();
218 // set the current font
219 virtual bool SetFont(const wxFont
& font
);
221 // set Unicode/ASCII mode
222 void SetUnicodeMode(bool unicodeMode
);
224 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
225 int GetSelection() const;
227 // is this item selected?
228 bool IsSelected(int item
) const;
230 // is this item the current one?
231 bool IsCurrentItem(int item
) const { return item
== m_current
; }
233 // get the margins around each cell
234 wxPoint
GetMargins() const { return m_ptMargins
; }
236 // get the background colour of selected cells
237 const wxColour
& GetSelectionBackground() const { return m_colBgSel
; }
242 // set the selection to the specified item, if it is wxNOT_FOUND the
243 // selection is unset
244 void SetSelection(int selection
);
246 // make this item visible
247 void EnsureVisible(int item
);
249 // set the margins: horizontal margin is the distance between the window
250 // border and the item contents while vertical margin is half of the
251 // distance between items
253 // by default both margins are 0
254 void SetMargins(const wxPoint
& pt
);
255 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
258 void SetCellSize(const wxSize
& sz
) { m_cellSize
= sz
; }
259 const wxSize
& GetCellSize() const { return m_cellSize
; }
261 // change the background colour of the selected cells
262 void SetSelectionBackground(const wxColour
& col
);
264 virtual wxVisualAttributes
GetDefaultAttributes() const
266 return GetClassDefaultAttributes(GetWindowVariant());
269 static wxVisualAttributes
270 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
272 // Get min/max symbol values
273 int GetMinSymbolValue() const { return m_minSymbolValue
; }
274 int GetMaxSymbolValue() const { return m_maxSymbolValue
; }
276 // Respond to size change
277 void OnSize(wxSizeEvent
& event
);
281 // draws a line of symbols
282 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
284 // gets the line height
285 virtual wxCoord
OnGetLineHeight(size_t line
) const;
288 void OnPaint(wxPaintEvent
& event
);
289 void OnKeyDown(wxKeyEvent
& event
);
290 void OnLeftDown(wxMouseEvent
& event
);
291 void OnLeftDClick(wxMouseEvent
& event
);
293 // common part of all ctors
296 // send the wxEVT_COMMAND_LISTBOX_SELECTED event
297 void SendSelectedEvent();
299 // change the current item (in single selection listbox it also implicitly
300 // changes the selection); current may be wxNOT_FOUND in which case there
301 // will be no current item any more
303 // return true if the current item changed, false otherwise
304 bool DoSetCurrent(int current
);
306 // flags for DoHandleItemClick
309 ItemClick_Shift
= 1, // item shift-clicked
310 ItemClick_Ctrl
= 2, // ctrl
311 ItemClick_Kbd
= 4 // item selected from keyboard
314 // common part of keyboard and mouse handling processing code
315 void DoHandleItemClick(int item
, int flags
);
317 // calculate line number from symbol value
318 int SymbolValueToLineNumber(int item
);
320 // initialise control from current min/max values
321 void SetupCtrl(bool scrollToSelection
= true);
324 int HitTest(const wxPoint
& pt
);
327 // the current item or wxNOT_FOUND
333 // the selection bg colour
337 wxBitmap
* m_doubleBuffer
;
342 // minimum and maximum symbol value
343 int m_minSymbolValue
;
345 // minimum and maximum symbol value
346 int m_maxSymbolValue
;
348 // number of items per line
349 int m_symbolsPerLine
;
351 // Unicode/ASCII mode
354 DECLARE_EVENT_TABLE()
355 DECLARE_NO_COPY_CLASS(wxSymbolListCtrl
)
356 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl
)
360 // _RICHTEXTSYMBOLDLG_H_