1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
18 #pragma implementation "univtoplevel.h"
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
29 #include "wx/toplevel.h"
30 #include "wx/univ/renderer.h"
31 #include "wx/dcclient.h"
32 #include "wx/bitmap.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 BEGIN_EVENT_TABLE(wxTopLevelWindow
, wxTopLevelWindowNative
)
41 WX_EVENT_TABLE_INPUT_CONSUMER(wxTopLevelWindow
)
42 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint
)
45 WX_FORWARD_TO_INPUT_CONSUMER(wxTopLevelWindow
)
48 // ============================================================================
50 // ============================================================================
52 int wxTopLevelWindow::ms_drawDecorations
= -1;
54 void wxTopLevelWindow::Init()
60 bool wxTopLevelWindow::Create(wxWindow
*parent
,
62 const wxString
& title
,
64 const wxSize
& sizeOrig
,
68 // init them to avoid compiler warnings
72 if ( ms_drawDecorations
== -1 )
73 ms_drawDecorations
= TRUE
;
74 // FIXME_MGL -- this is temporary; we assume for now that native TLW
75 // can't do decorations, which is not true
77 if ( ms_drawDecorations
)
79 CreateInputHandler(wxINP_HANDLER_TOPLEVEL
);
82 exstyleOrig
= GetExtraStyle();
83 // style &= ~(wxCAPTION | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
84 // wxSYSTEM_MENU | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW |
86 // style = wxSIMPLE_BORDER;
87 // SetExtraStyle(exstyleOrig &
88 // ~(wxFRAME_EX_CONTEXTHELP | wxDIALOG_EX_CONTEXTHELP));
91 if ( !wxTopLevelWindowNative::Create(parent
, id
, title
, pos
,
92 sizeOrig
, style
, name
) )
95 if ( ms_drawDecorations
)
97 m_windowStyle
= styleOrig
;
98 m_exStyle
= exstyleOrig
;
104 bool wxTopLevelWindow::ShowFullScreen(bool show
, long style
)
106 if ( show
== IsFullScreen() ) return FALSE
;
108 if ( ms_drawDecorations
)
112 m_fsSavedStyle
= m_windowStyle
;
113 if ( style
& wxFULLSCREEN_NOBORDER
)
114 m_windowStyle
|= wxSIMPLE_BORDER
;
115 if ( style
& wxFULLSCREEN_NOCAPTION
)
116 m_windowStyle
&= ~wxCAPTION
;
120 m_windowStyle
= m_fsSavedStyle
;
124 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
127 long wxTopLevelWindow::GetDecorationsStyle() const
131 if ( m_windowStyle
& wxCAPTION
)
133 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_BUTTON_CLOSE
;
134 if ( m_windowStyle
& wxMINIMIZE_BOX
)
135 style
|= wxTOPLEVEL_BUTTON_MINIMIZE
;
136 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
137 style
|= wxTOPLEVEL_BUTTON_MAXIMIZE
;
138 if ( m_exStyle
& (wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
))
139 style
|= wxTOPLEVEL_BUTTON_HELP
;
141 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
142 style
|= wxTOPLEVEL_BORDER
;
143 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxTHICK_FRAME
) )
144 style
|= wxTOPLEVEL_RESIZEABLE
;
147 style
|= wxTOPLEVEL_MAXIMIZED
;
148 if ( GetIcon().Ok() )
149 style
|= wxTOPLEVEL_ICON
;
151 style
|= wxTOPLEVEL_ACTIVE
;
156 // ----------------------------------------------------------------------------
157 // client area handling
158 // ----------------------------------------------------------------------------
160 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
162 if ( ms_drawDecorations
)
165 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
166 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
168 rect
= m_renderer
->GetFrameClientArea(rect
,
169 GetDecorationsStyle());
170 return rect
.GetPosition();
174 return wxTopLevelWindowNative::GetClientAreaOrigin();
178 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
180 if ( ms_drawDecorations
)
183 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
184 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
186 rect
= m_renderer
->GetFrameClientArea(rect
,
187 GetDecorationsStyle());
191 *height
= rect
.height
;
194 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
197 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
199 if ( ms_drawDecorations
)
201 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
202 GetDecorationsStyle());
203 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
206 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
209 void wxTopLevelWindow::OnNcPaint(wxPaintEvent
& event
)
211 if ( !ms_drawDecorations
|| !m_renderer
)
215 // get the window rect
217 wxSize size
= GetSize();
221 rect
.height
= size
.y
;
224 m_renderer
->DrawFrameTitleBar(dc
, rect
,
225 GetTitle(), m_titlebarIcon
,
226 GetDecorationsStyle());
230 // ----------------------------------------------------------------------------
232 // ----------------------------------------------------------------------------
234 void wxTopLevelWindow::SetIcon(const wxIcon
& icon
)
236 wxTopLevelWindowNative::SetIcon(icon
);
237 if ( !m_renderer
) return;
239 wxSize size
= m_renderer
->GetFrameIconSize();
241 if ( !icon
.Ok() || size
.x
== -1 )
242 m_titlebarIcon
= icon
;
246 bmp1
.CopyFromIcon(icon
);
248 m_titlebarIcon
= wxNullIcon
;
249 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
250 m_titlebarIcon
= icon
;
253 wxImage img
= bmp1
.ConvertToImage();
254 img
.Rescale(size
.x
, size
.y
);
255 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));
260 // ----------------------------------------------------------------------------
262 // ----------------------------------------------------------------------------
264 bool wxTopLevelWindow::PerformAction(const wxControlAction
& action
,
266 const wxString
& strArg
)
268 if ( action
== wxACTION_TOPLEVEL_ACTIVATE
)
270 if ( m_isActive
!= (bool)numArg
)
273 m_isActive
= (bool)numArg
;
274 wxNcPaintEvent
event(GetId());
275 event
.SetEventObject(this);
276 GetEventHandler()->ProcessEvent(event
);
277 printf("activation: %i\n", m_isActive
);
286 // ============================================================================
287 // wxStdFrameInputHandler: handles focus, resizing and titlebar buttons clicks
288 // ============================================================================
290 wxStdFrameInputHandler::wxStdFrameInputHandler(wxInputHandler
*inphand
)
291 : wxStdInputHandler(inphand
)
295 bool wxStdFrameInputHandler::HandleMouse(wxInputConsumer
*consumer
,
296 const wxMouseEvent
& event
)
298 return wxStdInputHandler::HandleMouse(consumer
, event
);
301 bool wxStdFrameInputHandler::HandleMouseMove(wxInputConsumer
*consumer
,
302 const wxMouseEvent
& event
)
304 return wxStdInputHandler::HandleMouseMove(consumer
, event
);
307 bool wxStdFrameInputHandler::HandleActivation(wxInputConsumer
*consumer
,
310 consumer
->PerformAction(wxACTION_TOPLEVEL_ACTIVATE
, activated
);