diff options
author | Hossein <hossein@libreoffice.org> | 2024-11-15 01:02:41 +0100 |
---|---|---|
committer | Hossein <hossein@libreoffice.org> | 2024-11-15 10:01:45 +0100 |
commit | f1c1a1b809c03140da7f4a2c2e7f27e484363342 (patch) | |
tree | 44d6bb5f4edc52a54e3d2c29b9d1da1739d1f84b | |
parent | d18fbc0c20180f6856e9e47eaa97e3763dd4d8e9 (diff) |
Add minimal vcl weld example application
The "minweld" is a minimal standalone vcl application that uses the
LibreOffice vcl weld framework to display the "tip of the day" dialog on
the screen. Upon clicking on the "Next Tip", a counter is incremented
and the text label containing its value is displayed/updated in the
center of the dialog box.
One can run the application by invoking:
./bin/run minweld
This example uses cui/ui/tipofthedaydialog.ui for the UI, but only uses
a few elements of it.
Change-Id: If304c60ddb262182cf23438ed1f83dba85e66391
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176610
Reviewed-by: Hossein <hossein@libreoffice.org>
Tested-by: Jenkins
-rw-r--r-- | Repository.mk | 1 | ||||
-rw-r--r-- | vcl/Executable_minweld.mk | 38 | ||||
-rw-r--r-- | vcl/Module_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/workben/minweld.cxx | 98 |
4 files changed, 138 insertions, 0 deletions
diff --git a/Repository.mk b/Repository.mk index a5772d7a155a..a263a235925a 100644 --- a/Repository.mk +++ b/Repository.mk @@ -77,6 +77,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \ vcldemo \ svdemo \ minvcl \ + minweld \ svptest \ tiledrendering \ mtfdemo \ diff --git a/vcl/Executable_minweld.mk b/vcl/Executable_minweld.mk new file mode 100644 index 000000000000..ff11bbc2881f --- /dev/null +++ b/vcl/Executable_minweld.mk @@ -0,0 +1,38 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Executable_Executable,minweld)) + +$(eval $(call gb_Executable_use_api,minweld,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_Executable_set_include,minweld,\ + $$(INCLUDE) \ + -I$(SRCDIR)/vcl/inc \ +)) + +$(eval $(call gb_Executable_use_libraries,minweld,\ + tl \ + sal \ + vcl \ + cppu \ + cppuhelper \ + comphelper \ + i18nlangtag \ + fwk \ +)) + +$(eval $(call gb_Executable_add_exception_objects,minweld,\ + vcl/workben/minweld \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index a79262b1c757..0ef5ffe879bb 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -45,6 +45,7 @@ $(eval $(call gb_Module_add_targets,vcl,\ Executable_vcldemo \ Executable_svdemo \ Executable_minvcl \ + Executable_minweld \ Executable_svptest \ Executable_icontest \ Executable_visualbackendtest \ diff --git a/vcl/workben/minweld.cxx b/vcl/workben/minweld.cxx new file mode 100644 index 000000000000..85e07c6de58c --- /dev/null +++ b/vcl/workben/minweld.cxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * 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> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <i18nlangtag/languagetag.hxx> +#include <i18nlangtag/mslangid.hxx> + +#include <vcl/svapp.hxx> +#include <vcl/weld.hxx> +#include <sal/main.h> + +#include <iostream> + +namespace +{ +class TipOfTheDayDialog : public weld::GenericDialogController +{ +public: + TipOfTheDayDialog(weld::Window* pParent = nullptr); + DECL_LINK(OnNextClick, weld::Button&, void); + +private: + std::unique_ptr<weld::Label> m_pTextLabel; + std::unique_ptr<weld::Button> m_pNextButton; + sal_Int32 m_nCounter = 0; +}; + +IMPL_LINK_NOARG(TipOfTheDayDialog, OnNextClick, weld::Button&, void) +{ + ++m_nCounter; + m_pTextLabel->set_label(u"Here you will see tip of the day #"_ustr + + OUString::number(m_nCounter) + "."); +} + +TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent) + : weld::GenericDialogController(pParent, u"cui/ui/tipofthedaydialog.ui"_ustr, + u"TipOfTheDayDialog"_ustr) + , m_pTextLabel(m_xBuilder->weld_label(u"lbText"_ustr)) + , m_pNextButton(m_xBuilder->weld_button(u"btnNext"_ustr)) +{ + m_pNextButton->connect_clicked(LINK(this, TipOfTheDayDialog, OnNextClick)); +} + +class TheApplication : public Application +{ +public: + virtual int Main(); +}; + +int TheApplication::Main() +{ + TipOfTheDayDialog dialog; + dialog.run(); + return 0; +} +} + +SAL_IMPLEMENT_MAIN() +{ + try + { + TheApplication aApp; + + 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(); + + aApp.Main(); + + framework::getDesktop(::comphelper::getProcessComponentContext())->terminate(); + DeInitVCL(); + comphelper::setProcessServiceFactory(nullptr); + } + catch (...) + { + std::cerr << "An exception has occurred\n"; + return 1; + } + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |