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