xref: /AOO41X/main/starmath/source/document.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_starmath.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/uno/Any.h>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <comphelper/accessibletexthelper.hxx>
37*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
39*cdf0e10cSrcweir #include <rtl/logfile.hxx>
40*cdf0e10cSrcweir #include <rtl/ustring.hxx>
41*cdf0e10cSrcweir #include <unotools/eventcfg.hxx>
42*cdf0e10cSrcweir #include <sfx2/event.hxx>
43*cdf0e10cSrcweir #include <sfx2/app.hxx>
44*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
45*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
46*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
47*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
48*cdf0e10cSrcweir #include <sfx2/msg.hxx>
49*cdf0e10cSrcweir #include <sfx2/objface.hxx>
50*cdf0e10cSrcweir #include <sfx2/printer.hxx>
51*cdf0e10cSrcweir #include <sfx2/request.hxx>
52*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
53*cdf0e10cSrcweir #include <sot/clsids.hxx>
54*cdf0e10cSrcweir #include <sot/exchange.hxx>
55*cdf0e10cSrcweir #include <sot/formats.hxx>
56*cdf0e10cSrcweir #include <sot/storage.hxx>
57*cdf0e10cSrcweir #include <svl/eitem.hxx>
58*cdf0e10cSrcweir #include <svl/fstathelper.hxx>
59*cdf0e10cSrcweir #include <svl/intitem.hxx>
60*cdf0e10cSrcweir #include <svl/itempool.hxx>
61*cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
62*cdf0e10cSrcweir #include <unotools/linguprops.hxx>
63*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
64*cdf0e10cSrcweir #include <svl/ptitem.hxx>
65*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
66*cdf0e10cSrcweir #include <svl/slstitm.hxx>
67*cdf0e10cSrcweir #include <svl/smplhint.hxx>
68*cdf0e10cSrcweir #include <svl/stritem.hxx>
69*cdf0e10cSrcweir #include <svtools/transfer.hxx>
70*cdf0e10cSrcweir #include <svl/undo.hxx>
71*cdf0e10cSrcweir #include <svl/urihelper.hxx>
72*cdf0e10cSrcweir #include <svl/whiter.hxx>
73*cdf0e10cSrcweir #include <editeng/editeng.hxx>
74*cdf0e10cSrcweir #include <editeng/editstat.hxx>
75*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
76*cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
77*cdf0e10cSrcweir #include <editeng/fontitem.hxx>
78*cdf0e10cSrcweir #include <editeng/unolingu.hxx>
79*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
80*cdf0e10cSrcweir #include <vcl/mapmod.hxx>
81*cdf0e10cSrcweir #include <tools/mapunit.hxx>
82*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
83*cdf0e10cSrcweir #include <sfx2/sfx.hrc>
84*cdf0e10cSrcweir #include <document.hxx>
85*cdf0e10cSrcweir #include <action.hxx>
86*cdf0e10cSrcweir #include <config.hxx>
87*cdf0e10cSrcweir #include <dialog.hxx>
88*cdf0e10cSrcweir #include <format.hxx>
89*cdf0e10cSrcweir #include <smdll.hxx>
90*cdf0e10cSrcweir #include <starmath.hrc>
91*cdf0e10cSrcweir #include <symbol.hxx>
92*cdf0e10cSrcweir #include <toolbox.hxx>
93*cdf0e10cSrcweir #include <unomodel.hxx>
94*cdf0e10cSrcweir #include <utility.hxx>
95*cdf0e10cSrcweir #include <view.hxx>
96*cdf0e10cSrcweir #include "mathtype.hxx"
97*cdf0e10cSrcweir #include "mathmlimport.hxx"
98*cdf0e10cSrcweir #include "mathmlexport.hxx"
99*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
100*cdf0e10cSrcweir #include <svx/svxids.hrc>
101*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir using namespace ::com::sun::star;
104*cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
105*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
106*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
107*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir #define DOCUMENT_BUFFER_SIZE	(sal_uInt16)32768
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir static const char __FAR_DATA pStarMathDoc[] = "StarMathDocument";
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir #define SmDocShell
115*cdf0e10cSrcweir #include "smslots.hxx"
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir ////////////////////////////////////////////////////////////
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir TYPEINIT1( SmDocShell, SfxObjectShell );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir SFX_IMPL_INTERFACE(SmDocShell, SfxObjectShell, SmResId(0))
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	SFX_POPUPMENU_REGISTRATION(SmResId(RID_VIEWMENU));
125*cdf0e10cSrcweir 	SFX_POPUPMENU_REGISTRATION(SmResId(RID_COMMANDMENU));
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir SFX_IMPL_OBJECTFACTORY(SmDocShell, SvGlobalName(SO3_SM_CLASSID), SFXOBJECTSHELL_STD_NORMAL, "smath" )
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir void SmDocShell::SFX_NOTIFY(SfxBroadcaster&, const TypeId&,
131*cdf0e10cSrcweir 					const SfxHint& rHint, const TypeId&)
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	switch (((SfxSimpleHint&)rHint).GetId())
134*cdf0e10cSrcweir 	{
135*cdf0e10cSrcweir 		case HINT_FORMATCHANGED:
136*cdf0e10cSrcweir 			SetFormulaArranged(sal_False);
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir             nModifyCount++;     //! see comment for SID_GAPHIC_SM in SmDocShell::GetState
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir             Repaint();
141*cdf0e10cSrcweir 			break;
142*cdf0e10cSrcweir 	}
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir void SmDocShell::LoadSymbols()
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::LoadSymbols" );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     SmModule *pp = SM_MOD();
150*cdf0e10cSrcweir     pp->GetSymbolManager().Load();
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir const String SmDocShell::GetComment() const
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetComment" );
157*cdf0e10cSrcweir     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
158*cdf0e10cSrcweir         const_cast<SmDocShell*>(this)->GetModel(), uno::UNO_QUERY_THROW);
159*cdf0e10cSrcweir     uno::Reference<document::XDocumentProperties> xDocProps(
160*cdf0e10cSrcweir         xDPS->getDocumentProperties());
161*cdf0e10cSrcweir     return xDocProps->getDescription();
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir void SmDocShell::SetText(const String& rBuffer)
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetText" );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	if (rBuffer != aText)
170*cdf0e10cSrcweir 	{
171*cdf0e10cSrcweir 		sal_Bool bIsEnabled = IsEnableSetModified();
172*cdf0e10cSrcweir 		if( bIsEnabled )
173*cdf0e10cSrcweir 			EnableSetModified( sal_False );
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 		aText = rBuffer;
176*cdf0e10cSrcweir         SetFormulaArranged( sal_False );
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir         Parse();
179*cdf0e10cSrcweir         //Repaint();
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir         SmViewShell *pViewSh = SmGetActiveView();
182*cdf0e10cSrcweir 		if( pViewSh )
183*cdf0e10cSrcweir         {
184*cdf0e10cSrcweir 			pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_TEXT);
185*cdf0e10cSrcweir             if ( SFX_CREATE_MODE_EMBEDDED == GetCreateMode() )
186*cdf0e10cSrcweir             {
187*cdf0e10cSrcweir                 // have SwOleClient::FormatChanged() to align the modified formula properly
188*cdf0e10cSrcweir                 // even if the vis area does not change (e.g. when formula text changes from
189*cdf0e10cSrcweir                 // "{a over b + c} over d" to "d over {a over b + c}"
190*cdf0e10cSrcweir                 SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir                 Repaint();
193*cdf0e10cSrcweir             }
194*cdf0e10cSrcweir             else
195*cdf0e10cSrcweir                 pViewSh->GetGraphicWindow().Invalidate();
196*cdf0e10cSrcweir         }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 		if ( bIsEnabled )
199*cdf0e10cSrcweir 			EnableSetModified( bIsEnabled );
200*cdf0e10cSrcweir 		SetModified(sal_True);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         // launch accessible event if necessary
203*cdf0e10cSrcweir         SmGraphicAccessible *pAcc = pViewSh ? pViewSh->GetGraphicWindow().GetAccessible_Impl() : 0;
204*cdf0e10cSrcweir         if (pAcc)
205*cdf0e10cSrcweir         {
206*cdf0e10cSrcweir 			Any aOldValue, aNewValue;
207*cdf0e10cSrcweir 			if ( comphelper::OCommonAccessibleText::implInitTextChangedEvent( aText, rBuffer, aOldValue, aNewValue ) )
208*cdf0e10cSrcweir 			{
209*cdf0e10cSrcweir 				pAcc->LaunchEvent( AccessibleEventId::TEXT_CHANGED,
210*cdf0e10cSrcweir 						aOldValue, aNewValue );
211*cdf0e10cSrcweir 			}
212*cdf0e10cSrcweir         }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir         if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
215*cdf0e10cSrcweir             OnDocumentPrinterChanged(0);
216*cdf0e10cSrcweir 	}
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir void SmDocShell::SetFormat(SmFormat& rFormat)
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetFormat" );
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	aFormat = rFormat;
224*cdf0e10cSrcweir 	SetFormulaArranged( sal_False );
225*cdf0e10cSrcweir 	SetModified( sal_True );
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir     nModifyCount++;     //! see comment for SID_GAPHIC_SM in SmDocShell::GetState
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     // don't use SmGetActiveView since the view shell might not be active (0 pointer)
230*cdf0e10cSrcweir     // if for example the Basic Macro dialog currently has the focus. Thus:
231*cdf0e10cSrcweir 	SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
232*cdf0e10cSrcweir 	while (pFrm)
233*cdf0e10cSrcweir 	{
234*cdf0e10cSrcweir 		pFrm->GetBindings().Invalidate(SID_GAPHIC_SM);
235*cdf0e10cSrcweir 		pFrm = SfxViewFrame::GetNext( *pFrm, this );
236*cdf0e10cSrcweir 	}
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir String SmDocShell::GetAccessibleText()
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetAccessibleText" );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     if (!IsFormulaArranged())
244*cdf0e10cSrcweir         ArrangeFormula();
245*cdf0e10cSrcweir     if (0 == aAccText.Len())
246*cdf0e10cSrcweir     {
247*cdf0e10cSrcweir         DBG_ASSERT( pTree, "Tree missing" );
248*cdf0e10cSrcweir         if (pTree)
249*cdf0e10cSrcweir             pTree->GetAccessibleText( aAccText );
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir     return aAccText;
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir void SmDocShell::Parse()
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Parse" );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	if (pTree)
259*cdf0e10cSrcweir 		delete pTree;
260*cdf0e10cSrcweir     ReplaceBadChars();
261*cdf0e10cSrcweir 	pTree = aInterpreter.Parse(aText);
262*cdf0e10cSrcweir 	nModifyCount++;     //! see comment for SID_GAPHIC_SM in SmDocShell::GetState
263*cdf0e10cSrcweir     SetFormulaArranged( sal_False );
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     aUsedSymbols = aInterpreter.GetUsedSymbols();
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir void SmDocShell::ArrangeFormula()
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ArrangeFormula" );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	if (IsFormulaArranged())
274*cdf0e10cSrcweir 		return;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 	//! Nur f�r die Dauer der Existenz dieses Objekts sind am Drucker die
277*cdf0e10cSrcweir 	//! richtigen Einstellungen garantiert.
278*cdf0e10cSrcweir     SmPrinterAccess  aPrtAcc(*this);
279*cdf0e10cSrcweir //	OutputDevice	*pOutDev = aPrtAcc.GetPrinter();
280*cdf0e10cSrcweir     OutputDevice* pOutDev = aPrtAcc.GetRefDev();
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	if (!pOutDev)
283*cdf0e10cSrcweir     {
284*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
285*cdf0e10cSrcweir 		DBG_ERROR("!! SmDocShell::ArrangeFormula: reference device missing !!");
286*cdf0e10cSrcweir #endif
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     // falls n�tig ein anderes OutputDevice holen f�r das formatiert wird
290*cdf0e10cSrcweir 	if (!pOutDev)
291*cdf0e10cSrcweir 	{
292*cdf0e10cSrcweir 		SmViewShell *pView = SmGetActiveView();
293*cdf0e10cSrcweir 		if (pView)
294*cdf0e10cSrcweir 			pOutDev = &pView->GetGraphicWindow();
295*cdf0e10cSrcweir 		else
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             pOutDev = &SM_MOD()->GetDefaultVirtualDev();
298*cdf0e10cSrcweir 			pOutDev->SetMapMode( MapMode(MAP_100TH_MM) );
299*cdf0e10cSrcweir 		}
300*cdf0e10cSrcweir 	}
301*cdf0e10cSrcweir 	DBG_ASSERT(pOutDev->GetMapMode().GetMapUnit() == MAP_100TH_MM,
302*cdf0e10cSrcweir 			   "Sm : falscher MapMode");
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 	const SmFormat &rFormat = GetFormat();
305*cdf0e10cSrcweir 	pTree->Prepare(rFormat, *this);
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir     // format/draw formulas always from left to right,
308*cdf0e10cSrcweir     // and numbers should not be converted
309*cdf0e10cSrcweir     sal_uLong nLayoutMode = pOutDev->GetLayoutMode();
310*cdf0e10cSrcweir     pOutDev->SetLayoutMode( TEXT_LAYOUT_BIDI_LTR );
311*cdf0e10cSrcweir     sal_Int16 nDigitLang = pOutDev->GetDigitLanguage();
312*cdf0e10cSrcweir     pOutDev->SetDigitLanguage( LANGUAGE_ENGLISH );
313*cdf0e10cSrcweir     //
314*cdf0e10cSrcweir     pTree->Arrange(*pOutDev, rFormat);
315*cdf0e10cSrcweir     //
316*cdf0e10cSrcweir     pOutDev->SetLayoutMode( nLayoutMode );
317*cdf0e10cSrcweir     pOutDev->SetDigitLanguage( nDigitLang );
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	SetFormulaArranged(sal_True);
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     // invalidate accessible text
322*cdf0e10cSrcweir     aAccText = String();
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir void SetEditEngineDefaultFonts(
327*cdf0e10cSrcweir         EditEngine &/*rEditEngine*/,
328*cdf0e10cSrcweir         SfxItemPool &rEditEngineItemPool )
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir         //
331*cdf0e10cSrcweir         // set fonts to be used
332*cdf0e10cSrcweir         //
333*cdf0e10cSrcweir         SvtLinguOptions aOpt;
334*cdf0e10cSrcweir         SvtLinguConfig().GetOptions( aOpt );
335*cdf0e10cSrcweir         //
336*cdf0e10cSrcweir         struct FontDta {
337*cdf0e10cSrcweir             sal_Int16       nFallbackLang;
338*cdf0e10cSrcweir             sal_Int16       nLang;
339*cdf0e10cSrcweir             sal_uInt16      nFontType;
340*cdf0e10cSrcweir             sal_uInt16      nFontInfoId;
341*cdf0e10cSrcweir             } aTable[3] =
342*cdf0e10cSrcweir         {
343*cdf0e10cSrcweir             // info to get western font to be used
344*cdf0e10cSrcweir             {   LANGUAGE_ENGLISH_US,    LANGUAGE_NONE,
345*cdf0e10cSrcweir                 DEFAULTFONT_FIXED,      EE_CHAR_FONTINFO },
346*cdf0e10cSrcweir             // info to get CJK font to be used
347*cdf0e10cSrcweir             {   LANGUAGE_JAPANESE,      LANGUAGE_NONE,
348*cdf0e10cSrcweir                 DEFAULTFONT_CJK_TEXT,   EE_CHAR_FONTINFO_CJK },
349*cdf0e10cSrcweir             // info to get CTL font to be used
350*cdf0e10cSrcweir             {   LANGUAGE_ARABIC_SAUDI_ARABIA,  LANGUAGE_NONE,
351*cdf0e10cSrcweir                 DEFAULTFONT_CTL_TEXT,   EE_CHAR_FONTINFO_CTL }
352*cdf0e10cSrcweir         };
353*cdf0e10cSrcweir         aTable[0].nLang = aOpt.nDefaultLanguage;
354*cdf0e10cSrcweir         aTable[1].nLang = aOpt.nDefaultLanguage_CJK;
355*cdf0e10cSrcweir         aTable[2].nLang = aOpt.nDefaultLanguage_CTL;
356*cdf0e10cSrcweir         //
357*cdf0e10cSrcweir         for (int i = 0;  i < 3;  ++i)
358*cdf0e10cSrcweir         {
359*cdf0e10cSrcweir             const FontDta &rFntDta = aTable[i];
360*cdf0e10cSrcweir             LanguageType nLang = (LANGUAGE_NONE == rFntDta.nLang) ?
361*cdf0e10cSrcweir                     rFntDta.nFallbackLang : rFntDta.nLang;
362*cdf0e10cSrcweir             Font aFont = Application::GetDefaultDevice()->GetDefaultFont(
363*cdf0e10cSrcweir                         rFntDta.nFontType, nLang, DEFAULTFONT_FLAGS_ONLYONE );
364*cdf0e10cSrcweir #ifdef DEBUG_TL
365*cdf0e10cSrcweir             ByteString aFntName( aFont.GetName(), 1 );
366*cdf0e10cSrcweir             int eFntFamily = aFont.GetFamily();
367*cdf0e10cSrcweir             ByteString aFntStyleName( aFont.GetStyleName(), 1 );
368*cdf0e10cSrcweir             int ePitch = aFont.GetPitch();
369*cdf0e10cSrcweir             int eCharSet = aFont.GetCharSet();
370*cdf0e10cSrcweir             fprintf(stderr, "\nFontName %s \n", aFntName.GetBuffer() );
371*cdf0e10cSrcweir             fprintf(stderr, "StyleName %s \n", aFntStyleName.GetBuffer() );
372*cdf0e10cSrcweir             fprintf(stderr, "eFntFamily %d \n", eFntFamily );
373*cdf0e10cSrcweir             fprintf(stderr, "ePitch %d \n", ePitch );
374*cdf0e10cSrcweir             fprintf(stderr, "eCharSet %d \n", eCharSet );
375*cdf0e10cSrcweir #endif
376*cdf0e10cSrcweir             rEditEngineItemPool.SetPoolDefaultItem(
377*cdf0e10cSrcweir                     SvxFontItem( aFont.GetFamily(), aFont.GetName(),
378*cdf0e10cSrcweir                         aFont.GetStyleName(), aFont.GetPitch(), aFont.GetCharSet(),
379*cdf0e10cSrcweir                         rFntDta.nFontInfoId ) );
380*cdf0e10cSrcweir         }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir         // set font heights
383*cdf0e10cSrcweir         SvxFontHeightItem aFontHeigt(
384*cdf0e10cSrcweir                         Application::GetDefaultDevice()->LogicToPixel(
385*cdf0e10cSrcweir                         Size( 0, 11 ), MapMode( MAP_POINT ) ).Height(), 100,
386*cdf0e10cSrcweir                         EE_CHAR_FONTHEIGHT );
387*cdf0e10cSrcweir         rEditEngineItemPool.SetPoolDefaultItem( aFontHeigt );
388*cdf0e10cSrcweir         aFontHeigt.SetWhich( EE_CHAR_FONTHEIGHT_CJK );
389*cdf0e10cSrcweir         rEditEngineItemPool.SetPoolDefaultItem( aFontHeigt );
390*cdf0e10cSrcweir         aFontHeigt.SetWhich( EE_CHAR_FONTHEIGHT_CTL );
391*cdf0e10cSrcweir         rEditEngineItemPool.SetPoolDefaultItem( aFontHeigt );
392*cdf0e10cSrcweir }
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir EditEngine& SmDocShell::GetEditEngine()
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetEditEngine" );
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	if (!pEditEngine)
400*cdf0e10cSrcweir 	{
401*cdf0e10cSrcweir         //!
402*cdf0e10cSrcweir         //! see also SmEditWindow::DataChanged !
403*cdf0e10cSrcweir         //!
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 		pEditEngineItemPool = EditEngine::CreatePool();
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir         SetEditEngineDefaultFonts( *pEditEngine, *pEditEngineItemPool );
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 		pEditEngine = new EditEngine( pEditEngineItemPool );
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 		pEditEngine->EnableUndo( sal_True );
412*cdf0e10cSrcweir 		pEditEngine->SetDefTab( sal_uInt16(
413*cdf0e10cSrcweir 			Application::GetDefaultDevice()->GetTextWidth( C2S("XXXX") ) ) );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 		pEditEngine->SetControlWord(
416*cdf0e10cSrcweir 				(pEditEngine->GetControlWord() | EE_CNTRL_AUTOINDENTING) &
417*cdf0e10cSrcweir 				(~EE_CNTRL_UNDOATTRIBS) &
418*cdf0e10cSrcweir 				(~EE_CNTRL_PASTESPECIAL) );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 		pEditEngine->SetWordDelimiters( C2S(" .=+-*/(){}[];\"" ) );
421*cdf0e10cSrcweir 		pEditEngine->SetRefMapMode( MAP_PIXEL );
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 		pEditEngine->SetPaperSize( Size( 800, 0 ) );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 		pEditEngine->EraseVirtualDevice();
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir         // set initial text if the document already has some...
428*cdf0e10cSrcweir         // (may be the case when reloading a doc)
429*cdf0e10cSrcweir         String aTxt( GetText() );
430*cdf0e10cSrcweir         if (aTxt.Len())
431*cdf0e10cSrcweir             pEditEngine->SetText( aTxt );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 		pEditEngine->ClearModifyFlag();
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 		// forces new settings to be used if the itempool was modified
436*cdf0e10cSrcweir 		// after cthe creation of the EditEngine
437*cdf0e10cSrcweir 		//pEditEngine->Clear();	//#77957 incorrect font size
438*cdf0e10cSrcweir 	}
439*cdf0e10cSrcweir 	return *pEditEngine;
440*cdf0e10cSrcweir }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir SfxItemPool& SmDocShell::GetEditEngineItemPool()
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetEditEngineItemPool" );
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 	if (!pEditEngineItemPool)
448*cdf0e10cSrcweir 		GetEditEngine();
449*cdf0e10cSrcweir 	DBG_ASSERT( pEditEngineItemPool, "EditEngineItemPool missing" );
450*cdf0e10cSrcweir 	return *pEditEngineItemPool;
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir void SmDocShell::Draw(OutputDevice &rDev, Point &rPosition)
455*cdf0e10cSrcweir {
456*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Draw" );
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     if (!pTree)
459*cdf0e10cSrcweir 		Parse();
460*cdf0e10cSrcweir 	DBG_ASSERT(pTree, "Sm : NULL pointer");
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 	if (!IsFormulaArranged())
463*cdf0e10cSrcweir 		ArrangeFormula();
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 	//Problem: Was passiert mit dem WYSIWYG? Wir haben waehrend wir inplace aktiv
466*cdf0e10cSrcweir 	//sind kein Referenzdevice und sind auch nicht darauf ausgerichtet. Es kann
467*cdf0e10cSrcweir 	//also jetzt eine Differenz zwischen der VisArea (spricht die Groesse im Client)
468*cdf0e10cSrcweir 	//und der jetzt vorliegenden Groese geben.
469*cdf0e10cSrcweir 	//Idee: Die Differenz koennte, zumindest behelfsmaessig, mit SmNod::SetSize
470*cdf0e10cSrcweir 	//angepasst werden.
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 	rPosition.X() += aFormat.GetDistance( DIS_LEFTSPACE );
473*cdf0e10cSrcweir 	rPosition.Y() += aFormat.GetDistance( DIS_TOPSPACE	);
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir     //! in case of high contrast-mode (accessibility option!)
476*cdf0e10cSrcweir     //! the draw mode needs to be set to default, because when imbedding
477*cdf0e10cSrcweir     //! Math for example in Calc in "a over b" the fraction bar may not
478*cdf0e10cSrcweir     //! be visible else. More generally: the FillColor may have been changed.
479*cdf0e10cSrcweir     sal_uLong nOldDrawMode = DRAWMODE_DEFAULT;
480*cdf0e10cSrcweir     sal_Bool bRestoreDrawMode = sal_False;
481*cdf0e10cSrcweir     if (OUTDEV_WINDOW == rDev.GetOutDevType() &&
482*cdf0e10cSrcweir         ((Window &) rDev).GetSettings().GetStyleSettings().GetHighContrastMode())
483*cdf0e10cSrcweir     {
484*cdf0e10cSrcweir         nOldDrawMode = rDev.GetDrawMode();
485*cdf0e10cSrcweir         rDev.SetDrawMode( DRAWMODE_DEFAULT );
486*cdf0e10cSrcweir         bRestoreDrawMode = sal_True;
487*cdf0e10cSrcweir     }
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir     // format/draw formulas always from left to right
490*cdf0e10cSrcweir     // and numbers should not be converted
491*cdf0e10cSrcweir     sal_uLong nLayoutMode = rDev.GetLayoutMode();
492*cdf0e10cSrcweir     rDev.SetLayoutMode( TEXT_LAYOUT_BIDI_LTR );
493*cdf0e10cSrcweir     sal_Int16 nDigitLang = rDev.GetDigitLanguage();
494*cdf0e10cSrcweir     rDev.SetDigitLanguage( LANGUAGE_ENGLISH );
495*cdf0e10cSrcweir     //
496*cdf0e10cSrcweir     pTree->Draw(rDev, rPosition);
497*cdf0e10cSrcweir     //
498*cdf0e10cSrcweir     rDev.SetLayoutMode( nLayoutMode );
499*cdf0e10cSrcweir     rDev.SetDigitLanguage( nDigitLang );
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir     if (bRestoreDrawMode)
502*cdf0e10cSrcweir         rDev.SetDrawMode( nOldDrawMode );
503*cdf0e10cSrcweir }
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir Size SmDocShell::GetSize()
508*cdf0e10cSrcweir {
509*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetSize" );
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 	Size aRet;
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 	if (!pTree)
514*cdf0e10cSrcweir 		Parse();
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir 	if (pTree)
517*cdf0e10cSrcweir 	{
518*cdf0e10cSrcweir 		if (!IsFormulaArranged())
519*cdf0e10cSrcweir 			ArrangeFormula();
520*cdf0e10cSrcweir 		aRet = pTree->GetSize();
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 		if ( !aRet.Width() )
523*cdf0e10cSrcweir 			aRet.Width() = 2000;
524*cdf0e10cSrcweir 		else
525*cdf0e10cSrcweir 			aRet.Width()  += aFormat.GetDistance( DIS_LEFTSPACE ) +
526*cdf0e10cSrcweir 							 aFormat.GetDistance( DIS_RIGHTSPACE );
527*cdf0e10cSrcweir 		if ( !aRet.Height() )
528*cdf0e10cSrcweir 			aRet.Height() = 1000;
529*cdf0e10cSrcweir 		else
530*cdf0e10cSrcweir 			aRet.Height() += aFormat.GetDistance( DIS_TOPSPACE ) +
531*cdf0e10cSrcweir 							 aFormat.GetDistance( DIS_BOTTOMSPACE );
532*cdf0e10cSrcweir 	}
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 	return aRet;
535*cdf0e10cSrcweir }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir ////////////////////////////////////////
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir SmPrinterAccess::SmPrinterAccess( SmDocShell &rDocShell )
540*cdf0e10cSrcweir {
541*cdf0e10cSrcweir 	if ( 0 != (pPrinter = rDocShell.GetPrt()) )
542*cdf0e10cSrcweir 	{
543*cdf0e10cSrcweir 		pPrinter->Push( PUSH_MAPMODE );
544*cdf0e10cSrcweir         if ( SFX_CREATE_MODE_EMBEDDED == rDocShell.GetCreateMode() )
545*cdf0e10cSrcweir 		{
546*cdf0e10cSrcweir 			// if it is an embedded object (without it's own printer)
547*cdf0e10cSrcweir 			// we change the MapMode temporarily.
548*cdf0e10cSrcweir 			//!If it is a document with it's own printer the MapMode should
549*cdf0e10cSrcweir 			//!be set correct (once) elsewhere(!), in order to avoid numerous
550*cdf0e10cSrcweir 			//!superfluous pushing and poping of the MapMode when using
551*cdf0e10cSrcweir 			//!this class.
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 			const MapUnit eOld = pPrinter->GetMapMode().GetMapUnit();
554*cdf0e10cSrcweir 			if ( MAP_100TH_MM != eOld )
555*cdf0e10cSrcweir 			{
556*cdf0e10cSrcweir 				MapMode aMap( pPrinter->GetMapMode() );
557*cdf0e10cSrcweir 				aMap.SetMapUnit( MAP_100TH_MM );
558*cdf0e10cSrcweir 				Point aTmp( aMap.GetOrigin() );
559*cdf0e10cSrcweir 				aTmp.X() = OutputDevice::LogicToLogic( aTmp.X(), eOld, MAP_100TH_MM );
560*cdf0e10cSrcweir 				aTmp.Y() = OutputDevice::LogicToLogic( aTmp.Y(), eOld, MAP_100TH_MM );
561*cdf0e10cSrcweir 				aMap.SetOrigin( aTmp );
562*cdf0e10cSrcweir 				pPrinter->SetMapMode( aMap );
563*cdf0e10cSrcweir 			}
564*cdf0e10cSrcweir 		}
565*cdf0e10cSrcweir 	}
566*cdf0e10cSrcweir     if ( 0 != (pRefDev = rDocShell.GetRefDev()) && pPrinter != pRefDev )
567*cdf0e10cSrcweir     {
568*cdf0e10cSrcweir         pRefDev->Push( PUSH_MAPMODE );
569*cdf0e10cSrcweir         if ( SFX_CREATE_MODE_EMBEDDED == rDocShell.GetCreateMode() )
570*cdf0e10cSrcweir         {
571*cdf0e10cSrcweir             // if it is an embedded object (without it's own printer)
572*cdf0e10cSrcweir             // we change the MapMode temporarily.
573*cdf0e10cSrcweir             //!If it is a document with it's own printer the MapMode should
574*cdf0e10cSrcweir             //!be set correct (once) elsewhere(!), in order to avoid numerous
575*cdf0e10cSrcweir             //!superfluous pushing and poping of the MapMode when using
576*cdf0e10cSrcweir             //!this class.
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir             const MapUnit eOld = pRefDev->GetMapMode().GetMapUnit();
579*cdf0e10cSrcweir             if ( MAP_100TH_MM != eOld )
580*cdf0e10cSrcweir             {
581*cdf0e10cSrcweir                 MapMode aMap( pRefDev->GetMapMode() );
582*cdf0e10cSrcweir                 aMap.SetMapUnit( MAP_100TH_MM );
583*cdf0e10cSrcweir                 Point aTmp( aMap.GetOrigin() );
584*cdf0e10cSrcweir                 aTmp.X() = OutputDevice::LogicToLogic( aTmp.X(), eOld, MAP_100TH_MM );
585*cdf0e10cSrcweir                 aTmp.Y() = OutputDevice::LogicToLogic( aTmp.Y(), eOld, MAP_100TH_MM );
586*cdf0e10cSrcweir                 aMap.SetOrigin( aTmp );
587*cdf0e10cSrcweir                 pRefDev->SetMapMode( aMap );
588*cdf0e10cSrcweir             }
589*cdf0e10cSrcweir         }
590*cdf0e10cSrcweir     }
591*cdf0e10cSrcweir }
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir SmPrinterAccess::~SmPrinterAccess()
594*cdf0e10cSrcweir {
595*cdf0e10cSrcweir 	if ( pPrinter )
596*cdf0e10cSrcweir 		pPrinter->Pop();
597*cdf0e10cSrcweir     if ( pRefDev && pRefDev != pPrinter )
598*cdf0e10cSrcweir         pRefDev->Pop();
599*cdf0e10cSrcweir }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir ////////////////////////////////////////
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir Printer* SmDocShell::GetPrt()
604*cdf0e10cSrcweir {
605*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetPrt" );
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir     if ( SFX_CREATE_MODE_EMBEDDED == GetCreateMode() )
608*cdf0e10cSrcweir 	{
609*cdf0e10cSrcweir 		//Normalerweise wird der Printer vom Server besorgt. Wenn dieser aber
610*cdf0e10cSrcweir 		//keinen liefert (weil etwa noch keine connection da ist), kann es
611*cdf0e10cSrcweir 		//dennoch sein, dass wir den Printer kennen, denn dieser wird in
612*cdf0e10cSrcweir 		//OnDocumentPrinterChanged vom Server durchgereicht und dann temporaer
613*cdf0e10cSrcweir 		//festgehalten.
614*cdf0e10cSrcweir         Printer *pPrt = GetDocumentPrinter();
615*cdf0e10cSrcweir         if ( !pPrt && pTmpPrinter )
616*cdf0e10cSrcweir             pPrt = pTmpPrinter;
617*cdf0e10cSrcweir         return pPrt;
618*cdf0e10cSrcweir 	}
619*cdf0e10cSrcweir 	else if ( !pPrinter )
620*cdf0e10cSrcweir 	{
621*cdf0e10cSrcweir 		SfxItemSet *pOptions =
622*cdf0e10cSrcweir 			new SfxItemSet(GetPool(),
623*cdf0e10cSrcweir 						   SID_PRINTSIZE,		SID_PRINTSIZE,
624*cdf0e10cSrcweir 						   SID_PRINTZOOM,		SID_PRINTZOOM,
625*cdf0e10cSrcweir 						   SID_PRINTTITLE,		SID_PRINTTITLE,
626*cdf0e10cSrcweir 						   SID_PRINTTEXT,		SID_PRINTTEXT,
627*cdf0e10cSrcweir 						   SID_PRINTFRAME,		SID_PRINTFRAME,
628*cdf0e10cSrcweir 						   SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
629*cdf0e10cSrcweir 						   0);
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir         SmModule *pp = SM_MOD();
632*cdf0e10cSrcweir 		pp->GetConfig()->ConfigToItemSet(*pOptions);
633*cdf0e10cSrcweir 		pPrinter = new SfxPrinter(pOptions);
634*cdf0e10cSrcweir 		pPrinter->SetMapMode( MapMode(MAP_100TH_MM) );
635*cdf0e10cSrcweir 	}
636*cdf0e10cSrcweir 	return pPrinter;
637*cdf0e10cSrcweir }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir OutputDevice* SmDocShell::GetRefDev()
640*cdf0e10cSrcweir {
641*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetRefDev" );
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir     if ( SFX_CREATE_MODE_EMBEDDED == GetCreateMode() )
644*cdf0e10cSrcweir     {
645*cdf0e10cSrcweir         OutputDevice* pOutDev = GetDocumentRefDev();
646*cdf0e10cSrcweir         if ( pOutDev )
647*cdf0e10cSrcweir             return pOutDev;
648*cdf0e10cSrcweir     }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir     return GetPrt();
651*cdf0e10cSrcweir }
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir void SmDocShell::SetPrinter( SfxPrinter *pNew )
655*cdf0e10cSrcweir {
656*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetPrinter" );
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir 	delete pPrinter;
659*cdf0e10cSrcweir 	pPrinter = pNew;	//Eigentumsuebergang!
660*cdf0e10cSrcweir 	pPrinter->SetMapMode( MapMode(MAP_100TH_MM) );
661*cdf0e10cSrcweir 	SetFormulaArranged(sal_False);
662*cdf0e10cSrcweir     Repaint();
663*cdf0e10cSrcweir }
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir void SmDocShell::OnDocumentPrinterChanged( Printer *pPrt )
666*cdf0e10cSrcweir {
667*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::OnDocumentPrinterChanged" );
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir     pTmpPrinter = pPrt;
670*cdf0e10cSrcweir 	SetFormulaArranged(sal_False);
671*cdf0e10cSrcweir 	Size aOldSize = GetVisArea().GetSize();
672*cdf0e10cSrcweir     Repaint();
673*cdf0e10cSrcweir 	if( aOldSize != GetVisArea().GetSize() && aText.Len() )
674*cdf0e10cSrcweir 		SetModified( sal_True );
675*cdf0e10cSrcweir 	pTmpPrinter = 0;
676*cdf0e10cSrcweir }
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir void SmDocShell::Repaint()
679*cdf0e10cSrcweir {
680*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Repaint" );
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir 	sal_Bool bIsEnabled = IsEnableSetModified();
683*cdf0e10cSrcweir 	if ( bIsEnabled )
684*cdf0e10cSrcweir 		EnableSetModified( sal_False );
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir     SetFormulaArranged( sal_False );
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 	Size aVisSize = GetSize();
689*cdf0e10cSrcweir 	SetVisAreaSize( aVisSize );
690*cdf0e10cSrcweir 	SmViewShell *pViewSh = SmGetActiveView();
691*cdf0e10cSrcweir 	if (pViewSh)
692*cdf0e10cSrcweir         pViewSh->GetGraphicWindow().Invalidate();
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir 	if ( bIsEnabled )
695*cdf0e10cSrcweir 		EnableSetModified( bIsEnabled );
696*cdf0e10cSrcweir }
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir SmDocShell::SmDocShell( const sal_uInt64 i_nSfxCreationFlags ) :
700*cdf0e10cSrcweir 	SfxObjectShell( i_nSfxCreationFlags ),
701*cdf0e10cSrcweir 	pTree				( 0 ),
702*cdf0e10cSrcweir     pEditEngineItemPool ( 0 ),
703*cdf0e10cSrcweir     pEditEngine         ( 0 ),
704*cdf0e10cSrcweir 	pPrinter			( 0 ),
705*cdf0e10cSrcweir     pTmpPrinter         ( 0 ),
706*cdf0e10cSrcweir 	nModifyCount		( 0 ),
707*cdf0e10cSrcweir 	bIsFormulaArranged	( sal_False )
708*cdf0e10cSrcweir {
709*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SmDocShell" );
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir 	SetPool(&SFX_APP()->GetPool());
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir     SmModule *pp = SM_MOD();
714*cdf0e10cSrcweir     aFormat = pp->GetConfig()->GetStandardFormat();
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir 	StartListening(aFormat);
717*cdf0e10cSrcweir 	StartListening(*pp->GetConfig());
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir 	SetBaseModel( new SmModel(this) );
720*cdf0e10cSrcweir }
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir SmDocShell::~SmDocShell()
725*cdf0e10cSrcweir {
726*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::~SmDocShell" );
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir     SmModule *pp = SM_MOD();
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir 	EndListening(aFormat);
731*cdf0e10cSrcweir 	EndListening(*pp->GetConfig());
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir 	delete pEditEngine;
734*cdf0e10cSrcweir 	SfxItemPool::Free(pEditEngineItemPool);
735*cdf0e10cSrcweir 	delete pTree;
736*cdf0e10cSrcweir 	delete pPrinter;
737*cdf0e10cSrcweir }
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir sal_Bool SmDocShell::SetData( const String& rData )
741*cdf0e10cSrcweir {
742*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetData" );
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir 	SetText( rData );
745*cdf0e10cSrcweir 	return sal_True;
746*cdf0e10cSrcweir }
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir sal_Bool SmDocShell::ConvertFrom(SfxMedium &rMedium)
750*cdf0e10cSrcweir {
751*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ConvertFrom" );
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir 	sal_Bool	 bSuccess = sal_False;
754*cdf0e10cSrcweir 	const String& rFltName = rMedium.GetFilter()->GetFilterName();
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir     DBG_ASSERT( !rFltName.EqualsAscii( STAROFFICE_XML ), "Wrong filter!");
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir     if ( rFltName.EqualsAscii( MATHML_XML ) )
759*cdf0e10cSrcweir 	{
760*cdf0e10cSrcweir 		if (pTree)
761*cdf0e10cSrcweir 		{
762*cdf0e10cSrcweir 			delete pTree;
763*cdf0e10cSrcweir 			pTree = 0;
764*cdf0e10cSrcweir 		}
765*cdf0e10cSrcweir         Reference<com::sun::star::frame::XModel> xModel(GetModel());
766*cdf0e10cSrcweir         SmXMLImportWrapper aEquation(xModel);
767*cdf0e10cSrcweir         bSuccess = 0 == aEquation.Import(rMedium);
768*cdf0e10cSrcweir 	}
769*cdf0e10cSrcweir 	else
770*cdf0e10cSrcweir 	{
771*cdf0e10cSrcweir 		SvStream *pStream = rMedium.GetInStream();
772*cdf0e10cSrcweir         if ( pStream )
773*cdf0e10cSrcweir 		{
774*cdf0e10cSrcweir             if ( SotStorage::IsStorageFile( pStream ) )
775*cdf0e10cSrcweir             {
776*cdf0e10cSrcweir                 SvStorageRef aStorage = new SotStorage( pStream, sal_False );
777*cdf0e10cSrcweir                 if ( aStorage->IsStream( C2S( "Equation Native" ) ) )
778*cdf0e10cSrcweir                 {
779*cdf0e10cSrcweir                     // is this a MathType Storage?
780*cdf0e10cSrcweir                     MathType aEquation( aText );
781*cdf0e10cSrcweir                     if ( sal_True == (bSuccess = (1 == aEquation.Parse( aStorage )) ))
782*cdf0e10cSrcweir                         Parse();
783*cdf0e10cSrcweir                 }
784*cdf0e10cSrcweir             }
785*cdf0e10cSrcweir             else
786*cdf0e10cSrcweir             {
787*cdf0e10cSrcweir                 //bSuccess = ImportSM20File( pStream );
788*cdf0e10cSrcweir             }
789*cdf0e10cSrcweir 		}
790*cdf0e10cSrcweir 	}
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir     if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
793*cdf0e10cSrcweir     {
794*cdf0e10cSrcweir         //???OnDocumentPrinterChanged(0);
795*cdf0e10cSrcweir         SetFormulaArranged( sal_False );
796*cdf0e10cSrcweir         Repaint();
797*cdf0e10cSrcweir     }
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir 	FinishedLoading( SFX_LOADED_ALL );
800*cdf0e10cSrcweir 	return bSuccess;
801*cdf0e10cSrcweir }
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir sal_Bool SmDocShell::InitNew( const uno::Reference < embed::XStorage >& xStorage )
805*cdf0e10cSrcweir {
806*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::InitNew" );
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
809*cdf0e10cSrcweir     if ( SfxObjectShell::InitNew( xStorage ) )
810*cdf0e10cSrcweir 	{
811*cdf0e10cSrcweir 		bRet = sal_True;
812*cdf0e10cSrcweir 		SetVisArea(Rectangle(Point(0, 0), Size(2000, 1000)));
813*cdf0e10cSrcweir 	}
814*cdf0e10cSrcweir 	return bRet;
815*cdf0e10cSrcweir }
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir sal_Bool SmDocShell::Load( SfxMedium& rMedium )
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Load" );
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
823*cdf0e10cSrcweir     if( SfxObjectShell::Load( rMedium ))
824*cdf0e10cSrcweir 	{
825*cdf0e10cSrcweir         uno::Reference < embed::XStorage > xStorage = GetMedium()->GetStorage();
826*cdf0e10cSrcweir         uno::Reference < container::XNameAccess > xAccess (xStorage, uno::UNO_QUERY);
827*cdf0e10cSrcweir         if (
828*cdf0e10cSrcweir             (
829*cdf0e10cSrcweir              xAccess->hasByName( C2S( "content.xml" ) ) &&
830*cdf0e10cSrcweir              xStorage->isStreamElement( C2S( "content.xml" ) )
831*cdf0e10cSrcweir             ) ||
832*cdf0e10cSrcweir             (
833*cdf0e10cSrcweir              xAccess->hasByName( C2S( "Content.xml" ) ) &&
834*cdf0e10cSrcweir              xStorage->isStreamElement( C2S( "Content.xml" ) )
835*cdf0e10cSrcweir             )
836*cdf0e10cSrcweir            )
837*cdf0e10cSrcweir         {
838*cdf0e10cSrcweir             // is this a fabulous math package ?
839*cdf0e10cSrcweir             Reference<com::sun::star::frame::XModel> xModel(GetModel());
840*cdf0e10cSrcweir             SmXMLImportWrapper aEquation(xModel);
841*cdf0e10cSrcweir             sal_uLong nError = aEquation.Import(rMedium);
842*cdf0e10cSrcweir             bRet = 0 == nError;
843*cdf0e10cSrcweir             SetError( nError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
844*cdf0e10cSrcweir         }
845*cdf0e10cSrcweir 	}
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir     if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
848*cdf0e10cSrcweir     {
849*cdf0e10cSrcweir         //???OnDocumentPrinterChanged(0);
850*cdf0e10cSrcweir 		SetFormulaArranged( sal_False );
851*cdf0e10cSrcweir         Repaint();
852*cdf0e10cSrcweir     }
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir 	FinishedLoading( SFX_LOADED_ALL );
855*cdf0e10cSrcweir 	return bRet;
856*cdf0e10cSrcweir }
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir //------------------------------------------------------------------
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir sal_Bool SmDocShell::Save()
861*cdf0e10cSrcweir {
862*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Save" );
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir     //! apply latest changes if necessary
865*cdf0e10cSrcweir     UpdateText();
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir     if ( SfxObjectShell::Save() )
868*cdf0e10cSrcweir 	{
869*cdf0e10cSrcweir 		if (!pTree)
870*cdf0e10cSrcweir 			Parse();
871*cdf0e10cSrcweir 		if( pTree && !IsFormulaArranged() )
872*cdf0e10cSrcweir 			ArrangeFormula();
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir         Reference<com::sun::star::frame::XModel> xModel(GetModel());
875*cdf0e10cSrcweir         SmXMLExportWrapper aEquation(xModel);
876*cdf0e10cSrcweir         aEquation.SetFlat(sal_False);
877*cdf0e10cSrcweir         return aEquation.Export(*GetMedium());
878*cdf0e10cSrcweir 	}
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 	return sal_False;
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir /*
884*cdf0e10cSrcweir  * replace bad characters that can not be saved. (#i74144)
885*cdf0e10cSrcweir  * */
886*cdf0e10cSrcweir sal_Bool SmDocShell::ReplaceBadChars()
887*cdf0e10cSrcweir {
888*cdf0e10cSrcweir 	sal_Bool bReplace = sal_False;
889*cdf0e10cSrcweir 	if (pEditEngine)
890*cdf0e10cSrcweir 	{
891*cdf0e10cSrcweir 		String aEngTxt( pEditEngine->GetText( LINEEND_LF ) );
892*cdf0e10cSrcweir 		const sal_Unicode *pEngTxt = aEngTxt.GetBuffer();
893*cdf0e10cSrcweir 		xub_StrLen nLen = aEngTxt.Len();
894*cdf0e10cSrcweir 		for (xub_StrLen i = 0;  i < nLen && !bReplace;  ++i)
895*cdf0e10cSrcweir 		{
896*cdf0e10cSrcweir 			const sal_Unicode c = *pEngTxt++;
897*cdf0e10cSrcweir 			if (c < ' ' && c != '\r' && c != '\n' && c != '\t')
898*cdf0e10cSrcweir 				bReplace = sal_True;
899*cdf0e10cSrcweir 		}
900*cdf0e10cSrcweir 		if (bReplace)
901*cdf0e10cSrcweir 		{
902*cdf0e10cSrcweir 			sal_Unicode *pChgTxt = aEngTxt.GetBufferAccess();
903*cdf0e10cSrcweir 			for (xub_StrLen i = 0;  i < nLen;  ++i)
904*cdf0e10cSrcweir 			{
905*cdf0e10cSrcweir 				sal_Unicode &rc = *pChgTxt++;
906*cdf0e10cSrcweir 				if (rc < ' ' && rc != '\r' && rc != '\n' && rc != '\t')
907*cdf0e10cSrcweir 					rc = ' ';
908*cdf0e10cSrcweir 			}
909*cdf0e10cSrcweir 			aEngTxt.ReleaseBufferAccess( nLen );
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir 			aText = aEngTxt;
912*cdf0e10cSrcweir 		}
913*cdf0e10cSrcweir 	}
914*cdf0e10cSrcweir 	return bReplace;
915*cdf0e10cSrcweir }
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir void SmDocShell::UpdateText()
919*cdf0e10cSrcweir {
920*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::UpdateText" );
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir     if (pEditEngine && pEditEngine->IsModified())
923*cdf0e10cSrcweir     {
924*cdf0e10cSrcweir         String aEngTxt( pEditEngine->GetText( LINEEND_LF ) );
925*cdf0e10cSrcweir         if (GetText() != aEngTxt)
926*cdf0e10cSrcweir             SetText( aEngTxt );
927*cdf0e10cSrcweir     }
928*cdf0e10cSrcweir }
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir sal_Bool SmDocShell::SaveAs( SfxMedium& rMedium )
932*cdf0e10cSrcweir {
933*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveAs" );
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir     //! apply latest changes if necessary
938*cdf0e10cSrcweir     UpdateText();
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir 	if ( SfxObjectShell::SaveAs( rMedium ) )
941*cdf0e10cSrcweir 	{
942*cdf0e10cSrcweir 		if (!pTree)
943*cdf0e10cSrcweir 			Parse();
944*cdf0e10cSrcweir 		if( pTree && !IsFormulaArranged() )
945*cdf0e10cSrcweir 			ArrangeFormula();
946*cdf0e10cSrcweir 
947*cdf0e10cSrcweir         Reference<com::sun::star::frame::XModel> xModel(GetModel());
948*cdf0e10cSrcweir         SmXMLExportWrapper aEquation(xModel);
949*cdf0e10cSrcweir         aEquation.SetFlat(sal_False);
950*cdf0e10cSrcweir         bRet = aEquation.Export(rMedium);
951*cdf0e10cSrcweir 	}
952*cdf0e10cSrcweir 	return bRet;
953*cdf0e10cSrcweir }
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir sal_Bool SmDocShell::ConvertTo( SfxMedium &rMedium )
956*cdf0e10cSrcweir {
957*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ConvertTo" );
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
960*cdf0e10cSrcweir 	const SfxFilter* pFlt = rMedium.GetFilter();
961*cdf0e10cSrcweir 	if( pFlt )
962*cdf0e10cSrcweir 	{
963*cdf0e10cSrcweir 		if( !pTree )
964*cdf0e10cSrcweir 			Parse();
965*cdf0e10cSrcweir 		if( pTree && !IsFormulaArranged() )
966*cdf0e10cSrcweir 			ArrangeFormula();
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir 		const String& rFltName = pFlt->GetFilterName();
969*cdf0e10cSrcweir 		if(rFltName.EqualsAscii( STAROFFICE_XML ))
970*cdf0e10cSrcweir 		{
971*cdf0e10cSrcweir             Reference<com::sun::star::frame::XModel> xModel(GetModel());
972*cdf0e10cSrcweir             SmXMLExportWrapper aEquation(xModel);
973*cdf0e10cSrcweir 			aEquation.SetFlat(sal_False);
974*cdf0e10cSrcweir 			bRet = aEquation.Export(rMedium);
975*cdf0e10cSrcweir 		}
976*cdf0e10cSrcweir 		else if(rFltName.EqualsAscii( MATHML_XML ))
977*cdf0e10cSrcweir 		{
978*cdf0e10cSrcweir             Reference<com::sun::star::frame::XModel> xModel(GetModel());
979*cdf0e10cSrcweir             SmXMLExportWrapper aEquation(xModel);
980*cdf0e10cSrcweir 			aEquation.SetFlat(sal_True);
981*cdf0e10cSrcweir 			bRet = aEquation.Export(rMedium);
982*cdf0e10cSrcweir 		}
983*cdf0e10cSrcweir         else if( pFlt->GetFilterName().EqualsAscii("MathType 3.x"))
984*cdf0e10cSrcweir             bRet = WriteAsMathType3( rMedium );
985*cdf0e10cSrcweir 	}
986*cdf0e10cSrcweir 	return bRet;
987*cdf0e10cSrcweir }
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir sal_Bool SmDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
990*cdf0e10cSrcweir {
991*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveCompleted" );
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir     if( SfxObjectShell::SaveCompleted( xStorage ))
994*cdf0e10cSrcweir 		return sal_True;
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir 	return sal_False;
997*cdf0e10cSrcweir }
998*cdf0e10cSrcweir 
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir void SmDocShell::Execute(SfxRequest& rReq)
1001*cdf0e10cSrcweir {
1002*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Execute" );
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir 	switch (rReq.GetSlot())
1005*cdf0e10cSrcweir 	{
1006*cdf0e10cSrcweir 		case SID_TEXTMODE:
1007*cdf0e10cSrcweir 		{
1008*cdf0e10cSrcweir             SmFormat aOldFormat  = GetFormat();
1009*cdf0e10cSrcweir             SmFormat aNewFormat( aOldFormat );
1010*cdf0e10cSrcweir             aNewFormat.SetTextmode(!aOldFormat.IsTextmode());
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir             ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager();
1013*cdf0e10cSrcweir             if (pTmpUndoMgr)
1014*cdf0e10cSrcweir                 pTmpUndoMgr->AddUndoAction(
1015*cdf0e10cSrcweir                     new SmFormatAction(this, aOldFormat, aNewFormat));
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir             SetFormat( aNewFormat );
1018*cdf0e10cSrcweir             Repaint();
1019*cdf0e10cSrcweir 		}
1020*cdf0e10cSrcweir 		break;
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir 		case SID_AUTO_REDRAW :
1023*cdf0e10cSrcweir 		{
1024*cdf0e10cSrcweir             SmModule *pp = SM_MOD();
1025*cdf0e10cSrcweir 			sal_Bool bRedraw = pp->GetConfig()->IsAutoRedraw();
1026*cdf0e10cSrcweir 			pp->GetConfig()->SetAutoRedraw(!bRedraw);
1027*cdf0e10cSrcweir 		}
1028*cdf0e10cSrcweir 		break;
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir 		case SID_LOADSYMBOLS:
1031*cdf0e10cSrcweir             LoadSymbols();
1032*cdf0e10cSrcweir 		break;
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir 		case SID_SAVESYMBOLS:
1035*cdf0e10cSrcweir             SaveSymbols();
1036*cdf0e10cSrcweir 		break;
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir 		case SID_FONT:
1039*cdf0e10cSrcweir 		{
1040*cdf0e10cSrcweir             // get device used to retrieve the FontList
1041*cdf0e10cSrcweir             OutputDevice *pDev = GetPrinter();
1042*cdf0e10cSrcweir             if (!pDev || pDev->GetDevFontCount() == 0)
1043*cdf0e10cSrcweir                 pDev = &SM_MOD()->GetDefaultVirtualDev();
1044*cdf0e10cSrcweir             DBG_ASSERT (pDev, "device for font list missing" );
1045*cdf0e10cSrcweir 
1046*cdf0e10cSrcweir             SmFontTypeDialog *pFontTypeDialog = new SmFontTypeDialog( NULL, pDev );
1047*cdf0e10cSrcweir 
1048*cdf0e10cSrcweir             SmFormat aOldFormat  = GetFormat();
1049*cdf0e10cSrcweir             pFontTypeDialog->ReadFrom( aOldFormat );
1050*cdf0e10cSrcweir 			if (pFontTypeDialog->Execute() == RET_OK)
1051*cdf0e10cSrcweir 			{
1052*cdf0e10cSrcweir                 SmFormat aNewFormat( aOldFormat );
1053*cdf0e10cSrcweir 
1054*cdf0e10cSrcweir 				pFontTypeDialog->WriteTo(aNewFormat);
1055*cdf0e10cSrcweir                 ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager();
1056*cdf0e10cSrcweir                 if (pTmpUndoMgr)
1057*cdf0e10cSrcweir                     pTmpUndoMgr->AddUndoAction(
1058*cdf0e10cSrcweir 						new SmFormatAction(this, aOldFormat, aNewFormat));
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir 				SetFormat( aNewFormat );
1061*cdf0e10cSrcweir                 Repaint();
1062*cdf0e10cSrcweir 			}
1063*cdf0e10cSrcweir 			delete pFontTypeDialog;
1064*cdf0e10cSrcweir 		}
1065*cdf0e10cSrcweir 		break;
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir 		case SID_FONTSIZE:
1068*cdf0e10cSrcweir 		{
1069*cdf0e10cSrcweir 			SmFontSizeDialog *pFontSizeDialog = new SmFontSizeDialog(NULL);
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir             SmFormat aOldFormat  = GetFormat();
1072*cdf0e10cSrcweir             pFontSizeDialog->ReadFrom( aOldFormat );
1073*cdf0e10cSrcweir 			if (pFontSizeDialog->Execute() == RET_OK)
1074*cdf0e10cSrcweir 			{
1075*cdf0e10cSrcweir                 SmFormat aNewFormat( aOldFormat );
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir 				pFontSizeDialog->WriteTo(aNewFormat);
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir                 ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager();
1080*cdf0e10cSrcweir                 if (pTmpUndoMgr)
1081*cdf0e10cSrcweir                     pTmpUndoMgr->AddUndoAction(
1082*cdf0e10cSrcweir 						new SmFormatAction(this, aOldFormat, aNewFormat));
1083*cdf0e10cSrcweir 
1084*cdf0e10cSrcweir 				SetFormat( aNewFormat );
1085*cdf0e10cSrcweir                 Repaint();
1086*cdf0e10cSrcweir 			}
1087*cdf0e10cSrcweir 			delete pFontSizeDialog;
1088*cdf0e10cSrcweir 		}
1089*cdf0e10cSrcweir 		break;
1090*cdf0e10cSrcweir 
1091*cdf0e10cSrcweir 		case SID_DISTANCE:
1092*cdf0e10cSrcweir 		{
1093*cdf0e10cSrcweir 			SmDistanceDialog *pDistanceDialog = new SmDistanceDialog(NULL);
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir             SmFormat aOldFormat  = GetFormat();
1096*cdf0e10cSrcweir             pDistanceDialog->ReadFrom( aOldFormat );
1097*cdf0e10cSrcweir 			if (pDistanceDialog->Execute() == RET_OK)
1098*cdf0e10cSrcweir 			{
1099*cdf0e10cSrcweir                 SmFormat aNewFormat( aOldFormat );
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir 				pDistanceDialog->WriteTo(aNewFormat);
1102*cdf0e10cSrcweir 
1103*cdf0e10cSrcweir                 ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager();
1104*cdf0e10cSrcweir                 if (pTmpUndoMgr)
1105*cdf0e10cSrcweir                     pTmpUndoMgr->AddUndoAction(
1106*cdf0e10cSrcweir 						new SmFormatAction(this, aOldFormat, aNewFormat));
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir 				SetFormat( aNewFormat );
1109*cdf0e10cSrcweir                 Repaint();
1110*cdf0e10cSrcweir 			}
1111*cdf0e10cSrcweir 			delete pDistanceDialog;
1112*cdf0e10cSrcweir 		}
1113*cdf0e10cSrcweir 		break;
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir 		case SID_ALIGN:
1116*cdf0e10cSrcweir 		{
1117*cdf0e10cSrcweir 			SmAlignDialog *pAlignDialog = new SmAlignDialog(NULL);
1118*cdf0e10cSrcweir 
1119*cdf0e10cSrcweir             SmFormat aOldFormat  = GetFormat();
1120*cdf0e10cSrcweir             pAlignDialog->ReadFrom( aOldFormat );
1121*cdf0e10cSrcweir 			if (pAlignDialog->Execute() == RET_OK)
1122*cdf0e10cSrcweir 			{
1123*cdf0e10cSrcweir                 SmFormat aNewFormat( aOldFormat );
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir 				pAlignDialog->WriteTo(aNewFormat);
1126*cdf0e10cSrcweir 
1127*cdf0e10cSrcweir                 SmModule *pp = SM_MOD();
1128*cdf0e10cSrcweir                 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
1129*cdf0e10cSrcweir                 pAlignDialog->WriteTo( aFmt );
1130*cdf0e10cSrcweir                 pp->GetConfig()->SetStandardFormat( aFmt );
1131*cdf0e10cSrcweir 
1132*cdf0e10cSrcweir                 ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager();
1133*cdf0e10cSrcweir                 if (pTmpUndoMgr)
1134*cdf0e10cSrcweir                     pTmpUndoMgr->AddUndoAction(
1135*cdf0e10cSrcweir                         new SmFormatAction(this, aOldFormat, aNewFormat));
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir 				SetFormat( aNewFormat );
1138*cdf0e10cSrcweir                 Repaint();
1139*cdf0e10cSrcweir 			}
1140*cdf0e10cSrcweir 			delete pAlignDialog;
1141*cdf0e10cSrcweir 		}
1142*cdf0e10cSrcweir 		break;
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir 		case SID_TEXT:
1145*cdf0e10cSrcweir 		{
1146*cdf0e10cSrcweir 			const SfxStringItem& rItem = (const SfxStringItem&)rReq.GetArgs()->Get(SID_TEXT);
1147*cdf0e10cSrcweir 			if (GetText() != rItem.GetValue())
1148*cdf0e10cSrcweir 				SetText(rItem.GetValue());
1149*cdf0e10cSrcweir 		}
1150*cdf0e10cSrcweir 		break;
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir 		case SID_UNDO:
1153*cdf0e10cSrcweir 		case SID_REDO:
1154*cdf0e10cSrcweir 		{
1155*cdf0e10cSrcweir             ::svl::IUndoManager* pTmpUndoMgr = GetUndoManager();
1156*cdf0e10cSrcweir             if( pTmpUndoMgr )
1157*cdf0e10cSrcweir 			{
1158*cdf0e10cSrcweir 				sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
1159*cdf0e10cSrcweir 				const SfxItemSet* pArgs = rReq.GetArgs();
1160*cdf0e10cSrcweir 				const SfxPoolItem* pItem;
1161*cdf0e10cSrcweir 				if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, sal_False, &pItem ))
1162*cdf0e10cSrcweir 					nCnt = ((SfxUInt16Item*)pItem)->GetValue();
1163*cdf0e10cSrcweir 
1164*cdf0e10cSrcweir 				sal_Bool (::svl::IUndoManager:: *fnDo)();
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 				sal_uInt16 nCount;
1167*cdf0e10cSrcweir 				if( SID_UNDO == rReq.GetSlot() )
1168*cdf0e10cSrcweir 				{
1169*cdf0e10cSrcweir                     nCount = pTmpUndoMgr->GetUndoActionCount();
1170*cdf0e10cSrcweir 					fnDo = &::svl::IUndoManager::Undo;
1171*cdf0e10cSrcweir 				}
1172*cdf0e10cSrcweir 				else
1173*cdf0e10cSrcweir 				{
1174*cdf0e10cSrcweir                     nCount = pTmpUndoMgr->GetRedoActionCount();
1175*cdf0e10cSrcweir 					fnDo = &::svl::IUndoManager::Redo;
1176*cdf0e10cSrcweir 				}
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir                 try
1179*cdf0e10cSrcweir                 {
1180*cdf0e10cSrcweir 				    for( ; nCnt && nCount; --nCnt, --nCount )
1181*cdf0e10cSrcweir                         (pTmpUndoMgr->*fnDo)();
1182*cdf0e10cSrcweir                 }
1183*cdf0e10cSrcweir                 catch( const Exception& e )
1184*cdf0e10cSrcweir                 {
1185*cdf0e10cSrcweir                     DBG_UNHANDLED_EXCEPTION();
1186*cdf0e10cSrcweir                 }
1187*cdf0e10cSrcweir 			}
1188*cdf0e10cSrcweir             Repaint();
1189*cdf0e10cSrcweir 			SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
1190*cdf0e10cSrcweir 			while( pFrm )
1191*cdf0e10cSrcweir 			{
1192*cdf0e10cSrcweir 				SfxBindings& rBind = pFrm->GetBindings();
1193*cdf0e10cSrcweir 				rBind.Invalidate(SID_UNDO);
1194*cdf0e10cSrcweir 				rBind.Invalidate(SID_REDO);
1195*cdf0e10cSrcweir 				rBind.Invalidate(SID_REPEAT);
1196*cdf0e10cSrcweir 				rBind.Invalidate(SID_CLEARHISTORY);
1197*cdf0e10cSrcweir 				pFrm = SfxViewFrame::GetNext( *pFrm, this );
1198*cdf0e10cSrcweir 			}
1199*cdf0e10cSrcweir 		}
1200*cdf0e10cSrcweir 		break;
1201*cdf0e10cSrcweir 	}
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir 	rReq.Done();
1204*cdf0e10cSrcweir }
1205*cdf0e10cSrcweir 
1206*cdf0e10cSrcweir 
1207*cdf0e10cSrcweir void SmDocShell::GetState(SfxItemSet &rSet)
1208*cdf0e10cSrcweir {
1209*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetState" );
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
1212*cdf0e10cSrcweir 
1213*cdf0e10cSrcweir 	for (sal_uInt16 nWh = aIter.FirstWhich();  0 != nWh;  nWh = aIter.NextWhich())
1214*cdf0e10cSrcweir 	{
1215*cdf0e10cSrcweir 		switch (nWh)
1216*cdf0e10cSrcweir 		{
1217*cdf0e10cSrcweir 		case SID_TEXTMODE:
1218*cdf0e10cSrcweir 			rSet.Put(SfxBoolItem(SID_TEXTMODE, GetFormat().IsTextmode()));
1219*cdf0e10cSrcweir 			break;
1220*cdf0e10cSrcweir 
1221*cdf0e10cSrcweir 		case SID_DOCTEMPLATE :
1222*cdf0e10cSrcweir 			rSet.DisableItem(SID_DOCTEMPLATE);
1223*cdf0e10cSrcweir 			break;
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 		case SID_AUTO_REDRAW :
1226*cdf0e10cSrcweir 			{
1227*cdf0e10cSrcweir                 SmModule  *pp = SM_MOD();
1228*cdf0e10cSrcweir 				sal_Bool	   bRedraw = pp->GetConfig()->IsAutoRedraw();
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir 				rSet.Put(SfxBoolItem(SID_AUTO_REDRAW, bRedraw));
1231*cdf0e10cSrcweir 			}
1232*cdf0e10cSrcweir 			break;
1233*cdf0e10cSrcweir 
1234*cdf0e10cSrcweir 		case SID_MODIFYSTATUS:
1235*cdf0e10cSrcweir 			{
1236*cdf0e10cSrcweir 				sal_Unicode cMod = ' ';
1237*cdf0e10cSrcweir 				if (IsModified())
1238*cdf0e10cSrcweir 					cMod = '*';
1239*cdf0e10cSrcweir 				rSet.Put(SfxStringItem(SID_MODIFYSTATUS, String(cMod)));
1240*cdf0e10cSrcweir 			}
1241*cdf0e10cSrcweir 			break;
1242*cdf0e10cSrcweir 
1243*cdf0e10cSrcweir 		case SID_TEXT:
1244*cdf0e10cSrcweir 			rSet.Put(SfxStringItem(SID_TEXT, GetText()));
1245*cdf0e10cSrcweir 			break;
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir         case SID_GAPHIC_SM:
1248*cdf0e10cSrcweir             //! very old (pre UNO) and ugly hack to invalidate the SmGraphicWindow.
1249*cdf0e10cSrcweir             //! If nModifyCount gets changed then the call below will implicitly notify
1250*cdf0e10cSrcweir             //! SmGraphicController::StateChanged and there the window gets invalidated.
1251*cdf0e10cSrcweir             //! Thus all the 'nModifyCount++' before invalidating this slot.
1252*cdf0e10cSrcweir             rSet.Put(SfxInt16Item(SID_GAPHIC_SM, nModifyCount));
1253*cdf0e10cSrcweir 			break;
1254*cdf0e10cSrcweir 
1255*cdf0e10cSrcweir 		case SID_UNDO:
1256*cdf0e10cSrcweir 		case SID_REDO:
1257*cdf0e10cSrcweir 			{
1258*cdf0e10cSrcweir 				SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
1259*cdf0e10cSrcweir 				if( pFrm )
1260*cdf0e10cSrcweir 					pFrm->GetSlotState( nWh, NULL, &rSet );
1261*cdf0e10cSrcweir 				else
1262*cdf0e10cSrcweir 					rSet.DisableItem( nWh );
1263*cdf0e10cSrcweir 			}
1264*cdf0e10cSrcweir 			break;
1265*cdf0e10cSrcweir 
1266*cdf0e10cSrcweir 		case SID_GETUNDOSTRINGS:
1267*cdf0e10cSrcweir 		case SID_GETREDOSTRINGS:
1268*cdf0e10cSrcweir 			{
1269*cdf0e10cSrcweir                 ::svl::IUndoManager* pTmpUndoMgr = GetUndoManager();
1270*cdf0e10cSrcweir                 if( pTmpUndoMgr )
1271*cdf0e10cSrcweir 				{
1272*cdf0e10cSrcweir 					UniString(::svl::IUndoManager:: *fnGetComment)( size_t, bool const ) const;
1273*cdf0e10cSrcweir 
1274*cdf0e10cSrcweir 					sal_uInt16 nCount;
1275*cdf0e10cSrcweir 					if( SID_GETUNDOSTRINGS == nWh )
1276*cdf0e10cSrcweir 					{
1277*cdf0e10cSrcweir                         nCount = pTmpUndoMgr->GetUndoActionCount();
1278*cdf0e10cSrcweir 						fnGetComment = &::svl::IUndoManager::GetUndoActionComment;
1279*cdf0e10cSrcweir 					}
1280*cdf0e10cSrcweir 					else
1281*cdf0e10cSrcweir 					{
1282*cdf0e10cSrcweir                         nCount = pTmpUndoMgr->GetRedoActionCount();
1283*cdf0e10cSrcweir 						fnGetComment = &::svl::IUndoManager::GetRedoActionComment;
1284*cdf0e10cSrcweir 					}
1285*cdf0e10cSrcweir 					if( nCount )
1286*cdf0e10cSrcweir 					{
1287*cdf0e10cSrcweir 						String sList;
1288*cdf0e10cSrcweir 						for( sal_uInt16 n = 0; n < nCount; ++n )
1289*cdf0e10cSrcweir                             ( sList += (pTmpUndoMgr->*fnGetComment)( n, ::svl::IUndoManager::TopLevel ) )
1290*cdf0e10cSrcweir 									+= '\n';
1291*cdf0e10cSrcweir 
1292*cdf0e10cSrcweir 						SfxStringListItem aItem( nWh );
1293*cdf0e10cSrcweir 						aItem.SetString( sList );
1294*cdf0e10cSrcweir 						rSet.Put( aItem );
1295*cdf0e10cSrcweir 					}
1296*cdf0e10cSrcweir 				}
1297*cdf0e10cSrcweir 				else
1298*cdf0e10cSrcweir 					rSet.DisableItem( nWh );
1299*cdf0e10cSrcweir 			}
1300*cdf0e10cSrcweir 			break;
1301*cdf0e10cSrcweir 		}
1302*cdf0e10cSrcweir 	}
1303*cdf0e10cSrcweir }
1304*cdf0e10cSrcweir 
1305*cdf0e10cSrcweir 
1306*cdf0e10cSrcweir ::svl::IUndoManager *SmDocShell::GetUndoManager()
1307*cdf0e10cSrcweir {
1308*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetUndoManager" );
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir 	if (!pEditEngine)
1311*cdf0e10cSrcweir 		GetEditEngine();
1312*cdf0e10cSrcweir 	return &pEditEngine->GetUndoManager();
1313*cdf0e10cSrcweir }
1314*cdf0e10cSrcweir 
1315*cdf0e10cSrcweir 
1316*cdf0e10cSrcweir void SmDocShell::SaveSymbols()
1317*cdf0e10cSrcweir {
1318*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveSymbols" );
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir     SmModule *pp = SM_MOD();
1321*cdf0e10cSrcweir     pp->GetSymbolManager().Save();
1322*cdf0e10cSrcweir }
1323*cdf0e10cSrcweir 
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir void SmDocShell::Draw(OutputDevice *pDevice,
1326*cdf0e10cSrcweir 					  const JobSetup &,
1327*cdf0e10cSrcweir                       sal_uInt16 /*nAspect*/)
1328*cdf0e10cSrcweir {
1329*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Draw" );
1330*cdf0e10cSrcweir 
1331*cdf0e10cSrcweir 	pDevice->IntersectClipRegion(GetVisArea());
1332*cdf0e10cSrcweir 	Point atmppoint;
1333*cdf0e10cSrcweir 	Draw(*pDevice, atmppoint);
1334*cdf0e10cSrcweir }
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir SfxItemPool& SmDocShell::GetPool() const
1337*cdf0e10cSrcweir {
1338*cdf0e10cSrcweir 	return SFX_APP()->GetPool();
1339*cdf0e10cSrcweir }
1340*cdf0e10cSrcweir 
1341*cdf0e10cSrcweir void SmDocShell::SetVisArea(const Rectangle & rVisArea)
1342*cdf0e10cSrcweir {
1343*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetVisArea" );
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir 	Rectangle aNewRect(rVisArea);
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir 	aNewRect.SetPos(Point());
1348*cdf0e10cSrcweir 
1349*cdf0e10cSrcweir 	if (! aNewRect.Right()) aNewRect.Right() = 2000;
1350*cdf0e10cSrcweir 	if (! aNewRect.Bottom()) aNewRect.Bottom() = 1000;
1351*cdf0e10cSrcweir 
1352*cdf0e10cSrcweir 	sal_Bool bIsEnabled = IsEnableSetModified();
1353*cdf0e10cSrcweir 	if ( bIsEnabled )
1354*cdf0e10cSrcweir 		EnableSetModified( sal_False );
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir     //TODO/LATER: it's unclear how this interacts with the SFX code
1357*cdf0e10cSrcweir     // If outplace editing, then dont resize the OutplaceWindow. But the
1358*cdf0e10cSrcweir 	// ObjectShell has to resize. Bug 56470
1359*cdf0e10cSrcweir 	sal_Bool bUnLockFrame;
1360*cdf0e10cSrcweir     if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !IsInPlaceActive() && GetFrame() )
1361*cdf0e10cSrcweir 	{
1362*cdf0e10cSrcweir 		GetFrame()->LockAdjustPosSizePixel();
1363*cdf0e10cSrcweir 		bUnLockFrame = sal_True;
1364*cdf0e10cSrcweir 	}
1365*cdf0e10cSrcweir 	else
1366*cdf0e10cSrcweir 		bUnLockFrame = sal_False;
1367*cdf0e10cSrcweir 
1368*cdf0e10cSrcweir     SfxObjectShell::SetVisArea( aNewRect );
1369*cdf0e10cSrcweir 
1370*cdf0e10cSrcweir 	if( bUnLockFrame )
1371*cdf0e10cSrcweir 		GetFrame()->UnlockAdjustPosSizePixel();
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir 	if ( bIsEnabled )
1374*cdf0e10cSrcweir 		EnableSetModified( bIsEnabled );
1375*cdf0e10cSrcweir }
1376*cdf0e10cSrcweir 
1377*cdf0e10cSrcweir 
1378*cdf0e10cSrcweir void SmDocShell::FillClass(SvGlobalName* pClassName,
1379*cdf0e10cSrcweir 						   sal_uInt32*  pFormat,
1380*cdf0e10cSrcweir                            String* /*pAppName*/,
1381*cdf0e10cSrcweir 						   String* pFullTypeName,
1382*cdf0e10cSrcweir                            String* pShortTypeName,
1383*cdf0e10cSrcweir                            sal_Int32 nFileFormat,
1384*cdf0e10cSrcweir                            sal_Bool bTemplate /* = sal_False */) const
1385*cdf0e10cSrcweir {
1386*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::FillClass" );
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir 	if (nFileFormat == SOFFICE_FILEFORMAT_60 )
1389*cdf0e10cSrcweir 	{
1390*cdf0e10cSrcweir 		*pClassName 	= SvGlobalName(SO3_SM_CLASSID_60);
1391*cdf0e10cSrcweir 		*pFormat		= SOT_FORMATSTR_ID_STARMATH_60;
1392*cdf0e10cSrcweir         *pFullTypeName  = String(SmResId(STR_MATH_DOCUMENT_FULLTYPE_CURRENT));
1393*cdf0e10cSrcweir 		*pShortTypeName = String(SmResId(RID_DOCUMENTSTR));
1394*cdf0e10cSrcweir 	}
1395*cdf0e10cSrcweir 	else if (nFileFormat == SOFFICE_FILEFORMAT_8 )
1396*cdf0e10cSrcweir 	{
1397*cdf0e10cSrcweir 		*pClassName 	= SvGlobalName(SO3_SM_CLASSID_60);
1398*cdf0e10cSrcweir         *pFormat		= bTemplate ? SOT_FORMATSTR_ID_STARMATH_8_TEMPLATE : SOT_FORMATSTR_ID_STARMATH_8;
1399*cdf0e10cSrcweir         *pFullTypeName  = String(SmResId(STR_MATH_DOCUMENT_FULLTYPE_CURRENT));
1400*cdf0e10cSrcweir 		*pShortTypeName = String(SmResId(RID_DOCUMENTSTR));
1401*cdf0e10cSrcweir 	}
1402*cdf0e10cSrcweir }
1403*cdf0e10cSrcweir 
1404*cdf0e10cSrcweir sal_uLong SmDocShell::GetMiscStatus() const
1405*cdf0e10cSrcweir {
1406*cdf0e10cSrcweir     return SfxObjectShell::GetMiscStatus() | SVOBJ_MISCSTATUS_NOTRESIZEABLE
1407*cdf0e10cSrcweir 											 | SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE;
1408*cdf0e10cSrcweir }
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir void SmDocShell::SetModified(sal_Bool bModified)
1411*cdf0e10cSrcweir {
1412*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetModified" );
1413*cdf0e10cSrcweir 
1414*cdf0e10cSrcweir 	if( IsEnableSetModified() )
1415*cdf0e10cSrcweir 	{
1416*cdf0e10cSrcweir 		SfxObjectShell::SetModified( bModified );
1417*cdf0e10cSrcweir 		Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED));
1418*cdf0e10cSrcweir 	}
1419*cdf0e10cSrcweir }
1420*cdf0e10cSrcweir 
1421*cdf0e10cSrcweir sal_Bool SmDocShell::WriteAsMathType3( SfxMedium& rMedium )
1422*cdf0e10cSrcweir {
1423*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::WriteAsMathType3" );
1424*cdf0e10cSrcweir 
1425*cdf0e10cSrcweir     MathType aEquation( aText, pTree );
1426*cdf0e10cSrcweir 
1427*cdf0e10cSrcweir     sal_Bool bRet = 0 != aEquation.ConvertFromStarMath( rMedium );
1428*cdf0e10cSrcweir     return bRet;
1429*cdf0e10cSrcweir }
1430*cdf0e10cSrcweir 
1431*cdf0e10cSrcweir 
1432