]> git.saurik.com Git - wxWidgets.git/blame - src/univ/topluniv.cpp
applied patch for regex building with BC++ (patch 463140)
[wxWidgets.git] / src / univ / topluniv.cpp
CommitLineData
0f1bf77d
VS
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"
24a23c35
VS
30#include "wx/univ/renderer.h"
31#include "wx/dcclient.h"
32#include "wx/bitmap.h"
33#include "wx/image.h"
0f1bf77d
VS
34
35
36// ----------------------------------------------------------------------------
37// event tables
38// ----------------------------------------------------------------------------
39
24a23c35
VS
40BEGIN_EVENT_TABLE(wxTopLevelWindow, wxTopLevelWindowNative)
41 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint)
42END_EVENT_TABLE()
43
0f1bf77d
VS
44
45// ============================================================================
46// implementation
47// ============================================================================
48
24a23c35
VS
49int wxTopLevelWindow::ms_drawDecorations = -1;
50
0f1bf77d
VS
51void wxTopLevelWindow::Init()
52{
24a23c35 53 m_isActive = FALSE;
0f1bf77d
VS
54}
55
56bool wxTopLevelWindow::Create(wxWindow *parent,
57 wxWindowID id,
58 const wxString& title,
59 const wxPoint& pos,
60 const wxSize& sizeOrig,
61 long style,
62 const wxString &name)
63{
2e9f62da
VZ
64 // init them to avoid compiler warnings
65 long styleOrig = 0,
66 exstyleOrig = 0;
24a23c35
VS
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
0f1bf77d
VS
85 if ( !wxTopLevelWindowNative::Create(parent, id, title, pos,
86 sizeOrig, style, name) )
87 return FALSE;
0f1bf77d 88
24a23c35
VS
89 if ( ms_drawDecorations )
90 {
91 m_windowStyle = styleOrig;
92 m_exStyle = exstyleOrig;
93 }
94
0f1bf77d
VS
95 return TRUE;
96}
97
98bool wxTopLevelWindow::ShowFullScreen(bool show, long style)
99{
2e9f62da
VZ
100 // VZ: doesn't compile
101#if 0
0f1bf77d
VS
102 if ( show == IsFullScreen() ) return FALSE;
103
104 return wxTopLevelWindowNative::ShowFullScreen(show, style);
105
106 // FIXME_MGL -- must handle caption hiding here if not in
107 // native decorations mode
2e9f62da
VZ
108#endif // 0
109
110 return FALSE;
0f1bf77d
VS
111}
112
24a23c35
VS
113long wxTopLevelWindow::GetDecorationsStyle() const
114{
115 long style = 0;
116
117 if ( m_windowStyle & wxCAPTION )
118 {
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;
126 }
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;
131
132 if ( IsMaximized() )
133 style |= wxTOPLEVEL_MAXIMIZED;
134 if ( GetIcon().Ok() )
135 style |= wxTOPLEVEL_ICON;
136 if ( /*m_isActive*/ 1 /* FIXME_MGL*/ )
137 style |= wxTOPLEVEL_ACTIVE;
138
139 return style;
140}
141
142// ----------------------------------------------------------------------------
143// client area handling
144// ----------------------------------------------------------------------------
145
146wxPoint wxTopLevelWindow::GetClientAreaOrigin() const
147{
148 if ( ms_drawDecorations )
149 {
150 int w, h;
151 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
152 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
153 wxSize(w, h));
154 rect = m_renderer->GetFrameClientArea(rect,
155 GetDecorationsStyle());
156 return rect.GetPosition();
157 }
158 else
159 {
160 return wxTopLevelWindowNative::GetClientAreaOrigin();
161 }
162}
163
164void wxTopLevelWindow::DoGetClientSize(int *width, int *height) const
165{
166 if ( ms_drawDecorations )
167 {
168 int w, h;
169 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
170 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
171 wxSize(w, h));
172 rect = m_renderer->GetFrameClientArea(rect,
173 GetDecorationsStyle());
174 if ( width )
175 *width = rect.width;
176 if ( height )
177 *height = rect.height;
178 }
179 else
180 wxTopLevelWindowNative::DoGetClientSize(width, height);
181}
182
183void wxTopLevelWindow::DoSetClientSize(int width, int height)
184{
185 if ( ms_drawDecorations )
186 {
187 wxSize size = m_renderer->GetFrameTotalSize(wxSize(width, height),
188 GetDecorationsStyle());
189 wxTopLevelWindowNative::DoSetClientSize(size.x, size.y);
190 }
191 else
192 wxTopLevelWindowNative::DoSetClientSize(width, height);
193}
194
195void wxTopLevelWindow::OnNcPaint(wxPaintEvent& event)
196{
197 if ( !ms_drawDecorations || !m_renderer )
198 event.Skip();
199 else
200 {
201 // get the window rect
202 wxRect rect;
203 wxSize size = GetSize();
204 rect.x =
205 rect.y = 0;
206 rect.width = size.x;
207 rect.height = size.y;
208
209 wxWindowDC dc(this);
210 m_renderer->DrawFrameTitleBar(dc, rect,
211 GetTitle(), m_titlebarIcon,
212 GetDecorationsStyle());
213 }
214}
215
216// ----------------------------------------------------------------------------
217// icons
218// ----------------------------------------------------------------------------
219
220void wxTopLevelWindow::SetIcon(const wxIcon& icon)
221{
222 wxTopLevelWindowNative::SetIcon(icon);
223 if ( !m_renderer ) return;
224
225 wxSize size = m_renderer->GetFrameIconSize();
226
227 if ( !icon.Ok() || size.x == -1 )
228 m_titlebarIcon = icon;
229 else
230 {
231 wxBitmap bmp1;
232 bmp1.CopyFromIcon(icon);
233 if ( !bmp1.Ok() )
234 m_titlebarIcon = wxNullIcon;
235 else if ( bmp1.GetWidth() == size.x && bmp1.GetHeight() == size.y )
236 m_titlebarIcon = icon;
237 else
238 {
239 wxImage img = bmp1.ConvertToImage();
240 img.Rescale(size.x, size.y);
241 m_titlebarIcon.CopyFromBitmap(wxBitmap(img));
242 }
243 }
244}