1/////////////////////////////////////////////////////////////////////////////
2// Name:        app.h
3// Purpose:     wxApp class
4// Author:      Julian Smart
5// Modified by:
6// Created:     01/02/97
7// RCS-ID:      $Id: app.h 53157 2008-04-13 12:17:37Z VS $
8// Copyright:   (c) Julian Smart
9// Licence:     wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_APP_H_
13#define _WX_APP_H_
14
15#include "wx/event.h"
16#include "wx/icon.h"
17
18class WXDLLIMPEXP_FWD_CORE wxFrame;
19class WXDLLIMPEXP_FWD_CORE wxWindow;
20class WXDLLIMPEXP_FWD_CORE wxApp;
21class WXDLLIMPEXP_FWD_CORE wxKeyEvent;
22class WXDLLIMPEXP_FWD_BASE wxLog;
23
24// Represents the application. Derive OnInit and declare
25// a new App object to start application
26class WXDLLEXPORT wxApp : public wxAppBase
27{
28    DECLARE_DYNAMIC_CLASS(wxApp)
29
30public:
31    wxApp();
32    virtual ~wxApp();
33
34    // override base class (pure) virtuals
35    virtual bool Initialize(int& argc, wxChar **argv);
36    virtual void CleanUp();
37
38    virtual bool Yield(bool onlyIfNeeded = false);
39    virtual void WakeUpIdle();
40
41    virtual void SetPrintMode(int mode) { m_printMode = mode; }
42    virtual int GetPrintMode() const { return m_printMode; }
43
44    // implementation only
45    void OnIdle(wxIdleEvent& event);
46    void OnEndSession(wxCloseEvent& event);
47    void OnQueryEndSession(wxCloseEvent& event);
48
49#if wxUSE_EXCEPTIONS
50    virtual bool OnExceptionInMainLoop();
51#endif // wxUSE_EXCEPTIONS
52
53    // deprecated functions, use wxEventLoop directly instead
54#if WXWIN_COMPATIBILITY_2_4
55    wxDEPRECATED( void DoMessage(WXMSG *pMsg) );
56    wxDEPRECATED( bool DoMessage() );
57    wxDEPRECATED( bool ProcessMessage(WXMSG* pMsg) );
58#endif // WXWIN_COMPATIBILITY_2_4
59
60protected:
61    int    m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT
62
63public:
64    // Implementation
65    static bool RegisterWindowClasses();
66    static bool UnregisterWindowClasses();
67
68#if wxUSE_RICHEDIT
69    // initialize the richedit DLL of (at least) given version, return true if
70    // ok (Win95 has version 1, Win98/NT4 has 1 and 2, W2K has 3)
71    static bool InitRichEdit(int version = 2);
72#endif // wxUSE_RICHEDIT
73
74    // returns 400, 470, 471 for comctl32.dll 4.00, 4.70, 4.71 or 0 if it
75    // wasn't found at all
76    static int GetComCtl32Version();
77
78    // the SW_XXX value to be used for the frames opened by the application
79    // (currently seems unused which is a bug -- TODO)
80    static int m_nCmdShow;
81
82protected:
83    DECLARE_EVENT_TABLE()
84    DECLARE_NO_COPY_CLASS(wxApp)
85};
86
87// ----------------------------------------------------------------------------
88// MSW-specific wxEntry() overload and IMPLEMENT_WXWIN_MAIN definition
89// ----------------------------------------------------------------------------
90
91// we need HINSTANCE declaration to define WinMain()
92#include "wx/msw/wrapwin.h"
93
94#ifndef SW_SHOWNORMAL
95    #define SW_SHOWNORMAL 1
96#endif
97
98// WinMain() is always ANSI, even in Unicode build, under normal Windows
99// but is always Unicode under CE
100#ifdef __WXWINCE__
101    typedef wchar_t *wxCmdLineArgType;
102#else
103    typedef char *wxCmdLineArgType;
104#endif
105
106extern int WXDLLEXPORT
107wxEntry(HINSTANCE hInstance,
108        HINSTANCE hPrevInstance = NULL,
109        wxCmdLineArgType pCmdLine = NULL,
110        int nCmdShow = SW_SHOWNORMAL);
111
112#if defined(__BORLANDC__) && wxUSE_UNICODE
113    // Borland C++ has the following nonstandard behaviour: when the -WU
114    // command line flag is used, the linker expects to find wWinMain instead
115    // of WinMain. This flag causes the compiler to define _UNICODE and
116    // UNICODE symbols and there's no way to detect its use, so we have to
117    // define both WinMain and wWinMain so that IMPLEMENT_WXWIN_MAIN works
118    // for both code compiled with and without -WU.
119    // See http://sourceforge.net/tracker/?func=detail&atid=309863&aid=1935997&group_id=9863
120    // for more details.
121    #define IMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD                        \
122        extern "C" int WINAPI wWinMain(HINSTANCE hInstance,                 \
123                                      HINSTANCE hPrevInstance,              \
124                                      wchar_t * WXUNUSED(lpCmdLine),        \
125                                      int nCmdShow)                         \
126        {                                                                   \
127            /* NB: wxEntry expects lpCmdLine argument to be char*, not */   \
128            /*     wchar_t*, but fortunately it's not used anywhere    */   \
129            /*     and we can simply pass NULL in:                     */   \
130            return wxEntry(hInstance, hPrevInstance, NULL, nCmdShow);       \
131        }
132#else
133    #define IMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD
134#endif // defined(__BORLANDC__) && wxUSE_UNICODE
135
136#define IMPLEMENT_WXWIN_MAIN \
137    extern "C" int WINAPI WinMain(HINSTANCE hInstance,                    \
138                                  HINSTANCE hPrevInstance,                \
139                                  wxCmdLineArgType lpCmdLine,             \
140                                  int nCmdShow)                           \
141    {                                                                     \
142        return wxEntry(hInstance, hPrevInstance, lpCmdLine, nCmdShow);    \
143    }                                                                     \
144    IMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD
145
146#endif // _WX_APP_H_
147
148