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