Jump to content

Dialog

From The Document Foundation Wiki
Dialog

Introduction

Dialog is used to show a dialog box, which is a window that interacts with the user. It can contain other widgets.

Screenshots

Dialog is displayed differently in different UI plugins.

File:Dialog-gtk3.png
weld::Dialog with GTK3
File:Dialog-gtk4.png
weld::Dialog with GTK4
File:Dialog-X11.png
weld::Dialog with X11 (gen)
File:Dialog-kf5.png
weld::Dialog with KF5
File:Dialog-qt5.png
weld::Dialog with Qt5
weld::Dialog with Windows
weld::Dialog with macOS

Code

#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/DialogController.hxx>
#include <vcl/weld/weld/Window.hxx>
#include <sal/main.h>

#include <iostream>

namespace
{
class TheDialog : public weld::GenericDialogController
{
public:
    TheDialog(weld::Window* pParent = nullptr);
};

TheDialog::TheDialog(weld::Window* pParent)
    : weld::GenericDialogController(pParent, u"cui/ui/Dialog.ui"_ustr,
                                    u"Dialog"_ustr)
{
}

class TheApplication : public Application
{
public:
    virtual int Main();
};

int TheApplication::Main()
{
    TheDialog 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;
}
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="cui">
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkDialog" id="Dialog">
    <property name="can-focus">False</property>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>

Native Implementations

Links