summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-02-28 13:30:13 +0000
committerCaolán McNamara <caolanm@redhat.com>2019-03-01 11:03:55 +0100
commitb164e74e85fc4c99f1042f22b5e3afc99ed159ca (patch)
treee283e9828760c149490f1724d24f345fe94ffd24 /sw
parent9b027c504778f3f44dcbfe7de4e9b542fa6c0a13 (diff)
weld SwSelectDBTableDialog
Change-Id: I3759d4da18a7cb5a8fce500bd15e7a004e36c605 Reviewed-on: https://gerrit.libreoffice.org/68507 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/strings.hrc2
-rw-r--r--sw/source/ui/dbui/addresslistdialog.cxx9
-rw-r--r--sw/source/ui/dbui/selectdbtabledialog.cxx130
-rw-r--r--sw/source/ui/dbui/selectdbtabledialog.hxx18
-rw-r--r--sw/uiconfig/swriter/ui/selecttabledialog.ui71
5 files changed, 113 insertions, 117 deletions
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index c5fdd50f5f77..85ec816ad3d8 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -829,8 +829,6 @@
#define ST_FINISH NC_("ST_FINISH", "~Finish")
#define ST_MMWTITLE NC_("ST_MMWTITLE", "Mail Merge Wizard")
-#define ST_NAME NC_("ST_NAME", "Name")
-#define ST_TYPE NC_("ST_TYPE", "Type")
#define ST_TABLE NC_("ST_TABLE", "Table")
#define ST_QUERY NC_("ST_QUERY", "Query")
diff --git a/sw/source/ui/dbui/addresslistdialog.cxx b/sw/source/ui/dbui/addresslistdialog.cxx
index 767800ec8f43..9d62691d751c 100644
--- a/sw/source/ui/dbui/addresslistdialog.cxx
+++ b/sw/source/ui/dbui/addresslistdialog.cxx
@@ -28,6 +28,7 @@
#include <dbconfig.hxx>
#include <unotools/tempfile.hxx>
#include <vcl/svapp.hxx>
+#include <vcl/fixed.hxx>
#include <tools/urlobj.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/types.hxx>
@@ -550,14 +551,14 @@ void SwAddressListDialog::DetectTablesAndQueries(
if(nTables > 1 && bWidthDialog)
{
//now call the table select dialog - if more than one table exists
- VclPtrInstance<SwSelectDBTableDialog> pDlg(this, pUserData->xConnection);
+ SwSelectDBTableDialog aDlg(GetFrameWeld(), pUserData->xConnection);
const OUString sTable = SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1);
if(!sTable.isEmpty())
- pDlg->SetSelectedTable(sTable, pUserData->nCommandType == CommandType::TABLE);
- if(RET_OK == pDlg->Execute())
+ aDlg.SetSelectedTable(sTable, pUserData->nCommandType == CommandType::TABLE);
+ if(RET_OK == aDlg.run())
{
bool bIsTable;
- m_aDBData.sCommand = pDlg->GetSelectedTable(bIsTable);
+ m_aDBData.sCommand = aDlg.GetSelectedTable(bIsTable);
m_aDBData.nCommandType = bIsTable ? CommandType::TABLE : CommandType::QUERY;
pUserData->nCommandType = m_aDBData.nCommandType;
}
diff --git a/sw/source/ui/dbui/selectdbtabledialog.cxx b/sw/source/ui/dbui/selectdbtabledialog.cxx
index f931563cd46a..c7c309265f5a 100644
--- a/sw/source/ui/dbui/selectdbtabledialog.cxx
+++ b/sw/source/ui/dbui/selectdbtabledialog.cxx
@@ -43,66 +43,21 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
-class SwAddressTable : public SvSimpleTable
-{
-public:
- explicit SwAddressTable(SvSimpleTableContainer& rParent);
- void InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText);
- virtual void Resize() override;
- void setColSizes();
-};
-
-SwAddressTable::SwAddressTable(SvSimpleTableContainer& rParent)
- : SvSimpleTable(rParent, 0)
-{
- SetSpaceBetweenEntries(3);
- SetSelectionMode(SelectionMode::Single);
- SetDragDropMode(DragDropMode::NONE);
- EnableAsyncDrag(false);
-}
-
-void SwAddressTable::InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText)
-{
- GetTheHeaderBar().InsertItem( nColumn, rText, 0, HeaderBarItemBits::LEFT );
-}
-
-void SwAddressTable::Resize()
-{
- SvSimpleTable::Resize();
- setColSizes();
-}
-
-void SwAddressTable::setColSizes()
-{
- HeaderBar &rHB = GetTheHeaderBar();
- if (rHB.GetItemCount() < 2)
- return;
-
- long nWidth = rHB.GetSizePixel().Width();
- nWidth /= 2;
-
- long nTabs[2] = { 0, nWidth };
- SvSimpleTable::SetTabs(SAL_N_ELEMENTS(nTabs), nTabs, MapUnit::MapPixel);
-}
-
-SwSelectDBTableDialog::SwSelectDBTableDialog(vcl::Window* pParent,
+SwSelectDBTableDialog::SwSelectDBTableDialog(weld::Window* pParent,
const uno::Reference< sdbc::XConnection>& rConnection)
- : SfxModalDialog(pParent, "SelectTableDialog", "modules/swriter/ui/selecttabledialog.ui")
+ : SfxDialogController(pParent, "modules/swriter/ui/selecttabledialog.ui", "SelectTableDialog")
, m_xConnection(rConnection)
+ , m_xTable(m_xBuilder->weld_tree_view("table"))
+ , m_xPreviewPB(m_xBuilder->weld_button("preview"))
{
- get(m_pPreviewPB, "preview");
+ m_xTable->set_size_request(m_xTable->get_approximate_digit_width() * 60,
+ m_xTable->get_height_rows(6));
- SvSimpleTableContainer *pHeaderTreeContainer = get<SvSimpleTableContainer>("table");
- Size aSize = pHeaderTreeContainer->LogicToPixel(Size(238 , 50), MapMode(MapUnit::MapAppFont));
- pHeaderTreeContainer->set_width_request(aSize.Width());
- pHeaderTreeContainer->set_height_request(aSize.Height());
- m_pTable = VclPtr<SwAddressTable>::Create(*pHeaderTreeContainer);
- long const aStaticTabs[]= { 0, 0 };
- m_pTable->SetTabs( SAL_N_ELEMENTS(aStaticTabs), aStaticTabs );
- m_pTable->InsertHeaderItem(1, SwResId(ST_NAME) );
- m_pTable->InsertHeaderItem(2, SwResId(ST_TYPE) );
+ std::vector<int> aWidths;
+ aWidths.push_back(m_xTable->get_approximate_digit_width() * 30);
+ m_xTable->set_column_fixed_widths(aWidths);
- m_pPreviewPB->SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl));
+ m_xPreviewPB->connect_clicked(LINK(this, SwSelectDBTableDialog, PreviewHdl));
Reference<XTablesSupplier> xTSupplier(m_xConnection, UNO_QUERY);
if (xTSupplier.is())
@@ -110,13 +65,11 @@ SwSelectDBTableDialog::SwSelectDBTableDialog(vcl::Window* pParent,
Reference<XNameAccess> xTables = xTSupplier->getTables();
Sequence<OUString> aTables = xTables->getElementNames();
const OUString* pTables = aTables.getConstArray();
- for(long i = 0; i < aTables.getLength(); i++)
+ for (int i = 0; i < aTables.getLength(); i++)
{
OUString sEntry = pTables[i];
- sEntry += "\t";
- sEntry += SwResId(ST_TABLE);
- SvTreeListEntry* pEntry = m_pTable->InsertEntry(sEntry);
- pEntry->SetUserData(nullptr);
+ m_xTable->append_text(sEntry);
+ m_xTable->set_text(i, SwResId(ST_TABLE), 1);
}
}
Reference<XQueriesSupplier> xQSupplier(m_xConnection, UNO_QUERY);
@@ -125,37 +78,30 @@ SwSelectDBTableDialog::SwSelectDBTableDialog(vcl::Window* pParent,
Reference<XNameAccess> xQueries = xQSupplier->getQueries();
Sequence<OUString> aQueries = xQueries->getElementNames();
const OUString* pQueries = aQueries.getConstArray();
- for(long i = 0; i < aQueries.getLength(); i++)
+ int nPos = m_xTable->n_children();
+ for (sal_Int32 i = 0; i < aQueries.getLength(); i++)
{
OUString sEntry = pQueries[i];
- sEntry += "\t";
- sEntry += SwResId(ST_QUERY);
- SvTreeListEntry* pEntry = m_pTable->InsertEntry(sEntry);
- pEntry->SetUserData(reinterpret_cast<void*>(1));
+ m_xTable->append_text(sEntry);
+ m_xTable->set_text(nPos, SwResId(ST_QUERY), 1);
+ m_xTable->set_id(nPos, OUString::number(1));
+ ++nPos;
}
}
}
SwSelectDBTableDialog::~SwSelectDBTableDialog()
{
- disposeOnce();
}
-void SwSelectDBTableDialog::dispose()
+IMPL_LINK_NOARG(SwSelectDBTableDialog, PreviewHdl, weld::Button&, void)
{
- m_pTable.disposeAndClear();
- m_pPreviewPB.clear();
- SfxModalDialog::dispose();
-}
-
-IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, Button*, pButton, void)
-{
- SvTreeListEntry* pEntry = m_pTable->FirstSelected();
- if(!pEntry)
+ int nEntry = m_xTable->get_selected_index();
+ if (nEntry == -1)
return;
- OUString sTableOrQuery = SvTabListBox::GetEntryText(pEntry, 0);
- sal_Int32 nCommandType = nullptr == pEntry->GetUserData() ? 0 : 1;
+ OUString sTableOrQuery = m_xTable->get_text(nEntry, 0);
+ sal_Int32 nCommandType = m_xTable->get_id(nEntry).isEmpty() ? 0 : 1;
OUString sDataSourceName;
Reference<XChild> xChild(m_xConnection, UNO_QUERY);
@@ -179,30 +125,32 @@ IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, Button*, pButton, void)
pProperties[4].Name = "ShowTreeViewButton";
pProperties[4].Value <<= false;
- VclPtrInstance< SwDBTablePreviewDialog > pDlg(pButton, aProperties);
+ VclPtrInstance< SwDBTablePreviewDialog > pDlg(nullptr, aProperties); //TODO
pDlg->Execute();
-
}
-OUString SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
+OUString SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable)
{
- SvTreeListEntry* pEntry = m_pTable->FirstSelected();
- bIsTable = pEntry->GetUserData() == nullptr;
- return SvTabListBox::GetEntryText(pEntry, 0);
+ int nEntry = m_xTable->get_selected_index();
+ if (nEntry != -1)
+ {
+ bIsTable = m_xTable->get_id(nEntry).isEmpty();
+ return m_xTable->get_text(nEntry, 0);
+ }
+ bIsTable = false;
+ return OUString();
}
-void SwSelectDBTableDialog::SetSelectedTable(const OUString& rTable, bool bIsTable)
+void SwSelectDBTableDialog::SetSelectedTable(const OUString& rTable, bool bIsTable)
{
- SvTreeListEntry* pEntry = m_pTable->First();
- while(pEntry)
+ for (int i = 0, nCount = m_xTable->n_children(); i < nCount; ++i)
{
- if((SvTabListBox::GetEntryText(pEntry, 0) == rTable) &&
- ((pEntry->GetUserData() == nullptr ) == bIsTable))
+ if (m_xTable->get_text(i, 0) == rTable &&
+ m_xTable->get_id(i).isEmpty() == bIsTable)
{
- m_pTable->Select(pEntry);
+ m_xTable->select(i);
break;
}
- pEntry = m_pTable->Next( pEntry );
}
}
diff --git a/sw/source/ui/dbui/selectdbtabledialog.hxx b/sw/source/ui/dbui/selectdbtabledialog.hxx
index 9f251f3ee8a6..4c4acfcc167d 100644
--- a/sw/source/ui/dbui/selectdbtabledialog.hxx
+++ b/sw/source/ui/dbui/selectdbtabledialog.hxx
@@ -21,30 +21,24 @@
#include <sfx2/basedlgs.hxx>
-#include <vcl/button.hxx>
-#include <vcl/fixed.hxx>
-#include <vcl/layout.hxx>
-
namespace com{namespace sun{namespace star{
namespace sdbc{
class XConnection;
}
}}}
-class SwAddressTable;
-
-class SwSelectDBTableDialog : public SfxModalDialog
+class SwSelectDBTableDialog : public SfxDialogController
{
- VclPtr<SwAddressTable> m_pTable;
- VclPtr<PushButton> m_pPreviewPB;
css::uno::Reference<css::sdbc::XConnection> m_xConnection;
- DECL_LINK(PreviewHdl, Button*, void);
+ std::unique_ptr<weld::TreeView> m_xTable;
+ std::unique_ptr<weld::Button> m_xPreviewPB;
+
+ DECL_LINK(PreviewHdl, weld::Button&, void);
public:
- SwSelectDBTableDialog(vcl::Window* pParent,
+ SwSelectDBTableDialog(weld::Window* pParent,
const css::uno::Reference<css::sdbc::XConnection>& xConnection);
virtual ~SwSelectDBTableDialog() override;
- virtual void dispose() override;
OUString GetSelectedTable(bool& bIsTable);
void SetSelectedTable(const OUString& rTable, bool bIsTable);
diff --git a/sw/uiconfig/swriter/ui/selecttabledialog.ui b/sw/uiconfig/swriter/ui/selecttabledialog.ui
index 020b37e9bcaf..35f9232455a0 100644
--- a/sw/uiconfig/swriter/ui/selecttabledialog.ui
+++ b/sw/uiconfig/swriter/ui/selecttabledialog.ui
@@ -1,14 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.22.1 -->
<interface domain="sw">
<requires lib="gtk+" version="3.18"/>
- <requires lib="LibreOffice" version="1.0"/>
+ <object class="GtkTreeStore" id="liststore1">
+ <columns>
+ <!-- column-name text -->
+ <column type="gchararray"/>
+ <!-- column-name text2 -->
+ <column type="gchararray"/>
+ <!-- column-name id -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkDialog" id="SelectTableDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes" context="selecttabledialog|SelectTableDialog">Select Table</property>
<property name="resizable">False</property>
+ <property name="modal">True</property>
+ <property name="default_width">0</property>
+ <property name="default_height">0</property>
<property name="type_hint">dialog</property>
+ <child>
+ <placeholder/>
+ </child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
@@ -84,11 +99,12 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes" context="selecttabledialog|select">The file you have selected contains more than one table. Please select the table containing the address list you want to use.</property>
<property name="use_underline">True</property>
<property name="wrap">True</property>
- <property name="max_width_chars">90</property>
+ <property name="width_chars">72</property>
+ <property name="max_width_chars">72</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
@@ -97,13 +113,52 @@
</packing>
</child>
<child>
- <object class="svtlo-SvSimpleTableContainer" id="table">
+ <object class="GtkScrolledWindow">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
- <child internal-child="selection">
- <object class="GtkTreeSelection" id="Simple Table Container-selection1"/>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkTreeView" id="table">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="model">liststore1</property>
+ <property name="search_column">0</property>
+ <property name="show_expanders">False</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="Macro Library List-selection1"/>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <property name="resizable">True</property>
+ <property name="spacing">6</property>
+ <property name="title" translatable="yes" context="selecttabledialog|column1">Name</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderer1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+ <property name="resizable">True</property>
+ <property name="spacing">6</property>
+ <property name="title" translatable="yes" context="selecttabledialog|column2">Type</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderer2"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
</child>
</object>
<packing>