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

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: view.cxx,v $
00006  *
00007  *  $Revision: 1.51 $
00008  *
00009  *  last change: $Author: rt $ $Date: 2007/11/09 10:53:10 $
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_XACCESSIBLE_HPP_
00041 #include <com/sun/star/accessibility/XAccessible.hpp>
00042 #endif
00043 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTOBJECT_HPP_
00044 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
00045 #endif
00046 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
00047 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
00048 #endif
00049 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
00050 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
00051 #endif
00052 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
00053 #include <com/sun/star/beans/XPropertySet.hpp>
00054 #endif
00055 
00056 #ifndef _RTL_LOGFILE_HXX_
00057 #include <rtl/logfile.hxx>
00058 #endif
00059 
00060 #ifndef _SV_MENU_HXX //autogen
00061 #include <vcl/menu.hxx>
00062 #endif
00063 #ifndef _SV_DECOVIEW_HXX //autogen
00064 #include <vcl/decoview.hxx>
00065 #endif
00066 #ifndef _SV_MSGBOX_HXX //autogen
00067 #include <vcl/msgbox.hxx>
00068 #endif
00069 
00070 #ifndef _SFX_WHITER_HXX //autogen
00071 #include <svtools/whiter.hxx>
00072 #endif
00073 #ifndef _UNDO_HXX //autogen
00074 #include <svtools/undo.hxx>
00075 #endif
00076 #ifndef _SFXINTITEM_HXX //autogen
00077 #include <svtools/intitem.hxx>
00078 #endif
00079 #ifndef _SFXPTITEM_HXX //autogen
00080 #include <svtools/ptitem.hxx>
00081 #endif
00082 #ifndef _SFXSTRITEM_HXX //autogen
00083 #include <svtools/stritem.hxx>
00084 #endif
00085 #ifndef _SFXENUMITEM_HXX //autogen
00086 #include <svtools/eitem.hxx>
00087 #endif
00088 #ifndef _SFXITEMSET_HXX //autogen
00089 #include <svtools/itemset.hxx>
00090 #endif
00091 #ifndef _SFXPOOLITEM_HXX //autogen
00092 #include <svtools/poolitem.hxx>
00093 #endif
00094 
00095 #ifndef _SFXMSG_HXX //autogen
00096 #include <sfx2/msg.hxx>
00097 #endif
00098 #ifndef _SFXDISPATCH_HXX //autogen
00099 #include <sfx2/dispatch.hxx>
00100 #endif
00101 #ifndef _SFXAPP_HXX //autogen
00102 #include <sfx2/app.hxx>
00103 #endif
00104 #ifndef _SFX_PRINTER_HXX //autogen
00105 #include <sfx2/printer.hxx>
00106 #endif
00107 #ifndef _SFXREQUEST_HXX //autogen
00108 #include <sfx2/request.hxx>
00109 #endif
00110 #ifndef _SFXDOCFILE_HXX //autogen
00111 #include <sfx2/docfile.hxx>
00112 #endif
00113 #ifndef _SFX_DOCFILT_HACK_HXX
00114 #include <sfx2/docfilt.hxx>
00115 #endif
00116 #ifndef _SFX_DOCINSERT_HXX
00117 #include <sfx2/docinsert.hxx>
00118 #endif
00119 #ifndef _FILEDLGHELPER_HXX
00120 #include <sfx2/filedlghelper.hxx>
00121 #endif
00122 
00123 #ifndef _SVX_ZOOMITEM_HXX //autogen
00124 #include <svx/zoomitem.hxx>
00125 #endif
00126 
00127 #ifndef _MyEDITENG_HXX
00128 #include <svx/editeng.hxx>
00129 #endif
00130 #ifndef _SV_WRKWIN_HXX //autogen
00131 #include <vcl/wrkwin.hxx>
00132 #endif
00133 #ifndef _TRANSFER_HXX
00134 #include <svtools/transfer.hxx>
00135 #endif
00136 
00137 #include <comphelper/storagehelper.hxx>
00138 #include <comphelper/processfactory.hxx>
00139 
00140 #include <sfx2/objface.hxx>
00141 
00142 #ifndef MATHML_HXX
00143 #include <mathml.hxx>
00144 #endif
00145 #ifndef VIEW_HXX
00146 #include "view.hxx"
00147 #endif
00148 #ifndef DOCUMENT_HXX
00149 #include "document.hxx"
00150 #endif
00151 #ifndef CONFIG_HXX
00152 #include "config.hxx"
00153 #endif
00154 #ifndef TOOLBOX_HXX
00155 #include "toolbox.hxx"
00156 #endif
00157 #ifndef DIALOG_HXX
00158 #include "dialog.hxx"
00159 #endif
00160 #ifndef _STARMATH_HRC
00161 #include "starmath.hrc"
00162 #endif
00163 
00164 
00165 #define MINWIDTH                200
00166 #define MINHEIGHT               200
00167 #define MINSPLIT                40
00168 #define SPLITTERWIDTH   2
00169 
00170 #define MINZOOM 25
00171 #define MAXZOOM 800
00172 
00173 #define SmViewShell
00174 #include "smslots.hxx"
00175 
00176 #include <svx/svxdlg.hxx> //CHINA001
00177 #include <svx/dialogs.hrc> //CHINA001
00178 
00179 
00180 using namespace com::sun::star::accessibility;
00181 using namespace com::sun::star;
00182 using namespace com::sun::star::uno;
00183 
00185 
00186 SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell):
00187         ScrollableWindow(&pShell->GetViewFrame()->GetWindow(), 0),
00188     pAccessible(0),
00189         pViewShell(pShell),
00190         nZoom(100),
00191         bIsCursorVisible(FALSE)
00192 {
00193         // docking windows are usually hidden (often already done in the
00194         // resource) and will be shown by the sfx framework.
00195         Hide();
00196 
00197         const Fraction aFraction (1,1);
00198         SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction));
00199 
00200     ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
00201 
00202     SetTotalSize();
00203 
00204         SetHelpId(HID_SMA_WIN_DOCUMENT);
00205         SetUniqueId(HID_SMA_WIN_DOCUMENT);
00206 }
00207 
00208 SmGraphicWindow::~SmGraphicWindow()
00209 {
00210     if (pAccessible)
00211         pAccessible->ClearWin();    // make Accessible defunctional
00212     // Note: memory for pAccessible will be freed when the reference
00213     // xAccessible is released.
00214 }
00215 
00216 void SmGraphicWindow::StateChanged( StateChangedType eType )
00217 {
00218         if ( eType == STATE_CHANGE_INITSHOW )
00219                 Show();
00220         ScrollableWindow::StateChanged( eType );
00221 }
00222 
00223 
00224 void SmGraphicWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
00225 {
00226     // Note: SetTextColor not necessary since the nodes that
00227     // get painted have the color information.
00228 #if OSL_DEBUG_LEVEL > 1
00229 //   ColorData nVal = rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor;
00230 #endif
00231     SetBackground( Color( (ColorData) rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor ) );
00232     Invalidate();
00233 }
00234 
00235 
00236 void SmGraphicWindow::DataChanged( const DataChangedEvent& rEvt )
00237 {
00238     ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
00239 
00240     ScrollableWindow::DataChanged( rEvt );
00241 }
00242 
00243 
00244 void SmGraphicWindow::MouseButtonDown(const MouseEvent& rMEvt)
00245 {
00246         ScrollableWindow::MouseButtonDown(rMEvt);
00247 
00248         //
00249         // set formula-cursor and selection of edit window according to the
00250         // position clicked at
00251         //
00252         DBG_ASSERT(rMEvt.GetClicks() > 0, "Sm : 0 clicks");
00253         if ( rMEvt.IsLeft() && pViewShell->GetEditWindow() )
00254         {
00255                 const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
00258                 if (!pTree)
00259                         return;
00260 
00261                 // get click position relativ to formula
00262                 Point  aPos (PixelToLogic(rMEvt.GetPosPixel())
00263                                          - GetFormulaDrawPos());
00264 
00265                 // if it was clicked inside the formula then get the appropriate node
00266                 const SmNode *pNode = 0;
00267                 if (pTree->OrientedDist(aPos) <= 0)
00268                         pNode = pTree->FindRectClosestTo(aPos);
00269 
00270                 if (pNode)
00271                 {       SmEditWindow  *pEdit = pViewShell->GetEditWindow();
00272                         const SmToken  aToken (pNode->GetToken());
00273 
00274 #ifdef notnow
00275                         // include introducing symbols of special char and text
00276                         // (ie '%' and '"')
00277                         USHORT  nExtra = (aToken.eType == TSPECIAL  ||  aToken.eType == TTEXT) ? 1 : 0;
00278 
00279                         // set selection to the beginning of the token
00280                         ESelection  aSel (aToken.nRow - 1, aToken.nCol - 1 - nExtra);
00281 
00282                         if (rMEvt.GetClicks() != 1)
00283                         {       // select whole token
00284                                 // for text include terminating symbol (ie '"')
00285                                 aSel.nEndPos += aToken.aText.Len() + nExtra
00286                                                                 + (aToken.eType == TTEXT ? 1 : 0);
00287                         }
00288 #endif
00289                         // set selection to the beginning of the token
00290             ESelection  aSel (aToken.nRow - 1, aToken.nCol - 1);
00291 
00292                         if (rMEvt.GetClicks() != 1 || aToken.eType == TPLACE)
00293                 aSel.nEndPos = aSel.nEndPos + sal::static_int_cast< USHORT >(aToken.aText.Len());
00294 
00295                         pEdit->SetSelection(aSel);
00296                         SetCursor(pNode);
00297 
00298                         // allow for immediate editing and
00300                         pEdit->GrabFocus();
00301                 }
00302         }
00303 }
00304 
00305 void SmGraphicWindow::GetFocus()
00306 {
00307     SmEditWindow *pEditWin = pViewShell ? pViewShell->GetEditWindow() : 0;
00308     if (pEditWin)
00309         pEditWin->GrabFocus();
00310 /*
00311     if (xAccessible.is())
00312     {
00313         uno::Any aOldValue, aNewValue;
00314         // aOldValue remains empty
00315         aNewValue <<= AccessibleStateType::FOCUSED;
00316         pAccessible->LaunchEvent( AccessibleEventId::STATE_CHANGED,
00317                 aOldValue, aNewValue );
00318     }
00319 */
00320 }
00321 
00322 void SmGraphicWindow::LoseFocus()
00323 {
00324     ScrollableWindow::LoseFocus();
00325     if (xAccessible.is())
00326     {
00327         uno::Any aOldValue, aNewValue;
00328         aOldValue <<= AccessibleStateType::FOCUSED;
00329         // aNewValue remains empty
00330         pAccessible->LaunchEvent( AccessibleEventId::STATE_CHANGED,
00331                 aOldValue, aNewValue );
00332     }
00333 }
00334 
00335 void SmGraphicWindow::ShowCursor(BOOL bShow)
00336         // shows or hides the formula-cursor depending on 'bShow' is TRUE or not
00337 {
00338         BOOL  bInvert = bShow != IsCursorVisible();
00339 
00340         if (bInvert)
00341                 InvertTracking(aCursorRect, SHOWTRACK_SMALL | SHOWTRACK_WINDOW);
00342 
00343         SetIsCursorVisible(bShow);
00344 }
00345 
00346 
00347 void SmGraphicWindow::SetCursor(const SmNode *pNode)
00348 {
00349         const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
00350 
00351         // get appropriate rectangle
00352         Point aOffset (pNode->GetTopLeft() - pTree->GetTopLeft()),
00353                   aTLPos  (GetFormulaDrawPos() + aOffset);
00354         aTLPos.X() -= pNode->GetItalicLeftSpace();
00355         Size  aSize   (pNode->GetItalicSize());
00356         Point aBRPos  (aTLPos.X() + aSize.Width(), aTLPos.Y() + aSize.Height());
00357 
00358         SetCursor(Rectangle(aTLPos, aSize));
00359 }
00360 
00361 void SmGraphicWindow::SetCursor(const Rectangle &rRect)
00362         // sets cursor to new position (rectangle) 'rRect'.
00363         // The old cursor will be removed, and the new one will be shown if
00364         // that is activated in the ConfigItem
00365 {
00366         SmModule *pp = SM_MOD1();
00367 
00368         if (IsCursorVisible())
00369                 ShowCursor(FALSE);              // clean up remainings of old cursor
00370         aCursorRect = rRect;
00371         if (pp->GetConfig()->IsShowFormulaCursor())
00372                 ShowCursor(TRUE);               // draw new cursor
00373 }
00374 
00375 const SmNode * SmGraphicWindow::SetCursorPos(USHORT nRow, USHORT nCol)
00376         // looks for a VISIBLE node in the formula tree with it's token at
00377         // (or around) the position 'nRow', 'nCol' in the edit window
00378         // (row and column numbering starts with 1 there!).
00379         // If there is such a node the formula-cursor is set to cover that nodes
00380         // rectangle. If not the formula-cursor will be hidden.
00381         // In any case the search result is being returned.
00382 {
00383         // find visible node with token at nRow, nCol
00384         const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree(),
00385                                  *pNode = 0;
00386         if (pTree)
00387                 pNode = pTree->FindTokenAt(nRow, nCol);
00388 
00389         if (pNode)
00390                 SetCursor(pNode);
00391         else
00392                 ShowCursor(FALSE);
00393 
00394         return pNode;
00395 }
00396 
00397 
00398 void SmGraphicWindow::Paint(const Rectangle&)
00399 {
00400         DBG_ASSERT(pViewShell, "Sm : NULL pointer");
00401 
00402         SmDocShell &rDoc = *pViewShell->GetDoc();
00403         Point aPoint;
00404 
00405         rDoc.Draw(*this, aPoint);       
00406 
00407         SetFormulaDrawPos(aPoint);
00408 
00409         SetIsCursorVisible(FALSE);      // (old) cursor must be drawn again
00410 
00411         const SmEditWindow *pEdit = pViewShell->GetEditWindow();
00412         if (pEdit)
00413         {       // get new position for formula-cursor (for possible altered formula)
00414                 USHORT  nRow, nCol;
00415                 SmGetLeftSelectionPart(pEdit->GetSelection(), nRow, nCol);
00416                 nRow++;
00417                 nCol++;
00418                 const SmNode *pFound = SetCursorPos(nRow, nCol);
00419 
00420                 SmModule  *pp = SM_MOD1();
00421                 if (pFound && pp->GetConfig()->IsShowFormulaCursor())
00422                         ShowCursor(TRUE);
00423         }
00424 }
00425 
00426 
00427 void SmGraphicWindow::SetTotalSize ()
00428 {
00429         SmDocShell &rDoc = *pViewShell->GetDoc();
00430         const Size aTmp( PixelToLogic( LogicToPixel( rDoc.GetSize() )));
00431         if ( aTmp != ScrollableWindow::GetTotalSize() )
00432                 ScrollableWindow::SetTotalSize( aTmp );
00433 }
00434 
00435 
00436 void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
00437 {
00438     if (! (GetView() && GetView()->KeyInput(rKEvt)) )
00439                 ScrollableWindow::KeyInput(rKEvt);
00440 }
00441 
00442 
00443 void SmGraphicWindow::Command(const CommandEvent& rCEvt)
00444 {
00445         BOOL bCallBase = TRUE;
00446     if ( !pViewShell->GetViewFrame()->GetFrame()->IsInPlace() )
00447         {
00448                 switch ( rCEvt.GetCommand() )
00449                 {
00450                         case COMMAND_CONTEXTMENU:
00451                         {
00452                                 GetParent()->ToTop();
00453                 SmResId aResId( RID_VIEWMENU );
00454                 PopupMenu* pPopupMenu = new PopupMenu(aResId);
00455                                 pPopupMenu->SetSelectHdl(LINK(this, SmGraphicWindow, MenuSelectHdl));
00456                 Point aPos(5, 5);
00457                 if (rCEvt.IsMouseEvent())
00458                     aPos = rCEvt.GetMousePosPixel();
00459                 DBG_ASSERT( pViewShell, "view shell missing" );
00460 
00461                 // added for replaceability of context menus #96085, #93782
00462                 pViewShell->GetViewFrame()->GetBindings().GetDispatcher()
00463                         ->ExecutePopup( aResId, this, &aPos );
00464                 //pPopupMenu->Execute( this, aPos );
00465 
00466                                 delete pPopupMenu;
00467                                 bCallBase = FALSE;
00468                         }
00469                         break;
00470 
00471                         case COMMAND_WHEEL:
00472                         {
00473                                 const CommandWheelData* pWData = rCEvt.GetWheelData();
00474                                 if  ( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
00475                                 {
00476                     USHORT nTmpZoom = GetZoom();
00477                                         if( 0L > pWData->GetDelta() )
00478                         nTmpZoom -= 10;
00479                                         else
00480                         nTmpZoom += 10;
00481                     SetZoom( nTmpZoom );
00482                                         bCallBase = FALSE;
00483                                 }
00484                         }
00485                         break;
00486                 }
00487         }
00488         if ( bCallBase )
00489                 ScrollableWindow::Command (rCEvt);
00490 }
00491 
00492 
00493 IMPL_LINK_INLINE_START( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
00494 {
00495     SmViewShell *pViewSh = GetView();
00496         if (pViewSh)
00497                 pViewSh->GetViewFrame()->GetDispatcher()->Execute( pMenu->GetCurItemId() );
00498         return 0;
00499 }
00500 IMPL_LINK_INLINE_END( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
00501 
00502 
00503 void SmGraphicWindow::SetZoom(USHORT Factor)
00504 {
00505         nZoom = Min(Max((USHORT) Factor, (USHORT) MINZOOM), (USHORT) MAXZOOM);
00506         Fraction   aFraction (nZoom, 100);
00507         SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction) );
00508         SetTotalSize();
00509     SmViewShell *pViewSh = GetView();
00510         if (pViewSh)
00511                 pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_ATTR_ZOOM);
00512         Invalidate();
00513 }
00514 
00515 
00516 void SmGraphicWindow::ZoomToFitInWindow()
00517 {
00518         SmDocShell &rDoc = *pViewShell->GetDoc();
00519 
00520         // set defined mapmode before calling 'LogicToPixel' below
00521         SetMapMode(MapMode(MAP_100TH_MM));
00522 
00523         Size       aSize (LogicToPixel(rDoc.GetSize()));
00524         Size       aWindowSize (GetSizePixel());
00525 
00526         if (aSize.Width() > 0  &&  aSize.Height() > 0)
00527     {
00528         long nVal = Min ((85 * aWindowSize.Width())  / aSize.Width(),
00529                       (85 * aWindowSize.Height()) / aSize.Height());
00530         SetZoom ( sal::static_int_cast< USHORT >(nVal) );
00531     }
00532 }
00533 
00534 uno::Reference< XAccessible > SmGraphicWindow::CreateAccessible()
00535 {
00536     if (!pAccessible)
00537     {
00538         pAccessible = new SmGraphicAccessible( this );
00539         xAccessible = pAccessible;
00540     }
00541     return xAccessible;
00542 }
00543 
00544 /**************************************************************************/
00545 
00546 
00547 SmGraphicController::SmGraphicController(SmGraphicWindow &rSmGraphic,
00548                         USHORT          nId_,
00549                                                 SfxBindings     &rBindings) :
00550     SfxControllerItem(nId_, rBindings),
00551     rGraphic(rSmGraphic)
00552 {
00553 }
00554 
00555 
00556 void SmGraphicController::StateChanged(USHORT nSID, SfxItemState eState, const SfxPoolItem* pState)
00557 {
00558         rGraphic.SetTotalSize();
00559         rGraphic.Invalidate();
00560         SfxControllerItem::StateChanged (nSID, eState, pState);
00561 }
00562 
00563 
00564 /**************************************************************************/
00565 
00566 
00567 SmEditController::SmEditController(SmEditWindow &rSmEdit,
00568                      USHORT       nId_,
00569                                          SfxBindings  &rBindings) :
00570     SfxControllerItem(nId_, rBindings),
00571     rEdit(rSmEdit)
00572 {
00573 }
00574 
00575 
00576 #if OSL_DEBUG_LEVEL > 1
00577 SmEditController::~SmEditController()
00578 {
00579 }
00580 #endif
00581 
00582 
00583 void SmEditController::StateChanged(USHORT nSID, SfxItemState eState, const SfxPoolItem* pState)
00584 {
00585         const SfxStringItem *pItem = PTR_CAST(SfxStringItem, pState);
00586 
00587         if ((pItem != NULL) && (rEdit.GetText() != pItem->GetValue()))
00588                 rEdit.SetText(pItem->GetValue());
00589         SfxControllerItem::StateChanged (nSID, eState, pState);
00590 }
00591 
00592 
00593 /**************************************************************************/
00594 
00595 SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings *pBindings_, SfxChildWindow *pChildWindow,
00596                                                            Window *pParent) :
00597     SfxDockingWindow(pBindings_, pChildWindow, pParent, SmResId(RID_CMDBOXWINDOW)),
00598     aEdit       (*this),
00599     aController (aEdit, SID_TEXT, *pBindings_),
00600     bExiting    (FALSE)
00601 {
00602         Hide ();
00603 }
00604 
00605 
00606 SmCmdBoxWindow::~SmCmdBoxWindow ()
00607 {
00608     bExiting = TRUE;
00609 }
00610 
00611 
00612 SmViewShell * SmCmdBoxWindow::GetView()
00613 {
00614     SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
00615     return PTR_CAST(SmViewShell, pView);
00616 }
00617 
00618 void SmCmdBoxWindow::Resize()
00619 {
00620         Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
00621 
00622         if (! IsFloatingMode())
00623         {
00624                 switch (GetAlignment())
00625                 {
00626                         case SFX_ALIGN_TOP:             aRect.Bottom()--;       break;
00627                         case SFX_ALIGN_BOTTOM:  aRect.Top()++;          break;
00628                         case SFX_ALIGN_LEFT:    aRect.Right()--;        break;
00629                         case SFX_ALIGN_RIGHT:   aRect.Left()++;         break;
00630             default:
00631                 break;
00632                 }
00633         }
00634 
00635         DecorationView aView(this);
00636         aRect.Left() += 8; aRect.Top()   += 8;
00637         aRect.Right()-= 8; aRect.Bottom()-= 8;
00638         aRect = aView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
00639 
00640         aEdit.SetPosSizePixel(aRect.TopLeft(), aRect.GetSize());
00641         SfxDockingWindow::Resize();
00642         Invalidate();
00643 }
00644 
00645 
00646 void SmCmdBoxWindow::Paint(const Rectangle& /*rRect*/)
00647 {
00648         Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
00649         DecorationView aView(this);
00650 
00651         if (! IsFloatingMode())
00652         {
00653                 Point aFrom, aTo;
00654                 switch (GetAlignment())
00655                 {
00656                         case SFX_ALIGN_TOP:
00657                                 aFrom = aRect.BottomLeft(); aTo = aRect.BottomRight();
00658                                 aRect.Bottom()--;
00659                                 break;
00660 
00661                         case SFX_ALIGN_BOTTOM:
00662                                 aFrom = aRect.TopLeft(); aTo = aRect.TopRight();
00663                                 aRect.Top()++;
00664                                 break;
00665 
00666                         case SFX_ALIGN_LEFT:
00667                                 aFrom = aRect.TopRight(); aTo = aRect.BottomRight();
00668                                 aRect.Right()--;
00669                                 break;
00670 
00671                         case SFX_ALIGN_RIGHT:
00672                                 aFrom = aRect.TopLeft(); aTo = aRect.BottomLeft();
00673                                 aRect.Left()++;
00674                                 break;
00675 
00676             default:
00677                 break;
00678                 }
00679                 DrawLine( aFrom, aTo );
00680                 aView.DrawFrame(aRect, FRAME_DRAW_OUT);
00681         }
00682         aRect.Left() += 8; aRect.Top()   += 8;
00683         aRect.Right()-= 8; aRect.Bottom()-= 8;
00684         aRect = aView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
00685 }
00686 
00687 
00688 Size SmCmdBoxWindow::CalcDockingSize(SfxChildAlignment eAlign)
00689 {
00690         switch (eAlign)
00691         {
00692                 case SFX_ALIGN_LEFT:
00693                 case SFX_ALIGN_RIGHT:
00694                         return Size();
00695         default:
00696             break;
00697         }
00698         return SfxDockingWindow::CalcDockingSize(eAlign);
00699 }
00700 
00701 
00702 SfxChildAlignment SmCmdBoxWindow::CheckAlignment(SfxChildAlignment eActual,
00703                                                                                          SfxChildAlignment eWish)
00704 {
00705         switch (eWish)
00706         {
00707                 case SFX_ALIGN_TOP:
00708                 case SFX_ALIGN_BOTTOM:
00709                 case SFX_ALIGN_NOALIGNMENT:
00710                         return eWish;
00711         default:
00712             break;
00713         }
00714 
00715         return eActual;
00716 }
00717 
00718 
00719 void SmCmdBoxWindow::StateChanged( StateChangedType nStateChange )
00720 {
00721         if (STATE_CHANGE_INITSHOW == nStateChange)
00722     {
00723         Resize();   // #98848# avoid SmEditWindow not being painted correctly
00724 
00725         // set initial position of window in floating mode
00726         if (TRUE == IsFloatingMode())
00727             AdjustPosition();   
00728 
00729         // make sure the formula can be edited right away
00730         aEdit.GrabFocus();
00731     }
00732 
00733     SfxDockingWindow::StateChanged( nStateChange );
00734 }
00735 
00736 
00737 void SmCmdBoxWindow::AdjustPosition()
00738 {
00739         Point aPt;
00740         const Rectangle aRect( aPt, GetParent()->GetOutputSizePixel() );
00741         Point aTopLeft( Point( aRect.Left(),
00742                                                    aRect.Bottom() - GetSizePixel().Height() ) );
00743         Point aPos( GetParent()->OutputToScreenPixel( aTopLeft ) );
00744         if (aPos.X() < 0)
00745                 aPos.X() = 0;
00746         if (aPos.Y() < 0)
00747                 aPos.Y() = 0;
00748         SetPosPixel( aPos );
00749 }
00750 
00751 
00752 void SmCmdBoxWindow::ToggleFloatingMode()
00753 {
00754         SfxDockingWindow::ToggleFloatingMode();
00755 
00756         if (GetFloatingWindow())
00757                 GetFloatingWindow()->SetMinOutputSizePixel(Size (200, 50));
00758 }
00759 
00760 
00761 void SmCmdBoxWindow::GetFocus()
00762 {
00763     if (!bExiting)
00764         aEdit.GrabFocus();
00765 }
00766 
00767 /**************************************************************************/
00768 
00769 
00770 SFX_IMPL_DOCKINGWINDOW(SmCmdBoxWrapper, SID_CMDBOXWINDOW);
00771 
00772 SmCmdBoxWrapper::SmCmdBoxWrapper(Window *pParentWindow, USHORT nId,
00773                                                                  SfxBindings *pBindings,
00774                                                                  SfxChildWinInfo *pInfo) :
00775         SfxChildWindow(pParentWindow, nId)
00776 {
00777         pWindow = new SmCmdBoxWindow(pBindings, this, pParentWindow);
00778 
00779     // make window docked to the bottom initially (after first start)
00780     eChildAlignment = SFX_ALIGN_BOTTOM;
00781     ((SfxDockingWindow *)pWindow)->Initialize(pInfo);
00782 }
00783 
00784 
00785 #if OSL_DEBUG_LEVEL > 1
00786 SmCmdBoxWrapper::~SmCmdBoxWrapper()
00787 {
00788 }
00789 #endif
00790 
00791 
00792 /**************************************************************************/
00793 
00794 struct SmViewShell_Impl
00795 {
00796     sfx2::DocumentInserter* pDocInserter;
00797     SfxRequest*             pRequest;
00798 
00799     SmViewShell_Impl() :
00800           pDocInserter( NULL )
00801         , pRequest( NULL )
00802     {}
00803 
00804     ~SmViewShell_Impl()
00805     {
00806         delete pDocInserter;
00807         delete pRequest;
00808     }
00809 };
00810 
00811 TYPEINIT1( SmViewShell, SfxViewShell );
00812 
00813 SFX_IMPL_INTERFACE(SmViewShell, SfxViewShell, SmResId(0))
00814 {
00815         SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS | SFX_VISIBILITY_STANDARD |
00816                                                                 SFX_VISIBILITY_FULLSCREEN | SFX_VISIBILITY_SERVER,
00817                                                                 SmResId(RID_MATH_TOOLBOX ));
00818         //Dummy-Objectbar, damit es bei aktivieren nicht staendig zuppelt.
00819 // Wegen #58705# entfernt (RID wurde nirgends verwendet)
00820 //      SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_SERVER,
00821 //                                                              SmResId(RID_DRAW_OBJECTBAR) );
00822 
00823         SFX_CHILDWINDOW_REGISTRATION(SmToolBoxWrapper::GetChildWindowId());
00824         SFX_CHILDWINDOW_REGISTRATION(SmCmdBoxWrapper::GetChildWindowId());
00825 }
00826 
00827 
00828 SFX_IMPL_VIEWFACTORY(SmViewShell, SmResId(RID_VIEWNAME))
00829 {
00830         SFX_VIEW_REGISTRATION(SmDocShell);
00831 }
00832 
00833 
00834 Size SmViewShell::GetOptimalSizePixel() const
00835 {
00836     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetOptimalSizePixel" );
00837 
00838         return aGraphic.LogicToPixel( ((SmViewShell*)this)->GetDoc()->GetSize() );
00839 }
00840 
00841 
00842 void SmViewShell::AdjustPosSizePixel(const Point &rPos, const Size &rSize)
00843 {
00844     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::AdjustPosSizePixel" );
00845 
00846         aGraphic.SetPosSizePixel(rPos, rSize);
00847 }
00848 
00849 
00850 void SmViewShell::InnerResizePixel(const Point &rOfs, const Size &rSize)
00851 {
00852     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::InnerResizePixel" );
00853 
00854     Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
00855     if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
00856     {
00857         Size aProvidedSize = GetWindow()->PixelToLogic( rSize, MAP_100TH_MM );
00858         SfxViewShell::SetZoomFactor( Fraction( aProvidedSize.Width(), aObjSize.Width() ),
00859                         Fraction( aProvidedSize.Height(), aObjSize.Height() ) );
00860     }
00861 
00862     SetBorderPixel( SvBorder() );
00863     GetGraphicWindow().SetPosSizePixel(rOfs, rSize);
00864         GetGraphicWindow().SetTotalSize();
00865 }
00866 
00867 
00868 void SmViewShell::OuterResizePixel(const Point &rOfs, const Size &rSize)
00869 {
00870     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::OuterResizePixel" );
00871 
00872     SmGraphicWindow &rWin = GetGraphicWindow();
00873     rWin.SetPosSizePixel(rOfs, rSize);
00874     if (GetDoc()->IsPreview())
00875         rWin.ZoomToFitInWindow();
00876     rWin.Update();
00877 }
00878 
00879 
00880 void SmViewShell::QueryObjAreaPixel( Rectangle& rRect ) const
00881 {
00882     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::QueryObjAreaPixel" );
00883 
00884         rRect.SetSize( GetGraphicWindow().GetSizePixel() );
00885 }
00886 
00887 
00888 void SmViewShell::SetZoomFactor( const Fraction &rX, const Fraction &rY )
00889 {
00890     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetZoomFactor" );
00891 
00892         const Fraction &rFrac = rX < rY ? rX : rY;
00893         GetGraphicWindow().SetZoom( (USHORT) long(rFrac * Fraction( 100, 1 )) );
00894 
00895         //Um Rundungsfehler zu minimieren lassen wir von der Basisklasse ggf.
00896         //auch die krummen Werte einstellen
00897         SfxViewShell::SetZoomFactor( rX, rY );
00898 }
00899 
00900 
00901 Size SmViewShell::GetTextLineSize(OutputDevice& rDevice, const String& rLine)
00902 {
00903     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetTextLineSize" );
00904 
00905         String aText;
00906         Size   aSize(rDevice.GetTextWidth(rLine), rDevice.GetTextHeight());
00907         USHORT nTabs = rLine.GetTokenCount('\t');
00908 
00909         if (nTabs > 0)
00910         {
00911                 long TabPos = rDevice.GetTextWidth('n') * 8;
00912 
00913                 aSize.Width() = 0;
00914 
00915                 for (USHORT i = 0; i < nTabs; i++)
00916                 {
00917                         if (i > 0)
00918                                 aSize.Width() = ((aSize.Width() / TabPos) + 1) * TabPos;
00919 
00920                         aText = rLine.GetToken(i, '\t');
00921                         aText.EraseLeadingChars('\t');
00922                         aText.EraseTrailingChars('\t');
00923                         aSize.Width() += rDevice.GetTextWidth(aText);
00924                 }
00925         }
00926 
00927         return aSize;
00928 }
00929 
00930 
00931 Size SmViewShell::GetTextSize(OutputDevice& rDevice, const String& rText, long MaxWidth)
00932 {
00933     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetTextSize" );
00934 
00935         Size    aSize;
00936         String  aLine;
00937         Size    TextSize;
00938         String  aText;
00939         USHORT  nLines = rText.GetTokenCount('\n');
00940 
00941         for (USHORT i = 0; i < nLines; i++)
00942         {
00943                 aLine = rText.GetToken(i, '\n');
00944                 aLine.EraseAllChars('\r');
00945                 aLine.EraseLeadingChars('\n');
00946                 aLine.EraseTrailingChars('\n');
00947 
00948                 aSize = GetTextLineSize(rDevice, aLine);
00949 
00950                 if (aSize.Width() > MaxWidth)
00951                 {
00952                         do
00953                         {
00954                                 xub_StrLen m    = aLine.Len();
00955                                 xub_StrLen nLen = m;
00956 
00957                                 for (xub_StrLen n = 0; n < nLen; n++)
00958                                 {
00959                                         sal_Unicode cLineChar = aLine.GetChar(n);
00960                                         if ((cLineChar == ' ') || (cLineChar == '\t'))
00961                                         {
00962                                                 aText = aLine.Copy(0, n);
00963                                                 if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
00964                                                         m = n;
00965                                                 else
00966                                                         break;
00967                                         }
00968                                 }
00969 
00970                                 aText = aLine.Copy(0, m);
00971                                 aLine.Erase(0, m);
00972                                 aSize = GetTextLineSize(rDevice, aText);
00973                                 TextSize.Height() += aSize.Height();
00974                                 TextSize.Width() = Max(TextSize.Width(), Min(aSize.Width(), MaxWidth));
00975 
00976                                 aLine.EraseLeadingChars(' ');
00977                                 aLine.EraseLeadingChars('\t');
00978                                 aLine.EraseLeadingChars(' ');
00979                         }
00980                         while (aLine.Len() > 0);
00981                 }
00982                 else
00983                 {
00984                         TextSize.Height() += aSize.Height();
00985                         TextSize.Width() = Max(TextSize.Width(), aSize.Width());
00986                 }
00987         }
00988 
00989         return TextSize;
00990 }
00991 
00992 
00993 void SmViewShell::DrawTextLine(OutputDevice& rDevice, const Point& rPosition, const String& rLine)
00994 {
00995     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::DrawTextLine" );
00996 
00997         String  aText;
00998         Point   aPoint (rPosition);
00999         USHORT  nTabs = rLine.GetTokenCount('\t');
01000 
01001         if (nTabs > 0)
01002         {
01003                 long TabPos = rDevice.GetTextWidth('n') * 8;
01004 
01005                 for (USHORT i = 0; i < nTabs; i++)
01006                 {
01007                         if (i > 0)
01008                                 aPoint.X() = ((aPoint.X() / TabPos) + 1) * TabPos;
01009 
01010                         aText = rLine.GetToken(i, '\t');
01011                         aText.EraseLeadingChars('\t');
01012                         aText.EraseTrailingChars('\t');
01013                         rDevice.DrawText(aPoint, aText);
01014                         aPoint.X() += rDevice.GetTextWidth(aText);
01015                 }
01016         }
01017         else
01018                 rDevice.DrawText(aPoint, rLine);
01019 }
01020 
01021 
01022 void SmViewShell::DrawText(OutputDevice& rDevice, const Point& rPosition, const String& rText, USHORT MaxWidth)
01023 {
01024     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::DrawText" );
01025 
01026         USHORT  nLines = rText.GetTokenCount('\n');
01027         Point   aPoint (rPosition);
01028         Size    aSize;
01029         String  aLine;
01030         String  aText;
01031 
01032         for (USHORT i = 0; i < nLines; i++)
01033         {
01034                 aLine = rText.GetToken(i, '\n');
01035                 aLine.EraseAllChars('\r');
01036                 aLine.EraseLeadingChars('\n');
01037                 aLine.EraseTrailingChars('\n');
01038                 aSize = GetTextLineSize(rDevice, aLine);
01039                 if (aSize.Width() > MaxWidth)
01040                 {
01041                         do
01042                         {
01043                                 xub_StrLen m    = aLine.Len();
01044                                 xub_StrLen nLen = m;
01045 
01046                                 for (xub_StrLen n = 0; n < nLen; n++)
01047                                 {
01048                                         sal_Unicode cLineChar = aLine.GetChar(n);
01049                                         if ((cLineChar == ' ') || (cLineChar == '\t'))
01050                                         {
01051                                                 aText = aLine.Copy(0, n);
01052                                                 if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
01053                                                         m = n;
01054                                                 else
01055                                                         break;
01056                                         }
01057                                 }
01058                                 aText = aLine.Copy(0, m);
01059                                 aLine.Erase(0, m);
01060 
01061                                 DrawTextLine(rDevice, aPoint, aText);
01062                                 aPoint.Y() += aSize.Height();
01063 
01064                                 aLine.EraseLeadingChars(' ');
01065                                 aLine.EraseLeadingChars('\t');
01066                                 aLine.EraseLeadingChars(' ');
01067                         }
01068                         while (GetTextLineSize(rDevice, aLine).Width() > MaxWidth);
01069 
01070                         // print the remaining text
01071                         if (aLine.Len() > 0)
01072                         {
01073                                 DrawTextLine(rDevice, aPoint, aLine);
01074                                 aPoint.Y() += aSize.Height();
01075                         }
01076                 }
01077                 else
01078                 {
01079                         DrawTextLine(rDevice, aPoint, aLine);
01080                         aPoint.Y() += aSize.Height();
01081                 }
01082         }
01083 }
01084 
01085 void SmViewShell::Impl_Print(
01086         OutputDevice &rOutDev, const SmPrintSize ePrintSize,
01087         Rectangle aOutRect, Point aZeroPoint )
01088 {
01089     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Impl_Print" );
01090 
01091         SmModule *pp = SM_MOD1();
01092 
01093     rOutDev.Push();
01094     rOutDev.SetLineColor( Color(COL_BLACK) );
01095 
01096         // output text on top
01097         if (pp->GetConfig()->IsPrintTitle())
01098         {
01099                 Size aSize600 (0, 600);
01100                 Size aSize650 (0, 650);
01101                 Font aFont(FAMILY_DONTKNOW, aSize600);
01102 
01103                 aFont.SetAlign(ALIGN_TOP);
01104                 aFont.SetWeight(WEIGHT_BOLD);
01105                 aFont.SetSize(aSize650);
01106         aFont.SetColor( Color(COL_BLACK) );
01107         rOutDev.SetFont(aFont);
01108 
01109         Size aTitleSize (GetTextSize(rOutDev, GetDoc()->GetTitle(), aOutRect.GetWidth() - 200));
01110 
01111                 aFont.SetWeight(WEIGHT_NORMAL);
01112                 aFont.SetSize(aSize600);
01113         rOutDev.SetFont(aFont);
01114 
01115         Size aDescSize (GetTextSize(rOutDev, GetDoc()->GetComment(), aOutRect.GetWidth() - 200));
01116 
01117         if (pp->GetConfig()->IsPrintFrame())
01118             rOutDev.DrawRect(Rectangle(aOutRect.TopLeft(),
01119                                Size(aOutRect.GetWidth(), 100 + aTitleSize.Height() + 200 + aDescSize.Height() + 100)));
01120         aOutRect.Top() += 200;
01121 
01122                 // output title
01123                 aFont.SetWeight(WEIGHT_BOLD);
01124                 aFont.SetSize(aSize650);
01125         rOutDev.SetFont(aFont);
01126         Point aPoint(aOutRect.Left() + (aOutRect.GetWidth() - aTitleSize.Width())  / 2,
01127                      aOutRect.Top());
01128         DrawText(rOutDev, aPoint, GetDoc()->GetTitle(),
01129                  sal::static_int_cast< USHORT >(aOutRect.GetWidth() - 200));
01130         aOutRect.Top() += aTitleSize.Height() + 200;
01131 
01132                 // output description
01133                 aFont.SetWeight(WEIGHT_NORMAL);
01134                 aFont.SetSize(aSize600);
01135         rOutDev.SetFont(aFont);
01136         aPoint.X() = aOutRect.Left() + (aOutRect.GetWidth()  - aDescSize.Width())  / 2;
01137         aPoint.Y() = aOutRect.Top();
01138         DrawText(rOutDev, aPoint, GetDoc()->GetComment(),
01139                  sal::static_int_cast< USHORT >(aOutRect.GetWidth() - 200));
01140         aOutRect.Top() += aDescSize.Height() + 300;
01141         }
01142 
01143         // output text on bottom
01144     if (pp->GetConfig()->IsPrintFormulaText())
01145         {
01146 //                Font aFont(FAMILY_DONTKNOW, Size(0, 600));
01147                 Font aFont;
01148 
01149                 aFont.SetAlign(ALIGN_TOP);
01150         aFont.SetColor( Color(COL_BLACK) );
01151 
01152                 // get size
01153         rOutDev.SetFont(aFont);
01154 
01155         Size aSize (GetTextSize(rOutDev, GetDoc()->GetText(), aOutRect.GetWidth() - 200));
01156 
01157         aOutRect.Bottom() -= aSize.Height() + 600;
01158 
01159         if (pp->GetConfig()->IsPrintFrame())
01160             rOutDev.DrawRect(Rectangle(aOutRect.BottomLeft(),
01161                                Size(aOutRect.GetWidth(), 200 + aSize.Height() + 200)));
01162 
01163         Point aPoint (aOutRect.Left() + (aOutRect.GetWidth()  - aSize.Width())  / 2,
01164                       aOutRect.Bottom() + 300);
01165         DrawText(rOutDev, aPoint, GetDoc()->GetText(),
01166                  sal::static_int_cast< USHORT >(aOutRect.GetWidth() - 200));
01167         aOutRect.Bottom() -= 200;
01168         }
01169 
01170         if (pp->GetConfig()->IsPrintFrame())
01171         rOutDev.DrawRect(aOutRect);
01172 
01173     aOutRect.Top()    += 100;
01174     aOutRect.Left()   += 100;
01175     aOutRect.Bottom() -= 100;
01176     aOutRect.Right()  -= 100;
01177 
01178         Size aSize (GetDoc()->GetSize());
01179 
01180         MapMode    OutputMapMode;
01181     switch (ePrintSize)
01182         {
01183                 case PRINT_SIZE_NORMAL:
01184                         OutputMapMode = MapMode(MAP_100TH_MM);
01185                         break;
01186 
01187                 case PRINT_SIZE_SCALED:
01188                         if ((aSize.Width() > 0) && (aSize.Height() > 0))
01189                         {
01190                 Size     OutputSize (rOutDev.LogicToPixel(Size(aOutRect.GetWidth(),
01191                                                             aOutRect.GetHeight()), MapMode(MAP_100TH_MM)));
01192                 Size     GraphicSize (rOutDev.LogicToPixel(aSize, MapMode(MAP_100TH_MM)));
01193                                 USHORT   nZ = (USHORT) Min((long)Fraction(OutputSize.Width()  * 100L, GraphicSize.Width()),
01194                                                                                           (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
01195                                 Fraction aFraction ((USHORT) Max ((USHORT) MINZOOM, Min((USHORT) MAXZOOM, (USHORT) (nZ - 10))), (USHORT) 100);
01196 
01197                 OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
01198                         }
01199                         else
01200                                 OutputMapMode = MapMode(MAP_100TH_MM);
01201                         break;
01202 
01203                 case PRINT_SIZE_ZOOMED:
01204                 {
01205             Fraction aFraction (pp->GetConfig()->GetPrintZoomFactor(), 100);
01206 
01207             OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
01208                         break;
01209                 }
01210         }
01211 
01212     aSize = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aSize, OutputMapMode),
01213                                                                    MapMode(MAP_100TH_MM));
01214 
01215     Point aPos (aOutRect.Left() + (aOutRect.GetWidth()  - aSize.Width())  / 2,
01216                 aOutRect.Top()  + (aOutRect.GetHeight() - aSize.Height()) / 2);
01217 
01218     aPos     = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aPos, MapMode(MAP_100TH_MM)),
01219                                                                                   OutputMapMode);
01220     aOutRect   = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aOutRect, MapMode(MAP_100TH_MM)),
01221                                                                                   OutputMapMode);
01222 
01223     rOutDev.SetMapMode(OutputMapMode);
01224     rOutDev.SetClipRegion(Region(aOutRect));
01225     GetDoc()->Draw(rOutDev, aPos);
01226     rOutDev.SetClipRegion();
01227 
01228     rOutDev.Pop();
01229 }
01230 
01231 USHORT SmViewShell::Print(SfxProgress &rProgress, BOOL bIsAPI, PrintDialog *pPrintDialog)
01232 {
01233     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Print" );
01234 
01235         SmPrinterAccess aPrinterAccess( *GetDoc() );
01236     Printer *pPrinter = aPrinterAccess.GetPrinter();
01237     //OutputDevice *pOutDev = pPrinter;
01238 
01239     SfxViewShell::Print (rProgress, bIsAPI, pPrintDialog);
01240 
01241         pPrinter->StartPage();
01242 
01243     Point     aZeroPoint;
01244     Rectangle OutputRect( aZeroPoint, pPrinter->GetOutputSize() );
01245 
01246     Point   aPrtPageOffset( pPrinter->GetPageOffset() );
01247     Size    aPrtPaperSize ( pPrinter->GetPaperSize() );
01248 
01249         // set minimum top and bottom border
01250     if (aPrtPageOffset.Y() < 2000)
01251         OutputRect.Top() += 2000 - aPrtPageOffset.Y();
01252     if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
01253         OutputRect.Bottom() -= 2000 - (aPrtPaperSize.Height() -
01254                                        (aPrtPageOffset.Y() + OutputRect.Bottom()));
01255 
01256         // set minimum left and right border
01257     if (aPrtPageOffset.X() < 2500)
01258         OutputRect.Left() += 2500 - aPrtPageOffset.X();
01259     if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
01260         OutputRect.Right() -= 1500 - (aPrtPaperSize.Width() -
01261                                       (aPrtPageOffset.X() + OutputRect.Right()));
01262 
01263     SmModule *pp = SM_MOD1();
01264     Impl_Print( *pPrinter, pp->GetConfig()->GetPrintSize(),
01265                  OutputRect, aZeroPoint );
01266 
01267         pPrinter->EndPage();
01268 
01269         return 0;
01270 }
01271 
01272 
01273 SfxPrinter* SmViewShell::GetPrinter(BOOL bCreate)
01274 {
01275     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetPrinter" );
01276 
01277         SmDocShell *pDoc = GetDoc();
01278         if ( pDoc->HasPrinter() || bCreate )
01279                 return pDoc->GetPrinter();
01280         return 0;
01281 }
01282 
01283 
01284 USHORT SmViewShell::SetPrinter(SfxPrinter *pNewPrinter, USHORT nDiffFlags, bool )
01285 {
01286     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetPrinter" );
01287 
01288         if ((nDiffFlags & SFX_PRINTER_PRINTER) == SFX_PRINTER_PRINTER)
01289                 GetDoc()->SetPrinter( pNewPrinter );
01290 
01291         if ((nDiffFlags & SFX_PRINTER_OPTIONS) == SFX_PRINTER_OPTIONS)
01292         {
01293                 SmModule *pp = SM_MOD1();
01294                 pp->GetConfig()->ItemSetToConfig(pNewPrinter->GetOptions());
01295         }
01296         return 0;
01297 }
01298 
01299 
01300 SfxTabPage* SmViewShell::CreatePrintOptionsPage(Window *pParent,
01301                                                                                                 const SfxItemSet &rOptions)
01302 {
01303     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::CreatePrintOptionsPage" );
01304 
01305         return SmPrintOptionsTabPage::Create(pParent, rOptions);
01306 }
01307 
01308 
01309 SmEditWindow *SmViewShell::GetEditWindow()
01310 {
01311     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetEditWindow" );
01312 
01313         SmCmdBoxWrapper *pWrapper = (SmCmdBoxWrapper *) GetViewFrame()->
01314                         GetChildWindow( SmCmdBoxWrapper::GetChildWindowId() );
01315 
01316         if (pWrapper != NULL)
01317         {
01318                 SmEditWindow *pEditWin  = pWrapper->GetEditWindow();
01319                 DBG_ASSERT( pEditWin, "SmEditWindow missing" );
01320                 return pEditWin;
01321         }
01322 
01323         return NULL;
01324 }
01325 
01326 
01327 void SmViewShell::SetStatusText(const String& Text)
01328 {
01329     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetStatusText" );
01330 
01331         StatusText = Text;
01332         GetViewFrame()->GetBindings().Invalidate(SID_TEXTSTATUS);
01333 }
01334 
01335 
01336 void SmViewShell::ShowError( const SmErrorDesc *pErrorDesc )
01337 {
01338     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::ShowError" );
01339 
01340         DBG_ASSERT(GetDoc(), "Sm : Document missing");
01341         if (pErrorDesc || 0 != (pErrorDesc = GetDoc()->GetParser().GetError(0)) )
01342         {
01343                 SetStatusText( pErrorDesc->Text );
01344                 GetEditWindow()->MarkError( Point( pErrorDesc->pNode->GetColumn(),
01345                                                                                    pErrorDesc->pNode->GetRow()));
01346         }
01347 }
01348 
01349 
01350 void SmViewShell::NextError()
01351 {
01352     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::NextError" );
01353 
01354         DBG_ASSERT(GetDoc(), "Sm : Document missing");
01355         const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser().NextError();
01356 
01357         if (pErrorDesc)
01358                 ShowError( pErrorDesc );
01359 }
01360 
01361 
01362 void SmViewShell::PrevError()
01363 {
01364     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::PrevError" );
01365 
01366         DBG_ASSERT(GetDoc(), "Sm : Document missing");
01367         const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser().PrevError();
01368 
01369         if (pErrorDesc)
01370                 ShowError( pErrorDesc );
01371 }
01372 
01373 
01374 BOOL SmViewShell::Insert( SfxMedium& rMedium )
01375 {
01376     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Insert" );
01377 
01378     SmDocShell *pDoc = GetDoc();
01379     String aText( pDoc->GetText() );
01380     String aTemp = aText;
01381     BOOL bRet = FALSE, bChkOldVersion = TRUE;
01382 
01383     uno::Reference < embed::XStorage > xStorage = rMedium.GetStorage();
01384     uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
01385     if ( xNameAccess.is() && xNameAccess->getElementNames().getLength() )
01386     {
01387         if ( xNameAccess->hasByName( C2S( "content.xml" ) ) || xNameAccess->hasByName( C2S( "Content.xml" ) ))
01388         {
01389             bChkOldVersion = FALSE;
01390             // is this a fabulous math package ?
01391             Reference<com::sun::star::frame::XModel> xModel(pDoc->GetModel());
01392             SmXMLWrapper aEquation(xModel);     
01393             bRet = 0 == aEquation.Import(rMedium);
01394         }
01395     }
01396 
01397     if( bRet )
01398     {
01399                 aText = pDoc->GetText();
01400         SmEditWindow *pEditWin = GetEditWindow();
01401         if (pEditWin)
01402             pEditWin->InsertText( aText );
01403         else
01404         {
01405             DBG_ERROR( "EditWindow missing" );
01406             aTemp += aText;
01407             aText  = aTemp;
01408         }
01409 
01410         pDoc->Parse();
01411         pDoc->SetModified(TRUE);
01412 
01413         SfxBindings &rBnd = GetViewFrame()->GetBindings();
01414         rBnd.Invalidate(SID_GAPHIC_SM);
01415         rBnd.Invalidate(SID_TEXT);
01416     }
01417     return bRet;
01418 }
01419 
01420 
01421 BOOL SmViewShell::InsertFrom(SfxMedium &rMedium)
01422 {
01423     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::InsertFrom" );
01424 
01425     BOOL        bSuccess = FALSE;
01426     SmDocShell *pDoc = GetDoc();
01427     SvStream   *pStream = rMedium.GetInStream();
01428     String      aText( pDoc->GetText() );
01429     String      aTemp = aText;
01430 
01431     if (pStream)
01432     {
01433         const String& rFltName = rMedium.GetFilter()->GetFilterName();
01434         if ( rFltName.EqualsAscii(MATHML_XML) )
01435         {
01436             Reference<com::sun::star::frame::XModel> xModel( pDoc->GetModel() );
01437             SmXMLWrapper aEquation(xModel);     
01438             bSuccess = 0 == aEquation.Import(rMedium);
01439         }
01440         else
01441         {
01442             //bSuccess = ImportSM20File( pStream );
01443         }
01444     }
01445 
01446     if( bSuccess )
01447     {
01448                 aText = pDoc->GetText();
01449         SmEditWindow *pEditWin = GetEditWindow();
01450         if (pEditWin)
01451             pEditWin->InsertText( aText );
01452         else
01453         {
01454             DBG_ERROR( "EditWindow missing" );
01455             aTemp += aText;
01456             aText  = aTemp;
01457         }
01458 
01459         pDoc->Parse();
01460         pDoc->SetModified(TRUE);
01461 
01462         SfxBindings &rBnd = GetViewFrame()->GetBindings();
01463         rBnd.Invalidate(SID_GAPHIC_SM);
01464         rBnd.Invalidate(SID_TEXT);
01465     }
01466 
01467     return bSuccess;
01468 }
01469 
01470 
01471 void SmViewShell::Execute(SfxRequest& rReq)
01472 {
01473     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Execute" );
01474 
01475         SmEditWindow *pWin = GetEditWindow();
01476 
01477         switch (rReq.GetSlot())
01478         {
01479                 case SID_FORMULACURSOR:
01480                 {
01481                         SmModule *pp = SM_MOD1();
01482 
01483                         const SfxItemSet  *pArgs = rReq.GetArgs();
01484                         const SfxPoolItem *pItem;
01485 
01486                         BOOL  bVal;
01487                         if ( pArgs &&
01488                                  SFX_ITEM_SET == pArgs->GetItemState( SID_FORMULACURSOR, FALSE, &pItem))
01489                                 bVal = ((SfxBoolItem *) pItem)->GetValue();
01490                         else
01491                                 bVal = !pp->GetConfig()->IsShowFormulaCursor();
01492 
01493                         pp->GetConfig()->SetShowFormulaCursor(bVal);
01494                         GetGraphicWindow().ShowCursor(bVal);
01495                         break;
01496                 }
01497                 case SID_DRAW:
01498                         if (pWin)
01499                         {
01500                                 GetDoc()->SetText( pWin->GetText() );
01501                                 SetStatusText(String());
01502                                 ShowError( 0 );
01503                 GetDoc()->Repaint();
01504                         }
01505                         break;
01506 
01507                 case SID_ADJUST:
01508         case SID_FITINWINDOW:
01509                         aGraphic.ZoomToFitInWindow();
01510                         break;
01511 
01512                 case SID_VIEW050:
01513                         aGraphic.SetZoom(50);
01514                         break;
01515 
01516                 case SID_VIEW100:
01517                         aGraphic.SetZoom(100);
01518                         break;
01519 
01520                 case SID_VIEW200:
01521                         aGraphic.SetZoom(200);
01522                         break;
01523 
01524                 case SID_ZOOMIN:
01525                         aGraphic.SetZoom(aGraphic.GetZoom() + 25);
01526                         break;
01527 
01528                 case SID_ZOOMOUT:
01529                         DBG_ASSERT(aGraphic.GetZoom() >= 25, "Sm: falsches USHORT Argument");
01530                         aGraphic.SetZoom(aGraphic.GetZoom() - 25);
01531                         break;
01532 
01533         case SID_COPYOBJECT:
01534         {
01535             //TODO/LATER: does not work because of UNO Tunneling - will be fixed later
01536             Reference< datatransfer::XTransferable > xTrans( GetDoc()->GetModel(), uno::UNO_QUERY );
01537             if( xTrans.is() )
01538             {
01539                 Reference< lang::XUnoTunnel> xTnnl( xTrans, uno::UNO_QUERY);
01540                 if( xTnnl.is() )
01541                 {
01542                     TransferableHelper* pTrans = reinterpret_cast< TransferableHelper * >(
01543                             sal::static_int_cast< sal_uIntPtr >(
01544                             xTnnl->getSomething( TransferableHelper::getUnoTunnelId() )));
01545                     if( pTrans )
01546                         pTrans->CopyToClipboard( this ? GetEditWindow() : 0 );
01547                 }
01548             }
01549         }
01550         break;
01551 
01552         case SID_PASTEOBJECT:
01553         {
01554             TransferableDataHelper aData( TransferableDataHelper::CreateFromSystemClipboard(this ? GetEditWindow(): 0) );
01555             uno::Reference < io::XInputStream > xStrm;
01556             SotFormatStringId nId;
01557             if( aData.GetTransferable().is() &&
01558                 ( aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
01559                   (aData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) &&
01560                    aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBED_SOURCE ))) &&
01561                 aData.GetInputStream( nId, xStrm ) && xStrm.is() )
01562             {
01563                 try
01564                 {
01565                     uno::Reference < embed::XStorage > xStorage =
01566                             ::comphelper::OStorageHelper::GetStorageFromInputStream( xStrm, ::comphelper::getProcessServiceFactory() );
01567                     uno::Reference < beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY );
01568                     SfxMedium aMedium( xStorage, String() );
01569                     Insert( aMedium );
01570                     GetDoc()->UpdateText();
01571                 }
01572                 catch (uno::Exception &)
01573                 {
01574                     DBG_ERROR( "SmViewShell::Execute (SID_PASTEOBJECT): failed to get storage from input stream" );
01575                 }
01576             }
01577         }
01578         break;
01579 
01580 
01581                 case SID_CUT:
01582                         if (pWin)
01583                                 pWin->Cut();
01584                         break;
01585 
01586                 case SID_COPY:
01587                         if (pWin)
01588                         {
01589                                 if (pWin->IsAllSelected())
01590                                 {
01591                     GetViewFrame()->GetDispatcher()->Execute(
01592                                                                 SID_COPYOBJECT, SFX_CALLMODE_STANDARD,
01593                                                                 new SfxVoidItem(SID_COPYOBJECT), 0L);
01594                                 }
01595                                 else
01596                                         pWin->Copy();
01597                         }
01598                         break;
01599 
01600                 case SID_PASTE:
01601                         {
01602                                 BOOL bCallExec = 0 == pWin;
01603                                 if( !bCallExec )
01604                                 {
01605                                         TransferableDataHelper aDataHelper(
01606                                                 TransferableDataHelper::CreateFromSystemClipboard(
01607                                                                                                         GetEditWindow()) );
01608 
01609                                         if( aDataHelper.GetTransferable().is() &&
01610                                                 aDataHelper.HasFormat( FORMAT_STRING ))
01611                                                 pWin->Paste();
01612                                         else
01613                                                 bCallExec = TRUE;
01614                                 }
01615                                 if( bCallExec )
01616                                 {
01617                     GetViewFrame()->GetDispatcher()->Execute(
01618                                                         SID_PASTEOBJECT, SFX_CALLMODE_STANDARD,
01619                                                         new SfxVoidItem(SID_PASTEOBJECT), 0L);
01620                                 }
01621                         }
01622                         break;
01623 
01624                 case SID_DELETE:
01625                         if (pWin)
01626                                 pWin->Delete();
01627                         break;
01628 
01629                 case SID_SELECT:
01630                         if (pWin)
01631                                 pWin->SelectAll();
01632                         break;
01633 
01634                 case SID_INSERTCOMMAND:
01635                 {
01636                         const SfxInt16Item& rItem =
01637                                 (const SfxInt16Item&)rReq.GetArgs()->Get(SID_INSERTCOMMAND);
01638 
01639                         if (pWin)
01640                                 pWin->InsertCommand(rItem.GetValue());
01641                         break;
01642                 }
01643 
01644                 case SID_INSERTTEXT:
01645                 {
01646                         const SfxStringItem& rItem =
01647                                 (const SfxStringItem&)rReq.GetArgs()->Get(SID_INSERTTEXT);
01648 
01649                         if (pWin)
01650                                 pWin->InsertText(rItem.GetValue());
01651                         break;
01652                 }
01653 
01654         case SID_INSERT_FORMULA:
01655         {
01656             delete pImpl->pRequest;
01657             pImpl->pRequest = new SfxRequest( rReq );
01658             delete pImpl->pDocInserter;
01659             pImpl->pDocInserter =
01660                 new ::sfx2::DocumentInserter( 0, GetDoc()->GetFactory().GetFactoryName(), 0 );
01661             pImpl->pDocInserter->StartExecuteModal( LINK( this, SmViewShell, DialogClosedHdl ) );
01662             return;
01663         }
01664 
01665         case SID_NEXTERR:
01666                         NextError();
01667                         if (pWin)
01668                                 pWin->GrabFocus();
01669                         break;
01670 
01671                 case SID_PREVERR:
01672                         PrevError();
01673                         if (pWin)
01674                                 pWin->GrabFocus();
01675                         break;
01676 
01677                 case SID_NEXTMARK:
01678                         if (pWin)
01679                         {
01680                                 pWin->SelNextMark();
01681                                 pWin->GrabFocus();
01682                         }
01683                         break;
01684 
01685                 case SID_PREVMARK:
01686                         if (pWin)
01687                         {
01688                                 pWin->SelPrevMark();
01689                                 pWin->GrabFocus();
01690                         }
01691                         break;
01692 
01693                 case SID_TEXTSTATUS:
01694                 {
01695                         if (rReq.GetArgs() != NULL)
01696                         {
01697                                 const SfxStringItem& rItem =
01698                                         (const SfxStringItem&)rReq.GetArgs()->Get(SID_TEXTSTATUS);
01699 
01700                                 SetStatusText(rItem.GetValue());
01701                         }
01702 
01703                         break;
01704                 }
01705 
01706                 case SID_GETEDITTEXT:
01707                         if (pWin)
01708                                 if (pWin->GetText ().Len ()) GetDoc()->SetText( pWin->GetText() );
01709                         break;
01710 
01711                 case SID_ATTR_ZOOM:
01712                 {
01713             if ( !GetViewFrame()->GetFrame()->IsInPlace() )
01714                         {
01715                                 //CHINA001 SvxZoomDialog *pDlg = 0;
01716                                 AbstractSvxZoomDialog *pDlg = 0;
01717                                 const SfxItemSet *pSet = rReq.GetArgs();
01718                                 if ( !pSet )
01719                                 {
01720                                         SfxItemSet aSet( GetDoc()->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
01721                                         aSet.Put( SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
01722                                         //CHINA001 pDlg = new SvxZoomDialog( &GetViewFrame()->GetWindow(), aSet);
01723                                         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
01724                                         if(pFact)
01725                                         {
01726                                                 pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aSet, RID_SVXDLG_ZOOM);
01727                                                 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
01728                                         }
01729                                         pDlg->SetLimits( MINZOOM, MAXZOOM );
01730                                         if( pDlg->Execute() != RET_CANCEL )
01731                                                 pSet = pDlg->GetOutputItemSet();
01732                                 }
01733                                 if ( pSet )
01734                                 {
01735                                         const SvxZoomItem &rZoom = (const SvxZoomItem &)pSet->Get(SID_ATTR_ZOOM);
01736                                         switch( rZoom.GetType() )
01737                                         {
01738                                                 case SVX_ZOOM_PERCENT:
01739                             aGraphic.SetZoom((USHORT)rZoom.GetValue ());
01740                                                         break;
01741 
01742                                                 case SVX_ZOOM_OPTIMAL:
01743                                                         aGraphic.ZoomToFitInWindow();
01744                                                         break;
01745 
01746                                                 case SVX_ZOOM_PAGEWIDTH:
01747                                                 case SVX_ZOOM_WHOLEPAGE:
01748                                                 {
01749                                                         const MapMode aMap( MAP_100TH_MM );
01750                                                         SfxPrinter *pPrinter = GetPrinter( TRUE );
01751                                                         Point aPoint;
01752                                                         Rectangle  OutputRect(aPoint, pPrinter->GetOutputSize());
01753                                                         Size       OutputSize(pPrinter->LogicToPixel(Size(OutputRect.GetWidth(),
01754                                                                                                                                                           OutputRect.GetHeight()), aMap));
01755                                                         Size       GraphicSize(pPrinter->LogicToPixel(GetDoc()->GetSize(), aMap));
01756                                                         USHORT     nZ = (USHORT) Min((long)Fraction(OutputSize.Width()  * 100L, GraphicSize.Width()),
01757                                                                                                                  (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
01758                                                         aGraphic.SetZoom (nZ);
01759                                                         break;
01760                                                 }
01761                         default:
01762                             break;
01763                                         }
01764                                 }
01765                                 delete pDlg;
01766                         }
01767                 }
01768                 break;
01769 
01770         case SID_TOOLBOX:
01771         {
01772             GetViewFrame()->ToggleChildWindow( SmToolBoxWrapper::GetChildWindowId() );
01773         }
01774         break;
01775 
01776         case SID_SYMBOLS_CATALOGUE:
01777         {
01778 
01779             // get device used to retrieve the FontList
01780             SmDocShell *pDoc = GetDoc();
01781             OutputDevice *pDev = pDoc->GetPrinter();
01782             if (!pDev || pDev->GetDevFontCount() == 0)
01783                 pDev = &SM_MOD1()->GetDefaultVirtualDev();
01784             DBG_ASSERT (pDev, "device for font list missing" );
01785 
01786             SmModule *pp = SM_MOD1();
01787             SmSymbolDialog( NULL, pDev, pp->GetSymSetManager(), *this ).Execute();
01788         }
01789         break;
01790 
01791 
01792         }
01793         rReq.Done();
01794 }
01795 
01796 
01797 void SmViewShell::GetState(SfxItemSet &rSet)
01798 {
01799     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetState" );
01800 
01801         SfxWhichIter aIter(rSet);
01802 
01803     SmEditWindow *pEditWin = GetEditWindow();
01804         for (USHORT nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich())
01805         {
01806                 switch (nWh)
01807                 {
01808                 case SID_CUT:
01809                 case SID_COPY:
01810                 case SID_DELETE:
01811             if (! pEditWin || ! pEditWin->IsSelected())
01812                                 rSet.DisableItem(nWh);
01813                         break;
01814 
01815                 case SID_PASTE:
01816             if( !xClipEvtLstnr.is()  &&  pEditWin)
01817                         {
01818                                 AddRemoveClipboardListener( TRUE );
01819                                 TransferableDataHelper aDataHelper(
01820                                                 TransferableDataHelper::CreateFromSystemClipboard(
01821                                                         pEditWin) );
01822 
01823                                 bPasteState = aDataHelper.GetTransferable().is() &&
01824                                  ( aDataHelper.HasFormat( FORMAT_STRING ) ||
01825                                    aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
01826                                    (aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
01827                                          && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE )));
01828                         }
01829                         if( !bPasteState )
01830                                 rSet.DisableItem( nWh );
01831                         break;
01832 
01833                 case SID_ATTR_ZOOM:
01834                         rSet.Put(SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
01835                         /* no break here */
01836                 case SID_VIEW050:
01837                 case SID_VIEW100:
01838                 case SID_VIEW200:
01839                 case SID_ADJUST:
01840                 case SID_ZOOMIN:
01841                 case SID_ZOOMOUT:
01842                 case SID_FITINWINDOW:
01843             if ( GetViewFrame()->GetFrame()->IsInPlace() )
01844                                 rSet.DisableItem( nWh );
01845                         break;
01846 
01847                 case SID_NEXTERR:
01848                 case SID_PREVERR:
01849                 case SID_NEXTMARK:
01850                 case SID_PREVMARK:
01851                 case SID_DRAW:
01852                 case SID_SELECT:
01853             if (! pEditWin || pEditWin->IsEmpty())
01854                                 rSet.DisableItem(nWh);
01855                         break;
01856 
01857                 case SID_TEXTSTATUS:
01858                         {
01859                                 rSet.Put(SfxStringItem(nWh, StatusText));
01860                         }
01861                         break;
01862 
01863                 case SID_FORMULACURSOR:
01864                         {
01865                                 SmModule *pp = SM_MOD1();
01866                                 rSet.Put(SfxBoolItem(nWh, pp->GetConfig()->IsShowFormulaCursor()));
01867                         }
01868                         break;
01869 
01870         case SID_TOOLBOX:
01871             {
01872                 BOOL bState = FALSE;
01873                 SfxChildWindow *pChildWnd = GetViewFrame()->
01874                         GetChildWindow( SmToolBoxWrapper::GetChildWindowId() );
01875                 if (pChildWnd  &&  pChildWnd->GetWindow()->IsVisible())
01876                     bState = TRUE;
01877                 rSet.Put(SfxBoolItem(SID_TOOLBOX, bState));
01878             }
01879             break;
01880 
01881         }
01882         }
01883 }
01884 
01885 
01886 SmViewShell::SmViewShell(SfxViewFrame *pFrame_, SfxViewShell *):
01887     SfxViewShell(pFrame_, SFX_VIEW_DISABLE_ACCELS | SFX_VIEW_MAXIMIZE_FIRST | SFX_VIEW_HAS_PRINTOPTIONS | SFX_VIEW_CAN_PRINT),
01888         aGraphic(this),
01889     aGraphicController(aGraphic, SID_GAPHIC_SM, pFrame_->GetBindings()),
01890     pImpl( new SmViewShell_Impl )
01891 {
01892     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SmViewShell" );
01893 
01894 //    pViewFrame = &pFrame_->GetWindow();
01895 
01896         SetStatusText(String());
01897         SetWindow(&aGraphic);
01898         SfxShell::SetName(C2S("SmView"));
01899         SfxShell::SetUndoManager( &GetDoc()->GetEditEngine().GetUndoManager() );
01900         SetHelpId( HID_SMA_VIEWSHELL_DOCUMENT );
01901 }
01902 
01903 
01904 SmViewShell::~SmViewShell()
01905 {
01906     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::~SmViewShell" );
01907 
01908     AddRemoveClipboardListener( FALSE );
01909 
01911     // Thus 'SmGetActiveView' will give a 0 pointer.
01912     // Thus we need to supply this view as argument
01913     SmEditWindow *pEditWin = GetEditWindow();
01914     if (pEditWin)
01915         pEditWin->DeleteEditView( *this );
01916     delete pImpl;
01917 }
01918 
01919 void SmViewShell::Deactivate( BOOL bIsMDIActivate )
01920 {
01921     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Deactivate" );
01922 
01923         SmEditWindow *pEdit = GetEditWindow();
01924         if ( pEdit )
01925                 pEdit->Flush();
01926 
01927         SfxViewShell::Deactivate( bIsMDIActivate );
01928 }
01929 
01930 
01931 void SmViewShell::Activate( BOOL bIsMDIActivate )
01932 {
01933     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Activate" );
01934 
01935         SfxViewShell::Activate( bIsMDIActivate );
01936 
01937         SmEditWindow *pEdit = GetEditWindow();
01938         if ( pEdit )
01939         {
01944         SmDocShell *pDoc = GetDoc();
01945         pDoc->SetText( pDoc->GetEditEngine().GetText( LINEEND_LF ) );
01946 
01947                 if ( bIsMDIActivate )
01948                         pEdit->GrabFocus();
01949         }
01950 }
01951 
01952 //------------------------------------------------------------------
01953 
01954 IMPL_LINK( SmViewShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
01955 {
01956     DBG_ASSERT( _pFileDlg, "SmViewShell::DialogClosedHdl(): no file dialog" );
01957     DBG_ASSERT( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
01958 
01959     if ( ERRCODE_NONE == _pFileDlg->GetError() )
01960     {
01961         //USHORT nSlot = pImpl->pRequest->GetSlot();
01962         SfxMedium* pMedium = pImpl->pDocInserter->CreateMedium();
01963 
01964         if ( pMedium != NULL )
01965         {
01966             if ( pMedium->IsStorage() )
01967                 Insert( *pMedium );
01968             else
01969                 InsertFrom( *pMedium );
01970             delete pMedium;
01971 
01972             SmDocShell* pDoc = GetDoc();
01973             pDoc->UpdateText();
01974             pDoc->ArrangeFormula();
01975             pDoc->Repaint();
01976             // adjust window, repaint, increment ModifyCount,...
01977             GetViewFrame()->GetBindings().Invalidate(SID_GAPHIC_SM);
01978         }
01979     }
01980 
01981     pImpl->pRequest->SetReturnValue( SfxBoolItem( pImpl->pRequest->GetSlot(), TRUE ) );
01982     pImpl->pRequest->Done();
01983     return 0;
01984 }
01985 

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