1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextsymboldlg.h
4 // Author: Julian Smart
6 // Created: 10/5/2006 3:11:58 PM
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _RICHTEXTSYMBOLDLG_H_
13 #define _RICHTEXTSYMBOLDLG_H_
19 #include "wx/dialog.h"
20 #include "wx/vscroll.h"
21 #include "wx/combobox.h"
22 #include "wx/stattext.h"
23 #include "wx/textctrl.h"
26 * Forward declarations
29 ////@begin forward declarations
30 class wxSymbolListCtrl
;
31 ////@end forward declarations
33 // __UNICODE__ is a symbol used by DialogBlocks-generated code.
44 #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE (wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX)
45 #define SYMBOL_WXSYMBOLPICKERDIALOG_TITLE _("Symbols")
46 #define SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME ID_SYMBOLPICKERDIALOG
47 #define SYMBOL_WXSYMBOLPICKERDIALOG_SIZE wxSize(400, 300)
48 #define SYMBOL_WXSYMBOLPICKERDIALOG_POSITION wxDefaultPosition
51 * wxSymbolPickerDialog class declaration
54 class WXDLLIMPEXP_RICHTEXT wxSymbolPickerDialog
: public wxDialog
56 DECLARE_DYNAMIC_CLASS( wxSymbolPickerDialog
)
61 wxSymbolPickerDialog( );
62 wxSymbolPickerDialog( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
63 wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxString
& caption
= SYMBOL_WXSYMBOLPICKERDIALOG_TITLE
, const wxPoint
& pos
= SYMBOL_WXSYMBOLPICKERDIALOG_POSITION
, const wxSize
& size
= SYMBOL_WXSYMBOLPICKERDIALOG_SIZE
, long style
= SYMBOL_WXSYMBOLPICKERDIALOG_STYLE
);
66 bool Create( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
67 wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxString
& caption
= SYMBOL_WXSYMBOLPICKERDIALOG_TITLE
, const wxPoint
& pos
= SYMBOL_WXSYMBOLPICKERDIALOG_POSITION
, const wxSize
& size
= SYMBOL_WXSYMBOLPICKERDIALOG_SIZE
, long style
= SYMBOL_WXSYMBOLPICKERDIALOG_STYLE
);
69 /// Initialises members variables
72 /// Creates the controls and sizers
73 void CreateControls();
75 /// Update the display
76 void UpdateSymbolDisplay(bool updateSymbolList
= true, bool showAtSubset
= true);
78 /// Respond to symbol selection
79 void OnSymbolSelected( wxCommandEvent
& event
);
82 void SetUnicodeMode(bool unicodeMode
);
84 /// Show at the current subset selection
87 /// Get the selected symbol character
88 int GetSymbolChar() const;
90 /// Is there a selection?
91 bool HasSelection() const { return !m_symbol
.IsEmpty(); }
93 /// Specifying normal text?
94 bool UseNormalFont() const { return m_fontName
.IsEmpty(); }
96 /// Should we show tooltips?
97 static bool ShowToolTips() { return sm_showToolTips
; }
99 /// Determines whether tooltips will be shown
100 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
103 virtual bool TransferDataToWindow();
105 ////@begin wxSymbolPickerDialog event handler declarations
107 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT
108 void OnFontCtrlSelected( wxCommandEvent
& event
);
110 #if defined(__UNICODE__)
111 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET
112 void OnSubsetSelected( wxCommandEvent
& event
);
115 #if defined(__UNICODE__)
116 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM
117 void OnFromUnicodeSelected( wxCommandEvent
& event
);
120 /// wxEVT_UPDATE_UI event handler for wxID_OK
121 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 ////@begin wxSymbolPickerDialog member variables
147 wxComboBox
* m_fontCtrl
;
148 #if defined(__UNICODE__)
149 wxComboBox
* m_subsetCtrl
;
151 wxSymbolListCtrl
* m_symbolsCtrl
;
152 wxStaticText
* m_symbolStaticCtrl
;
153 wxTextCtrl
* m_characterCodeCtrl
;
154 #if defined(__UNICODE__)
155 wxComboBox
* m_fromUnicodeCtrl
;
160 wxString m_normalTextFontName
;
161 /// Control identifiers
163 ID_SYMBOLPICKERDIALOG
= 10600,
164 ID_SYMBOLPICKERDIALOG_FONT
= 10602,
165 ID_SYMBOLPICKERDIALOG_SUBSET
= 10605,
166 ID_SYMBOLPICKERDIALOG_LISTCTRL
= 10608,
167 ID_SYMBOLPICKERDIALOG_CHARACTERCODE
= 10601,
168 ID_SYMBOLPICKERDIALOG_FROM
= 10603
170 ////@end wxSymbolPickerDialog member variables
173 static bool sm_showToolTips
;
177 * The scrolling symbol list.
180 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
: public wxVScrolledWindow
183 // constructors and such
184 // ---------------------
186 // default constructor, you must call Create() later
187 wxSymbolListCtrl() { Init(); }
189 // normal constructor which calls Create() internally
190 wxSymbolListCtrl(wxWindow
*parent
,
191 wxWindowID id
= wxID_ANY
,
192 const wxPoint
& pos
= wxDefaultPosition
,
193 const wxSize
& size
= wxDefaultSize
,
195 const wxString
& name
= wxPanelNameStr
)
199 (void)Create(parent
, id
, pos
, size
, style
, name
);
202 // really creates the control and sets the initial number of items in it
203 // (which may be changed later with SetItemCount())
205 // returns true on success or false if the control couldn't be created
206 bool Create(wxWindow
*parent
,
207 wxWindowID id
= wxID_ANY
,
208 const wxPoint
& pos
= wxDefaultPosition
,
209 const wxSize
& size
= wxDefaultSize
,
211 const wxString
& name
= wxPanelNameStr
);
213 // dtor does some internal cleanup
214 virtual ~wxSymbolListCtrl();
220 // set the current font
221 virtual bool SetFont(const wxFont
& font
);
223 // set Unicode/ASCII mode
224 void SetUnicodeMode(bool unicodeMode
);
226 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
227 int GetSelection() const;
229 // is this item selected?
230 bool IsSelected(int item
) const;
232 // is this item the current one?
233 bool IsCurrentItem(int item
) const { return item
== m_current
; }
235 // get the margins around each cell
236 wxPoint
GetMargins() const { return m_ptMargins
; }
238 // get the background colour of selected cells
239 const wxColour
& GetSelectionBackground() const { return m_colBgSel
; }
244 // set the selection to the specified item, if it is wxNOT_FOUND the
245 // selection is unset
246 void SetSelection(int selection
);
248 // make this item visible
249 void EnsureVisible(int item
);
251 // set the margins: horizontal margin is the distance between the window
252 // border and the item contents while vertical margin is half of the
253 // distance between items
255 // by default both margins are 0
256 void SetMargins(const wxPoint
& pt
);
257 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
260 void SetCellSize(const wxSize
& sz
) { m_cellSize
= sz
; }
261 const wxSize
& GetCellSize() const { return m_cellSize
; }
263 // change the background colour of the selected cells
264 void SetSelectionBackground(const wxColour
& col
);
266 virtual wxVisualAttributes
GetDefaultAttributes() const
268 return GetClassDefaultAttributes(GetWindowVariant());
271 static wxVisualAttributes
272 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
274 // Get min/max symbol values
275 int GetMinSymbolValue() const { return m_minSymbolValue
; }
276 int GetMaxSymbolValue() const { return m_maxSymbolValue
; }
278 // Respond to size change
279 void OnSize(wxSizeEvent
& event
);
283 // draws a line of symbols
284 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
286 // gets the line height
287 virtual wxCoord
OnGetRowHeight(size_t line
) const;
290 void OnPaint(wxPaintEvent
& event
);
291 void OnKeyDown(wxKeyEvent
& event
);
292 void OnLeftDown(wxMouseEvent
& event
);
293 void OnLeftDClick(wxMouseEvent
& event
);
295 // common part of all ctors
298 // send the wxEVT_COMMAND_LISTBOX_SELECTED event
299 void SendSelectedEvent();
301 // change the current item (in single selection listbox it also implicitly
302 // changes the selection); current may be wxNOT_FOUND in which case there
303 // will be no current item any more
305 // return true if the current item changed, false otherwise
306 bool DoSetCurrent(int current
);
308 // flags for DoHandleItemClick
311 ItemClick_Shift
= 1, // item shift-clicked
312 ItemClick_Ctrl
= 2, // ctrl
313 ItemClick_Kbd
= 4 // item selected from keyboard
316 // common part of keyboard and mouse handling processing code
317 void DoHandleItemClick(int item
, int flags
);
319 // calculate line number from symbol value
320 int SymbolValueToLineNumber(int item
);
322 // initialise control from current min/max values
323 void SetupCtrl(bool scrollToSelection
= true);
326 int HitTest(const wxPoint
& pt
);
329 // the current item or wxNOT_FOUND
335 // the selection bg colour
339 wxBitmap
* m_doubleBuffer
;
344 // minimum and maximum symbol value
345 int m_minSymbolValue
;
347 // minimum and maximum symbol value
348 int m_maxSymbolValue
;
350 // number of items per line
351 int m_symbolsPerLine
;
353 // Unicode/ASCII mode
356 DECLARE_EVENT_TABLE()
357 DECLARE_NO_COPY_CLASS(wxSymbolListCtrl
)
358 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl
)
362 // _RICHTEXTSYMBOLDLG_H_