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

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: edit.cxx,v $
00006  *
00007  *  $Revision: 1.38 $
00008  *
00009  *  last change: $Author: vg $ $Date: 2007/05/25 12:12:44 $
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 
00053 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
00054 #include <toolkit/helper/vclunohelper.hxx>
00055 #endif
00056 
00057 
00058 #include "starmath.hrc"
00059 #define ITEMID_FONT             1
00060 #define ITEMID_FONTHEIGHT       2
00061 #define ITEMID_LRSPACE          3
00062 #define ITEMID_WEIGHT           4
00063 
00064 
00065 #ifndef _SV_MENU_HXX //autogen
00066 #include <vcl/menu.hxx>
00067 #endif
00068 #ifndef _MyEDITVIEW_HXX //autogen
00069 #include <svx/editview.hxx>
00070 #endif
00071 #ifndef _MyEDITENG_HXX //autogen
00072 #include <svx/editeng.hxx>
00073 #endif
00074 #ifndef _EDITSTAT_HXX //autogen
00075 #include <svx/editstat.hxx>
00076 #endif
00077 #ifndef _EEITEM_HXX //autogen
00078 #include <svx/eeitem.hxx>
00079 #endif
00080 #ifndef _SFXDISPATCH_HXX //autogen
00081 #include <sfx2/dispatch.hxx>
00082 #endif
00083 #ifndef _SFXINTITEM_HXX //autogen
00084 #include <svtools/intitem.hxx>
00085 #endif
00086 #ifndef _SFXITEMPOOL_HXX //autogen
00087 #include <svtools/itempool.hxx>
00088 #endif
00089 #ifndef _SFXSTRITEM_HXX //autogen
00090 #include <svtools/stritem.hxx>
00091 #endif
00092 #ifndef _SVX_FHGTITEM_HXX //autogen
00093 #include <svx/fhgtitem.hxx>
00094 #endif
00095 #ifndef _SVX_WGHTITEM_HXX //autogen
00096 #include <svx/wghtitem.hxx>
00097 #endif
00098 #ifndef _SVX_LRSPITEM_HXX //autogen
00099 #include <svx/lrspitem.hxx>
00100 #endif
00101 #ifndef _SFXITEMSET_HXX //autogen
00102 #include <svtools/itemset.hxx>
00103 #endif
00104 #ifndef _SVX_FONTITEM_HXX //autogen
00105 #include <svx/fontitem.hxx>
00106 #endif
00107 
00108 
00109 #include "edit.hxx"
00110 #include "view.hxx"
00111 #include "document.hxx"
00112 #include "config.hxx"
00113 
00114 #define SCROLL_LINE             24
00115 
00116 #define MINWIDTH                200
00117 #define MINHEIGHT               200
00118 #define MINSPLIT                40
00119 #define SPLITTERWIDTH   2
00120 
00121 
00122 using namespace com::sun::star::accessibility;
00123 using namespace com::sun::star;
00124 using namespace com::sun::star::uno;
00125 
00127 
00128 
00129 void SmGetLeftSelectionPart(const ESelection aSel,
00130                                                         USHORT &nPara, USHORT &nPos)
00131         // returns paragraph number and position of the selections left part
00132 {
00133         // compare start and end of selection and use the one that comes first
00134         if (    aSel.nStartPara <  aSel.nEndPara
00135                 ||      aSel.nStartPara == aSel.nEndPara  &&  aSel.nStartPos < aSel.nEndPos)
00136         {       nPara = aSel.nStartPara;
00137                 nPos  = aSel.nStartPos;
00138         }
00139         else
00140         {       nPara = aSel.nEndPara;
00141                 nPos  = aSel.nEndPos;
00142         }
00143 }
00144 
00146 
00147 SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
00148     Window              (&rMyCmdBoxWin),
00149     DropTargetHelper    ( this ),
00150     pAccessible         (0),
00151     rCmdBox             (rMyCmdBoxWin),
00152     pEditView           (0),
00153     pHScrollBar         (0),
00154     pVScrollBar         (0),
00155     pScrollBox          (0)
00156 {
00157         SetHelpId(HID_SMA_COMMAND_WIN_EDIT);
00158         SetMapMode(MAP_PIXEL);
00159 
00160     // Even RTL languages don't use RTL for math
00161     rCmdBox.GetEditWindow()->EnableRTL( FALSE );
00162 
00163     ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
00164 
00165     // compare DataChanged
00166         SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
00167 
00168         aModifyTimer.SetTimeoutHdl(LINK(this, SmEditWindow, ModifyTimerHdl));
00169         aModifyTimer.SetTimeout(2000);
00170         aModifyTimer.Start();
00171 
00172         aCursorMoveTimer.SetTimeoutHdl(LINK(this, SmEditWindow, CursorMoveTimerHdl));
00173         aCursorMoveTimer.SetTimeout(500);
00174 
00175         // if not called explicitly the this edit window within the
00176         // command window will just show an empty gray panel.
00177     Show();
00178 }
00179 
00180 
00181 SmEditWindow::~SmEditWindow()
00182 {
00183         aCursorMoveTimer.Stop();
00184         aModifyTimer.Stop();
00185 
00186 
00187     // #112565# clean up of classes used for accessibility
00188     // must be done before EditView (and thus EditEngine) is no longer
00189     // available for those classes.
00190     if (pAccessible)
00191         pAccessible->ClearWin();    // make Accessible defunctional
00192     // Note: memory for pAccessible will be freed when the reference
00193     // xAccessible is released.
00194 
00195     if (pEditView)
00196     {
00197         EditEngine *pEditEngine = pEditView->GetEditEngine();
00198         if (pEditEngine)
00199         {
00200             pEditEngine->SetStatusEventHdl( Link() );
00201             pEditEngine->RemoveView( pEditView );
00202         }
00203     }
00204         delete pEditView;
00205         delete pHScrollBar;
00206         delete pVScrollBar;
00207         delete pScrollBox;
00208 }
00209 
00210 
00211 SmViewShell * SmEditWindow::GetView()
00212 {
00213     return rCmdBox.GetView();
00214 }
00215 
00216 
00217 SmDocShell * SmEditWindow::GetDoc()
00218 {
00219     SmViewShell *pView = rCmdBox.GetView();
00220     return pView ? pView->GetDoc() : 0;
00221 }
00222 
00223 
00224 EditEngine * SmEditWindow::GetEditEngine()
00225 {
00226     EditEngine *pEditEng = 0;
00227     if (pEditView)
00228         pEditEng = pEditView->GetEditEngine();
00229     else
00230     {
00231         SmDocShell *pDoc = GetDoc();
00232         if (pDoc)
00233             pEditEng = &pDoc->GetEditEngine();
00234     }
00235     return pEditEng;
00236 }
00237 
00238 
00239 SfxItemPool * SmEditWindow::GetEditEngineItemPool()
00240 {
00241     SmDocShell *pDoc = GetDoc();
00242     return pDoc ? &pDoc->GetEditEngineItemPool() : 0;
00243 }
00244 
00245 void SmEditWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
00246 {
00247     // Note: SetBackground still done in SmEditWindow::DataChanged
00248 #if OSL_DEBUG_LEVEL > 1
00249 //   ColorData nVal = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
00250 #endif
00251     SetTextColor( rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor );
00252     Invalidate();
00253 }
00254 
00255 void SmEditWindow::DataChanged( const DataChangedEvent& )
00256 {
00257     const StyleSettings aSettings( GetSettings().GetStyleSettings() );
00258 
00259     ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
00260     SetBackground( aSettings.GetWindowColor() );
00261 
00262     // edit fields in other Applications use this font instead of
00263     // the application font thus we use this one too
00264     SetPointFont( aSettings.GetFieldFont() /*aSettings.GetAppFont()*/ );
00265 
00266     EditEngine  *pEditEngine = GetEditEngine();
00267     SfxItemPool *pEditEngineItemPool = GetEditEngineItemPool();
00268 
00269         if (pEditEngine && pEditEngineItemPool)
00270         {
00274 
00275                 pEditEngine->SetDefTab( USHORT( GetTextWidth( C2S("XXXX") ) ) );
00276 
00277         SetEditEngineDefaultFonts( *pEditEngine, *pEditEngineItemPool );
00278 
00279                 // forces new settings to be used
00280         // unfortunately this resets the whole edit engine
00281         // thus we need to save at least the text
00282         String aTxt( pEditEngine->GetText( LINEEND_LF ) );
00283                 pEditEngine->Clear();   //#77957 incorrect font size
00284         pEditEngine->SetText( aTxt );
00285         }
00286 
00287         AdjustScrollBars();
00288         Resize();
00289 }
00290 
00291 IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
00292 {
00293         SmModule *pp = SM_MOD1();
00294         if (pp->GetConfig()->IsAutoRedraw())
00295                 Flush();
00296         aModifyTimer.Start();
00297         return 0;
00298 }
00299 
00300 
00301 IMPL_LINK(SmEditWindow, CursorMoveTimerHdl, Timer *, EMPTYARG /*pTimer*/)
00302         // every once in a while check cursor position (selection) of edit
00303         // window and if it has changed (try to) set the formula-cursor
00304         // according to that.
00305 {
00306         ESelection      aNewSelection   (GetSelection());
00307 
00308         if (!aNewSelection.IsEqual(aOldSelection))
00309     {   SmViewShell *pView = rCmdBox.GetView();
00310 
00311                 if (pView)
00312                 {
00313                         // get row and column to look for
00314                         USHORT  nRow, nCol;
00315                         SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
00316                         nRow++;
00317                         nCol++;
00318 
00319                         pView->GetGraphicWindow().SetCursorPos(nRow, nCol);
00320 
00321                         aOldSelection = aNewSelection;
00322                 }
00323         }
00324 
00325         return 0;
00326 }
00327 
00328 
00329 void SmEditWindow::Resize()
00330 {
00331         if (!pEditView)
00332                 CreateEditView();
00333 
00334         if (pEditView)
00335         {
00336                 pEditView->SetOutputArea(AdjustScrollBars());
00337                 pEditView->ShowCursor();
00338 
00339         DBG_ASSERT( pEditView->GetEditEngine(), "EditEngine missing" );
00340                 const long nMaxVisAreaStart = pEditView->GetEditEngine()->GetTextHeight() -
00341                                                                           pEditView->GetOutputArea().GetHeight();
00342                 if (pEditView->GetVisArea().Top() > nMaxVisAreaStart)
00343                 {
00344                         Rectangle aVisArea(pEditView->GetVisArea() );
00345                         aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0;
00346                         aVisArea.SetSize(pEditView->GetOutputArea().GetSize());
00347                         pEditView->SetVisArea(aVisArea);
00348                         pEditView->ShowCursor();
00349                 }
00350                 InitScrollBars();
00351         }
00352         Invalidate();
00353 }
00354 
00355 void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
00356 {
00357         if (pEditView)
00358                 pEditView->MouseButtonUp(rEvt);
00359         else
00360                 Window::MouseButtonUp (rEvt);
00361 
00362         // ggf FormulaCursor neu positionieren
00363         CursorMoveTimerHdl(&aCursorMoveTimer);
00364 }
00365 
00366 void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)
00367 {
00368         if (pEditView)
00369                 pEditView->MouseButtonDown(rEvt);
00370         else
00371                 Window::MouseButtonDown (rEvt);
00372 
00373         GrabFocus();
00374 }
00375 
00376 void SmEditWindow::Command(const CommandEvent& rCEvt)
00377 {
00378     BOOL bForwardEvt = TRUE;
00379         if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU)
00380         {
00381                 GetParent()->ToTop();
00382 
00383         Point aPoint = rCEvt.GetMousePosPixel();
00384                 PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU));
00385 
00386         // added for replaceability of context menus #96085, #93782
00387         Menu* pMenu = NULL;
00388         ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
00389         aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
00390         aEvent.ExecutePosition.X = aPoint.X();
00391         aEvent.ExecutePosition.Y = aPoint.Y();
00392         if ( GetView()->TryContextMenuInterception( *pPopupMenu, pMenu, aEvent ) )
00393         {
00394             if ( pMenu )
00395             {
00396                 delete pPopupMenu;
00397                 pPopupMenu = (PopupMenu*) pMenu;
00398             }
00399         }
00400 
00401         pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl));
00402 
00403         pPopupMenu->Execute( this, aPoint );
00404                 delete pPopupMenu;
00405         bForwardEvt = FALSE;
00406         }
00407     else if (rCEvt.GetCommand() == COMMAND_WHEEL)
00408         bForwardEvt = !HandleWheelCommands( rCEvt );
00409 
00410     if (bForwardEvt)
00411     {
00412         if (pEditView)
00413             pEditView->Command( rCEvt );
00414         else
00415             Window::Command (rCEvt);
00416     }
00417 }
00418 
00419 
00420 BOOL SmEditWindow::HandleWheelCommands( const CommandEvent &rCEvt )
00421 {
00422     BOOL bCommandHandled = FALSE;    // true if the CommandEvent needs not
00423                                     // to be passed on (because it has fully
00424                                     // been taken care of).
00425 
00426     const CommandWheelData* pWData = rCEvt.GetWheelData();
00427     if (pWData)
00428     {
00429         if (COMMAND_WHEEL_ZOOM == pWData->GetMode())
00430             bCommandHandled = TRUE;     // no zooming in Command window
00431         else
00432             bCommandHandled = HandleScrollCommand( rCEvt, pHScrollBar, pVScrollBar);
00433     }
00434 
00435     return bCommandHandled;
00436 }
00437 
00438 
00439 IMPL_LINK_INLINE_START( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
00440 {
00441     SmViewShell *pViewSh = rCmdBox.GetView();
00442         if (pViewSh)
00443                 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
00444                                 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
00445                                 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
00446         return 0;
00447 }
00448 IMPL_LINK_INLINE_END( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
00449 
00450 void SmEditWindow::KeyInput(const KeyEvent& rKEvt)
00451 {
00452         if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
00453         {
00454                 BOOL bCallBase = TRUE;
00455                 SfxViewShell* pViewShell = GetView();
00456                 if ( pViewShell && pViewShell->ISA(SmViewShell) )
00457                 {
00458             // Terminate possible InPlace mode
00459             bCallBase = !pViewShell->Escape();
00460                 }
00461                 if ( bCallBase )
00462                         Window::KeyInput( rKEvt );
00463         }
00464         else
00465         {
00466         // Timer neu starten, um den Handler (auch bei laengeren Eingaben)
00467         // moeglichst nur einmal am Ende aufzurufen.
00468                 aCursorMoveTimer.Start();
00469 
00470         DBG_ASSERT( pEditView, "EditView missing (NULL pointer)" );
00471         if (!pEditView)
00472             CreateEditView();
00473                 if ( !pEditView->PostKeyEvent(rKEvt) )
00474                 {
00475             SmViewShell *pView = GetView();
00476             if ( pView && !pView->KeyInput(rKEvt) )
00477                         {
00478                                         /* fuert bei F1 (Hilfe) zum Zerstoeren von this! */
00479                                 Flush();
00480                                 if ( aModifyTimer.IsActive() )
00481                                         aModifyTimer.Stop();
00482                                 Window::KeyInput(rKEvt);
00483                         }
00484                         else
00485                         {
00486                                 //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack
00487                                 //im SFX) den Focus auf die View gesetzt
00488                                 SfxViewShell* pVShell = GetView();
00489                                 if ( pVShell && pVShell->ISA(SmViewShell) &&
00490                                          ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() )
00491                                 {
00492                                         GrabFocus();
00493                                 }
00494                         }
00495                 }
00496                 else
00497         {
00498             // have doc-shell modified only for formula input/change and not
00499             // cursor travelling and such things...
00500             SmDocShell *pDocShell = GetDoc();
00501             if (pDocShell)
00502                 pDocShell->SetModified( GetEditEngine()->IsModified() );
00503 
00504             aModifyTimer.Start();
00505         }
00506         }
00507 }
00508 
00509 void SmEditWindow::Paint(const Rectangle& rRect)
00510 {
00511         if (!pEditView)
00512                 CreateEditView();
00513         pEditView->Paint(rRect);
00514 }
00515 
00516 void SmEditWindow::CreateEditView()
00517 {
00518     EditEngine *pEditEngine = GetEditEngine();
00519 
00522         if (!pEditView && pEditEngine)
00523         {
00524                 pEditView = new EditView( pEditEngine, this );
00525                 pEditEngine->InsertView( pEditView );
00526 
00527         if (!pVScrollBar)
00528             pVScrollBar = new ScrollBar(this, WinBits(WB_VSCROLL));
00529         if (!pHScrollBar)
00530             pHScrollBar = new ScrollBar(this, WinBits(WB_HSCROLL));
00531         if (!pScrollBox)
00532             pScrollBox  = new ScrollBarBox(this);
00533                 pVScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
00534                 pHScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
00535         pVScrollBar->EnableDrag( TRUE );
00536         pHScrollBar->EnableDrag( TRUE );
00537 
00538                 pEditView->SetOutputArea(AdjustScrollBars());
00539 
00540                 ESelection eSelection;
00541 
00542                 pEditView->SetSelection(eSelection);
00543                 Update();
00544                 pEditView->ShowCursor(TRUE, TRUE);
00545 
00546                 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
00547                 SetPointer(pEditView->GetPointer());
00548 
00549                 SetScrollBarRanges();
00550         }
00551 }
00552 
00553 
00554 IMPL_LINK( SmEditWindow, EditStatusHdl, EditStatus *, EMPTYARG /*pStat*/ )
00555 {
00556     if (!pEditView)
00557                 return 1;
00558         else
00559         {
00560                 SetScrollBarRanges();
00561                 return 0;
00562         }
00563 }
00564 
00565 IMPL_LINK_INLINE_START( SmEditWindow, ScrollHdl, ScrollBar *, EMPTYARG /*pScrollBar*/ )
00566 {
00567     DBG_ASSERT(pEditView, "EditView missing");
00568     if (pEditView)
00569     {
00570         pEditView->SetVisArea(Rectangle(Point(pHScrollBar->GetThumbPos(),
00571                                             pVScrollBar->GetThumbPos()),
00572                                         pEditView->GetVisArea().GetSize()));
00573         pEditView->Invalidate();
00574     }
00575         return 0;
00576 }
00577 IMPL_LINK_INLINE_END( SmEditWindow, ScrollHdl, ScrollBar *, pScrollBar )
00578 
00579 Rectangle SmEditWindow::AdjustScrollBars()
00580 {
00581         const Size aOut( GetOutputSizePixel() );
00582         Point aPoint;
00583         Rectangle aRect( aPoint, aOut );
00584 
00585         if (pVScrollBar && pHScrollBar && pScrollBox)
00586         {
00587                 const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
00588                 Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L;
00589                 pVScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp));
00590 
00591                 aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L;
00592                 pHScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp));
00593 
00594                 aPt.X() = pHScrollBar->GetSizePixel().Width();
00595                 aPt.Y() = pVScrollBar->GetSizePixel().Height();
00596                 pScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp ));
00597 
00598                 aRect.Right()  = aPt.X() - 2;
00599                 aRect.Bottom() = aPt.Y() - 2;
00600         }
00601         return aRect;
00602 }
00603 
00604 void SmEditWindow::SetScrollBarRanges()
00605 {
00606         // Extra-Methode, nicht InitScrollBars, da auch fuer EditEngine-Events.
00607     EditEngine *pEditEngine = GetEditEngine();
00608         if (pVScrollBar && pHScrollBar && pEditEngine && pEditView)
00609         {
00610                 long nTmp = pEditEngine->GetTextHeight();
00611                 pVScrollBar->SetRange(Range(0, nTmp));
00612                 pVScrollBar->SetThumbPos(pEditView->GetVisArea().Top());
00613 
00614                 nTmp = pEditEngine->GetPaperSize().Width();
00615                 pHScrollBar->SetRange(Range(0,nTmp));
00616                 pHScrollBar->SetThumbPos(pEditView->GetVisArea().Left());
00617         }
00618 }
00619 
00620 void SmEditWindow::InitScrollBars()
00621 {
00622     if (pVScrollBar && pHScrollBar && pScrollBox && pEditView)
00623         {
00624                 const Size aOut( pEditView->GetOutputArea().GetSize() );
00625                 pVScrollBar->SetVisibleSize(aOut.Height());
00626                 pVScrollBar->SetPageSize(aOut.Height() * 8 / 10);
00627                 pVScrollBar->SetLineSize(aOut.Height() * 2 / 10);
00628 
00629                 pHScrollBar->SetVisibleSize(aOut.Width());
00630                 pHScrollBar->SetPageSize(aOut.Width() * 8 / 10);
00631                 pHScrollBar->SetLineSize(SCROLL_LINE );
00632 
00633                 SetScrollBarRanges();
00634 
00635                 pVScrollBar->Show();
00636                 pHScrollBar->Show();
00637                 pScrollBox->Show();
00638         }
00639 }
00640 
00641 
00642 String SmEditWindow::GetText() const
00643 {
00644         String aText;
00645     EditEngine *pEditEngine = const_cast< SmEditWindow* >(this)->GetEditEngine();
00646         DBG_ASSERT( pEditEngine, "EditEngine missing" );
00647         if (pEditEngine)
00648                 aText = pEditEngine->GetText( LINEEND_LF );
00649         return aText;
00650 }
00651 
00652 
00653 void SmEditWindow::SetText(const XubString& rText)
00654 {
00655     EditEngine *pEditEngine = GetEditEngine();
00656         DBG_ASSERT( pEditEngine, "EditEngine missing" );
00657         if (pEditEngine  &&  !pEditEngine->IsModified())
00658         {
00659                 if (!pEditView)
00660                         CreateEditView();
00661 
00662                 ESelection eSelection = pEditView->GetSelection();
00663 
00664                 pEditEngine->SetText(rText);
00665                 pEditEngine->ClearModifyFlag();
00666 
00669                 aModifyTimer.Start();
00670                 aCursorMoveTimer.Start();
00671 
00672                 pEditView->SetSelection(eSelection);
00673         }
00674 }
00675 
00676 
00677 void SmEditWindow::GetFocus()
00678 {
00679         Window::GetFocus();
00680 
00681     if (xAccessible.is())
00682     {
00683         // Note: will implicitly send the AccessibleStateType::FOCUSED event
00684         ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
00685         if (pHelper)
00686             pHelper->SetFocus( sal_True );
00687     }
00688 
00689     if (!pEditView)
00690          CreateEditView();
00691     EditEngine *pEditEngine = GetEditEngine();
00692         if (pEditEngine)
00693                 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
00694 }
00695 
00696 
00697 void SmEditWindow::LoseFocus()
00698 {
00699     EditEngine *pEditEngine = GetEditEngine();
00700         if (pEditEngine)
00701                 pEditEngine->SetStatusEventHdl( Link() );
00702 
00703         Window::LoseFocus();
00704 
00705     if (xAccessible.is())
00706     {
00707         // Note: will implicitly send the AccessibleStateType::FOCUSED event
00708         ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
00709         if (pHelper)
00710             pHelper->SetFocus( sal_False );
00711     }
00712 }
00713 
00714 
00715 BOOL SmEditWindow::IsAllSelected() const
00716 {
00717     BOOL bRes = FALSE;
00718     EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
00719         DBG_ASSERT( pEditView, "NULL pointer" );
00720     DBG_ASSERT( pEditEngine, "NULL pointer" );
00721     if (pEditEngine  &&  pEditView)
00722     {
00723         ESelection eSelection( pEditView->GetSelection() );
00724         INT32 nParaCnt = pEditEngine->GetParagraphCount();
00725         if (!(nParaCnt - 1))
00726         {
00727             String Text( pEditEngine->GetText( LINEEND_LF ) );
00728             bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1);
00729         }
00730         else
00731         {
00732             bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
00733         }
00734     }
00735     return bRes;
00736 }
00737 
00738 void SmEditWindow::SelectAll()
00739 {
00740         DBG_ASSERT( pEditView, "NULL pointer" );
00741         if (pEditView)
00742         {
00743                 // 0xFFFF as last two parameters refers to the end of the text
00744                 pEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
00745         }
00746 }
00747 
00748 void SmEditWindow::InsertCommand(USHORT nCommand)
00749 {
00750     DBG_ASSERT( pEditView, "EditView missing" );
00751     if (pEditView)
00752     {
00753         //Anfang der Selektion merken und hinterher den Cursor daraufsetzen. Nur so
00754         //macht das SelNextMark() Sinn.
00755         ESelection aSelection = pEditView->GetSelection();
00756         aSelection.nEndPos  = aSelection.nStartPos;
00757         aSelection.nEndPara = aSelection.nStartPara;
00758 
00759         DBG_ASSERT( pEditView, "NULL pointer" );
00760         String  aText = String(SmResId(nCommand));
00761         pEditView->InsertText(aText);
00762 
00763         if (HasMark(aText))
00764         {   // set selection to next mark
00765             pEditView->SetSelection(aSelection);
00766             SelNextMark();
00767         }
00768         else
00769         {   // set selection after inserted text
00770             aSelection.nEndPos    = aSelection.nEndPos + sal::static_int_cast< xub_StrLen >(aText.Len());
00771             aSelection.nStartPos  = aSelection.nEndPos;
00772             pEditView->SetSelection(aSelection);
00773         }
00774 
00775         GrabFocus();
00776     }
00777 }
00778 
00779 void SmEditWindow::MarkError(const Point &rPos)
00780 {
00781     DBG_ASSERT( pEditView, "EditView missing" );
00782     if (pEditView)
00783     {
00784         const xub_StrLen    nCol = sal::static_int_cast< xub_StrLen >(rPos.X());
00785         const USHORT        nRow = sal::static_int_cast< USHORT >(rPos.Y() - 1);
00786 
00787         pEditView->SetSelection(ESelection(nRow, nCol - 1, nRow, nCol));
00788         GrabFocus();
00789     }
00790 }
00791 
00792 void SmEditWindow::SelNextMark()
00793 {
00794     EditEngine *pEditEngine = GetEditEngine();
00795         DBG_ASSERT( pEditView, "NULL pointer" );
00796         DBG_ASSERT( pEditEngine, "NULL pointer" );
00797     if (pEditEngine  &&  pEditView)
00798     {
00799         ESelection eSelection = pEditView->GetSelection();
00800         USHORT     Pos        = eSelection.nEndPos;
00801         String     aMark (C2S("<?>"));
00802         String     aText;
00803         USHORT     nCounts    = pEditEngine->GetParagraphCount();
00804 
00805         while (eSelection.nEndPara < nCounts)
00806         {
00807             aText = pEditEngine->GetText( eSelection.nEndPara );
00808             Pos   = aText.Search(aMark, Pos);
00809 
00810             if (Pos != STRING_NOTFOUND)
00811             {
00812                 pEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3));
00813                 break;
00814             }
00815 
00816             Pos = 0;
00817             eSelection.nEndPara++;
00818         }
00819     }
00820 }
00821 
00822 void SmEditWindow::SelPrevMark()
00823 {
00824     EditEngine *pEditEngine = GetEditEngine();
00825         DBG_ASSERT( pEditEngine, "NULL pointer" );
00826         DBG_ASSERT( pEditView, "NULL pointer" );
00827     if (pEditEngine  &&  pEditView)
00828     {
00829         ESelection eSelection = pEditView->GetSelection();
00830         USHORT     Pos        = STRING_NOTFOUND;
00831         xub_StrLen Max        = eSelection.nStartPos;
00832         String     Text( pEditEngine->GetText( eSelection.nStartPara ) );
00833         String     aMark (C2S("<?>"));
00834         USHORT     nCounts    = pEditEngine->GetParagraphCount();
00835 
00836         do
00837         {
00838             USHORT Fnd = Text.Search(aMark, 0);
00839 
00840             while ((Fnd < Max) && (Fnd != STRING_NOTFOUND))
00841             {
00842                 Pos = Fnd;
00843                 Fnd = Text.Search(aMark, Fnd + 1);
00844             }
00845 
00846             if (Pos == STRING_NOTFOUND)
00847             {
00848                 eSelection.nStartPara--;
00849                 Text = pEditEngine->GetText( eSelection.nStartPara );
00850                 Max = Text.Len();
00851             }
00852         }
00853         while ((eSelection.nStartPara < nCounts) &&
00854             (Pos == STRING_NOTFOUND));
00855 
00856         if (Pos != STRING_NOTFOUND)
00857         {
00858             pEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3));
00859         }
00860     }
00861 }
00862 
00863 BOOL SmEditWindow::HasMark(const String& rText) const
00864         // returns true iff 'rText' contains a mark
00865 {
00866         return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND;
00867 }
00868 
00869 void SmEditWindow::MouseMove(const MouseEvent &rEvt)
00870 {
00871         if (pEditView)
00872                 pEditView->MouseMove(rEvt);
00873 }
00874 
00875 sal_Int8 SmEditWindow::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
00876 {
00877         return pEditView ? /*pEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE;
00878 }
00879 
00880 sal_Int8 SmEditWindow::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
00881 {
00882         return pEditView ? /*pEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE;
00883 }
00884 
00885 ESelection SmEditWindow::GetSelection() const
00886 {
00887     // pointer may be 0 when reloading a document and the old view
00888     // was already destroyed
00889     //(DBG_ASSERT( pEditView, "NULL pointer" );
00890         ESelection eSel;
00891         if (pEditView)
00892                 eSel = pEditView->GetSelection();
00893         return eSel;
00894 }
00895 
00896 void SmEditWindow::SetSelection(const ESelection &rSel)
00897 {
00898         DBG_ASSERT( pEditView, "NULL pointer" );
00899     if (pEditView)
00900         pEditView->SetSelection(rSel);
00901 }
00902 
00903 BOOL SmEditWindow::IsEmpty() const
00904 {
00905     EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
00906     BOOL bEmpty = sal::static_int_cast< BOOL >(
00907                     pEditEngine ? pEditEngine->GetTextLen() == 0 : FALSE);
00908     return bEmpty;
00909 }
00910 
00911 BOOL SmEditWindow::IsSelected() const
00912 {
00913     return pEditView ? pEditView->HasSelection() : FALSE;
00914 }
00915 
00916 void SmEditWindow::Cut()
00917 {
00918     DBG_ASSERT( pEditView, "EditView missing" );
00919     if (pEditView)
00920         pEditView->Cut();
00921 }
00922 
00923 void SmEditWindow::Copy()
00924 {
00925     DBG_ASSERT( pEditView, "EditView missing" );
00926     if (pEditView)
00927         pEditView->Copy();
00928 }
00929 
00930 void SmEditWindow::Paste()
00931 {
00932     DBG_ASSERT( pEditView, "EditView missing" );
00933     if (pEditView)
00934         pEditView->Paste();
00935 }
00936 
00937 void SmEditWindow::Delete()
00938 {
00939     DBG_ASSERT( pEditView, "EditView missing" );
00940     if (pEditView)
00941         pEditView->DeleteSelected();
00942 }
00943 
00944 void SmEditWindow::InsertText(const String& Text)
00945 {
00946     DBG_ASSERT( pEditView, "EditView missing" );
00947     if (pEditView)
00948         pEditView->InsertText(Text);
00949 }
00950 
00951 void SmEditWindow::Flush()
00952 {
00953     EditEngine *pEditEngine = GetEditEngine();
00954         if (pEditEngine  &&  pEditEngine->IsModified())
00955         {
00956                 pEditEngine->ClearModifyFlag();
00957         SmViewShell *pViewSh = rCmdBox.GetView();
00958                 if (pViewSh)
00959                         pViewSh->GetViewFrame()->GetDispatcher()->Execute(
00960                                         SID_TEXT, SFX_CALLMODE_STANDARD,
00961                                         new SfxStringItem(SID_TEXT, GetText()), 0L);
00962         }
00963 
00964         if (aCursorMoveTimer.IsActive())
00965         {
00966                 aCursorMoveTimer.Stop();
00967                 // ggf noch die (neue) FormulaCursor Position setzen
00968                 CursorMoveTimerHdl(&aCursorMoveTimer);
00969         }
00970 }
00971 
00972 
00973 void SmEditWindow::DeleteEditView( SmViewShell & /*rView*/ )
00974 {
00975     if (pEditView)
00976     {
00977         EditEngine *pEditEngine = pEditView->GetEditEngine();
00978         if (pEditEngine)
00979         {
00980             pEditEngine->SetStatusEventHdl( Link() );
00981             pEditEngine->RemoveView( pEditView );
00982         }
00983         delete pEditView;
00984         pEditView = 0;
00985     }
00986 }
00987 
00988 
00989 uno::Reference< XAccessible > SmEditWindow::CreateAccessible()
00990 {
00991     if (!pAccessible)
00992     {
00993         pAccessible = new SmEditAccessible( this );
00994         xAccessible = pAccessible;
00995         pAccessible->Init();
00996     }
00997     return xAccessible;
00998 }
00999 

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