LCOV - code coverage report
Current view: top level - starmath/source - view.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 350 1048 33.4 %
Date: 2014-04-11 Functions: 66 103 64.1 %
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 <com/sun/star/accessibility/AccessibleEventId.hpp>
      21             : #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
      22             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      23             : #include <com/sun/star/accessibility/XAccessible.hpp>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/frame/Desktop.hpp>
      26             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      27             : #include <com/sun/star/container/XChild.hpp>
      28             : 
      29             : #include <comphelper/processfactory.hxx>
      30             : #include <comphelper/storagehelper.hxx>
      31             : #include <comphelper/string.hxx>
      32             : #include <sfx2/app.hxx>
      33             : #include <sfx2/dispatch.hxx>
      34             : #include <sfx2/docfile.hxx>
      35             : #include <sfx2/docfilt.hxx>
      36             : #include <sfx2/docinsert.hxx>
      37             : #include <sfx2/filedlghelper.hxx>
      38             : #include <sfx2/msg.hxx>
      39             : #include <sfx2/objface.hxx>
      40             : #include <sfx2/printer.hxx>
      41             : #include <sfx2/request.hxx>
      42             : #include <svl/eitem.hxx>
      43             : #include <svl/intitem.hxx>
      44             : #include <svl/itemset.hxx>
      45             : #include <svl/poolitem.hxx>
      46             : #include <svl/ptitem.hxx>
      47             : #include <svl/stritem.hxx>
      48             : #include <svtools/transfer.hxx>
      49             : #include <svtools/miscopt.hxx>
      50             : #include <svl/undo.hxx>
      51             : #include <svl/whiter.hxx>
      52             : #include <svx/dialogs.hrc>
      53             : #include <svx/zoomslideritem.hxx>
      54             : #include <editeng/editeng.hxx>
      55             : #include <svx/svxdlg.hxx>
      56             : #include <sfx2/zoomitem.hxx>
      57             : #include <vcl/decoview.hxx>
      58             : #include <vcl/menu.hxx>
      59             : #include <vcl/msgbox.hxx>
      60             : #include <vcl/wrkwin.hxx>
      61             : #include <vcl/settings.hxx>
      62             : 
      63             : #include <fstream>
      64             : 
      65             : #include "unomodel.hxx"
      66             : #include "view.hxx"
      67             : #include "config.hxx"
      68             : #include "dialog.hxx"
      69             : #include "document.hxx"
      70             : #include "starmath.hrc"
      71             : #include "toolbox.hxx"
      72             : #include "mathmlimport.hxx"
      73             : #include "cursor.hxx"
      74             : #include "accessibility.hxx"
      75             : #include "ElementsDockingWindow.hxx"
      76             : 
      77             : #define MINZOOM         25
      78             : #define MAXZOOM         800
      79             : 
      80             : // space around the edit window, in pixels
      81             : // fdo#69111: Increased border on the top so that the window is
      82             : // easier to tear off.
      83             : #define CMD_BOX_PADDING 4
      84             : #define CMD_BOX_PADDING_TOP 10
      85             : 
      86             : #define SmViewShell
      87             : #include "smslots.hxx"
      88             : 
      89             : using namespace com::sun::star;
      90             : using namespace com::sun::star::accessibility;
      91             : using namespace com::sun::star::uno;
      92             : 
      93             : 
      94             : 
      95          21 : SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell):
      96          21 :     ScrollableWindow(&pShell->GetViewFrame()->GetWindow(), 0),
      97             :     pAccessible(0),
      98             :     pViewShell(pShell),
      99          21 :     nZoom(100)
     100             : {
     101             :     // docking windows are usually hidden (often already done in the
     102             :     // resource) and will be shown by the sfx framework.
     103          21 :     Hide();
     104             : 
     105          21 :     const Fraction aFraction (1,1);
     106          21 :     SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction));
     107             : 
     108          21 :     ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
     109             : 
     110          21 :     SetTotalSize();
     111             : 
     112          21 :     SetHelpId(HID_SMA_WIN_DOCUMENT);
     113          21 :     SetUniqueId(HID_SMA_WIN_DOCUMENT);
     114             : 
     115          21 :     ShowLine(false);
     116          21 :     CaretBlinkInit();
     117          21 : }
     118             : 
     119          34 : SmGraphicWindow::~SmGraphicWindow()
     120             : {
     121          17 :     if (pAccessible)
     122           3 :         pAccessible->ClearWin();    // make Accessible defunctional
     123             :     // Note: memory for pAccessible will be freed when the reference
     124             :     // xAccessible is released.
     125          17 :     CaretBlinkStop();
     126          17 : }
     127             : 
     128          59 : void SmGraphicWindow::StateChanged( StateChangedType eType )
     129             : {
     130          59 :     if ( eType == STATE_CHANGE_INITSHOW )
     131          17 :         Show();
     132          59 :     ScrollableWindow::StateChanged( eType );
     133          59 : }
     134             : 
     135             : 
     136          21 : void SmGraphicWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
     137             : {
     138             :     // Note: SetTextColor not necessary since the nodes that
     139             :     // get painted have the color information.
     140             : #if OSL_DEBUG_LEVEL > 1
     141             : //   ColorData nVal = rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor;
     142             : #endif
     143          21 :     SetBackground( Color( (ColorData) rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor ) );
     144          21 :     Invalidate();
     145          21 : }
     146             : 
     147             : 
     148           0 : void SmGraphicWindow::DataChanged( const DataChangedEvent& rEvt )
     149             : {
     150           0 :     ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
     151             : 
     152           0 :     ScrollableWindow::DataChanged( rEvt );
     153           0 : }
     154             : 
     155             : 
     156           0 : void SmGraphicWindow::MouseButtonDown(const MouseEvent& rMEvt)
     157             : {
     158           0 :     ScrollableWindow::MouseButtonDown(rMEvt);
     159             : 
     160           0 :     GrabFocus();
     161             : 
     162             : 
     163             :     // set formula-cursor and selection of edit window according to the
     164             :     // position clicked at
     165             : 
     166             :     SAL_WARN_IF( rMEvt.GetClicks() == 0, "starmath", "0 clicks" );
     167           0 :     if ( rMEvt.IsLeft() )
     168             :     {
     169             :         // get click position relativ to formula
     170           0 :         Point  aPos (PixelToLogic(rMEvt.GetPosPixel())
     171           0 :                      - GetFormulaDrawPos());
     172             : 
     173           0 :         const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
     174           0 :         if (!pTree)
     175           0 :             return;
     176             : 
     177           0 :         if (IsInlineEditEnabled()) {
     178           0 :             pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, !rMEvt.IsShift());
     179           0 :             return;
     180             :         }
     181           0 :         const SmNode *pNode = 0;
     182             :         // if it was clicked inside the formula then get the appropriate node
     183           0 :         if (pTree->OrientedDist(aPos) <= 0)
     184           0 :             pNode = pTree->FindRectClosestTo(aPos);
     185             : 
     186           0 :         if (pNode)
     187           0 :         {   SmEditWindow  *pEdit = pViewShell->GetEditWindow();
     188           0 :             if (!pEdit)
     189           0 :                 return;
     190           0 :             const SmToken  aToken (pNode->GetToken());
     191             : 
     192             :             // set selection to the beginning of the token
     193           0 :             ESelection  aSel (aToken.nRow - 1, aToken.nCol - 1);
     194             : 
     195           0 :             if (rMEvt.GetClicks() != 1 || aToken.eType == TPLACE)
     196           0 :                 aSel.nEndPos = aSel.nEndPos + sal::static_int_cast< sal_uInt16 >(aToken.aText.getLength());
     197             : 
     198           0 :             pEdit->SetSelection(aSel);
     199           0 :             SetCursor(pNode);
     200             : 
     201             :             // allow for immediate editing and
     202             :             //! implicitly synchronize the cursor position mark in this window
     203           0 :             pEdit->GrabFocus();
     204             :         }
     205             :     }
     206             : }
     207             : 
     208           0 : void SmGraphicWindow::MouseMove(const MouseEvent &rMEvt)
     209             : {
     210           0 :     ScrollableWindow::MouseMove(rMEvt);
     211             : 
     212           0 :     if (rMEvt.IsLeft() && IsInlineEditEnabled())
     213             :     {
     214           0 :         Point aPos(PixelToLogic(rMEvt.GetPosPixel()) - GetFormulaDrawPos());
     215           0 :         pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, false);
     216             : 
     217           0 :         CaretBlinkStop();
     218           0 :         SetIsCursorVisible(true);
     219           0 :         CaretBlinkStart();
     220           0 :         RepaintViewShellDoc();
     221             :     }
     222           0 : }
     223             : 
     224         148 : bool SmGraphicWindow::IsInlineEditEnabled() const
     225             : {
     226         148 :     return pViewShell->IsInlineEditEnabled();
     227             : }
     228             : 
     229           1 : void SmGraphicWindow::GetFocus()
     230             : {
     231           1 :     if (!IsInlineEditEnabled())
     232           2 :         return;
     233           0 :     if (pViewShell->GetEditWindow())
     234           0 :         pViewShell->GetEditWindow()->Flush();
     235             :     //Let view shell know what insertions should be done in visual editor
     236           0 :     pViewShell->SetInsertIntoEditWindow(false);
     237           0 :     SetIsCursorVisible(true);
     238           0 :     ShowLine(true);
     239           0 :     CaretBlinkStart();
     240           0 :     RepaintViewShellDoc();
     241             : }
     242             : 
     243           1 : void SmGraphicWindow::LoseFocus()
     244             : {
     245           1 :     ScrollableWindow::LoseFocus();
     246           1 :     if (xAccessible.is())
     247             :     {
     248           2 :         uno::Any aOldValue, aNewValue;
     249           1 :         aOldValue <<= AccessibleStateType::FOCUSED;
     250             :         // aNewValue remains empty
     251             :         pAccessible->LaunchEvent( AccessibleEventId::STATE_CHANGED,
     252           2 :                 aOldValue, aNewValue );
     253             :     }
     254           1 :     if (!IsInlineEditEnabled())
     255           2 :         return;
     256           0 :     SetIsCursorVisible(false);
     257           0 :     ShowLine(false);
     258           0 :     CaretBlinkStop();
     259           0 :     RepaintViewShellDoc();
     260             : }
     261             : 
     262           0 : void SmGraphicWindow::RepaintViewShellDoc()
     263             : {
     264           0 :     SmDocShell &rDoc = *pViewShell->GetDoc();
     265           0 :     rDoc.Repaint();
     266           0 : }
     267             : 
     268           0 : IMPL_LINK_NOARG(SmGraphicWindow, CaretBlinkTimerHdl)
     269             : {
     270           0 :     if (IsCursorVisible())
     271           0 :         SetIsCursorVisible(false);
     272             :     else
     273           0 :         SetIsCursorVisible(true);
     274             : 
     275           0 :     RepaintViewShellDoc();
     276             : 
     277           0 :     return 0;
     278             : }
     279             : 
     280          21 : void SmGraphicWindow::CaretBlinkInit()
     281             : {
     282          21 :     aCaretBlinkTimer.SetTimeoutHdl(LINK(this, SmGraphicWindow, CaretBlinkTimerHdl));
     283          21 :     aCaretBlinkTimer.SetTimeout( ScrollableWindow::GetSettings().GetStyleSettings().GetCursorBlinkTime() );
     284          21 : }
     285             : 
     286           0 : void SmGraphicWindow::CaretBlinkStart()
     287             : {
     288           0 :     if (!IsInlineEditEnabled())
     289           0 :         return;
     290           0 :     if ( aCaretBlinkTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME )
     291           0 :         aCaretBlinkTimer.Start();
     292             : }
     293             : 
     294          17 : void SmGraphicWindow::CaretBlinkStop()
     295             : {
     296          17 :     if (!IsInlineEditEnabled())
     297          34 :         return;
     298           0 :     aCaretBlinkTimer.Stop();
     299             : }
     300             : 
     301          36 : void SmGraphicWindow::ShowCursor(bool bShow)
     302             :     // shows or hides the formula-cursor depending on 'bShow' is true or not
     303             : {
     304          36 :     if (IsInlineEditEnabled())
     305          36 :         return;
     306             : 
     307          36 :     bool  bInvert = bShow != IsCursorVisible();
     308             : 
     309          36 :     if (bInvert)
     310          10 :         InvertTracking(aCursorRect, SHOWTRACK_SMALL | SHOWTRACK_WINDOW);
     311             : 
     312          36 :     SetIsCursorVisible(bShow);
     313             : }
     314             : 
     315          21 : void SmGraphicWindow::ShowLine(bool bShow)
     316             : {
     317          21 :     if (!IsInlineEditEnabled())
     318          42 :         return;
     319             : 
     320           0 :     bIsLineVisible = bShow;
     321             : }
     322             : 
     323          10 : void SmGraphicWindow::SetCursor(const SmNode *pNode)
     324             : {
     325          10 :     if (IsInlineEditEnabled())
     326          10 :         return;
     327             : 
     328          10 :     const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
     329             : 
     330             :     // get appropriate rectangle
     331          10 :     Point aOffset (pNode->GetTopLeft() - pTree->GetTopLeft()),
     332          10 :           aTLPos  (GetFormulaDrawPos() + aOffset);
     333          10 :     aTLPos.X() -= pNode->GetItalicLeftSpace();
     334          10 :     Size  aSize   (pNode->GetItalicSize());
     335             : 
     336          10 :     SetCursor(Rectangle(aTLPos, aSize));
     337             : }
     338             : 
     339          10 : void SmGraphicWindow::SetCursor(const Rectangle &rRect)
     340             :     // sets cursor to new position (rectangle) 'rRect'.
     341             :     // The old cursor will be removed, and the new one will be shown if
     342             :     // that is activated in the ConfigItem
     343             : {
     344          10 :     if (IsInlineEditEnabled())
     345          10 :         return;
     346             : 
     347          10 :     SmModule *pp = SM_MOD();
     348             : 
     349          10 :     if (IsCursorVisible())
     350           0 :         ShowCursor(false);      // clean up remainings of old cursor
     351          10 :     aCursorRect = rRect;
     352          10 :     if (pp->GetConfig()->IsShowFormulaCursor())
     353          10 :         ShowCursor(true);       // draw new cursor
     354             : }
     355             : 
     356          26 : const SmNode * SmGraphicWindow::SetCursorPos(sal_uInt16 nRow, sal_uInt16 nCol)
     357             :     // looks for a VISIBLE node in the formula tree with it's token at
     358             :     // (or around) the position 'nRow', 'nCol' in the edit window
     359             :     // (row and column numbering starts with 1 there!).
     360             :     // If there is such a node the formula-cursor is set to cover that nodes
     361             :     // rectangle. If not the formula-cursor will be hidden.
     362             :     // In any case the search result is being returned.
     363             : {
     364          26 :     if (IsInlineEditEnabled())
     365           0 :         return NULL;
     366             : 
     367             :     // find visible node with token at nRow, nCol
     368          26 :     const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree(),
     369          26 :                  *pNode = 0;
     370          26 :     if (pTree)
     371          26 :         pNode = pTree->FindTokenAt(nRow, nCol);
     372             : 
     373          26 :     if (pNode)
     374          10 :         SetCursor(pNode);
     375             :     else
     376          16 :         ShowCursor(false);
     377             : 
     378          26 :     return pNode;
     379             : }
     380             : 
     381          26 : void SmGraphicWindow::Paint(const Rectangle&)
     382             : {
     383             :     SAL_WARN_IF( !pViewShell, "starmath", "view shell missing" );
     384             : 
     385          26 :     SmDocShell &rDoc = *pViewShell->GetDoc();
     386          26 :     Point aPoint;
     387             : 
     388          26 :     rDoc.DrawFormula(*this, aPoint, true);  //! modifies aPoint to be the topleft
     389             :                                 //! corner of the formula
     390          26 :     SetFormulaDrawPos(aPoint);
     391          26 :     if(IsInlineEditEnabled())
     392             :     {
     393             :         //Draw cursor if any...
     394           0 :         if(pViewShell->GetDoc()->HasCursor() && IsLineVisible())
     395           0 :             pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint, IsCursorVisible());
     396             :     }
     397             :     else
     398             :     {
     399          26 :         SetIsCursorVisible(false);  // (old) cursor must be drawn again
     400             : 
     401          26 :         const SmEditWindow *pEdit = pViewShell->GetEditWindow();
     402          26 :         if (pEdit)
     403             :         {   // get new position for formula-cursor (for possible altered formula)
     404             :             sal_Int32  nRow;
     405             :             sal_uInt16 nCol;
     406          26 :             SmGetLeftSelectionPart(pEdit->GetSelection(), nRow, nCol);
     407          26 :             nRow++;
     408          26 :             nCol++;
     409          26 :             const SmNode *pFound = SetCursorPos(static_cast<sal_uInt16>(nRow), nCol);
     410             : 
     411          26 :             SmModule  *pp = SM_MOD();
     412          26 :             if (pFound && pp->GetConfig()->IsShowFormulaCursor())
     413          10 :                 ShowCursor(true);
     414             :         }
     415             :     }
     416          26 : }
     417             : 
     418             : 
     419          37 : void SmGraphicWindow::SetTotalSize ()
     420             : {
     421          37 :     SmDocShell &rDoc = *pViewShell->GetDoc();
     422          37 :     const Size aTmp( PixelToLogic( LogicToPixel( rDoc.GetSize() )));
     423          37 :     if ( aTmp != ScrollableWindow::GetTotalSize() )
     424          35 :         ScrollableWindow::SetTotalSize( aTmp );
     425          37 : }
     426             : 
     427           0 : void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
     428             : {
     429           0 :     if (!IsInlineEditEnabled()) {
     430           0 :         if (! (GetView() && GetView()->KeyInput(rKEvt)) )
     431           0 :             ScrollableWindow::KeyInput(rKEvt);
     432           0 :         return;
     433             :     }
     434             : 
     435           0 :     SmCursor& rCursor = pViewShell->GetDoc()->GetCursor();
     436           0 :     KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction();
     437           0 :     if (eFunc == KEYFUNC_COPY)
     438           0 :         rCursor.Copy();
     439           0 :     else if (eFunc == KEYFUNC_CUT)
     440           0 :         rCursor.Cut();
     441           0 :     else if (eFunc == KEYFUNC_PASTE)
     442           0 :         rCursor.Paste();
     443             :     else {
     444           0 :     sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
     445           0 :     switch(nCode)
     446             :     {
     447             :         case KEY_LEFT:
     448             :         {
     449           0 :             rCursor.Move(this, MoveLeft, !rKEvt.GetKeyCode().IsShift());
     450           0 :         }break;
     451             :         case KEY_RIGHT:
     452             :         {
     453           0 :             rCursor.Move(this, MoveRight, !rKEvt.GetKeyCode().IsShift());
     454           0 :         }break;
     455             :         case KEY_UP:
     456             :         {
     457           0 :             rCursor.Move(this, MoveUp, !rKEvt.GetKeyCode().IsShift());
     458           0 :         }break;
     459             :         case KEY_DOWN:
     460             :         {
     461           0 :             rCursor.Move(this, MoveDown, !rKEvt.GetKeyCode().IsShift());
     462           0 :         }break;
     463             :         case KEY_RETURN:
     464             :         {
     465           0 :             if(!rKEvt.GetKeyCode().IsShift())
     466           0 :                 rCursor.InsertRow();
     467             : #ifdef DEBUG_ENABLE_DUMPASDOT
     468             :             else {
     469             :                 SmNode *pTree = (SmNode*)pViewShell->GetDoc()->GetFormulaTree();
     470             :                 std::fstream file("/tmp/smath-dump.gv", std::fstream::out);
     471             :                 OUString label(pViewShell->GetDoc()->GetText());
     472             :                 pTree->DumpAsDot(file, &label);
     473             :                 file.close();
     474             :             }
     475             : #endif /* DEBUG_ENABLE_DUMPASDOT */
     476           0 :         }break;
     477             :         case KEY_DELETE:
     478             :         {
     479           0 :             if(!rCursor.HasSelection()){
     480           0 :                 rCursor.Move(this, nCode == KEY_DELETE ? MoveRight : MoveLeft, false);
     481           0 :                 if(rCursor.HasComplexSelection()) break;
     482             :             }
     483           0 :             rCursor.Delete();
     484           0 :         }break;
     485             :         case KEY_BACKSPACE:
     486             :         {
     487           0 :             rCursor.DeletePrev(this);
     488           0 :         }break;
     489             :         case KEY_ADD:
     490           0 :             rCursor.InsertElement(PlusElement);
     491           0 :             break;
     492             :         case KEY_SUBTRACT:
     493           0 :             if(rKEvt.GetKeyCode().IsShift())
     494           0 :                 rCursor.InsertSubSup(RSUB);
     495             :             else
     496           0 :                 rCursor.InsertElement(MinusElement);
     497           0 :             break;
     498             :         case KEY_MULTIPLY:
     499           0 :             rCursor.InsertElement(CDotElement);
     500           0 :             break;
     501             :         case KEY_DIVIDE:
     502           0 :             rCursor.InsertFraction();
     503           0 :             break;
     504             :         case KEY_LESS:
     505           0 :             rCursor.InsertElement(LessThanElement);
     506           0 :             break;
     507             :         case KEY_GREATER:
     508           0 :             rCursor.InsertElement(GreaterThanElement);
     509           0 :             break;
     510             :         case KEY_EQUAL:
     511           0 :             rCursor.InsertElement(EqualElement);
     512           0 :             break;
     513             :         default:
     514             :         {
     515           0 :             sal_Unicode code = rKEvt.GetCharCode();
     516           0 :             SmBraceNode* pBraceNode = NULL;
     517             : 
     518           0 :             if(code == ' ') {
     519           0 :                 rCursor.InsertElement(BlankElement);
     520           0 :             }else if(code == '^') {
     521           0 :                 rCursor.InsertSubSup(RSUP);
     522           0 :             }else if(code == '(') {
     523           0 :                 rCursor.InsertBrackets(RoundBrackets);
     524           0 :             }else if(code == '[') {
     525           0 :                 rCursor.InsertBrackets(SquareBrackets);
     526           0 :             }else if(code == '{') {
     527           0 :                 rCursor.InsertBrackets(CurlyBrackets);
     528           0 :             }else if(code == '!') {
     529           0 :                 rCursor.InsertElement(FactorialElement);
     530           0 :             }else if(code == '%') {
     531           0 :                 rCursor.InsertElement(PercentElement);
     532           0 :             }else if(code == ')' && rCursor.IsAtTailOfBracket(RoundBrackets, &pBraceNode)) {
     533           0 :                 rCursor.MoveAfterBracket(pBraceNode);
     534           0 :             }else if(code == ']' && rCursor.IsAtTailOfBracket(SquareBrackets, &pBraceNode)) {
     535           0 :                 rCursor.MoveAfterBracket(pBraceNode);
     536           0 :             }else if(code == '}' && rCursor.IsAtTailOfBracket(CurlyBrackets, &pBraceNode)) {
     537           0 :                 rCursor.MoveAfterBracket(pBraceNode);
     538             :             }else{
     539           0 :                 if(code != 0){
     540           0 :                     rCursor.InsertText(OUString(code));
     541           0 :                 }else if (! (GetView() && GetView()->KeyInput(rKEvt)) )
     542           0 :                     ScrollableWindow::KeyInput(rKEvt);
     543             :             }
     544             :         }
     545             :     }
     546             :     }
     547           0 :     CaretBlinkStop();
     548           0 :     CaretBlinkStart();
     549           0 :     SetIsCursorVisible(true);
     550           0 :     RepaintViewShellDoc();
     551             : }
     552             : 
     553             : 
     554           0 : void SmGraphicWindow::Command(const CommandEvent& rCEvt)
     555             : {
     556           0 :     bool bCallBase = true;
     557           0 :     if ( !pViewShell->GetViewFrame()->GetFrame().IsInPlace() )
     558             :     {
     559           0 :         switch ( rCEvt.GetCommand() )
     560             :         {
     561             :             case COMMAND_CONTEXTMENU:
     562             :             {
     563           0 :                 GetParent()->ToTop();
     564           0 :                 SmResId aResId( RID_VIEWMENU );
     565           0 :                 PopupMenu* pPopupMenu = new PopupMenu(aResId);
     566           0 :                 pPopupMenu->SetSelectHdl(LINK(this, SmGraphicWindow, MenuSelectHdl));
     567           0 :                 Point aPos(5, 5);
     568           0 :                 if (rCEvt.IsMouseEvent())
     569           0 :                     aPos = rCEvt.GetMousePosPixel();
     570             :                 SAL_WARN_IF( !pViewShell, "starmath", "view shell missing" );
     571             : 
     572             :                 // added for replaceability of context menus
     573           0 :                 pViewShell->GetViewFrame()->GetBindings().GetDispatcher()
     574           0 :                         ->ExecutePopup( aResId, this, &aPos );
     575             : 
     576           0 :                 delete pPopupMenu;
     577           0 :                 bCallBase = false;
     578             :             }
     579           0 :             break;
     580             : 
     581             :             case COMMAND_WHEEL:
     582             :             {
     583           0 :                 const CommandWheelData* pWData = rCEvt.GetWheelData();
     584           0 :                 if  ( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
     585             :                 {
     586           0 :                     sal_uInt16 nTmpZoom = GetZoom();
     587           0 :                     if( 0L > pWData->GetDelta() )
     588           0 :                         nTmpZoom -= 10;
     589             :                     else
     590           0 :                         nTmpZoom += 10;
     591           0 :                     SetZoom( nTmpZoom );
     592           0 :                     bCallBase = false;
     593             :                 }
     594             :             }
     595           0 :             break;
     596             :         }
     597             :     }
     598           0 :     if ( bCallBase )
     599           0 :         ScrollableWindow::Command (rCEvt);
     600           0 : }
     601             : 
     602             : 
     603           0 : IMPL_LINK_INLINE_START( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
     604             : {
     605           0 :     SmViewShell *pViewSh = GetView();
     606           0 :     if (pViewSh)
     607           0 :         pViewSh->GetViewFrame()->GetDispatcher()->Execute( pMenu->GetCurItemId() );
     608           0 :     return 0;
     609             : }
     610           0 : IMPL_LINK_INLINE_END( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
     611             : 
     612             : 
     613           8 : void SmGraphicWindow::SetZoom(sal_uInt16 Factor)
     614             : {
     615           8 :     nZoom = std::min(std::max((sal_uInt16) Factor, (sal_uInt16) MINZOOM), (sal_uInt16) MAXZOOM);
     616           8 :     Fraction   aFraction (nZoom, 100);
     617           8 :     SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction) );
     618           8 :     SetTotalSize();
     619           8 :     SmViewShell *pViewSh = GetView();
     620           8 :     if (pViewSh)
     621             :     {
     622           8 :         pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_ATTR_ZOOM);
     623           8 :         pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_ATTR_ZOOMSLIDER);
     624             :     }
     625           8 :     Invalidate();
     626           8 : }
     627             : 
     628             : 
     629           2 : void SmGraphicWindow::ZoomToFitInWindow()
     630             : {
     631           2 :     SmDocShell &rDoc = *pViewShell->GetDoc();
     632             : 
     633             :     // set defined mapmode before calling 'LogicToPixel' below
     634           2 :     SetMapMode(MapMode(MAP_100TH_MM));
     635             : 
     636           2 :     Size       aSize (LogicToPixel(rDoc.GetSize()));
     637           2 :     Size       aWindowSize (GetSizePixel());
     638             : 
     639           2 :     if (aSize.Width() > 0  &&  aSize.Height() > 0)
     640             :     {
     641           2 :         long nVal = std::min ((85 * aWindowSize.Width())  / aSize.Width(),
     642           4 :                       (85 * aWindowSize.Height()) / aSize.Height());
     643           2 :         SetZoom ( sal::static_int_cast< sal_uInt16 >(nVal) );
     644             :     }
     645           2 : }
     646             : 
     647           3 : uno::Reference< XAccessible > SmGraphicWindow::CreateAccessible()
     648             : {
     649           3 :     if (!pAccessible)
     650             :     {
     651           3 :         pAccessible = new SmGraphicAccessible( this );
     652           3 :         xAccessible = pAccessible;
     653             :     }
     654           3 :     return xAccessible;
     655             : }
     656             : 
     657             : /**************************************************************************/
     658             : 
     659             : 
     660          21 : SmGraphicController::SmGraphicController(SmGraphicWindow &rSmGraphic,
     661             :                         sal_uInt16          nId_,
     662             :                         SfxBindings     &rBindings) :
     663             :     SfxControllerItem(nId_, rBindings),
     664          21 :     rGraphic(rSmGraphic)
     665             : {
     666          21 : }
     667             : 
     668             : 
     669           8 : void SmGraphicController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
     670             : {
     671           8 :     rGraphic.SetTotalSize();
     672           8 :     rGraphic.Invalidate();
     673           8 :     SfxControllerItem::StateChanged (nSID, eState, pState);
     674           8 : }
     675             : 
     676             : 
     677             : /**************************************************************************/
     678             : 
     679             : 
     680          21 : SmEditController::SmEditController(SmEditWindow &rSmEdit,
     681             :                      sal_uInt16       nId_,
     682             :                      SfxBindings  &rBindings) :
     683             :     SfxControllerItem(nId_, rBindings),
     684          21 :     rEdit(rSmEdit)
     685             : {
     686          21 : }
     687             : 
     688             : 
     689             : #if OSL_DEBUG_LEVEL > 1
     690             : SmEditController::~SmEditController()
     691             : {
     692             : }
     693             : #endif
     694             : 
     695             : 
     696           6 : void SmEditController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
     697             : {
     698           6 :     const SfxStringItem *pItem = PTR_CAST(SfxStringItem, pState);
     699             : 
     700           6 :     if ((pItem != NULL) && (rEdit.GetText() != OUString(pItem->GetValue())))
     701           5 :         rEdit.SetText(pItem->GetValue());
     702           6 :     SfxControllerItem::StateChanged (nSID, eState, pState);
     703           6 : }
     704             : 
     705             : 
     706             : /**************************************************************************/
     707             : 
     708          21 : SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings *pBindings_, SfxChildWindow *pChildWindow,
     709             :                                Window *pParent) :
     710             :     SfxDockingWindow(pBindings_, pChildWindow, pParent, SmResId(RID_CMDBOXWINDOW)),
     711             :     aEdit       (*this),
     712             :     aController (aEdit, SID_TEXT, *pBindings_),
     713          21 :     bExiting    (false)
     714             : {
     715          21 :     Hide ();
     716             : 
     717          21 :     aInitialFocusTimer.SetTimeoutHdl(LINK(this, SmCmdBoxWindow, InitialFocusTimerHdl));
     718          21 :     aInitialFocusTimer.SetTimeout(100);
     719          21 : }
     720             : 
     721             : 
     722          63 : SmCmdBoxWindow::~SmCmdBoxWindow ()
     723             : {
     724          21 :     aInitialFocusTimer.Stop();
     725          21 :     bExiting = true;
     726          42 : }
     727             : 
     728             : 
     729         136 : SmViewShell * SmCmdBoxWindow::GetView()
     730             : {
     731         136 :     SfxDispatcher *pDispatcher = GetBindings().GetDispatcher();
     732         136 :     SfxViewShell *pView = pDispatcher ? pDispatcher->GetFrame()->GetViewShell() : NULL;
     733         136 :     return PTR_CAST(SmViewShell, pView);
     734             : }
     735             : 
     736          34 : void SmCmdBoxWindow::Resize()
     737             : {
     738          34 :     Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
     739          34 :     aRect.Left()   += CMD_BOX_PADDING;
     740          34 :     aRect.Top()    += CMD_BOX_PADDING_TOP;
     741          34 :     aRect.Right()  -= CMD_BOX_PADDING;
     742          34 :     aRect.Bottom() -= CMD_BOX_PADDING;
     743             : 
     744          34 :     DecorationView aView(this);
     745          34 :     aRect = aView.DrawFrame( aRect, FRAME_DRAW_IN | FRAME_DRAW_NODRAW );
     746             : 
     747          34 :     aEdit.SetPosSizePixel(aRect.TopLeft(), aRect.GetSize());
     748          34 :     SfxDockingWindow::Resize();
     749          34 :     Invalidate();
     750          34 : }
     751             : 
     752             : 
     753          23 : void SmCmdBoxWindow::Paint(const Rectangle& /*rRect*/)
     754             : {
     755          23 :     Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
     756          23 :     aRect.Left()   += CMD_BOX_PADDING;
     757          23 :     aRect.Top()    += CMD_BOX_PADDING_TOP;
     758          23 :     aRect.Right()  -= CMD_BOX_PADDING;
     759          23 :     aRect.Bottom() -= CMD_BOX_PADDING;
     760             : 
     761          23 :     DecorationView aView(this);
     762          23 :     aView.DrawFrame( aRect, FRAME_DRAW_IN );
     763          23 : }
     764             : 
     765             : 
     766           0 : Size SmCmdBoxWindow::CalcDockingSize(SfxChildAlignment eAlign)
     767             : {
     768           0 :     switch (eAlign)
     769             :     {
     770             :         case SFX_ALIGN_LEFT:
     771             :         case SFX_ALIGN_RIGHT:
     772           0 :             return Size();
     773             :         default:
     774           0 :             break;
     775             :     }
     776           0 :     return SfxDockingWindow::CalcDockingSize(eAlign);
     777             : }
     778             : 
     779             : 
     780          15 : SfxChildAlignment SmCmdBoxWindow::CheckAlignment(SfxChildAlignment eActual,
     781             :                                              SfxChildAlignment eWish)
     782             : {
     783          15 :     switch (eWish)
     784             :     {
     785             :         case SFX_ALIGN_TOP:
     786             :         case SFX_ALIGN_BOTTOM:
     787             :         case SFX_ALIGN_NOALIGNMENT:
     788          15 :             return eWish;
     789             :         default:
     790           0 :             break;
     791             :     }
     792             : 
     793           0 :     return eActual;
     794             : }
     795             : 
     796             : 
     797          72 : void SmCmdBoxWindow::StateChanged( StateChangedType nStateChange )
     798             : {
     799          72 :     if (STATE_CHANGE_INITSHOW == nStateChange)
     800             :     {
     801          17 :         Resize();   // avoid SmEditWindow not being painted correctly
     802             : 
     803             :         // set initial position of window in floating mode
     804          17 :         if (IsFloatingMode())
     805           0 :             AdjustPosition();   //! don't change pos in docking-mode !
     806             : 
     807          17 :         aInitialFocusTimer.Start();
     808             :     }
     809             : 
     810          72 :     SfxDockingWindow::StateChanged( nStateChange );
     811          72 : }
     812             : 
     813             : 
     814          26 : IMPL_LINK( SmCmdBoxWindow, InitialFocusTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
     815             : {
     816             :     // We want to have the focus in the edit window once Math has been opened
     817             :     // to allow for immediate typing.
     818             :     // Problem: There is no proper way to do this
     819             :     // Thus: this timer based solution has been implemented (see GrabFocus below)
     820             : 
     821             :     // Follow-up problem (#i114910): grabing the focus may bust the help system since
     822             :     // it relies on getting the current frame which conflicts with grabbing the focus.
     823             :     // Thus aside from the 'GrabFocus' call everything else is to get the
     824             :     // help reliably working despite using 'GrabFocus'.
     825             : 
     826             :     try
     827             :     {
     828          13 :         uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( comphelper::getProcessComponentContext() );
     829             : 
     830          13 :         aEdit.GrabFocus();
     831             : 
     832          13 :         bool bInPlace = GetView()->GetViewFrame()->GetFrame().IsInPlace();
     833          26 :         uno::Reference< frame::XFrame > xFrame( GetBindings().GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface());
     834          13 :         if ( bInPlace )
     835             :         {
     836           0 :             uno::Reference< container::XChild > xModel( GetView()->GetDoc()->GetModel(), uno::UNO_QUERY_THROW );
     837           0 :             uno::Reference< frame::XModel > xParent( xModel->getParent(), uno::UNO_QUERY_THROW );
     838           0 :             uno::Reference< frame::XController > xParentCtrler( xParent->getCurrentController() );
     839           0 :             uno::Reference< frame::XFramesSupplier > xParentFrame( xParentCtrler->getFrame(), uno::UNO_QUERY_THROW );
     840           0 :             xParentFrame->setActiveFrame( xFrame );
     841             :         }
     842             :         else
     843             :         {
     844          13 :             xDesktop->setActiveFrame( xFrame );
     845          13 :         }
     846             :     }
     847           0 :     catch (uno::Exception &)
     848             :     {
     849             :         SAL_WARN( "starmath", "failed to properly set initial focus to edit window" );
     850             :     }
     851          13 :     return 0;
     852             : }
     853             : 
     854             : 
     855           0 : void SmCmdBoxWindow::AdjustPosition()
     856             : {
     857           0 :     Point aPt;
     858           0 :     const Rectangle aRect( aPt, GetParent()->GetOutputSizePixel() );
     859             :     Point aTopLeft( Point( aRect.Left(),
     860           0 :                            aRect.Bottom() - GetSizePixel().Height() ) );
     861           0 :     Point aPos( GetParent()->OutputToScreenPixel( aTopLeft ) );
     862           0 :     if (aPos.X() < 0)
     863           0 :         aPos.X() = 0;
     864           0 :     if (aPos.Y() < 0)
     865           0 :         aPos.Y() = 0;
     866           0 :     SetPosPixel( aPos );
     867           0 : }
     868             : 
     869             : 
     870           0 : void SmCmdBoxWindow::ToggleFloatingMode()
     871             : {
     872           0 :     SfxDockingWindow::ToggleFloatingMode();
     873             : 
     874           0 :     if (GetFloatingWindow())
     875           0 :         GetFloatingWindow()->SetMinOutputSizePixel(Size (200, 50));
     876           0 : }
     877             : 
     878             : 
     879          16 : void SmCmdBoxWindow::GetFocus()
     880             : {
     881          16 :     if (!bExiting)
     882           0 :         aEdit.GrabFocus();
     883          16 : }
     884             : 
     885             : /**************************************************************************/
     886             : 
     887             : 
     888         342 : SFX_IMPL_DOCKINGWINDOW_WITHID(SmCmdBoxWrapper, SID_CMDBOXWINDOW);
     889             : 
     890          17 : SmCmdBoxWrapper::SmCmdBoxWrapper(Window *pParentWindow, sal_uInt16 nId,
     891             :                                  SfxBindings *pBindings,
     892             :                                  SfxChildWinInfo *pInfo) :
     893          17 :     SfxChildWindow(pParentWindow, nId)
     894             : {
     895          17 :     pWindow = new SmCmdBoxWindow(pBindings, this, pParentWindow);
     896             : 
     897             :     // make window docked to the bottom initially (after first start)
     898          17 :     eChildAlignment = SFX_ALIGN_BOTTOM;
     899          17 :     ((SfxDockingWindow *)pWindow)->Initialize(pInfo);
     900          17 : }
     901             : 
     902             : 
     903             : #if OSL_DEBUG_LEVEL > 1
     904             : SmCmdBoxWrapper::~SmCmdBoxWrapper()
     905             : {
     906             : }
     907             : #endif
     908             : 
     909             : 
     910             : /**************************************************************************/
     911             : 
     912             : struct SmViewShell_Impl
     913             : {
     914             :     sfx2::DocumentInserter* pDocInserter;
     915             :     SfxRequest*             pRequest;
     916             :     SvtMiscOptions          aOpts;
     917             : 
     918          21 :     SmViewShell_Impl() :
     919             :           pDocInserter( NULL )
     920          21 :         , pRequest( NULL )
     921          21 :     {}
     922             : 
     923          17 :     ~SmViewShell_Impl()
     924          17 :     {
     925          17 :         delete pDocInserter;
     926          17 :         delete pRequest;
     927          17 :     }
     928             : };
     929             : 
     930         903 : TYPEINIT1( SmViewShell, SfxViewShell );
     931             : 
     932        2218 : SFX_IMPL_INTERFACE(SmViewShell, SfxViewShell, SmResId(0))
     933             : {
     934          18 :     SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS | SFX_VISIBILITY_STANDARD |
     935             :                                 SFX_VISIBILITY_FULLSCREEN | SFX_VISIBILITY_SERVER,
     936           9 :                                 SmResId(RID_MATH_TOOLBOX ));
     937             :     //Dummy-Objectbar, to avoid quiver while activating
     938             : 
     939           9 :     SFX_CHILDWINDOW_REGISTRATION(SID_TASKPANE);
     940           9 :     SFX_CHILDWINDOW_REGISTRATION(SmToolBoxWrapper::GetChildWindowId());
     941           9 :     SFX_CHILDWINDOW_REGISTRATION(SmCmdBoxWrapper::GetChildWindowId());
     942           9 :     SFX_CHILDWINDOW_REGISTRATION(SmElementsDockingWindowWrapper::GetChildWindowId());
     943           9 : }
     944             : 
     945             : 
     946          39 : SFX_IMPL_NAMED_VIEWFACTORY(SmViewShell, "Default")
     947             : {
     948           9 :     SFX_VIEW_REGISTRATION(SmDocShell);
     949           9 : }
     950             : 
     951             : 
     952           0 : void SmViewShell::AdjustPosSizePixel(const Point &rPos, const Size &rSize)
     953             : {
     954             :     SAL_INFO( "starmath", "SmViewShell::AdjustPosSizePixel" );
     955             : 
     956           0 :     aGraphic.SetPosSizePixel(rPos, rSize);
     957           0 : }
     958             : 
     959             : 
     960           0 : void SmViewShell::InnerResizePixel(const Point &rOfs, const Size &rSize)
     961             : {
     962             :     SAL_INFO( "starmath", "SmViewShell::InnerResizePixel" );
     963             : 
     964           0 :     Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
     965           0 :     if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
     966             :     {
     967           0 :         Size aProvidedSize = GetWindow()->PixelToLogic( rSize, MAP_100TH_MM );
     968           0 :         SfxViewShell::SetZoomFactor( Fraction( aProvidedSize.Width(), aObjSize.Width() ),
     969           0 :                         Fraction( aProvidedSize.Height(), aObjSize.Height() ) );
     970             :     }
     971             : 
     972           0 :     SetBorderPixel( SvBorder() );
     973           0 :     GetGraphicWindow().SetPosSizePixel(rOfs, rSize);
     974           0 :     GetGraphicWindow().SetTotalSize();
     975           0 : }
     976             : 
     977             : 
     978          38 : void SmViewShell::OuterResizePixel(const Point &rOfs, const Size &rSize)
     979             : {
     980             :     SAL_INFO( "starmath", "SmViewShell::OuterResizePixel" );
     981             : 
     982          38 :     SmGraphicWindow &rWin = GetGraphicWindow();
     983          38 :     rWin.SetPosSizePixel(rOfs, rSize);
     984          38 :     if (GetDoc()->IsPreview())
     985           0 :         rWin.ZoomToFitInWindow();
     986          38 :     rWin.Update();
     987          38 : }
     988             : 
     989             : 
     990           0 : void SmViewShell::QueryObjAreaPixel( Rectangle& rRect ) const
     991             : {
     992             :     SAL_INFO( "starmath", "SmViewShell::QueryObjAreaPixel" );
     993             : 
     994           0 :     rRect.SetSize( GetGraphicWindow().GetSizePixel() );
     995           0 : }
     996             : 
     997             : 
     998           0 : void SmViewShell::SetZoomFactor( const Fraction &rX, const Fraction &rY )
     999             : {
    1000             :     SAL_INFO( "starmath", "SmViewShell::SetZoomFactor" );
    1001             : 
    1002           0 :     const Fraction &rFrac = rX < rY ? rX : rY;
    1003           0 :     GetGraphicWindow().SetZoom( (sal_uInt16) long(rFrac * Fraction( 100, 1 )) );
    1004             : 
    1005             :     //To avoid rounding errors base class regulates crooked values too
    1006             :     //if necessary
    1007           0 :     SfxViewShell::SetZoomFactor( rX, rY );
    1008           0 : }
    1009             : 
    1010             : 
    1011           0 : Size SmViewShell::GetTextLineSize(OutputDevice& rDevice, const OUString& rLine)
    1012             : {
    1013             :     SAL_INFO( "starmath", "SmViewShell::GetTextLineSize" );
    1014             : 
    1015           0 :     Size   aSize(rDevice.GetTextWidth(rLine), rDevice.GetTextHeight());
    1016           0 :     sal_uInt16 nTabs = comphelper::string::getTokenCount(rLine, '\t');
    1017           0 :     long nTabPos = 0;
    1018           0 :     if (nTabs > 0)
    1019           0 :         nTabPos = rDevice.approximate_char_width() * 8;
    1020             : 
    1021           0 :     if (nTabPos)
    1022             :     {
    1023           0 :         aSize.Width() = 0;
    1024             : 
    1025           0 :         for (sal_uInt16 i = 0; i < nTabs; i++)
    1026             :         {
    1027           0 :             if (i > 0)
    1028           0 :                 aSize.Width() = ((aSize.Width() / nTabPos) + 1) * nTabPos;
    1029             : 
    1030           0 :             OUString aText = rLine.getToken(i, '\t');
    1031           0 :             aText = comphelper::string::stripStart(aText, '\t');
    1032           0 :             aText = comphelper::string::stripEnd(aText, '\t');
    1033           0 :             aSize.Width() += rDevice.GetTextWidth(aText);
    1034           0 :         }
    1035             :     }
    1036             : 
    1037           0 :     return aSize;
    1038             : }
    1039             : 
    1040             : 
    1041           0 : Size SmViewShell::GetTextSize(OutputDevice& rDevice, const OUString& rText, long MaxWidth)
    1042             : {
    1043             :     SAL_INFO( "starmath", "SmViewShell::GetTextSize" );
    1044             : 
    1045           0 :     Size    aSize;
    1046           0 :     Size    TextSize;
    1047           0 :     sal_uInt16  nLines = comphelper::string::getTokenCount(rText, '\n');
    1048             : 
    1049           0 :     for (sal_uInt16 i = 0; i < nLines; i++)
    1050             :     {
    1051           0 :         OUString aLine = rText.getToken(i, '\n');
    1052           0 :         aLine = comphelper::string::remove(aLine, '\r');
    1053           0 :         aLine = comphelper::string::stripStart(aLine, '\n');
    1054           0 :         aLine = comphelper::string::stripEnd(aLine, '\n');
    1055             : 
    1056           0 :         aSize = GetTextLineSize(rDevice, aLine);
    1057             : 
    1058           0 :         if (aSize.Width() > MaxWidth)
    1059             :         {
    1060           0 :             do
    1061             :             {
    1062           0 :                 OUString aText;
    1063           0 :                 sal_Int32 m = aLine.getLength();
    1064           0 :                 sal_Int32 nLen = m;
    1065             : 
    1066           0 :                 for (sal_Int32 n = 0; n < nLen; n++)
    1067             :                 {
    1068           0 :                     sal_Unicode cLineChar = aLine[n];
    1069           0 :                     if ((cLineChar == ' ') || (cLineChar == '\t'))
    1070             :                     {
    1071           0 :                         aText = aLine.copy(0, n);
    1072           0 :                         if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
    1073           0 :                             m = n;
    1074             :                         else
    1075           0 :                             break;
    1076             :                     }
    1077             :                 }
    1078             : 
    1079           0 :                 aText = aLine.copy(0, m);
    1080           0 :                 aLine = aLine.replaceAt(0, m, "");
    1081           0 :                 aSize = GetTextLineSize(rDevice, aText);
    1082           0 :                 TextSize.Height() += aSize.Height();
    1083           0 :                 TextSize.Width() = std::max(TextSize.Width(), std::min(aSize.Width(), MaxWidth));
    1084             : 
    1085           0 :                 aLine = comphelper::string::stripStart(aLine, ' ');
    1086           0 :                 aLine = comphelper::string::stripStart(aLine, '\t');
    1087           0 :                 aLine = comphelper::string::stripStart(aLine, ' ');
    1088             :             }
    1089           0 :             while (!aLine.isEmpty());
    1090             :         }
    1091             :         else
    1092             :         {
    1093           0 :             TextSize.Height() += aSize.Height();
    1094           0 :             TextSize.Width() = std::max(TextSize.Width(), aSize.Width());
    1095             :         }
    1096           0 :     }
    1097             : 
    1098           0 :     return TextSize;
    1099             : }
    1100             : 
    1101             : 
    1102           0 : void SmViewShell::DrawTextLine(OutputDevice& rDevice, const Point& rPosition, const OUString& rLine)
    1103             : {
    1104             :     SAL_INFO( "starmath", "SmViewShell::DrawTextLine" );
    1105             : 
    1106           0 :     Point   aPoint (rPosition);
    1107             : 
    1108           0 :     sal_uInt16 nTabs = comphelper::string::getTokenCount(rLine, '\t');
    1109           0 :     long nTabPos = 0;
    1110           0 :     if (nTabs > 0)
    1111           0 :         nTabPos = rDevice.approximate_char_width() * 8;
    1112             : 
    1113           0 :     if (nTabPos)
    1114             :     {
    1115           0 :         for (sal_uInt16 i = 0; i < nTabs; ++i)
    1116             :         {
    1117           0 :             if (i > 0)
    1118           0 :                 aPoint.X() = ((aPoint.X() / nTabPos) + 1) * nTabPos;
    1119             : 
    1120           0 :             OUString aText = rLine.getToken(i, '\t');
    1121           0 :             aText = comphelper::string::stripStart(aText, '\t');
    1122           0 :             aText = comphelper::string::stripEnd(aText, '\t');
    1123           0 :             rDevice.DrawText(aPoint, aText);
    1124           0 :             aPoint.X() += rDevice.GetTextWidth(aText);
    1125           0 :         }
    1126             :     }
    1127             :     else
    1128           0 :         rDevice.DrawText(aPoint, rLine);
    1129           0 : }
    1130             : 
    1131             : 
    1132           0 : void SmViewShell::DrawText(OutputDevice& rDevice, const Point& rPosition, const OUString& rText, sal_uInt16 MaxWidth)
    1133             : {
    1134             :     SAL_INFO( "starmath", "SmViewShell::DrawText" );
    1135             : 
    1136           0 :     sal_uInt16 nLines = comphelper::string::getTokenCount(rText, '\n');
    1137           0 :     Point   aPoint (rPosition);
    1138           0 :     Size    aSize;
    1139             : 
    1140           0 :     for (sal_uInt16 i = 0; i < nLines; i++)
    1141             :     {
    1142           0 :         OUString aLine = rText.getToken(i, '\n');
    1143           0 :         aLine = comphelper::string::remove(aLine, '\r');
    1144           0 :         aLine = comphelper::string::stripEnd(aLine, '\n');
    1145           0 :         aLine = comphelper::string::stripEnd(aLine, '\n');
    1146           0 :         aSize = GetTextLineSize(rDevice, aLine);
    1147           0 :         if (aSize.Width() > MaxWidth)
    1148             :         {
    1149           0 :             do
    1150             :             {
    1151           0 :                 OUString aText;
    1152           0 :                 sal_Int32 m = aLine.getLength();
    1153           0 :                 sal_Int32 nLen = m;
    1154             : 
    1155           0 :                 for (sal_Int32 n = 0; n < nLen; n++)
    1156             :                 {
    1157           0 :                     sal_Unicode cLineChar = aLine[n];
    1158           0 :                     if ((cLineChar == ' ') || (cLineChar == '\t'))
    1159             :                     {
    1160           0 :                         aText = aLine.copy(0, n);
    1161           0 :                         if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
    1162           0 :                             m = n;
    1163             :                         else
    1164           0 :                             break;
    1165             :                     }
    1166             :                 }
    1167           0 :                 aText = aLine.copy(0, m);
    1168           0 :                 aLine = aLine.replaceAt(0, m, "");
    1169             : 
    1170           0 :                 DrawTextLine(rDevice, aPoint, aText);
    1171           0 :                 aPoint.Y() += aSize.Height();
    1172             : 
    1173           0 :                 aLine = comphelper::string::stripStart(aLine, ' ');
    1174           0 :                 aLine = comphelper::string::stripStart(aLine, '\t');
    1175           0 :                 aLine = comphelper::string::stripStart(aLine, ' ');
    1176             :             }
    1177           0 :             while (GetTextLineSize(rDevice, aLine).Width() > MaxWidth);
    1178             : 
    1179             :             // print the remaining text
    1180           0 :             if (!aLine.isEmpty())
    1181             :             {
    1182           0 :                 DrawTextLine(rDevice, aPoint, aLine);
    1183           0 :                 aPoint.Y() += aSize.Height();
    1184             :             }
    1185             :         }
    1186             :         else
    1187             :         {
    1188           0 :             DrawTextLine(rDevice, aPoint, aLine);
    1189           0 :             aPoint.Y() += aSize.Height();
    1190             :         }
    1191           0 :     }
    1192           0 : }
    1193             : 
    1194           0 : void SmViewShell::Impl_Print(
    1195             :         OutputDevice &rOutDev,
    1196             :         const SmPrintUIOptions &rPrintUIOptions,
    1197             :         Rectangle aOutRect, Point aZeroPoint )
    1198             : {
    1199             :     SAL_INFO( "starmath", "SmViewShell::Impl_Print" );
    1200             : 
    1201           0 :     const bool bIsPrintTitle = rPrintUIOptions.getBoolValue( PRTUIOPT_TITLE_ROW, true );
    1202           0 :     const bool bIsPrintFrame = rPrintUIOptions.getBoolValue( PRTUIOPT_BORDER, true );
    1203           0 :     const bool bIsPrintFormulaText = rPrintUIOptions.getBoolValue( PRTUIOPT_FORMULA_TEXT, true );
    1204           0 :     SmPrintSize ePrintSize( static_cast< SmPrintSize >( rPrintUIOptions.getIntValue( PRTUIOPT_PRINT_FORMAT, PRINT_SIZE_NORMAL ) ));
    1205           0 :     const sal_uInt16 nZoomFactor = static_cast< sal_uInt16 >(rPrintUIOptions.getIntValue( PRTUIOPT_PRINT_SCALE, 100 ));
    1206             : 
    1207           0 :     rOutDev.Push();
    1208           0 :     rOutDev.SetLineColor( Color(COL_BLACK) );
    1209             : 
    1210             :     // output text on top
    1211           0 :     if (bIsPrintTitle)
    1212             :     {
    1213           0 :         Size aSize600 (0, 600);
    1214           0 :         Size aSize650 (0, 650);
    1215           0 :         Font aFont(FAMILY_DONTKNOW, aSize600);
    1216             : 
    1217           0 :         aFont.SetAlign(ALIGN_TOP);
    1218           0 :         aFont.SetWeight(WEIGHT_BOLD);
    1219           0 :         aFont.SetSize(aSize650);
    1220           0 :         aFont.SetColor( Color(COL_BLACK) );
    1221           0 :         rOutDev.SetFont(aFont);
    1222             : 
    1223           0 :         Size aTitleSize (GetTextSize(rOutDev, GetDoc()->GetTitle(), aOutRect.GetWidth() - 200));
    1224             : 
    1225           0 :         aFont.SetWeight(WEIGHT_NORMAL);
    1226           0 :         aFont.SetSize(aSize600);
    1227           0 :         rOutDev.SetFont(aFont);
    1228             : 
    1229           0 :         Size aDescSize (GetTextSize(rOutDev, GetDoc()->GetComment(), aOutRect.GetWidth() - 200));
    1230             : 
    1231           0 :         if (bIsPrintFrame)
    1232             :             rOutDev.DrawRect(Rectangle(aOutRect.TopLeft(),
    1233           0 :                                Size(aOutRect.GetWidth(), 100 + aTitleSize.Height() + 200 + aDescSize.Height() + 100)));
    1234           0 :         aOutRect.Top() += 200;
    1235             : 
    1236             :         // output title
    1237           0 :         aFont.SetWeight(WEIGHT_BOLD);
    1238           0 :         aFont.SetSize(aSize650);
    1239           0 :         rOutDev.SetFont(aFont);
    1240           0 :         Point aPoint(aOutRect.Left() + (aOutRect.GetWidth() - aTitleSize.Width())  / 2,
    1241           0 :                      aOutRect.Top());
    1242           0 :         DrawText(rOutDev, aPoint, GetDoc()->GetTitle(),
    1243           0 :                  sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
    1244           0 :         aOutRect.Top() += aTitleSize.Height() + 200;
    1245             : 
    1246             :         // output description
    1247           0 :         aFont.SetWeight(WEIGHT_NORMAL);
    1248           0 :         aFont.SetSize(aSize600);
    1249           0 :         rOutDev.SetFont(aFont);
    1250           0 :         aPoint.X() = aOutRect.Left() + (aOutRect.GetWidth()  - aDescSize.Width())  / 2;
    1251           0 :         aPoint.Y() = aOutRect.Top();
    1252             :         DrawText(rOutDev, aPoint, GetDoc()->GetComment(),
    1253           0 :                  sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
    1254           0 :         aOutRect.Top() += aDescSize.Height() + 300;
    1255             :     }
    1256             : 
    1257             :     // output text on bottom
    1258           0 :     if (bIsPrintFormulaText)
    1259             :     {
    1260           0 :         Font aFont(FAMILY_DONTKNOW, Size(0, 600));
    1261           0 :         aFont.SetAlign(ALIGN_TOP);
    1262           0 :         aFont.SetColor( Color(COL_BLACK) );
    1263             : 
    1264             :         // get size
    1265           0 :         rOutDev.SetFont(aFont);
    1266             : 
    1267           0 :         Size aSize (GetTextSize(rOutDev, GetDoc()->GetText(), aOutRect.GetWidth() - 200));
    1268             : 
    1269           0 :         aOutRect.Bottom() -= aSize.Height() + 600;
    1270             : 
    1271           0 :         if (bIsPrintFrame)
    1272             :             rOutDev.DrawRect(Rectangle(aOutRect.BottomLeft(),
    1273           0 :                                Size(aOutRect.GetWidth(), 200 + aSize.Height() + 200)));
    1274             : 
    1275           0 :         Point aPoint (aOutRect.Left() + (aOutRect.GetWidth()  - aSize.Width())  / 2,
    1276           0 :                       aOutRect.Bottom() + 300);
    1277             :         DrawText(rOutDev, aPoint, GetDoc()->GetText(),
    1278           0 :                  sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
    1279           0 :         aOutRect.Bottom() -= 200;
    1280             :     }
    1281             : 
    1282           0 :     if (bIsPrintFrame)
    1283           0 :         rOutDev.DrawRect(aOutRect);
    1284             : 
    1285           0 :     aOutRect.Top()    += 100;
    1286           0 :     aOutRect.Left()   += 100;
    1287           0 :     aOutRect.Bottom() -= 100;
    1288           0 :     aOutRect.Right()  -= 100;
    1289             : 
    1290           0 :     Size aSize (GetDoc()->GetSize());
    1291             : 
    1292           0 :     MapMode    OutputMapMode;
    1293             :     // PDF export should always use PRINT_SIZE_NORMAL ...
    1294           0 :     if (!rPrintUIOptions.getBoolValue( "IsPrinter", false ) )
    1295           0 :         ePrintSize = PRINT_SIZE_NORMAL;
    1296           0 :     switch (ePrintSize)
    1297             :     {
    1298             :         case PRINT_SIZE_NORMAL:
    1299           0 :             OutputMapMode = MapMode(MAP_100TH_MM);
    1300           0 :             break;
    1301             : 
    1302             :         case PRINT_SIZE_SCALED:
    1303           0 :             if ((aSize.Width() > 0) && (aSize.Height() > 0))
    1304             :             {
    1305             :                 Size     OutputSize (rOutDev.LogicToPixel(Size(aOutRect.GetWidth(),
    1306           0 :                                                             aOutRect.GetHeight()), MapMode(MAP_100TH_MM)));
    1307           0 :                 Size     GraphicSize (rOutDev.LogicToPixel(aSize, MapMode(MAP_100TH_MM)));
    1308           0 :                 sal_uInt16   nZ = (sal_uInt16) std::min((long)Fraction(OutputSize.Width()  * 100L, GraphicSize.Width()),
    1309           0 :                                               (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
    1310           0 :                 Fraction aFraction ((sal_uInt16) std::max ((sal_uInt16) MINZOOM, std::min((sal_uInt16) MAXZOOM, (sal_uInt16) (nZ - 10))), (sal_uInt16) 100);
    1311             : 
    1312           0 :                 OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
    1313             :             }
    1314             :             else
    1315           0 :                 OutputMapMode = MapMode(MAP_100TH_MM);
    1316           0 :             break;
    1317             : 
    1318             :         case PRINT_SIZE_ZOOMED:
    1319             :         {
    1320           0 :             Fraction aFraction( nZoomFactor, 100 );
    1321             : 
    1322           0 :             OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
    1323           0 :             break;
    1324             :         }
    1325             :     }
    1326             : 
    1327             :     aSize = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aSize, OutputMapMode),
    1328           0 :                                    MapMode(MAP_100TH_MM));
    1329             : 
    1330           0 :     Point aPos (aOutRect.Left() + (aOutRect.GetWidth()  - aSize.Width())  / 2,
    1331           0 :                 aOutRect.Top()  + (aOutRect.GetHeight() - aSize.Height()) / 2);
    1332             : 
    1333           0 :     aPos     = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aPos, MapMode(MAP_100TH_MM)),
    1334           0 :                                           OutputMapMode);
    1335           0 :     aOutRect   = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aOutRect, MapMode(MAP_100TH_MM)),
    1336           0 :                                           OutputMapMode);
    1337             : 
    1338           0 :     rOutDev.SetMapMode(OutputMapMode);
    1339           0 :     rOutDev.SetClipRegion(Region(aOutRect));
    1340           0 :     GetDoc()->DrawFormula(rOutDev, aPos, false);
    1341           0 :     rOutDev.SetClipRegion();
    1342             : 
    1343           0 :     rOutDev.Pop();
    1344           0 : }
    1345             : 
    1346           0 : sal_uInt16 SmViewShell::Print(SfxProgress & /*rProgress*/, sal_Bool /*bIsAPI*/)
    1347             : {
    1348             :     SAL_WARN( "starmath", "SmViewShell::Print: no longer used with new UI print dialog. Should be removed!!" );
    1349           0 :     return 0;
    1350             : }
    1351             : 
    1352             : 
    1353          76 : SfxPrinter* SmViewShell::GetPrinter(bool bCreate)
    1354             : {
    1355             :     SAL_INFO( "starmath", "SmViewShell::GetPrinter" );
    1356             : 
    1357          76 :     SmDocShell *pDoc = GetDoc();
    1358          76 :     if ( pDoc->HasPrinter() || bCreate )
    1359          76 :         return pDoc->GetPrinter();
    1360           0 :     return 0;
    1361             : }
    1362             : 
    1363             : 
    1364           0 : sal_uInt16 SmViewShell::SetPrinter(SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
    1365             : {
    1366             :     SAL_INFO( "starmath", "SmViewShell::SetPrinter" );
    1367           0 :     SfxPrinter *pOld = GetDoc()->GetPrinter();
    1368           0 :     if ( pOld && pOld->IsPrinting() )
    1369           0 :         return SFX_PRINTERROR_BUSY;
    1370             : 
    1371           0 :     if ((nDiffFlags & SFX_PRINTER_PRINTER) == SFX_PRINTER_PRINTER)
    1372           0 :         GetDoc()->SetPrinter( pNewPrinter );
    1373             : 
    1374           0 :     if ((nDiffFlags & SFX_PRINTER_OPTIONS) == SFX_PRINTER_OPTIONS)
    1375             :     {
    1376           0 :         SmModule *pp = SM_MOD();
    1377           0 :         pp->GetConfig()->ItemSetToConfig(pNewPrinter->GetOptions());
    1378             :     }
    1379           0 :     return 0;
    1380             : }
    1381             : 
    1382           0 : bool SmViewShell::HasPrintOptionsPage() const
    1383             : {
    1384           0 :     return true;
    1385             : }
    1386             : 
    1387           0 : SfxTabPage* SmViewShell::CreatePrintOptionsPage(Window *pParent,
    1388             :                                                 const SfxItemSet &rOptions)
    1389             : {
    1390             :     SAL_INFO( "starmath", "SmViewShell::CreatePrintOptionsPage" );
    1391             : 
    1392           0 :     return SmPrintOptionsTabPage::Create(pParent, rOptions);
    1393             : }
    1394             : 
    1395             : 
    1396         290 : SmEditWindow *SmViewShell::GetEditWindow()
    1397             : {
    1398             :     SAL_INFO( "starmath", "SmViewShell::GetEditWindow" );
    1399             : 
    1400             :     SmCmdBoxWrapper *pWrapper = (SmCmdBoxWrapper *) GetViewFrame()->
    1401         290 :             GetChildWindow( SmCmdBoxWrapper::GetChildWindowId() );
    1402             : 
    1403         290 :     if (pWrapper != NULL)
    1404             :     {
    1405         197 :         SmEditWindow *pEditWin  = pWrapper->GetEditWindow();
    1406             :         SAL_WARN_IF( !pEditWin, "starmath", "SmEditWindow missing" );
    1407         197 :         return pEditWin;
    1408             :     }
    1409             : 
    1410          93 :     return NULL;
    1411             : }
    1412             : 
    1413             : 
    1414          21 : void SmViewShell::SetStatusText(const OUString& rText)
    1415             : {
    1416             :     SAL_INFO( "starmath", "SmViewShell::SetStatusText" );
    1417             : 
    1418          21 :     aStatusText = rText;
    1419          21 :     GetViewFrame()->GetBindings().Invalidate(SID_TEXTSTATUS);
    1420          21 : }
    1421             : 
    1422             : 
    1423           0 : void SmViewShell::ShowError( const SmErrorDesc *pErrorDesc )
    1424             : {
    1425             :     SAL_INFO( "starmath", "SmViewShell::ShowError" );
    1426             : 
    1427             :     SAL_WARN_IF( !GetDoc(), "starmath", "Document missing" );
    1428           0 :     if (pErrorDesc || 0 != (pErrorDesc = GetDoc()->GetParser().GetError(0)) )
    1429             :     {
    1430           0 :         SetStatusText( pErrorDesc->Text );
    1431           0 :         GetEditWindow()->MarkError( Point( pErrorDesc->pNode->GetColumn(),
    1432           0 :                                            pErrorDesc->pNode->GetRow()));
    1433             :     }
    1434           0 : }
    1435             : 
    1436             : 
    1437           0 : void SmViewShell::NextError()
    1438             : {
    1439             :     SAL_INFO( "starmath", "SmViewShell::NextError" );
    1440             : 
    1441             :     SAL_WARN_IF( !GetDoc(), "starmath", "Document missing" );
    1442           0 :     const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser().NextError();
    1443             : 
    1444           0 :     if (pErrorDesc)
    1445           0 :         ShowError( pErrorDesc );
    1446           0 : }
    1447             : 
    1448             : 
    1449           0 : void SmViewShell::PrevError()
    1450             : {
    1451             :     SAL_INFO( "starmath", "SmViewShell::PrevError" );
    1452             : 
    1453             :     SAL_WARN_IF( !GetDoc(), "starmath", "Document missing" );
    1454           0 :     const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser().PrevError();
    1455             : 
    1456           0 :     if (pErrorDesc)
    1457           0 :         ShowError( pErrorDesc );
    1458           0 : }
    1459             : 
    1460             : 
    1461           0 : void SmViewShell::Insert( SfxMedium& rMedium )
    1462             : {
    1463             :     SAL_INFO( "starmath", "SmViewShell::Insert" );
    1464             : 
    1465           0 :     SmDocShell *pDoc = GetDoc();
    1466           0 :     bool bRet = false;
    1467             : 
    1468           0 :     uno::Reference < embed::XStorage > xStorage = rMedium.GetStorage();
    1469           0 :     uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
    1470           0 :     if ( xNameAccess.is() && xNameAccess->getElementNames().getLength() )
    1471             :     {
    1472           0 :         if ( xNameAccess->hasByName( OUString("content.xml") ) || xNameAccess->hasByName( OUString("Content.xml") ))
    1473             :         {
    1474             :             // is this a fabulous math package ?
    1475           0 :             Reference<com::sun::star::frame::XModel> xModel(pDoc->GetModel());
    1476           0 :             SmXMLImportWrapper aEquation(xModel);    //!! modifies the result of pDoc->GetText() !!
    1477           0 :             bRet = 0 == aEquation.Import(rMedium);
    1478             :         }
    1479             :     }
    1480             : 
    1481           0 :     if( bRet )
    1482             :     {
    1483           0 :         OUString aText = pDoc->GetText();
    1484           0 :         SmEditWindow *pEditWin = GetEditWindow();
    1485           0 :         if (pEditWin)
    1486           0 :             pEditWin->InsertText( aText );
    1487             :         else
    1488             :         {
    1489             :             SAL_WARN( "starmath", "EditWindow missing" );
    1490             :         }
    1491             : 
    1492           0 :         pDoc->Parse();
    1493           0 :         pDoc->SetModified(true);
    1494             : 
    1495           0 :         SfxBindings &rBnd = GetViewFrame()->GetBindings();
    1496           0 :         rBnd.Invalidate(SID_GAPHIC_SM);
    1497           0 :         rBnd.Invalidate(SID_TEXT);
    1498           0 :     }
    1499           0 : }
    1500             : 
    1501           0 : void SmViewShell::InsertFrom(SfxMedium &rMedium)
    1502             : {
    1503             :     SAL_INFO( "starmath", "SmViewShell::InsertFrom" );
    1504             : 
    1505           0 :     bool        bSuccess = false;
    1506           0 :     SmDocShell *pDoc = GetDoc();
    1507           0 :     SvStream   *pStream = rMedium.GetInStream();
    1508             : 
    1509           0 :     if (pStream)
    1510             :     {
    1511           0 :         const OUString& rFltName = rMedium.GetFilter()->GetFilterName();
    1512           0 :         if ( rFltName == MATHML_XML )
    1513             :         {
    1514           0 :             Reference<com::sun::star::frame::XModel> xModel( pDoc->GetModel() );
    1515           0 :             SmXMLImportWrapper aEquation(xModel);    //!! modifies the result of pDoc->GetText() !!
    1516           0 :             bSuccess = 0 == aEquation.Import(rMedium);
    1517             :         }
    1518             :     }
    1519             : 
    1520           0 :     if( bSuccess )
    1521             :     {
    1522           0 :         OUString aText = pDoc->GetText();
    1523           0 :         SmEditWindow *pEditWin = GetEditWindow();
    1524           0 :         if (pEditWin)
    1525           0 :             pEditWin->InsertText( aText );
    1526             :         else
    1527             :             SAL_WARN( "starmath", "EditWindow missing" );
    1528             : 
    1529           0 :         pDoc->Parse();
    1530           0 :         pDoc->SetModified(true);
    1531             : 
    1532           0 :         SfxBindings &rBnd = GetViewFrame()->GetBindings();
    1533           0 :         rBnd.Invalidate(SID_GAPHIC_SM);
    1534           0 :         rBnd.Invalidate(SID_TEXT);
    1535             :     }
    1536           0 : }
    1537             : 
    1538           8 : void SmViewShell::Execute(SfxRequest& rReq)
    1539             : {
    1540             :     SAL_INFO( "starmath", "SmViewShell::Execute" );
    1541             : 
    1542           8 :     SmEditWindow *pWin = GetEditWindow();
    1543             : 
    1544           8 :     switch (rReq.GetSlot())
    1545             :     {
    1546             :         case SID_FORMULACURSOR:
    1547             :         {
    1548           0 :             SmModule *pp = SM_MOD();
    1549             : 
    1550           0 :             const SfxItemSet  *pArgs = rReq.GetArgs();
    1551             :             const SfxPoolItem *pItem;
    1552             : 
    1553             :             bool  bVal;
    1554           0 :             if ( pArgs &&
    1555           0 :                  SFX_ITEM_SET == pArgs->GetItemState( SID_FORMULACURSOR, false, &pItem))
    1556           0 :                 bVal = ((SfxBoolItem *) pItem)->GetValue();
    1557             :             else
    1558           0 :                 bVal = !pp->GetConfig()->IsShowFormulaCursor();
    1559             : 
    1560           0 :             pp->GetConfig()->SetShowFormulaCursor(bVal);
    1561           0 :             if (!IsInlineEditEnabled())
    1562           0 :                 GetGraphicWindow().ShowCursor(bVal);
    1563           0 :             break;
    1564             :         }
    1565             :         case SID_DRAW:
    1566           0 :             if (pWin)
    1567             :             {
    1568           0 :                 GetDoc()->SetText( pWin->GetText() );
    1569           0 :                 SetStatusText(OUString());
    1570           0 :                 ShowError( 0 );
    1571           0 :                 GetDoc()->Repaint();
    1572             :             }
    1573           0 :             break;
    1574             : 
    1575             :         case SID_ZOOM_OPTIMAL:
    1576           1 :             aGraphic.ZoomToFitInWindow();
    1577           1 :             break;
    1578             : 
    1579             :         case SID_ZOOMIN:
    1580           1 :             aGraphic.SetZoom(aGraphic.GetZoom() + 25);
    1581           1 :             break;
    1582             : 
    1583             :         case SID_ZOOMOUT:
    1584             :             SAL_WARN_IF( aGraphic.GetZoom() < 25, "starmath", "incorrect sal_uInt16 argument" );
    1585           2 :             aGraphic.SetZoom(aGraphic.GetZoom() - 25);
    1586           2 :             break;
    1587             : 
    1588             :         case SID_COPYOBJECT:
    1589             :         {
    1590             :             //TODO/LATER: does not work because of UNO Tunneling - will be fixed later
    1591           0 :             Reference< datatransfer::XTransferable > xTrans( GetDoc()->GetModel(), uno::UNO_QUERY );
    1592           0 :             if( xTrans.is() )
    1593             :             {
    1594           0 :                 Reference< lang::XUnoTunnel> xTnnl( xTrans, uno::UNO_QUERY);
    1595           0 :                 if( xTnnl.is() )
    1596             :                 {
    1597             :                     TransferableHelper* pTrans = reinterpret_cast< TransferableHelper * >(
    1598             :                             sal::static_int_cast< sal_uIntPtr >(
    1599           0 :                             xTnnl->getSomething( TransferableHelper::getUnoTunnelId() )));
    1600           0 :                     if( pTrans )
    1601           0 :                         pTrans->CopyToClipboard(GetEditWindow());
    1602           0 :                 }
    1603           0 :             }
    1604             :         }
    1605           0 :         break;
    1606             : 
    1607             :         case SID_PASTEOBJECT:
    1608             :         {
    1609           0 :             TransferableDataHelper aData( TransferableDataHelper::CreateFromSystemClipboard(GetEditWindow()) );
    1610           0 :             uno::Reference < io::XInputStream > xStrm;
    1611             :             SotFormatStringId nId;
    1612           0 :             if( aData.GetTransferable().is() &&
    1613           0 :                 ( aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
    1614           0 :                   (aData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) &&
    1615           0 :                    aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBED_SOURCE ))) &&
    1616           0 :                 aData.GetInputStream( nId, xStrm ) && xStrm.is() )
    1617             :             {
    1618             :                 try
    1619             :                 {
    1620             :                     uno::Reference < embed::XStorage > xStorage =
    1621           0 :                             ::comphelper::OStorageHelper::GetStorageFromInputStream( xStrm, ::comphelper::getProcessComponentContext() );
    1622           0 :                     uno::Reference < beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY );
    1623           0 :                     SfxMedium aMedium( xStorage, OUString() );
    1624           0 :                     Insert( aMedium );
    1625           0 :                     GetDoc()->UpdateText();
    1626             :                 }
    1627           0 :                 catch (uno::Exception &)
    1628             :                 {
    1629             :                     SAL_WARN( "starmath", "SmViewShell::Execute (SID_PASTEOBJECT): failed to get storage from input stream" );
    1630             :                 }
    1631           0 :             }
    1632             :         }
    1633           0 :         break;
    1634             : 
    1635             : 
    1636             :         case SID_CUT:
    1637           0 :             if (pWin)
    1638           0 :                 pWin->Cut();
    1639           0 :             break;
    1640             : 
    1641             :         case SID_COPY:
    1642           0 :             if (pWin)
    1643             :             {
    1644           0 :                 if (pWin->IsAllSelected())
    1645             :                 {
    1646             :                     GetViewFrame()->GetDispatcher()->Execute(
    1647             :                                 SID_COPYOBJECT, SFX_CALLMODE_STANDARD,
    1648           0 :                                 new SfxVoidItem(SID_COPYOBJECT), 0L);
    1649             :                 }
    1650             :                 else
    1651           0 :                     pWin->Copy();
    1652             :             }
    1653           0 :             break;
    1654             : 
    1655             :         case SID_PASTE:
    1656             :             {
    1657           0 :                 bool bCallExec = 0 == pWin;
    1658           0 :                 if( !bCallExec )
    1659             :                 {
    1660             :                     TransferableDataHelper aDataHelper(
    1661             :                         TransferableDataHelper::CreateFromSystemClipboard(
    1662           0 :                                                     GetEditWindow()) );
    1663             : 
    1664           0 :                     if( aDataHelper.GetTransferable().is() &&
    1665           0 :                         aDataHelper.HasFormat( FORMAT_STRING ))
    1666           0 :                         pWin->Paste();
    1667             :                     else
    1668           0 :                         bCallExec = true;
    1669             :                 }
    1670           0 :                 if( bCallExec )
    1671             :                 {
    1672             :                     GetViewFrame()->GetDispatcher()->Execute(
    1673             :                             SID_PASTEOBJECT, SFX_CALLMODE_STANDARD,
    1674           0 :                             new SfxVoidItem(SID_PASTEOBJECT), 0L);
    1675             :                 }
    1676             :             }
    1677           0 :             break;
    1678             : 
    1679             :         case SID_DELETE:
    1680           0 :             if (pWin)
    1681           0 :                 pWin->Delete();
    1682           0 :             break;
    1683             : 
    1684             :         case SID_SELECT:
    1685           0 :             if (pWin)
    1686           0 :                 pWin->SelectAll();
    1687           0 :             break;
    1688             : 
    1689             :         case SID_INSERTCOMMAND:
    1690             :         {
    1691             :             const SfxInt16Item& rItem =
    1692           0 :                 (const SfxInt16Item&)rReq.GetArgs()->Get(SID_INSERTCOMMAND);
    1693             : 
    1694           0 :             if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
    1695           0 :                 pWin->InsertCommand(rItem.GetValue());
    1696           0 :             if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow)) {
    1697           0 :                 GetDoc()->GetCursor().InsertCommand(rItem.GetValue());
    1698           0 :                 GetGraphicWindow().GrabFocus();
    1699             :             }
    1700           0 :             break;
    1701             :         }
    1702             : 
    1703             :         case SID_INSERTCOMMANDTEXT:
    1704             :         {
    1705           0 :             const SfxStringItem& rItem = (const SfxStringItem&)rReq.GetArgs()->Get(SID_INSERTCOMMANDTEXT);
    1706             : 
    1707           0 :             if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
    1708             :             {
    1709           0 :                 pWin->InsertText(rItem.GetValue());
    1710             :             }
    1711           0 :             if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow))
    1712             :             {
    1713           0 :                 GetDoc()->GetCursor().InsertCommandText(rItem.GetValue());
    1714           0 :                 GetGraphicWindow().GrabFocus();
    1715             :             }
    1716           0 :             break;
    1717             : 
    1718             :         }
    1719             : 
    1720             :         case SID_INSERTSYMBOL:
    1721             :         {
    1722             :             const SfxStringItem& rItem =
    1723           0 :                 (const SfxStringItem&)rReq.GetArgs()->Get(SID_INSERTSYMBOL);
    1724             : 
    1725           0 :             if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
    1726           0 :                 pWin->InsertText(rItem.GetValue());
    1727           0 :             if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow))
    1728           0 :                 GetDoc()->GetCursor().InsertSpecial(rItem.GetValue());
    1729           0 :             break;
    1730             :         }
    1731             : 
    1732             :         case SID_IMPORT_FORMULA:
    1733             :         {
    1734           0 :             delete pImpl->pRequest;
    1735           0 :             pImpl->pRequest = new SfxRequest( rReq );
    1736           0 :             delete pImpl->pDocInserter;
    1737             :             pImpl->pDocInserter = new ::sfx2::DocumentInserter(
    1738           0 :                         GetDoc()->GetFactory().GetFactoryName(), false );
    1739           0 :             pImpl->pDocInserter->StartExecuteModal( LINK( this, SmViewShell, DialogClosedHdl ) );
    1740           0 :             break;
    1741             :         }
    1742             : 
    1743             :         case SID_NEXTERR:
    1744           0 :             NextError();
    1745           0 :             if (pWin)
    1746           0 :                 pWin->GrabFocus();
    1747           0 :             break;
    1748             : 
    1749             :         case SID_PREVERR:
    1750           0 :             PrevError();
    1751           0 :             if (pWin)
    1752           0 :                 pWin->GrabFocus();
    1753           0 :             break;
    1754             : 
    1755             :         case SID_NEXTMARK:
    1756           0 :             if (pWin)
    1757             :             {
    1758           0 :                 pWin->SelNextMark();
    1759           0 :                 pWin->GrabFocus();
    1760             :             }
    1761           0 :             break;
    1762             : 
    1763             :         case SID_PREVMARK:
    1764           0 :             if (pWin)
    1765             :             {
    1766           0 :                 pWin->SelPrevMark();
    1767           0 :                 pWin->GrabFocus();
    1768             :             }
    1769           0 :             break;
    1770             : 
    1771             :         case SID_TEXTSTATUS:
    1772             :         {
    1773           0 :             if (rReq.GetArgs() != NULL)
    1774             :             {
    1775             :                 const SfxStringItem& rItem =
    1776           0 :                     (const SfxStringItem&)rReq.GetArgs()->Get(SID_TEXTSTATUS);
    1777             : 
    1778           0 :                 SetStatusText(rItem.GetValue());
    1779             :             }
    1780             : 
    1781           0 :             break;
    1782             :         }
    1783             : 
    1784             :         case SID_GETEDITTEXT:
    1785           0 :             if (pWin)
    1786           0 :                 if (!pWin->GetText().isEmpty()) GetDoc()->SetText( pWin->GetText() );
    1787           0 :             break;
    1788             : 
    1789             :         case SID_ATTR_ZOOM:
    1790             :         {
    1791           4 :             if ( !GetViewFrame()->GetFrame().IsInPlace() )
    1792             :             {
    1793           4 :                 AbstractSvxZoomDialog *pDlg = 0;
    1794           4 :                 const SfxItemSet *pSet = rReq.GetArgs();
    1795           4 :                 if ( !pSet )
    1796             :                 {
    1797           0 :                     SfxItemSet aSet( GetDoc()->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
    1798           0 :                     aSet.Put( SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
    1799           0 :                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    1800           0 :                     if(pFact)
    1801             :                     {
    1802           0 :                         pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aSet);
    1803             :                         SAL_WARN_IF( !pDlg, "starmath", "Dialogdiet fail!" );
    1804           0 :                         pDlg->SetLimits( MINZOOM, MAXZOOM );
    1805           0 :                         if( pDlg->Execute() != RET_CANCEL )
    1806           0 :                             pSet = pDlg->GetOutputItemSet();
    1807           0 :                     }
    1808             :                 }
    1809           4 :                 if ( pSet )
    1810             :                 {
    1811           4 :                     const SvxZoomItem &rZoom = (const SvxZoomItem &)pSet->Get(SID_ATTR_ZOOM);
    1812           4 :                     switch( rZoom.GetType() )
    1813             :                     {
    1814             :                         case SVX_ZOOM_PERCENT:
    1815           3 :                             aGraphic.SetZoom((sal_uInt16)rZoom.GetValue ());
    1816           3 :                             break;
    1817             : 
    1818             :                         case SVX_ZOOM_OPTIMAL:
    1819           1 :                             aGraphic.ZoomToFitInWindow();
    1820           1 :                             break;
    1821             : 
    1822             :                         case SVX_ZOOM_PAGEWIDTH:
    1823             :                         case SVX_ZOOM_WHOLEPAGE:
    1824             :                         {
    1825           0 :                             const MapMode aMap( MAP_100TH_MM );
    1826           0 :                             SfxPrinter *pPrinter = GetPrinter( true );
    1827           0 :                             Point aPoint;
    1828           0 :                             Rectangle  OutputRect(aPoint, pPrinter->GetOutputSize());
    1829             :                             Size       OutputSize(pPrinter->LogicToPixel(Size(OutputRect.GetWidth(),
    1830           0 :                                                                               OutputRect.GetHeight()), aMap));
    1831           0 :                             Size       GraphicSize(pPrinter->LogicToPixel(GetDoc()->GetSize(), aMap));
    1832           0 :                             sal_uInt16     nZ = (sal_uInt16) std::min((long)Fraction(OutputSize.Width()  * 100L, GraphicSize.Width()),
    1833           0 :                                                          (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
    1834           0 :                             aGraphic.SetZoom (nZ);
    1835           0 :                             break;
    1836             :                         }
    1837             :                         default:
    1838           0 :                             break;
    1839             :                     }
    1840             :                 }
    1841           4 :                 delete pDlg;
    1842             :             }
    1843             :         }
    1844           4 :         break;
    1845             : 
    1846             :         case SID_ATTR_ZOOMSLIDER:
    1847             :         {
    1848           0 :             const SfxItemSet *pArgs = rReq.GetArgs();
    1849             :             const SfxPoolItem* pItem;
    1850             : 
    1851           0 :             if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) )
    1852             :             {
    1853           0 :                 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
    1854           0 :                 aGraphic.SetZoom( nCurrentZoom );
    1855             :             }
    1856             :         }
    1857           0 :         break;
    1858             : 
    1859             :         case SID_TOOLBOX:
    1860             :         {
    1861           0 :             GetViewFrame()->ToggleChildWindow( SmToolBoxWrapper::GetChildWindowId() );
    1862             :         }
    1863           0 :         break;
    1864             : 
    1865             :         case SID_ELEMENTSDOCKINGWINDOW:
    1866             :         {
    1867           0 :             GetViewFrame()->ToggleChildWindow( SmElementsDockingWindowWrapper::GetChildWindowId() );
    1868           0 :             GetViewFrame()->GetBindings().Invalidate( SID_ELEMENTSDOCKINGWINDOW );
    1869             : 
    1870           0 :             rReq.Ignore ();
    1871             :         }
    1872           0 :         break;
    1873             : 
    1874             :         case SID_SYMBOLS_CATALOGUE:
    1875             :         {
    1876             : 
    1877             :             // get device used to retrieve the FontList
    1878           0 :             SmDocShell *pDoc = GetDoc();
    1879           0 :             OutputDevice *pDev = pDoc->GetPrinter();
    1880           0 :             if (!pDev || pDev->GetDevFontCount() == 0)
    1881           0 :                 pDev = &SM_MOD()->GetDefaultVirtualDev();
    1882             :             SAL_WARN_IF( !pDev, "starmath", "device for font list missing" );
    1883             : 
    1884           0 :             SmModule *pp = SM_MOD();
    1885           0 :             SmSymbolDialog( NULL, pDev, pp->GetSymbolManager(), *this ).Execute();
    1886             :         }
    1887           0 :         break;
    1888             :     }
    1889           8 :     rReq.Done();
    1890           8 : }
    1891             : 
    1892             : 
    1893         205 : void SmViewShell::GetState(SfxItemSet &rSet)
    1894             : {
    1895             :     SAL_INFO( "starmath", "SmViewShell::GetState" );
    1896             : 
    1897         205 :     SfxWhichIter aIter(rSet);
    1898             : 
    1899         205 :     SmEditWindow *pEditWin = GetEditWindow();
    1900         490 :     for (sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich())
    1901             :     {
    1902         285 :         switch (nWh)
    1903             :         {
    1904             :         case SID_CUT:
    1905             :         case SID_COPY:
    1906             :         case SID_DELETE:
    1907          42 :             if (! pEditWin || ! pEditWin->IsSelected())
    1908          42 :                 rSet.DisableItem(nWh);
    1909          42 :             break;
    1910             : 
    1911             :         case SID_PASTE:
    1912          21 :             if (pEditWin)
    1913             :             {
    1914             :                 TransferableDataHelper aDataHelper(
    1915             :                         TransferableDataHelper::CreateFromSystemClipboard(
    1916          21 :                                                         pEditWin) );
    1917             : 
    1918          21 :                 bPasteState = aDataHelper.GetTransferable().is() &&
    1919           0 :                  ( aDataHelper.HasFormat( FORMAT_STRING ) ||
    1920           0 :                    aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
    1921           0 :                    (aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
    1922          21 :                       && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE )));
    1923             :             }
    1924          21 :             if( !bPasteState )
    1925          21 :                 rSet.DisableItem( nWh );
    1926          21 :             break;
    1927             : 
    1928             :         case SID_ATTR_ZOOM:
    1929          67 :             rSet.Put(SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
    1930             :             /* no break here */
    1931             :         case SID_ZOOMIN:
    1932             :         case SID_ZOOMOUT:
    1933             :         case SID_ZOOM_OPTIMAL:
    1934         109 :             if ( GetViewFrame()->GetFrame().IsInPlace() )
    1935           0 :                 rSet.DisableItem( nWh );
    1936         109 :             break;
    1937             : 
    1938             :         case SID_ATTR_ZOOMSLIDER :
    1939             :             {
    1940          25 :                 const sal_uInt16 nCurrentZoom = aGraphic.GetZoom();
    1941          25 :                 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM );
    1942          25 :                 aZoomSliderItem.AddSnappingPoint( 100 );
    1943          25 :                 rSet.Put( aZoomSliderItem );
    1944             :             }
    1945          25 :         break;
    1946             : 
    1947             :         case SID_NEXTERR:
    1948             :         case SID_PREVERR:
    1949             :         case SID_NEXTMARK:
    1950             :         case SID_PREVMARK:
    1951             :         case SID_DRAW:
    1952             :         case SID_SELECT:
    1953          21 :             if (! pEditWin || pEditWin->IsEmpty())
    1954          16 :                 rSet.DisableItem(nWh);
    1955          21 :             break;
    1956             : 
    1957             :         case SID_TEXTSTATUS:
    1958             :             {
    1959          25 :                 rSet.Put(SfxStringItem(nWh, aStatusText));
    1960             :             }
    1961          25 :             break;
    1962             : 
    1963             :         case SID_FORMULACURSOR:
    1964             :             {
    1965          21 :                 SmModule *pp = SM_MOD();
    1966          21 :                 rSet.Put(SfxBoolItem(nWh, pp->GetConfig()->IsShowFormulaCursor()));
    1967             :             }
    1968          21 :             break;
    1969             :         case SID_ELEMENTSDOCKINGWINDOW:
    1970             :             {
    1971           0 :                 bool bState = false;
    1972             :                 SfxChildWindow *pChildWnd = GetViewFrame()->
    1973           0 :                         GetChildWindow( SmElementsDockingWindowWrapper::GetChildWindowId() );
    1974           0 :                 if (pChildWnd  &&  pChildWnd->GetWindow()->IsVisible())
    1975           0 :                     bState = true;
    1976           0 :                 rSet.Put(SfxBoolItem(SID_ELEMENTSDOCKINGWINDOW, bState));
    1977             :             }
    1978           0 :             break;
    1979             :         case SID_TOOLBOX:
    1980             :             {
    1981           0 :                 bool bState = false;
    1982             :                 SfxChildWindow *pChildWnd = GetViewFrame()->
    1983           0 :                         GetChildWindow( SmToolBoxWrapper::GetChildWindowId() );
    1984           0 :                 if (pChildWnd  &&  pChildWnd->GetWindow()->IsVisible())
    1985           0 :                     bState = true;
    1986           0 :                 rSet.Put(SfxBoolItem(SID_TOOLBOX, bState));
    1987             :             }
    1988           0 :             break;
    1989             : 
    1990             :         }
    1991         205 :     }
    1992         205 : }
    1993             : 
    1994             : 
    1995          21 : SmViewShell::SmViewShell(SfxViewFrame *pFrame_, SfxViewShell *)
    1996             :     : SfxViewShell(pFrame_, SFX_VIEW_HAS_PRINTOPTIONS | SFX_VIEW_CAN_PRINT)
    1997          21 :     , pImpl(new SmViewShell_Impl)
    1998             :     , aGraphic(this)
    1999          21 :     , aGraphicController(aGraphic, SID_GAPHIC_SM, pFrame_->GetBindings())
    2000             :     , bPasteState(false)
    2001          63 :     , bInsertIntoEditWindow(false)
    2002             : {
    2003             :     SAL_INFO( "starmath", "SmViewShell::SmViewShell" );
    2004             : 
    2005          21 :     SetStatusText(OUString());
    2006          21 :     SetWindow(&aGraphic);
    2007          21 :     SfxShell::SetName(OUString("SmView"));
    2008          21 :     SfxShell::SetUndoManager( &GetDoc()->GetEditEngine().GetUndoManager() );
    2009          21 :     SetHelpId( HID_SMA_VIEWSHELL_DOCUMENT );
    2010          21 : }
    2011             : 
    2012             : 
    2013          51 : SmViewShell::~SmViewShell()
    2014             : {
    2015             :     SAL_INFO( "starmath", "SmViewShell::~SmViewShell" );
    2016             : 
    2017             :     //!! this view shell is not active anymore !!
    2018             :     // Thus 'SmGetActiveView' will give a 0 pointer.
    2019             :     // Thus we need to supply this view as argument
    2020          17 :     SmEditWindow *pEditWin = GetEditWindow();
    2021          17 :     if (pEditWin)
    2022           0 :         pEditWin->DeleteEditView( *this );
    2023          17 :     delete pImpl;
    2024          34 : }
    2025             : 
    2026          17 : void SmViewShell::Deactivate( bool bIsMDIActivate )
    2027             : {
    2028             :     SAL_INFO( "starmath", "SmViewShell::Deactivate" );
    2029             : 
    2030          17 :     SmEditWindow *pEdit = GetEditWindow();
    2031          17 :     if ( pEdit )
    2032           0 :         pEdit->Flush();
    2033             : 
    2034          17 :     SfxViewShell::Deactivate( bIsMDIActivate );
    2035          17 : }
    2036             : 
    2037             : 
    2038          17 : void SmViewShell::Activate( bool bIsMDIActivate )
    2039             : {
    2040             :     SAL_INFO( "starmath", "SmViewShell::Activate" );
    2041             : 
    2042          17 :     SfxViewShell::Activate( bIsMDIActivate );
    2043             : 
    2044          17 :     SmEditWindow *pEdit = GetEditWindow();
    2045          17 :     if ( pEdit )
    2046             :     {
    2047             :         //! Since there is no way to be informed if a "drag and drop"
    2048             :         //! event has taken place, we call SetText here in order to
    2049             :         //! syncronize the GraphicWindow display with the text in the
    2050             :         //! EditEngine.
    2051          17 :         SmDocShell *pDoc = GetDoc();
    2052          17 :         pDoc->SetText( pDoc->GetEditEngine().GetText( LINEEND_LF ) );
    2053             : 
    2054          17 :         if ( bIsMDIActivate )
    2055          17 :             pEdit->GrabFocus();
    2056             :     }
    2057          17 : }
    2058             : 
    2059           0 : IMPL_LINK( SmViewShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
    2060             : {
    2061             :     SAL_WARN_IF( !_pFileDlg, "starmath", "SmViewShell::DialogClosedHdl(): no file dialog" );
    2062             :     SAL_WARN_IF( !pImpl->pDocInserter, "starmath", "ScDocShell::DialogClosedHdl(): no document inserter" );
    2063             : 
    2064           0 :     if ( ERRCODE_NONE == _pFileDlg->GetError() )
    2065             :     {
    2066           0 :         SfxMedium* pMedium = pImpl->pDocInserter->CreateMedium();
    2067             : 
    2068           0 :         if ( pMedium != NULL )
    2069             :         {
    2070           0 :             if ( pMedium->IsStorage() )
    2071           0 :                 Insert( *pMedium );
    2072             :             else
    2073           0 :                 InsertFrom( *pMedium );
    2074           0 :             delete pMedium;
    2075             : 
    2076           0 :             SmDocShell* pDoc = GetDoc();
    2077           0 :             pDoc->UpdateText();
    2078           0 :             pDoc->ArrangeFormula();
    2079           0 :             pDoc->Repaint();
    2080             :             // adjust window, repaint, increment ModifyCount,...
    2081           0 :             GetViewFrame()->GetBindings().Invalidate(SID_GAPHIC_SM);
    2082             :         }
    2083             :     }
    2084             : 
    2085           0 :     pImpl->pRequest->SetReturnValue( SfxBoolItem( pImpl->pRequest->GetSlot(), true ) );
    2086           0 :     pImpl->pRequest->Done();
    2087           0 :     return 0;
    2088             : }
    2089             : 
    2090         273 : void SmViewShell::Notify( SfxBroadcaster& , const SfxHint& rHint )
    2091             : {
    2092         273 :     if ( rHint.IsA(TYPE(SfxSimpleHint)) )
    2093             :     {
    2094         133 :         switch( ( (SfxSimpleHint&) rHint ).GetId() )
    2095             :         {
    2096             :             case SFX_HINT_MODECHANGED:
    2097             :             case SFX_HINT_DOCCHANGED:
    2098          85 :                 GetViewFrame()->GetBindings().InvalidateAll(false);
    2099          85 :                 break;
    2100             :             default:
    2101          48 :                 break;
    2102             :         }
    2103             :     }
    2104         273 : }
    2105             : 
    2106         218 : bool SmViewShell::IsInlineEditEnabled() const
    2107             : {
    2108         218 :     return pImpl->aOpts.IsExperimentalMode();
    2109          27 : }
    2110             : 
    2111             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10