1 /////////////////////////////////////////////////////////////////////////////// 2 // Name: wx/qt/window.h 3 // Purpose: wxWindow class 4 // Author: Peter Most, Javier Torres, Mariano Reingart 5 // Copyright: (c) 2009 wxWidgets dev team 6 // Licence: wxWindows licence 7 /////////////////////////////////////////////////////////////////////////////// 8 9 #ifndef _WX_QT_WINDOW_H_ 10 #define _WX_QT_WINDOW_H_ 11 12 class QShortcut; 13 template < class T > class QList; 14 15 class QWidget; 16 class QScrollArea; 17 class QScrollBar; 18 class QPicture; 19 class QPainter; 20 21 class QPaintEvent; 22 class QResizeEvent; 23 class QWheelEvent; 24 class QKeyEvent; 25 class QMouseEvent; 26 class QEvent; 27 class QMoveEvent; 28 class QEvent; 29 class QEvent; 30 class QCloseEvent; 31 class QContextMenuEvent; 32 class QFocusEvent; 33 34 class WXDLLIMPEXP_FWD_CORE wxScrollBar; 35 class WXDLLIMPEXP_FWD_CORE wxQtShortcutHandler; 36 37 /* wxQt specific notes: 38 * 39 * Remember to implement the Qt object getters on all subclasses: 40 * - GetHandle() returns the Qt object 41 * - QtGetScrollBarsContainer() returns the widget where scrollbars are placed 42 * For example, for wxFrame, GetHandle() is the QMainWindow, 43 * QtGetScrollBarsContainer() is the central widget and QtGetContainer() is a widget 44 * in a layout inside the central widget that also contains the scrollbars. 45 * Return 0 from QtGetScrollBarsContainer() to disable SetScrollBar() and friends 46 * for wxWindow subclasses. 47 * 48 * 49 * Event handling is achieved by using the template class wxQtEventForwarder 50 * found in winevent_qt.(h|cpp) to send all Qt events here to QtHandleXXXEvent() 51 * methods. All these methods receive the Qt event and the handler. This is 52 * done because events of the containers (the scrolled part of the window) are 53 * sent to the same wxWindow instance, that must be able to differentiate them 54 * as some events need different handling (paintEvent) depending on that. 55 * We pass the QWidget pointer to all event handlers for consistency. 56 */ 57 class WXDLLIMPEXP_CORE wxWindowQt : public wxWindowBase 58 { 59 public: 60 wxWindowQt(); 61 ~wxWindowQt(); 62 wxWindowQt(wxWindowQt *parent, 63 wxWindowID id, 64 const wxPoint& pos = wxDefaultPosition, 65 const wxSize& size = wxDefaultSize, 66 long style = 0, 67 const wxString& name = wxASCII_STR(wxPanelNameStr)); 68 69 bool Create(wxWindowQt *parent, 70 wxWindowID id, 71 const wxPoint& pos = wxDefaultPosition, 72 const wxSize& size = wxDefaultSize, 73 long style = 0, 74 const wxString& name = wxASCII_STR(wxPanelNameStr)); 75 76 // Used by all window classes in the widget creation process. 77 void PostCreation( bool generic = true ); 78 79 void AddChild( wxWindowBase *child ) wxOVERRIDE; 80 81 virtual bool Show( bool show = true ) wxOVERRIDE; 82 83 virtual void SetLabel(const wxString& label) wxOVERRIDE; 84 virtual wxString GetLabel() const wxOVERRIDE; 85 86 virtual void DoEnable( bool enable ) wxOVERRIDE; 87 virtual void SetFocus() wxOVERRIDE; 88 89 // Parent/Child: 90 static void QtReparent( QWidget *child, QWidget *parent ); 91 virtual bool Reparent( wxWindowBase *newParent ) wxOVERRIDE; 92 93 // Z-order 94 virtual void Raise() wxOVERRIDE; 95 virtual void Lower() wxOVERRIDE; 96 97 // move the mouse to the specified position 98 virtual void WarpPointer(int x, int y) wxOVERRIDE; 99 100 virtual void Update() wxOVERRIDE; 101 virtual void Refresh( bool eraseBackground = true, 102 const wxRect *rect = (const wxRect *) NULL ) wxOVERRIDE; 103 104 virtual bool SetCursor( const wxCursor &cursor ) wxOVERRIDE; 105 virtual bool SetFont(const wxFont& font) wxOVERRIDE; 106 107 // get the (average) character size for the current font 108 virtual int GetCharHeight() const wxOVERRIDE; 109 virtual int GetCharWidth() const wxOVERRIDE; 110 111 virtual void SetScrollbar( int orient, 112 int pos, 113 int thumbvisible, 114 int range, 115 bool refresh = true ) wxOVERRIDE; 116 virtual void SetScrollPos( int orient, int pos, bool refresh = true ) wxOVERRIDE; 117 virtual int GetScrollPos( int orient ) const wxOVERRIDE; 118 virtual int GetScrollThumb( int orient ) const wxOVERRIDE; 119 virtual int GetScrollRange( int orient ) const wxOVERRIDE; 120 121 // scroll window to the specified position 122 virtual void ScrollWindow( int dx, int dy, 123 const wxRect* rect = NULL ) wxOVERRIDE; 124 125 // Styles 126 virtual void SetWindowStyleFlag( long style ) wxOVERRIDE; 127 virtual void SetExtraStyle( long exStyle ) wxOVERRIDE; 128 129 virtual bool SetBackgroundStyle(wxBackgroundStyle style) wxOVERRIDE; 130 virtual bool IsTransparentBackgroundSupported(wxString* reason = NULL) const wxOVERRIDE; 131 virtual bool SetTransparent(wxByte alpha) wxOVERRIDE; CanSetTransparent()132 virtual bool CanSetTransparent() wxOVERRIDE { return true; } 133 134 virtual bool SetBackgroundColour(const wxColour& colour) wxOVERRIDE; 135 virtual bool SetForegroundColour(const wxColour& colour) wxOVERRIDE; 136 137 QWidget *GetHandle() const wxOVERRIDE; 138 139 #if wxUSE_DRAG_AND_DROP 140 virtual void SetDropTarget( wxDropTarget *dropTarget ) wxOVERRIDE; 141 #endif 142 143 #if wxUSE_ACCEL 144 // accelerators 145 // ------------ 146 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel ) wxOVERRIDE; 147 #endif // wxUSE_ACCEL 148 149 // wxQt implementation internals: 150 151 // Caller maintains ownership of pict - window will NOT delete it 152 void QtSetPicture( QPicture* pict ); 153 154 QPainter *QtGetPainter(); 155 156 virtual bool QtHandlePaintEvent ( QWidget *handler, QPaintEvent *event ); 157 virtual bool QtHandleResizeEvent ( QWidget *handler, QResizeEvent *event ); 158 virtual bool QtHandleWheelEvent ( QWidget *handler, QWheelEvent *event ); 159 virtual bool QtHandleKeyEvent ( QWidget *handler, QKeyEvent *event ); 160 virtual bool QtHandleMouseEvent ( QWidget *handler, QMouseEvent *event ); 161 virtual bool QtHandleEnterEvent ( QWidget *handler, QEvent *event ); 162 virtual bool QtHandleMoveEvent ( QWidget *handler, QMoveEvent *event ); 163 virtual bool QtHandleShowEvent ( QWidget *handler, QEvent *event ); 164 virtual bool QtHandleChangeEvent ( QWidget *handler, QEvent *event ); 165 virtual bool QtHandleCloseEvent ( QWidget *handler, QCloseEvent *event ); 166 virtual bool QtHandleContextMenuEvent ( QWidget *handler, QContextMenuEvent *event ); 167 virtual bool QtHandleFocusEvent ( QWidget *handler, QFocusEvent *event ); 168 169 static void QtStoreWindowPointer( QWidget *widget, const wxWindowQt *window ); 170 static wxWindowQt *QtRetrieveWindowPointer( const QWidget *widget ); 171 static void QtSendSetCursorEvent(wxWindowQt* win, wxPoint posClient); 172 173 #if wxUSE_ACCEL 174 virtual void QtHandleShortcut ( int command ); 175 #endif // wxUSE_ACCEL 176 177 virtual QScrollArea *QtGetScrollBarsContainer() const; 178 179 #if wxUSE_TOOLTIPS 180 // applies tooltip to the widget. 181 virtual void QtApplyToolTip(const wxString& text); 182 #endif // wxUSE_TOOLTIPS 183 184 protected: 185 virtual void DoGetTextExtent(const wxString& string, 186 int *x, int *y, 187 int *descent = NULL, 188 int *externalLeading = NULL, 189 const wxFont *font = NULL) const wxOVERRIDE; 190 191 // coordinates translation 192 virtual void DoClientToScreen( int *x, int *y ) const wxOVERRIDE; 193 virtual void DoScreenToClient( int *x, int *y ) const wxOVERRIDE; 194 195 // capture/release the mouse, used by Capture/ReleaseMouse() 196 virtual void DoCaptureMouse() wxOVERRIDE; 197 virtual void DoReleaseMouse() wxOVERRIDE; 198 199 // retrieve the position/size of the window 200 virtual void DoGetPosition(int *x, int *y) const wxOVERRIDE; 201 202 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO) wxOVERRIDE; 203 virtual void DoGetSize(int *width, int *height) const wxOVERRIDE; 204 205 // same as DoSetSize() for the client size 206 virtual void DoSetClientSize(int width, int height) wxOVERRIDE; 207 virtual void DoGetClientSize(int *width, int *height) const wxOVERRIDE; 208 209 virtual void DoMoveWindow(int x, int y, int width, int height) wxOVERRIDE; 210 211 #if wxUSE_TOOLTIPS 212 virtual void DoSetToolTip( wxToolTip *tip ) wxOVERRIDE; 213 #endif // wxUSE_TOOLTIPS 214 215 #if wxUSE_MENUS 216 virtual bool DoPopupMenu(wxMenu *menu, int x, int y) wxOVERRIDE; 217 #endif // wxUSE_MENUS 218 219 // Return the parent to use for children being reparented to us: this is 220 // overridden in wxFrame to use its central widget rather than the frame 221 // itself. QtGetParentWidget()222 virtual QWidget* QtGetParentWidget() const { return GetHandle(); } 223 224 virtual bool EnableTouchEvents(int eventsMask) wxOVERRIDE; 225 226 QWidget *m_qtWindow; 227 228 private: 229 void Init(); 230 QScrollArea *m_qtContainer; // either NULL or the same as m_qtWindow pointer 231 232 QScrollBar *m_horzScrollBar; // owned by m_qtWindow when allocated 233 QScrollBar *m_vertScrollBar; // owned by m_qtWindow when allocated 234 235 // Return the viewport of m_qtContainer, if it's used, or just m_qtWindow. 236 // 237 // Always returns non-null pointer if the window has been already created. 238 QWidget *QtGetClientWidget() const; 239 240 QScrollBar *QtGetScrollBar( int orientation ) const; 241 QScrollBar *QtSetScrollBar( int orientation, QScrollBar *scrollBar=NULL ); 242 243 bool QtSetBackgroundStyle(); 244 245 QPicture *m_qtPicture; // not owned 246 wxScopedPtr<QPainter> m_qtPainter; // always allocated 247 248 bool m_mouseInside; 249 250 #if wxUSE_ACCEL 251 wxVector<QShortcut*> m_qtShortcuts; // owned by whatever GetHandle() returns 252 wxScopedPtr<wxQtShortcutHandler> m_qtShortcutHandler; // always allocated 253 bool m_processingShortcut; 254 #endif // wxUSE_ACCEL 255 256 wxDECLARE_DYNAMIC_CLASS_NO_COPY( wxWindowQt ); 257 }; 258 259 #endif // _WX_QT_WINDOW_H_ 260