/Users/ericb/Desktop/SRC680_m247/starmath/source/document.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: document.cxx,v $
00006  *
00007  *  $Revision: 1.91 $
00008  *
00009  *  last change: $Author: vg $ $Date: 2007/07/20 06:15:24 $
00010  *
00011  *  The Contents of this file are made available subject to
00012  *  the terms of GNU Lesser General Public License Version 2.1.
00013  *
00014  *
00015  *    GNU Lesser General Public License Version 2.1
00016  *    =============================================
00017  *    Copyright 2005 by Sun Microsystems, Inc.
00018  *    901 San Antonio Road, Palo Alto, CA 94303, USA
00019  *
00020  *    This library is free software; you can redistribute it and/or
00021  *    modify it under the terms of the GNU Lesser General Public
00022  *    License version 2.1, as published by the Free Software Foundation.
00023  *
00024  *    This library is distributed in the hope that it will be useful,
00025  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  *    Lesser General Public License for more details.
00028  *
00029  *    You should have received a copy of the GNU Lesser General Public
00030  *    License along with this library; if not, write to the Free Software
00031  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00032  *    MA  02111-1307  USA
00033  *
00034  ************************************************************************/
00035 
00036 // MARKER(update_precomp.py): autogen include statement, do not remove
00037 #include "precompiled_starmath.hxx"
00038 
00039 
00040 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
00041 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
00042 #endif
00043 
00044 #ifndef _RTL_LOGFILE_HXX_
00045 #include <rtl/logfile.hxx>
00046 #endif
00047 #ifndef _RTL_USTRING_HXX_
00048 #include <rtl/ustring.hxx>
00049 #endif
00050 #ifndef _UCBHELPER_CONTENT_HXX
00051 #include <ucbhelper/content.hxx>
00052 #endif
00053 #ifndef _SOT_FORMATS_HXX
00054 #include <sot/formats.hxx>
00055 #endif
00056 #include <sot/storage.hxx>
00057 #ifndef _SVTOOLS_LINGUPROPS_HXX_
00058 #include <svtools/linguprops.hxx>
00059 #endif
00060 #ifndef _SVTOOLS_LINGUCFG_HXX_
00061 #include <svtools/lingucfg.hxx>
00062 #endif
00063 #ifndef _SFXSMPLHINT_HXX //autogen
00064 #include <svtools/smplhint.hxx>
00065 #endif
00066 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
00067 #include <svtools/pathoptions.hxx>
00068 #endif
00069 #ifndef _SO_CLSIDS_HXX //autogen
00070 #include <sot/clsids.hxx>
00071 #endif
00072 #ifndef _SOT_EXCHANGE_HXX //autogen
00073 #include <sot/exchange.hxx>
00074 #endif
00075 #ifndef _SV_MSGBOX_HXX //autogen
00076 #include <vcl/msgbox.hxx>
00077 #endif
00078 
00079 #include <vcl/mapunit.hxx>
00080 #include <vcl/mapmod.hxx>
00081 #include <comphelper/storagehelper.hxx>
00082 #include <comphelper/processfactory.hxx>
00083 
00084 #ifndef COMPHELPER_ACCESSIBLE_TEXT_HELPER_HXX
00085 #include <comphelper/accessibletexthelper.hxx>
00086 #endif
00087 
00088 #ifndef _SFXENUMITEM_HXX //autogen
00089 #include <svtools/eitem.hxx>
00090 #endif
00091 #ifndef _SFX_WHITER_HXX //autogen
00092 #include <svtools/whiter.hxx>
00093 #endif
00094 #ifndef _SFXINTITEM_HXX //autogen
00095 #include <svtools/intitem.hxx>
00096 #endif
00097 #ifndef _SFXSTRITEM_HXX //autogen
00098 #include <svtools/stritem.hxx>
00099 #endif
00100 #ifndef _SFXPTITEM_HXX //autogen
00101 #include <svtools/ptitem.hxx>
00102 #endif
00103 #ifndef _UNDO_HXX //autogen
00104 #include <svtools/undo.hxx>
00105 #endif
00106 #ifndef _SFXITEMPOOL_HXX //autogen
00107 #include <svtools/itempool.hxx>
00108 #endif
00109 #ifndef SVTOOLS_URIHELPER_HXX
00110 #include <svtools/urihelper.hxx>
00111 #endif
00112 #ifndef _SVTOOLS_FSTATHELPER_HXX
00113 #include <svtools/fstathelper.hxx>
00114 #endif
00115 #ifndef _TRANSFER_HXX
00116 #include <svtools/transfer.hxx>
00117 #endif
00118 
00119 #ifndef _SFXDISPATCH_HXX //autogen
00120 #include <sfx2/dispatch.hxx>
00121 #endif
00122 #ifndef _SFXDOCINF_HXX //autogen
00123 #include <sfx2/docinf.hxx>
00124 #endif
00125 #ifndef _SFXDOCFILE_HXX //autogen
00126 #include <sfx2/docfile.hxx>
00127 #endif
00128 #ifndef _SFXAPP_HXX //autogen
00129 #include <sfx2/app.hxx>
00130 #endif
00131 #ifndef _SFXREQUEST_HXX //autogen
00132 #include <sfx2/request.hxx>
00133 #endif
00134 #ifndef _SFXVIEWFRM_HXX
00135 #include <sfx2/viewfrm.hxx>
00136 #endif
00137 #ifndef _SFXECODE_HXX //autogen
00138 #include <svtools/sfxecode.hxx>
00139 #endif
00140 #ifndef _SFX_PRINTER_HXX //autogen
00141 #include <sfx2/printer.hxx>
00142 #endif
00143 #ifndef _SFX_DOCFILT_HACK_HXX
00144 #include <sfx2/docfilt.hxx>
00145 #endif
00146 #ifndef _SFXITEMPOOL_HXX
00147 #include <svtools/itempool.hxx>
00148 #endif
00149 #ifndef _MyEDITENG_HXX
00150 #include <svx/editeng.hxx>
00151 #endif
00152 #ifndef _EEITEM_HXX
00153 #include <svx/eeitem.hxx>
00154 #endif
00155 #ifndef _EDITSTAT_HXX
00156 #include <svx/editstat.hxx>
00157 #endif
00158 #ifndef _SVX_FONTITEM_HXX
00159 #include <svx/fontitem.hxx>
00160 #endif
00161 #ifndef _SVX_FHGTITEM_HXX
00162 #include <svx/fhgtitem.hxx>
00163 #endif
00164 #ifndef _UNO_LINGU_HXX
00165 #include <svx/unolingu.hxx>
00166 #endif
00167 #ifndef _SFXSLSTITM_HXX
00168 #include <svtools/slstitm.hxx>
00169 #endif
00170 
00171 #ifndef _COM_SUN_STAR_UNO_ANY_H_
00172 #include <com/sun/star/uno/Any.h>
00173 #endif
00174 #ifndef _COM_SUN_STAR_LANG_LOCALE_HPP_
00175 #include <com/sun/star/lang/Locale.hpp>
00176 #endif
00177 
00178 #ifndef STARMATH_HRC
00179 #include <starmath.hrc>
00180 #endif
00181 #ifndef DOCUMENT_HXX
00182 #include <document.hxx>
00183 #endif
00184 #ifndef UNOMODEL_HXX
00185 #include <unomodel.hxx>
00186 #endif
00187 #ifndef CONFIG_HXX
00188 #include <config.hxx>
00189 #endif
00190 #ifndef SYMBOL_HXX
00191 #include <symbol.hxx>
00192 #endif
00193 #ifndef TOOLBOX_HXX
00194 #include <toolbox.hxx>
00195 #endif
00196 #ifndef DIALOG_HXX
00197 #include <dialog.hxx>
00198 #endif
00199 #ifndef ACTION_HXX
00200 #include <action.hxx>
00201 #endif
00202 #ifndef VIEW_HXX
00203 #include <view.hxx>
00204 #endif
00205 #ifndef UTILITY_HXX
00206 #include <utility.hxx>
00207 #endif
00208 #ifndef FORMAT_HXX
00209 #include <format.hxx>
00210 #endif
00211 #ifndef MATHTYPE_HXX
00212 #include <mathtype.hxx>
00213 #endif
00214 #ifndef MATHML_HXX
00215 #include <mathml.hxx>
00216 #endif
00217 
00218 #include <smdll.hxx>
00219 
00220 #include <sfx2/fcontnr.hxx>
00221 #include <sfx2/msg.hxx>
00222 #include <sfx2/objface.hxx>
00223 
00224 using namespace ::com::sun::star;
00225 using namespace ::com::sun::star::lang;
00226 using namespace ::com::sun::star::ucb;
00227 using namespace ::com::sun::star::uno;
00228 using namespace ::com::sun::star::accessibility;
00229 
00230 #define A2OU(x)        rtl::OUString::createFromAscii( x )
00231 
00232 #define DOCUMENT_BUFFER_SIZE    (USHORT)32768
00233 
00234 static const char __FAR_DATA pStarMathDoc[] = "StarMathDocument";
00235 
00236 
00237 /**************************************************************************/
00238 /*
00239 **
00240 **      CLASS IMPLEMENTATION
00241 **
00242 **/
00243 
00244 #define SmDocShell
00245 #include "smslots.hxx"
00246 
00247 TYPEINIT1( SmDocShell, SfxObjectShell );
00248 
00249 SFX_IMPL_INTERFACE(SmDocShell, SfxObjectShell, SmResId(0))
00250 {
00251         SFX_POPUPMENU_REGISTRATION(SmResId(RID_VIEWMENU));
00252         SFX_POPUPMENU_REGISTRATION(SmResId(RID_COMMANDMENU));
00253 }
00254 
00255 SFX_IMPL_OBJECTFACTORY(SmDocShell, SvGlobalName(SO3_SM_CLASSID), SFXOBJECTSHELL_STD_NORMAL, "smath" )
00256 
00257 void SmDocShell::SFX_NOTIFY(SfxBroadcaster&, const TypeId&,
00258                                         const SfxHint& rHint, const TypeId&)
00259 {
00260         switch (((SfxSimpleHint&)rHint).GetId())
00261         {
00262                 case HINT_FORMATCHANGED:
00263                         SetFormulaArranged(FALSE);
00264             nModifyCount++;     
00265                                                                 // ohne dies wird die Grafik letztlich
00266                                                                 // nicht geupdatet
00267             Repaint();
00268                         break;
00269         }
00270 }
00271 
00272 void SmDocShell::LoadSymbols()
00273 {
00274     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::LoadSymbols" );
00275 
00276     SmModule *pp = SM_MOD1();
00277     pp->GetSymSetManager().Load();
00278 }
00279 
00280 
00281 const String &SmDocShell::GetComment() const
00282 {
00283     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetComment" );
00284     static String aString(((SmDocShell *) this)->GetDocInfo().GetComment());
00285         return aString;// ((SmDocShell *) this)->GetDocInfo().GetComment();
00286 }
00287 
00288 
00289 void SmDocShell::SetText(const String& rBuffer)
00290 {
00291     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetText" );
00292 
00293         if (rBuffer != aText)
00294         {
00295                 BOOL bIsEnabled = IsEnableSetModified();
00296                 if( bIsEnabled )
00297                         EnableSetModified( FALSE );
00298 
00299                 aText = rBuffer;
00300         SetFormulaArranged( FALSE );
00301 
00302         Parse();
00303         //Repaint();
00304 
00305         SmViewShell *pViewSh = SmGetActiveView();
00306                 if( pViewSh )
00307         {
00308                         pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_TEXT);
00309             if ( SFX_CREATE_MODE_EMBEDDED == GetCreateMode() )
00310                 Repaint();
00311             else
00312                 pViewSh->GetGraphicWindow().Invalidate();
00313         }
00314 
00315                 if ( bIsEnabled )
00316                         EnableSetModified( bIsEnabled );
00317                 SetModified(TRUE);
00318 
00319         // launch accessible event if necessary
00320         SmGraphicAccessible *pAcc = pViewSh ? pViewSh->GetGraphicWindow().GetAccessible_Impl() : 0;
00321         if (pAcc)
00322         {
00323                         Any aOldValue, aNewValue;
00324                         if ( comphelper::OCommonAccessibleText::implInitTextChangedEvent( aText, rBuffer, aOldValue, aNewValue ) )
00325                         {
00326                                 pAcc->LaunchEvent( AccessibleEventId::TEXT_CHANGED,
00327                                                 aOldValue, aNewValue );
00328                         }
00329         }
00330 
00331         if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
00332             OnDocumentPrinterChanged(0);
00333         }
00334 }
00335 
00336 void SmDocShell::SetFormat(SmFormat& rFormat)
00337 {
00338     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetFormat" );
00339 
00340         aFormat = rFormat;
00341         SetFormulaArranged(FALSE);
00342         SmViewShell *pViewSh = SmGetActiveView();
00343         if (pViewSh)
00344         pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_GAPHIC_SM);
00345         SetModified(TRUE);
00346 }
00347 
00348 String SmDocShell::GetAccessibleText()
00349 {
00350     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetAccessibleText" );
00351 
00352     if (!IsFormulaArranged())
00353         ArrangeFormula();
00354     if (0 == aAccText.Len())
00355     {
00356         DBG_ASSERT( pTree, "Tree missing" );
00357         if (pTree)
00358             pTree->GetAccessibleText( aAccText );
00359     }
00360     return aAccText;
00361 }
00362 
00363 void SmDocShell::Parse()
00364 {
00365     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Parse" );
00366 
00367         if (pTree)
00368                 delete pTree;
00369     ReplaceBadChars();
00370         pTree = aInterpreter.Parse(aText);
00371         nModifyCount++;
00372     SetFormulaArranged( FALSE );
00373 }
00374 
00375 
00376 void SmDocShell::ArrangeFormula()
00377 {
00378     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ArrangeFormula" );
00379 
00380         if (IsFormulaArranged())
00381                 return;
00382 
00385     SmPrinterAccess  aPrtAcc(*this);
00386 //      OutputDevice    *pOutDev = aPrtAcc.GetPrinter();
00387     OutputDevice* pOutDev = aPrtAcc.GetRefDev();
00388 
00389         if (!pOutDev)
00390     {
00391 #if OSL_DEBUG_LEVEL > 1
00392                 DBG_ERROR("!! SmDocShell::ArrangeFormula: reference device missing !!");
00393 #endif
00394     }
00395 
00396     // falls nötig ein anderes OutputDevice holen für das formatiert wird
00397         if (!pOutDev)
00398         {
00399                 SmViewShell *pView = SmGetActiveView();
00400                 if (pView)
00401                         pOutDev = &pView->GetGraphicWindow();
00402                 else
00403         {
00404                         pOutDev = &SM_MOD1()->GetDefaultVirtualDev();
00405                         pOutDev->SetMapMode( MapMode(MAP_100TH_MM) );
00406                 }
00407         }
00408         DBG_ASSERT(pOutDev->GetMapMode().GetMapUnit() == MAP_100TH_MM,
00409                            "Sm : falscher MapMode");
00410 
00411         const SmFormat &rFormat = GetFormat();
00412         pTree->Prepare(rFormat, *this);
00413 
00414     // format/draw formulas always from left to right,
00415     // and numbers should not be converted
00416     ULONG nLayoutMode = pOutDev->GetLayoutMode();
00417     pOutDev->SetLayoutMode( TEXT_LAYOUT_BIDI_LTR );
00418     INT16 nDigitLang = pOutDev->GetDigitLanguage();
00419     pOutDev->SetDigitLanguage( LANGUAGE_ENGLISH );
00420     //
00421     pTree->Arrange(*pOutDev, rFormat);
00422     //
00423     pOutDev->SetLayoutMode( nLayoutMode );
00424     pOutDev->SetDigitLanguage( nDigitLang );
00425 
00426         SetFormulaArranged(TRUE);
00427 
00428     // invalidate accessible text
00429     aAccText = String();
00430 }
00431 
00432 
00433 void SetEditEngineDefaultFonts(
00434         EditEngine &/*rEditEngine*/,
00435         SfxItemPool &rEditEngineItemPool )
00436 {
00437         //
00438         // set fonts to be used
00439         //
00440         SvtLinguOptions aOpt;
00441         SvtLinguConfig().GetOptions( aOpt );
00442         //
00443         struct FontDta {
00444             INT16       nFallbackLang;
00445             INT16       nLang;
00446             USHORT      nFontType;
00447             USHORT      nFontInfoId;
00448             } aTable[3] =
00449         {
00450             // info to get western font to be used
00451             {   LANGUAGE_ENGLISH_US,    LANGUAGE_NONE,
00452                 DEFAULTFONT_FIXED,      EE_CHAR_FONTINFO },
00453             // info to get CJK font to be used
00454             {   LANGUAGE_JAPANESE,      LANGUAGE_NONE,
00455                 DEFAULTFONT_CJK_TEXT,   EE_CHAR_FONTINFO_CJK },
00456             // info to get CTL font to be used
00457             {   LANGUAGE_ARABIC,        LANGUAGE_NONE,
00458                 DEFAULTFONT_CTL_TEXT,   EE_CHAR_FONTINFO_CTL }
00459         };
00460         aTable[0].nLang = aOpt.nDefaultLanguage;
00461         aTable[1].nLang = aOpt.nDefaultLanguage_CJK;
00462         aTable[2].nLang = aOpt.nDefaultLanguage_CTL;
00463         //
00464         for (int i = 0;  i < 3;  ++i)
00465         {
00466             const FontDta &rFntDta = aTable[i];
00467             LanguageType nLang = (LANGUAGE_NONE == rFntDta.nLang) ?
00468                     rFntDta.nFallbackLang : rFntDta.nLang;
00469             Font aFont = Application::GetDefaultDevice()->GetDefaultFont(
00470                         rFntDta.nFontType, nLang, DEFAULTFONT_FLAGS_ONLYONE );
00471 #ifdef DEBUG_TL
00472             ByteString aFntName( aFont.GetName(), 1 );
00473             int eFntFamily = aFont.GetFamily();
00474             ByteString aFntStyleName( aFont.GetStyleName(), 1 );
00475             int ePitch = aFont.GetPitch();
00476             int eCharSet = aFont.GetCharSet();
00477             fprintf(stderr, "\nFontName %s \n", aFntName.GetBuffer() );
00478             fprintf(stderr, "StyleName %s \n", aFntStyleName.GetBuffer() );
00479             fprintf(stderr, "eFntFamily %d \n", eFntFamily );
00480             fprintf(stderr, "ePitch %d \n", ePitch );
00481             fprintf(stderr, "eCharSet %d \n", eCharSet );
00482 #endif
00483             rEditEngineItemPool.SetPoolDefaultItem(
00484                     SvxFontItem( aFont.GetFamily(), aFont.GetName(),
00485                         aFont.GetStyleName(), aFont.GetPitch(), aFont.GetCharSet(),
00486                         rFntDta.nFontInfoId ) );
00487         }
00488 
00489         // set font heights
00490         SvxFontHeightItem aFontHeigt(
00491                         Application::GetDefaultDevice()->LogicToPixel(
00492                         Size( 0, 11 ), MapMode( MAP_POINT ) ).Height(), 100,
00493                         EE_CHAR_FONTHEIGHT );
00494         rEditEngineItemPool.SetPoolDefaultItem( aFontHeigt );
00495         aFontHeigt.SetWhich( EE_CHAR_FONTHEIGHT_CJK );
00496         rEditEngineItemPool.SetPoolDefaultItem( aFontHeigt );
00497         aFontHeigt.SetWhich( EE_CHAR_FONTHEIGHT_CTL );
00498         rEditEngineItemPool.SetPoolDefaultItem( aFontHeigt );
00499 }
00500 
00501 
00502 EditEngine& SmDocShell::GetEditEngine()
00503 {
00504     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetEditEngine" );
00505 
00506         if (!pEditEngine)
00507         {
00511 
00512                 pEditEngineItemPool = EditEngine::CreatePool();
00513 
00514         SetEditEngineDefaultFonts( *pEditEngine, *pEditEngineItemPool );
00515 
00516                 pEditEngine = new EditEngine( pEditEngineItemPool );
00517 
00518                 pEditEngine->EnableUndo( TRUE );
00519                 pEditEngine->SetDefTab( USHORT(
00520                         Application::GetDefaultDevice()->GetTextWidth( C2S("XXXX") ) ) );
00521 
00522                 pEditEngine->SetControlWord(
00523                                 (pEditEngine->GetControlWord() | EE_CNTRL_AUTOINDENTING) &
00524                                 (~EE_CNTRL_UNDOATTRIBS) &
00525                                 (~EE_CNTRL_PASTESPECIAL) );
00526 
00527                 pEditEngine->SetWordDelimiters( C2S(" .=+-*/(){}[];\"" ) );
00528                 pEditEngine->SetRefMapMode( MAP_PIXEL );
00529 
00530                 pEditEngine->SetPaperSize( Size( 800, 0 ) );
00531 
00532                 pEditEngine->EraseVirtualDevice();
00533 
00534         // set initial text if the document already has some...
00535         // (may be the case when reloading a doc)
00536         String aTxt( GetText() );
00537         if (aTxt.Len())
00538             pEditEngine->SetText( aTxt );
00539 
00540                 pEditEngine->ClearModifyFlag();
00541 
00542                 // forces new settings to be used if the itempool was modified
00543                 // after cthe creation of the EditEngine
00544                 //pEditEngine->Clear(); //#77957 incorrect font size
00545         }
00546         return *pEditEngine;
00547 }
00548 
00549 
00550 SfxItemPool& SmDocShell::GetEditEngineItemPool()
00551 {
00552     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetEditEngineItemPool" );
00553 
00554         if (!pEditEngineItemPool)
00555                 GetEditEngine();
00556         DBG_ASSERT( pEditEngineItemPool, "EditEngineItemPool missing" );
00557         return *pEditEngineItemPool;
00558 }
00559 
00560 
00561 void SmDocShell::Draw(OutputDevice &rDev, Point &rPosition)
00562 {
00563     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Draw" );
00564 
00565     if (!pTree)
00566                 Parse();
00567         DBG_ASSERT(pTree, "Sm : NULL pointer");
00568 
00569         if (!IsFormulaArranged())
00570                 ArrangeFormula();
00571 
00572         //Problem: Was passiert mit dem WYSIWYG? Wir haben waehrend wir inplace aktiv
00573         //sind kein Referenzdevice und sind auch nicht darauf ausgerichtet. Es kann
00574         //also jetzt eine Differenz zwischen der VisArea (spricht die Groesse im Client)
00575         //und der jetzt vorliegenden Groese geben.
00576         //Idee: Die Differenz koennte, zumindest behelfsmaessig, mit SmNod::SetSize
00577         //angepasst werden.
00578 
00579         rPosition.X() += aFormat.GetDistance( DIS_LEFTSPACE );
00580         rPosition.Y() += aFormat.GetDistance( DIS_TOPSPACE      );
00581 
00586     ULONG nOldDrawMode = DRAWMODE_DEFAULT;
00587     BOOL bRestoreDrawMode = FALSE;
00588     if (OUTDEV_WINDOW == rDev.GetOutDevType() &&
00589         ((Window &) rDev).GetDisplayBackground().GetColor().IsDark())
00590     {
00591         nOldDrawMode = rDev.GetDrawMode();
00592         rDev.SetDrawMode( DRAWMODE_DEFAULT );
00593         bRestoreDrawMode = TRUE;
00594     }
00595 
00596     // format/draw formulas always from left to right
00597     // and numbers should not be converted
00598     ULONG nLayoutMode = rDev.GetLayoutMode();
00599     rDev.SetLayoutMode( TEXT_LAYOUT_BIDI_LTR );
00600     INT16 nDigitLang = rDev.GetDigitLanguage();
00601     rDev.SetDigitLanguage( LANGUAGE_ENGLISH );
00602     //
00603     pTree->Draw(rDev, rPosition);
00604     //
00605     rDev.SetLayoutMode( nLayoutMode );
00606     rDev.SetDigitLanguage( nDigitLang );
00607 
00608     if (bRestoreDrawMode)
00609         rDev.SetDrawMode( nOldDrawMode );
00610 }
00611 
00612 
00613 
00614 Size SmDocShell::GetSize()
00615 {
00616     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetSize" );
00617 
00618         Size aRet;
00619 
00620         if (!pTree)
00621                 Parse();
00622 
00623         if (pTree)
00624         {
00625                 if (!IsFormulaArranged())
00626                         ArrangeFormula();
00627                 aRet = pTree->GetSize();
00628 
00629                 if ( !aRet.Width() )
00630                         aRet.Width() = 2000;
00631                 else
00632                         aRet.Width()  += aFormat.GetDistance( DIS_LEFTSPACE ) +
00633                                                          aFormat.GetDistance( DIS_RIGHTSPACE );
00634                 if ( !aRet.Height() )
00635                         aRet.Height() = 1000;
00636                 else
00637                         aRet.Height() += aFormat.GetDistance( DIS_TOPSPACE ) +
00638                                                          aFormat.GetDistance( DIS_BOTTOMSPACE );
00639         }
00640 
00641         return aRet;
00642 }
00643 
00645 
00646 SmPrinterAccess::SmPrinterAccess( SmDocShell &rDocShell )
00647 {
00648         if ( 0 != (pPrinter = rDocShell.GetPrt()) )
00649         {
00650                 pPrinter->Push( PUSH_MAPMODE );
00651         if ( SFX_CREATE_MODE_EMBEDDED == rDocShell.GetCreateMode() )
00652                 {
00653                         // if it is an embedded object (without it's own printer)
00654                         // we change the MapMode temporarily.
00659 
00660                         const MapUnit eOld = pPrinter->GetMapMode().GetMapUnit();
00661                         if ( MAP_100TH_MM != eOld )
00662                         {
00663                                 MapMode aMap( pPrinter->GetMapMode() );
00664                                 aMap.SetMapUnit( MAP_100TH_MM );
00665                                 Point aTmp( aMap.GetOrigin() );
00666                                 aTmp.X() = OutputDevice::LogicToLogic( aTmp.X(), eOld, MAP_100TH_MM );
00667                                 aTmp.Y() = OutputDevice::LogicToLogic( aTmp.Y(), eOld, MAP_100TH_MM );
00668                                 aMap.SetOrigin( aTmp );
00669                                 pPrinter->SetMapMode( aMap );
00670                         }
00671                 }
00672         }
00673     if ( 0 != (pRefDev = rDocShell.GetRefDev()) && pPrinter != pRefDev )
00674     {
00675         pRefDev->Push( PUSH_MAPMODE );
00676         if ( SFX_CREATE_MODE_EMBEDDED == rDocShell.GetCreateMode() )
00677         {
00678             // if it is an embedded object (without it's own printer)
00679             // we change the MapMode temporarily.
00684 
00685             const MapUnit eOld = pRefDev->GetMapMode().GetMapUnit();
00686             if ( MAP_100TH_MM != eOld )
00687             {
00688                 MapMode aMap( pRefDev->GetMapMode() );
00689                 aMap.SetMapUnit( MAP_100TH_MM );
00690                 Point aTmp( aMap.GetOrigin() );
00691                 aTmp.X() = OutputDevice::LogicToLogic( aTmp.X(), eOld, MAP_100TH_MM );
00692                 aTmp.Y() = OutputDevice::LogicToLogic( aTmp.Y(), eOld, MAP_100TH_MM );
00693                 aMap.SetOrigin( aTmp );
00694                 pRefDev->SetMapMode( aMap );
00695             }
00696         }
00697     }
00698 }
00699 
00700 SmPrinterAccess::~SmPrinterAccess()
00701 {
00702         if ( pPrinter )
00703                 pPrinter->Pop();
00704     if ( pRefDev && pRefDev != pPrinter )
00705         pRefDev->Pop();
00706 }
00707 
00709 
00710 Printer* SmDocShell::GetPrt()
00711 {
00712     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetPrt" );
00713 
00714     if ( SFX_CREATE_MODE_EMBEDDED == GetCreateMode() )
00715         {
00716                 //Normalerweise wird der Printer vom Server besorgt. Wenn dieser aber
00717                 //keinen liefert (weil etwa noch keine connection da ist), kann es
00718                 //dennoch sein, dass wir den Printer kennen, denn dieser wird in
00719                 //OnDocumentPrinterChanged vom Server durchgereicht und dann temporaer
00720                 //festgehalten.
00721         Printer *pPrt = GetDocumentPrinter();
00722         if ( !pPrt && pTmpPrinter )
00723             pPrt = pTmpPrinter;
00724         return pPrt;
00725         }
00726         else if ( !pPrinter )
00727         {
00728                 SfxItemSet *pOptions =
00729                         new SfxItemSet(GetPool(),
00730                                                    SID_PRINTSIZE,               SID_PRINTSIZE,
00731                                                    SID_PRINTZOOM,               SID_PRINTZOOM,
00732                                                    SID_PRINTTITLE,              SID_PRINTTITLE,
00733                                                    SID_PRINTTEXT,               SID_PRINTTEXT,
00734                                                    SID_PRINTFRAME,              SID_PRINTFRAME,
00735                                                    SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
00736                                                    0);
00737 
00738                 SmModule *pp = SM_MOD1();
00739                 pp->GetConfig()->ConfigToItemSet(*pOptions);
00740                 pPrinter = new SfxPrinter(pOptions);
00741                 pPrinter->SetMapMode( MapMode(MAP_100TH_MM) );
00742         }
00743         return pPrinter;
00744 }
00745 
00746 OutputDevice* SmDocShell::GetRefDev()
00747 {
00748     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetRefDev" );
00749 
00750     if ( SFX_CREATE_MODE_EMBEDDED == GetCreateMode() )
00751     {
00752         OutputDevice* pOutDev = GetDocumentRefDev();
00753         if ( pOutDev )
00754             return pOutDev;
00755     }
00756 
00757     return GetPrt();
00758 }
00759 
00760 
00761 void SmDocShell::SetPrinter( SfxPrinter *pNew )
00762 {
00763     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetPrinter" );
00764 
00765         delete pPrinter;
00766         pPrinter = pNew;        //Eigentumsuebergang!
00767         pPrinter->SetMapMode( MapMode(MAP_100TH_MM) );
00768         SetFormulaArranged(FALSE);
00769     Repaint();
00770 }
00771 
00772 void SmDocShell::OnDocumentPrinterChanged( Printer *pPrt )
00773 {
00774     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::OnDocumentPrinterChanged" );
00775 
00776     pTmpPrinter = pPrt;
00777         SetFormulaArranged(FALSE);
00778         Size aOldSize = GetVisArea().GetSize();
00779     Repaint();
00780         if( aOldSize != GetVisArea().GetSize() && aText.Len() )
00781                 SetModified( TRUE );
00782         pTmpPrinter = 0;
00783 }
00784 
00785 void SmDocShell::Repaint()
00786 {
00787     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Repaint" );
00788 
00789         BOOL bIsEnabled = IsEnableSetModified();
00790         if ( bIsEnabled )
00791                 EnableSetModified( FALSE );
00792 
00793     SetFormulaArranged( FALSE );
00794 
00795         Size aVisSize = GetSize();
00796         SetVisAreaSize( aVisSize );
00797         SmViewShell *pViewSh = SmGetActiveView();
00798         if (pViewSh)
00799         pViewSh->GetGraphicWindow().Invalidate();
00800 
00801         if ( bIsEnabled )
00802                 EnableSetModified( bIsEnabled );
00803 }
00804 
00805 
00806 SmDocShell::SmDocShell(SfxObjectCreateMode eMode) :
00807         SfxObjectShell(eMode),
00808         pTree                           ( 0 ),
00809     pEditEngineItemPool ( 0 ),
00810     pEditEngine         ( 0 ),
00811         pPrinter                        ( 0 ),
00812     pTmpPrinter         ( 0 ),
00813         nModifyCount            ( 0 ),
00814         bIsFormulaArranged      ( FALSE )
00815 {
00816     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SmDocShell" );
00817 
00818         SetPool(&SFX_APP()->GetPool());
00819 
00820         SmModule *pp = SM_MOD1();
00821     aFormat = pp->GetConfig()->GetStandardFormat();
00822 
00823         StartListening(aFormat);
00824         StartListening(*pp->GetConfig());
00825 
00826         SetModel( new SmModel(this) );  
00827 
00828 
00829 }
00830 
00831 
00832 
00833 SmDocShell::~SmDocShell()
00834 {
00835     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::~SmDocShell" );
00836 
00837         SmModule *pp = SM_MOD1();
00838 
00839         EndListening(aFormat);
00840         EndListening(*pp->GetConfig());
00841 
00842         delete pEditEngine;
00843         delete pEditEngineItemPool;
00844         delete pTree;
00845         delete pPrinter;
00846 }
00847 
00848 
00849 BOOL SmDocShell::SetData( const String& rData )
00850 {
00851     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetData" );
00852 
00853         SetText( rData );
00854         return TRUE;
00855 }
00856 
00857 
00858 BOOL SmDocShell::ConvertFrom(SfxMedium &rMedium)
00859 {
00860     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ConvertFrom" );
00861 
00862         BOOL     bSuccess = FALSE;
00863         const String& rFltName = rMedium.GetFilter()->GetFilterName();
00864 
00865     DBG_ASSERT( !rFltName.EqualsAscii( STAROFFICE_XML ), "Wrong filter!");
00866 
00867     if ( rFltName.EqualsAscii( MATHML_XML ) )
00868         {
00869                 if (pTree)
00870                 {
00871                         delete pTree;
00872                         pTree = 0;
00873                 }
00874         Reference<com::sun::star::frame::XModel> xModel(GetModel());
00875                 SmXMLWrapper aEquation(xModel);
00876         bSuccess = 0 == aEquation.Import(rMedium);
00877         }
00878         else
00879         {
00880                 SvStream *pStream = rMedium.GetInStream();
00881         if ( pStream )
00882                 {
00883             if ( SotStorage::IsStorageFile( pStream ) )
00884             {
00885                 SvStorageRef aStorage = new SotStorage( pStream, FALSE );
00886                 if ( aStorage->IsStream( C2S( "Equation Native" ) ) )
00887                 {
00888                     // is this a MathType Storage?
00889                     MathType aEquation( aText );
00890                     if ( TRUE == (bSuccess = (1 == aEquation.Parse( aStorage )) ))
00891                         Parse();
00892                 }
00893             }
00894             else
00895             {
00896                 //bSuccess = ImportSM20File( pStream );
00897             }
00898                 }
00899         }
00900 
00901     if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
00902     {
00903         //???OnDocumentPrinterChanged(0);
00904         SetFormulaArranged( FALSE );
00905         Repaint();
00906     }
00907 
00908         FinishedLoading( SFX_LOADED_ALL );
00909         return bSuccess;
00910 }
00911 
00912 
00913 BOOL SmDocShell::InitNew( const uno::Reference < embed::XStorage >& xStorage )
00914 {
00915     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::InitNew" );
00916 
00917         BOOL bRet = FALSE;
00918     if ( SfxObjectShell::InitNew( xStorage ) )
00919         {
00920                 bRet = TRUE;
00921                 SetVisArea(Rectangle(Point(0, 0), Size(2000, 1000)));
00922         }
00923         return bRet;
00924 }
00925 
00926 
00927 BOOL SmDocShell::Load( SfxMedium& rMedium )
00928 {
00929     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Load" );
00930 
00931         BOOL bRet = FALSE;
00932     if( SfxObjectShell::Load( rMedium ))
00933         {
00934         uno::Reference < embed::XStorage > xStorage = pMedium->GetStorage();
00935         uno::Reference < container::XNameAccess > xAccess (xStorage, uno::UNO_QUERY);
00936         if ( xAccess->hasByName( C2S( "content.xml" ) ) && xStorage->isStreamElement( C2S( "content.xml" ) ) ||
00937              xAccess->hasByName( C2S( "Content.xml" ) ) && xStorage->isStreamElement( C2S( "Content.xml" ) ) )
00938         {
00939             // is this a fabulous math package ?
00940             Reference<com::sun::star::frame::XModel> xModel(GetModel());
00941             SmXMLWrapper aEquation(xModel);
00942             ULONG nError = aEquation.Import(rMedium);
00943             bRet = 0 == nError;
00944             SetError( nError );
00945         }
00946         }
00947 
00948     if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
00949     {
00950         //???OnDocumentPrinterChanged(0);
00951                 SetFormulaArranged( FALSE );
00952         Repaint();
00953     }
00954 
00955         FinishedLoading( SFX_LOADED_ALL );
00956         return bRet;
00957 }
00958 
00959 //------------------------------------------------------------------
00960 
00961 BOOL SmDocShell::Save()
00962 {
00963     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Save" );
00964 
00966     UpdateText();
00967 
00968     if ( SfxObjectShell::Save() )
00969         {
00970                 if (!pTree)
00971                         Parse();
00972                 if( pTree && !IsFormulaArranged() )
00973                         ArrangeFormula();
00974 
00975         Reference<com::sun::star::frame::XModel> xModel(GetModel());
00976         SmXMLWrapper aEquation(xModel);
00977         aEquation.SetFlat(sal_False);
00978         return aEquation.Export(*GetMedium());
00979         }
00980 
00981         return FALSE;
00982 }
00983 
00984 /*
00985  * replace bad characters that can not be saved. (#i74144)
00986  * */
00987 sal_Bool SmDocShell::ReplaceBadChars()
00988 {
00989         sal_Bool bReplace = sal_False;
00990         if (pEditEngine)
00991         {
00992                 String aEngTxt( pEditEngine->GetText( LINEEND_LF ) );
00993                 const sal_Unicode *pEngTxt = aEngTxt.GetBuffer();
00994                 xub_StrLen nLen = aEngTxt.Len();
00995                 for (xub_StrLen i = 0;  i < nLen && !bReplace;  ++i)
00996                 {
00997                         const sal_Unicode c = *pEngTxt++;
00998                         if (c < ' ' && c != '\r' && c != '\n' && c != '\t')
00999                                 bReplace = sal_True;
01000                 }
01001                 if (bReplace)
01002                 {
01003                         sal_Unicode *pChgTxt = aEngTxt.GetBufferAccess();
01004                         for (xub_StrLen i = 0;  i < nLen;  ++i)
01005                         {
01006                                 sal_Unicode &rc = *pChgTxt++;
01007                                 if (rc < ' ' && rc != '\r' && rc != '\n' && rc != '\t')
01008                                         rc = ' ';
01009                         }
01010                         aEngTxt.ReleaseBufferAccess( nLen );
01011 
01012                         aText = aEngTxt;
01013                 }
01014         }
01015         return bReplace;
01016 }
01017 
01018 
01019 void SmDocShell::UpdateText()
01020 {
01021     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::UpdateText" );
01022 
01023     if (pEditEngine && pEditEngine->IsModified())
01024     {
01025         String aEngTxt( pEditEngine->GetText( LINEEND_LF ) );
01026         if (GetText() != aEngTxt)
01027             SetText( aEngTxt );
01028     }
01029 }
01030 
01031 
01032 BOOL SmDocShell::SaveAs( SfxMedium& rMedium )
01033 {
01034     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveAs" );
01035 
01036         BOOL bRet = FALSE;
01037 
01039     UpdateText();
01040 
01041         if ( SfxObjectShell::SaveAs( rMedium ) )
01042         {
01043                 if (!pTree)
01044                         Parse();
01045                 if( pTree && !IsFormulaArranged() )
01046                         ArrangeFormula();
01047 
01048         Reference<com::sun::star::frame::XModel> xModel(GetModel());
01049         SmXMLWrapper aEquation(xModel);
01050         aEquation.SetFlat(sal_False);
01051         bRet = aEquation.Export(rMedium);
01052         }
01053         return bRet;
01054 }
01055 
01056 BOOL SmDocShell::ConvertTo( SfxMedium &rMedium )
01057 {
01058     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::ConvertTo" );
01059 
01060         BOOL bRet = FALSE;
01061         const SfxFilter* pFlt = rMedium.GetFilter();
01062         if( pFlt )
01063         {
01064                 if( !pTree )
01065                         Parse();
01066                 if( pTree && !IsFormulaArranged() )
01067                         ArrangeFormula();
01068 
01069                 const String& rFltName = pFlt->GetFilterName();
01070                 if(rFltName.EqualsAscii( STAROFFICE_XML ))
01071                 {
01072             Reference<com::sun::star::frame::XModel> xModel(GetModel());
01073                         SmXMLWrapper aEquation(xModel);
01074                         aEquation.SetFlat(sal_False);
01075                         bRet = aEquation.Export(rMedium);
01076                 }
01077                 else if(rFltName.EqualsAscii( MATHML_XML ))
01078                 {
01079             Reference<com::sun::star::frame::XModel> xModel(GetModel());
01080                         SmXMLWrapper aEquation(xModel);
01081                         aEquation.SetFlat(sal_True);
01082                         bRet = aEquation.Export(rMedium);
01083                 }
01084         else if( pFlt->GetFilterName().EqualsAscii("MathType 3.x"))
01085             bRet = WriteAsMathType3( rMedium );
01086         }
01087         return bRet;
01088 }
01089 
01090 BOOL SmDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
01091 {
01092     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveCompleted" );
01093 
01094     if( SfxObjectShell::SaveCompleted( xStorage ))
01095                 return TRUE;
01096 
01097         return FALSE;
01098 }
01099 
01100 
01101 void SmDocShell::Execute(SfxRequest& rReq)
01102 {
01103     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Execute" );
01104 
01105         switch (rReq.GetSlot())
01106         {
01107                 case SID_TEXTMODE:
01108                 {
01109             SmFormat aOldFormat  = GetFormat();
01110             SmFormat aNewFormat( aOldFormat );
01111             aNewFormat.SetTextmode(!aOldFormat.IsTextmode());
01112 
01113             SfxUndoManager *pTmpUndoMgr = GetUndoManager();
01114             if (pTmpUndoMgr)
01115                 pTmpUndoMgr->AddUndoAction(
01116                     new SmFormatAction(this, aOldFormat, aNewFormat));
01117 
01118             SetFormat( aNewFormat );
01119             Repaint();
01120                 }
01121                 break;
01122 
01123                 case SID_AUTO_REDRAW :
01124                 {
01125                         SmModule *pp = SM_MOD1();
01126                         BOOL bRedraw = pp->GetConfig()->IsAutoRedraw();
01127                         pp->GetConfig()->SetAutoRedraw(!bRedraw);
01128                 }
01129                 break;
01130 
01131                 case SID_LOADSYMBOLS:
01132             LoadSymbols();
01133                 break;
01134 
01135                 case SID_SAVESYMBOLS:
01136             SaveSymbols();
01137                 break;
01138 
01139                 case SID_FONT:
01140                 {
01141             // get device used to retrieve the FontList
01142             OutputDevice *pDev = GetPrinter();
01143             if (!pDev || pDev->GetDevFontCount() == 0)
01144                 pDev = &SM_MOD1()->GetDefaultVirtualDev();
01145             DBG_ASSERT (pDev, "device for font list missing" );
01146 
01147             SmFontTypeDialog *pFontTypeDialog = new SmFontTypeDialog( NULL, pDev );
01148 
01149             SmFormat aOldFormat  = GetFormat();
01150             pFontTypeDialog->ReadFrom( aOldFormat );
01151                         if (pFontTypeDialog->Execute() == RET_OK)
01152                         {
01153                 SmFormat aNewFormat( aOldFormat );
01154 
01155                                 pFontTypeDialog->WriteTo(aNewFormat);
01156                 SfxUndoManager *pTmpUndoMgr = GetUndoManager();
01157                 if (pTmpUndoMgr)
01158                     pTmpUndoMgr->AddUndoAction(
01159                                                 new SmFormatAction(this, aOldFormat, aNewFormat));
01160 
01161                                 SetFormat( aNewFormat );
01162                 Repaint();
01163                         }
01164                         delete pFontTypeDialog;
01165                 }
01166                 break;
01167 
01168                 case SID_FONTSIZE:
01169                 {
01170                         SmFontSizeDialog *pFontSizeDialog = new SmFontSizeDialog(NULL);
01171 
01172             SmFormat aOldFormat  = GetFormat();
01173             pFontSizeDialog->ReadFrom( aOldFormat );
01174                         if (pFontSizeDialog->Execute() == RET_OK)
01175                         {
01176                 SmFormat aNewFormat( aOldFormat );
01177 
01178                                 pFontSizeDialog->WriteTo(aNewFormat);
01179 
01180                 SfxUndoManager *pTmpUndoMgr = GetUndoManager();
01181                 if (pTmpUndoMgr)
01182                     pTmpUndoMgr->AddUndoAction(
01183                                                 new SmFormatAction(this, aOldFormat, aNewFormat));
01184 
01185                                 SetFormat( aNewFormat );
01186                 Repaint();
01187                         }
01188                         delete pFontSizeDialog;
01189                 }
01190                 break;
01191 
01192                 case SID_DISTANCE:
01193                 {
01194                         SmDistanceDialog *pDistanceDialog = new SmDistanceDialog(NULL);
01195 
01196             SmFormat aOldFormat  = GetFormat();
01197             pDistanceDialog->ReadFrom( aOldFormat );
01198                         if (pDistanceDialog->Execute() == RET_OK)
01199                         {
01200                 SmFormat aNewFormat( aOldFormat );
01201 
01202                                 pDistanceDialog->WriteTo(aNewFormat);
01203 
01204                 SfxUndoManager *pTmpUndoMgr = GetUndoManager();
01205                 if (pTmpUndoMgr)
01206                     pTmpUndoMgr->AddUndoAction(
01207                                                 new SmFormatAction(this, aOldFormat, aNewFormat));
01208 
01209                                 SetFormat( aNewFormat );
01210                 Repaint();
01211                         }
01212                         delete pDistanceDialog;
01213                 }
01214                 break;
01215 
01216                 case SID_ALIGN:
01217                 {
01218                         SmAlignDialog *pAlignDialog = new SmAlignDialog(NULL);
01219 
01220             SmFormat aOldFormat  = GetFormat();
01221             pAlignDialog->ReadFrom( aOldFormat );
01222                         if (pAlignDialog->Execute() == RET_OK)
01223                         {
01224                 SmFormat aNewFormat( aOldFormat );
01225 
01226                                 pAlignDialog->WriteTo(aNewFormat);
01227 
01228                 SmModule *pp = SM_MOD1();
01229                 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
01230                 pAlignDialog->WriteTo( aFmt );
01231                 pp->GetConfig()->SetStandardFormat( aFmt );
01232 
01233                 SfxUndoManager *pTmpUndoMgr = GetUndoManager();
01234                 if (pTmpUndoMgr)
01235                     pTmpUndoMgr->AddUndoAction(
01236                         new SmFormatAction(this, aOldFormat, aNewFormat));
01237 
01238                                 SetFormat( aNewFormat );
01239                 Repaint();
01240                         }
01241                         delete pAlignDialog;
01242                 }
01243                 break;
01244 
01245                 case SID_TEXT:
01246                 {
01247                         const SfxStringItem& rItem =
01248                                 (const SfxStringItem&)rReq.GetArgs()->Get(SID_TEXT);
01249 
01250                         if (GetText() != rItem.GetValue())
01251                         {
01252                                 SetText(rItem.GetValue());
01253                         }
01254                 }
01255                 break;
01256 
01257                 case SID_UNDO:
01258                 case SID_REDO:
01259                 {
01260             SfxUndoManager* pTmpUndoMgr = GetUndoManager();
01261             if( pTmpUndoMgr )
01262                         {
01263                                 USHORT nId = rReq.GetSlot(), nCnt = 1;
01264                                 const SfxItemSet* pArgs = rReq.GetArgs();
01265                                 const SfxPoolItem* pItem;
01266                                 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, FALSE, &pItem ))
01267                                         nCnt = ((SfxUInt16Item*)pItem)->GetValue();
01268 
01269                                 BOOL (SfxUndoManager:: *fnDo)( USHORT );
01270 
01271                                 sal_uInt16 nCount;
01272                                 if( SID_UNDO == rReq.GetSlot() )
01273                                 {
01274                     nCount = pTmpUndoMgr->GetUndoActionCount();
01275                                         fnDo = &SfxUndoManager::Undo;
01276                                 }
01277                                 else
01278                                 {
01279                     nCount = pTmpUndoMgr->GetRedoActionCount();
01280                                         fnDo = &SfxUndoManager::Redo;
01281                                 }
01282 
01283                                 for( ; nCnt && nCount; --nCnt, --nCount )
01284                     (pTmpUndoMgr->*fnDo)( 0 );
01285                         }
01286             Repaint();
01287                 }
01288                 break;
01289         }
01290 }
01291 
01292 
01293 void SmDocShell::GetState(SfxItemSet &rSet)
01294 {
01295     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetState" );
01296 
01297         SfxWhichIter aIter(rSet);
01298 
01299         for (USHORT nWh = aIter.FirstWhich();  0 != nWh;  nWh = aIter.NextWhich())
01300         {
01301                 switch (nWh)
01302                 {
01303                 case SID_TEXTMODE:
01304                         rSet.Put(SfxBoolItem(SID_TEXTMODE, GetFormat().IsTextmode()));
01305                         break;
01306 
01307                 case SID_DOCTEMPLATE :
01308                         rSet.DisableItem(SID_DOCTEMPLATE);
01309                         break;
01310 
01311                 case SID_AUTO_REDRAW :
01312                         {
01313                                 SmModule  *pp = SM_MOD1();
01314                                 BOOL       bRedraw = pp->GetConfig()->IsAutoRedraw();
01315 
01316                                 rSet.Put(SfxBoolItem(SID_AUTO_REDRAW, bRedraw));
01317                         }
01318                         break;
01319 
01320                 case SID_MODIFYSTATUS:
01321                         {
01322                                 sal_Unicode cMod = ' ';
01323                                 if (IsModified())
01324                                         cMod = '*';
01325                                 rSet.Put(SfxStringItem(SID_MODIFYSTATUS, String(cMod)));
01326                         }
01327                         break;
01328 
01329                 case SID_TEXT:
01330                         rSet.Put(SfxStringItem(SID_TEXT, GetText()));
01331                         break;
01332 
01333         case SID_GAPHIC_SM:
01334             rSet.Put(SfxInt16Item(SID_GAPHIC_SM, nModifyCount));
01335                         break;
01336 
01337                 case SID_UNDO:
01338                 case SID_REDO:
01339                         {
01340                                 SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
01341                                 if( pFrm )
01342                                         pFrm->GetSlotState( nWh, NULL, &rSet );
01343                                 else
01344                                         rSet.DisableItem( nWh );
01345                         }
01346                         break;
01347 
01348                 case SID_GETUNDOSTRINGS:
01349                 case SID_GETREDOSTRINGS:
01350                         {
01351                 SfxUndoManager* pTmpUndoMgr = GetUndoManager();
01352                 if( pTmpUndoMgr )
01353                                 {
01354                                         UniString(SfxUndoManager:: *fnGetComment)( USHORT ) const;
01355 
01356                                         sal_uInt16 nCount;
01357                                         if( SID_GETUNDOSTRINGS == nWh )
01358                                         {
01359                         nCount = pTmpUndoMgr->GetUndoActionCount();
01360                                                 fnGetComment = &SfxUndoManager::GetUndoActionComment;
01361                                         }
01362                                         else
01363                                         {
01364                         nCount = pTmpUndoMgr->GetRedoActionCount();
01365                                                 fnGetComment = &SfxUndoManager::GetRedoActionComment;
01366                                         }
01367                                         if( nCount )
01368                                         {
01369                                                 String sList;
01370                                                 for( sal_uInt16 n = 0; n < nCount; ++n )
01371                             ( sList += (pTmpUndoMgr->*fnGetComment)( n ) )
01372                                                                         += '\n';
01373 
01374                                                 SfxStringListItem aItem( nWh );
01375                                                 aItem.SetString( sList );
01376                                                 rSet.Put( aItem );
01377                                         }
01378                                 }
01379                                 else
01380                                         rSet.DisableItem( nWh );
01381                         }
01382                         break;
01383                 }
01384         }
01385 }
01386 
01387 
01388 SfxUndoManager *SmDocShell::GetUndoManager()
01389 {
01390     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::GetUndoManager" );
01391 
01392         if (!pEditEngine)
01393                 GetEditEngine();
01394         return &pEditEngine->GetUndoManager();
01395 }
01396 
01397 
01398 void SmDocShell::SaveSymbols()
01399 {
01400     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveSymbols" );
01401 
01402     SmModule *pp = SM_MOD1();
01403     pp->GetSymSetManager().Save();
01404 }
01405 
01406 
01407 void SmDocShell::Draw(OutputDevice *pDevice,
01408                                           const JobSetup &,
01409                       USHORT /*nAspect*/)
01410 {
01411     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::Draw" );
01412 
01413         pDevice->IntersectClipRegion(GetVisArea());
01414         Point atmppoint;
01415         Draw(*pDevice, atmppoint);
01416 }
01417 
01418 SfxItemPool& SmDocShell::GetPool() const
01419 {
01420         return SFX_APP()->GetPool();
01421 }
01422 
01423 void SmDocShell::SetVisArea(const Rectangle & rVisArea)
01424 {
01425     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetVisArea" );
01426 
01427         Rectangle aNewRect(rVisArea);
01428 
01429         aNewRect.SetPos(Point());
01430 
01431         if (! aNewRect.Right()) aNewRect.Right() = 2000;
01432         if (! aNewRect.Bottom()) aNewRect.Bottom() = 1000;
01433 
01434         BOOL bIsEnabled = IsEnableSetModified();
01435         if ( bIsEnabled )
01436                 EnableSetModified( FALSE );
01437 
01438     //TODO/LATER: it's unclear how this interacts with the SFX code
01439     // If outplace editing, then dont resize the OutplaceWindow. But the
01440         // ObjectShell has to resize. Bug 56470
01441         BOOL bUnLockFrame;
01442     if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !IsInPlaceActive() && GetFrame() )
01443         {
01444                 GetFrame()->LockAdjustPosSizePixel();
01445                 bUnLockFrame = TRUE;
01446         }
01447         else
01448                 bUnLockFrame = FALSE;
01449 
01450     SfxObjectShell::SetVisArea( aNewRect );
01451 
01452         if( bUnLockFrame )
01453                 GetFrame()->UnlockAdjustPosSizePixel();
01454 
01455         if ( bIsEnabled )
01456                 EnableSetModified( bIsEnabled );
01457 }
01458 
01459 
01460 void SmDocShell::FillClass(SvGlobalName* pClassName,
01461                                                    sal_uInt32*  pFormat,
01462                            String* /*pAppName*/,
01463                                                    String* pFullTypeName,
01464                            String* pShortTypeName,
01465                                                    sal_Int32 nFileFormat ) const
01466 {
01467     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::FillClass" );
01468 
01469         if (nFileFormat == SOFFICE_FILEFORMAT_60 )
01470         {
01471                 *pClassName     = SvGlobalName(SO3_SM_CLASSID_60);
01472                 *pFormat                = SOT_FORMATSTR_ID_STARMATH_60;
01473         *pFullTypeName  = String(SmResId(STR_MATH_DOCUMENT_FULLTYPE_CURRENT));
01474                 *pShortTypeName = String(SmResId(RID_DOCUMENTSTR));
01475         }
01476         else if (nFileFormat == SOFFICE_FILEFORMAT_8 )
01477         {
01478                 *pClassName     = SvGlobalName(SO3_SM_CLASSID_60);
01479                 *pFormat                = SOT_FORMATSTR_ID_STARMATH_8;
01480         *pFullTypeName  = String(SmResId(STR_MATH_DOCUMENT_FULLTYPE_CURRENT));
01481                 *pShortTypeName = String(SmResId(RID_DOCUMENTSTR));
01482         }
01483 }
01484 
01485 ULONG SmDocShell::GetMiscStatus() const
01486 {
01487     return SfxObjectShell::GetMiscStatus() | SVOBJ_MISCSTATUS_NOTRESIZEABLE
01488                                                                                          | SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE;
01489 }
01490 
01491 void SmDocShell::SetModified(BOOL bModified)
01492 {
01493     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SetModified" );
01494 
01495         if( IsEnableSetModified() )
01496         {
01497                 SfxObjectShell::SetModified( bModified );
01498                 Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED));
01499         }
01500 }
01501 
01502 BOOL SmDocShell::WriteAsMathType3( SfxMedium& rMedium )
01503 {
01504     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::WriteAsMathType3" );
01505 
01506     MathType aEquation( aText, pTree );
01507 
01508     BOOL bRet = 0 != aEquation.ConvertFromStarMath( rMedium );
01509     return bRet;
01510 }
01511 
01512 

Generated on Wed Feb 20 17:21:56 2008 for maths by  doxygen 1.5.1