diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-09-07 13:42:54 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-09-08 15:07:22 +0200 |
commit | 842c71a1fae1def3e8b694ae3b820b34ad26bce4 (patch) | |
tree | 8b00253118bb278c5dda9b2a97897e93e2f9e691 /cui | |
parent | 97b6fd8e9ec4c655a5b73cbb4f64be06e7057242 (diff) |
weld FontFeaturesDialog
Change-Id: I67ab7388593aceb00b660e4d40904a4eef247620
Reviewed-on: https://gerrit.libreoffice.org/60148
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/UIConfig_cui.mk | 1 | ||||
-rw-r--r-- | cui/source/dialogs/FontFeaturesDialog.cxx | 122 | ||||
-rw-r--r-- | cui/source/inc/FontFeaturesDialog.hxx | 37 | ||||
-rw-r--r-- | cui/source/tabpages/chardlg.cxx | 6 | ||||
-rw-r--r-- | cui/uiconfig/ui/fontfeaturesdialog.ui | 33 | ||||
-rw-r--r-- | cui/uiconfig/ui/fontfragment.ui | 50 |
6 files changed, 151 insertions, 98 deletions
diff --git a/cui/UIConfig_cui.mk b/cui/UIConfig_cui.mk index dd3e94bb1a9b..d6ba15a82667 100644 --- a/cui/UIConfig_cui.mk +++ b/cui/UIConfig_cui.mk @@ -53,6 +53,7 @@ $(eval $(call gb_UIConfig_add_uifiles,cui,\ cui/uiconfig/ui/embossdialog \ cui/uiconfig/ui/eventassigndialog \ cui/uiconfig/ui/eventassignpage \ + cui/uiconfig/ui/fontfragment \ cui/uiconfig/ui/formatnumberdialog \ cui/uiconfig/ui/fmsearchdialog \ cui/uiconfig/ui/gradientpage \ diff --git a/cui/source/dialogs/FontFeaturesDialog.cxx b/cui/source/dialogs/FontFeaturesDialog.cxx index 078e9a630a80..272031bc54a4 100644 --- a/cui/source/dialogs/FontFeaturesDialog.cxx +++ b/cui/source/dialogs/FontFeaturesDialog.cxx @@ -16,28 +16,23 @@ using namespace css; namespace cui { -FontFeaturesDialog::FontFeaturesDialog(vcl::Window* pParent, OUString const& rFontName) - : ModalDialog(pParent, "FontFeaturesDialog", "cui/ui/fontfeaturesdialog.ui") +FontFeaturesDialog::FontFeaturesDialog(weld::Window* pParent, OUString const& rFontName) + : GenericDialogController(pParent, "cui/ui/fontfeaturesdialog.ui", "FontFeaturesDialog") , m_sFontName(rFontName) + , m_xContentWindow(m_xBuilder->weld_scrolled_window("contentWindow")) + , m_xContentGrid(m_xBuilder->weld_container("contentGrid")) + , m_xPreviewWindow(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWindow)) { - get(m_pContentGrid, "contentGrid"); - get(m_pPreviewWindow, "preview"); initialize(); } -FontFeaturesDialog::~FontFeaturesDialog() { disposeOnce(); } +FontFeaturesDialog::~FontFeaturesDialog() {} -VclPtr<ComboBox> makeEnumComboBox(vcl::Window* pParent, - vcl::font::FeatureDefinition const& rFeatureDefinition) +void makeEnumComboBox(weld::ComboBoxText& rNameBox, + vcl::font::FeatureDefinition const& rFeatureDefinition) { - VclPtr<ComboBox> aNameBox( - VclPtr<ComboBox>::Create(pParent, WB_TABSTOP | WB_DROPDOWN | WB_AUTOHSCROLL)); for (vcl::font::FeatureParameter const& rParameter : rFeatureDefinition.getEnumParameters()) - { - aNameBox->InsertEntry(rParameter.getDescription()); - } - aNameBox->EnableAutoSize(true); - return aNameBox; + rNameBox.append_text(rParameter.getDescription()); } void FontFeaturesDialog::initialize() @@ -88,7 +83,7 @@ void FontFeaturesDialog::fillGrid(std::vector<vcl::font::Feature> const& rFontFe if (!aDefinition) aDefinition = { nFontFeatureCode, nullptr }; - m_aFeatureItems.emplace_back(); + m_aFeatureItems.emplace_back(m_xContentGrid.get()); sal_uInt32 nValue = 0; if (aExistingFeatures.find(nFontFeatureCode) != aExistingFeatures.end()) @@ -99,63 +94,47 @@ void FontFeaturesDialog::fillGrid(std::vector<vcl::font::Feature> const& rFontFe sal_Int32 nGridPositionX = (i % 2) * 2; sal_Int32 nGridPositionY = i / 2; + aCurrentItem.m_xContainer->set_grid_left_attach(nGridPositionX); + aCurrentItem.m_xContainer->set_grid_top_attach(nGridPositionY); - Link<ComboBox&, void> aComboBoxSelectHandler + Link<weld::ComboBoxText&, void> aComboBoxSelectHandler = LINK(this, FontFeaturesDialog, ComboBoxSelectedHdl); - Link<CheckBox&, void> aCheckBoxToggleHandler + Link<weld::ToggleButton&, void> aCheckBoxToggleHandler = LINK(this, FontFeaturesDialog, CheckBoxToggledHdl); if (aDefinition.getType() == vcl::font::FeatureParameterType::ENUM) { - aCurrentItem.m_pText - = VclPtr<FixedText>::Create(m_pContentGrid, WB_LEFT | WB_VCENTER | WB_3DLOOK); - aCurrentItem.m_pText->set_grid_left_attach(nGridPositionX); - aCurrentItem.m_pText->set_grid_top_attach(nGridPositionY); - aCurrentItem.m_pText->set_margin_left(6); - aCurrentItem.m_pText->set_margin_right(6); - aCurrentItem.m_pText->set_margin_top(3); - aCurrentItem.m_pText->set_margin_bottom(3); - aCurrentItem.m_pText->SetText(aDefinition.getDescription()); - aCurrentItem.m_pText->Show(); - - aCurrentItem.m_pCombo = makeEnumComboBox(m_pContentGrid, aDefinition); - - aCurrentItem.m_pCombo->SelectEntryPos(nValue); - aCurrentItem.m_pCombo->set_grid_left_attach(nGridPositionX + 1); - aCurrentItem.m_pCombo->set_grid_top_attach(nGridPositionY); - aCurrentItem.m_pCombo->set_margin_left(6); - aCurrentItem.m_pCombo->set_margin_right(6); - aCurrentItem.m_pCombo->set_margin_top(3); - aCurrentItem.m_pCombo->set_margin_bottom(3); - aCurrentItem.m_pCombo->SetSelectHdl(aComboBoxSelectHandler); - aCurrentItem.m_pCombo->Show(); + aCurrentItem.m_xText->set_label(aDefinition.getDescription()); + aCurrentItem.m_xText->show(); + + makeEnumComboBox(*aCurrentItem.m_xCombo, aDefinition); + + aCurrentItem.m_xCombo->set_active(nValue); + aCurrentItem.m_xCombo->connect_changed(aComboBoxSelectHandler); + aCurrentItem.m_xCombo->show(); } else { - aCurrentItem.m_pCheck = VclPtr<CheckBox>::Create( - m_pContentGrid, WB_CLIPCHILDREN | WB_LEFT | WB_VCENTER | WB_3DLOOK); - aCurrentItem.m_pCheck->set_grid_left_attach(nGridPositionX); - aCurrentItem.m_pCheck->set_grid_top_attach(nGridPositionY); - aCurrentItem.m_pCheck->set_grid_width(2); - aCurrentItem.m_pCheck->set_margin_left(6); - aCurrentItem.m_pCheck->set_margin_right(6); - aCurrentItem.m_pCheck->set_margin_top(3); - aCurrentItem.m_pCheck->set_margin_bottom(3); - aCurrentItem.m_pCheck->Check(nValue > 0); - aCurrentItem.m_pCheck->SetText(aDefinition.getDescription()); - aCurrentItem.m_pCheck->SetToggleHdl(aCheckBoxToggleHandler); - aCurrentItem.m_pCheck->Show(); + aCurrentItem.m_xCheck->set_active(nValue > 0); + aCurrentItem.m_xCheck->set_label(aDefinition.getDescription()); + aCurrentItem.m_xCheck->connect_toggled(aCheckBoxToggleHandler); + aCurrentItem.m_xCheck->show(); } i++; } + + Size aSize(m_xContentWindow->get_preferred_size()); + Size aMaxSize(std::min<int>(aSize.Width(), m_xContentGrid->get_approximate_digit_width() * 100), + std::min<int>(aSize.Height(), m_xContentGrid->get_text_height() * 20)); + m_xContentWindow->set_size_request(aMaxSize.Width(), aMaxSize.Height()); } void FontFeaturesDialog::updateFontPreview() { - vcl::Font rPreviewFont = m_pPreviewWindow->GetFont(); - vcl::Font rPreviewFontCJK = m_pPreviewWindow->GetCJKFont(); - vcl::Font rPreviewFontCTL = m_pPreviewWindow->GetCTLFont(); + vcl::Font rPreviewFont = m_aPreviewWindow.GetFont(); + vcl::Font rPreviewFontCJK = m_aPreviewWindow.GetCJKFont(); + vcl::Font rPreviewFontCTL = m_aPreviewWindow.GetCTLFont(); OUString sNewFontName = createFontNameWithFeatures(); @@ -163,25 +142,18 @@ void FontFeaturesDialog::updateFontPreview() rPreviewFontCJK.SetFamilyName(sNewFontName); rPreviewFontCTL.SetFamilyName(sNewFontName); - m_pPreviewWindow->SetFont(rPreviewFont, rPreviewFontCJK, rPreviewFontCTL); + m_aPreviewWindow.SetFont(rPreviewFont, rPreviewFontCJK, rPreviewFontCTL); } -void FontFeaturesDialog::dispose() +IMPL_LINK_NOARG(FontFeaturesDialog, CheckBoxToggledHdl, weld::ToggleButton&, void) { - m_pContentGrid.clear(); - m_pPreviewWindow.clear(); - for (FontFeatureItem& rItem : m_aFeatureItems) - { - rItem.m_pText.disposeAndClear(); - rItem.m_pCombo.disposeAndClear(); - rItem.m_pCheck.disposeAndClear(); - } - ModalDialog::dispose(); + updateFontPreview(); } -IMPL_LINK_NOARG(FontFeaturesDialog, CheckBoxToggledHdl, CheckBox&, void) { updateFontPreview(); } - -IMPL_LINK_NOARG(FontFeaturesDialog, ComboBoxSelectedHdl, ComboBox&, void) { updateFontPreview(); } +IMPL_LINK_NOARG(FontFeaturesDialog, ComboBoxSelectedHdl, weld::ComboBoxText&, void) +{ + updateFontPreview(); +} OUString FontFeaturesDialog::createFontNameWithFeatures() { @@ -191,9 +163,9 @@ OUString FontFeaturesDialog::createFontNameWithFeatures() for (FontFeatureItem& rItem : m_aFeatureItems) { - if (rItem.m_pCheck) + if (rItem.m_xCheck->get_visible()) { - if (rItem.m_pCheck->IsChecked()) + if (rItem.m_xCheck->get_active()) { if (!bFirst) sNameSuffix.append(OUString(vcl::font::FeatureSeparator)); @@ -203,9 +175,9 @@ OUString FontFeaturesDialog::createFontNameWithFeatures() sNameSuffix.append(vcl::font::featureCodeAsString(rItem.m_aFeatureCode)); } } - else if (rItem.m_pCombo && rItem.m_pText) + else if (rItem.m_xCombo->get_visible() && rItem.m_xText->get_visible()) { - sal_uInt32 nSelection = rItem.m_pCombo->GetSelectedEntryPos(); + int nSelection = rItem.m_xCombo->get_active(); if (nSelection > 0) { if (!bFirst) @@ -225,9 +197,9 @@ OUString FontFeaturesDialog::createFontNameWithFeatures() return sResultFontName; } -short FontFeaturesDialog::Execute() +short FontFeaturesDialog::execute() { - short nResult = ModalDialog::Execute(); + short nResult = m_xDialog->run(); if (nResult == RET_OK) { m_sResultFontName = createFontNameWithFeatures(); diff --git a/cui/source/inc/FontFeaturesDialog.hxx b/cui/source/inc/FontFeaturesDialog.hxx index aa3a4aa22d0f..0ba23fe6186c 100644 --- a/cui/source/inc/FontFeaturesDialog.hxx +++ b/cui/source/inc/FontFeaturesDialog.hxx @@ -11,7 +11,8 @@ #ifndef INCLUDED_CUI_SOURCE_INC_FONTFEATURESDIALOG_HXX #define INCLUDED_CUI_SOURCE_INC_FONTFEATURESDIALOG_HXX -#include <vcl/layout.hxx> +#include <vcl/svapp.hxx> +#include <vcl/weld.hxx> #include <vcl/font/Feature.hxx> #include <svx/fntctrl.hxx> #include "chardlg.hxx" @@ -21,40 +22,48 @@ namespace cui { struct FontFeatureItem { - FontFeatureItem() + FontFeatureItem(weld::Widget* pParent) : m_aFeatureCode(0) + , m_xBuilder(Application::CreateBuilder(pParent, "cui/ui/fontfragment.ui")) + , m_xContainer(m_xBuilder->weld_widget("fontentry")) + , m_xText(m_xBuilder->weld_label("label")) + , m_xCombo(m_xBuilder->weld_combo_box_text("combo")) + , m_xCheck(m_xBuilder->weld_check_button("check")) { } sal_uInt32 m_aFeatureCode; - VclPtr<Control> m_pText; - VclPtr<ComboBox> m_pCombo; - VclPtr<CheckBox> m_pCheck; + std::unique_ptr<weld::Builder> m_xBuilder; + std::unique_ptr<weld::Widget> m_xContainer; + std::unique_ptr<weld::Label> m_xText; + std::unique_ptr<weld::ComboBoxText> m_xCombo; + std::unique_ptr<weld::CheckButton> m_xCheck; }; -class FontFeaturesDialog : public ModalDialog +class FontFeaturesDialog : public weld::GenericDialogController { private: - VclPtr<VclGrid> m_pContentGrid; - VclPtr<SvxFontPrevWindow> m_pPreviewWindow; - std::vector<FontFeatureItem> m_aFeatureItems; OUString m_sFontName; OUString m_sResultFontName; + FontPrevWindow m_aPreviewWindow; + std::unique_ptr<weld::ScrolledWindow> m_xContentWindow; + std::unique_ptr<weld::Container> m_xContentGrid; + std::unique_ptr<weld::CustomWeld> m_xPreviewWindow; + void initialize(); OUString createFontNameWithFeatures(); void fillGrid(std::vector<vcl::font::Feature> const& rFontFeatures); - DECL_LINK(ComboBoxSelectedHdl, ComboBox&, void); - DECL_LINK(CheckBoxToggledHdl, CheckBox&, void); + DECL_LINK(ComboBoxSelectedHdl, weld::ComboBoxText&, void); + DECL_LINK(CheckBoxToggledHdl, weld::ToggleButton&, void); public: - FontFeaturesDialog(vcl::Window* pParent, OUString const& rFontName); + FontFeaturesDialog(weld::Window* pParent, OUString const& rFontName); ~FontFeaturesDialog() override; - void dispose() override; - short Execute() override; + short execute(); OUString const& getResultFontName() { return m_sResultFontName; } diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx index 2c729da529f6..1bb2f41b4f82 100644 --- a/cui/source/tabpages/chardlg.cxx +++ b/cui/source/tabpages/chardlg.cxx @@ -1226,10 +1226,10 @@ IMPL_LINK(SvxCharNamePage, FontFeatureButtonClicked, Button*, pButton, void ) if (!sFontName.isEmpty() && pNameBox) { - ScopedVclPtrInstance<cui::FontFeaturesDialog> pDialog(this, sFontName); - if (pDialog->Execute() == RET_OK) + cui::FontFeaturesDialog aDialog(GetDialogFrameWeld(), sFontName); + if (aDialog.execute() == RET_OK) { - pNameBox->SetText(pDialog->getResultFontName()); + pNameBox->SetText(aDialog.getResultFontName()); UpdatePreview_Impl(); } } diff --git a/cui/uiconfig/ui/fontfeaturesdialog.ui b/cui/uiconfig/ui/fontfeaturesdialog.ui index 33964b4538bd..dcbce1de44c2 100644 --- a/cui/uiconfig/ui/fontfeaturesdialog.ui +++ b/cui/uiconfig/ui/fontfeaturesdialog.ui @@ -2,8 +2,9 @@ <!-- Generated with glade 3.22.1 --> <interface domain="cui"> <requires lib="gtk+" version="3.18"/> - <requires lib="LibreOffice" version="1.0"/> <object class="GtkDialog" id="FontFeaturesDialog"> + <property name="width_request">-1</property> + <property name="height_request">-1</property> <property name="can_focus">False</property> <property name="border_width">6</property> <property name="title" translatable="yes" context="fontfeaturesdialog|FontFeaturesDialog">Font Features</property> @@ -82,10 +83,12 @@ <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> - <object class="GtkScrolledWindow"> + <object class="GtkScrolledWindow" id="contentWindow"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="shadow_type">in</property> + <property name="propagate_natural_width">True</property> + <property name="propagate_natural_height">True</property> <child> <object class="GtkViewport"> <property name="visible">True</property> @@ -94,6 +97,9 @@ <object class="GtkGrid" id="contentGrid"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="valign">start</property> + <property name="row_spacing">6</property> + <property name="column_spacing">12</property> <child> <placeholder/> </child> @@ -141,12 +147,27 @@ <property name="left_padding">12</property> <property name="right_padding">12</property> <child> - <object class="svxlo-SvxFontPrevWindow" id="preview:border"> + <object class="GtkScrolledWindow" id="previewwin"> <property name="visible">True</property> <property name="can_focus">False</property> - <child internal-child="accessible"> - <object class="AtkObject" id="preview:border-atkobject"> - <property name="AtkObject::accessible-name" translatable="yes" context="fontfeaturesdialog|preview-atkobject">Preview</property> + <property name="hscrollbar_policy">never</property> + <property name="vscrollbar_policy">never</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkViewport"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkDrawingArea" id="preview"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child internal-child="accessible"> + <object class="AtkObject" id="preview-atkobject"> + <property name="AtkObject::accessible-name" translatable="yes" context="fontfeaturesdialog|preview-atkobject">Preview</property> + </object> + </child> + </object> + </child> </object> </child> </object> diff --git a/cui/uiconfig/ui/fontfragment.ui b/cui/uiconfig/ui/fontfragment.ui new file mode 100644 index 000000000000..325671d04b51 --- /dev/null +++ b/cui/uiconfig/ui/fontfragment.ui @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> +<interface domain="sw"> + <requires lib="gtk+" version="3.20"/> + <object class="GtkGrid" id="fontentry"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="no_show_all">True</property> + <property name="valign">start</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="column_spacing">6</property> + <child> + <object class="GtkLabel" id="label"> + <property name="can_focus">False</property> + <property name="no_show_all">True</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">combo</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="check"> + <property name="label">placeholder</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="no_show_all">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="left_attach">2</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="combo"> + <property name="can_focus">False</property> + <property name="no_show_all">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + </packing> + </child> + </object> +</interface> |