1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #ifdef SW_DLLIMPLEMENTATION
27 #undef SW_DLLIMPLEMENTATION
28 #endif
29
30
31 #include <tools/poly.hxx>
32 #include <viewopt.hxx>
33
34 #include "swtypes.hxx"
35 #include "cmdid.h"
36 #include "label.hxx"
37 #include "labimp.hxx"
38 #include "labimg.hxx"
39 #include "labfmt.hxx"
40 #include "uitool.hxx"
41
42 #include "label.hrc"
43 #include "labfmt.hrc"
44 #include <unomid.h>
45
46 using namespace utl;
47 using namespace rtl;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::beans;
50
51 // #define ------------------------------------------------------------------
52
53 #define ROUND(x) ((sal_uInt16) ((x) + .5))
54
55 // --------------------------------------------------------------------------
SwLabPreview(const SwLabFmtPage * pParent,const ResId & rResID)56 SwLabPreview::SwLabPreview( const SwLabFmtPage* pParent, const ResId& rResID ) :
57
58 Window((Window*) pParent, rResID),
59
60 aGrayColor(COL_LIGHTGRAY),
61
62 aHDistStr (SW_RES(STR_HDIST )),
63 aVDistStr (SW_RES(STR_VDIST )),
64 aWidthStr (SW_RES(STR_WIDTH )),
65 aHeightStr(SW_RES(STR_HEIGHT)),
66 aLeftStr (SW_RES(STR_LEFT )),
67 aUpperStr (SW_RES(STR_UPPER )),
68 aColsStr (SW_RES(STR_COLS )),
69 aRowsStr (SW_RES(STR_ROWS ))
70 {
71 SetMapMode(MAP_PIXEL);
72
73 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
74 const Color& rWinColor = rStyleSettings.GetWindowColor();
75 SetBackground(Wallpaper(rWinColor));
76
77 Font aFont = GetFont();
78 aFont.SetTransparent(sal_True);
79 aFont.SetWeight (WEIGHT_NORMAL);
80 SetFont(aFont);
81
82 const Size aSz(GetOutputSizePixel());
83
84 lOutWPix = aSz.Width ();
85 lOutHPix = aSz.Height();
86
87
88 lHDistWidth = GetTextWidth(aHDistStr );
89 lVDistWidth = GetTextWidth(aVDistStr );
90 lHeightWidth = GetTextWidth(aHeightStr);
91 lLeftWidth = GetTextWidth(aLeftStr );
92 lUpperWidth = GetTextWidth(aUpperStr );
93 lColsWidth = GetTextWidth(aColsStr );
94
95 lXHeight = GetTextHeight();
96 lXWidth = GetTextWidth('X');
97
98 // Skalierungsfaktor
99 float fx = (float)(lOutWPix - (2 * (lLeftWidth + 15))) / (float)lOutWPix;
100
101 lOutWPix23 = (long)((float)lOutWPix * fx);
102 lOutHPix23 = (long)((float)lOutHPix * fx);
103 }
104
105 // --------------------------------------------------------------------------
~SwLabPreview()106 SwLabPreview::~SwLabPreview()
107 {
108 }
109 // --------------------------------------------------------------------------
Paint(const Rectangle &)110 void SwLabPreview::Paint(const Rectangle &)
111 {
112 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
113 const Color& rWinColor = rStyleSettings.GetWindowColor();
114 const Color& rFieldTextColor = SwViewOption::GetFontColor();
115
116 Font aFont = GetFont();
117 aFont.SetFillColor( rWinColor );
118 aFont.SetColor(rFieldTextColor);
119 SetFont(aFont);
120
121 SetBackground(Wallpaper(rWinColor));
122
123 SetLineColor(rWinColor);
124 SetFillColor(aGrayColor);
125 Font aPaintFont(GetFont());
126 aPaintFont.SetTransparent(sal_False);
127 SetFont(aPaintFont);
128
129 // Groesse des darzustellenden Bereichs
130 long lDispW = ROUND(aItem.lLeft + aItem.lHDist);
131 long lDispH = ROUND(aItem.lUpper + aItem.lVDist);
132 if (aItem.nCols == 1)
133 lDispW += ROUND(aItem.lLeft );
134 else
135 lDispW += ROUND(aItem.lHDist / 10);
136 if (aItem.nRows == 1)
137 lDispH += ROUND(aItem.lUpper);
138 else
139 lDispH += ROUND(aItem.lVDist / 10);
140
141 // Skalierungsfaktor
142 float fx = (float) lOutWPix23 / Max(1L, lDispW),
143 fy = (float) lOutHPix23 / Max(1L, lDispH),
144 f = fx < fy ? fx : fy;
145
146 // Nullpunkt
147 long lOutlineW = ROUND(f * lDispW);
148 long lOutlineH = ROUND(f * lDispH);
149
150 long lX0 = (lOutWPix - lOutlineW) / 2;
151 long lY0 = (lOutHPix - lOutlineH) / 2;
152 long lX1 = ROUND(lX0 + f * aItem.lLeft );
153 long lY1 = ROUND(lY0 + f * aItem.lUpper);
154 long lX2 = ROUND(lX0 + f * (aItem.lLeft + aItem.lWidth ));
155 long lY2 = ROUND(lY0 + f * (aItem.lUpper + aItem.lHeight));
156 long lX3 = ROUND(lX0 + f * (aItem.lLeft + aItem.lHDist ));
157 long lY3 = ROUND(lY0 + f * (aItem.lUpper + aItem.lVDist ));
158
159 // Umriss zeichnen (Flaeche)
160 DrawRect(Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH)));
161
162 // Umriss zeichnen (Umrandung)
163 SetLineColor(rFieldTextColor);
164 DrawLine(Point(lX0, lY0), Point(lX0 + lOutlineW - 1, lY0)); // Oben
165 DrawLine(Point(lX0, lY0), Point(lX0, lY0 + lOutlineH - 1)); // Links
166 if (aItem.nCols == 1)
167 DrawLine(Point(lX0 + lOutlineW - 1, lY0), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Rechts
168 if (aItem.nRows == 1)
169 DrawLine(Point(lX0, lY0 + lOutlineH - 1), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Unten
170
171 // Etiketten
172 SetClipRegion (Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH)));
173 SetFillColor(rWinColor);
174 for (sal_uInt16 nRow = 0; nRow < Min((sal_uInt16) 2, (sal_uInt16) aItem.nRows); nRow++)
175 for (sal_uInt16 nCol = 0; nCol < Min((sal_uInt16) 2, (sal_uInt16) aItem.nCols); nCol++)
176 DrawRect(Rectangle(
177 Point(ROUND(lX0 + f * (aItem.lLeft + nCol * aItem.lHDist)),
178 ROUND(lY0 + f * (aItem.lUpper + nRow * aItem.lVDist))),
179 Size (ROUND(f * aItem.lWidth ),
180 ROUND(f * aItem.lHeight))));
181 SetClipRegion();
182
183 // Beschritung: Rand links
184 if (aItem.lLeft)
185 {
186 long lX = (lX0 + lX1) / 2;
187 DrawArrow(Point(lX0, lY0 - 5), Point(lX1, lY0 - 5), sal_False);
188 DrawArrow(Point(lX, lY0 - 10), Point(lX, lY0 - 5), sal_True);
189 DrawText(Point(lX1 - lLeftWidth, lY0 - 10 - lXHeight), aLeftStr);
190 }
191
192 // Beschriftung: Rand oben
193 if (aItem.lUpper)
194 {
195 DrawArrow(Point(lX0 - 5, lY0), Point(lX0 - 5, lY1), sal_False);
196 DrawText(Point(lX0 - 10 - lUpperWidth, ROUND(lY0 + f * aItem.lUpper / 2 - lXHeight / 2)), aUpperStr);
197 }
198
199 // Beschriftung: Breite und Hoehe
200 {
201 long lX = lX2 - lXWidth / 2 - lHeightWidth / 2;
202 long lY = lY1 + lXHeight;
203
204 DrawLine(Point(lX1, lY), Point(lX2 - 1, lY));
205 DrawLine(Point(lX, lY1), Point(lX, lY2 - 1));
206
207 DrawText(Point(lX1 + lXWidth / 2, lY - lXHeight / 2), aWidthStr);
208 DrawText(Point(lX - lHeightWidth / 2, lY2 - lXHeight - lXHeight / 2), aHeightStr);
209 }
210
211 // Beschriftung: Horz. Abstand
212 if (aItem.nCols > 1)
213 {
214 long lX = (lX1 + lX3) / 2;
215 DrawArrow(Point(lX1, lY0 - 5), Point(lX3, lY0 - 5), sal_False);
216 DrawArrow(Point(lX, lY0 - 10), Point(lX, lY0 - 5), sal_True);
217 DrawText(Point(lX - lHDistWidth / 2, lY0 - 10 - lXHeight), aHDistStr);
218 }
219
220 // Beschriftung: Vertikaler Abstand
221 if (aItem.nRows > 1)
222 {
223 DrawArrow(Point(lX0 - 5, lY1), Point(lX0 - 5, lY3), sal_False);
224 DrawText(Point(lX0 - 10 - lVDistWidth, ROUND(lY1 + f * aItem.lVDist / 2 - lXHeight / 2)), aVDistStr);
225 }
226
227 // Beschriftung: Spalten
228 {
229 long lY = lY0 + lOutlineH + 4;
230 DrawArrow(Point(lX0, lY), Point(lX0 + lOutlineW - 1, lY), sal_True);
231 DrawText(Point((lX0 + lX0 + lOutlineW - 1) / 2 - lColsWidth / 2, lY + 5), aColsStr);
232 }
233
234 // Beschriftung: Zeilen
235 {
236 long lX = lX0 + lOutlineW + 4;
237 DrawArrow(Point(lX, lY0), Point(lX, lY0 + lOutlineH - 1), sal_True);
238 DrawText(Point(lX + 5, (lY0 + lY0 + lOutlineH - 1 - lXHeight / 2) / 2), aRowsStr);
239 }
240 }
241
242 // Pfeil bzw. Intervall zeichnen --------------------------------------------
243
244
245
DrawArrow(const Point & rP1,const Point & rP2,sal_Bool bArrow)246 void SwLabPreview::DrawArrow(const Point &rP1, const Point &rP2, sal_Bool bArrow)
247 {
248 DrawLine(rP1, rP2);
249
250 if (bArrow)
251 {
252 Point aArr[3];
253
254 // Pfeil zeichnen
255 if (rP1.Y() == rP2.Y())
256 {
257 // Waagerecht
258 aArr[0].X() = rP2.X() - 5;
259 aArr[0].Y() = rP2.Y() - 2;
260 aArr[1].X() = rP2.X();
261 aArr[1].Y() = rP2.Y();
262 aArr[2].X() = rP2.X() - 5;
263 aArr[2].Y() = rP2.Y() + 2;
264 }
265 else
266 {
267 // Senkrecht
268 aArr[0].X() = rP2.X() - 2;
269 aArr[0].Y() = rP2.Y() - 5;
270 aArr[1].X() = rP2.X() + 2;
271 aArr[1].Y() = rP2.Y() - 5;
272 aArr[2].X() = rP2.X();
273 aArr[2].Y() = rP2.Y();
274 }
275
276 const Color& rFieldTextColor = SwViewOption::GetFontColor();
277 SetFillColor(rFieldTextColor);
278 DrawPolygon(Polygon(3, aArr));
279 }
280 else
281 {
282 // Intervall zeichnen
283 if (rP1.Y() == rP2.Y())
284 {
285 // Waagerecht
286 DrawLine(Point(rP1.X(), rP1.Y() - 2), Point(rP1.X(), rP1.Y() + 2));
287 DrawLine(Point(rP2.X(), rP2.Y() - 2), Point(rP2.X(), rP2.Y() + 2));
288 }
289 else
290 {
291 // Senkrecht
292 DrawLine(Point(rP1.X() - 2, rP1.Y()), Point(rP1.X() + 2, rP1.Y()));
293 DrawLine(Point(rP2.X() - 2, rP2.Y()), Point(rP2.X() + 2, rP2.Y()));
294 }
295 }
296 }
297
298 // --------------------------------------------------------------------------
299
Update(const SwLabItem & rItem)300 void SwLabPreview::Update(const SwLabItem& rItem)
301 {
302 aItem = rItem;
303 Invalidate();
304 }
305
306 // --------------------------------------------------------------------------
307
308
309
SwLabFmtPage(Window * pParent,const SfxItemSet & rSet)310 SwLabFmtPage::SwLabFmtPage(Window* pParent, const SfxItemSet& rSet) :
311
312 SfxTabPage(pParent, SW_RES(TP_LAB_FMT), rSet),
313 aMakeFI (this, SW_RES(FI_MAKE)),
314 aTypeFI (this, SW_RES(FI_TYPE)),
315 aPreview (this, SW_RES(WIN_PREVIEW)),
316 aHDistText (this, SW_RES(TXT_HDIST )),
317 aHDistField (this, SW_RES(FLD_HDIST )),
318 aVDistText (this, SW_RES(TXT_VDIST )),
319 aVDistField (this, SW_RES(FLD_VDIST )),
320 aWidthText (this, SW_RES(TXT_WIDTH )),
321 aWidthField (this, SW_RES(FLD_WIDTH )),
322 aHeightText (this, SW_RES(TXT_HEIGHT )),
323 aHeightField (this, SW_RES(FLD_HEIGHT )),
324 aLeftText (this, SW_RES(TXT_LEFT )),
325 aLeftField (this, SW_RES(FLD_LEFT )),
326 aUpperText (this, SW_RES(TXT_UPPER )),
327 aUpperField (this, SW_RES(FLD_UPPER )),
328 aColsText (this, SW_RES(TXT_COLUMNS)),
329 aColsField (this, SW_RES(FLD_COLUMNS)),
330 aRowsText (this, SW_RES(TXT_ROWS )),
331 aRowsField (this, SW_RES(FLD_ROWS )),
332 aPaperWidthText (this, SW_RES(TXT_PAPER_WIDTH)),
333 aPaperWidthField (this, SW_RES(FLD_PAPER_WIDTH)),
334 aPaperHeightText (this, SW_RES(TXT_PAPER_HEIGHT)),
335 aPaperHeightField(this, SW_RES(FLD_PAPER_HEIGHT)),
336 aSavePB (this, SW_RES(PB_SAVE )),
337 bModified(sal_False),
338 aItem ((const SwLabItem&) rSet.Get(FN_LABEL))
339 {
340 FreeResource();
341 SetExchangeSupport();
342
343 // Metriken
344 FieldUnit aMetric = ::GetDfltMetric(sal_False);
345 SetMetric(aHDistField , aMetric);
346 SetMetric(aVDistField , aMetric);
347 SetMetric(aWidthField , aMetric);
348 SetMetric(aHeightField, aMetric);
349 SetMetric(aLeftField , aMetric);
350 SetMetric(aUpperField , aMetric);
351 SetMetric(aPaperWidthField, aMetric);
352 SetMetric(aPaperHeightField, aMetric);
353
354 // Handler installieren
355 Link aLk = LINK(this, SwLabFmtPage, ModifyHdl);
356 aHDistField .SetModifyHdl( aLk );
357 aVDistField .SetModifyHdl( aLk );
358 aWidthField .SetModifyHdl( aLk );
359 aHeightField.SetModifyHdl( aLk );
360 aLeftField .SetModifyHdl( aLk );
361 aUpperField .SetModifyHdl( aLk );
362 aColsField .SetModifyHdl( aLk );
363 aRowsField .SetModifyHdl( aLk );
364 aPaperWidthField .SetModifyHdl( aLk );
365 aPaperHeightField.SetModifyHdl( aLk );
366
367 aLk = LINK(this, SwLabFmtPage, LoseFocusHdl);
368 aHDistField .SetLoseFocusHdl( aLk );
369 aVDistField .SetLoseFocusHdl( aLk );
370 aWidthField .SetLoseFocusHdl( aLk );
371 aHeightField.SetLoseFocusHdl( aLk );
372 aLeftField .SetLoseFocusHdl( aLk );
373 aUpperField .SetLoseFocusHdl( aLk );
374 aColsField .SetLoseFocusHdl( aLk );
375 aRowsField .SetLoseFocusHdl( aLk );
376
377 aSavePB.SetClickHdl( LINK (this, SwLabFmtPage, SaveHdl));
378 // Timer einstellen
379 aPreviewTimer.SetTimeout(1000);
380 aPreviewTimer.SetTimeoutHdl(LINK(this, SwLabFmtPage, PreviewHdl));
381 }
382
383 // --------------------------------------------------------------------------
384
385
386
~SwLabFmtPage()387 SwLabFmtPage::~SwLabFmtPage()
388 {
389 }
390
391 // Modify-Handler der MetricFields. Preview-Timer starten -------------------
392
393
394
IMPL_LINK_INLINE_START(SwLabFmtPage,ModifyHdl,Edit *,EMPTYARG)395 IMPL_LINK_INLINE_START( SwLabFmtPage, ModifyHdl, Edit *, EMPTYARG )
396 {
397 bModified = sal_True;
398 aPreviewTimer.Start();
399 return 0;
400 }
IMPL_LINK_INLINE_END(SwLabFmtPage,ModifyHdl,Edit *,EMPTYARG)401 IMPL_LINK_INLINE_END( SwLabFmtPage, ModifyHdl, Edit *, EMPTYARG )
402
403 // Preview invalidaten ------------------------------------------------------
404
405
406
407 IMPL_LINK_INLINE_START( SwLabFmtPage, PreviewHdl, Timer *, EMPTYARG )
408 {
409 aPreviewTimer.Stop();
410 ChangeMinMax();
411 FillItem( aItem );
412 aPreview.Update( aItem );
413
414 return 0;
415 }
IMPL_LINK_INLINE_END(SwLabFmtPage,PreviewHdl,Timer *,EMPTYARG)416 IMPL_LINK_INLINE_END( SwLabFmtPage, PreviewHdl, Timer *, EMPTYARG )
417
418 // LoseFocus-Handler: Bei Aenderung sofort updaten --------------------------
419
420
421
422 IMPL_LINK_INLINE_START( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
423 {
424 if (((Edit*) pControl)->IsModified())
425 PreviewHdl(0);
426 return 0;
427 }
IMPL_LINK_INLINE_END(SwLabFmtPage,LoseFocusHdl,Control *,pControl)428 IMPL_LINK_INLINE_END( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
429
430 // Minima und Maxima fuer Fields festlegen ----------------------------------
431
432
433 void SwLabFmtPage::ChangeMinMax()
434 {
435 long lMax = 31748; // 56 cm
436
437 // Min und Max
438
439 long lLeft = static_cast< long >(GETFLDVAL(aLeftField )),
440 lUpper = static_cast< long >(GETFLDVAL(aUpperField)),
441 lHDist = static_cast< long >(GETFLDVAL(aHDistField)),
442 lVDist = static_cast< long >(GETFLDVAL(aVDistField));
443
444 long nMinSize = 10; // 0,1cm
445
446 aHDistField .SetMin(nMinSize, FUNIT_CM);
447 aVDistField .SetMin(nMinSize, FUNIT_CM);
448
449 aHDistField .SetMax((long) 100 * ((lMax - lLeft ) / Max(1L, (long) aColsField.GetValue())), FUNIT_TWIP);
450 aVDistField .SetMax((long) 100 * ((lMax - lUpper) / Max(1L, (long) aRowsField.GetValue())), FUNIT_TWIP);
451
452 aWidthField .SetMin(nMinSize, FUNIT_CM);
453 aHeightField.SetMin(nMinSize, FUNIT_CM);
454
455 aWidthField .SetMax((long) 100 * (lHDist), FUNIT_TWIP);
456 aHeightField.SetMax((long) 100 * (lVDist), FUNIT_TWIP);
457
458 aLeftField .SetMax((long) 100 * (lMax - (long) aColsField.GetValue() * GETFLDVAL(aHDistField)), FUNIT_TWIP);
459 aUpperField .SetMax((long) 100 * (lMax - (long) aRowsField.GetValue() * GETFLDVAL(aVDistField)), FUNIT_TWIP);
460
461 aColsField .SetMax((lMax - lLeft ) / Max(1L, lHDist));
462 aRowsField .SetMax((lMax - lUpper) / Max(1L, lVDist));
463
464 // First und Last
465
466 aHDistField .SetFirst(aHDistField .GetMin());
467 aVDistField .SetFirst(aVDistField .GetMin());
468
469 aHDistField .SetLast (aHDistField .GetMax());
470 aVDistField .SetLast (aVDistField .GetMax());
471
472 aWidthField .SetFirst(aWidthField .GetMin());
473 aHeightField.SetFirst(aHeightField.GetMin());
474
475 aWidthField .SetLast (aWidthField .GetMax());
476 aHeightField.SetLast (aHeightField.GetMax());
477
478 aLeftField .SetLast (aLeftField .GetMax());
479 aUpperField .SetLast (aUpperField .GetMax());
480
481 aColsField .SetLast (aColsField .GetMax());
482 aRowsField .SetLast (aRowsField .GetMax());
483
484 aHDistField .Reformat();
485 aVDistField .Reformat();
486 aWidthField .Reformat();
487 aHeightField.Reformat();
488 aLeftField .Reformat();
489 aUpperField .Reformat();
490 aColsField .Reformat();
491 aRowsField .Reformat();
492 }
493
494 // --------------------------------------------------------------------------
495
496
497
Create(Window * pParent,const SfxItemSet & rSet)498 SfxTabPage* SwLabFmtPage::Create(Window* pParent, const SfxItemSet& rSet)
499 {
500 return new SwLabFmtPage(pParent, rSet);
501 }
502
503 // ----------------------------------------------------------------------------
504
505
506
ActivatePage(const SfxItemSet & rSet)507 void SwLabFmtPage::ActivatePage(const SfxItemSet& rSet)
508 {
509 SfxItemSet aSet(rSet);
510 Reset(aSet);
511 }
512
513 // ----------------------------------------------------------------------------
514
515
516
DeactivatePage(SfxItemSet * _pSet)517 int SwLabFmtPage::DeactivatePage(SfxItemSet* _pSet)
518 {
519 if (_pSet)
520 FillItemSet(*_pSet);
521
522 return sal_True;
523 }
524
525 // --------------------------------------------------------------------------
526
527
528
FillItem(SwLabItem & rItem)529 void SwLabFmtPage::FillItem(SwLabItem& rItem)
530 {
531 if (bModified)
532 {
533 rItem.aMake = rItem.aType = SW_RESSTR(STR_CUSTOM);
534
535 SwLabRec& rRec = *GetParent()->Recs()[0];
536 rItem.lHDist = rRec.lHDist = static_cast< long >(GETFLDVAL(aHDistField ));
537 rItem.lVDist = rRec.lVDist = static_cast< long >(GETFLDVAL(aVDistField ));
538 rItem.lWidth = rRec.lWidth = static_cast< long >(GETFLDVAL(aWidthField ));
539 rItem.lHeight = rRec.lHeight = static_cast< long >(GETFLDVAL(aHeightField));
540 rItem.lLeft = rRec.lLeft = static_cast< long >(GETFLDVAL(aLeftField ));
541 rItem.lUpper = rRec.lUpper = static_cast< long >(GETFLDVAL(aUpperField ));
542 rItem.nCols = rRec.nCols = (sal_uInt16) aColsField.GetValue();
543 rItem.nRows = rRec.nRows = (sal_uInt16) aRowsField.GetValue();
544 rItem.lPaperWidth = rRec.lPaperWidth = static_cast< long >(GETFLDVAL(aPaperWidthField));
545 rItem.lPaperHeight = rRec.lPaperHeight = static_cast< long >(GETFLDVAL(aPaperHeightField));
546 }
547 }
548
549 // --------------------------------------------------------------------------
550
551
552
FillItemSet(SfxItemSet & rSet)553 sal_Bool SwLabFmtPage::FillItemSet(SfxItemSet& rSet)
554 {
555 FillItem(aItem);
556 rSet.Put(aItem);
557
558 return sal_True;
559 }
560
561 // --------------------------------------------------------------------------
Reset(const SfxItemSet &)562 void SwLabFmtPage::Reset(const SfxItemSet& )
563 {
564 // Fields initialisieren
565 GetParent()->GetLabItem(aItem);
566
567 aHDistField .SetMax(100 * aItem.lHDist , FUNIT_TWIP);
568 aVDistField .SetMax(100 * aItem.lVDist , FUNIT_TWIP);
569 aWidthField .SetMax(100 * aItem.lWidth , FUNIT_TWIP);
570 aHeightField.SetMax(100 * aItem.lHeight, FUNIT_TWIP);
571 aLeftField .SetMax(100 * aItem.lLeft , FUNIT_TWIP);
572 aUpperField .SetMax(100 * aItem.lUpper , FUNIT_TWIP);
573
574 SETFLDVAL(aHDistField , aItem.lHDist );
575 SETFLDVAL(aVDistField , aItem.lVDist );
576 SETFLDVAL(aWidthField , aItem.lWidth );
577 SETFLDVAL(aHeightField, aItem.lHeight);
578 SETFLDVAL(aLeftField , aItem.lLeft );
579 SETFLDVAL(aUpperField , aItem.lUpper );
580 SETFLDVAL(aPaperWidthField , aItem.lPaperWidth );
581 SETFLDVAL(aPaperHeightField, aItem.lPaperHeight);
582
583 aColsField.SetMax(aItem.nCols);
584 aRowsField.SetMax(aItem.nRows);
585
586 aColsField .SetValue(aItem.nCols);
587 aRowsField .SetValue(aItem.nRows);
588 aMakeFI.SetText(aItem.aMake);
589 aTypeFI.SetText(aItem.aType);
590 PreviewHdl(0);
591 }
592 /* -----------------------------22.01.01 15:11--------------------------------
593
594 ---------------------------------------------------------------------------*/
595
IMPL_LINK(SwLabFmtPage,SaveHdl,PushButton *,EMPTYARG)596 IMPL_LINK( SwLabFmtPage, SaveHdl, PushButton *, EMPTYARG )
597 {
598 SwLabRec aRec;
599 aRec.lHDist = static_cast< long >(GETFLDVAL(aHDistField ));
600 aRec.lVDist = static_cast< long >(GETFLDVAL(aVDistField ));
601 aRec.lWidth = static_cast< long >(GETFLDVAL(aWidthField ));
602 aRec.lHeight = static_cast< long >(GETFLDVAL(aHeightField));
603 aRec.lLeft = static_cast< long >(GETFLDVAL(aLeftField ));
604 aRec.lUpper = static_cast< long >(GETFLDVAL(aUpperField ));
605 aRec.nCols = (sal_uInt16) aColsField.GetValue();
606 aRec.nRows = (sal_uInt16) aRowsField.GetValue();
607 aRec.lPaperWidth = static_cast< long >(GETFLDVAL(aPaperWidthField ));
608 aRec.lPaperHeight = static_cast< long >(GETFLDVAL(aPaperHeightField));
609 aRec.bCont = aItem.bCont;
610 SwSaveLabelDlg* pSaveDlg = new SwSaveLabelDlg(this, aRec);
611 pSaveDlg->SetLabel(aItem.aLstMake, aItem.aLstType);
612 pSaveDlg->Execute();
613 if(pSaveDlg->GetLabel(aItem))
614 {
615 bModified = sal_False;
616 const Sequence<OUString>& rMan = GetParent()->GetLabelsConfig().GetManufacturers();
617 SvStringsDtor& rMakes = GetParent()->Makes();
618 if(rMakes.Count() < (sal_uInt16)rMan.getLength())
619 {
620 rMakes.DeleteAndDestroy(0, rMakes.Count());
621 const OUString* pMan = rMan.getConstArray();
622 for(sal_Int32 nMan = 0; nMan < rMan.getLength(); nMan++)
623 {
624 rMakes.Insert( new String(pMan[nMan]), rMakes.Count() );
625 }
626 }
627 aMakeFI.SetText(aItem.aMake);
628 aTypeFI.SetText(aItem.aType);
629 }
630 delete pSaveDlg;
631 return 0;
632 }
633 /* -----------------------------23.01.01 10:41--------------------------------
634
635 ---------------------------------------------------------------------------*/
SwSaveLabelDlg(SwLabFmtPage * pParent,SwLabRec & rRec)636 SwSaveLabelDlg::SwSaveLabelDlg(SwLabFmtPage* pParent, SwLabRec& rRec) :
637 ModalDialog(pParent, SW_RES(DLG_SAVE_LABEL)),
638 aOptionsFL(this,SW_RES(FL_OPTIONS )),
639 aMakeFT(this, SW_RES(FT_MAKE )),
640 aMakeCB(this, SW_RES(CB_MAKE )),
641 aTypeFT(this, SW_RES(FT_TYPE )),
642 aTypeED(this, SW_RES(ED_TYPE )),
643
644 aOKPB(this, SW_RES(PB_OK )),
645 aCancelPB(this, SW_RES(PB_CANCEL )),
646 aHelpPB(this, SW_RES(PB_HELP )),
647
648 aQueryMB(this, SW_RES(MB_QUERY )),
649
650 bSuccess(sal_False),
651 pLabPage(pParent),
652 rLabRec(rRec)
653 {
654 FreeResource();
655
656 aOKPB.SetClickHdl(LINK(this, SwSaveLabelDlg, OkHdl));
657 Link aLk(LINK(this, SwSaveLabelDlg, ModifyHdl));
658 aMakeCB.SetModifyHdl(aLk);
659 aTypeED.SetModifyHdl(aLk);
660
661 SwLabelConfig& rCfg = pLabPage->GetParent()->GetLabelsConfig();
662 const Sequence<OUString>& rMan = rCfg.GetManufacturers();
663 const OUString* pMan = rMan.getConstArray();
664 for(sal_Int32 i = 0; i < rMan.getLength(); i++)
665 aMakeCB.InsertEntry(pMan[i]);
666 }
667 /* -----------------------------23.01.01 10:40--------------------------------
668
669 ---------------------------------------------------------------------------*/
IMPL_LINK(SwSaveLabelDlg,OkHdl,OKButton *,EMPTYARG)670 IMPL_LINK(SwSaveLabelDlg, OkHdl, OKButton*, EMPTYARG)
671 {
672 SwLabelConfig& rCfg = pLabPage->GetParent()->GetLabelsConfig();
673 String sMake(aMakeCB.GetText());
674 String sType(aTypeED.GetText());
675 if(rCfg.HasLabel(sMake, sType))
676 {
677 String sTmp(aQueryMB.GetMessText());
678 String sQuery(sTmp);
679 sQuery.SearchAndReplace(C2S("%1"), sMake);
680 sQuery.SearchAndReplace(C2S("%2"), sType);
681 aQueryMB.SetMessText(sQuery);
682
683 short eRet = aQueryMB.Execute();
684 aQueryMB.SetMessText(sTmp);
685 if(RET_YES != eRet)
686 return 0;
687 }
688 rLabRec.aType = sType;
689 rCfg.SaveLabel(sMake, sType, rLabRec);
690 bSuccess = sal_True;
691 EndDialog(RET_OK);
692 return 0;
693 }
694 /* -----------------------------23.01.01 11:22--------------------------------
695
696 ---------------------------------------------------------------------------*/
IMPL_LINK(SwSaveLabelDlg,ModifyHdl,Edit *,EMPTYARG)697 IMPL_LINK(SwSaveLabelDlg, ModifyHdl, Edit*, EMPTYARG)
698 {
699 aOKPB.Enable(aMakeCB.GetText().Len() && aTypeED.GetText().Len());
700 return 0;
701 }
702 /* -----------------------------23.01.01 16:06--------------------------------
703
704 ---------------------------------------------------------------------------*/
GetLabel(SwLabItem & rItem)705 sal_Bool SwSaveLabelDlg::GetLabel(SwLabItem& rItem)
706 {
707 if(bSuccess)
708 {
709 rItem.aMake = aMakeCB.GetText();
710 rItem.aType = aTypeED.GetText();
711 rItem.lHDist = rLabRec.lHDist;
712 rItem.lVDist = rLabRec.lVDist;
713 rItem.lWidth = rLabRec.lWidth;
714 rItem.lHeight = rLabRec.lHeight;
715 rItem.lLeft = rLabRec.lLeft;
716 rItem.lUpper = rLabRec.lUpper;
717 rItem.nCols = rLabRec.nCols;
718 rItem.nRows = rLabRec.nRows;
719 rItem.lPaperWidth = rLabRec.lPaperWidth;
720 rItem.lPaperHeight = rLabRec.lPaperHeight;
721 }
722 return bSuccess;
723 }
724
725