]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/combo.h | |
3 | // Purpose: wxComboCtrl declaration | |
4 | // Author: Jaakko Salli | |
5 | // Modified by: | |
6 | // Created: Apr-30-2006 | |
7 | // Copyright: (c) Jaakko Salli | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_COMBOCONTROL_H_BASE_ | |
12 | #define _WX_COMBOCONTROL_H_BASE_ | |
13 | ||
14 | ||
15 | /* | |
16 | A few words about all the classes defined in this file are probably in | |
17 | order: why do we need extra wxComboCtrl and wxComboPopup classes? | |
18 | ||
19 | This is because a traditional combobox is a combination of a text control | |
20 | (with a button allowing to open the pop down list) with a listbox and | |
21 | wxComboBox class is exactly such control, however we want to also have other | |
22 | combinations - in fact, we want to allow anything at all to be used as pop | |
23 | down list, not just a wxListBox. | |
24 | ||
25 | So we define a base wxComboCtrl which can use any control as pop down | |
26 | list and wxComboBox deriving from it which implements the standard wxWidgets | |
27 | combobox API. wxComboCtrl needs to be told somehow which control to use | |
28 | and this is done by SetPopupControl(). However, we need something more than | |
29 | just a wxControl in this method as, for example, we need to call | |
30 | SetSelection("initial text value") and wxControl doesn't have such method. | |
31 | So we also need a wxComboPopup which is just a very simple interface which | |
32 | must be implemented by a control to be usable as a popup. | |
33 | ||
34 | We couldn't derive wxComboPopup from wxControl as this would make it | |
35 | impossible to have a class deriving from both wxListBx and from it, so | |
36 | instead it is just a mix-in. | |
37 | */ | |
38 | ||
39 | ||
40 | #include "wx/defs.h" | |
41 | ||
42 | #if wxUSE_COMBOCTRL | |
43 | ||
44 | #include "wx/control.h" | |
45 | #include "wx/renderer.h" // this is needed for wxCONTROL_XXX flags | |
46 | #include "wx/bitmap.h" // wxBitmap used by-value | |
47 | #include "wx/textentry.h" | |
48 | ||
49 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; | |
50 | class WXDLLIMPEXP_FWD_CORE wxComboPopup; | |
51 | ||
52 | // | |
53 | // New window styles for wxComboCtrlBase | |
54 | // | |
55 | enum | |
56 | { | |
57 | // Double-clicking a read-only combo triggers call to popup's OnComboPopup. | |
58 | // In wxOwnerDrawnComboBox, for instance, it cycles item. | |
59 | wxCC_SPECIAL_DCLICK = 0x0100, | |
60 | ||
61 | // Dropbutton acts like standard push button. | |
62 | wxCC_STD_BUTTON = 0x0200 | |
63 | }; | |
64 | ||
65 | ||
66 | // wxComboCtrl internal flags | |
67 | enum | |
68 | { | |
69 | // First those that can be passed to Customize. | |
70 | // It is Windows style for all flags to be clear. | |
71 | ||
72 | // Button is preferred outside the border (GTK style) | |
73 | wxCC_BUTTON_OUTSIDE_BORDER = 0x0001, | |
74 | // Show popup on mouse up instead of mouse down (which is the Windows style) | |
75 | wxCC_POPUP_ON_MOUSE_UP = 0x0002, | |
76 | // All text is not automatically selected on click | |
77 | wxCC_NO_TEXT_AUTO_SELECT = 0x0004, | |
78 | // Drop-button stays down as long as popup is displayed. | |
79 | wxCC_BUTTON_STAYS_DOWN = 0x0008, | |
80 | // Drop-button covers the entire control. | |
81 | wxCC_FULL_BUTTON = 0x0010, | |
82 | // Drop-button goes over the custom-border (used under WinVista). | |
83 | wxCC_BUTTON_COVERS_BORDER = 0x0020, | |
84 | ||
85 | // Internal use: signals creation is complete | |
86 | wxCC_IFLAG_CREATED = 0x0100, | |
87 | // Internal use: really put button outside | |
88 | wxCC_IFLAG_BUTTON_OUTSIDE = 0x0200, | |
89 | // Internal use: SetMargins has been successfully called | |
90 | wxCC_IFLAG_LEFT_MARGIN_SET = 0x0400, | |
91 | // Internal use: Set wxTAB_TRAVERSAL to parent when popup is dismissed | |
92 | wxCC_IFLAG_PARENT_TAB_TRAVERSAL = 0x0800, | |
93 | // Internal use: Secondary popup window type should be used (if available). | |
94 | wxCC_IFLAG_USE_ALT_POPUP = 0x1000, | |
95 | // Internal use: Skip popup animation. | |
96 | wxCC_IFLAG_DISABLE_POPUP_ANIM = 0x2000, | |
97 | // Internal use: Drop-button is a bitmap button or has non-default size | |
98 | // (but can still be on either side of the control), regardless whether | |
99 | // specified by the platform or the application. | |
100 | wxCC_IFLAG_HAS_NONSTANDARD_BUTTON = 0x4000 | |
101 | }; | |
102 | ||
103 | ||
104 | // Flags used by PreprocessMouseEvent and HandleButtonMouseEvent | |
105 | enum | |
106 | { | |
107 | wxCC_MF_ON_BUTTON = 0x0001, // cursor is on dropbutton area | |
108 | wxCC_MF_ON_CLICK_AREA = 0x0002 // cursor is on dropbutton or other area | |
109 | // that can be clicked to show the popup. | |
110 | }; | |
111 | ||
112 | ||
113 | // Namespace for wxComboCtrl feature flags | |
114 | struct wxComboCtrlFeatures | |
115 | { | |
116 | enum | |
117 | { | |
118 | MovableButton = 0x0001, // Button can be on either side of control | |
119 | BitmapButton = 0x0002, // Button may be replaced with bitmap | |
120 | ButtonSpacing = 0x0004, // Button can have spacing from the edge | |
121 | // of the control | |
122 | TextIndent = 0x0008, // SetMargins can be used to control | |
123 | // left margin. | |
124 | PaintControl = 0x0010, // Combo control itself can be custom painted | |
125 | PaintWritable = 0x0020, // A variable-width area in front of writable | |
126 | // combo control's textctrl can be custom | |
127 | // painted | |
128 | Borderless = 0x0040, // wxNO_BORDER window style works | |
129 | ||
130 | // There are no feature flags for... | |
131 | // PushButtonBitmapBackground - if its in wxRendererNative, then it should be | |
132 | // not an issue to have it automatically under the bitmap. | |
133 | ||
134 | All = MovableButton|BitmapButton| | |
135 | ButtonSpacing|TextIndent| | |
136 | PaintControl|PaintWritable| | |
137 | Borderless | |
138 | }; | |
139 | }; | |
140 | ||
141 | ||
142 | class WXDLLIMPEXP_CORE wxComboCtrlBase : public wxControl, | |
143 | public wxTextEntry | |
144 | { | |
145 | friend class wxComboPopup; | |
146 | friend class wxComboPopupEvtHandler; | |
147 | public: | |
148 | // ctors and such | |
149 | wxComboCtrlBase() : wxControl(), wxTextEntry() { Init(); } | |
150 | ||
151 | bool Create(wxWindow *parent, | |
152 | wxWindowID id, | |
153 | const wxString& value, | |
154 | const wxPoint& pos, | |
155 | const wxSize& size, | |
156 | long style, | |
157 | const wxValidator& validator, | |
158 | const wxString& name); | |
159 | ||
160 | virtual ~wxComboCtrlBase(); | |
161 | ||
162 | // Show/hide popup window (wxComboBox-compatible methods) | |
163 | virtual void Popup(); | |
164 | virtual void Dismiss() | |
165 | { | |
166 | HidePopup(true); | |
167 | } | |
168 | ||
169 | // Show/hide popup window. | |
170 | // TODO: Maybe deprecate in favor of Popup()/Dismiss(). | |
171 | // However, these functions are still called internally | |
172 | // so it is not straightforward. | |
173 | virtual void ShowPopup(); | |
174 | virtual void HidePopup(bool generateEvent=false); | |
175 | ||
176 | // Override for totally custom combo action | |
177 | virtual void OnButtonClick(); | |
178 | ||
179 | // return true if the popup is currently shown | |
180 | bool IsPopupShown() const { return m_popupWinState == Visible; } | |
181 | ||
182 | // set interface class instance derived from wxComboPopup | |
183 | // NULL popup can be used to indicate default in a derived class | |
184 | void SetPopupControl( wxComboPopup* popup ) | |
185 | { | |
186 | DoSetPopupControl(popup); | |
187 | } | |
188 | ||
189 | // get interface class instance derived from wxComboPopup | |
190 | wxComboPopup* GetPopupControl() | |
191 | { | |
192 | EnsurePopupControl(); | |
193 | return m_popupInterface; | |
194 | } | |
195 | ||
196 | // get the popup window containing the popup control | |
197 | wxWindow *GetPopupWindow() const { return m_winPopup; } | |
198 | ||
199 | // Get the text control which is part of the combobox. | |
200 | wxTextCtrl *GetTextCtrl() const { return m_text; } | |
201 | ||
202 | // get the dropdown button which is part of the combobox | |
203 | // note: its not necessarily a wxButton or wxBitmapButton | |
204 | wxWindow *GetButton() const { return m_btn; } | |
205 | ||
206 | // forward these methods to all subcontrols | |
207 | virtual bool Enable(bool enable = true); | |
208 | virtual bool Show(bool show = true); | |
209 | virtual bool SetFont(const wxFont& font); | |
210 | ||
211 | // | |
212 | // wxTextEntry methods | |
213 | // | |
214 | // NB: We basically need to override all of them because there is | |
215 | // no guarantee how platform-specific wxTextEntry is implemented. | |
216 | // | |
217 | virtual void SetValue(const wxString& value) | |
218 | { wxTextEntryBase::SetValue(value); } | |
219 | virtual void ChangeValue(const wxString& value) | |
220 | { wxTextEntryBase::ChangeValue(value); } | |
221 | ||
222 | virtual void WriteText(const wxString& text); | |
223 | virtual void AppendText(const wxString& text) | |
224 | { wxTextEntryBase::AppendText(text); } | |
225 | ||
226 | virtual wxString GetValue() const | |
227 | { return wxTextEntryBase::GetValue(); } | |
228 | ||
229 | virtual wxString GetRange(long from, long to) const | |
230 | { return wxTextEntryBase::GetRange(from, to); } | |
231 | ||
232 | // Replace() and DoSetValue() need to be fully re-implemented since | |
233 | // EventSuppressor utility class does not work with the way | |
234 | // wxComboCtrl is implemented. | |
235 | virtual void Replace(long from, long to, const wxString& value); | |
236 | ||
237 | virtual void Remove(long from, long to); | |
238 | ||
239 | virtual void Copy(); | |
240 | virtual void Cut(); | |
241 | virtual void Paste(); | |
242 | ||
243 | virtual void Undo(); | |
244 | virtual void Redo(); | |
245 | virtual bool CanUndo() const; | |
246 | virtual bool CanRedo() const; | |
247 | ||
248 | virtual void SetInsertionPoint(long pos); | |
249 | virtual long GetInsertionPoint() const; | |
250 | virtual long GetLastPosition() const; | |
251 | ||
252 | virtual void SetSelection(long from, long to); | |
253 | virtual void GetSelection(long *from, long *to) const; | |
254 | ||
255 | virtual bool IsEditable() const; | |
256 | virtual void SetEditable(bool editable); | |
257 | ||
258 | virtual bool SetHint(const wxString& hint); | |
259 | virtual wxString GetHint() const; | |
260 | ||
261 | // This method sets the text without affecting list selection | |
262 | // (ie. wxComboPopup::SetStringValue doesn't get called). | |
263 | void SetText(const wxString& value); | |
264 | ||
265 | // This method sets value and also optionally sends EVT_TEXT | |
266 | // (needed by combo popups) | |
267 | wxDEPRECATED( void SetValueWithEvent(const wxString& value, | |
268 | bool withEvent = true) ); | |
269 | ||
270 | // Changes value of the control as if user had done it by selecting an | |
271 | // item from a combo box drop-down list. Needs to be public so that | |
272 | // derived popup classes can call it. | |
273 | void SetValueByUser(const wxString& value); | |
274 | ||
275 | // | |
276 | // Popup customization methods | |
277 | // | |
278 | ||
279 | // Sets minimum width of the popup. If wider than combo control, it will extend to the left. | |
280 | // Remarks: | |
281 | // * Value -1 indicates the default. | |
282 | // * Custom popup may choose to ignore this (wxOwnerDrawnComboBox does not). | |
283 | void SetPopupMinWidth( int width ) | |
284 | { | |
285 | m_widthMinPopup = width; | |
286 | } | |
287 | ||
288 | // Sets preferred maximum height of the popup. | |
289 | // Remarks: | |
290 | // * Value -1 indicates the default. | |
291 | // * Custom popup may choose to ignore this (wxOwnerDrawnComboBox does not). | |
292 | void SetPopupMaxHeight( int height ) | |
293 | { | |
294 | m_heightPopup = height; | |
295 | } | |
296 | ||
297 | // Extends popup size horizontally, relative to the edges of the combo control. | |
298 | // Remarks: | |
299 | // * Popup minimum width may override extLeft (ie. it has higher precedence). | |
300 | // * Values 0 indicate default. | |
301 | // * Custom popup may not take this fully into account (wxOwnerDrawnComboBox takes). | |
302 | void SetPopupExtents( int extLeft, int extRight ) | |
303 | { | |
304 | m_extLeft = extLeft; | |
305 | m_extRight = extRight; | |
306 | } | |
307 | ||
308 | // Set width, in pixels, of custom paint area in writable combo. | |
309 | // In read-only, used to indicate area that is not covered by the | |
310 | // focus rectangle (which may or may not be drawn, depending on the | |
311 | // popup type). | |
312 | void SetCustomPaintWidth( int width ); | |
313 | int GetCustomPaintWidth() const { return m_widthCustomPaint; } | |
314 | ||
315 | // Set side of the control to which the popup will align itself. | |
316 | // Valid values are wxLEFT, wxRIGHT and 0. The default value 0 wmeans | |
317 | // that the side of the button will be used. | |
318 | void SetPopupAnchor( int anchorSide ) | |
319 | { | |
320 | m_anchorSide = anchorSide; | |
321 | } | |
322 | ||
323 | // Set position of dropdown button. | |
324 | // width: button width. <= 0 for default. | |
325 | // height: button height. <= 0 for default. | |
326 | // side: wxLEFT or wxRIGHT, indicates on which side the button will be placed. | |
327 | // spacingX: empty space on sides of the button. Default is 0. | |
328 | // Remarks: | |
329 | // There is no spacingY - the button will be centered vertically. | |
330 | void SetButtonPosition( int width = -1, | |
331 | int height = -1, | |
332 | int side = wxRIGHT, | |
333 | int spacingX = 0 ); | |
334 | ||
335 | // Returns current size of the dropdown button. | |
336 | wxSize GetButtonSize(); | |
337 | ||
338 | // | |
339 | // Sets dropbutton to be drawn with custom bitmaps. | |
340 | // | |
341 | // bmpNormal: drawn when cursor is not on button | |
342 | // pushButtonBg: Draw push button background below the image. | |
343 | // NOTE! This is usually only properly supported on platforms with appropriate | |
344 | // method in wxRendererNative. | |
345 | // bmpPressed: drawn when button is depressed | |
346 | // bmpHover: drawn when cursor hovers on button. This is ignored on platforms | |
347 | // that do not generally display hover differently. | |
348 | // bmpDisabled: drawn when combobox is disabled. | |
349 | void SetButtonBitmaps( const wxBitmap& bmpNormal, | |
350 | bool pushButtonBg = false, | |
351 | const wxBitmap& bmpPressed = wxNullBitmap, | |
352 | const wxBitmap& bmpHover = wxNullBitmap, | |
353 | const wxBitmap& bmpDisabled = wxNullBitmap ); | |
354 | ||
355 | #if WXWIN_COMPATIBILITY_2_8 | |
356 | // | |
357 | // This will set the space in pixels between left edge of the control and the | |
358 | // text, regardless whether control is read-only (ie. no wxTextCtrl) or not. | |
359 | // Platform-specific default can be set with value-1. | |
360 | // Remarks | |
361 | // * This method may do nothing on some native implementations. | |
362 | wxDEPRECATED( void SetTextIndent( int indent ) ); | |
363 | ||
364 | // Returns actual indentation in pixels. | |
365 | wxDEPRECATED( wxCoord GetTextIndent() const ); | |
366 | #endif | |
367 | ||
368 | // Returns area covered by the text field. | |
369 | const wxRect& GetTextRect() const | |
370 | { | |
371 | return m_tcArea; | |
372 | } | |
373 | ||
374 | // Call with enable as true to use a type of popup window that guarantees ability | |
375 | // to focus the popup control, and normal function of common native controls. | |
376 | // This alternative popup window is usually a wxDialog, and as such it's parent | |
377 | // frame will appear as if the focus has been lost from it. | |
378 | void UseAltPopupWindow( bool enable = true ) | |
379 | { | |
380 | wxASSERT_MSG( !m_winPopup, | |
381 | wxT("call this only before SetPopupControl") ); | |
382 | ||
383 | if ( enable ) | |
384 | m_iFlags |= wxCC_IFLAG_USE_ALT_POPUP; | |
385 | else | |
386 | m_iFlags &= ~wxCC_IFLAG_USE_ALT_POPUP; | |
387 | } | |
388 | ||
389 | // Call with false to disable popup animation, if any. | |
390 | void EnablePopupAnimation( bool enable = true ) | |
391 | { | |
392 | if ( enable ) | |
393 | m_iFlags &= ~wxCC_IFLAG_DISABLE_POPUP_ANIM; | |
394 | else | |
395 | m_iFlags |= wxCC_IFLAG_DISABLE_POPUP_ANIM; | |
396 | } | |
397 | ||
398 | // | |
399 | // Utilies needed by the popups or native implementations | |
400 | // | |
401 | ||
402 | // Returns true if given key combination should toggle the popup. | |
403 | // NB: This is a separate from other keyboard handling because: | |
404 | // 1) Replaceability. | |
405 | // 2) Centralized code (otherwise it'd be split up between | |
406 | // wxComboCtrl key handler and wxVListBoxComboPopup's | |
407 | // key handler). | |
408 | virtual bool IsKeyPopupToggle(const wxKeyEvent& event) const = 0; | |
409 | ||
410 | // Prepare background of combo control or an item in a dropdown list | |
411 | // in a way typical on platform. This includes painting the focus/disabled | |
412 | // background and setting the clipping region. | |
413 | // Unless you plan to paint your own focus indicator, you should always call this | |
414 | // in your wxComboPopup::PaintComboControl implementation. | |
415 | // In addition, it sets pen and text colour to what looks good and proper | |
416 | // against the background. | |
417 | // flags: wxRendererNative flags: wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control | |
418 | // wxCONTROL_SELECTED: list item is selected | |
419 | // wxCONTROL_DISABLED: control/item is disabled | |
420 | virtual void PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const; | |
421 | ||
422 | // Returns true if focus indicator should be drawn in the control. | |
423 | bool ShouldDrawFocus() const | |
424 | { | |
425 | const wxWindow* curFocus = FindFocus(); | |
426 | return ( IsPopupWindowState(Hidden) && | |
427 | (curFocus == m_mainCtrlWnd || (m_btn && curFocus == m_btn)) && | |
428 | (m_windowStyle & wxCB_READONLY) ); | |
429 | } | |
430 | ||
431 | // These methods return references to appropriate dropbutton bitmaps | |
432 | const wxBitmap& GetBitmapNormal() const { return m_bmpNormal; } | |
433 | const wxBitmap& GetBitmapPressed() const { return m_bmpPressed; } | |
434 | const wxBitmap& GetBitmapHover() const { return m_bmpHover; } | |
435 | const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; } | |
436 | ||
437 | // Set custom style flags for embedded wxTextCtrl. Usually must be used | |
438 | // with two-step creation, before Create() call. | |
439 | void SetTextCtrlStyle( int style ); | |
440 | ||
441 | // Return internal flags | |
442 | wxUint32 GetInternalFlags() const { return m_iFlags; } | |
443 | ||
444 | // Return true if Create has finished | |
445 | bool IsCreated() const { return m_iFlags & wxCC_IFLAG_CREATED ? true : false; } | |
446 | ||
447 | // Need to override to return text area background colour | |
448 | wxColour GetBackgroundColour() const; | |
449 | ||
450 | // common code to be called on popup hide/dismiss | |
451 | void OnPopupDismiss(bool generateEvent); | |
452 | ||
453 | // PopupShown states | |
454 | enum | |
455 | { | |
456 | Hidden = 0, | |
457 | //Closing = 1, | |
458 | Animating = 2, | |
459 | Visible = 3 | |
460 | }; | |
461 | ||
462 | bool IsPopupWindowState( int state ) const { return (state == m_popupWinState) ? true : false; } | |
463 | ||
464 | wxByte GetPopupWindowState() const { return m_popupWinState; } | |
465 | ||
466 | // Set value returned by GetMainWindowOfCompositeControl | |
467 | void SetCtrlMainWnd( wxWindow* wnd ) { m_mainCtrlWnd = wnd; } | |
468 | ||
469 | // This is public so we can access it from wxComboCtrlTextCtrl | |
470 | virtual wxWindow *GetMainWindowOfCompositeControl() | |
471 | { return m_mainCtrlWnd; } | |
472 | ||
473 | // also set the embedded wxTextCtrl colours | |
474 | virtual bool SetForegroundColour(const wxColour& colour); | |
475 | virtual bool SetBackgroundColour(const wxColour& colour); | |
476 | ||
477 | protected: | |
478 | ||
479 | // Returns true if hint text should be drawn in the control | |
480 | bool ShouldUseHintText(int flags = 0) const | |
481 | { | |
482 | return ( !m_text && | |
483 | !(flags & wxCONTROL_ISSUBMENU) && | |
484 | !m_valueString.length() && | |
485 | m_hintText.length() && | |
486 | !ShouldDrawFocus() ); | |
487 | } | |
488 | ||
489 | // | |
490 | // Override these for customization purposes | |
491 | // | |
492 | ||
493 | // called from wxSizeEvent handler | |
494 | virtual void OnResize() = 0; | |
495 | ||
496 | // Return native text identation | |
497 | // (i.e. text margin, for pure text, not textctrl) | |
498 | virtual wxCoord GetNativeTextIndent() const; | |
499 | ||
500 | // Called in syscolourchanged handler and base create | |
501 | virtual void OnThemeChange(); | |
502 | ||
503 | // Creates wxTextCtrl. | |
504 | // extraStyle: Extra style parameters | |
505 | void CreateTextCtrl( int extraStyle ); | |
506 | ||
507 | // Called when text was changed programmatically | |
508 | // (e.g. from WriteText()) | |
509 | void OnSetValue(const wxString& value); | |
510 | ||
511 | // Installs standard input handler to combo (and optionally to the textctrl) | |
512 | void InstallInputHandlers(); | |
513 | ||
514 | // Flags for DrawButton | |
515 | enum | |
516 | { | |
517 | Button_PaintBackground = 0x0001, // Paints control background below the button | |
518 | Button_BitmapOnly = 0x0002 // Only paints the bitmap | |
519 | }; | |
520 | ||
521 | // Draws dropbutton. Using wxRenderer or bitmaps, as appropriate. | |
522 | // Flags are defined above. | |
523 | virtual void DrawButton( wxDC& dc, const wxRect& rect, int flags = Button_PaintBackground ); | |
524 | ||
525 | // Call if cursor is on button area or mouse is captured for the button. | |
526 | //bool HandleButtonMouseEvent( wxMouseEvent& event, bool isInside ); | |
527 | bool HandleButtonMouseEvent( wxMouseEvent& event, int flags ); | |
528 | ||
529 | // returns true if event was consumed or filtered (event type is also set to 0 in this case) | |
530 | bool PreprocessMouseEvent( wxMouseEvent& event, int flags ); | |
531 | ||
532 | // | |
533 | // This will handle left_down and left_dclick events outside button in a Windows-like manner. | |
534 | // If you need alternate behaviour, it is recommended you manipulate and filter events to it | |
535 | // instead of building your own handling routine (for reference, on wxEVT_LEFT_DOWN it will | |
536 | // toggle popup and on wxEVT_LEFT_DCLICK it will do the same or run the popup's dclick method, | |
537 | // if defined - you should pass events of other types of it for common processing). | |
538 | void HandleNormalMouseEvent( wxMouseEvent& event ); | |
539 | ||
540 | // Creates popup window, calls interface->Create(), etc | |
541 | void CreatePopup(); | |
542 | ||
543 | // Destroy popup window and all related constructs | |
544 | void DestroyPopup(); | |
545 | ||
546 | // override the base class virtuals involved in geometry calculations | |
547 | // The common version only sets a default width, so the derived classes | |
548 | // should override it and set the height and change the width as needed. | |
549 | virtual wxSize DoGetBestSize() const; | |
550 | virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const; | |
551 | ||
552 | // NULL popup can be used to indicate default in a derived class | |
553 | virtual void DoSetPopupControl(wxComboPopup* popup); | |
554 | ||
555 | // ensures there is atleast the default popup | |
556 | void EnsurePopupControl(); | |
557 | ||
558 | // Recalculates button and textctrl areas. Called when size or button setup change. | |
559 | // btnWidth: default/calculated width of the dropbutton. 0 means unchanged, | |
560 | // just recalculate. | |
561 | void CalculateAreas( int btnWidth = 0 ); | |
562 | ||
563 | // Standard textctrl positioning routine. Just give it platform-dependant | |
564 | // textctrl coordinate adjustment. | |
565 | virtual void PositionTextCtrl( int textCtrlXAdjust = 0, | |
566 | int textCtrlYAdjust = 0); | |
567 | ||
568 | // event handlers | |
569 | void OnSizeEvent( wxSizeEvent& event ); | |
570 | void OnFocusEvent(wxFocusEvent& event); | |
571 | void OnIdleEvent(wxIdleEvent& event); | |
572 | void OnTextCtrlEvent(wxCommandEvent& event); | |
573 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
574 | void OnKeyEvent(wxKeyEvent& event); | |
575 | void OnCharEvent(wxKeyEvent& event); | |
576 | ||
577 | // Set customization flags (directs how wxComboCtrlBase helpers behave) | |
578 | void Customize( wxUint32 flags ) { m_iFlags |= flags; } | |
579 | ||
580 | // Dispatches size event and refreshes | |
581 | void RecalcAndRefresh(); | |
582 | ||
583 | // Flags for DoShowPopup and AnimateShow | |
584 | enum | |
585 | { | |
586 | ShowBelow = 0x0000, // Showing popup below the control | |
587 | ShowAbove = 0x0001, // Showing popup above the control | |
588 | CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set | |
589 | }; | |
590 | ||
591 | // Shows and positions the popup. | |
592 | virtual void DoShowPopup( const wxRect& rect, int flags ); | |
593 | ||
594 | // Implement in derived class to create a drop-down animation. | |
595 | // Return true if finished immediately. Otherwise popup is only | |
596 | // shown when the derived class call DoShowPopup. | |
597 | // Flags are same as for DoShowPopup. | |
598 | virtual bool AnimateShow( const wxRect& rect, int flags ); | |
599 | ||
600 | #if wxUSE_TOOLTIPS | |
601 | virtual void DoSetToolTip( wxToolTip *tip ); | |
602 | #endif | |
603 | ||
604 | // protected wxTextEntry methods | |
605 | virtual void DoSetValue(const wxString& value, int flags); | |
606 | virtual wxString DoGetValue() const; | |
607 | virtual wxWindow *GetEditableWindow() { return this; } | |
608 | ||
609 | // margins functions | |
610 | virtual bool DoSetMargins(const wxPoint& pt); | |
611 | virtual wxPoint DoGetMargins() const; | |
612 | ||
613 | // This is used when m_text is hidden (readonly). | |
614 | wxString m_valueString; | |
615 | ||
616 | // This is used when control is unfocused and m_valueString is empty | |
617 | wxString m_hintText; | |
618 | ||
619 | // the text control and button we show all the time | |
620 | wxTextCtrl* m_text; | |
621 | wxWindow* m_btn; | |
622 | ||
623 | // wxPopupWindow or similar containing the window managed by the interface. | |
624 | wxWindow* m_winPopup; | |
625 | ||
626 | // the popup control/panel | |
627 | wxWindow* m_popup; | |
628 | ||
629 | // popup interface | |
630 | wxComboPopup* m_popupInterface; | |
631 | ||
632 | // this is input etc. handler for the text control | |
633 | wxEvtHandler* m_textEvtHandler; | |
634 | ||
635 | // this is for the top level window | |
636 | wxEvtHandler* m_toplevEvtHandler; | |
637 | ||
638 | // this is for the control in popup | |
639 | wxEvtHandler* m_popupEvtHandler; | |
640 | ||
641 | // this is for the popup window | |
642 | wxEvtHandler* m_popupWinEvtHandler; | |
643 | ||
644 | // main (ie. topmost) window of a composite control (default = this) | |
645 | wxWindow* m_mainCtrlWnd; | |
646 | ||
647 | // used to prevent immediate re-popupping in case closed popup | |
648 | // by clicking on the combo control (needed because of inconsistent | |
649 | // transient implementation across platforms). | |
650 | wxLongLong m_timeCanAcceptClick; | |
651 | ||
652 | // how much popup should expand to the left/right of the control | |
653 | wxCoord m_extLeft; | |
654 | wxCoord m_extRight; | |
655 | ||
656 | // minimum popup width | |
657 | wxCoord m_widthMinPopup; | |
658 | ||
659 | // preferred popup height | |
660 | wxCoord m_heightPopup; | |
661 | ||
662 | // how much of writable combo is custom-paint by callback? | |
663 | // also used to indicate area that is not covered by "blue" | |
664 | // selection indicator. | |
665 | wxCoord m_widthCustomPaint; | |
666 | ||
667 | // left margin, in pixels | |
668 | wxCoord m_marginLeft; | |
669 | ||
670 | // side on which the popup is aligned | |
671 | int m_anchorSide; | |
672 | ||
673 | // Width of the "fake" border | |
674 | wxCoord m_widthCustomBorder; | |
675 | ||
676 | // The button and textctrl click/paint areas | |
677 | wxRect m_tcArea; | |
678 | wxRect m_btnArea; | |
679 | ||
680 | // Colour of the text area, in case m_text is NULL | |
681 | wxColour m_tcBgCol; | |
682 | ||
683 | // current button state (uses renderer flags) | |
684 | int m_btnState; | |
685 | ||
686 | // button position | |
687 | int m_btnWid; | |
688 | int m_btnHei; | |
689 | int m_btnSide; | |
690 | int m_btnSpacingX; | |
691 | ||
692 | // last default button width | |
693 | int m_btnWidDefault; | |
694 | ||
695 | // custom dropbutton bitmaps | |
696 | wxBitmap m_bmpNormal; | |
697 | wxBitmap m_bmpPressed; | |
698 | wxBitmap m_bmpHover; | |
699 | wxBitmap m_bmpDisabled; | |
700 | ||
701 | // area used by the button | |
702 | wxSize m_btnSize; | |
703 | ||
704 | // platform-dependant customization and other flags | |
705 | wxUint32 m_iFlags; | |
706 | ||
707 | // custom style for m_text | |
708 | int m_textCtrlStyle; | |
709 | ||
710 | // draw blank button background under bitmap? | |
711 | bool m_blankButtonBg; | |
712 | ||
713 | // is the popup window currenty shown? | |
714 | wxByte m_popupWinState; | |
715 | ||
716 | // should the focus be reset to the textctrl in idle time? | |
717 | bool m_resetFocus; | |
718 | ||
719 | // is the text-area background colour overridden? | |
720 | bool m_hasTcBgCol; | |
721 | ||
722 | private: | |
723 | void Init(); | |
724 | ||
725 | wxByte m_ignoreEvtText; // Number of next EVT_TEXTs to ignore | |
726 | ||
727 | // Is popup window wxPopupTransientWindow, wxPopupWindow or wxDialog? | |
728 | wxByte m_popupWinType; | |
729 | ||
730 | DECLARE_EVENT_TABLE() | |
731 | ||
732 | DECLARE_ABSTRACT_CLASS(wxComboCtrlBase) | |
733 | }; | |
734 | ||
735 | ||
736 | // ---------------------------------------------------------------------------- | |
737 | // wxComboPopup is the interface which must be implemented by a control to be | |
738 | // used as a popup by wxComboCtrl | |
739 | // ---------------------------------------------------------------------------- | |
740 | ||
741 | ||
742 | // wxComboPopup internal flags | |
743 | enum | |
744 | { | |
745 | wxCP_IFLAG_CREATED = 0x0001 // Set by wxComboCtrlBase after Create is called | |
746 | }; | |
747 | ||
748 | class WXDLLIMPEXP_FWD_CORE wxComboCtrl; | |
749 | ||
750 | ||
751 | class WXDLLIMPEXP_CORE wxComboPopup | |
752 | { | |
753 | friend class wxComboCtrlBase; | |
754 | public: | |
755 | wxComboPopup() | |
756 | { | |
757 | m_combo = NULL; | |
758 | m_iFlags = 0; | |
759 | } | |
760 | ||
761 | // This is called immediately after construction finishes. m_combo member | |
762 | // variable has been initialized before the call. | |
763 | // NOTE: It is not in constructor so the derived class doesn't need to redefine | |
764 | // a default constructor of its own. | |
765 | virtual void Init() { } | |
766 | ||
767 | virtual ~wxComboPopup(); | |
768 | ||
769 | // Create the popup child control. | |
770 | // Return true for success. | |
771 | virtual bool Create(wxWindow* parent) = 0; | |
772 | ||
773 | // Calls Destroy() for the popup control (i.e. one returned by | |
774 | // GetControl()) and makes sure that 'this' is deleted at the end. | |
775 | // Default implementation works for both cases where popup control | |
776 | // class is multiple inherited or created on heap as a separate | |
777 | // object. | |
778 | virtual void DestroyPopup(); | |
779 | ||
780 | // We must have an associated control which is subclassed by the combobox. | |
781 | virtual wxWindow *GetControl() = 0; | |
782 | ||
783 | // Called immediately after the popup is shown | |
784 | virtual void OnPopup(); | |
785 | ||
786 | // Called when popup is dismissed | |
787 | virtual void OnDismiss(); | |
788 | ||
789 | // Called just prior to displaying popup. | |
790 | // Default implementation does nothing. | |
791 | virtual void SetStringValue( const wxString& value ); | |
792 | ||
793 | // Gets displayed string representation of the value. | |
794 | virtual wxString GetStringValue() const = 0; | |
795 | ||
796 | // Called to check if the popup - when an item container - actually | |
797 | // has matching item. Case-sensitivity checking etc. is up to the | |
798 | // implementation. If the found item matched the string, but is | |
799 | // different, it should be written back to pItem. Default implementation | |
800 | // always return true and does not alter trueItem. | |
801 | virtual bool FindItem(const wxString& item, wxString* trueItem=NULL); | |
802 | ||
803 | // This is called to custom paint in the combo control itself (ie. not the popup). | |
804 | // Default implementation draws value as string. | |
805 | virtual void PaintComboControl( wxDC& dc, const wxRect& rect ); | |
806 | ||
807 | // Receives wxEVT_KEY_DOWN key events from the parent wxComboCtrl. | |
808 | // Events not handled should be skipped, as usual. | |
809 | virtual void OnComboKeyEvent( wxKeyEvent& event ); | |
810 | ||
811 | // Receives wxEVT_CHAR key events from the parent wxComboCtrl. | |
812 | // Events not handled should be skipped, as usual. | |
813 | virtual void OnComboCharEvent( wxKeyEvent& event ); | |
814 | ||
815 | // Implement if you need to support special action when user | |
816 | // double-clicks on the parent wxComboCtrl. | |
817 | virtual void OnComboDoubleClick(); | |
818 | ||
819 | // Return final size of popup. Called on every popup, just prior to OnShow. | |
820 | // minWidth = preferred minimum width for window | |
821 | // prefHeight = preferred height. Only applies if > 0, | |
822 | // maxHeight = max height for window, as limited by screen size | |
823 | // and should only be rounded down, if necessary. | |
824 | virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ); | |
825 | ||
826 | // Return true if you want delay call to Create until the popup is shown | |
827 | // for the first time. It is more efficient, but note that it is often | |
828 | // more convenient to have the control created immediately. | |
829 | // Default returns false. | |
830 | virtual bool LazyCreate(); | |
831 | ||
832 | // | |
833 | // Utilies | |
834 | // | |
835 | ||
836 | // Hides the popup | |
837 | void Dismiss(); | |
838 | ||
839 | // Returns true if Create has been called. | |
840 | bool IsCreated() const | |
841 | { | |
842 | return (m_iFlags & wxCP_IFLAG_CREATED) ? true : false; | |
843 | } | |
844 | ||
845 | // Returns pointer to the associated parent wxComboCtrl. | |
846 | wxComboCtrl* GetComboCtrl() const; | |
847 | ||
848 | // Default PaintComboControl behaviour | |
849 | static void DefaultPaintComboControl( wxComboCtrlBase* combo, | |
850 | wxDC& dc, | |
851 | const wxRect& rect ); | |
852 | ||
853 | protected: | |
854 | wxComboCtrlBase* m_combo; | |
855 | wxUint32 m_iFlags; | |
856 | ||
857 | private: | |
858 | // Called in wxComboCtrlBase::SetPopupControl | |
859 | void InitBase(wxComboCtrlBase *combo) | |
860 | { | |
861 | m_combo = combo; | |
862 | } | |
863 | }; | |
864 | ||
865 | ||
866 | // ---------------------------------------------------------------------------- | |
867 | // include the platform-dependent header defining the real class | |
868 | // ---------------------------------------------------------------------------- | |
869 | ||
870 | #if defined(__WXUNIVERSAL__) | |
871 | // No native universal (but it must still be first in the list) | |
872 | #elif defined(__WXMSW__) | |
873 | #include "wx/msw/combo.h" | |
874 | #endif | |
875 | ||
876 | // Any ports may need generic as an alternative | |
877 | #include "wx/generic/combo.h" | |
878 | ||
879 | #endif // wxUSE_COMBOCTRL | |
880 | ||
881 | #endif | |
882 | // _WX_COMBOCONTROL_H_BASE_ |