fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / starmath / source / view.cxx
blobd0272aabb14083fc5d41af9b8711df5150333209
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
21 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
22 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
23 #include <com/sun/star/accessibility/XAccessible.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/frame/Desktop.hpp>
26 #include <com/sun/star/frame/XFramesSupplier.hpp>
27 #include <com/sun/star/container/XChild.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/storagehelper.hxx>
31 #include <comphelper/string.hxx>
32 #include <rtl/logfile.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <sfx2/docfilt.hxx>
37 #include <sfx2/docinsert.hxx>
38 #include <sfx2/filedlghelper.hxx>
39 #include <sfx2/msg.hxx>
40 #include <sfx2/objface.hxx>
41 #include <sfx2/printer.hxx>
42 #include <sfx2/request.hxx>
43 #include <svl/eitem.hxx>
44 #include <svl/intitem.hxx>
45 #include <svl/itemset.hxx>
46 #include <svl/poolitem.hxx>
47 #include <svl/ptitem.hxx>
48 #include <svl/stritem.hxx>
49 #include <svtools/transfer.hxx>
50 #include <svtools/miscopt.hxx>
51 #include <svl/undo.hxx>
52 #include <svl/whiter.hxx>
53 #include <svx/dialogs.hrc>
54 #include <editeng/editeng.hxx>
55 #include <svx/svxdlg.hxx>
56 #include <sfx2/zoomitem.hxx>
57 #include <vcl/decoview.hxx>
58 #include <vcl/menu.hxx>
59 #include <vcl/msgbox.hxx>
60 #include <vcl/wrkwin.hxx>
61 #include <fstream>
63 #include "unomodel.hxx"
64 #include "view.hxx"
65 #include "config.hxx"
66 #include "dialog.hxx"
67 #include "document.hxx"
68 #include "starmath.hrc"
69 #include "toolbox.hxx"
70 #include "mathmlimport.hxx"
71 #include "cursor.hxx"
72 #include "accessibility.hxx"
73 #include "ElementsDockingWindow.hxx"
75 #define MINZOOM 25
76 #define MAXZOOM 800
78 // space around the edit window, in pixels
79 #define CMD_BOX_PADDING 10
81 #define SmViewShell
82 #include "smslots.hxx"
84 using namespace com::sun::star;
85 using namespace com::sun::star::accessibility;
86 using namespace com::sun::star::uno;
88 //////////////////////////////////////////////////////////////////////
90 SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell):
91 ScrollableWindow(&pShell->GetViewFrame()->GetWindow(), 0),
92 pAccessible(0),
93 pViewShell(pShell),
94 nZoom(100)
96 // docking windows are usually hidden (often already done in the
97 // resource) and will be shown by the sfx framework.
98 Hide();
100 const Fraction aFraction (1,1);
101 SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction));
103 ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
105 SetTotalSize();
107 SetHelpId(HID_SMA_WIN_DOCUMENT);
108 SetUniqueId(HID_SMA_WIN_DOCUMENT);
110 ShowLine(false);
111 CaretBlinkInit();
114 SmGraphicWindow::~SmGraphicWindow()
116 if (pAccessible)
117 pAccessible->ClearWin(); // make Accessible defunctional
118 // Note: memory for pAccessible will be freed when the reference
119 // xAccessible is released.
120 CaretBlinkStop();
123 void SmGraphicWindow::StateChanged( StateChangedType eType )
125 if ( eType == STATE_CHANGE_INITSHOW )
126 Show();
127 ScrollableWindow::StateChanged( eType );
131 void SmGraphicWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
133 // Note: SetTextColor not necessary since the nodes that
134 // get painted have the color information.
135 #if OSL_DEBUG_LEVEL > 1
136 // ColorData nVal = rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor;
137 #endif
138 SetBackground( Color( (ColorData) rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor ) );
139 Invalidate();
143 void SmGraphicWindow::DataChanged( const DataChangedEvent& rEvt )
145 ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
147 ScrollableWindow::DataChanged( rEvt );
151 void SmGraphicWindow::MouseButtonDown(const MouseEvent& rMEvt)
153 ScrollableWindow::MouseButtonDown(rMEvt);
155 GrabFocus();
158 // set formula-cursor and selection of edit window according to the
159 // position clicked at
161 OSL_ENSURE(rMEvt.GetClicks() > 0, "Sm : 0 clicks");
162 if ( rMEvt.IsLeft() )
164 // get click position relativ to formula
165 Point aPos (PixelToLogic(rMEvt.GetPosPixel())
166 - GetFormulaDrawPos());
168 const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
169 if (!pTree)
170 return;
172 if (IsInlineEditEnabled()) {
173 pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, !rMEvt.IsShift());
174 return;
176 const SmNode *pNode = 0;
177 // if it was clicked inside the formula then get the appropriate node
178 if (pTree->OrientedDist(aPos) <= 0)
179 pNode = pTree->FindRectClosestTo(aPos);
181 if (pNode)
182 { SmEditWindow *pEdit = pViewShell->GetEditWindow();
183 if (!pEdit)
184 return;
185 const SmToken aToken (pNode->GetToken());
187 // set selection to the beginning of the token
188 ESelection aSel (aToken.nRow - 1, aToken.nCol - 1);
190 if (rMEvt.GetClicks() != 1 || aToken.eType == TPLACE)
191 aSel.nEndPos = aSel.nEndPos + sal::static_int_cast< sal_uInt16 >(aToken.aText.getLength());
193 pEdit->SetSelection(aSel);
194 SetCursor(pNode);
196 // allow for immediate editing and
197 //! implicitly synchronize the cursor position mark in this window
198 pEdit->GrabFocus();
203 void SmGraphicWindow::MouseMove(const MouseEvent &rMEvt)
205 ScrollableWindow::MouseMove(rMEvt);
207 if (rMEvt.IsLeft() && IsInlineEditEnabled())
209 Point aPos(PixelToLogic(rMEvt.GetPosPixel()) - GetFormulaDrawPos());
210 pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, false);
212 CaretBlinkStop();
213 SetIsCursorVisible(true);
214 CaretBlinkStart();
215 RepaintViewShellDoc();
219 bool SmGraphicWindow::IsInlineEditEnabled() const
221 return pViewShell->IsInlineEditEnabled();
224 void SmGraphicWindow::GetFocus()
226 if (!IsInlineEditEnabled())
227 return;
228 if (pViewShell->GetEditWindow())
229 pViewShell->GetEditWindow()->Flush();
230 //Let view shell know what insertions should be done in visual editor
231 pViewShell->SetInsertIntoEditWindow(false);
232 SetIsCursorVisible(true);
233 ShowLine(true);
234 CaretBlinkStart();
235 RepaintViewShellDoc();
238 void SmGraphicWindow::LoseFocus()
240 ScrollableWindow::LoseFocus();
241 if (xAccessible.is())
243 uno::Any aOldValue, aNewValue;
244 aOldValue <<= AccessibleStateType::FOCUSED;
245 // aNewValue remains empty
246 pAccessible->LaunchEvent( AccessibleEventId::STATE_CHANGED,
247 aOldValue, aNewValue );
249 if (!IsInlineEditEnabled())
250 return;
251 SetIsCursorVisible(false);
252 ShowLine(false);
253 CaretBlinkStop();
254 RepaintViewShellDoc();
257 void SmGraphicWindow::RepaintViewShellDoc()
259 SmDocShell &rDoc = *pViewShell->GetDoc();
260 rDoc.Repaint();
263 IMPL_LINK_NOARG(SmGraphicWindow, CaretBlinkTimerHdl)
265 if (IsCursorVisible())
266 SetIsCursorVisible(false);
267 else
268 SetIsCursorVisible(true);
270 RepaintViewShellDoc();
272 return 0;
275 void SmGraphicWindow::CaretBlinkInit()
277 aCaretBlinkTimer.SetTimeoutHdl(LINK(this, SmGraphicWindow, CaretBlinkTimerHdl));
278 aCaretBlinkTimer.SetTimeout( ScrollableWindow::GetSettings().GetStyleSettings().GetCursorBlinkTime() );
281 void SmGraphicWindow::CaretBlinkStart()
283 if (!IsInlineEditEnabled())
284 return;
285 if ( aCaretBlinkTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME )
286 aCaretBlinkTimer.Start();
289 void SmGraphicWindow::CaretBlinkStop()
291 if (!IsInlineEditEnabled())
292 return;
293 aCaretBlinkTimer.Stop();
296 void SmGraphicWindow::ShowCursor(bool bShow)
297 // shows or hides the formula-cursor depending on 'bShow' is true or not
299 if (IsInlineEditEnabled())
300 return;
302 bool bInvert = bShow != IsCursorVisible();
304 if (bInvert)
305 InvertTracking(aCursorRect, SHOWTRACK_SMALL | SHOWTRACK_WINDOW);
307 SetIsCursorVisible(bShow);
310 void SmGraphicWindow::ShowLine(bool bShow)
312 if (!IsInlineEditEnabled())
313 return;
315 bIsLineVisible = bShow;
318 void SmGraphicWindow::SetCursor(const SmNode *pNode)
320 if (IsInlineEditEnabled())
321 return;
323 const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
325 // get appropriate rectangle
326 Point aOffset (pNode->GetTopLeft() - pTree->GetTopLeft()),
327 aTLPos (GetFormulaDrawPos() + aOffset);
328 aTLPos.X() -= pNode->GetItalicLeftSpace();
329 Size aSize (pNode->GetItalicSize());
331 SetCursor(Rectangle(aTLPos, aSize));
334 void SmGraphicWindow::SetCursor(const Rectangle &rRect)
335 // sets cursor to new position (rectangle) 'rRect'.
336 // The old cursor will be removed, and the new one will be shown if
337 // that is activated in the ConfigItem
339 if (IsInlineEditEnabled())
340 return;
342 SmModule *pp = SM_MOD();
344 if (IsCursorVisible())
345 ShowCursor(false); // clean up remainings of old cursor
346 aCursorRect = rRect;
347 if (pp->GetConfig()->IsShowFormulaCursor())
348 ShowCursor(true); // draw new cursor
351 const SmNode * SmGraphicWindow::SetCursorPos(sal_uInt16 nRow, sal_uInt16 nCol)
352 // looks for a VISIBLE node in the formula tree with it's token at
353 // (or around) the position 'nRow', 'nCol' in the edit window
354 // (row and column numbering starts with 1 there!).
355 // If there is such a node the formula-cursor is set to cover that nodes
356 // rectangle. If not the formula-cursor will be hidden.
357 // In any case the search result is being returned.
359 if (IsInlineEditEnabled())
360 return NULL;
362 // find visible node with token at nRow, nCol
363 const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree(),
364 *pNode = 0;
365 if (pTree)
366 pNode = pTree->FindTokenAt(nRow, nCol);
368 if (pNode)
369 SetCursor(pNode);
370 else
371 ShowCursor(false);
373 return pNode;
376 void SmGraphicWindow::Paint(const Rectangle&)
378 OSL_ENSURE(pViewShell, "Sm : NULL pointer");
380 SmDocShell &rDoc = *pViewShell->GetDoc();
381 Point aPoint;
383 rDoc.DrawFormula(*this, aPoint, true); //! modifies aPoint to be the topleft
384 //! corner of the formula
385 SetFormulaDrawPos(aPoint);
386 if(IsInlineEditEnabled())
388 //Draw cursor if any...
389 if(pViewShell->GetDoc()->HasCursor() && IsLineVisible())
390 pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint, IsCursorVisible());
392 else
394 SetIsCursorVisible(false); // (old) cursor must be drawn again
396 const SmEditWindow *pEdit = pViewShell->GetEditWindow();
397 if (pEdit)
398 { // get new position for formula-cursor (for possible altered formula)
399 sal_Int32 nRow;
400 sal_uInt16 nCol;
401 SmGetLeftSelectionPart(pEdit->GetSelection(), nRow, nCol);
402 nRow++;
403 nCol++;
404 const SmNode *pFound = SetCursorPos(static_cast<sal_uInt16>(nRow), nCol);
406 SmModule *pp = SM_MOD();
407 if (pFound && pp->GetConfig()->IsShowFormulaCursor())
408 ShowCursor(true);
414 void SmGraphicWindow::SetTotalSize ()
416 SmDocShell &rDoc = *pViewShell->GetDoc();
417 const Size aTmp( PixelToLogic( LogicToPixel( rDoc.GetSize() )));
418 if ( aTmp != ScrollableWindow::GetTotalSize() )
419 ScrollableWindow::SetTotalSize( aTmp );
422 void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
424 if (!IsInlineEditEnabled()) {
425 if (! (GetView() && GetView()->KeyInput(rKEvt)) )
426 ScrollableWindow::KeyInput(rKEvt);
427 return;
430 SmCursor& rCursor = pViewShell->GetDoc()->GetCursor();
431 KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction();
432 if (eFunc == KEYFUNC_COPY)
433 rCursor.Copy();
434 else if (eFunc == KEYFUNC_CUT)
435 rCursor.Cut();
436 else if (eFunc == KEYFUNC_PASTE)
437 rCursor.Paste();
438 else {
439 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
440 switch(nCode)
442 case KEY_LEFT:
444 rCursor.Move(this, MoveLeft, !rKEvt.GetKeyCode().IsShift());
445 }break;
446 case KEY_RIGHT:
448 rCursor.Move(this, MoveRight, !rKEvt.GetKeyCode().IsShift());
449 }break;
450 case KEY_UP:
452 rCursor.Move(this, MoveUp, !rKEvt.GetKeyCode().IsShift());
453 }break;
454 case KEY_DOWN:
456 rCursor.Move(this, MoveDown, !rKEvt.GetKeyCode().IsShift());
457 }break;
458 case KEY_RETURN:
460 if(!rKEvt.GetKeyCode().IsShift())
461 rCursor.InsertRow();
462 #ifdef DEBUG_ENABLE_DUMPASDOT
463 else {
464 SmNode *pTree = (SmNode*)pViewShell->GetDoc()->GetFormulaTree();
465 std::fstream file("/tmp/smath-dump.gv", std::fstream::out);
466 OUString label(pViewShell->GetDoc()->GetText());
467 pTree->DumpAsDot(file, &label);
468 file.close();
470 #endif /* DEBUG_ENABLE_DUMPASDOT */
471 }break;
472 case KEY_DELETE:
474 if(!rCursor.HasSelection()){
475 rCursor.Move(this, nCode == KEY_DELETE ? MoveRight : MoveLeft, false);
476 if(rCursor.HasComplexSelection()) break;
478 rCursor.Delete();
479 }break;
480 case KEY_BACKSPACE:
482 rCursor.DeletePrev(this);
483 }break;
484 case KEY_ADD:
485 rCursor.InsertElement(PlusElement);
486 break;
487 case KEY_SUBTRACT:
488 if(rKEvt.GetKeyCode().IsShift())
489 rCursor.InsertSubSup(RSUB);
490 else
491 rCursor.InsertElement(MinusElement);
492 break;
493 case KEY_MULTIPLY:
494 rCursor.InsertElement(CDotElement);
495 break;
496 case KEY_DIVIDE:
497 rCursor.InsertFraction();
498 break;
499 case KEY_LESS:
500 rCursor.InsertElement(LessThanElement);
501 break;
502 case KEY_GREATER:
503 rCursor.InsertElement(GreaterThanElement);
504 break;
505 case KEY_EQUAL:
506 rCursor.InsertElement(EqualElement);
507 break;
508 default:
510 sal_Unicode code = rKEvt.GetCharCode();
511 SmBraceNode* pBraceNode = NULL;
513 if(code == ' ') {
514 rCursor.InsertElement(BlankElement);
515 }else if(code == '^') {
516 rCursor.InsertSubSup(RSUP);
517 }else if(code == '(') {
518 rCursor.InsertBrackets(RoundBrackets);
519 }else if(code == '[') {
520 rCursor.InsertBrackets(SquareBrackets);
521 }else if(code == '{') {
522 rCursor.InsertBrackets(CurlyBrackets);
523 }else if(code == '!') {
524 rCursor.InsertElement(FactorialElement);
525 }else if(code == '%') {
526 rCursor.InsertElement(PercentElement);
527 }else if(code == ')' && rCursor.IsAtTailOfBracket(RoundBrackets, &pBraceNode)) {
528 rCursor.MoveAfterBracket(pBraceNode);
529 }else if(code == ']' && rCursor.IsAtTailOfBracket(SquareBrackets, &pBraceNode)) {
530 rCursor.MoveAfterBracket(pBraceNode);
531 }else if(code == '}' && rCursor.IsAtTailOfBracket(CurlyBrackets, &pBraceNode)) {
532 rCursor.MoveAfterBracket(pBraceNode);
533 }else{
534 if(code != 0){
535 rCursor.InsertText(OUString(code));
536 }else if (! (GetView() && GetView()->KeyInput(rKEvt)) )
537 ScrollableWindow::KeyInput(rKEvt);
542 CaretBlinkStop();
543 CaretBlinkStart();
544 SetIsCursorVisible(true);
545 RepaintViewShellDoc();
549 void SmGraphicWindow::Command(const CommandEvent& rCEvt)
551 bool bCallBase = true;
552 if ( !pViewShell->GetViewFrame()->GetFrame().IsInPlace() )
554 switch ( rCEvt.GetCommand() )
556 case COMMAND_CONTEXTMENU:
558 GetParent()->ToTop();
559 SmResId aResId( RID_VIEWMENU );
560 PopupMenu* pPopupMenu = new PopupMenu(aResId);
561 pPopupMenu->SetSelectHdl(LINK(this, SmGraphicWindow, MenuSelectHdl));
562 Point aPos(5, 5);
563 if (rCEvt.IsMouseEvent())
564 aPos = rCEvt.GetMousePosPixel();
565 OSL_ENSURE( pViewShell, "view shell missing" );
567 // added for replaceability of context menus
568 pViewShell->GetViewFrame()->GetBindings().GetDispatcher()
569 ->ExecutePopup( aResId, this, &aPos );
571 delete pPopupMenu;
572 bCallBase = false;
574 break;
576 case COMMAND_WHEEL:
578 const CommandWheelData* pWData = rCEvt.GetWheelData();
579 if ( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
581 sal_uInt16 nTmpZoom = GetZoom();
582 if( 0L > pWData->GetDelta() )
583 nTmpZoom -= 10;
584 else
585 nTmpZoom += 10;
586 SetZoom( nTmpZoom );
587 bCallBase = false;
590 break;
593 if ( bCallBase )
594 ScrollableWindow::Command (rCEvt);
598 IMPL_LINK_INLINE_START( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
600 SmViewShell *pViewSh = GetView();
601 if (pViewSh)
602 pViewSh->GetViewFrame()->GetDispatcher()->Execute( pMenu->GetCurItemId() );
603 return 0;
605 IMPL_LINK_INLINE_END( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
608 void SmGraphicWindow::SetZoom(sal_uInt16 Factor)
610 nZoom = std::min(std::max((sal_uInt16) Factor, (sal_uInt16) MINZOOM), (sal_uInt16) MAXZOOM);
611 Fraction aFraction (nZoom, 100);
612 SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction) );
613 SetTotalSize();
614 SmViewShell *pViewSh = GetView();
615 if (pViewSh)
616 pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_ATTR_ZOOM);
617 Invalidate();
621 void SmGraphicWindow::ZoomToFitInWindow()
623 SmDocShell &rDoc = *pViewShell->GetDoc();
625 // set defined mapmode before calling 'LogicToPixel' below
626 SetMapMode(MapMode(MAP_100TH_MM));
628 Size aSize (LogicToPixel(rDoc.GetSize()));
629 Size aWindowSize (GetSizePixel());
631 if (aSize.Width() > 0 && aSize.Height() > 0)
633 long nVal = std::min ((85 * aWindowSize.Width()) / aSize.Width(),
634 (85 * aWindowSize.Height()) / aSize.Height());
635 SetZoom ( sal::static_int_cast< sal_uInt16 >(nVal) );
639 uno::Reference< XAccessible > SmGraphicWindow::CreateAccessible()
641 if (!pAccessible)
643 pAccessible = new SmGraphicAccessible( this );
644 xAccessible = pAccessible;
646 return xAccessible;
649 /**************************************************************************/
652 SmGraphicController::SmGraphicController(SmGraphicWindow &rSmGraphic,
653 sal_uInt16 nId_,
654 SfxBindings &rBindings) :
655 SfxControllerItem(nId_, rBindings),
656 rGraphic(rSmGraphic)
661 void SmGraphicController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
663 rGraphic.SetTotalSize();
664 rGraphic.Invalidate();
665 SfxControllerItem::StateChanged (nSID, eState, pState);
669 /**************************************************************************/
672 SmEditController::SmEditController(SmEditWindow &rSmEdit,
673 sal_uInt16 nId_,
674 SfxBindings &rBindings) :
675 SfxControllerItem(nId_, rBindings),
676 rEdit(rSmEdit)
681 #if OSL_DEBUG_LEVEL > 1
682 SmEditController::~SmEditController()
685 #endif
688 void SmEditController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
690 const SfxStringItem *pItem = PTR_CAST(SfxStringItem, pState);
692 if ((pItem != NULL) && (rEdit.GetText() != OUString(pItem->GetValue())))
693 rEdit.SetText(pItem->GetValue());
694 SfxControllerItem::StateChanged (nSID, eState, pState);
698 /**************************************************************************/
700 SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings *pBindings_, SfxChildWindow *pChildWindow,
701 Window *pParent) :
702 SfxDockingWindow(pBindings_, pChildWindow, pParent, SmResId(RID_CMDBOXWINDOW)),
703 aEdit (*this),
704 aController (aEdit, SID_TEXT, *pBindings_),
705 bExiting (false)
707 Hide ();
709 aInitialFocusTimer.SetTimeoutHdl(LINK(this, SmCmdBoxWindow, InitialFocusTimerHdl));
710 aInitialFocusTimer.SetTimeout(100);
714 SmCmdBoxWindow::~SmCmdBoxWindow ()
716 aInitialFocusTimer.Stop();
717 bExiting = true;
721 SmViewShell * SmCmdBoxWindow::GetView()
723 SfxDispatcher *pDispatcher = GetBindings().GetDispatcher();
724 SfxViewShell *pView = pDispatcher ? pDispatcher->GetFrame()->GetViewShell() : NULL;
725 return PTR_CAST(SmViewShell, pView);
728 void SmCmdBoxWindow::Resize()
730 Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
731 aRect.Left() += CMD_BOX_PADDING;
732 aRect.Top() += CMD_BOX_PADDING;
733 aRect.Right() -= CMD_BOX_PADDING;
734 aRect.Bottom() -= CMD_BOX_PADDING;
736 DecorationView aView(this);
737 aRect = aView.DrawFrame( aRect, FRAME_DRAW_IN | FRAME_DRAW_NODRAW );
739 aEdit.SetPosSizePixel(aRect.TopLeft(), aRect.GetSize());
740 SfxDockingWindow::Resize();
741 Invalidate();
745 void SmCmdBoxWindow::Paint(const Rectangle& /*rRect*/)
747 Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
748 aRect.Left() += CMD_BOX_PADDING;
749 aRect.Top() += CMD_BOX_PADDING;
750 aRect.Right() -= CMD_BOX_PADDING;
751 aRect.Bottom() -= CMD_BOX_PADDING;
753 DecorationView aView(this);
754 aView.DrawFrame( aRect, FRAME_DRAW_IN );
758 Size SmCmdBoxWindow::CalcDockingSize(SfxChildAlignment eAlign)
760 switch (eAlign)
762 case SFX_ALIGN_LEFT:
763 case SFX_ALIGN_RIGHT:
764 return Size();
765 default:
766 break;
768 return SfxDockingWindow::CalcDockingSize(eAlign);
772 SfxChildAlignment SmCmdBoxWindow::CheckAlignment(SfxChildAlignment eActual,
773 SfxChildAlignment eWish)
775 switch (eWish)
777 case SFX_ALIGN_TOP:
778 case SFX_ALIGN_BOTTOM:
779 case SFX_ALIGN_NOALIGNMENT:
780 return eWish;
781 default:
782 break;
785 return eActual;
789 void SmCmdBoxWindow::StateChanged( StateChangedType nStateChange )
791 if (STATE_CHANGE_INITSHOW == nStateChange)
793 Resize(); // avoid SmEditWindow not being painted correctly
795 // set initial position of window in floating mode
796 if (IsFloatingMode())
797 AdjustPosition(); //! don't change pos in docking-mode !
799 aInitialFocusTimer.Start();
802 SfxDockingWindow::StateChanged( nStateChange );
806 IMPL_LINK( SmCmdBoxWindow, InitialFocusTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
808 // We want to have the focus in the edit window once Math has been opened
809 // to allow for immediate typing.
810 // Problem: There is no proper way to do this
811 // Thus: this timer based soultion has been implemented (see GrabFocus below)
813 // Follow-up problem (#i114910): grabing the focus may bust the help system since
814 // it relies on getting the current frame which conflicts with grabbing the focus.
815 // Thus aside from the 'GrabFocus' call everything else is to get the
816 // help reliably working despite using 'GrabFocus'.
820 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( comphelper::getProcessComponentContext() );
822 aEdit.GrabFocus();
824 bool bInPlace = GetView()->GetViewFrame()->GetFrame().IsInPlace();
825 uno::Reference< frame::XFrame > xFrame( GetBindings().GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface());
826 if ( bInPlace )
828 uno::Reference< container::XChild > xModel( GetView()->GetDoc()->GetModel(), uno::UNO_QUERY_THROW );
829 uno::Reference< frame::XModel > xParent( xModel->getParent(), uno::UNO_QUERY_THROW );
830 uno::Reference< frame::XController > xParentCtrler( xParent->getCurrentController() );
831 uno::Reference< frame::XFramesSupplier > xParentFrame( xParentCtrler->getFrame(), uno::UNO_QUERY_THROW );
832 xParentFrame->setActiveFrame( xFrame );
834 else
836 xDesktop->setActiveFrame( xFrame );
839 catch (uno::Exception &)
841 OSL_FAIL( "failed to properly set initial focus to edit window" );
843 return 0;
847 void SmCmdBoxWindow::AdjustPosition()
849 Point aPt;
850 const Rectangle aRect( aPt, GetParent()->GetOutputSizePixel() );
851 Point aTopLeft( Point( aRect.Left(),
852 aRect.Bottom() - GetSizePixel().Height() ) );
853 Point aPos( GetParent()->OutputToScreenPixel( aTopLeft ) );
854 if (aPos.X() < 0)
855 aPos.X() = 0;
856 if (aPos.Y() < 0)
857 aPos.Y() = 0;
858 SetPosPixel( aPos );
862 void SmCmdBoxWindow::ToggleFloatingMode()
864 SfxDockingWindow::ToggleFloatingMode();
866 if (GetFloatingWindow())
867 GetFloatingWindow()->SetMinOutputSizePixel(Size (200, 50));
871 void SmCmdBoxWindow::GetFocus()
873 if (!bExiting)
874 aEdit.GrabFocus();
877 /**************************************************************************/
880 SFX_IMPL_DOCKINGWINDOW_WITHID(SmCmdBoxWrapper, SID_CMDBOXWINDOW);
882 SmCmdBoxWrapper::SmCmdBoxWrapper(Window *pParentWindow, sal_uInt16 nId,
883 SfxBindings *pBindings,
884 SfxChildWinInfo *pInfo) :
885 SfxChildWindow(pParentWindow, nId)
887 pWindow = new SmCmdBoxWindow(pBindings, this, pParentWindow);
889 // make window docked to the bottom initially (after first start)
890 eChildAlignment = SFX_ALIGN_BOTTOM;
891 ((SfxDockingWindow *)pWindow)->Initialize(pInfo);
895 #if OSL_DEBUG_LEVEL > 1
896 SmCmdBoxWrapper::~SmCmdBoxWrapper()
899 #endif
902 /**************************************************************************/
904 struct SmViewShell_Impl
906 sfx2::DocumentInserter* pDocInserter;
907 SfxRequest* pRequest;
908 SvtMiscOptions aOpts;
910 SmViewShell_Impl() :
911 pDocInserter( NULL )
912 , pRequest( NULL )
915 ~SmViewShell_Impl()
917 delete pDocInserter;
918 delete pRequest;
922 TYPEINIT1( SmViewShell, SfxViewShell );
924 SFX_IMPL_INTERFACE(SmViewShell, SfxViewShell, SmResId(0))
926 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS | SFX_VISIBILITY_STANDARD |
927 SFX_VISIBILITY_FULLSCREEN | SFX_VISIBILITY_SERVER,
928 SmResId(RID_MATH_TOOLBOX ));
929 //Dummy-Objectbar, to avoid quiver while activating
931 SFX_CHILDWINDOW_REGISTRATION(SID_TASKPANE);
932 SFX_CHILDWINDOW_REGISTRATION(SmToolBoxWrapper::GetChildWindowId());
933 SFX_CHILDWINDOW_REGISTRATION(SmCmdBoxWrapper::GetChildWindowId());
934 SFX_CHILDWINDOW_REGISTRATION(SmElementsDockingWindowWrapper::GetChildWindowId());
938 SFX_IMPL_NAMED_VIEWFACTORY(SmViewShell, "Default")
940 SFX_VIEW_REGISTRATION(SmDocShell);
944 void SmViewShell::AdjustPosSizePixel(const Point &rPos, const Size &rSize)
946 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::AdjustPosSizePixel" );
948 aGraphic.SetPosSizePixel(rPos, rSize);
952 void SmViewShell::InnerResizePixel(const Point &rOfs, const Size &rSize)
954 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::InnerResizePixel" );
956 Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
957 if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
959 Size aProvidedSize = GetWindow()->PixelToLogic( rSize, MAP_100TH_MM );
960 SfxViewShell::SetZoomFactor( Fraction( aProvidedSize.Width(), aObjSize.Width() ),
961 Fraction( aProvidedSize.Height(), aObjSize.Height() ) );
964 SetBorderPixel( SvBorder() );
965 GetGraphicWindow().SetPosSizePixel(rOfs, rSize);
966 GetGraphicWindow().SetTotalSize();
970 void SmViewShell::OuterResizePixel(const Point &rOfs, const Size &rSize)
972 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::OuterResizePixel" );
974 SmGraphicWindow &rWin = GetGraphicWindow();
975 rWin.SetPosSizePixel(rOfs, rSize);
976 if (GetDoc()->IsPreview())
977 rWin.ZoomToFitInWindow();
978 rWin.Update();
982 void SmViewShell::QueryObjAreaPixel( Rectangle& rRect ) const
984 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::QueryObjAreaPixel" );
986 rRect.SetSize( GetGraphicWindow().GetSizePixel() );
990 void SmViewShell::SetZoomFactor( const Fraction &rX, const Fraction &rY )
992 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetZoomFactor" );
994 const Fraction &rFrac = rX < rY ? rX : rY;
995 GetGraphicWindow().SetZoom( (sal_uInt16) long(rFrac * Fraction( 100, 1 )) );
997 //To avoid rounding errors base class regulates crooked values too
998 //if necessary
999 SfxViewShell::SetZoomFactor( rX, rY );
1003 Size SmViewShell::GetTextLineSize(OutputDevice& rDevice, const String& rLine)
1005 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetTextLineSize" );
1007 Size aSize(rDevice.GetTextWidth(rLine), rDevice.GetTextHeight());
1008 sal_uInt16 nTabs = comphelper::string::getTokenCount(rLine, '\t');
1010 if (nTabs > 0)
1012 long TabPos = rDevice.GetTextWidth(OUString('n')) * 8;
1014 aSize.Width() = 0;
1016 for (sal_uInt16 i = 0; i < nTabs; i++)
1018 if (i > 0)
1019 aSize.Width() = ((aSize.Width() / TabPos) + 1) * TabPos;
1021 OUString aText = rLine.GetToken(i, '\t');
1022 aText = comphelper::string::stripStart(aText, '\t');
1023 aText = comphelper::string::stripEnd(aText, '\t');
1024 aSize.Width() += rDevice.GetTextWidth(aText);
1028 return aSize;
1032 Size SmViewShell::GetTextSize(OutputDevice& rDevice, const String& rText, long MaxWidth)
1034 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetTextSize" );
1036 Size aSize;
1037 Size TextSize;
1038 sal_uInt16 nLines = comphelper::string::getTokenCount(rText, '\n');
1040 for (sal_uInt16 i = 0; i < nLines; i++)
1042 OUString aLine = rText.GetToken(i, '\n');
1043 aLine = comphelper::string::remove(aLine, '\r');
1044 aLine = comphelper::string::stripStart(aLine, '\n');
1045 aLine = comphelper::string::stripEnd(aLine, '\n');
1047 aSize = GetTextLineSize(rDevice, aLine);
1049 if (aSize.Width() > MaxWidth)
1053 OUString aText;
1054 sal_Int32 m = aLine.getLength();
1055 sal_Int32 nLen = m;
1057 for (sal_Int32 n = 0; n < nLen; n++)
1059 sal_Unicode cLineChar = aLine[n];
1060 if ((cLineChar == ' ') || (cLineChar == '\t'))
1062 aText = aLine.copy(0, n);
1063 if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
1064 m = n;
1065 else
1066 break;
1070 aText = aLine.copy(0, m);
1071 aLine = aLine.replaceAt(0, m, "");
1072 aSize = GetTextLineSize(rDevice, aText);
1073 TextSize.Height() += aSize.Height();
1074 TextSize.Width() = std::max(TextSize.Width(), std::min(aSize.Width(), MaxWidth));
1076 aLine = comphelper::string::stripStart(aLine, ' ');
1077 aLine = comphelper::string::stripStart(aLine, '\t');
1078 aLine = comphelper::string::stripStart(aLine, ' ');
1080 while (!aLine.isEmpty());
1082 else
1084 TextSize.Height() += aSize.Height();
1085 TextSize.Width() = std::max(TextSize.Width(), aSize.Width());
1089 return TextSize;
1093 void SmViewShell::DrawTextLine(OutputDevice& rDevice, const Point& rPosition, const String& rLine)
1095 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::DrawTextLine" );
1097 Point aPoint (rPosition);
1098 sal_uInt16 nTabs = comphelper::string::getTokenCount(rLine, '\t');
1100 if (nTabs > 0)
1102 long TabPos = rDevice.GetTextWidth(OUString('n')) * 8;
1104 for (sal_uInt16 i = 0; i < nTabs; i++)
1106 if (i > 0)
1107 aPoint.X() = ((aPoint.X() / TabPos) + 1) * TabPos;
1109 OUString aText = rLine.GetToken(i, '\t');
1110 aText = comphelper::string::stripStart(aText, '\t');
1111 aText = comphelper::string::stripEnd(aText, '\t');
1112 rDevice.DrawText(aPoint, aText);
1113 aPoint.X() += rDevice.GetTextWidth(aText);
1116 else
1117 rDevice.DrawText(aPoint, rLine);
1121 void SmViewShell::DrawText(OutputDevice& rDevice, const Point& rPosition, const String& rText, sal_uInt16 MaxWidth)
1123 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::DrawText" );
1125 sal_uInt16 nLines = comphelper::string::getTokenCount(rText, '\n');
1126 Point aPoint (rPosition);
1127 Size aSize;
1129 for (sal_uInt16 i = 0; i < nLines; i++)
1131 OUString aLine = rText.GetToken(i, '\n');
1132 aLine = comphelper::string::remove(aLine, '\r');
1133 aLine = comphelper::string::stripEnd(aLine, '\n');
1134 aLine = comphelper::string::stripEnd(aLine, '\n');
1135 aSize = GetTextLineSize(rDevice, aLine);
1136 if (aSize.Width() > MaxWidth)
1140 OUString aText;
1141 sal_Int32 m = aLine.getLength();
1142 sal_Int32 nLen = m;
1144 for (sal_Int32 n = 0; n < nLen; n++)
1146 sal_Unicode cLineChar = aLine[n];
1147 if ((cLineChar == ' ') || (cLineChar == '\t'))
1149 aText = aLine.copy(0, n);
1150 if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
1151 m = n;
1152 else
1153 break;
1156 aText = aLine.copy(0, m);
1157 aLine = aLine.replaceAt(0, m, "");
1159 DrawTextLine(rDevice, aPoint, aText);
1160 aPoint.Y() += aSize.Height();
1162 aLine = comphelper::string::stripStart(aLine, ' ');
1163 aLine = comphelper::string::stripStart(aLine, '\t');
1164 aLine = comphelper::string::stripStart(aLine, ' ');
1166 while (GetTextLineSize(rDevice, aLine).Width() > MaxWidth);
1168 // print the remaining text
1169 if (!aLine.isEmpty())
1171 DrawTextLine(rDevice, aPoint, aLine);
1172 aPoint.Y() += aSize.Height();
1175 else
1177 DrawTextLine(rDevice, aPoint, aLine);
1178 aPoint.Y() += aSize.Height();
1183 void SmViewShell::Impl_Print(
1184 OutputDevice &rOutDev,
1185 const SmPrintUIOptions &rPrintUIOptions,
1186 Rectangle aOutRect, Point aZeroPoint )
1188 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Impl_Print" );
1190 const bool bIsPrintTitle = rPrintUIOptions.getBoolValue( PRTUIOPT_TITLE_ROW, sal_True );
1191 const bool bIsPrintFrame = rPrintUIOptions.getBoolValue( PRTUIOPT_BORDER, sal_True );
1192 const bool bIsPrintFormulaText = rPrintUIOptions.getBoolValue( PRTUIOPT_FORMULA_TEXT, sal_True );
1193 SmPrintSize ePrintSize( static_cast< SmPrintSize >( rPrintUIOptions.getIntValue( PRTUIOPT_PRINT_FORMAT, PRINT_SIZE_NORMAL ) ));
1194 const sal_uInt16 nZoomFactor = static_cast< sal_uInt16 >(rPrintUIOptions.getIntValue( PRTUIOPT_PRINT_SCALE, 100 ));
1196 rOutDev.Push();
1197 rOutDev.SetLineColor( Color(COL_BLACK) );
1199 // output text on top
1200 if (bIsPrintTitle)
1202 Size aSize600 (0, 600);
1203 Size aSize650 (0, 650);
1204 Font aFont(FAMILY_DONTKNOW, aSize600);
1206 aFont.SetAlign(ALIGN_TOP);
1207 aFont.SetWeight(WEIGHT_BOLD);
1208 aFont.SetSize(aSize650);
1209 aFont.SetColor( Color(COL_BLACK) );
1210 rOutDev.SetFont(aFont);
1212 Size aTitleSize (GetTextSize(rOutDev, GetDoc()->GetTitle(), aOutRect.GetWidth() - 200));
1214 aFont.SetWeight(WEIGHT_NORMAL);
1215 aFont.SetSize(aSize600);
1216 rOutDev.SetFont(aFont);
1218 Size aDescSize (GetTextSize(rOutDev, GetDoc()->GetComment(), aOutRect.GetWidth() - 200));
1220 if (bIsPrintFrame)
1221 rOutDev.DrawRect(Rectangle(aOutRect.TopLeft(),
1222 Size(aOutRect.GetWidth(), 100 + aTitleSize.Height() + 200 + aDescSize.Height() + 100)));
1223 aOutRect.Top() += 200;
1225 // output title
1226 aFont.SetWeight(WEIGHT_BOLD);
1227 aFont.SetSize(aSize650);
1228 rOutDev.SetFont(aFont);
1229 Point aPoint(aOutRect.Left() + (aOutRect.GetWidth() - aTitleSize.Width()) / 2,
1230 aOutRect.Top());
1231 DrawText(rOutDev, aPoint, GetDoc()->GetTitle(),
1232 sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
1233 aOutRect.Top() += aTitleSize.Height() + 200;
1235 // output description
1236 aFont.SetWeight(WEIGHT_NORMAL);
1237 aFont.SetSize(aSize600);
1238 rOutDev.SetFont(aFont);
1239 aPoint.X() = aOutRect.Left() + (aOutRect.GetWidth() - aDescSize.Width()) / 2;
1240 aPoint.Y() = aOutRect.Top();
1241 DrawText(rOutDev, aPoint, GetDoc()->GetComment(),
1242 sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
1243 aOutRect.Top() += aDescSize.Height() + 300;
1246 // output text on bottom
1247 if (bIsPrintFormulaText)
1249 Font aFont(FAMILY_DONTKNOW, Size(0, 600));
1250 aFont.SetAlign(ALIGN_TOP);
1251 aFont.SetColor( Color(COL_BLACK) );
1253 // get size
1254 rOutDev.SetFont(aFont);
1256 Size aSize (GetTextSize(rOutDev, GetDoc()->GetText(), aOutRect.GetWidth() - 200));
1258 aOutRect.Bottom() -= aSize.Height() + 600;
1260 if (bIsPrintFrame)
1261 rOutDev.DrawRect(Rectangle(aOutRect.BottomLeft(),
1262 Size(aOutRect.GetWidth(), 200 + aSize.Height() + 200)));
1264 Point aPoint (aOutRect.Left() + (aOutRect.GetWidth() - aSize.Width()) / 2,
1265 aOutRect.Bottom() + 300);
1266 DrawText(rOutDev, aPoint, GetDoc()->GetText(),
1267 sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
1268 aOutRect.Bottom() -= 200;
1271 if (bIsPrintFrame)
1272 rOutDev.DrawRect(aOutRect);
1274 aOutRect.Top() += 100;
1275 aOutRect.Left() += 100;
1276 aOutRect.Bottom() -= 100;
1277 aOutRect.Right() -= 100;
1279 Size aSize (GetDoc()->GetSize());
1281 MapMode OutputMapMode;
1282 // PDF export should always use PRINT_SIZE_NORMAL ...
1283 if (!rPrintUIOptions.getBoolValue( "IsPrinter", sal_False ) )
1284 ePrintSize = PRINT_SIZE_NORMAL;
1285 switch (ePrintSize)
1287 case PRINT_SIZE_NORMAL:
1288 OutputMapMode = MapMode(MAP_100TH_MM);
1289 break;
1291 case PRINT_SIZE_SCALED:
1292 if ((aSize.Width() > 0) && (aSize.Height() > 0))
1294 Size OutputSize (rOutDev.LogicToPixel(Size(aOutRect.GetWidth(),
1295 aOutRect.GetHeight()), MapMode(MAP_100TH_MM)));
1296 Size GraphicSize (rOutDev.LogicToPixel(aSize, MapMode(MAP_100TH_MM)));
1297 sal_uInt16 nZ = (sal_uInt16) std::min((long)Fraction(OutputSize.Width() * 100L, GraphicSize.Width()),
1298 (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
1299 Fraction aFraction ((sal_uInt16) std::max ((sal_uInt16) MINZOOM, std::min((sal_uInt16) MAXZOOM, (sal_uInt16) (nZ - 10))), (sal_uInt16) 100);
1301 OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
1303 else
1304 OutputMapMode = MapMode(MAP_100TH_MM);
1305 break;
1307 case PRINT_SIZE_ZOOMED:
1309 Fraction aFraction( nZoomFactor, 100 );
1311 OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
1312 break;
1316 aSize = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aSize, OutputMapMode),
1317 MapMode(MAP_100TH_MM));
1319 Point aPos (aOutRect.Left() + (aOutRect.GetWidth() - aSize.Width()) / 2,
1320 aOutRect.Top() + (aOutRect.GetHeight() - aSize.Height()) / 2);
1322 aPos = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aPos, MapMode(MAP_100TH_MM)),
1323 OutputMapMode);
1324 aOutRect = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aOutRect, MapMode(MAP_100TH_MM)),
1325 OutputMapMode);
1327 rOutDev.SetMapMode(OutputMapMode);
1328 rOutDev.SetClipRegion(Region(aOutRect));
1329 GetDoc()->DrawFormula(rOutDev, aPos, false);
1330 rOutDev.SetClipRegion();
1332 rOutDev.Pop();
1335 sal_uInt16 SmViewShell::Print(SfxProgress & /*rProgress*/, sal_Bool /*bIsAPI*/)
1337 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Print" );
1338 OSL_FAIL( "SmViewShell::Print: no longer used with new UI print dialog. Should be removed!!" );
1339 return 0;
1343 SfxPrinter* SmViewShell::GetPrinter(sal_Bool bCreate)
1345 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetPrinter" );
1347 SmDocShell *pDoc = GetDoc();
1348 if ( pDoc->HasPrinter() || bCreate )
1349 return pDoc->GetPrinter();
1350 return 0;
1354 sal_uInt16 SmViewShell::SetPrinter(SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
1356 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetPrinter" );
1357 SfxPrinter *pOld = GetDoc()->GetPrinter();
1358 if ( pOld && pOld->IsPrinting() )
1359 return SFX_PRINTERROR_BUSY;
1361 if ((nDiffFlags & SFX_PRINTER_PRINTER) == SFX_PRINTER_PRINTER)
1362 GetDoc()->SetPrinter( pNewPrinter );
1364 if ((nDiffFlags & SFX_PRINTER_OPTIONS) == SFX_PRINTER_OPTIONS)
1366 SmModule *pp = SM_MOD();
1367 pp->GetConfig()->ItemSetToConfig(pNewPrinter->GetOptions());
1369 return 0;
1372 bool SmViewShell::HasPrintOptionsPage() const
1374 return true;
1377 SfxTabPage* SmViewShell::CreatePrintOptionsPage(Window *pParent,
1378 const SfxItemSet &rOptions)
1380 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::CreatePrintOptionsPage" );
1382 return SmPrintOptionsTabPage::Create(pParent, rOptions);
1386 SmEditWindow *SmViewShell::GetEditWindow()
1388 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetEditWindow" );
1390 SmCmdBoxWrapper *pWrapper = (SmCmdBoxWrapper *) GetViewFrame()->
1391 GetChildWindow( SmCmdBoxWrapper::GetChildWindowId() );
1393 if (pWrapper != NULL)
1395 SmEditWindow *pEditWin = pWrapper->GetEditWindow();
1396 OSL_ENSURE( pEditWin, "SmEditWindow missing" );
1397 return pEditWin;
1400 return NULL;
1404 void SmViewShell::SetStatusText(const OUString& rText)
1406 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetStatusText" );
1408 aStatusText = rText;
1409 GetViewFrame()->GetBindings().Invalidate(SID_TEXTSTATUS);
1413 void SmViewShell::ShowError( const SmErrorDesc *pErrorDesc )
1415 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::ShowError" );
1417 OSL_ENSURE(GetDoc(), "Sm : Document missing");
1418 if (pErrorDesc || 0 != (pErrorDesc = GetDoc()->GetParser().GetError(0)) )
1420 SetStatusText( pErrorDesc->Text );
1421 GetEditWindow()->MarkError( Point( pErrorDesc->pNode->GetColumn(),
1422 pErrorDesc->pNode->GetRow()));
1427 void SmViewShell::NextError()
1429 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::NextError" );
1431 OSL_ENSURE(GetDoc(), "Sm : Document missing");
1432 const SmErrorDesc *pErrorDesc = GetDoc()->GetParser().NextError();
1434 if (pErrorDesc)
1435 ShowError( pErrorDesc );
1439 void SmViewShell::PrevError()
1441 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::PrevError" );
1443 OSL_ENSURE(GetDoc(), "Sm : Document missing");
1444 const SmErrorDesc *pErrorDesc = GetDoc()->GetParser().PrevError();
1446 if (pErrorDesc)
1447 ShowError( pErrorDesc );
1451 bool SmViewShell::Insert( SfxMedium& rMedium )
1453 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Insert" );
1455 SmDocShell *pDoc = GetDoc();
1456 bool bRet = false;
1458 uno::Reference < embed::XStorage > xStorage = rMedium.GetStorage();
1459 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
1460 if ( xNameAccess.is() && xNameAccess->getElementNames().getLength() )
1462 if ( xNameAccess->hasByName( OUString("content.xml") ) || xNameAccess->hasByName( OUString("Content.xml") ))
1464 // is this a fabulous math package ?
1465 Reference<com::sun::star::frame::XModel> xModel(pDoc->GetModel());
1466 SmXMLImportWrapper aEquation(xModel); //!! modifies the result of pDoc->GetText() !!
1467 bRet = 0 == aEquation.Import(rMedium);
1471 if( bRet )
1473 OUString aText = pDoc->GetText();
1474 SmEditWindow *pEditWin = GetEditWindow();
1475 if (pEditWin)
1476 pEditWin->InsertText( aText );
1477 else
1479 OSL_FAIL( "EditWindow missing" );
1482 pDoc->Parse();
1483 pDoc->SetModified(true);
1485 SfxBindings &rBnd = GetViewFrame()->GetBindings();
1486 rBnd.Invalidate(SID_GAPHIC_SM);
1487 rBnd.Invalidate(SID_TEXT);
1489 return bRet;
1493 bool SmViewShell::InsertFrom(SfxMedium &rMedium)
1495 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::InsertFrom" );
1497 bool bSuccess = false;
1498 SmDocShell *pDoc = GetDoc();
1499 SvStream *pStream = rMedium.GetInStream();
1501 if (pStream)
1503 const OUString& rFltName = rMedium.GetFilter()->GetFilterName();
1504 if ( rFltName == MATHML_XML )
1506 Reference<com::sun::star::frame::XModel> xModel( pDoc->GetModel() );
1507 SmXMLImportWrapper aEquation(xModel); //!! modifies the result of pDoc->GetText() !!
1508 bSuccess = 0 == aEquation.Import(rMedium);
1512 if( bSuccess )
1514 OUString aText = pDoc->GetText();
1515 SmEditWindow *pEditWin = GetEditWindow();
1516 if (pEditWin)
1517 pEditWin->InsertText( aText );
1518 else
1520 OSL_FAIL( "EditWindow missing" );
1523 pDoc->Parse();
1524 pDoc->SetModified(true);
1526 SfxBindings &rBnd = GetViewFrame()->GetBindings();
1527 rBnd.Invalidate(SID_GAPHIC_SM);
1528 rBnd.Invalidate(SID_TEXT);
1531 return bSuccess;
1535 void SmViewShell::Execute(SfxRequest& rReq)
1537 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Execute" );
1539 SmEditWindow *pWin = GetEditWindow();
1541 switch (rReq.GetSlot())
1543 case SID_FORMULACURSOR:
1545 SmModule *pp = SM_MOD();
1547 const SfxItemSet *pArgs = rReq.GetArgs();
1548 const SfxPoolItem *pItem;
1550 bool bVal;
1551 if ( pArgs &&
1552 SFX_ITEM_SET == pArgs->GetItemState( SID_FORMULACURSOR, false, &pItem))
1553 bVal = ((SfxBoolItem *) pItem)->GetValue();
1554 else
1555 bVal = !pp->GetConfig()->IsShowFormulaCursor();
1557 pp->GetConfig()->SetShowFormulaCursor(bVal);
1558 if (!IsInlineEditEnabled())
1559 GetGraphicWindow().ShowCursor(bVal);
1560 break;
1562 case SID_DRAW:
1563 if (pWin)
1565 GetDoc()->SetText( pWin->GetText() );
1566 SetStatusText(OUString());
1567 ShowError( 0 );
1568 GetDoc()->Repaint();
1570 break;
1572 case SID_ADJUST:
1573 case SID_FITINWINDOW:
1574 aGraphic.ZoomToFitInWindow();
1575 break;
1577 case SID_VIEW050:
1578 aGraphic.SetZoom(50);
1579 break;
1581 case SID_VIEW100:
1582 aGraphic.SetZoom(100);
1583 break;
1585 case SID_VIEW200:
1586 aGraphic.SetZoom(200);
1587 break;
1589 case SID_ZOOMIN:
1590 aGraphic.SetZoom(aGraphic.GetZoom() + 25);
1591 break;
1593 case SID_ZOOMOUT:
1594 OSL_ENSURE(aGraphic.GetZoom() >= 25, "Sm: incorrect sal_uInt16 argument");
1595 aGraphic.SetZoom(aGraphic.GetZoom() - 25);
1596 break;
1598 case SID_COPYOBJECT:
1600 //TODO/LATER: does not work because of UNO Tunneling - will be fixed later
1601 Reference< datatransfer::XTransferable > xTrans( GetDoc()->GetModel(), uno::UNO_QUERY );
1602 if( xTrans.is() )
1604 Reference< lang::XUnoTunnel> xTnnl( xTrans, uno::UNO_QUERY);
1605 if( xTnnl.is() )
1607 TransferableHelper* pTrans = reinterpret_cast< TransferableHelper * >(
1608 sal::static_int_cast< sal_uIntPtr >(
1609 xTnnl->getSomething( TransferableHelper::getUnoTunnelId() )));
1610 if( pTrans )
1611 pTrans->CopyToClipboard( this ? GetEditWindow() : 0 );
1615 break;
1617 case SID_PASTEOBJECT:
1619 TransferableDataHelper aData( TransferableDataHelper::CreateFromSystemClipboard(this ? GetEditWindow(): 0) );
1620 uno::Reference < io::XInputStream > xStrm;
1621 SotFormatStringId nId;
1622 if( aData.GetTransferable().is() &&
1623 ( aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
1624 (aData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) &&
1625 aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBED_SOURCE ))) &&
1626 aData.GetInputStream( nId, xStrm ) && xStrm.is() )
1630 uno::Reference < embed::XStorage > xStorage =
1631 ::comphelper::OStorageHelper::GetStorageFromInputStream( xStrm, ::comphelper::getProcessComponentContext() );
1632 uno::Reference < beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY );
1633 SfxMedium aMedium( xStorage, OUString() );
1634 Insert( aMedium );
1635 GetDoc()->UpdateText();
1637 catch (uno::Exception &)
1639 OSL_FAIL( "SmViewShell::Execute (SID_PASTEOBJECT): failed to get storage from input stream" );
1643 break;
1646 case SID_CUT:
1647 if (pWin)
1648 pWin->Cut();
1649 break;
1651 case SID_COPY:
1652 if (pWin)
1654 if (pWin->IsAllSelected())
1656 GetViewFrame()->GetDispatcher()->Execute(
1657 SID_COPYOBJECT, SFX_CALLMODE_STANDARD,
1658 new SfxVoidItem(SID_COPYOBJECT), 0L);
1660 else
1661 pWin->Copy();
1663 break;
1665 case SID_PASTE:
1667 bool bCallExec = 0 == pWin;
1668 if( !bCallExec )
1670 TransferableDataHelper aDataHelper(
1671 TransferableDataHelper::CreateFromSystemClipboard(
1672 GetEditWindow()) );
1674 if( aDataHelper.GetTransferable().is() &&
1675 aDataHelper.HasFormat( FORMAT_STRING ))
1676 pWin->Paste();
1677 else
1678 bCallExec = true;
1680 if( bCallExec )
1682 GetViewFrame()->GetDispatcher()->Execute(
1683 SID_PASTEOBJECT, SFX_CALLMODE_STANDARD,
1684 new SfxVoidItem(SID_PASTEOBJECT), 0L);
1687 break;
1689 case SID_DELETE:
1690 if (pWin)
1691 pWin->Delete();
1692 break;
1694 case SID_SELECT:
1695 if (pWin)
1696 pWin->SelectAll();
1697 break;
1699 case SID_INSERTCOMMAND:
1701 const SfxInt16Item& rItem =
1702 (const SfxInt16Item&)rReq.GetArgs()->Get(SID_INSERTCOMMAND);
1704 if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
1705 pWin->InsertCommand(rItem.GetValue());
1706 if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow)) {
1707 GetDoc()->GetCursor().InsertCommand(rItem.GetValue());
1708 GetGraphicWindow().GrabFocus();
1710 break;
1713 case SID_INSERTCOMMANDTEXT:
1715 const SfxStringItem& rItem = (const SfxStringItem&)rReq.GetArgs()->Get(SID_INSERTCOMMANDTEXT);
1717 if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
1719 pWin->InsertText(rItem.GetValue());
1721 if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow))
1723 GetDoc()->GetCursor().InsertCommandText(rItem.GetValue());
1724 GetGraphicWindow().GrabFocus();
1726 break;
1730 case SID_INSERTSYMBOL:
1732 const SfxStringItem& rItem =
1733 (const SfxStringItem&)rReq.GetArgs()->Get(SID_INSERTSYMBOL);
1735 if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
1736 pWin->InsertText(rItem.GetValue());
1737 if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow))
1738 GetDoc()->GetCursor().InsertSpecial(rItem.GetValue());
1739 break;
1742 case SID_IMPORT_FORMULA:
1744 delete pImpl->pRequest;
1745 pImpl->pRequest = new SfxRequest( rReq );
1746 delete pImpl->pDocInserter;
1747 pImpl->pDocInserter = new ::sfx2::DocumentInserter(
1748 GetDoc()->GetFactory().GetFactoryName(), 0 );
1749 pImpl->pDocInserter->StartExecuteModal( LINK( this, SmViewShell, DialogClosedHdl ) );
1750 break;
1753 case SID_NEXTERR:
1754 NextError();
1755 if (pWin)
1756 pWin->GrabFocus();
1757 break;
1759 case SID_PREVERR:
1760 PrevError();
1761 if (pWin)
1762 pWin->GrabFocus();
1763 break;
1765 case SID_NEXTMARK:
1766 if (pWin)
1768 pWin->SelNextMark();
1769 pWin->GrabFocus();
1771 break;
1773 case SID_PREVMARK:
1774 if (pWin)
1776 pWin->SelPrevMark();
1777 pWin->GrabFocus();
1779 break;
1781 case SID_TEXTSTATUS:
1783 if (rReq.GetArgs() != NULL)
1785 const SfxStringItem& rItem =
1786 (const SfxStringItem&)rReq.GetArgs()->Get(SID_TEXTSTATUS);
1788 SetStatusText(rItem.GetValue());
1791 break;
1794 case SID_GETEDITTEXT:
1795 if (pWin)
1796 if (!pWin->GetText().isEmpty()) GetDoc()->SetText( pWin->GetText() );
1797 break;
1799 case SID_ATTR_ZOOM:
1801 if ( !GetViewFrame()->GetFrame().IsInPlace() )
1803 AbstractSvxZoomDialog *pDlg = 0;
1804 const SfxItemSet *pSet = rReq.GetArgs();
1805 if ( !pSet )
1807 SfxItemSet aSet( GetDoc()->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
1808 aSet.Put( SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
1809 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1810 if(pFact)
1812 pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aSet);
1813 OSL_ENSURE(pDlg, "Dialogdiet fail!");
1814 pDlg->SetLimits( MINZOOM, MAXZOOM );
1815 if( pDlg->Execute() != RET_CANCEL )
1816 pSet = pDlg->GetOutputItemSet();
1819 if ( pSet )
1821 const SvxZoomItem &rZoom = (const SvxZoomItem &)pSet->Get(SID_ATTR_ZOOM);
1822 switch( rZoom.GetType() )
1824 case SVX_ZOOM_PERCENT:
1825 aGraphic.SetZoom((sal_uInt16)rZoom.GetValue ());
1826 break;
1828 case SVX_ZOOM_OPTIMAL:
1829 aGraphic.ZoomToFitInWindow();
1830 break;
1832 case SVX_ZOOM_PAGEWIDTH:
1833 case SVX_ZOOM_WHOLEPAGE:
1835 const MapMode aMap( MAP_100TH_MM );
1836 SfxPrinter *pPrinter = GetPrinter( true );
1837 Point aPoint;
1838 Rectangle OutputRect(aPoint, pPrinter->GetOutputSize());
1839 Size OutputSize(pPrinter->LogicToPixel(Size(OutputRect.GetWidth(),
1840 OutputRect.GetHeight()), aMap));
1841 Size GraphicSize(pPrinter->LogicToPixel(GetDoc()->GetSize(), aMap));
1842 sal_uInt16 nZ = (sal_uInt16) std::min((long)Fraction(OutputSize.Width() * 100L, GraphicSize.Width()),
1843 (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
1844 aGraphic.SetZoom (nZ);
1845 break;
1847 default:
1848 break;
1851 delete pDlg;
1854 break;
1856 case SID_TOOLBOX:
1858 GetViewFrame()->ToggleChildWindow( SmToolBoxWrapper::GetChildWindowId() );
1860 break;
1862 case SID_ELEMENTSDOCKINGWINDOW:
1864 GetViewFrame()->ToggleChildWindow( SmElementsDockingWindowWrapper::GetChildWindowId() );
1865 GetViewFrame()->GetBindings().Invalidate( SID_ELEMENTSDOCKINGWINDOW );
1867 rReq.Ignore ();
1869 break;
1871 case SID_SYMBOLS_CATALOGUE:
1874 // get device used to retrieve the FontList
1875 SmDocShell *pDoc = GetDoc();
1876 OutputDevice *pDev = pDoc->GetPrinter();
1877 if (!pDev || pDev->GetDevFontCount() == 0)
1878 pDev = &SM_MOD()->GetDefaultVirtualDev();
1879 OSL_ENSURE (pDev, "device for font list missing" );
1881 SmModule *pp = SM_MOD();
1882 SmSymbolDialog( NULL, pDev, pp->GetSymbolManager(), *this ).Execute();
1884 break;
1886 rReq.Done();
1890 void SmViewShell::GetState(SfxItemSet &rSet)
1892 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetState" );
1894 SfxWhichIter aIter(rSet);
1896 SmEditWindow *pEditWin = GetEditWindow();
1897 for (sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich())
1899 switch (nWh)
1901 case SID_CUT:
1902 case SID_COPY:
1903 case SID_DELETE:
1904 if (! pEditWin || ! pEditWin->IsSelected())
1905 rSet.DisableItem(nWh);
1906 break;
1908 case SID_PASTE:
1909 if( !xClipEvtLstnr.is() && pEditWin)
1911 TransferableDataHelper aDataHelper(
1912 TransferableDataHelper::CreateFromSystemClipboard(
1913 pEditWin) );
1915 bPasteState = aDataHelper.GetTransferable().is() &&
1916 ( aDataHelper.HasFormat( FORMAT_STRING ) ||
1917 aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
1918 (aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
1919 && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE )));
1921 if( !bPasteState )
1922 rSet.DisableItem( nWh );
1923 break;
1925 case SID_ATTR_ZOOM:
1926 rSet.Put(SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
1927 /* no break here */
1928 case SID_VIEW050:
1929 case SID_VIEW100:
1930 case SID_VIEW200:
1931 case SID_ADJUST:
1932 case SID_ZOOMIN:
1933 case SID_ZOOMOUT:
1934 case SID_FITINWINDOW:
1935 if ( GetViewFrame()->GetFrame().IsInPlace() )
1936 rSet.DisableItem( nWh );
1937 break;
1939 case SID_NEXTERR:
1940 case SID_PREVERR:
1941 case SID_NEXTMARK:
1942 case SID_PREVMARK:
1943 case SID_DRAW:
1944 case SID_SELECT:
1945 if (! pEditWin || pEditWin->IsEmpty())
1946 rSet.DisableItem(nWh);
1947 break;
1949 case SID_TEXTSTATUS:
1951 rSet.Put(SfxStringItem(nWh, aStatusText));
1953 break;
1955 case SID_FORMULACURSOR:
1957 SmModule *pp = SM_MOD();
1958 rSet.Put(SfxBoolItem(nWh, pp->GetConfig()->IsShowFormulaCursor()));
1960 break;
1961 case SID_ELEMENTSDOCKINGWINDOW:
1963 bool bState = false;
1964 SfxChildWindow *pChildWnd = GetViewFrame()->
1965 GetChildWindow( SmElementsDockingWindowWrapper::GetChildWindowId() );
1966 if (pChildWnd && pChildWnd->GetWindow()->IsVisible())
1967 bState = true;
1968 rSet.Put(SfxBoolItem(SID_ELEMENTSDOCKINGWINDOW, bState));
1970 break;
1971 case SID_TOOLBOX:
1973 bool bState = false;
1974 SfxChildWindow *pChildWnd = GetViewFrame()->
1975 GetChildWindow( SmToolBoxWrapper::GetChildWindowId() );
1976 if (pChildWnd && pChildWnd->GetWindow()->IsVisible())
1977 bState = true;
1978 rSet.Put(SfxBoolItem(SID_TOOLBOX, bState));
1980 break;
1987 SmViewShell::SmViewShell(SfxViewFrame *pFrame_, SfxViewShell *):
1988 SfxViewShell(pFrame_, SFX_VIEW_HAS_PRINTOPTIONS | SFX_VIEW_CAN_PRINT),
1989 pImpl( new SmViewShell_Impl ),
1990 aGraphic(this),
1991 aGraphicController(aGraphic, SID_GAPHIC_SM, pFrame_->GetBindings())
1992 , bInsertIntoEditWindow(false)
1994 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SmViewShell" );
1996 SetStatusText(OUString());
1997 SetWindow(&aGraphic);
1998 SfxShell::SetName(OUString("SmView"));
1999 SfxShell::SetUndoManager( &GetDoc()->GetEditEngine().GetUndoManager() );
2000 SetHelpId( HID_SMA_VIEWSHELL_DOCUMENT );
2004 SmViewShell::~SmViewShell()
2006 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::~SmViewShell" );
2008 //!! this view shell is not active anymore !!
2009 // Thus 'SmGetActiveView' will give a 0 pointer.
2010 // Thus we need to supply this view as argument
2011 SmEditWindow *pEditWin = GetEditWindow();
2012 if (pEditWin)
2013 pEditWin->DeleteEditView( *this );
2014 delete pImpl;
2017 void SmViewShell::Deactivate( sal_Bool bIsMDIActivate )
2019 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Deactivate" );
2021 SmEditWindow *pEdit = GetEditWindow();
2022 if ( pEdit )
2023 pEdit->Flush();
2025 SfxViewShell::Deactivate( bIsMDIActivate );
2029 void SmViewShell::Activate( sal_Bool bIsMDIActivate )
2031 RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Activate" );
2033 SfxViewShell::Activate( bIsMDIActivate );
2035 SmEditWindow *pEdit = GetEditWindow();
2036 if ( pEdit )
2038 //! Since there is no way to be informed if a "drag and drop"
2039 //! event has taken place, we call SetText here in order to
2040 //! syncronize the GraphicWindow display with the text in the
2041 //! EditEngine.
2042 SmDocShell *pDoc = GetDoc();
2043 pDoc->SetText( pDoc->GetEditEngine().GetText( LINEEND_LF ) );
2045 if ( bIsMDIActivate )
2046 pEdit->GrabFocus();
2050 IMPL_LINK( SmViewShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
2052 OSL_ENSURE( _pFileDlg, "SmViewShell::DialogClosedHdl(): no file dialog" );
2053 OSL_ENSURE( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2055 if ( ERRCODE_NONE == _pFileDlg->GetError() )
2057 SfxMedium* pMedium = pImpl->pDocInserter->CreateMedium();
2059 if ( pMedium != NULL )
2061 if ( pMedium->IsStorage() )
2062 Insert( *pMedium );
2063 else
2064 InsertFrom( *pMedium );
2065 delete pMedium;
2067 SmDocShell* pDoc = GetDoc();
2068 pDoc->UpdateText();
2069 pDoc->ArrangeFormula();
2070 pDoc->Repaint();
2071 // adjust window, repaint, increment ModifyCount,...
2072 GetViewFrame()->GetBindings().Invalidate(SID_GAPHIC_SM);
2076 pImpl->pRequest->SetReturnValue( SfxBoolItem( pImpl->pRequest->GetSlot(), true ) );
2077 pImpl->pRequest->Done();
2078 return 0;
2081 void SmViewShell::Notify( SfxBroadcaster& , const SfxHint& rHint )
2083 if ( rHint.IsA(TYPE(SfxSimpleHint)) )
2085 switch( ( (SfxSimpleHint&) rHint ).GetId() )
2087 case SFX_HINT_MODECHANGED:
2088 case SFX_HINT_DOCCHANGED:
2089 GetViewFrame()->GetBindings().InvalidateAll(false);
2090 break;
2091 default:
2092 break;
2097 bool SmViewShell::IsInlineEditEnabled() const
2099 return pImpl->aOpts.IsExperimentalMode();
2102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */