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 <swtypes.hxx>
21 : #include <globals.hrc>
22 : #include <misc.hrc>
23 :
24 : #include <utlui.hrc>
25 : #include <unotools.hrc>
26 : #include <unotools.hxx>
27 : #include <unoprnms.hxx>
28 : #include <i18nutil/unicode.hxx>
29 : #include <osl/diagnose.h>
30 : #include <vcl/msgbox.hxx>
31 : #include <vcl/svapp.hxx>
32 : #include <vcl/settings.hxx>
33 : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
34 : #include <com/sun/star/view/XScreenCursor.hpp>
35 : #include <com/sun/star/view/DocumentZoomType.hpp>
36 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
37 : #include <com/sun/star/style/XStyle.hpp>
38 : #include <com/sun/star/text/XTextDocument.hpp>
39 : #include <com/sun/star/awt/Toolkit.hpp>
40 : #include <com/sun/star/awt/PosSize.hpp>
41 : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
42 : #include <com/sun/star/container/XNameContainer.hpp>
43 : #include <com/sun/star/frame/XLayoutManager.hpp>
44 : #include <comphelper/processfactory.hxx>
45 : #include <sfx2/dispatch.hxx>
46 : #include <svl/stritem.hxx>
47 : #include <shellio.hxx>
48 : #include <docsh.hxx>
49 : #include <view.hxx>
50 : #include <wrtsh.hxx>
51 : #include <swmodule.hxx>
52 : #include <TextCursorHelper.hxx>
53 : #include <unocrsr.hxx>
54 : #include <doc.hxx>
55 :
56 : #include <unomid.h>
57 :
58 : using namespace ::com::sun::star;
59 :
60 : const sal_Char cFrameControl[] = "com.sun.star.frame.FrameControl";
61 : const sal_Char cFactory[] = "private:factory/swriter";
62 :
63 : bool SwOneExampleFrame::bShowServiceNotAvailableMessage = true;
64 :
65 0 : SwOneExampleFrame::SwOneExampleFrame( vcl::Window& rWin,
66 : sal_uInt32 nFlags,
67 : const Link<>* pInitializedLink,
68 : const OUString* pURL ) :
69 : aTopWindow(VclPtr<SwFrmCtrlWindow>::Create(&rWin, this)),
70 : aMenuRes(SW_RES(RES_FRMEX_MENU)),
71 0 : pModuleView(SW_MOD()->GetView()),
72 : nStyleFlags(nFlags),
73 : bIsInitialized(false),
74 0 : bServiceAvailable(false)
75 : {
76 0 : if (pURL && !pURL->isEmpty())
77 0 : sArgumentURL = *pURL;
78 :
79 0 : aTopWindow->SetPosSizePixel(Point(0, 0), rWin.GetSizePixel());
80 :
81 0 : if( pInitializedLink )
82 0 : aInitializedLink = *pInitializedLink;
83 :
84 : // the controller is asynchronously set
85 0 : aLoadedIdle.SetIdleHdl(LINK(this, SwOneExampleFrame, TimeoutHdl));
86 0 : aLoadedIdle.SetPriority(SchedulerPriority::LOWER);
87 :
88 0 : CreateControl();
89 :
90 0 : aTopWindow->Show();
91 0 : }
92 :
93 0 : void SwOneExampleFrame::CreateErrorMessage(vcl::Window* pParent)
94 : {
95 0 : if(SwOneExampleFrame::bShowServiceNotAvailableMessage)
96 : {
97 0 : OUString sInfo(SW_RES(STR_SERVICE_UNAVAILABLE));
98 0 : sInfo += OUString(cFrameControl);
99 0 : ScopedVclPtr<InfoBox>::Create(pParent, sInfo)->Execute();
100 0 : SwOneExampleFrame::bShowServiceNotAvailableMessage = false;
101 : }
102 0 : }
103 :
104 0 : SwOneExampleFrame::~SwOneExampleFrame()
105 : {
106 0 : DisposeControl();
107 0 : }
108 :
109 0 : void SwOneExampleFrame::CreateControl()
110 : {
111 0 : if(_xControl.is())
112 0 : return ;
113 : uno::Reference< lang::XMultiServiceFactory >
114 0 : xMgr = comphelper::getProcessServiceFactory();
115 0 : uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
116 0 : uno::Reference< uno::XInterface > xInst = xMgr->createInstance( "com.sun.star.frame.FrameControl" );
117 0 : _xControl = uno::Reference< awt::XControl >(xInst, uno::UNO_QUERY);
118 0 : if(_xControl.is())
119 : {
120 0 : uno::Reference< awt::XWindowPeer > xParent( aTopWindow->GetComponentInterface() );
121 :
122 0 : uno::Reference< awt::XToolkit > xToolkit( awt::Toolkit::create(xContext), uno::UNO_QUERY_THROW );
123 :
124 0 : _xControl->createPeer( xToolkit, xParent );
125 :
126 0 : uno::Reference< awt::XWindow > xWin( _xControl, uno::UNO_QUERY );
127 0 : xWin->setVisible(sal_False);
128 0 : Size aWinSize(aTopWindow->GetOutputSizePixel());
129 0 : xWin->setPosSize( 0, 0, aWinSize.Width(), aWinSize.Height(), awt::PosSize::SIZE );
130 :
131 0 : uno::Reference< beans::XPropertySet > xPrSet(xInst, uno::UNO_QUERY);
132 0 : uno::Any aURL;
133 : // create new doc
134 0 : OUString sTempURL(cFactory);
135 0 : if(!sArgumentURL.isEmpty())
136 0 : sTempURL = sArgumentURL;
137 0 : aURL <<= sTempURL;
138 :
139 0 : uno::Sequence<beans::PropertyValue> aSeq(3);
140 0 : beans::PropertyValue* pValues = aSeq.getArray();
141 0 : pValues[0].Name = "ReadOnly";
142 0 : pValues[0].Value <<= true;
143 0 : pValues[1].Name = "OpenFlags";
144 0 : pValues[1].Value <<= OUString("-RB");
145 0 : pValues[2].Name = "Referer";
146 0 : pValues[2].Value <<= OUString("private:user");
147 0 : uno::Any aArgs;
148 0 : aArgs.setValue(&aSeq, cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get());
149 :
150 0 : xPrSet->setPropertyValue( "LoaderArguments", aArgs );
151 : //save and set readonly???
152 :
153 0 : xPrSet->setPropertyValue("ComponentURL", aURL);
154 :
155 0 : aLoadedIdle.Start();
156 0 : bServiceAvailable = true;
157 0 : }
158 : }
159 :
160 0 : void SwOneExampleFrame::DisposeControl()
161 : {
162 0 : _xCursor = 0;
163 0 : if(_xControl.is())
164 0 : _xControl->dispose();
165 0 : _xControl = 0;
166 0 : _xModel = 0;
167 0 : _xController = 0;
168 0 : }
169 :
170 0 : static void disableScrollBars(uno::Reference< beans::XPropertySet > xViewProps,
171 : bool bEnableOnlineMode)
172 : {
173 : //the scrollbar logic is kind of busted looking in writer, when the hori scrollbar
174 : //property is changed then the hori scrollbar is enabled if the property is
175 : //true or browse (online) mode is enabled. So...
176 : //disable online mode
177 : //turn off scrollbars
178 : //turn back on online mode if that's what we want
179 : //which subverts the (dodgy/buggy) scrollbar setting
180 :
181 : //To reproduce this problem, in edit->autotext and click through
182 : //the examples and see if the preview gets a horizontal scrollbar
183 0 : uno::Any aFalseSet(uno::makeAny(false));
184 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_ONLINE_LAYOUT, aFalseSet);
185 :
186 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_HORI_SCROLL_BAR, aFalseSet);
187 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_VERT_SCROLL_BAR, aFalseSet);
188 :
189 0 : if (bEnableOnlineMode)
190 : {
191 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_ONLINE_LAYOUT, uno::makeAny(true));
192 0 : }
193 0 : }
194 :
195 0 : IMPL_LINK_TYPED( SwOneExampleFrame, TimeoutHdl, Idle*, pTimer, void )
196 : {
197 0 : if(!_xControl.is())
198 0 : return;
199 :
200 : // now get the model
201 0 : uno::Reference< beans::XPropertySet > xPrSet(_xControl, uno::UNO_QUERY);
202 0 : uno::Any aFrame = xPrSet->getPropertyValue("Frame");
203 0 : uno::Reference< frame::XFrame > xFrm;
204 0 : aFrame >>= xFrm;
205 :
206 0 : uno::Reference< beans::XPropertySet > xPropSet( xFrm, uno::UNO_QUERY );
207 0 : if ( xPropSet.is() )
208 : {
209 : try
210 : {
211 0 : uno::Reference< frame::XLayoutManager > xLayoutManager;
212 0 : uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
213 0 : aValue >>= xLayoutManager;
214 0 : if ( xLayoutManager.is() )
215 0 : xLayoutManager->setVisible( sal_False );
216 : }
217 0 : catch (const uno::Exception&)
218 : {
219 : }
220 : }
221 :
222 0 : _xController = xFrm->getController();
223 0 : if(_xController.is())
224 : {
225 0 : _xModel = _xController->getModel();
226 : //now the ViewOptions should be set properly
227 0 : uno::Reference< view::XViewSettingsSupplier > xSettings(_xController, uno::UNO_QUERY);
228 0 : uno::Reference< beans::XPropertySet > xViewProps = xSettings->getViewSettings();
229 :
230 0 : const uno::Any aTrueSet( true );
231 0 : const uno::Any aFalseSet( false );
232 :
233 0 : if( !bIsInitialized )
234 : {
235 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_BREAKS, aFalseSet);
236 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_DRAWINGS, aTrueSet);
237 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_FIELD_COMMANDS, aFalseSet);
238 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_GRAPHICS, aTrueSet);
239 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_HIDDEN_PARAGRAPHS, aFalseSet);
240 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_HIDDEN_TEXT, aFalseSet);
241 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_HORI_RULER, aFalseSet);
242 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_PARA_BREAKS, aFalseSet);
243 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_PROTECTED_SPACES, aFalseSet);
244 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_SOFT_HYPHENS, aFalseSet);
245 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_SPACES, aFalseSet);
246 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_TABLES, aTrueSet);
247 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_TABSTOPS, aFalseSet);
248 0 : xViewProps->setPropertyValue(UNO_NAME_SHOW_VERT_RULER, aFalseSet);
249 :
250 0 : if(0 ==(nStyleFlags&EX_SHOW_ONLINE_LAYOUT))
251 : {
252 0 : uno::Any aZoom;
253 0 : aZoom <<= (sal_Int16)view::DocumentZoomType::PAGE_WIDTH_EXACT;
254 0 : xViewProps->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom);
255 : }
256 : else
257 : {
258 0 : uno::Any aZoom;
259 0 : aZoom <<= (sal_Int16)view::DocumentZoomType::BY_VALUE;
260 0 : xViewProps->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom);
261 :
262 0 : sal_Int16 nZoomValue = 50;
263 0 : if(EX_SHOW_BUSINESS_CARDS == nStyleFlags)
264 : {
265 0 : nZoomValue = 80;
266 : }
267 0 : aZoom <<= nZoomValue;
268 0 : xViewProps->setPropertyValue(UNO_NAME_ZOOM_VALUE, aZoom);
269 : }
270 :
271 : // set onlinelayout property after setting the zoom
272 0 : disableScrollBars(xViewProps, (nStyleFlags&EX_SHOW_ONLINE_LAYOUT) != 0);
273 0 : bIsInitialized = true;
274 : }
275 :
276 0 : uno::Reference< text::XTextDocument > xDoc(_xModel, uno::UNO_QUERY);
277 0 : uno::Reference< text::XText > xText = xDoc->getText();
278 0 : _xCursor = xText->createTextCursor();
279 :
280 : //From here, a cursor is defined, which goes through the template,
281 : //and overwrites the template words where it is necessary.
282 :
283 0 : uno::Reference< lang::XUnoTunnel> xTunnel( _xCursor, uno::UNO_QUERY);
284 0 : if( xTunnel.is() )
285 : {
286 0 : OTextCursorHelper* pCrsr = reinterpret_cast<OTextCursorHelper*>( xTunnel->getSomething(
287 0 : OTextCursorHelper::getUnoTunnelId() ));
288 0 : if( pCrsr )
289 : {
290 0 : SwEditShell* pSh = pCrsr->GetDoc()->GetEditShell();
291 :
292 0 : do
293 : {
294 0 : if (pSh->GetCurWord() == "HEADING1")
295 : {
296 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_HEADING1));
297 : }
298 0 : else if (pSh->GetCurWord() == "ENTRY1")
299 : {
300 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_ENTRY1));
301 : }
302 0 : else if (pSh->GetCurWord() == "HEADING11")
303 : {
304 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_HEADING11));
305 : }
306 0 : else if (pSh->GetCurWord() == "ENTRY11")
307 : {
308 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_ENTRY11));
309 : }
310 0 : else if (pSh->GetCurWord() == "HEADING12")
311 : {
312 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_HEADING12));
313 : }
314 0 : else if (pSh->GetCurWord() == "ENTRY12")
315 : {
316 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_ENTRY12));
317 : }
318 0 : else if (pSh->GetCurWord() == "TABLE1")
319 : {
320 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_TABLE1));
321 : }
322 0 : else if (pSh->GetCurWord() == "IMAGE1")
323 : {
324 0 : pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_IMAGE1));
325 : }
326 : else
327 : {;}
328 : }
329 0 : while(pSh->Right(sal_uInt16(1), sal_uInt16(1), true));
330 : }
331 : }
332 :
333 0 : uno::Reference< beans::XPropertySet > xCrsrProp(_xCursor, uno::UNO_QUERY);
334 0 : uno::Any aPageStyle = xCrsrProp->getPropertyValue(UNO_NAME_PAGE_STYLE_NAME);
335 0 : OUString sPageStyle;
336 0 : aPageStyle >>= sPageStyle;
337 :
338 0 : uno::Reference< style::XStyleFamiliesSupplier > xSSupp( xDoc, uno::UNO_QUERY);
339 0 : uno::Reference< container::XNameAccess > xStyles = xSSupp->getStyleFamilies();
340 0 : uno::Any aPFamily = xStyles->getByName( "PageStyles" );
341 0 : uno::Reference< container::XNameContainer > xPFamily;
342 :
343 0 : if( EX_SHOW_DEFAULT_PAGE != nStyleFlags
344 0 : && (aPFamily >>= xPFamily) && !sPageStyle.isEmpty() )
345 : {
346 0 : uno::Any aPStyle = xPFamily->getByName( sPageStyle );
347 0 : uno::Reference< style::XStyle > xPStyle;
348 0 : aPStyle >>= xPStyle;
349 0 : uno::Reference< beans::XPropertySet > xPProp(xPStyle, uno::UNO_QUERY);
350 0 : uno::Any aSize = xPProp->getPropertyValue(UNO_NAME_SIZE);
351 0 : awt::Size aPSize;
352 0 : aSize >>= aPSize;
353 : //TODO: set page width to card width
354 0 : aPSize.Width = 10000;
355 0 : aSize.setValue(&aPSize, ::cppu::UnoType<awt::Size>::get());
356 0 : xPProp->setPropertyValue(UNO_NAME_SIZE, aSize);
357 :
358 0 : uno::Any aZero; aZero <<= (sal_Int32)0;
359 0 : xPProp->setPropertyValue(UNO_NAME_LEFT_MARGIN, aZero);
360 0 : xPProp->setPropertyValue(UNO_NAME_RIGHT_MARGIN, aZero);
361 : }
362 :
363 0 : uno::Reference< awt::XWindow > xWin( _xControl, uno::UNO_QUERY );
364 0 : Size aWinSize(aTopWindow->GetOutputSizePixel());
365 0 : xWin->setPosSize( 0, 0, aWinSize.Width(), aWinSize.Height(), awt::PosSize::SIZE );
366 :
367 : // can only be done here - the SFX changes the ScrollBar values
368 0 : disableScrollBars(xViewProps, (nStyleFlags&EX_SHOW_ONLINE_LAYOUT) != 0);
369 :
370 0 : if (aInitializedLink.IsSet())
371 0 : aInitializedLink.Call(this);
372 :
373 0 : uno::Reference< text::XTextViewCursorSupplier > xCrsrSupp(_xController, uno::UNO_QUERY);
374 0 : uno::Reference< view::XScreenCursor > xScrCrsr(xCrsrSupp->getViewCursor(), uno::UNO_QUERY);
375 0 : if(xScrCrsr.is())
376 0 : xScrCrsr->screenUp();
377 :
378 0 : xWin->setVisible( sal_True );
379 0 : aTopWindow->Show();
380 :
381 0 : if( xTunnel.is() )
382 : {
383 0 : OTextCursorHelper* pCrsr = reinterpret_cast<OTextCursorHelper*>( xTunnel->getSomething(
384 0 : OTextCursorHelper::getUnoTunnelId() ));
385 0 : if( pCrsr )
386 : {
387 0 : SwEditShell* pSh = pCrsr->GetDoc()->GetEditShell();
388 0 : if( pSh->ActionCount() )
389 : {
390 0 : pSh->EndAllAction();
391 0 : pSh->UnlockPaint();
392 : }
393 : }
394 : }
395 :
396 0 : SW_MOD()->SetView(pModuleView);
397 : }
398 : else
399 0 : pTimer->Start();
400 : }
401 :
402 0 : void SwOneExampleFrame::ClearDocument( bool bStartUpdateTimer )
403 : {
404 0 : uno::Reference< lang::XUnoTunnel> xTunnel( _xCursor, uno::UNO_QUERY);
405 0 : if( xTunnel.is() )
406 : {
407 0 : OTextCursorHelper* pCrsr = reinterpret_cast<OTextCursorHelper*>(xTunnel->getSomething(
408 0 : OTextCursorHelper::getUnoTunnelId()) );
409 0 : if( pCrsr )
410 : {
411 0 : SwDoc* pDoc = pCrsr->GetDoc();
412 0 : SwEditShell* pSh = pDoc->GetEditShell();
413 0 : pSh->LockPaint();
414 0 : pSh->StartAllAction();
415 0 : pSh->KillPams();
416 0 : pSh->ClearMark();
417 0 : pDoc->ClearDoc();
418 0 : pSh->ClearUpCrsrs();
419 :
420 0 : if( aLoadedIdle.IsActive() || !bStartUpdateTimer )
421 : {
422 0 : pSh->EndAllAction();
423 0 : pSh->UnlockPaint();
424 : }
425 0 : if( bStartUpdateTimer )
426 0 : aLoadedIdle.Start();
427 : }
428 : else
429 : {
430 0 : _xCursor->gotoStart(sal_False);
431 0 : _xCursor->gotoEnd(sal_True);
432 0 : _xCursor->setString(OUString());
433 : }
434 0 : }
435 0 : }
436 :
437 : static const sal_Int16 nZoomValues[] =
438 : {
439 : 20,
440 : 40,
441 : 50,
442 : 75,
443 : 100
444 : };
445 :
446 : #define ITEM_UP 100
447 : #define ITEM_DOWN 200
448 : #define ITEM_ZOOM 300
449 :
450 0 : void SwOneExampleFrame::CreatePopup(const Point& rPt)
451 : {
452 0 : PopupMenu aPop;
453 0 : PopupMenu aSubPop1;
454 0 : ResStringArray& rArr = aMenuRes.GetMenuArray();
455 :
456 0 : aPop.InsertItem(ITEM_UP, rArr.GetString(rArr.FindIndex(ST_MENU_UP )));
457 0 : aPop.InsertItem(ITEM_DOWN, rArr.GetString(rArr.FindIndex(ST_MENU_DOWN )));
458 :
459 0 : Link<> aSelLk = LINK(this, SwOneExampleFrame, PopupHdl );
460 0 : aPop.SetSelectHdl(aSelLk);
461 0 : if(EX_SHOW_ONLINE_LAYOUT == nStyleFlags)
462 : {
463 0 : aPop.InsertItem(ITEM_ZOOM, rArr.GetString(rArr.FindIndex(ST_MENU_ZOOM )));
464 :
465 0 : uno::Reference< view::XViewSettingsSupplier > xSettings(_xController, uno::UNO_QUERY);
466 0 : uno::Reference< beans::XPropertySet > xViewProps = xSettings->getViewSettings();
467 :
468 0 : uno::Any aZoom = xViewProps->getPropertyValue(UNO_NAME_ZOOM_VALUE);
469 0 : sal_Int16 nZoom = 0;
470 0 : aZoom >>= nZoom;
471 :
472 0 : for (sal_uInt16 i = 0;
473 0 : i < (sizeof(nZoomValues)/sizeof(nZoomValues[0])); ++i)
474 : {
475 0 : OUString sTemp = unicode::formatPercent(nZoomValues[i],
476 0 : Application::GetSettings().GetUILanguageTag());
477 0 : aSubPop1.InsertItem( ITEM_ZOOM + i + 1, sTemp);
478 0 : if(nZoom == nZoomValues[i])
479 0 : aSubPop1.CheckItem(ITEM_ZOOM + i + 1);
480 0 : }
481 0 : aPop.SetPopupMenu( ITEM_ZOOM, &aSubPop1 );
482 0 : aSubPop1.SetSelectHdl(aSelLk);
483 : }
484 0 : aPop.Execute( aTopWindow.get(), rPt );
485 :
486 0 : }
487 :
488 0 : IMPL_LINK(SwOneExampleFrame, PopupHdl, Menu*, pMenu )
489 : {
490 0 : sal_uInt16 nId = pMenu->GetCurItemId();
491 0 : if ((nId > ITEM_ZOOM) &&
492 0 : (nId <= (ITEM_ZOOM + (sizeof(nZoomValues)/sizeof(nZoomValues[0])))))
493 : {
494 0 : sal_Int16 nZoom = nZoomValues[nId - ITEM_ZOOM - 1];
495 0 : uno::Reference< view::XViewSettingsSupplier > xSettings(_xController, uno::UNO_QUERY);
496 0 : uno::Reference< beans::XPropertySet > xViewProps = xSettings->getViewSettings();
497 :
498 0 : uno::Any aZoom;
499 0 : aZoom <<= nZoom;
500 0 : xViewProps->setPropertyValue(UNO_NAME_ZOOM_VALUE, aZoom);
501 0 : aZoom <<= (sal_Int16)view::DocumentZoomType::BY_VALUE;
502 0 : xViewProps->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom);
503 : }
504 0 : else if(ITEM_UP == nId || ITEM_DOWN == nId)
505 : {
506 0 : uno::Reference< text::XTextViewCursorSupplier > xCrsrSupp(_xController, uno::UNO_QUERY);
507 0 : uno::Reference< view::XScreenCursor > xScrCrsr(xCrsrSupp->getViewCursor(), uno::UNO_QUERY);
508 0 : if(ITEM_UP == nId)
509 0 : xScrCrsr->screenUp();
510 : else
511 0 : xScrCrsr->screenDown();
512 : }
513 0 : return 0;
514 : };
515 :
516 0 : SwFrmCtrlWindow::SwFrmCtrlWindow(vcl::Window* pParent, SwOneExampleFrame* pFrame)
517 : : VclEventBox(pParent)
518 0 : , pExampleFrame(pFrame)
519 : {
520 0 : set_expand(true);
521 0 : set_fill(true);
522 0 : }
523 :
524 0 : void SwFrmCtrlWindow::Command( const CommandEvent& rCEvt )
525 : {
526 0 : switch ( rCEvt.GetCommand() )
527 : {
528 : case CommandEventId::ContextMenu:
529 : {
530 : //#125881# quickly clicking crashes because the control is not fully initialized
531 0 : if(pExampleFrame->GetController().is())
532 0 : pExampleFrame->CreatePopup(rCEvt.GetMousePosPixel());
533 : }
534 0 : break;
535 : case CommandEventId::Wheel:
536 : case CommandEventId::StartAutoScroll:
537 : case CommandEventId::AutoScroll:
538 0 : break;
539 : default:;
540 : }
541 0 : }
542 :
543 0 : Size SwFrmCtrlWindow::GetOptimalSize() const
544 : {
545 0 : return LogicToPixel(Size(82, 124), MapMode(MAP_APPFONT));
546 : }
547 :
548 0 : void SwFrmCtrlWindow::Resize()
549 : {
550 0 : VclEventBox::Resize();
551 0 : pExampleFrame->ClearDocument(true);
552 0 : }
553 :
554 0 : MenuResource::MenuResource(const ResId& rResId) :
555 : Resource(rResId),
556 0 : aMenuArray(ResId(1,*rResId.GetResMgr()))
557 : {
558 0 : FreeResource();
559 177 : }
560 :
561 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|