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"
25 * Forward declarations
28 ////@begin forward declarations
29 class wxSymbolListCtrl
;
30 ////@end forward declarations
32 // __UNICODE__ is a symbol used by DialogBlocks-generated code.
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
= 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
);
65 bool Create( 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
);
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(); }
95 /// Should we show tooltips?
96 static bool ShowToolTips() { return sm_showToolTips
; }
98 /// Determines whether tooltips will be shown
99 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
102 virtual bool TransferDataToWindow();
104 ////@begin wxSymbolPickerDialog event handler declarations
106 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT
107 void OnFontCtrlSelected( wxCommandEvent
& event
);
109 #if defined(__UNICODE__)
110 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET
111 void OnSubsetSelected( wxCommandEvent
& event
);
114 #if defined(__UNICODE__)
115 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM
116 void OnFromUnicodeSelected( wxCommandEvent
& event
);
119 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
120 /// wxEVT_UPDATE_UI event handler for wxID_OK
121 void OnOkUpdate( wxUpdateUIEvent
& event
);
124 #if defined(__WXMAC__)
125 /// wxEVT_UPDATE_UI event handler for wxID_OK
126 void OnOkUpdate( wxUpdateUIEvent
& event
);
129 ////@end wxSymbolPickerDialog event handler declarations
131 ////@begin wxSymbolPickerDialog member function declarations
133 wxString
GetFontName() const { return m_fontName
; }
134 void SetFontName(wxString value
) { m_fontName
= value
; }
136 wxString
GetSymbol() const { return m_symbol
; }
137 void SetSymbol(wxString value
) { m_symbol
= value
; }
139 bool GetFromUnicode() const { return m_fromUnicode
; }
140 void SetFromUnicode(bool value
) { m_fromUnicode
= value
; }
142 wxString
GetNormalTextFontName() const { return m_normalTextFontName
; }
143 void SetNormalTextFontName(wxString value
) { m_normalTextFontName
= value
; }
145 /// Retrieves bitmap resources
146 wxBitmap
GetBitmapResource( const wxString
& name
);
148 /// Retrieves icon resources
149 wxIcon
GetIconResource( const wxString
& name
);
150 ////@end wxSymbolPickerDialog member function declarations
152 ////@begin wxSymbolPickerDialog member variables
153 wxComboBox
* m_fontCtrl
;
154 #if defined(__UNICODE__)
155 wxComboBox
* m_subsetCtrl
;
157 wxSymbolListCtrl
* m_symbolsCtrl
;
158 wxStaticText
* m_symbolStaticCtrl
;
159 wxTextCtrl
* m_characterCodeCtrl
;
160 #if defined(__UNICODE__)
161 wxComboBox
* m_fromUnicodeCtrl
;
166 wxString m_normalTextFontName
;
167 /// Control identifiers
169 ID_SYMBOLPICKERDIALOG
= 10600,
170 ID_SYMBOLPICKERDIALOG_FONT
= 10602,
171 ID_SYMBOLPICKERDIALOG_SUBSET
= 10605,
172 ID_SYMBOLPICKERDIALOG_LISTCTRL
= 10608,
173 ID_SYMBOLPICKERDIALOG_CHARACTERCODE
= 10601,
174 ID_SYMBOLPICKERDIALOG_FROM
= 10603
176 ////@end wxSymbolPickerDialog member variables
179 static bool sm_showToolTips
;
183 * The scrolling symbol list.
186 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
: public wxVScrolledWindow
189 // constructors and such
190 // ---------------------
192 // default constructor, you must call Create() later
193 wxSymbolListCtrl() { Init(); }
195 // normal constructor which calls Create() internally
196 wxSymbolListCtrl(wxWindow
*parent
,
197 wxWindowID id
= wxID_ANY
,
198 const wxPoint
& pos
= wxDefaultPosition
,
199 const wxSize
& size
= wxDefaultSize
,
201 const wxString
& name
= wxPanelNameStr
)
205 (void)Create(parent
, id
, pos
, size
, style
, name
);
208 // really creates the control and sets the initial number of items in it
209 // (which may be changed later with SetItemCount())
211 // returns true on success or false if the control couldn't be created
212 bool Create(wxWindow
*parent
,
213 wxWindowID id
= wxID_ANY
,
214 const wxPoint
& pos
= wxDefaultPosition
,
215 const wxSize
& size
= wxDefaultSize
,
217 const wxString
& name
= wxPanelNameStr
);
219 // dtor does some internal cleanup
220 virtual ~wxSymbolListCtrl();
226 // set the current font
227 virtual bool SetFont(const wxFont
& font
);
229 // set Unicode/ASCII mode
230 void SetUnicodeMode(bool unicodeMode
);
232 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
233 int GetSelection() const;
235 // is this item selected?
236 bool IsSelected(int item
) const;
238 // is this item the current one?
239 bool IsCurrentItem(int item
) const { return item
== m_current
; }
241 // get the margins around each cell
242 wxPoint
GetMargins() const { return m_ptMargins
; }
244 // get the background colour of selected cells
245 const wxColour
& GetSelectionBackground() const { return m_colBgSel
; }
250 // set the selection to the specified item, if it is wxNOT_FOUND the
251 // selection is unset
252 void SetSelection(int selection
);
254 // make this item visible
255 void EnsureVisible(int item
);
257 // set the margins: horizontal margin is the distance between the window
258 // border and the item contents while vertical margin is half of the
259 // distance between items
261 // by default both margins are 0
262 void SetMargins(const wxPoint
& pt
);
263 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
266 void SetCellSize(const wxSize
& sz
) { m_cellSize
= sz
; }
267 const wxSize
& GetCellSize() const { return m_cellSize
; }
269 // change the background colour of the selected cells
270 void SetSelectionBackground(const wxColour
& col
);
272 virtual wxVisualAttributes
GetDefaultAttributes() const
274 return GetClassDefaultAttributes(GetWindowVariant());
277 static wxVisualAttributes
278 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
280 // Get min/max symbol values
281 int GetMinSymbolValue() const { return m_minSymbolValue
; }
282 int GetMaxSymbolValue() const { return m_maxSymbolValue
; }
284 // Respond to size change
285 void OnSize(wxSizeEvent
& event
);
289 // draws a line of symbols
290 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
292 // gets the line height
293 virtual wxCoord
OnGetLineHeight(size_t line
) const;
296 void OnPaint(wxPaintEvent
& event
);
297 void OnKeyDown(wxKeyEvent
& event
);
298 void OnLeftDown(wxMouseEvent
& event
);
299 void OnLeftDClick(wxMouseEvent
& event
);
301 // common part of all ctors
304 // send the wxEVT_COMMAND_LISTBOX_SELECTED event
305 void SendSelectedEvent();
307 // change the current item (in single selection listbox it also implicitly
308 // changes the selection); current may be wxNOT_FOUND in which case there
309 // will be no current item any more
311 // return true if the current item changed, false otherwise
312 bool DoSetCurrent(int current
);
314 // flags for DoHandleItemClick
317 ItemClick_Shift
= 1, // item shift-clicked
318 ItemClick_Ctrl
= 2, // ctrl
319 ItemClick_Kbd
= 4 // item selected from keyboard
322 // common part of keyboard and mouse handling processing code
323 void DoHandleItemClick(int item
, int flags
);
325 // calculate line number from symbol value
326 int SymbolValueToLineNumber(int item
);
328 // initialise control from current min/max values
329 void SetupCtrl(bool scrollToSelection
= true);
332 int HitTest(const wxPoint
& pt
);
335 // the current item or wxNOT_FOUND
341 // the selection bg colour
345 wxBitmap
* m_doubleBuffer
;
350 // minimum and maximum symbol value
351 int m_minSymbolValue
;
353 // minimum and maximum symbol value
354 int m_maxSymbolValue
;
356 // number of items per line
357 int m_symbolsPerLine
;
359 // Unicode/ASCII mode
362 DECLARE_EVENT_TABLE()
363 DECLARE_NO_COPY_CLASS(wxSymbolListCtrl
)
364 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl
)
368 // _RICHTEXTSYMBOLDLG_H_