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
39using namespace ::com::sun::star::lang;
40using namespace ::com::sun::star::container;
41using namespace ::com::sun::star::uno;
42using 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->m_aEnvItem;
63
64 const tools::Long nPageW = std::max(rItem.m_nWidth, rItem.m_nHeight);
65 const tools::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 tools::Long nW = static_cast<tools::Long>(f * nPageW);
83 const tools::Long nH = static_cast<tools::Long>(f * nPageH);
84 const tools::Long nX = (aSize.Width () - nW) / 2;
85 const tools::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 tools::Long nSendX = nX + static_cast<tools::Long>(f * rItem.m_nSendFromLeft);
93 const tools::Long nSendY = nY + static_cast<tools::Long>(f * rItem.m_nSendFromTop );
94 const tools::Long nSendW = static_cast<tools::Long>(f * (rItem.m_nAddrFromLeft - rItem.m_nSendFromLeft));
95 const tools::Long nSendH = static_cast<tools::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 tools::Long nAddrX = nX + static_cast<tools::Long>(f * rItem.m_nAddrFromLeft);
103 const tools::Long nAddrY = nY + static_cast<tools::Long>(f * rItem.m_nAddrFromTop );
104 const tools::Long nAddrW = static_cast<tools::Long>(f * (nPageW - rItem.m_nAddrFromLeft - 566));
105 const tools::Long nAddrH = static_cast<tools::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 tools::Long nStmpW = static_cast<tools::Long>(f * 1417 /* 2,5 cm */);
111 const tools::Long nStmpH = static_cast<tools::Long>(f * 1701 /* 3,0 cm */);
112 const tools::Long nStmpX = nX + nW - static_cast<tools::Long>(f * 566) - nStmpW;
113 const tools::Long nStmpY = nY + static_cast<tools::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 , m_aEnvItem(static_cast<const SwEnvItem&>( rSet.Get(FN_ENVELOP)))
123 , m_pSh(pWrtSh)
124 , m_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 m_pAddresseeSet.reset();
140 m_pSenderSet.reset();
141}
142
143void SwEnvDlg::PageCreated(const OString& rId, SfxTabPage &rPage)
144{
145 if (rId == "printer")
146 {
147 static_cast<SwEnvPrtPage*>(&rPage)->SetPrt(m_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 (m_pAddresseeSet)
166 {
169 }
170 if (m_pSenderSet)
171 {
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
208{
209 m_pDialog = pDialog;
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_toggled(LINK(this, SwEnvPage, SenderHdl));
218
220 m_sActDBName = aData.sDataSource + OUStringChar(DB_DELIM) + aData.sCommand;
222}
223
225{
226}
227
228IMPL_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()->m_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();
279 const Sequence<OUString> aDataNames = SwDBManager::GetExistingDatabaseNames();
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
297std::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()->m_aEnvItem);
306 Reset(&aSet);
307}
308
310{
311 FillItem(GetParentSwEnvDlg()->m_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()->m_aEnvItem);
327 rSet->Put(GetParentSwEnvDlg()->m_aEnvItem);
328 return true;
329}
330
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: */
const StyleSettings & GetStyleSettings() const
sal_uInt8 GetBlue() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
void DrawRect(const tools::Rectangle &rRect)
void SetLineColor()
void SetFillColor()
void SetBackground()
const AllSettings & GetSettings() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual short Ok()
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
weld::Button * GetUserButton() const
void SetExchangeSupport()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetWindowColor() const
const Color & GetDialogColor() const
static css::uno::Sequence< OUString > GetExistingDatabaseNames()
Definition: dbmgr.cxx:2522
bool GetTableNames(weld::ComboBox &rBox, const OUString &rDBName)
Fill listbox with all table names of a database.
Definition: dbmgr.cxx:634
void GetColumnNames(weld::ComboBox &rBox, const OUString &rDBName, const OUString &rTableName)
Fill listbox with all column names of a database table.
Definition: dbmgr.cxx:674
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Definition: edfld.cxx:328
SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:121
SwDBData const & GetDBData() const
Database information.
Definition: edfld.cxx:291
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: envlop1.cxx:143
SwEnvItem m_aEnvItem
Definition: envlop.hxx:66
std::unique_ptr< SfxItemSet > m_pSenderSet
Definition: envlop.hxx:70
virtual ~SwEnvDlg() override
Definition: envlop1.cxx:137
std::unique_ptr< weld::Button > m_xModify
Definition: envlop.hxx:72
VclPtr< Printer > m_pPrinter
Definition: envlop.hxx:68
virtual short Ok() override
Definition: envlop1.cxx:159
SwWrtShell * m_pSh
Definition: envlop.hxx:67
SwEnvDlg(weld::Window *pParent, const SfxItemSet &rSet, SwWrtShell *pWrtSh, Printer *pPrt, bool bInsert)
Definition: envlop1.cxx:119
std::unique_ptr< SfxItemSet > m_pAddresseeSet
Definition: envlop.hxx:69
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: envfmt.cxx:340
sal_Int32 m_nWidth
Definition: envimg.hxx:49
sal_Int32 m_nSendFromLeft
Definition: envimg.hxx:47
OUString m_aSendText
Definition: envimg.hxx:44
OUString m_aAddrText
Definition: envimg.hxx:42
sal_Int32 m_nSendFromTop
Definition: envimg.hxx:48
sal_Int32 m_nAddrFromTop
Definition: envimg.hxx:46
sal_Int32 m_nAddrFromLeft
Definition: envimg.hxx:45
sal_Int32 m_nHeight
Definition: envimg.hxx:50
bool m_bSend
Definition: envimg.hxx:43
SwWrtShell * m_pSh
Definition: envlop.hxx:86
std::unique_ptr< weld::ComboBox > m_xDBFieldLB
Definition: envlop.hxx:93
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: envlop1.cxx:302
SwEnvDlg * GetParentSwEnvDlg()
Definition: envlop.hxx:105
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: envlop1.cxx:324
SwEnvPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: envlop1.cxx:180
std::unique_ptr< weld::CheckButton > m_xSenderBox
Definition: envlop.hxx:95
SwEnvDlg * m_pDialog
Definition: envlop.hxx:85
std::unique_ptr< weld::ComboBox > m_xTableLB
Definition: envlop.hxx:92
std::unique_ptr< weld::TextView > m_xAddrEdit
Definition: envlop.hxx:90
OUString m_sActDBName
Definition: envlop.hxx:87
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: envlop1.cxx:309
std::unique_ptr< weld::TextView > m_xSenderEdit
Definition: envlop.hxx:96
std::unique_ptr< weld::ComboBox > m_xDatabaseLB
Definition: envlop.hxx:91
std::unique_ptr< weld::Button > m_xInsertBT
Definition: envlop.hxx:94
void InitDatabaseBox()
Definition: envlop1.cxx:273
virtual ~SwEnvPage() override
Definition: envlop1.cxx:224
void FillItem(SwEnvItem &rItem)
Definition: envlop1.cxx:317
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: envlop1.cxx:297
void Init(SwEnvDlg *pDialog)
Definition: envlop1.cxx:207
SwEnvPreview m_aPreview
Definition: envlop.hxx:89
virtual void Reset(const SfxItemSet *rSet) override
Definition: envlop1.cxx:331
SwEnvDlg * m_pDialog
Definition: envlop.hxx:49
void SetDialog(SwEnvDlg *pDialog)
Definition: envlop.hxx:56
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: envlop1.cxx:56
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: envprt.cxx:127
Represents the style of a paragraph.
Definition: fmtcol.hxx:59
virtual bool SetFormatAttr(const SfxPoolItem &rAttr) override
Override to recognize changes on the <SwNumRuleItem> and register/unregister the paragragh style at t...
Definition: fmtcol.cxx:334
static Color & GetFontColor()
Definition: viewopt.cxx:454
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
virtual void set_label(const OUString &rText)=0
Size const & GetOutputSizePixel() const
virtual int get_text_height() const=0
virtual void set_size_request(int nWidth, int nHeight)=0
virtual float get_approximate_digit_width() const=0
#define FN_ENVELOP
Definition: cmdid.h:763
void Init()
OUString MakeSender()
Definition: envimg.cxx:49
IMPL_LINK_NOARG(SwEnvPage, FieldHdl, weld::Button &, void)
Definition: envlop1.cxx:246
IMPL_LINK(SwEnvPage, DatabaseHdl, weld::ComboBox &, rListBox, void)
Definition: envlop1.cxx:228
LineEnd GetSystemLineEnd()
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
aStr
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:48
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, std::u16string_view rNewToken)
long Long
void(* f)(TrueTypeTable *)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
@ RES_POOLCOLL_ENVELOPE_ADDRESS
Addressee.
Definition: poolfmt.hxx:354
@ RES_POOLCOLL_SEND_ADDRESS
Sender.
Definition: poolfmt.hxx:355
static SfxItemSet & rSet
#define DB_DELIM
Definition: swtypes.hxx:130
DeactivateRC
#define RET_USER
RET_OK