]>
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 | ||
24 | /*! | |
25 | * Forward declarations | |
26 | */ | |
27 | ||
28 | ////@begin forward declarations | |
29 | class wxSymbolListCtrl; | |
30 | ////@end forward declarations | |
31 | ||
32 | // __UNICODE__ is a symbol used by DialogBlocks-generated code. | |
33 | #ifndef __UNICODE__ | |
34 | #if wxUSE_UNICODE | |
35 | #define __UNICODE__ | |
36 | #endif | |
37 | #endif | |
38 | ||
39 | /*! | |
40 | * Symbols | |
41 | */ | |
42 | ||
43 | #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE (wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX) | |
44 | #define SYMBOL_WXSYMBOLPICKERDIALOG_TITLE _("Symbols") | |
45 | #define SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME ID_SYMBOLPICKERDIALOG | |
46 | #define SYMBOL_WXSYMBOLPICKERDIALOG_SIZE wxSize(400, 300) | |
47 | #define SYMBOL_WXSYMBOLPICKERDIALOG_POSITION wxDefaultPosition | |
48 | ||
49 | /*! | |
50 | * wxSymbolPickerDialog class declaration | |
51 | */ | |
52 | ||
53 | class WXDLLIMPEXP_RICHTEXT wxSymbolPickerDialog: public wxDialog | |
54 | { | |
55 | DECLARE_DYNAMIC_CLASS( wxSymbolPickerDialog ) | |
56 | DECLARE_EVENT_TABLE() | |
57 | ||
58 | public: | |
59 | /// Constructors | |
60 | wxSymbolPickerDialog( ); | |
61 | wxSymbolPickerDialog( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont, | |
62 | 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 ); | |
63 | ||
64 | /// Creation | |
65 | bool Create( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont, | |
66 | 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 ); | |
67 | ||
68 | /// Initialises members variables | |
69 | void Init(); | |
70 | ||
71 | /// Creates the controls and sizers | |
72 | void CreateControls(); | |
73 | ||
74 | /// Update the display | |
75 | void UpdateSymbolDisplay(bool updateSymbolList = true, bool showAtSubset = true); | |
76 | ||
77 | /// Respond to symbol selection | |
78 | void OnSymbolSelected( wxCommandEvent& event ); | |
79 | ||
80 | /// Set Unicode mode | |
81 | void SetUnicodeMode(bool unicodeMode); | |
82 | ||
83 | /// Show at the current subset selection | |
84 | void ShowAtSubset(); | |
85 | ||
86 | /// Get the selected symbol character | |
87 | int GetSymbolChar() const; | |
88 | ||
89 | /// Is there a selection? | |
90 | bool HasSelection() const { return !m_symbol.IsEmpty(); } | |
91 | ||
92 | /// Specifying normal text? | |
93 | bool UseNormalFont() const { return m_fontName.IsEmpty(); } | |
94 | ||
95 | /// Should we show tooltips? | |
96 | static bool ShowToolTips() { return sm_showToolTips; } | |
97 | ||
98 | /// Determines whether tooltips will be shown | |
99 | static void SetShowToolTips(bool show) { sm_showToolTips = show; } | |
100 | ||
101 | /// Data transfer | |
102 | virtual bool TransferDataToWindow(); | |
103 | ||
104 | ////@begin wxSymbolPickerDialog event handler declarations | |
105 | ||
106 | /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT | |
107 | void OnFontCtrlSelected( wxCommandEvent& event ); | |
108 | ||
109 | #if defined(__UNICODE__) | |
110 | /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET | |
111 | void OnSubsetSelected( wxCommandEvent& event ); | |
112 | ||
113 | #endif | |
114 | #if defined(__UNICODE__) | |
115 | /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM | |
116 | void OnFromUnicodeSelected( wxCommandEvent& event ); | |
117 | ||
118 | #endif | |
119 | ||
120 | /// wxEVT_UPDATE_UI event handler for wxID_OK | |
121 | void OnOkUpdate( wxUpdateUIEvent& event ); | |
122 | ||
123 | ////@end wxSymbolPickerDialog event handler declarations | |
124 | ||
125 | ////@begin wxSymbolPickerDialog member function declarations | |
126 | ||
127 | wxString GetFontName() const { return m_fontName ; } | |
128 | void SetFontName(wxString value) { m_fontName = value ; } | |
129 | ||
130 | wxString GetSymbol() const { return m_symbol ; } | |
131 | void SetSymbol(wxString value) { m_symbol = value ; } | |
132 | ||
133 | bool GetFromUnicode() const { return m_fromUnicode ; } | |
134 | void SetFromUnicode(bool value) { m_fromUnicode = value ; } | |
135 | ||
136 | wxString GetNormalTextFontName() const { return m_normalTextFontName ; } | |
137 | void SetNormalTextFontName(wxString value) { m_normalTextFontName = value ; } | |
138 | ||
139 | /// Retrieves bitmap resources | |
140 | wxBitmap GetBitmapResource( const wxString& name ); | |
141 | ||
142 | /// Retrieves icon resources | |
143 | wxIcon GetIconResource( const wxString& name ); | |
144 | ////@end wxSymbolPickerDialog member function declarations | |
145 | ||
146 | ////@begin wxSymbolPickerDialog member variables | |
147 | wxComboBox* m_fontCtrl; | |
148 | #if defined(__UNICODE__) | |
149 | wxComboBox* m_subsetCtrl; | |
150 | #endif | |
151 | wxSymbolListCtrl* m_symbolsCtrl; | |
152 | wxStaticText* m_symbolStaticCtrl; | |
153 | wxTextCtrl* m_characterCodeCtrl; | |
154 | #if defined(__UNICODE__) | |
155 | wxComboBox* m_fromUnicodeCtrl; | |
156 | #endif | |
157 | wxString m_fontName; | |
158 | wxString m_symbol; | |
159 | bool m_fromUnicode; | |
160 | wxString m_normalTextFontName; | |
161 | /// Control identifiers | |
162 | enum { | |
163 | ID_SYMBOLPICKERDIALOG = 10600, | |
164 | ID_SYMBOLPICKERDIALOG_FONT = 10602, | |
165 | ID_SYMBOLPICKERDIALOG_SUBSET = 10605, | |
166 | ID_SYMBOLPICKERDIALOG_LISTCTRL = 10608, | |
167 | ID_SYMBOLPICKERDIALOG_CHARACTERCODE = 10601, | |
168 | ID_SYMBOLPICKERDIALOG_FROM = 10603 | |
169 | }; | |
170 | ////@end wxSymbolPickerDialog member variables | |
171 | ||
172 | bool m_dontUpdate; | |
173 | static bool sm_showToolTips; | |
174 | }; | |
175 | ||
176 | /*! | |
177 | * The scrolling symbol list. | |
178 | */ | |
179 | ||
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); | |
222 | ||
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); | |
247 | ||
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)); } | |
258 | ||
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); | |
273 | ||
274 | // Get min/max symbol values | |
275 | int GetMinSymbolValue() const { return m_minSymbolValue; } | |
276 | int GetMaxSymbolValue() const { return m_maxSymbolValue; } | |
277 | ||
278 | // Respond to size change | |
279 | void OnSize(wxSizeEvent& event); | |
280 | ||
281 | protected: | |
282 | ||
283 | // draws a line of symbols | |
284 | virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const; | |
285 | ||
286 | // gets the line height | |
287 | virtual wxCoord OnGetRowHeight(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); | |
318 | ||
319 | // calculate line number from symbol value | |
320 | int SymbolValueToLineNumber(int item); | |
321 | ||
322 | // initialise control from current min/max values | |
323 | void SetupCtrl(bool scrollToSelection = true); | |
324 | ||
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; | |
340 | ||
341 | // cell size | |
342 | wxSize m_cellSize; | |
343 | ||
344 | // minimum and maximum symbol value | |
345 | int m_minSymbolValue; | |
346 | ||
347 | // minimum and maximum symbol value | |
348 | int m_maxSymbolValue; | |
349 | ||
350 | // number of items per line | |
351 | int m_symbolsPerLine; | |
352 | ||
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_ |