]>
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" | |
d949570b | 23 | #include "wx/textctrl.h" |
ebf0a029 JS |
24 | |
25 | /*! | |
26 | * Forward declarations | |
27 | */ | |
28 | ||
29 | ////@begin forward declarations | |
dadd4f55 | 30 | class wxSymbolListCtrl; |
ebf0a029 JS |
31 | ////@end forward declarations |
32 | ||
2a6c3e25 JS |
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 | ||
ebf0a029 JS |
40 | /*! |
41 | * Symbols | |
42 | */ | |
43 | ||
38b13085 | 44 | #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE (wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX) |
ebf0a029 JS |
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 | |
b68603d5 | 55 | { |
ebf0a029 JS |
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, | |
8871035d | 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 ); |
ebf0a029 JS |
64 | |
65 | /// Creation | |
66 | bool Create( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont, | |
8871035d | 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 ); |
ebf0a029 JS |
68 | |
69 | /// Initialises members variables | |
70 | void Init(); | |
71 | ||
72 | /// Creates the controls and sizers | |
73 | void CreateControls(); | |
b68603d5 | 74 | |
ebf0a029 JS |
75 | /// Update the display |
76 | void UpdateSymbolDisplay(bool updateSymbolList = true, bool showAtSubset = true); | |
77 | ||
78 | /// Respond to symbol selection | |
79 | void OnSymbolSelected( wxCommandEvent& event ); | |
b68603d5 | 80 | |
ebf0a029 JS |
81 | /// Set Unicode mode |
82 | void SetUnicodeMode(bool unicodeMode); | |
b68603d5 | 83 | |
ebf0a029 JS |
84 | /// Show at the current subset selection |
85 | void ShowAtSubset(); | |
b68603d5 | 86 | |
ebf0a029 JS |
87 | /// Get the selected symbol character |
88 | int GetSymbolChar() const; | |
89 | ||
90 | /// Is there a selection? | |
91 | bool HasSelection() const { return !m_symbol.IsEmpty(); } | |
b68603d5 | 92 | |
ebf0a029 JS |
93 | /// Specifying normal text? |
94 | bool UseNormalFont() const { return m_fontName.IsEmpty(); } | |
b68603d5 | 95 | |
dadd4f55 JS |
96 | /// Should we show tooltips? |
97 | static bool ShowToolTips() { return sm_showToolTips; } | |
41a85215 | 98 | |
dadd4f55 JS |
99 | /// Determines whether tooltips will be shown |
100 | static void SetShowToolTips(bool show) { sm_showToolTips = show; } | |
101 | ||
ebf0a029 JS |
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 | |
ebf0a029 JS |
120 | /// wxEVT_UPDATE_UI event handler for wxID_OK |
121 | void OnOkUpdate( wxUpdateUIEvent& event ); | |
122 | ||
ebf0a029 JS |
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 | ||
ebf0a029 JS |
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; | |
dadd4f55 | 173 | static bool sm_showToolTips; |
ebf0a029 JS |
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 | 286 | // gets the line height |
e02c72fa | 287 | virtual wxCoord OnGetRowHeight(size_t line) const; |
ebf0a029 JS |
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_ |