Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/poly.hxx>
30 : : #include <viewopt.hxx>
31 : :
32 : : #include "swtypes.hxx"
33 : : #include "cmdid.h"
34 : : #include "label.hxx"
35 : : #include "labimp.hxx"
36 : : #include "labimg.hxx"
37 : : #include "labfmt.hxx"
38 : : #include "uitool.hxx"
39 : :
40 : : #include "label.hrc"
41 : : #include "labfmt.hrc"
42 : : #include <unomid.h>
43 : :
44 : : using namespace utl;
45 : : using namespace ::com::sun::star::uno;
46 : : using namespace ::com::sun::star::beans;
47 : :
48 : : using ::rtl::OUString;
49 : :
50 : : #define ROUND(x) ((sal_uInt16) ((x) + .5))
51 : :
52 : 0 : SwLabPreview::SwLabPreview( const SwLabFmtPage* pParent, const ResId& rResID ) :
53 : :
54 : : Window((Window*) pParent, rResID),
55 : :
56 : : aGrayColor(COL_LIGHTGRAY),
57 : :
58 : : aHDistStr (SW_RES(STR_HDIST )),
59 : : aVDistStr (SW_RES(STR_VDIST )),
60 : : aWidthStr (SW_RES(STR_WIDTH )),
61 : : aHeightStr(SW_RES(STR_HEIGHT)),
62 : : aLeftStr (SW_RES(STR_LEFT )),
63 : : aUpperStr (SW_RES(STR_UPPER )),
64 : : aColsStr (SW_RES(STR_COLS )),
65 : : aRowsStr (SW_RES(STR_ROWS )),
66 : : aPWidthStr (SW_RES(STR_PWIDTH )),
67 : 0 : aPHeightStr(SW_RES(STR_PHEIGHT))
68 : : {
69 : 0 : SetMapMode(MAP_PIXEL);
70 : :
71 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
72 : 0 : const Color& rWinColor = rStyleSettings.GetWindowColor();
73 : 0 : SetBackground(Wallpaper(rWinColor));
74 : :
75 : 0 : Font aFont = GetFont();
76 : 0 : aFont.SetTransparent(sal_True);
77 : 0 : aFont.SetWeight (WEIGHT_NORMAL);
78 : 0 : SetFont(aFont);
79 : :
80 : 0 : const Size aSz(GetOutputSizePixel());
81 : :
82 : 0 : lOutWPix = aSz.Width ();
83 : 0 : lOutHPix = aSz.Height();
84 : :
85 : :
86 : 0 : lHDistWidth = GetTextWidth(aHDistStr );
87 : 0 : lVDistWidth = GetTextWidth(aVDistStr );
88 : 0 : lHeightWidth = GetTextWidth(aHeightStr);
89 : 0 : lLeftWidth = GetTextWidth(aLeftStr );
90 : 0 : lUpperWidth = GetTextWidth(aUpperStr );
91 : 0 : lColsWidth = GetTextWidth(aColsStr );
92 : 0 : lPWidthWidth = GetTextWidth(aPWidthStr);
93 : 0 : lPHeightWidth = GetTextWidth(aPHeightStr);
94 : 0 : lXHeight = GetTextHeight();
95 : 0 : lXWidth = GetTextWidth(rtl::OUString('X'));
96 : :
97 : : // Scale factor
98 : 0 : float fx = (float)(lOutWPix - (2 * (lLeftWidth + 15))) / (float)lOutWPix;
99 : :
100 : 0 : lOutWPix23 = (long)((float)lOutWPix * fx);
101 : 0 : lOutHPix23 = (long)((float)lOutHPix * fx);
102 : 0 : }
103 : :
104 : 0 : SwLabPreview::~SwLabPreview()
105 : : {
106 : 0 : }
107 : :
108 : 0 : void SwLabPreview::Paint(const Rectangle &)
109 : : {
110 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
111 : 0 : const Color& rWinColor = rStyleSettings.GetWindowColor();
112 : 0 : const Color& rFieldTextColor = SwViewOption::GetFontColor();
113 : :
114 : 0 : Font aFont = GetFont();
115 : 0 : aFont.SetFillColor( rWinColor );
116 : 0 : aFont.SetColor(rFieldTextColor);
117 : 0 : SetFont(aFont);
118 : :
119 : 0 : SetBackground(Wallpaper(rWinColor));
120 : :
121 : 0 : SetLineColor(rWinColor);
122 : 0 : SetFillColor(aGrayColor);
123 : 0 : Font aPaintFont(GetFont());
124 : 0 : aPaintFont.SetTransparent(sal_False);
125 : 0 : SetFont(aPaintFont);
126 : :
127 : : // size of region to be displayed
128 : 0 : long lDispW = ROUND(aItem.lLeft + aItem.lHDist);
129 : 0 : long lDispH = ROUND(aItem.lUpper + aItem.lVDist);
130 : 0 : if (aItem.nCols == 1)
131 : 0 : lDispW += ROUND(aItem.lLeft );
132 : : else
133 : 0 : lDispW += ROUND(aItem.lHDist / 10);
134 : 0 : if (aItem.nRows == 1)
135 : 0 : lDispH += ROUND(aItem.lUpper);
136 : : else
137 : 0 : lDispH += ROUND(aItem.lVDist / 10);
138 : :
139 : : // Scale factor
140 : 0 : float fx = (float) lOutWPix23 / Max(1L, lDispW),
141 : 0 : fy = (float) lOutHPix23 / Max(1L, lDispH),
142 : 0 : f = fx < fy ? fx : fy;
143 : :
144 : : // zero point
145 : 0 : long lOutlineW = ROUND(f * lDispW);
146 : 0 : long lOutlineH = ROUND(f * lDispH);
147 : :
148 : 0 : long lX0 = (lOutWPix - lOutlineW) / 2;
149 : 0 : long lY0 = (lOutHPix - lOutlineH) / 2;
150 : 0 : long lX1 = ROUND(lX0 + f * aItem.lLeft );
151 : 0 : long lY1 = ROUND(lY0 + f * aItem.lUpper);
152 : 0 : long lX2 = ROUND(lX0 + f * (aItem.lLeft + aItem.lWidth ));
153 : 0 : long lY2 = ROUND(lY0 + f * (aItem.lUpper + aItem.lHeight));
154 : 0 : long lX3 = ROUND(lX0 + f * (aItem.lLeft + aItem.lHDist ));
155 : 0 : long lY3 = ROUND(lY0 + f * (aItem.lUpper + aItem.lVDist ));
156 : :
157 : : // draw outline (area)
158 : 0 : DrawRect(Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH)));
159 : :
160 : : // draw outline (border)
161 : 0 : SetLineColor(rFieldTextColor);
162 : 0 : DrawLine(Point(lX0, lY0), Point(lX0 + lOutlineW - 1, lY0)); // Up
163 : 0 : DrawLine(Point(lX0, lY0), Point(lX0, lY0 + lOutlineH - 1)); // Left
164 : 0 : if (aItem.nCols == 1)
165 : 0 : DrawLine(Point(lX0 + lOutlineW - 1, lY0), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Right
166 : 0 : if (aItem.nRows == 1)
167 : 0 : DrawLine(Point(lX0, lY0 + lOutlineH - 1), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Down
168 : :
169 : : // Labels
170 : 0 : SetClipRegion (Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH)));
171 : 0 : SetFillColor( COL_LIGHTGRAYBLUE );
172 : 0 : for (sal_uInt16 nRow = 0; nRow < Min((sal_uInt16) 2, (sal_uInt16) aItem.nRows); nRow++)
173 : 0 : for (sal_uInt16 nCol = 0; nCol < Min((sal_uInt16) 2, (sal_uInt16) aItem.nCols); nCol++)
174 : : DrawRect(Rectangle(
175 : : Point(ROUND(lX0 + f * (aItem.lLeft + nCol * aItem.lHDist)),
176 : : ROUND(lY0 + f * (aItem.lUpper + nRow * aItem.lVDist))),
177 : : Size (ROUND(f * aItem.lWidth ),
178 : 0 : ROUND(f * aItem.lHeight))));
179 : 0 : SetClipRegion();
180 : :
181 : : // annotation: left border
182 : 0 : if (aItem.lLeft)
183 : : {
184 : 0 : long lX = (lX0 + lX1) / 2;
185 : 0 : DrawArrow(Point(lX0, lY0 - 5), Point(lX1, lY0 - 5), sal_False);
186 : 0 : DrawArrow(Point(lX, lY0 - 10), Point(lX, lY0 - 5), sal_True);
187 : 0 : DrawText(Point(lX1 - lLeftWidth, lY0 - 10 - lXHeight), aLeftStr);
188 : : }
189 : :
190 : : // annotation: upper border
191 : 0 : if (aItem.lUpper)
192 : : {
193 : 0 : DrawArrow(Point(lX0 - 5, lY0), Point(lX0 - 5, lY1), sal_False);
194 : 0 : DrawText(Point(lX0 - 10 - lUpperWidth, ROUND(lY0 + f * aItem.lUpper / 2 - lXHeight / 2)), aUpperStr);
195 : : }
196 : :
197 : : // annotation: width and height
198 : : {
199 : 0 : long lX = lX2 - lXWidth / 2 - lHeightWidth / 2;
200 : 0 : long lY = lY1 + lXHeight;
201 : :
202 : 0 : DrawLine(Point(lX1, lY), Point(lX2 - 1, lY));
203 : 0 : DrawLine(Point(lX, lY1), Point(lX, lY2 - 1));
204 : :
205 : 0 : DrawText(Point(lX1 + lXWidth / 2, lY - lXHeight / 2), aWidthStr);
206 : 0 : DrawText(Point(lX - lHeightWidth / 2, lY2 - lXHeight - lXHeight / 2), aHeightStr);
207 : : }
208 : :
209 : : // annotation: horizontal gap
210 : 0 : if (aItem.nCols > 1)
211 : : {
212 : 0 : long lX = (lX1 + lX3) / 2;
213 : 0 : DrawArrow(Point(lX1, lY0 - 5), Point(lX3, lY0 - 5), sal_False);
214 : 0 : DrawArrow(Point(lX, lY0 - 10), Point(lX, lY0 - 5), sal_True);
215 : 0 : DrawText(Point(lX - lHDistWidth / 2, lY0 - 10 - lXHeight), aHDistStr);
216 : : }
217 : :
218 : : // annotation: vertical gap
219 : 0 : if (aItem.nRows > 1)
220 : : {
221 : 0 : DrawArrow(Point(lX0 - 5, lY1), Point(lX0 - 5, lY3), sal_False);
222 : 0 : DrawText(Point(lX0 - 10 - lVDistWidth, ROUND(lY1 + f * aItem.lVDist / 2 - lXHeight / 2)), aVDistStr);
223 : : }
224 : :
225 : : // annotation: columns
226 : : {
227 : 0 : long lY = lY0 + lOutlineH + 4;
228 : 0 : DrawArrow(Point(lX0, lY), Point(lX0 + lOutlineW - 1, lY), sal_True);
229 : 0 : DrawText(Point((lX0 + lX0 + lOutlineW - 1) / 2 - lColsWidth / 2, lY + 5), aColsStr);
230 : : }
231 : :
232 : : // annotation: lines
233 : : {
234 : 0 : long lX = lX0 + lOutlineW + 4;
235 : 0 : DrawArrow(Point(lX, lY0), Point(lX, lY0 + lOutlineH - 1), sal_True);
236 : 0 : DrawText(Point(lX + 5, (lY0 + lY0 + lOutlineH - 1 - lXHeight / 2) / 2), aRowsStr);
237 : 0 : }
238 : 0 : }
239 : :
240 : : // Arror or interval character --------------------------------------------
241 : :
242 : 0 : void SwLabPreview::DrawArrow(const Point &rP1, const Point &rP2, sal_Bool bArrow)
243 : : {
244 : 0 : DrawLine(rP1, rP2);
245 : :
246 : 0 : if (bArrow)
247 : : {
248 : 0 : Point aArr[3];
249 : :
250 : : // Arrow character
251 : 0 : if (rP1.Y() == rP2.Y())
252 : : {
253 : : // Horizontal
254 : 0 : aArr[0].X() = rP2.X() - 5;
255 : 0 : aArr[0].Y() = rP2.Y() - 2;
256 : 0 : aArr[1].X() = rP2.X();
257 : 0 : aArr[1].Y() = rP2.Y();
258 : 0 : aArr[2].X() = rP2.X() - 5;
259 : 0 : aArr[2].Y() = rP2.Y() + 2;
260 : : }
261 : : else
262 : : {
263 : : // Vertical
264 : 0 : aArr[0].X() = rP2.X() - 2;
265 : 0 : aArr[0].Y() = rP2.Y() - 5;
266 : 0 : aArr[1].X() = rP2.X() + 2;
267 : 0 : aArr[1].Y() = rP2.Y() - 5;
268 : 0 : aArr[2].X() = rP2.X();
269 : 0 : aArr[2].Y() = rP2.Y();
270 : : }
271 : :
272 : 0 : const Color& rFieldTextColor = SwViewOption::GetFontColor();
273 : 0 : SetFillColor(rFieldTextColor);
274 : 0 : DrawPolygon(Polygon(3, aArr));
275 : : }
276 : : else
277 : : {
278 : : // Interval symbol
279 : 0 : if (rP1.Y() == rP2.Y())
280 : : {
281 : : // Horizontal
282 : 0 : DrawLine(Point(rP1.X(), rP1.Y() - 2), Point(rP1.X(), rP1.Y() + 2));
283 : 0 : DrawLine(Point(rP2.X(), rP2.Y() - 2), Point(rP2.X(), rP2.Y() + 2));
284 : : }
285 : : else
286 : : {
287 : : // Vertical
288 : 0 : DrawLine(Point(rP1.X() - 2, rP1.Y()), Point(rP1.X() + 2, rP1.Y()));
289 : 0 : DrawLine(Point(rP2.X() - 2, rP2.Y()), Point(rP2.X() + 2, rP2.Y()));
290 : : }
291 : : }
292 : 0 : }
293 : :
294 : 0 : void SwLabPreview::Update(const SwLabItem& rItem)
295 : : {
296 : 0 : aItem = rItem;
297 : 0 : Invalidate();
298 : 0 : }
299 : :
300 : 0 : SwLabFmtPage::SwLabFmtPage(Window* pParent, const SfxItemSet& rSet) :
301 : :
302 : : SfxTabPage(pParent, SW_RES(TP_LAB_FMT), rSet),
303 : : aMakeFI (this, SW_RES(FI_MAKE)),
304 : : aTypeFI (this, SW_RES(FI_TYPE)),
305 : : aPreview (this, SW_RES(WIN_PREVIEW)),
306 : : aHDistText (this, SW_RES(TXT_HDIST )),
307 : : aHDistField (this, SW_RES(FLD_HDIST )),
308 : : aVDistText (this, SW_RES(TXT_VDIST )),
309 : : aVDistField (this, SW_RES(FLD_VDIST )),
310 : : aWidthText (this, SW_RES(TXT_WIDTH )),
311 : : aWidthField (this, SW_RES(FLD_WIDTH )),
312 : : aHeightText (this, SW_RES(TXT_HEIGHT )),
313 : : aHeightField (this, SW_RES(FLD_HEIGHT )),
314 : : aLeftText (this, SW_RES(TXT_LEFT )),
315 : : aLeftField (this, SW_RES(FLD_LEFT )),
316 : : aUpperText (this, SW_RES(TXT_UPPER )),
317 : : aUpperField (this, SW_RES(FLD_UPPER )),
318 : : aColsText (this, SW_RES(TXT_COLUMNS)),
319 : : aColsField (this, SW_RES(FLD_COLUMNS)),
320 : : aRowsText (this, SW_RES(TXT_ROWS )),
321 : : aRowsField (this, SW_RES(FLD_ROWS )),
322 : : aPWidthText (this, SW_RES(TXT_PWIDTH )),
323 : : aPWidthField (this, SW_RES(FLD_PWIDTH )),
324 : : aPHeightText (this, SW_RES(TXT_PHEIGHT )),
325 : : aPHeightField (this, SW_RES(FLD_PHEIGHT )),
326 : : aSavePB (this, SW_RES(PB_SAVE )),
327 : : bModified(sal_False),
328 : 0 : aItem ((const SwLabItem&) rSet.Get(FN_LABEL))
329 : : {
330 : 0 : FreeResource();
331 : 0 : SetExchangeSupport();
332 : :
333 : : // Metrics
334 : 0 : FieldUnit aMetric = ::GetDfltMetric(sal_False);
335 : 0 : SetMetric(aHDistField , aMetric);
336 : 0 : SetMetric(aVDistField , aMetric);
337 : 0 : SetMetric(aWidthField , aMetric);
338 : 0 : SetMetric(aHeightField, aMetric);
339 : 0 : SetMetric(aLeftField , aMetric);
340 : 0 : SetMetric(aUpperField , aMetric);
341 : 0 : SetMetric(aPWidthField , aMetric);
342 : 0 : SetMetric(aPHeightField, aMetric);
343 : :
344 : : // Install handlers
345 : 0 : Link aLk = LINK(this, SwLabFmtPage, ModifyHdl);
346 : 0 : aHDistField .SetModifyHdl( aLk );
347 : 0 : aVDistField .SetModifyHdl( aLk );
348 : 0 : aWidthField .SetModifyHdl( aLk );
349 : 0 : aHeightField.SetModifyHdl( aLk );
350 : 0 : aLeftField .SetModifyHdl( aLk );
351 : 0 : aUpperField .SetModifyHdl( aLk );
352 : 0 : aColsField .SetModifyHdl( aLk );
353 : 0 : aRowsField .SetModifyHdl( aLk );
354 : 0 : aPWidthField .SetModifyHdl( aLk );
355 : 0 : aPHeightField.SetModifyHdl( aLk );
356 : :
357 : 0 : aLk = LINK(this, SwLabFmtPage, LoseFocusHdl);
358 : 0 : aHDistField .SetLoseFocusHdl( aLk );
359 : 0 : aVDistField .SetLoseFocusHdl( aLk );
360 : 0 : aWidthField .SetLoseFocusHdl( aLk );
361 : 0 : aHeightField.SetLoseFocusHdl( aLk );
362 : 0 : aLeftField .SetLoseFocusHdl( aLk );
363 : 0 : aUpperField .SetLoseFocusHdl( aLk );
364 : 0 : aColsField .SetLoseFocusHdl( aLk );
365 : 0 : aRowsField .SetLoseFocusHdl( aLk );
366 : 0 : aPWidthField .SetLoseFocusHdl( aLk );
367 : 0 : aPHeightField.SetLoseFocusHdl( aLk );
368 : :
369 : 0 : aSavePB.SetClickHdl( LINK (this, SwLabFmtPage, SaveHdl));
370 : : // Set timer
371 : 0 : aPreviewTimer.SetTimeout(1000);
372 : 0 : aPreviewTimer.SetTimeoutHdl(LINK(this, SwLabFmtPage, PreviewHdl));
373 : 0 : }
374 : :
375 : 0 : SwLabFmtPage::~SwLabFmtPage()
376 : : {
377 : 0 : }
378 : :
379 : : // Modify-handler of MetricFields. start preview timer
380 : 0 : IMPL_LINK_NOARG_INLINE_START(SwLabFmtPage, ModifyHdl)
381 : : {
382 : 0 : bModified = sal_True;
383 : 0 : aPreviewTimer.Start();
384 : 0 : return 0;
385 : : }
386 : 0 : IMPL_LINK_NOARG_INLINE_END(SwLabFmtPage, ModifyHdl)
387 : :
388 : : // Invalidate preview
389 : 0 : IMPL_LINK_NOARG_INLINE_START(SwLabFmtPage, PreviewHdl)
390 : : {
391 : 0 : aPreviewTimer.Stop();
392 : 0 : ChangeMinMax();
393 : 0 : FillItem( aItem );
394 : 0 : aPreview.Update( aItem );
395 : :
396 : 0 : return 0;
397 : : }
398 : 0 : IMPL_LINK_NOARG_INLINE_END(SwLabFmtPage, PreviewHdl)
399 : :
400 : : // LoseFocus-Handler: Update on change --------------------------
401 : 0 : IMPL_LINK_INLINE_START( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
402 : : {
403 : 0 : if (((Edit*) pControl)->IsModified())
404 : 0 : PreviewHdl(0);
405 : 0 : return 0;
406 : : }
407 : 0 : IMPL_LINK_INLINE_END( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
408 : :
409 : 0 : void SwLabFmtPage::ChangeMinMax()
410 : : {
411 : 0 : long lMax = 31748; // 56 cm
412 : 0 : long nMinSize = 10; // 0,1cm
413 : :
414 : : // Min and Max
415 : :
416 : 0 : int nCols = aColsField.GetValue(),
417 : 0 : nRows = aRowsField.GetValue();
418 : 0 : long lLeft = static_cast< long >(GETFLDVAL(aLeftField )),
419 : 0 : lUpper = static_cast< long >(GETFLDVAL(aUpperField)),
420 : 0 : lHDist = static_cast< long >(GETFLDVAL(aHDistField)),
421 : 0 : lVDist = static_cast< long >(GETFLDVAL(aVDistField)),
422 : 0 : lWidth = static_cast< long >(GETFLDVAL(aWidthField)),
423 : 0 : lHeight = static_cast< long >(GETFLDVAL(aHeightField)),
424 : 0 : lMinPWidth = lLeft + (nCols - 1) * lHDist + lWidth,
425 : 0 : lMinPHeight = lUpper + (nRows - 1) * lVDist + lHeight;
426 : :
427 : 0 : aHDistField .SetMin(nMinSize, FUNIT_CM);
428 : 0 : aVDistField .SetMin(nMinSize, FUNIT_CM);
429 : :
430 : 0 : aHDistField .SetMax((long) 100 * ((lMax - lLeft ) / Max(1L, (long) nCols)), FUNIT_TWIP);
431 : 0 : aVDistField .SetMax((long) 100 * ((lMax - lUpper) / Max(1L, (long) nRows)), FUNIT_TWIP);
432 : :
433 : 0 : aWidthField .SetMin(nMinSize, FUNIT_CM);
434 : 0 : aHeightField.SetMin(nMinSize, FUNIT_CM);
435 : :
436 : 0 : aWidthField .SetMax((long) 100 * (lHDist), FUNIT_TWIP);
437 : 0 : aHeightField.SetMax((long) 100 * (lVDist), FUNIT_TWIP);
438 : :
439 : 0 : aLeftField .SetMax((long) 100 * (lMax - nCols * lHDist), FUNIT_TWIP);
440 : 0 : aUpperField .SetMax((long) 100 * (lMax - nRows * lVDist), FUNIT_TWIP);
441 : :
442 : 0 : aColsField .SetMin( 1 );
443 : 0 : aRowsField .SetMin( 1 );
444 : :
445 : 0 : aColsField .SetMax((lMax - lLeft ) / Max(1L, lHDist));
446 : 0 : aRowsField .SetMax((lMax - lUpper) / Max(1L, lVDist));
447 : 0 : aPWidthField .SetMin( (long) 100 * lMinPWidth, FUNIT_TWIP );
448 : 0 : aPHeightField.SetMin( (long) 100 * lMinPHeight, FUNIT_TWIP );
449 : :
450 : 0 : aPWidthField .SetMax( (long) 100 * lMax, FUNIT_TWIP);
451 : 0 : aPHeightField.SetMax( (long) 100 * lMax, FUNIT_TWIP);
452 : : // First and Last
453 : :
454 : 0 : aHDistField .SetFirst(aHDistField .GetMin());
455 : 0 : aVDistField .SetFirst(aVDistField .GetMin());
456 : :
457 : 0 : aHDistField .SetLast (aHDistField .GetMax());
458 : 0 : aVDistField .SetLast (aVDistField .GetMax());
459 : :
460 : 0 : aWidthField .SetFirst(aWidthField .GetMin());
461 : 0 : aHeightField.SetFirst(aHeightField.GetMin());
462 : :
463 : 0 : aWidthField .SetLast (aWidthField .GetMax());
464 : 0 : aHeightField.SetLast (aHeightField.GetMax());
465 : :
466 : 0 : aLeftField .SetLast (aLeftField .GetMax());
467 : 0 : aUpperField .SetLast (aUpperField .GetMax());
468 : :
469 : 0 : aColsField .SetLast (aColsField .GetMax());
470 : 0 : aRowsField .SetLast (aRowsField .GetMax());
471 : 0 : aPWidthField .SetFirst(aPWidthField .GetMin());
472 : 0 : aPHeightField.SetFirst(aPHeightField.GetMin());
473 : :
474 : 0 : aPWidthField .SetLast (aPWidthField .GetMax());
475 : 0 : aPHeightField.SetLast (aPHeightField.GetMax());
476 : 0 : aHDistField .Reformat();
477 : 0 : aVDistField .Reformat();
478 : 0 : aWidthField .Reformat();
479 : 0 : aHeightField.Reformat();
480 : 0 : aLeftField .Reformat();
481 : 0 : aUpperField .Reformat();
482 : 0 : aColsField .Reformat();
483 : 0 : aRowsField .Reformat();
484 : 0 : aPWidthField .Reformat();
485 : 0 : aPHeightField.Reformat();
486 : 0 : }
487 : :
488 : 0 : SfxTabPage* SwLabFmtPage::Create(Window* pParent, const SfxItemSet& rSet)
489 : : {
490 : 0 : return new SwLabFmtPage(pParent, rSet);
491 : : }
492 : :
493 : 0 : void SwLabFmtPage::ActivatePage(const SfxItemSet& rSet)
494 : : {
495 : 0 : SfxItemSet aSet(rSet);
496 : 0 : Reset(aSet);
497 : 0 : }
498 : :
499 : 0 : int SwLabFmtPage::DeactivatePage(SfxItemSet* _pSet)
500 : : {
501 : 0 : if (_pSet)
502 : 0 : FillItemSet(*_pSet);
503 : :
504 : 0 : return sal_True;
505 : : }
506 : :
507 : 0 : void SwLabFmtPage::FillItem(SwLabItem& rItem)
508 : : {
509 : 0 : if (bModified)
510 : : {
511 : 0 : rItem.aMake = rItem.aType = SW_RESSTR(STR_CUSTOM);
512 : :
513 : 0 : SwLabRec& rRec = *GetParent()->Recs()[0];
514 : 0 : rItem.lHDist = rRec.lHDist = static_cast< long >(GETFLDVAL(aHDistField ));
515 : 0 : rItem.lVDist = rRec.lVDist = static_cast< long >(GETFLDVAL(aVDistField ));
516 : 0 : rItem.lWidth = rRec.lWidth = static_cast< long >(GETFLDVAL(aWidthField ));
517 : 0 : rItem.lHeight = rRec.lHeight = static_cast< long >(GETFLDVAL(aHeightField));
518 : 0 : rItem.lLeft = rRec.lLeft = static_cast< long >(GETFLDVAL(aLeftField ));
519 : 0 : rItem.lUpper = rRec.lUpper = static_cast< long >(GETFLDVAL(aUpperField ));
520 : 0 : rItem.nCols = rRec.nCols = (sal_uInt16) aColsField.GetValue();
521 : 0 : rItem.nRows = rRec.nRows = (sal_uInt16) aRowsField.GetValue();
522 : 0 : rItem.lPWidth = rRec.lPWidth = static_cast< long >(GETFLDVAL(aPWidthField ));
523 : 0 : rItem.lPHeight = rRec.lPHeight = static_cast< long >(GETFLDVAL(aPHeightField));
524 : : }
525 : 0 : }
526 : :
527 : 0 : sal_Bool SwLabFmtPage::FillItemSet(SfxItemSet& rSet)
528 : : {
529 : 0 : FillItem(aItem);
530 : 0 : rSet.Put(aItem);
531 : :
532 : 0 : return sal_True;
533 : : }
534 : :
535 : 0 : void SwLabFmtPage::Reset(const SfxItemSet& )
536 : : {
537 : : // Initialise fields
538 : 0 : GetParent()->GetLabItem(aItem);
539 : :
540 : 0 : aHDistField .SetMax(100 * aItem.lHDist , FUNIT_TWIP);
541 : 0 : aVDistField .SetMax(100 * aItem.lVDist , FUNIT_TWIP);
542 : 0 : aWidthField .SetMax(100 * aItem.lWidth , FUNIT_TWIP);
543 : 0 : aHeightField.SetMax(100 * aItem.lHeight, FUNIT_TWIP);
544 : 0 : aLeftField .SetMax(100 * aItem.lLeft , FUNIT_TWIP);
545 : 0 : aUpperField .SetMax(100 * aItem.lUpper , FUNIT_TWIP);
546 : 0 : aPWidthField .SetMax(100 * aItem.lPWidth , FUNIT_TWIP);
547 : 0 : aPHeightField.SetMax(100 * aItem.lPHeight, FUNIT_TWIP);
548 : :
549 : 0 : SETFLDVAL(aHDistField , aItem.lHDist );
550 : 0 : SETFLDVAL(aVDistField , aItem.lVDist );
551 : 0 : SETFLDVAL(aWidthField , aItem.lWidth );
552 : 0 : SETFLDVAL(aHeightField, aItem.lHeight);
553 : 0 : SETFLDVAL(aLeftField , aItem.lLeft );
554 : 0 : SETFLDVAL(aUpperField , aItem.lUpper );
555 : 0 : SETFLDVAL(aPWidthField , aItem.lPWidth );
556 : 0 : SETFLDVAL(aPHeightField, aItem.lPHeight);
557 : :
558 : 0 : aColsField.SetMax(aItem.nCols);
559 : 0 : aRowsField.SetMax(aItem.nRows);
560 : :
561 : 0 : aColsField .SetValue(aItem.nCols);
562 : 0 : aRowsField .SetValue(aItem.nRows);
563 : 0 : aMakeFI.SetText(aItem.aMake);
564 : 0 : aTypeFI.SetText(aItem.aType);
565 : 0 : PreviewHdl(0);
566 : 0 : }
567 : :
568 : 0 : IMPL_LINK_NOARG(SwLabFmtPage, SaveHdl)
569 : : {
570 : 0 : SwLabRec aRec;
571 : 0 : aRec.lHDist = static_cast< long >(GETFLDVAL(aHDistField ));
572 : 0 : aRec.lVDist = static_cast< long >(GETFLDVAL(aVDistField ));
573 : 0 : aRec.lWidth = static_cast< long >(GETFLDVAL(aWidthField ));
574 : 0 : aRec.lHeight = static_cast< long >(GETFLDVAL(aHeightField));
575 : 0 : aRec.lLeft = static_cast< long >(GETFLDVAL(aLeftField ));
576 : 0 : aRec.lUpper = static_cast< long >(GETFLDVAL(aUpperField ));
577 : 0 : aRec.nCols = (sal_uInt16) aColsField.GetValue();
578 : 0 : aRec.nRows = (sal_uInt16) aRowsField.GetValue();
579 : 0 : aRec.lPWidth = static_cast< long >(GETFLDVAL(aPWidthField ));
580 : 0 : aRec.lPHeight = static_cast< long >(GETFLDVAL(aPHeightField));
581 : 0 : aRec.bCont = aItem.bCont;
582 : 0 : SwSaveLabelDlg* pSaveDlg = new SwSaveLabelDlg(this, aRec);
583 : 0 : pSaveDlg->SetLabel(aItem.aLstMake, aItem.aLstType);
584 : 0 : pSaveDlg->Execute();
585 : 0 : if(pSaveDlg->GetLabel(aItem))
586 : : {
587 : 0 : bModified = sal_False;
588 : 0 : const Sequence<OUString>& rMan = GetParent()->GetLabelsConfig().GetManufacturers();
589 : 0 : std::vector<rtl::OUString>& rMakes(GetParent()->Makes());
590 : 0 : if(rMakes.size() < (sal_uInt16)rMan.getLength())
591 : : {
592 : 0 : rMakes.clear();
593 : 0 : const OUString* pMan = rMan.getConstArray();
594 : 0 : for(sal_Int32 nMan = 0; nMan < rMan.getLength(); nMan++)
595 : 0 : rMakes.push_back(pMan[nMan]);
596 : : }
597 : 0 : aMakeFI.SetText(aItem.aMake);
598 : 0 : aTypeFI.SetText(aItem.aType);
599 : : }
600 : 0 : delete pSaveDlg;
601 : 0 : return 0;
602 : : }
603 : :
604 : 0 : SwSaveLabelDlg::SwSaveLabelDlg(SwLabFmtPage* pParent, SwLabRec& rRec) :
605 : : ModalDialog(pParent, SW_RES(DLG_SAVE_LABEL)),
606 : : aOptionsFL(this,SW_RES(FL_OPTIONS )),
607 : : aMakeFT(this, SW_RES(FT_MAKE )),
608 : : aMakeCB(this, SW_RES(CB_MAKE )),
609 : : aTypeFT(this, SW_RES(FT_TYPE )),
610 : : aTypeED(this, SW_RES(ED_TYPE )),
611 : :
612 : : aOKPB(this, SW_RES(PB_OK )),
613 : : aCancelPB(this, SW_RES(PB_CANCEL )),
614 : : aHelpPB(this, SW_RES(PB_HELP )),
615 : :
616 : : aQueryMB(this, SW_RES(MB_QUERY )),
617 : :
618 : : bSuccess(sal_False),
619 : : pLabPage(pParent),
620 : 0 : rLabRec(rRec)
621 : : {
622 : 0 : FreeResource();
623 : :
624 : 0 : aOKPB.SetClickHdl(LINK(this, SwSaveLabelDlg, OkHdl));
625 : 0 : Link aLk(LINK(this, SwSaveLabelDlg, ModifyHdl));
626 : 0 : aMakeCB.SetModifyHdl(aLk);
627 : 0 : aTypeED.SetModifyHdl(aLk);
628 : :
629 : 0 : SwLabelConfig& rCfg = pLabPage->GetParent()->GetLabelsConfig();
630 : 0 : const Sequence<OUString>& rMan = rCfg.GetManufacturers();
631 : 0 : const OUString* pMan = rMan.getConstArray();
632 : 0 : for(sal_Int32 i = 0; i < rMan.getLength(); i++)
633 : 0 : aMakeCB.InsertEntry(pMan[i]);
634 : 0 : }
635 : :
636 : 0 : IMPL_LINK_NOARG(SwSaveLabelDlg, OkHdl)
637 : : {
638 : 0 : SwLabelConfig& rCfg = pLabPage->GetParent()->GetLabelsConfig();
639 : 0 : String sMake(aMakeCB.GetText());
640 : 0 : String sType(aTypeED.GetText());
641 : 0 : if(rCfg.HasLabel(sMake, sType))
642 : : {
643 : 0 : String sTmp(aQueryMB.GetMessText());
644 : 0 : String sQuery(sTmp);
645 : 0 : sQuery.SearchAndReplace(rtl::OUString("%1"), sMake);
646 : 0 : sQuery.SearchAndReplace(rtl::OUString("%2"), sType);
647 : 0 : aQueryMB.SetMessText(sQuery);
648 : :
649 : 0 : short eRet = aQueryMB.Execute();
650 : 0 : aQueryMB.SetMessText(sTmp);
651 : 0 : if(RET_YES != eRet)
652 : 0 : return 0;
653 : : }
654 : 0 : rLabRec.aType = sType;
655 : 0 : rCfg.SaveLabel(sMake, sType, rLabRec);
656 : 0 : bSuccess = sal_True;
657 : 0 : EndDialog(RET_OK);
658 : 0 : return 0;
659 : : }
660 : :
661 : 0 : IMPL_LINK_NOARG(SwSaveLabelDlg, ModifyHdl)
662 : : {
663 : 0 : aOKPB.Enable(aMakeCB.GetText().Len() && aTypeED.GetText().Len());
664 : 0 : return 0;
665 : : }
666 : :
667 : 0 : sal_Bool SwSaveLabelDlg::GetLabel(SwLabItem& rItem)
668 : : {
669 : 0 : if(bSuccess)
670 : : {
671 : 0 : rItem.aMake = aMakeCB.GetText();
672 : 0 : rItem.aType = aTypeED.GetText();
673 : 0 : rItem.lHDist = rLabRec.lHDist;
674 : 0 : rItem.lVDist = rLabRec.lVDist;
675 : 0 : rItem.lWidth = rLabRec.lWidth;
676 : 0 : rItem.lHeight = rLabRec.lHeight;
677 : 0 : rItem.lLeft = rLabRec.lLeft;
678 : 0 : rItem.lUpper = rLabRec.lUpper;
679 : 0 : rItem.nCols = rLabRec.nCols;
680 : 0 : rItem.nRows = rLabRec.nRows;
681 : 0 : rItem.lPWidth = rLabRec.lPWidth;
682 : 0 : rItem.lPHeight = rLabRec.lPHeight;
683 : : }
684 : 0 : return bSuccess;
685 : : }
686 : :
687 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|