partial implementation of wxTLW's decorations
[wxWidgets.git] / src / univ / topluniv.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: topluniv.cpp
3 // Author: Vaclav Slavik
4 // Id: $Id$
5 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 // ============================================================================
10 // declarations
11 // ============================================================================
12
13 // ----------------------------------------------------------------------------
14 // headers
15 // ----------------------------------------------------------------------------
16
17 #ifdef __GNUG__
18 #pragma implementation "univtoplevel.h"
19 #endif
20
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
23
24 #ifdef __BORLANDC__
25 #pragma hdrstop
26 #endif
27
28 #include "wx/defs.h"
29 #include "wx/toplevel.h"
30 #include "wx/univ/renderer.h"
31 #include "wx/dcclient.h"
32 #include "wx/bitmap.h"
33 #include "wx/image.h"
34
35
36 // ----------------------------------------------------------------------------
37 // event tables
38 // ----------------------------------------------------------------------------
39
40 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
41
42 BEGIN_EVENT_TABLE(wxTopLevelWindow, wxTopLevelWindowNative)
43 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint)
44 END_EVENT_TABLE()
45
46
47 // ============================================================================
48 // implementation
49 // ============================================================================
50
51 int wxTopLevelWindow::ms_drawDecorations = -1;
52
53 void wxTopLevelWindow::Init()
54 {
55 m_isActive = FALSE;
56 }
57
58 bool wxTopLevelWindow::Create(wxWindow *parent,
59 wxWindowID id,
60 const wxString& title,
61 const wxPoint& pos,
62 const wxSize& sizeOrig,
63 long style,
64 const wxString &name)
65 {
66 long styleOrig, exstyleOrig;
67
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
72
73 if ( ms_drawDecorations )
74 {
75 styleOrig = style;
76 exstyleOrig = GetExtraStyle();
77 style &= ~(wxCAPTION | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
78 wxSYSTEM_MENU | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW |
79 wxTHICK_FRAME);
80 style = wxSIMPLE_BORDER;
81 SetExtraStyle(exstyleOrig &
82 ~(wxFRAME_EX_CONTEXTHELP | wxDIALOG_EX_CONTEXTHELP));
83 }
84
85 if ( !wxTopLevelWindowNative::Create(parent, id, title, pos,
86 sizeOrig, style, name) )
87 return FALSE;
88
89 if ( ms_drawDecorations )
90 {
91 m_windowStyle = styleOrig;
92 m_exStyle = exstyleOrig;
93 }
94
95 return TRUE;
96 }
97
98 bool wxTopLevelWindow::ShowFullScreen(bool show, long style)
99 {
100 if ( show == IsFullScreen() ) return FALSE;
101
102 return wxTopLevelWindowNative::ShowFullScreen(show, style);
103
104 // FIXME_MGL -- must handle caption hiding here if not in
105 // native decorations mode
106 }
107
108 long wxTopLevelWindow::GetDecorationsStyle() const
109 {
110 long style = 0;
111
112 if ( m_windowStyle & wxCAPTION )
113 {
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;
121 }
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;
126
127 if ( IsMaximized() )
128 style |= wxTOPLEVEL_MAXIMIZED;
129 if ( GetIcon().Ok() )
130 style |= wxTOPLEVEL_ICON;
131 if ( /*m_isActive*/ 1 /* FIXME_MGL*/ )
132 style |= wxTOPLEVEL_ACTIVE;
133
134 return style;
135 }
136
137 // ----------------------------------------------------------------------------
138 // client area handling
139 // ----------------------------------------------------------------------------
140
141 wxPoint wxTopLevelWindow::GetClientAreaOrigin() const
142 {
143 if ( ms_drawDecorations )
144 {
145 int w, h;
146 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
147 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
148 wxSize(w, h));
149 rect = m_renderer->GetFrameClientArea(rect,
150 GetDecorationsStyle());
151 return rect.GetPosition();
152 }
153 else
154 {
155 return wxTopLevelWindowNative::GetClientAreaOrigin();
156 }
157 }
158
159 void wxTopLevelWindow::DoGetClientSize(int *width, int *height) const
160 {
161 if ( ms_drawDecorations )
162 {
163 int w, h;
164 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
165 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
166 wxSize(w, h));
167 rect = m_renderer->GetFrameClientArea(rect,
168 GetDecorationsStyle());
169 if ( width )
170 *width = rect.width;
171 if ( height )
172 *height = rect.height;
173 }
174 else
175 wxTopLevelWindowNative::DoGetClientSize(width, height);
176 }
177
178 void wxTopLevelWindow::DoSetClientSize(int width, int height)
179 {
180 if ( ms_drawDecorations )
181 {
182 wxSize size = m_renderer->GetFrameTotalSize(wxSize(width, height),
183 GetDecorationsStyle());
184 wxTopLevelWindowNative::DoSetClientSize(size.x, size.y);
185 }
186 else
187 wxTopLevelWindowNative::DoSetClientSize(width, height);
188 }
189
190 void wxTopLevelWindow::OnNcPaint(wxPaintEvent& event)
191 {
192 if ( !ms_drawDecorations || !m_renderer )
193 event.Skip();
194 else
195 {
196 // get the window rect
197 wxRect rect;
198 wxSize size = GetSize();
199 rect.x =
200 rect.y = 0;
201 rect.width = size.x;
202 rect.height = size.y;
203
204 wxWindowDC dc(this);
205 m_renderer->DrawFrameTitleBar(dc, rect,
206 GetTitle(), m_titlebarIcon,
207 GetDecorationsStyle());
208 }
209 }
210
211 // ----------------------------------------------------------------------------
212 // icons
213 // ----------------------------------------------------------------------------
214
215 void wxTopLevelWindow::SetIcon(const wxIcon& icon)
216 {
217 wxTopLevelWindowNative::SetIcon(icon);
218 if ( !m_renderer ) return;
219
220 wxSize size = m_renderer->GetFrameIconSize();
221
222 if ( !icon.Ok() || size.x == -1 )
223 m_titlebarIcon = icon;
224 else
225 {
226 wxBitmap bmp1;
227 bmp1.CopyFromIcon(icon);
228 if ( !bmp1.Ok() )
229 m_titlebarIcon = wxNullIcon;
230 else if ( bmp1.GetWidth() == size.x && bmp1.GetHeight() == size.y )
231 m_titlebarIcon = icon;
232 else
233 {
234 wxImage img = bmp1.ConvertToImage();
235 img.Rescale(size.x, size.y);
236 m_titlebarIcon.CopyFromBitmap(wxBitmap(img));
237 }
238 }
239 }