summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2022-12-05 03:15:36 +0100
committerHossein <hossein@libreoffice.org>2023-01-28 09:00:04 +0000
commit10c340c2b59dd677d6f598901506b08ff2cbd49c (patch)
tree25abd03047a4949ea8d70a92c8effdafa65990a7
parent5e193d854596db714ca786c2a676b5ac9684d5eb (diff)
Add exception handling to minvcl, minify code
Improve minvcl example: * Add exception handling * Minify code by removing custom Window Change-Id: I1f1dc10c05812b4cfad7d38e09d7ecd26bec35b9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143650 Tested-by: Jenkins Reviewed-by: Hossein <hossein@libreoffice.org>
-rw-r--r--vcl/workben/minvcl.cxx68
1 files changed, 29 insertions, 39 deletions
diff --git a/vcl/workben/minvcl.cxx b/vcl/workben/minvcl.cxx
index 2e5aa3c061bb..465573918cfd 100644
--- a/vcl/workben/minvcl.cxx
+++ b/vcl/workben/minvcl.cxx
@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <sal/config.h>
+
#include <framework/desktop.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <comphelper/processfactory.hxx>
@@ -14,73 +16,61 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#include <i18nlangtag/languagetag.hxx>
#include <i18nlangtag/mslangid.hxx>
-#include <o3tl/deleter.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
+#include <sal/main.h>
+
+#include <iostream>
namespace
{
-class TheWindow : public WorkWindow
-{
-public:
- TheWindow()
- : WorkWindow(nullptr, WB_APP | WB_STDWORK)
- {
- }
- virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
-};
-
class TheApplication : public Application
{
public:
virtual int Main();
private:
- VclPtr<TheWindow> mpWin;
+ VclPtr<vcl::Window> mpWin;
};
}
-void TheWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
-{
- rRenderContext.DrawText(Point(rRect.GetWidth() / 2, rRect.getOpenHeight() / 2),
- OUString(u"VCL module in LibreOffice"));
-}
-
int TheApplication::Main()
{
- mpWin = VclPtr<TheWindow>::Create();
- mpWin->SetText(u"VCL");
+ mpWin = VclPtr<WorkWindow>::Create(nullptr, WB_APP | WB_STDWORK);
+ mpWin->SetText(u"Minimum VCL application with a window");
mpWin->Show();
Execute();
mpWin.disposeAndClear();
return 0;
}
-static int main_impl()
+SAL_IMPLEMENT_MAIN()
{
- auto xContext = cppu::defaultBootstrap_InitialComponentContext();
- css::uno::Reference<css::lang::XMultiServiceFactory> xServiceManager(
- xContext->getServiceManager(), css::uno::UNO_QUERY);
- comphelper::setProcessServiceFactory(xServiceManager);
- LanguageTag::setConfiguredSystemLanguage(MsLangId::getSystemLanguage());
+ try
+ {
+ TheApplication aApp;
- TheApplication aApp;
- InitVCL();
- int ret = aApp.Main();
- framework::getDesktop(::comphelper::getProcessComponentContext())->terminate();
- DeInitVCL();
+ auto xContext = cppu::defaultBootstrap_InitialComponentContext();
+ css::uno::Reference<css::lang::XMultiServiceFactory> xServiceManager(
+ xContext->getServiceManager(), css::uno::UNO_QUERY);
+ comphelper::setProcessServiceFactory(xServiceManager);
+ LanguageTag::setConfiguredSystemLanguage(MsLangId::getSystemLanguage());
+ InitVCL();
- comphelper::setProcessServiceFactory(nullptr);
+ aApp.Main();
- return ret;
-}
+ framework::getDesktop(::comphelper::getProcessComponentContext())->terminate();
+ DeInitVCL();
+ comphelper::setProcessServiceFactory(nullptr);
+ }
+ catch (...)
+ {
+ std::cout << "Exception has occured\n";
+ return 1;
+ }
-int main()
-{
- int ret;
- suppress_fun_call_w_exception(ret = main_impl());
- return ret;
+ return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */