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