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 <tools/lineend.hxx>
22 #include <vcl/print.hxx>
23 #include <vcl/settings.hxx>
24 
25 #include <swwait.hxx>
26 #include <viewopt.hxx>
27 
28 #include <wrtsh.hxx>
29 #include <cmdid.h>
30 #include "envfmt.hxx"
31 #include <envlop.hxx>
32 #include "envprt.hxx"
33 #include <fmtcol.hxx>
34 #include <poolfmt.hxx>
35 #include <view.hxx>
36 
37 #include <comphelper/string.hxx>
38 
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star;
43 
45  : m_pDialog(nullptr)
46 {
47 }
48 
50 {
51  CustomWidgetController::SetDrawingArea(pDrawingArea);
52  pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 20,
53  pDrawingArea->get_text_height() * 8);
54 }
55 
57 {
58  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
59  rRenderContext.SetBackground(rRenderContext.GetSettings().GetStyleSettings().GetDialogColor());
60  rRenderContext.Erase();
61 
62  const SwEnvItem& rItem = m_pDialog->aEnvItem;
63 
64  const long nPageW = std::max(rItem.m_nWidth, rItem.m_nHeight);
65  const long nPageH = std::min(rItem.m_nWidth, rItem.m_nHeight);
66 
67  Size aSize(GetOutputSizePixel());
68 
69  const double f = 0.8 * std::min(
70  double(aSize.Width()) / double(nPageW),
71  double(aSize.Height()) / double(nPageH));
72 
73  Color aBack = rSettings.GetWindowColor();
75  Color aMedium((aBack.GetRed() + aFront.GetRed()) / 2,
76  (aBack.GetGreen() + aFront.GetGreen()) / 2,
77  (aBack.GetBlue() + aFront.GetBlue()) / 2);
78 
79  rRenderContext.SetLineColor(aFront);
80 
81  // Envelope
82  const long nW = static_cast<long>(f * nPageW);
83  const long nH = static_cast<long>(f * nPageH);
84  const long nX = (aSize.Width () - nW) / 2;
85  const long nY = (aSize.Height() - nH) / 2;
86  rRenderContext.SetFillColor(aBack);
87  rRenderContext.DrawRect(tools::Rectangle(Point(nX, nY), Size(nW, nH)));
88 
89  // Sender
90  if (rItem.m_bSend)
91  {
92  const long nSendX = nX + static_cast<long>(f * rItem.m_nSendFromLeft);
93  const long nSendY = nY + static_cast<long>(f * rItem.m_nSendFromTop );
94  const long nSendW = static_cast<long>(f * (rItem.m_nAddrFromLeft - rItem.m_nSendFromLeft));
95  const long nSendH = static_cast<long>(f * (rItem.m_nAddrFromTop - rItem.m_nSendFromTop - 566));
96  rRenderContext.SetFillColor(aMedium);
97 
98  rRenderContext.DrawRect(tools::Rectangle(Point(nSendX, nSendY), Size(nSendW, nSendH)));
99  }
100 
101  // Addressee
102  const long nAddrX = nX + static_cast<long>(f * rItem.m_nAddrFromLeft);
103  const long nAddrY = nY + static_cast<long>(f * rItem.m_nAddrFromTop );
104  const long nAddrW = static_cast<long>(f * (nPageW - rItem.m_nAddrFromLeft - 566));
105  const long nAddrH = static_cast<long>(f * (nPageH - rItem.m_nAddrFromTop - 566));
106  rRenderContext.SetFillColor(aMedium);
107  rRenderContext.DrawRect(tools::Rectangle(Point(nAddrX, nAddrY), Size(nAddrW, nAddrH)));
108 
109  // Stamp
110  const long nStmpW = static_cast<long>(f * 1417 /* 2,5 cm */);
111  const long nStmpH = static_cast<long>(f * 1701 /* 3,0 cm */);
112  const long nStmpX = nX + nW - static_cast<long>(f * 566) - nStmpW;
113  const long nStmpY = nY + static_cast<long>(f * 566);
114 
115  rRenderContext.SetFillColor(aBack);
116  rRenderContext.DrawRect(tools::Rectangle(Point(nStmpX, nStmpY), Size(nStmpW, nStmpH)));
117 }
118 
120  SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert)
121  : SfxTabDialogController(pParent, "modules/swriter/ui/envdialog.ui", "EnvDialog", &rSet)
122  , aEnvItem(static_cast<const SwEnvItem&>( rSet.Get(FN_ENVELOP)))
123  , pSh(pWrtSh)
124  , pPrinter(pPrt)
125  , m_xModify(m_xBuilder->weld_button("modify"))
126 {
127  if (!bInsert)
128  {
129  GetUserButton()->set_label(m_xModify->get_label());
130  }
131 
132  AddTabPage("envelope", SwEnvPage::Create, nullptr);
133  AddTabPage("format", SwEnvFormatPage::Create, nullptr);
134  AddTabPage("printer", SwEnvPrtPage::Create, nullptr);
135 }
136 
138 {
139  pAddresseeSet.reset();
140  pSenderSet.reset();
141 }
142 
143 void SwEnvDlg::PageCreated(const OString& rId, SfxTabPage &rPage)
144 {
145  if (rId == "printer")
146  {
147  static_cast<SwEnvPrtPage*>(&rPage)->SetPrt(pPrinter);
148  }
149  else if (rId == "envelope")
150  {
151  static_cast<SwEnvPage*>(&rPage)->Init(this);
152  }
153  else if (rId == "format")
154  {
155  static_cast<SwEnvFormatPage*>(&rPage)->Init(this);
156  }
157 }
158 
160 {
161  short nRet = SfxTabDialogController::Ok();
162 
163  if (nRet == RET_OK || nRet == RET_USER)
164  {
165  if (pAddresseeSet)
166  {
168  pColl->SetFormatAttr(*pAddresseeSet);
169  }
170  if (pSenderSet)
171  {
173  pColl->SetFormatAttr(*pSenderSet);
174  }
175  }
176 
177  return nRet;
178 }
179 
181  : SfxTabPage(pPage, pController, "modules/swriter/ui/envaddresspage.ui", "EnvAddressPage", &rSet)
182  , m_pDialog(nullptr)
183  , m_pSh(nullptr)
184  , m_xAddrEdit(m_xBuilder->weld_text_view("addredit"))
185  , m_xDatabaseLB(m_xBuilder->weld_combo_box("database"))
186  , m_xTableLB(m_xBuilder->weld_combo_box("table"))
187  , m_xDBFieldLB(m_xBuilder->weld_combo_box("field"))
188  , m_xInsertBT(m_xBuilder->weld_button("insert"))
189  , m_xSenderBox(m_xBuilder->weld_check_button("sender"))
190  , m_xSenderEdit(m_xBuilder->weld_text_view("senderedit"))
191  , m_xPreview(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreview))
192 {
193  auto nTextBoxHeight(m_xAddrEdit->get_height_rows(10));
194  auto nTextBoxWidth(m_xAddrEdit->get_approximate_digit_width() * 25);
195 
196  m_xAddrEdit->set_size_request(nTextBoxWidth, nTextBoxHeight);
197  m_xSenderEdit->set_size_request(nTextBoxWidth, nTextBoxHeight);
198 
199  auto nListBoxWidth = m_xTableLB->get_approximate_digit_width() * 25;
200  m_xTableLB->set_size_request(nListBoxWidth, -1);
201  m_xDatabaseLB->set_size_request(nListBoxWidth, -1);
202  m_xDBFieldLB->set_size_request(nListBoxWidth, -1);
203 
205 }
206 
207 void SwEnvPage::Init(SwEnvDlg* pDialog)
208 {
209  m_pDialog = pDialog;
210  m_pSh = m_pDialog->pSh;
211  m_aPreview.SetDialog(pDialog);
212 
213  // Install handlers
214  m_xDatabaseLB->connect_changed(LINK(this, SwEnvPage, DatabaseHdl));
215  m_xTableLB->connect_changed(LINK(this, SwEnvPage, DatabaseHdl));
216  m_xInsertBT->connect_clicked(LINK(this, SwEnvPage, FieldHdl));
217  m_xSenderBox->connect_clicked(LINK(this, SwEnvPage, SenderHdl));
218 
220  m_sActDBName = aData.sDataSource + OUStringChar(DB_DELIM) + aData.sCommand;
221  InitDatabaseBox();
222 }
223 
225 {
226 }
227 
228 IMPL_LINK( SwEnvPage, DatabaseHdl, weld::ComboBox&, rListBox, void )
229 {
230  SwWait aWait( *m_pSh->GetView().GetDocShell(), true );
231 
232  if (&rListBox == m_xDatabaseLB.get())
233  {
234  m_sActDBName = rListBox.get_active_text();
235  m_pSh->GetDBManager()->GetTableNames(*m_xTableLB, m_sActDBName);
236  m_sActDBName += OUStringChar(DB_DELIM);
237  }
238  else
239  {
240  m_sActDBName = comphelper::string::setToken(m_sActDBName, 1, DB_DELIM, m_xTableLB->get_active_text());
241  }
242  m_pSh->GetDBManager()->GetColumnNames(*m_xDBFieldLB, m_xDatabaseLB->get_active_text(),
243  m_xTableLB->get_active_text());
244 }
245 
247 {
248  OUString aStr("<" + m_xDatabaseLB->get_active_text() + "." +
249  m_xTableLB->get_active_text() + "." +
250  m_xTableLB->get_active_id() + "." +
251  m_xDBFieldLB->get_active_text() + ">");
252  m_xAddrEdit->replace_selection(aStr);
253  int nStartPos, nEndPos;
254  m_xAddrEdit->get_selection_bounds(nStartPos, nEndPos);
255  m_xAddrEdit->grab_focus();
256  m_xAddrEdit->select_region(nStartPos, nEndPos);
257 }
258 
260 {
261  const bool bEnable = m_xSenderBox->get_active();
262  GetParentSwEnvDlg()->aEnvItem.m_bSend = bEnable;
263  m_xSenderEdit->set_sensitive(bEnable);
264  if (bEnable)
265  {
266  m_xSenderEdit->grab_focus();
267  if (m_xSenderEdit->get_text().isEmpty())
268  m_xSenderEdit->set_text(MakeSender());
269  }
270  m_xPreview->queue_draw();
271 }
272 
274 {
275  if (!m_pSh->GetDBManager())
276  return;
277 
278  m_xDatabaseLB->clear();
280 
281  for (const OUString& rDataName : aDataNames)
282  m_xDatabaseLB->append_text(rDataName);
283 
284  sal_Int32 nIdx{ 0 };
285  OUString sDBName = m_sActDBName.getToken( 0, DB_DELIM, nIdx );
286  OUString sTableName = m_sActDBName.getToken( 0, DB_DELIM, nIdx );
287  m_xDatabaseLB->set_active_text(sDBName);
288  if (m_pSh->GetDBManager()->GetTableNames(*m_xTableLB, sDBName))
289  {
290  m_xTableLB->append_text(sTableName);
291  m_pSh->GetDBManager()->GetColumnNames(*m_xDBFieldLB, sDBName, sTableName);
292  }
293  else
294  m_xDBFieldLB->clear();
295 }
296 
297 std::unique_ptr<SfxTabPage> SwEnvPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
298 {
299  return std::make_unique<SwEnvPage>(pPage, pController, *rSet);
300 }
301 
303 {
304  SfxItemSet aSet(rSet);
305  aSet.Put(GetParentSwEnvDlg()->aEnvItem);
306  Reset(&aSet);
307 }
308 
310 {
311  FillItem(GetParentSwEnvDlg()->aEnvItem);
312  if( _pSet )
313  FillItemSet(_pSet);
314  return DeactivateRC::LeavePage;
315 }
316 
318 {
319  rItem.m_aAddrText = m_xAddrEdit->get_text();
320  rItem.m_bSend = m_xSenderBox->get_active();
321  rItem.m_aSendText = m_xSenderEdit->get_text();
322 }
323 
325 {
326  FillItem(GetParentSwEnvDlg()->aEnvItem);
327  rSet->Put(GetParentSwEnvDlg()->aEnvItem);
328  return true;
329 }
330 
331 void SwEnvPage::Reset(const SfxItemSet* rSet)
332 {
333  SwEnvItem aItem = static_cast<const SwEnvItem&>( rSet->Get(FN_ENVELOP));
336  m_xSenderBox->set_active(aItem.m_bSend);
337  SenderHdl(*m_xSenderBox);
338 }
339 
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: envlop1.cxx:309
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:123
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: envlop1.cxx:302
OUString m_aSendText
Definition: envimg.hxx:44
void Init()
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: envlop1.cxx:324
const char aData[]
Definition: ww8scan.hxx:47
#define FN_ENVELOP
Definition: cmdid.h:743
bool GetTableNames(weld::ComboBox &rBox, const OUString &rDBName)
Fill listbox with all table names of a database.
Definition: dbmgr.cxx:697
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:56
std::unique_ptr< weld::ComboBox > m_xDatabaseLB
Definition: envlop.hxx:90
virtual short Ok() override
Definition: envlop1.cxx:159
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: envlop1.cxx:297
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
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:329
SwEnvDlg(weld::Window *pParent, const SfxItemSet &rSet, SwWrtShell *pWrtSh, Printer *pPrt, bool bInsert)
Definition: envlop1.cxx:119
virtual ~SwEnvPage() override
Definition: envlop1.cxx:224
Size const & GetOutputSizePixel() const
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
virtual short Ok()
static css::uno::Sequence< OUString > GetExistingDatabaseNames()
Definition: dbmgr.cxx:2591
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: envlop1.cxx:49
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: envfmt.cxx:408
void SetBackground()
std::unique_ptr< SfxItemSet > pAddresseeSet
Definition: envlop.hxx:69
void SetExchangeSupport()
void InitDatabaseBox()
Definition: envlop1.cxx:273
sal_Int32 m_nAddrFromTop
Definition: envimg.hxx:46
LineEnd GetSystemLineEnd()
IMPL_LINK(SwEnvPage, DatabaseHdl, weld::ComboBox &, rListBox, void)
Definition: envlop1.cxx:228
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:337
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
SwEnvPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: envlop1.cxx:180
std::unique_ptr< SfxItemSet > pSenderSet
Definition: envlop.hxx:70
void SetDialog(SwEnvDlg *pDialog)
Definition: envlop.hxx:56
void SetFillColor()
SwWrtShell * pSh
Definition: envlop.hxx:67
SwDBData const & GetDBData() const
Database information.
Definition: edfld.cxx:295
const AllSettings & GetSettings() const
OUString MakeSender()
Definition: envimg.cxx:48
SwEnvDlg * GetParentSwEnvDlg()
Definition: envlop.hxx:104
#define DB_DELIM
Definition: swtypes.hxx:137
SwEnvDlg * m_pDialog
Definition: envlop.hxx:49
IMPL_LINK_NOARG(SwEnvPage, FieldHdl, weld::Button &, void)
Definition: envlop1.cxx:246
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:317
SwEnvItem aEnvItem
Definition: envlop.hxx:66
static Color & GetFontColor()
Definition: viewopt.cxx:425
RET_OK
std::unique_ptr< weld::ComboBox > m_xDBFieldLB
Definition: envlop.hxx:92
virtual int get_text_height() const =0
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
const Color & GetWindowColor() const
std::unique_ptr< weld::Button > m_xInsertBT
Definition: envlop.hxx:93
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: envprt.cxx:127
DeactivateRC
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
void(* f)(TrueTypeTable *)
virtual ~SwEnvDlg() override
Definition: envlop1.cxx:137
void GetColumnNames(weld::ComboBox &rBox, const OUString &rDBName, const OUString &rTableName)
Fill listbox with all column names of a database table.
Definition: dbmgr.cxx:737
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:331
OUString sCommand
Definition: swdbdata.hxx:31
void Init(SwEnvDlg *pDialog)
Definition: envlop1.cxx:207
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:143
std::unique_ptr< weld::TextView > m_xAddrEdit
Definition: envlop.hxx:89