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