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