]> git.saurik.com Git - wxWidgets.git/blame - src/univ/topluniv.cpp
added wxTreeEvent::GetKeyEvent() to allow to retrieve the key event flags from EVT_TR...
[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{
24a23c35
VS
64 long styleOrig, exstyleOrig;
65
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
70
71 if ( ms_drawDecorations )
72 {
73 styleOrig = style;
74 exstyleOrig = GetExtraStyle();
75 style &= ~(wxCAPTION | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
76 wxSYSTEM_MENU | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW |
77 wxTHICK_FRAME);
78 style = wxSIMPLE_BORDER;
79 SetExtraStyle(exstyleOrig &
80 ~(wxFRAME_EX_CONTEXTHELP | wxDIALOG_EX_CONTEXTHELP));
81 }
82
0f1bf77d
VS
83 if ( !wxTopLevelWindowNative::Create(parent, id, title, pos,
84 sizeOrig, style, name) )
85 return FALSE;
0f1bf77d 86
24a23c35
VS
87 if ( ms_drawDecorations )
88 {
89 m_windowStyle = styleOrig;
90 m_exStyle = exstyleOrig;
91 }
92
0f1bf77d
VS
93 return TRUE;
94}
95
96bool wxTopLevelWindow::ShowFullScreen(bool show, long style)
97{
98 if ( show == IsFullScreen() ) return FALSE;
99
100 return wxTopLevelWindowNative::ShowFullScreen(show, style);
101
102 // FIXME_MGL -- must handle caption hiding here if not in
103 // native decorations mode
104}
105
24a23c35
VS
106long wxTopLevelWindow::GetDecorationsStyle() const
107{
108 long style = 0;
109
110 if ( m_windowStyle & wxCAPTION )
111 {
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;
119 }
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;
124
125 if ( IsMaximized() )
126 style |= wxTOPLEVEL_MAXIMIZED;
127 if ( GetIcon().Ok() )
128 style |= wxTOPLEVEL_ICON;
129 if ( /*m_isActive*/ 1 /* FIXME_MGL*/ )
130 style |= wxTOPLEVEL_ACTIVE;
131
132 return style;
133}
134
135// ----------------------------------------------------------------------------
136// client area handling
137// ----------------------------------------------------------------------------
138
139wxPoint wxTopLevelWindow::GetClientAreaOrigin() const
140{
141 if ( ms_drawDecorations )
142 {
143 int w, h;
144 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
145 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
146 wxSize(w, h));
147 rect = m_renderer->GetFrameClientArea(rect,
148 GetDecorationsStyle());
149 return rect.GetPosition();
150 }
151 else
152 {
153 return wxTopLevelWindowNative::GetClientAreaOrigin();
154 }
155}
156
157void wxTopLevelWindow::DoGetClientSize(int *width, int *height) const
158{
159 if ( ms_drawDecorations )
160 {
161 int w, h;
162 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
163 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
164 wxSize(w, h));
165 rect = m_renderer->GetFrameClientArea(rect,
166 GetDecorationsStyle());
167 if ( width )
168 *width = rect.width;
169 if ( height )
170 *height = rect.height;
171 }
172 else
173 wxTopLevelWindowNative::DoGetClientSize(width, height);
174}
175
176void wxTopLevelWindow::DoSetClientSize(int width, int height)
177{
178 if ( ms_drawDecorations )
179 {
180 wxSize size = m_renderer->GetFrameTotalSize(wxSize(width, height),
181 GetDecorationsStyle());
182 wxTopLevelWindowNative::DoSetClientSize(size.x, size.y);
183 }
184 else
185 wxTopLevelWindowNative::DoSetClientSize(width, height);
186}
187
188void wxTopLevelWindow::OnNcPaint(wxPaintEvent& event)
189{
190 if ( !ms_drawDecorations || !m_renderer )
191 event.Skip();
192 else
193 {
194 // get the window rect
195 wxRect rect;
196 wxSize size = GetSize();
197 rect.x =
198 rect.y = 0;
199 rect.width = size.x;
200 rect.height = size.y;
201
202 wxWindowDC dc(this);
203 m_renderer->DrawFrameTitleBar(dc, rect,
204 GetTitle(), m_titlebarIcon,
205 GetDecorationsStyle());
206 }
207}
208
209// ----------------------------------------------------------------------------
210// icons
211// ----------------------------------------------------------------------------
212
213void wxTopLevelWindow::SetIcon(const wxIcon& icon)
214{
215 wxTopLevelWindowNative::SetIcon(icon);
216 if ( !m_renderer ) return;
217
218 wxSize size = m_renderer->GetFrameIconSize();
219
220 if ( !icon.Ok() || size.x == -1 )
221 m_titlebarIcon = icon;
222 else
223 {
224 wxBitmap bmp1;
225 bmp1.CopyFromIcon(icon);
226 if ( !bmp1.Ok() )
227 m_titlebarIcon = wxNullIcon;
228 else if ( bmp1.GetWidth() == size.x && bmp1.GetHeight() == size.y )
229 m_titlebarIcon = icon;
230 else
231 {
232 wxImage img = bmp1.ConvertToImage();
233 img.Rescale(size.x, size.y);
234 m_titlebarIcon.CopyFromBitmap(wxBitmap(img));
235 }
236 }
237}