1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 #include <viewopt.hxx>
29 #include <swtypes.hxx>
37 #include <strings.hrc>
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::beans
;
43 #define ROUND(x) static_cast<tools::Long>((x) + .5)
47 // Arrow or interval character
48 void DrawArrow(vcl::RenderContext
& rRenderContext
, const Point
&rP1
, const Point
&rP2
, bool bArrow
)
50 rRenderContext
.DrawLine(rP1
, rP2
);
56 if (rP1
.Y() == rP2
.Y())
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 );
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() );
77 const Color
& rFieldTextColor
= SwViewOption::GetCurrentViewOptions().GetFontColor();
78 rRenderContext
.SetFillColor(rFieldTextColor
);
79 rRenderContext
.DrawPolygon( tools::Polygon(3, aArr
));
84 if (rP1
.Y() == rP2
.Y())
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));
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()));
101 SwLabPreview::SwLabPreview()
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
))
122 void SwLabPreview::SetDrawingArea(weld::DrawingArea
* pWidget
)
124 CustomWidgetController::SetDrawingArea(pWidget
);
126 pWidget
->set_size_request(pWidget
->get_approximate_digit_width() * 54,
127 pWidget
->get_text_height() * 15);
129 m_lHDistWidth
= pWidget
->get_pixel_size(m_aHDistStr
).Width();
130 m_lVDistWidth
= pWidget
->get_pixel_size(m_aVDistStr
).Width();
131 m_lHeightWidth
= pWidget
->get_pixel_size(m_aHeightStr
).Width();
132 m_lLeftWidth
= pWidget
->get_pixel_size(m_aLeftStr
).Width();
133 m_lUpperWidth
= pWidget
->get_pixel_size(m_aUpperStr
).Width();
134 m_lColsWidth
= pWidget
->get_pixel_size(m_aColsStr
).Width();
135 m_lXWidth
= pWidget
->get_pixel_size(OUString('X')).Width();
136 m_lXHeight
= pWidget
->get_text_height();
139 void SwLabPreview::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
141 const Size
aSize(GetOutputSizePixel());
142 const tools::Long lOutWPix
= aSize
.Width();
143 const tools::Long lOutHPix
= aSize
.Height();
146 const double fxpix
= double(lOutWPix
- (2 * (m_lLeftWidth
+ 15))) / double(lOutWPix
);
148 const tools::Long lOutWPix23
= tools::Long(double(lOutWPix
) * fxpix
);
149 const tools::Long lOutHPix23
= tools::Long(double(lOutHPix
) * fxpix
);
151 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
152 const Color
& rWinColor
= rStyleSettings
.GetWindowColor();
153 const Color
& rFieldTextColor
= SwViewOption::GetCurrentViewOptions().GetFontColor();
155 vcl::Font aFont
= rRenderContext
.GetFont();
156 aFont
.SetFillColor(rWinColor
);
157 aFont
.SetColor(rFieldTextColor
);
158 rRenderContext
.SetFont(aFont
);
160 rRenderContext
.SetBackground(Wallpaper(rWinColor
));
161 rRenderContext
.Erase();
163 rRenderContext
.SetLineColor(rWinColor
);
164 rRenderContext
.SetFillColor(m_aGrayColor
);
165 vcl::Font
aPaintFont(rRenderContext
.GetFont());
166 aPaintFont
.SetTransparent(false);
167 rRenderContext
.SetFont(aPaintFont
);
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));
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));
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
);
184 const tools::Long lOutlineW
= ROUND(f
* lDispW
);
185 const tools::Long lOutlineH
= ROUND(f
* lDispH
);
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
));
196 // draw outline (area)
197 rRenderContext
.DrawRect(tools::Rectangle(Point(lX0
, lY0
), Size(lOutlineW
, lOutlineH
)));
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
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();
221 // annotation: left border
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
);
230 // annotation: upper border
231 if (m_aItem
.m_lUpper
)
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
);
237 // annotation: width and height
239 tools::Long lX
= lX2
- m_lXWidth
/ 2 - m_lHeightWidth
/ 2;
240 tools::Long lY
= lY1
+ m_lXHeight
;
242 rRenderContext
.DrawLine(Point(lX1
, lY
), Point(lX2
- 1, lY
));
243 rRenderContext
.DrawLine(Point(lX
, lY1
), Point(lX
, lY2
- 1));
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
);
249 // annotation: horizontal gap
250 if (m_aItem
.m_nCols
> 1)
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
);
258 // annotation: vertical gap
259 if (m_aItem
.m_nRows
> 1)
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
);
265 // annotation: columns
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
);
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
);
280 void SwLabPreview::UpdateItem(const SwLabItem
& rItem
)
286 SwLabFormatPage::SwLabFormatPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
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
) ))
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"))
306 SetExchangeSupport();
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
);
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
);
330 m_xColsField
->connect_value_changed(LINK(this, SwLabFormatPage
, ModifyHdl
));
331 m_xRowsField
->connect_value_changed(LINK(this, SwLabFormatPage
, ModifyHdl
));
333 m_xSavePB
->connect_clicked( LINK (this, SwLabFormatPage
, SaveHdl
));
335 m_aPreviewIdle
.SetPriority(TaskPriority::LOWEST
);
336 m_aPreviewIdle
.SetInvokeHandler(LINK(this, SwLabFormatPage
, PreviewHdl
));
339 SwLabFormatPage::~SwLabFormatPage()
343 // Modify-handler of MetricFields. start preview timer
344 IMPL_LINK_NOARG(SwLabFormatPage
, MetricModifyHdl
, weld::MetricSpinButton
&, void)
347 m_aPreviewIdle
.Start();
350 IMPL_LINK_NOARG(SwLabFormatPage
, ModifyHdl
, weld::SpinButton
&, void)
353 m_aPreviewIdle
.Start();
356 // Invalidate preview
357 IMPL_LINK_NOARG(SwLabFormatPage
, PreviewHdl
, Timer
*, void)
359 m_aPreviewIdle
.Stop();
362 m_aPreview
.UpdateItem(m_aItem
);
365 void SwLabFormatPage::ChangeMinMax()
367 tools::Long lMax
= 31748; // 56 cm
368 tools::Long nMinSize
= 10; // 0,1cm
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
;
383 m_xHDistField
->set_min(nMinSize
, FieldUnit::CM
);
384 m_xVDistField
->set_min(nMinSize
, FieldUnit::CM
);
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
);
389 m_xWidthField
->set_min(nMinSize
, FieldUnit::CM
);
390 m_xHeightField
->set_min(nMinSize
, FieldUnit::CM
);
392 m_xWidthField
->set_max(tools::Long(100) * lHDist
, FieldUnit::TWIP
);
393 m_xHeightField
->set_max(tools::Long(100) * lVDist
, FieldUnit::TWIP
);
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
);
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
));
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
);
405 std::unique_ptr
<SfxTabPage
> SwLabFormatPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
407 return std::make_unique
<SwLabFormatPage
>(pPage
, pController
, *rSet
);
410 void SwLabFormatPage::ActivatePage(const SfxItemSet
& rSet
)
412 SfxItemSet
aSet(rSet
);
416 DeactivateRC
SwLabFormatPage::DeactivatePage(SfxItemSet
* _pSet
)
421 return DeactivateRC::LeavePage
;
424 void SwLabFormatPage::FillItem(SwLabItem
& rItem
)
429 rItem
.m_aMake
= rItem
.m_aType
= SwResId(STR_CUSTOM_LABEL
);
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
));
445 bool SwLabFormatPage::FillItemSet(SfxItemSet
* rSet
)
453 void SwLabFormatPage::Reset(const SfxItemSet
* )
456 GetParentSwLabDlg()->GetLabItem(m_aItem
);
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
);
467 setfldval(*m_xHDistField
, m_aItem
.m_lHDist
);
468 setfldval(*m_xVDistField
, m_aItem
.m_lVDist
);
469 setfldval(*m_xWidthField
, m_aItem
.m_lWidth
);
470 setfldval(*m_xHeightField
, m_aItem
.m_lHeight
);
471 setfldval(*m_xLeftField
, m_aItem
.m_lLeft
);
472 setfldval(*m_xUpperField
, m_aItem
.m_lUpper
);
473 setfldval(*m_xPWidthField
, m_aItem
.m_lPWidth
);
474 setfldval(*m_xPHeightField
, m_aItem
.m_lPHeight
);
476 m_xColsField
->set_max(m_aItem
.m_nCols
);
477 m_xRowsField
->set_max(m_aItem
.m_nRows
);
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
);
486 IMPL_LINK_NOARG(SwLabFormatPage
, SaveHdl
, weld::Button
&, void)
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
);
503 if (aSaveDlg
.GetLabel(m_aItem
))
506 const std::vector
<OUString
>& rMan
= GetParentSwLabDlg()->GetLabelsConfig().GetManufacturers();
507 std::vector
<OUString
>& rMakes(GetParentSwLabDlg()->Makes());
508 if(rMakes
.size() < rMan
.size())
512 m_xMakeFI
->set_label(m_aItem
.m_aMake
);
513 m_xTypeFI
->set_label(m_aItem
.m_aType
);
517 SwSaveLabelDlg::SwSaveLabelDlg(SwLabDlg
* pParent
, SwLabRec
& rRec
)
518 : GenericDialogController(pParent
->getDialog(), "modules/swriter/ui/savelabeldialog.ui", "SaveLabelDialog")
520 , m_pLabDialog(pParent
)
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"))
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
));
530 SwLabelConfig
& rCfg
= m_pLabDialog
->GetLabelsConfig();
531 const std::vector
<OUString
>& rMan
= rCfg
.GetManufacturers();
532 for (const auto & i
: rMan
)
534 m_xMakeCB
->append_text(i
);
538 SwSaveLabelDlg::~SwSaveLabelDlg()
542 IMPL_LINK_NOARG(SwSaveLabelDlg
, OkHdl
, weld::Button
&, void)
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
))
549 if ( rCfg
.IsPredefinedLabel(sMake
, sType
) )
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"));
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
));
565 if (RET_YES
!= xQuery
->run())
568 m_rLabRec
.m_aType
= sType
;
569 rCfg
.SaveLabel(sMake
, sType
, m_rLabRec
);
571 m_xDialog
->response(RET_OK
);
574 void SwSaveLabelDlg::Modify()
576 m_xOKPB
->set_sensitive(!m_xMakeCB
->get_active_text().isEmpty() && !m_xTypeED
->get_text().isEmpty());
579 IMPL_LINK_NOARG(SwSaveLabelDlg
, ModifyComboHdl
, weld::ComboBox
&, void)
584 IMPL_LINK_NOARG(SwSaveLabelDlg
, ModifyEntryHdl
, weld::Entry
&, void)
589 bool SwSaveLabelDlg::GetLabel(SwLabItem
& rItem
)
593 rItem
.m_aMake
= m_xMakeCB
->get_active_text();
594 rItem
.m_aType
= m_xTypeED
->get_text();
595 rItem
.m_lHDist
= m_rLabRec
.m_nHDist
;
596 rItem
.m_lVDist
= m_rLabRec
.m_nVDist
;
597 rItem
.m_lWidth
= m_rLabRec
.m_nWidth
;
598 rItem
.m_lHeight
= m_rLabRec
.m_nHeight
;
599 rItem
.m_lLeft
= m_rLabRec
.m_nLeft
;
600 rItem
.m_lUpper
= m_rLabRec
.m_nUpper
;
601 rItem
.m_nCols
= m_rLabRec
.m_nCols
;
602 rItem
.m_nRows
= m_rLabRec
.m_nRows
;
603 rItem
.m_lPWidth
= m_rLabRec
.m_nPWidth
;
604 rItem
.m_lPHeight
= m_rLabRec
.m_nPHeight
;
609 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */