Jump to content

Window

From The Document Foundation Wiki
Window

Introduction

Window is a top level window in LibreOffice, and can contain other widgets. This widget is useful for creating popups and dockable widgets. Otherwise, one should use Dialog.

Screenshots

Window is displayed differently in different UI plugins.

weld::Window with GTK3
weld::Window with GTK4
weld::Window with X11 (gen)
weld::Window with KF5
weld::Window with Qt5

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

#include <iostream>

namespace
{
class TheWindow : public DockingWindow
{
public:
    TheWindow(vcl::Window* pParent = nullptr);
    bool Close() override;
};

// expected UI file: instdir/share/config/soffice.cfg/vcl/ui/Window.ui
TheWindow::TheWindow(vcl::Window* pParent)
    : DockingWindow(pParent, u"Window"_ustr, u"vcl/ui/Window.ui"_ustr)
{
    SetText(u"Window"_ustr);
}

bool TheWindow::Close()
{
    Application::Quit();
    return DockingWindow::Close();
}

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

int TheApplication::Main()
{
    TheWindow window;
    window.Show();
    Execute();
    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>
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkWindow" id="Window">
    <property name="can-focus">False</property>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>

Native Implementations

*Please note that in Qt, it is based on QtXWindow, which is based on QWidget, and not QWindow. Having a common parent, Qwidget is helpful here.

Links