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 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
121 /// wxEVT_UPDATE_UI event handler for wxID_OK
122 void OnOkUpdate( wxUpdateUIEvent
& event
);
125 #if defined(__WXMAC__)
126 /// wxEVT_UPDATE_UI event handler for wxID_OK
127 void OnOkUpdate( wxUpdateUIEvent
& event
);
130 ////@end wxSymbolPickerDialog event handler declarations
132 ////@begin wxSymbolPickerDialog member function declarations
134 wxString
GetFontName() const { return m_fontName
; }
135 void SetFontName(wxString value
) { m_fontName
= value
; }
137 wxString
GetSymbol() const { return m_symbol
; }
138 void SetSymbol(wxString value
) { m_symbol
= value
; }
140 bool GetFromUnicode() const { return m_fromUnicode
; }
141 void SetFromUnicode(bool value
) { m_fromUnicode
= value
; }
143 wxString
GetNormalTextFontName() const { return m_normalTextFontName
; }
144 void SetNormalTextFontName(wxString value
) { m_normalTextFontName
= value
; }
146 /// Retrieves bitmap resources
147 wxBitmap
GetBitmapResource( const wxString
& name
);
149 /// Retrieves icon resources
150 wxIcon
GetIconResource( const wxString
& name
);
151 ////@end wxSymbolPickerDialog member function declarations
153 ////@begin wxSymbolPickerDialog member variables
154 wxComboBox
* m_fontCtrl
;
155 #if defined(__UNICODE__)
156 wxComboBox
* m_subsetCtrl
;
158 wxSymbolListCtrl
* m_symbolsCtrl
;
159 wxStaticText
* m_symbolStaticCtrl
;
160 wxTextCtrl
* m_characterCodeCtrl
;
161 #if defined(__UNICODE__)
162 wxComboBox
* m_fromUnicodeCtrl
;
167 wxString m_normalTextFontName
;
168 /// Control identifiers
170 ID_SYMBOLPICKERDIALOG
= 10600,
171 ID_SYMBOLPICKERDIALOG_FONT
= 10602,
172 ID_SYMBOLPICKERDIALOG_SUBSET
= 10605,
173 ID_SYMBOLPICKERDIALOG_LISTCTRL
= 10608,
174 ID_SYMBOLPICKERDIALOG_CHARACTERCODE
= 10601,
175 ID_SYMBOLPICKERDIALOG_FROM
= 10603
177 ////@end wxSymbolPickerDialog member variables
180 static bool sm_showToolTips
;
184 * The scrolling symbol list.
187 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
: public wxVScrolledWindow
190 // constructors and such
191 // ---------------------
193 // default constructor, you must call Create() later
194 wxSymbolListCtrl() { Init(); }
196 // normal constructor which calls Create() internally
197 wxSymbolListCtrl(wxWindow
*parent
,
198 wxWindowID id
= wxID_ANY
,
199 const wxPoint
& pos
= wxDefaultPosition
,
200 const wxSize
& size
= wxDefaultSize
,
202 const wxString
& name
= wxPanelNameStr
)
206 (void)Create(parent
, id
, pos
, size
, style
, name
);
209 // really creates the control and sets the initial number of items in it
210 // (which may be changed later with SetItemCount())
212 // returns true on success or false if the control couldn't be created
213 bool Create(wxWindow
*parent
,
214 wxWindowID id
= wxID_ANY
,
215 const wxPoint
& pos
= wxDefaultPosition
,
216 const wxSize
& size
= wxDefaultSize
,
218 const wxString
& name
= wxPanelNameStr
);
220 // dtor does some internal cleanup
221 virtual ~wxSymbolListCtrl();
227 // set the current font
228 virtual bool SetFont(const wxFont
& font
);
230 // set Unicode/ASCII mode
231 void SetUnicodeMode(bool unicodeMode
);
233 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
234 int GetSelection() const;
236 // is this item selected?
237 bool IsSelected(int item
) const;
239 // is this item the current one?
240 bool IsCurrentItem(int item
) const { return item
== m_current
; }
242 // get the margins around each cell
243 wxPoint
GetMargins() const { return m_ptMargins
; }
245 // get the background colour of selected cells
246 const wxColour
& GetSelectionBackground() const { return m_colBgSel
; }
251 // set the selection to the specified item, if it is wxNOT_FOUND the
252 // selection is unset
253 void SetSelection(int selection
);
255 // make this item visible
256 void EnsureVisible(int item
);
258 // set the margins: horizontal margin is the distance between the window
259 // border and the item contents while vertical margin is half of the
260 // distance between items
262 // by default both margins are 0
263 void SetMargins(const wxPoint
& pt
);
264 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
267 void SetCellSize(const wxSize
& sz
) { m_cellSize
= sz
; }
268 const wxSize
& GetCellSize() const { return m_cellSize
; }
270 // change the background colour of the selected cells
271 void SetSelectionBackground(const wxColour
& col
);
273 virtual wxVisualAttributes
GetDefaultAttributes() const
275 return GetClassDefaultAttributes(GetWindowVariant());
278 static wxVisualAttributes
279 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
281 // Get min/max symbol values
282 int GetMinSymbolValue() const { return m_minSymbolValue
; }
283 int GetMaxSymbolValue() const { return m_maxSymbolValue
; }
285 // Respond to size change
286 void OnSize(wxSizeEvent
& event
);
290 // draws a line of symbols
291 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
293 // gets the line height
294 virtual wxCoord
OnGetRowHeight(size_t line
) const;
297 void OnPaint(wxPaintEvent
& event
);
298 void OnKeyDown(wxKeyEvent
& event
);
299 void OnLeftDown(wxMouseEvent
& event
);
300 void OnLeftDClick(wxMouseEvent
& event
);
302 // common part of all ctors
305 // send the wxEVT_COMMAND_LISTBOX_SELECTED event
306 void SendSelectedEvent();
308 // change the current item (in single selection listbox it also implicitly
309 // changes the selection); current may be wxNOT_FOUND in which case there
310 // will be no current item any more
312 // return true if the current item changed, false otherwise
313 bool DoSetCurrent(int current
);
315 // flags for DoHandleItemClick
318 ItemClick_Shift
= 1, // item shift-clicked
319 ItemClick_Ctrl
= 2, // ctrl
320 ItemClick_Kbd
= 4 // item selected from keyboard
323 // common part of keyboard and mouse handling processing code
324 void DoHandleItemClick(int item
, int flags
);
326 // calculate line number from symbol value
327 int SymbolValueToLineNumber(int item
);
329 // initialise control from current min/max values
330 void SetupCtrl(bool scrollToSelection
= true);
333 int HitTest(const wxPoint
& pt
);
336 // the current item or wxNOT_FOUND
342 // the selection bg colour
346 wxBitmap
* m_doubleBuffer
;
351 // minimum and maximum symbol value
352 int m_minSymbolValue
;
354 // minimum and maximum symbol value
355 int m_maxSymbolValue
;
357 // number of items per line
358 int m_symbolsPerLine
;
360 // Unicode/ASCII mode
363 DECLARE_EVENT_TABLE()
364 DECLARE_NO_COPY_CLASS(wxSymbolListCtrl
)
365 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl
)
369 // _RICHTEXTSYMBOLDLG_H_