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