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