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
, _T("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
| wxTOPLEVEL_BUTTON_CLOSE
;
188 if ( (m_windowStyle
& wxMINIMIZE_BOX
) && ms_canIconize
)
189 style
|= wxTOPLEVEL_BUTTON_ICONIZE
;
190 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
193 style
|= wxTOPLEVEL_BUTTON_RESTORE
;
195 style
|= wxTOPLEVEL_BUTTON_MAXIMIZE
;
198 if ( m_exStyle
& wxWS_EX_CONTEXTHELP
)
199 style
|= wxTOPLEVEL_BUTTON_HELP
;
202 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
203 style
|= wxTOPLEVEL_BORDER
;
204 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxRESIZE_BORDER
) )
205 style
|= wxTOPLEVEL_RESIZEABLE
;
208 style
|= wxTOPLEVEL_MAXIMIZED
;
209 if ( GetIcon().Ok() )
210 style
|= wxTOPLEVEL_ICON
;
212 style
|= wxTOPLEVEL_ACTIVE
;
217 void wxTopLevelWindow::RefreshTitleBar()
219 wxNcPaintEvent
event(GetId());
220 event
.SetEventObject(this);
221 GetEventHandler()->ProcessEvent(event
);
224 // ----------------------------------------------------------------------------
225 // client area handling
226 // ----------------------------------------------------------------------------
228 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
230 if ( !m_usingNativeDecorations
)
233 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
234 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
236 rect
= m_renderer
->GetFrameClientArea(rect
,
237 GetDecorationsStyle());
238 return rect
.GetPosition();
242 return wxTopLevelWindowNative::GetClientAreaOrigin();
246 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
248 if ( !m_usingNativeDecorations
)
251 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
252 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
254 rect
= m_renderer
->GetFrameClientArea(rect
,
255 GetDecorationsStyle());
259 *height
= rect
.height
;
262 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
265 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
267 if ( !m_usingNativeDecorations
)
269 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
270 GetDecorationsStyle());
271 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
274 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
277 void wxTopLevelWindow::OnNcPaint(wxNcPaintEvent
& event
)
279 if ( m_usingNativeDecorations
|| !m_renderer
)
283 else // we're drawing the decorations ourselves
285 // get the window rect
286 wxRect
rect(GetSize());
289 m_renderer
->DrawFrameTitleBar(dc
, rect
,
290 GetTitle(), m_titlebarIcon
,
291 GetDecorationsStyle(),
297 long wxTopLevelWindow::HitTest(const wxPoint
& pt
) const
300 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
301 wxRect
rect(wxTopLevelWindowNative::GetClientAreaOrigin(), wxSize(w
, h
));
303 return m_renderer
->HitTestFrame(rect
, pt
+GetClientAreaOrigin(), GetDecorationsStyle());
306 int wxTopLevelWindow::GetMinWidth() const
308 if ( !m_usingNativeDecorations
)
310 return wxMax(wxTopLevelWindowNative::GetMinWidth(),
311 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).x
);
314 return wxTopLevelWindowNative::GetMinWidth();
317 int wxTopLevelWindow::GetMinHeight() const
319 if ( !m_usingNativeDecorations
)
321 return wxMax(wxTopLevelWindowNative::GetMinHeight(),
322 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).y
);
325 return wxTopLevelWindowNative::GetMinHeight();
328 // ----------------------------------------------------------------------------
330 // ----------------------------------------------------------------------------
332 void wxTopLevelWindow::SetIcons(const wxIconBundle
& icons
)
334 wxTopLevelWindowNative::SetIcons(icons
);
336 if ( !m_usingNativeDecorations
&& m_renderer
)
338 wxSize size
= m_renderer
->GetFrameIconSize();
339 const wxIcon
& icon
= icons
.GetIcon( size
);
341 if ( !icon
.Ok() || size
.x
== wxDefaultCoord
)
342 m_titlebarIcon
= icon
;
346 bmp1
.CopyFromIcon(icon
);
348 m_titlebarIcon
= wxNullIcon
;
349 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
350 m_titlebarIcon
= icon
;
354 wxImage img
= bmp1
.ConvertToImage();
355 img
.Rescale(size
.x
, size
.y
);
356 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));
358 #endif // wxUSE_IMAGE
363 // ----------------------------------------------------------------------------
364 // interactive manipulation
365 // ----------------------------------------------------------------------------
368 static bool wxGetResizingCursor(long hitTestResult
, wxCursor
& cursor
)
370 if ( hitTestResult
& wxHT_TOPLEVEL_ANY_BORDER
)
372 switch (hitTestResult
)
374 case wxHT_TOPLEVEL_BORDER_N
:
375 case wxHT_TOPLEVEL_BORDER_S
:
376 cursor
= wxCursor(wxCURSOR_SIZENS
);
378 case wxHT_TOPLEVEL_BORDER_W
:
379 case wxHT_TOPLEVEL_BORDER_E
:
380 cursor
= wxCursor(wxCURSOR_SIZEWE
);
382 case wxHT_TOPLEVEL_BORDER_NE
:
383 case wxHT_TOPLEVEL_BORDER_SW
:
384 cursor
= wxCursor(wxCURSOR_SIZENESW
);
386 case wxHT_TOPLEVEL_BORDER_NW
:
387 case wxHT_TOPLEVEL_BORDER_SE
:
388 cursor
= wxCursor(wxCURSOR_SIZENWSE
);
399 #define wxINTERACTIVE_RESIZE_DIR \
400 (wxINTERACTIVE_RESIZE_W | wxINTERACTIVE_RESIZE_E | \
401 wxINTERACTIVE_RESIZE_S | wxINTERACTIVE_RESIZE_N)
403 struct wxInteractiveMoveData
405 wxTopLevelWindow
*m_window
;
406 wxEventLoop
*m_evtLoop
;
411 wxSize m_minSize
, m_maxSize
;
415 class wxInteractiveMoveHandler
: public wxEvtHandler
418 wxInteractiveMoveHandler(wxInteractiveMoveData
& data
) : m_data(data
) {}
421 DECLARE_EVENT_TABLE()
422 void OnMouseMove(wxMouseEvent
& event
);
423 void OnMouseDown(wxMouseEvent
& event
);
424 void OnMouseUp(wxMouseEvent
& event
);
425 void OnKeyDown(wxKeyEvent
& event
);
427 wxInteractiveMoveData
& m_data
;
430 BEGIN_EVENT_TABLE(wxInteractiveMoveHandler
, wxEvtHandler
)
431 EVT_MOTION(wxInteractiveMoveHandler::OnMouseMove
)
432 EVT_LEFT_DOWN(wxInteractiveMoveHandler::OnMouseDown
)
433 EVT_LEFT_UP(wxInteractiveMoveHandler::OnMouseUp
)
434 EVT_KEY_DOWN(wxInteractiveMoveHandler::OnKeyDown
)
438 static inline LINKAGEMODE
439 void wxApplyResize(wxInteractiveMoveData
& data
, const wxPoint
& diff
)
441 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
443 data
.m_rect
.x
+= diff
.x
;
444 data
.m_rect
.width
-= diff
.x
;
446 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
448 data
.m_rect
.width
+= diff
.x
;
450 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
452 data
.m_rect
.y
+= diff
.y
;
453 data
.m_rect
.height
-= diff
.y
;
455 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
457 data
.m_rect
.height
+= diff
.y
;
460 if ( data
.m_minSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
< data
.m_minSize
.x
)
462 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
463 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
464 data
.m_rect
.width
= data
.m_minSize
.x
;
466 if ( data
.m_maxSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
> data
.m_maxSize
.x
)
468 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
469 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
470 data
.m_rect
.width
= data
.m_maxSize
.x
;
472 if ( data
.m_minSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
< data
.m_minSize
.y
)
474 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
475 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
476 data
.m_rect
.height
= data
.m_minSize
.y
;
478 if ( data
.m_maxSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
> data
.m_maxSize
.y
)
480 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
481 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
482 data
.m_rect
.height
= data
.m_maxSize
.y
;
486 void wxInteractiveMoveHandler::OnMouseMove(wxMouseEvent
& event
)
488 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
491 else if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
493 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
494 m_data
.m_rect
= m_data
.m_rectOrig
;
495 m_data
.m_rect
.Offset(diff
);
496 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
499 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE
)
501 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
502 m_data
.m_rect
= m_data
.m_rectOrig
;
503 wxApplyResize(m_data
, diff
);
504 m_data
.m_window
->SetSize(m_data
.m_rect
);
508 void wxInteractiveMoveHandler::OnMouseDown(wxMouseEvent
& WXUNUSED(event
))
510 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
512 m_data
.m_evtLoop
->Exit();
516 void wxInteractiveMoveHandler::OnKeyDown(wxKeyEvent
& event
)
518 wxPoint
diff(wxDefaultCoord
,wxDefaultCoord
);
520 switch ( event
.GetKeyCode() )
522 case WXK_UP
: diff
= wxPoint(0, -16); break;
523 case WXK_DOWN
: diff
= wxPoint(0, 16); break;
524 case WXK_LEFT
: diff
= wxPoint(-16, 0); break;
525 case WXK_RIGHT
: diff
= wxPoint(16, 0); break;
527 m_data
.m_window
->SetSize(m_data
.m_rectOrig
);
528 m_data
.m_evtLoop
->Exit();
531 m_data
.m_evtLoop
->Exit();
535 if ( diff
.x
!= wxDefaultCoord
)
537 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
539 m_data
.m_flags
&= ~wxINTERACTIVE_WAIT_FOR_INPUT
;
540 if ( m_data
.m_sizingCursor
)
543 m_data
.m_sizingCursor
= false;
546 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
548 m_data
.m_pos
= m_data
.m_window
->GetPosition() +
549 wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
554 bool changeCur
= false;
556 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
558 m_data
.m_rect
.Offset(diff
);
559 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
560 warp
= wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
562 else /* wxINTERACTIVE_RESIZE */
564 if ( !(m_data
.m_flags
&
565 (wxINTERACTIVE_RESIZE_N
| wxINTERACTIVE_RESIZE_S
)) )
569 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_N
;
570 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
;
573 else if ( diff
.y
> 0 )
575 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_S
;
576 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
+
577 m_data
.m_window
->GetSize().y
;
581 if ( !(m_data
.m_flags
&
582 (wxINTERACTIVE_RESIZE_W
| wxINTERACTIVE_RESIZE_E
)) )
586 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_W
;
587 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
;
590 else if ( diff
.x
> 0 )
592 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_E
;
593 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
+
594 m_data
.m_window
->GetSize().x
;
599 wxApplyResize(m_data
, diff
);
600 m_data
.m_window
->SetSize(m_data
.m_rect
);
602 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
604 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
605 warp
.x
= m_data
.m_window
->GetSize().x
-1;
607 warp
.x
= wxGetMousePosition().x
- m_data
.m_window
->GetPosition().x
;
609 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
611 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
612 warp
.y
= m_data
.m_window
->GetSize().y
-1;
614 warp
.y
= wxGetMousePosition().y
- m_data
.m_window
->GetPosition().y
;
617 warp
-= m_data
.m_window
->GetClientAreaOrigin();
618 m_data
.m_window
->WarpPointer(warp
.x
, warp
.y
);
622 long hit
= m_data
.m_window
->HitTest(warp
);
624 if ( wxGetResizingCursor(hit
, cur
) )
626 if ( m_data
.m_sizingCursor
)
628 wxBeginBusyCursor(&cur
);
629 m_data
.m_sizingCursor
= true;
635 void wxInteractiveMoveHandler::OnMouseUp(wxMouseEvent
& WXUNUSED(event
))
637 m_data
.m_evtLoop
->Exit();
641 void wxTopLevelWindow::InteractiveMove(int flags
)
643 wxASSERT_MSG( !((flags
& wxINTERACTIVE_MOVE
) && (flags
& wxINTERACTIVE_RESIZE
)),
644 wxT("can't move and resize window at the same time") );
646 wxASSERT_MSG( !(flags
& wxINTERACTIVE_RESIZE
) ||
647 (flags
& wxINTERACTIVE_WAIT_FOR_INPUT
) ||
648 (flags
& wxINTERACTIVE_RESIZE_DIR
),
649 wxT("direction of resizing not specified") );
651 wxInteractiveMoveData data
;
657 if ( flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
659 wxCursor
sizingCursor(wxCURSOR_SIZING
);
660 wxBeginBusyCursor(&sizingCursor
);
661 data
.m_sizingCursor
= true;
665 data
.m_sizingCursor
= false;
667 data
.m_window
= this;
668 data
.m_evtLoop
= &loop
;
669 data
.m_flags
= flags
;
670 data
.m_rect
= data
.m_rectOrig
= GetRect();
671 data
.m_pos
= wxGetMousePosition();
672 data
.m_minSize
= wxSize(GetMinWidth(), GetMinHeight());
673 data
.m_maxSize
= wxSize(GetMaxWidth(), GetMaxHeight());
675 wxEvtHandler
*handler
= new wxInteractiveMoveHandler(data
);
676 this->PushEventHandler(handler
);
682 this->RemoveEventHandler(handler
);
685 if ( data
.m_sizingCursor
)
689 // ----------------------------------------------------------------------------
691 // ----------------------------------------------------------------------------
693 void wxTopLevelWindow::ClickTitleBarButton(long button
)
697 case wxTOPLEVEL_BUTTON_CLOSE
:
701 case wxTOPLEVEL_BUTTON_ICONIZE
:
705 case wxTOPLEVEL_BUTTON_MAXIMIZE
:
709 case wxTOPLEVEL_BUTTON_RESTORE
:
713 case wxTOPLEVEL_BUTTON_HELP
:
716 wxContextHelp
contextHelp(this);
722 wxFAIL_MSG(wxT("incorrect button specification"));
726 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
728 const wxString
& WXUNUSED(strArg
))
730 bool isActive
= numArg
!= 0;
732 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
734 if ( m_isActive
!= isActive
)
736 m_isActive
= isActive
;
742 else if ( action
== wxACTION_TOPLEVEL_BUTTON_PRESS
)
744 m_pressedButton
= numArg
;
749 else if ( action
== wxACTION_TOPLEVEL_BUTTON_RELEASE
)
756 else if ( action
== wxACTION_TOPLEVEL_BUTTON_CLICK
)
760 ClickTitleBarButton(numArg
);
764 else if ( action
== wxACTION_TOPLEVEL_MOVE
)
766 InteractiveMove(wxINTERACTIVE_MOVE
);
770 else if ( action
== wxACTION_TOPLEVEL_RESIZE
)
772 int flags
= wxINTERACTIVE_RESIZE
;
773 if ( numArg
& wxHT_TOPLEVEL_BORDER_N
)
774 flags
|= wxINTERACTIVE_RESIZE_N
;
775 if ( numArg
& wxHT_TOPLEVEL_BORDER_S
)
776 flags
|= wxINTERACTIVE_RESIZE_S
;
777 if ( numArg
& wxHT_TOPLEVEL_BORDER_W
)
778 flags
|= wxINTERACTIVE_RESIZE_W
;
779 if ( numArg
& wxHT_TOPLEVEL_BORDER_E
)
780 flags
|= wxINTERACTIVE_RESIZE_E
;
781 InteractiveMove(flags
);
789 void wxTopLevelWindow::OnSystemMenu(wxCommandEvent
& event
)
793 switch (event
.GetId())
795 case wxID_CLOSE_FRAME
:
796 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
797 wxTOPLEVEL_BUTTON_CLOSE
);
799 case wxID_MOVE_FRAME
:
800 InteractiveMove(wxINTERACTIVE_MOVE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
802 case wxID_RESIZE_FRAME
:
803 InteractiveMove(wxINTERACTIVE_RESIZE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
805 case wxID_MAXIMIZE_FRAME
:
806 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
807 wxTOPLEVEL_BUTTON_MAXIMIZE
);
809 case wxID_ICONIZE_FRAME
:
810 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
811 wxTOPLEVEL_BUTTON_ICONIZE
);
813 case wxID_RESTORE_FRAME
:
814 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
815 wxTOPLEVEL_BUTTON_RESTORE
);
828 wxTopLevelWindow::GetStdInputHandler(wxInputHandler
*handlerDef
)
830 static wxStdTLWInputHandler
s_handler(handlerDef
);
835 // ============================================================================
836 // wxStdTLWInputHandler: handles focus, resizing and titlebar buttons clicks
837 // ============================================================================
839 wxStdTLWInputHandler::wxStdTLWInputHandler(wxInputHandler
*inphand
)
840 : wxStdInputHandler(inphand
)
845 m_borderCursorOn
= false;
848 bool wxStdTLWInputHandler::HandleMouse(wxInputConsumer
*consumer
,
849 const wxMouseEvent
& event
)
851 // the button has 2 states: pressed and normal with the following
852 // transitions between them:
854 // normal -> left down -> capture mouse and go to pressed state
855 // pressed -> left up inside -> generate click -> go to normal
856 // outside ------------------>
858 // the other mouse buttons are ignored
859 if ( event
.Button(1) )
861 if ( event
.ButtonDown(1) )
863 wxTopLevelWindow
*w
= wxStaticCast(consumer
->GetInputWindow(), wxTopLevelWindow
);
864 long hit
= w
->HitTest(event
.GetPosition());
866 if ( hit
& wxHT_TOPLEVEL_ANY_BUTTON
)
869 m_winCapture
->CaptureMouse();
872 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
875 else if ( (hit
& wxHT_TOPLEVEL_TITLEBAR
) && !w
->IsMaximized() )
877 consumer
->PerformAction(wxACTION_TOPLEVEL_MOVE
);
880 else if ( (consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
881 && (hit
& wxHT_TOPLEVEL_ANY_BORDER
) )
883 consumer
->PerformAction(wxACTION_TOPLEVEL_RESIZE
, hit
);
892 m_winCapture
->ReleaseMouse();
895 if ( m_winHitTest
== m_winPressed
)
897 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
, m_winPressed
);
901 //else: the mouse was released outside the window, this doesn't
906 return wxStdInputHandler::HandleMouse(consumer
, event
);
909 bool wxStdTLWInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
910 const wxMouseEvent
& event
)
912 if ( event
.GetEventObject() == m_winCapture
)
914 long hit
= m_winCapture
->HitTest(event
.GetPosition());
916 if ( hit
!= m_winHitTest
)
918 if ( hit
!= m_winPressed
)
919 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_RELEASE
, m_winPressed
);
921 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
927 else if ( consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
929 wxTopLevelWindow
*win
= wxStaticCast(consumer
->GetInputWindow(),
931 long hit
= win
->HitTest(event
.GetPosition());
933 if ( hit
!= m_winHitTest
)
937 if ( m_borderCursorOn
)
939 m_borderCursorOn
= false;
940 win
->SetCursor(m_origCursor
);
943 if ( hit
& wxHT_TOPLEVEL_ANY_BORDER
)
947 m_borderCursorOn
= wxGetResizingCursor(hit
, cur
);
948 if ( m_borderCursorOn
)
950 m_origCursor
= win
->GetCursor();
957 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
960 bool wxStdTLWInputHandler::HandleActivation(wxInputConsumer
*consumer
,
963 if ( m_borderCursorOn
)
965 consumer
->GetInputWindow()->SetCursor(m_origCursor
);
966 m_borderCursorOn
= false;
968 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);