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