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 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint
)
45 // ============================================================================
47 // ============================================================================
49 int wxTopLevelWindow::ms_drawDecorations
= -1;
51 void wxTopLevelWindow::Init()
56 bool wxTopLevelWindow::Create(wxWindow
*parent
,
58 const wxString
& title
,
60 const wxSize
& sizeOrig
,
64 // init them to avoid compiler warnings
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 // VZ: doesn't compile
102 if ( show
== IsFullScreen() ) return FALSE
;
104 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
106 // FIXME_MGL -- must handle caption hiding here if not in
107 // native decorations mode
113 long wxTopLevelWindow::GetDecorationsStyle() const
117 if ( m_windowStyle
& wxCAPTION
)
119 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_CLOSE_BUTTON
;
120 if ( m_windowStyle
& wxMINIMIZE_BOX
)
121 style
|= wxTOPLEVEL_MINIMIZE_BUTTON
;
122 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
123 style
|= wxTOPLEVEL_MAXIMIZE_BUTTON
;
124 if ( m_exStyle
& (wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
))
125 style
|= wxTOPLEVEL_HELP_BUTTON
;
127 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
128 style
|= wxTOPLEVEL_BORDER
;
129 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxTHICK_FRAME
) )
130 style
|= wxTOPLEVEL_RESIZEABLE
;
133 style
|= wxTOPLEVEL_MAXIMIZED
;
134 if ( GetIcon().Ok() )
135 style
|= wxTOPLEVEL_ICON
;
136 if ( /*m_isActive*/ 1 /* FIXME_MGL*/ )
137 style
|= wxTOPLEVEL_ACTIVE
;
142 // ----------------------------------------------------------------------------
143 // client area handling
144 // ----------------------------------------------------------------------------
146 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
148 if ( ms_drawDecorations
)
151 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
152 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
154 rect
= m_renderer
->GetFrameClientArea(rect
,
155 GetDecorationsStyle());
156 return rect
.GetPosition();
160 return wxTopLevelWindowNative::GetClientAreaOrigin();
164 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
166 if ( ms_drawDecorations
)
169 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
170 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
172 rect
= m_renderer
->GetFrameClientArea(rect
,
173 GetDecorationsStyle());
177 *height
= rect
.height
;
180 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
183 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
185 if ( ms_drawDecorations
)
187 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
188 GetDecorationsStyle());
189 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
192 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
195 void wxTopLevelWindow::OnNcPaint(wxPaintEvent
& event
)
197 if ( !ms_drawDecorations
|| !m_renderer
)
201 // get the window rect
203 wxSize size
= GetSize();
207 rect
.height
= size
.y
;
210 m_renderer
->DrawFrameTitleBar(dc
, rect
,
211 GetTitle(), m_titlebarIcon
,
212 GetDecorationsStyle());
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 void wxTopLevelWindow::SetIcon(const wxIcon
& icon
)
222 wxTopLevelWindowNative::SetIcon(icon
);
223 if ( !m_renderer
) return;
225 wxSize size
= m_renderer
->GetFrameIconSize();
227 if ( !icon
.Ok() || size
.x
== -1 )
228 m_titlebarIcon
= icon
;
232 bmp1
.CopyFromIcon(icon
);
234 m_titlebarIcon
= wxNullIcon
;
235 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
236 m_titlebarIcon
= icon
;
239 wxImage img
= bmp1
.ConvertToImage();
240 img
.Rescale(size
.x
, size
.y
);
241 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));