LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/utlui - unotools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 279 0.0 %
Date: 2012-12-17 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10