diff --git a/uppsrc/Core/App.cpp b/uppsrc/Core/App.cpp index c75a39df8..3c63d41de 100644 --- a/uppsrc/Core/App.cpp +++ b/uppsrc/Core/App.cpp @@ -305,6 +305,23 @@ void CommonInit() sMainRunning = true; } +void Exit(int code) +{ + SetExitCode(code); + throw ExitExc(); +} + +void AppExecute__(void (*app)()) +{ + try { + (*app)(); + } + catch(Exc e) { + Panic(e); + } + catch(ExitExc) {} +} + #ifdef PLATFORM_POSIX void s_ill_handler(int) diff --git a/uppsrc/Core/App.h b/uppsrc/Core/App.h index 15e0d7034..cb34c48e1 100644 --- a/uppsrc/Core/App.h +++ b/uppsrc/Core/App.h @@ -31,7 +31,12 @@ bool IsMainRunning(); //void Main(); // By console application #endif +struct ExitExc {}; + +void Exit(int code = 1); + void AppExit__(); +void AppExecute__(void (*app)()); #ifdef PLATFORM_WIN32 @@ -42,16 +47,11 @@ void AppInitEnvironment__(); void ConsoleMainFn_(); \ \ int main(int argc, char *argv[]) { \ - try { \ - UPP::AppInit__(argc, (const char **)argv); \ - ConsoleMainFn_(); \ - UPP::DeleteUsrLog(); \ - UPP::AppExit__(); \ - return UPP::GetExitCode(); \ - } \ - catch(Exc e) { \ - Panic(e); \ - } \ + UPP::AppInit__(argc, (const char **)argv); \ + UPP::AppExecute__(ConsoleMainFn_); \ + UPP::DeleteUsrLog(); \ + UPP::AppExit__(); \ + return UPP::GetExitCode(); \ } \ \ void ConsoleMainFn_() @@ -67,7 +67,7 @@ void ConsoleMainFn_(); \ \ int main(int argc, const char **argv, const char **envptr) { \ UPP::AppInit__(argc, argv, envptr); \ - ConsoleMainFn_(); \ + UPP::AppExecute__(ConsoleMainFn_); \ UPP::DeleteUsrLog(); \ UPP::AppExit__(); \ return UPP::GetExitCode(); \ diff --git a/uppsrc/CtrlCore/Win32GuiA.h b/uppsrc/CtrlCore/Win32GuiA.h index d094ce64f..0bb49f83d 100644 --- a/uppsrc/CtrlCore/Win32GuiA.h +++ b/uppsrc/CtrlCore/Win32GuiA.h @@ -1,112 +1,107 @@ -class ViewDraw : public SystemDraw { -public: - ViewDraw(Ctrl *ctrl); - ~ViewDraw(); - -protected: - HWND hwnd; -}; - - -Vector& coreCmdLine__(); -Vector SplitCmdLine__(const char *cmd); - -#ifdef PLATFORM_WINCE - -#define GUI_APP_MAIN \ -void GuiMainFn_();\ -\ -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow) \ -{ \ - UPP::Ctrl::InitWin32(hInstance); \ - UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \ - UPP::AppInitEnvironment__(); \ - try { \ - GuiMainFn_(); \ - } \ - catch(Exc e) { \ - Panic(e); \ - } \ - UPP::UsrLog("---------- About to delete this log..."); \ - UPP::DeleteUsrLog(); \ - UPP::Ctrl::ExitWin32(); \ - UPP::AppExit__(); \ - return UPP::GetExitCode(); \ -} \ -\ -void GuiMainFn_() - -#else - -#define GUI_APP_MAIN \ -void GuiMainFn_();\ -\ -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) \ -{ \ - UPP::Ctrl::InitWin32(hInstance); \ - UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \ - UPP::AppInitEnvironment__(); \ - try { \ - GuiMainFn_(); \ - } \ - catch(Exc e) { \ - Panic(e); \ - } \ - UPP::Ctrl::CloseTopCtrls(); \ - UPP::UsrLog("---------- About to delete this log..."); \ - UPP::DeleteUsrLog(); \ - UPP::Ctrl::ExitWin32(); \ - UPP::AppExit__(); \ - return UPP::GetExitCode(); \ -} \ -\ -void GuiMainFn_() - -#define DLL_APP_MAIN \ -void _DllMainAppInit(); \ -\ -BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved) \ -{ \ - if(fdwReason == DLL_PROCESS_ATTACH) { \ - Ctrl::InitWin32(AppGetHandle()); \ - AppInitEnvironment__(); \ - _DllMainAppInit(); \ - } \ - else \ - if(fdwReason == DLL_PROCESS_DETACH) { \ - Ctrl::ExitWin32(); \ - } \ - return true; \ -} \ -\ -void _DllMainAppInit() - -#endif - -#ifndef PLATFORM_WINCE - -class DHCtrl : public Ctrl { -public: - virtual void State(int reason); - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - virtual void NcCreate(HWND hwnd); - virtual void NcDestroy(); - -private: - void OpenHWND(); - void SyncHWND(); - -protected: - void CloseHWND(); - HWND hwnd; - -public: - HWND GetHWND() { return hwnd; } -// void Refresh() { InvalidateRect(GetHWND(), NULL, false); } - - DHCtrl(); - ~DHCtrl(); -}; - -#endif - +class ViewDraw : public SystemDraw { +public: + ViewDraw(Ctrl *ctrl); + ~ViewDraw(); + +protected: + HWND hwnd; +}; + + +Vector& coreCmdLine__(); +Vector SplitCmdLine__(const char *cmd); + +#ifdef PLATFORM_WINCE + +#define GUI_APP_MAIN \ +void GuiMainFn_();\ +\ +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow) \ +{ \ + UPP::Ctrl::InitWin32(hInstance); \ + UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \ + UPP::AppInitEnvironment__(); \ + try { \ + GuiMainFn_(); \ + } \ + catch(Exc e) { \ + Panic(e); \ + } \ + UPP::UsrLog("---------- About to delete this log..."); \ + UPP::DeleteUsrLog(); \ + UPP::Ctrl::ExitWin32(); \ + UPP::AppExit__(); \ + return UPP::GetExitCode(); \ +} \ +\ +void GuiMainFn_() + +#else + +#define GUI_APP_MAIN \ +void GuiMainFn_();\ +\ +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) \ +{ \ + UPP::Ctrl::InitWin32(hInstance); \ + UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \ + UPP::AppInitEnvironment__(); \ + UPP::AppExecute__(GuiMainFn_); \ + UPP::Ctrl::CloseTopCtrls(); \ + UPP::UsrLog("---------- About to delete this log..."); \ + UPP::DeleteUsrLog(); \ + UPP::Ctrl::ExitWin32(); \ + UPP::AppExit__(); \ + return UPP::GetExitCode(); \ +} \ +\ +void GuiMainFn_() + +#define DLL_APP_MAIN \ +void _DllMainAppInit(); \ +\ +BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved) \ +{ \ + if(fdwReason == DLL_PROCESS_ATTACH) { \ + Ctrl::InitWin32(AppGetHandle()); \ + AppInitEnvironment__(); \ + UPP::AppExecute__(_DllMainAppInit); \ + } \ + else \ + if(fdwReason == DLL_PROCESS_DETACH) { \ + Ctrl::ExitWin32(); \ + } \ + return true; \ +} \ +\ +void _DllMainAppInit() + +#endif + +#ifndef PLATFORM_WINCE + +class DHCtrl : public Ctrl { +public: + virtual void State(int reason); + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + virtual void NcCreate(HWND hwnd); + virtual void NcDestroy(); + +private: + void OpenHWND(); + void SyncHWND(); + +protected: + void CloseHWND(); + HWND hwnd; + +public: + HWND GetHWND() { return hwnd; } +// void Refresh() { InvalidateRect(GetHWND(), NULL, false); } + + DHCtrl(); + ~DHCtrl(); +}; + +#endif + diff --git a/uppsrc/CtrlCore/X11GuiA.h b/uppsrc/CtrlCore/X11GuiA.h index 2d18e03c9..dafca1e95 100644 --- a/uppsrc/CtrlCore/X11GuiA.h +++ b/uppsrc/CtrlCore/X11GuiA.h @@ -1,74 +1,69 @@ -class ViewDraw : public SystemDraw { -public: - ViewDraw(Ctrl *ctrl); - ~ViewDraw(); - -protected: - bool caret; -}; - - -#define GUI_APP_MAIN \ -void GuiMainFn_(); \ -\ -int main(int argc, const char **argv, const char **envptr) { \ - UPP::AppInit__(argc, argv, envptr); \ - UPP::Ctrl::InitX11(NULL); \ - try { \ - GuiMainFn_(); \ - } \ - catch(Exc e) { \ - Panic(e); \ - } \ - UPP::UsrLog("---------- About to delete this log..."); \ - UPP::DeleteUsrLog(); \ - UPP::Ctrl::ExitX11(); \ - UPP::AppExit__(); \ - return UPP::GetExitCode(); \ -} \ - \ -void GuiMainFn_() - -class DHCtrl : public Ctrl { - int isError; - bool isMapped; - Size CurrentSize; - XVisualInfo* UserVisualInfo; - String ErrorMessage; - - void MapWindow(bool map); - bool Init(void); - void Terminate(void); - -protected: - Visual *GetVisual(void); - XVisualInfo GetVisualInfo(void); - - virtual XVisualInfo *CreateVisual(void) {return 0;} - virtual void SetAttributes(unsigned long &ValueMask, XSetWindowAttributes &attr) {} - virtual void Paint(Draw &draw) {} - virtual void BeforeInit(void) {} - virtual void AfterInit(bool Error) {} - virtual void BeforeTerminate(void) {} - virtual void AfterTerminate(void) {} - virtual void Resize(int w, int h) {} - - void SetError(bool err) { isError = err; } - void SetErrorMessage(String const &msg) { ErrorMessage = msg; } - - virtual void State(int reason); - - Window hwnd; - bool isInitialized; - -public: - typedef DHCtrl CLASSNAME; - - bool IsInitialized(void) { return isInitialized; } - - bool GetError(void) { return isError; } - String GetErrorMessage(void) { return ErrorMessage; } - - DHCtrl(); - ~DHCtrl(); -}; +class ViewDraw : public SystemDraw { +public: + ViewDraw(Ctrl *ctrl); + ~ViewDraw(); + +protected: + bool caret; +}; + + +#define GUI_APP_MAIN \ +void GuiMainFn_(); \ +\ +int main(int argc, const char **argv, const char **envptr) { \ + UPP::AppInit__(argc, argv, envptr); \ + UPP::Ctrl::InitX11(NULL); \ + UPP::AppExecute__(GuiMainFn_); \ + UPP::UsrLog("---------- About to delete this log..."); \ + UPP::DeleteUsrLog(); \ + UPP::Ctrl::ExitX11(); \ + UPP::AppExit__(); \ + return UPP::GetExitCode(); \ +} \ + \ +void GuiMainFn_() + +class DHCtrl : public Ctrl { + int isError; + bool isMapped; + Size CurrentSize; + XVisualInfo* UserVisualInfo; + String ErrorMessage; + + void MapWindow(bool map); + bool Init(void); + void Terminate(void); + +protected: + Visual *GetVisual(void); + XVisualInfo GetVisualInfo(void); + + virtual XVisualInfo *CreateVisual(void) {return 0;} + virtual void SetAttributes(unsigned long &ValueMask, XSetWindowAttributes &attr) {} + virtual void Paint(Draw &draw) {} + virtual void BeforeInit(void) {} + virtual void AfterInit(bool Error) {} + virtual void BeforeTerminate(void) {} + virtual void AfterTerminate(void) {} + virtual void Resize(int w, int h) {} + + void SetError(bool err) { isError = err; } + void SetErrorMessage(String const &msg) { ErrorMessage = msg; } + + virtual void State(int reason); + + Window hwnd; + bool isInitialized; + +public: + typedef DHCtrl CLASSNAME; + + bool IsInitialized(void) { return isInitialized; } + + bool GetError(void) { return isError; } + String GetErrorMessage(void) { return ErrorMessage; } + + DHCtrl(); + ~DHCtrl(); +};