1 /////////////////////////////////////////////////////////////////////////////
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18 #pragma implementation "univtoplevel.h"
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
31 #include "wx/dcclient.h"
32 #include "wx/settings.h"
35 #include "wx/toplevel.h"
36 #include "wx/univ/renderer.h"
37 #include "wx/bitmap.h"
39 #include "wx/cshelp.h"
40 #include "wx/evtloop.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 BEGIN_EVENT_TABLE(wxTopLevelWindow
, wxTopLevelWindowNative
)
48 WX_EVENT_TABLE_INPUT_CONSUMER(wxTopLevelWindow
)
49 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint
)
50 EVT_MENU_RANGE(wxID_CLOSE_FRAME
, wxID_RESTORE_FRAME
, wxTopLevelWindow::OnSystemMenu
)
53 WX_FORWARD_TO_INPUT_CONSUMER(wxTopLevelWindow
)
55 // ============================================================================
57 // ============================================================================
59 int wxTopLevelWindow::ms_drawDecorations
= -1;
60 int wxTopLevelWindow::ms_canIconize
= -1;
62 void wxTopLevelWindow::Init()
69 bool wxTopLevelWindow::Create(wxWindow
*parent
,
71 const wxString
& title
,
77 // init them to avoid compiler warnings
81 if ( ms_drawDecorations
== -1 )
84 !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS
)
85 || wxGetEnv(wxT("WXDECOR"), NULL
);
86 // FIXME -- wxUniv should provide a way to force non-native decorations!
87 // $WXDECOR is just a hack in absence of better wxUniv solution
90 if ( ms_canIconize
== -1 )
92 ms_canIconize
= wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME
);
95 if ( ms_drawDecorations
)
97 CreateInputHandler(wxINP_HANDLER_TOPLEVEL
);
100 exstyleOrig
= GetExtraStyle();
101 style
&= ~(wxCAPTION
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
102 wxSYSTEM_MENU
| wxRESIZE_BORDER
| wxFRAME_TOOL_WINDOW
|
104 style
= wxSIMPLE_BORDER
;
105 SetExtraStyle(exstyleOrig
&
106 ~(wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
));
109 if ( !wxTopLevelWindowNative::Create(parent
, id
, title
, pos
,
113 if ( ms_drawDecorations
)
115 m_windowStyle
= styleOrig
;
116 m_exStyle
= exstyleOrig
;
122 bool wxTopLevelWindow::ShowFullScreen(bool show
, long style
)
124 if ( show
== IsFullScreen() ) return FALSE
;
126 if ( ms_drawDecorations
)
130 m_fsSavedStyle
= m_windowStyle
;
131 if ( style
& wxFULLSCREEN_NOBORDER
)
132 m_windowStyle
|= wxSIMPLE_BORDER
;
133 if ( style
& wxFULLSCREEN_NOCAPTION
)
134 m_windowStyle
&= ~wxCAPTION
;
138 m_windowStyle
= m_fsSavedStyle
;
142 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
145 long wxTopLevelWindow::GetDecorationsStyle() const
149 if ( m_windowStyle
& wxCAPTION
)
151 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_BUTTON_CLOSE
;
152 if ( (m_windowStyle
& wxMINIMIZE_BOX
) && ms_canIconize
)
153 style
|= wxTOPLEVEL_BUTTON_ICONIZE
;
154 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
157 style
|= wxTOPLEVEL_BUTTON_RESTORE
;
159 style
|= wxTOPLEVEL_BUTTON_MAXIMIZE
;
162 if ( m_exStyle
& (wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
))
163 style
|= wxTOPLEVEL_BUTTON_HELP
;
166 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
167 style
|= wxTOPLEVEL_BORDER
;
168 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxTHICK_FRAME
) )
169 style
|= wxTOPLEVEL_RESIZEABLE
;
172 style
|= wxTOPLEVEL_MAXIMIZED
;
173 if ( GetIcon().Ok() )
174 style
|= wxTOPLEVEL_ICON
;
176 style
|= wxTOPLEVEL_ACTIVE
;
181 void wxTopLevelWindow::RefreshTitleBar()
183 wxNcPaintEvent
event(GetId());
184 event
.SetEventObject(this);
185 GetEventHandler()->ProcessEvent(event
);
188 // ----------------------------------------------------------------------------
189 // client area handling
190 // ----------------------------------------------------------------------------
192 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
194 if ( ms_drawDecorations
)
197 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
198 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
200 rect
= m_renderer
->GetFrameClientArea(rect
,
201 GetDecorationsStyle());
202 return rect
.GetPosition();
206 return wxTopLevelWindowNative::GetClientAreaOrigin();
210 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
212 if ( ms_drawDecorations
)
215 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
216 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
218 rect
= m_renderer
->GetFrameClientArea(rect
,
219 GetDecorationsStyle());
223 *height
= rect
.height
;
226 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
229 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
231 if ( ms_drawDecorations
)
233 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
234 GetDecorationsStyle());
235 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
238 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
241 void wxTopLevelWindow::OnNcPaint(wxPaintEvent
& event
)
243 if ( !ms_drawDecorations
|| !m_renderer
)
247 // get the window rect
249 wxSize size
= GetSize();
253 rect
.height
= size
.y
;
256 m_renderer
->DrawFrameTitleBar(dc
, rect
,
257 GetTitle(), m_titlebarIcon
,
258 GetDecorationsStyle(),
264 long wxTopLevelWindow::HitTest(const wxPoint
& pt
) const
267 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
268 wxRect
rect(wxTopLevelWindowNative::GetClientAreaOrigin(), wxSize(w
, h
));
270 return m_renderer
->HitTestFrame(rect
, pt
+GetClientAreaOrigin(), GetDecorationsStyle());
273 int wxTopLevelWindow::GetMinWidth() const
275 if ( ms_drawDecorations
)
277 return wxMax(wxTopLevelWindowNative::GetMinWidth(),
278 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).x
);
281 return wxTopLevelWindowNative::GetMinWidth();
284 int wxTopLevelWindow::GetMinHeight() const
286 if ( ms_drawDecorations
)
288 return wxMax(wxTopLevelWindowNative::GetMinHeight(),
289 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).y
);
292 return wxTopLevelWindowNative::GetMinHeight();
295 // ----------------------------------------------------------------------------
297 // ----------------------------------------------------------------------------
299 void wxTopLevelWindow::SetIcons(const wxIconBundle
& icons
)
301 wxTopLevelWindowNative::SetIcons(icons
);
303 if ( ms_drawDecorations
&& m_renderer
)
305 wxSize size
= m_renderer
->GetFrameIconSize();
306 const wxIcon
& icon
= icons
.GetIcon( size
);
308 if ( !icon
.Ok() || size
.x
== -1 )
309 m_titlebarIcon
= icon
;
313 bmp1
.CopyFromIcon(icon
);
315 m_titlebarIcon
= wxNullIcon
;
316 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
317 m_titlebarIcon
= icon
;
320 wxImage img
= bmp1
.ConvertToImage();
321 img
.Rescale(size
.x
, size
.y
);
322 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));
328 // ----------------------------------------------------------------------------
329 // interactive manipulation
330 // ----------------------------------------------------------------------------
333 static bool wxGetResizingCursor(long hitTestResult
, wxCursor
& cursor
)
335 if ( hitTestResult
& wxHT_TOPLEVEL_ANY_BORDER
)
337 switch (hitTestResult
)
339 case wxHT_TOPLEVEL_BORDER_N
:
340 case wxHT_TOPLEVEL_BORDER_S
:
341 cursor
= wxCursor(wxCURSOR_SIZENS
);
343 case wxHT_TOPLEVEL_BORDER_W
:
344 case wxHT_TOPLEVEL_BORDER_E
:
345 cursor
= wxCursor(wxCURSOR_SIZEWE
);
347 case wxHT_TOPLEVEL_BORDER_NE
:
348 case wxHT_TOPLEVEL_BORDER_SW
:
349 cursor
= wxCursor(wxCURSOR_SIZENESW
);
351 case wxHT_TOPLEVEL_BORDER_NW
:
352 case wxHT_TOPLEVEL_BORDER_SE
:
353 cursor
= wxCursor(wxCURSOR_SIZENWSE
);
365 #define wxINTERACTIVE_RESIZE_DIR \
366 (wxINTERACTIVE_RESIZE_W | wxINTERACTIVE_RESIZE_E | \
367 wxINTERACTIVE_RESIZE_S | wxINTERACTIVE_RESIZE_N)
369 struct wxInteractiveMoveData
371 wxTopLevelWindow
*m_window
;
372 wxEventLoop
*m_evtLoop
;
377 wxSize m_minSize
, m_maxSize
;
381 class wxInteractiveMoveHandler
: public wxEvtHandler
384 wxInteractiveMoveHandler(wxInteractiveMoveData
& data
) : m_data(data
) {}
387 DECLARE_EVENT_TABLE()
388 void OnMouseMove(wxMouseEvent
& event
);
389 void OnMouseDown(wxMouseEvent
& event
);
390 void OnMouseUp(wxMouseEvent
& event
);
391 void OnKeyDown(wxKeyEvent
& event
);
393 wxInteractiveMoveData
& m_data
;
396 BEGIN_EVENT_TABLE(wxInteractiveMoveHandler
, wxEvtHandler
)
397 EVT_MOTION(wxInteractiveMoveHandler::OnMouseMove
)
398 EVT_LEFT_DOWN(wxInteractiveMoveHandler::OnMouseDown
)
399 EVT_LEFT_UP(wxInteractiveMoveHandler::OnMouseUp
)
400 EVT_KEY_DOWN(wxInteractiveMoveHandler::OnKeyDown
)
404 static inline LINKAGEMODE
405 void wxApplyResize(wxInteractiveMoveData
& data
, const wxPoint
& diff
)
407 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
409 data
.m_rect
.x
+= diff
.x
;
410 data
.m_rect
.width
-= diff
.x
;
412 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
414 data
.m_rect
.width
+= diff
.x
;
416 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
418 data
.m_rect
.y
+= diff
.y
;
419 data
.m_rect
.height
-= diff
.y
;
421 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
423 data
.m_rect
.height
+= diff
.y
;
426 if ( data
.m_minSize
.x
!= -1 && data
.m_rect
.width
< data
.m_minSize
.x
)
428 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
429 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
430 data
.m_rect
.width
= data
.m_minSize
.x
;
432 if ( data
.m_maxSize
.x
!= -1 && data
.m_rect
.width
> data
.m_maxSize
.x
)
434 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
435 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
436 data
.m_rect
.width
= data
.m_maxSize
.x
;
438 if ( data
.m_minSize
.y
!= -1 && data
.m_rect
.height
< data
.m_minSize
.y
)
440 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
441 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
442 data
.m_rect
.height
= data
.m_minSize
.y
;
444 if ( data
.m_maxSize
.y
!= -1 && data
.m_rect
.height
> data
.m_maxSize
.y
)
446 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
447 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
448 data
.m_rect
.height
= data
.m_maxSize
.y
;
452 void wxInteractiveMoveHandler::OnMouseMove(wxMouseEvent
& event
)
454 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
457 else if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
459 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
460 m_data
.m_rect
= m_data
.m_rectOrig
;
461 m_data
.m_rect
.Offset(diff
);
462 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
465 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE
)
467 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
468 m_data
.m_rect
= m_data
.m_rectOrig
;
469 wxApplyResize(m_data
, diff
);
470 m_data
.m_window
->SetSize(m_data
.m_rect
);
474 void wxInteractiveMoveHandler::OnMouseDown(wxMouseEvent
& WXUNUSED(event
))
476 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
478 m_data
.m_evtLoop
->Exit();
482 void wxInteractiveMoveHandler::OnKeyDown(wxKeyEvent
& event
)
486 switch ( event
.GetKeyCode() )
488 case WXK_UP
: diff
= wxPoint(0, -16); break;
489 case WXK_DOWN
: diff
= wxPoint(0, 16); break;
490 case WXK_LEFT
: diff
= wxPoint(-16, 0); break;
491 case WXK_RIGHT
: diff
= wxPoint(16, 0); break;
493 m_data
.m_window
->SetSize(m_data
.m_rectOrig
);
494 m_data
.m_evtLoop
->Exit();
497 m_data
.m_evtLoop
->Exit();
503 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
505 m_data
.m_flags
&= ~wxINTERACTIVE_WAIT_FOR_INPUT
;
506 if ( m_data
.m_sizingCursor
)
509 m_data
.m_sizingCursor
= FALSE
;
512 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
514 m_data
.m_pos
= m_data
.m_window
->GetPosition() +
515 wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
520 bool changeCur
= FALSE
;
522 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
524 m_data
.m_rect
.Offset(diff
);
525 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
526 warp
= wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
528 else /* wxINTERACTIVE_RESIZE */
530 if ( !(m_data
.m_flags
&
531 (wxINTERACTIVE_RESIZE_N
| wxINTERACTIVE_RESIZE_S
)) )
535 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_N
;
536 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
;
539 else if ( diff
.y
> 0 )
541 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_S
;
542 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
+
543 m_data
.m_window
->GetSize().y
;
547 if ( !(m_data
.m_flags
&
548 (wxINTERACTIVE_RESIZE_W
| wxINTERACTIVE_RESIZE_E
)) )
552 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_W
;
553 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
;
556 else if ( diff
.x
> 0 )
558 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_E
;
559 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
+
560 m_data
.m_window
->GetSize().x
;
565 wxApplyResize(m_data
, diff
);
566 m_data
.m_window
->SetSize(m_data
.m_rect
);
568 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
570 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
571 warp
.x
= m_data
.m_window
->GetSize().x
-1;
573 warp
.x
= wxGetMousePosition().x
- m_data
.m_window
->GetPosition().x
;
575 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
577 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
578 warp
.y
= m_data
.m_window
->GetSize().y
-1;
580 warp
.y
= wxGetMousePosition().y
- m_data
.m_window
->GetPosition().y
;
583 warp
-= m_data
.m_window
->GetClientAreaOrigin();
584 m_data
.m_window
->WarpPointer(warp
.x
, warp
.y
);
588 long hit
= m_data
.m_window
->HitTest(warp
);
590 if ( wxGetResizingCursor(hit
, cur
) )
592 if ( m_data
.m_sizingCursor
)
594 wxBeginBusyCursor(&cur
);
595 m_data
.m_sizingCursor
= TRUE
;
601 void wxInteractiveMoveHandler::OnMouseUp(wxMouseEvent
& WXUNUSED(event
))
603 m_data
.m_evtLoop
->Exit();
607 void wxTopLevelWindow::InteractiveMove(int flags
)
609 wxASSERT_MSG( !((flags
& wxINTERACTIVE_MOVE
) && (flags
& wxINTERACTIVE_RESIZE
)),
610 wxT("can't move and resize window at the same time") );
612 wxASSERT_MSG( !(flags
& wxINTERACTIVE_RESIZE
) ||
613 (flags
& wxINTERACTIVE_WAIT_FOR_INPUT
) ||
614 (flags
& wxINTERACTIVE_RESIZE_DIR
),
615 wxT("direction of resizing not specified") );
617 wxInteractiveMoveData data
;
623 if ( flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
625 wxCursor
sizingCursor(wxCURSOR_SIZING
);
626 wxBeginBusyCursor(&sizingCursor
);
627 data
.m_sizingCursor
= TRUE
;
631 data
.m_sizingCursor
= FALSE
;
633 data
.m_window
= this;
634 data
.m_evtLoop
= &loop
;
635 data
.m_flags
= flags
;
636 data
.m_rect
= data
.m_rectOrig
= GetRect();
637 data
.m_pos
= wxGetMousePosition();
638 data
.m_minSize
= wxSize(GetMinWidth(), GetMinHeight());
639 data
.m_maxSize
= wxSize(GetMaxWidth(), GetMaxHeight());
641 wxEvtHandler
*handler
= new wxInteractiveMoveHandler(data
);
642 this->PushEventHandler(handler
);
648 this->RemoveEventHandler(handler
);
651 if ( data
.m_sizingCursor
)
655 // ----------------------------------------------------------------------------
657 // ----------------------------------------------------------------------------
659 void wxTopLevelWindow::ClickTitleBarButton(long button
)
663 case wxTOPLEVEL_BUTTON_CLOSE
:
667 case wxTOPLEVEL_BUTTON_ICONIZE
:
671 case wxTOPLEVEL_BUTTON_MAXIMIZE
:
675 case wxTOPLEVEL_BUTTON_RESTORE
:
679 case wxTOPLEVEL_BUTTON_HELP
:
682 wxContextHelp
contextHelp(this);
688 wxFAIL_MSG(wxT("incorrect button specification"));
692 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
694 const wxString
& WXUNUSED(strArg
))
696 bool isActive
= numArg
!= 0;
698 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
700 if ( m_isActive
!= isActive
)
702 m_isActive
= isActive
;
708 else if ( action
== wxACTION_TOPLEVEL_BUTTON_PRESS
)
710 m_pressedButton
= numArg
;
715 else if ( action
== wxACTION_TOPLEVEL_BUTTON_RELEASE
)
722 else if ( action
== wxACTION_TOPLEVEL_BUTTON_CLICK
)
726 ClickTitleBarButton(numArg
);
730 else if ( action
== wxACTION_TOPLEVEL_MOVE
)
732 InteractiveMove(wxINTERACTIVE_MOVE
);
736 else if ( action
== wxACTION_TOPLEVEL_RESIZE
)
738 int flags
= wxINTERACTIVE_RESIZE
;
739 if ( numArg
& wxHT_TOPLEVEL_BORDER_N
)
740 flags
|= wxINTERACTIVE_RESIZE_N
;
741 if ( numArg
& wxHT_TOPLEVEL_BORDER_S
)
742 flags
|= wxINTERACTIVE_RESIZE_S
;
743 if ( numArg
& wxHT_TOPLEVEL_BORDER_W
)
744 flags
|= wxINTERACTIVE_RESIZE_W
;
745 if ( numArg
& wxHT_TOPLEVEL_BORDER_E
)
746 flags
|= wxINTERACTIVE_RESIZE_E
;
747 InteractiveMove(flags
);
755 void wxTopLevelWindow::OnSystemMenu(wxCommandEvent
& event
)
759 switch (event
.GetId())
761 case wxID_CLOSE_FRAME
:
762 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
763 wxTOPLEVEL_BUTTON_CLOSE
);
765 case wxID_MOVE_FRAME
:
766 InteractiveMove(wxINTERACTIVE_MOVE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
768 case wxID_RESIZE_FRAME
:
769 InteractiveMove(wxINTERACTIVE_RESIZE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
771 case wxID_MAXIMIZE_FRAME
:
772 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
773 wxTOPLEVEL_BUTTON_MAXIMIZE
);
775 case wxID_ICONIZE_FRAME
:
776 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
777 wxTOPLEVEL_BUTTON_ICONIZE
);
779 case wxID_RESTORE_FRAME
:
780 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
781 wxTOPLEVEL_BUTTON_RESTORE
);
793 // ============================================================================
794 // wxStdFrameInputHandler: handles focus, resizing and titlebar buttons clicks
795 // ============================================================================
797 wxStdFrameInputHandler::wxStdFrameInputHandler(wxInputHandler
*inphand
)
798 : wxStdInputHandler(inphand
)
803 m_borderCursorOn
= FALSE
;
806 bool wxStdFrameInputHandler::HandleMouse(wxInputConsumer
*consumer
,
807 const wxMouseEvent
& event
)
809 // the button has 2 states: pressed and normal with the following
810 // transitions between them:
812 // normal -> left down -> capture mouse and go to pressed state
813 // pressed -> left up inside -> generate click -> go to normal
814 // outside ------------------>
816 // the other mouse buttons are ignored
817 if ( event
.Button(1) )
819 if ( event
.ButtonDown(1) )
821 wxTopLevelWindow
*w
= wxStaticCast(consumer
->GetInputWindow(), wxTopLevelWindow
);
822 long hit
= w
->HitTest(event
.GetPosition());
824 if ( hit
& wxHT_TOPLEVEL_ANY_BUTTON
)
827 m_winCapture
->CaptureMouse();
830 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
833 else if ( (hit
& wxHT_TOPLEVEL_TITLEBAR
) && !w
->IsMaximized() )
835 consumer
->PerformAction(wxACTION_TOPLEVEL_MOVE
);
838 else if ( (consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
839 && (hit
& wxHT_TOPLEVEL_ANY_BORDER
) )
841 consumer
->PerformAction(wxACTION_TOPLEVEL_RESIZE
, hit
);
850 m_winCapture
->ReleaseMouse();
853 if ( m_winHitTest
== m_winPressed
)
855 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
, m_winPressed
);
859 //else: the mouse was released outside the window, this doesn't
864 return wxStdInputHandler::HandleMouse(consumer
, event
);
867 bool wxStdFrameInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
868 const wxMouseEvent
& event
)
870 if ( event
.GetEventObject() == m_winCapture
)
872 long hit
= m_winCapture
->HitTest(event
.GetPosition());
874 if ( hit
!= m_winHitTest
)
876 if ( hit
!= m_winPressed
)
877 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_RELEASE
, m_winPressed
);
879 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
885 else if ( consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
887 wxTopLevelWindow
*win
= wxStaticCast(consumer
->GetInputWindow(),
889 long hit
= win
->HitTest(event
.GetPosition());
891 if ( hit
!= m_winHitTest
)
895 if ( m_borderCursorOn
)
897 m_borderCursorOn
= FALSE
;
898 win
->SetCursor(m_origCursor
);
901 if ( hit
& wxHT_TOPLEVEL_ANY_BORDER
)
905 m_borderCursorOn
= wxGetResizingCursor(hit
, cur
);
906 if ( m_borderCursorOn
)
908 m_origCursor
= win
->GetCursor();
915 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
918 bool wxStdFrameInputHandler::HandleActivation(wxInputConsumer
*consumer
,
921 if ( m_borderCursorOn
)
923 consumer
->GetInputWindow()->SetCursor(m_origCursor
);
924 m_borderCursorOn
= FALSE
;
926 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);