LibreOffice Module sw (master) 1
labfmt.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 <svtools/unitconv.hxx>
21#include <tools/poly.hxx>
22#include <vcl/weld.hxx>
23#include <vcl/svapp.hxx>
24#include <vcl/settings.hxx>
25#include <sal/log.hxx>
26
27#include <viewopt.hxx>
28
29#include <swtypes.hxx>
30#include <cmdid.h>
31#include <label.hxx>
32#include <labimp.hxx>
33#include <labimg.hxx>
34#include "labfmt.hxx"
35#include <uitool.hxx>
36
37#include <strings.hrc>
38
39using namespace utl;
40using namespace ::com::sun::star::uno;
41using namespace ::com::sun::star::beans;
42
43#define ROUND(x) static_cast<tools::Long>((x) + .5)
44
45namespace {
46
47// Arrow or interval character
48void DrawArrow(vcl::RenderContext& rRenderContext, const Point &rP1, const Point &rP2, bool bArrow)
49{
50 rRenderContext.DrawLine(rP1, rP2);
51 if (bArrow)
52 {
53 Point aArr[3];
54
55 // Arrow character
56 if (rP1.Y() == rP2.Y())
57 {
58 // Horizontal
59 aArr[0].setX( rP2.X() - 5 );
60 aArr[0].setY( rP2.Y() - 2 );
61 aArr[1].setX( rP2.X() );
62 aArr[1].setY( rP2.Y() );
63 aArr[2].setX( rP2.X() - 5 );
64 aArr[2].setY( rP2.Y() + 2 );
65 }
66 else
67 {
68 // Vertical
69 aArr[0].setX( rP2.X() - 2 );
70 aArr[0].setY( rP2.Y() - 5 );
71 aArr[1].setX( rP2.X() + 2 );
72 aArr[1].setY( rP2.Y() - 5 );
73 aArr[2].setX( rP2.X() );
74 aArr[2].setY( rP2.Y() );
75 }
76
77 const Color& rFieldTextColor = SwViewOption::GetFontColor();
78 rRenderContext.SetFillColor(rFieldTextColor);
79 rRenderContext.DrawPolygon( tools::Polygon(3, aArr));
80 }
81 else
82 {
83 // Interval symbol
84 if (rP1.Y() == rP2.Y())
85 {
86 // Horizontal
87 rRenderContext.DrawLine(Point(rP1.X(), rP1.Y() - 2), Point(rP1.X(), rP1.Y() + 2));
88 rRenderContext.DrawLine(Point(rP2.X(), rP2.Y() - 2), Point(rP2.X(), rP2.Y() + 2));
89 }
90 else
91 {
92 // Vertical
93 rRenderContext.DrawLine(Point(rP1.X() - 2, rP1.Y()), Point(rP1.X() + 2, rP1.Y()));
94 rRenderContext.DrawLine(Point(rP2.X() - 2, rP2.Y()), Point(rP2.X() + 2, rP2.Y()));
95 }
96 }
97}
98
99}
100
102 : m_aGrayColor(COL_LIGHTGRAY)
103 , m_aHDistStr(SwResId(STR_HDIST))
104 , m_aVDistStr(SwResId(STR_VDIST))
105 , m_aWidthStr(SwResId(STR_WIDTH))
106 , m_aHeightStr(SwResId(STR_HEIGHT))
107 , m_aLeftStr(SwResId(STR_LEFT))
108 , m_aUpperStr(SwResId(STR_UPPER))
109 , m_aColsStr(SwResId(STR_COLS))
110 , m_aRowsStr(SwResId(STR_ROWS))
111 , m_lHDistWidth(0)
112 , m_lVDistWidth(0)
113 , m_lHeightWidth(0)
114 , m_lLeftWidth(0)
115 , m_lUpperWidth(0)
116 , m_lColsWidth(0)
117 , m_lXWidth(0)
118 , m_lXHeight(0)
119{
120}
121
123{
124 CustomWidgetController::SetDrawingArea(pWidget);
125
126 pWidget->set_size_request(pWidget->get_approximate_digit_width() * 54,
127 pWidget->get_text_height() * 15);
128
135 m_lXWidth = pWidget->get_pixel_size(OUString('X')).Width();
136 m_lXHeight = pWidget->get_text_height();
137}
138
140{
141 const Size aSize(GetOutputSizePixel());
142 const tools::Long lOutWPix = aSize.Width();
143 const tools::Long lOutHPix = aSize.Height();
144
145 // Scale factor
146 const double fxpix = double(lOutWPix - (2 * (m_lLeftWidth + 15))) / double(lOutWPix);
147
148 const tools::Long lOutWPix23 = tools::Long(double(lOutWPix) * fxpix);
149 const tools::Long lOutHPix23 = tools::Long(double(lOutHPix) * fxpix);
150
151 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
152 const Color& rWinColor = rStyleSettings.GetWindowColor();
153 const Color& rFieldTextColor = SwViewOption::GetFontColor();
154
155 vcl::Font aFont = rRenderContext.GetFont();
156 aFont.SetFillColor(rWinColor);
157 aFont.SetColor(rFieldTextColor);
158 rRenderContext.SetFont(aFont);
159
160 rRenderContext.SetBackground(Wallpaper(rWinColor));
161 rRenderContext.Erase();
162
163 rRenderContext.SetLineColor(rWinColor);
164 rRenderContext.SetFillColor(m_aGrayColor);
165 vcl::Font aPaintFont(rRenderContext.GetFont());
166 aPaintFont.SetTransparent(false);
167 rRenderContext.SetFont(aPaintFont);
168
169 // size of region to be displayed
170 const tools::Long lDispW = m_aItem.m_lLeft + m_aItem.m_lHDist + ((m_aItem.m_nCols == 1)
172 : ROUND(m_aItem.m_lHDist / 10.0));
173
174 const tools::Long lDispH = m_aItem.m_lUpper + m_aItem.m_lVDist + ((m_aItem.m_nRows == 1)
176 : ROUND(m_aItem.m_lVDist / 10.0));
177
178 // Scale factor
179 const float fx = float(lOutWPix23) / std::max(tools::Long(1), lDispW);
180 const float fy = float(lOutHPix23) / std::max(tools::Long(1), lDispH);
181 const float f = std::min(fx, fy);
182
183 // zero point
184 const tools::Long lOutlineW = ROUND(f * lDispW);
185 const tools::Long lOutlineH = ROUND(f * lDispH);
186
187 const tools::Long lX0 = (lOutWPix - lOutlineW) / 2;
188 const tools::Long lY0 = (lOutHPix - lOutlineH) / 2;
189 const tools::Long lX1 = lX0 + ROUND(f * m_aItem.m_lLeft );
190 const tools::Long lY1 = lY0 + ROUND(f * m_aItem.m_lUpper);
191 const tools::Long lX2 = lX0 + ROUND(f * (m_aItem.m_lLeft + m_aItem.m_lWidth ));
192 const tools::Long lY2 = lY0 + ROUND(f * (m_aItem.m_lUpper + m_aItem.m_lHeight));
193 const tools::Long lX3 = lX0 + ROUND(f * (m_aItem.m_lLeft + m_aItem.m_lHDist ));
194 const tools::Long lY3 = lY0 + ROUND(f * (m_aItem.m_lUpper + m_aItem.m_lVDist ));
195
196 // draw outline (area)
197 rRenderContext.DrawRect(tools::Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH)));
198
199 // draw outline (border)
200 rRenderContext.SetLineColor(rFieldTextColor);
201 rRenderContext.DrawLine(Point(lX0, lY0), Point(lX0 + lOutlineW - 1, lY0)); // Up
202 rRenderContext.DrawLine(Point(lX0, lY0), Point(lX0, lY0 + lOutlineH - 1)); // Left
203 if (m_aItem.m_nCols == 1)
204 rRenderContext.DrawLine(Point(lX0 + lOutlineW - 1, lY0), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Right
205 if (m_aItem.m_nRows == 1)
206 rRenderContext.DrawLine(Point(lX0, lY0 + lOutlineH - 1), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Down
207
208 // Labels
209 rRenderContext.SetClipRegion(vcl::Region(tools::Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH))));
210 rRenderContext.SetFillColor(COL_LIGHTGRAYBLUE);
211 const sal_Int32 nRows = std::min<sal_Int32>(2, m_aItem.m_nRows);
212 const sal_Int32 nCols = std::min<sal_Int32>(2, m_aItem.m_nCols);
213 for (sal_Int32 nRow = 0; nRow < nRows; ++nRow)
214 for (sal_Int32 nCol = 0; nCol < nCols; ++nCol)
215 rRenderContext.DrawRect(tools::Rectangle(Point(lX0 + ROUND(f * (m_aItem.m_lLeft + nCol * m_aItem.m_lHDist)),
216 lY0 + ROUND(f * (m_aItem.m_lUpper + nRow * m_aItem.m_lVDist))),
218 ROUND(f * m_aItem.m_lHeight))));
219 rRenderContext.SetClipRegion();
220
221 // annotation: left border
222 if (m_aItem.m_lLeft)
223 {
224 tools::Long lX = (lX0 + lX1) / 2;
225 DrawArrow(rRenderContext, Point(lX0, lY0 - 5), Point(lX1, lY0 - 5), false);
226 DrawArrow(rRenderContext, Point(lX, lY0 - 10), Point(lX, lY0 - 5), true);
227 rRenderContext.DrawText(Point(lX1 - m_lLeftWidth, lY0 - 10 - m_lXHeight), m_aLeftStr);
228 }
229
230 // annotation: upper border
231 if (m_aItem.m_lUpper)
232 {
233 DrawArrow(rRenderContext, Point(lX0 - 5, lY0), Point(lX0 - 5, lY1), false);
234 rRenderContext.DrawText(Point(lX0 - 10 - m_lUpperWidth, lY0 + ROUND(f*m_aItem.m_lUpper/2.0 - m_lXHeight/2.0)), m_aUpperStr);
235 }
236
237 // annotation: width and height
238 {
239 tools::Long lX = lX2 - m_lXWidth / 2 - m_lHeightWidth / 2;
240 tools::Long lY = lY1 + m_lXHeight;
241
242 rRenderContext.DrawLine(Point(lX1, lY), Point(lX2 - 1, lY));
243 rRenderContext.DrawLine(Point(lX, lY1), Point(lX, lY2 - 1));
244
245 rRenderContext.DrawText(Point(lX1 + m_lXWidth / 2, lY - m_lXHeight / 2), m_aWidthStr);
246 rRenderContext.DrawText(Point(lX - m_lHeightWidth / 2, lY2 - m_lXHeight - m_lXHeight / 2), m_aHeightStr);
247 }
248
249 // annotation: horizontal gap
250 if (m_aItem.m_nCols > 1)
251 {
252 tools::Long lX = (lX1 + lX3) / 2;
253 DrawArrow(rRenderContext, Point(lX1, lY0 - 5), Point(lX3, lY0 - 5), false);
254 DrawArrow(rRenderContext, Point(lX, lY0 - 10), Point(lX, lY0 - 5), true);
255 rRenderContext.DrawText(Point(lX - m_lHDistWidth / 2, lY0 - 10 - m_lXHeight), m_aHDistStr);
256 }
257
258 // annotation: vertical gap
259 if (m_aItem.m_nRows > 1)
260 {
261 DrawArrow(rRenderContext, Point(lX0 - 5, lY1), Point(lX0 - 5, lY3), false);
262 rRenderContext.DrawText(Point(lX0 - 10 - m_lVDistWidth, lY1 + ROUND(f*m_aItem.m_lVDist/2.0 - m_lXHeight/2.0)), m_aVDistStr);
263 }
264
265 // annotation: columns
266 {
267 tools::Long lY = lY0 + lOutlineH + 4;
268 DrawArrow(rRenderContext, Point(lX0, lY), Point(lX0 + lOutlineW - 1, lY), true);
269 rRenderContext.DrawText(Point((lX0 + lX0 + lOutlineW - 1) / 2 - m_lColsWidth / 2, lY + 5), m_aColsStr);
270 }
271
272 // annotation: lines
273 {
274 tools::Long lX = lX0 + lOutlineW + 4;
275 DrawArrow(rRenderContext, Point(lX, lY0), Point(lX, lY0 + lOutlineH - 1), true);
276 rRenderContext.DrawText(Point(lX + 5, (lY0 + lY0 + lOutlineH - 1 - m_lXHeight / 2) / 2), m_aRowsStr);
277 }
278}
279
281{
282 m_aItem = rItem;
283 Invalidate();
284}
285
287 : SfxTabPage(pPage, pController, "modules/swriter/ui/labelformatpage.ui", "LabelFormatPage", &rSet)
288 , m_aPreviewIdle("SwLabFormatPage Preview")
289 , m_aItem(static_cast<const SwLabItem&>( rSet.Get(FN_LABEL) ))
290 , m_bModified(false)
291 , m_xMakeFI(m_xBuilder->weld_label("make"))
292 , m_xTypeFI(m_xBuilder->weld_label("type"))
293 , m_xPreview(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreview))
294 , m_xHDistField(m_xBuilder->weld_metric_spin_button("hori", FieldUnit::CM))
295 , m_xVDistField(m_xBuilder->weld_metric_spin_button("vert", FieldUnit::CM))
296 , m_xWidthField(m_xBuilder->weld_metric_spin_button("width", FieldUnit::CM))
297 , m_xHeightField(m_xBuilder->weld_metric_spin_button("height", FieldUnit::CM))
298 , m_xLeftField(m_xBuilder->weld_metric_spin_button("left", FieldUnit::CM))
299 , m_xUpperField(m_xBuilder->weld_metric_spin_button("top", FieldUnit::CM))
300 , m_xColsField(m_xBuilder->weld_spin_button("cols"))
301 , m_xRowsField(m_xBuilder->weld_spin_button("rows"))
302 , m_xPWidthField(m_xBuilder->weld_metric_spin_button("pagewidth", FieldUnit::CM))
303 , m_xPHeightField(m_xBuilder->weld_metric_spin_button("pageheight", FieldUnit::CM))
304 , m_xSavePB(m_xBuilder->weld_button("save"))
305{
307
308 // Metrics
309 FieldUnit aMetric = ::GetDfltMetric(false);
310 ::SetFieldUnit(*m_xHDistField, aMetric);
311 ::SetFieldUnit(*m_xVDistField , aMetric);
312 ::SetFieldUnit(*m_xWidthField , aMetric);
313 ::SetFieldUnit(*m_xHeightField, aMetric);
314 ::SetFieldUnit(*m_xLeftField , aMetric);
315 ::SetFieldUnit(*m_xUpperField , aMetric);
316 ::SetFieldUnit(*m_xPWidthField , aMetric);
317 ::SetFieldUnit(*m_xPHeightField, aMetric);
318
319 // Install handlers
320 Link<weld::MetricSpinButton&,void> aLk = LINK(this, SwLabFormatPage, MetricModifyHdl);
321 m_xHDistField->connect_value_changed( aLk );
322 m_xVDistField->connect_value_changed( aLk );
323 m_xWidthField->connect_value_changed( aLk );
324 m_xHeightField->connect_value_changed( aLk );
325 m_xLeftField->connect_value_changed( aLk );
326 m_xUpperField->connect_value_changed( aLk );
327 m_xPWidthField->connect_value_changed( aLk );
328 m_xPHeightField->connect_value_changed( aLk );
329
330 m_xColsField->connect_value_changed(LINK(this, SwLabFormatPage, ModifyHdl));
331 m_xRowsField->connect_value_changed(LINK(this, SwLabFormatPage, ModifyHdl));
332
333 m_xSavePB->connect_clicked( LINK (this, SwLabFormatPage, SaveHdl));
334 // Set timer
335 m_aPreviewIdle.SetPriority(TaskPriority::LOWEST);
337}
338
340{
341}
342
343// Modify-handler of MetricFields. start preview timer
345{
346 m_bModified = true;
347 m_aPreviewIdle.Start();
348}
349
351{
352 m_bModified = true;
353 m_aPreviewIdle.Start();
354}
355
356// Invalidate preview
358{
359 m_aPreviewIdle.Stop();
360 ChangeMinMax();
361 FillItem( m_aItem );
362 m_aPreview.UpdateItem(m_aItem);
363}
364
366{
367 tools::Long lMax = 31748; // 56 cm
368 tools::Long nMinSize = 10; // 0,1cm
369
370 // Min and Max
371
372 int nCols = m_xColsField->get_value(),
373 nRows = m_xRowsField->get_value();
374 tools::Long lLeft = static_cast< tools::Long >(getfldval(*m_xLeftField )),
375 lUpper = static_cast< tools::Long >(getfldval(*m_xUpperField)),
376 lHDist = static_cast< tools::Long >(getfldval(*m_xHDistField)),
377 lVDist = static_cast< tools::Long >(getfldval(*m_xVDistField)),
378 lWidth = static_cast< tools::Long >(getfldval(*m_xWidthField)),
379 lHeight = static_cast< tools::Long >(getfldval(*m_xHeightField)),
380 lMinPWidth = lLeft + (nCols - 1) * lHDist + lWidth,
381 lMinPHeight = lUpper + (nRows - 1) * lVDist + lHeight;
382
383 m_xHDistField->set_min(nMinSize, FieldUnit::CM);
384 m_xVDistField->set_min(nMinSize, FieldUnit::CM);
385
386 m_xHDistField->set_max(100 * ((lMax - lLeft ) / std::max(1, nCols)), FieldUnit::TWIP);
387 m_xVDistField->set_max(100 * ((lMax - lUpper) / std::max(1, nRows)), FieldUnit::TWIP);
388
389 m_xWidthField->set_min(nMinSize, FieldUnit::CM);
390 m_xHeightField->set_min(nMinSize, FieldUnit::CM);
391
392 m_xWidthField->set_max(tools::Long(100) * lHDist, FieldUnit::TWIP);
393 m_xHeightField->set_max(tools::Long(100) * lVDist, FieldUnit::TWIP);
394
395 m_xLeftField->set_max(tools::Long(100) * (lMax - nCols * lHDist), FieldUnit::TWIP);
396 m_xUpperField->set_max(tools::Long(100) * (lMax - nRows * lVDist), FieldUnit::TWIP);
397
398 m_xColsField->set_range(1, (lMax - lLeft ) / std::max(tools::Long(1), lHDist));
399 m_xRowsField->set_range(1, (lMax - lUpper) / std::max(tools::Long(1), lVDist));
400
401 m_xPWidthField->set_range(tools::Long(100) * lMinPWidth, tools::Long(100) * lMax, FieldUnit::TWIP);
402 m_xPHeightField->set_range(tools::Long(100) * lMinPHeight, tools::Long(100) * lMax, FieldUnit::TWIP);
403}
404
405std::unique_ptr<SfxTabPage> SwLabFormatPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
406{
407 return std::make_unique<SwLabFormatPage>(pPage, pController, *rSet);
408}
409
411{
412 SfxItemSet aSet(rSet);
413 Reset(&aSet);
414}
415
417{
418 if (_pSet)
419 FillItemSet(_pSet);
420
421 return DeactivateRC::LeavePage;
422}
423
425{
426 if (!m_bModified)
427 return;
428
429 rItem.m_aMake = rItem.m_aType = SwResId(STR_CUSTOM_LABEL);
430
431 SwLabRec& rRec = *GetParentSwLabDlg()->Recs()[0];
432 rItem.m_lHDist = rRec.m_nHDist = static_cast< tools::Long >(getfldval(*m_xHDistField ));
433 rItem.m_lVDist = rRec.m_nVDist = static_cast< tools::Long >(getfldval(*m_xVDistField ));
434 rItem.m_lWidth = rRec.m_nWidth = static_cast< tools::Long >(getfldval(*m_xWidthField ));
435 rItem.m_lHeight = rRec.m_nHeight = static_cast< tools::Long >(getfldval(*m_xHeightField));
436 rItem.m_lLeft = rRec.m_nLeft = static_cast< tools::Long >(getfldval(*m_xLeftField ));
437 rItem.m_lUpper = rRec.m_nUpper = static_cast< tools::Long >(getfldval(*m_xUpperField ));
438 rItem.m_nCols = rRec.m_nCols = static_cast< sal_Int32 >(m_xColsField->get_value());
439 rItem.m_nRows = rRec.m_nRows = static_cast< sal_Int32 >(m_xRowsField->get_value());
440 rItem.m_lPWidth = rRec.m_nPWidth = static_cast< tools::Long >(getfldval(*m_xPWidthField ));
441 rItem.m_lPHeight = rRec.m_nPHeight = static_cast< tools::Long >(getfldval(*m_xPHeightField));
442
443}
444
446{
448 rSet->Put(m_aItem);
449
450 return true;
451}
452
454{
455 // Initialise fields
457
458 m_xHDistField->set_max(100 * m_aItem.m_lHDist , FieldUnit::TWIP);
459 m_xVDistField->set_max(100 * m_aItem.m_lVDist , FieldUnit::TWIP);
460 m_xWidthField->set_max(100 * m_aItem.m_lWidth , FieldUnit::TWIP);
461 m_xHeightField->set_max(100 * m_aItem.m_lHeight, FieldUnit::TWIP);
462 m_xLeftField->set_max(100 * m_aItem.m_lLeft , FieldUnit::TWIP);
463 m_xUpperField->set_max(100 * m_aItem.m_lUpper , FieldUnit::TWIP);
464 m_xPWidthField->set_max(100 * m_aItem.m_lPWidth , FieldUnit::TWIP);
465 m_xPHeightField->set_max(100 * m_aItem.m_lPHeight, FieldUnit::TWIP);
466
475
476 m_xColsField->set_max(m_aItem.m_nCols);
477 m_xRowsField->set_max(m_aItem.m_nRows);
478
479 m_xColsField->set_value(m_aItem.m_nCols);
480 m_xRowsField->set_value(m_aItem.m_nRows);
481 m_xMakeFI->set_label(m_aItem.m_aMake);
482 m_xTypeFI->set_label(m_aItem.m_aType);
483 PreviewHdl(nullptr);
484}
485
487{
488 SwLabRec aRec;
489 aRec.m_nHDist = static_cast< tools::Long >(getfldval(*m_xHDistField));
490 aRec.m_nVDist = static_cast< tools::Long >(getfldval(*m_xVDistField ));
491 aRec.m_nWidth = static_cast< tools::Long >(getfldval(*m_xWidthField ));
492 aRec.m_nHeight = static_cast< tools::Long >(getfldval(*m_xHeightField));
493 aRec.m_nLeft = static_cast< tools::Long >(getfldval(*m_xLeftField ));
494 aRec.m_nUpper = static_cast< tools::Long >(getfldval(*m_xUpperField ));
495 aRec.m_nCols = static_cast< sal_Int32 >(m_xColsField->get_value());
496 aRec.m_nRows = static_cast< sal_Int32 >(m_xRowsField->get_value());
497 aRec.m_nPWidth = static_cast< tools::Long >(getfldval(*m_xPWidthField ));
498 aRec.m_nPHeight = static_cast< tools::Long >(getfldval(*m_xPHeightField));
499 aRec.m_bCont = m_aItem.m_bCont;
500 SwSaveLabelDlg aSaveDlg(GetParentSwLabDlg(), aRec);
501 aSaveDlg.SetLabel(m_aItem.m_aLstMake, m_aItem.m_aLstType);
502 aSaveDlg.run();
503 if (aSaveDlg.GetLabel(m_aItem))
504 {
505 m_bModified = false;
506 const std::vector<OUString>& rMan = GetParentSwLabDlg()->GetLabelsConfig().GetManufacturers();
507 std::vector<OUString>& rMakes(GetParentSwLabDlg()->Makes());
508 if(rMakes.size() < rMan.size())
509 {
510 rMakes = rMan;
511 }
512 m_xMakeFI->set_label(m_aItem.m_aMake);
513 m_xTypeFI->set_label(m_aItem.m_aType);
514 }
515}
516
518 : GenericDialogController(pParent->getDialog(), "modules/swriter/ui/savelabeldialog.ui", "SaveLabelDialog")
519 , m_bSuccess(false)
520 , m_pLabDialog(pParent)
521 , m_rLabRec(rRec)
522 , m_xMakeCB(m_xBuilder->weld_combo_box("brand"))
523 , m_xTypeED(m_xBuilder->weld_entry("type"))
524 , m_xOKPB(m_xBuilder->weld_button("ok"))
525{
526 m_xOKPB->connect_clicked(LINK(this, SwSaveLabelDlg, OkHdl));
527 m_xMakeCB->connect_changed(LINK(this, SwSaveLabelDlg, ModifyComboHdl));
528 m_xTypeED->connect_changed(LINK(this, SwSaveLabelDlg, ModifyEntryHdl));
529
531 const std::vector<OUString>& rMan = rCfg.GetManufacturers();
532 for (const auto & i : rMan)
533 {
534 m_xMakeCB->append_text(i);
535 }
536}
537
539{
540}
541
543{
544 SwLabelConfig& rCfg = m_pLabDialog->GetLabelsConfig();
545 OUString sMake(m_xMakeCB->get_active_text());
546 OUString sType(m_xTypeED->get_text());
547 if(rCfg.HasLabel(sMake, sType))
548 {
549 if ( rCfg.IsPredefinedLabel(sMake, sType) )
550 {
551 SAL_WARN( "sw.envelp", "label is predefined and cannot be overwritten" );
552 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), "modules/swriter/ui/cannotsavelabeldialog.ui"));
553 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("CannotSaveLabelDialog"));
554 xBox->run();
555 return;
556 }
557
558 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), "modules/swriter/ui/querysavelabeldialog.ui"));
559 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QuerySaveLabelDialog"));
560 xQuery->set_primary_text(xQuery->get_primary_text().
561 replaceAll("%1", sMake).replaceAll("%2", sType));
562 xQuery->set_secondary_text(xQuery->get_secondary_text().
563 replaceAll("%1", sMake).replaceAll("%2", sType));
564
565 if (RET_YES != xQuery->run())
566 return;
567 }
568 m_rLabRec.m_aType = sType;
569 rCfg.SaveLabel(sMake, sType, m_rLabRec);
570 m_bSuccess = true;
571 m_xDialog->response(RET_OK);
572}
573
575{
576 m_xOKPB->set_sensitive(!m_xMakeCB->get_active_text().isEmpty() && !m_xTypeED->get_text().isEmpty());
577}
578
580{
581 Modify();
582}
583
585{
586 Modify();
587}
588
590{
591 if(m_bSuccess)
592 {
593 rItem.m_aMake = m_xMakeCB->get_active_text();
594 rItem.m_aType = m_xTypeED->get_text();
599 rItem.m_lLeft = m_rLabRec.m_nLeft;
601 rItem.m_nCols = m_rLabRec.m_nCols;
602 rItem.m_nRows = m_rLabRec.m_nRows;
605 }
606 return m_bSuccess;
607}
608
609/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sType
Reference< XExecutableDialog > m_xDialog
const StyleSettings & GetStyleSettings() const
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
void SetLineColor()
void DrawPolygon(const tools::Polygon &rPoly)
void SetClipRegion()
void SetFillColor()
void SetBackground()
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const AllSettings & GetSettings() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetExchangeSupport()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetWindowColor() const
void GetLabItem(SwLabItem &rItem)
Definition: label1.cxx:158
SwLabelConfig & GetLabelsConfig()
Definition: label.hxx:78
SwLabRecs & Recs()
Definition: label.hxx:57
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: labfmt.cxx:405
std::unique_ptr< weld::Button > m_xSavePB
Definition: labfmt.hxx:87
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: labfmt.cxx:445
std::unique_ptr< weld::MetricSpinButton > m_xPHeightField
Definition: labfmt.hxx:86
std::unique_ptr< weld::Label > m_xTypeFI
Definition: labfmt.hxx:75
SwLabFormatPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: labfmt.cxx:286
std::unique_ptr< weld::Label > m_xMakeFI
Definition: labfmt.hxx:74
std::unique_ptr< weld::MetricSpinButton > m_xUpperField
Definition: labfmt.hxx:82
std::unique_ptr< weld::SpinButton > m_xRowsField
Definition: labfmt.hxx:84
Idle m_aPreviewIdle
Definition: labfmt.hxx:68
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: labfmt.cxx:416
SwLabItem m_aItem
Definition: labfmt.hxx:69
std::unique_ptr< weld::MetricSpinButton > m_xHeightField
Definition: labfmt.hxx:80
std::unique_ptr< weld::MetricSpinButton > m_xWidthField
Definition: labfmt.hxx:79
std::unique_ptr< weld::MetricSpinButton > m_xPWidthField
Definition: labfmt.hxx:85
virtual ~SwLabFormatPage() override
Definition: labfmt.cxx:339
SwLabDlg * GetParentSwLabDlg()
Definition: labfmt.hxx:110
void FillItem(SwLabItem &rItem)
Definition: labfmt.cxx:424
bool m_bModified
Definition: labfmt.hxx:70
std::unique_ptr< weld::MetricSpinButton > m_xLeftField
Definition: labfmt.hxx:81
virtual void Reset(const SfxItemSet *rSet) override
Definition: labfmt.cxx:453
void ChangeMinMax()
Definition: labfmt.cxx:365
std::unique_ptr< weld::MetricSpinButton > m_xHDistField
Definition: labfmt.hxx:77
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: labfmt.cxx:410
std::unique_ptr< weld::MetricSpinButton > m_xVDistField
Definition: labfmt.hxx:78
std::unique_ptr< weld::SpinButton > m_xColsField
Definition: labfmt.hxx:83
sal_Int32 m_nRows
Definition: labimg.hxx:57
sal_Int32 m_lPWidth
Definition: labimg.hxx:61
sal_Int32 m_lUpper
Definition: labimg.hxx:55
sal_Int32 m_lPHeight
Definition: labimg.hxx:60
sal_Int32 m_lWidth
Definition: labimg.hxx:52
sal_Int32 m_lVDist
Definition: labimg.hxx:51
sal_Int32 m_nCols
Definition: labimg.hxx:56
sal_Int32 m_lLeft
Definition: labimg.hxx:54
OUString m_aMake
Definition: labimg.hxx:48
sal_Int32 m_lHeight
Definition: labimg.hxx:53
sal_Int32 m_lHDist
Definition: labimg.hxx:50
OUString m_aType
Definition: labimg.hxx:49
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: labfmt.cxx:122
OUString m_aVDistStr
Definition: labfmt.hxx:37
OUString m_aHeightStr
Definition: labfmt.hxx:39
OUString m_aUpperStr
Definition: labfmt.hxx:41
OUString m_aLeftStr
Definition: labfmt.hxx:40
OUString m_aWidthStr
Definition: labfmt.hxx:38
SwLabItem m_aItem
Definition: labfmt.hxx:55
void UpdateItem(const SwLabItem &rItem)
Definition: labfmt.cxx:280
OUString m_aHDistStr
Definition: labfmt.hxx:36
tools::Long m_lXHeight
Definition: labfmt.hxx:53
tools::Long m_lHDistWidth
Definition: labfmt.hxx:45
tools::Long m_lHeightWidth
Definition: labfmt.hxx:47
tools::Long m_lColsWidth
Definition: labfmt.hxx:50
OUString m_aRowsStr
Definition: labfmt.hxx:43
tools::Long m_lXWidth
Definition: labfmt.hxx:52
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: labfmt.cxx:139
tools::Long m_lVDistWidth
Definition: labfmt.hxx:46
Color m_aGrayColor
Definition: labfmt.hxx:34
tools::Long m_lUpperWidth
Definition: labfmt.hxx:49
tools::Long m_lLeftWidth
Definition: labfmt.hxx:48
OUString m_aColsStr
Definition: labfmt.hxx:42
tools::Long m_nUpper
Definition: labrec.hxx:46
tools::Long m_nPHeight
Definition: labrec.hxx:48
bool m_bCont
Definition: labrec.hxx:51
tools::Long m_nLeft
Definition: labrec.hxx:45
tools::Long m_nVDist
Definition: labrec.hxx:42
tools::Long m_nWidth
Definition: labrec.hxx:43
sal_Int32 m_nCols
Definition: labrec.hxx:49
tools::Long m_nPWidth
Definition: labrec.hxx:47
sal_Int32 m_nRows
Definition: labrec.hxx:50
tools::Long m_nHeight
Definition: labrec.hxx:44
tools::Long m_nHDist
Definition: labrec.hxx:41
bool IsPredefinedLabel(const OUString &rManufacturer, const OUString &rType)
Definition: labelcfg.hxx:53
const std::vector< OUString > & GetManufacturers() const
Definition: labelcfg.hxx:50
void SaveLabel(const OUString &rManufacturer, const OUString &rType, const SwLabRec &rRec)
Definition: labelcfg.cxx:260
bool HasLabel(const OUString &rManufacturer, const OUString &rType)
Definition: labelcfg.cxx:252
void Modify()
Definition: labfmt.cxx:574
bool GetLabel(SwLabItem &rItem)
Definition: labfmt.cxx:589
void SetLabel(const OUString &rMake, const OUString &rType)
Definition: labfmt.hxx:133
std::unique_ptr< weld::ComboBox > m_xMakeCB
Definition: labfmt.hxx:119
SwSaveLabelDlg(SwLabDlg *pParent, SwLabRec &rRec)
Definition: labfmt.cxx:517
std::unique_ptr< weld::Button > m_xOKPB
Definition: labfmt.hxx:121
bool m_bSuccess
Definition: labfmt.hxx:115
virtual ~SwSaveLabelDlg() override
Definition: labfmt.cxx:538
std::unique_ptr< weld::Entry > m_xTypeED
Definition: labfmt.hxx:120
SwLabDlg * m_pLabDialog
Definition: labfmt.hxx:116
SwLabRec & m_rLabRec
Definition: labfmt.hxx:117
static Color & GetFontColor()
Definition: viewopt.cxx:454
void SetPriority(TaskPriority ePriority)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
void SetTransparent(bool bTransparent)
void SetFillColor(const Color &)
void SetColor(const Color &)
Size const & GetOutputSizePixel() const
virtual short run()
virtual int get_text_height() const=0
virtual Size get_pixel_size(const OUString &rText) const=0
virtual void set_size_request(int nWidth, int nHeight)=0
virtual float get_approximate_digit_width() const=0
constexpr ::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
constexpr ::Color COL_LIGHTGRAYBLUE(0xE0, 0xE0, 0xFF)
FieldUnit
#define ROUND(x)
Definition: labfmt.cxx:43
IMPL_LINK_NOARG(SwLabFormatPage, MetricModifyHdl, weld::MetricSpinButton &, void)
Definition: labfmt.cxx:344
int getfldval(const weld::MetricSpinButton &rField)
Definition: labimp.hxx:24
void setfldval(weld::MetricSpinButton &rField, int lValue)
Definition: labimp.hxx:29
#define SAL_WARN(area, stream)
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
int i
const SvxPageUsage aArr[]
long Long
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
static SfxItemSet & rSet
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
DeactivateRC
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:755
RET_OK
RET_YES