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