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 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow
, wxWindow
)
42 BEGIN_EVENT_TABLE(wxTopLevelWindow
, wxTopLevelWindowNative
)
43 EVT_NC_PAINT(wxTopLevelWindow
::OnNcPaint
)
47 // ============================================================================
49 // ============================================================================
51 int wxTopLevelWindow
::ms_drawDecorations
= -1;
53 void wxTopLevelWindow
::Init()
58 bool wxTopLevelWindow
::Create(wxWindow
*parent
,
60 const wxString
& title
,
62 const wxSize
& sizeOrig
,
66 long styleOrig
, exstyleOrig
;
68 if ( ms_drawDecorations
== -1 )
69 ms_drawDecorations
= TRUE
;
70 // FIXME_MGL -- this is temporary; we assume for now that native TLW
71 // can't do decorations, which is not true
73 if ( ms_drawDecorations
)
76 exstyleOrig
= GetExtraStyle();
77 style
&= ~(wxCAPTION
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
78 wxSYSTEM_MENU
| wxRESIZE_BORDER
| wxFRAME_TOOL_WINDOW
|
80 style
= wxSIMPLE_BORDER
;
81 SetExtraStyle(exstyleOrig
&
82 ~(wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
));
85 if ( !wxTopLevelWindowNative
::Create(parent
, id
, title
, pos
,
86 sizeOrig
, style
, name
) )
89 if ( ms_drawDecorations
)
91 m_windowStyle
= styleOrig
;
92 m_exStyle
= exstyleOrig
;
98 bool wxTopLevelWindow
::ShowFullScreen(bool show
, long style
)
100 if ( show
== IsFullScreen() ) return FALSE
;
102 return wxTopLevelWindowNative
::ShowFullScreen(show
, style
);
104 // FIXME_MGL -- must handle caption hiding here if not in
105 // native decorations mode
108 long wxTopLevelWindow
::GetDecorationsStyle() const
112 if ( m_windowStyle
& wxCAPTION
)
114 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_CLOSE_BUTTON
;
115 if ( m_windowStyle
& wxMINIMIZE_BOX
)
116 style
|= wxTOPLEVEL_MINIMIZE_BUTTON
;
117 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
118 style
|= wxTOPLEVEL_MAXIMIZE_BUTTON
;
119 if ( m_exStyle
& (wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
))
120 style
|= wxTOPLEVEL_HELP_BUTTON
;
122 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
123 style
|= wxTOPLEVEL_BORDER
;
124 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxTHICK_FRAME
) )
125 style
|= wxTOPLEVEL_RESIZEABLE
;
128 style
|= wxTOPLEVEL_MAXIMIZED
;
129 if ( GetIcon().Ok() )
130 style
|= wxTOPLEVEL_ICON
;
131 if ( /*m_isActive*/ 1 /* FIXME_MGL*/ )
132 style
|= wxTOPLEVEL_ACTIVE
;
137 // ----------------------------------------------------------------------------
138 // client area handling
139 // ----------------------------------------------------------------------------
141 wxPoint wxTopLevelWindow
::GetClientAreaOrigin() const
143 if ( ms_drawDecorations
)
146 wxTopLevelWindowNative
::DoGetClientSize(&w
, &h
);
147 wxRect rect
= wxRect(wxTopLevelWindowNative
::GetClientAreaOrigin(),
149 rect
= m_renderer
->GetFrameClientArea(rect
,
150 GetDecorationsStyle());
151 return rect
.GetPosition();
155 return wxTopLevelWindowNative
::GetClientAreaOrigin();
159 void wxTopLevelWindow
::DoGetClientSize(int *width
, int *height
) const
161 if ( ms_drawDecorations
)
164 wxTopLevelWindowNative
::DoGetClientSize(&w
, &h
);
165 wxRect rect
= wxRect(wxTopLevelWindowNative
::GetClientAreaOrigin(),
167 rect
= m_renderer
->GetFrameClientArea(rect
,
168 GetDecorationsStyle());
172 *height
= rect
.height
;
175 wxTopLevelWindowNative
::DoGetClientSize(width
, height
);
178 void wxTopLevelWindow
::DoSetClientSize(int width
, int height
)
180 if ( ms_drawDecorations
)
182 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
183 GetDecorationsStyle());
184 wxTopLevelWindowNative
::DoSetClientSize(size
.x
, size
.y
);
187 wxTopLevelWindowNative
::DoSetClientSize(width
, height
);
190 void wxTopLevelWindow
::OnNcPaint(wxPaintEvent
& event
)
192 if ( !ms_drawDecorations
|| !m_renderer
)
196 // get the window rect
198 wxSize size
= GetSize();
202 rect
.height
= size
.y
;
205 m_renderer
->DrawFrameTitleBar(dc
, rect
,
206 GetTitle(), m_titlebarIcon
,
207 GetDecorationsStyle());
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 void wxTopLevelWindow
::SetIcon(const wxIcon
& icon
)
217 wxTopLevelWindowNative
::SetIcon(icon
);
218 if ( !m_renderer
) return;
220 wxSize size
= m_renderer
->GetFrameIconSize();
222 if ( !icon
.Ok() || size
.x
== -1 )
223 m_titlebarIcon
= icon
;
227 bmp1
.CopyFromIcon(icon
);
229 m_titlebarIcon
= wxNullIcon
;
230 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
231 m_titlebarIcon
= icon
;
234 wxImage img
= bmp1
.ConvertToImage();
235 img
.Rescale(size
.x
, size
.y
);
236 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));