Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <string>
21 : #include <comphelper/string.hxx>
22 : #include <i18nutil/unicode.hxx>
23 : #include <svl/eitem.hxx>
24 : #include <sfx2/htmlmode.hxx>
25 : #include <sfx2/dispatch.hxx>
26 : #include <sfx2/bindings.hxx>
27 : #include <sfx2/imagemgr.hxx>
28 : #include <swmodule.hxx>
29 : #include <view.hxx>
30 : #include <initui.hxx>
31 : #include <viewopt.hxx>
32 : #include <docsh.hxx>
33 : #include <gloshdl.hxx>
34 : #include <glosdoc.hxx>
35 : #include <gloslst.hxx>
36 : #include <workctrl.hxx>
37 : #include <workctrl.hrc>
38 : #include <cmdid.h>
39 : #include <helpid.h>
40 : #include <wrtsh.hxx>
41 : #include <svl/imageitm.hxx>
42 : #include <vcl/lstbox.hxx>
43 : #include <vcl/settings.hxx>
44 : #include <rtl/ustring.hxx>
45 : #include "swabstdlg.hxx"
46 : #include <misc.hrc>
47 :
48 : #include <vcl/svapp.hxx>
49 :
50 : // Size check
51 : #define NAVI_ENTRIES 20
52 : #if NAVI_ENTRIES != NID_COUNT
53 : #error SwScrollNaviPopup-CTOR static array wrong size. Are new IDs added?
54 : #endif
55 :
56 : using namespace ::com::sun::star;
57 : using namespace ::com::sun::star::uno;
58 : using namespace ::com::sun::star::beans;
59 : using namespace ::com::sun::star::frame;
60 :
61 74 : SFX_IMPL_TOOLBOX_CONTROL( SwTbxInsertCtrl, SfxImageItem);
62 37 : SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxVoidItem );
63 37 : SFX_IMPL_TOOLBOX_CONTROL( SwTbxFieldCtrl, SfxBoolItem );
64 :
65 0 : SwTbxInsertCtrl::SwTbxInsertCtrl(
66 : sal_uInt16 nSlotId,
67 : sal_uInt16 nId,
68 : ToolBox& rTbx ) :
69 : SfxToolBoxControl( nSlotId, nId, rTbx ),
70 0 : nLastSlotId(FN_INSERT_CTRL == nSlotId ? FN_INSERT_TABLE : SID_INSERT_DIAGRAM)
71 : {
72 0 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
73 0 : }
74 :
75 0 : SwTbxInsertCtrl::~SwTbxInsertCtrl()
76 : {
77 0 : }
78 :
79 0 : void SAL_CALL SwTbxInsertCtrl::update() throw (uno::RuntimeException, std::exception)
80 : {
81 0 : ToolBox& rTbx = GetToolBox();
82 0 : OUString aSlotURL = "slot:" + OUString::number( nLastSlotId);
83 0 : Image aImage = GetImage( m_xFrame, aSlotURL, hasBigImages() );
84 :
85 0 : rTbx.SetItemImage(GetId(), aImage);
86 0 : rTbx.Invalidate();
87 :
88 0 : SfxToolBoxControl::update();
89 0 : }
90 :
91 0 : void SwTbxInsertCtrl::StateChanged( sal_uInt16 /*nSID*/,
92 : SfxItemState eState,
93 : const SfxPoolItem* pState )
94 : {
95 0 : sal_uInt16 nId = GetId();
96 0 : GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) );
97 :
98 0 : if( eState == SFX_ITEM_AVAILABLE )
99 : {
100 0 : const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState );
101 0 : if(pItem)
102 : {
103 0 : nLastSlotId = pItem->GetValue();
104 0 : if( nLastSlotId )
105 0 : nId = nLastSlotId;
106 :
107 0 : OUString aSlotURL = "slot:" + OUString::number( nId);
108 0 : ToolBox& rBox = GetToolBox();
109 0 : Image aImage = GetImage( m_xFrame, aSlotURL, hasBigImages() );
110 0 : rBox.SetItemImage(GetId(), aImage);
111 0 : rBox.SetItemImageMirrorMode( GetId(), false );
112 0 : rBox.SetItemImageAngle( GetId(), pItem->GetRotation() );
113 0 : rBox.SetItemImageMirrorMode( GetId(), pItem->IsMirrored() );
114 : }
115 : }
116 :
117 0 : }
118 :
119 0 : SfxPopupWindow* SwTbxInsertCtrl::CreatePopupWindow()
120 : {
121 0 : if(GetSlotId() == FN_INSERT_CTRL)
122 : {
123 0 : OUString aToolBarResStr( "private:resource/toolbar/insertbar" );
124 0 : createAndPositionSubToolBar( aToolBarResStr );
125 : }
126 : else /* FN_INSERT_OBJ_CTRL */
127 : {
128 0 : OUString aToolBarResStr( "private:resource/toolbar/insertobjectbar" );
129 0 : createAndPositionSubToolBar( aToolBarResStr );
130 : }
131 0 : return NULL;
132 : }
133 :
134 0 : SfxPopupWindowType SwTbxInsertCtrl::GetPopupWindowType() const
135 : {
136 0 : return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
137 : }
138 :
139 0 : void SwTbxInsertCtrl::Select( sal_Bool /*bMod1*/ )
140 : {
141 0 : if( nLastSlotId )
142 : {
143 0 : SfxViewShell* pCurSh( SfxViewShell::Current() );
144 0 : SfxDispatcher* pDispatch( 0 );
145 :
146 0 : if ( pCurSh )
147 : {
148 0 : SfxViewFrame* pViewFrame = pCurSh->GetViewFrame();
149 0 : if ( pViewFrame )
150 0 : pDispatch = pViewFrame->GetDispatcher();
151 : }
152 :
153 0 : if ( pDispatch )
154 0 : pDispatch->Execute(nLastSlotId);
155 : }
156 0 : }
157 :
158 0 : SwTbxAutoTextCtrl::SwTbxAutoTextCtrl(
159 : sal_uInt16 nSlotId,
160 : sal_uInt16 nId,
161 : ToolBox& rTbx ) :
162 : SfxToolBoxControl( nSlotId, nId, rTbx ),
163 : pPopup(0),
164 0 : pView(0)
165 : {
166 0 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
167 0 : }
168 :
169 0 : SwTbxAutoTextCtrl::~SwTbxAutoTextCtrl()
170 : {
171 0 : DelPopup();
172 0 : }
173 :
174 0 : SfxPopupWindow* SwTbxAutoTextCtrl::CreatePopupWindow()
175 : {
176 0 : pView = ::GetActiveView();
177 0 : if(pView && !pView->GetDocShell()->IsReadOnly() &&
178 0 : !pView->GetWrtShell().HasReadonlySel() )
179 : {
180 0 : ToolBox& rBox = GetToolBox();
181 :
182 0 : Rectangle aItemRect( rBox.GetItemRect( GetId() ) );
183 0 : Point aPt(rBox.OutputToScreenPixel(aItemRect.TopLeft()));
184 0 : aPt.X() += aItemRect.GetWidth()/2;
185 0 : aPt.Y() += aItemRect.GetHeight()/2;
186 0 : if(pView)
187 : {
188 0 : Link aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl);
189 :
190 0 : pPopup = new PopupMenu;
191 0 : SwGlossaryList* pGlossaryList = ::GetGlossaryList();
192 0 : sal_uInt16 nGroupCount = pGlossaryList->GetGroupCount();
193 0 : for(sal_uInt16 i = 1; i <= nGroupCount; i++)
194 : {
195 0 : OUString sTitle = pGlossaryList->GetGroupTitle(i - 1);
196 0 : sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1);
197 0 : if(nBlockCount)
198 : {
199 0 : sal_uInt16 nIndex = 100 * (i);
200 : // but insert without extension
201 0 : pPopup->InsertItem( i, sTitle);
202 0 : PopupMenu* pSub = new PopupMenu;
203 0 : pSub->SetSelectHdl(aLnk);
204 0 : pPopup->SetPopupMenu(i, pSub);
205 0 : for(sal_uInt16 j = 0; j < nBlockCount; j++)
206 : {
207 0 : OUString sLongName(pGlossaryList->GetBlockLongName(i - 1, j));
208 0 : OUString sShortName(pGlossaryList->GetBlockShortName(i - 1, j));
209 :
210 0 : OUString sEntry = sShortName + " - " + sLongName;
211 0 : pSub->InsertItem(++nIndex, sEntry);
212 0 : }
213 : }
214 0 : }
215 : }
216 0 : ToolBox* pToolBox = &GetToolBox();
217 0 : sal_uInt16 nId = GetId();
218 0 : pToolBox->SetItemDown( nId, true );
219 :
220 0 : pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
221 0 : (pToolBox->GetAlign() == WINDOWALIGN_TOP || pToolBox->GetAlign() == WINDOWALIGN_BOTTOM) ?
222 0 : POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
223 :
224 0 : pToolBox->SetItemDown( nId, false );
225 : }
226 0 : GetToolBox().EndSelection();
227 0 : DelPopup();
228 0 : return 0;
229 :
230 : }
231 :
232 0 : SfxPopupWindowType SwTbxAutoTextCtrl::GetPopupWindowType() const
233 : {
234 0 : return SFX_POPUPWINDOW_ONTIMEOUT;
235 : }
236 :
237 0 : void SwTbxAutoTextCtrl::StateChanged( sal_uInt16,
238 : SfxItemState,
239 : const SfxPoolItem* pState )
240 : {
241 0 : GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
242 0 : }
243 :
244 0 : IMPL_LINK(SwTbxAutoTextCtrl, PopupHdl, PopupMenu*, pMenu)
245 : {
246 0 : sal_uInt16 nId = pMenu->GetCurItemId();
247 :
248 0 : sal_uInt16 nBlock = nId / 100;
249 :
250 0 : SwGlossaryList* pGlossaryList = ::GetGlossaryList();
251 0 : OUString sGroup = pGlossaryList->GetGroupName(nBlock - 1, false);
252 : OUString sShortName =
253 0 : pGlossaryList->GetBlockShortName(nBlock - 1, nId - (100 * nBlock) - 1);
254 :
255 0 : SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl();
256 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
257 : OSL_ENSURE(pFact, "Dialogdiet fail!");
258 0 : ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
259 0 : if ( fnSetActGroup )
260 0 : (*fnSetActGroup)( sGroup );
261 0 : pGlosHdl->SetCurGroup(sGroup, sal_True);
262 0 : pGlosHdl->InsertGlossary(sShortName);
263 :
264 0 : return 0;
265 : }
266 :
267 0 : void SwTbxAutoTextCtrl::DelPopup()
268 : {
269 0 : if(pPopup)
270 : {
271 0 : for( sal_uInt16 i = 0; i < pPopup->GetItemCount(); i ++ )
272 : {
273 0 : PopupMenu* pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i));
274 0 : delete pSubPopup;
275 : }
276 0 : delete pPopup;
277 0 : pPopup = 0;
278 : }
279 0 : }
280 :
281 0 : SwTbxFieldCtrl::SwTbxFieldCtrl(
282 : sal_uInt16 nSlotId,
283 : sal_uInt16 nId,
284 : ToolBox& rTbx ) :
285 : SfxToolBoxControl( nSlotId, nId, rTbx ),
286 : pPopup(0),
287 0 : pView(0)
288 : {
289 0 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
290 0 : }
291 :
292 0 : SwTbxFieldCtrl::~SwTbxFieldCtrl()
293 : {
294 0 : DelPopup();
295 0 : }
296 :
297 0 : SfxPopupWindow* SwTbxFieldCtrl::CreatePopupWindow()
298 : {
299 0 : pView = ::GetActiveView();
300 0 : if(pView && !pView->GetDocShell()->IsReadOnly() &&
301 0 : !pView->GetWrtShell().HasReadonlySel() )
302 : {
303 0 : ToolBox& rBox = GetToolBox();
304 :
305 0 : Rectangle aItemRect( rBox.GetItemRect( GetId() ) );
306 0 : Point aPt(rBox.OutputToScreenPixel(aItemRect.TopLeft()));
307 0 : aPt.X() += aItemRect.GetWidth()/2;
308 0 : aPt.Y() += aItemRect.GetHeight()/2;
309 0 : if(pView)
310 : {
311 0 : Link aLnk = LINK(this, SwTbxFieldCtrl, PopupHdl);
312 :
313 0 : pPopup = new PopupMenu(SW_RES(RID_INSERT_FIELD_CTRL));
314 0 : pPopup->SetSelectHdl(aLnk);
315 :
316 0 : if (::GetHtmlMode(pView->GetDocShell()) & HTMLMODE_ON)
317 : {
318 0 : pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_PGCOUNT));
319 0 : pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_TOPIC));
320 : }
321 : }
322 0 : ToolBox* pToolBox = &GetToolBox();
323 0 : sal_uInt16 nId = GetId();
324 0 : pToolBox->SetItemDown( nId, true );
325 :
326 0 : pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
327 0 : (pToolBox->GetAlign() == WINDOWALIGN_TOP || pToolBox->GetAlign() == WINDOWALIGN_BOTTOM) ?
328 0 : POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
329 :
330 0 : pToolBox->SetItemDown( nId, false );
331 : }
332 0 : GetToolBox().EndSelection();
333 0 : DelPopup();
334 0 : return 0;
335 :
336 : }
337 :
338 0 : SfxPopupWindowType SwTbxFieldCtrl::GetPopupWindowType() const
339 : {
340 0 : return SFX_POPUPWINDOW_ONTIMEOUT;
341 : }
342 :
343 0 : void SwTbxFieldCtrl::StateChanged( sal_uInt16,
344 : SfxItemState eState,
345 : const SfxPoolItem* pState )
346 : {
347 0 : GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
348 0 : if (eState >= SFX_ITEM_DEFAULT)
349 : {
350 0 : GetToolBox().CheckItem( GetId(), ((SfxBoolItem*)pState)->GetValue() );
351 : }
352 0 : }
353 :
354 0 : IMPL_LINK(SwTbxFieldCtrl, PopupHdl, PopupMenu*, pMenu)
355 : {
356 0 : sal_uInt16 nId = pMenu->GetCurItemId();
357 :
358 0 : Sequence< PropertyValue > aArgs;
359 0 : const char* pChar = 0;
360 0 : switch(nId)
361 : {
362 : case FN_INSERT_FLD_DATE:
363 0 : pChar = ".uno:InsertDateField";
364 0 : break;
365 : case FN_INSERT_FLD_TIME:
366 0 : pChar = ".uno:InsertTimeField";
367 0 : break;
368 : case FN_INSERT_FLD_PGNUMBER:
369 0 : pChar = ".uno:InsertPageNumberField";
370 0 : break;
371 : case FN_INSERT_FLD_PGCOUNT:
372 0 : pChar = ".uno:InsertPageCountField";
373 0 : break;
374 : case FN_INSERT_FLD_TOPIC:
375 0 : pChar = ".uno:InsertTopicField";
376 0 : break;
377 : case FN_INSERT_FLD_TITLE:
378 0 : pChar = ".uno:InsertTitleField";
379 0 : break;
380 : case FN_INSERT_FLD_AUTHOR:
381 0 : pChar = ".uno:InsertAuthorField";
382 0 : break;
383 : default:
384 0 : pChar = ".uno:InsertFieldCtrl";
385 : }
386 0 : Dispatch( OUString::createFromAscii( pChar ),aArgs );
387 :
388 0 : return 0;
389 : }
390 :
391 0 : void SwTbxFieldCtrl::DelPopup()
392 : {
393 0 : if(pPopup)
394 : {
395 0 : delete pPopup;
396 0 : pPopup = 0;
397 : }
398 0 : }
399 :
400 : // Navigation-Popup
401 : // determine the order of the toolbox items
402 : static sal_uInt16 aNavigationInsertIds[ NAVI_ENTRIES ] =
403 : {
404 : // -- first line
405 : NID_TBL,
406 : NID_FRM,
407 : NID_GRF,
408 : NID_OLE,
409 : NID_PGE,
410 : NID_OUTL,
411 : NID_MARK,
412 : NID_DRW,
413 : NID_CTRL,
414 : NID_PREV,
415 : // -- second line
416 : NID_REG,
417 : NID_BKM,
418 : NID_SEL,
419 : NID_FTN,
420 : NID_POSTIT,
421 : NID_SRCH_REP,
422 : NID_INDEX_ENTRY,
423 : NID_TABLE_FORMULA,
424 : NID_TABLE_FORMULA_ERROR,
425 : NID_NEXT
426 : };
427 : static const char* aNavigationHelpIds[ NAVI_ENTRIES ] =
428 : {
429 : // -- first line
430 : HID_NID_TBL,
431 : HID_NID_FRM,
432 : HID_NID_GRF,
433 : HID_NID_OLE,
434 : HID_NID_PGE,
435 : HID_NID_OUTL,
436 : HID_NID_MARK,
437 : HID_NID_DRW,
438 : HID_NID_CTRL,
439 : HID_NID_PREV,
440 : // -- second line
441 : HID_NID_REG,
442 : HID_NID_BKM,
443 : HID_NID_SEL,
444 : HID_NID_FTN,
445 : HID_NID_POSTIT,
446 : HID_NID_SRCH_REP,
447 : HID_NID_INDEX_ENTRY,
448 : HID_NID_TABLE_FORMULA,
449 : HID_NID_TABLE_FORMULA_ERROR,
450 : HID_NID_NEXT
451 : };
452 :
453 0 : SwScrollNaviPopup::SwScrollNaviPopup(sal_uInt16 nId, const Reference< XFrame >& rFrame, Window *pParent)
454 : : SfxPopupWindow(nId, rFrame, pParent, SW_RES(RID_SCROLL_NAVIGATION_WIN)),
455 : aToolBox(this, 0),
456 : aSeparator(this, SW_RES(FL_SEP)),
457 : aInfoField(this, SW_RES(FI_INFO)),
458 0 : aIList(SW_RES(IL_VALUES))
459 : {
460 : sal_uInt16 i;
461 :
462 0 : aToolBox.SetHelpId(HID_NAVI_VS);
463 0 : aToolBox.SetLineCount( 2 );
464 0 : aToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
465 0 : for( i = 0; i < NID_COUNT; i++)
466 : {
467 0 : sal_uInt16 nNaviId = aNavigationInsertIds[i];
468 0 : OUString sText;
469 0 : ToolBoxItemBits nTbxBits = 0;
470 0 : if((NID_PREV != nNaviId) && (NID_NEXT != nNaviId))
471 : {
472 : // -2, there's no string for Next/Prev
473 0 : sal_uInt16 nResStr = ST_TBL - 2 + nNaviId - NID_START;
474 0 : sText = SW_RESSTR(nResStr);
475 0 : nTbxBits = TIB_CHECKABLE;
476 : }
477 : else
478 : {
479 0 : if (nNaviId == NID_PREV)
480 0 : sText = SW_RESSTR(STR_IMGBTN_PGE_UP);
481 0 : else if (nNaviId == NID_NEXT)
482 0 : sText = SW_RESSTR(STR_IMGBTN_PGE_DOWN);
483 : }
484 0 : aToolBox.InsertItem(nNaviId, sText, nTbxBits);
485 0 : aToolBox.SetHelpId( nNaviId, aNavigationHelpIds[i] );
486 0 : }
487 0 : ApplyImageList();
488 0 : aToolBox.InsertBreak(NID_COUNT/2);
489 : // don't call it before!
490 0 : FreeResource();
491 :
492 : // these are global strings
493 0 : for( i = 0; i < 2 * NID_COUNT; i++)
494 : {
495 0 : sQuickHelp[i] = SW_RESSTR(STR_IMGBTN_START + i);
496 : }
497 :
498 0 : Size aImgSize = aIList.GetImageSize();
499 0 : aImgSize.Width() += 5;
500 0 : aImgSize.Height() += 5;
501 0 : Size aSz = aToolBox.CalcWindowSizePixel(2);
502 0 : aToolBox.SetPosSizePixel( Point(), aSz );
503 0 : sal_uInt16 nItemId = SwView::GetMoveType();
504 0 : aInfoField.SetText(aToolBox.GetItemText(nItemId));
505 0 : aToolBox.CheckItem( nItemId, true );
506 0 : Size aFTSize(aInfoField.GetSizePixel());
507 0 : Size aSepSize(aSeparator.GetSizePixel());
508 0 : aSepSize.Width() = aSz.Width();
509 :
510 0 : aSz.Height() += aFTSize.Height() + aSepSize.Height();
511 : aInfoField.SetPosSizePixel(
512 0 : Point(0, aSz.Height() - aFTSize.Height()), Size(aSz.Width(), aFTSize.Height()));
513 :
514 0 : aSeparator.SetSizePixel(aSepSize);
515 0 : aSeparator.SetPosPixel(Point(0, aSz.Height() - aFTSize.Height() - aSepSize.Height()));
516 :
517 0 : SetOutputSizePixel(aSz);
518 0 : aToolBox.SetSelectHdl(LINK(this, SwScrollNaviPopup, SelectHdl));
519 0 : aToolBox.StartSelection();
520 0 : aToolBox.Show();
521 0 : }
522 :
523 0 : SwScrollNaviPopup::~SwScrollNaviPopup()
524 : {
525 0 : }
526 :
527 0 : void SwScrollNaviPopup::DataChanged( const DataChangedEvent& rDCEvt )
528 : {
529 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
530 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
531 0 : ApplyImageList();
532 :
533 0 : Window::DataChanged( rDCEvt );
534 0 : }
535 :
536 0 : void SwScrollNaviPopup::ApplyImageList()
537 : {
538 0 : ImageList& rImgLst = aIList;
539 0 : for(sal_uInt16 i = 0; i < NID_COUNT; i++)
540 : {
541 0 : sal_uInt16 nNaviId = aNavigationInsertIds[i];
542 0 : aToolBox.SetItemImage(nNaviId, rImgLst.GetImage(nNaviId));
543 : }
544 0 : }
545 :
546 0 : SfxPopupWindow* SwScrollNaviPopup::Clone() const
547 : {
548 0 : return new SwScrollNaviPopup( GetId(), GetFrame(), GetParent() );
549 : }
550 :
551 0 : IMPL_LINK(SwScrollNaviPopup, SelectHdl, ToolBox*, pSet)
552 : {
553 0 : sal_uInt16 nSet = pSet->GetCurItemId();
554 0 : if( nSet != NID_PREV && nSet != NID_NEXT )
555 : {
556 0 : SwView::SetMoveType(nSet);
557 0 : aToolBox.SetItemText(NID_NEXT, sQuickHelp[nSet - NID_START]);
558 0 : aToolBox.SetItemText(NID_PREV, sQuickHelp[nSet - NID_START + NID_COUNT]);
559 0 : aInfoField.SetText(aToolBox.GetItemText(nSet));
560 : // check the current button only
561 0 : for(sal_uInt16 i = 0; i < NID_COUNT; i++)
562 : {
563 0 : sal_uInt16 nItemId = aToolBox.GetItemId( i );
564 0 : aToolBox.CheckItem( nItemId, nItemId == nSet );
565 0 : }
566 : }
567 : else
568 : {
569 0 : Sequence< PropertyValue > aArgs;
570 0 : OUString cmd(".uno:ScrollToPrevious");
571 0 : if (NID_NEXT == nSet)
572 0 : cmd = OUString(".uno:ScrollToNext");
573 0 : SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
574 0 : cmd, aArgs );
575 : }
576 0 : return 0;
577 : }
578 :
579 0 : void SwScrollNaviToolBox::MouseButtonUp( const MouseEvent& rMEvt )
580 : {
581 0 : ToolBox::MouseButtonUp(rMEvt);
582 0 : if ( ((SwScrollNaviPopup*)GetParent())->IsInPopupMode() )
583 0 : ((SwScrollNaviPopup*)GetParent())->EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
584 0 : }
585 :
586 0 : void SwScrollNaviToolBox::RequestHelp( const HelpEvent& rHEvt )
587 : {
588 0 : SetItemText(NID_NEXT, SwScrollNaviPopup::GetQuickHelpText(sal_True));
589 0 : SetItemText(NID_PREV, SwScrollNaviPopup::GetQuickHelpText(sal_False));
590 0 : ToolBox::RequestHelp( rHEvt );
591 :
592 0 : }
593 :
594 0 : OUString SwScrollNaviPopup::GetQuickHelpText(sal_Bool bNext)
595 : {
596 0 : sal_uInt16 nResId = STR_IMGBTN_START;
597 0 : nResId += SwView::GetMoveType() - NID_START;
598 0 : if(!bNext)
599 0 : nResId += NID_COUNT;
600 0 : return SW_RESSTR(nResId);
601 : }
602 :
603 0 : void SwHlpImageButton::RequestHelp( const HelpEvent& rHEvt )
604 : {
605 :
606 0 : SetQuickHelpText(SwScrollNaviPopup::GetQuickHelpText(!bUp));
607 :
608 0 : ImageButton::RequestHelp(rHEvt);
609 0 : }
610 :
611 : class SwZoomBox_Impl : public ComboBox
612 : {
613 : sal_uInt16 nSlotId;
614 : bool bRelease;
615 : uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
616 :
617 : public:
618 : SwZoomBox_Impl(
619 : Window* pParent,
620 : sal_uInt16 nSlot,
621 : const Reference< XDispatchProvider >& rDispatchProvider );
622 : virtual ~SwZoomBox_Impl();
623 :
624 : protected:
625 : virtual void Select() SAL_OVERRIDE;
626 : virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
627 :
628 : void ReleaseFocus();
629 :
630 : };
631 :
632 0 : SwZoomBox_Impl::SwZoomBox_Impl(
633 : Window* pParent,
634 : sal_uInt16 nSlot,
635 : const Reference< XDispatchProvider >& rDispatchProvider ):
636 : ComboBox( pParent, SW_RES(RID_PVIEW_ZOOM_LB)),
637 : nSlotId(nSlot),
638 : bRelease(true),
639 0 : m_xDispatchProvider( rDispatchProvider )
640 : {
641 0 : EnableAutocomplete( false );
642 : sal_uInt16 aZoomValues[] =
643 0 : { 25, 50, 75, 100, 150, 200 };
644 0 : for(sal_uInt16 i = 0; i < sizeof(aZoomValues)/sizeof(sal_uInt16); i++)
645 : {
646 0 : OUString sEntry = unicode::formatPercent(aZoomValues[i],
647 0 : Application::GetSettings().GetUILanguageTag());
648 0 : InsertEntry(sEntry);
649 0 : }
650 0 : }
651 :
652 0 : SwZoomBox_Impl::~SwZoomBox_Impl()
653 0 : {}
654 :
655 0 : void SwZoomBox_Impl::Select()
656 : {
657 0 : if ( !IsTravelSelect() )
658 : {
659 0 : OUString sEntry(comphelper::string::remove(GetText(), '%'));
660 0 : sal_uInt16 nZoom = (sal_uInt16)sEntry.toInt32();
661 0 : if(nZoom < MINZOOM)
662 0 : nZoom = MINZOOM;
663 0 : if(nZoom > MAXZOOM)
664 0 : nZoom = MAXZOOM;
665 :
666 0 : SfxUInt16Item aItem( nSlotId, nZoom );
667 0 : if ( FN_PREVIEW_ZOOM == nSlotId )
668 : {
669 0 : Any a;
670 0 : Sequence< PropertyValue > aArgs( 1 );
671 0 : aArgs[0].Name = "PreviewZoom";
672 0 : aItem.QueryValue( a );
673 0 : aArgs[0].Value = a;
674 : SfxToolBoxControl::Dispatch(
675 : m_xDispatchProvider,
676 : OUString( ".uno:PreviewZoom" ),
677 0 : aArgs );
678 : }
679 :
680 0 : ReleaseFocus();
681 : }
682 0 : }
683 :
684 0 : bool SwZoomBox_Impl::Notify( NotifyEvent& rNEvt )
685 : {
686 0 : bool bHandled = false;
687 :
688 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
689 : {
690 0 : sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
691 :
692 0 : switch ( nCode )
693 : {
694 : case KEY_RETURN:
695 : case KEY_TAB:
696 : {
697 0 : if ( KEY_TAB == nCode )
698 0 : bRelease = false;
699 : else
700 0 : bHandled = true;
701 0 : Select();
702 0 : break;
703 : }
704 :
705 : case KEY_ESCAPE:
706 0 : SetText( GetSavedValue() );
707 0 : ReleaseFocus();
708 0 : break;
709 : }
710 : }
711 0 : else if ( EVENT_LOSEFOCUS == rNEvt.GetType() )
712 : {
713 0 : Window* pFocusWin = Application::GetFocusWindow();
714 0 : if ( !HasFocus() && GetSubEdit() != pFocusWin )
715 0 : SetText( GetSavedValue() );
716 : }
717 :
718 0 : return bHandled || ComboBox::Notify( rNEvt );
719 : }
720 :
721 0 : void SwZoomBox_Impl::ReleaseFocus()
722 : {
723 0 : if ( !bRelease )
724 : {
725 0 : bRelease = true;
726 0 : return;
727 : }
728 0 : SfxViewShell* pCurSh = SfxViewShell::Current();
729 :
730 0 : if ( pCurSh )
731 : {
732 0 : Window* pShellWnd = pCurSh->GetWindow();
733 :
734 0 : if ( pShellWnd )
735 0 : pShellWnd->GrabFocus();
736 : }
737 : }
738 :
739 37 : SFX_IMPL_TOOLBOX_CONTROL( SwPreviewZoomControl, SfxUInt16Item);
740 :
741 0 : SwPreviewZoomControl::SwPreviewZoomControl(
742 : sal_uInt16 nSlotId,
743 : sal_uInt16 nId,
744 : ToolBox& rTbx) :
745 0 : SfxToolBoxControl( nSlotId, nId, rTbx )
746 : {
747 0 : }
748 :
749 0 : SwPreviewZoomControl::~SwPreviewZoomControl()
750 : {
751 0 : }
752 :
753 0 : void SwPreviewZoomControl::StateChanged( sal_uInt16 /*nSID*/,
754 : SfxItemState eState,
755 : const SfxPoolItem* pState )
756 : {
757 0 : sal_uInt16 nId = GetId();
758 0 : GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) );
759 0 : SwZoomBox_Impl* pBox = (SwZoomBox_Impl*)GetToolBox().GetItemWindow( GetId() );
760 0 : if(SFX_ITEM_AVAILABLE <= eState)
761 : {
762 0 : OUString sZoom(unicode::formatPercent(((const SfxUInt16Item*)pState)->GetValue(),
763 0 : Application::GetSettings().GetUILanguageTag()));
764 0 : pBox->SetText(sZoom);
765 0 : pBox->SaveValue();
766 : }
767 0 : }
768 :
769 0 : Window* SwPreviewZoomControl::CreateItemWindow( Window *pParent )
770 : {
771 0 : SwZoomBox_Impl* pRet = new SwZoomBox_Impl( pParent, GetSlotId(), Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ));
772 0 : return pRet;
773 111 : }
774 :
775 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|