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 wxTopLevelWindow::wxTopLevelWindow()
67 wxTopLevelWindow::wxTopLevelWindow(wxWindow
*parent
,
69 const wxString
& title
,
77 Create(parent
, id
, title
, pos
, size
, style
, name
);
80 void wxTopLevelWindow::Init()
87 bool wxTopLevelWindow::Create(wxWindow
*parent
,
89 const wxString
& title
,
95 // init them to avoid compiler warnings
99 if ( ms_drawDecorations
== -1 )
102 !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS
)
103 || wxGetEnv(wxT("WXDECOR"), NULL
);
104 // FIXME -- wxUniv should provide a way to force non-native decorations!
105 // $WXDECOR is just a hack in absence of better wxUniv solution
108 if ( ms_canIconize
== -1 )
110 ms_canIconize
= wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME
);
113 if ( ms_drawDecorations
)
115 CreateInputHandler(wxINP_HANDLER_TOPLEVEL
);
118 exstyleOrig
= GetExtraStyle();
119 style
&= ~(wxCAPTION
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
120 wxSYSTEM_MENU
| wxRESIZE_BORDER
| wxFRAME_TOOL_WINDOW
|
122 style
|= wxSIMPLE_BORDER
;
123 SetExtraStyle(exstyleOrig
&
124 ~(wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
));
127 if ( !wxTopLevelWindowNative::Create(parent
, id
, title
, pos
,
131 if ( ms_drawDecorations
)
133 m_windowStyle
= styleOrig
;
134 m_exStyle
= exstyleOrig
;
140 bool wxTopLevelWindow::ShowFullScreen(bool show
, long style
)
142 if ( show
== IsFullScreen() ) return FALSE
;
144 if ( ms_drawDecorations
)
148 m_fsSavedStyle
= m_windowStyle
;
149 if ( style
& wxFULLSCREEN_NOBORDER
)
150 m_windowStyle
|= wxSIMPLE_BORDER
;
151 if ( style
& wxFULLSCREEN_NOCAPTION
)
152 m_windowStyle
&= ~wxCAPTION
;
156 m_windowStyle
= m_fsSavedStyle
;
160 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
163 long wxTopLevelWindow::GetDecorationsStyle() const
167 if ( m_windowStyle
& wxCAPTION
)
169 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_BUTTON_CLOSE
;
170 if ( (m_windowStyle
& wxMINIMIZE_BOX
) && ms_canIconize
)
171 style
|= wxTOPLEVEL_BUTTON_ICONIZE
;
172 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
175 style
|= wxTOPLEVEL_BUTTON_RESTORE
;
177 style
|= wxTOPLEVEL_BUTTON_MAXIMIZE
;
180 if ( m_exStyle
& (wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
))
181 style
|= wxTOPLEVEL_BUTTON_HELP
;
184 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
185 style
|= wxTOPLEVEL_BORDER
;
186 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxTHICK_FRAME
) )
187 style
|= wxTOPLEVEL_RESIZEABLE
;
190 style
|= wxTOPLEVEL_MAXIMIZED
;
191 if ( GetIcon().Ok() )
192 style
|= wxTOPLEVEL_ICON
;
194 style
|= wxTOPLEVEL_ACTIVE
;
199 void wxTopLevelWindow::RefreshTitleBar()
201 wxNcPaintEvent
event(GetId());
202 event
.SetEventObject(this);
203 GetEventHandler()->ProcessEvent(event
);
206 // ----------------------------------------------------------------------------
207 // client area handling
208 // ----------------------------------------------------------------------------
210 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
212 if ( ms_drawDecorations
)
215 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
216 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
218 rect
= m_renderer
->GetFrameClientArea(rect
,
219 GetDecorationsStyle());
220 return rect
.GetPosition();
224 return wxTopLevelWindowNative::GetClientAreaOrigin();
228 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
230 if ( ms_drawDecorations
)
233 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
234 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
236 rect
= m_renderer
->GetFrameClientArea(rect
,
237 GetDecorationsStyle());
241 *height
= rect
.height
;
244 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
247 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
249 if ( ms_drawDecorations
)
251 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
252 GetDecorationsStyle());
253 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
256 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
259 void wxTopLevelWindow::OnNcPaint(wxPaintEvent
& event
)
261 if ( !ms_drawDecorations
|| !m_renderer
)
265 // get the window rect
267 wxSize size
= GetSize();
271 rect
.height
= size
.y
;
274 m_renderer
->DrawFrameTitleBar(dc
, rect
,
275 GetTitle(), m_titlebarIcon
,
276 GetDecorationsStyle(),
282 long wxTopLevelWindow::HitTest(const wxPoint
& pt
) const
285 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
286 wxRect
rect(wxTopLevelWindowNative::GetClientAreaOrigin(), wxSize(w
, h
));
288 return m_renderer
->HitTestFrame(rect
, pt
+GetClientAreaOrigin(), GetDecorationsStyle());
291 int wxTopLevelWindow::GetMinWidth() const
293 if ( ms_drawDecorations
)
295 return wxMax(wxTopLevelWindowNative::GetMinWidth(),
296 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).x
);
299 return wxTopLevelWindowNative::GetMinWidth();
302 int wxTopLevelWindow::GetMinHeight() const
304 if ( ms_drawDecorations
)
306 return wxMax(wxTopLevelWindowNative::GetMinHeight(),
307 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).y
);
310 return wxTopLevelWindowNative::GetMinHeight();
313 // ----------------------------------------------------------------------------
315 // ----------------------------------------------------------------------------
317 void wxTopLevelWindow::SetIcons(const wxIconBundle
& icons
)
319 wxTopLevelWindowNative::SetIcons(icons
);
321 if ( ms_drawDecorations
&& m_renderer
)
323 wxSize size
= m_renderer
->GetFrameIconSize();
324 const wxIcon
& icon
= icons
.GetIcon( size
);
326 if ( !icon
.Ok() || size
.x
== -1 )
327 m_titlebarIcon
= icon
;
331 bmp1
.CopyFromIcon(icon
);
333 m_titlebarIcon
= wxNullIcon
;
334 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
335 m_titlebarIcon
= icon
;
338 wxImage img
= bmp1
.ConvertToImage();
339 img
.Rescale(size
.x
, size
.y
);
340 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));
346 // ----------------------------------------------------------------------------
347 // interactive manipulation
348 // ----------------------------------------------------------------------------
351 static bool wxGetResizingCursor(long hitTestResult
, wxCursor
& cursor
)
353 if ( hitTestResult
& wxHT_TOPLEVEL_ANY_BORDER
)
355 switch (hitTestResult
)
357 case wxHT_TOPLEVEL_BORDER_N
:
358 case wxHT_TOPLEVEL_BORDER_S
:
359 cursor
= wxCursor(wxCURSOR_SIZENS
);
361 case wxHT_TOPLEVEL_BORDER_W
:
362 case wxHT_TOPLEVEL_BORDER_E
:
363 cursor
= wxCursor(wxCURSOR_SIZEWE
);
365 case wxHT_TOPLEVEL_BORDER_NE
:
366 case wxHT_TOPLEVEL_BORDER_SW
:
367 cursor
= wxCursor(wxCURSOR_SIZENESW
);
369 case wxHT_TOPLEVEL_BORDER_NW
:
370 case wxHT_TOPLEVEL_BORDER_SE
:
371 cursor
= wxCursor(wxCURSOR_SIZENWSE
);
376 // not rachable due to earlier return
386 #define wxINTERACTIVE_RESIZE_DIR \
387 (wxINTERACTIVE_RESIZE_W | wxINTERACTIVE_RESIZE_E | \
388 wxINTERACTIVE_RESIZE_S | wxINTERACTIVE_RESIZE_N)
390 struct wxInteractiveMoveData
392 wxTopLevelWindow
*m_window
;
393 wxEventLoop
*m_evtLoop
;
398 wxSize m_minSize
, m_maxSize
;
402 class wxInteractiveMoveHandler
: public wxEvtHandler
405 wxInteractiveMoveHandler(wxInteractiveMoveData
& data
) : m_data(data
) {}
408 DECLARE_EVENT_TABLE()
409 void OnMouseMove(wxMouseEvent
& event
);
410 void OnMouseDown(wxMouseEvent
& event
);
411 void OnMouseUp(wxMouseEvent
& event
);
412 void OnKeyDown(wxKeyEvent
& event
);
414 wxInteractiveMoveData
& m_data
;
417 BEGIN_EVENT_TABLE(wxInteractiveMoveHandler
, wxEvtHandler
)
418 EVT_MOTION(wxInteractiveMoveHandler::OnMouseMove
)
419 EVT_LEFT_DOWN(wxInteractiveMoveHandler::OnMouseDown
)
420 EVT_LEFT_UP(wxInteractiveMoveHandler::OnMouseUp
)
421 EVT_KEY_DOWN(wxInteractiveMoveHandler::OnKeyDown
)
425 static inline LINKAGEMODE
426 void wxApplyResize(wxInteractiveMoveData
& data
, const wxPoint
& diff
)
428 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
430 data
.m_rect
.x
+= diff
.x
;
431 data
.m_rect
.width
-= diff
.x
;
433 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
435 data
.m_rect
.width
+= diff
.x
;
437 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
439 data
.m_rect
.y
+= diff
.y
;
440 data
.m_rect
.height
-= diff
.y
;
442 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
444 data
.m_rect
.height
+= diff
.y
;
447 if ( data
.m_minSize
.x
!= -1 && data
.m_rect
.width
< data
.m_minSize
.x
)
449 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
450 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
451 data
.m_rect
.width
= data
.m_minSize
.x
;
453 if ( data
.m_maxSize
.x
!= -1 && data
.m_rect
.width
> data
.m_maxSize
.x
)
455 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
456 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
457 data
.m_rect
.width
= data
.m_maxSize
.x
;
459 if ( data
.m_minSize
.y
!= -1 && data
.m_rect
.height
< data
.m_minSize
.y
)
461 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
462 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
463 data
.m_rect
.height
= data
.m_minSize
.y
;
465 if ( data
.m_maxSize
.y
!= -1 && data
.m_rect
.height
> data
.m_maxSize
.y
)
467 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
468 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
469 data
.m_rect
.height
= data
.m_maxSize
.y
;
473 void wxInteractiveMoveHandler::OnMouseMove(wxMouseEvent
& event
)
475 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
478 else if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
480 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
481 m_data
.m_rect
= m_data
.m_rectOrig
;
482 m_data
.m_rect
.Offset(diff
);
483 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
486 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE
)
488 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
489 m_data
.m_rect
= m_data
.m_rectOrig
;
490 wxApplyResize(m_data
, diff
);
491 m_data
.m_window
->SetSize(m_data
.m_rect
);
495 void wxInteractiveMoveHandler::OnMouseDown(wxMouseEvent
& WXUNUSED(event
))
497 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
499 m_data
.m_evtLoop
->Exit();
503 void wxInteractiveMoveHandler::OnKeyDown(wxKeyEvent
& event
)
507 switch ( event
.GetKeyCode() )
509 case WXK_UP
: diff
= wxPoint(0, -16); break;
510 case WXK_DOWN
: diff
= wxPoint(0, 16); break;
511 case WXK_LEFT
: diff
= wxPoint(-16, 0); break;
512 case WXK_RIGHT
: diff
= wxPoint(16, 0); break;
514 m_data
.m_window
->SetSize(m_data
.m_rectOrig
);
515 m_data
.m_evtLoop
->Exit();
518 m_data
.m_evtLoop
->Exit();
524 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
526 m_data
.m_flags
&= ~wxINTERACTIVE_WAIT_FOR_INPUT
;
527 if ( m_data
.m_sizingCursor
)
530 m_data
.m_sizingCursor
= FALSE
;
533 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
535 m_data
.m_pos
= m_data
.m_window
->GetPosition() +
536 wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
541 bool changeCur
= FALSE
;
543 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
545 m_data
.m_rect
.Offset(diff
);
546 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
547 warp
= wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
549 else /* wxINTERACTIVE_RESIZE */
551 if ( !(m_data
.m_flags
&
552 (wxINTERACTIVE_RESIZE_N
| wxINTERACTIVE_RESIZE_S
)) )
556 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_N
;
557 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
;
560 else if ( diff
.y
> 0 )
562 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_S
;
563 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
+
564 m_data
.m_window
->GetSize().y
;
568 if ( !(m_data
.m_flags
&
569 (wxINTERACTIVE_RESIZE_W
| wxINTERACTIVE_RESIZE_E
)) )
573 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_W
;
574 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
;
577 else if ( diff
.x
> 0 )
579 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_E
;
580 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
+
581 m_data
.m_window
->GetSize().x
;
586 wxApplyResize(m_data
, diff
);
587 m_data
.m_window
->SetSize(m_data
.m_rect
);
589 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
591 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
592 warp
.x
= m_data
.m_window
->GetSize().x
-1;
594 warp
.x
= wxGetMousePosition().x
- m_data
.m_window
->GetPosition().x
;
596 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
598 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
599 warp
.y
= m_data
.m_window
->GetSize().y
-1;
601 warp
.y
= wxGetMousePosition().y
- m_data
.m_window
->GetPosition().y
;
604 warp
-= m_data
.m_window
->GetClientAreaOrigin();
605 m_data
.m_window
->WarpPointer(warp
.x
, warp
.y
);
609 long hit
= m_data
.m_window
->HitTest(warp
);
611 if ( wxGetResizingCursor(hit
, cur
) )
613 if ( m_data
.m_sizingCursor
)
615 wxBeginBusyCursor(&cur
);
616 m_data
.m_sizingCursor
= TRUE
;
622 void wxInteractiveMoveHandler::OnMouseUp(wxMouseEvent
& WXUNUSED(event
))
624 m_data
.m_evtLoop
->Exit();
628 void wxTopLevelWindow::InteractiveMove(int flags
)
630 wxASSERT_MSG( !((flags
& wxINTERACTIVE_MOVE
) && (flags
& wxINTERACTIVE_RESIZE
)),
631 wxT("can't move and resize window at the same time") );
633 wxASSERT_MSG( !(flags
& wxINTERACTIVE_RESIZE
) ||
634 (flags
& wxINTERACTIVE_WAIT_FOR_INPUT
) ||
635 (flags
& wxINTERACTIVE_RESIZE_DIR
),
636 wxT("direction of resizing not specified") );
638 wxInteractiveMoveData data
;
644 if ( flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
646 wxCursor
sizingCursor(wxCURSOR_SIZING
);
647 wxBeginBusyCursor(&sizingCursor
);
648 data
.m_sizingCursor
= TRUE
;
652 data
.m_sizingCursor
= FALSE
;
654 data
.m_window
= this;
655 data
.m_evtLoop
= &loop
;
656 data
.m_flags
= flags
;
657 data
.m_rect
= data
.m_rectOrig
= GetRect();
658 data
.m_pos
= wxGetMousePosition();
659 data
.m_minSize
= wxSize(GetMinWidth(), GetMinHeight());
660 data
.m_maxSize
= wxSize(GetMaxWidth(), GetMaxHeight());
662 wxEvtHandler
*handler
= new wxInteractiveMoveHandler(data
);
663 this->PushEventHandler(handler
);
669 this->RemoveEventHandler(handler
);
672 if ( data
.m_sizingCursor
)
676 // ----------------------------------------------------------------------------
678 // ----------------------------------------------------------------------------
680 void wxTopLevelWindow::ClickTitleBarButton(long button
)
684 case wxTOPLEVEL_BUTTON_CLOSE
:
688 case wxTOPLEVEL_BUTTON_ICONIZE
:
692 case wxTOPLEVEL_BUTTON_MAXIMIZE
:
696 case wxTOPLEVEL_BUTTON_RESTORE
:
700 case wxTOPLEVEL_BUTTON_HELP
:
703 wxContextHelp
contextHelp(this);
709 wxFAIL_MSG(wxT("incorrect button specification"));
713 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
715 const wxString
& WXUNUSED(strArg
))
717 bool isActive
= numArg
!= 0;
719 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
721 if ( m_isActive
!= isActive
)
723 m_isActive
= isActive
;
729 else if ( action
== wxACTION_TOPLEVEL_BUTTON_PRESS
)
731 m_pressedButton
= numArg
;
736 else if ( action
== wxACTION_TOPLEVEL_BUTTON_RELEASE
)
743 else if ( action
== wxACTION_TOPLEVEL_BUTTON_CLICK
)
747 ClickTitleBarButton(numArg
);
751 else if ( action
== wxACTION_TOPLEVEL_MOVE
)
753 InteractiveMove(wxINTERACTIVE_MOVE
);
757 else if ( action
== wxACTION_TOPLEVEL_RESIZE
)
759 int flags
= wxINTERACTIVE_RESIZE
;
760 if ( numArg
& wxHT_TOPLEVEL_BORDER_N
)
761 flags
|= wxINTERACTIVE_RESIZE_N
;
762 if ( numArg
& wxHT_TOPLEVEL_BORDER_S
)
763 flags
|= wxINTERACTIVE_RESIZE_S
;
764 if ( numArg
& wxHT_TOPLEVEL_BORDER_W
)
765 flags
|= wxINTERACTIVE_RESIZE_W
;
766 if ( numArg
& wxHT_TOPLEVEL_BORDER_E
)
767 flags
|= wxINTERACTIVE_RESIZE_E
;
768 InteractiveMove(flags
);
776 void wxTopLevelWindow::OnSystemMenu(wxCommandEvent
& event
)
780 switch (event
.GetId())
782 case wxID_CLOSE_FRAME
:
783 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
784 wxTOPLEVEL_BUTTON_CLOSE
);
786 case wxID_MOVE_FRAME
:
787 InteractiveMove(wxINTERACTIVE_MOVE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
789 case wxID_RESIZE_FRAME
:
790 InteractiveMove(wxINTERACTIVE_RESIZE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
792 case wxID_MAXIMIZE_FRAME
:
793 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
794 wxTOPLEVEL_BUTTON_MAXIMIZE
);
796 case wxID_ICONIZE_FRAME
:
797 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
798 wxTOPLEVEL_BUTTON_ICONIZE
);
800 case wxID_RESTORE_FRAME
:
801 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
802 wxTOPLEVEL_BUTTON_RESTORE
);
814 // ============================================================================
815 // wxStdFrameInputHandler: handles focus, resizing and titlebar buttons clicks
816 // ============================================================================
818 wxStdFrameInputHandler::wxStdFrameInputHandler(wxInputHandler
*inphand
)
819 : wxStdInputHandler(inphand
)
824 m_borderCursorOn
= FALSE
;
827 bool wxStdFrameInputHandler::HandleMouse(wxInputConsumer
*consumer
,
828 const wxMouseEvent
& event
)
830 // the button has 2 states: pressed and normal with the following
831 // transitions between them:
833 // normal -> left down -> capture mouse and go to pressed state
834 // pressed -> left up inside -> generate click -> go to normal
835 // outside ------------------>
837 // the other mouse buttons are ignored
838 if ( event
.Button(1) )
840 if ( event
.ButtonDown(1) )
842 wxTopLevelWindow
*w
= wxStaticCast(consumer
->GetInputWindow(), wxTopLevelWindow
);
843 long hit
= w
->HitTest(event
.GetPosition());
845 if ( hit
& wxHT_TOPLEVEL_ANY_BUTTON
)
848 m_winCapture
->CaptureMouse();
851 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
854 else if ( (hit
& wxHT_TOPLEVEL_TITLEBAR
) && !w
->IsMaximized() )
856 consumer
->PerformAction(wxACTION_TOPLEVEL_MOVE
);
859 else if ( (consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
860 && (hit
& wxHT_TOPLEVEL_ANY_BORDER
) )
862 consumer
->PerformAction(wxACTION_TOPLEVEL_RESIZE
, hit
);
871 m_winCapture
->ReleaseMouse();
874 if ( m_winHitTest
== m_winPressed
)
876 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
, m_winPressed
);
880 //else: the mouse was released outside the window, this doesn't
885 return wxStdInputHandler::HandleMouse(consumer
, event
);
888 bool wxStdFrameInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
889 const wxMouseEvent
& event
)
891 if ( event
.GetEventObject() == m_winCapture
)
893 long hit
= m_winCapture
->HitTest(event
.GetPosition());
895 if ( hit
!= m_winHitTest
)
897 if ( hit
!= m_winPressed
)
898 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_RELEASE
, m_winPressed
);
900 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
906 else if ( consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
908 wxTopLevelWindow
*win
= wxStaticCast(consumer
->GetInputWindow(),
910 long hit
= win
->HitTest(event
.GetPosition());
912 if ( hit
!= m_winHitTest
)
916 if ( m_borderCursorOn
)
918 m_borderCursorOn
= FALSE
;
919 win
->SetCursor(m_origCursor
);
922 if ( hit
& wxHT_TOPLEVEL_ANY_BORDER
)
926 m_borderCursorOn
= wxGetResizingCursor(hit
, cur
);
927 if ( m_borderCursorOn
)
929 m_origCursor
= win
->GetCursor();
936 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
939 bool wxStdFrameInputHandler::HandleActivation(wxInputConsumer
*consumer
,
942 if ( m_borderCursorOn
)
944 consumer
->GetInputWindow()->SetCursor(m_origCursor
);
945 m_borderCursorOn
= FALSE
;
947 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);