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
;
31 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
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 _("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
)
63 wxSymbolPickerDialog( );
64 wxSymbolPickerDialog( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
65 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 bool Create( const wxString
& symbol
, const wxString
& fontName
, const wxString
& normalTextFont
,
69 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
);
71 /// Initialises members variables
74 /// Creates the controls and sizers
75 void CreateControls();
77 /// Update the display
78 void UpdateSymbolDisplay(bool updateSymbolList
= true, bool showAtSubset
= true);
80 /// Respond to symbol selection
81 void OnSymbolSelected( wxCommandEvent
& event
);
84 void SetUnicodeMode(bool unicodeMode
);
86 /// Show at the current subset selection
89 /// Get the selected symbol character
90 int GetSymbolChar() const;
92 /// Is there a selection?
93 bool HasSelection() const { return !m_symbol
.IsEmpty(); }
95 /// Specifying normal text?
96 bool UseNormalFont() const { return m_fontName
.IsEmpty(); }
98 /// Should we show tooltips?
99 static bool ShowToolTips() { return sm_showToolTips
; }
101 /// Determines whether tooltips will be shown
102 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
105 virtual bool TransferDataToWindow();
107 ////@begin wxSymbolPickerDialog event handler declarations
109 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT
110 void OnFontCtrlSelected( wxCommandEvent
& event
);
112 #if defined(__UNICODE__)
113 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET
114 void OnSubsetSelected( wxCommandEvent
& event
);
117 #if defined(__UNICODE__)
118 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM
119 void OnFromUnicodeSelected( wxCommandEvent
& event
);
123 /// wxEVT_UPDATE_UI event handler for wxID_OK
124 void OnOkUpdate( wxUpdateUIEvent
& event
);
126 ////@end wxSymbolPickerDialog event handler declarations
128 ////@begin wxSymbolPickerDialog member function declarations
130 wxString
GetFontName() const { return m_fontName
; }
131 void SetFontName(wxString value
) { m_fontName
= value
; }
133 wxString
GetSymbol() const { return m_symbol
; }
134 void SetSymbol(wxString value
) { m_symbol
= value
; }
136 bool GetFromUnicode() const { return m_fromUnicode
; }
137 void SetFromUnicode(bool value
) { m_fromUnicode
= value
; }
139 wxString
GetNormalTextFontName() const { return m_normalTextFontName
; }
140 void SetNormalTextFontName(wxString value
) { m_normalTextFontName
= value
; }
142 /// Retrieves bitmap resources
143 wxBitmap
GetBitmapResource( const wxString
& name
);
145 /// Retrieves icon resources
146 wxIcon
GetIconResource( const wxString
& name
);
147 ////@end wxSymbolPickerDialog member function declarations
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
176 static bool sm_showToolTips
;
180 * The scrolling symbol list.
183 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
: public wxVScrolledWindow
186 // constructors and such
187 // ---------------------
189 // default constructor, you must call Create() later
190 wxSymbolListCtrl() { Init(); }
192 // normal constructor which calls Create() internally
193 wxSymbolListCtrl(wxWindow
*parent
,
194 wxWindowID id
= wxID_ANY
,
195 const wxPoint
& pos
= wxDefaultPosition
,
196 const wxSize
& size
= wxDefaultSize
,
198 const wxString
& name
= wxPanelNameStr
)
202 (void)Create(parent
, id
, pos
, size
, style
, name
);
205 // really creates the control and sets the initial number of items in it
206 // (which may be changed later with SetItemCount())
208 // returns true on success or false if the control couldn't be created
209 bool Create(wxWindow
*parent
,
210 wxWindowID id
= wxID_ANY
,
211 const wxPoint
& pos
= wxDefaultPosition
,
212 const wxSize
& size
= wxDefaultSize
,
214 const wxString
& name
= wxPanelNameStr
);
216 // dtor does some internal cleanup
217 virtual ~wxSymbolListCtrl();
223 // set the current font
224 virtual bool SetFont(const wxFont
& font
);
226 // set Unicode/ASCII mode
227 void SetUnicodeMode(bool unicodeMode
);
229 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
230 int GetSelection() const;
232 // is this item selected?
233 bool IsSelected(int item
) const;
235 // is this item the current one?
236 bool IsCurrentItem(int item
) const { return item
== m_current
; }
238 // get the margins around each cell
239 wxPoint
GetMargins() const { return m_ptMargins
; }
241 // get the background colour of selected cells
242 const wxColour
& GetSelectionBackground() const { return m_colBgSel
; }
247 // set the selection to the specified item, if it is wxNOT_FOUND the
248 // selection is unset
249 void SetSelection(int selection
);
251 // make this item visible
252 void EnsureVisible(int item
);
254 // set the margins: horizontal margin is the distance between the window
255 // border and the item contents while vertical margin is half of the
256 // distance between items
258 // by default both margins are 0
259 void SetMargins(const wxPoint
& pt
);
260 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
263 void SetCellSize(const wxSize
& sz
) { m_cellSize
= sz
; }
264 const wxSize
& GetCellSize() const { return m_cellSize
; }
266 // change the background colour of the selected cells
267 void SetSelectionBackground(const wxColour
& col
);
269 virtual wxVisualAttributes
GetDefaultAttributes() const
271 return GetClassDefaultAttributes(GetWindowVariant());
274 static wxVisualAttributes
275 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
277 // Get min/max symbol values
278 int GetMinSymbolValue() const { return m_minSymbolValue
; }
279 int GetMaxSymbolValue() const { return m_maxSymbolValue
; }
281 // Respond to size change
282 void OnSize(wxSizeEvent
& event
);
286 // draws a line of symbols
287 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
289 // gets the line height
290 virtual wxCoord
OnGetRowHeight(size_t line
) const;
293 void OnPaint(wxPaintEvent
& event
);
294 void OnKeyDown(wxKeyEvent
& event
);
295 void OnLeftDown(wxMouseEvent
& event
);
296 void OnLeftDClick(wxMouseEvent
& event
);
298 // common part of all ctors
301 // send the wxEVT_COMMAND_LISTBOX_SELECTED event
302 void SendSelectedEvent();
304 // change the current item (in single selection listbox it also implicitly
305 // changes the selection); current may be wxNOT_FOUND in which case there
306 // will be no current item any more
308 // return true if the current item changed, false otherwise
309 bool DoSetCurrent(int current
);
311 // flags for DoHandleItemClick
314 ItemClick_Shift
= 1, // item shift-clicked
315 ItemClick_Ctrl
= 2, // ctrl
316 ItemClick_Kbd
= 4 // item selected from keyboard
319 // common part of keyboard and mouse handling processing code
320 void DoHandleItemClick(int item
, int flags
);
322 // calculate line number from symbol value
323 int SymbolValueToLineNumber(int item
);
325 // initialise control from current min/max values
326 void SetupCtrl(bool scrollToSelection
= true);
329 int HitTest(const wxPoint
& pt
);
332 // the current item or wxNOT_FOUND
338 // the selection bg colour
342 wxBitmap
* m_doubleBuffer
;
347 // minimum and maximum symbol value
348 int m_minSymbolValue
;
350 // minimum and maximum symbol value
351 int m_maxSymbolValue
;
353 // number of items per line
354 int m_symbolsPerLine
;
356 // Unicode/ASCII mode
359 DECLARE_EVENT_TABLE()
360 DECLARE_NO_COPY_CLASS(wxSymbolListCtrl
)
361 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl
)
365 // _RICHTEXTSYMBOLDLG_H_