1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "EditWindow.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "sdmod.hxx" 34*cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 35*cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp> 36*cdf0e10cSrcweir #include <editeng/editeng.hxx> 37*cdf0e10cSrcweir #include <editeng/editview.hxx> 38*cdf0e10cSrcweir #include <vcl/scrbar.hxx> 39*cdf0e10cSrcweir #include <editeng/eeitem.hxx> 40*cdf0e10cSrcweir #include "sdresid.hxx" 41*cdf0e10cSrcweir #include <svl/itempool.hxx> 42*cdf0e10cSrcweir #include <editeng/fhgtitem.hxx> 43*cdf0e10cSrcweir #include <vos/mutex.hxx> 44*cdf0e10cSrcweir #include <vcl/svapp.hxx> 45*cdf0e10cSrcweir #include <unotools/linguprops.hxx> 46*cdf0e10cSrcweir #include <unotools/lingucfg.hxx> 47*cdf0e10cSrcweir #include <editeng/fontitem.hxx> 48*cdf0e10cSrcweir #include <editeng/editstat.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #define SCROLL_LINE 24 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir using namespace com::sun::star::accessibility; 53*cdf0e10cSrcweir using namespace com::sun::star; 54*cdf0e10cSrcweir using namespace com::sun::star::uno; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir namespace sd { namespace notes { 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir EditWindow::EditWindow (Window* pParentWindow, SfxItemPool* pItemPool) 59*cdf0e10cSrcweir : Window (pParentWindow, WinBits()), 60*cdf0e10cSrcweir DropTargetHelper(this), 61*cdf0e10cSrcweir mpEditView(NULL), 62*cdf0e10cSrcweir mpEditEngine(NULL), 63*cdf0e10cSrcweir mpHorizontalScrollBar(NULL), 64*cdf0e10cSrcweir mpVerticalScrollBar(NULL), 65*cdf0e10cSrcweir mpScrollBox(NULL) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir SetMapMode(MAP_PIXEL); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // compare DataChanged 70*cdf0e10cSrcweir SetBackground (GetSettings().GetStyleSettings().GetWindowColor()); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir maModifyTimer.SetTimeout(2000); 73*cdf0e10cSrcweir maModifyTimer.Start(); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir maCursorMoveTimer.SetTimeout(500); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir CreateEditView(); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir SvxFontHeightItem aItem (GetFont().GetSize().Height(), 100, 80*cdf0e10cSrcweir EE_CHAR_FONTHEIGHT); 81*cdf0e10cSrcweir pItemPool->SetPoolDefaultItem (aItem); 82*cdf0e10cSrcweir aItem.SetWhich(EE_CHAR_FONTHEIGHT_CJK); 83*cdf0e10cSrcweir pItemPool->SetPoolDefaultItem (aItem); 84*cdf0e10cSrcweir aItem.SetWhich(EE_CHAR_FONTHEIGHT_CTL); 85*cdf0e10cSrcweir pItemPool->SetPoolDefaultItem (aItem); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir InsertText (UniString::CreateFromAscii("EditWindow created and ready.\n")); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir EditWindow::~EditWindow (void) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir maCursorMoveTimer.Stop(); 94*cdf0e10cSrcweir maModifyTimer.Stop(); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir if (mpEditView != NULL) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir EditEngine *pEditEngine = mpEditView->GetEditEngine(); 99*cdf0e10cSrcweir if (pEditEngine) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir pEditEngine->SetStatusEventHdl(Link()); 102*cdf0e10cSrcweir pEditEngine->RemoveView (mpEditView); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir delete mpEditView; 106*cdf0e10cSrcweir delete mpHorizontalScrollBar; 107*cdf0e10cSrcweir delete mpVerticalScrollBar; 108*cdf0e10cSrcweir delete mpScrollBox; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir //////////////////////////////////////// 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir void SmGetLeftSelectionPart(const ESelection aSel, 116*cdf0e10cSrcweir sal_uInt16 &nPara, sal_uInt16 &nPos) 117*cdf0e10cSrcweir // returns paragraph number and position of the selections left part 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir // compare start and end of selection and use the one that comes first 120*cdf0e10cSrcweir if ( 121*cdf0e10cSrcweir (aSel.nStartPara < aSel.nEndPara) || 122*cdf0e10cSrcweir (aSel.nStartPara == aSel.nEndPara && aSel.nStartPos < aSel.nEndPos) 123*cdf0e10cSrcweir ) 124*cdf0e10cSrcweir { nPara = aSel.nStartPara; 125*cdf0e10cSrcweir nPos = aSel.nStartPos; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir else 128*cdf0e10cSrcweir { nPara = aSel.nEndPara; 129*cdf0e10cSrcweir nPos = aSel.nEndPos; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir EditEngine * EditWindow::GetEditEngine (void) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir if (mpEditEngine == NULL) 139*cdf0e10cSrcweir mpEditEngine = CreateEditEngine (); 140*cdf0e10cSrcweir return mpEditEngine; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir EditEngine* EditWindow::CreateEditEngine (void) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir EditEngine* pEditEngine = mpEditEngine; 149*cdf0e10cSrcweir if (pEditEngine == NULL) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir mpEditEngineItemPool = EditEngine::CreatePool(); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // 154*cdf0e10cSrcweir // set fonts to be used 155*cdf0e10cSrcweir // 156*cdf0e10cSrcweir SvtLinguOptions aOpt; 157*cdf0e10cSrcweir SvtLinguConfig().GetOptions( aOpt ); 158*cdf0e10cSrcweir // 159*cdf0e10cSrcweir struct FontDta { 160*cdf0e10cSrcweir sal_Int16 nFallbackLang; 161*cdf0e10cSrcweir sal_Int16 nLang; 162*cdf0e10cSrcweir sal_uInt16 nFontType; 163*cdf0e10cSrcweir sal_uInt16 nFontInfoId; 164*cdf0e10cSrcweir } aTable[3] = 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir // info to get western font to be used 167*cdf0e10cSrcweir { LANGUAGE_ENGLISH_US, LANGUAGE_NONE, 168*cdf0e10cSrcweir DEFAULTFONT_SERIF, EE_CHAR_FONTINFO }, 169*cdf0e10cSrcweir // info to get CJK font to be used 170*cdf0e10cSrcweir { LANGUAGE_JAPANESE, LANGUAGE_NONE, 171*cdf0e10cSrcweir DEFAULTFONT_CJK_TEXT, EE_CHAR_FONTINFO_CJK }, 172*cdf0e10cSrcweir // info to get CTL font to be used 173*cdf0e10cSrcweir { LANGUAGE_ARABIC_SAUDI_ARABIA, LANGUAGE_NONE, 174*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT, EE_CHAR_FONTINFO_CTL } 175*cdf0e10cSrcweir }; 176*cdf0e10cSrcweir aTable[0].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN); 177*cdf0e10cSrcweir aTable[1].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN); 178*cdf0e10cSrcweir aTable[2].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX); 179*cdf0e10cSrcweir // 180*cdf0e10cSrcweir for (int i = 0; i < 3; ++i) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir const FontDta &rFntDta = aTable[i]; 183*cdf0e10cSrcweir LanguageType nLang = (LANGUAGE_NONE == rFntDta.nLang) ? 184*cdf0e10cSrcweir rFntDta.nFallbackLang : rFntDta.nLang; 185*cdf0e10cSrcweir Font aFont = Application::GetDefaultDevice()->GetDefaultFont( 186*cdf0e10cSrcweir rFntDta.nFontType, nLang, DEFAULTFONT_FLAGS_ONLYONE); 187*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( 188*cdf0e10cSrcweir SvxFontItem( 189*cdf0e10cSrcweir aFont.GetFamily(), 190*cdf0e10cSrcweir aFont.GetName(), 191*cdf0e10cSrcweir aFont.GetStyleName(), 192*cdf0e10cSrcweir aFont.GetPitch(), 193*cdf0e10cSrcweir aFont.GetCharSet(), 194*cdf0e10cSrcweir rFntDta.nFontInfoId)); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // set font heights 198*cdf0e10cSrcweir SvxFontHeightItem aFontHeigt( 199*cdf0e10cSrcweir Application::GetDefaultDevice()->LogicToPixel( 200*cdf0e10cSrcweir Size (0, 10), MapMode (MAP_POINT)).Height(), 100, 201*cdf0e10cSrcweir EE_CHAR_FONTHEIGHT ); 202*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt); 203*cdf0e10cSrcweir aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CJK); 204*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt); 205*cdf0e10cSrcweir aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CTL); 206*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir pEditEngine = new EditEngine (mpEditEngineItemPool); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir pEditEngine->EnableUndo (sal_True); 211*cdf0e10cSrcweir pEditEngine->SetDefTab (sal_uInt16( 212*cdf0e10cSrcweir Application::GetDefaultDevice()->GetTextWidth( 213*cdf0e10cSrcweir UniString::CreateFromAscii("XXXX")))); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir pEditEngine->SetControlWord( 216*cdf0e10cSrcweir (pEditEngine->GetControlWord() 217*cdf0e10cSrcweir | EE_CNTRL_AUTOINDENTING) & 218*cdf0e10cSrcweir (~EE_CNTRL_UNDOATTRIBS) & 219*cdf0e10cSrcweir (~EE_CNTRL_PASTESPECIAL)); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir pEditEngine->SetWordDelimiters ( 222*cdf0e10cSrcweir UniString::CreateFromAscii(" .=+-*/(){}[];\"")); 223*cdf0e10cSrcweir pEditEngine->SetRefMapMode (MAP_PIXEL); 224*cdf0e10cSrcweir pEditEngine->SetPaperSize (Size(800, 0)); 225*cdf0e10cSrcweir pEditEngine->EraseVirtualDevice(); 226*cdf0e10cSrcweir pEditEngine->ClearModifyFlag(); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir return pEditEngine; 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir void EditWindow::DataChanged (const DataChangedEvent&) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir const StyleSettings aSettings (GetSettings().GetStyleSettings()); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir SetBackground( aSettings.GetWindowColor() ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir // edit fields in other Applications use this font instead of 242*cdf0e10cSrcweir // the application font thus we use this one too 243*cdf0e10cSrcweir SetPointFont( aSettings.GetFieldFont() ); 244*cdf0e10cSrcweir EditEngine* pEditEngine = GetEditEngine(); 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir if (pEditEngine!=NULL && mpEditEngineItemPool!=NULL) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir //! 249*cdf0e10cSrcweir //! see also SmDocShell::GetEditEngine() ! 250*cdf0e10cSrcweir //! 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir // pEditEngine->SetDefTab( sal_uInt16( GetTextWidth( C2S("XXXX") ) ) ); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir sal_uInt16 aFntInfoId[3] = { 255*cdf0e10cSrcweir EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL }; 256*cdf0e10cSrcweir for (int i = 0; i < 3; ++i) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir const SfxPoolItem *pItem = mpEditEngineItemPool->GetPoolDefaultItem( aFntInfoId[i] ); 259*cdf0e10cSrcweir if( pItem ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir const SvxFontItem *pFntItem = ((const SvxFontItem *) pItem); 262*cdf0e10cSrcweir const Font &rFnt = aSettings.GetFieldFont(); 263*cdf0e10cSrcweir SvxFontItem aFntItem( rFnt.GetFamily(), rFnt.GetName(), 264*cdf0e10cSrcweir rFnt.GetStyleName(), rFnt.GetPitch(), 265*cdf0e10cSrcweir pFntItem->GetCharSet(), 266*cdf0e10cSrcweir aFntInfoId[i] ); 267*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( aFntItem ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir SvxFontHeightItem aItem( GetFont().GetSize().Height(), 100, 272*cdf0e10cSrcweir EE_CHAR_FONTHEIGHT ); 273*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( aItem ); 274*cdf0e10cSrcweir aItem.SetWhich( EE_CHAR_FONTHEIGHT_CJK ); 275*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( aItem ); 276*cdf0e10cSrcweir aItem.SetWhich( EE_CHAR_FONTHEIGHT_CTL ); 277*cdf0e10cSrcweir mpEditEngineItemPool->SetPoolDefaultItem( aItem ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir // forces new settings to be used 280*cdf0e10cSrcweir // unfortunately this resets the whole edit engine 281*cdf0e10cSrcweir // thus we need to save at least the text 282*cdf0e10cSrcweir String aTxt( pEditEngine->GetText( LINEEND_LF ) ); 283*cdf0e10cSrcweir pEditEngine->Clear(); //#77957 incorrect font size 284*cdf0e10cSrcweir pEditEngine->SetText( aTxt ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir String aText (mpEditEngine->GetText (LINEEND_LF)); 288*cdf0e10cSrcweir mpEditEngine->Clear(); 289*cdf0e10cSrcweir mpEditEngine->SetText (aText); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir AdjustScrollBars(); 292*cdf0e10cSrcweir Resize(); 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir void EditWindow::Resize (void) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir if (!mpEditView) 301*cdf0e10cSrcweir CreateEditView(); 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir if (mpEditView != NULL) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir mpEditView->SetOutputArea(AdjustScrollBars()); 306*cdf0e10cSrcweir mpEditView->ShowCursor(); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir DBG_ASSERT( mpEditView->GetEditEngine(), "EditEngine missing" ); 309*cdf0e10cSrcweir const long nMaxVisAreaStart = mpEditView->GetEditEngine()->GetTextHeight() - 310*cdf0e10cSrcweir mpEditView->GetOutputArea().GetHeight(); 311*cdf0e10cSrcweir if (mpEditView->GetVisArea().Top() > nMaxVisAreaStart) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir Rectangle aVisArea(mpEditView->GetVisArea() ); 314*cdf0e10cSrcweir aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0; 315*cdf0e10cSrcweir aVisArea.SetSize(mpEditView->GetOutputArea().GetSize()); 316*cdf0e10cSrcweir mpEditView->SetVisArea(aVisArea); 317*cdf0e10cSrcweir mpEditView->ShowCursor(); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir InitScrollBars(); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir Invalidate(); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir void EditWindow::MouseButtonUp(const MouseEvent &rEvt) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir if (mpEditView != NULL) 330*cdf0e10cSrcweir mpEditView->MouseButtonUp(rEvt); 331*cdf0e10cSrcweir else 332*cdf0e10cSrcweir Window::MouseButtonUp (rEvt); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir // ggf FormulaCursor neu positionieren 335*cdf0e10cSrcweir // CursorMoveTimerHdl(&aCursorMoveTimer); 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir void EditWindow::MouseButtonDown(const MouseEvent &rEvt) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir if (mpEditView != NULL) 344*cdf0e10cSrcweir mpEditView->MouseButtonDown(rEvt); 345*cdf0e10cSrcweir else 346*cdf0e10cSrcweir Window::MouseButtonDown (rEvt); 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir GrabFocus(); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir void EditWindow::Command(const CommandEvent& rCEvt) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir /* if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir GetParent()->ToTop(); 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir Point aPoint = rCEvt.GetMousePosPixel(); 361*cdf0e10cSrcweir PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU)); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir // added for replaceability of context menus #96085, #93782 364*cdf0e10cSrcweir Menu* pMenu = NULL; 365*cdf0e10cSrcweir ::com::sun::star::ui::ContextMenuExecuteEvent aEvent; 366*cdf0e10cSrcweir aEvent.SourceWindow = VCLUnoHelper::GetInterface( this ); 367*cdf0e10cSrcweir aEvent.ExecutePosition.X = aPoint.X(); 368*cdf0e10cSrcweir aEvent.ExecutePosition.Y = aPoint.Y(); 369*cdf0e10cSrcweir if ( GetView()->TryContextMenuInterception( *pPopupMenu, pMenu, aEvent ) ) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir if ( pMenu ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir delete pPopupMenu; 374*cdf0e10cSrcweir pPopupMenu = (PopupMenu*) pMenu; 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir pPopupMenu->SetSelectHdl(LINK(this, EditWindow, MenuSelectHdl)); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir pPopupMenu->Execute( this, aPoint ); 381*cdf0e10cSrcweir delete pPopupMenu; 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir else*/ if (mpEditView) 384*cdf0e10cSrcweir mpEditView->Command( rCEvt ); 385*cdf0e10cSrcweir else 386*cdf0e10cSrcweir Window::Command (rCEvt); 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir IMPL_LINK_INLINE_START( EditWindow, MenuSelectHdl, Menu *, EMPTYARG ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir /* SmViewShell *pViewSh = rCmdBox.GetView(); 392*cdf0e10cSrcweir if (pViewSh) 393*cdf0e10cSrcweir pViewSh->GetViewFrame()->GetDispatcher()->Execute( 394*cdf0e10cSrcweir SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD, 395*cdf0e10cSrcweir new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L); 396*cdf0e10cSrcweir */ 397*cdf0e10cSrcweir return 0; 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir IMPL_LINK_INLINE_END( EditWindow, MenuSelectHdl, Menu *, EMPTYARG ) 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir void EditWindow::KeyInput(const KeyEvent& ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir /* if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir sal_Bool bCallBase = sal_True; 406*cdf0e10cSrcweir SfxViewShell* pViewShell = SfxViewShell::Current(); 407*cdf0e10cSrcweir if ( pViewShell && pViewShell->ISA(SmViewShell) ) 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir SmDocShell* pDocSh = (SmDocShell*) pViewShell->GetViewFrame()->GetObjectShell(); 410*cdf0e10cSrcweir if (pDocSh) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir // fuert zum (sofortigen) Zerstoeren von this! 413*cdf0e10cSrcweir pDocSh->DoInPlaceActivate( sal_False ); 414*cdf0e10cSrcweir bCallBase = sal_False; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir if ( bCallBase ) 418*cdf0e10cSrcweir Window::KeyInput( rKEvt ); 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir else 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir // Timer neu starten, um den Handler (auch bei l�ngeren Eingaben) 423*cdf0e10cSrcweir // m�glichst nur einmal am Ende aufzurufen. 424*cdf0e10cSrcweir aCursorMoveTimer.Start(); 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "EditView missing (NULL pointer)" ); 427*cdf0e10cSrcweir if (!mpEditView) 428*cdf0e10cSrcweir CreateEditView(); 429*cdf0e10cSrcweir if ( !mpEditView->PostKeyEvent(rKEvt) ) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir if ( !SfxViewShell::Current()->KeyInput(rKEvt) ) 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir // fuert bei F1 (Hilfe) zum Zerstoeren von this! 434*cdf0e10cSrcweir Flush(); 435*cdf0e10cSrcweir if ( aModifyTimer.IsActive() ) 436*cdf0e10cSrcweir aModifyTimer.Stop(); 437*cdf0e10cSrcweir Window::KeyInput(rKEvt); 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir else 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack 442*cdf0e10cSrcweir //im SFX) den Focus auf die View gesetzt 443*cdf0e10cSrcweir SfxViewShell* pVShell = SfxViewShell::Current(); 444*cdf0e10cSrcweir if ( pVShell && pVShell->ISA(SmViewShell) && 445*cdf0e10cSrcweir ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() ) 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir GrabFocus(); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir else 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir // have doc-shell modified only for formula input/change and not 454*cdf0e10cSrcweir // cursor travelling and such things... 455*cdf0e10cSrcweir SmDocShell *pDocShell = GetDoc(); 456*cdf0e10cSrcweir if (pDocShell) 457*cdf0e10cSrcweir pDocShell->SetModified( GetEditEngine()->IsModified() ); 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir aModifyTimer.Start(); 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir */ 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir void EditWindow::Paint(const Rectangle& rRect) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir if (!mpEditView) 471*cdf0e10cSrcweir CreateEditView(); 472*cdf0e10cSrcweir mpEditView->Paint(rRect); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir void EditWindow::CreateEditView (void) 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir EditEngine* pEditEngine = GetEditEngine(); 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir //! pEditEngine and mpEditView may be 0. 483*cdf0e10cSrcweir //! For example when the program is used by the document-converter 484*cdf0e10cSrcweir if (mpEditView==NULL && pEditEngine!=NULL) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir mpEditView = new EditView (pEditEngine, this); 487*cdf0e10cSrcweir pEditEngine->InsertView (mpEditView); 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir if (mpVerticalScrollBar == NULL) 490*cdf0e10cSrcweir mpVerticalScrollBar = new ScrollBar ( 491*cdf0e10cSrcweir this, WinBits(WB_VSCROLL | WB_DRAG)); 492*cdf0e10cSrcweir if (mpHorizontalScrollBar == NULL) 493*cdf0e10cSrcweir mpHorizontalScrollBar = new ScrollBar ( 494*cdf0e10cSrcweir this, WinBits(WB_HSCROLL | WB_DRAG)); 495*cdf0e10cSrcweir if (mpScrollBox == NULL) 496*cdf0e10cSrcweir mpScrollBox = new ScrollBarBox (this); 497*cdf0e10cSrcweir mpVerticalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl)); 498*cdf0e10cSrcweir mpHorizontalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl)); 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir mpEditView->SetOutputArea(AdjustScrollBars()); 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir ESelection eSelection; 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir mpEditView->SetSelection(eSelection); 505*cdf0e10cSrcweir Update(); 506*cdf0e10cSrcweir mpEditView->ShowCursor(sal_True, sal_True); 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir pEditEngine->SetStatusEventHdl( 509*cdf0e10cSrcweir LINK(this, EditWindow, EditStatusHdl)); 510*cdf0e10cSrcweir SetPointer(mpEditView->GetPointer()); 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir SetScrollBarRanges(); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir IMPL_LINK( EditWindow, EditStatusHdl, EditStatus *, EMPTYARG ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir if (!mpEditView) 522*cdf0e10cSrcweir return 1; 523*cdf0e10cSrcweir else 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir SetScrollBarRanges(); 526*cdf0e10cSrcweir return 0; 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir IMPL_LINK_INLINE_START( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG ) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir DBG_ASSERT(mpEditView, "EditView missing"); 533*cdf0e10cSrcweir if (mpEditView) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir mpEditView->SetVisArea(Rectangle(Point(mpHorizontalScrollBar->GetThumbPos(), 536*cdf0e10cSrcweir mpVerticalScrollBar->GetThumbPos()), 537*cdf0e10cSrcweir mpEditView->GetVisArea().GetSize())); 538*cdf0e10cSrcweir mpEditView->Invalidate(); 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir return 0; 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir IMPL_LINK_INLINE_END( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG ) 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir Rectangle EditWindow::AdjustScrollBars() 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir const Size aOut( GetOutputSizePixel() ); 547*cdf0e10cSrcweir Point aPoint; 548*cdf0e10cSrcweir Rectangle aRect( aPoint, aOut ); 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir if (mpVerticalScrollBar && mpHorizontalScrollBar && mpScrollBox) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize(); 553*cdf0e10cSrcweir Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L; 554*cdf0e10cSrcweir mpVerticalScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp)); 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L; 557*cdf0e10cSrcweir mpHorizontalScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp)); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir aPt.X() = mpHorizontalScrollBar->GetSizePixel().Width(); 560*cdf0e10cSrcweir aPt.Y() = mpVerticalScrollBar->GetSizePixel().Height(); 561*cdf0e10cSrcweir mpScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp )); 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir aRect.Right() = aPt.X() - 2; 564*cdf0e10cSrcweir aRect.Bottom() = aPt.Y() - 2; 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir return aRect; 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir void EditWindow::SetScrollBarRanges() 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir EditEngine* pEditEngine = GetEditEngine(); 572*cdf0e10cSrcweir if (mpEditView != NULL && pEditEngine != NULL) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir if (mpVerticalScrollBar != NULL) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir long nTmp = pEditEngine->GetTextHeight(); 577*cdf0e10cSrcweir mpVerticalScrollBar->SetRange(Range(0, nTmp)); 578*cdf0e10cSrcweir mpVerticalScrollBar->SetThumbPos(mpEditView->GetVisArea().Top()); 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir if (mpHorizontalScrollBar != NULL) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir long nTmp = pEditEngine->GetPaperSize().Width(); 583*cdf0e10cSrcweir mpHorizontalScrollBar->SetRange(Range(0,nTmp)); 584*cdf0e10cSrcweir mpHorizontalScrollBar->SetThumbPos(mpEditView->GetVisArea().Left()); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir void EditWindow::InitScrollBars() 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir if (mpEditView != NULL) 592*cdf0e10cSrcweir { 593*cdf0e10cSrcweir const Size aOut( mpEditView->GetOutputArea().GetSize() ); 594*cdf0e10cSrcweir if (mpVerticalScrollBar != NULL) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir mpVerticalScrollBar->SetVisibleSize(aOut.Height()); 597*cdf0e10cSrcweir mpVerticalScrollBar->SetPageSize(aOut.Height() * 8 / 10); 598*cdf0e10cSrcweir mpVerticalScrollBar->SetLineSize(aOut.Height() * 2 / 10); 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir if (mpHorizontalScrollBar != NULL) 602*cdf0e10cSrcweir { 603*cdf0e10cSrcweir mpHorizontalScrollBar->SetVisibleSize(aOut.Width()); 604*cdf0e10cSrcweir mpHorizontalScrollBar->SetPageSize(aOut.Width() * 8 / 10); 605*cdf0e10cSrcweir mpHorizontalScrollBar->SetLineSize(SCROLL_LINE ); 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir SetScrollBarRanges(); 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir if (mpVerticalScrollBar != NULL) 611*cdf0e10cSrcweir mpVerticalScrollBar->Show(); 612*cdf0e10cSrcweir if (mpHorizontalScrollBar != NULL) 613*cdf0e10cSrcweir mpHorizontalScrollBar->Show(); 614*cdf0e10cSrcweir if (mpScrollBox != NULL) 615*cdf0e10cSrcweir mpScrollBox->Show(); 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir XubString EditWindow::GetText() 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir String aText; 623*cdf0e10cSrcweir EditEngine *pEditEngine = GetEditEngine(); 624*cdf0e10cSrcweir DBG_ASSERT( pEditEngine, "EditEngine missing" ); 625*cdf0e10cSrcweir if (pEditEngine) 626*cdf0e10cSrcweir aText = pEditEngine->GetText( LINEEND_LF ); 627*cdf0e10cSrcweir return aText; 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir void EditWindow::SetText(const XubString& rText) 632*cdf0e10cSrcweir { 633*cdf0e10cSrcweir EditEngine *pEditEngine = GetEditEngine(); 634*cdf0e10cSrcweir DBG_ASSERT( pEditEngine, "EditEngine missing" ); 635*cdf0e10cSrcweir if (pEditEngine && !pEditEngine->IsModified()) 636*cdf0e10cSrcweir { 637*cdf0e10cSrcweir if (!mpEditView) 638*cdf0e10cSrcweir CreateEditView(); 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir ESelection eSelection = mpEditView->GetSelection(); 641*cdf0e10cSrcweir 642*cdf0e10cSrcweir pEditEngine->SetText(rText); 643*cdf0e10cSrcweir pEditEngine->ClearModifyFlag(); 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir //! Hier die Timer neu zu starten verhindert, dass die Handler f�r andere 646*cdf0e10cSrcweir //! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden. 647*cdf0e10cSrcweir maModifyTimer.Start(); 648*cdf0e10cSrcweir maCursorMoveTimer.Start(); 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir mpEditView->SetSelection(eSelection); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir void EditWindow::GetFocus() 656*cdf0e10cSrcweir { 657*cdf0e10cSrcweir Window::GetFocus(); 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir if (!mpEditView) 660*cdf0e10cSrcweir CreateEditView(); 661*cdf0e10cSrcweir if (mpEditEngine != NULL) 662*cdf0e10cSrcweir mpEditEngine->SetStatusEventHdl( 663*cdf0e10cSrcweir LINK(this, EditWindow, EditStatusHdl)); 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir void EditWindow::LoseFocus() 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir if (mpEditEngine != NULL) 670*cdf0e10cSrcweir mpEditEngine->SetStatusEventHdl (Link()); 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir Window::LoseFocus(); 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir sal_Bool EditWindow::IsAllSelected() const 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir sal_Bool bRes = sal_False; 679*cdf0e10cSrcweir EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine(); 680*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "NULL pointer" ); 681*cdf0e10cSrcweir DBG_ASSERT( pEditEngine, "NULL pointer" ); 682*cdf0e10cSrcweir if (pEditEngine && mpEditView) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir ESelection eSelection( mpEditView->GetSelection() ); 685*cdf0e10cSrcweir sal_Int32 nParaCnt = pEditEngine->GetParagraphCount(); 686*cdf0e10cSrcweir if (!(nParaCnt - 1)) 687*cdf0e10cSrcweir { 688*cdf0e10cSrcweir String Text( pEditEngine->GetText( LINEEND_LF ) ); 689*cdf0e10cSrcweir bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1); 690*cdf0e10cSrcweir } 691*cdf0e10cSrcweir else 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1); 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir return bRes; 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir void EditWindow::SelectAll() 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "NULL pointer" ); 702*cdf0e10cSrcweir if (mpEditView) 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir // 0xFFFF as last two parameters refers to the end of the text 705*cdf0e10cSrcweir mpEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) ); 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir } 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir void EditWindow::MarkError(const Point &rPos) 711*cdf0e10cSrcweir { 712*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "EditView missing" ); 713*cdf0e10cSrcweir if (mpEditView) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir const int Col = rPos.X(); 716*cdf0e10cSrcweir const int Row = rPos.Y() - 1; 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir mpEditView->SetSelection(ESelection ( (sal_uInt16)Row, (sal_uInt16)(Col - 1), (sal_uInt16)Row, (sal_uInt16)Col)); 719*cdf0e10cSrcweir GrabFocus(); 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir void EditWindow::SelNextMark() 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir EditEngine *pEditEngine = GetEditEngine(); 726*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "NULL pointer" ); 727*cdf0e10cSrcweir DBG_ASSERT( pEditEngine, "NULL pointer" ); 728*cdf0e10cSrcweir if (pEditEngine && mpEditView) 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir ESelection eSelection = mpEditView->GetSelection(); 731*cdf0e10cSrcweir sal_uInt16 Pos = eSelection.nEndPos; 732*cdf0e10cSrcweir String aMark (UniString::CreateFromAscii("<?>")); 733*cdf0e10cSrcweir String aText; 734*cdf0e10cSrcweir sal_uInt16 nCounts = pEditEngine->GetParagraphCount(); 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir while (eSelection.nEndPara < nCounts) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir aText = pEditEngine->GetText( eSelection.nEndPara ); 739*cdf0e10cSrcweir Pos = aText.Search(aMark, Pos); 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir if (Pos != STRING_NOTFOUND) 742*cdf0e10cSrcweir { 743*cdf0e10cSrcweir mpEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3)); 744*cdf0e10cSrcweir break; 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir Pos = 0; 748*cdf0e10cSrcweir eSelection.nEndPara++; 749*cdf0e10cSrcweir } 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir void EditWindow::SelPrevMark() 754*cdf0e10cSrcweir { 755*cdf0e10cSrcweir EditEngine *pEditEngine = GetEditEngine(); 756*cdf0e10cSrcweir DBG_ASSERT( pEditEngine, "NULL pointer" ); 757*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "NULL pointer" ); 758*cdf0e10cSrcweir if (pEditEngine && mpEditView) 759*cdf0e10cSrcweir { 760*cdf0e10cSrcweir ESelection eSelection = mpEditView->GetSelection(); 761*cdf0e10cSrcweir sal_uInt16 Pos = STRING_NOTFOUND; 762*cdf0e10cSrcweir xub_StrLen Max = eSelection.nStartPos; 763*cdf0e10cSrcweir String Text( pEditEngine->GetText( eSelection.nStartPara ) ); 764*cdf0e10cSrcweir String aMark (UniString::CreateFromAscii("<?>")); 765*cdf0e10cSrcweir sal_uInt16 nCounts = pEditEngine->GetParagraphCount(); 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir do 768*cdf0e10cSrcweir { 769*cdf0e10cSrcweir sal_uInt16 Fnd = Text.Search(aMark, 0); 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir while ((Fnd < Max) && (Fnd != STRING_NOTFOUND)) 772*cdf0e10cSrcweir { 773*cdf0e10cSrcweir Pos = Fnd; 774*cdf0e10cSrcweir Fnd = Text.Search(aMark, Fnd + 1); 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir 777*cdf0e10cSrcweir if (Pos == STRING_NOTFOUND) 778*cdf0e10cSrcweir { 779*cdf0e10cSrcweir eSelection.nStartPara--; 780*cdf0e10cSrcweir Text = pEditEngine->GetText( eSelection.nStartPara ); 781*cdf0e10cSrcweir Max = Text.Len(); 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir } 784*cdf0e10cSrcweir while ((eSelection.nStartPara < nCounts) && 785*cdf0e10cSrcweir (Pos == STRING_NOTFOUND)); 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir if (Pos != STRING_NOTFOUND) 788*cdf0e10cSrcweir { 789*cdf0e10cSrcweir mpEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3)); 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir } 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir sal_Bool EditWindow::HasMark(const String& rText) const 795*cdf0e10cSrcweir // returns true iff 'rText' contains a mark 796*cdf0e10cSrcweir { 797*cdf0e10cSrcweir return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND; 798*cdf0e10cSrcweir } 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir void EditWindow::MouseMove(const MouseEvent &rEvt) 801*cdf0e10cSrcweir { 802*cdf0e10cSrcweir if (mpEditView) 803*cdf0e10cSrcweir mpEditView->MouseMove(rEvt); 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir sal_Int8 EditWindow::AcceptDrop( const AcceptDropEvent& ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir return mpEditView ? /*mpEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE; 809*cdf0e10cSrcweir } 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir sal_Int8 EditWindow::ExecuteDrop( const ExecuteDropEvent& ) 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir return mpEditView ? /*mpEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE; 814*cdf0e10cSrcweir } 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir ESelection EditWindow::GetSelection() const 817*cdf0e10cSrcweir { 818*cdf0e10cSrcweir // pointer may be 0 when reloading a document and the old view 819*cdf0e10cSrcweir // was already destroyed 820*cdf0e10cSrcweir //(DBG_ASSERT( mpEditView, "NULL pointer" ); 821*cdf0e10cSrcweir ESelection eSel; 822*cdf0e10cSrcweir if (mpEditView) 823*cdf0e10cSrcweir eSel = mpEditView->GetSelection(); 824*cdf0e10cSrcweir return eSel; 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir void EditWindow::SetSelection(const ESelection &rSel) 828*cdf0e10cSrcweir { 829*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "NULL pointer" ); 830*cdf0e10cSrcweir if (mpEditView) 831*cdf0e10cSrcweir mpEditView->SetSelection(rSel); 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir sal_Bool EditWindow::IsEmpty() const 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine(); 837*cdf0e10cSrcweir return (pEditEngine && (pEditEngine->GetTextLen() == 0)) ? sal_True : sal_False; 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir sal_Bool EditWindow::IsSelected() const 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir return mpEditView ? mpEditView->HasSelection() : sal_False; 843*cdf0e10cSrcweir } 844*cdf0e10cSrcweir 845*cdf0e10cSrcweir void EditWindow::Cut() 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "EditView missing" ); 848*cdf0e10cSrcweir if (mpEditView) 849*cdf0e10cSrcweir mpEditView->Cut(); 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir void EditWindow::Copy() 853*cdf0e10cSrcweir { 854*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "EditView missing" ); 855*cdf0e10cSrcweir if (mpEditView) 856*cdf0e10cSrcweir mpEditView->Copy(); 857*cdf0e10cSrcweir } 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir void EditWindow::Paste() 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "EditView missing" ); 862*cdf0e10cSrcweir if (mpEditView) 863*cdf0e10cSrcweir mpEditView->Paste(); 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir void EditWindow::Delete() 867*cdf0e10cSrcweir { 868*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "EditView missing" ); 869*cdf0e10cSrcweir if (mpEditView) 870*cdf0e10cSrcweir mpEditView->DeleteSelected(); 871*cdf0e10cSrcweir } 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir void EditWindow::InsertText(const String& Text) 874*cdf0e10cSrcweir { 875*cdf0e10cSrcweir DBG_ASSERT( mpEditView, "EditView missing" ); 876*cdf0e10cSrcweir ::vos::OGuard aGuard (::Application::GetSolarMutex()); 877*cdf0e10cSrcweir if (mpEditView) 878*cdf0e10cSrcweir mpEditView->InsertText(Text); 879*cdf0e10cSrcweir } 880*cdf0e10cSrcweir 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir } } // end of namespace ::sd::notes 884