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 long styleOrig
, exstyleOrig
;
66 if ( ms_drawDecorations
== -1 )
67 ms_drawDecorations
= TRUE
;
68 // FIXME_MGL -- this is temporary; we assume for now that native TLW
69 // can't do decorations, which is not true
71 if ( ms_drawDecorations
)
74 exstyleOrig
= GetExtraStyle();
75 style
&= ~(wxCAPTION
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
76 wxSYSTEM_MENU
| wxRESIZE_BORDER
| wxFRAME_TOOL_WINDOW
|
78 style
= wxSIMPLE_BORDER
;
79 SetExtraStyle(exstyleOrig
&
80 ~(wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
));
83 if ( !wxTopLevelWindowNative::Create(parent
, id
, title
, pos
,
84 sizeOrig
, style
, name
) )
87 if ( ms_drawDecorations
)
89 m_windowStyle
= styleOrig
;
90 m_exStyle
= exstyleOrig
;
96 bool wxTopLevelWindow::ShowFullScreen(bool show
, long style
)
98 if ( show
== IsFullScreen() ) return FALSE
;
100 return wxTopLevelWindowNative::ShowFullScreen(show
, style
);
102 // FIXME_MGL -- must handle caption hiding here if not in
103 // native decorations mode
106 long wxTopLevelWindow::GetDecorationsStyle() const
110 if ( m_windowStyle
& wxCAPTION
)
112 style
|= wxTOPLEVEL_TITLEBAR
| wxTOPLEVEL_CLOSE_BUTTON
;
113 if ( m_windowStyle
& wxMINIMIZE_BOX
)
114 style
|= wxTOPLEVEL_MINIMIZE_BUTTON
;
115 if ( m_windowStyle
& wxMAXIMIZE_BOX
)
116 style
|= wxTOPLEVEL_MAXIMIZE_BUTTON
;
117 if ( m_exStyle
& (wxFRAME_EX_CONTEXTHELP
| wxDIALOG_EX_CONTEXTHELP
))
118 style
|= wxTOPLEVEL_HELP_BUTTON
;
120 if ( (m_windowStyle
& (wxSIMPLE_BORDER
| wxNO_BORDER
)) == 0 )
121 style
|= wxTOPLEVEL_BORDER
;
122 if ( m_windowStyle
& (wxRESIZE_BORDER
| wxTHICK_FRAME
) )
123 style
|= wxTOPLEVEL_RESIZEABLE
;
126 style
|= wxTOPLEVEL_MAXIMIZED
;
127 if ( GetIcon().Ok() )
128 style
|= wxTOPLEVEL_ICON
;
129 if ( /*m_isActive*/ 1 /* FIXME_MGL*/ )
130 style
|= wxTOPLEVEL_ACTIVE
;
135 // ----------------------------------------------------------------------------
136 // client area handling
137 // ----------------------------------------------------------------------------
139 wxPoint
wxTopLevelWindow::GetClientAreaOrigin() const
141 if ( ms_drawDecorations
)
144 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
145 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
147 rect
= m_renderer
->GetFrameClientArea(rect
,
148 GetDecorationsStyle());
149 return rect
.GetPosition();
153 return wxTopLevelWindowNative::GetClientAreaOrigin();
157 void wxTopLevelWindow::DoGetClientSize(int *width
, int *height
) const
159 if ( ms_drawDecorations
)
162 wxTopLevelWindowNative::DoGetClientSize(&w
, &h
);
163 wxRect rect
= wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
165 rect
= m_renderer
->GetFrameClientArea(rect
,
166 GetDecorationsStyle());
170 *height
= rect
.height
;
173 wxTopLevelWindowNative::DoGetClientSize(width
, height
);
176 void wxTopLevelWindow::DoSetClientSize(int width
, int height
)
178 if ( ms_drawDecorations
)
180 wxSize size
= m_renderer
->GetFrameTotalSize(wxSize(width
, height
),
181 GetDecorationsStyle());
182 wxTopLevelWindowNative::DoSetClientSize(size
.x
, size
.y
);
185 wxTopLevelWindowNative::DoSetClientSize(width
, height
);
188 void wxTopLevelWindow::OnNcPaint(wxPaintEvent
& event
)
190 if ( !ms_drawDecorations
|| !m_renderer
)
194 // get the window rect
196 wxSize size
= GetSize();
200 rect
.height
= size
.y
;
203 m_renderer
->DrawFrameTitleBar(dc
, rect
,
204 GetTitle(), m_titlebarIcon
,
205 GetDecorationsStyle());
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 void wxTopLevelWindow::SetIcon(const wxIcon
& icon
)
215 wxTopLevelWindowNative::SetIcon(icon
);
216 if ( !m_renderer
) return;
218 wxSize size
= m_renderer
->GetFrameIconSize();
220 if ( !icon
.Ok() || size
.x
== -1 )
221 m_titlebarIcon
= icon
;
225 bmp1
.CopyFromIcon(icon
);
227 m_titlebarIcon
= wxNullIcon
;
228 else if ( bmp1
.GetWidth() == size
.x
&& bmp1
.GetHeight() == size
.y
)
229 m_titlebarIcon
= icon
;
232 wxImage img
= bmp1
.ConvertToImage();
233 img
.Rescale(size
.x
, size
.y
);
234 m_titlebarIcon
.CopyFromBitmap(wxBitmap(img
));