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 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 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 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 150cdf0e10cSrcweir 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 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 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 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 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 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 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 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 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 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 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 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 589cdf0e10cSrcweir SmPrinterAccess::~SmPrinterAccess() 590cdf0e10cSrcweir { 591cdf0e10cSrcweir if ( pPrinter ) 592cdf0e10cSrcweir pPrinter->Pop(); 593cdf0e10cSrcweir if ( pRefDev && pRefDev != pPrinter ) 594cdf0e10cSrcweir pRefDev->Pop(); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir //////////////////////////////////////// 598cdf0e10cSrcweir 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, 625cdf0e10cSrcweir 0); 626cdf0e10cSrcweir 627cdf0e10cSrcweir SmModule *pp = SM_MOD(); 628cdf0e10cSrcweir pp->GetConfig()->ConfigToItemSet(*pOptions); 629cdf0e10cSrcweir pPrinter = new SfxPrinter(pOptions); 630cdf0e10cSrcweir pPrinter->SetMapMode( MapMode(MAP_100TH_MM) ); 631cdf0e10cSrcweir } 632cdf0e10cSrcweir return pPrinter; 633cdf0e10cSrcweir } 634cdf0e10cSrcweir 635cdf0e10cSrcweir OutputDevice* SmDocShell::GetRefDev() 636cdf0e10cSrcweir { 637cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetRefDev" ); 638cdf0e10cSrcweir 639cdf0e10cSrcweir if ( SFX_CREATE_MODE_EMBEDDED == GetCreateMode() ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir OutputDevice* pOutDev = GetDocumentRefDev(); 642cdf0e10cSrcweir if ( pOutDev ) 643cdf0e10cSrcweir return pOutDev; 644cdf0e10cSrcweir } 645cdf0e10cSrcweir 646cdf0e10cSrcweir return GetPrt(); 647cdf0e10cSrcweir } 648cdf0e10cSrcweir 649cdf0e10cSrcweir 650cdf0e10cSrcweir void SmDocShell::SetPrinter( SfxPrinter *pNew ) 651cdf0e10cSrcweir { 652cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetPrinter" ); 653cdf0e10cSrcweir 654cdf0e10cSrcweir delete pPrinter; 655cdf0e10cSrcweir pPrinter = pNew; //Eigentumsuebergang! 656cdf0e10cSrcweir pPrinter->SetMapMode( MapMode(MAP_100TH_MM) ); 657cdf0e10cSrcweir SetFormulaArranged(sal_False); 658cdf0e10cSrcweir Repaint(); 659cdf0e10cSrcweir } 660cdf0e10cSrcweir 661cdf0e10cSrcweir void SmDocShell::OnDocumentPrinterChanged( Printer *pPrt ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::OnDocumentPrinterChanged" ); 664cdf0e10cSrcweir 665cdf0e10cSrcweir pTmpPrinter = pPrt; 666cdf0e10cSrcweir SetFormulaArranged(sal_False); 667cdf0e10cSrcweir Size aOldSize = GetVisArea().GetSize(); 668cdf0e10cSrcweir Repaint(); 669cdf0e10cSrcweir if( aOldSize != GetVisArea().GetSize() && aText.Len() ) 670cdf0e10cSrcweir SetModified( sal_True ); 671cdf0e10cSrcweir pTmpPrinter = 0; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir 674cdf0e10cSrcweir void SmDocShell::Repaint() 675cdf0e10cSrcweir { 676cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Repaint" ); 677cdf0e10cSrcweir 678cdf0e10cSrcweir sal_Bool bIsEnabled = IsEnableSetModified(); 679cdf0e10cSrcweir if ( bIsEnabled ) 680cdf0e10cSrcweir EnableSetModified( sal_False ); 681cdf0e10cSrcweir 682cdf0e10cSrcweir SetFormulaArranged( sal_False ); 683cdf0e10cSrcweir 684cdf0e10cSrcweir Size aVisSize = GetSize(); 685cdf0e10cSrcweir SetVisAreaSize( aVisSize ); 686cdf0e10cSrcweir SmViewShell *pViewSh = SmGetActiveView(); 687cdf0e10cSrcweir if (pViewSh) 688cdf0e10cSrcweir pViewSh->GetGraphicWindow().Invalidate(); 689cdf0e10cSrcweir 690cdf0e10cSrcweir if ( bIsEnabled ) 691cdf0e10cSrcweir EnableSetModified( bIsEnabled ); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir 694cdf0e10cSrcweir 695cdf0e10cSrcweir SmDocShell::SmDocShell( const sal_uInt64 i_nSfxCreationFlags ) : 696cdf0e10cSrcweir SfxObjectShell( i_nSfxCreationFlags ), 697cdf0e10cSrcweir pTree ( 0 ), 698cdf0e10cSrcweir pEditEngineItemPool ( 0 ), 699cdf0e10cSrcweir pEditEngine ( 0 ), 700cdf0e10cSrcweir pPrinter ( 0 ), 701cdf0e10cSrcweir pTmpPrinter ( 0 ), 702cdf0e10cSrcweir nModifyCount ( 0 ), 703cdf0e10cSrcweir bIsFormulaArranged ( sal_False ) 704cdf0e10cSrcweir { 705cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SmDocShell" ); 706cdf0e10cSrcweir 707cdf0e10cSrcweir SetPool(&SFX_APP()->GetPool()); 708cdf0e10cSrcweir 709cdf0e10cSrcweir SmModule *pp = SM_MOD(); 710cdf0e10cSrcweir aFormat = pp->GetConfig()->GetStandardFormat(); 711cdf0e10cSrcweir 712cdf0e10cSrcweir StartListening(aFormat); 713cdf0e10cSrcweir StartListening(*pp->GetConfig()); 714cdf0e10cSrcweir 715cdf0e10cSrcweir SetBaseModel( new SmModel(this) ); 716cdf0e10cSrcweir } 717cdf0e10cSrcweir 718cdf0e10cSrcweir 719cdf0e10cSrcweir 720cdf0e10cSrcweir SmDocShell::~SmDocShell() 721cdf0e10cSrcweir { 722cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::~SmDocShell" ); 723cdf0e10cSrcweir 724cdf0e10cSrcweir SmModule *pp = SM_MOD(); 725cdf0e10cSrcweir 726cdf0e10cSrcweir EndListening(aFormat); 727cdf0e10cSrcweir EndListening(*pp->GetConfig()); 728cdf0e10cSrcweir 729cdf0e10cSrcweir delete pEditEngine; 730cdf0e10cSrcweir SfxItemPool::Free(pEditEngineItemPool); 731cdf0e10cSrcweir delete pTree; 732cdf0e10cSrcweir delete pPrinter; 733cdf0e10cSrcweir } 734cdf0e10cSrcweir 735cdf0e10cSrcweir 736cdf0e10cSrcweir sal_Bool SmDocShell::SetData( const String& rData ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetData" ); 739cdf0e10cSrcweir 740cdf0e10cSrcweir SetText( rData ); 741cdf0e10cSrcweir return sal_True; 742cdf0e10cSrcweir } 743cdf0e10cSrcweir 744cdf0e10cSrcweir 745cdf0e10cSrcweir sal_Bool SmDocShell::ConvertFrom(SfxMedium &rMedium) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ConvertFrom" ); 748cdf0e10cSrcweir 749cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 750cdf0e10cSrcweir const String& rFltName = rMedium.GetFilter()->GetFilterName(); 751cdf0e10cSrcweir 752cdf0e10cSrcweir DBG_ASSERT( !rFltName.EqualsAscii( STAROFFICE_XML ), "Wrong filter!"); 753cdf0e10cSrcweir 754cdf0e10cSrcweir if ( rFltName.EqualsAscii( MATHML_XML ) ) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir if (pTree) 757cdf0e10cSrcweir { 758cdf0e10cSrcweir delete pTree; 759cdf0e10cSrcweir pTree = 0; 760cdf0e10cSrcweir } 761cdf0e10cSrcweir Reference<com::sun::star::frame::XModel> xModel(GetModel()); 762cdf0e10cSrcweir SmXMLImportWrapper aEquation(xModel); 763cdf0e10cSrcweir bSuccess = 0 == aEquation.Import(rMedium); 764cdf0e10cSrcweir } 765cdf0e10cSrcweir else 766cdf0e10cSrcweir { 767cdf0e10cSrcweir SvStream *pStream = rMedium.GetInStream(); 768cdf0e10cSrcweir if ( pStream ) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir if ( SotStorage::IsStorageFile( pStream ) ) 771cdf0e10cSrcweir { 772cdf0e10cSrcweir SvStorageRef aStorage = new SotStorage( pStream, sal_False ); 773cdf0e10cSrcweir if ( aStorage->IsStream( C2S( "Equation Native" ) ) ) 774cdf0e10cSrcweir { 775cdf0e10cSrcweir // is this a MathType Storage? 776cdf0e10cSrcweir MathType aEquation( aText ); 777cdf0e10cSrcweir if ( sal_True == (bSuccess = (1 == aEquation.Parse( aStorage )) )) 778cdf0e10cSrcweir Parse(); 779cdf0e10cSrcweir } 780cdf0e10cSrcweir } 781cdf0e10cSrcweir else 782cdf0e10cSrcweir { 783cdf0e10cSrcweir //bSuccess = ImportSM20File( pStream ); 784cdf0e10cSrcweir } 785cdf0e10cSrcweir } 786cdf0e10cSrcweir } 787cdf0e10cSrcweir 788cdf0e10cSrcweir if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 789cdf0e10cSrcweir { 790cdf0e10cSrcweir //???OnDocumentPrinterChanged(0); 791cdf0e10cSrcweir SetFormulaArranged( sal_False ); 792cdf0e10cSrcweir Repaint(); 793cdf0e10cSrcweir } 794cdf0e10cSrcweir 795cdf0e10cSrcweir FinishedLoading( SFX_LOADED_ALL ); 796cdf0e10cSrcweir return bSuccess; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir 799cdf0e10cSrcweir 800cdf0e10cSrcweir sal_Bool SmDocShell::InitNew( const uno::Reference < embed::XStorage >& xStorage ) 801cdf0e10cSrcweir { 802cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::InitNew" ); 803cdf0e10cSrcweir 804cdf0e10cSrcweir sal_Bool bRet = sal_False; 805cdf0e10cSrcweir if ( SfxObjectShell::InitNew( xStorage ) ) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir bRet = sal_True; 808cdf0e10cSrcweir SetVisArea(Rectangle(Point(0, 0), Size(2000, 1000))); 809cdf0e10cSrcweir } 810cdf0e10cSrcweir return bRet; 811cdf0e10cSrcweir } 812cdf0e10cSrcweir 813cdf0e10cSrcweir 814cdf0e10cSrcweir sal_Bool SmDocShell::Load( SfxMedium& rMedium ) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Load" ); 817cdf0e10cSrcweir 818cdf0e10cSrcweir sal_Bool bRet = sal_False; 819cdf0e10cSrcweir if( SfxObjectShell::Load( rMedium )) 820cdf0e10cSrcweir { 821cdf0e10cSrcweir uno::Reference < embed::XStorage > xStorage = GetMedium()->GetStorage(); 822cdf0e10cSrcweir uno::Reference < container::XNameAccess > xAccess (xStorage, uno::UNO_QUERY); 823cdf0e10cSrcweir if ( 824cdf0e10cSrcweir ( 825cdf0e10cSrcweir xAccess->hasByName( C2S( "content.xml" ) ) && 826cdf0e10cSrcweir xStorage->isStreamElement( C2S( "content.xml" ) ) 827cdf0e10cSrcweir ) || 828cdf0e10cSrcweir ( 829cdf0e10cSrcweir xAccess->hasByName( C2S( "Content.xml" ) ) && 830cdf0e10cSrcweir xStorage->isStreamElement( C2S( "Content.xml" ) ) 831cdf0e10cSrcweir ) 832cdf0e10cSrcweir ) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir // is this a fabulous math package ? 835cdf0e10cSrcweir Reference<com::sun::star::frame::XModel> xModel(GetModel()); 836cdf0e10cSrcweir SmXMLImportWrapper aEquation(xModel); 837cdf0e10cSrcweir sal_uLong nError = aEquation.Import(rMedium); 838cdf0e10cSrcweir bRet = 0 == nError; 839cdf0e10cSrcweir SetError( nError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 840cdf0e10cSrcweir } 841cdf0e10cSrcweir } 842cdf0e10cSrcweir 843cdf0e10cSrcweir if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir //???OnDocumentPrinterChanged(0); 846cdf0e10cSrcweir SetFormulaArranged( sal_False ); 847cdf0e10cSrcweir Repaint(); 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir FinishedLoading( SFX_LOADED_ALL ); 851cdf0e10cSrcweir return bRet; 852cdf0e10cSrcweir } 853cdf0e10cSrcweir 854cdf0e10cSrcweir //------------------------------------------------------------------ 855cdf0e10cSrcweir 856cdf0e10cSrcweir sal_Bool SmDocShell::Save() 857cdf0e10cSrcweir { 858cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Save" ); 859cdf0e10cSrcweir 860cdf0e10cSrcweir //! apply latest changes if necessary 861cdf0e10cSrcweir UpdateText(); 862cdf0e10cSrcweir 863cdf0e10cSrcweir if ( SfxObjectShell::Save() ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir if (!pTree) 866cdf0e10cSrcweir Parse(); 867cdf0e10cSrcweir if( pTree && !IsFormulaArranged() ) 868cdf0e10cSrcweir ArrangeFormula(); 869cdf0e10cSrcweir 870cdf0e10cSrcweir Reference<com::sun::star::frame::XModel> xModel(GetModel()); 871cdf0e10cSrcweir SmXMLExportWrapper aEquation(xModel); 872cdf0e10cSrcweir aEquation.SetFlat(sal_False); 873cdf0e10cSrcweir return aEquation.Export(*GetMedium()); 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir return sal_False; 877cdf0e10cSrcweir } 878cdf0e10cSrcweir 879cdf0e10cSrcweir /* 880cdf0e10cSrcweir * replace bad characters that can not be saved. (#i74144) 881cdf0e10cSrcweir * */ 882cdf0e10cSrcweir sal_Bool SmDocShell::ReplaceBadChars() 883cdf0e10cSrcweir { 884cdf0e10cSrcweir sal_Bool bReplace = sal_False; 885cdf0e10cSrcweir if (pEditEngine) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir String aEngTxt( pEditEngine->GetText( LINEEND_LF ) ); 888cdf0e10cSrcweir const sal_Unicode *pEngTxt = aEngTxt.GetBuffer(); 889cdf0e10cSrcweir xub_StrLen nLen = aEngTxt.Len(); 890cdf0e10cSrcweir for (xub_StrLen i = 0; i < nLen && !bReplace; ++i) 891cdf0e10cSrcweir { 892cdf0e10cSrcweir const sal_Unicode c = *pEngTxt++; 893cdf0e10cSrcweir if (c < ' ' && c != '\r' && c != '\n' && c != '\t') 894cdf0e10cSrcweir bReplace = sal_True; 895cdf0e10cSrcweir } 896cdf0e10cSrcweir if (bReplace) 897cdf0e10cSrcweir { 898cdf0e10cSrcweir sal_Unicode *pChgTxt = aEngTxt.GetBufferAccess(); 899cdf0e10cSrcweir for (xub_StrLen i = 0; i < nLen; ++i) 900cdf0e10cSrcweir { 901cdf0e10cSrcweir sal_Unicode &rc = *pChgTxt++; 902cdf0e10cSrcweir if (rc < ' ' && rc != '\r' && rc != '\n' && rc != '\t') 903cdf0e10cSrcweir rc = ' '; 904cdf0e10cSrcweir } 905cdf0e10cSrcweir aEngTxt.ReleaseBufferAccess( nLen ); 906cdf0e10cSrcweir 907cdf0e10cSrcweir aText = aEngTxt; 908cdf0e10cSrcweir } 909cdf0e10cSrcweir } 910cdf0e10cSrcweir return bReplace; 911cdf0e10cSrcweir } 912cdf0e10cSrcweir 913cdf0e10cSrcweir 914cdf0e10cSrcweir void SmDocShell::UpdateText() 915cdf0e10cSrcweir { 916cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::UpdateText" ); 917cdf0e10cSrcweir 918cdf0e10cSrcweir if (pEditEngine && pEditEngine->IsModified()) 919cdf0e10cSrcweir { 920cdf0e10cSrcweir String aEngTxt( pEditEngine->GetText( LINEEND_LF ) ); 921cdf0e10cSrcweir if (GetText() != aEngTxt) 922cdf0e10cSrcweir SetText( aEngTxt ); 923cdf0e10cSrcweir } 924cdf0e10cSrcweir } 925cdf0e10cSrcweir 926cdf0e10cSrcweir 927cdf0e10cSrcweir sal_Bool SmDocShell::SaveAs( SfxMedium& rMedium ) 928cdf0e10cSrcweir { 929cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveAs" ); 930cdf0e10cSrcweir 931cdf0e10cSrcweir sal_Bool bRet = sal_False; 932cdf0e10cSrcweir 933cdf0e10cSrcweir //! apply latest changes if necessary 934cdf0e10cSrcweir UpdateText(); 935cdf0e10cSrcweir 936cdf0e10cSrcweir if ( SfxObjectShell::SaveAs( rMedium ) ) 937cdf0e10cSrcweir { 938cdf0e10cSrcweir if (!pTree) 939cdf0e10cSrcweir Parse(); 940cdf0e10cSrcweir if( pTree && !IsFormulaArranged() ) 941cdf0e10cSrcweir ArrangeFormula(); 942cdf0e10cSrcweir 943cdf0e10cSrcweir Reference<com::sun::star::frame::XModel> xModel(GetModel()); 944cdf0e10cSrcweir SmXMLExportWrapper aEquation(xModel); 945cdf0e10cSrcweir aEquation.SetFlat(sal_False); 946cdf0e10cSrcweir bRet = aEquation.Export(rMedium); 947cdf0e10cSrcweir } 948cdf0e10cSrcweir return bRet; 949cdf0e10cSrcweir } 950cdf0e10cSrcweir 951cdf0e10cSrcweir sal_Bool SmDocShell::ConvertTo( SfxMedium &rMedium ) 952cdf0e10cSrcweir { 953cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ConvertTo" ); 954cdf0e10cSrcweir 955cdf0e10cSrcweir sal_Bool bRet = sal_False; 956cdf0e10cSrcweir const SfxFilter* pFlt = rMedium.GetFilter(); 957cdf0e10cSrcweir if( pFlt ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir if( !pTree ) 960cdf0e10cSrcweir Parse(); 961cdf0e10cSrcweir if( pTree && !IsFormulaArranged() ) 962cdf0e10cSrcweir ArrangeFormula(); 963cdf0e10cSrcweir 964cdf0e10cSrcweir const String& rFltName = pFlt->GetFilterName(); 965cdf0e10cSrcweir if(rFltName.EqualsAscii( STAROFFICE_XML )) 966cdf0e10cSrcweir { 967cdf0e10cSrcweir Reference<com::sun::star::frame::XModel> xModel(GetModel()); 968cdf0e10cSrcweir SmXMLExportWrapper aEquation(xModel); 969cdf0e10cSrcweir aEquation.SetFlat(sal_False); 970cdf0e10cSrcweir bRet = aEquation.Export(rMedium); 971cdf0e10cSrcweir } 972cdf0e10cSrcweir else if(rFltName.EqualsAscii( MATHML_XML )) 973cdf0e10cSrcweir { 974cdf0e10cSrcweir Reference<com::sun::star::frame::XModel> xModel(GetModel()); 975cdf0e10cSrcweir SmXMLExportWrapper aEquation(xModel); 976cdf0e10cSrcweir aEquation.SetFlat(sal_True); 977cdf0e10cSrcweir bRet = aEquation.Export(rMedium); 978cdf0e10cSrcweir } 979cdf0e10cSrcweir else if( pFlt->GetFilterName().EqualsAscii("MathType 3.x")) 980cdf0e10cSrcweir bRet = WriteAsMathType3( rMedium ); 981cdf0e10cSrcweir } 982cdf0e10cSrcweir return bRet; 983cdf0e10cSrcweir } 984cdf0e10cSrcweir 985cdf0e10cSrcweir sal_Bool SmDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) 986cdf0e10cSrcweir { 987cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveCompleted" ); 988cdf0e10cSrcweir 989cdf0e10cSrcweir if( SfxObjectShell::SaveCompleted( xStorage )) 990cdf0e10cSrcweir return sal_True; 991cdf0e10cSrcweir 992cdf0e10cSrcweir return sal_False; 993cdf0e10cSrcweir } 994cdf0e10cSrcweir 995cdf0e10cSrcweir 996cdf0e10cSrcweir void SmDocShell::Execute(SfxRequest& rReq) 997cdf0e10cSrcweir { 998cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Execute" ); 999cdf0e10cSrcweir 1000cdf0e10cSrcweir switch (rReq.GetSlot()) 1001cdf0e10cSrcweir { 1002cdf0e10cSrcweir case SID_TEXTMODE: 1003cdf0e10cSrcweir { 1004cdf0e10cSrcweir SmFormat aOldFormat = GetFormat(); 1005cdf0e10cSrcweir SmFormat aNewFormat( aOldFormat ); 1006cdf0e10cSrcweir aNewFormat.SetTextmode(!aOldFormat.IsTextmode()); 1007cdf0e10cSrcweir 1008cdf0e10cSrcweir ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager(); 1009cdf0e10cSrcweir if (pTmpUndoMgr) 1010cdf0e10cSrcweir pTmpUndoMgr->AddUndoAction( 1011cdf0e10cSrcweir new SmFormatAction(this, aOldFormat, aNewFormat)); 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir SetFormat( aNewFormat ); 1014cdf0e10cSrcweir Repaint(); 1015cdf0e10cSrcweir } 1016cdf0e10cSrcweir break; 1017cdf0e10cSrcweir 1018cdf0e10cSrcweir case SID_AUTO_REDRAW : 1019cdf0e10cSrcweir { 1020cdf0e10cSrcweir SmModule *pp = SM_MOD(); 1021cdf0e10cSrcweir sal_Bool bRedraw = pp->GetConfig()->IsAutoRedraw(); 1022cdf0e10cSrcweir pp->GetConfig()->SetAutoRedraw(!bRedraw); 1023cdf0e10cSrcweir } 1024cdf0e10cSrcweir break; 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir case SID_LOADSYMBOLS: 1027cdf0e10cSrcweir LoadSymbols(); 1028cdf0e10cSrcweir break; 1029cdf0e10cSrcweir 1030cdf0e10cSrcweir case SID_SAVESYMBOLS: 1031cdf0e10cSrcweir SaveSymbols(); 1032cdf0e10cSrcweir break; 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir case SID_FONT: 1035cdf0e10cSrcweir { 1036cdf0e10cSrcweir // get device used to retrieve the FontList 1037cdf0e10cSrcweir OutputDevice *pDev = GetPrinter(); 1038cdf0e10cSrcweir if (!pDev || pDev->GetDevFontCount() == 0) 1039cdf0e10cSrcweir pDev = &SM_MOD()->GetDefaultVirtualDev(); 1040cdf0e10cSrcweir DBG_ASSERT (pDev, "device for font list missing" ); 1041cdf0e10cSrcweir 1042cdf0e10cSrcweir SmFontTypeDialog *pFontTypeDialog = new SmFontTypeDialog( NULL, pDev ); 1043cdf0e10cSrcweir 1044cdf0e10cSrcweir SmFormat aOldFormat = GetFormat(); 1045cdf0e10cSrcweir pFontTypeDialog->ReadFrom( aOldFormat ); 1046cdf0e10cSrcweir if (pFontTypeDialog->Execute() == RET_OK) 1047cdf0e10cSrcweir { 1048cdf0e10cSrcweir SmFormat aNewFormat( aOldFormat ); 1049cdf0e10cSrcweir 1050cdf0e10cSrcweir pFontTypeDialog->WriteTo(aNewFormat); 1051cdf0e10cSrcweir ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager(); 1052cdf0e10cSrcweir if (pTmpUndoMgr) 1053cdf0e10cSrcweir pTmpUndoMgr->AddUndoAction( 1054cdf0e10cSrcweir new SmFormatAction(this, aOldFormat, aNewFormat)); 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir SetFormat( aNewFormat ); 1057cdf0e10cSrcweir Repaint(); 1058cdf0e10cSrcweir } 1059cdf0e10cSrcweir delete pFontTypeDialog; 1060cdf0e10cSrcweir } 1061cdf0e10cSrcweir break; 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir case SID_FONTSIZE: 1064cdf0e10cSrcweir { 1065cdf0e10cSrcweir SmFontSizeDialog *pFontSizeDialog = new SmFontSizeDialog(NULL); 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir SmFormat aOldFormat = GetFormat(); 1068cdf0e10cSrcweir pFontSizeDialog->ReadFrom( aOldFormat ); 1069cdf0e10cSrcweir if (pFontSizeDialog->Execute() == RET_OK) 1070cdf0e10cSrcweir { 1071cdf0e10cSrcweir SmFormat aNewFormat( aOldFormat ); 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir pFontSizeDialog->WriteTo(aNewFormat); 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager(); 1076cdf0e10cSrcweir if (pTmpUndoMgr) 1077cdf0e10cSrcweir pTmpUndoMgr->AddUndoAction( 1078cdf0e10cSrcweir new SmFormatAction(this, aOldFormat, aNewFormat)); 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir SetFormat( aNewFormat ); 1081cdf0e10cSrcweir Repaint(); 1082cdf0e10cSrcweir } 1083cdf0e10cSrcweir delete pFontSizeDialog; 1084cdf0e10cSrcweir } 1085cdf0e10cSrcweir break; 1086cdf0e10cSrcweir 1087cdf0e10cSrcweir case SID_DISTANCE: 1088cdf0e10cSrcweir { 1089cdf0e10cSrcweir SmDistanceDialog *pDistanceDialog = new SmDistanceDialog(NULL); 1090cdf0e10cSrcweir 1091cdf0e10cSrcweir SmFormat aOldFormat = GetFormat(); 1092cdf0e10cSrcweir pDistanceDialog->ReadFrom( aOldFormat ); 1093cdf0e10cSrcweir if (pDistanceDialog->Execute() == RET_OK) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir SmFormat aNewFormat( aOldFormat ); 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir pDistanceDialog->WriteTo(aNewFormat); 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager(); 1100cdf0e10cSrcweir if (pTmpUndoMgr) 1101cdf0e10cSrcweir pTmpUndoMgr->AddUndoAction( 1102cdf0e10cSrcweir new SmFormatAction(this, aOldFormat, aNewFormat)); 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir SetFormat( aNewFormat ); 1105cdf0e10cSrcweir Repaint(); 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir delete pDistanceDialog; 1108cdf0e10cSrcweir } 1109cdf0e10cSrcweir break; 1110cdf0e10cSrcweir 1111cdf0e10cSrcweir case SID_ALIGN: 1112cdf0e10cSrcweir { 1113cdf0e10cSrcweir SmAlignDialog *pAlignDialog = new SmAlignDialog(NULL); 1114cdf0e10cSrcweir 1115cdf0e10cSrcweir SmFormat aOldFormat = GetFormat(); 1116cdf0e10cSrcweir pAlignDialog->ReadFrom( aOldFormat ); 1117cdf0e10cSrcweir if (pAlignDialog->Execute() == RET_OK) 1118cdf0e10cSrcweir { 1119cdf0e10cSrcweir SmFormat aNewFormat( aOldFormat ); 1120cdf0e10cSrcweir 1121cdf0e10cSrcweir pAlignDialog->WriteTo(aNewFormat); 1122cdf0e10cSrcweir 1123cdf0e10cSrcweir SmModule *pp = SM_MOD(); 1124cdf0e10cSrcweir SmFormat aFmt( pp->GetConfig()->GetStandardFormat() ); 1125cdf0e10cSrcweir pAlignDialog->WriteTo( aFmt ); 1126cdf0e10cSrcweir pp->GetConfig()->SetStandardFormat( aFmt ); 1127cdf0e10cSrcweir 1128cdf0e10cSrcweir ::svl::IUndoManager *pTmpUndoMgr = GetUndoManager(); 1129cdf0e10cSrcweir if (pTmpUndoMgr) 1130cdf0e10cSrcweir pTmpUndoMgr->AddUndoAction( 1131cdf0e10cSrcweir new SmFormatAction(this, aOldFormat, aNewFormat)); 1132cdf0e10cSrcweir 1133cdf0e10cSrcweir SetFormat( aNewFormat ); 1134cdf0e10cSrcweir Repaint(); 1135cdf0e10cSrcweir } 1136cdf0e10cSrcweir delete pAlignDialog; 1137cdf0e10cSrcweir } 1138cdf0e10cSrcweir break; 1139cdf0e10cSrcweir 1140cdf0e10cSrcweir case SID_TEXT: 1141cdf0e10cSrcweir { 1142cdf0e10cSrcweir const SfxStringItem& rItem = (const SfxStringItem&)rReq.GetArgs()->Get(SID_TEXT); 1143cdf0e10cSrcweir if (GetText() != rItem.GetValue()) 1144cdf0e10cSrcweir SetText(rItem.GetValue()); 1145cdf0e10cSrcweir } 1146cdf0e10cSrcweir break; 1147cdf0e10cSrcweir 1148cdf0e10cSrcweir case SID_UNDO: 1149cdf0e10cSrcweir case SID_REDO: 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir ::svl::IUndoManager* pTmpUndoMgr = GetUndoManager(); 1152cdf0e10cSrcweir if( pTmpUndoMgr ) 1153cdf0e10cSrcweir { 1154cdf0e10cSrcweir sal_uInt16 nId = rReq.GetSlot(), nCnt = 1; 1155cdf0e10cSrcweir const SfxItemSet* pArgs = rReq.GetArgs(); 1156cdf0e10cSrcweir const SfxPoolItem* pItem; 1157cdf0e10cSrcweir if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, sal_False, &pItem )) 1158cdf0e10cSrcweir nCnt = ((SfxUInt16Item*)pItem)->GetValue(); 1159cdf0e10cSrcweir 1160cdf0e10cSrcweir sal_Bool (::svl::IUndoManager:: *fnDo)(); 1161cdf0e10cSrcweir 1162cdf0e10cSrcweir sal_uInt16 nCount; 1163cdf0e10cSrcweir if( SID_UNDO == rReq.GetSlot() ) 1164cdf0e10cSrcweir { 1165cdf0e10cSrcweir nCount = pTmpUndoMgr->GetUndoActionCount(); 1166cdf0e10cSrcweir fnDo = &::svl::IUndoManager::Undo; 1167cdf0e10cSrcweir } 1168cdf0e10cSrcweir else 1169cdf0e10cSrcweir { 1170cdf0e10cSrcweir nCount = pTmpUndoMgr->GetRedoActionCount(); 1171cdf0e10cSrcweir fnDo = &::svl::IUndoManager::Redo; 1172cdf0e10cSrcweir } 1173cdf0e10cSrcweir 1174cdf0e10cSrcweir try 1175cdf0e10cSrcweir { 1176cdf0e10cSrcweir for( ; nCnt && nCount; --nCnt, --nCount ) 1177cdf0e10cSrcweir (pTmpUndoMgr->*fnDo)(); 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir catch( const Exception& e ) 1180cdf0e10cSrcweir { 1181cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1182cdf0e10cSrcweir } 1183cdf0e10cSrcweir } 1184*64ead7c1SAriel Constenla-Haile 1185*64ead7c1SAriel Constenla-Haile SmModule *pModule = SM_MOD(); 1186*64ead7c1SAriel Constenla-Haile if ( pModule && pModule->GetConfig()->IsAutoRedraw() ) 1187*64ead7c1SAriel Constenla-Haile UpdateText(); 1188cdf0e10cSrcweir Repaint(); 1189cdf0e10cSrcweir SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this ); 1190cdf0e10cSrcweir while( pFrm ) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir SfxBindings& rBind = pFrm->GetBindings(); 1193cdf0e10cSrcweir rBind.Invalidate(SID_UNDO); 1194cdf0e10cSrcweir rBind.Invalidate(SID_REDO); 1195cdf0e10cSrcweir rBind.Invalidate(SID_REPEAT); 1196cdf0e10cSrcweir rBind.Invalidate(SID_CLEARHISTORY); 1197cdf0e10cSrcweir pFrm = SfxViewFrame::GetNext( *pFrm, this ); 1198cdf0e10cSrcweir } 1199cdf0e10cSrcweir } 1200cdf0e10cSrcweir break; 1201cdf0e10cSrcweir } 1202cdf0e10cSrcweir 1203cdf0e10cSrcweir rReq.Done(); 1204cdf0e10cSrcweir } 1205cdf0e10cSrcweir 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir void SmDocShell::GetState(SfxItemSet &rSet) 1208cdf0e10cSrcweir { 1209cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetState" ); 1210cdf0e10cSrcweir 1211cdf0e10cSrcweir SfxWhichIter aIter(rSet); 1212cdf0e10cSrcweir 1213cdf0e10cSrcweir for (sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich()) 1214cdf0e10cSrcweir { 1215cdf0e10cSrcweir switch (nWh) 1216cdf0e10cSrcweir { 1217cdf0e10cSrcweir case SID_TEXTMODE: 1218cdf0e10cSrcweir rSet.Put(SfxBoolItem(SID_TEXTMODE, GetFormat().IsTextmode())); 1219cdf0e10cSrcweir break; 1220cdf0e10cSrcweir 1221cdf0e10cSrcweir case SID_DOCTEMPLATE : 1222cdf0e10cSrcweir rSet.DisableItem(SID_DOCTEMPLATE); 1223cdf0e10cSrcweir break; 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir case SID_AUTO_REDRAW : 1226cdf0e10cSrcweir { 1227cdf0e10cSrcweir SmModule *pp = SM_MOD(); 1228cdf0e10cSrcweir sal_Bool bRedraw = pp->GetConfig()->IsAutoRedraw(); 1229cdf0e10cSrcweir 1230cdf0e10cSrcweir rSet.Put(SfxBoolItem(SID_AUTO_REDRAW, bRedraw)); 1231cdf0e10cSrcweir } 1232cdf0e10cSrcweir break; 1233cdf0e10cSrcweir 1234cdf0e10cSrcweir case SID_MODIFYSTATUS: 1235cdf0e10cSrcweir { 1236cdf0e10cSrcweir sal_Unicode cMod = ' '; 1237cdf0e10cSrcweir if (IsModified()) 1238cdf0e10cSrcweir cMod = '*'; 1239cdf0e10cSrcweir rSet.Put(SfxStringItem(SID_MODIFYSTATUS, String(cMod))); 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir break; 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir case SID_TEXT: 1244cdf0e10cSrcweir rSet.Put(SfxStringItem(SID_TEXT, GetText())); 1245cdf0e10cSrcweir break; 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir case SID_GAPHIC_SM: 1248cdf0e10cSrcweir //! very old (pre UNO) and ugly hack to invalidate the SmGraphicWindow. 1249cdf0e10cSrcweir //! If nModifyCount gets changed then the call below will implicitly notify 1250cdf0e10cSrcweir //! SmGraphicController::StateChanged and there the window gets invalidated. 1251cdf0e10cSrcweir //! Thus all the 'nModifyCount++' before invalidating this slot. 1252cdf0e10cSrcweir rSet.Put(SfxInt16Item(SID_GAPHIC_SM, nModifyCount)); 1253cdf0e10cSrcweir break; 1254cdf0e10cSrcweir 1255cdf0e10cSrcweir case SID_UNDO: 1256cdf0e10cSrcweir case SID_REDO: 1257cdf0e10cSrcweir { 1258cdf0e10cSrcweir SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this ); 1259cdf0e10cSrcweir if( pFrm ) 1260cdf0e10cSrcweir pFrm->GetSlotState( nWh, NULL, &rSet ); 1261cdf0e10cSrcweir else 1262cdf0e10cSrcweir rSet.DisableItem( nWh ); 1263cdf0e10cSrcweir } 1264cdf0e10cSrcweir break; 1265cdf0e10cSrcweir 1266cdf0e10cSrcweir case SID_GETUNDOSTRINGS: 1267cdf0e10cSrcweir case SID_GETREDOSTRINGS: 1268cdf0e10cSrcweir { 1269cdf0e10cSrcweir ::svl::IUndoManager* pTmpUndoMgr = GetUndoManager(); 1270cdf0e10cSrcweir if( pTmpUndoMgr ) 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir UniString(::svl::IUndoManager:: *fnGetComment)( size_t, bool const ) const; 1273cdf0e10cSrcweir 1274cdf0e10cSrcweir sal_uInt16 nCount; 1275cdf0e10cSrcweir if( SID_GETUNDOSTRINGS == nWh ) 1276cdf0e10cSrcweir { 1277cdf0e10cSrcweir nCount = pTmpUndoMgr->GetUndoActionCount(); 1278cdf0e10cSrcweir fnGetComment = &::svl::IUndoManager::GetUndoActionComment; 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir else 1281cdf0e10cSrcweir { 1282cdf0e10cSrcweir nCount = pTmpUndoMgr->GetRedoActionCount(); 1283cdf0e10cSrcweir fnGetComment = &::svl::IUndoManager::GetRedoActionComment; 1284cdf0e10cSrcweir } 1285cdf0e10cSrcweir if( nCount ) 1286cdf0e10cSrcweir { 1287cdf0e10cSrcweir String sList; 1288cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; ++n ) 1289cdf0e10cSrcweir ( sList += (pTmpUndoMgr->*fnGetComment)( n, ::svl::IUndoManager::TopLevel ) ) 1290cdf0e10cSrcweir += '\n'; 1291cdf0e10cSrcweir 1292cdf0e10cSrcweir SfxStringListItem aItem( nWh ); 1293cdf0e10cSrcweir aItem.SetString( sList ); 1294cdf0e10cSrcweir rSet.Put( aItem ); 1295cdf0e10cSrcweir } 1296cdf0e10cSrcweir } 1297cdf0e10cSrcweir else 1298cdf0e10cSrcweir rSet.DisableItem( nWh ); 1299cdf0e10cSrcweir } 1300cdf0e10cSrcweir break; 1301cdf0e10cSrcweir } 1302cdf0e10cSrcweir } 1303cdf0e10cSrcweir } 1304cdf0e10cSrcweir 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir ::svl::IUndoManager *SmDocShell::GetUndoManager() 1307cdf0e10cSrcweir { 1308cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetUndoManager" ); 1309cdf0e10cSrcweir 1310cdf0e10cSrcweir if (!pEditEngine) 1311cdf0e10cSrcweir GetEditEngine(); 1312cdf0e10cSrcweir return &pEditEngine->GetUndoManager(); 1313cdf0e10cSrcweir } 1314cdf0e10cSrcweir 1315cdf0e10cSrcweir 1316cdf0e10cSrcweir void SmDocShell::SaveSymbols() 1317cdf0e10cSrcweir { 1318cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveSymbols" ); 1319cdf0e10cSrcweir 1320cdf0e10cSrcweir SmModule *pp = SM_MOD(); 1321cdf0e10cSrcweir pp->GetSymbolManager().Save(); 1322cdf0e10cSrcweir } 1323cdf0e10cSrcweir 1324cdf0e10cSrcweir 1325cdf0e10cSrcweir void SmDocShell::Draw(OutputDevice *pDevice, 1326cdf0e10cSrcweir const JobSetup &, 1327cdf0e10cSrcweir sal_uInt16 /*nAspect*/) 1328cdf0e10cSrcweir { 1329cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Draw" ); 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir pDevice->IntersectClipRegion(GetVisArea()); 1332cdf0e10cSrcweir Point atmppoint; 1333cdf0e10cSrcweir Draw(*pDevice, atmppoint); 1334cdf0e10cSrcweir } 1335cdf0e10cSrcweir 1336cdf0e10cSrcweir SfxItemPool& SmDocShell::GetPool() const 1337cdf0e10cSrcweir { 1338cdf0e10cSrcweir return SFX_APP()->GetPool(); 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir void SmDocShell::SetVisArea(const Rectangle & rVisArea) 1342cdf0e10cSrcweir { 1343cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetVisArea" ); 1344cdf0e10cSrcweir 1345cdf0e10cSrcweir Rectangle aNewRect(rVisArea); 1346cdf0e10cSrcweir 1347cdf0e10cSrcweir aNewRect.SetPos(Point()); 1348cdf0e10cSrcweir 1349cdf0e10cSrcweir if (! aNewRect.Right()) aNewRect.Right() = 2000; 1350cdf0e10cSrcweir if (! aNewRect.Bottom()) aNewRect.Bottom() = 1000; 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir sal_Bool bIsEnabled = IsEnableSetModified(); 1353cdf0e10cSrcweir if ( bIsEnabled ) 1354cdf0e10cSrcweir EnableSetModified( sal_False ); 1355cdf0e10cSrcweir 1356cdf0e10cSrcweir //TODO/LATER: it's unclear how this interacts with the SFX code 1357cdf0e10cSrcweir // If outplace editing, then dont resize the OutplaceWindow. But the 1358cdf0e10cSrcweir // ObjectShell has to resize. Bug 56470 1359cdf0e10cSrcweir sal_Bool bUnLockFrame; 1360cdf0e10cSrcweir if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !IsInPlaceActive() && GetFrame() ) 1361cdf0e10cSrcweir { 1362cdf0e10cSrcweir GetFrame()->LockAdjustPosSizePixel(); 1363cdf0e10cSrcweir bUnLockFrame = sal_True; 1364cdf0e10cSrcweir } 1365cdf0e10cSrcweir else 1366cdf0e10cSrcweir bUnLockFrame = sal_False; 1367cdf0e10cSrcweir 1368cdf0e10cSrcweir SfxObjectShell::SetVisArea( aNewRect ); 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir if( bUnLockFrame ) 1371cdf0e10cSrcweir GetFrame()->UnlockAdjustPosSizePixel(); 1372cdf0e10cSrcweir 1373cdf0e10cSrcweir if ( bIsEnabled ) 1374cdf0e10cSrcweir EnableSetModified( bIsEnabled ); 1375cdf0e10cSrcweir } 1376cdf0e10cSrcweir 1377cdf0e10cSrcweir 1378cdf0e10cSrcweir void SmDocShell::FillClass(SvGlobalName* pClassName, 1379cdf0e10cSrcweir sal_uInt32* pFormat, 1380cdf0e10cSrcweir String* /*pAppName*/, 1381cdf0e10cSrcweir String* pFullTypeName, 1382cdf0e10cSrcweir String* pShortTypeName, 1383cdf0e10cSrcweir sal_Int32 nFileFormat, 1384cdf0e10cSrcweir sal_Bool bTemplate /* = sal_False */) const 1385cdf0e10cSrcweir { 1386cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::FillClass" ); 1387cdf0e10cSrcweir 1388cdf0e10cSrcweir if (nFileFormat == SOFFICE_FILEFORMAT_60 ) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir *pClassName = SvGlobalName(SO3_SM_CLASSID_60); 1391cdf0e10cSrcweir *pFormat = SOT_FORMATSTR_ID_STARMATH_60; 1392cdf0e10cSrcweir *pFullTypeName = String(SmResId(STR_MATH_DOCUMENT_FULLTYPE_CURRENT)); 1393cdf0e10cSrcweir *pShortTypeName = String(SmResId(RID_DOCUMENTSTR)); 1394cdf0e10cSrcweir } 1395cdf0e10cSrcweir else if (nFileFormat == SOFFICE_FILEFORMAT_8 ) 1396cdf0e10cSrcweir { 1397cdf0e10cSrcweir *pClassName = SvGlobalName(SO3_SM_CLASSID_60); 1398cdf0e10cSrcweir *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARMATH_8_TEMPLATE : SOT_FORMATSTR_ID_STARMATH_8; 1399cdf0e10cSrcweir *pFullTypeName = String(SmResId(STR_MATH_DOCUMENT_FULLTYPE_CURRENT)); 1400cdf0e10cSrcweir *pShortTypeName = String(SmResId(RID_DOCUMENTSTR)); 1401cdf0e10cSrcweir } 1402cdf0e10cSrcweir } 1403cdf0e10cSrcweir 1404cdf0e10cSrcweir sal_uLong SmDocShell::GetMiscStatus() const 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir return SfxObjectShell::GetMiscStatus() | SVOBJ_MISCSTATUS_NOTRESIZEABLE 1407cdf0e10cSrcweir | SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE; 1408cdf0e10cSrcweir } 1409cdf0e10cSrcweir 1410cdf0e10cSrcweir void SmDocShell::SetModified(sal_Bool bModified) 1411cdf0e10cSrcweir { 1412cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetModified" ); 1413cdf0e10cSrcweir 1414cdf0e10cSrcweir if( IsEnableSetModified() ) 1415cdf0e10cSrcweir { 1416cdf0e10cSrcweir SfxObjectShell::SetModified( bModified ); 1417cdf0e10cSrcweir Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED)); 1418cdf0e10cSrcweir } 1419cdf0e10cSrcweir } 1420cdf0e10cSrcweir 1421cdf0e10cSrcweir sal_Bool SmDocShell::WriteAsMathType3( SfxMedium& rMedium ) 1422cdf0e10cSrcweir { 1423cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::WriteAsMathType3" ); 1424cdf0e10cSrcweir 1425cdf0e10cSrcweir MathType aEquation( aText, pTree ); 1426cdf0e10cSrcweir 1427cdf0e10cSrcweir sal_Bool bRet = 0 != aEquation.ConvertFromStarMath( rMedium ); 1428cdf0e10cSrcweir return bRet; 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir 1431cdf0e10cSrcweir 1432