1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: view.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
35 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
37 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38 #include <com/sun/star/accessibility/XAccessible.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <comphelper/processfactory.hxx>
42 #include <comphelper/storagehelper.hxx>
43 #include <rtl/logfile.hxx>
44 #include <sfx2/app.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/docfile.hxx>
47 #include <sfx2/docfilt.hxx>
48 #include <sfx2/docinsert.hxx>
49 #include <sfx2/filedlghelper.hxx>
50 #include <sfx2/msg.hxx>
51 #include <sfx2/objface.hxx>
52 #include <sfx2/printer.hxx>
53 #include <sfx2/request.hxx>
54 #include <svtools/eitem.hxx>
55 #include <svtools/intitem.hxx>
56 #include <svtools/itemset.hxx>
57 #include <svtools/poolitem.hxx>
58 #include <svtools/ptitem.hxx>
59 #include <svtools/stritem.hxx>
60 #include <svtools/transfer.hxx>
61 #include <svtools/undo.hxx>
62 #include <svtools/whiter.hxx>
63 #include <svx/dialogs.hrc>
64 #include <svx/editeng.hxx>
65 #include <svx/svxdlg.hxx>
66 #include <svx/zoomitem.hxx>
67 #include <vcl/decoview.hxx>
68 #include <vcl/menu.hxx>
69 #include <vcl/msgbox.hxx>
70 #include <vcl/wrkwin.hxx>
75 #include "document.hxx"
76 #include "starmath.hrc"
77 #include "toolbox.hxx"
78 #include "mathmlimport.hxx"
84 #define SPLITTERWIDTH 2
90 #include "smslots.hxx"
94 using namespace com::sun::star
;
95 using namespace com::sun::star::accessibility
;
96 using namespace com::sun::star::uno
;
98 //////////////////////////////////////////////////////////////////////
100 SmGraphicWindow::SmGraphicWindow(SmViewShell
* pShell
):
101 ScrollableWindow(&pShell
->GetViewFrame()->GetWindow(), 0),
105 bIsCursorVisible(FALSE
)
107 // docking windows are usually hidden (often already done in the
108 // resource) and will be shown by the sfx framework.
111 const Fraction
aFraction (1,1);
112 SetMapMode( MapMode(MAP_100TH_MM
, Point(), aFraction
, aFraction
));
114 ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
118 SetHelpId(HID_SMA_WIN_DOCUMENT
);
119 SetUniqueId(HID_SMA_WIN_DOCUMENT
);
122 SmGraphicWindow::~SmGraphicWindow()
125 pAccessible
->ClearWin(); // make Accessible defunctional
126 // Note: memory for pAccessible will be freed when the reference
127 // xAccessible is released.
130 void SmGraphicWindow::StateChanged( StateChangedType eType
)
132 if ( eType
== STATE_CHANGE_INITSHOW
)
134 ScrollableWindow::StateChanged( eType
);
138 void SmGraphicWindow::ApplyColorConfigValues( const svtools::ColorConfig
&rColorCfg
)
140 // Note: SetTextColor not necessary since the nodes that
141 // get painted have the color information.
142 #if OSL_DEBUG_LEVEL > 1
143 // ColorData nVal = rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor;
145 SetBackground( Color( (ColorData
) rColorCfg
.GetColorValue(svtools::DOCCOLOR
).nColor
) );
150 void SmGraphicWindow::DataChanged( const DataChangedEvent
& rEvt
)
152 ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
154 ScrollableWindow::DataChanged( rEvt
);
158 void SmGraphicWindow::MouseButtonDown(const MouseEvent
& rMEvt
)
160 ScrollableWindow::MouseButtonDown(rMEvt
);
163 // set formula-cursor and selection of edit window according to the
164 // position clicked at
166 DBG_ASSERT(rMEvt
.GetClicks() > 0, "Sm : 0 clicks");
167 if ( rMEvt
.IsLeft() && pViewShell
->GetEditWindow() )
169 const SmNode
*pTree
= pViewShell
->GetDoc()->GetFormulaTree();
170 //! kann NULL sein! ZB wenn bereits beim laden des Dokuments (bevor der
171 //! Parser angeworfen wurde) ins Fenster geklickt wird.
175 // get click position relativ to formula
176 Point
aPos (PixelToLogic(rMEvt
.GetPosPixel())
177 - GetFormulaDrawPos());
179 // if it was clicked inside the formula then get the appropriate node
180 const SmNode
*pNode
= 0;
181 if (pTree
->OrientedDist(aPos
) <= 0)
182 pNode
= pTree
->FindRectClosestTo(aPos
);
185 { SmEditWindow
*pEdit
= pViewShell
->GetEditWindow();
186 const SmToken
aToken (pNode
->GetToken());
189 // include introducing symbols of special char and text
191 USHORT nExtra
= (aToken
.eType
== TSPECIAL
|| aToken
.eType
== TTEXT
) ? 1 : 0;
193 // set selection to the beginning of the token
194 ESelection
aSel (aToken
.nRow
- 1, aToken
.nCol
- 1 - nExtra
);
196 if (rMEvt
.GetClicks() != 1)
197 { // select whole token
198 // for text include terminating symbol (ie '"')
199 aSel
.nEndPos
+= aToken
.aText
.Len() + nExtra
200 + (aToken
.eType
== TTEXT
? 1 : 0);
203 // set selection to the beginning of the token
204 ESelection
aSel (aToken
.nRow
- 1, aToken
.nCol
- 1);
206 if (rMEvt
.GetClicks() != 1 || aToken
.eType
== TPLACE
)
207 aSel
.nEndPos
= aSel
.nEndPos
+ sal::static_int_cast
< USHORT
>(aToken
.aText
.Len());
209 pEdit
->SetSelection(aSel
);
212 // allow for immediate editing and
213 //! implicitly synchronize the cursor position mark in this window
219 void SmGraphicWindow::GetFocus()
222 if (xAccessible.is())
224 uno::Any aOldValue, aNewValue;
225 // aOldValue remains empty
226 aNewValue <<= AccessibleStateType::FOCUSED;
227 pAccessible->LaunchEvent( AccessibleEventId::STATE_CHANGED,
228 aOldValue, aNewValue );
233 void SmGraphicWindow::LoseFocus()
235 ScrollableWindow::LoseFocus();
236 if (xAccessible
.is())
238 uno::Any aOldValue
, aNewValue
;
239 aOldValue
<<= AccessibleStateType::FOCUSED
;
240 // aNewValue remains empty
241 pAccessible
->LaunchEvent( AccessibleEventId::STATE_CHANGED
,
242 aOldValue
, aNewValue
);
246 void SmGraphicWindow::ShowCursor(BOOL bShow
)
247 // shows or hides the formula-cursor depending on 'bShow' is TRUE or not
249 BOOL bInvert
= bShow
!= IsCursorVisible();
252 InvertTracking(aCursorRect
, SHOWTRACK_SMALL
| SHOWTRACK_WINDOW
);
254 SetIsCursorVisible(bShow
);
258 void SmGraphicWindow::SetCursor(const SmNode
*pNode
)
260 const SmNode
*pTree
= pViewShell
->GetDoc()->GetFormulaTree();
262 // get appropriate rectangle
263 Point
aOffset (pNode
->GetTopLeft() - pTree
->GetTopLeft()),
264 aTLPos (GetFormulaDrawPos() + aOffset
);
265 aTLPos
.X() -= pNode
->GetItalicLeftSpace();
266 Size
aSize (pNode
->GetItalicSize());
267 Point
aBRPos (aTLPos
.X() + aSize
.Width(), aTLPos
.Y() + aSize
.Height());
269 SetCursor(Rectangle(aTLPos
, aSize
));
272 void SmGraphicWindow::SetCursor(const Rectangle
&rRect
)
273 // sets cursor to new position (rectangle) 'rRect'.
274 // The old cursor will be removed, and the new one will be shown if
275 // that is activated in the ConfigItem
277 SmModule
*pp
= SM_MOD1();
279 if (IsCursorVisible())
280 ShowCursor(FALSE
); // clean up remainings of old cursor
282 if (pp
->GetConfig()->IsShowFormulaCursor())
283 ShowCursor(TRUE
); // draw new cursor
286 const SmNode
* SmGraphicWindow::SetCursorPos(USHORT nRow
, USHORT nCol
)
287 // looks for a VISIBLE node in the formula tree with it's token at
288 // (or around) the position 'nRow', 'nCol' in the edit window
289 // (row and column numbering starts with 1 there!).
290 // If there is such a node the formula-cursor is set to cover that nodes
291 // rectangle. If not the formula-cursor will be hidden.
292 // In any case the search result is being returned.
294 // find visible node with token at nRow, nCol
295 const SmNode
*pTree
= pViewShell
->GetDoc()->GetFormulaTree(),
298 pNode
= pTree
->FindTokenAt(nRow
, nCol
);
309 void SmGraphicWindow::Paint(const Rectangle
&)
311 DBG_ASSERT(pViewShell
, "Sm : NULL pointer");
313 SmDocShell
&rDoc
= *pViewShell
->GetDoc();
316 rDoc
.Draw(*this, aPoint
); //! modifies aPoint to be the topleft
317 //! corner of the formula
318 SetFormulaDrawPos(aPoint
);
320 SetIsCursorVisible(FALSE
); // (old) cursor must be drawn again
322 const SmEditWindow
*pEdit
= pViewShell
->GetEditWindow();
324 { // get new position for formula-cursor (for possible altered formula)
326 SmGetLeftSelectionPart(pEdit
->GetSelection(), nRow
, nCol
);
329 const SmNode
*pFound
= SetCursorPos(nRow
, nCol
);
331 SmModule
*pp
= SM_MOD1();
332 if (pFound
&& pp
->GetConfig()->IsShowFormulaCursor())
338 void SmGraphicWindow::SetTotalSize ()
340 SmDocShell
&rDoc
= *pViewShell
->GetDoc();
341 const Size
aTmp( PixelToLogic( LogicToPixel( rDoc
.GetSize() )));
342 if ( aTmp
!= ScrollableWindow::GetTotalSize() )
343 ScrollableWindow::SetTotalSize( aTmp
);
347 void SmGraphicWindow::KeyInput(const KeyEvent
& rKEvt
)
349 if (! (GetView() && GetView()->KeyInput(rKEvt
)) )
350 ScrollableWindow::KeyInput(rKEvt
);
354 void SmGraphicWindow::Command(const CommandEvent
& rCEvt
)
356 BOOL bCallBase
= TRUE
;
357 if ( !pViewShell
->GetViewFrame()->GetFrame()->IsInPlace() )
359 switch ( rCEvt
.GetCommand() )
361 case COMMAND_CONTEXTMENU
:
363 GetParent()->ToTop();
364 SmResId
aResId( RID_VIEWMENU
);
365 PopupMenu
* pPopupMenu
= new PopupMenu(aResId
);
366 pPopupMenu
->SetSelectHdl(LINK(this, SmGraphicWindow
, MenuSelectHdl
));
368 if (rCEvt
.IsMouseEvent())
369 aPos
= rCEvt
.GetMousePosPixel();
370 DBG_ASSERT( pViewShell
, "view shell missing" );
372 // added for replaceability of context menus #96085, #93782
373 pViewShell
->GetViewFrame()->GetBindings().GetDispatcher()
374 ->ExecutePopup( aResId
, this, &aPos
);
375 //pPopupMenu->Execute( this, aPos );
384 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
385 if ( pWData
&& COMMAND_WHEEL_ZOOM
== pWData
->GetMode() )
387 USHORT nTmpZoom
= GetZoom();
388 if( 0L > pWData
->GetDelta() )
400 ScrollableWindow::Command (rCEvt
);
404 IMPL_LINK_INLINE_START( SmGraphicWindow
, MenuSelectHdl
, Menu
*, pMenu
)
406 SmViewShell
*pViewSh
= GetView();
408 pViewSh
->GetViewFrame()->GetDispatcher()->Execute( pMenu
->GetCurItemId() );
411 IMPL_LINK_INLINE_END( SmGraphicWindow
, MenuSelectHdl
, Menu
*, pMenu
)
414 void SmGraphicWindow::SetZoom(USHORT Factor
)
416 nZoom
= Min(Max((USHORT
) Factor
, (USHORT
) MINZOOM
), (USHORT
) MAXZOOM
);
417 Fraction
aFraction (nZoom
, 100);
418 SetMapMode( MapMode(MAP_100TH_MM
, Point(), aFraction
, aFraction
) );
420 SmViewShell
*pViewSh
= GetView();
422 pViewSh
->GetViewFrame()->GetBindings().Invalidate(SID_ATTR_ZOOM
);
427 void SmGraphicWindow::ZoomToFitInWindow()
429 SmDocShell
&rDoc
= *pViewShell
->GetDoc();
431 // set defined mapmode before calling 'LogicToPixel' below
432 SetMapMode(MapMode(MAP_100TH_MM
));
434 Size
aSize (LogicToPixel(rDoc
.GetSize()));
435 Size
aWindowSize (GetSizePixel());
437 if (aSize
.Width() > 0 && aSize
.Height() > 0)
439 long nVal
= Min ((85 * aWindowSize
.Width()) / aSize
.Width(),
440 (85 * aWindowSize
.Height()) / aSize
.Height());
441 SetZoom ( sal::static_int_cast
< USHORT
>(nVal
) );
445 uno::Reference
< XAccessible
> SmGraphicWindow::CreateAccessible()
449 pAccessible
= new SmGraphicAccessible( this );
450 xAccessible
= pAccessible
;
455 /**************************************************************************/
458 SmGraphicController::SmGraphicController(SmGraphicWindow
&rSmGraphic
,
460 SfxBindings
&rBindings
) :
461 SfxControllerItem(nId_
, rBindings
),
467 void SmGraphicController::StateChanged(USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
469 rGraphic
.SetTotalSize();
470 rGraphic
.Invalidate();
471 SfxControllerItem::StateChanged (nSID
, eState
, pState
);
475 /**************************************************************************/
478 SmEditController::SmEditController(SmEditWindow
&rSmEdit
,
480 SfxBindings
&rBindings
) :
481 SfxControllerItem(nId_
, rBindings
),
487 #if OSL_DEBUG_LEVEL > 1
488 SmEditController::~SmEditController()
494 void SmEditController::StateChanged(USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
496 const SfxStringItem
*pItem
= PTR_CAST(SfxStringItem
, pState
);
498 if ((pItem
!= NULL
) && (rEdit
.GetText() != pItem
->GetValue()))
499 rEdit
.SetText(pItem
->GetValue());
500 SfxControllerItem::StateChanged (nSID
, eState
, pState
);
504 /**************************************************************************/
506 SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings
*pBindings_
, SfxChildWindow
*pChildWindow
,
508 SfxDockingWindow(pBindings_
, pChildWindow
, pParent
, SmResId(RID_CMDBOXWINDOW
)),
510 aController (aEdit
, SID_TEXT
, *pBindings_
),
515 aInitialFocusTimer
.SetTimeoutHdl(LINK(this, SmCmdBoxWindow
, InitialFocusTimerHdl
));
516 aInitialFocusTimer
.SetTimeout(100);
520 SmCmdBoxWindow::~SmCmdBoxWindow ()
522 aInitialFocusTimer
.Stop();
527 SmViewShell
* SmCmdBoxWindow::GetView()
529 SfxViewShell
*pView
= GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
530 return PTR_CAST(SmViewShell
, pView
);
533 void SmCmdBoxWindow::Resize()
535 Rectangle aRect
= Rectangle(Point(0, 0), GetOutputSizePixel());
537 if (! IsFloatingMode())
539 switch (GetAlignment())
541 case SFX_ALIGN_TOP
: aRect
.Bottom()--; break;
542 case SFX_ALIGN_BOTTOM
: aRect
.Top()++; break;
543 case SFX_ALIGN_LEFT
: aRect
.Right()--; break;
544 case SFX_ALIGN_RIGHT
: aRect
.Left()++; break;
550 DecorationView
aView(this);
551 aRect
.Left() += 8; aRect
.Top() += 8;
552 aRect
.Right()-= 8; aRect
.Bottom()-= 8;
553 aRect
= aView
.DrawFrame( aRect
, FRAME_DRAW_DOUBLEIN
);
555 aEdit
.SetPosSizePixel(aRect
.TopLeft(), aRect
.GetSize());
556 SfxDockingWindow::Resize();
561 void SmCmdBoxWindow::Paint(const Rectangle
& /*rRect*/)
563 Rectangle aRect
= Rectangle(Point(0, 0), GetOutputSizePixel());
564 DecorationView
aView(this);
566 if (! IsFloatingMode())
569 switch (GetAlignment())
572 aFrom
= aRect
.BottomLeft(); aTo
= aRect
.BottomRight();
576 case SFX_ALIGN_BOTTOM
:
577 aFrom
= aRect
.TopLeft(); aTo
= aRect
.TopRight();
582 aFrom
= aRect
.TopRight(); aTo
= aRect
.BottomRight();
586 case SFX_ALIGN_RIGHT
:
587 aFrom
= aRect
.TopLeft(); aTo
= aRect
.BottomLeft();
594 DrawLine( aFrom
, aTo
);
595 aView
.DrawFrame(aRect
, FRAME_DRAW_OUT
);
597 aRect
.Left() += 8; aRect
.Top() += 8;
598 aRect
.Right()-= 8; aRect
.Bottom()-= 8;
599 aRect
= aView
.DrawFrame( aRect
, FRAME_DRAW_DOUBLEIN
);
603 Size
SmCmdBoxWindow::CalcDockingSize(SfxChildAlignment eAlign
)
608 case SFX_ALIGN_RIGHT
:
613 return SfxDockingWindow::CalcDockingSize(eAlign
);
617 SfxChildAlignment
SmCmdBoxWindow::CheckAlignment(SfxChildAlignment eActual
,
618 SfxChildAlignment eWish
)
623 case SFX_ALIGN_BOTTOM
:
624 case SFX_ALIGN_NOALIGNMENT
:
634 void SmCmdBoxWindow::StateChanged( StateChangedType nStateChange
)
636 if (STATE_CHANGE_INITSHOW
== nStateChange
)
638 Resize(); // #98848# avoid SmEditWindow not being painted correctly
640 // set initial position of window in floating mode
641 if (TRUE
== IsFloatingMode())
642 AdjustPosition(); //! don't change pos in docking-mode !
644 // // make sure the formula can be edited right away
645 // aEdit.GrabFocus();
647 // grab focus as above does not work...
648 // Thus we implement a timer based solution to get the inital
649 // focus in the Edit window.
650 aInitialFocusTimer
.Start();
653 SfxDockingWindow::StateChanged( nStateChange
);
657 IMPL_LINK( SmCmdBoxWindow
, InitialFocusTimerHdl
, Timer
*, EMPTYARG
/*pTimer*/ )
664 void SmCmdBoxWindow::AdjustPosition()
667 const Rectangle
aRect( aPt
, GetParent()->GetOutputSizePixel() );
668 Point
aTopLeft( Point( aRect
.Left(),
669 aRect
.Bottom() - GetSizePixel().Height() ) );
670 Point
aPos( GetParent()->OutputToScreenPixel( aTopLeft
) );
679 void SmCmdBoxWindow::ToggleFloatingMode()
681 SfxDockingWindow::ToggleFloatingMode();
683 if (GetFloatingWindow())
684 GetFloatingWindow()->SetMinOutputSizePixel(Size (200, 50));
688 void SmCmdBoxWindow::GetFocus()
694 /**************************************************************************/
697 SFX_IMPL_DOCKINGWINDOW(SmCmdBoxWrapper
, SID_CMDBOXWINDOW
);
699 SmCmdBoxWrapper::SmCmdBoxWrapper(Window
*pParentWindow
, USHORT nId
,
700 SfxBindings
*pBindings
,
701 SfxChildWinInfo
*pInfo
) :
702 SfxChildWindow(pParentWindow
, nId
)
704 pWindow
= new SmCmdBoxWindow(pBindings
, this, pParentWindow
);
706 // make window docked to the bottom initially (after first start)
707 eChildAlignment
= SFX_ALIGN_BOTTOM
;
708 ((SfxDockingWindow
*)pWindow
)->Initialize(pInfo
);
712 #if OSL_DEBUG_LEVEL > 1
713 SmCmdBoxWrapper::~SmCmdBoxWrapper()
719 /**************************************************************************/
721 struct SmViewShell_Impl
723 sfx2::DocumentInserter
* pDocInserter
;
724 SfxRequest
* pRequest
;
738 TYPEINIT1( SmViewShell
, SfxViewShell
);
740 SFX_IMPL_INTERFACE(SmViewShell
, SfxViewShell
, SmResId(0))
742 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS
| SFX_VISIBILITY_STANDARD
|
743 SFX_VISIBILITY_FULLSCREEN
| SFX_VISIBILITY_SERVER
,
744 SmResId(RID_MATH_TOOLBOX
));
745 //Dummy-Objectbar, damit es bei aktivieren nicht staendig zuppelt.
746 // Wegen #58705# entfernt (RID wurde nirgends verwendet)
747 // SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_SERVER,
748 // SmResId(RID_DRAW_OBJECTBAR) );
750 SFX_CHILDWINDOW_REGISTRATION(SmToolBoxWrapper::GetChildWindowId());
751 SFX_CHILDWINDOW_REGISTRATION(SmCmdBoxWrapper::GetChildWindowId());
755 SFX_IMPL_VIEWFACTORY(SmViewShell
, SmResId(RID_VIEWNAME
))
757 SFX_VIEW_REGISTRATION(SmDocShell
);
761 Size
SmViewShell::GetOptimalSizePixel() const
763 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::GetOptimalSizePixel" );
765 return aGraphic
.LogicToPixel( ((SmViewShell
*)this)->GetDoc()->GetSize() );
769 void SmViewShell::AdjustPosSizePixel(const Point
&rPos
, const Size
&rSize
)
771 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::AdjustPosSizePixel" );
773 aGraphic
.SetPosSizePixel(rPos
, rSize
);
777 void SmViewShell::InnerResizePixel(const Point
&rOfs
, const Size
&rSize
)
779 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::InnerResizePixel" );
781 Size aObjSize
= GetObjectShell()->GetVisArea().GetSize();
782 if ( aObjSize
.Width() > 0 && aObjSize
.Height() > 0 )
784 Size aProvidedSize
= GetWindow()->PixelToLogic( rSize
, MAP_100TH_MM
);
785 SfxViewShell::SetZoomFactor( Fraction( aProvidedSize
.Width(), aObjSize
.Width() ),
786 Fraction( aProvidedSize
.Height(), aObjSize
.Height() ) );
789 SetBorderPixel( SvBorder() );
790 GetGraphicWindow().SetPosSizePixel(rOfs
, rSize
);
791 GetGraphicWindow().SetTotalSize();
795 void SmViewShell::OuterResizePixel(const Point
&rOfs
, const Size
&rSize
)
797 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::OuterResizePixel" );
799 SmGraphicWindow
&rWin
= GetGraphicWindow();
800 rWin
.SetPosSizePixel(rOfs
, rSize
);
801 if (GetDoc()->IsPreview())
802 rWin
.ZoomToFitInWindow();
807 void SmViewShell::QueryObjAreaPixel( Rectangle
& rRect
) const
809 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::QueryObjAreaPixel" );
811 rRect
.SetSize( GetGraphicWindow().GetSizePixel() );
815 void SmViewShell::SetZoomFactor( const Fraction
&rX
, const Fraction
&rY
)
817 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::SetZoomFactor" );
819 const Fraction
&rFrac
= rX
< rY
? rX
: rY
;
820 GetGraphicWindow().SetZoom( (USHORT
) long(rFrac
* Fraction( 100, 1 )) );
822 //Um Rundungsfehler zu minimieren lassen wir von der Basisklasse ggf.
823 //auch die krummen Werte einstellen
824 SfxViewShell::SetZoomFactor( rX
, rY
);
828 Size
SmViewShell::GetTextLineSize(OutputDevice
& rDevice
, const String
& rLine
)
830 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::GetTextLineSize" );
833 Size
aSize(rDevice
.GetTextWidth(rLine
), rDevice
.GetTextHeight());
834 USHORT nTabs
= rLine
.GetTokenCount('\t');
838 long TabPos
= rDevice
.GetTextWidth('n') * 8;
842 for (USHORT i
= 0; i
< nTabs
; i
++)
845 aSize
.Width() = ((aSize
.Width() / TabPos
) + 1) * TabPos
;
847 aText
= rLine
.GetToken(i
, '\t');
848 aText
.EraseLeadingChars('\t');
849 aText
.EraseTrailingChars('\t');
850 aSize
.Width() += rDevice
.GetTextWidth(aText
);
858 Size
SmViewShell::GetTextSize(OutputDevice
& rDevice
, const String
& rText
, long MaxWidth
)
860 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::GetTextSize" );
866 USHORT nLines
= rText
.GetTokenCount('\n');
868 for (USHORT i
= 0; i
< nLines
; i
++)
870 aLine
= rText
.GetToken(i
, '\n');
871 aLine
.EraseAllChars('\r');
872 aLine
.EraseLeadingChars('\n');
873 aLine
.EraseTrailingChars('\n');
875 aSize
= GetTextLineSize(rDevice
, aLine
);
877 if (aSize
.Width() > MaxWidth
)
881 xub_StrLen m
= aLine
.Len();
884 for (xub_StrLen n
= 0; n
< nLen
; n
++)
886 sal_Unicode cLineChar
= aLine
.GetChar(n
);
887 if ((cLineChar
== ' ') || (cLineChar
== '\t'))
889 aText
= aLine
.Copy(0, n
);
890 if (GetTextLineSize(rDevice
, aText
).Width() < MaxWidth
)
897 aText
= aLine
.Copy(0, m
);
899 aSize
= GetTextLineSize(rDevice
, aText
);
900 TextSize
.Height() += aSize
.Height();
901 TextSize
.Width() = Max(TextSize
.Width(), Min(aSize
.Width(), MaxWidth
));
903 aLine
.EraseLeadingChars(' ');
904 aLine
.EraseLeadingChars('\t');
905 aLine
.EraseLeadingChars(' ');
907 while (aLine
.Len() > 0);
911 TextSize
.Height() += aSize
.Height();
912 TextSize
.Width() = Max(TextSize
.Width(), aSize
.Width());
920 void SmViewShell::DrawTextLine(OutputDevice
& rDevice
, const Point
& rPosition
, const String
& rLine
)
922 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::DrawTextLine" );
925 Point
aPoint (rPosition
);
926 USHORT nTabs
= rLine
.GetTokenCount('\t');
930 long TabPos
= rDevice
.GetTextWidth('n') * 8;
932 for (USHORT i
= 0; i
< nTabs
; i
++)
935 aPoint
.X() = ((aPoint
.X() / TabPos
) + 1) * TabPos
;
937 aText
= rLine
.GetToken(i
, '\t');
938 aText
.EraseLeadingChars('\t');
939 aText
.EraseTrailingChars('\t');
940 rDevice
.DrawText(aPoint
, aText
);
941 aPoint
.X() += rDevice
.GetTextWidth(aText
);
945 rDevice
.DrawText(aPoint
, rLine
);
949 void SmViewShell::DrawText(OutputDevice
& rDevice
, const Point
& rPosition
, const String
& rText
, USHORT MaxWidth
)
951 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::DrawText" );
953 USHORT nLines
= rText
.GetTokenCount('\n');
954 Point
aPoint (rPosition
);
959 for (USHORT i
= 0; i
< nLines
; i
++)
961 aLine
= rText
.GetToken(i
, '\n');
962 aLine
.EraseAllChars('\r');
963 aLine
.EraseLeadingChars('\n');
964 aLine
.EraseTrailingChars('\n');
965 aSize
= GetTextLineSize(rDevice
, aLine
);
966 if (aSize
.Width() > MaxWidth
)
970 xub_StrLen m
= aLine
.Len();
973 for (xub_StrLen n
= 0; n
< nLen
; n
++)
975 sal_Unicode cLineChar
= aLine
.GetChar(n
);
976 if ((cLineChar
== ' ') || (cLineChar
== '\t'))
978 aText
= aLine
.Copy(0, n
);
979 if (GetTextLineSize(rDevice
, aText
).Width() < MaxWidth
)
985 aText
= aLine
.Copy(0, m
);
988 DrawTextLine(rDevice
, aPoint
, aText
);
989 aPoint
.Y() += aSize
.Height();
991 aLine
.EraseLeadingChars(' ');
992 aLine
.EraseLeadingChars('\t');
993 aLine
.EraseLeadingChars(' ');
995 while (GetTextLineSize(rDevice
, aLine
).Width() > MaxWidth
);
997 // print the remaining text
1000 DrawTextLine(rDevice
, aPoint
, aLine
);
1001 aPoint
.Y() += aSize
.Height();
1006 DrawTextLine(rDevice
, aPoint
, aLine
);
1007 aPoint
.Y() += aSize
.Height();
1012 void SmViewShell::Impl_Print(
1013 OutputDevice
&rOutDev
, const SmPrintSize ePrintSize
,
1014 Rectangle aOutRect
, Point aZeroPoint
)
1016 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::Impl_Print" );
1018 SmModule
*pp
= SM_MOD1();
1021 rOutDev
.SetLineColor( Color(COL_BLACK
) );
1023 // output text on top
1024 if (pp
->GetConfig()->IsPrintTitle())
1026 Size
aSize600 (0, 600);
1027 Size
aSize650 (0, 650);
1028 Font
aFont(FAMILY_DONTKNOW
, aSize600
);
1030 aFont
.SetAlign(ALIGN_TOP
);
1031 aFont
.SetWeight(WEIGHT_BOLD
);
1032 aFont
.SetSize(aSize650
);
1033 aFont
.SetColor( Color(COL_BLACK
) );
1034 rOutDev
.SetFont(aFont
);
1036 Size
aTitleSize (GetTextSize(rOutDev
, GetDoc()->GetTitle(), aOutRect
.GetWidth() - 200));
1038 aFont
.SetWeight(WEIGHT_NORMAL
);
1039 aFont
.SetSize(aSize600
);
1040 rOutDev
.SetFont(aFont
);
1042 Size
aDescSize (GetTextSize(rOutDev
, GetDoc()->GetComment(), aOutRect
.GetWidth() - 200));
1044 if (pp
->GetConfig()->IsPrintFrame())
1045 rOutDev
.DrawRect(Rectangle(aOutRect
.TopLeft(),
1046 Size(aOutRect
.GetWidth(), 100 + aTitleSize
.Height() + 200 + aDescSize
.Height() + 100)));
1047 aOutRect
.Top() += 200;
1050 aFont
.SetWeight(WEIGHT_BOLD
);
1051 aFont
.SetSize(aSize650
);
1052 rOutDev
.SetFont(aFont
);
1053 Point
aPoint(aOutRect
.Left() + (aOutRect
.GetWidth() - aTitleSize
.Width()) / 2,
1055 DrawText(rOutDev
, aPoint
, GetDoc()->GetTitle(),
1056 sal::static_int_cast
< USHORT
>(aOutRect
.GetWidth() - 200));
1057 aOutRect
.Top() += aTitleSize
.Height() + 200;
1059 // output description
1060 aFont
.SetWeight(WEIGHT_NORMAL
);
1061 aFont
.SetSize(aSize600
);
1062 rOutDev
.SetFont(aFont
);
1063 aPoint
.X() = aOutRect
.Left() + (aOutRect
.GetWidth() - aDescSize
.Width()) / 2;
1064 aPoint
.Y() = aOutRect
.Top();
1065 DrawText(rOutDev
, aPoint
, GetDoc()->GetComment(),
1066 sal::static_int_cast
< USHORT
>(aOutRect
.GetWidth() - 200));
1067 aOutRect
.Top() += aDescSize
.Height() + 300;
1070 // output text on bottom
1071 if (pp
->GetConfig()->IsPrintFormulaText())
1073 // Font aFont(FAMILY_DONTKNOW, Size(0, 600));
1076 aFont
.SetAlign(ALIGN_TOP
);
1077 aFont
.SetColor( Color(COL_BLACK
) );
1080 rOutDev
.SetFont(aFont
);
1082 Size
aSize (GetTextSize(rOutDev
, GetDoc()->GetText(), aOutRect
.GetWidth() - 200));
1084 aOutRect
.Bottom() -= aSize
.Height() + 600;
1086 if (pp
->GetConfig()->IsPrintFrame())
1087 rOutDev
.DrawRect(Rectangle(aOutRect
.BottomLeft(),
1088 Size(aOutRect
.GetWidth(), 200 + aSize
.Height() + 200)));
1090 Point
aPoint (aOutRect
.Left() + (aOutRect
.GetWidth() - aSize
.Width()) / 2,
1091 aOutRect
.Bottom() + 300);
1092 DrawText(rOutDev
, aPoint
, GetDoc()->GetText(),
1093 sal::static_int_cast
< USHORT
>(aOutRect
.GetWidth() - 200));
1094 aOutRect
.Bottom() -= 200;
1097 if (pp
->GetConfig()->IsPrintFrame())
1098 rOutDev
.DrawRect(aOutRect
);
1100 aOutRect
.Top() += 100;
1101 aOutRect
.Left() += 100;
1102 aOutRect
.Bottom() -= 100;
1103 aOutRect
.Right() -= 100;
1105 Size
aSize (GetDoc()->GetSize());
1107 MapMode OutputMapMode
;
1110 case PRINT_SIZE_NORMAL
:
1111 OutputMapMode
= MapMode(MAP_100TH_MM
);
1114 case PRINT_SIZE_SCALED
:
1115 if ((aSize
.Width() > 0) && (aSize
.Height() > 0))
1117 Size
OutputSize (rOutDev
.LogicToPixel(Size(aOutRect
.GetWidth(),
1118 aOutRect
.GetHeight()), MapMode(MAP_100TH_MM
)));
1119 Size
GraphicSize (rOutDev
.LogicToPixel(aSize
, MapMode(MAP_100TH_MM
)));
1120 USHORT nZ
= (USHORT
) Min((long)Fraction(OutputSize
.Width() * 100L, GraphicSize
.Width()),
1121 (long)Fraction(OutputSize
.Height() * 100L, GraphicSize
.Height()));
1122 Fraction
aFraction ((USHORT
) Max ((USHORT
) MINZOOM
, Min((USHORT
) MAXZOOM
, (USHORT
) (nZ
- 10))), (USHORT
) 100);
1124 OutputMapMode
= MapMode(MAP_100TH_MM
, aZeroPoint
, aFraction
, aFraction
);
1127 OutputMapMode
= MapMode(MAP_100TH_MM
);
1130 case PRINT_SIZE_ZOOMED
:
1132 Fraction
aFraction (pp
->GetConfig()->GetPrintZoomFactor(), 100);
1134 OutputMapMode
= MapMode(MAP_100TH_MM
, aZeroPoint
, aFraction
, aFraction
);
1139 aSize
= rOutDev
.PixelToLogic(rOutDev
.LogicToPixel(aSize
, OutputMapMode
),
1140 MapMode(MAP_100TH_MM
));
1142 Point
aPos (aOutRect
.Left() + (aOutRect
.GetWidth() - aSize
.Width()) / 2,
1143 aOutRect
.Top() + (aOutRect
.GetHeight() - aSize
.Height()) / 2);
1145 aPos
= rOutDev
.PixelToLogic(rOutDev
.LogicToPixel(aPos
, MapMode(MAP_100TH_MM
)),
1147 aOutRect
= rOutDev
.PixelToLogic(rOutDev
.LogicToPixel(aOutRect
, MapMode(MAP_100TH_MM
)),
1150 rOutDev
.SetMapMode(OutputMapMode
);
1151 rOutDev
.SetClipRegion(Region(aOutRect
));
1152 GetDoc()->Draw(rOutDev
, aPos
);
1153 rOutDev
.SetClipRegion();
1158 USHORT
SmViewShell::Print(SfxProgress
&rProgress
, BOOL bIsAPI
, PrintDialog
*pPrintDialog
)
1160 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::Print" );
1162 SmPrinterAccess
aPrinterAccess( *GetDoc() );
1163 Printer
*pPrinter
= aPrinterAccess
.GetPrinter();
1164 //OutputDevice *pOutDev = pPrinter;
1166 SfxViewShell::Print (rProgress
, bIsAPI
, pPrintDialog
);
1168 pPrinter
->StartPage();
1171 Rectangle
OutputRect( aZeroPoint
, pPrinter
->GetOutputSize() );
1173 Point
aPrtPageOffset( pPrinter
->GetPageOffset() );
1174 Size
aPrtPaperSize ( pPrinter
->GetPaperSize() );
1176 // set minimum top and bottom border
1177 if (aPrtPageOffset
.Y() < 2000)
1178 OutputRect
.Top() += 2000 - aPrtPageOffset
.Y();
1179 if ((aPrtPaperSize
.Height() - (aPrtPageOffset
.Y() + OutputRect
.Bottom())) < 2000)
1180 OutputRect
.Bottom() -= 2000 - (aPrtPaperSize
.Height() -
1181 (aPrtPageOffset
.Y() + OutputRect
.Bottom()));
1183 // set minimum left and right border
1184 if (aPrtPageOffset
.X() < 2500)
1185 OutputRect
.Left() += 2500 - aPrtPageOffset
.X();
1186 if ((aPrtPaperSize
.Width() - (aPrtPageOffset
.X() + OutputRect
.Right())) < 1500)
1187 OutputRect
.Right() -= 1500 - (aPrtPaperSize
.Width() -
1188 (aPrtPageOffset
.X() + OutputRect
.Right()));
1190 SmModule
*pp
= SM_MOD1();
1191 Impl_Print( *pPrinter
, pp
->GetConfig()->GetPrintSize(),
1192 OutputRect
, aZeroPoint
);
1194 pPrinter
->EndPage();
1200 SfxPrinter
* SmViewShell::GetPrinter(BOOL bCreate
)
1202 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::GetPrinter" );
1204 SmDocShell
*pDoc
= GetDoc();
1205 if ( pDoc
->HasPrinter() || bCreate
)
1206 return pDoc
->GetPrinter();
1211 USHORT
SmViewShell::SetPrinter(SfxPrinter
*pNewPrinter
, USHORT nDiffFlags
, bool )
1213 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::SetPrinter" );
1214 SfxPrinter
*pOld
= GetDoc()->GetPrinter();
1215 if ( pOld
&& pOld
->IsPrinting() )
1216 return SFX_PRINTERROR_BUSY
;
1218 if ((nDiffFlags
& SFX_PRINTER_PRINTER
) == SFX_PRINTER_PRINTER
)
1219 GetDoc()->SetPrinter( pNewPrinter
);
1221 if ((nDiffFlags
& SFX_PRINTER_OPTIONS
) == SFX_PRINTER_OPTIONS
)
1223 SmModule
*pp
= SM_MOD1();
1224 pp
->GetConfig()->ItemSetToConfig(pNewPrinter
->GetOptions());
1230 SfxTabPage
* SmViewShell::CreatePrintOptionsPage(Window
*pParent
,
1231 const SfxItemSet
&rOptions
)
1233 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::CreatePrintOptionsPage" );
1235 return SmPrintOptionsTabPage::Create(pParent
, rOptions
);
1239 SmEditWindow
*SmViewShell::GetEditWindow()
1241 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::GetEditWindow" );
1243 SmCmdBoxWrapper
*pWrapper
= (SmCmdBoxWrapper
*) GetViewFrame()->
1244 GetChildWindow( SmCmdBoxWrapper::GetChildWindowId() );
1246 if (pWrapper
!= NULL
)
1248 SmEditWindow
*pEditWin
= pWrapper
->GetEditWindow();
1249 DBG_ASSERT( pEditWin
, "SmEditWindow missing" );
1257 void SmViewShell::SetStatusText(const String
& Text
)
1259 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::SetStatusText" );
1262 GetViewFrame()->GetBindings().Invalidate(SID_TEXTSTATUS
);
1266 void SmViewShell::ShowError( const SmErrorDesc
*pErrorDesc
)
1268 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::ShowError" );
1270 DBG_ASSERT(GetDoc(), "Sm : Document missing");
1271 if (pErrorDesc
|| 0 != (pErrorDesc
= GetDoc()->GetParser().GetError(0)) )
1273 SetStatusText( pErrorDesc
->Text
);
1274 GetEditWindow()->MarkError( Point( pErrorDesc
->pNode
->GetColumn(),
1275 pErrorDesc
->pNode
->GetRow()));
1280 void SmViewShell::NextError()
1282 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::NextError" );
1284 DBG_ASSERT(GetDoc(), "Sm : Document missing");
1285 const SmErrorDesc
*pErrorDesc
= GetDoc()->GetParser().NextError();
1288 ShowError( pErrorDesc
);
1292 void SmViewShell::PrevError()
1294 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::PrevError" );
1296 DBG_ASSERT(GetDoc(), "Sm : Document missing");
1297 const SmErrorDesc
*pErrorDesc
= GetDoc()->GetParser().PrevError();
1300 ShowError( pErrorDesc
);
1304 BOOL
SmViewShell::Insert( SfxMedium
& rMedium
)
1306 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::Insert" );
1308 SmDocShell
*pDoc
= GetDoc();
1309 String
aText( pDoc
->GetText() );
1310 String aTemp
= aText
;
1311 BOOL bRet
= FALSE
, bChkOldVersion
= TRUE
;
1313 uno::Reference
< embed::XStorage
> xStorage
= rMedium
.GetStorage();
1314 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY
);
1315 if ( xNameAccess
.is() && xNameAccess
->getElementNames().getLength() )
1317 if ( xNameAccess
->hasByName( C2S( "content.xml" ) ) || xNameAccess
->hasByName( C2S( "Content.xml" ) ))
1319 bChkOldVersion
= FALSE
;
1320 // is this a fabulous math package ?
1321 Reference
<com::sun::star::frame::XModel
> xModel(pDoc
->GetModel());
1322 SmXMLImportWrapper
aEquation(xModel
); //!! modifies the result of pDoc->GetText() !!
1323 bRet
= 0 == aEquation
.Import(rMedium
);
1329 aText
= pDoc
->GetText();
1330 SmEditWindow
*pEditWin
= GetEditWindow();
1332 pEditWin
->InsertText( aText
);
1335 DBG_ERROR( "EditWindow missing" );
1341 pDoc
->SetModified(TRUE
);
1343 SfxBindings
&rBnd
= GetViewFrame()->GetBindings();
1344 rBnd
.Invalidate(SID_GAPHIC_SM
);
1345 rBnd
.Invalidate(SID_TEXT
);
1351 BOOL
SmViewShell::InsertFrom(SfxMedium
&rMedium
)
1353 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::InsertFrom" );
1355 BOOL bSuccess
= FALSE
;
1356 SmDocShell
*pDoc
= GetDoc();
1357 SvStream
*pStream
= rMedium
.GetInStream();
1358 String
aText( pDoc
->GetText() );
1359 String aTemp
= aText
;
1363 const String
& rFltName
= rMedium
.GetFilter()->GetFilterName();
1364 if ( rFltName
.EqualsAscii(MATHML_XML
) )
1366 Reference
<com::sun::star::frame::XModel
> xModel( pDoc
->GetModel() );
1367 SmXMLImportWrapper
aEquation(xModel
); //!! modifies the result of pDoc->GetText() !!
1368 bSuccess
= 0 == aEquation
.Import(rMedium
);
1372 //bSuccess = ImportSM20File( pStream );
1378 aText
= pDoc
->GetText();
1379 SmEditWindow
*pEditWin
= GetEditWindow();
1381 pEditWin
->InsertText( aText
);
1384 DBG_ERROR( "EditWindow missing" );
1390 pDoc
->SetModified(TRUE
);
1392 SfxBindings
&rBnd
= GetViewFrame()->GetBindings();
1393 rBnd
.Invalidate(SID_GAPHIC_SM
);
1394 rBnd
.Invalidate(SID_TEXT
);
1401 void SmViewShell::Execute(SfxRequest
& rReq
)
1403 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::Execute" );
1405 SmEditWindow
*pWin
= GetEditWindow();
1407 switch (rReq
.GetSlot())
1409 case SID_FORMULACURSOR
:
1411 SmModule
*pp
= SM_MOD1();
1413 const SfxItemSet
*pArgs
= rReq
.GetArgs();
1414 const SfxPoolItem
*pItem
;
1418 SFX_ITEM_SET
== pArgs
->GetItemState( SID_FORMULACURSOR
, FALSE
, &pItem
))
1419 bVal
= ((SfxBoolItem
*) pItem
)->GetValue();
1421 bVal
= !pp
->GetConfig()->IsShowFormulaCursor();
1423 pp
->GetConfig()->SetShowFormulaCursor(bVal
);
1424 GetGraphicWindow().ShowCursor(bVal
);
1430 GetDoc()->SetText( pWin
->GetText() );
1431 SetStatusText(String());
1433 GetDoc()->Repaint();
1438 case SID_FITINWINDOW
:
1439 aGraphic
.ZoomToFitInWindow();
1443 aGraphic
.SetZoom(50);
1447 aGraphic
.SetZoom(100);
1451 aGraphic
.SetZoom(200);
1455 aGraphic
.SetZoom(aGraphic
.GetZoom() + 25);
1459 DBG_ASSERT(aGraphic
.GetZoom() >= 25, "Sm: falsches USHORT Argument");
1460 aGraphic
.SetZoom(aGraphic
.GetZoom() - 25);
1463 case SID_COPYOBJECT
:
1465 //TODO/LATER: does not work because of UNO Tunneling - will be fixed later
1466 Reference
< datatransfer::XTransferable
> xTrans( GetDoc()->GetModel(), uno::UNO_QUERY
);
1469 Reference
< lang::XUnoTunnel
> xTnnl( xTrans
, uno::UNO_QUERY
);
1472 TransferableHelper
* pTrans
= reinterpret_cast< TransferableHelper
* >(
1473 sal::static_int_cast
< sal_uIntPtr
>(
1474 xTnnl
->getSomething( TransferableHelper::getUnoTunnelId() )));
1476 pTrans
->CopyToClipboard( this ? GetEditWindow() : 0 );
1482 case SID_PASTEOBJECT
:
1484 TransferableDataHelper
aData( TransferableDataHelper::CreateFromSystemClipboard(this ? GetEditWindow(): 0) );
1485 uno::Reference
< io::XInputStream
> xStrm
;
1486 SotFormatStringId nId
;
1487 if( aData
.GetTransferable().is() &&
1488 ( aData
.HasFormat( nId
= SOT_FORMATSTR_ID_EMBEDDED_OBJ
) ||
1489 (aData
.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
) &&
1490 aData
.HasFormat( nId
= SOT_FORMATSTR_ID_EMBED_SOURCE
))) &&
1491 aData
.GetInputStream( nId
, xStrm
) && xStrm
.is() )
1495 uno::Reference
< embed::XStorage
> xStorage
=
1496 ::comphelper::OStorageHelper::GetStorageFromInputStream( xStrm
, ::comphelper::getProcessServiceFactory() );
1497 uno::Reference
< beans::XPropertySet
> xProps( xStorage
, uno::UNO_QUERY
);
1498 SfxMedium
aMedium( xStorage
, String() );
1500 GetDoc()->UpdateText();
1502 catch (uno::Exception
&)
1504 DBG_ERROR( "SmViewShell::Execute (SID_PASTEOBJECT): failed to get storage from input stream" );
1519 if (pWin
->IsAllSelected())
1521 GetViewFrame()->GetDispatcher()->Execute(
1522 SID_COPYOBJECT
, SFX_CALLMODE_STANDARD
,
1523 new SfxVoidItem(SID_COPYOBJECT
), 0L);
1532 BOOL bCallExec
= 0 == pWin
;
1535 TransferableDataHelper
aDataHelper(
1536 TransferableDataHelper::CreateFromSystemClipboard(
1539 if( aDataHelper
.GetTransferable().is() &&
1540 aDataHelper
.HasFormat( FORMAT_STRING
))
1547 GetViewFrame()->GetDispatcher()->Execute(
1548 SID_PASTEOBJECT
, SFX_CALLMODE_STANDARD
,
1549 new SfxVoidItem(SID_PASTEOBJECT
), 0L);
1564 case SID_INSERTCOMMAND
:
1566 const SfxInt16Item
& rItem
=
1567 (const SfxInt16Item
&)rReq
.GetArgs()->Get(SID_INSERTCOMMAND
);
1570 pWin
->InsertCommand(rItem
.GetValue());
1574 case SID_INSERTTEXT
:
1576 const SfxStringItem
& rItem
=
1577 (const SfxStringItem
&)rReq
.GetArgs()->Get(SID_INSERTTEXT
);
1580 pWin
->InsertText(rItem
.GetValue());
1584 case SID_INSERT_FORMULA
:
1586 delete pImpl
->pRequest
;
1587 pImpl
->pRequest
= new SfxRequest( rReq
);
1588 delete pImpl
->pDocInserter
;
1589 pImpl
->pDocInserter
=
1590 new ::sfx2::DocumentInserter( 0, GetDoc()->GetFactory().GetFactoryName(), 0 );
1591 pImpl
->pDocInserter
->StartExecuteModal( LINK( this, SmViewShell
, DialogClosedHdl
) );
1610 pWin
->SelNextMark();
1618 pWin
->SelPrevMark();
1623 case SID_TEXTSTATUS
:
1625 if (rReq
.GetArgs() != NULL
)
1627 const SfxStringItem
& rItem
=
1628 (const SfxStringItem
&)rReq
.GetArgs()->Get(SID_TEXTSTATUS
);
1630 SetStatusText(rItem
.GetValue());
1636 case SID_GETEDITTEXT
:
1638 if (pWin
->GetText ().Len ()) GetDoc()->SetText( pWin
->GetText() );
1643 if ( !GetViewFrame()->GetFrame()->IsInPlace() )
1645 //CHINA001 SvxZoomDialog *pDlg = 0;
1646 AbstractSvxZoomDialog
*pDlg
= 0;
1647 const SfxItemSet
*pSet
= rReq
.GetArgs();
1650 SfxItemSet
aSet( GetDoc()->GetPool(), SID_ATTR_ZOOM
, SID_ATTR_ZOOM
);
1651 aSet
.Put( SvxZoomItem( SVX_ZOOM_PERCENT
, aGraphic
.GetZoom()));
1652 //CHINA001 pDlg = new SvxZoomDialog( &GetViewFrame()->GetWindow(), aSet);
1653 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
1656 pDlg
= pFact
->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aSet
, RID_SVXDLG_ZOOM
);
1657 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
1659 pDlg
->SetLimits( MINZOOM
, MAXZOOM
);
1660 if( pDlg
->Execute() != RET_CANCEL
)
1661 pSet
= pDlg
->GetOutputItemSet();
1665 const SvxZoomItem
&rZoom
= (const SvxZoomItem
&)pSet
->Get(SID_ATTR_ZOOM
);
1666 switch( rZoom
.GetType() )
1668 case SVX_ZOOM_PERCENT
:
1669 aGraphic
.SetZoom((USHORT
)rZoom
.GetValue ());
1672 case SVX_ZOOM_OPTIMAL
:
1673 aGraphic
.ZoomToFitInWindow();
1676 case SVX_ZOOM_PAGEWIDTH
:
1677 case SVX_ZOOM_WHOLEPAGE
:
1679 const MapMode
aMap( MAP_100TH_MM
);
1680 SfxPrinter
*pPrinter
= GetPrinter( TRUE
);
1682 Rectangle
OutputRect(aPoint
, pPrinter
->GetOutputSize());
1683 Size
OutputSize(pPrinter
->LogicToPixel(Size(OutputRect
.GetWidth(),
1684 OutputRect
.GetHeight()), aMap
));
1685 Size
GraphicSize(pPrinter
->LogicToPixel(GetDoc()->GetSize(), aMap
));
1686 USHORT nZ
= (USHORT
) Min((long)Fraction(OutputSize
.Width() * 100L, GraphicSize
.Width()),
1687 (long)Fraction(OutputSize
.Height() * 100L, GraphicSize
.Height()));
1688 aGraphic
.SetZoom (nZ
);
1702 GetViewFrame()->ToggleChildWindow( SmToolBoxWrapper::GetChildWindowId() );
1706 case SID_SYMBOLS_CATALOGUE
:
1709 // get device used to retrieve the FontList
1710 SmDocShell
*pDoc
= GetDoc();
1711 OutputDevice
*pDev
= pDoc
->GetPrinter();
1712 if (!pDev
|| pDev
->GetDevFontCount() == 0)
1713 pDev
= &SM_MOD1()->GetDefaultVirtualDev();
1714 DBG_ASSERT (pDev
, "device for font list missing" );
1716 SmModule
*pp
= SM_MOD1();
1717 SmSymbolDialog( NULL
, pDev
, pp
->GetSymSetManager(), *this ).Execute();
1725 void SmViewShell::GetState(SfxItemSet
&rSet
)
1727 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::GetState" );
1729 SfxWhichIter
aIter(rSet
);
1731 SmEditWindow
*pEditWin
= GetEditWindow();
1732 for (USHORT nWh
= aIter
.FirstWhich(); nWh
!= 0; nWh
= aIter
.NextWhich())
1739 if (! pEditWin
|| ! pEditWin
->IsSelected())
1740 rSet
.DisableItem(nWh
);
1744 if( !xClipEvtLstnr
.is() && pEditWin
)
1746 TransferableDataHelper
aDataHelper(
1747 TransferableDataHelper::CreateFromSystemClipboard(
1750 bPasteState
= aDataHelper
.GetTransferable().is() &&
1751 ( aDataHelper
.HasFormat( FORMAT_STRING
) ||
1752 aDataHelper
.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ
) ||
1753 (aDataHelper
.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
)
1754 && aDataHelper
.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
)));
1757 rSet
.DisableItem( nWh
);
1761 rSet
.Put(SvxZoomItem( SVX_ZOOM_PERCENT
, aGraphic
.GetZoom()));
1769 case SID_FITINWINDOW
:
1770 if ( GetViewFrame()->GetFrame()->IsInPlace() )
1771 rSet
.DisableItem( nWh
);
1780 if (! pEditWin
|| pEditWin
->IsEmpty())
1781 rSet
.DisableItem(nWh
);
1784 case SID_TEXTSTATUS
:
1786 rSet
.Put(SfxStringItem(nWh
, StatusText
));
1790 case SID_FORMULACURSOR
:
1792 SmModule
*pp
= SM_MOD1();
1793 rSet
.Put(SfxBoolItem(nWh
, pp
->GetConfig()->IsShowFormulaCursor()));
1799 BOOL bState
= FALSE
;
1800 SfxChildWindow
*pChildWnd
= GetViewFrame()->
1801 GetChildWindow( SmToolBoxWrapper::GetChildWindowId() );
1802 if (pChildWnd
&& pChildWnd
->GetWindow()->IsVisible())
1804 rSet
.Put(SfxBoolItem(SID_TOOLBOX
, bState
));
1813 SmViewShell::SmViewShell(SfxViewFrame
*pFrame_
, SfxViewShell
*):
1814 SfxViewShell(pFrame_
, SFX_VIEW_DISABLE_ACCELS
| SFX_VIEW_MAXIMIZE_FIRST
| SFX_VIEW_HAS_PRINTOPTIONS
| SFX_VIEW_CAN_PRINT
),
1816 aGraphicController(aGraphic
, SID_GAPHIC_SM
, pFrame_
->GetBindings()),
1817 pImpl( new SmViewShell_Impl
)
1819 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::SmViewShell" );
1821 // pViewFrame = &pFrame_->GetWindow();
1823 SetStatusText(String());
1824 SetWindow(&aGraphic
);
1825 SfxShell::SetName(C2S("SmView"));
1826 SfxShell::SetUndoManager( &GetDoc()->GetEditEngine().GetUndoManager() );
1827 SetHelpId( HID_SMA_VIEWSHELL_DOCUMENT
);
1831 SmViewShell::~SmViewShell()
1833 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::~SmViewShell" );
1835 //!! this view shell is not active anymore !!
1836 // Thus 'SmGetActiveView' will give a 0 pointer.
1837 // Thus we need to supply this view as argument
1838 SmEditWindow
*pEditWin
= GetEditWindow();
1840 pEditWin
->DeleteEditView( *this );
1844 void SmViewShell::Deactivate( BOOL bIsMDIActivate
)
1846 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::Deactivate" );
1848 SmEditWindow
*pEdit
= GetEditWindow();
1852 SfxViewShell::Deactivate( bIsMDIActivate
);
1856 void SmViewShell::Activate( BOOL bIsMDIActivate
)
1858 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmViewShell::Activate" );
1860 SfxViewShell::Activate( bIsMDIActivate
);
1862 SmEditWindow
*pEdit
= GetEditWindow();
1865 //! Since there is no way to be informed if a "drag and drop"
1866 //! event has taken place, we call SetText here in order to
1867 //! syncronize the GraphicWindow display with the text in the
1869 SmDocShell
*pDoc
= GetDoc();
1870 pDoc
->SetText( pDoc
->GetEditEngine().GetText( LINEEND_LF
) );
1872 if ( bIsMDIActivate
)
1877 //------------------------------------------------------------------
1879 IMPL_LINK( SmViewShell
, DialogClosedHdl
, sfx2::FileDialogHelper
*, _pFileDlg
)
1881 DBG_ASSERT( _pFileDlg
, "SmViewShell::DialogClosedHdl(): no file dialog" );
1882 DBG_ASSERT( pImpl
->pDocInserter
, "ScDocShell::DialogClosedHdl(): no document inserter" );
1884 if ( ERRCODE_NONE
== _pFileDlg
->GetError() )
1886 //USHORT nSlot = pImpl->pRequest->GetSlot();
1887 SfxMedium
* pMedium
= pImpl
->pDocInserter
->CreateMedium();
1889 if ( pMedium
!= NULL
)
1891 if ( pMedium
->IsStorage() )
1894 InsertFrom( *pMedium
);
1897 SmDocShell
* pDoc
= GetDoc();
1899 pDoc
->ArrangeFormula();
1901 // adjust window, repaint, increment ModifyCount,...
1902 GetViewFrame()->GetBindings().Invalidate(SID_GAPHIC_SM
);
1906 pImpl
->pRequest
->SetReturnValue( SfxBoolItem( pImpl
->pRequest
->GetSlot(), TRUE
) );
1907 pImpl
->pRequest
->Done();
1911 void SmViewShell::Notify( SfxBroadcaster
& , const SfxHint
& rHint
)
1913 if ( rHint
.IsA(TYPE(SfxSimpleHint
)) )
1915 switch( ( (SfxSimpleHint
&) rHint
).GetId() )
1917 case SFX_HINT_MODECHANGED
:
1918 case SFX_HINT_DOCCHANGED
:
1919 GetViewFrame()->GetBindings().InvalidateAll(FALSE
);