]>
Commit | Line | Data |
---|---|---|
ebf0a029 | 1 | ///////////////////////////////////////////////////////////////////////////// |
b68603d5 WS |
2 | // Name: wx/richtext/richtextsymboldlg.h |
3 | // Purpose: | |
ebf0a029 | 4 | // Author: Julian Smart |
b68603d5 | 5 | // Modified by: |
ebf0a029 | 6 | // Created: 10/5/2006 3:11:58 PM |
b68603d5 | 7 | // RCS-ID: $Id$ |
ebf0a029 | 8 | // Copyright: (c) Julian Smart |
b68603d5 | 9 | // Licence: wxWindows licence |
ebf0a029 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _RICHTEXTSYMBOLDLG_H_ | |
13 | #define _RICHTEXTSYMBOLDLG_H_ | |
14 | ||
15 | /*! | |
16 | * Includes | |
17 | */ | |
18 | ||
38b13085 | 19 | #include "wx/dialog.h" |
ebf0a029 JS |
20 | #include "wx/vscroll.h" |
21 | ||
22 | /*! | |
23 | * Forward declarations | |
24 | */ | |
25 | ||
26 | ////@begin forward declarations | |
38b13085 PC |
27 | class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl; |
28 | class WXDLLIMPEXP_CORE wxComboBox; | |
29 | class WXDLLIMPEXP_CORE wxStaticText; | |
30 | class WXDLLIMPEXP_CORE wxTextCtrl; | |
ebf0a029 JS |
31 | ////@end forward declarations |
32 | ||
ebf0a029 JS |
33 | /*! |
34 | * Symbols | |
35 | */ | |
36 | ||
38b13085 | 37 | #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE (wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX) |
ebf0a029 JS |
38 | #define SYMBOL_WXSYMBOLPICKERDIALOG_TITLE _("Symbols") |
39 | #define SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME ID_SYMBOLPICKERDIALOG | |
40 | #define SYMBOL_WXSYMBOLPICKERDIALOG_SIZE wxSize(400, 300) | |
41 | #define SYMBOL_WXSYMBOLPICKERDIALOG_POSITION wxDefaultPosition | |
42 | ||
43 | /*! | |
44 | * wxSymbolPickerDialog class declaration | |
45 | */ | |
46 | ||
47 | class WXDLLIMPEXP_RICHTEXT wxSymbolPickerDialog: public wxDialog | |
b68603d5 | 48 | { |
ebf0a029 JS |
49 | DECLARE_DYNAMIC_CLASS( wxSymbolPickerDialog ) |
50 | DECLARE_EVENT_TABLE() | |
51 | ||
52 | public: | |
53 | /// Constructors | |
54 | wxSymbolPickerDialog( ); | |
55 | wxSymbolPickerDialog( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont, | |
56 | 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 ); | |
57 | ||
58 | /// Creation | |
59 | bool Create( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont, | |
60 | 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 ); | |
61 | ||
62 | /// Initialises members variables | |
63 | void Init(); | |
64 | ||
65 | /// Creates the controls and sizers | |
66 | void CreateControls(); | |
b68603d5 | 67 | |
ebf0a029 JS |
68 | /// Update the display |
69 | void UpdateSymbolDisplay(bool updateSymbolList = true, bool showAtSubset = true); | |
70 | ||
71 | /// Respond to symbol selection | |
72 | void OnSymbolSelected( wxCommandEvent& event ); | |
b68603d5 | 73 | |
ebf0a029 JS |
74 | /// Set Unicode mode |
75 | void SetUnicodeMode(bool unicodeMode); | |
b68603d5 | 76 | |
ebf0a029 JS |
77 | /// Show at the current subset selection |
78 | void ShowAtSubset(); | |
b68603d5 | 79 | |
ebf0a029 JS |
80 | /// Get the selected symbol character |
81 | int GetSymbolChar() const; | |
82 | ||
83 | /// Is there a selection? | |
84 | bool HasSelection() const { return !m_symbol.IsEmpty(); } | |
b68603d5 | 85 | |
ebf0a029 JS |
86 | /// Specifying normal text? |
87 | bool UseNormalFont() const { return m_fontName.IsEmpty(); } | |
b68603d5 | 88 | |
ebf0a029 JS |
89 | /// Data transfer |
90 | virtual bool TransferDataToWindow(); | |
91 | ||
92 | ////@begin wxSymbolPickerDialog event handler declarations | |
93 | ||
94 | /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT | |
95 | void OnFontCtrlSelected( wxCommandEvent& event ); | |
96 | ||
97 | #if defined(__UNICODE__) | |
98 | /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET | |
99 | void OnSubsetSelected( wxCommandEvent& event ); | |
100 | ||
101 | #endif | |
102 | #if defined(__UNICODE__) | |
103 | /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM | |
104 | void OnFromUnicodeSelected( wxCommandEvent& event ); | |
105 | ||
106 | #endif | |
b68603d5 WS |
107 | #if defined(__WXMSW__) || \ |
108 | defined(__WXMAC__) || \ | |
109 | defined(__WXGTK__) || \ | |
110 | defined(__WXPM__) || \ | |
111 | defined(__WXMGL__) || \ | |
112 | defined(__WXMOTIF__) || \ | |
113 | defined(__WXCOCOA__) || \ | |
114 | defined(__WXX11__) || \ | |
115 | defined(__WXPALMOS__) | |
ebf0a029 | 116 | |
ebf0a029 JS |
117 | /// wxEVT_UPDATE_UI event handler for wxID_OK |
118 | void OnOkUpdate( wxUpdateUIEvent& event ); | |
119 | ||
120 | #endif | |
121 | ////@end wxSymbolPickerDialog event handler declarations | |
122 | ||
123 | ////@begin wxSymbolPickerDialog member function declarations | |
124 | ||
125 | wxString GetFontName() const { return m_fontName ; } | |
126 | void SetFontName(wxString value) { m_fontName = value ; } | |
127 | ||
128 | wxString GetSymbol() const { return m_symbol ; } | |
129 | void SetSymbol(wxString value) { m_symbol = value ; } | |
130 | ||
131 | bool GetFromUnicode() const { return m_fromUnicode ; } | |
132 | void SetFromUnicode(bool value) { m_fromUnicode = value ; } | |
133 | ||
134 | wxString GetNormalTextFontName() const { return m_normalTextFontName ; } | |
135 | void SetNormalTextFontName(wxString value) { m_normalTextFontName = value ; } | |
136 | ||
137 | /// Retrieves bitmap resources | |
138 | wxBitmap GetBitmapResource( const wxString& name ); | |
139 | ||
140 | /// Retrieves icon resources | |
141 | wxIcon GetIconResource( const wxString& name ); | |
142 | ////@end wxSymbolPickerDialog member function declarations | |
143 | ||
144 | /// Should we show tooltips? | |
145 | static bool ShowToolTips(); | |
146 | ||
147 | ////@begin wxSymbolPickerDialog member variables | |
148 | wxComboBox* m_fontCtrl; | |
149 | #if defined(__UNICODE__) | |
150 | wxComboBox* m_subsetCtrl; | |
151 | #endif | |
152 | wxSymbolListCtrl* m_symbolsCtrl; | |
153 | wxStaticText* m_symbolStaticCtrl; | |
154 | wxTextCtrl* m_characterCodeCtrl; | |
155 | #if defined(__UNICODE__) | |
156 | wxComboBox* m_fromUnicodeCtrl; | |
157 | #endif | |
158 | wxString m_fontName; | |
159 | wxString m_symbol; | |
160 | bool m_fromUnicode; | |
161 | wxString m_normalTextFontName; | |
162 | /// Control identifiers | |
163 | enum { | |
164 | ID_SYMBOLPICKERDIALOG = 10600, | |
165 | ID_SYMBOLPICKERDIALOG_FONT = 10602, | |
166 | ID_SYMBOLPICKERDIALOG_SUBSET = 10605, | |
167 | ID_SYMBOLPICKERDIALOG_LISTCTRL = 10608, | |
168 | ID_SYMBOLPICKERDIALOG_CHARACTERCODE = 10601, | |
169 | ID_SYMBOLPICKERDIALOG_FROM = 10603 | |
170 | }; | |
171 | ////@end wxSymbolPickerDialog member variables | |
172 | ||
173 | bool m_dontUpdate; | |
174 | }; | |
175 | ||
176 | /*! | |
177 | * The scrolling symbol list. | |
178 | */ | |
b68603d5 | 179 | |
ebf0a029 JS |
180 | class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl : public wxVScrolledWindow |
181 | { | |
182 | public: | |
183 | // constructors and such | |
184 | // --------------------- | |
185 | ||
186 | // default constructor, you must call Create() later | |
187 | wxSymbolListCtrl() { Init(); } | |
188 | ||
189 | // normal constructor which calls Create() internally | |
190 | wxSymbolListCtrl(wxWindow *parent, | |
191 | wxWindowID id = wxID_ANY, | |
192 | const wxPoint& pos = wxDefaultPosition, | |
193 | const wxSize& size = wxDefaultSize, | |
194 | long style = 0, | |
195 | const wxString& name = wxPanelNameStr) | |
196 | { | |
197 | Init(); | |
198 | ||
199 | (void)Create(parent, id, pos, size, style, name); | |
200 | } | |
201 | ||
202 | // really creates the control and sets the initial number of items in it | |
203 | // (which may be changed later with SetItemCount()) | |
204 | // | |
205 | // returns true on success or false if the control couldn't be created | |
206 | bool Create(wxWindow *parent, | |
207 | wxWindowID id = wxID_ANY, | |
208 | const wxPoint& pos = wxDefaultPosition, | |
209 | const wxSize& size = wxDefaultSize, | |
210 | long style = 0, | |
211 | const wxString& name = wxPanelNameStr); | |
212 | ||
213 | // dtor does some internal cleanup | |
214 | virtual ~wxSymbolListCtrl(); | |
215 | ||
216 | ||
217 | // accessors | |
218 | // --------- | |
219 | ||
220 | // set the current font | |
221 | virtual bool SetFont(const wxFont& font); | |
b68603d5 | 222 | |
ebf0a029 JS |
223 | // set Unicode/ASCII mode |
224 | void SetUnicodeMode(bool unicodeMode); | |
225 | ||
226 | // get the index of the currently selected item or wxNOT_FOUND if there is no selection | |
227 | int GetSelection() const; | |
228 | ||
229 | // is this item selected? | |
230 | bool IsSelected(int item) const; | |
231 | ||
232 | // is this item the current one? | |
233 | bool IsCurrentItem(int item) const { return item == m_current; } | |
234 | ||
235 | // get the margins around each cell | |
236 | wxPoint GetMargins() const { return m_ptMargins; } | |
237 | ||
238 | // get the background colour of selected cells | |
239 | const wxColour& GetSelectionBackground() const { return m_colBgSel; } | |
240 | ||
241 | // operations | |
242 | // ---------- | |
243 | ||
244 | // set the selection to the specified item, if it is wxNOT_FOUND the | |
245 | // selection is unset | |
246 | void SetSelection(int selection); | |
b68603d5 | 247 | |
ebf0a029 JS |
248 | // make this item visible |
249 | void EnsureVisible(int item); | |
250 | ||
251 | // set the margins: horizontal margin is the distance between the window | |
252 | // border and the item contents while vertical margin is half of the | |
253 | // distance between items | |
254 | // | |
255 | // by default both margins are 0 | |
256 | void SetMargins(const wxPoint& pt); | |
257 | void SetMargins(wxCoord x, wxCoord y) { SetMargins(wxPoint(x, y)); } | |
b68603d5 | 258 | |
ebf0a029 JS |
259 | // set the cell size |
260 | void SetCellSize(const wxSize& sz) { m_cellSize = sz; } | |
261 | const wxSize& GetCellSize() const { return m_cellSize; } | |
262 | ||
263 | // change the background colour of the selected cells | |
264 | void SetSelectionBackground(const wxColour& col); | |
265 | ||
266 | virtual wxVisualAttributes GetDefaultAttributes() const | |
267 | { | |
268 | return GetClassDefaultAttributes(GetWindowVariant()); | |
269 | } | |
270 | ||
271 | static wxVisualAttributes | |
272 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
b68603d5 | 273 | |
ebf0a029 JS |
274 | // Get min/max symbol values |
275 | int GetMinSymbolValue() const { return m_minSymbolValue; } | |
276 | int GetMaxSymbolValue() const { return m_maxSymbolValue; } | |
b68603d5 | 277 | |
ebf0a029 JS |
278 | // Respond to size change |
279 | void OnSize(wxSizeEvent& event); | |
280 | ||
281 | protected: | |
282 | ||
b68603d5 | 283 | // draws a line of symbols |
ebf0a029 | 284 | virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const; |
b68603d5 | 285 | |
ebf0a029 JS |
286 | // gets the line height |
287 | virtual wxCoord OnGetLineHeight(size_t line) const; | |
288 | ||
289 | // event handlers | |
290 | void OnPaint(wxPaintEvent& event); | |
291 | void OnKeyDown(wxKeyEvent& event); | |
292 | void OnLeftDown(wxMouseEvent& event); | |
293 | void OnLeftDClick(wxMouseEvent& event); | |
294 | ||
295 | // common part of all ctors | |
296 | void Init(); | |
297 | ||
298 | // send the wxEVT_COMMAND_LISTBOX_SELECTED event | |
299 | void SendSelectedEvent(); | |
300 | ||
301 | // change the current item (in single selection listbox it also implicitly | |
302 | // changes the selection); current may be wxNOT_FOUND in which case there | |
303 | // will be no current item any more | |
304 | // | |
305 | // return true if the current item changed, false otherwise | |
306 | bool DoSetCurrent(int current); | |
307 | ||
308 | // flags for DoHandleItemClick | |
309 | enum | |
310 | { | |
311 | ItemClick_Shift = 1, // item shift-clicked | |
312 | ItemClick_Ctrl = 2, // ctrl | |
313 | ItemClick_Kbd = 4 // item selected from keyboard | |
314 | }; | |
315 | ||
316 | // common part of keyboard and mouse handling processing code | |
317 | void DoHandleItemClick(int item, int flags); | |
b68603d5 | 318 | |
ebf0a029 JS |
319 | // calculate line number from symbol value |
320 | int SymbolValueToLineNumber(int item); | |
b68603d5 | 321 | |
ebf0a029 JS |
322 | // initialise control from current min/max values |
323 | void SetupCtrl(bool scrollToSelection = true); | |
b68603d5 | 324 | |
ebf0a029 JS |
325 | // hit testing |
326 | int HitTest(const wxPoint& pt); | |
327 | ||
328 | private: | |
329 | // the current item or wxNOT_FOUND | |
330 | int m_current; | |
331 | ||
332 | // margins | |
333 | wxPoint m_ptMargins; | |
334 | ||
335 | // the selection bg colour | |
336 | wxColour m_colBgSel; | |
337 | ||
338 | // double buffer | |
339 | wxBitmap* m_doubleBuffer; | |
b68603d5 | 340 | |
ebf0a029 JS |
341 | // cell size |
342 | wxSize m_cellSize; | |
b68603d5 | 343 | |
ebf0a029 JS |
344 | // minimum and maximum symbol value |
345 | int m_minSymbolValue; | |
346 | ||
347 | // minimum and maximum symbol value | |
348 | int m_maxSymbolValue; | |
b68603d5 | 349 | |
ebf0a029 JS |
350 | // number of items per line |
351 | int m_symbolsPerLine; | |
b68603d5 | 352 | |
ebf0a029 JS |
353 | // Unicode/ASCII mode |
354 | bool m_unicodeMode; | |
355 | ||
356 | DECLARE_EVENT_TABLE() | |
357 | DECLARE_NO_COPY_CLASS(wxSymbolListCtrl) | |
358 | DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl) | |
359 | }; | |
360 | ||
361 | #endif | |
362 | // _RICHTEXTSYMBOLDLG_H_ |