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 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/dcclient.h"
28 #include "wx/settings.h"
31 #include "wx/toplevel.h"
32 #include "wx/univ/renderer.h"
33 #include "wx/bitmap.h"
35 #include "wx/cshelp.h"
36 #include "wx/evtloop.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 BEGIN_EVENT_TABLE(wxTopLevelWindow
, wxTopLevelWindowNative
)
44 WX_EVENT_TABLE_INPUT_CONSUMER(wxTopLevelWindow
)
45 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint
)
46 EVT_MENU_RANGE(wxID_CLOSE_FRAME
, wxID_RESTORE_FRAME
, wxTopLevelWindow::OnSystemMenu
)
49 WX_FORWARD_TO_INPUT_CONSUMER(wxTopLevelWindow
)
51 // ============================================================================
53 // ============================================================================
55 int wxTopLevelWindow::ms_drawDecorations
= -1;
56 int wxTopLevelWindow::ms_canIconize
= -1;
58 void wxTopLevelWindow::Init()
65 bool wxTopLevelWindow::Create(wxWindow
*parent
,
67 const wxString
& title
,
73 // init them to avoid compiler warnings
77 if ( ms_drawDecorations
== -1 )
80 !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS
)
81 || wxGetEnv(wxT("WXDECOR"), NULL
);
82 // FIXME -- wxUniv should provide a way to force non-native decorations!
83 // $WXDECOR is just a hack in absence of better wxUniv solution
86 if ( ms_canIconize
== -1 )
88 ms_canIconize
= wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME
);
91 if ( ms_drawDecorations
)
93 CreateInputHandler(wxINP_HANDLER_TOPLEVEL
);
96 exstyleOrig
= GetExtraStyle();
97 style
&= ~(wxCAPTION
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
98 wxSYSTEM_MENU
| wxRESIZE_BORDER
| wxFRAME_TOOL_WINDOW
|
100 style
|= wxSIMPLE_BORDER
;
101 SetExtraStyle(exstyleOrig
&
102 ~(wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
));
105 if ( !wxTopLevelWindowNative::Create(parent
, id
, title
, pos
,
109 if ( ms_drawDecorations
)
111 m_windowStyle
= styleOrig
;
112 m_exStyle
= exstyleOrig
;
118 bool wxTopLevelWindow::ShowFullScreen(bool show
, long style
)
120 if ( show
== IsFullScreen() ) return false;
122 if ( ms_drawDecorations
)
126 m_fsSavedStyle
= m_windowStyle
;
127 if ( style
& wxFULLSCREEN_NOBORDER
)
128 m_windowStyle
|= wxSIMPLE_BORDER
;
129 if ( style
& wxFULLSCREEN_NOCAPTION
)
130 m_windowStyle
&= ~wxCAPTION
;
134 m_windowStyle
= m_fsSavedStyle
;
138 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
141 long wxTopLevelWindow::GetDecorationsStyle() const
145 if ( m_windowStyle
& wxCAPTION
)
147 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_BUTTON_CLOSE
;
148 if ( (m_windowStyle
& wxMINIMIZE_BOX
) && ms_canIconize
)
149 style
|= wxTOPLEVEL_BUTTON_ICONIZE
;
150 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
153 style
|= wxTOPLEVEL_BUTTON_RESTORE
;
155 style
|= wxTOPLEVEL_BUTTON_MAXIMIZE
;
158 if ( m_exStyle
& (wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
))
159 style
|= wxTOPLEVEL_BUTTON_HELP
;
162 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
163 style
|= wxTOPLEVEL_BORDER
;
164 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxTHICK_FRAME
) )
165 style
|= wxTOPLEVEL_RESIZEABLE
;
168 style
|= wxTOPLEVEL_MAXIMIZED
;
169 if ( GetIcon().Ok() )
170 style
|= wxTOPLEVEL_ICON
;
172 style
|= wxTOPLEVEL_ACTIVE
;
177 void wxTopLevelWindow::RefreshTitleBar()
179 wxNcPaintEvent
event(GetId());
180 event
.SetEventObject(this);
181 GetEventHandler()->ProcessEvent(event
);
184 // ----------------------------------------------------------------------------
185 // client area handling
186 // ----------------------------------------------------------------------------
188 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
190 if ( ms_drawDecorations
)
193 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
194 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
196 rect
= m_renderer
->GetFrameClientArea(rect
,
197 GetDecorationsStyle());
198 return rect
.GetPosition();
202 return wxTopLevelWindowNative::GetClientAreaOrigin();
206 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
208 if ( ms_drawDecorations
)
211 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
212 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
214 rect
= m_renderer
->GetFrameClientArea(rect
,
215 GetDecorationsStyle());
219 *height
= rect
.height
;
222 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
225 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
227 if ( ms_drawDecorations
)
229 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
230 GetDecorationsStyle());
231 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
234 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
237 void wxTopLevelWindow::OnNcPaint(wxNcPaintEvent
& event
)
239 if ( !ms_drawDecorations
|| !m_renderer
)
243 // get the window rect
245 wxSize size
= GetSize();
249 rect
.height
= size
.y
;
252 m_renderer
->DrawFrameTitleBar(dc
, rect
,
253 GetTitle(), m_titlebarIcon
,
254 GetDecorationsStyle(),
260 long wxTopLevelWindow::HitTest(const wxPoint
& pt
) const
263 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
264 wxRect
rect(wxTopLevelWindowNative::GetClientAreaOrigin(), wxSize(w
, h
));
266 return m_renderer
->HitTestFrame(rect
, pt
+GetClientAreaOrigin(), GetDecorationsStyle());
269 int wxTopLevelWindow::GetMinWidth() const
271 if ( ms_drawDecorations
)
273 return wxMax(wxTopLevelWindowNative::GetMinWidth(),
274 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).x
);
277 return wxTopLevelWindowNative::GetMinWidth();
280 int wxTopLevelWindow::GetMinHeight() const
282 if ( ms_drawDecorations
)
284 return wxMax(wxTopLevelWindowNative::GetMinHeight(),
285 m_renderer
->GetFrameMinSize(GetDecorationsStyle()).y
);
288 return wxTopLevelWindowNative::GetMinHeight();
291 // ----------------------------------------------------------------------------
293 // ----------------------------------------------------------------------------
295 void wxTopLevelWindow::SetIcons(const wxIconBundle
& icons
)
297 wxTopLevelWindowNative::SetIcons(icons
);
299 if ( ms_drawDecorations
&& m_renderer
)
301 wxSize size
= m_renderer
->GetFrameIconSize();
302 const wxIcon
& icon
= icons
.GetIcon( size
);
304 if ( !icon
.Ok() || size
.x
== wxDefaultCoord
)
305 m_titlebarIcon
= icon
;
309 bmp1
.CopyFromIcon(icon
);
311 m_titlebarIcon
= wxNullIcon
;
312 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
313 m_titlebarIcon
= icon
;
316 wxImage img
= bmp1
.ConvertToImage();
317 img
.Rescale(size
.x
, size
.y
);
318 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));
324 // ----------------------------------------------------------------------------
325 // interactive manipulation
326 // ----------------------------------------------------------------------------
329 static bool wxGetResizingCursor(long hitTestResult
, wxCursor
& cursor
)
331 if ( hitTestResult
& wxHT_TOPLEVEL_ANY_BORDER
)
333 switch (hitTestResult
)
335 case wxHT_TOPLEVEL_BORDER_N
:
336 case wxHT_TOPLEVEL_BORDER_S
:
337 cursor
= wxCursor(wxCURSOR_SIZENS
);
339 case wxHT_TOPLEVEL_BORDER_W
:
340 case wxHT_TOPLEVEL_BORDER_E
:
341 cursor
= wxCursor(wxCURSOR_SIZEWE
);
343 case wxHT_TOPLEVEL_BORDER_NE
:
344 case wxHT_TOPLEVEL_BORDER_SW
:
345 cursor
= wxCursor(wxCURSOR_SIZENESW
);
347 case wxHT_TOPLEVEL_BORDER_NW
:
348 case wxHT_TOPLEVEL_BORDER_SE
:
349 cursor
= wxCursor(wxCURSOR_SIZENWSE
);
354 // not rachable due to earlier return
364 #define wxINTERACTIVE_RESIZE_DIR \
365 (wxINTERACTIVE_RESIZE_W | wxINTERACTIVE_RESIZE_E | \
366 wxINTERACTIVE_RESIZE_S | wxINTERACTIVE_RESIZE_N)
368 struct wxInteractiveMoveData
370 wxTopLevelWindow
*m_window
;
371 wxEventLoop
*m_evtLoop
;
376 wxSize m_minSize
, m_maxSize
;
380 class wxInteractiveMoveHandler
: public wxEvtHandler
383 wxInteractiveMoveHandler(wxInteractiveMoveData
& data
) : m_data(data
) {}
386 DECLARE_EVENT_TABLE()
387 void OnMouseMove(wxMouseEvent
& event
);
388 void OnMouseDown(wxMouseEvent
& event
);
389 void OnMouseUp(wxMouseEvent
& event
);
390 void OnKeyDown(wxKeyEvent
& event
);
392 wxInteractiveMoveData
& m_data
;
395 BEGIN_EVENT_TABLE(wxInteractiveMoveHandler
, wxEvtHandler
)
396 EVT_MOTION(wxInteractiveMoveHandler::OnMouseMove
)
397 EVT_LEFT_DOWN(wxInteractiveMoveHandler::OnMouseDown
)
398 EVT_LEFT_UP(wxInteractiveMoveHandler::OnMouseUp
)
399 EVT_KEY_DOWN(wxInteractiveMoveHandler::OnKeyDown
)
403 static inline LINKAGEMODE
404 void wxApplyResize(wxInteractiveMoveData
& data
, const wxPoint
& diff
)
406 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
408 data
.m_rect
.x
+= diff
.x
;
409 data
.m_rect
.width
-= diff
.x
;
411 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
413 data
.m_rect
.width
+= diff
.x
;
415 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
417 data
.m_rect
.y
+= diff
.y
;
418 data
.m_rect
.height
-= diff
.y
;
420 else if ( data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
422 data
.m_rect
.height
+= diff
.y
;
425 if ( data
.m_minSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
< data
.m_minSize
.x
)
427 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
428 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
429 data
.m_rect
.width
= data
.m_minSize
.x
;
431 if ( data
.m_maxSize
.x
!= wxDefaultCoord
&& data
.m_rect
.width
> data
.m_maxSize
.x
)
433 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
434 data
.m_rect
.x
-= data
.m_minSize
.x
- data
.m_rect
.width
;
435 data
.m_rect
.width
= data
.m_maxSize
.x
;
437 if ( data
.m_minSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
< data
.m_minSize
.y
)
439 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
440 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
441 data
.m_rect
.height
= data
.m_minSize
.y
;
443 if ( data
.m_maxSize
.y
!= wxDefaultCoord
&& data
.m_rect
.height
> data
.m_maxSize
.y
)
445 if ( data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
446 data
.m_rect
.y
-= data
.m_minSize
.y
- data
.m_rect
.height
;
447 data
.m_rect
.height
= data
.m_maxSize
.y
;
451 void wxInteractiveMoveHandler::OnMouseMove(wxMouseEvent
& event
)
453 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
456 else if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
458 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
459 m_data
.m_rect
= m_data
.m_rectOrig
;
460 m_data
.m_rect
.Offset(diff
);
461 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
464 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE
)
466 wxPoint diff
= wxGetMousePosition() - m_data
.m_pos
;
467 m_data
.m_rect
= m_data
.m_rectOrig
;
468 wxApplyResize(m_data
, diff
);
469 m_data
.m_window
->SetSize(m_data
.m_rect
);
473 void wxInteractiveMoveHandler::OnMouseDown(wxMouseEvent
& WXUNUSED(event
))
475 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
477 m_data
.m_evtLoop
->Exit();
481 void wxInteractiveMoveHandler::OnKeyDown(wxKeyEvent
& event
)
483 wxPoint
diff(wxDefaultCoord
,wxDefaultCoord
);
485 switch ( event
.GetKeyCode() )
487 case WXK_UP
: diff
= wxPoint(0, -16); break;
488 case WXK_DOWN
: diff
= wxPoint(0, 16); break;
489 case WXK_LEFT
: diff
= wxPoint(-16, 0); break;
490 case WXK_RIGHT
: diff
= wxPoint(16, 0); break;
492 m_data
.m_window
->SetSize(m_data
.m_rectOrig
);
493 m_data
.m_evtLoop
->Exit();
496 m_data
.m_evtLoop
->Exit();
500 if ( diff
.x
!= wxDefaultCoord
)
502 if ( m_data
.m_flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
504 m_data
.m_flags
&= ~wxINTERACTIVE_WAIT_FOR_INPUT
;
505 if ( m_data
.m_sizingCursor
)
508 m_data
.m_sizingCursor
= false;
511 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
513 m_data
.m_pos
= m_data
.m_window
->GetPosition() +
514 wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
519 bool changeCur
= false;
521 if ( m_data
.m_flags
& wxINTERACTIVE_MOVE
)
523 m_data
.m_rect
.Offset(diff
);
524 m_data
.m_window
->Move(m_data
.m_rect
.GetPosition());
525 warp
= wxPoint(m_data
.m_window
->GetSize().x
/2, 8);
527 else /* wxINTERACTIVE_RESIZE */
529 if ( !(m_data
.m_flags
&
530 (wxINTERACTIVE_RESIZE_N
| wxINTERACTIVE_RESIZE_S
)) )
534 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_N
;
535 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
;
538 else if ( diff
.y
> 0 )
540 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_S
;
541 m_data
.m_pos
.y
= m_data
.m_window
->GetPosition().y
+
542 m_data
.m_window
->GetSize().y
;
546 if ( !(m_data
.m_flags
&
547 (wxINTERACTIVE_RESIZE_W
| wxINTERACTIVE_RESIZE_E
)) )
551 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_W
;
552 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
;
555 else if ( diff
.x
> 0 )
557 m_data
.m_flags
|= wxINTERACTIVE_RESIZE_E
;
558 m_data
.m_pos
.x
= m_data
.m_window
->GetPosition().x
+
559 m_data
.m_window
->GetSize().x
;
564 wxApplyResize(m_data
, diff
);
565 m_data
.m_window
->SetSize(m_data
.m_rect
);
567 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_W
)
569 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_E
)
570 warp
.x
= m_data
.m_window
->GetSize().x
-1;
572 warp
.x
= wxGetMousePosition().x
- m_data
.m_window
->GetPosition().x
;
574 if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_N
)
576 else if ( m_data
.m_flags
& wxINTERACTIVE_RESIZE_S
)
577 warp
.y
= m_data
.m_window
->GetSize().y
-1;
579 warp
.y
= wxGetMousePosition().y
- m_data
.m_window
->GetPosition().y
;
582 warp
-= m_data
.m_window
->GetClientAreaOrigin();
583 m_data
.m_window
->WarpPointer(warp
.x
, warp
.y
);
587 long hit
= m_data
.m_window
->HitTest(warp
);
589 if ( wxGetResizingCursor(hit
, cur
) )
591 if ( m_data
.m_sizingCursor
)
593 wxBeginBusyCursor(&cur
);
594 m_data
.m_sizingCursor
= true;
600 void wxInteractiveMoveHandler::OnMouseUp(wxMouseEvent
& WXUNUSED(event
))
602 m_data
.m_evtLoop
->Exit();
606 void wxTopLevelWindow::InteractiveMove(int flags
)
608 wxASSERT_MSG( !((flags
& wxINTERACTIVE_MOVE
) && (flags
& wxINTERACTIVE_RESIZE
)),
609 wxT("can't move and resize window at the same time") );
611 wxASSERT_MSG( !(flags
& wxINTERACTIVE_RESIZE
) ||
612 (flags
& wxINTERACTIVE_WAIT_FOR_INPUT
) ||
613 (flags
& wxINTERACTIVE_RESIZE_DIR
),
614 wxT("direction of resizing not specified") );
616 wxInteractiveMoveData data
;
622 if ( flags
& wxINTERACTIVE_WAIT_FOR_INPUT
)
624 wxCursor
sizingCursor(wxCURSOR_SIZING
);
625 wxBeginBusyCursor(&sizingCursor
);
626 data
.m_sizingCursor
= true;
630 data
.m_sizingCursor
= false;
632 data
.m_window
= this;
633 data
.m_evtLoop
= &loop
;
634 data
.m_flags
= flags
;
635 data
.m_rect
= data
.m_rectOrig
= GetRect();
636 data
.m_pos
= wxGetMousePosition();
637 data
.m_minSize
= wxSize(GetMinWidth(), GetMinHeight());
638 data
.m_maxSize
= wxSize(GetMaxWidth(), GetMaxHeight());
640 wxEvtHandler
*handler
= new wxInteractiveMoveHandler(data
);
641 this->PushEventHandler(handler
);
647 this->RemoveEventHandler(handler
);
650 if ( data
.m_sizingCursor
)
654 // ----------------------------------------------------------------------------
656 // ----------------------------------------------------------------------------
658 void wxTopLevelWindow::ClickTitleBarButton(long button
)
662 case wxTOPLEVEL_BUTTON_CLOSE
:
666 case wxTOPLEVEL_BUTTON_ICONIZE
:
670 case wxTOPLEVEL_BUTTON_MAXIMIZE
:
674 case wxTOPLEVEL_BUTTON_RESTORE
:
678 case wxTOPLEVEL_BUTTON_HELP
:
681 wxContextHelp
contextHelp(this);
687 wxFAIL_MSG(wxT("incorrect button specification"));
691 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
693 const wxString
& WXUNUSED(strArg
))
695 bool isActive
= numArg
!= 0;
697 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
699 if ( m_isActive
!= isActive
)
701 m_isActive
= isActive
;
707 else if ( action
== wxACTION_TOPLEVEL_BUTTON_PRESS
)
709 m_pressedButton
= numArg
;
714 else if ( action
== wxACTION_TOPLEVEL_BUTTON_RELEASE
)
721 else if ( action
== wxACTION_TOPLEVEL_BUTTON_CLICK
)
725 ClickTitleBarButton(numArg
);
729 else if ( action
== wxACTION_TOPLEVEL_MOVE
)
731 InteractiveMove(wxINTERACTIVE_MOVE
);
735 else if ( action
== wxACTION_TOPLEVEL_RESIZE
)
737 int flags
= wxINTERACTIVE_RESIZE
;
738 if ( numArg
& wxHT_TOPLEVEL_BORDER_N
)
739 flags
|= wxINTERACTIVE_RESIZE_N
;
740 if ( numArg
& wxHT_TOPLEVEL_BORDER_S
)
741 flags
|= wxINTERACTIVE_RESIZE_S
;
742 if ( numArg
& wxHT_TOPLEVEL_BORDER_W
)
743 flags
|= wxINTERACTIVE_RESIZE_W
;
744 if ( numArg
& wxHT_TOPLEVEL_BORDER_E
)
745 flags
|= wxINTERACTIVE_RESIZE_E
;
746 InteractiveMove(flags
);
754 void wxTopLevelWindow::OnSystemMenu(wxCommandEvent
& event
)
758 switch (event
.GetId())
760 case wxID_CLOSE_FRAME
:
761 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
762 wxTOPLEVEL_BUTTON_CLOSE
);
764 case wxID_MOVE_FRAME
:
765 InteractiveMove(wxINTERACTIVE_MOVE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
767 case wxID_RESIZE_FRAME
:
768 InteractiveMove(wxINTERACTIVE_RESIZE
| wxINTERACTIVE_WAIT_FOR_INPUT
);
770 case wxID_MAXIMIZE_FRAME
:
771 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
772 wxTOPLEVEL_BUTTON_MAXIMIZE
);
774 case wxID_ICONIZE_FRAME
:
775 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
776 wxTOPLEVEL_BUTTON_ICONIZE
);
778 case wxID_RESTORE_FRAME
:
779 ret
= PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
,
780 wxTOPLEVEL_BUTTON_RESTORE
);
792 // ============================================================================
793 // wxStdFrameInputHandler: handles focus, resizing and titlebar buttons clicks
794 // ============================================================================
796 wxStdFrameInputHandler::wxStdFrameInputHandler(wxInputHandler
*inphand
)
797 : wxStdInputHandler(inphand
)
802 m_borderCursorOn
= false;
805 bool wxStdFrameInputHandler::HandleMouse(wxInputConsumer
*consumer
,
806 const wxMouseEvent
& event
)
808 // the button has 2 states: pressed and normal with the following
809 // transitions between them:
811 // normal -> left down -> capture mouse and go to pressed state
812 // pressed -> left up inside -> generate click -> go to normal
813 // outside ------------------>
815 // the other mouse buttons are ignored
816 if ( event
.Button(1) )
818 if ( event
.ButtonDown(1) )
820 wxTopLevelWindow
*w
= wxStaticCast(consumer
->GetInputWindow(), wxTopLevelWindow
);
821 long hit
= w
->HitTest(event
.GetPosition());
823 if ( hit
& wxHT_TOPLEVEL_ANY_BUTTON
)
826 m_winCapture
->CaptureMouse();
829 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
832 else if ( (hit
& wxHT_TOPLEVEL_TITLEBAR
) && !w
->IsMaximized() )
834 consumer
->PerformAction(wxACTION_TOPLEVEL_MOVE
);
837 else if ( (consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
838 && (hit
& wxHT_TOPLEVEL_ANY_BORDER
) )
840 consumer
->PerformAction(wxACTION_TOPLEVEL_RESIZE
, hit
);
849 m_winCapture
->ReleaseMouse();
852 if ( m_winHitTest
== m_winPressed
)
854 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_CLICK
, m_winPressed
);
858 //else: the mouse was released outside the window, this doesn't
863 return wxStdInputHandler::HandleMouse(consumer
, event
);
866 bool wxStdFrameInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
867 const wxMouseEvent
& event
)
869 if ( event
.GetEventObject() == m_winCapture
)
871 long hit
= m_winCapture
->HitTest(event
.GetPosition());
873 if ( hit
!= m_winHitTest
)
875 if ( hit
!= m_winPressed
)
876 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_RELEASE
, m_winPressed
);
878 consumer
->PerformAction(wxACTION_TOPLEVEL_BUTTON_PRESS
, m_winPressed
);
884 else if ( consumer
->GetInputWindow()->GetWindowStyle() & wxRESIZE_BORDER
)
886 wxTopLevelWindow
*win
= wxStaticCast(consumer
->GetInputWindow(),
888 long hit
= win
->HitTest(event
.GetPosition());
890 if ( hit
!= m_winHitTest
)
894 if ( m_borderCursorOn
)
896 m_borderCursorOn
= false;
897 win
->SetCursor(m_origCursor
);
900 if ( hit
& wxHT_TOPLEVEL_ANY_BORDER
)
904 m_borderCursorOn
= wxGetResizingCursor(hit
, cur
);
905 if ( m_borderCursorOn
)
907 m_origCursor
= win
->GetCursor();
914 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
917 bool wxStdFrameInputHandler::HandleActivation(wxInputConsumer
*consumer
,
920 if ( m_borderCursorOn
)
922 consumer
->GetInputWindow()->SetCursor(m_origCursor
);
923 m_borderCursorOn
= false;
925 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);