1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextsymboldlg.h
4 // Author: Julian Smart
6 // Created: 10/5/2006 3:11:58 PM
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _RICHTEXTSYMBOLDLG_H_
12 #define _RICHTEXTSYMBOLDLG_H_
18 #include "wx/richtext/richtextuicustomization.h"
19 #include "wx/dialog.h"
20 #include "wx/vscroll.h"
23 * Forward declarations
26 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
27 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
28 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
30 ////@begin forward declarations
31 class wxSymbolListCtrl
;
32 class wxStdDialogButtonSizer
;
33 ////@end forward declarations
35 // __UNICODE__ is a symbol used by DialogBlocks-generated code.
46 #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE (wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX)
47 #define SYMBOL_WXSYMBOLPICKERDIALOG_TITLE wxGetTranslation("Symbols")
48 #define SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME ID_SYMBOLPICKERDIALOG
49 #define SYMBOL_WXSYMBOLPICKERDIALOG_SIZE wxSize(400, 300)
50 #define SYMBOL_WXSYMBOLPICKERDIALOG_POSITION wxDefaultPosition
53 * wxSymbolPickerDialog class declaration
56 class WXDLLIMPEXP_RICHTEXT wxSymbolPickerDialog
: public wxDialog
58 DECLARE_DYNAMIC_CLASS( wxSymbolPickerDialog
)
60 DECLARE_HELP_PROVISION()
64 wxSymbolPickerDialog( );
65 wxSymbolPickerDialog( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
66 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 bool Create( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
70 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
);
72 /// Initialises members variables
75 /// Creates the controls and sizers
76 void CreateControls();
78 /// Update the display
79 void UpdateSymbolDisplay(bool updateSymbolList
= true, bool showAtSubset
= true);
81 /// Respond to symbol selection
82 void OnSymbolSelected( wxCommandEvent
& event
);
85 void SetUnicodeMode(bool unicodeMode
);
87 /// Show at the current subset selection
90 /// Get the selected symbol character
91 int GetSymbolChar() const;
93 /// Is there a selection?
94 bool HasSelection() const { return !m_symbol
.IsEmpty(); }
96 /// Specifying normal text?
97 bool UseNormalFont() const { return m_fontName
.IsEmpty(); }
99 /// Should we show tooltips?
100 static bool ShowToolTips() { return sm_showToolTips
; }
102 /// Determines whether tooltips will be shown
103 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
106 virtual bool TransferDataToWindow();
108 ////@begin wxSymbolPickerDialog event handler declarations
110 /// wxEVT_COMBOBOX event handler for ID_SYMBOLPICKERDIALOG_FONT
111 void OnFontCtrlSelected( wxCommandEvent
& event
);
113 #if defined(__UNICODE__)
114 /// wxEVT_COMBOBOX event handler for ID_SYMBOLPICKERDIALOG_SUBSET
115 void OnSubsetSelected( wxCommandEvent
& event
);
117 /// wxEVT_UPDATE_UI event handler for ID_SYMBOLPICKERDIALOG_SUBSET
118 void OnSymbolpickerdialogSubsetUpdate( wxUpdateUIEvent
& event
);
121 #if defined(__UNICODE__)
122 /// wxEVT_COMBOBOX event handler for ID_SYMBOLPICKERDIALOG_FROM
123 void OnFromUnicodeSelected( wxCommandEvent
& event
);
126 /// wxEVT_UPDATE_UI event handler for wxID_OK
127 void OnOkUpdate( wxUpdateUIEvent
& event
);
129 /// wxEVT_BUTTON event handler for wxID_HELP
130 void OnHelpClick( wxCommandEvent
& event
);
132 /// wxEVT_UPDATE_UI event handler for wxID_HELP
133 void OnHelpUpdate( wxUpdateUIEvent
& event
);
135 ////@end wxSymbolPickerDialog event handler declarations
137 ////@begin wxSymbolPickerDialog member function declarations
139 wxString
GetFontName() const { return m_fontName
; }
140 void SetFontName(wxString value
) { m_fontName
= value
; }
142 bool GetFromUnicode() const { return m_fromUnicode
; }
143 void SetFromUnicode(bool value
) { m_fromUnicode
= value
; }
145 wxString
GetNormalTextFontName() const { return m_normalTextFontName
; }
146 void SetNormalTextFontName(wxString value
) { m_normalTextFontName
= value
; }
148 wxString
GetSymbol() const { return m_symbol
; }
149 void SetSymbol(wxString value
) { m_symbol
= value
; }
151 /// Retrieves bitmap resources
152 wxBitmap
GetBitmapResource( const wxString
& name
);
154 /// Retrieves icon resources
155 wxIcon
GetIconResource( const wxString
& name
);
156 ////@end wxSymbolPickerDialog member function declarations
158 ////@begin wxSymbolPickerDialog member variables
159 wxComboBox
* m_fontCtrl
;
160 #if defined(__UNICODE__)
161 wxComboBox
* m_subsetCtrl
;
163 wxSymbolListCtrl
* m_symbolsCtrl
;
164 wxStaticText
* m_symbolStaticCtrl
;
165 wxTextCtrl
* m_characterCodeCtrl
;
166 #if defined(__UNICODE__)
167 wxComboBox
* m_fromUnicodeCtrl
;
169 wxStdDialogButtonSizer
* m_stdButtonSizer
;
172 wxString m_normalTextFontName
;
174 /// Control identifiers
176 ID_SYMBOLPICKERDIALOG
= 10600,
177 ID_SYMBOLPICKERDIALOG_FONT
= 10602,
178 ID_SYMBOLPICKERDIALOG_SUBSET
= 10605,
179 ID_SYMBOLPICKERDIALOG_LISTCTRL
= 10608,
180 ID_SYMBOLPICKERDIALOG_CHARACTERCODE
= 10601,
181 ID_SYMBOLPICKERDIALOG_FROM
= 10603
183 ////@end wxSymbolPickerDialog member variables
186 static bool sm_showToolTips
;
190 * The scrolling symbol list.
193 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
: public wxVScrolledWindow
196 // constructors and such
197 // ---------------------
199 // default constructor, you must call Create() later
200 wxSymbolListCtrl() { Init(); }
202 // normal constructor which calls Create() internally
203 wxSymbolListCtrl(wxWindow
*parent
,
204 wxWindowID id
= wxID_ANY
,
205 const wxPoint
& pos
= wxDefaultPosition
,
206 const wxSize
& size
= wxDefaultSize
,
208 const wxString
& name
= wxPanelNameStr
)
212 (void)Create(parent
, id
, pos
, size
, style
, name
);
215 // really creates the control and sets the initial number of items in it
216 // (which may be changed later with SetItemCount())
218 // returns true on success or false if the control couldn't be created
219 bool Create(wxWindow
*parent
,
220 wxWindowID id
= wxID_ANY
,
221 const wxPoint
& pos
= wxDefaultPosition
,
222 const wxSize
& size
= wxDefaultSize
,
224 const wxString
& name
= wxPanelNameStr
);
226 // dtor does some internal cleanup
227 virtual ~wxSymbolListCtrl();
233 // set the current font
234 virtual bool SetFont(const wxFont
& font
);
236 // set Unicode/ASCII mode
237 void SetUnicodeMode(bool unicodeMode
);
239 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
240 int GetSelection() const;
242 // is this item selected?
243 bool IsSelected(int item
) const;
245 // is this item the current one?
246 bool IsCurrentItem(int item
) const { return item
== m_current
; }
248 // get the margins around each cell
249 wxPoint
GetMargins() const { return m_ptMargins
; }
251 // get the background colour of selected cells
252 const wxColour
& GetSelectionBackground() const { return m_colBgSel
; }
257 // set the selection to the specified item, if it is wxNOT_FOUND the
258 // selection is unset
259 void SetSelection(int selection
);
261 // make this item visible
262 void EnsureVisible(int item
);
264 // set the margins: horizontal margin is the distance between the window
265 // border and the item contents while vertical margin is half of the
266 // distance between items
268 // by default both margins are 0
269 void SetMargins(const wxPoint
& pt
);
270 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
273 void SetCellSize(const wxSize
& sz
) { m_cellSize
= sz
; }
274 const wxSize
& GetCellSize() const { return m_cellSize
; }
276 // change the background colour of the selected cells
277 void SetSelectionBackground(const wxColour
& col
);
279 virtual wxVisualAttributes
GetDefaultAttributes() const
281 return GetClassDefaultAttributes(GetWindowVariant());
284 static wxVisualAttributes
285 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
287 // Get min/max symbol values
288 int GetMinSymbolValue() const { return m_minSymbolValue
; }
289 int GetMaxSymbolValue() const { return m_maxSymbolValue
; }
291 // Respond to size change
292 void OnSize(wxSizeEvent
& event
);
296 // draws a line of symbols
297 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
299 // gets the line height
300 virtual wxCoord
OnGetRowHeight(size_t line
) const;
303 void OnPaint(wxPaintEvent
& event
);
304 void OnKeyDown(wxKeyEvent
& event
);
305 void OnLeftDown(wxMouseEvent
& event
);
306 void OnLeftDClick(wxMouseEvent
& event
);
308 // common part of all ctors
311 // send the wxEVT_LISTBOX event
312 void SendSelectedEvent();
314 // change the current item (in single selection listbox it also implicitly
315 // changes the selection); current may be wxNOT_FOUND in which case there
316 // will be no current item any more
318 // return true if the current item changed, false otherwise
319 bool DoSetCurrent(int current
);
321 // flags for DoHandleItemClick
324 ItemClick_Shift
= 1, // item shift-clicked
325 ItemClick_Ctrl
= 2, // ctrl
326 ItemClick_Kbd
= 4 // item selected from keyboard
329 // common part of keyboard and mouse handling processing code
330 void DoHandleItemClick(int item
, int flags
);
332 // calculate line number from symbol value
333 int SymbolValueToLineNumber(int item
);
335 // initialise control from current min/max values
336 void SetupCtrl(bool scrollToSelection
= true);
339 int HitTest(const wxPoint
& pt
);
342 // the current item or wxNOT_FOUND
348 // the selection bg colour
352 wxBitmap
* m_doubleBuffer
;
357 // minimum and maximum symbol value
358 int m_minSymbolValue
;
360 // minimum and maximum symbol value
361 int m_maxSymbolValue
;
363 // number of items per line
364 int m_symbolsPerLine
;
366 // Unicode/ASCII mode
369 DECLARE_EVENT_TABLE()
370 wxDECLARE_NO_COPY_CLASS(wxSymbolListCtrl
);
371 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl
)
375 // _RICHTEXTSYMBOLDLG_H_