weld pages of the insert envelope dialog

SwEnvPrtPage, SwEnvFormatPage, SwEnvPage

Change-Id: I76b0298994fcd663c0b415ae6e29af054a335bbf
Reviewed-on: https://gerrit.libreoffice.org/53503
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/extras/source/glade/libreoffice-catalog.xml.in b/extras/source/glade/libreoffice-catalog.xml.in
index 48e7f9c..c1565f2 100644
--- a/extras/source/glade/libreoffice-catalog.xml.in
+++ b/extras/source/glade/libreoffice-catalog.xml.in
@@ -422,9 +422,6 @@
    <glade-widget-class title="NUP Preview" name="vcllo-ShowNupOrderWindow"
                        generic-name="NUP Preview" parent="GtkDrawingArea"
                        icon-name="widget-gtk-drawingarea"/>
    <glade-widget-class title="Envelope Preview" name="swuilo-SwEnvPreview"
                        generic-name="Envelope Preview" parent="GtkDrawingArea"
                        icon-name="widget-gtk-drawingarea"/>
    <glade-widget-class title="Frame Preview" name="svxlo-SvxSwFrameExample"
                        generic-name="Frame Preview" parent="GtkDrawingArea"
                        icon-name="widget-gtk-drawingarea"/>
diff --git a/sw/inc/bitmaps.hlst b/sw/inc/bitmaps.hlst
index 5e3c8e8..dd29566 100644
--- a/sw/inc/bitmaps.hlst
+++ b/sw/inc/bitmaps.hlst
@@ -21,19 +21,6 @@
#define RID_GRAPHIC_REPLACEBMP                  "res/grafikei.png"
#define RID_GRAPHIC_ERRORBMP                    "res/grafikde.png"

#define BMP_HOR_LEFT_LOWER                      "sw/res/envhl_l.png"
#define BMP_HOR_LEFT_UPPER                      "sw/res/envhl_u.png"
#define BMP_HOR_CNTR_LOWER                      "sw/res/envhc_l.png"
#define BMP_HOR_CNTR_UPPER                      "sw/res/envhc_u.png"
#define BMP_HOR_RGHT_LOWER                      "sw/res/envhr_l.png"
#define BMP_HOR_RGHT_UPPER                      "sw/res/envhr_u.png"
#define BMP_VER_LEFT_LOWER                      "sw/res/envvl_l.png"
#define BMP_VER_LEFT_UPPER                      "sw/res/envvl_u.png"
#define BMP_VER_CNTR_LOWER                      "sw/res/envvc_l.png"
#define BMP_VER_CNTR_UPPER                      "sw/res/envvc_u.png"
#define BMP_VER_RGHT_LOWER                      "sw/res/envvr_l.png"
#define BMP_VER_RGHT_UPPER                      "sw/res/envvr_u.png"

#define BMP_REDLINE_INSERTED                    "sw/res/redline_inserted.png"
#define BMP_REDLINE_DELETED                     "sw/res/redline_deleted.png"
#define BMP_REDLINE_FORMATED                    "sw/res/redline_inserted.png"
diff --git a/sw/source/ui/envelp/envfmt.cxx b/sw/source/ui/envelp/envfmt.cxx
index c8b5cfc..a7aaaf4 100644
--- a/sw/source/ui/envelp/envfmt.cxx
+++ b/sw/source/ui/envelp/envfmt.cxx
@@ -23,6 +23,7 @@
#include <editeng/tstpitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/brushitem.hxx>
#include <svtools/unitconv.hxx>
#include <vcl/menu.hxx>

#include <cmdid.h>
@@ -113,64 +114,45 @@ namespace {
static long lUserW = 5669; // 10 cm
static long lUserH = 5669; // 10 cm

SwEnvFormatPage::SwEnvFormatPage(vcl::Window* pParent, const SfxItemSet& rSet)
    : SfxTabPage(pParent, "EnvFormatPage",
        "modules/swriter/ui/envformatpage.ui", &rSet)
SwEnvFormatPage::SwEnvFormatPage(TabPageParent pParent, const SfxItemSet& rSet)
    : SfxTabPage(pParent, "modules/swriter/ui/envformatpage.ui", "EnvFormatPage", &rSet)
    , m_xAddrLeftField(m_xBuilder->weld_metric_spin_button("leftaddr", FUNIT_CM))
    , m_xAddrTopField(m_xBuilder->weld_metric_spin_button("topaddr", FUNIT_CM))
    , m_xAddrEditButton(m_xBuilder->weld_menu_button("addredit"))
    , m_xSendLeftField(m_xBuilder->weld_metric_spin_button("leftsender", FUNIT_CM))
    , m_xSendTopField(m_xBuilder->weld_metric_spin_button("topsender", FUNIT_CM))
    , m_xSendEditButton(m_xBuilder->weld_menu_button("senderedit"))
    , m_xSizeFormatBox(m_xBuilder->weld_combo_box_text("format"))
    , m_xSizeWidthField(m_xBuilder->weld_metric_spin_button("width", FUNIT_CM))
    , m_xSizeHeightField(m_xBuilder->weld_metric_spin_button("height", FUNIT_CM))
    , m_xPreview(new SwEnvPreview(m_xBuilder->weld_drawing_area("preview")))
{
    get(m_pAddrLeftField, "leftaddr");
    get(m_pAddrTopField, "topaddr");
    get(m_pSendLeftField,"leftsender");
    get(m_pSendTopField, "topsender");
    get(m_pSizeFormatBox, "format");
    get(m_pSizeWidthField, "width");
    get(m_pSizeHeightField, "height");
    get(m_pPreview, "preview");
    get(m_pAddrEditButton, "addredit");
    get(m_pSendEditButton, "senderedit");
    SetExchangeSupport();

    // Metrics
    FieldUnit aMetric = ::GetDfltMetric(false);
    SetMetric(*m_pAddrLeftField, aMetric);
    SetMetric(*m_pAddrTopField, aMetric);
    SetMetric(*m_pSendLeftField, aMetric);
    SetMetric(*m_pSendTopField, aMetric);
    SetMetric(*m_pSizeWidthField, aMetric);
    SetMetric(*m_pSizeHeightField, aMetric);
    ::SetFieldUnit(*m_xAddrLeftField, aMetric);
    ::SetFieldUnit(*m_xAddrTopField, aMetric);
    ::SetFieldUnit(*m_xSendLeftField, aMetric);
    ::SetFieldUnit(*m_xSendTopField, aMetric);
    ::SetFieldUnit(*m_xSizeWidthField, aMetric);
    ::SetFieldUnit(*m_xSizeHeightField, aMetric);

    // Install handlers
    Link<SpinField&,void> aLk = LINK(this, SwEnvFormatPage, ModifyHdl);
    m_pAddrLeftField->SetUpHdl( aLk );
    m_pAddrTopField->SetUpHdl( aLk );
    m_pSendLeftField->SetUpHdl( aLk );
    m_pSendTopField->SetUpHdl( aLk );
    m_pSizeWidthField->SetUpHdl( aLk );
    m_pSizeHeightField->SetUpHdl( aLk );
    Link<weld::MetricSpinButton&,void> aLk = LINK(this, SwEnvFormatPage, ModifyHdl);
    m_xAddrLeftField->connect_value_changed( aLk );
    m_xAddrTopField->connect_value_changed( aLk );
    m_xSendLeftField->connect_value_changed( aLk );
    m_xSendTopField->connect_value_changed( aLk );
    m_xSizeWidthField->connect_value_changed( aLk );
    m_xSizeHeightField->connect_value_changed( aLk );

    m_pAddrLeftField->SetDownHdl( aLk );
    m_pAddrTopField->SetDownHdl( aLk );
    m_pSendLeftField->SetDownHdl( aLk );
    m_pSendTopField->SetDownHdl( aLk );
    m_pSizeWidthField->SetDownHdl( aLk );
    m_pSizeHeightField->SetDownHdl( aLk );
    m_xAddrEditButton->connect_selected(LINK(this, SwEnvFormatPage, AddrEditHdl));
    m_xSendEditButton->connect_selected(LINK(this, SwEnvFormatPage, SendEditHdl));

    Link<Control&,void> aLk3 = LINK(this, SwEnvFormatPage, LoseFocusHdl);
    m_pAddrLeftField->SetLoseFocusHdl( aLk3 );
    m_pAddrTopField->SetLoseFocusHdl( aLk3 );
    m_pSendLeftField->SetLoseFocusHdl( aLk3 );
    m_pSendTopField->SetLoseFocusHdl( aLk3 );
    m_pSizeWidthField->SetLoseFocusHdl( aLk3 );
    m_pSizeHeightField->SetLoseFocusHdl( aLk3 );
    m_xSizeFormatBox->connect_changed(LINK(this, SwEnvFormatPage, FormatHdl));

    Link<MenuButton *, void> aLk2 = LINK(this, SwEnvFormatPage, EditHdl );
    m_pAddrEditButton->SetSelectHdl( aLk2 );
    m_pSendEditButton->SetSelectHdl( aLk2 );

    m_pPreview->SetBorderStyle( WindowBorderStyle::MONO );

    m_pSizeFormatBox->SetSelectHdl(LINK(this, SwEnvFormatPage, FormatHdl));

    // m_pSizeFormatBox
    // m_xSizeFormatBox
    for (sal_uInt16 i = PAPER_A3; i <= PAPER_KAI32BIG; i++)
    {
        if (i != PAPER_USER)
@@ -181,18 +163,23 @@ SwEnvFormatPage::SwEnvFormatPage(vcl::Window* pParent, const SfxItemSet& rSet)
                continue;

            sal_Int32 nPos = 0;
            while (nPos < m_pSizeFormatBox->GetEntryCount() &&
                   m_pSizeFormatBox->GetEntry(nPos) < aPaperName)
            while (nPos < m_xSizeFormatBox->get_count() &&
                   m_xSizeFormatBox->get_text(nPos) < aPaperName)
            {
                ++nPos;
            }
            m_pSizeFormatBox->InsertEntry(aPaperName, nPos);
            aIDs.insert( aIDs.begin() + nPos, i);
            m_xSizeFormatBox->insert_text(nPos, aPaperName);
            m_aIDs.insert( m_aIDs.begin() + nPos, i);
        }
    }
    m_pSizeFormatBox->InsertEntry(SvxPaperInfo::GetName(PAPER_USER));
    aIDs.push_back( sal_uInt16(PAPER_USER) );
    m_xSizeFormatBox->append_text(SvxPaperInfo::GetName(PAPER_USER));
    m_aIDs.push_back( sal_uInt16(PAPER_USER) );
}

void SwEnvFormatPage::Init(SwEnvDlg* pDialog)
{
    m_pDialog = pDialog;
    m_xPreview->SetDialog(m_pDialog);
}

SwEnvFormatPage::~SwEnvFormatPage()
@@ -200,76 +187,61 @@ SwEnvFormatPage::~SwEnvFormatPage()
    disposeOnce();
}

void SwEnvFormatPage::dispose()
IMPL_LINK( SwEnvFormatPage, ModifyHdl, weld::MetricSpinButton&, rEdit, void )
{
    m_pAddrLeftField.clear();
    m_pAddrTopField.clear();
    m_pAddrEditButton.clear();
    m_pSendLeftField.clear();
    m_pSendTopField.clear();
    m_pSendEditButton.clear();
    m_pSizeFormatBox.clear();
    m_pSizeWidthField.clear();
    m_pSizeHeightField.clear();
    m_pPreview.clear();
    SfxTabPage::dispose();
}
    int lWVal = getfieldval(*m_xSizeWidthField);
    int lHVal = getfieldval(*m_xSizeHeightField);

    int lWidth  = std::max(lWVal, lHVal);
    int lHeight = std::min(lWVal, lHVal);

IMPL_LINK( SwEnvFormatPage, LoseFocusHdl, Control&, rControl, void )
{
    ModifyHdl(static_cast<SpinField&>(rControl));
}
IMPL_LINK( SwEnvFormatPage, ModifyHdl, SpinField&, rEdit, void )
{
    long lWVal = static_cast< long >(GetFieldVal(*m_pSizeWidthField ));
    long lHVal = static_cast< long >(GetFieldVal(*m_pSizeHeightField));

    long lWidth  = std::max(lWVal, lHVal);
    long lHeight = std::min(lWVal, lHVal);

    if (&rEdit == m_pSizeWidthField || &rEdit == m_pSizeHeightField)
    if (&rEdit == m_xSizeWidthField.get() || &rEdit == m_xSizeHeightField.get())
    {
        long nRotatedWidth = lHeight;
        long nRotatedHeight = lWidth;
        int nRotatedWidth = lHeight;
        int nRotatedHeight = lWidth;
        Paper ePaper = SvxPaperInfo::GetSvxPaper(
            Size(nRotatedWidth, nRotatedHeight), MapUnit::MapTwip);
        for (size_t i = 0; i < aIDs.size(); ++i)
            if (aIDs[i] == static_cast<sal_uInt16>(ePaper))
                m_pSizeFormatBox->SelectEntryPos(static_cast<sal_Int32>(i));
        for (size_t i = 0; i < m_aIDs.size(); ++i)
            if (m_aIDs[i] == static_cast<sal_uInt16>(ePaper))
                m_xSizeFormatBox->set_active(i);

        // remember user size
        if (aIDs[m_pSizeFormatBox->GetSelectedEntryPos()] == sal_uInt16(PAPER_USER))
        if (m_aIDs[m_xSizeFormatBox->get_active()] == sal_uInt16(PAPER_USER))
        {
            lUserW = lWidth ;
            lUserH = lHeight;
        }

        m_pSizeFormatBox->GetSelectHdl().Call(*m_pSizeFormatBox);
        FormatHdl(*m_xSizeFormatBox);
    }
    else
    {
        FillItem(GetParentSwEnvDlg()->aEnvItem);
        SetMinMax();
        m_pPreview->Invalidate();
        m_xPreview->queue_draw();
    }
}

IMPL_LINK( SwEnvFormatPage, EditHdl, MenuButton *, pButton, void )
IMPL_LINK(SwEnvFormatPage, AddrEditHdl, const OString&, rIdent, void)
{
    Edit(rIdent, true);
}

IMPL_LINK(SwEnvFormatPage, SendEditHdl, const OString&, rIdent, void)
{
    Edit(rIdent, false);
}

void SwEnvFormatPage::Edit(const OString& rIdent, bool bSender)
{
    SwWrtShell* pSh = GetParentSwEnvDlg()->pSh;
    OSL_ENSURE(pSh, "Shell missing");

    // determine collection-ptr
    bool bSender = pButton != m_pAddrEditButton;

    SwTextFormatColl* pColl = pSh->GetTextCollFromPool( static_cast< sal_uInt16 >(
        bSender ? RES_POOLCOLL_SENDADRESS : RES_POOLCOLL_JAKETADRESS));
    OSL_ENSURE(pColl, "Text collection missing");

    OString sIdent(pButton->GetCurItemIdent());

    if (sIdent == "character")
    if (rIdent == "character")
    {
        SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);

@@ -290,7 +262,7 @@ IMPL_LINK( SwEnvFormatPage, EditHdl, MenuButton *, pButton, void )
            pCollSet->Put(aOutputSet);
        }
    }
    else if (sIdent == "paragraph")
    else if (rIdent == "paragraph")
    {
        SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);

@@ -380,7 +352,7 @@ SfxItemSet *SwEnvFormatPage::GetCollItemSet(SwTextFormatColl const * pColl, bool
    return pAddrSet;
}

IMPL_LINK_NOARG(SwEnvFormatPage, FormatHdl, ListBox&, void)
IMPL_LINK_NOARG(SwEnvFormatPage, FormatHdl, weld::ComboBoxText&, void)
{
    long lWidth;
    long lHeight;
@@ -389,7 +361,7 @@ IMPL_LINK_NOARG(SwEnvFormatPage, FormatHdl, ListBox&, void)
    long lAddrFromLeft;
    long lAddrFromTop;

    const sal_uInt16 nPaper = aIDs[m_pSizeFormatBox->GetSelectedEntryPos()];
    const sal_uInt16 nPaper = m_aIDs[m_xSizeFormatBox->get_active()];
    if (nPaper != sal_uInt16(PAPER_USER))
    {
        Size aSz = SvxPaperInfo::GetPaperSize(static_cast<Paper>(nPaper));
@@ -407,60 +379,42 @@ IMPL_LINK_NOARG(SwEnvFormatPage, FormatHdl, ListBox&, void)
    lAddrFromLeft = lWidth  / 2;
    lAddrFromTop  = lHeight / 2;

    SetFieldVal(*m_pAddrLeftField, lAddrFromLeft);
    SetFieldVal(*m_pAddrTopField , lAddrFromTop );
    SetFieldVal(*m_pSendLeftField, lSendFromLeft);
    SetFieldVal(*m_pSendTopField , lSendFromTop );
    setfieldval(*m_xAddrLeftField, lAddrFromLeft);
    setfieldval(*m_xAddrTopField , lAddrFromTop );
    setfieldval(*m_xSendLeftField, lSendFromLeft);
    setfieldval(*m_xSendTopField , lSendFromTop );

    SetFieldVal(*m_pSizeWidthField , lWidth );
    SetFieldVal(*m_pSizeHeightField, lHeight);
    setfieldval(*m_xSizeWidthField , lWidth );
    setfieldval(*m_xSizeHeightField, lHeight);

    SetMinMax();

    FillItem(GetParentSwEnvDlg()->aEnvItem);
    m_pPreview->Invalidate();
    m_xPreview->queue_draw();
}

void SwEnvFormatPage::SetMinMax()
{
    long lWVal = static_cast< long >(GetFieldVal(*m_pSizeWidthField ));
    long lHVal = static_cast< long >(GetFieldVal(*m_pSizeHeightField));
    long lWVal = static_cast< long >(getfieldval(*m_xSizeWidthField ));
    long lHVal = static_cast< long >(getfieldval(*m_xSizeHeightField));

    long lWidth  = std::max(lWVal, lHVal),
         lHeight = std::min(lWVal, lHVal);

    // Min and Max
    m_pAddrLeftField->SetMin(long(100) * (GetFieldVal(*m_pSendLeftField) + 566), FUNIT_TWIP);
    m_pAddrLeftField->SetMax(long(100) * (lWidth  - 2 * 566), FUNIT_TWIP);
    m_pAddrTopField->SetMin(long(100) * (GetFieldVal(*m_pSendTopField ) + 2 * 566), FUNIT_TWIP);
    m_pAddrTopField->SetMax(long(100) * (lHeight - 2 * 566), FUNIT_TWIP);
    m_pSendLeftField->SetMin(long(100) * 566, FUNIT_TWIP);
    m_pSendLeftField->SetMax(long(100) * (GetFieldVal(*m_pAddrLeftField) - 566), FUNIT_TWIP);
    m_pSendTopField->SetMin(long(100) * 566, FUNIT_TWIP);
    m_pSendTopField->SetMax(long(100) * (GetFieldVal(*m_pAddrTopField ) - 2 * 566), FUNIT_TWIP);

    // First and last
    m_pAddrLeftField->SetFirst(m_pAddrLeftField->GetMin());
    m_pAddrLeftField->SetLast(m_pAddrLeftField->GetMax());
    m_pAddrTopField->SetFirst(m_pAddrTopField->GetMin());
    m_pAddrTopField->SetLast(m_pAddrTopField->GetMax());
    m_pSendLeftField->SetFirst(m_pSendLeftField->GetMin());
    m_pSendLeftField->SetLast(m_pSendLeftField->GetMax());
    m_pSendTopField->SetFirst(m_pSendTopField->GetMin());
    m_pSendTopField->SetLast(m_pSendTopField->GetMax());

    // Reformat fields
    m_pAddrLeftField->Reformat();
    m_pAddrTopField->Reformat();
    m_pSendLeftField->Reformat();
    m_pSendTopField->Reformat();
    m_pSizeWidthField->Reformat();
    m_pSizeHeightField->Reformat();
    m_xAddrLeftField->set_range(100 * (getfieldval(*m_xSendLeftField) + 566),
                                100 * (lWidth  - 2 * 566), FUNIT_TWIP);
    m_xAddrTopField->set_range(100 * (getfieldval(*m_xSendTopField ) + 2 * 566),
                               100 * (lHeight - 2 * 566), FUNIT_TWIP);
    m_xSendLeftField->set_range(100 * 566,
                                100 * (getfieldval(*m_xAddrLeftField) - 566), FUNIT_TWIP);
    m_xSendTopField->set_range(100 * 566,
                               100 * (getfieldval(*m_xAddrTopField ) - 2 * 566), FUNIT_TWIP);
}

VclPtr<SfxTabPage> SwEnvFormatPage::Create(TabPageParent pParent, const SfxItemSet* rSet)
{
    return VclPtr<SwEnvFormatPage>::Create(pParent.pParent, *rSet);
    return VclPtr<SwEnvFormatPage>::Create(pParent, *rSet);
}

void SwEnvFormatPage::ActivatePage(const SfxItemSet& rSet)
@@ -479,16 +433,16 @@ DeactivateRC SwEnvFormatPage::DeactivatePage(SfxItemSet* _pSet)

void SwEnvFormatPage::FillItem(SwEnvItem& rItem)
{
    rItem.m_nAddrFromLeft = static_cast< sal_Int32 >(GetFieldVal(*m_pAddrLeftField));
    rItem.m_nAddrFromTop  = static_cast< sal_Int32 >(GetFieldVal(*m_pAddrTopField ));
    rItem.m_nSendFromLeft = static_cast< sal_Int32 >(GetFieldVal(*m_pSendLeftField));
    rItem.m_nSendFromTop  = static_cast< sal_Int32 >(GetFieldVal(*m_pSendTopField ));
    rItem.m_nAddrFromLeft = static_cast< sal_Int32 >(getfieldval(*m_xAddrLeftField));
    rItem.m_nAddrFromTop  = static_cast< sal_Int32 >(getfieldval(*m_xAddrTopField ));
    rItem.m_nSendFromLeft = static_cast< sal_Int32 >(getfieldval(*m_xSendLeftField));
    rItem.m_nSendFromTop  = static_cast< sal_Int32 >(getfieldval(*m_xSendTopField ));

    const sal_uInt16 nPaper = aIDs[m_pSizeFormatBox->GetSelectedEntryPos()];
    const sal_uInt16 nPaper = m_aIDs[m_xSizeFormatBox->get_active()];
    if (nPaper == sal_uInt16(PAPER_USER))
    {
        long lWVal = static_cast< long >(GetFieldVal(*m_pSizeWidthField ));
        long lHVal = static_cast< long >(GetFieldVal(*m_pSizeHeightField));
        long lWVal = static_cast< long >(getfieldval(*m_xSizeWidthField ));
        long lHVal = static_cast< long >(getfieldval(*m_xSizeHeightField));
        rItem.m_nWidth  = std::max(lWVal, lHVal);
        rItem.m_nHeight = std::min(lWVal, lHVal);
    }
@@ -515,17 +469,17 @@ void SwEnvFormatPage::Reset(const SfxItemSet* rSet)
    Paper ePaper = SvxPaperInfo::GetSvxPaper(
        Size( std::min(rItem.m_nWidth, rItem.m_nHeight),
        std::max(rItem.m_nWidth, rItem.m_nHeight)), MapUnit::MapTwip);
    for (size_t i = 0; i < aIDs.size(); ++i)
        if (aIDs[i] == static_cast<sal_uInt16>(ePaper))
            m_pSizeFormatBox->SelectEntryPos(static_cast<sal_Int32>(i));
    for (size_t i = 0; i < m_aIDs.size(); ++i)
        if (m_aIDs[i] == static_cast<sal_uInt16>(ePaper))
            m_xSizeFormatBox->set_active(i);

    // Metric fields
    SetFieldVal(*m_pAddrLeftField, rItem.m_nAddrFromLeft);
    SetFieldVal(*m_pAddrTopField, rItem.m_nAddrFromTop );
    SetFieldVal(*m_pSendLeftField, rItem.m_nSendFromLeft);
    SetFieldVal(*m_pSendTopField, rItem.m_nSendFromTop );
    SetFieldVal(*m_pSizeWidthField  , std::max(rItem.m_nWidth, rItem.m_nHeight));
    SetFieldVal(*m_pSizeHeightField , std::min(rItem.m_nWidth, rItem.m_nHeight));
    setfieldval(*m_xAddrLeftField, rItem.m_nAddrFromLeft);
    setfieldval(*m_xAddrTopField, rItem.m_nAddrFromTop );
    setfieldval(*m_xSendLeftField, rItem.m_nSendFromLeft);
    setfieldval(*m_xSendTopField, rItem.m_nSendFromTop );
    setfieldval(*m_xSizeWidthField  , std::max(rItem.m_nWidth, rItem.m_nHeight));
    setfieldval(*m_xSizeHeightField , std::min(rItem.m_nWidth, rItem.m_nHeight));
    SetMinMax();

    DELETEZ(GetParentSwEnvDlg()->pSenderSet);
diff --git a/sw/source/ui/envelp/envfmt.hxx b/sw/source/ui/envelp/envfmt.hxx
index 1d3593e..d5aec67 100644
--- a/sw/source/ui/envelp/envfmt.hxx
+++ b/sw/source/ui/envelp/envfmt.hxx
@@ -19,47 +19,52 @@
#ifndef INCLUDED_SW_SOURCE_UI_ENVELP_ENVFMT_HXX
#define INCLUDED_SW_SOURCE_UI_ENVELP_ENVFMT_HXX

#include <vcl/field.hxx>
#include <vcl/menubtn.hxx>
#include <vcl/group.hxx>

#include <vcl/weld.hxx>
#include <envlop.hxx>

class SwTextFormatColl;

class SwEnvFormatPage : public SfxTabPage
{
    VclPtr<MetricField>  m_pAddrLeftField;
    VclPtr<MetricField>  m_pAddrTopField;
    VclPtr<MenuButton>   m_pAddrEditButton;
    VclPtr<MetricField>  m_pSendLeftField;
    VclPtr<MetricField>  m_pSendTopField;
    VclPtr<MenuButton>   m_pSendEditButton;
    VclPtr<ListBox>      m_pSizeFormatBox;
    VclPtr<MetricField>  m_pSizeWidthField;
    VclPtr<MetricField>  m_pSizeHeightField;
    VclPtr<SwEnvPreview> m_pPreview;
    VclPtr<SwEnvDlg> m_pDialog;
    std::vector<sal_uInt16>  m_aIDs;

    std::vector<sal_uInt16>  aIDs;
    std::unique_ptr<weld::MetricSpinButton>  m_xAddrLeftField;
    std::unique_ptr<weld::MetricSpinButton>  m_xAddrTopField;
    std::unique_ptr<weld::MenuButton> m_xAddrEditButton;
    std::unique_ptr<weld::MetricSpinButton>  m_xSendLeftField;
    std::unique_ptr<weld::MetricSpinButton>  m_xSendTopField;
    std::unique_ptr<weld::MenuButton> m_xSendEditButton;
    std::unique_ptr<weld::ComboBoxText> m_xSizeFormatBox;
    std::unique_ptr<weld::MetricSpinButton>  m_xSizeWidthField;
    std::unique_ptr<weld::MetricSpinButton>  m_xSizeHeightField;
    std::unique_ptr<SwEnvPreview> m_xPreview;

    DECL_LINK( ModifyHdl, SpinField&, void );
    DECL_LINK( LoseFocusHdl, Control&, void );
    DECL_LINK( EditHdl, MenuButton *, void );
    DECL_LINK(FormatHdl, ListBox&, void);
    DECL_LINK(ModifyHdl, weld::MetricSpinButton&, void);
    DECL_LINK(AddrEditHdl, const OString&, void);
    DECL_LINK(SendEditHdl, const OString&, void);
    DECL_LINK(FormatHdl, weld::ComboBoxText&, void);

    void SetMinMax();

    SfxItemSet  *GetCollItemSet(SwTextFormatColl const * pColl, bool bSender);

    SwEnvDlg    *GetParentSwEnvDlg() {return static_cast<SwEnvDlg*>(GetParentDialog());}
    void Edit(const OString& rIdent, bool bSender);

    SwEnvDlg    *GetParentSwEnvDlg() { return m_pDialog; }

    using TabPage::ActivatePage;
    using TabPage::DeactivatePage;

public:
    SwEnvFormatPage(vcl::Window* pParent, const SfxItemSet& rSet);
    SwEnvFormatPage(TabPageParent pParent, const SfxItemSet& rSet);
    void Init(SwEnvDlg* pDialog);
    virtual void dispose() override
    {
        m_pDialog.clear();
        SfxTabPage::dispose();
    }
    virtual ~SwEnvFormatPage() override;
    virtual void dispose() override;

    static VclPtr<SfxTabPage> Create(TabPageParent pParent, const SfxItemSet* rSet);

diff --git a/sw/source/ui/envelp/envlop1.cxx b/sw/source/ui/envelp/envlop1.cxx
index 002518c..28926fb 100644
--- a/sw/source/ui/envelp/envlop1.cxx
+++ b/sw/source/ui/envelp/envlop1.cxx
@@ -20,6 +20,7 @@
#include <dbmgr.hxx>
#include <sfx2/app.hxx>
#include <vcl/builderfactory.hxx>
#include <vcl/print.hxx>
#include <vcl/settings.hxx>

#include <swwait.hxx>
@@ -43,39 +44,39 @@ using namespace ::com::sun::star::container;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star;

SwEnvPreview::SwEnvPreview(vcl::Window* pParent, WinBits nStyle)
    : Window(pParent, nStyle)
SwEnvPreview::SwEnvPreview(weld::DrawingArea* pDrawingArea)
    : m_xDrawingArea(pDrawingArea)
    , m_pDialog(nullptr)
{
    SetMapMode(MapMode(MapUnit::MapPixel));
    m_xDrawingArea->set_size_request(m_xDrawingArea->get_approximate_digit_width() * 20,
                                     m_xDrawingArea->get_text_height() * 8);
    m_xDrawingArea->connect_size_allocate(LINK(this, SwEnvPreview, DoResize));
    m_xDrawingArea->connect_draw(LINK(this, SwEnvPreview, DoPaint));
}

Size SwEnvPreview::GetOptimalSize() const
IMPL_LINK(SwEnvPreview, DoResize, const Size&, rSize, void)
{
    return LogicToPixel(Size(84 , 63), MapMode(MapUnit::MapAppFont));
    m_aSize = rSize;
}

VCL_BUILDER_FACTORY_ARGS(SwEnvPreview, 0)

void SwEnvPreview::DataChanged( const DataChangedEvent& rDCEvt )
IMPL_LINK(SwEnvPreview, DoPaint, weld::DrawingArea::draw_args, aPayload, void)
{
    Window::DataChanged( rDCEvt );
    if (DataChangedEventType::SETTINGS == rDCEvt.GetType())
        Invalidate();
}
    vcl::RenderContext& rRenderContext = aPayload.first;

void SwEnvPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle &)
{
    //SetMapMode(MapMode(MapUnit::MapPixel));

    const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
    SetBackground(rRenderContext.GetSettings().GetStyleSettings().GetDialogColor());
    rRenderContext.SetBackground(rRenderContext.GetSettings().GetStyleSettings().GetDialogColor());
    rRenderContext.Erase();

    const SwEnvItem& rItem = static_cast<SwEnvDlg*>(GetParentDialog())->aEnvItem;
    const SwEnvItem& rItem = m_pDialog->aEnvItem;

    const long nPageW = std::max(rItem.m_nWidth, rItem.m_nHeight);
    const long nPageH = std::min(rItem.m_nWidth, rItem.m_nHeight);

    const double f = 0.8 * std::min(
        double(GetOutputSizePixel().Width()) / double(nPageW),
        double(GetOutputSizePixel().Height()) / double(nPageH));
        double(m_aSize.Width()) / double(nPageW),
        double(m_aSize.Height()) / double(nPageH));

    Color aBack = rSettings.GetWindowColor();
    Color aFront = SwViewOption::GetFontColor();
@@ -88,8 +89,8 @@ void SwEnvPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectan
    // Envelope
    const long nW = static_cast<long>(f * nPageW);
    const long nH = static_cast<long>(f * nPageH);
    const long nX = (GetOutputSizePixel().Width () - nW) / 2;
    const long nY = (GetOutputSizePixel().Height() - nH) / 2;
    const long nX = (m_aSize.Width () - nW) / 2;
    const long nY = (m_aSize.Height() - nH) / 2;
    rRenderContext.SetFillColor(aBack);
    rRenderContext.DrawRect(tools::Rectangle(Point(nX, nY), Size(nW, nH)));

@@ -139,8 +140,8 @@ SwEnvDlg::SwEnvDlg(vcl::Window* pParent, const SfxItemSet& rSet,
        GetUserButton()->SetText(get<PushButton>("modify")->GetText());
    }

    AddTabPage("envelope", SwEnvPage   ::Create, nullptr);
    AddTabPage("format", SwEnvFormatPage::Create, nullptr);
    m_nEnvAddressId = AddTabPage("envelope", SwEnvPage   ::Create, nullptr);
    m_nEnvFormatId = AddTabPage("format", SwEnvFormatPage::Create, nullptr);
    m_nEnvPrintId = AddTabPage("printer", SwEnvPrtPage::Create, nullptr);
}

@@ -163,6 +164,14 @@ void SwEnvDlg::PageCreated(sal_uInt16 nId, SfxTabPage &rPage)
    {
        static_cast<SwEnvPrtPage*>(&rPage)->SetPrt(pPrinter);
    }
    else if (nId == m_nEnvAddressId)
    {
        static_cast<SwEnvPage*>(&rPage)->Init(this);
    }
    else if (nId == m_nEnvFormatId)
    {
        static_cast<SwEnvFormatPage*>(&rPage)->Init(this);
    }
}

short SwEnvDlg::Ok()
@@ -186,44 +195,47 @@ short SwEnvDlg::Ok()
    return nRet;
}

SwEnvPage::SwEnvPage(vcl::Window* pParent, const SfxItemSet& rSet)
    : SfxTabPage(pParent, "EnvAddressPage",
        "modules/swriter/ui/envaddresspage.ui", &rSet)
SwEnvPage::SwEnvPage(TabPageParent pParent, const SfxItemSet& rSet)
    : SfxTabPage(pParent, "modules/swriter/ui/envaddresspage.ui", "EnvAddressPage", &rSet)
    , m_pDialog(nullptr)
    , m_pSh(nullptr)
    , m_xAddrEdit(m_xBuilder->weld_text_view("addredit"))
    , m_xDatabaseLB(m_xBuilder->weld_combo_box_text("database"))
    , m_xTableLB(m_xBuilder->weld_combo_box_text("table"))
    , m_xDBFieldLB(m_xBuilder->weld_combo_box_text("field"))
    , m_xInsertBT(m_xBuilder->weld_button("insert"))
    , m_xSenderBox(m_xBuilder->weld_check_button("sender"))
    , m_xSenderEdit(m_xBuilder->weld_text_view("senderedit"))
    , m_xPreview(new SwEnvPreview(m_xBuilder->weld_drawing_area("preview")))
{
    get(m_pAddrEdit, "addredit");
    get(m_pDatabaseLB, "database");
    get(m_pTableLB, "table");
    get(m_pDBFieldLB, "field");
    get(m_pInsertBT, "insert");
    get(m_pSenderBox, "sender");
    get(m_pSenderEdit, "senderedit");
    get(m_pPreview, "preview");
    auto nTextBoxHeight(m_xAddrEdit->get_height_rows(10));
    auto nTextBoxWidth(m_xAddrEdit->get_approximate_digit_width() * 20);

    long nTextBoxHeight(m_pAddrEdit->GetTextHeight() * 10);
    long nTextBoxWidth(m_pAddrEdit->approximate_char_width() * 25);
    m_xAddrEdit->set_size_request(nTextBoxWidth, nTextBoxHeight);
    m_xSenderEdit->set_size_request(nTextBoxWidth, nTextBoxHeight);

    m_pAddrEdit->set_height_request(nTextBoxHeight);
    m_pAddrEdit->set_width_request(nTextBoxWidth);
    m_pSenderEdit->set_height_request(nTextBoxHeight);
    m_pSenderEdit->set_width_request(nTextBoxWidth);

    long nListBoxWidth = approximate_char_width() * 30;
    m_pTableLB->set_width_request(nListBoxWidth);
    m_pDatabaseLB->set_width_request(nListBoxWidth);
    m_pDBFieldLB->set_width_request(nListBoxWidth);
    auto nListBoxWidth = m_xTableLB->get_approximate_digit_width() * 25;
    m_xTableLB->set_size_request(nListBoxWidth, -1);
    m_xDatabaseLB->set_size_request(nListBoxWidth, -1);
    m_xDBFieldLB->set_size_request(nListBoxWidth, -1);

    SetExchangeSupport();
    pSh = GetParentSwEnvDlg()->pSh;
}

void SwEnvPage::Init(SwEnvDlg* pDialog)
{
    m_pDialog = pDialog;
    m_pSh = m_pDialog->pSh;
    m_xPreview->SetDialog(pDialog);

    // Install handlers
    m_pDatabaseLB->SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl     ));
    m_pTableLB->SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl     ));
    m_pInsertBT->SetClickHdl (LINK(this, SwEnvPage, FieldHdl        ));
    m_pSenderBox->SetClickHdl (LINK(this, SwEnvPage, SenderHdl       ));
    m_pPreview->SetBorderStyle( WindowBorderStyle::MONO );
    m_xDatabaseLB->connect_changed(LINK(this, SwEnvPage, DatabaseHdl));
    m_xTableLB->connect_changed(LINK(this, SwEnvPage, DatabaseHdl));
    m_xInsertBT->connect_clicked(LINK(this, SwEnvPage, FieldHdl));
    m_xSenderBox->connect_clicked(LINK(this, SwEnvPage, SenderHdl));

    SwDBData aData = pSh->GetDBData();
    sActDBName = aData.sDataSource + OUStringLiteral1(DB_DELIM) + aData.sCommand;
    SwDBData aData = m_pSh->GetDBData();
    m_sActDBName = aData.sDataSource + OUStringLiteral1(DB_DELIM) + aData.sCommand;
    InitDatabaseBox();
}

@@ -232,91 +244,78 @@ SwEnvPage::~SwEnvPage()
    disposeOnce();
}

void SwEnvPage::dispose()
IMPL_LINK( SwEnvPage, DatabaseHdl, weld::ComboBoxText&, rListBox, void )
{
    m_pAddrEdit.clear();
    m_pDatabaseLB.clear();
    m_pTableLB.clear();
    m_pDBFieldLB.clear();
    m_pInsertBT.clear();
    m_pSenderBox.clear();
    m_pSenderEdit.clear();
    m_pPreview.clear();
    SfxTabPage::dispose();
}
    SwWait aWait( *m_pSh->GetView().GetDocShell(), true );

IMPL_LINK( SwEnvPage, DatabaseHdl, ListBox&, rListBox, void )
{
    SwWait aWait( *pSh->GetView().GetDocShell(), true );

    if (&rListBox == m_pDatabaseLB)
    if (&rListBox == m_xDatabaseLB.get())
    {
        sActDBName = rListBox.GetSelectedEntry();
        pSh->GetDBManager()->GetTableNames(m_pTableLB, sActDBName);
        sActDBName += OUStringLiteral1(DB_DELIM);
        m_sActDBName = rListBox.get_active_text();
        m_pSh->GetDBManager()->GetTableNames(*m_xTableLB, m_sActDBName);
        m_sActDBName += OUStringLiteral1(DB_DELIM);
    }
    else
    {
        sActDBName = comphelper::string::setToken(sActDBName, 1, DB_DELIM, m_pTableLB->GetSelectedEntry());
        m_sActDBName = comphelper::string::setToken(m_sActDBName, 1, DB_DELIM, m_xTableLB->get_active_text());
    }
    pSh->GetDBManager()->GetColumnNames(m_pDBFieldLB, m_pDatabaseLB->GetSelectedEntry(),
                                       m_pTableLB->GetSelectedEntry());
    m_pSh->GetDBManager()->GetColumnNames(*m_xDBFieldLB, m_xDatabaseLB->get_active_text(),
                                          m_xTableLB->get_active_text());
}

IMPL_LINK_NOARG(SwEnvPage, FieldHdl, Button*, void)
IMPL_LINK_NOARG(SwEnvPage, FieldHdl, weld::Button&, void)
{
    OUString aStr("<" + m_pDatabaseLB->GetSelectedEntry() + "." +
                  m_pTableLB->GetSelectedEntry() + "." +
                  OUString(m_pTableLB->GetSelectedEntryData() == nullptr ? '0' : '1') + "." +
                  m_pDBFieldLB->GetSelectedEntry() + ">");
    m_pAddrEdit->ReplaceSelected(aStr);
    Selection aSel = m_pAddrEdit->GetSelection();
    m_pAddrEdit->GrabFocus();
    m_pAddrEdit->SetSelection(aSel);
    OUString aStr("<" + m_xDatabaseLB->get_active_text() + "." +
                  m_xTableLB->get_active_text() + "." +
                  m_xTableLB->get_active_id() + "." +
                  m_xDBFieldLB->get_active_text() + ">");
    m_xAddrEdit->replace_selection(aStr);
    int nStartPos, nEndPos;
    m_xAddrEdit->get_selection_bounds(nStartPos, nEndPos);
    m_xAddrEdit->grab_focus();
    m_xAddrEdit->select_region(nStartPos, nEndPos);
}

IMPL_LINK_NOARG(SwEnvPage, SenderHdl, Button*, void)
IMPL_LINK_NOARG(SwEnvPage, SenderHdl, weld::Button&, void)
{
    const bool bEnable = m_pSenderBox->IsChecked();
    const bool bEnable = m_xSenderBox->get_active();
    GetParentSwEnvDlg()->aEnvItem.m_bSend = bEnable;
    m_pSenderEdit->Enable(bEnable);
    if ( bEnable )
    m_xSenderEdit->set_sensitive(bEnable);
    if (bEnable)
    {
        m_pSenderEdit->GrabFocus();
        if(m_pSenderEdit->GetText().isEmpty())
            m_pSenderEdit->SetText(MakeSender());
        m_xSenderEdit->grab_focus();
        if (m_xSenderEdit->get_text().isEmpty())
            m_xSenderEdit->set_text(MakeSender());
    }
    m_pPreview->Invalidate();
    m_xPreview->queue_draw();
}

void SwEnvPage::InitDatabaseBox()
{
    if (pSh->GetDBManager())
    if (m_pSh->GetDBManager())
    {
        m_pDatabaseLB->Clear();
        m_xDatabaseLB->clear();
        Sequence<OUString> aDataNames = SwDBManager::GetExistingDatabaseNames();
        const OUString* pDataNames = aDataNames.getConstArray();

        for (sal_Int32 i = 0; i < aDataNames.getLength(); i++)
            m_pDatabaseLB->InsertEntry(pDataNames[i]);
        for (sal_Int32 i = 0; i < aDataNames.getLength(); ++i)
            m_xDatabaseLB->append_text(pDataNames[i]);

        OUString sDBName = sActDBName.getToken( 0, DB_DELIM );
        OUString sTableName = sActDBName.getToken( 1, DB_DELIM );
        m_pDatabaseLB->SelectEntry(sDBName);
        if (pSh->GetDBManager()->GetTableNames(m_pTableLB, sDBName))
        OUString sDBName = m_sActDBName.getToken( 0, DB_DELIM );
        OUString sTableName = m_sActDBName.getToken( 1, DB_DELIM );
        m_xDatabaseLB->set_active(sDBName);
        if (m_pSh->GetDBManager()->GetTableNames(*m_xTableLB, sDBName))
        {
            m_pTableLB->SelectEntry(sTableName);
            pSh->GetDBManager()->GetColumnNames(m_pDBFieldLB, sDBName, sTableName);
            m_xTableLB->append_text(sTableName);
            m_pSh->GetDBManager()->GetColumnNames(*m_xDBFieldLB, sDBName, sTableName);
        }
        else
            m_pDBFieldLB->Clear();

            m_xDBFieldLB->clear();
    }
}

VclPtr<SfxTabPage> SwEnvPage::Create(TabPageParent pParent, const SfxItemSet* rSet)
{
    return VclPtr<SwEnvPage>::Create(pParent.pParent, *rSet);
    return VclPtr<SwEnvPage>::Create(pParent, *rSet);
}

void SwEnvPage::ActivatePage(const SfxItemSet& rSet)
@@ -336,9 +335,9 @@ DeactivateRC SwEnvPage::DeactivatePage(SfxItemSet* _pSet)

void SwEnvPage::FillItem(SwEnvItem& rItem)
{
    rItem.m_aAddrText = m_pAddrEdit->GetText();
    rItem.m_bSend     = m_pSenderBox->IsChecked();
    rItem.m_aSendText = m_pSenderEdit->GetText();
    rItem.m_aAddrText = m_xAddrEdit->get_text();
    rItem.m_bSend     = m_xSenderBox->get_active();
    rItem.m_aSendText = m_xSenderEdit->get_text();
}

bool SwEnvPage::FillItemSet(SfxItemSet* rSet)
@@ -351,10 +350,10 @@ bool SwEnvPage::FillItemSet(SfxItemSet* rSet)
void SwEnvPage::Reset(const SfxItemSet* rSet)
{
    SwEnvItem aItem = static_cast<const SwEnvItem&>( rSet->Get(FN_ENVELOP));
    m_pAddrEdit->SetText(convertLineEnd(aItem.m_aAddrText, GetSystemLineEnd()));
    m_pSenderEdit->SetText(convertLineEnd(aItem.m_aSendText, GetSystemLineEnd()));
    m_pSenderBox->Check  (aItem.m_bSend);
    m_pSenderBox->GetClickHdl().Call(m_pSenderBox);
    m_xAddrEdit->set_text(convertLineEnd(aItem.m_aAddrText, GetSystemLineEnd()));
    m_xSenderEdit->set_text(convertLineEnd(aItem.m_aSendText, GetSystemLineEnd()));
    m_xSenderBox->set_active(aItem.m_bSend);
    SenderHdl(*m_xSenderBox);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/envelp/envprt.cxx b/sw/source/ui/envelp/envprt.cxx
index 7605bd4..fee13aa 100644
--- a/sw/source/ui/envelp/envprt.cxx
+++ b/sw/source/ui/envelp/envprt.cxx
@@ -19,6 +19,7 @@

#include <vcl/print.hxx>
#include <svtools/prnsetup.hxx>
#include <svtools/unitconv.hxx>

#include <swtypes.hxx>
#include <cmdid.h>
@@ -28,42 +29,49 @@

#include <bitmaps.hlst>

SwEnvPrtPage::SwEnvPrtPage(vcl::Window* pParent, const SfxItemSet& rSet)
    : SfxTabPage(pParent, "EnvPrinterPage",
        "modules/swriter/ui/envprinterpage.ui", &rSet)
    , pPrt(nullptr)
SwEnvPrtPage::SwEnvPrtPage(TabPageParent pParent, const SfxItemSet& rSet)
    : SfxTabPage(pParent, "modules/swriter/ui/envprinterpage.ui", "EnvPrinterPage", &rSet)
    , m_xUpper(m_xBuilder->weld_widget("upper"))
    , m_xLower(m_xBuilder->weld_widget("lower"))
    , m_xTopButton(m_xBuilder->weld_radio_button("top"))
    , m_xBottomButton(m_xBuilder->weld_radio_button("bottom"))
    , m_xRightField(m_xBuilder->weld_metric_spin_button("right", FUNIT_CM))
    , m_xDownField(m_xBuilder->weld_metric_spin_button("down", FUNIT_CM))
    , m_xPrinterInfo(m_xBuilder->weld_label("printername"))
    , m_xPrtSetup(m_xBuilder->weld_button("setup"))
    , m_aIdsL { std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("horileftl")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("horicenterl")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("horirightl")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("vertleftl")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("vertcenterl")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("vertrightl")) }
    , m_aIdsU { std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("horileftu")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("horicenteru")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("horirightu")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("vertleftu")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("vertcenteru")),
                std::unique_ptr<weld::RadioButton>(m_xBuilder->weld_radio_button("vertrightu")) }
{
    get(m_pAlignBox, "alignbox");
    get(m_pTopButton, "top");
    get(m_pBottomButton, "bottom");
    get(m_pRightField, "right");
    get(m_pDownField, "down");
    get(m_pPrinterInfo, "printername");
    get(m_pPrtSetup, "setup");
    SetExchangeSupport();

    // Metrics
    FieldUnit eUnit = ::GetDfltMetric(false);
    SetMetric(*m_pRightField, eUnit);
    SetMetric(*m_pDownField, eUnit);
    ::SetFieldUnit(*m_xRightField, eUnit);
    ::SetFieldUnit(*m_xDownField, eUnit);

    // Install handlers
    m_pTopButton->SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
    m_pBottomButton->SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
    m_xTopButton->connect_toggled(LINK(this, SwEnvPrtPage, ClickHdl));
    m_xBottomButton->connect_toggled(LINK(this, SwEnvPrtPage, ClickHdl));

    m_pPrtSetup->SetClickHdl(LINK(this, SwEnvPrtPage, ButtonHdl));
    m_xPrtSetup->connect_clicked(LINK(this, SwEnvPrtPage, ButtonHdl));

    for (auto& a : m_aIdsL)
        a->connect_toggled(LINK(this, SwEnvPrtPage, LowerHdl));
    for (auto& a : m_aIdsU)
        a->connect_toggled(LINK(this, SwEnvPrtPage, UpperHdl));

    // Bitmaps
    m_pBottomButton->GetClickHdl().Call(m_pBottomButton);

    // ToolBox
    m_pAlignBox->SetClickHdl(LINK(this, SwEnvPrtPage, AlignHdl));
    m_aIds[ENV_HOR_LEFT] = m_pAlignBox->GetItemId("horileft");
    m_aIds[ENV_HOR_CNTR] = m_pAlignBox->GetItemId("horicenter");
    m_aIds[ENV_HOR_RGHT] = m_pAlignBox->GetItemId("horiright");
    m_aIds[ENV_VER_LEFT] = m_pAlignBox->GetItemId("vertleft");
    m_aIds[ENV_VER_CNTR] = m_pAlignBox->GetItemId("vertcenter");
    m_aIds[ENV_VER_RGHT] = m_pAlignBox->GetItemId("vertright");
    ClickHdl(*m_xBottomButton);
}

SwEnvPrtPage::~SwEnvPrtPage()
@@ -71,84 +79,63 @@ SwEnvPrtPage::~SwEnvPrtPage()
    disposeOnce();
}

void SwEnvPrtPage::dispose()
IMPL_LINK_NOARG(SwEnvPrtPage, ClickHdl, weld::ToggleButton&, void)
{
    m_pAlignBox.clear();
    m_pTopButton.clear();
    m_pBottomButton.clear();
    m_pRightField.clear();
    m_pDownField.clear();
    m_pPrinterInfo.clear();
    m_pPrtSetup.clear();
    pPrt.clear();
    SfxTabPage::dispose();
    // Envelope from bottom, otherwise Envelope from top
    const bool bLowerActive = m_xBottomButton->get_active();
    m_xUpper->show(!bLowerActive);
    m_xLower->show(bLowerActive);
}

IMPL_LINK_NOARG(SwEnvPrtPage, ClickHdl, Button*, void)
IMPL_LINK(SwEnvPrtPage, LowerHdl, weld::ToggleButton&, rButton, void)
{
    if (m_pBottomButton->IsChecked())
    for (int i = ENV_HOR_LEFT; i <= ENV_VER_RGHT; ++i)
    {
        // Envelope from bottom
        m_pAlignBox->SetItemImage(m_aIds[ENV_HOR_LEFT], Image(BitmapEx(BMP_HOR_LEFT_LOWER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_HOR_CNTR], Image(BitmapEx(BMP_HOR_CNTR_LOWER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_HOR_RGHT], Image(BitmapEx(BMP_HOR_RGHT_LOWER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_VER_LEFT], Image(BitmapEx(BMP_VER_LEFT_LOWER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_VER_CNTR], Image(BitmapEx(BMP_VER_CNTR_LOWER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_VER_RGHT], Image(BitmapEx(BMP_VER_RGHT_LOWER)));
    }
    else
    {
        // Envelope from top
        m_pAlignBox->SetItemImage(m_aIds[ENV_HOR_LEFT], Image(BitmapEx(BMP_HOR_LEFT_UPPER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_HOR_CNTR], Image(BitmapEx(BMP_HOR_CNTR_UPPER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_HOR_RGHT], Image(BitmapEx(BMP_HOR_RGHT_UPPER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_VER_LEFT], Image(BitmapEx(BMP_VER_LEFT_UPPER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_VER_CNTR], Image(BitmapEx(BMP_VER_CNTR_UPPER)));
        m_pAlignBox->SetItemImage(m_aIds[ENV_VER_RGHT], Image(BitmapEx(BMP_VER_RGHT_UPPER)));
    }
}

IMPL_LINK( SwEnvPrtPage, ButtonHdl, Button *, pBtn, void )
{
    if (pBtn == m_pPrtSetup)
    {
        // Call printer setup
        if (pPrt)
        if (&rButton == m_aIdsL[i].get())
        {
            PrinterSetupDialog aDlg(GetFrameWeld());
            aDlg.SetPrinter(pPrt);
            aDlg.execute();
            GrabFocus();
            m_pPrinterInfo->SetText(pPrt->GetName());
            m_aIdsU[i]->set_active(m_aIdsL[i]->get_active());
            break;
        }
    }
}

IMPL_LINK_NOARG(SwEnvPrtPage, AlignHdl, ToolBox *, void)
IMPL_LINK(SwEnvPrtPage, UpperHdl, weld::ToggleButton&, rButton, void)
{
    if (m_pAlignBox->GetCurItemId())
    for (int i = ENV_HOR_LEFT; i <= ENV_VER_RGHT; ++i)
    {
        for (int i = ENV_HOR_LEFT; i <= ENV_VER_RGHT; ++i)
            m_pAlignBox->CheckItem(m_aIds[i], false);
        m_pAlignBox->CheckItem(m_pAlignBox->GetCurItemId());
        if (&rButton == m_aIdsU[i].get())
        {
            m_aIdsL[i]->set_active(m_aIdsU[i]->get_active());
            break;
        }
    }
    else
}

IMPL_LINK(SwEnvPrtPage, ButtonHdl, weld::Button&, rBtn, void)
{
    if (&rBtn == m_xPrtSetup.get())
    {
        // GetCurItemId() == 0 is possible!
        const SwEnvItem& rItem = static_cast<const SwEnvItem&>( GetItemSet().Get(FN_ENVELOP) );
        m_pAlignBox->CheckItem(m_aIds[rItem.m_eAlign]);
        // Call printer setup
        if (m_xPrt)
        {
            PrinterSetupDialog aDlg(GetTabDialog()->GetFrameWeld());
            aDlg.SetPrinter(m_xPrt);
            aDlg.execute();
            rBtn.grab_focus();
            m_xPrinterInfo->set_label(m_xPrt->GetName());
        }
    }
}

VclPtr<SfxTabPage> SwEnvPrtPage::Create(TabPageParent pParent, const SfxItemSet* rSet)
{
    return VclPtr<SwEnvPrtPage>::Create(pParent.pParent, *rSet);
    return VclPtr<SwEnvPrtPage>::Create(pParent, *rSet);
}

void SwEnvPrtPage::ActivatePage(const SfxItemSet&)
{
    if (pPrt)
        m_pPrinterInfo->SetText(pPrt->GetName());
    if (m_xPrt)
        m_xPrinterInfo->set_label(m_xPrt->GetName());
}

DeactivateRC SwEnvPrtPage::DeactivatePage(SfxItemSet* _pSet)
@@ -163,7 +150,8 @@ void SwEnvPrtPage::FillItem(SwEnvItem& rItem)
    int nOrient = 0;
    for (int i = ENV_HOR_LEFT; i <= ENV_VER_RGHT; ++i)
    {
        if (m_pAlignBox->IsItemChecked(m_aIds[i]))
        assert(m_aIdsL[i]->get_active() == m_aIdsU[i]->get_active());
        if (m_aIdsL[i]->get_active())
        {
            nOrient = i;
            break;
@@ -171,9 +159,9 @@ void SwEnvPrtPage::FillItem(SwEnvItem& rItem)
    }

    rItem.m_eAlign          = static_cast<SwEnvAlign>(nOrient);
    rItem.m_bPrintFromAbove = m_pTopButton->IsChecked();
    rItem.m_nShiftRight     = static_cast< sal_Int32 >(GetFieldVal(*m_pRightField));
    rItem.m_nShiftDown      = static_cast< sal_Int32 >(GetFieldVal(*m_pDownField ));
    rItem.m_bPrintFromAbove = m_xTopButton->get_active();
    rItem.m_nShiftRight     = getfieldval(*m_xRightField);
    rItem.m_nShiftDown      = getfieldval(*m_xDownField);
}

bool SwEnvPrtPage::FillItemSet(SfxItemSet* rSet)
@@ -187,18 +175,19 @@ void SwEnvPrtPage::Reset(const SfxItemSet* rSet)
{
    // Read item
    const SwEnvItem& rItem = static_cast<const SwEnvItem&>( rSet->Get(FN_ENVELOP) );
    m_pAlignBox->CheckItem(m_aIds[rItem.m_eAlign]);
    m_aIdsL[rItem.m_eAlign]->set_active(true);
    m_aIdsU[rItem.m_eAlign]->set_active(true);

    if (rItem.m_bPrintFromAbove)
        m_pTopButton->Check();
        m_xTopButton->set_active(true);
    else
        m_pBottomButton->Check();
        m_xBottomButton->set_active(true);

    SetFieldVal(*m_pRightField, rItem.m_nShiftRight);
    SetFieldVal(*m_pDownField , rItem.m_nShiftDown );
    setfieldval(*m_xRightField, rItem.m_nShiftRight);
    setfieldval(*m_xDownField , rItem.m_nShiftDown );

    ActivatePage(*rSet);
    ClickHdl(m_pTopButton);
    ClickHdl(*m_xTopButton);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/envelp/envprt.hxx b/sw/source/ui/envelp/envprt.hxx
index 8d70bb9..94b7d08 100644
--- a/sw/source/ui/envelp/envprt.hxx
+++ b/sw/source/ui/envelp/envprt.hxx
@@ -21,12 +21,7 @@
#define INCLUDED_SW_SOURCE_UI_ENVELP_ENVPRT_HXX

#include <sfx2/tabdlg.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/field.hxx>
#include <vcl/fixed.hxx>
#include <vcl/group.hxx>
#include <vcl/button.hxx>
#include <vcl/print.hxx>
#include <vcl/weld.hxx>

#include <envimg.hxx>
#include <envlop.hxx>
@@ -35,31 +30,39 @@ class SwEnvDlg;

class SwEnvPrtPage : public SfxTabPage
{
    VclPtr<ToolBox>     m_pAlignBox;
    VclPtr<RadioButton> m_pTopButton;
    VclPtr<RadioButton> m_pBottomButton;
    VclPtr<MetricField> m_pRightField;
    VclPtr<MetricField> m_pDownField;
    VclPtr<FixedText>   m_pPrinterInfo;
    VclPtr<PushButton>  m_pPrtSetup;
    std::unique_ptr<weld::Widget> m_xUpper;
    std::unique_ptr<weld::Widget> m_xLower;
    std::unique_ptr<weld::RadioButton> m_xTopButton;
    std::unique_ptr<weld::RadioButton> m_xBottomButton;
    std::unique_ptr<weld::MetricSpinButton> m_xRightField;
    std::unique_ptr<weld::MetricSpinButton> m_xDownField;
    std::unique_ptr<weld::Label>   m_xPrinterInfo;
    std::unique_ptr<weld::Button>  m_xPrtSetup;

    sal_uInt16 m_aIds[ENV_VER_RGHT-ENV_HOR_LEFT+1];
    std::unique_ptr<weld::RadioButton> m_aIdsL[ENV_VER_RGHT-ENV_HOR_LEFT+1];
    std::unique_ptr<weld::RadioButton> m_aIdsU[ENV_VER_RGHT-ENV_HOR_LEFT+1];

    VclPtr<Printer>     pPrt;
    VclPtr<Printer>     m_xPrt;

    DECL_LINK(ClickHdl, Button*, void);
    DECL_LINK(AlignHdl, ToolBox *, void);
    DECL_LINK(ButtonHdl, Button *, void );
    DECL_LINK(LowerHdl, weld::ToggleButton&, void);
    DECL_LINK(UpperHdl, weld::ToggleButton&, void);
    DECL_LINK(ClickHdl, weld::ToggleButton&, void);
    DECL_LINK(AlignHdl, weld::ToggleButton&, void);
    DECL_LINK(ButtonHdl, weld::Button&, void );

    SwEnvDlg* GetParentSwEnvDlg() {return static_cast<SwEnvDlg*>( GetParentDialog());}
    SwEnvDlg* GetParentSwEnvDlg() {return static_cast<SwEnvDlg*>(GetTabDialog()); }

    using TabPage::ActivatePage;
    using TabPage::DeactivatePage;

public:
    SwEnvPrtPage(vcl::Window* pParent, const SfxItemSet& rSet);
    SwEnvPrtPage(TabPageParent pParent, const SfxItemSet& rSet);
    virtual void dispose() override
    {
        m_xPrt.clear();
        SfxTabPage::dispose();
    }
    virtual ~SwEnvPrtPage() override;
    virtual void dispose() override;

    static VclPtr<SfxTabPage> Create(TabPageParent pParent, const SfxItemSet* rSet);

@@ -69,7 +72,7 @@ public:
    virtual bool FillItemSet(SfxItemSet* rSet) override;
    virtual void Reset(const SfxItemSet* rSet) override;

    void SetPrt(Printer* pPrinter) { pPrt = pPrinter; }
    void SetPrt(Printer* pPrinter) { m_xPrt = pPrinter; }
};

#endif
diff --git a/sw/source/uibase/inc/envlop.hxx b/sw/source/uibase/inc/envlop.hxx
index 3a21cbdf..989e50c 100644
--- a/sw/source/uibase/inc/envlop.hxx
+++ b/sw/source/uibase/inc/envlop.hxx
@@ -23,34 +23,46 @@
#include <sfx2/tabdlg.hxx>

#include <vcl/fixed.hxx>

#include <vcl/edit.hxx>

#include <vcl/lstbox.hxx>

#include <vcl/button.hxx>
#include <vcl/weld.hxx>

#include "envimg.hxx"

#define GetFieldVal(rField)         (rField).Denormalize((rField).GetValue(FUNIT_TWIP))
#define SetFieldVal(rField, lValue) (rField).SetValue((rField).Normalize(lValue), FUNIT_TWIP)

inline int getfieldval(weld::MetricSpinButton& rField)
{
    return rField.denormalize(rField.get_value(FUNIT_TWIP));
}

inline void setfieldval(weld::MetricSpinButton& rField, int lValue)
{
    rField.set_value(rField.normalize(lValue), FUNIT_TWIP);
}

class SwEnvDlg;
class SwEnvPage;
class SwEnvFormatPage;
class SwWrtShell;
class Printer;

class SwEnvPreview : public vcl::Window
class SwEnvPreview
{
    void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
private:
    std::unique_ptr<weld::DrawingArea> m_xDrawingArea;
    VclPtr<SwEnvDlg> m_pDialog;
    Size m_aSize;

    DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void);
    DECL_LINK(DoResize, const Size& rSize, void);

public:

    SwEnvPreview(vcl::Window * pParent, WinBits nStyle);

protected:
    virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
    virtual Size GetOptimalSize() const override;
    SwEnvPreview(weld::DrawingArea* pDrawingArea);
    void SetDialog(SwEnvDlg* pDialog) { m_pDialog = pDialog; }
    void queue_draw() { m_xDrawingArea->queue_draw(); }
};

class SwEnvDlg : public SfxTabDialog
@@ -66,45 +78,48 @@ friend class SwEnvPreview;
    SfxItemSet      *pAddresseeSet;
    SfxItemSet      *pSenderSet;
    sal_uInt16      m_nEnvPrintId;
    sal_uInt16      m_nEnvAddressId;
    sal_uInt16      m_nEnvFormatId;

    virtual void    PageCreated( sal_uInt16 nId, SfxTabPage &rPage ) override;
    virtual short   Ok() override;

public:
     SwEnvDlg(vcl::Window* pParent, const SfxItemSet& rSet, SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert);
    SwEnvDlg(vcl::Window* pParent, const SfxItemSet& rSet, SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert);
    virtual ~SwEnvDlg() override;
    virtual void dispose() override;
};

class SwEnvPage : public SfxTabPage
{
    VclPtr<VclMultiLineEdit> m_pAddrEdit;
    VclPtr<ListBox>      m_pDatabaseLB;
    VclPtr<ListBox>      m_pTableLB;
    VclPtr<ListBox>      m_pDBFieldLB;
    VclPtr<PushButton>   m_pInsertBT;
    VclPtr<CheckBox>     m_pSenderBox;
    VclPtr<VclMultiLineEdit> m_pSenderEdit;
    VclPtr<SwEnvPreview> m_pPreview;
    VclPtr<SwEnvDlg> m_pDialog;
    SwWrtShell*   m_pSh;
    OUString      m_sActDBName;

    SwWrtShell*   pSh;
    OUString      sActDBName;
    std::unique_ptr<weld::TextView> m_xAddrEdit;
    std::unique_ptr<weld::ComboBoxText> m_xDatabaseLB;
    std::unique_ptr<weld::ComboBoxText> m_xTableLB;
    std::unique_ptr<weld::ComboBoxText> m_xDBFieldLB;
    std::unique_ptr<weld::Button> m_xInsertBT;
    std::unique_ptr<weld::CheckButton> m_xSenderBox;
    std::unique_ptr<weld::TextView> m_xSenderEdit;
    std::unique_ptr<SwEnvPreview> m_xPreview;

    DECL_LINK( DatabaseHdl, ListBox&, void );
    DECL_LINK(FieldHdl, Button*, void );
    DECL_LINK(SenderHdl, Button*, void );
    DECL_LINK(DatabaseHdl, weld::ComboBoxText&, void);
    DECL_LINK(FieldHdl, weld::Button&, void);
    DECL_LINK(SenderHdl, weld::Button&, void);

    void InitDatabaseBox();

    SwEnvDlg* GetParentSwEnvDlg() {return static_cast<SwEnvDlg*>(GetParentDialog());}
    SwEnvDlg* GetParentSwEnvDlg() { return m_pDialog; }

    using SfxTabPage::ActivatePage;
    using SfxTabPage::DeactivatePage;

public:
    SwEnvPage(vcl::Window* pParent, const SfxItemSet& rSet);
    SwEnvPage(TabPageParent pParent, const SfxItemSet& rSet);
    void Init(SwEnvDlg* pDialog);
    virtual ~SwEnvPage() override;
    virtual void dispose() override;

    static VclPtr<SfxTabPage> Create(TabPageParent pParent, const SfxItemSet* rSet);

@@ -113,6 +128,11 @@ public:
            void FillItem(SwEnvItem& rItem);
    virtual bool FillItemSet(SfxItemSet* rSet) override;
    virtual void Reset(const SfxItemSet* rSet) override;
    virtual void dispose() override
    {
        m_pDialog.clear();
        SfxTabPage::dispose();
    }
};

#endif
diff --git a/sw/uiconfig/swriter/ui/envaddresspage.ui b/sw/uiconfig/swriter/ui/envaddresspage.ui
index e2f9e16..37e84a2 100644
--- a/sw/uiconfig/swriter/ui/envaddresspage.ui
+++ b/sw/uiconfig/swriter/ui/envaddresspage.ui
@@ -337,7 +337,7 @@
          </packing>
        </child>
        <child>
          <object class="swuilo-SwEnvPreview" id="preview">
          <object class="GtkDrawingArea" id="preview">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child internal-child="accessible">
diff --git a/sw/uiconfig/swriter/ui/envformatpage.ui b/sw/uiconfig/swriter/ui/envformatpage.ui
index e6fae48..8e8d742 100644
--- a/sw/uiconfig/swriter/ui/envformatpage.ui
+++ b/sw/uiconfig/swriter/ui/envformatpage.ui
@@ -1,10 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<interface domain="sw">
  <!-- interface-requires gtk+ 3.0 -->
  <!-- interface-requires LibreOffice 1.0 -->
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkAdjustment" id="adjustment1">
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkAdjustment" id="adjustment2">
    <property name="lower">5</property>
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkAdjustment" id="adjustment3">
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkAdjustment" id="adjustment4">
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkAdjustment" id="adjustment5">
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkAdjustment" id="adjustment6">
    <property name="lower">5</property>
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkMenu" id="editmenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkMenuItem" id="character">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="envformatpage|character">C_haracter...</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="paragraph">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="envformatpage|paragraph">P_aragraph...</property>
        <property name="use_underline">True</property>
      </object>
    </child>
  </object>
  <object class="GtkGrid" id="EnvFormatPage">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="hexpand">True</property>
    <property name="vexpand">True</property>
    <property name="border_width">6</property>
    <property name="row_spacing">12</property>
    <child>
@@ -44,31 +98,29 @@
                            <property name="row_spacing">6</property>
                            <property name="column_spacing">12</property>
                            <child>
                              <object class="GtkSpinButton" id="leftaddr:0.00cm">
                              <object class="GtkSpinButton" id="leftaddr">
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="activates_default">True</property>
                                <property name="adjustment">adjustment1</property>
                                <property name="digits">2</property>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
                              <object class="GtkSpinButton" id="topaddr:0.00cm">
                              <object class="GtkSpinButton" id="topaddr">
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="adjustment">adjustment1</property>
                                <property name="activates_default">True</property>
                                <property name="adjustment">adjustment3</property>
                                <property name="digits">2</property>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">1</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
@@ -81,10 +133,10 @@
                                    <property name="visible">True</property>
                                    <property name="can_focus">False</property>
                                    <property name="margin_left">12</property>
                                    <property name="xalign">0</property>
                                    <property name="label" translatable="yes" context="envformatpage|label5">from left</property>
                                    <property name="use_underline">True</property>
                                    <property name="mnemonic_widget">leftaddr:0.00cm</property>
                                    <property name="mnemonic_widget">leftaddr</property>
                                    <property name="xalign">0</property>
                                  </object>
                                  <packing>
                                    <property name="expand">False</property>
@@ -96,8 +148,6 @@
                              <packing>
                                <property name="left_attach">0</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
@@ -110,10 +160,10 @@
                                    <property name="visible">True</property>
                                    <property name="can_focus">False</property>
                                    <property name="margin_left">12</property>
                                    <property name="xalign">0</property>
                                    <property name="label" translatable="yes" context="envformatpage|label6">from top</property>
                                    <property name="use_underline">True</property>
                                    <property name="mnemonic_widget">topaddr:0.00cm</property>
                                    <property name="mnemonic_widget">topaddr</property>
                                    <property name="xalign">0</property>
                                  </object>
                                  <packing>
                                    <property name="expand">False</property>
@@ -125,16 +175,12 @@
                              <packing>
                                <property name="left_attach">0</property>
                                <property name="top_attach">1</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                          </object>
                          <packing>
                            <property name="left_attach">0</property>
                            <property name="top_attach">0</property>
                            <property name="width">1</property>
                            <property name="height">1</property>
                          </packing>
                        </child>
                        <child>
@@ -147,44 +193,36 @@
                              <object class="GtkLabel" id="label7">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="xalign">0</property>
                                <property name="label" translatable="yes" context="envformatpage|label7">Format</property>
                                <property name="use_underline">True</property>
                                <property name="mnemonic_widget">addredit:editmenu</property>
                                <property name="mnemonic_widget">addredit</property>
                                <property name="xalign">0</property>
                              </object>
                              <packing>
                                <property name="left_attach">0</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
                              <object class="GtkButton" id="addredit:editmenu">
                              <object class="GtkMenuButton" id="addredit">
                                <property name="label" translatable="yes" context="envformatpage|addredit">Edit</property>
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="receives_default">True</property>
                                <property name="popup">editmenu</property>
                                <child>
                                  <placeholder/>
                                </child>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
                              <placeholder/>
                            </child>
                            <child>
                              <placeholder/>
                            </child>
                          </object>
                          <packing>
                            <property name="left_attach">1</property>
                            <property name="top_attach">0</property>
                            <property name="width">1</property>
                            <property name="height">1</property>
                          </packing>
                        </child>
                      </object>
@@ -216,8 +254,6 @@
      <packing>
        <property name="left_attach">0</property>
        <property name="top_attach">0</property>
        <property name="width">1</property>
        <property name="height">1</property>
      </packing>
    </child>
    <child>
@@ -259,31 +295,29 @@
                            <property name="row_spacing">6</property>
                            <property name="column_spacing">12</property>
                            <child>
                              <object class="GtkSpinButton" id="leftsender:0.00cm">
                              <object class="GtkSpinButton" id="leftsender">
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="adjustment">adjustment1</property>
                                <property name="activates_default">True</property>
                                <property name="adjustment">adjustment4</property>
                                <property name="digits">2</property>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
                              <object class="GtkSpinButton" id="topsender:0.00cm">
                              <object class="GtkSpinButton" id="topsender">
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="adjustment">adjustment1</property>
                                <property name="activates_default">True</property>
                                <property name="adjustment">adjustment5</property>
                                <property name="digits">2</property>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">1</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
@@ -296,10 +330,10 @@
                                    <property name="visible">True</property>
                                    <property name="can_focus">False</property>
                                    <property name="margin_left">12</property>
                                    <property name="xalign">0</property>
                                    <property name="label" translatable="yes" context="envformatpage|label8">from left</property>
                                    <property name="use_underline">True</property>
                                    <property name="mnemonic_widget">leftsender:0.00cm</property>
                                    <property name="mnemonic_widget">leftsender</property>
                                    <property name="xalign">0</property>
                                  </object>
                                  <packing>
                                    <property name="expand">False</property>
@@ -311,8 +345,6 @@
                              <packing>
                                <property name="left_attach">0</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
@@ -325,10 +357,10 @@
                                    <property name="visible">True</property>
                                    <property name="can_focus">False</property>
                                    <property name="margin_left">12</property>
                                    <property name="xalign">0</property>
                                    <property name="label" translatable="yes" context="envformatpage|label9">from top</property>
                                    <property name="use_underline">True</property>
                                    <property name="mnemonic_widget">topsender:0.00cm</property>
                                    <property name="mnemonic_widget">topsender</property>
                                    <property name="xalign">0</property>
                                  </object>
                                  <packing>
                                    <property name="expand">False</property>
@@ -340,16 +372,12 @@
                              <packing>
                                <property name="left_attach">0</property>
                                <property name="top_attach">1</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                          </object>
                          <packing>
                            <property name="left_attach">0</property>
                            <property name="top_attach">0</property>
                            <property name="width">1</property>
                            <property name="height">1</property>
                          </packing>
                        </child>
                        <child>
@@ -362,44 +390,36 @@
                              <object class="GtkLabel" id="label10">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="xalign">0</property>
                                <property name="label" translatable="yes" context="envformatpage|label10">Format</property>
                                <property name="use_underline">True</property>
                                <property name="mnemonic_widget">senderedit:editmenu</property>
                                <property name="mnemonic_widget">senderedit</property>
                                <property name="xalign">0</property>
                              </object>
                              <packing>
                                <property name="left_attach">0</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
                              <object class="GtkButton" id="senderedit:editmenu">
                              <object class="GtkMenuButton" id="senderedit">
                                <property name="label" translatable="yes" context="envformatpage|senderedit">Edit</property>
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="receives_default">True</property>
                                <property name="popup">editmenu</property>
                                <child>
                                  <placeholder/>
                                </child>
                              </object>
                              <packing>
                                <property name="left_attach">1</property>
                                <property name="top_attach">0</property>
                                <property name="width">1</property>
                                <property name="height">1</property>
                              </packing>
                            </child>
                            <child>
                              <placeholder/>
                            </child>
                            <child>
                              <placeholder/>
                            </child>
                          </object>
                          <packing>
                            <property name="left_attach">1</property>
                            <property name="top_attach">0</property>
                            <property name="width">1</property>
                            <property name="height">1</property>
                          </packing>
                        </child>
                      </object>
@@ -431,8 +451,6 @@
      <packing>
        <property name="left_attach">0</property>
        <property name="top_attach">1</property>
        <property name="width">1</property>
        <property name="height">1</property>
      </packing>
    </child>
    <child>
@@ -466,104 +484,90 @@
                      <object class="GtkLabel" id="label12">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes" context="envformatpage|label12">F_ormat</property>
                        <property name="use_underline">True</property>
                        <property name="mnemonic_widget">format</property>
                        <property name="xalign">0</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkLabel" id="label13">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes" context="envformatpage|label13">_Width</property>
                        <property name="use_underline">True</property>
                        <property name="mnemonic_widget">width:0.00cm</property>
                        <property name="mnemonic_widget">width</property>
                        <property name="xalign">0</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">1</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkLabel" id="label14">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes" context="envformatpage|label14">_Height</property>
                        <property name="use_underline">True</property>
                        <property name="mnemonic_widget">height:0.00cm</property>
                        <property name="mnemonic_widget">height</property>
                        <property name="xalign">0</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">2</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkSpinButton" id="width:0.00cm">
                      <object class="GtkSpinButton" id="width">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="halign">start</property>
                        <property name="activates_default">True</property>
                        <property name="adjustment">adjustment2</property>
                        <property name="digits">2</property>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>
                        <property name="top_attach">1</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkSpinButton" id="height:0.00cm">
                      <object class="GtkSpinButton" id="height">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="halign">start</property>
                        <property name="adjustment">adjustment2</property>
                        <property name="activates_default">True</property>
                        <property name="adjustment">adjustment6</property>
                        <property name="digits">2</property>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>
                        <property name="top_attach">2</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkComboBoxText" id="format">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="entry_text_column">0</property>
                        <property name="id_column">1</property>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>
                        <property name="top_attach">0</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">0</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                  </packing>
                </child>
                <child>
                  <object class="swuilo-SwEnvPreview" id="preview">
                  <object class="GtkDrawingArea" id="preview">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <child internal-child="accessible">
@@ -575,8 +579,6 @@
                  <packing>
                    <property name="left_attach">1</property>
                    <property name="top_attach">0</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                  </packing>
                </child>
              </object>
@@ -597,50 +599,17 @@
      <packing>
        <property name="left_attach">0</property>
        <property name="top_attach">2</property>
        <property name="width">1</property>
        <property name="height">1</property>
      </packing>
    </child>
  </object>
  <object class="GtkAdjustment" id="adjustment1">
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkAdjustment" id="adjustment2">
    <property name="lower">5</property>
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkMenu" id="editmenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkMenuItem" id="character">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="envformatpage|character">C_haracter...</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="paragraph">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="envformatpage|paragraph">P_aragraph...</property>
        <property name="use_underline">True</property>
      </object>
    </child>
  </object>
  <object class="GtkSizeGroup" id="sizegroup1">
    <widgets>
      <widget name="leftaddr:0.00cm"/>
      <widget name="topaddr:0.00cm"/>
      <widget name="leftsender:0.00cm"/>
      <widget name="topsender:0.00cm"/>
      <widget name="width:0.00cm"/>
      <widget name="height:0.00cm"/>
      <widget name="leftaddr"/>
      <widget name="topaddr"/>
      <widget name="leftsender"/>
      <widget name="topsender"/>
      <widget name="width"/>
      <widget name="height"/>
    </widgets>
  </object>
  <object class="GtkSizeGroup" id="sizegroup2">
diff --git a/sw/uiconfig/swriter/ui/envprinterpage.ui b/sw/uiconfig/swriter/ui/envprinterpage.ui
index 82ff983..43f6f7e 100644
--- a/sw/uiconfig/swriter/ui/envprinterpage.ui
+++ b/sw/uiconfig/swriter/ui/envprinterpage.ui
@@ -1,14 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<interface domain="sw">
  <!-- interface-requires gtk+ 3.0 -->
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkAdjustment" id="adjustment1">
    <property name="upper">100</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkImage" id="image1">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envhl_l.png</property>
  </object>
  <object class="GtkImage" id="image10">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envvl_u.png</property>
  </object>
  <object class="GtkImage" id="image11">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envvc_u.png</property>
  </object>
  <object class="GtkImage" id="image12">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envvr_u.png</property>
  </object>
  <object class="GtkImage" id="image2">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envhc_l.png</property>
  </object>
  <object class="GtkImage" id="image3">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envhr_l.png</property>
  </object>
  <object class="GtkImage" id="image4">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envvl_l.png</property>
  </object>
  <object class="GtkImage" id="image5">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envvc_l.png</property>
  </object>
  <object class="GtkImage" id="image6">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envvr_l.png</property>
  </object>
  <object class="GtkImage" id="image7">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envhl_u.png</property>
  </object>
  <object class="GtkImage" id="image8">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envhc_u.png</property>
  </object>
  <object class="GtkImage" id="image9">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">sw/res/envhr_u.png</property>
  </object>
  <object class="GtkBox" id="EnvPrinterPage">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="hexpand">True</property>
    <property name="vexpand">True</property>
    <property name="border_width">6</property>
    <property name="orientation">vertical</property>
    <property name="spacing">12</property>
@@ -40,13 +103,11 @@
                    <property name="xalign">0</property>
                    <property name="active">True</property>
                    <property name="draw_indicator">True</property>
                    <property name="group">bottom</property>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">1</property>
                    <property name="top_attach">2</property>
                    <property name="width">2</property>
                    <property name="height">1</property>
                  </packing>
                </child>
                <child>
@@ -62,154 +123,161 @@
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">2</property>
                    <property name="top_attach">3</property>
                    <property name="width">2</property>
                    <property name="height">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkLabel" id="label3">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes" context="envprinterpage|label3">_Shift right</property>
                    <property name="use_underline">True</property>
                    <property name="mnemonic_widget">right</property>
                    <property name="xalign">0</property>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">3</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                    <property name="top_attach">4</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkLabel" id="label4">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes" context="envprinterpage|label4">Shift _down</property>
                    <property name="use_underline">True</property>
                    <property name="mnemonic_widget">down</property>
                    <property name="xalign">0</property>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">4</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                    <property name="top_attach">5</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkSpinButton" id="right:0.00cm">
                  <object class="GtkSpinButton" id="right">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="activates_default">True</property>
                    <property name="digits">2</property>
                  </object>
                  <packing>
                    <property name="left_attach">1</property>
                    <property name="top_attach">3</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                    <property name="top_attach">4</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkSpinButton" id="down:0.00cm">
                  <object class="GtkSpinButton" id="down">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="activates_default">True</property>
                    <property name="adjustment">adjustment1</property>
                    <property name="digits">2</property>
                  </object>
                  <packing>
                    <property name="left_attach">1</property>
                    <property name="top_attach">4</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                    <property name="top_attach">5</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolbar" id="alignbox">
                    <property name="visible">True</property>
                  <object class="GtkGrid" id="lower">
                    <property name="can_focus">False</property>
                    <property name="column_spacing">6</property>
                    <child>
                      <object class="GtkToolButton" id="horileft">
                      <object class="GtkRadioButton" id="horileftl">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horileft|tooltip_text">Horizontal Left</property>
                        <property name="action_name">horileft</property>
                        <property name="label" translatable="yes" context="envprinterpage|horileft">Horizontal Left</property>
                        <property name="use_underline">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horileftl|tooltip_text">Horizontal Left</property>
                        <property name="image">image1</property>
                        <property name="always_show_image">True</property>
                        <property name="active">True</property>
                        <property name="draw_indicator">True</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">True</property>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="horicenter">
                      <object class="GtkRadioButton" id="horicenterl">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horicenter|tooltip_text">Horizontal Center</property>
                        <property name="action_name">horicenter</property>
                        <property name="label" translatable="yes" context="envprinterpage|horicenter">Horizontal Center</property>
                        <property name="use_underline">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horicenterl|tooltip_text">Horizontal Center</property>
                        <property name="image">image2</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftl</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">True</property>
                        <property name="left_attach">1</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="horiright">
                      <object class="GtkRadioButton" id="horirightl">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horiright|tooltip_text">Horizontal Right</property>
                        <property name="action_name">horiright</property>
                        <property name="label" translatable="yes" context="envprinterpage|horiright">Horizontal Right</property>
                        <property name="use_underline">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horirightl|tooltip_text">Horizontal Right</property>
                        <property name="image">image3</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftl</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">True</property>
                        <property name="left_attach">2</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="vertleft">
                      <object class="GtkRadioButton" id="vertleftl">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertleft|tooltip_text">Vertical Left</property>
                        <property name="action_name">vertleft</property>
                        <property name="label" translatable="yes" context="envprinterpage|vertleft">Vertical Left</property>
                        <property name="use_underline">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertleftl|tooltip_text">Vertical Left</property>
                        <property name="image">image4</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftl</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">True</property>
                        <property name="left_attach">3</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="vertcenter">
                      <object class="GtkRadioButton" id="vertcenterl">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertcenter|tooltip_text">Vertical Center</property>
                        <property name="action_name">vertcenter</property>
                        <property name="label" translatable="yes" context="envprinterpage|vertcenter">Vertical Center</property>
                        <property name="use_underline">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertcenterl|tooltip_text">Vertical Center</property>
                        <property name="image">image5</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftl</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">True</property>
                        <property name="left_attach">4</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="vertright">
                      <object class="GtkRadioButton" id="vertrightl">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertright|tooltip_text">Vertical Right</property>
                        <property name="action_name">vertright</property>
                        <property name="label" translatable="yes" context="envprinterpage|vertright">Vertical Right</property>
                        <property name="use_underline">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertrightl|tooltip_text">Vertical Right</property>
                        <property name="image">image6</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftl</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">True</property>
                        <property name="left_attach">5</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                  </object>
@@ -217,7 +285,114 @@
                    <property name="left_attach">0</property>
                    <property name="top_attach">0</property>
                    <property name="width">2</property>
                    <property name="height">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkGrid" id="upper">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="column_spacing">6</property>
                    <child>
                      <object class="GtkRadioButton" id="horileftu">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horileftu|tooltip_text">Horizontal Left</property>
                        <property name="image">image7</property>
                        <property name="always_show_image">True</property>
                        <property name="active">True</property>
                        <property name="draw_indicator">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkRadioButton" id="horicenteru">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horicenteru|tooltip_text">Horizontal Center</property>
                        <property name="image">image8</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftu</property>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkRadioButton" id="horirightu">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|horirightu|tooltip_text">Horizontal Right</property>
                        <property name="image">image9</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftu</property>
                      </object>
                      <packing>
                        <property name="left_attach">2</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkRadioButton" id="vertleftu">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertleftu|tooltip_text">Vertical Left</property>
                        <property name="image">image10</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftu</property>
                      </object>
                      <packing>
                        <property name="left_attach">3</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkRadioButton" id="vertcenteru">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertcenteru|tooltip_text">Vertical Center</property>
                        <property name="image">image11</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftu</property>
                      </object>
                      <packing>
                        <property name="left_attach">4</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkRadioButton" id="vertrightu">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="tooltip_text" translatable="yes" context="envprinterpage|vertrightu|tooltip_text">Vertical Right</property>
                        <property name="image">image12</property>
                        <property name="always_show_image">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">horileftu</property>
                      </object>
                      <packing>
                        <property name="left_attach">5</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">1</property>
                    <property name="width">2</property>
                  </packing>
                </child>
              </object>
@@ -272,8 +447,6 @@
                  <packing>
                    <property name="left_attach">1</property>
                    <property name="top_attach">0</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                  </packing>
                </child>
                <child>
@@ -281,16 +454,14 @@
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="hexpand">True</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes" context="envprinterpage|printername">Printer Name</property>
                    <property name="use_underline">True</property>
                    <property name="mnemonic_widget">setup</property>
                    <property name="xalign">0</property>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">0</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                  </packing>
                </child>
              </object>