1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/topluniv.cpp
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
24 #include "wx/toplevel.h"
27 #include "wx/dcclient.h"
28 #include "wx/settings.h"
29 #include "wx/bitmap.h"
34 #include "wx/univ/renderer.h"
35 #include "wx/cshelp.h"
36 #include "wx/evtloop.h"
38 // ----------------------------------------------------------------------------
39 // wxStdTLWInputHandler: handles focus, resizing and titlebar buttons clicks
40 // ----------------------------------------------------------------------------
42 class WXDLLEXPORT wxStdTLWInputHandler
: public wxStdInputHandler
45 wxStdTLWInputHandler(wxInputHandler
*inphand
);
47 virtual bool HandleMouse(wxInputConsumer
*consumer
,
48 const wxMouseEvent
& event
);
49 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
);
50 virtual bool HandleActivation(wxInputConsumer
*consumer
, bool activated
);
53 // the window (button) which has capture or NULL and the last hittest result
54 wxTopLevelWindow
*m_winCapture
;
57 bool m_borderCursorOn
;
58 wxCursor m_origCursor
;
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 BEGIN_EVENT_TABLE(wxTopLevelWindow
, wxTopLevelWindowNative
)
67 WX_EVENT_TABLE_INPUT_CONSUMER(wxTopLevelWindow
)
68 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint
)
69 EVT_MENU_RANGE(wxID_CLOSE_FRAME
, wxID_RESTORE_FRAME
, wxTopLevelWindow::OnSystemMenu
)
72 WX_FORWARD_TO_INPUT_CONSUMER(wxTopLevelWindow
)
74 // ============================================================================
76 // ============================================================================
78 int wxTopLevelWindow::ms_drawDecorations
= -1;
79 int wxTopLevelWindow::ms_canIconize
= -1;
81 void wxTopLevelWindow::Init()
83 // once-only ms_drawDecorations initialization
84 if ( ms_drawDecorations
== -1 )
87 !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS
) ||
88 wxGetEnv(wxT("WXDECOR"), NULL
);
91 m_usingNativeDecorations
= ms_drawDecorations
== 0;
97 bool wxTopLevelWindow::Create(wxWindow
*parent
,
99 const wxString
& title
,
103 const wxString
&name
)
105 // init them to avoid compiler warnings
109 if ( !m_usingNativeDecorations
)
111 CreateInputHandler(wxINP_HANDLER_TOPLEVEL
);
114 exstyleOrig
= GetExtraStyle();
115 style
&= ~(wxCAPTION
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
116 wxSYSTEM_MENU
| wxRESIZE_BORDER
| wxFRAME_TOOL_WINDOW
|
118 style
|= wxBORDER_NONE
;
119 SetExtraStyle(exstyleOrig
& ~wxWS_EX_CONTEXTHELP
);
122 if ( !wxTopLevelWindowNative::Create(parent
, id
, title
, pos
,
126 if ( !m_usingNativeDecorations
)
128 m_windowStyle
= styleOrig
;
129 m_exStyle
= exstyleOrig
;
135 bool wxTopLevelWindow::ShowFullScreen(bool show
, long style
)
137 if ( show
== IsFullScreen() ) return false;
139 if ( !m_usingNativeDecorations
)
143 m_fsSavedStyle
= m_windowStyle
;
144 if ( style
& wxFULLSCREEN_NOBORDER
)
145 m_windowStyle
|= wxSIMPLE_BORDER
;
146 if ( style
& wxFULLSCREEN_NOCAPTION
)
147 m_windowStyle
&= ~wxCAPTION
;
151 m_windowStyle
= m_fsSavedStyle
;
155 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
159 void wxTopLevelWindow::UseNativeDecorationsByDefault(bool native
)
161 ms_drawDecorations
= !native
;
164 void wxTopLevelWindow::UseNativeDecorations(bool native
)
166 wxASSERT_MSG( !m_windowStyle
, wxT("must be called before Create()") );
168 m_usingNativeDecorations
= native
;
171 bool wxTopLevelWindow::IsUsingNativeDecorations() const
173 return m_usingNativeDecorations
;
176 long wxTopLevelWindow::GetDecorationsStyle() const
180 if ( m_windowStyle
& wxCAPTION
)
182 if ( ms_canIconize
== -1 )
184 ms_canIconize
= wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME
);
187 style
|= wxTOPLEVEL_TITLEBAR
;
188 if ( m_windowStyle
& wxCLOSE_BOX
)
189 style
|= wxTOPLEVEL_BUTTON_CLOSE
;
190 if ( (m_windowStyle
& wxMINIMIZE_BOX
) && ms_canIconize
)
191 style
|= wxTOPLEVEL_BUTTON_ICONIZE
;
192 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
195 style
|= wxTOPLEVEL_BUTTON_RESTORE
;
197 style
|= wxTOPLEVEL_BUTTON_MAXIMIZE
;
200 if ( m_exStyle
& wxWS_EX_CONTEXTHELP
)
201 style
|= wxTOPLEVEL_BUTTON_HELP
;
204 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
205 style
|= wxTOPLEVEL_BORDER
;
206 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxRESIZE_BORDER
) )
207 style
|= wxTOPLEVEL_RESIZEABLE
;
210 style
|= wxTOPLEVEL_MAXIMIZED
;
211 if ( GetIcon().Ok() )
212 style
|= wxTOPLEVEL_ICON
;
214 style
|= wxTOPLEVEL_ACTIVE
;
219 void wxTopLevelWindow::RefreshTitleBar()
221 wxNcPaintEvent
event(GetId());
222 event
.SetEventObject(this);
223 GetEventHandler()->ProcessEvent(event
);
226 // ----------------------------------------------------------------------------
227 // client area handling
228 // ----------------------------------------------------------------------------
230 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
232 if ( !m_usingNativeDecorations
)
235 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
236 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
238 rect
= m_renderer
->GetFrameClientArea(rect
,
239 GetDecorationsStyle());
240 return rect
.GetPosition();
244 return wxTopLevelWindowNative::GetClientAreaOrigin();
248 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
250 if ( !m_usingNativeDecorations
)
253 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
254 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
256 rect
= m_renderer
->GetFrameClientArea(rect
,
257 GetDecorationsStyle());
261 *height
= rect
.height
;
264 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
267 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
269 if ( !m_usingNativeDecorations
)
271 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
272 GetDecorationsStyle());
273 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
276 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
279 void wxTopLevelWindow::OnNcPaint(wxNcPaintEvent
& event
)
281 if ( m_usingNativeDecorations
|| !m_renderer
)
285 else // we're drawing the decorations ourselves
287 // get the window rect
288 wxRect
rect(GetSize());
291 m_renderer
->DrawFrameTitleBar(dc
, rect
,
292 GetTitle(), m_titlebarIcon
,
293 GetDecorationsStyle(),
299 long wxTopLevelWindow::HitTest(const wxPoint
& pt
) const
302 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
303 wxRect
rect(wxTopLevelWindowNative::GetClientAreaOrigin(), wxSize(w
, h
));
305 return m_renderer
->HitTestFrame(rect
, pt
+GetClientAreaOrigin(), GetDecorationsStyle());
308 wxSize
wxTopLevelWindow::GetMinSize() const
310 wxSize size
= wxTopLevelWindowNative::GetMinSize();
311 if ( !m_usingNativeDecorations
)
313 size
.IncTo(m_renderer
->GetFrameMinSize(GetDecorationsStyle()));
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 void wxTopLevelWindow::SetIcons(const wxIconBundle
& icons
)
325 wxTopLevelWindowNative::SetIcons(icons
);
327 if ( !m_usingNativeDecorations
&& m_renderer
)
329 wxSize size
= m_renderer
->GetFrameIconSize();
330 const wxIcon
& icon
= icons
.GetIcon( size
);
332 if ( !icon
.Ok() || size
.x
== wxDefaultCoord
)
333 m_titlebarIcon
= icon
;
337 bmp1
.CopyFromIcon(icon
);
339 m_titlebarIcon
= wxNullIcon
;
340 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
341 m_titlebarIcon
= icon
;
345 wxImage img
= bmp1
.ConvertToImage();
346 img
.Rescale(size
.x
, size
.y
);
347 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));
349 #endif // wxUSE_IMAGE
354 // ----------------------------------------------------------------------------
355 // interactive manipulation
356 // ----------------------------------------------------------------------------
359 static bool wxGetResizingCursor(long hitTestResult
, wxCursor
& cursor
)
361 if ( hitTestResult
& wxHT_TOPLEVEL_ANY_BORDER
)
363 switch (hitTestResult
)
365 case wxHT_TOPLEVEL_BORDER_N
:
366 case wxHT_TOPLEVEL_BORDER_S
:
367 cursor
= wxCursor(wxCURSOR_SIZENS
);
369 case wxHT_TOPLEVEL_BORDER_W
:
370 case wxHT_TOPLEVEL_BORDER_E
:
371 cursor
= wxCursor(wxCURSOR_SIZEWE
);
373 case wxHT_TOPLEVEL_BORDER_NE
:
374 case wxHT_TOPLEVEL_BORDER_SW
:
375 cursor
= wxCursor(wxCURSOR_SIZENESW
);
377 case wxHT_TOPLEVEL_BORDER_NW
:
378 case wxHT_TOPLEVEL_BORDER_SE
:
379 cursor
= wxCursor(wxCURSOR_SIZENWSE
);
390 #define wxINTERACTIVE_RESIZE_DIR \
391 (wxINTERACTIVE_RESIZE_W | wxINTERACTIVE_RESIZE_E | \
392 wxINTERACTIVE_RESIZE_S | wxINTERACTIVE_RESIZE_N)
394 struct wxInteractiveMoveData
396 wxTopLevelWindow
*m_window
;
397 wxEventLoop
*m_evtLoop
;
402 wxSize m_minSize
, m_maxSize
;
406 class wxInteractiveMoveHandler
: public wxEvtHandler
409 wxInteractiveMoveHandler(wxInteractiveMoveData
& data
) : m_data(data
) {}
412 DECLARE_EVENT_TABLE()
413 void OnMouseMove(wxMouseEvent
& event
);
414 void OnMouseDown(wxMouseEvent
& event
);
415 void OnMouseUp(wxMouseEvent
& event
);
416 void OnKeyDown(wxKeyEvent
& event
);
418 wxInteractiveMoveData
& m_data
;
421 BEGIN_EVENT_TABLE(wxInteractiveMoveHandler
, wxEvtHandler
)
422 EVT_MOTION(wxInteractiveMoveHandler::OnMouseMove
)
423 EVT_LEFT_DOWN(wxInteractiveMoveHandler::OnMouseDown
)
424 EVT_LEFT_UP(wxInteractiveMoveHandler::OnMouseUp
)
425 EVT_KEY_DOWN(wxInteractiveMoveHandler::OnKeyDown
)
429 static inline LINKAGEMODE
430 void wxApplyResize(wxInteractiveMoveData
& data
, const wxPoint
& diff
)
432 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
434 data
.m_rect
.x
+= diff
.x
;
435 data
.m_rect
.width
-= diff
.x
;
437 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
439 data
.m_rect
.width
+= diff
.x
;
441 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
443 data
.m_rect
.y
+= diff
.y
;
444 data
.m_rect
.height
-= diff
.y
;
446 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
448 data
.m_rect
.height
+= diff
.y
;
451 if ( data
.m_minSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
< data
.m_minSize
.x
)
453 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
454 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
455 data
.m_rect
.width
= data
.m_minSize
.x
;
457 if ( data
.m_maxSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
> data
.m_maxSize
.x
)
459 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
460 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
461 data
.m_rect
.width
= data
.m_maxSize
.x
;
463 if ( data
.m_minSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
< data
.m_minSize
.y
)
465 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
466 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
467 data
.m_rect
.height
= data
.m_minSize
.y
;
469 if ( data
.m_maxSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
> data
.m_maxSize
.y
)
471 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
472 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
473 data
.m_rect
.height
= data
.m_maxSize
.y
;
477 void wxInteractiveMoveHandler::OnMouseMove(wxMouseEvent
& event
)
479 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
482 else if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
484 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
485 m_data
.m_rect
= m_data
.m_rectOrig
;
486 m_data
.m_rect
.Offset(diff
);
487 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
490 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE
)
492 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
493 m_data
.m_rect
= m_data
.m_rectOrig
;
494 wxApplyResize(m_data
, diff
);
495 m_data
.m_window
->SetSize(m_data
.m_rect
);
499 void wxInteractiveMoveHandler::OnMouseDown(wxMouseEvent
& WXUNUSED(event
))
501 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
503 m_data
.m_evtLoop
->Exit();
507 void wxInteractiveMoveHandler::OnKeyDown(wxKeyEvent
& event
)
509 wxPoint
diff(wxDefaultCoord
,wxDefaultCoord
);
511 switch ( event
.GetKeyCode() )
513 case WXK_UP
: diff
= wxPoint(0, -16); break;
514 case WXK_DOWN
: diff
= wxPoint(0, 16); break;
515 case WXK_LEFT
: diff
= wxPoint(-16, 0); break;
516 case WXK_RIGHT
: diff
= wxPoint(16, 0); break;
518 m_data
.m_window
->SetSize(m_data
.m_rectOrig
);
519 m_data
.m_evtLoop
->Exit();
522 m_data
.m_evtLoop
->Exit();
526 if ( diff
.x
!= wxDefaultCoord
)
528 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
530 m_data
.m_flags
&= ~wxINTERACTIVE_WAIT_FOR_INPUT
;
531 if ( m_data
.m_sizingCursor
)
534 m_data
.m_sizingCursor
= false;
537 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
539 m_data
.m_pos
= m_data
.m_window
->GetPosition() +
540 wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
545 bool changeCur
= false;
547 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
549 m_data
.m_rect
.Offset(diff
);
550 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
551 warp
= wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
553 else /* wxINTERACTIVE_RESIZE */
555 if ( !(m_data
.m_flags
&
556 (wxINTERACTIVE_RESIZE_N
| wxINTERACTIVE_RESIZE_S
)) )
560 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_N
;
561 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
;
564 else if ( diff
.y
> 0 )
566 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_S
;
567 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
+
568 m_data
.m_window
->GetSize().y
;
572 if ( !(m_data
.m_flags
&
573 (wxINTERACTIVE_RESIZE_W
| wxINTERACTIVE_RESIZE_E
)) )
577 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_W
;
578 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
;
581 else if ( diff
.x
> 0 )
583 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_E
;
584 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
+
585 m_data
.m_window
->GetSize().x
;
590 wxApplyResize(m_data
, diff
);
591 m_data
.m_window
->SetSize(m_data
.m_rect
);
593 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
595 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
596 warp
.x
= m_data
.m_window
->GetSize().x
-1;
598 warp
.x
= wxGetMousePosition().x
- m_data
.m_window
->GetPosition().x
;
600 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
602 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
603 warp
.y
= m_data
.m_window
->GetSize().y
-1;
605 warp
.y
= wxGetMousePosition().y
- m_data
.m_window
->GetPosition().y
;
608 warp
-= m_data
.m_window
->GetClientAreaOrigin();
609 m_data
.m_window
->WarpPointer(warp
.x
, warp
.y
);
613 long hit
= m_data
.m_window
->HitTest(warp
);
615 if ( wxGetResizingCursor(hit
, cur
) )
617 if ( m_data
.m_sizingCursor
)
619 wxBeginBusyCursor(&cur
);
620 m_data
.m_sizingCursor
= true;
626 void wxInteractiveMoveHandler::OnMouseUp(wxMouseEvent
& WXUNUSED(event
))
628 m_data
.m_evtLoop
->Exit();
632 void wxTopLevelWindow::InteractiveMove(int flags
)
634 wxASSERT_MSG( !((flags
& wxINTERACTIVE_MOVE
) && (flags
& wxINTERACTIVE_RESIZE
)),
635 wxT("can't move and resize window at the same time") );
637 wxASSERT_MSG( !(flags
& wxINTERACTIVE_RESIZE
) ||
638 (flags
& wxINTERACTIVE_WAIT_FOR_INPUT
) ||
639 (flags
& wxINTERACTIVE_RESIZE_DIR
),
640 wxT("direction of resizing not specified") );
642 wxInteractiveMoveData data
;
648 if ( flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
650 wxCursor
sizingCursor(wxCURSOR_SIZING
);
651 wxBeginBusyCursor(&sizingCursor
);
652 data
.m_sizingCursor
= true;
656 data
.m_sizingCursor
= false;
658 data
.m_window
= this;
659 data
.m_evtLoop
= &loop
;
660 data
.m_flags
= flags
;
661 data
.m_rect
= data
.m_rectOrig
= GetRect();
662 data
.m_pos
= wxGetMousePosition();
663 data
.m_minSize
= wxSize(GetMinWidth(), GetMinHeight());
664 data
.m_maxSize
= wxSize(GetMaxWidth(), GetMaxHeight());
666 wxEvtHandler
*handler
= new wxInteractiveMoveHandler(data
);
667 this->PushEventHandler(handler
);
673 this->RemoveEventHandler(handler
);
676 if ( data
.m_sizingCursor
)
680 // ----------------------------------------------------------------------------
682 // ----------------------------------------------------------------------------
684 void wxTopLevelWindow::ClickTitleBarButton(long button
)
688 case wxTOPLEVEL_BUTTON_CLOSE
:
692 case wxTOPLEVEL_BUTTON_ICONIZE
:
696 case wxTOPLEVEL_BUTTON_MAXIMIZE
:
700 case wxTOPLEVEL_BUTTON_RESTORE
:
704 case wxTOPLEVEL_BUTTON_HELP
:
707 wxContextHelp
contextHelp(this);
713 wxFAIL_MSG(wxT("incorrect button specification"));
717 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
719 const wxString
& WXUNUSED(strArg
))
721 bool isActive
= numArg
!= 0;
723 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
725 if ( m_isActive
!= isActive
)
727 m_isActive
= isActive
;
733 else if ( action
== wxACTION_TOPLEVEL_BUTTON_PRESS
)
735 m_pressedButton
= numArg
;
740 else if ( action
== wxACTION_TOPLEVEL_BUTTON_RELEASE
)
747 else if ( action
== wxACTION_TOPLEVEL_BUTTON_CLICK
)
751 ClickTitleBarButton(numArg
);
755 else if ( action
== wxACTION_TOPLEVEL_MOVE
)
757 InteractiveMove(wxINTERACTIVE_MOVE
);
761 else if ( action
== wxACTION_TOPLEVEL_RESIZE
)
763 int flags
= wxINTERACTIVE_RESIZE
;
764 if ( numArg
& wxHT_TOPLEVEL_BORDER_N
)
765 flags
|= wxINTERACTIVE_RESIZE_N
;
766 if ( numArg
& wxHT_TOPLEVEL_BORDER_S
)
767 flags
|= wxINTERACTIVE_RESIZE_S
;
768 if ( numArg
& wxHT_TOPLEVEL_BORDER_W
)
769 flags
|= wxINTERACTIVE_RESIZE_W
;
770 if ( numArg
& wxHT_TOPLEVEL_BORDER_E
)
771 flags
|= wxINTERACTIVE_RESIZE_E
;
772 InteractiveMove(flags
);
780 void wxTopLevelWindow::OnSystemMenu(wxCommandEvent
& event
)
784 switch (event
.GetId())
786 case wxID_CLOSE_FRAME
:
787 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
788 wxTOPLEVEL_BUTTON_CLOSE
);
790 case wxID_MOVE_FRAME
:
791 InteractiveMove(wxINTERACTIVE_MOVE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
793 case wxID_RESIZE_FRAME
:
794 InteractiveMove(wxINTERACTIVE_RESIZE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
796 case wxID_MAXIMIZE_FRAME
:
797 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
798 wxTOPLEVEL_BUTTON_MAXIMIZE
);
800 case wxID_ICONIZE_FRAME
:
801 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
802 wxTOPLEVEL_BUTTON_ICONIZE
);
804 case wxID_RESTORE_FRAME
:
805 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
806 wxTOPLEVEL_BUTTON_RESTORE
);
819 wxTopLevelWindow::GetStdInputHandler(wxInputHandler
*handlerDef
)
821 static wxStdTLWInputHandler
s_handler(handlerDef
);
826 // ============================================================================
827 // wxStdTLWInputHandler: handles focus, resizing and titlebar buttons clicks
828 // ============================================================================
830 wxStdTLWInputHandler::wxStdTLWInputHandler(wxInputHandler
*inphand
)
831 : wxStdInputHandler(inphand
)
836 m_borderCursorOn
= false;
839 bool wxStdTLWInputHandler::HandleMouse(wxInputConsumer
*consumer
,
840 const wxMouseEvent
& event
)
842 // the button has 2 states: pressed and normal with the following
843 // transitions between them:
845 // normal -> left down -> capture mouse and go to pressed state
846 // pressed -> left up inside -> generate click -> go to normal
847 // outside ------------------>
849 // the other mouse buttons are ignored
850 if ( event
.Button(1) )
852 if ( event
.ButtonDown(1) )
854 wxTopLevelWindow
*w
= wxStaticCast(consumer
->GetInputWindow(), wxTopLevelWindow
);
855 long hit
= w
->HitTest(event
.GetPosition());
857 if ( hit
& wxHT_TOPLEVEL_ANY_BUTTON
)
860 m_winCapture
->CaptureMouse();
863 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
866 else if ( (hit
& wxHT_TOPLEVEL_TITLEBAR
) && !w
->IsMaximized() )
868 consumer
->PerformAction(wxACTION_TOPLEVEL_MOVE
);
871 else if ( (consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
872 && (hit
& wxHT_TOPLEVEL_ANY_BORDER
) )
874 consumer
->PerformAction(wxACTION_TOPLEVEL_RESIZE
, hit
);
883 m_winCapture
->ReleaseMouse();
886 if ( m_winHitTest
== m_winPressed
)
888 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
, m_winPressed
);
892 //else: the mouse was released outside the window, this doesn't
897 return wxStdInputHandler::HandleMouse(consumer
, event
);
900 bool wxStdTLWInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
901 const wxMouseEvent
& event
)
903 if ( event
.GetEventObject() == m_winCapture
)
905 long hit
= m_winCapture
->HitTest(event
.GetPosition());
907 if ( hit
!= m_winHitTest
)
909 if ( hit
!= m_winPressed
)
910 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_RELEASE
, m_winPressed
);
912 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
918 else if ( consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
920 wxTopLevelWindow
*win
= wxStaticCast(consumer
->GetInputWindow(),
922 long hit
= win
->HitTest(event
.GetPosition());
924 if ( hit
!= m_winHitTest
)
928 if ( m_borderCursorOn
)
930 m_borderCursorOn
= false;
931 win
->SetCursor(m_origCursor
);
934 if ( hit
& wxHT_TOPLEVEL_ANY_BORDER
)
938 m_borderCursorOn
= wxGetResizingCursor(hit
, cur
);
939 if ( m_borderCursorOn
)
941 m_origCursor
= win
->GetCursor();
948 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
951 bool wxStdTLWInputHandler::HandleActivation(wxInputConsumer
*consumer
,
954 if ( m_borderCursorOn
)
956 consumer
->GetInputWindow()->SetCursor(m_origCursor
);
957 m_borderCursorOn
= false;
959 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);