LibreOffice Module sw (master)  1
envlop1.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <dbmgr.hxx>
21 #include <sfx2/app.hxx>
22 #include <tools/lineend.hxx>
23 #include <vcl/print.hxx>
24 #include <vcl/settings.hxx>
25 
26 #include <swwait.hxx>
27 #include <viewopt.hxx>
28 
29 #include <wrtsh.hxx>
30 #include <cmdid.h>
31 #include "envfmt.hxx"
32 #include <envlop.hxx>
33 #include "envprt.hxx"
34 #include <fmtcol.hxx>
35 #include <poolfmt.hxx>
36 #include <view.hxx>
37 
38 #include <comphelper/string.hxx>
39 
40 #include <unomid.h>
41 
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star;
46 
48  : m_pDialog(nullptr)
49 {
50 }
51 
53 {
54  CustomWidgetController::SetDrawingArea(pDrawingArea);
55  pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 20,
56  pDrawingArea->get_text_height() * 8);
57 }
58 
60 {
61  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
62  rRenderContext.SetBackground(rRenderContext.GetSettings().GetStyleSettings().GetDialogColor());
63  rRenderContext.Erase();
64 
65  const SwEnvItem& rItem = m_pDialog->aEnvItem;
66 
67  const long nPageW = std::max(rItem.m_nWidth, rItem.m_nHeight);
68  const long nPageH = std::min(rItem.m_nWidth, rItem.m_nHeight);
69 
70  Size aSize(GetOutputSizePixel());
71 
72  const double f = 0.8 * std::min(
73  double(aSize.Width()) / double(nPageW),
74  double(aSize.Height()) / double(nPageH));
75 
76  Color aBack = rSettings.GetWindowColor();
78  Color aMedium = Color((aBack.GetRed() + aFront.GetRed()) / 2,
79  (aBack.GetGreen() + aFront.GetGreen()) / 2,
80  (aBack.GetBlue() + aFront.GetBlue()) / 2);
81 
82  rRenderContext.SetLineColor(aFront);
83 
84  // Envelope
85  const long nW = static_cast<long>(f * nPageW);
86  const long nH = static_cast<long>(f * nPageH);
87  const long nX = (aSize.Width () - nW) / 2;
88  const long nY = (aSize.Height() - nH) / 2;
89  rRenderContext.SetFillColor(aBack);
90  rRenderContext.DrawRect(tools::Rectangle(Point(nX, nY), Size(nW, nH)));
91 
92  // Sender
93  if (rItem.m_bSend)
94  {
95  const long nSendX = nX + static_cast<long>(f * rItem.m_nSendFromLeft);
96  const long nSendY = nY + static_cast<long>(f * rItem.m_nSendFromTop );
97  const long nSendW = static_cast<long>(f * (rItem.m_nAddrFromLeft - rItem.m_nSendFromLeft));
98  const long nSendH = static_cast<long>(f * (rItem.m_nAddrFromTop - rItem.m_nSendFromTop - 566));
99  rRenderContext.SetFillColor(aMedium);
100 
101  rRenderContext.DrawRect(tools::Rectangle(Point(nSendX, nSendY), Size(nSendW, nSendH)));
102  }
103 
104  // Addressee
105  const long nAddrX = nX + static_cast<long>(f * rItem.m_nAddrFromLeft);
106  const long nAddrY = nY + static_cast<long>(f * rItem.m_nAddrFromTop );
107  const long nAddrW = static_cast<long>(f * (nPageW - rItem.m_nAddrFromLeft - 566));
108  const long nAddrH = static_cast<long>(f * (nPageH - rItem.m_nAddrFromTop - 566));
109  rRenderContext.SetFillColor(aMedium);
110  rRenderContext.DrawRect(tools::Rectangle(Point(nAddrX, nAddrY), Size(nAddrW, nAddrH)));
111 
112  // Stamp
113  const long nStmpW = static_cast<long>(f * 1417 /* 2,5 cm */);
114  const long nStmpH = static_cast<long>(f * 1701 /* 3,0 cm */);
115  const long nStmpX = nX + nW - static_cast<long>(f * 566) - nStmpW;
116  const long nStmpY = nY + static_cast<long>(f * 566);
117 
118  rRenderContext.SetFillColor(aBack);
119  rRenderContext.DrawRect(tools::Rectangle(Point(nStmpX, nStmpY), Size(nStmpW, nStmpH)));
120 }
121 
123  SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert)
124  : SfxTabDialogController(pParent, "modules/swriter/ui/envdialog.ui", "EnvDialog", &rSet)
125  , aEnvItem(static_cast<const SwEnvItem&>( rSet.Get(FN_ENVELOP)))
126  , pSh(pWrtSh)
127  , pPrinter(pPrt)
128  , m_xModify(m_xBuilder->weld_button("modify"))
129 {
130  if (!bInsert)
131  {
132  GetUserButton()->set_label(m_xModify->get_label());
133  }
134 
135  AddTabPage("envelope", SwEnvPage::Create, nullptr);
136  AddTabPage("format", SwEnvFormatPage::Create, nullptr);
137  AddTabPage("printer", SwEnvPrtPage::Create, nullptr);
138 }
139 
141 {
142  pAddresseeSet.reset();
143  pSenderSet.reset();
144 }
145 
146 void SwEnvDlg::PageCreated(const OString& rId, SfxTabPage &rPage)
147 {
148  if (rId == "printer")
149  {
150  static_cast<SwEnvPrtPage*>(&rPage)->SetPrt(pPrinter);
151  }
152  else if (rId == "envelope")
153  {
154  static_cast<SwEnvPage*>(&rPage)->Init(this);
155  }
156  else if (rId == "format")
157  {
158  static_cast<SwEnvFormatPage*>(&rPage)->Init(this);
159  }
160 }
161 
163 {
164  short nRet = SfxTabDialogController::Ok();
165 
166  if (nRet == RET_OK || nRet == RET_USER)
167  {
168  if (pAddresseeSet)
169  {
171  pColl->SetFormatAttr(*pAddresseeSet);
172  }
173  if (pSenderSet)
174  {
176  pColl->SetFormatAttr(*pSenderSet);
177  }
178  }
179 
180  return nRet;
181 }
182 
184  : SfxTabPage(pParent, "modules/swriter/ui/envaddresspage.ui", "EnvAddressPage", &rSet)
185  , m_pDialog(nullptr)
186  , m_pSh(nullptr)
187  , m_xAddrEdit(m_xBuilder->weld_text_view("addredit"))
188  , m_xDatabaseLB(m_xBuilder->weld_combo_box("database"))
189  , m_xTableLB(m_xBuilder->weld_combo_box("table"))
190  , m_xDBFieldLB(m_xBuilder->weld_combo_box("field"))
191  , m_xInsertBT(m_xBuilder->weld_button("insert"))
192  , m_xSenderBox(m_xBuilder->weld_check_button("sender"))
193  , m_xSenderEdit(m_xBuilder->weld_text_view("senderedit"))
194  , m_xPreview(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreview))
195 {
196  auto nTextBoxHeight(m_xAddrEdit->get_height_rows(10));
197  auto nTextBoxWidth(m_xAddrEdit->get_approximate_digit_width() * 25);
198 
199  m_xAddrEdit->set_size_request(nTextBoxWidth, nTextBoxHeight);
200  m_xSenderEdit->set_size_request(nTextBoxWidth, nTextBoxHeight);
201 
202  auto nListBoxWidth = m_xTableLB->get_approximate_digit_width() * 25;
203  m_xTableLB->set_size_request(nListBoxWidth, -1);
204  m_xDatabaseLB->set_size_request(nListBoxWidth, -1);
205  m_xDBFieldLB->set_size_request(nListBoxWidth, -1);
206 
208 }
209 
210 void SwEnvPage::Init(SwEnvDlg* pDialog)
211 {
212  m_pDialog = pDialog;
213  m_pSh = m_pDialog->pSh;
214  m_aPreview.SetDialog(pDialog);
215 
216  // Install handlers
217  m_xDatabaseLB->connect_changed(LINK(this, SwEnvPage, DatabaseHdl));
218  m_xTableLB->connect_changed(LINK(this, SwEnvPage, DatabaseHdl));
219  m_xInsertBT->connect_clicked(LINK(this, SwEnvPage, FieldHdl));
220  m_xSenderBox->connect_clicked(LINK(this, SwEnvPage, SenderHdl));
221 
223  m_sActDBName = aData.sDataSource + OUStringLiteral1(DB_DELIM) + aData.sCommand;
224  InitDatabaseBox();
225 }
226 
228 {
229  disposeOnce();
230 }
231 
232 IMPL_LINK( SwEnvPage, DatabaseHdl, weld::ComboBox&, rListBox, void )
233 {
234  SwWait aWait( *m_pSh->GetView().GetDocShell(), true );
235 
236  if (&rListBox == m_xDatabaseLB.get())
237  {
238  m_sActDBName = rListBox.get_active_text();
239  m_pSh->GetDBManager()->GetTableNames(*m_xTableLB, m_sActDBName);
240  m_sActDBName += OUStringLiteral1(DB_DELIM);
241  }
242  else
243  {
244  m_sActDBName = comphelper::string::setToken(m_sActDBName, 1, DB_DELIM, m_xTableLB->get_active_text());
245  }
246  m_pSh->GetDBManager()->GetColumnNames(*m_xDBFieldLB, m_xDatabaseLB->get_active_text(),
247  m_xTableLB->get_active_text());
248 }
249 
251 {
252  OUString aStr("<" + m_xDatabaseLB->get_active_text() + "." +
253  m_xTableLB->get_active_text() + "." +
254  m_xTableLB->get_active_id() + "." +
255  m_xDBFieldLB->get_active_text() + ">");
256  m_xAddrEdit->replace_selection(aStr);
257  int nStartPos, nEndPos;
258  m_xAddrEdit->get_selection_bounds(nStartPos, nEndPos);
259  m_xAddrEdit->grab_focus();
260  m_xAddrEdit->select_region(nStartPos, nEndPos);
261 }
262 
264 {
265  const bool bEnable = m_xSenderBox->get_active();
266  GetParentSwEnvDlg()->aEnvItem.m_bSend = bEnable;
267  m_xSenderEdit->set_sensitive(bEnable);
268  if (bEnable)
269  {
270  m_xSenderEdit->grab_focus();
271  if (m_xSenderEdit->get_text().isEmpty())
272  m_xSenderEdit->set_text(MakeSender());
273  }
274  m_xPreview->queue_draw();
275 }
276 
278 {
279  if (m_pSh->GetDBManager())
280  {
281  m_xDatabaseLB->clear();
283  const OUString* pDataNames = aDataNames.getConstArray();
284 
285  for (sal_Int32 i = 0; i < aDataNames.getLength(); ++i)
286  m_xDatabaseLB->append_text(pDataNames[i]);
287 
288  sal_Int32 nIdx{ 0 };
289  OUString sDBName = m_sActDBName.getToken( 0, DB_DELIM, nIdx );
290  OUString sTableName = m_sActDBName.getToken( 0, DB_DELIM, nIdx );
291  m_xDatabaseLB->set_active_text(sDBName);
292  if (m_pSh->GetDBManager()->GetTableNames(*m_xTableLB, sDBName))
293  {
294  m_xTableLB->append_text(sTableName);
295  m_pSh->GetDBManager()->GetColumnNames(*m_xDBFieldLB, sDBName, sTableName);
296  }
297  else
298  m_xDBFieldLB->clear();
299  }
300 }
301 
303 {
304  return VclPtr<SwEnvPage>::Create(pParent, *rSet);
305 }
306 
308 {
309  SfxItemSet aSet(rSet);
310  aSet.Put(GetParentSwEnvDlg()->aEnvItem);
311  Reset(&aSet);
312 }
313 
315 {
316  FillItem(GetParentSwEnvDlg()->aEnvItem);
317  if( _pSet )
318  FillItemSet(_pSet);
319  return DeactivateRC::LeavePage;
320 }
321 
323 {
324  rItem.m_aAddrText = m_xAddrEdit->get_text();
325  rItem.m_bSend = m_xSenderBox->get_active();
326  rItem.m_aSendText = m_xSenderEdit->get_text();
327 }
328 
330 {
331  FillItem(GetParentSwEnvDlg()->aEnvItem);
332  rSet->Put(GetParentSwEnvDlg()->aEnvItem);
333  return true;
334 }
335 
336 void SwEnvPage::Reset(const SfxItemSet* rSet)
337 {
338  SwEnvItem aItem = static_cast<const SwEnvItem&>( rSet->Get(FN_ENVELOP));
341  m_xSenderBox->set_active(aItem.m_bSend);
342  SenderHdl(*m_xSenderBox);
343 }
344 
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void GetColumnNames(ListBox *pListBox, const OUString &rDBName, const OUString &rTableName)
Fill listbox with all column names of a database table.
Definition: dbmgr.cxx:754
long Width() const
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: envlop1.cxx:314
virtual void set_label(const OUString &rText)=0
const Color & GetDialogColor() const
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
sal_uInt8 GetRed() const
SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:125
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: envlop1.cxx:307
OUString m_aSendText
Definition: envimg.hxx:44
void Init()
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: envlop1.cxx:329
#define FN_ENVELOP
Definition: cmdid.h:717
bool GetTableNames(weld::ComboBox &rBox, const OUString &rDBName)
Fill listbox with all table names of a database.
Definition: dbmgr.cxx:712
long Height() const
sal_Int32 m_nHeight
Definition: envimg.hxx:50
std::unique_ptr< weld::TextView > m_xSenderEdit
Definition: envlop.hxx:95
OUString sDataSource
Definition: swdbdata.hxx:30
std::unique_ptr< weld::ComboBox > m_xTableLB
Definition: envlop.hxx:91
const StyleSettings & GetStyleSettings() const
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: envlop1.cxx:59
std::unique_ptr< weld::ComboBox > m_xDatabaseLB
Definition: envlop.hxx:90
virtual short Ok() override
Definition: envlop1.cxx:162
sal_Int32 m_nWidth
Definition: envimg.hxx:49
std::unique_ptr< weld::Button > m_xModify
Definition: envlop.hxx:72
sal_Int32 m_nAddrFromLeft
Definition: envimg.hxx:45
SwEnvPage(TabPageParent pParent, const SfxItemSet &rSet)
Definition: envlop1.cxx:183
sal_Int32 m_nSendFromLeft
Definition: envimg.hxx:47
virtual bool SetFormatAttr(const SfxPoolItem &rAttr) override
Override to recognize changes on the and register/unregister the paragragh style at t...
Definition: fmtcol.cxx:330
SwEnvDlg(weld::Window *pParent, const SfxItemSet &rSet, SwWrtShell *pWrtSh, Printer *pPrt, bool bInsert)
Definition: envlop1.cxx:122
virtual ~SwEnvPage() override
Definition: envlop1.cxx:227
Size const & GetOutputSizePixel() const
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: envfmt.cxx:415
Used by the UI to modify the document model.
Definition: wrtsh.hxx:86
virtual short Ok()
static css::uno::Sequence< OUString > GetExistingDatabaseNames()
Definition: dbmgr.cxx:2614
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: envlop1.cxx:52
void SetBackground()
std::unique_ptr< SfxItemSet > pAddresseeSet
Definition: envlop.hxx:69
void SetExchangeSupport()
void InitDatabaseBox()
Definition: envlop1.cxx:277
sal_Int32 m_nAddrFromTop
Definition: envimg.hxx:46
LineEnd GetSystemLineEnd()
IMPL_LINK(SwEnvPage, DatabaseHdl, weld::ComboBox &, rListBox, void)
Definition: envlop1.cxx:232
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: envprt.cxx:130
sal_uInt8 GetBlue() const
VclPtr< Printer > pPrinter
Definition: envlop.hxx:68
void DrawRect(const tools::Rectangle &rRect)
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Definition: edfld.cxx:340
std::unique_ptr< weld::CheckButton > m_xSenderBox
Definition: envlop.hxx:94
bool m_bSend
Definition: envimg.hxx:43
void SetLineColor()
SwEnvPreview m_aPreview
Definition: envlop.hxx:88
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: envlop1.cxx:302
std::unique_ptr< SfxItemSet > pSenderSet
Definition: envlop.hxx:70
void SetDialog(SwEnvDlg *pDialog)
Definition: envlop.hxx:56
int i
void SetFillColor()
SwWrtShell * pSh
Definition: envlop.hxx:67
SwDBData const & GetDBData() const
Database information.
Definition: edfld.cxx:298
const AllSettings & GetSettings() const
GUIDCNamePair const aData
OUString MakeSender()
Definition: envimg.cxx:49
SwEnvDlg * GetParentSwEnvDlg()
Definition: envlop.hxx:104
#define DB_DELIM
Definition: swtypes.hxx:141
SwEnvDlg * m_pDialog
Definition: envlop.hxx:49
IMPL_LINK_NOARG(SwEnvPage, FieldHdl, weld::Button &, void)
Definition: envlop1.cxx:250
SwWrtShell * m_pSh
Definition: envlop.hxx:85
sal_uInt8 GetGreen() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
#define RET_USER
OUString m_sActDBName
Definition: envlop.hxx:86
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
OUString m_aAddrText
Definition: envimg.hxx:42
void FillItem(SwEnvItem &rItem)
Definition: envlop1.cxx:322
SwEnvItem aEnvItem
Definition: envlop.hxx:66
static Color & GetFontColor()
Definition: viewopt.cxx:427
RET_OK
std::unique_ptr< weld::ComboBox > m_xDBFieldLB
Definition: envlop.hxx:92
virtual int get_text_height() const =0
static VclPtr< reference_type > Create(Arg &&...arg)
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
const Color & GetWindowColor() const
std::unique_ptr< weld::Button > m_xInsertBT
Definition: envlop.hxx:93
DeactivateRC
SVX_DLLPUBLIC MSO_SPT Get(const OUString &)
void(* f)(TrueTypeTable *)
virtual ~SwEnvDlg() override
Definition: envlop1.cxx:140
weld::Button * GetUserButton() const
sal_Int32 m_nSendFromTop
Definition: envimg.hxx:48
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, const OUString &rNewToken)
virtual void set_size_request(int nWidth, int nHeight)=0
virtual void Reset(const SfxItemSet *rSet) override
Definition: envlop1.cxx:336
OUString sCommand
Definition: swdbdata.hxx:31
void Init(SwEnvDlg *pDialog)
Definition: envlop1.cxx:210
aStr
virtual float get_approximate_digit_width() const =0
SwEnvDlg * m_pDialog
Definition: envlop.hxx:84
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: envlop1.cxx:146
std::unique_ptr< weld::TextView > m_xAddrEdit
Definition: envlop.hxx:89