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 31 32 33 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 34 #include <svl/eitem.hxx> 35 #include <svx/htmlmode.hxx> 36 #include <sfx2/dispatch.hxx> 37 #include <sfx2/bindings.hxx> 38 #ifndef _SFX_IMAGEMGR_HXX 39 #include <sfx2/imagemgr.hxx> 40 #endif 41 #include <swmodule.hxx> 42 #ifndef _VIEW_HXX 43 #include <view.hxx> 44 #endif 45 #include <initui.hxx> 46 #include <viewopt.hxx> 47 #ifndef _DOCSH_HXX 48 #include <docsh.hxx> 49 #endif 50 #include <gloshdl.hxx> 51 #include <glosdoc.hxx> 52 #include <gloslst.hxx> 53 #include <workctrl.hxx> 54 #ifndef _WORKCTRL_HRC 55 #include <workctrl.hrc> 56 #endif 57 #ifndef _CMDID_H 58 #include <cmdid.h> 59 #endif 60 #ifndef _HELPID_H 61 #include <helpid.h> 62 #endif 63 #include <wrtsh.hxx> 64 #include <svl/imageitm.hxx> 65 #include <vcl/lstbox.hxx> 66 #include <rtl/ustring.hxx> 67 #include "swabstdlg.hxx" 68 #include <misc.hrc> 69 70 #include <vcl/svapp.hxx> 71 72 //JP 14.01.99: Size Abpruefung 73 #define NAVI_ENTRIES 20 74 #if NAVI_ENTRIES != NID_COUNT 75 #error SwScrollNaviPopup-CTOR static Array falsche Size. Wurden neue IDs zugefuegt ?? 76 #endif 77 78 using ::rtl::OUString; 79 using namespace ::com::sun::star; 80 using namespace ::com::sun::star::uno; 81 using namespace ::com::sun::star::beans; 82 using namespace ::com::sun::star::frame; 83 84 SFX_IMPL_TOOLBOX_CONTROL( SwTbxInsertCtrl, SfxImageItem); 85 SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxBoolItem ); 86 87 /********************************************************************** 88 89 **********************************************************************/ 90 SwTbxInsertCtrl::SwTbxInsertCtrl( 91 sal_uInt16 nSlotId, 92 sal_uInt16 nId, 93 ToolBox& rTbx ) : 94 SfxToolBoxControl( nSlotId, nId, rTbx ), 95 nLastSlotId(FN_INSERT_CTRL == nSlotId ? FN_INSERT_TABLE : SID_INSERT_DIAGRAM) 96 { 97 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 98 } 99 /********************************************************************** 100 101 **********************************************************************/ 102 SwTbxInsertCtrl::~SwTbxInsertCtrl() 103 { 104 } 105 106 void SAL_CALL SwTbxInsertCtrl::update() throw (uno::RuntimeException) 107 { 108 ToolBox& rTbx = GetToolBox(); 109 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 110 aSlotURL += rtl::OUString::valueOf( sal_Int32( nLastSlotId )); 111 Image aImage = GetImage( m_xFrame, 112 aSlotURL, 113 hasBigImages(), 114 rTbx.GetSettings().GetStyleSettings().GetHighContrastMode() ); 115 116 rTbx.SetItemImage(GetId(), aImage); 117 rTbx.Invalidate(); 118 119 SfxToolBoxControl::update(); 120 } 121 122 /********************************************************************** 123 124 **********************************************************************/ 125 126 127 void SwTbxInsertCtrl::StateChanged( sal_uInt16 /*nSID*/, 128 SfxItemState eState, 129 const SfxPoolItem* pState ) 130 { 131 sal_uInt16 nId = GetId(); 132 GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) ); 133 134 if( eState == SFX_ITEM_AVAILABLE ) 135 { 136 const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState ); 137 if(pItem) 138 { 139 nLastSlotId = pItem->GetValue(); 140 if( nLastSlotId ) 141 nId = nLastSlotId; 142 143 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 144 aSlotURL += rtl::OUString::valueOf( sal_Int32( nId )); 145 ToolBox& rBox = GetToolBox(); 146 Image aImage = GetImage( m_xFrame, 147 aSlotURL, 148 hasBigImages(), 149 rBox.GetSettings().GetStyleSettings().GetHighContrastMode() ); 150 rBox.SetItemImage(GetId(), aImage); 151 rBox.SetItemImageMirrorMode( GetId(), sal_False ); 152 rBox.SetItemImageAngle( GetId(), pItem->GetRotation() ); 153 rBox.SetItemImageMirrorMode( GetId(), pItem->IsMirrored() ); 154 } 155 } 156 157 } 158 /********************************************************************** 159 160 **********************************************************************/ 161 162 163 SfxPopupWindow* SwTbxInsertCtrl::CreatePopupWindow() 164 { 165 if(GetSlotId() == FN_INSERT_CTRL) 166 { 167 OUString aToolBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertbar" )); 168 createAndPositionSubToolBar( aToolBarResStr ); 169 } 170 else /* FN_INSERT_OBJ_CTRL */ 171 { 172 OUString aToolBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertobjectbar" )); 173 createAndPositionSubToolBar( aToolBarResStr ); 174 } 175 return NULL; 176 } 177 178 /********************************************************************** 179 180 **********************************************************************/ 181 182 183 SfxPopupWindowType SwTbxInsertCtrl::GetPopupWindowType() const 184 { 185 return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK; 186 } 187 188 189 /********************************************************************** 190 191 **********************************************************************/ 192 193 194 void SwTbxInsertCtrl::Select( sal_Bool /*bMod1*/ ) 195 { 196 if( nLastSlotId ) 197 { 198 SfxViewShell* pCurSh( SfxViewShell::Current() ); 199 SfxDispatcher* pDispatch( 0 ); 200 201 if ( pCurSh ) 202 { 203 SfxViewFrame* pViewFrame = pCurSh->GetViewFrame(); 204 if ( pViewFrame ) 205 pDispatch = pViewFrame->GetDispatcher(); 206 } 207 208 if ( pDispatch ) 209 pDispatch->Execute(nLastSlotId); 210 } 211 } 212 213 /********************************************************************** 214 215 **********************************************************************/ 216 217 218 SwTbxAutoTextCtrl::SwTbxAutoTextCtrl( 219 sal_uInt16 nSlotId, 220 sal_uInt16 nId, 221 ToolBox& rTbx ) : 222 SfxToolBoxControl( nSlotId, nId, rTbx ), 223 pPopup(0), 224 pView(0) 225 { 226 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 227 } 228 /********************************************************************** 229 230 **********************************************************************/ 231 232 233 SwTbxAutoTextCtrl::~SwTbxAutoTextCtrl() 234 { 235 DelPopup(); 236 } 237 238 /********************************************************************** 239 240 **********************************************************************/ 241 242 243 SfxPopupWindow* SwTbxAutoTextCtrl::CreatePopupWindow() 244 { 245 pView = ::GetActiveView(); 246 if(pView && !pView->GetDocShell()->IsReadOnly() && 247 !pView->GetWrtShell().HasReadonlySel() ) 248 { 249 ToolBox& rBox = GetToolBox(); 250 251 Rectangle aItemRect( rBox.GetItemRect( GetId() ) ); 252 Point aPt(rBox.OutputToScreenPixel(aItemRect.TopLeft())); 253 aPt.X() += aItemRect.GetWidth()/2; 254 aPt.Y() += aItemRect.GetHeight()/2; 255 if(pView) 256 { 257 Link aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl); 258 259 if (GetSlotId() == FN_INSERT_FIELD_CTRL) 260 { 261 pPopup = new PopupMenu(SW_RES(RID_INSERT_FIELD_CTRL)); 262 pPopup->SetSelectHdl(aLnk); 263 264 if (::GetHtmlMode(pView->GetDocShell()) & HTMLMODE_ON) 265 { 266 pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_PGCOUNT)); 267 pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_TOPIC)); 268 } 269 } 270 else 271 { 272 pPopup = new PopupMenu; 273 SwGlossaryList* pGlossaryList = ::GetGlossaryList(); 274 sal_uInt16 nGroupCount = pGlossaryList->GetGroupCount(); 275 for(sal_uInt16 i = 1; i <= nGroupCount; i++) 276 { 277 // Gruppenname mit Pfad-Extension besorgen 278 String sTitle; 279 String sGroupName = pGlossaryList->GetGroupName(i - 1, sal_False, &sTitle); 280 sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1); 281 if(nBlockCount) 282 { 283 sal_uInt16 nIndex = 100 * (i); 284 // aber ohne extension einfuegen 285 pPopup->InsertItem( i, sTitle);//sGroupName.GetToken(0, GLOS_DELIM)); 286 PopupMenu* pSub = new PopupMenu; 287 pSub->SetSelectHdl(aLnk); 288 pPopup->SetPopupMenu(i, pSub); 289 for(sal_uInt16 j = 0; j < nBlockCount; j++) 290 { 291 String sEntry; 292 String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry)); 293 sEntry.AppendAscii(" - "); 294 sEntry += sLongName; 295 pSub->InsertItem(++nIndex, sEntry); 296 } 297 } 298 } 299 } 300 } 301 ToolBox* pToolBox = &GetToolBox(); 302 sal_uInt16 nId = GetId(); 303 pToolBox->SetItemDown( nId, sal_True ); 304 305 pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ), 306 (pToolBox->GetAlign() == WINDOWALIGN_TOP || pToolBox->GetAlign() == WINDOWALIGN_BOTTOM) ? 307 POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT ); 308 309 pToolBox->SetItemDown( nId, sal_False ); 310 } 311 GetToolBox().EndSelection(); 312 DelPopup(); 313 return 0; 314 315 } 316 317 318 /********************************************************************** 319 320 **********************************************************************/ 321 322 323 SfxPopupWindowType SwTbxAutoTextCtrl::GetPopupWindowType() const 324 { 325 return SFX_POPUPWINDOW_ONTIMEOUT; 326 } 327 328 /********************************************************************** 329 330 **********************************************************************/ 331 332 333 void SwTbxAutoTextCtrl::StateChanged( sal_uInt16 nSID, 334 SfxItemState eState, 335 const SfxPoolItem* pState ) 336 { 337 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) ); 338 if(FN_INSERT_FIELD_CTRL == nSID && eState >= SFX_ITEM_DEFAULT) 339 { 340 GetToolBox().CheckItem( GetId(), ((SfxBoolItem*)pState)->GetValue() ); 341 } 342 } 343 344 /********************************************************************** 345 346 **********************************************************************/ 347 348 349 IMPL_LINK(SwTbxAutoTextCtrl, PopupHdl, PopupMenu*, pMenu) 350 { 351 sal_uInt16 nId = pMenu->GetCurItemId(); 352 353 if ( GetSlotId() == FN_INSERT_FIELD_CTRL) 354 { 355 Sequence< PropertyValue > aArgs; 356 const char* pChar = 0; 357 switch(nId) 358 { 359 case FN_INSERT_FLD_DATE: 360 pChar = ".uno:InsertDateField"; 361 break; 362 case FN_INSERT_FLD_TIME: 363 pChar = ".uno:InsertTimeField"; 364 break; 365 case FN_INSERT_FLD_PGNUMBER: 366 pChar = ".uno:InsertPageNumberField"; 367 break; 368 case FN_INSERT_FLD_PGCOUNT: 369 pChar = ".uno:InsertPageCountField"; 370 break; 371 case FN_INSERT_FLD_TOPIC: 372 pChar = ".uno:InsertTopicField"; 373 break; 374 case FN_INSERT_FLD_TITLE: 375 pChar = ".uno:InsertTitleField"; 376 break; 377 case FN_INSERT_FLD_AUTHOR: 378 pChar = ".uno:InsertAuthorField"; 379 break; 380 default: 381 pChar = ".uno:InsertFieldCtrl"; 382 } 383 Dispatch( rtl::OUString::createFromAscii( pChar ),aArgs ); 384 } 385 else 386 { 387 sal_uInt16 nBlock = nId / 100; 388 389 SwGlossaryList* pGlossaryList = ::GetGlossaryList(); 390 String sShortName; 391 String sGroup = pGlossaryList->GetGroupName(nBlock - 1, sal_False); 392 String sLongName(pGlossaryList->GetBlockName(nBlock - 1, nId - (100 * nBlock) - 1, sShortName)); 393 394 SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl(); 395 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); 396 DBG_ASSERT(pFact, "Dialogdiet fail!"); 397 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc( DLG_RENAME_GLOS ); 398 if ( fnSetActGroup ) 399 (*fnSetActGroup)( sGroup ); 400 pGlosHdl->SetCurGroup(sGroup, sal_True); 401 pGlosHdl->InsertGlossary(sShortName); 402 } 403 return 0; 404 } 405 406 /********************************************************************** 407 408 **********************************************************************/ 409 410 411 void SwTbxAutoTextCtrl::DelPopup() 412 { 413 if(pPopup) 414 { 415 if (GetSlotId() != FN_INSERT_FIELD_CTRL) 416 { 417 for( sal_uInt16 i = 0; i < pPopup->GetItemCount(); i ++ ) 418 { 419 PopupMenu* pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i)); 420 delete pSubPopup; 421 } 422 } 423 delete pPopup; 424 pPopup = 0; 425 } 426 } 427 428 /*-----------------19.02.97 10.52------------------- 429 Navigations-Popup 430 --------------------------------------------------*/ 431 // determine the order of the toolbox items 432 static sal_uInt16 __READONLY_DATA aNavigationInsertIds[ NAVI_ENTRIES ] = 433 { 434 // -- first line 435 NID_TBL, 436 NID_FRM, 437 NID_GRF, 438 NID_OLE, 439 NID_PGE, 440 NID_OUTL, 441 NID_MARK, 442 NID_DRW, 443 NID_CTRL, 444 NID_PREV, 445 // -- second line 446 NID_REG, 447 NID_BKM, 448 NID_SEL, 449 NID_FTN, 450 NID_POSTIT, 451 NID_SRCH_REP, 452 NID_INDEX_ENTRY, 453 NID_TABLE_FORMULA, 454 NID_TABLE_FORMULA_ERROR, 455 NID_NEXT 456 }; 457 static const char* __READONLY_DATA aNavigationHelpIds[ NAVI_ENTRIES ] = 458 { 459 // -- first line 460 HID_NID_TBL, 461 HID_NID_FRM, 462 HID_NID_GRF, 463 HID_NID_OLE, 464 HID_NID_PGE, 465 HID_NID_OUTL, 466 HID_NID_MARK, 467 HID_NID_DRW, 468 HID_NID_CTRL, 469 HID_NID_PREV, 470 // -- second line 471 HID_NID_REG, 472 HID_NID_BKM, 473 HID_NID_SEL, 474 HID_NID_FTN, 475 HID_NID_POSTIT, 476 HID_NID_SRCH_REP, 477 HID_NID_INDEX_ENTRY, 478 HID_NID_TABLE_FORMULA, 479 HID_NID_TABLE_FORMULA_ERROR, 480 HID_NID_NEXT 481 }; 482 483 SwScrollNaviPopup::SwScrollNaviPopup( sal_uInt16 nId, const Reference< XFrame >& rFrame ) 484 : SfxPopupWindow(nId, rFrame, SW_RES(RID_SCROLL_NAVIGATION_WIN) ), 485 aToolBox(this, 0), 486 aSeparator(this, SW_RES(FL_SEP)), 487 aInfoField(this, SW_RES(FI_INFO)), 488 aIList(SW_RES(IL_VALUES)), 489 aIListH(SW_RES(ILH_VALUES)), 490 nFwdId(FN_START_OF_NEXT_PAGE), 491 nBackId(FN_START_OF_PREV_PAGE) 492 { 493 sal_uInt16 i; 494 495 aToolBox.SetHelpId(HID_NAVI_VS); 496 aToolBox.SetLineCount( 2 ); 497 aToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT); 498 for( i = 0; i < NID_COUNT; i++) 499 { 500 sal_uInt16 nNaviId = aNavigationInsertIds[i]; 501 String sText; 502 ToolBoxItemBits nTbxBits = 0; 503 if((NID_PREV != nNaviId) && (NID_NEXT != nNaviId)) 504 { 505 // -2, there's no string for Next/Prev 506 sal_uInt16 nResStr = ST_TBL - 2 + nNaviId - NID_START; 507 sText = String(SW_RES(nResStr)); 508 nTbxBits = TIB_CHECKABLE; 509 } 510 aToolBox.InsertItem(nNaviId, sText, nTbxBits); 511 aToolBox.SetHelpId( nNaviId, aNavigationHelpIds[i] ); 512 } 513 ApplyImageList(); 514 aToolBox.InsertBreak(NID_COUNT/2); 515 // don't call it before! 516 FreeResource(); 517 518 // these are global strings 519 for( i = 0; i < 2 * NID_COUNT; i++) 520 { 521 sQuickHelp[i] = String(SW_RES(STR_IMGBTN_START + i)); 522 } 523 524 Size aImgSize = aIList.GetImageSize(); 525 aImgSize.Width() += 5; 526 aImgSize.Height() += 5; 527 Size aSz = aToolBox.CalcWindowSizePixel(2); 528 aToolBox.SetPosSizePixel( Point(), aSz ); 529 sal_uInt16 nItemId = SwView::GetMoveType(); 530 aInfoField.SetText(aToolBox.GetItemText(nItemId)); 531 aToolBox.CheckItem( nItemId, sal_True ); 532 Size aFTSize(aInfoField.GetSizePixel()); 533 Size aSepSize(aSeparator.GetSizePixel()); 534 aSepSize.Width() = aSz.Width(); 535 536 aSz.Height() += aFTSize.Height() + aSepSize.Height(); 537 aInfoField.SetPosSizePixel( 538 Point(0, aSz.Height() - aFTSize.Height()), Size(aSz.Width(), aFTSize.Height())); 539 540 aSeparator.SetSizePixel(aSepSize); 541 aSeparator.SetPosPixel(Point(0, aSz.Height() - aFTSize.Height() - aSepSize.Height())); 542 543 SetOutputSizePixel(aSz); 544 aToolBox.SetSelectHdl(LINK(this, SwScrollNaviPopup, SelectHdl)); 545 aToolBox.StartSelection(); 546 aToolBox.Show(); 547 } 548 /*-----------------19.02.97 12.45------------------- 549 550 --------------------------------------------------*/ 551 552 SwScrollNaviPopup::~SwScrollNaviPopup() 553 { 554 } 555 /* -----------------------------08.05.2002 14:00------------------------------ 556 557 ---------------------------------------------------------------------------*/ 558 void SwScrollNaviPopup::DataChanged( const DataChangedEvent& rDCEvt ) 559 { 560 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 561 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 562 ApplyImageList(); 563 564 Window::DataChanged( rDCEvt ); 565 } 566 /* -----------------------------08.05.2002 14:02------------------------------ 567 568 ---------------------------------------------------------------------------*/ 569 void SwScrollNaviPopup::ApplyImageList() 570 { 571 ImageList& rImgLst = aToolBox.GetSettings().GetStyleSettings().GetHighContrastMode() ? 572 aIListH : aIList; 573 for(sal_uInt16 i = 0; i < NID_COUNT; i++) 574 { 575 sal_uInt16 nNaviId = aNavigationInsertIds[i]; 576 aToolBox.SetItemImage(nNaviId, rImgLst.GetImage(nNaviId)); 577 } 578 } 579 /*-----------------19.02.97 13.58------------------- 580 581 --------------------------------------------------*/ 582 583 SfxPopupWindow* SwScrollNaviPopup::Clone() const 584 { 585 return new SwScrollNaviPopup( GetId(), GetFrame() ); 586 } 587 588 /*-----------------19.02.97 14.10------------------- 589 590 --------------------------------------------------*/ 591 592 IMPL_LINK(SwScrollNaviPopup, SelectHdl, ToolBox*, pSet) 593 { 594 sal_uInt16 nSet = pSet->GetCurItemId(); 595 if( nSet != NID_PREV && nSet != NID_NEXT ) 596 { 597 SwView::SetMoveType(nSet); 598 aToolBox.SetItemText(NID_NEXT, sQuickHelp[nSet - NID_START]); 599 aToolBox.SetItemText(NID_PREV, sQuickHelp[nSet - NID_START + NID_COUNT]); 600 aInfoField.SetText(aToolBox.GetItemText(nSet)); 601 //check the current button only 602 for(sal_uInt16 i = 0; i < NID_COUNT; i++) 603 { 604 sal_uInt16 nItemId = aToolBox.GetItemId( i ); 605 aToolBox.CheckItem( nItemId, nItemId == nSet ); 606 } 607 } 608 else 609 { 610 SfxBoolItem aNext(FN_SCROLL_NEXT_PREV, NID_NEXT == nSet); 611 Any a; 612 Sequence< PropertyValue > aArgs( 1 ); 613 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollNextPrev" )); 614 aNext.QueryValue( a ); 615 aArgs[0].Value = a; 616 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ), 617 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ScrollNextPrev" )), 618 aArgs ); 619 } 620 return 0; 621 } 622 /*-----------------23.02.97 18.21------------------- 623 624 --------------------------------------------------*/ 625 626 void SwScrollNaviToolBox::MouseButtonUp( const MouseEvent& rMEvt ) 627 { 628 ToolBox::MouseButtonUp(rMEvt); 629 if ( ((SwScrollNaviPopup*)GetParent())->IsInPopupMode() ) 630 ((SwScrollNaviPopup*)GetParent())->EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL ); 631 } 632 633 /*-----------------20.06.97 13:28------------------- 634 635 --------------------------------------------------*/ 636 void SwScrollNaviToolBox::RequestHelp( const HelpEvent& rHEvt ) 637 { 638 SetItemText(NID_NEXT, SwScrollNaviPopup::GetQuickHelpText(sal_True)); 639 SetItemText(NID_PREV, SwScrollNaviPopup::GetQuickHelpText(sal_False)); 640 ToolBox::RequestHelp( rHEvt ); 641 642 } 643 644 /*-----------------20.06.97 13:41------------------- 645 646 --------------------------------------------------*/ 647 String SwScrollNaviPopup::GetQuickHelpText(sal_Bool bNext) 648 { 649 sal_uInt16 nResId = STR_IMGBTN_START; 650 nResId += SwView::GetMoveType() - NID_START; 651 if(!bNext) 652 nResId += NID_COUNT; 653 return String(SW_RES(nResId)); 654 } 655 /* -----------------------------05.09.2002 13:53------------------------------ 656 657 ---------------------------------------------------------------------------*/ 658 void SwNaviImageButton::Click() 659 { 660 // SfxBindings& rBind = SfxViewFrame::Current()->GetBindings(); 661 // rBind.ENTERREGISTRATIONS(); 662 pPopup = new 663 SwScrollNaviPopup( FN_SCROLL_NAVIGATION, 664 m_xFrame ); 665 // rBind.LEAVEREGISTRATIONS(); 666 Point aPos = OutputToScreenPixel(Point(0,0)); 667 Rectangle aRect(aPos, GetSizePixel()); 668 SetPopupWindow( pPopup ); 669 pPopup->StartPopupMode(aRect, FLOATWIN_POPUPMODE_LEFT|FLOATWIN_POPUPMODE_ALLOWTEAROFF); 670 } 671 672 //-------------------------------------------------------------------- 673 674 void SwNaviImageButton::SetPopupWindow( SfxPopupWindow* pWindow ) 675 { 676 pPopupWindow = pWindow; 677 pPopupWindow->SetPopupModeEndHdl( LINK( this, SwNaviImageButton, PopupModeEndHdl )); 678 pPopupWindow->SetDeleteLink_Impl( LINK( this, SwNaviImageButton, ClosePopupWindow )); 679 } 680 681 //-------------------------------------------------------------------- 682 683 IMPL_LINK( SwNaviImageButton, PopupModeEndHdl, void *, EMPTYARG ) 684 { 685 if ( pPopupWindow->IsVisible() ) 686 { 687 // Replace floating window with popup window and destroy 688 // floating window instance. 689 delete pFloatingWindow; 690 pFloatingWindow = pPopupWindow; 691 pPopupWindow = 0; 692 } 693 else 694 { 695 // Popup window has been closed by the user. No replacement, instance 696 // will destroy itself. 697 pPopupWindow = 0; 698 } 699 700 return 1; 701 } 702 703 //-------------------------------------------------------------------- 704 IMPL_LINK( SwNaviImageButton, ClosePopupWindow, SfxPopupWindow *, pWindow ) 705 { 706 if ( pWindow == pFloatingWindow ) 707 pFloatingWindow = 0; 708 else 709 pPopupWindow = 0; 710 711 return 1; 712 } 713 714 /*-----------------21.02.97 09:41------------------- 715 716 --------------------------------------------------*/ 717 718 void SwHlpImageButton::RequestHelp( const HelpEvent& rHEvt ) 719 { 720 721 SetQuickHelpText(SwScrollNaviPopup::GetQuickHelpText(!bUp)); 722 723 ImageButton::RequestHelp(rHEvt); 724 } 725 726 /*-----------------25.02.97 12:38------------------- 727 728 --------------------------------------------------*/ 729 730 SwNaviImageButton::SwNaviImageButton( 731 Window* pParent, 732 const Reference< XFrame >& rFrame ) : 733 ImageButton(pParent, SW_RES(BTN_NAVI)), 734 pPopup(0), 735 aImage(SW_RES(IMG_BTN)), 736 aImageH(SW_RES(IMG_BTN_H)), 737 sQuickText(SW_RES(ST_QUICK)), 738 pPopupWindow(0), 739 pFloatingWindow(0), 740 m_xFrame( rFrame ) 741 { 742 FreeResource(); 743 SetStyle(GetStyle()|WB_NOPOINTERFOCUS); 744 SetQuickHelpText(sQuickText); 745 SetModeImage( GetSettings().GetStyleSettings().GetHighContrastMode() ? aImageH : aImage); 746 } 747 /* -----------------------------2002/07/05 9:41------------------------------- 748 749 ---------------------------------------------------------------------------*/ 750 void SwNaviImageButton::DataChanged( const DataChangedEvent& rDCEvt ) 751 { 752 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 753 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 754 SetModeImage( GetSettings().GetStyleSettings().GetHighContrastMode() ? aImageH : aImage); 755 756 Window::DataChanged( rDCEvt ); 757 } 758 /* -----------------26.11.2002 09:28----------------- 759 * 760 * --------------------------------------------------*/ 761 class SwZoomBox_Impl : public ComboBox 762 { 763 sal_uInt16 nSlotId; 764 sal_Bool bRelease; 765 uno::Reference< frame::XDispatchProvider > m_xDispatchProvider; 766 767 public: 768 SwZoomBox_Impl( 769 Window* pParent, 770 sal_uInt16 nSlot, 771 const Reference< XDispatchProvider >& rDispatchProvider ); 772 ~SwZoomBox_Impl(); 773 774 protected: 775 virtual void Select(); 776 virtual long Notify( NotifyEvent& rNEvt ); 777 778 void ReleaseFocus(); 779 780 }; 781 /* -----------------26.11.2002 09:29----------------- 782 * 783 * --------------------------------------------------*/ 784 SwZoomBox_Impl::SwZoomBox_Impl( 785 Window* pParent, 786 sal_uInt16 nSlot, 787 const Reference< XDispatchProvider >& rDispatchProvider ): 788 ComboBox( pParent, SW_RES(RID_PVIEW_ZOOM_LB)), 789 nSlotId(nSlot), 790 bRelease(sal_True), 791 m_xDispatchProvider( rDispatchProvider ) 792 { 793 EnableAutocomplete( sal_False ); 794 sal_uInt16 aZoomValues[] = 795 { 25, 50, 75, 100, 150, 200 }; 796 for(sal_uInt16 i = 0; i < sizeof(aZoomValues)/sizeof(sal_uInt16); i++) 797 { 798 String sEntry = String::CreateFromInt32(aZoomValues[i]); 799 sEntry += '%'; 800 InsertEntry(sEntry); 801 } 802 } 803 /* -----------------26.11.2002 09:29----------------- 804 * 805 * --------------------------------------------------*/ 806 SwZoomBox_Impl::~SwZoomBox_Impl() 807 {} 808 /* -----------------26.11.2002 09:34----------------- 809 * 810 * --------------------------------------------------*/ 811 void SwZoomBox_Impl::Select() 812 { 813 if ( !IsTravelSelect() ) 814 { 815 String sEntry(GetText()); 816 sEntry.EraseAllChars( '%' ); 817 sal_uInt16 nZoom = (sal_uInt16)sEntry.ToInt32(); 818 if(nZoom < MINZOOM) 819 nZoom = MINZOOM; 820 if(nZoom > MAXZOOM) 821 nZoom = MAXZOOM; 822 823 SfxUInt16Item aItem( nSlotId, nZoom ); 824 if ( FN_PREVIEW_ZOOM == nSlotId ) 825 { 826 Any a; 827 Sequence< PropertyValue > aArgs( 1 ); 828 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PreviewZoom" )); 829 aItem.QueryValue( a ); 830 aArgs[0].Value = a; 831 SfxToolBoxControl::Dispatch( 832 m_xDispatchProvider, 833 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PreviewZoom" )), 834 aArgs ); 835 } 836 837 ReleaseFocus(); 838 } 839 } 840 /* -----------------02.12.2002 07:49----------------- 841 * 842 * --------------------------------------------------*/ 843 long SwZoomBox_Impl::Notify( NotifyEvent& rNEvt ) 844 { 845 long nHandled = 0; 846 847 if ( rNEvt.GetType() == EVENT_KEYINPUT ) 848 { 849 sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode(); 850 851 switch ( nCode ) 852 { 853 case KEY_RETURN: 854 case KEY_TAB: 855 { 856 if ( KEY_TAB == nCode ) 857 bRelease = sal_False; 858 else 859 nHandled = 1; 860 Select(); 861 break; 862 } 863 864 case KEY_ESCAPE: 865 SetText( GetSavedValue() ); 866 ReleaseFocus(); 867 break; 868 } 869 } 870 else if ( EVENT_LOSEFOCUS == rNEvt.GetType() ) 871 { 872 Window* pFocusWin = Application::GetFocusWindow(); 873 if ( !HasFocus() && GetSubEdit() != pFocusWin ) 874 SetText( GetSavedValue() ); 875 } 876 877 return nHandled ? nHandled : ComboBox::Notify( rNEvt ); 878 } 879 /* -----------------02.12.2002 07:51----------------- 880 * 881 * --------------------------------------------------*/ 882 void SwZoomBox_Impl::ReleaseFocus() 883 { 884 if ( !bRelease ) 885 { 886 bRelease = sal_True; 887 return; 888 } 889 SfxViewShell* pCurSh = SfxViewShell::Current(); 890 891 if ( pCurSh ) 892 { 893 Window* pShellWnd = pCurSh->GetWindow(); 894 895 if ( pShellWnd ) 896 pShellWnd->GrabFocus(); 897 } 898 } 899 900 /* -----------------26.11.2002 09:29----------------- 901 * 902 * --------------------------------------------------*/ 903 SFX_IMPL_TOOLBOX_CONTROL( SwPreviewZoomControl, SfxUInt16Item); 904 905 SwPreviewZoomControl::SwPreviewZoomControl( 906 sal_uInt16 nSlotId, 907 sal_uInt16 nId, 908 ToolBox& rTbx) : 909 SfxToolBoxControl( nSlotId, nId, rTbx ) 910 { 911 } 912 /* -----------------26.11.2002 09:29----------------- 913 * 914 * --------------------------------------------------*/ 915 SwPreviewZoomControl::~SwPreviewZoomControl() 916 { 917 } 918 /* -----------------26.11.2002 09:29----------------- 919 * 920 * --------------------------------------------------*/ 921 void SwPreviewZoomControl::StateChanged( sal_uInt16 /*nSID*/, 922 SfxItemState eState, 923 const SfxPoolItem* pState ) 924 { 925 sal_uInt16 nId = GetId(); 926 GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) ); 927 SwZoomBox_Impl* pBox = (SwZoomBox_Impl*)GetToolBox().GetItemWindow( GetId() ); 928 if(SFX_ITEM_AVAILABLE <= eState) 929 { 930 String sZoom(String::CreateFromInt32(((const SfxUInt16Item*)pState)->GetValue())); 931 sZoom += '%'; 932 pBox->SetText(sZoom); 933 pBox->SaveValue(); 934 } 935 } 936 /* -----------------26.11.2002 09:29----------------- 937 * 938 * --------------------------------------------------*/ 939 Window* SwPreviewZoomControl::CreateItemWindow( Window *pParent ) 940 { 941 SwZoomBox_Impl* pRet = new SwZoomBox_Impl( pParent, GetSlotId(), Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY )); 942 return pRet; 943 } 944