xref: /aoo4110/main/sw/source/ui/envelp/labfmt.cxx (revision b1cdbd2c)
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     aSavePB      (this, SW_RES(PB_SAVE  )),
333     bModified(sal_False),
334     aItem        ((const SwLabItem&) rSet.Get(FN_LABEL))
335 {
336 	FreeResource();
337 	SetExchangeSupport();
338 
339 	// Metriken
340 	FieldUnit aMetric = ::GetDfltMetric(sal_False);
341 	SetMetric(aHDistField , aMetric);
342 	SetMetric(aVDistField , aMetric);
343 	SetMetric(aWidthField , aMetric);
344 	SetMetric(aHeightField, aMetric);
345 	SetMetric(aLeftField  , aMetric);
346 	SetMetric(aUpperField , aMetric);
347 
348 	// Handler installieren
349 	Link aLk = LINK(this, SwLabFmtPage, ModifyHdl);
350 	aHDistField .SetModifyHdl( aLk );
351 	aVDistField .SetModifyHdl( aLk );
352 	aWidthField .SetModifyHdl( aLk );
353 	aHeightField.SetModifyHdl( aLk );
354 	aLeftField	.SetModifyHdl( aLk );
355 	aUpperField .SetModifyHdl( aLk );
356 	aColsField	.SetModifyHdl( aLk );
357 	aRowsField	.SetModifyHdl( aLk );
358 
359 	aLk = LINK(this, SwLabFmtPage, LoseFocusHdl);
360 	aHDistField .SetLoseFocusHdl( aLk );
361 	aVDistField .SetLoseFocusHdl( aLk );
362 	aWidthField .SetLoseFocusHdl( aLk );
363 	aHeightField.SetLoseFocusHdl( aLk );
364 	aLeftField	.SetLoseFocusHdl( aLk );
365 	aUpperField .SetLoseFocusHdl( aLk );
366 	aColsField	.SetLoseFocusHdl( aLk );
367 	aRowsField	.SetLoseFocusHdl( aLk );
368 
369 	aSavePB.SetClickHdl( LINK (this, SwLabFmtPage, SaveHdl));
370 	// Timer einstellen
371 	aPreviewTimer.SetTimeout(1000);
372 	aPreviewTimer.SetTimeoutHdl(LINK(this, SwLabFmtPage, PreviewHdl));
373 }
374 
375 // --------------------------------------------------------------------------
376 
377 
378 
~SwLabFmtPage()379 SwLabFmtPage::~SwLabFmtPage()
380 {
381 }
382 
383 // Modify-Handler der MetricFields. Preview-Timer starten -------------------
384 
385 
386 
IMPL_LINK_INLINE_START(SwLabFmtPage,ModifyHdl,Edit *,EMPTYARG)387 IMPL_LINK_INLINE_START( SwLabFmtPage, ModifyHdl, Edit *, EMPTYARG )
388 {
389 	bModified = sal_True;
390 	aPreviewTimer.Start();
391 	return 0;
392 }
IMPL_LINK_INLINE_END(SwLabFmtPage,ModifyHdl,Edit *,EMPTYARG)393 IMPL_LINK_INLINE_END( SwLabFmtPage, ModifyHdl, Edit *, EMPTYARG )
394 
395 // Preview invalidaten ------------------------------------------------------
396 
397 
398 
399 IMPL_LINK_INLINE_START( SwLabFmtPage, PreviewHdl, Timer *, EMPTYARG )
400 {
401 	aPreviewTimer.Stop();
402 	ChangeMinMax();
403 	FillItem( aItem );
404 	aPreview.Update( aItem );
405 
406 	return 0;
407 }
IMPL_LINK_INLINE_END(SwLabFmtPage,PreviewHdl,Timer *,EMPTYARG)408 IMPL_LINK_INLINE_END( SwLabFmtPage, PreviewHdl, Timer *, EMPTYARG )
409 
410 // LoseFocus-Handler: Bei Aenderung sofort updaten --------------------------
411 
412 
413 
414 IMPL_LINK_INLINE_START( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
415 {
416 	if (((Edit*) pControl)->IsModified())
417 		PreviewHdl(0);
418 	return 0;
419 }
IMPL_LINK_INLINE_END(SwLabFmtPage,LoseFocusHdl,Control *,pControl)420 IMPL_LINK_INLINE_END( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
421 
422 // Minima und Maxima fuer Fields festlegen ----------------------------------
423 
424 
425 void SwLabFmtPage::ChangeMinMax()
426 {
427 	long lMax = 31748; // 56 cm
428 
429 	// Min und Max
430 
431     long lLeft  = static_cast< long >(GETFLDVAL(aLeftField )),
432          lUpper = static_cast< long >(GETFLDVAL(aUpperField)),
433          lHDist = static_cast< long >(GETFLDVAL(aHDistField)),
434          lVDist = static_cast< long >(GETFLDVAL(aVDistField));
435 
436 	long nMinSize = 10;	// 0,1cm
437 
438 	aHDistField .SetMin(nMinSize, FUNIT_CM);
439 	aVDistField .SetMin(nMinSize, FUNIT_CM);
440 
441 	aHDistField .SetMax((long) 100 * ((lMax - lLeft ) / Max(1L, (long) aColsField.GetValue())), FUNIT_TWIP);
442 	aVDistField .SetMax((long) 100 * ((lMax - lUpper) / Max(1L, (long) aRowsField.GetValue())), FUNIT_TWIP);
443 
444 	aWidthField .SetMin(nMinSize, FUNIT_CM);
445 	aHeightField.SetMin(nMinSize, FUNIT_CM);
446 
447 	aWidthField .SetMax((long) 100 * (lHDist), FUNIT_TWIP);
448 	aHeightField.SetMax((long) 100 * (lVDist), FUNIT_TWIP);
449 
450 	aLeftField	.SetMax((long) 100 * (lMax - (long) aColsField.GetValue() * GETFLDVAL(aHDistField)), FUNIT_TWIP);
451 	aUpperField .SetMax((long) 100 * (lMax - (long) aRowsField.GetValue() * GETFLDVAL(aVDistField)), FUNIT_TWIP);
452 
453 	aColsField	.SetMax((lMax - lLeft ) / Max(1L, lHDist));
454 	aRowsField	.SetMax((lMax - lUpper) / Max(1L, lVDist));
455 
456 	// First und Last
457 
458 	aHDistField .SetFirst(aHDistField .GetMin());
459 	aVDistField .SetFirst(aVDistField .GetMin());
460 
461 	aHDistField .SetLast (aHDistField .GetMax());
462 	aVDistField .SetLast (aVDistField .GetMax());
463 
464 	aWidthField .SetFirst(aWidthField .GetMin());
465 	aHeightField.SetFirst(aHeightField.GetMin());
466 
467 	aWidthField .SetLast (aWidthField .GetMax());
468 	aHeightField.SetLast (aHeightField.GetMax());
469 
470 	aLeftField	.SetLast (aLeftField  .GetMax());
471 	aUpperField .SetLast (aUpperField .GetMax());
472 
473 	aColsField	.SetLast (aColsField  .GetMax());
474 	aRowsField	.SetLast (aRowsField  .GetMax());
475 
476 	aHDistField .Reformat();
477 	aVDistField .Reformat();
478 	aWidthField .Reformat();
479 	aHeightField.Reformat();
480 	aLeftField	.Reformat();
481 	aUpperField .Reformat();
482 	aColsField	.Reformat();
483 	aRowsField	.Reformat();
484 }
485 
486 // --------------------------------------------------------------------------
487 
488 
489 
Create(Window * pParent,const SfxItemSet & rSet)490 SfxTabPage* SwLabFmtPage::Create(Window* pParent, const SfxItemSet& rSet)
491 {
492 	return new SwLabFmtPage(pParent, rSet);
493 }
494 
495 // ----------------------------------------------------------------------------
496 
497 
498 
ActivatePage(const SfxItemSet & rSet)499 void SwLabFmtPage::ActivatePage(const SfxItemSet& rSet)
500 {
501 	SfxItemSet aSet(rSet);
502 	Reset(aSet);
503 }
504 
505 // ----------------------------------------------------------------------------
506 
507 
508 
DeactivatePage(SfxItemSet * _pSet)509 int SwLabFmtPage::DeactivatePage(SfxItemSet* _pSet)
510 {
511     if (_pSet)
512         FillItemSet(*_pSet);
513 
514 	return sal_True;
515 }
516 
517 // --------------------------------------------------------------------------
518 
519 
520 
FillItem(SwLabItem & rItem)521 void SwLabFmtPage::FillItem(SwLabItem& rItem)
522 {
523 	if (bModified)
524 	{
525 		rItem.aMake = rItem.aType = SW_RESSTR(STR_CUSTOM);
526 
527 		SwLabRec& rRec = *GetParent()->Recs()[0];
528         rItem.lHDist  = rRec.lHDist  = static_cast< long >(GETFLDVAL(aHDistField ));
529         rItem.lVDist  = rRec.lVDist  = static_cast< long >(GETFLDVAL(aVDistField ));
530         rItem.lWidth  = rRec.lWidth  = static_cast< long >(GETFLDVAL(aWidthField ));
531         rItem.lHeight = rRec.lHeight = static_cast< long >(GETFLDVAL(aHeightField));
532         rItem.lLeft   = rRec.lLeft   = static_cast< long >(GETFLDVAL(aLeftField  ));
533         rItem.lUpper  = rRec.lUpper  = static_cast< long >(GETFLDVAL(aUpperField ));
534 		rItem.nCols   = rRec.nCols	 = (sal_uInt16) aColsField.GetValue();
535 		rItem.nRows   = rRec.nRows	 = (sal_uInt16) aRowsField.GetValue();
536 	}
537 }
538 
539 // --------------------------------------------------------------------------
540 
541 
542 
FillItemSet(SfxItemSet & rSet)543 sal_Bool SwLabFmtPage::FillItemSet(SfxItemSet& rSet)
544 {
545 	FillItem(aItem);
546 	rSet.Put(aItem);
547 
548 	return sal_True;
549 }
550 
551 // --------------------------------------------------------------------------
Reset(const SfxItemSet &)552 void SwLabFmtPage::Reset(const SfxItemSet& )
553 {
554 	// Fields initialisieren
555 	GetParent()->GetLabItem(aItem);
556 
557 	aHDistField .SetMax(100 * aItem.lHDist , FUNIT_TWIP);
558 	aVDistField .SetMax(100 * aItem.lVDist , FUNIT_TWIP);
559 	aWidthField .SetMax(100 * aItem.lWidth , FUNIT_TWIP);
560 	aHeightField.SetMax(100 * aItem.lHeight, FUNIT_TWIP);
561 	aLeftField	.SetMax(100 * aItem.lLeft  , FUNIT_TWIP);
562 	aUpperField .SetMax(100 * aItem.lUpper , FUNIT_TWIP);
563 
564 	SETFLDVAL(aHDistField , aItem.lHDist );
565 	SETFLDVAL(aVDistField , aItem.lVDist );
566 	SETFLDVAL(aWidthField , aItem.lWidth );
567 	SETFLDVAL(aHeightField, aItem.lHeight);
568 	SETFLDVAL(aLeftField  , aItem.lLeft  );
569 	SETFLDVAL(aUpperField , aItem.lUpper );
570 
571 	aColsField.SetMax(aItem.nCols);
572 	aRowsField.SetMax(aItem.nRows);
573 
574 	aColsField	.SetValue(aItem.nCols);
575 	aRowsField	.SetValue(aItem.nRows);
576 	aMakeFI.SetText(aItem.aMake);
577 	aTypeFI.SetText(aItem.aType);
578 	PreviewHdl(0);
579 }
580 /* -----------------------------22.01.01 15:11--------------------------------
581 
582  ---------------------------------------------------------------------------*/
583 
IMPL_LINK(SwLabFmtPage,SaveHdl,PushButton *,EMPTYARG)584 IMPL_LINK( SwLabFmtPage, SaveHdl, PushButton *, EMPTYARG )
585 {
586 	SwLabRec aRec;
587     aRec.lHDist  = static_cast< long >(GETFLDVAL(aHDistField ));
588     aRec.lVDist  = static_cast< long >(GETFLDVAL(aVDistField ));
589     aRec.lWidth  = static_cast< long >(GETFLDVAL(aWidthField ));
590     aRec.lHeight = static_cast< long >(GETFLDVAL(aHeightField));
591     aRec.lLeft   = static_cast< long >(GETFLDVAL(aLeftField  ));
592     aRec.lUpper  = static_cast< long >(GETFLDVAL(aUpperField ));
593 	aRec.nCols	 = (sal_uInt16) aColsField.GetValue();
594 	aRec.nRows	 = (sal_uInt16) aRowsField.GetValue();
595 	aRec.bCont = aItem.bCont;
596 	SwSaveLabelDlg* pSaveDlg = new SwSaveLabelDlg(this, aRec);
597 	pSaveDlg->SetLabel(aItem.aLstMake, aItem.aLstType);
598 	pSaveDlg->Execute();
599 	if(pSaveDlg->GetLabel(aItem))
600 	{
601 		bModified = sal_False;
602 		const Sequence<OUString>& rMan = GetParent()->GetLabelsConfig().GetManufacturers();
603 		SvStringsDtor& rMakes = GetParent()->Makes();
604 		if(rMakes.Count() < (sal_uInt16)rMan.getLength())
605 		{
606 			rMakes.DeleteAndDestroy(0, rMakes.Count());
607 			const OUString* pMan = rMan.getConstArray();
608 			for(sal_Int32 nMan = 0; nMan < rMan.getLength(); nMan++)
609 			{
610 				rMakes.Insert( new String(pMan[nMan]), rMakes.Count() );
611 			}
612 		}
613 		aMakeFI.SetText(aItem.aMake);
614 		aTypeFI.SetText(aItem.aType);
615 	}
616 	delete pSaveDlg;
617 	return 0;
618 }
619 /* -----------------------------23.01.01 10:41--------------------------------
620 
621  ---------------------------------------------------------------------------*/
SwSaveLabelDlg(SwLabFmtPage * pParent,SwLabRec & rRec)622 SwSaveLabelDlg::SwSaveLabelDlg(SwLabFmtPage* pParent, SwLabRec& rRec) :
623 	ModalDialog(pParent, SW_RES(DLG_SAVE_LABEL)),
624     aOptionsFL(this,SW_RES(FL_OPTIONS  )),
625     aMakeFT(this,   SW_RES(FT_MAKE     )),
626     aMakeCB(this,   SW_RES(CB_MAKE     )),
627     aTypeFT(this,   SW_RES(FT_TYPE     )),
628     aTypeED(this,   SW_RES(ED_TYPE     )),
629 
630     aOKPB(this,     SW_RES(PB_OK     )),
631     aCancelPB(this, SW_RES(PB_CANCEL )),
632     aHelpPB(this,   SW_RES(PB_HELP      )),
633 
634     aQueryMB(this,  SW_RES(MB_QUERY )),
635 
636     bSuccess(sal_False),
637     pLabPage(pParent),
638     rLabRec(rRec)
639 {
640 	FreeResource();
641 
642 	aOKPB.SetClickHdl(LINK(this, SwSaveLabelDlg, OkHdl));
643 	Link aLk(LINK(this, SwSaveLabelDlg, ModifyHdl));
644 	aMakeCB.SetModifyHdl(aLk);
645 	aTypeED.SetModifyHdl(aLk);
646 
647 	SwLabelConfig& rCfg = pLabPage->GetParent()->GetLabelsConfig();
648 	const Sequence<OUString>& rMan = rCfg.GetManufacturers();
649 	const OUString* pMan = rMan.getConstArray();
650 	for(sal_Int32 i = 0; i < rMan.getLength(); i++)
651 		aMakeCB.InsertEntry(pMan[i]);
652 }
653 /* -----------------------------23.01.01 10:40--------------------------------
654 
655  ---------------------------------------------------------------------------*/
IMPL_LINK(SwSaveLabelDlg,OkHdl,OKButton *,EMPTYARG)656 IMPL_LINK(SwSaveLabelDlg, OkHdl, OKButton*, EMPTYARG)
657 {
658 	SwLabelConfig& rCfg = pLabPage->GetParent()->GetLabelsConfig();
659 	String sMake(aMakeCB.GetText());
660 	String sType(aTypeED.GetText());
661 	if(rCfg.HasLabel(sMake, sType))
662 	{
663 		String sTmp(aQueryMB.GetMessText());
664 		String sQuery(sTmp);
665 		sQuery.SearchAndReplace(C2S("%1"), sMake);
666 		sQuery.SearchAndReplace(C2S("%2"), sType);
667 		aQueryMB.SetMessText(sQuery);
668 
669 		short eRet = aQueryMB.Execute();
670 		aQueryMB.SetMessText(sTmp);
671 		if(RET_YES != eRet)
672 			return 0;
673 	}
674 	rLabRec.aType = sType;
675 	rCfg.SaveLabel(sMake, sType, rLabRec);
676 	bSuccess = sal_True;
677 	EndDialog(RET_OK);
678 	return 0;
679 }
680 /* -----------------------------23.01.01 11:22--------------------------------
681 
682  ---------------------------------------------------------------------------*/
IMPL_LINK(SwSaveLabelDlg,ModifyHdl,Edit *,EMPTYARG)683 IMPL_LINK(SwSaveLabelDlg, ModifyHdl, Edit*, EMPTYARG)
684 {
685 	aOKPB.Enable(aMakeCB.GetText().Len() && aTypeED.GetText().Len());
686 	return 0;
687 }
688 /* -----------------------------23.01.01 16:06--------------------------------
689 
690  ---------------------------------------------------------------------------*/
GetLabel(SwLabItem & rItem)691 sal_Bool SwSaveLabelDlg::GetLabel(SwLabItem& rItem)
692 {
693 	if(bSuccess)
694 	{
695 		rItem.aMake = aMakeCB.GetText();
696 		rItem.aType = aTypeED.GetText();
697 		rItem.lHDist  = rLabRec.lHDist;
698 		rItem.lVDist  = rLabRec.lVDist;
699 		rItem.lWidth  = rLabRec.lWidth;
700 		rItem.lHeight = rLabRec.lHeight;
701 		rItem.lLeft   = rLabRec.lLeft;
702 		rItem.lUpper  = rLabRec.lUpper;
703 		rItem.nCols   = rLabRec.nCols;
704 		rItem.nRows   = rLabRec.nRows;
705 	}
706 	return bSuccess;
707 }
708 
709