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"
23 * Forward declarations
26 ////@begin forward declarations
27 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl
;
28 class WXDLLIMPEXP_CORE wxComboBox
;
29 class WXDLLIMPEXP_CORE wxStaticText
;
30 class WXDLLIMPEXP_CORE wxTextCtrl
;
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
= SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME
, 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
= SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME
, 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(); }
97 virtual bool TransferDataToWindow();
99 ////@begin wxSymbolPickerDialog event handler declarations
101 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT
102 void OnFontCtrlSelected( wxCommandEvent
& event
);
104 #if defined(__UNICODE__)
105 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET
106 void OnSubsetSelected( wxCommandEvent
& event
);
109 #if defined(__UNICODE__)
110 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM
111 void OnFromUnicodeSelected( wxCommandEvent
& event
);
114 #if defined(__WXMSW__) || \
115 defined(__WXMAC__) || \
116 defined(__WXGTK__) || \
117 defined(__WXPM__) || \
118 defined(__WXMGL__) || \
119 defined(__WXMOTIF__) || \
120 defined(__WXCOCOA__) || \
121 defined(__WXX11__) || \
122 defined(__WXPALMOS__)
124 /// wxEVT_UPDATE_UI event handler for wxID_OK
125 void OnOkUpdate( wxUpdateUIEvent
& event
);
128 ////@end wxSymbolPickerDialog event handler declarations
130 ////@begin wxSymbolPickerDialog member function declarations
132 wxString
GetFontName() const { return m_fontName
; }
133 void SetFontName(wxString value
) { m_fontName
= value
; }
135 wxString
GetSymbol() const { return m_symbol
; }
136 void SetSymbol(wxString value
) { m_symbol
= value
; }
138 bool GetFromUnicode() const { return m_fromUnicode
; }
139 void SetFromUnicode(bool value
) { m_fromUnicode
= value
; }
141 wxString
GetNormalTextFontName() const { return m_normalTextFontName
; }
142 void SetNormalTextFontName(wxString value
) { m_normalTextFontName
= value
; }
144 /// Retrieves bitmap resources
145 wxBitmap
GetBitmapResource( const wxString
& name
);
147 /// Retrieves icon resources
148 wxIcon
GetIconResource( const wxString
& name
);
149 ////@end wxSymbolPickerDialog member function declarations
151 /// Should we show tooltips?
152 static bool ShowToolTips();
154 ////@begin wxSymbolPickerDialog member variables
155 wxComboBox
* m_fontCtrl
;
156 #if defined(__UNICODE__)
157 wxComboBox
* m_subsetCtrl
;
159 wxSymbolListCtrl
* m_symbolsCtrl
;
160 wxStaticText
* m_symbolStaticCtrl
;
161 wxTextCtrl
* m_characterCodeCtrl
;
162 #if defined(__UNICODE__)
163 wxComboBox
* m_fromUnicodeCtrl
;
168 wxString m_normalTextFontName
;
169 /// Control identifiers
171 ID_SYMBOLPICKERDIALOG
= 10600,
172 ID_SYMBOLPICKERDIALOG_FONT
= 10602,
173 ID_SYMBOLPICKERDIALOG_SUBSET
= 10605,
174 ID_SYMBOLPICKERDIALOG_LISTCTRL
= 10608,
175 ID_SYMBOLPICKERDIALOG_CHARACTERCODE
= 10601,
176 ID_SYMBOLPICKERDIALOG_FROM
= 10603
178 ////@end wxSymbolPickerDialog member variables
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
OnGetLineHeight(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_