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