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