LCOV - code coverage report
Current view: top level - sw/source/core/uibase/utlui - unotools.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 292 0.0 %
Date: 2014-04-14 Functions: 0 19 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             : #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( Window& rWin,
      66             :                                         sal_uInt32 nFlags,
      67             :                                         const Link* pInitializedLink,
      68             :                                         const OUString* pURL ) :
      69             :     aTopWindow(&rWin, this),
      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->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 :     aLoadedTimer.SetTimeoutHdl(LINK(this, SwOneExampleFrame, TimeoutHdl));
      86           0 :     aLoadedTimer.SetTimeout(200);
      87             : 
      88           0 :     CreateControl();
      89             : 
      90           0 :     aTopWindow.Show();
      91           0 : }
      92             : 
      93           0 : void SwOneExampleFrame::CreateErrorMessage(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 :         InfoBox(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 :         sal_Bool bTrue = sal_True;
     143           0 :         pValues[0].Value.setValue(&bTrue, ::getBooleanCppuType());
     144           0 :         pValues[1].Name = "OpenFlags";
     145           0 :         pValues[1].Value <<= OUString("-RB");
     146           0 :         pValues[2].Name = "Referer";
     147           0 :         pValues[2].Value <<= OUString("private:user");
     148           0 :         uno::Any aArgs;
     149           0 :         aArgs.setValue(&aSeq, ::getCppuType((uno::Sequence<beans::PropertyValue>*)0));
     150             : 
     151           0 :         xPrSet->setPropertyValue( "LoaderArguments", aArgs );
     152             :         //save and set readonly???
     153             : 
     154           0 :         xPrSet->setPropertyValue("ComponentURL", aURL);
     155             : 
     156           0 :         aLoadedTimer.Start();
     157           0 :         bServiceAvailable = sal_True;
     158           0 :     }
     159             : }
     160             : 
     161           0 : void    SwOneExampleFrame::DisposeControl()
     162             : {
     163           0 :     _xCursor = 0;
     164           0 :     if(_xControl.is())
     165           0 :         _xControl->dispose();
     166           0 :     _xControl = 0;
     167           0 :     _xModel = 0;
     168           0 :     _xController = 0;
     169           0 : }
     170             : 
     171           0 : static void disableScrollBars(uno::Reference< beans::XPropertySet > xViewProps,
     172             :     bool bEnableOnlineMode)
     173             : {
     174             :     //the scrollbar logic is kind of busted looking in writer, when the hori scrollbar
     175             :     //property is changed then the hori scrollbar is enabled if the property is
     176             :     //true or browse (online) mode is enabled. So...
     177             :     //disable online mode
     178             :     //turn off scrollbars
     179             :     //turn back on online mode if that's what we want
     180             :     //which subverts the (dodgy/buggy) scrollbar setting
     181             : 
     182             :     //To reproduce this problem, in edit->autotext and click through
     183             :     //the examples and see if the preview gets a horizontal scrollbar
     184           0 :     uno::Any aFalseSet(uno::makeAny(sal_False));
     185           0 :     xViewProps->setPropertyValue(UNO_NAME_SHOW_ONLINE_LAYOUT, aFalseSet);
     186             : 
     187           0 :     xViewProps->setPropertyValue(UNO_NAME_SHOW_HORI_SCROLL_BAR, aFalseSet);
     188           0 :     xViewProps->setPropertyValue(UNO_NAME_SHOW_VERT_SCROLL_BAR, aFalseSet);
     189             : 
     190           0 :     if (bEnableOnlineMode)
     191             :     {
     192           0 :         xViewProps->setPropertyValue(UNO_NAME_SHOW_ONLINE_LAYOUT, uno::makeAny(sal_True));
     193           0 :     }
     194           0 : }
     195             : 
     196           0 : IMPL_LINK( SwOneExampleFrame, TimeoutHdl, Timer*, pTimer )
     197             : {
     198           0 :     if(!_xControl.is())
     199           0 :         return 0;
     200             : 
     201             :     // now get the model
     202           0 :     uno::Reference< beans::XPropertySet >  xPrSet(_xControl, uno::UNO_QUERY);
     203           0 :     uno::Any aFrame = xPrSet->getPropertyValue("Frame");
     204           0 :     uno::Reference< frame::XFrame >  xFrm;
     205           0 :     aFrame >>= xFrm;
     206             : 
     207           0 :     uno::Reference< beans::XPropertySet > xPropSet( xFrm, uno::UNO_QUERY );
     208           0 :     if ( xPropSet.is() )
     209             :     {
     210             :         try
     211             :         {
     212           0 :             uno::Reference< frame::XLayoutManager > xLayoutManager;
     213           0 :             uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
     214           0 :             aValue >>= xLayoutManager;
     215           0 :             if ( xLayoutManager.is() )
     216           0 :                 xLayoutManager->setVisible( sal_False );
     217             :         }
     218           0 :         catch (const uno::Exception&)
     219             :         {
     220             :         }
     221             :     }
     222             : 
     223           0 :     _xController = xFrm->getController();
     224           0 :     if(_xController.is())
     225             :     {
     226           0 :         _xModel = _xController->getModel();
     227             :         //now the ViewOptions should be set properly
     228           0 :         uno::Reference< view::XViewSettingsSupplier >  xSettings(_xController, uno::UNO_QUERY);
     229           0 :         uno::Reference< beans::XPropertySet >  xViewProps = xSettings->getViewSettings();
     230             : 
     231           0 :         sal_Bool bTrue = sal_True;
     232           0 :         sal_Bool bFalse = sal_False;
     233           0 :         uno::Any aTrueSet( &bTrue, ::getBooleanCppuType() );
     234           0 :         uno::Any aFalseSet( &bFalse, ::getBooleanCppuType() );
     235             : 
     236           0 :         if( !bIsInitialized )
     237             :         {
     238           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_BREAKS, aFalseSet);
     239           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_DRAWINGS, aTrueSet);
     240           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_FIELD_COMMANDS, aFalseSet);
     241           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_GRAPHICS, aTrueSet);
     242           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_HIDDEN_PARAGRAPHS, aFalseSet);
     243           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_HIDDEN_TEXT, aFalseSet);
     244           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_HORI_RULER, aFalseSet);
     245           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_PARA_BREAKS, aFalseSet);
     246           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_PROTECTED_SPACES, aFalseSet);
     247           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_SOFT_HYPHENS, aFalseSet);
     248           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_SPACES, aFalseSet);
     249           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_TABLES, aTrueSet);
     250           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_TABSTOPS, aFalseSet);
     251           0 :             xViewProps->setPropertyValue(UNO_NAME_SHOW_VERT_RULER, aFalseSet);
     252             : 
     253           0 :             if(0 ==(nStyleFlags&EX_SHOW_ONLINE_LAYOUT))
     254             :             {
     255           0 :                 uno::Any aZoom;
     256           0 :                 aZoom <<= (sal_Int16)view::DocumentZoomType::PAGE_WIDTH_EXACT;
     257           0 :                 xViewProps->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom);
     258             :             }
     259             :             else
     260             :             {
     261           0 :                 uno::Any aZoom;
     262           0 :                 aZoom <<= (sal_Int16)view::DocumentZoomType::BY_VALUE;
     263           0 :                 xViewProps->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom);
     264             : 
     265           0 :                 sal_Int16 nZoomValue = 50;
     266           0 :                 if(EX_SHOW_BUSINESS_CARDS == nStyleFlags)
     267             :                 {
     268           0 :                     nZoomValue = 80;
     269             :                 }
     270           0 :                 aZoom <<= nZoomValue;
     271           0 :                 xViewProps->setPropertyValue(UNO_NAME_ZOOM_VALUE, aZoom);
     272             :             }
     273             : 
     274             :             // set onlinelayout property after setting the zoom
     275           0 :             disableScrollBars(xViewProps, (nStyleFlags&EX_SHOW_ONLINE_LAYOUT) != 0);
     276           0 :             bIsInitialized = sal_True;
     277             :         }
     278             : 
     279           0 :         uno::Reference< text::XTextDocument >  xDoc(_xModel, uno::UNO_QUERY);
     280           0 :         uno::Reference< text::XText >  xText = xDoc->getText();
     281           0 :         _xCursor = xText->createTextCursor();
     282             : 
     283             :         //From here, a cursor is defined, which goes through the template,
     284             :         //and overwrites the template words where it is necessary.
     285             : 
     286           0 :         uno::Reference< lang::XUnoTunnel> xTunnel( _xCursor, uno::UNO_QUERY);
     287           0 :         if( xTunnel.is() )
     288             :         {
     289           0 :             OTextCursorHelper* pCrsr = reinterpret_cast<OTextCursorHelper*>( xTunnel->getSomething(
     290           0 :                                         OTextCursorHelper::getUnoTunnelId() ));
     291           0 :             if( pCrsr )
     292             :             {
     293           0 :                 SwEditShell* pSh = pCrsr->GetDoc()->GetEditShell();
     294             : 
     295           0 :                 do
     296             :                 {
     297           0 :                   if (pSh->GetCurWord() == "HEADING1")
     298             :                   {
     299           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_HEADING1));
     300             :                   }
     301           0 :                   else if (pSh->GetCurWord() == "ENTRY1")
     302             :                   {
     303           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_ENTRY1));
     304             :                   }
     305           0 :                   else if (pSh->GetCurWord() == "HEADING11")
     306             :                   {
     307           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_HEADING11));
     308             :                   }
     309           0 :                   else if (pSh->GetCurWord() == "ENTRY11")
     310             :                   {
     311           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_ENTRY11));
     312             :                   }
     313           0 :                   else if (pSh->GetCurWord() == "HEADING12")
     314             :                   {
     315           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_HEADING12));
     316             :                   }
     317           0 :                   else if (pSh->GetCurWord() == "ENTRY12")
     318             :                   {
     319           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_ENTRY12));
     320             :                   }
     321           0 :                   else if (pSh->GetCurWord() == "TABLE1")
     322             :                   {
     323           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_TABLE1));
     324             :                   }
     325           0 :                   else if (pSh->GetCurWord() == "IMAGE1")
     326             :                   {
     327           0 :                     pSh->Overwrite(SW_RESSTR(STR_IDXEXAMPLE_IDXTXT_IMAGE1));
     328             :                   }
     329             :                   else
     330             :                   {;}
     331             :                 }
     332           0 :                 while(pSh->Right(sal_uInt16(1), sal_uInt16(1), sal_True) == sal_True);
     333             :             }
     334             :         }
     335             : 
     336           0 :         uno::Reference< beans::XPropertySet >  xCrsrProp(_xCursor, uno::UNO_QUERY);
     337           0 :         uno::Any aPageStyle = xCrsrProp->getPropertyValue(UNO_NAME_PAGE_STYLE_NAME);
     338           0 :         OUString sPageStyle;
     339           0 :         aPageStyle >>= sPageStyle;
     340             : 
     341           0 :         uno::Reference< style::XStyleFamiliesSupplier >  xSSupp( xDoc, uno::UNO_QUERY);
     342           0 :         uno::Reference< container::XNameAccess >  xStyles = xSSupp->getStyleFamilies();
     343           0 :         uno::Any aPFamily = xStyles->getByName( "PageStyles" );
     344           0 :         uno::Reference< container::XNameContainer >  xPFamily;
     345             : 
     346           0 :         if( EX_SHOW_DEFAULT_PAGE != nStyleFlags
     347           0 :                 && (aPFamily >>= xPFamily) && !sPageStyle.isEmpty() )
     348             :         {
     349           0 :             uno::Any aPStyle = xPFamily->getByName( sPageStyle );
     350           0 :             uno::Reference< style::XStyle >  xPStyle;
     351           0 :             aPStyle >>= xPStyle;
     352           0 :             uno::Reference< beans::XPropertySet >  xPProp(xPStyle, uno::UNO_QUERY);
     353           0 :             uno::Any aSize = xPProp->getPropertyValue(UNO_NAME_SIZE);
     354           0 :             awt::Size aPSize;
     355           0 :             aSize >>= aPSize;
     356             :             //TODO: set page width to card width
     357           0 :             aPSize.Width = 10000;
     358           0 :             aSize.setValue(&aPSize, ::getCppuType((awt::Size*)0));
     359           0 :             xPProp->setPropertyValue(UNO_NAME_SIZE, aSize);
     360             : 
     361           0 :             uno::Any aZero; aZero <<= (sal_Int32)0;
     362           0 :             xPProp->setPropertyValue(UNO_NAME_LEFT_MARGIN, aZero);
     363           0 :             xPProp->setPropertyValue(UNO_NAME_RIGHT_MARGIN, aZero);
     364             :         }
     365             : 
     366           0 :         uno::Reference< awt::XWindow >  xWin( _xControl, uno::UNO_QUERY );
     367           0 :         Size aWinSize(aTopWindow.GetOutputSizePixel());
     368           0 :         xWin->setPosSize( 0, 0, aWinSize.Width(), aWinSize.Height(), awt::PosSize::SIZE );
     369             : 
     370             :         // can only be done here - the SFX changes the ScrollBar values
     371           0 :         disableScrollBars(xViewProps, (nStyleFlags&EX_SHOW_ONLINE_LAYOUT) != 0);
     372             : 
     373           0 :         if (aInitializedLink.IsSet())
     374           0 :             aInitializedLink.Call(this);
     375             : 
     376           0 :         uno::Reference< text::XTextViewCursorSupplier >  xCrsrSupp(_xController, uno::UNO_QUERY);
     377           0 :         uno::Reference< view::XScreenCursor >  xScrCrsr(xCrsrSupp->getViewCursor(), uno::UNO_QUERY);
     378           0 :         if(xScrCrsr.is())
     379           0 :             xScrCrsr->screenUp();
     380             : 
     381           0 :         xWin->setVisible( sal_True );
     382           0 :         aTopWindow.Show();
     383             : 
     384           0 :         if( xTunnel.is() )
     385             :         {
     386           0 :             OTextCursorHelper* pCrsr = reinterpret_cast<OTextCursorHelper*>( xTunnel->getSomething(
     387           0 :                                         OTextCursorHelper::getUnoTunnelId() ));
     388           0 :             if( pCrsr )
     389             :             {
     390           0 :                 SwEditShell* pSh = pCrsr->GetDoc()->GetEditShell();
     391           0 :                 if( pSh->ActionCount() )
     392             :                 {
     393           0 :                     pSh->EndAllAction();
     394           0 :                     pSh->UnlockPaint();
     395             :                 }
     396             :             }
     397             :         }
     398             : 
     399           0 :         SW_MOD()->SetView(pModuleView);
     400             :     }
     401             :     else
     402           0 :         pTimer->Start();
     403           0 :     return 0;
     404             : }
     405             : 
     406           0 : void SwOneExampleFrame::ClearDocument( sal_Bool bStartUpdateTimer )
     407             : {
     408           0 :     uno::Reference< lang::XUnoTunnel> xTunnel( _xCursor, uno::UNO_QUERY);
     409           0 :     if( xTunnel.is() )
     410             :     {
     411           0 :         OTextCursorHelper* pCrsr = reinterpret_cast<OTextCursorHelper*>(xTunnel->getSomething(
     412           0 :                                         OTextCursorHelper::getUnoTunnelId()) );
     413           0 :         if( pCrsr )
     414             :         {
     415           0 :             SwDoc* pDoc = pCrsr->GetDoc();
     416           0 :             SwEditShell* pSh = pDoc->GetEditShell();
     417           0 :             pSh->LockPaint();
     418           0 :             pSh->StartAllAction();
     419           0 :             pDoc->ClearDoc();
     420             : 
     421           0 :             if( aLoadedTimer.IsActive() || !bStartUpdateTimer )
     422             :             {
     423           0 :                 pSh->EndAllAction();
     424           0 :                 pSh->UnlockPaint();
     425             :             }
     426           0 :             if( bStartUpdateTimer )
     427           0 :                 aLoadedTimer.Start();
     428             :         }
     429             :         else
     430             :         {
     431           0 :             _xCursor->gotoStart(sal_False);
     432           0 :             _xCursor->gotoEnd(sal_True);
     433           0 :             _xCursor->setString(OUString());
     434             :         }
     435           0 :     }
     436           0 : }
     437             : 
     438             : static const sal_Int16 nZoomValues[] =
     439             : {
     440             :     20,
     441             :     40,
     442             :     50,
     443             :     75,
     444             :     100
     445             : };
     446             : 
     447             : #define ITEM_UP     100
     448             : #define ITEM_DOWN   200
     449             : #define ITEM_ZOOM   300
     450             : 
     451           0 : void SwOneExampleFrame::CreatePopup(const Point& rPt)
     452             : {
     453           0 :     PopupMenu aPop;
     454           0 :     PopupMenu aSubPop1;
     455           0 :     ResStringArray& rArr = aMenuRes.GetMenuArray();
     456             : 
     457           0 :     aPop.InsertItem(ITEM_UP,   rArr.GetString(rArr.FindIndex(ST_MENU_UP )));
     458           0 :     aPop.InsertItem(ITEM_DOWN, rArr.GetString(rArr.FindIndex(ST_MENU_DOWN )));
     459             : 
     460           0 :     Link aSelLk = LINK(this, SwOneExampleFrame, PopupHdl );
     461           0 :     aPop.SetSelectHdl(aSelLk);
     462           0 :     if(EX_SHOW_ONLINE_LAYOUT == nStyleFlags)
     463             :     {
     464           0 :         aPop.InsertItem(ITEM_ZOOM, rArr.GetString(rArr.FindIndex(ST_MENU_ZOOM   )));
     465             : 
     466           0 :         uno::Reference< view::XViewSettingsSupplier >  xSettings(_xController, uno::UNO_QUERY);
     467           0 :         uno::Reference< beans::XPropertySet >  xViewProps = xSettings->getViewSettings();
     468             : 
     469           0 :         uno::Any aZoom = xViewProps->getPropertyValue(UNO_NAME_ZOOM_VALUE);
     470           0 :         sal_Int16 nZoom = 0;
     471           0 :         aZoom >>= nZoom;
     472             : 
     473           0 :         for (sal_uInt16 i = 0;
     474           0 :                 i < (sizeof(nZoomValues)/sizeof(nZoomValues[0])); ++i)
     475             :         {
     476           0 :             OUString sTemp = unicode::formatPercent(nZoomValues[i],
     477           0 :                 Application::GetSettings().GetUILanguageTag());
     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(UNO_NAME_ZOOM_VALUE, aZoom);
     502           0 :         aZoom <<= (sal_Int16)view::DocumentZoomType::BY_VALUE;
     503           0 :         xViewProps->setPropertyValue(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           0 : }
     561             : 
     562             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10