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