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