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