1 /////////////////////////////////////////////////////////////////////////////// 2 // Name: wx/popupwin.h 3 // Purpose: wxPopupWindow interface declaration 4 // Author: Vadim Zeitlin 5 // Modified by: 6 // Created: 06.01.01 7 // RCS-ID: $Id: popupwin.h 53135 2008-04-12 02:31:04Z VZ $ 8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> 9 // License: wxWindows licence 10 /////////////////////////////////////////////////////////////////////////////// 11 12 #ifndef _WX_POPUPWIN_H_BASE_ 13 #define _WX_POPUPWIN_H_BASE_ 14 15 #include "wx/defs.h" 16 17 #if wxUSE_POPUPWIN 18 19 #include "wx/window.h" 20 21 // ---------------------------------------------------------------------------- 22 // wxPopupWindow: a special kind of top level window used for popup menus, 23 // combobox popups and such. 24 // ---------------------------------------------------------------------------- 25 26 class WXDLLEXPORT wxPopupWindowBase : public wxWindow 27 { 28 public: wxPopupWindowBase()29 wxPopupWindowBase() { } 30 virtual ~wxPopupWindowBase(); 31 32 // create the popup window 33 // 34 // style may only contain border flags 35 bool Create(wxWindow *parent, int style = wxBORDER_NONE); 36 37 // move the popup window to the right position, i.e. such that it is 38 // entirely visible 39 // 40 // the popup is positioned at ptOrigin + size if it opens below and to the 41 // right (default), at ptOrigin - sizePopup if it opens above and to the 42 // left &c 43 // 44 // the point must be given in screen coordinates! 45 virtual void Position(const wxPoint& ptOrigin, 46 const wxSize& size); 47 IsTopLevel()48 virtual bool IsTopLevel() const { return true; } 49 50 DECLARE_NO_COPY_CLASS(wxPopupWindowBase) 51 }; 52 53 54 // include the real class declaration 55 #if defined(__WXMSW__) 56 #include "wx/msw/popupwin.h" 57 #elif defined(__WXPM__) 58 #include "wx/os2/popupwin.h" 59 #elif defined(__WXGTK20__) 60 #include "wx/gtk/popupwin.h" 61 #elif defined(__WXGTK__) 62 #include "wx/gtk1/popupwin.h" 63 #elif defined(__WXX11__) 64 #include "wx/x11/popupwin.h" 65 #elif defined(__WXMOTIF__) 66 #include "wx/motif/popupwin.h" 67 #elif defined(__WXMGL__) 68 #include "wx/mgl/popupwin.h" 69 #elif defined(__WXMAC__) 70 #include "wx/mac/popupwin.h" 71 #else 72 #error "wxPopupWindow is not supported under this platform." 73 #endif 74 75 // ---------------------------------------------------------------------------- 76 // wxPopupTransientWindow: a wxPopupWindow which disappears automatically 77 // when the user clicks mouse outside it or if it loses focus in any other way 78 // ---------------------------------------------------------------------------- 79 80 class WXDLLIMPEXP_FWD_CORE wxPopupWindowHandler; 81 class WXDLLIMPEXP_FWD_CORE wxPopupFocusHandler; 82 83 class WXDLLEXPORT wxPopupTransientWindow : public wxPopupWindow 84 { 85 public: 86 // ctors wxPopupTransientWindow()87 wxPopupTransientWindow() { Init(); } 88 wxPopupTransientWindow(wxWindow *parent, int style = wxBORDER_NONE); 89 90 virtual ~wxPopupTransientWindow(); 91 92 // popup the window (this will show it too) and keep focus at winFocus 93 // (or itself if it's NULL), dismiss the popup if we lose focus 94 virtual void Popup(wxWindow *focus = NULL); 95 96 // hide the window 97 virtual void Dismiss(); 98 99 // can the window be dismissed now? 100 // 101 // VZ: where is this used?? CanDismiss()102 virtual bool CanDismiss() 103 { return true; } 104 105 // called when a mouse is pressed while the popup is shown: return true 106 // from here to prevent its normal processing by the popup (which consists 107 // in dismissing it if the mouse is cilcked outside it) 108 virtual bool ProcessLeftDown(wxMouseEvent& event); 109 110 // Overridden to grab the input on some plaforms 111 virtual bool Show( bool show = true ); 112 113 protected: 114 // common part of all ctors 115 void Init(); 116 117 // this is called when the popup is disappeared because of anything 118 // else but direct call to Dismiss() 119 virtual void OnDismiss(); 120 121 // dismiss and notify the derived class 122 void DismissAndNotify(); 123 124 // remove our event handlers 125 void PopHandlers(); 126 127 // get alerted when child gets deleted from under us 128 void OnDestroy(wxWindowDestroyEvent& event); 129 130 #if defined( __WXMSW__ ) || defined( __WXMAC__ ) 131 // check if the mouse needs captured or released 132 void OnIdle(wxIdleEvent& event); 133 #endif 134 135 // the child of this popup if any 136 wxWindow *m_child; 137 138 // the window which has the focus while we're shown 139 wxWindow *m_focus; 140 141 // these classes may call our DismissAndNotify() 142 friend class wxPopupWindowHandler; 143 friend class wxPopupFocusHandler; 144 145 // the handlers we created, may be NULL (if not, must be deleted) 146 wxPopupWindowHandler *m_handlerPopup; 147 wxPopupFocusHandler *m_handlerFocus; 148 149 DECLARE_EVENT_TABLE() 150 DECLARE_DYNAMIC_CLASS(wxPopupTransientWindow) 151 DECLARE_NO_COPY_CLASS(wxPopupTransientWindow) 152 }; 153 154 #if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__) 155 156 // ---------------------------------------------------------------------------- 157 // wxPopupComboWindow: wxPopupTransientWindow used by wxComboBox 158 // ---------------------------------------------------------------------------- 159 160 class WXDLLEXPORT wxComboBox; 161 class WXDLLEXPORT wxComboCtrl; 162 163 class WXDLLEXPORT wxPopupComboWindow : public wxPopupTransientWindow 164 { 165 public: wxPopupComboWindow()166 wxPopupComboWindow() { m_combo = NULL; } 167 wxPopupComboWindow(wxComboCtrl *parent); 168 169 bool Create(wxComboCtrl *parent); 170 171 // position the window correctly relatively to the combo 172 void PositionNearCombo(); 173 174 protected: 175 // notify the combo here 176 virtual void OnDismiss(); 177 178 // forward the key presses to the combobox 179 void OnKeyDown(wxKeyEvent& event); 180 181 // the parent combobox 182 wxComboCtrl *m_combo; 183 184 DECLARE_EVENT_TABLE() 185 DECLARE_DYNAMIC_CLASS(wxPopupComboWindow) 186 }; 187 188 #endif // wxUSE_COMBOBOX && defined(__WXUNIVERSAL__) 189 190 #endif // wxUSE_POPUPWIN 191 192 #endif // _WX_POPUPWIN_H_BASE_ 193