]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/app.cpp
Allow entering minus sign in wxMSW wxSpinCtrl if needed.
[wxWidgets.git] / src / mgl / app.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/mgl/app.cpp
32b8ec41 3// Author: Vaclav Slavik
7bdc1879 4// based on GTK and MSW implementations
32b8ec41 5// Id: $Id$
c41c20a5 6// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
65571936 7// Licence: wxWindows licence
32b8ec41
VZ
8/////////////////////////////////////////////////////////////////////////////
9
7bdc1879
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
670f9935 17#include "wx/app.h"
2ec3892d 18
7bdc1879
VS
19#ifndef WX_PRECOMP
20 #include "wx/settings.h"
7bdc1879
VS
21 #include "wx/frame.h"
22 #include "wx/dialog.h"
2ec3892d 23 #include "wx/log.h"
7bdc1879 24 #include "wx/intl.h"
02761f6c 25 #include "wx/module.h"
7bdc1879 26#endif
32b8ec41 27
90eb13e6 28#include "wx/evtloop.h"
ef344ff8 29#include "wx/fontutil.h"
df028524
VS
30#include "wx/univ/theme.h"
31#include "wx/univ/renderer.h"
58061670 32#include "wx/univ/colschem.h"
05c9ccbe 33#include "wx/sysopt.h"
7bdc1879 34#include "wx/mgl/private.h"
d7ae4a62 35#include "wx/private/fontmgr.h"
32b8ec41
VZ
36
37//-----------------------------------------------------------------------------
505f0a85 38// wxApp::Exit()
32b8ec41
VZ
39//-----------------------------------------------------------------------------
40
e2478fde 41void wxApp::Exit()
32b8ec41 42{
7bdc1879 43 MGL_exit();
32b8ec41
VZ
44 exit(0);
45}
46
7bdc1879 47
32b8ec41
VZ
48//-----------------------------------------------------------------------------
49// wxWakeUpIdle
50//-----------------------------------------------------------------------------
51
e2478fde 52void wxApp::WakeUpIdle()
32b8ec41 53{
7bdc1879
VS
54#if wxUSE_THREADS
55 if (!wxThread::IsMain())
56 wxMutexGuiEnter();
57#endif
58
e2478fde
VZ
59 while (wxTheApp->ProcessIdle())
60 ;
7bdc1879
VS
61
62#if wxUSE_THREADS
63 if (!wxThread::IsMain())
64 wxMutexGuiLeave();
65#endif
32b8ec41
VZ
66}
67
58061670
VS
68//-----------------------------------------------------------------------------
69// Root window
70//-----------------------------------------------------------------------------
71
72class wxRootWindow : public wxWindow
73{
74 public:
0471d486 75 wxRootWindow() : wxWindow(NULL, wxID_ANY)
58061670
VS
76 {
77 SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng));
78 SetBackgroundColour(wxTHEME_COLOUR(DESKTOP));
79 }
d3c7fc99 80 virtual ~wxRootWindow()
58061670
VS
81 {
82 // we don't want to delete MGL_WM's rootWnd
7c9955d1 83 m_wnd = NULL;
58061670
VS
84 }
85
0471d486 86 virtual bool AcceptsFocus() const { return false; }
7c9955d1 87
b7d5acd0 88 DECLARE_DYNAMIC_CLASS(wxRootWindow)
58061670
VS
89};
90
b7d5acd0
VS
91IMPLEMENT_DYNAMIC_CLASS(wxRootWindow, wxWindow)
92
58061670
VS
93static wxRootWindow *gs_rootWindow = NULL;
94
95//-----------------------------------------------------------------------------
96// MGL initialization
97//-----------------------------------------------------------------------------
98
fedec981 99static bool wxCreateMGL_WM(const wxVideoMode& displayMode)
58061670
VS
100{
101 int mode;
58061670 102 int refresh = MGL_DEFAULT_REFRESH;
7c9955d1 103
58061670 104#if wxUSE_SYSTEM_OPTIONS
05c9ccbe 105 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) )
58061670
VS
106 refresh = wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
107#endif
7c9955d1
JS
108
109 mode = MGL_findMode(displayMode.GetWidth(),
110 displayMode.GetHeight(),
634f6a1f 111 displayMode.GetDepth());
58061670
VS
112 if ( mode == -1 )
113 {
7c9955d1 114 wxLogError(_("Mode %ix%i-%i not available."),
d76048f5
VS
115 displayMode.GetWidth(),
116 displayMode.GetHeight(),
634f6a1f 117 displayMode.GetDepth());
0471d486 118 return false;
58061670
VS
119 }
120 g_displayDC = new MGLDisplayDC(mode, 1, refresh);
121 if ( !g_displayDC->isValid() )
122 {
123 delete g_displayDC;
124 g_displayDC = NULL;
0471d486 125 return false;
58061670 126 }
7c9955d1 127
58061670
VS
128 g_winMng = MGL_wmCreate(g_displayDC->getDC());
129 if (!g_winMng)
0471d486 130 return false;
1f43b5c9 131
0471d486 132 return true;
58061670
VS
133}
134
135static void wxDestroyMGL_WM()
136{
137 if ( g_winMng )
138 {
139 MGL_wmDestroy(g_winMng);
140 g_winMng = NULL;
141 }
142 if ( g_displayDC )
143 {
144 delete g_displayDC;
145 g_displayDC = NULL;
146 }
147}
148
32b8ec41
VZ
149//-----------------------------------------------------------------------------
150// wxApp
151//-----------------------------------------------------------------------------
152
153IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
154
752464f9 155wxApp::wxApp()
7bdc1879
VS
156{
157}
158
159wxApp::~wxApp()
160{
161}
162
fedec981 163wxVideoMode wxGetDefaultDisplayMode()
a3e76614
VS
164{
165 wxString mode;
166 unsigned w, h, bpp;
167
7c9955d1 168 if ( !wxGetEnv(wxT("WXMODE"), &mode) ||
9a83f860 169 (wxSscanf(mode.c_str(), wxT("%ux%u-%u"), &w, &h, &bpp) != 3) )
a3e76614
VS
170 {
171 w = 640, h = 480, bpp = 16;
172 }
173
fedec981 174 return wxVideoMode(w, h, bpp);
a3e76614
VS
175}
176
fedec981 177bool wxApp::SetDisplayMode(const wxVideoMode& mode)
634f6a1f
VS
178{
179 if ( !mode.IsOk() )
180 {
0471d486 181 return false;
634f6a1f
VS
182 }
183 if ( g_displayDC != NULL )
184 {
185 // FIXME_MGL -- we currently don't allow to switch video mode
1f43b5c9 186 // more than once. This can hopefully be changed...
634f6a1f 187 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
0471d486 188 return false;
634f6a1f 189 }
1f43b5c9
VS
190
191 if ( !wxCreateMGL_WM(mode) )
0471d486 192 return false;
1f43b5c9
VS
193 gs_rootWindow = new wxRootWindow;
194
634f6a1f 195 m_displayMode = mode;
1f43b5c9 196
0471d486 197 return true;
634f6a1f
VS
198}
199
7bdc1879
VS
200bool wxApp::OnInitGui()
201{
7bdc1879 202 if ( !wxAppBase::OnInitGui() )
0471d486 203 return false;
7bdc1879 204
d76048f5 205 // MGL redirects stdout and stderr to physical console, so lets redirect
4b6a582b
VZ
206 // it to file if WXSTDERR environment variable is set to be able to see
207 // wxLogDebug() output
343e418c
VS
208 wxString redirect;
209 if ( wxGetEnv(wxT("WXSTDERR"), &redirect) )
210 freopen(redirect.mb_str(), "wt", stderr);
2ec3892d 211
d76048f5
VS
212 wxLog *oldLog = wxLog::SetActiveTarget(new wxLogGui);
213 if ( oldLog ) delete oldLog;
214
0471d486 215 return true;
7bdc1879
VS
216}
217
05e2b077 218bool wxApp::Initialize(int& argc, wxChar **argv)
7bdc1879 219{
05e2b077
VZ
220#ifdef __DJGPP__
221 // VS: disable long filenames under DJGPP as the very first thing,
222 // since SciTech MGL doesn't like them much...
223 wxSetEnv(wxT("LFN"), wxT("N"));
224#endif
225
79481be2
MW
226 // intialize MGL before creating wxFontsManager since it uses MGL funcs
227 if ( MGL_init(".", NULL) == 0 )
228 {
229 wxLogError(_("Cannot initialize SciTech MGL!"));
230 return false;
231 }
232
94826170 233 if ( !wxAppBase::Initialize(argc, argv) )
ddfca47f 234 {
79481be2 235 MGL_exit();
94826170
VZ
236 return false;
237 }
7bdc1879 238
7bdc1879
VS
239#if wxUSE_INTL
240 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
241#endif
242
94826170 243 return true;
32b8ec41
VZ
244}
245
bfb8eb7e
MW
246// Modules are cleaned up after wxApp::CleanUp(), and some modules may
247// require MGL to still be alive, e.g. the stock fonts need the fonts
248// manager. So append this module last minute in wxApp::CleanUp() to close
249// down MGL after all the other modules have been cleaned up.
250//
251struct wxMGLFinalCleanup: public wxModule
252{
253 bool OnInit() { return true; }
254
255 void OnExit()
256 {
d7ae4a62 257 wxFontsManager::CleanUp();
bfb8eb7e
MW
258
259 wxDestroyMGL_WM();
260 MGL_exit();
261 }
262};
263
7bdc1879
VS
264void wxApp::CleanUp()
265{
d76048f5
VS
266 delete gs_rootWindow;
267
94826170 268 wxAppBase::CleanUp();
7bdc1879 269
bfb8eb7e 270 wxModule::RegisterModule(new wxMGLFinalCleanup);
7bdc1879 271}