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