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"
33 #include "wx/univ/renderer.h"
34 #include "wx/cshelp.h"
35 #include "wx/evtloop.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 BEGIN_EVENT_TABLE(wxTopLevelWindow
, wxTopLevelWindowNative
)
43 WX_EVENT_TABLE_INPUT_CONSUMER(wxTopLevelWindow
)
44 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint
)
45 EVT_MENU_RANGE(wxID_CLOSE_FRAME
, wxID_RESTORE_FRAME
, wxTopLevelWindow::OnSystemMenu
)
48 WX_FORWARD_TO_INPUT_CONSUMER(wxTopLevelWindow
)
50 // ============================================================================
52 // ============================================================================
54 int wxTopLevelWindow::ms_drawDecorations
= -1;
55 int wxTopLevelWindow::ms_canIconize
= -1;
57 void wxTopLevelWindow::Init()
64 bool wxTopLevelWindow::Create(wxWindow
*parent
,
66 const wxString
& title
,
72 // init them to avoid compiler warnings
76 if ( ms_drawDecorations
== -1 )
79 !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS
)
80 || wxGetEnv(wxT("WXDECOR"), NULL
);
81 // FIXME -- wxUniv should provide a way to force non-native decorations!
82 // $WXDECOR is just a hack in absence of better wxUniv solution
85 if ( ms_canIconize
== -1 )
87 ms_canIconize
= wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME
);
90 if ( ms_drawDecorations
)
92 CreateInputHandler(wxINP_HANDLER_TOPLEVEL
);
95 exstyleOrig
= GetExtraStyle();
96 style
&= ~(wxCAPTION
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
97 wxSYSTEM_MENU
| wxRESIZE_BORDER
| wxFRAME_TOOL_WINDOW
|
99 style
|= wxSIMPLE_BORDER
;
100 SetExtraStyle(exstyleOrig
& ~wxWS_EX_CONTEXTHELP
);
103 if ( !wxTopLevelWindowNative::Create(parent
, id
, title
, pos
,
107 if ( ms_drawDecorations
)
109 m_windowStyle
= styleOrig
;
110 m_exStyle
= exstyleOrig
;
116 bool wxTopLevelWindow::ShowFullScreen(bool show
, long style
)
118 if ( show
== IsFullScreen() ) return false;
120 if ( ms_drawDecorations
)
124 m_fsSavedStyle
= m_windowStyle
;
125 if ( style
& wxFULLSCREEN_NOBORDER
)
126 m_windowStyle
|= wxSIMPLE_BORDER
;
127 if ( style
& wxFULLSCREEN_NOCAPTION
)
128 m_windowStyle
&= ~wxCAPTION
;
132 m_windowStyle
= m_fsSavedStyle
;
136 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
139 long wxTopLevelWindow::GetDecorationsStyle() const
143 if ( m_windowStyle
& wxCAPTION
)
145 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_BUTTON_CLOSE
;
146 if ( (m_windowStyle
& wxMINIMIZE_BOX
) && ms_canIconize
)
147 style
|= wxTOPLEVEL_BUTTON_ICONIZE
;
148 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
151 style
|= wxTOPLEVEL_BUTTON_RESTORE
;
153 style
|= wxTOPLEVEL_BUTTON_MAXIMIZE
;
156 if ( m_exStyle
& wxWS_EX_CONTEXTHELP
)
157 style
|= wxTOPLEVEL_BUTTON_HELP
;
160 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
161 style
|= wxTOPLEVEL_BORDER
;
162 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxRESIZE_BORDER
) )
163 style
|= wxTOPLEVEL_RESIZEABLE
;
166 style
|= wxTOPLEVEL_MAXIMIZED
;
167 if ( GetIcon().Ok() )
168 style
|= wxTOPLEVEL_ICON
;
170 style
|= wxTOPLEVEL_ACTIVE
;
175 void wxTopLevelWindow::RefreshTitleBar()
177 wxNcPaintEvent
event(GetId());
178 event
.SetEventObject(this);
179 GetEventHandler()->ProcessEvent(event
);
182 // ----------------------------------------------------------------------------
183 // client area handling
184 // ----------------------------------------------------------------------------
186 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
188 if ( ms_drawDecorations
)
191 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
192 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
194 rect
= m_renderer
->GetFrameClientArea(rect
,
195 GetDecorationsStyle());
196 return rect
.GetPosition();
200 return wxTopLevelWindowNative::GetClientAreaOrigin();
204 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
206 if ( ms_drawDecorations
)
209 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
210 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
212 rect
= m_renderer
->GetFrameClientArea(rect
,
213 GetDecorationsStyle());
217 *height
= rect
.height
;
220 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
223 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
225 if ( ms_drawDecorations
)
227 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
228 GetDecorationsStyle());
229 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
232 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
235 void wxTopLevelWindow::OnNcPaint(wxNcPaintEvent
& event
)
237 if ( !ms_drawDecorations
|| !m_renderer
)
241 // get the window rect
242 wxRect
rect(GetSize());
245 m_renderer
->DrawFrameTitleBar(dc
, rect
,
246 GetTitle(), m_titlebarIcon
,
247 GetDecorationsStyle(),
253 long wxTopLevelWindow::HitTest(const wxPoint
& pt
) const
256 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
257 wxRect
rect(wxTopLevelWindowNative::GetClientAreaOrigin(), wxSize(w
, h
));
259 return m_renderer
->HitTestFrame(rect
, pt
+GetClientAreaOrigin(), GetDecorationsStyle());
262 int wxTopLevelWindow::GetMinWidth() const
264 if ( ms_drawDecorations
)
266 return wxMax(wxTopLevelWindowNative::GetMinWidth(),
267 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).x
);
270 return wxTopLevelWindowNative::GetMinWidth();
273 int wxTopLevelWindow::GetMinHeight() const
275 if ( ms_drawDecorations
)
277 return wxMax(wxTopLevelWindowNative::GetMinHeight(),
278 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).y
);
281 return wxTopLevelWindowNative::GetMinHeight();
284 // ----------------------------------------------------------------------------
286 // ----------------------------------------------------------------------------
288 void wxTopLevelWindow::SetIcons(const wxIconBundle
& icons
)
290 wxTopLevelWindowNative::SetIcons(icons
);
292 if ( ms_drawDecorations
&& m_renderer
)
294 wxSize size
= m_renderer
->GetFrameIconSize();
295 const wxIcon
& icon
= icons
.GetIcon( size
);
297 if ( !icon
.Ok() || size
.x
== wxDefaultCoord
)
298 m_titlebarIcon
= icon
;
302 bmp1
.CopyFromIcon(icon
);
304 m_titlebarIcon
= wxNullIcon
;
305 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
306 m_titlebarIcon
= icon
;
310 wxImage img
= bmp1
.ConvertToImage();
311 img
.Rescale(size
.x
, size
.y
);
312 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));
314 #endif // wxUSE_IMAGE
319 // ----------------------------------------------------------------------------
320 // interactive manipulation
321 // ----------------------------------------------------------------------------
324 static bool wxGetResizingCursor(long hitTestResult
, wxCursor
& cursor
)
326 if ( hitTestResult
& wxHT_TOPLEVEL_ANY_BORDER
)
328 switch (hitTestResult
)
330 case wxHT_TOPLEVEL_BORDER_N
:
331 case wxHT_TOPLEVEL_BORDER_S
:
332 cursor
= wxCursor(wxCURSOR_SIZENS
);
334 case wxHT_TOPLEVEL_BORDER_W
:
335 case wxHT_TOPLEVEL_BORDER_E
:
336 cursor
= wxCursor(wxCURSOR_SIZEWE
);
338 case wxHT_TOPLEVEL_BORDER_NE
:
339 case wxHT_TOPLEVEL_BORDER_SW
:
340 cursor
= wxCursor(wxCURSOR_SIZENESW
);
342 case wxHT_TOPLEVEL_BORDER_NW
:
343 case wxHT_TOPLEVEL_BORDER_SE
:
344 cursor
= wxCursor(wxCURSOR_SIZENWSE
);
355 #define wxINTERACTIVE_RESIZE_DIR \
356 (wxINTERACTIVE_RESIZE_W | wxINTERACTIVE_RESIZE_E | \
357 wxINTERACTIVE_RESIZE_S | wxINTERACTIVE_RESIZE_N)
359 struct wxInteractiveMoveData
361 wxTopLevelWindow
*m_window
;
362 wxEventLoop
*m_evtLoop
;
367 wxSize m_minSize
, m_maxSize
;
371 class wxInteractiveMoveHandler
: public wxEvtHandler
374 wxInteractiveMoveHandler(wxInteractiveMoveData
& data
) : m_data(data
) {}
377 DECLARE_EVENT_TABLE()
378 void OnMouseMove(wxMouseEvent
& event
);
379 void OnMouseDown(wxMouseEvent
& event
);
380 void OnMouseUp(wxMouseEvent
& event
);
381 void OnKeyDown(wxKeyEvent
& event
);
383 wxInteractiveMoveData
& m_data
;
386 BEGIN_EVENT_TABLE(wxInteractiveMoveHandler
, wxEvtHandler
)
387 EVT_MOTION(wxInteractiveMoveHandler::OnMouseMove
)
388 EVT_LEFT_DOWN(wxInteractiveMoveHandler::OnMouseDown
)
389 EVT_LEFT_UP(wxInteractiveMoveHandler::OnMouseUp
)
390 EVT_KEY_DOWN(wxInteractiveMoveHandler::OnKeyDown
)
394 static inline LINKAGEMODE
395 void wxApplyResize(wxInteractiveMoveData
& data
, const wxPoint
& diff
)
397 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
399 data
.m_rect
.x
+= diff
.x
;
400 data
.m_rect
.width
-= diff
.x
;
402 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
404 data
.m_rect
.width
+= diff
.x
;
406 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
408 data
.m_rect
.y
+= diff
.y
;
409 data
.m_rect
.height
-= diff
.y
;
411 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
413 data
.m_rect
.height
+= diff
.y
;
416 if ( data
.m_minSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
< data
.m_minSize
.x
)
418 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
419 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
420 data
.m_rect
.width
= data
.m_minSize
.x
;
422 if ( data
.m_maxSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
> data
.m_maxSize
.x
)
424 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
425 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
426 data
.m_rect
.width
= data
.m_maxSize
.x
;
428 if ( data
.m_minSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
< data
.m_minSize
.y
)
430 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
431 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
432 data
.m_rect
.height
= data
.m_minSize
.y
;
434 if ( data
.m_maxSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
> data
.m_maxSize
.y
)
436 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
437 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
438 data
.m_rect
.height
= data
.m_maxSize
.y
;
442 void wxInteractiveMoveHandler::OnMouseMove(wxMouseEvent
& event
)
444 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
447 else if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
449 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
450 m_data
.m_rect
= m_data
.m_rectOrig
;
451 m_data
.m_rect
.Offset(diff
);
452 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
455 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE
)
457 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
458 m_data
.m_rect
= m_data
.m_rectOrig
;
459 wxApplyResize(m_data
, diff
);
460 m_data
.m_window
->SetSize(m_data
.m_rect
);
464 void wxInteractiveMoveHandler::OnMouseDown(wxMouseEvent
& WXUNUSED(event
))
466 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
468 m_data
.m_evtLoop
->Exit();
472 void wxInteractiveMoveHandler::OnKeyDown(wxKeyEvent
& event
)
474 wxPoint
diff(wxDefaultCoord
,wxDefaultCoord
);
476 switch ( event
.GetKeyCode() )
478 case WXK_UP
: diff
= wxPoint(0, -16); break;
479 case WXK_DOWN
: diff
= wxPoint(0, 16); break;
480 case WXK_LEFT
: diff
= wxPoint(-16, 0); break;
481 case WXK_RIGHT
: diff
= wxPoint(16, 0); break;
483 m_data
.m_window
->SetSize(m_data
.m_rectOrig
);
484 m_data
.m_evtLoop
->Exit();
487 m_data
.m_evtLoop
->Exit();
491 if ( diff
.x
!= wxDefaultCoord
)
493 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
495 m_data
.m_flags
&= ~wxINTERACTIVE_WAIT_FOR_INPUT
;
496 if ( m_data
.m_sizingCursor
)
499 m_data
.m_sizingCursor
= false;
502 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
504 m_data
.m_pos
= m_data
.m_window
->GetPosition() +
505 wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
510 bool changeCur
= false;
512 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
514 m_data
.m_rect
.Offset(diff
);
515 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
516 warp
= wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
518 else /* wxINTERACTIVE_RESIZE */
520 if ( !(m_data
.m_flags
&
521 (wxINTERACTIVE_RESIZE_N
| wxINTERACTIVE_RESIZE_S
)) )
525 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_N
;
526 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
;
529 else if ( diff
.y
> 0 )
531 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_S
;
532 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
+
533 m_data
.m_window
->GetSize().y
;
537 if ( !(m_data
.m_flags
&
538 (wxINTERACTIVE_RESIZE_W
| wxINTERACTIVE_RESIZE_E
)) )
542 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_W
;
543 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
;
546 else if ( diff
.x
> 0 )
548 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_E
;
549 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
+
550 m_data
.m_window
->GetSize().x
;
555 wxApplyResize(m_data
, diff
);
556 m_data
.m_window
->SetSize(m_data
.m_rect
);
558 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
560 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
561 warp
.x
= m_data
.m_window
->GetSize().x
-1;
563 warp
.x
= wxGetMousePosition().x
- m_data
.m_window
->GetPosition().x
;
565 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
567 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
568 warp
.y
= m_data
.m_window
->GetSize().y
-1;
570 warp
.y
= wxGetMousePosition().y
- m_data
.m_window
->GetPosition().y
;
573 warp
-= m_data
.m_window
->GetClientAreaOrigin();
574 m_data
.m_window
->WarpPointer(warp
.x
, warp
.y
);
578 long hit
= m_data
.m_window
->HitTest(warp
);
580 if ( wxGetResizingCursor(hit
, cur
) )
582 if ( m_data
.m_sizingCursor
)
584 wxBeginBusyCursor(&cur
);
585 m_data
.m_sizingCursor
= true;
591 void wxInteractiveMoveHandler::OnMouseUp(wxMouseEvent
& WXUNUSED(event
))
593 m_data
.m_evtLoop
->Exit();
597 void wxTopLevelWindow::InteractiveMove(int flags
)
599 wxASSERT_MSG( !((flags
& wxINTERACTIVE_MOVE
) && (flags
& wxINTERACTIVE_RESIZE
)),
600 wxT("can't move and resize window at the same time") );
602 wxASSERT_MSG( !(flags
& wxINTERACTIVE_RESIZE
) ||
603 (flags
& wxINTERACTIVE_WAIT_FOR_INPUT
) ||
604 (flags
& wxINTERACTIVE_RESIZE_DIR
),
605 wxT("direction of resizing not specified") );
607 wxInteractiveMoveData data
;
613 if ( flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
615 wxCursor
sizingCursor(wxCURSOR_SIZING
);
616 wxBeginBusyCursor(&sizingCursor
);
617 data
.m_sizingCursor
= true;
621 data
.m_sizingCursor
= false;
623 data
.m_window
= this;
624 data
.m_evtLoop
= &loop
;
625 data
.m_flags
= flags
;
626 data
.m_rect
= data
.m_rectOrig
= GetRect();
627 data
.m_pos
= wxGetMousePosition();
628 data
.m_minSize
= wxSize(GetMinWidth(), GetMinHeight());
629 data
.m_maxSize
= wxSize(GetMaxWidth(), GetMaxHeight());
631 wxEvtHandler
*handler
= new wxInteractiveMoveHandler(data
);
632 this->PushEventHandler(handler
);
638 this->RemoveEventHandler(handler
);
641 if ( data
.m_sizingCursor
)
645 // ----------------------------------------------------------------------------
647 // ----------------------------------------------------------------------------
649 void wxTopLevelWindow::ClickTitleBarButton(long button
)
653 case wxTOPLEVEL_BUTTON_CLOSE
:
657 case wxTOPLEVEL_BUTTON_ICONIZE
:
661 case wxTOPLEVEL_BUTTON_MAXIMIZE
:
665 case wxTOPLEVEL_BUTTON_RESTORE
:
669 case wxTOPLEVEL_BUTTON_HELP
:
672 wxContextHelp
contextHelp(this);
678 wxFAIL_MSG(wxT("incorrect button specification"));
682 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
684 const wxString
& WXUNUSED(strArg
))
686 bool isActive
= numArg
!= 0;
688 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
690 if ( m_isActive
!= isActive
)
692 m_isActive
= isActive
;
698 else if ( action
== wxACTION_TOPLEVEL_BUTTON_PRESS
)
700 m_pressedButton
= numArg
;
705 else if ( action
== wxACTION_TOPLEVEL_BUTTON_RELEASE
)
712 else if ( action
== wxACTION_TOPLEVEL_BUTTON_CLICK
)
716 ClickTitleBarButton(numArg
);
720 else if ( action
== wxACTION_TOPLEVEL_MOVE
)
722 InteractiveMove(wxINTERACTIVE_MOVE
);
726 else if ( action
== wxACTION_TOPLEVEL_RESIZE
)
728 int flags
= wxINTERACTIVE_RESIZE
;
729 if ( numArg
& wxHT_TOPLEVEL_BORDER_N
)
730 flags
|= wxINTERACTIVE_RESIZE_N
;
731 if ( numArg
& wxHT_TOPLEVEL_BORDER_S
)
732 flags
|= wxINTERACTIVE_RESIZE_S
;
733 if ( numArg
& wxHT_TOPLEVEL_BORDER_W
)
734 flags
|= wxINTERACTIVE_RESIZE_W
;
735 if ( numArg
& wxHT_TOPLEVEL_BORDER_E
)
736 flags
|= wxINTERACTIVE_RESIZE_E
;
737 InteractiveMove(flags
);
745 void wxTopLevelWindow::OnSystemMenu(wxCommandEvent
& event
)
749 switch (event
.GetId())
751 case wxID_CLOSE_FRAME
:
752 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
753 wxTOPLEVEL_BUTTON_CLOSE
);
755 case wxID_MOVE_FRAME
:
756 InteractiveMove(wxINTERACTIVE_MOVE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
758 case wxID_RESIZE_FRAME
:
759 InteractiveMove(wxINTERACTIVE_RESIZE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
761 case wxID_MAXIMIZE_FRAME
:
762 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
763 wxTOPLEVEL_BUTTON_MAXIMIZE
);
765 case wxID_ICONIZE_FRAME
:
766 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
767 wxTOPLEVEL_BUTTON_ICONIZE
);
769 case wxID_RESTORE_FRAME
:
770 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
771 wxTOPLEVEL_BUTTON_RESTORE
);
783 // ============================================================================
784 // wxStdFrameInputHandler: handles focus, resizing and titlebar buttons clicks
785 // ============================================================================
787 wxStdFrameInputHandler::wxStdFrameInputHandler(wxInputHandler
*inphand
)
788 : wxStdInputHandler(inphand
)
793 m_borderCursorOn
= false;
796 bool wxStdFrameInputHandler::HandleMouse(wxInputConsumer
*consumer
,
797 const wxMouseEvent
& event
)
799 // the button has 2 states: pressed and normal with the following
800 // transitions between them:
802 // normal -> left down -> capture mouse and go to pressed state
803 // pressed -> left up inside -> generate click -> go to normal
804 // outside ------------------>
806 // the other mouse buttons are ignored
807 if ( event
.Button(1) )
809 if ( event
.ButtonDown(1) )
811 wxTopLevelWindow
*w
= wxStaticCast(consumer
->GetInputWindow(), wxTopLevelWindow
);
812 long hit
= w
->HitTest(event
.GetPosition());
814 if ( hit
& wxHT_TOPLEVEL_ANY_BUTTON
)
817 m_winCapture
->CaptureMouse();
820 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
823 else if ( (hit
& wxHT_TOPLEVEL_TITLEBAR
) && !w
->IsMaximized() )
825 consumer
->PerformAction(wxACTION_TOPLEVEL_MOVE
);
828 else if ( (consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
829 && (hit
& wxHT_TOPLEVEL_ANY_BORDER
) )
831 consumer
->PerformAction(wxACTION_TOPLEVEL_RESIZE
, hit
);
840 m_winCapture
->ReleaseMouse();
843 if ( m_winHitTest
== m_winPressed
)
845 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
, m_winPressed
);
849 //else: the mouse was released outside the window, this doesn't
854 return wxStdInputHandler::HandleMouse(consumer
, event
);
857 bool wxStdFrameInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
858 const wxMouseEvent
& event
)
860 if ( event
.GetEventObject() == m_winCapture
)
862 long hit
= m_winCapture
->HitTest(event
.GetPosition());
864 if ( hit
!= m_winHitTest
)
866 if ( hit
!= m_winPressed
)
867 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_RELEASE
, m_winPressed
);
869 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
875 else if ( consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
877 wxTopLevelWindow
*win
= wxStaticCast(consumer
->GetInputWindow(),
879 long hit
= win
->HitTest(event
.GetPosition());
881 if ( hit
!= m_winHitTest
)
885 if ( m_borderCursorOn
)
887 m_borderCursorOn
= false;
888 win
->SetCursor(m_origCursor
);
891 if ( hit
& wxHT_TOPLEVEL_ANY_BORDER
)
895 m_borderCursorOn
= wxGetResizingCursor(hit
, cur
);
896 if ( m_borderCursorOn
)
898 m_origCursor
= win
->GetCursor();
905 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
908 bool wxStdFrameInputHandler::HandleActivation(wxInputConsumer
*consumer
,
911 if ( m_borderCursorOn
)
913 consumer
->GetInputWindow()->SetCursor(m_origCursor
);
914 m_borderCursorOn
= false;
916 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);