popupwin.h 5.9 KB

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