Update ooo320-m1
[ooovba.git] / sw / source / ui / ribbar / workctrl.cxx
blobe74b212fd4367c4cf0843750bcd494f5c028f430
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: workctrl.cxx,v $
10 * $Revision: 1.33 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
37 #include <svtools/eitem.hxx>
38 #include <svx/htmlmode.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/bindings.hxx>
41 #ifndef _SFX_IMAGEMGR_HXX
42 #include <sfx2/imagemgr.hxx>
43 #endif
44 #include <swmodule.hxx>
45 #ifndef _VIEW_HXX
46 #include <view.hxx>
47 #endif
48 #include <initui.hxx>
49 #include <viewopt.hxx>
50 #ifndef _DOCSH_HXX
51 #include <docsh.hxx>
52 #endif
53 #include <gloshdl.hxx>
54 #include <glosdoc.hxx>
55 #include <gloslst.hxx>
56 #include <tbxmgr.hxx>
57 #include <workctrl.hxx>
58 #ifndef _WORKCTRL_HRC
59 #include <workctrl.hrc>
60 #endif
61 #ifndef _CMDID_H
62 #include <cmdid.h>
63 #endif
64 #ifndef _HELPID_H
65 #include <helpid.h>
66 #endif
67 #include <wrtsh.hxx>
68 #include <svtools/imageitm.hxx>
69 #include <vcl/lstbox.hxx>
70 #include <rtl/ustring.hxx>
71 #include "swabstdlg.hxx"
72 #include <misc.hrc>
74 #include <vcl/svapp.hxx>
76 //JP 14.01.99: Size Abpruefung
77 #define NAVI_ENTRIES 20
78 #if NAVI_ENTRIES != NID_COUNT
79 #error SwScrollNaviPopup-CTOR static Array falsche Size. Wurden neue IDs zugefuegt ??
80 #endif
82 using ::rtl::OUString;
83 using namespace ::com::sun::star;
84 using namespace ::com::sun::star::uno;
85 using namespace ::com::sun::star::beans;
86 using namespace ::com::sun::star::frame;
88 SFX_IMPL_TOOLBOX_CONTROL( SwTbxInsertCtrl, SfxImageItem);
89 SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxBoolItem );
91 /**********************************************************************
93 **********************************************************************/
94 SwTbxInsertCtrl::SwTbxInsertCtrl(
95 USHORT nSlotId,
96 USHORT nId,
97 ToolBox& rTbx ) :
98 SfxToolBoxControl( nSlotId, nId, rTbx ),
99 nLastSlotId(FN_INSERT_CTRL == nSlotId ? FN_INSERT_TABLE : SID_INSERT_DIAGRAM)
101 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
103 /**********************************************************************
105 **********************************************************************/
106 SwTbxInsertCtrl::~SwTbxInsertCtrl()
110 void SAL_CALL SwTbxInsertCtrl::update() throw (uno::RuntimeException)
112 ToolBox& rTbx = GetToolBox();
113 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
114 aSlotURL += rtl::OUString::valueOf( sal_Int32( nLastSlotId ));
115 Image aImage = GetImage( m_xFrame,
116 aSlotURL,
117 hasBigImages(),
118 rTbx.GetDisplayBackground().GetColor().IsDark() );
120 rTbx.SetItemImage(GetId(), aImage);
121 rTbx.Invalidate();
123 SfxToolBoxControl::update();
126 /**********************************************************************
128 **********************************************************************/
131 void SwTbxInsertCtrl::StateChanged( USHORT /*nSID*/,
132 SfxItemState eState,
133 const SfxPoolItem* pState )
135 USHORT nId = GetId();
136 GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) );
138 if( eState == SFX_ITEM_AVAILABLE )
140 const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState );
141 if(pItem)
143 nLastSlotId = pItem->GetValue();
144 if( nLastSlotId )
145 nId = nLastSlotId;
147 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
148 aSlotURL += rtl::OUString::valueOf( sal_Int32( nId ));
149 Image aImage = GetImage( m_xFrame,
150 aSlotURL,
151 hasBigImages(),
152 GetToolBox().GetDisplayBackground().GetColor().IsDark() );
153 ToolBox& rBox = GetToolBox();
154 rBox.SetItemImage(GetId(), aImage);
155 rBox.SetItemImageMirrorMode( GetId(), FALSE );
156 rBox.SetItemImageAngle( GetId(), pItem->GetRotation() );
157 rBox.SetItemImageMirrorMode( GetId(), pItem->IsMirrored() );
162 /**********************************************************************
164 **********************************************************************/
167 SfxPopupWindow* SwTbxInsertCtrl::CreatePopupWindow()
169 if(GetSlotId() == FN_INSERT_CTRL)
171 OUString aToolBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertbar" ));
172 createAndPositionSubToolBar( aToolBarResStr );
174 else /* FN_INSERT_OBJ_CTRL */
176 OUString aToolBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertobjectbar" ));
177 createAndPositionSubToolBar( aToolBarResStr );
179 return NULL;
182 /**********************************************************************
184 **********************************************************************/
187 SfxPopupWindowType SwTbxInsertCtrl::GetPopupWindowType() const
189 return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
193 /**********************************************************************
195 **********************************************************************/
198 void SwTbxInsertCtrl::Select( BOOL /*bMod1*/ )
200 if( nLastSlotId )
202 SfxViewShell* pCurSh( SfxViewShell::Current() );
203 SfxDispatcher* pDispatch( 0 );
205 if ( pCurSh )
207 SfxViewFrame* pViewFrame = pCurSh->GetViewFrame();
208 if ( pViewFrame )
209 pDispatch = pViewFrame->GetDispatcher();
212 if ( pDispatch )
213 pDispatch->Execute(nLastSlotId);
217 /**********************************************************************
219 **********************************************************************/
222 SwTbxAutoTextCtrl::SwTbxAutoTextCtrl(
223 USHORT nSlotId,
224 USHORT nId,
225 ToolBox& rTbx ) :
226 SfxToolBoxControl( nSlotId, nId, rTbx ),
227 pPopup(0),
228 pView(0)
230 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
232 /**********************************************************************
234 **********************************************************************/
237 SwTbxAutoTextCtrl::~SwTbxAutoTextCtrl()
239 DelPopup();
242 /**********************************************************************
244 **********************************************************************/
247 SfxPopupWindow* SwTbxAutoTextCtrl::CreatePopupWindow()
249 pView = ::GetActiveView();
250 if(pView && !pView->GetDocShell()->IsReadOnly() &&
251 !pView->GetWrtShell().HasReadonlySel() )
253 ToolBox& rBox = GetToolBox();
255 Rectangle aItemRect( rBox.GetItemRect( GetId() ) );
256 Point aPt(rBox.OutputToScreenPixel(aItemRect.TopLeft()));
257 aPt.X() += aItemRect.GetWidth()/2;
258 aPt.Y() += aItemRect.GetHeight()/2;
259 if(pView)
261 Link aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl);
263 if (GetSlotId() == FN_INSERT_FIELD_CTRL)
265 pPopup = new PopupMenu(SW_RES(RID_INSERT_FIELD_CTRL));
266 pPopup->SetSelectHdl(aLnk);
268 if (::GetHtmlMode(pView->GetDocShell()) & HTMLMODE_ON)
270 pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_PGCOUNT));
271 pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_TOPIC));
274 else
276 pPopup = new PopupMenu;
277 SwGlossaryList* pGlossaryList = ::GetGlossaryList();
278 USHORT nGroupCount = pGlossaryList->GetGroupCount();
279 for(USHORT i = 1; i <= nGroupCount; i++)
281 // Gruppenname mit Pfad-Extension besorgen
282 String sTitle;
283 String sGroupName = pGlossaryList->GetGroupName(i - 1, FALSE, &sTitle);
284 USHORT nBlockCount = pGlossaryList->GetBlockCount(i -1);
285 if(nBlockCount)
287 USHORT nIndex = 100 * (i);
288 // aber ohne extension einfuegen
289 pPopup->InsertItem( i, sTitle);//sGroupName.GetToken(0, GLOS_DELIM));
290 PopupMenu* pSub = new PopupMenu;
291 pSub->SetSelectHdl(aLnk);
292 pPopup->SetPopupMenu(i, pSub);
293 for(USHORT j = 0; j < nBlockCount; j++)
295 String sEntry;
296 String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry));
297 sEntry.AppendAscii(" - ");
298 sEntry += sLongName;
299 pSub->InsertItem(++nIndex, sEntry);
305 ToolBox* pToolBox = &GetToolBox();
306 USHORT nId = GetId();
307 pToolBox->SetItemDown( nId, TRUE );
309 pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
310 (pToolBox->GetAlign() == WINDOWALIGN_TOP || pToolBox->GetAlign() == WINDOWALIGN_BOTTOM) ?
311 POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
313 pToolBox->SetItemDown( nId, FALSE );
315 GetToolBox().EndSelection();
316 DelPopup();
317 return 0;
322 /**********************************************************************
324 **********************************************************************/
327 SfxPopupWindowType SwTbxAutoTextCtrl::GetPopupWindowType() const
329 return SFX_POPUPWINDOW_ONTIMEOUT;
332 /**********************************************************************
334 **********************************************************************/
337 void SwTbxAutoTextCtrl::StateChanged( USHORT nSID,
338 SfxItemState eState,
339 const SfxPoolItem* pState )
341 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
342 if(FN_INSERT_FIELD_CTRL == nSID && eState >= SFX_ITEM_DEFAULT)
344 GetToolBox().CheckItem( GetId(), ((SfxBoolItem*)pState)->GetValue() );
348 /**********************************************************************
350 **********************************************************************/
353 IMPL_LINK(SwTbxAutoTextCtrl, PopupHdl, PopupMenu*, pMenu)
355 USHORT nId = pMenu->GetCurItemId();
357 if ( GetSlotId() == FN_INSERT_FIELD_CTRL)
359 Sequence< PropertyValue > aArgs;
360 const char* pChar = 0;
361 switch(nId)
363 case FN_INSERT_FLD_DATE:
364 pChar = ".uno:InsertDateField";
365 break;
366 case FN_INSERT_FLD_TIME:
367 pChar = ".uno:InsertTimeField";
368 break;
369 case FN_INSERT_FLD_PGNUMBER:
370 pChar = ".uno:InsertPageNumberField";
371 break;
372 case FN_INSERT_FLD_PGCOUNT:
373 pChar = ".uno:InsertPageCountField";
374 break;
375 case FN_INSERT_FLD_TOPIC:
376 pChar = ".uno:InsertTopicField";
377 break;
378 case FN_INSERT_FLD_TITLE:
379 pChar = ".uno:InsertTitleField";
380 break;
381 case FN_INSERT_FLD_AUTHOR:
382 pChar = ".uno:InsertAuthorField";
383 break;
384 default:
385 pChar = ".uno:InsertFieldCtrl";
387 Dispatch( rtl::OUString::createFromAscii( pChar ),aArgs );
389 else
391 USHORT nBlock = nId / 100;
393 SwGlossaryList* pGlossaryList = ::GetGlossaryList();
394 String sShortName;
395 String sGroup = pGlossaryList->GetGroupName(nBlock - 1, FALSE);
396 String sLongName(pGlossaryList->GetBlockName(nBlock - 1, nId - (100 * nBlock) - 1, sShortName));
398 SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl();
399 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
400 DBG_ASSERT(pFact, "Dialogdiet fail!");
401 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc( DLG_RENAME_GLOS );
402 if ( fnSetActGroup )
403 (*fnSetActGroup)( sGroup );
404 pGlosHdl->SetCurGroup(sGroup, TRUE);
405 pGlosHdl->InsertGlossary(sShortName);
407 return 0;
410 /**********************************************************************
412 **********************************************************************/
415 void SwTbxAutoTextCtrl::DelPopup()
417 if(pPopup)
419 if (GetSlotId() != FN_INSERT_FIELD_CTRL)
421 for( USHORT i = 0; i < pPopup->GetItemCount(); i ++ )
423 PopupMenu* pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i));
424 delete pSubPopup;
427 delete pPopup;
428 pPopup = 0;
432 /*-----------------19.02.97 10.52-------------------
433 Navigations-Popup
434 --------------------------------------------------*/
435 // determine the order of the toolbox items
436 static USHORT __READONLY_DATA aNavigationInsertIds[ NAVI_ENTRIES ] =
438 // -- first line
439 NID_TBL,
440 NID_FRM,
441 NID_GRF,
442 NID_OLE,
443 NID_PGE,
444 NID_OUTL,
445 NID_MARK,
446 NID_DRW,
447 NID_CTRL,
448 NID_PREV,
449 // -- second line
450 NID_REG,
451 NID_BKM,
452 NID_SEL,
453 NID_FTN,
454 NID_POSTIT,
455 NID_SRCH_REP,
456 NID_INDEX_ENTRY,
457 NID_TABLE_FORMULA,
458 NID_TABLE_FORMULA_ERROR,
459 NID_NEXT
461 static USHORT __READONLY_DATA aNavigationHelpIds[ NAVI_ENTRIES ] =
463 // -- first line
464 HID_NID_TBL,
465 HID_NID_FRM,
466 HID_NID_GRF,
467 HID_NID_OLE,
468 HID_NID_PGE,
469 HID_NID_OUTL,
470 HID_NID_MARK,
471 HID_NID_DRW,
472 HID_NID_CTRL,
473 HID_NID_PREV,
474 // -- second line
475 HID_NID_REG,
476 HID_NID_BKM,
477 HID_NID_SEL,
478 HID_NID_FTN,
479 HID_NID_POSTIT,
480 HID_NID_SRCH_REP,
481 HID_NID_INDEX_ENTRY,
482 HID_NID_TABLE_FORMULA,
483 HID_NID_TABLE_FORMULA_ERROR,
484 HID_NID_NEXT
487 SwScrollNaviPopup::SwScrollNaviPopup( USHORT nId, const Reference< XFrame >& rFrame )
488 : SfxPopupWindow(nId, rFrame, SW_RES(RID_SCROLL_NAVIGATION_WIN) ),
489 aToolBox(this, 0),
490 aSeparator(this, SW_RES(FL_SEP)),
491 aInfoField(this, SW_RES(FI_INFO)),
492 aIList(SW_RES(IL_VALUES)),
493 aIListH(SW_RES(ILH_VALUES)),
494 nFwdId(FN_START_OF_NEXT_PAGE),
495 nBackId(FN_START_OF_PREV_PAGE)
497 USHORT i;
499 aToolBox.SetHelpId(HID_NAVI_VS);
500 aToolBox.SetLineCount( 2 );
501 aToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
502 for( i = 0; i < NID_COUNT; i++)
504 USHORT nNaviId = aNavigationInsertIds[i];
505 String sText;
506 ToolBoxItemBits nTbxBits = 0;
507 if((NID_PREV != nNaviId) && (NID_NEXT != nNaviId))
509 // -2, there's no string for Next/Prev
510 USHORT nResStr = ST_TBL - 2 + nNaviId - NID_START;
511 sText = String(SW_RES(nResStr));
512 nTbxBits = TIB_CHECKABLE;
514 aToolBox.InsertItem(nNaviId, sText, nTbxBits);
515 aToolBox.SetHelpId( nNaviId, aNavigationHelpIds[i] );
517 ApplyImageList();
518 aToolBox.InsertBreak(NID_COUNT/2);
519 // don't call it before!
520 FreeResource();
522 // these are global strings
523 for( i = 0; i < 2 * NID_COUNT; i++)
525 sQuickHelp[i] = String(SW_RES(STR_IMGBTN_START + i));
528 Size aImgSize = aIList.GetImageSize();
529 aImgSize.Width() += 5;
530 aImgSize.Height() += 5;
531 Size aSz = aToolBox.CalcWindowSizePixel(2);
532 aToolBox.SetPosSizePixel( Point(), aSz );
533 USHORT nItemId = SwView::GetMoveType();
534 aInfoField.SetText(aToolBox.GetItemText(nItemId));
535 aToolBox.CheckItem( nItemId, sal_True );
536 Size aFTSize(aInfoField.GetSizePixel());
537 Size aSepSize(aSeparator.GetSizePixel());
538 aSepSize.Width() = aSz.Width();
540 aSz.Height() += aFTSize.Height() + aSepSize.Height();
541 aInfoField.SetPosSizePixel(
542 Point(0, aSz.Height() - aFTSize.Height()), Size(aSz.Width(), aFTSize.Height()));
544 aSeparator.SetSizePixel(aSepSize);
545 aSeparator.SetPosPixel(Point(0, aSz.Height() - aFTSize.Height() - aSepSize.Height()));
547 SetOutputSizePixel(aSz);
548 aToolBox.SetSelectHdl(LINK(this, SwScrollNaviPopup, SelectHdl));
549 aToolBox.StartSelection();
550 aToolBox.Show();
552 /*-----------------19.02.97 12.45-------------------
554 --------------------------------------------------*/
556 SwScrollNaviPopup::~SwScrollNaviPopup()
559 /* -----------------------------08.05.2002 14:00------------------------------
561 ---------------------------------------------------------------------------*/
562 void SwScrollNaviPopup::DataChanged( const DataChangedEvent& rDCEvt )
564 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
565 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
566 ApplyImageList();
568 Window::DataChanged( rDCEvt );
570 /* -----------------------------08.05.2002 14:02------------------------------
572 ---------------------------------------------------------------------------*/
573 void SwScrollNaviPopup::ApplyImageList()
575 ImageList& rImgLst = aToolBox.GetDisplayBackground().GetColor().IsDark() ?
576 aIListH : aIList;
577 for(USHORT i = 0; i < NID_COUNT; i++)
579 USHORT nNaviId = aNavigationInsertIds[i];
580 aToolBox.SetItemImage(nNaviId, rImgLst.GetImage(nNaviId));
583 /*-----------------19.02.97 13.58-------------------
585 --------------------------------------------------*/
587 SfxPopupWindow* SwScrollNaviPopup::Clone() const
589 return new SwScrollNaviPopup( GetId(), GetFrame() );
592 /*-----------------19.02.97 14.10-------------------
594 --------------------------------------------------*/
596 IMPL_LINK(SwScrollNaviPopup, SelectHdl, ToolBox*, pSet)
598 USHORT nSet = pSet->GetCurItemId();
599 if( nSet != NID_PREV && nSet != NID_NEXT )
601 SwView::SetMoveType(nSet);
602 aToolBox.SetItemText(NID_NEXT, sQuickHelp[nSet - NID_START]);
603 aToolBox.SetItemText(NID_PREV, sQuickHelp[nSet - NID_START + NID_COUNT]);
604 aInfoField.SetText(aToolBox.GetItemText(nSet));
605 //check the current button only
606 for(USHORT i = 0; i < NID_COUNT; i++)
608 USHORT nItemId = aToolBox.GetItemId( i );
609 aToolBox.CheckItem( nItemId, nItemId == nSet );
612 else
614 SfxBoolItem aNext(FN_SCROLL_NEXT_PREV, NID_NEXT == nSet);
615 Any a;
616 Sequence< PropertyValue > aArgs( 1 );
617 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollNextPrev" ));
618 aNext.QueryValue( a );
619 aArgs[0].Value = a;
620 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
621 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ScrollNextPrev" )),
622 aArgs );
624 return 0;
626 /*-----------------23.02.97 18.21-------------------
628 --------------------------------------------------*/
630 void SwScrollNaviToolBox::MouseButtonUp( const MouseEvent& rMEvt )
632 ToolBox::MouseButtonUp(rMEvt);
633 if ( ((SwScrollNaviPopup*)GetParent())->IsInPopupMode() )
634 ((SwScrollNaviPopup*)GetParent())->EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
637 /*-----------------20.06.97 13:28-------------------
639 --------------------------------------------------*/
640 void SwScrollNaviToolBox::RequestHelp( const HelpEvent& rHEvt )
642 SetItemText(NID_NEXT, SwScrollNaviPopup::GetQuickHelpText(TRUE));
643 SetItemText(NID_PREV, SwScrollNaviPopup::GetQuickHelpText(FALSE));
644 ToolBox::RequestHelp( rHEvt );
648 /*-----------------20.06.97 13:41-------------------
650 --------------------------------------------------*/
651 String SwScrollNaviPopup::GetQuickHelpText(BOOL bNext)
653 USHORT nResId = STR_IMGBTN_START;
654 nResId += SwView::GetMoveType() - NID_START;
655 if(!bNext)
656 nResId += NID_COUNT;
657 return String(SW_RES(nResId));
659 /* -----------------------------05.09.2002 13:53------------------------------
661 ---------------------------------------------------------------------------*/
662 void SwNaviImageButton::Click()
664 // SfxBindings& rBind = SfxViewFrame::Current()->GetBindings();
665 // rBind.ENTERREGISTRATIONS();
666 pPopup = new
667 SwScrollNaviPopup( FN_SCROLL_NAVIGATION,
668 m_xFrame );
669 // rBind.LEAVEREGISTRATIONS();
670 Point aPos = OutputToScreenPixel(Point(0,0));
671 Rectangle aRect(aPos, GetSizePixel());
672 SetPopupWindow( pPopup );
673 pPopup->StartPopupMode(aRect, FLOATWIN_POPUPMODE_LEFT|FLOATWIN_POPUPMODE_ALLOWTEAROFF);
676 //--------------------------------------------------------------------
678 void SwNaviImageButton::SetPopupWindow( SfxPopupWindow* pWindow )
680 pPopupWindow = pWindow;
681 pPopupWindow->SetPopupModeEndHdl( LINK( this, SwNaviImageButton, PopupModeEndHdl ));
682 pPopupWindow->SetDeleteLink_Impl( LINK( this, SwNaviImageButton, ClosePopupWindow ));
685 //--------------------------------------------------------------------
687 IMPL_LINK( SwNaviImageButton, PopupModeEndHdl, void *, EMPTYARG )
689 if ( pPopupWindow->IsVisible() )
691 // Replace floating window with popup window and destroy
692 // floating window instance.
693 delete pFloatingWindow;
694 pFloatingWindow = pPopupWindow;
695 pPopupWindow = 0;
697 else
699 // Popup window has been closed by the user. No replacement, instance
700 // will destroy itself.
701 pPopupWindow = 0;
704 return 1;
707 //--------------------------------------------------------------------
708 IMPL_LINK( SwNaviImageButton, ClosePopupWindow, SfxPopupWindow *, pWindow )
710 if ( pWindow == pFloatingWindow )
711 pFloatingWindow = 0;
712 else
713 pPopupWindow = 0;
715 return 1;
718 /*-----------------21.02.97 09:41-------------------
720 --------------------------------------------------*/
722 void SwHlpImageButton::RequestHelp( const HelpEvent& rHEvt )
725 SetQuickHelpText(SwScrollNaviPopup::GetQuickHelpText(!bUp));
727 ImageButton::RequestHelp(rHEvt);
730 /*-----------------25.02.97 12:38-------------------
732 --------------------------------------------------*/
734 SwNaviImageButton::SwNaviImageButton(
735 Window* pParent,
736 const Reference< XFrame >& rFrame ) :
737 ImageButton(pParent, SW_RES(BTN_NAVI)),
738 pPopup(0),
739 aImage(SW_RES(IMG_BTN)),
740 aImageH(SW_RES(IMG_BTN_H)),
741 sQuickText(SW_RES(ST_QUICK)),
742 pPopupWindow(0),
743 pFloatingWindow(0),
744 m_xFrame( rFrame )
746 FreeResource();
747 SetStyle(GetStyle()|WB_NOPOINTERFOCUS);
748 SetQuickHelpText(sQuickText);
749 SetModeImage( GetDisplayBackground().GetColor().IsDark() ? aImageH : aImage);
751 /* -----------------------------2002/07/05 9:41-------------------------------
753 ---------------------------------------------------------------------------*/
754 void SwNaviImageButton::DataChanged( const DataChangedEvent& rDCEvt )
756 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
757 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
758 SetModeImage( GetDisplayBackground().GetColor().IsDark() ? aImageH : aImage);
760 Window::DataChanged( rDCEvt );
762 /* -----------------26.11.2002 09:28-----------------
764 * --------------------------------------------------*/
765 class SwZoomBox_Impl : public ComboBox
767 USHORT nSlotId;
768 BOOL bRelease;
769 uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
771 public:
772 SwZoomBox_Impl(
773 Window* pParent,
774 USHORT nSlot,
775 const Reference< XDispatchProvider >& rDispatchProvider );
776 ~SwZoomBox_Impl();
778 protected:
779 virtual void Select();
780 virtual long Notify( NotifyEvent& rNEvt );
782 void ReleaseFocus();
785 /* -----------------26.11.2002 09:29-----------------
787 * --------------------------------------------------*/
788 SwZoomBox_Impl::SwZoomBox_Impl(
789 Window* pParent,
790 USHORT nSlot,
791 const Reference< XDispatchProvider >& rDispatchProvider ):
792 ComboBox( pParent, SW_RES(RID_PVIEW_ZOOM_LB)),
793 nSlotId(nSlot),
794 bRelease(TRUE),
795 m_xDispatchProvider( rDispatchProvider )
797 EnableAutocomplete( FALSE );
798 USHORT aZoomValues[] =
799 { 25, 50, 75, 100, 150, 200 };
800 for(USHORT i = 0; i < sizeof(aZoomValues)/sizeof(USHORT); i++)
802 String sEntry = String::CreateFromInt32(aZoomValues[i]);
803 sEntry += '%';
804 InsertEntry(sEntry);
807 /* -----------------26.11.2002 09:29-----------------
809 * --------------------------------------------------*/
810 SwZoomBox_Impl::~SwZoomBox_Impl()
812 /* -----------------26.11.2002 09:34-----------------
814 * --------------------------------------------------*/
815 void SwZoomBox_Impl::Select()
817 if ( !IsTravelSelect() )
819 String sEntry(GetText());
820 sEntry.EraseAllChars( '%' );
821 USHORT nZoom = (USHORT)sEntry.ToInt32();
822 if(nZoom < MINZOOM)
823 nZoom = MINZOOM;
824 if(nZoom > MAXZOOM)
825 nZoom = MAXZOOM;
827 SfxUInt16Item aItem( nSlotId, nZoom );
828 if ( FN_PREVIEW_ZOOM == nSlotId )
830 Any a;
831 Sequence< PropertyValue > aArgs( 1 );
832 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PreviewZoom" ));
833 aItem.QueryValue( a );
834 aArgs[0].Value = a;
835 SfxToolBoxControl::Dispatch(
836 m_xDispatchProvider,
837 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PreviewZoom" )),
838 aArgs );
841 ReleaseFocus();
844 /* -----------------02.12.2002 07:49-----------------
846 * --------------------------------------------------*/
847 long SwZoomBox_Impl::Notify( NotifyEvent& rNEvt )
849 long nHandled = 0;
851 if ( rNEvt.GetType() == EVENT_KEYINPUT )
853 USHORT nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
855 switch ( nCode )
857 case KEY_RETURN:
858 case KEY_TAB:
860 if ( KEY_TAB == nCode )
861 bRelease = FALSE;
862 else
863 nHandled = 1;
864 Select();
865 break;
868 case KEY_ESCAPE:
869 SetText( GetSavedValue() );
870 ReleaseFocus();
871 break;
874 else if ( EVENT_LOSEFOCUS == rNEvt.GetType() )
876 Window* pFocusWin = Application::GetFocusWindow();
877 if ( !HasFocus() && GetSubEdit() != pFocusWin )
878 SetText( GetSavedValue() );
881 return nHandled ? nHandled : ComboBox::Notify( rNEvt );
883 /* -----------------02.12.2002 07:51-----------------
885 * --------------------------------------------------*/
886 void SwZoomBox_Impl::ReleaseFocus()
888 if ( !bRelease )
890 bRelease = TRUE;
891 return;
893 SfxViewShell* pCurSh = SfxViewShell::Current();
895 if ( pCurSh )
897 Window* pShellWnd = pCurSh->GetWindow();
899 if ( pShellWnd )
900 pShellWnd->GrabFocus();
904 /* -----------------26.11.2002 09:29-----------------
906 * --------------------------------------------------*/
907 SFX_IMPL_TOOLBOX_CONTROL( SwPreviewZoomControl, SfxUInt16Item);
909 SwPreviewZoomControl::SwPreviewZoomControl(
910 USHORT nSlotId,
911 USHORT nId,
912 ToolBox& rTbx) :
913 SfxToolBoxControl( nSlotId, nId, rTbx )
916 /* -----------------26.11.2002 09:29-----------------
918 * --------------------------------------------------*/
919 SwPreviewZoomControl::~SwPreviewZoomControl()
922 /* -----------------26.11.2002 09:29-----------------
924 * --------------------------------------------------*/
925 void SwPreviewZoomControl::StateChanged( USHORT /*nSID*/,
926 SfxItemState eState,
927 const SfxPoolItem* pState )
929 USHORT nId = GetId();
930 GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) );
931 SwZoomBox_Impl* pBox = (SwZoomBox_Impl*)GetToolBox().GetItemWindow( GetId() );
932 if(SFX_ITEM_AVAILABLE <= eState)
934 String sZoom(String::CreateFromInt32(((const SfxUInt16Item*)pState)->GetValue()));
935 sZoom += '%';
936 pBox->SetText(sZoom);
937 pBox->SaveValue();
940 /* -----------------26.11.2002 09:29-----------------
942 * --------------------------------------------------*/
943 Window* SwPreviewZoomControl::CreateItemWindow( Window *pParent )
945 SwZoomBox_Impl* pRet = new SwZoomBox_Impl( pParent, GetSlotId(), Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ));
946 return pRet;