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