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(wxNcPaintEvent
& 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
);
358 // not rachable due to earlier return
368 #define wxINTERACTIVE_RESIZE_DIR \
369 (wxINTERACTIVE_RESIZE_W | wxINTERACTIVE_RESIZE_E | \
370 wxINTERACTIVE_RESIZE_S | wxINTERACTIVE_RESIZE_N)
372 struct wxInteractiveMoveData
374 wxTopLevelWindow
*m_window
;
375 wxEventLoop
*m_evtLoop
;
380 wxSize m_minSize
, m_maxSize
;
384 class wxInteractiveMoveHandler
: public wxEvtHandler
387 wxInteractiveMoveHandler(wxInteractiveMoveData
& data
) : m_data(data
) {}
390 DECLARE_EVENT_TABLE()
391 void OnMouseMove(wxMouseEvent
& event
);
392 void OnMouseDown(wxMouseEvent
& event
);
393 void OnMouseUp(wxMouseEvent
& event
);
394 void OnKeyDown(wxKeyEvent
& event
);
396 wxInteractiveMoveData
& m_data
;
399 BEGIN_EVENT_TABLE(wxInteractiveMoveHandler
, wxEvtHandler
)
400 EVT_MOTION(wxInteractiveMoveHandler::OnMouseMove
)
401 EVT_LEFT_DOWN(wxInteractiveMoveHandler::OnMouseDown
)
402 EVT_LEFT_UP(wxInteractiveMoveHandler::OnMouseUp
)
403 EVT_KEY_DOWN(wxInteractiveMoveHandler::OnKeyDown
)
407 static inline LINKAGEMODE
408 void wxApplyResize(wxInteractiveMoveData
& data
, const wxPoint
& diff
)
410 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
412 data
.m_rect
.x
+= diff
.x
;
413 data
.m_rect
.width
-= diff
.x
;
415 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
417 data
.m_rect
.width
+= diff
.x
;
419 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
421 data
.m_rect
.y
+= diff
.y
;
422 data
.m_rect
.height
-= diff
.y
;
424 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
426 data
.m_rect
.height
+= diff
.y
;
429 if ( data
.m_minSize
.x
!= -1 && data
.m_rect
.width
< data
.m_minSize
.x
)
431 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
432 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
433 data
.m_rect
.width
= data
.m_minSize
.x
;
435 if ( data
.m_maxSize
.x
!= -1 && data
.m_rect
.width
> data
.m_maxSize
.x
)
437 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
438 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
439 data
.m_rect
.width
= data
.m_maxSize
.x
;
441 if ( data
.m_minSize
.y
!= -1 && data
.m_rect
.height
< data
.m_minSize
.y
)
443 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
444 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
445 data
.m_rect
.height
= data
.m_minSize
.y
;
447 if ( data
.m_maxSize
.y
!= -1 && data
.m_rect
.height
> data
.m_maxSize
.y
)
449 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
450 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
451 data
.m_rect
.height
= data
.m_maxSize
.y
;
455 void wxInteractiveMoveHandler::OnMouseMove(wxMouseEvent
& event
)
457 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
460 else if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
462 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
463 m_data
.m_rect
= m_data
.m_rectOrig
;
464 m_data
.m_rect
.Offset(diff
);
465 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
468 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE
)
470 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
471 m_data
.m_rect
= m_data
.m_rectOrig
;
472 wxApplyResize(m_data
, diff
);
473 m_data
.m_window
->SetSize(m_data
.m_rect
);
477 void wxInteractiveMoveHandler::OnMouseDown(wxMouseEvent
& WXUNUSED(event
))
479 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
481 m_data
.m_evtLoop
->Exit();
485 void wxInteractiveMoveHandler::OnKeyDown(wxKeyEvent
& event
)
489 switch ( event
.GetKeyCode() )
491 case WXK_UP
: diff
= wxPoint(0, -16); break;
492 case WXK_DOWN
: diff
= wxPoint(0, 16); break;
493 case WXK_LEFT
: diff
= wxPoint(-16, 0); break;
494 case WXK_RIGHT
: diff
= wxPoint(16, 0); break;
496 m_data
.m_window
->SetSize(m_data
.m_rectOrig
);
497 m_data
.m_evtLoop
->Exit();
500 m_data
.m_evtLoop
->Exit();
506 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
508 m_data
.m_flags
&= ~wxINTERACTIVE_WAIT_FOR_INPUT
;
509 if ( m_data
.m_sizingCursor
)
512 m_data
.m_sizingCursor
= FALSE
;
515 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
517 m_data
.m_pos
= m_data
.m_window
->GetPosition() +
518 wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
523 bool changeCur
= FALSE
;
525 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
527 m_data
.m_rect
.Offset(diff
);
528 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
529 warp
= wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
531 else /* wxINTERACTIVE_RESIZE */
533 if ( !(m_data
.m_flags
&
534 (wxINTERACTIVE_RESIZE_N
| wxINTERACTIVE_RESIZE_S
)) )
538 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_N
;
539 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
;
542 else if ( diff
.y
> 0 )
544 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_S
;
545 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
+
546 m_data
.m_window
->GetSize().y
;
550 if ( !(m_data
.m_flags
&
551 (wxINTERACTIVE_RESIZE_W
| wxINTERACTIVE_RESIZE_E
)) )
555 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_W
;
556 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
;
559 else if ( diff
.x
> 0 )
561 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_E
;
562 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
+
563 m_data
.m_window
->GetSize().x
;
568 wxApplyResize(m_data
, diff
);
569 m_data
.m_window
->SetSize(m_data
.m_rect
);
571 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
573 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
574 warp
.x
= m_data
.m_window
->GetSize().x
-1;
576 warp
.x
= wxGetMousePosition().x
- m_data
.m_window
->GetPosition().x
;
578 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
580 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
581 warp
.y
= m_data
.m_window
->GetSize().y
-1;
583 warp
.y
= wxGetMousePosition().y
- m_data
.m_window
->GetPosition().y
;
586 warp
-= m_data
.m_window
->GetClientAreaOrigin();
587 m_data
.m_window
->WarpPointer(warp
.x
, warp
.y
);
591 long hit
= m_data
.m_window
->HitTest(warp
);
593 if ( wxGetResizingCursor(hit
, cur
) )
595 if ( m_data
.m_sizingCursor
)
597 wxBeginBusyCursor(&cur
);
598 m_data
.m_sizingCursor
= TRUE
;
604 void wxInteractiveMoveHandler::OnMouseUp(wxMouseEvent
& WXUNUSED(event
))
606 m_data
.m_evtLoop
->Exit();
610 void wxTopLevelWindow::InteractiveMove(int flags
)
612 wxASSERT_MSG( !((flags
& wxINTERACTIVE_MOVE
) && (flags
& wxINTERACTIVE_RESIZE
)),
613 wxT("can't move and resize window at the same time") );
615 wxASSERT_MSG( !(flags
& wxINTERACTIVE_RESIZE
) ||
616 (flags
& wxINTERACTIVE_WAIT_FOR_INPUT
) ||
617 (flags
& wxINTERACTIVE_RESIZE_DIR
),
618 wxT("direction of resizing not specified") );
620 wxInteractiveMoveData data
;
626 if ( flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
628 wxCursor
sizingCursor(wxCURSOR_SIZING
);
629 wxBeginBusyCursor(&sizingCursor
);
630 data
.m_sizingCursor
= TRUE
;
634 data
.m_sizingCursor
= FALSE
;
636 data
.m_window
= this;
637 data
.m_evtLoop
= &loop
;
638 data
.m_flags
= flags
;
639 data
.m_rect
= data
.m_rectOrig
= GetRect();
640 data
.m_pos
= wxGetMousePosition();
641 data
.m_minSize
= wxSize(GetMinWidth(), GetMinHeight());
642 data
.m_maxSize
= wxSize(GetMaxWidth(), GetMaxHeight());
644 wxEvtHandler
*handler
= new wxInteractiveMoveHandler(data
);
645 this->PushEventHandler(handler
);
651 this->RemoveEventHandler(handler
);
654 if ( data
.m_sizingCursor
)
658 // ----------------------------------------------------------------------------
660 // ----------------------------------------------------------------------------
662 void wxTopLevelWindow::ClickTitleBarButton(long button
)
666 case wxTOPLEVEL_BUTTON_CLOSE
:
670 case wxTOPLEVEL_BUTTON_ICONIZE
:
674 case wxTOPLEVEL_BUTTON_MAXIMIZE
:
678 case wxTOPLEVEL_BUTTON_RESTORE
:
682 case wxTOPLEVEL_BUTTON_HELP
:
685 wxContextHelp
contextHelp(this);
691 wxFAIL_MSG(wxT("incorrect button specification"));
695 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
697 const wxString
& WXUNUSED(strArg
))
699 bool isActive
= numArg
!= 0;
701 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
703 if ( m_isActive
!= isActive
)
705 m_isActive
= isActive
;
711 else if ( action
== wxACTION_TOPLEVEL_BUTTON_PRESS
)
713 m_pressedButton
= numArg
;
718 else if ( action
== wxACTION_TOPLEVEL_BUTTON_RELEASE
)
725 else if ( action
== wxACTION_TOPLEVEL_BUTTON_CLICK
)
729 ClickTitleBarButton(numArg
);
733 else if ( action
== wxACTION_TOPLEVEL_MOVE
)
735 InteractiveMove(wxINTERACTIVE_MOVE
);
739 else if ( action
== wxACTION_TOPLEVEL_RESIZE
)
741 int flags
= wxINTERACTIVE_RESIZE
;
742 if ( numArg
& wxHT_TOPLEVEL_BORDER_N
)
743 flags
|= wxINTERACTIVE_RESIZE_N
;
744 if ( numArg
& wxHT_TOPLEVEL_BORDER_S
)
745 flags
|= wxINTERACTIVE_RESIZE_S
;
746 if ( numArg
& wxHT_TOPLEVEL_BORDER_W
)
747 flags
|= wxINTERACTIVE_RESIZE_W
;
748 if ( numArg
& wxHT_TOPLEVEL_BORDER_E
)
749 flags
|= wxINTERACTIVE_RESIZE_E
;
750 InteractiveMove(flags
);
758 void wxTopLevelWindow::OnSystemMenu(wxCommandEvent
& event
)
762 switch (event
.GetId())
764 case wxID_CLOSE_FRAME
:
765 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
766 wxTOPLEVEL_BUTTON_CLOSE
);
768 case wxID_MOVE_FRAME
:
769 InteractiveMove(wxINTERACTIVE_MOVE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
771 case wxID_RESIZE_FRAME
:
772 InteractiveMove(wxINTERACTIVE_RESIZE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
774 case wxID_MAXIMIZE_FRAME
:
775 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
776 wxTOPLEVEL_BUTTON_MAXIMIZE
);
778 case wxID_ICONIZE_FRAME
:
779 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
780 wxTOPLEVEL_BUTTON_ICONIZE
);
782 case wxID_RESTORE_FRAME
:
783 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
784 wxTOPLEVEL_BUTTON_RESTORE
);
796 // ============================================================================
797 // wxStdFrameInputHandler: handles focus, resizing and titlebar buttons clicks
798 // ============================================================================
800 wxStdFrameInputHandler::wxStdFrameInputHandler(wxInputHandler
*inphand
)
801 : wxStdInputHandler(inphand
)
806 m_borderCursorOn
= FALSE
;
809 bool wxStdFrameInputHandler::HandleMouse(wxInputConsumer
*consumer
,
810 const wxMouseEvent
& event
)
812 // the button has 2 states: pressed and normal with the following
813 // transitions between them:
815 // normal -> left down -> capture mouse and go to pressed state
816 // pressed -> left up inside -> generate click -> go to normal
817 // outside ------------------>
819 // the other mouse buttons are ignored
820 if ( event
.Button(1) )
822 if ( event
.ButtonDown(1) )
824 wxTopLevelWindow
*w
= wxStaticCast(consumer
->GetInputWindow(), wxTopLevelWindow
);
825 long hit
= w
->HitTest(event
.GetPosition());
827 if ( hit
& wxHT_TOPLEVEL_ANY_BUTTON
)
830 m_winCapture
->CaptureMouse();
833 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
836 else if ( (hit
& wxHT_TOPLEVEL_TITLEBAR
) && !w
->IsMaximized() )
838 consumer
->PerformAction(wxACTION_TOPLEVEL_MOVE
);
841 else if ( (consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
842 && (hit
& wxHT_TOPLEVEL_ANY_BORDER
) )
844 consumer
->PerformAction(wxACTION_TOPLEVEL_RESIZE
, hit
);
853 m_winCapture
->ReleaseMouse();
856 if ( m_winHitTest
== m_winPressed
)
858 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
, m_winPressed
);
862 //else: the mouse was released outside the window, this doesn't
867 return wxStdInputHandler::HandleMouse(consumer
, event
);
870 bool wxStdFrameInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
871 const wxMouseEvent
& event
)
873 if ( event
.GetEventObject() == m_winCapture
)
875 long hit
= m_winCapture
->HitTest(event
.GetPosition());
877 if ( hit
!= m_winHitTest
)
879 if ( hit
!= m_winPressed
)
880 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_RELEASE
, m_winPressed
);
882 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
888 else if ( consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
890 wxTopLevelWindow
*win
= wxStaticCast(consumer
->GetInputWindow(),
892 long hit
= win
->HitTest(event
.GetPosition());
894 if ( hit
!= m_winHitTest
)
898 if ( m_borderCursorOn
)
900 m_borderCursorOn
= FALSE
;
901 win
->SetCursor(m_origCursor
);
904 if ( hit
& wxHT_TOPLEVEL_ANY_BORDER
)
908 m_borderCursorOn
= wxGetResizingCursor(hit
, cur
);
909 if ( m_borderCursorOn
)
911 m_origCursor
= win
->GetCursor();
918 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
921 bool wxStdFrameInputHandler::HandleActivation(wxInputConsumer
*consumer
,
924 if ( m_borderCursorOn
)
926 consumer
->GetInputWindow()->SetCursor(m_origCursor
);
927 m_borderCursorOn
= FALSE
;
929 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);