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 
39 using namespace utl;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42 
43 #define ROUND(x) static_cast<long>((x) + .5)
44 
45 namespace {
46 
47 // Arrow or interval character
48 void 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 long lOutWPix = aSize.Width();
143  const long lOutHPix = aSize.Height();
144 
145  // Scale factor
146  const double fxpix = double(lOutWPix - (2 * (m_lLeftWidth + 15))) / double(lOutWPix);
147 
148  const long lOutWPix23 = long(double(lOutWPix) * fxpix);
149  const long lOutHPix23 = 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 long lDispW = m_aItem.m_lLeft + m_aItem.m_lHDist + ((m_aItem.m_nCols == 1)
171  ? m_aItem.m_lLeft
172  : ROUND(m_aItem.m_lHDist / 10.0));
173 
174  const long lDispH = m_aItem.m_lUpper + m_aItem.m_lVDist + ((m_aItem.m_nRows == 1)
175  ? m_aItem.m_lUpper
176  : ROUND(m_aItem.m_lVDist / 10.0));
177 
178  // Scale factor
179  const float fx = float(lOutWPix23) / std::max(1L, lDispW);
180  const float fy = float(lOutHPix23) / std::max(1L, lDispH);
181  const float f = std::min(fx, fy);
182 
183  // zero point
184  const long lOutlineW = ROUND(f * lDispW);
185  const long lOutlineH = ROUND(f * lDispH);
186 
187  const long lX0 = (lOutWPix - lOutlineW) / 2;
188  const long lY0 = (lOutHPix - lOutlineH) / 2;
189  const long lX1 = lX0 + ROUND(f * m_aItem.m_lLeft );
190  const long lY1 = lY0 + ROUND(f * m_aItem.m_lUpper);
191  const long lX2 = lX0 + ROUND(f * (m_aItem.m_lLeft + m_aItem.m_lWidth ));
192  const long lY2 = lY0 + ROUND(f * (m_aItem.m_lUpper + m_aItem.m_lHeight));
193  const long lX3 = lX0 + ROUND(f * (m_aItem.m_lLeft + m_aItem.m_lHDist ));
194  const 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))),
217  Size(ROUND(f * m_aItem.m_lWidth),
218  ROUND(f * m_aItem.m_lHeight))));
219  rRenderContext.SetClipRegion();
220 
221  // annotation: left border
222  if (m_aItem.m_lLeft)
223  {
224  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  long lX = lX2 - m_lXWidth / 2 - m_lHeightWidth / 2;
240  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  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  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  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  , aPreviewIdle("SwLabFormatPage Preview")
289  , aItem(static_cast<const SwLabItem&>( rSet.Get(FN_LABEL) ))
290  , 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  aPreviewIdle.SetPriority(TaskPriority::LOWEST);
337 }
338 
340 {
341 }
342 
343 // Modify-handler of MetricFields. start preview timer
345 {
346  bModified = true;
347  aPreviewIdle.Start();
348 }
349 
351 {
352  bModified = true;
353  aPreviewIdle.Start();
354 }
355 
356 // Invalidate preview
357 IMPL_LINK_NOARG(SwLabFormatPage, PreviewHdl, Timer *, void)
358 {
359  aPreviewIdle.Stop();
360  ChangeMinMax();
361  FillItem( aItem );
362  m_aPreview.UpdateItem(aItem);
363 }
364 
366 {
367  long lMax = 31748; // 56 cm
368  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  long lLeft = static_cast< long >(getfldval(*m_xLeftField )),
375  lUpper = static_cast< long >(getfldval(*m_xUpperField)),
376  lHDist = static_cast< long >(getfldval(*m_xHDistField)),
377  lVDist = static_cast< long >(getfldval(*m_xVDistField)),
378  lWidth = static_cast< long >(getfldval(*m_xWidthField)),
379  lHeight = static_cast< 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(long(100) * ((lMax - lLeft ) / std::max(1L, static_cast<long>(nCols))), FieldUnit::TWIP);
387  m_xVDistField->set_max(long(100) * ((lMax - lUpper) / std::max(1L, static_cast<long>(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(long(100) * lHDist, FieldUnit::TWIP);
393  m_xHeightField->set_max(long(100) * lVDist, FieldUnit::TWIP);
394 
395  m_xLeftField->set_max(long(100) * (lMax - nCols * lHDist), FieldUnit::TWIP);
396  m_xUpperField->set_max(long(100) * (lMax - nRows * lVDist), FieldUnit::TWIP);
397 
398  m_xColsField->set_range(1, (lMax - lLeft ) / std::max(1L, lHDist));
399  m_xRowsField->set_range(1, (lMax - lUpper) / std::max(1L, lVDist));
400 
401  m_xPWidthField->set_range(long(100) * lMinPWidth, long(100) * lMax, FieldUnit::TWIP);
402  m_xPHeightField->set_range(long(100) * lMinPHeight, long(100) * lMax, FieldUnit::TWIP);
403 }
404 
405 std::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 (!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< long >(getfldval(*m_xHDistField ));
433  rItem.m_lVDist = rRec.m_nVDist = static_cast< long >(getfldval(*m_xVDistField ));
434  rItem.m_lWidth = rRec.m_nWidth = static_cast< long >(getfldval(*m_xWidthField ));
435  rItem.m_lHeight = rRec.m_nHeight = static_cast< long >(getfldval(*m_xHeightField));
436  rItem.m_lLeft = rRec.m_nLeft = static_cast< long >(getfldval(*m_xLeftField ));
437  rItem.m_lUpper = rRec.m_nUpper = static_cast< 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< long >(getfldval(*m_xPWidthField ));
441  rItem.m_lPHeight = rRec.m_nPHeight = static_cast< long >(getfldval(*m_xPHeightField));
442 
443 }
444 
446 {
447  FillItem(aItem);
448  rSet->Put(aItem);
449 
450  return true;
451 }
452 
454 {
455  // Initialise fields
457 
458  m_xHDistField->set_max(100 * aItem.m_lHDist , FieldUnit::TWIP);
459  m_xVDistField->set_max(100 * aItem.m_lVDist , FieldUnit::TWIP);
460  m_xWidthField->set_max(100 * aItem.m_lWidth , FieldUnit::TWIP);
461  m_xHeightField->set_max(100 * aItem.m_lHeight, FieldUnit::TWIP);
462  m_xLeftField->set_max(100 * aItem.m_lLeft , FieldUnit::TWIP);
463  m_xUpperField->set_max(100 * aItem.m_lUpper , FieldUnit::TWIP);
464  m_xPWidthField->set_max(100 * aItem.m_lPWidth , FieldUnit::TWIP);
465  m_xPHeightField->set_max(100 * aItem.m_lPHeight, FieldUnit::TWIP);
466 
475 
476  m_xColsField->set_max(aItem.m_nCols);
477  m_xRowsField->set_max(aItem.m_nRows);
478 
479  m_xColsField->set_value(aItem.m_nCols);
480  m_xRowsField->set_value(aItem.m_nRows);
481  m_xMakeFI->set_label(aItem.m_aMake);
482  m_xTypeFI->set_label(aItem.m_aType);
483  PreviewHdl(nullptr);
484 }
485 
487 {
488  SwLabRec aRec;
489  aRec.m_nHDist = static_cast< long >(getfldval(*m_xHDistField));
490  aRec.m_nVDist = static_cast< long >(getfldval(*m_xVDistField ));
491  aRec.m_nWidth = static_cast< long >(getfldval(*m_xWidthField ));
492  aRec.m_nHeight = static_cast< long >(getfldval(*m_xHeightField));
493  aRec.m_nLeft = static_cast< long >(getfldval(*m_xLeftField ));
494  aRec.m_nUpper = static_cast< 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< long >(getfldval(*m_xPWidthField ));
498  aRec.m_nPHeight = static_cast< long >(getfldval(*m_xPHeightField));
499  aRec.m_bCont = aItem.m_bCont;
500  SwSaveLabelDlg aSaveDlg(GetParentSwLabDlg(), aRec);
501  aSaveDlg.SetLabel(aItem.m_aLstMake, aItem.m_aLstType);
502  aSaveDlg.run();
503  if (aSaveDlg.GetLabel(aItem))
504  {
505  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(aItem.m_aMake);
513  m_xTypeFI->set_label(aItem.m_aType);
514  }
515 }
516 
518  : GenericDialogController(pParent->getDialog(), "modules/swriter/ui/savelabeldialog.ui", "SaveLabelDialog")
519  , bSuccess(false)
520  , m_pLabDialog(pParent)
521  , 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  rLabRec.m_aType = sType;
569  rCfg.SaveLabel(sMake, sType, rLabRec);
570  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(bSuccess)
592  {
593  rItem.m_aMake = m_xMakeCB->get_active_text();
594  rItem.m_aType = m_xTypeED->get_text();
595  rItem.m_lHDist = rLabRec.m_nHDist;
596  rItem.m_lVDist = rLabRec.m_nVDist;
597  rItem.m_lWidth = rLabRec.m_nWidth;
598  rItem.m_lHeight = rLabRec.m_nHeight;
599  rItem.m_lLeft = rLabRec.m_nLeft;
600  rItem.m_lUpper = rLabRec.m_nUpper;
601  rItem.m_nCols = rLabRec.m_nCols;
602  rItem.m_nRows = rLabRec.m_nRows;
603  rItem.m_lPWidth = rLabRec.m_nPWidth;
604  rItem.m_lPHeight = rLabRec.m_nPHeight;
605  }
606  return bSuccess;
607 }
608 
609 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetClipRegion()
long Width() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
OUString m_aMake
Definition: labimg.hxx:48
long m_nHDist
Definition: labrec.hxx:40
void SetFillColor(const Color &)
FieldUnit
sal_Int32 m_lHeight
Definition: labimg.hxx:53
long m_nHeight
Definition: labrec.hxx:43
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: labfmt.cxx:445
sal_Int32 m_nRows
Definition: labrec.hxx:49
std::unique_ptr< weld::SpinButton > m_xColsField
Definition: labfmt.hxx:84
std::unique_ptr< weld::Button > m_xSavePB
Definition: labfmt.hxx:88
sal_Int32 m_lVDist
Definition: labimg.hxx:51
long m_lXHeight
Definition: labfmt.hxx:53
Color m_aGrayColor
Definition: labfmt.hxx:34
long Height() const
bool bModified
Definition: labfmt.hxx:71
std::unique_ptr< weld::Label > m_xTypeFI
Definition: labfmt.hxx:76
OUString m_aColsStr
Definition: labfmt.hxx:42
sal_Int32 m_lLeft
Definition: labimg.hxx:54
long m_lColsWidth
Definition: labfmt.hxx:50
const StyleSettings & GetStyleSettings() const
std::unique_ptr< weld::MetricSpinButton > m_xPHeightField
Definition: labfmt.hxx:87
bool HasLabel(const OUString &rManufacturer, const OUString &rType)
Definition: labelcfg.cxx:256
long m_nWidth
Definition: labrec.hxx:42
void DrawPolygon(const tools::Polygon &rPoly)
void Modify()
Definition: labfmt.cxx:574
std::unique_ptr< weld::MetricSpinButton > m_xLeftField
Definition: labfmt.hxx:82
std::unique_ptr< weld::Entry > m_xTypeED
Definition: labfmt.hxx:120
SwLabFormatPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: labfmt.cxx:286
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
std::unique_ptr< weld::ComboBox > m_xMakeCB
Definition: labfmt.hxx:119
void setfldval(weld::MetricSpinButton &rField, int lValue)
Definition: labimp.hxx:29
constexpr::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
SwLabRec & rLabRec
Definition: labfmt.hxx:117
sal_Int32 m_lUpper
Definition: labimg.hxx:55
Size const & GetOutputSizePixel() const
OUString m_aVDistStr
Definition: labfmt.hxx:37
std::unique_ptr< weld::SpinButton > m_xRowsField
Definition: labfmt.hxx:85
sal_Int32 m_lPWidth
Definition: labimg.hxx:61
long m_nLeft
Definition: labrec.hxx:44
OUString m_aHeightStr
Definition: labfmt.hxx:39
IMPL_LINK_NOARG(SwLabFormatPage, MetricModifyHdl, weld::MetricSpinButton &, void)
Definition: labfmt.cxx:344
void SetBackground()
RET_YES
bool m_bCont
Definition: labrec.hxx:50
void UpdateItem(const SwLabItem &rItem)
Definition: labfmt.cxx:280
const vcl::Font & GetFont() const
void SetExchangeSupport()
std::unique_ptr< weld::Button > m_xOKPB
Definition: labfmt.hxx:121
std::unique_ptr< weld::MetricSpinButton > m_xUpperField
Definition: labfmt.hxx:83
long m_nVDist
Definition: labrec.hxx:41
void DrawLine(const Point &rStartPt, const Point &rEndPt)
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: labfmt.cxx:410
Idle aPreviewIdle
Definition: labfmt.hxx:69
void DrawRect(const tools::Rectangle &rRect)
long m_lHDistWidth
Definition: labfmt.hxx:45
SwSaveLabelDlg(SwLabDlg *pParent, SwLabRec &rRec)
Definition: labfmt.cxx:517
bool GetLabel(SwLabItem &rItem)
Definition: labfmt.cxx:589
void SetLineColor()
OptionalString sType
OUString m_aLeftStr
Definition: labfmt.hxx:40
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:686
int i
virtual void Reset(const SfxItemSet *rSet) override
Definition: labfmt.cxx:453
long m_nPWidth
Definition: labrec.hxx:46
int getfldval(const weld::MetricSpinButton &rField)
Definition: labimp.hxx:24
sal_Int32 m_lHDist
Definition: labimg.hxx:50
const SvxPageUsage aArr[]
sal_Int32 m_nRows
Definition: labimg.hxx:57
void SetFillColor()
virtual ~SwLabFormatPage() override
Definition: labfmt.cxx:339
OUString m_aType
Definition: labimg.hxx:49
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: labfmt.cxx:416
sal_Int32 m_nCols
Definition: labimg.hxx:56
constexpr::Color COL_LIGHTGRAYBLUE(0xE0, 0xE0, 0xFF)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: labfmt.cxx:139
const AllSettings & GetSettings() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
OUString m_aUpperStr
Definition: labfmt.hxx:41
void SetLabel(const OUString &rMake, const OUString &rType)
Definition: labfmt.hxx:133
long m_lHeightWidth
Definition: labfmt.hxx:47
sal_Int32 m_lPHeight
Definition: labimg.hxx:60
SwLabDlg * m_pLabDialog
Definition: labfmt.hxx:116
sal_Int32 m_nCols
Definition: labrec.hxx:48
void SetColor(const Color &)
SwLabelConfig & GetLabelsConfig()
Definition: label.hxx:78
const std::vector< OUString > & GetManufacturers() const
Definition: labelcfg.hxx:50
OUString m_aHDistStr
Definition: labfmt.hxx:36
std::unique_ptr< weld::MetricSpinButton > m_xHDistField
Definition: labfmt.hxx:78
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: labfmt.cxx:405
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
long m_lUpperWidth
Definition: labfmt.hxx:49
OUString m_aWidthStr
Definition: labfmt.hxx:38
void FillItem(SwLabItem &rItem)
Definition: labfmt.cxx:424
virtual ~SwSaveLabelDlg() override
Definition: labfmt.cxx:538
std::unique_ptr< weld::MetricSpinButton > m_xPWidthField
Definition: labfmt.hxx:86
void SetFont(const vcl::Font &rNewFont)
void SetTransparent(bool bTransparent)
static Color & GetFontColor()
Definition: viewopt.cxx:425
RET_OK
virtual int get_text_height() const =0
void ChangeMinMax()
Definition: labfmt.cxx:365
long m_lXWidth
Definition: labfmt.hxx:52
std::unique_ptr< weld::Label > m_xMakeFI
Definition: labfmt.hxx:75
long m_lVDistWidth
Definition: labfmt.hxx:46
Reference< XExecutableDialog > m_xDialog
SwLabItem aItem
Definition: labfmt.hxx:70
virtual short run()
void SetInvokeHandler(const Link< Timer *, void > &rLink)
const Color & GetWindowColor() const
virtual Size get_pixel_size(const OUString &rText) const =0
OUString m_aRowsStr
Definition: labfmt.hxx:43
DeactivateRC
#define ROUND(x)
Definition: labfmt.cxx:43
long m_nPHeight
Definition: labrec.hxx:47
void SaveLabel(const OUString &rManufacturer, const OUString &rType, const SwLabRec &rRec)
Definition: labelcfg.cxx:264
#define SAL_WARN(area, stream)
SwLabItem m_aItem
Definition: labfmt.hxx:55
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
void(* f)(TrueTypeTable *)
void SetPriority(TaskPriority ePriority)
sal_Int32 m_lWidth
Definition: labimg.hxx:52
virtual void set_size_request(int nWidth, int nHeight)=0
bool IsPredefinedLabel(const OUString &rManufacturer, const OUString &rType)
Definition: labelcfg.hxx:53
std::unique_ptr< weld::MetricSpinButton > m_xWidthField
Definition: labfmt.hxx:80
long m_lLeftWidth
Definition: labfmt.hxx:48
std::unique_ptr< weld::MetricSpinButton > m_xVDistField
Definition: labfmt.hxx:79
SwLabRecs & Recs()
Definition: label.hxx:57
virtual float get_approximate_digit_width() const =0
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: labfmt.cxx:122
SwLabDlg * GetParentSwLabDlg()
Definition: labfmt.hxx:110
void GetLabItem(SwLabItem &rItem)
Definition: label1.cxx:166
long m_nUpper
Definition: labrec.hxx:45
std::unique_ptr< weld::MetricSpinButton > m_xHeightField
Definition: labfmt.hxx:81