Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <com/sun/star/accessibility/XAccessible.hpp>
21 : : #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
22 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 : : #include <toolkit/helper/vclunohelper.hxx>
25 : :
26 : :
27 : : #include "starmath.hrc"
28 : : #define ITEMID_FONT 1
29 : : #define ITEMID_FONTHEIGHT 2
30 : : #define ITEMID_LRSPACE 3
31 : : #define ITEMID_WEIGHT 4
32 : :
33 : :
34 : : #include <vcl/menu.hxx>
35 : : #include <editeng/editview.hxx>
36 : : #include <editeng/editeng.hxx>
37 : : #include <editeng/editstat.hxx>
38 : : #include <editeng/eeitem.hxx>
39 : : #include <sfx2/dispatch.hxx>
40 : : #include <svl/intitem.hxx>
41 : : #include <svl/itempool.hxx>
42 : : #include <svl/stritem.hxx>
43 : : #include <editeng/fhgtitem.hxx>
44 : : #include <editeng/wghtitem.hxx>
45 : : #include <editeng/lrspitem.hxx>
46 : : #include <svl/itemset.hxx>
47 : : #include <editeng/fontitem.hxx>
48 : : #include <sfx2/viewfrm.hxx>
49 : :
50 : : #include "edit.hxx"
51 : : #include "view.hxx"
52 : : #include "document.hxx"
53 : : #include "config.hxx"
54 : : #include "accessibility.hxx"
55 : :
56 : : #define SCROLL_LINE 24
57 : :
58 : :
59 : : using namespace com::sun::star::accessibility;
60 : : using namespace com::sun::star;
61 : : using namespace com::sun::star::uno;
62 : :
63 : : ////////////////////////////////////////
64 : :
65 : :
66 : 39 : void SmGetLeftSelectionPart(const ESelection &rSel,
67 : : sal_uInt16 &nPara, sal_uInt16 &nPos)
68 : : // returns paragraph number and position of the selections left part
69 : : {
70 : : // compare start and end of selection and use the one that comes first
71 [ + - ][ + - ]: 39 : if ( rSel.nStartPara < rSel.nEndPara
[ - + ]
72 : : || (rSel.nStartPara == rSel.nEndPara && rSel.nStartPos < rSel.nEndPos) )
73 : 0 : { nPara = rSel.nStartPara;
74 : 0 : nPos = rSel.nStartPos;
75 : : }
76 : : else
77 : 39 : { nPara = rSel.nEndPara;
78 : 39 : nPos = rSel.nEndPos;
79 : : }
80 : 39 : }
81 : :
82 : 101 : bool SmEditWindow::IsInlineEditEnabled()
83 : : {
84 : 101 : SmViewShell *pView = GetView();
85 [ + - ]: 101 : return pView ? pView->IsInlineEditEnabled() : false;
86 : : }
87 : :
88 : : ////////////////////////////////////////
89 : :
90 : 34 : SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
91 : : Window (&rMyCmdBoxWin),
92 : : DropTargetHelper ( this ),
93 : : pAccessible (0),
94 : : rCmdBox (rMyCmdBoxWin),
95 : : pEditView (0),
96 : : pHScrollBar (0),
97 : : pVScrollBar (0),
98 [ + - ][ + - ]: 34 : pScrollBox (0)
[ + - ]
99 : : {
100 [ + - ]: 34 : SetHelpId(HID_SMA_COMMAND_WIN_EDIT);
101 [ + - ][ + - ]: 34 : SetMapMode(MAP_PIXEL);
[ + - ]
102 : :
103 : : // Even RTL languages don't use RTL for math
104 [ + - ]: 34 : rCmdBox.GetEditWindow()->EnableRTL( false );
105 : :
106 [ + - ][ + - ]: 34 : ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
[ + - ]
107 : :
108 : : // compare DataChanged
109 [ + - ][ + - ]: 34 : SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
[ + - ]
110 : :
111 [ + - ]: 34 : aModifyTimer.SetTimeoutHdl(LINK(this, SmEditWindow, ModifyTimerHdl));
112 [ + - ]: 34 : aModifyTimer.SetTimeout(500);
113 : :
114 [ + - ][ + - ]: 34 : if (!IsInlineEditEnabled())
115 : : {
116 [ + - ]: 34 : aCursorMoveTimer.SetTimeoutHdl(LINK(this, SmEditWindow, CursorMoveTimerHdl));
117 [ + - ]: 34 : aCursorMoveTimer.SetTimeout(500);
118 : : }
119 : :
120 : : // if not called explicitly the this edit window within the
121 : : // command window will just show an empty gray panel.
122 [ + - ]: 34 : Show();
123 : 34 : }
124 : :
125 : :
126 [ + - ][ + - ]: 34 : SmEditWindow::~SmEditWindow()
[ + - ]
127 : : {
128 [ + - ]: 34 : aModifyTimer.Stop();
129 : :
130 [ + - ]: 34 : StartCursorMove();
131 : :
132 : : // clean up of classes used for accessibility
133 : : // must be done before EditView (and thus EditEngine) is no longer
134 : : // available for those classes.
135 [ + + ]: 34 : if (pAccessible)
136 [ + - ]: 4 : pAccessible->ClearWin(); // make Accessible defunctional
137 : : // Note: memory for pAccessible will be freed when the reference
138 : : // xAccessible is released.
139 : :
140 [ + - ]: 34 : if (pEditView)
141 : : {
142 [ + - ]: 34 : EditEngine *pEditEngine = pEditView->GetEditEngine();
143 [ + - ]: 34 : if (pEditEngine)
144 : : {
145 [ + - ][ + - ]: 34 : pEditEngine->SetStatusEventHdl( Link() );
146 [ + - ]: 34 : pEditEngine->RemoveView( pEditView );
147 : : }
148 : : }
149 [ + - ][ + - ]: 34 : delete pEditView;
150 [ + - ][ + - ]: 34 : delete pHScrollBar;
151 [ + - ][ + - ]: 34 : delete pVScrollBar;
152 [ + - ][ + - ]: 34 : delete pScrollBox;
153 [ - + ]: 34 : }
154 : :
155 : 34 : void SmEditWindow::StartCursorMove()
156 : : {
157 [ + - ]: 34 : if (!IsInlineEditEnabled())
158 : 34 : aCursorMoveTimer.Stop();
159 : 34 : }
160 : :
161 : 0 : void SmEditWindow::InvalidateSlots()
162 : : {
163 : 0 : SfxBindings& rBind = GetView()->GetViewFrame()->GetBindings();
164 : 0 : rBind.Invalidate(SID_COPY);
165 : 0 : rBind.Invalidate(SID_CUT);
166 : 0 : rBind.Invalidate(SID_DELETE);
167 : 0 : }
168 : :
169 : 134 : SmViewShell * SmEditWindow::GetView()
170 : : {
171 : 134 : return rCmdBox.GetView();
172 : : }
173 : :
174 : :
175 : 34 : SmDocShell * SmEditWindow::GetDoc()
176 : : {
177 : 34 : SmViewShell *pView = rCmdBox.GetView();
178 [ + - ]: 34 : return pView ? pView->GetDoc() : 0;
179 : : }
180 : :
181 : :
182 : 336 : EditEngine * SmEditWindow::GetEditEngine()
183 : : {
184 : 336 : EditEngine *pEditEng = 0;
185 [ + + ]: 336 : if (pEditView)
186 : 302 : pEditEng = pEditView->GetEditEngine();
187 : : else
188 : : {
189 : 34 : SmDocShell *pDoc = GetDoc();
190 [ + - ]: 34 : if (pDoc)
191 : 34 : pEditEng = &pDoc->GetEditEngine();
192 : : }
193 : 336 : return pEditEng;
194 : : }
195 : :
196 : :
197 : 0 : SfxItemPool * SmEditWindow::GetEditEngineItemPool()
198 : : {
199 : 0 : SmDocShell *pDoc = GetDoc();
200 [ # # ]: 0 : return pDoc ? &pDoc->GetEditEngineItemPool() : 0;
201 : : }
202 : :
203 : 34 : void SmEditWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
204 : : {
205 : : // Note: SetBackground still done in SmEditWindow::DataChanged
206 : : #if OSL_DEBUG_LEVEL > 1
207 : : // ColorData nVal = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
208 : : #endif
209 [ + - ]: 34 : SetTextColor( rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor );
210 : 34 : Invalidate();
211 : 34 : }
212 : :
213 : 0 : void SmEditWindow::DataChanged( const DataChangedEvent& )
214 : : {
215 [ # # ]: 0 : const StyleSettings aSettings( GetSettings().GetStyleSettings() );
216 : :
217 [ # # ][ # # ]: 0 : ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
[ # # ]
218 [ # # ][ # # ]: 0 : SetBackground( aSettings.GetWindowColor() );
[ # # ]
219 : :
220 : : // edit fields in other Applications use this font instead of
221 : : // the application font thus we use this one too
222 [ # # ]: 0 : SetPointFont( aSettings.GetFieldFont() /*aSettings.GetAppFont()*/ );
223 : :
224 [ # # ]: 0 : EditEngine *pEditEngine = GetEditEngine();
225 [ # # ]: 0 : SfxItemPool *pEditEngineItemPool = GetEditEngineItemPool();
226 : :
227 [ # # ][ # # ]: 0 : if (pEditEngine && pEditEngineItemPool)
228 : : {
229 : : //!
230 : : //! see also SmDocShell::GetEditEngine() !
231 : : //!
232 : :
233 [ # # ][ # # ]: 0 : pEditEngine->SetDefTab(sal_uInt16(GetTextWidth(rtl::OUString("XXXX"))));
[ # # ][ # # ]
234 : :
235 [ # # ]: 0 : SetEditEngineDefaultFonts(*pEditEngineItemPool);
236 : :
237 : : // forces new settings to be used
238 : : // unfortunately this resets the whole edit engine
239 : : // thus we need to save at least the text
240 [ # # ]: 0 : String aTxt( pEditEngine->GetText( LINEEND_LF ) );
241 [ # # ]: 0 : pEditEngine->Clear(); //incorrect font size
242 [ # # ][ # # ]: 0 : pEditEngine->SetText( aTxt );
243 : : }
244 : :
245 [ # # ]: 0 : AdjustScrollBars();
246 [ # # ][ # # ]: 0 : Resize();
247 : 0 : }
248 : :
249 : 4 : IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
250 : : {
251 : 4 : SmModule *pp = SM_MOD();
252 [ + - ]: 4 : if (pp->GetConfig()->IsAutoRedraw())
253 : 4 : Flush();
254 : 4 : aModifyTimer.Stop();
255 : 4 : return 0;
256 : : }
257 : :
258 : 0 : IMPL_LINK(SmEditWindow, CursorMoveTimerHdl, Timer *, EMPTYARG /*pTimer*/)
259 : : // every once in a while check cursor position (selection) of edit
260 : : // window and if it has changed (try to) set the formula-cursor
261 : : // according to that.
262 : : {
263 [ # # ][ # # ]: 0 : if (IsInlineEditEnabled())
264 : 0 : return 0;
265 : :
266 [ # # ]: 0 : ESelection aNewSelection(GetSelection());
267 : :
268 [ # # ]: 0 : if (!aNewSelection.IsEqual(aOldSelection))
269 : : {
270 [ # # ]: 0 : SmViewShell *pView = rCmdBox.GetView();
271 [ # # ]: 0 : if (pView)
272 : : {
273 : : // get row and column to look for
274 : : sal_uInt16 nRow, nCol;
275 : 0 : SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
276 : 0 : nRow++;
277 : 0 : nCol++;
278 [ # # ]: 0 : pView->GetGraphicWindow().SetCursorPos(nRow, nCol);
279 : 0 : aOldSelection = aNewSelection;
280 : : }
281 : : }
282 [ # # ]: 0 : aCursorMoveTimer.Stop();
283 : :
284 : 0 : return 0;
285 : : }
286 : :
287 : 74 : void SmEditWindow::Resize()
288 : : {
289 [ + + ]: 74 : if (!pEditView)
290 : 34 : CreateEditView();
291 : :
292 [ + - ]: 74 : if (pEditView)
293 : : {
294 [ + - ]: 74 : pEditView->SetOutputArea(AdjustScrollBars());
295 : 74 : pEditView->ShowCursor();
296 : :
297 : : OSL_ENSURE( pEditView->GetEditEngine(), "EditEngine missing" );
298 : 74 : const long nMaxVisAreaStart = pEditView->GetEditEngine()->GetTextHeight() -
299 : 74 : pEditView->GetOutputArea().GetHeight();
300 [ + + ]: 74 : if (pEditView->GetVisArea().Top() > nMaxVisAreaStart)
301 : : {
302 [ + - ]: 40 : Rectangle aVisArea(pEditView->GetVisArea() );
303 : 40 : aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0;
304 [ + - ][ + - ]: 40 : aVisArea.SetSize(pEditView->GetOutputArea().GetSize());
[ + - ]
305 [ + - ]: 40 : pEditView->SetVisArea(aVisArea);
306 [ + - ]: 40 : pEditView->ShowCursor();
307 : : }
308 : 74 : InitScrollBars();
309 : : }
310 : 74 : Invalidate();
311 : 74 : }
312 : :
313 : 0 : void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
314 : : {
315 [ # # ]: 0 : if (pEditView)
316 : 0 : pEditView->MouseButtonUp(rEvt);
317 : : else
318 : 0 : Window::MouseButtonUp (rEvt);
319 : :
320 [ # # ]: 0 : if (!IsInlineEditEnabled())
321 : 0 : CursorMoveTimerHdl(&aCursorMoveTimer);
322 : 0 : InvalidateSlots();
323 : 0 : }
324 : :
325 : 0 : void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)
326 : : {
327 [ # # ]: 0 : if (pEditView)
328 : 0 : pEditView->MouseButtonDown(rEvt);
329 : : else
330 : 0 : Window::MouseButtonDown (rEvt);
331 : :
332 : 0 : GrabFocus();
333 : 0 : }
334 : :
335 : 0 : void SmEditWindow::Command(const CommandEvent& rCEvt)
336 : : {
337 : 0 : bool bForwardEvt = true;
338 [ # # ]: 0 : if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU)
339 : : {
340 [ # # ][ # # ]: 0 : GetParent()->ToTop();
341 : :
342 : 0 : Point aPoint = rCEvt.GetMousePosPixel();
343 [ # # ][ # # ]: 0 : PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU));
[ # # ]
344 : :
345 : : // added for replaceability of context menus
346 : 0 : Menu* pMenu = NULL;
347 [ # # ]: 0 : ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
348 [ # # ][ # # ]: 0 : aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
349 : 0 : aEvent.ExecutePosition.X = aPoint.X();
350 : 0 : aEvent.ExecutePosition.Y = aPoint.Y();
351 : 0 : ::rtl::OUString sDummy;
352 [ # # ][ # # ]: 0 : if ( GetView()->TryContextMenuInterception( *pPopupMenu, sDummy, pMenu, aEvent ) )
[ # # ][ # # ]
[ # # ]
353 : : {
354 [ # # ]: 0 : if ( pMenu )
355 : : {
356 [ # # ][ # # ]: 0 : delete pPopupMenu;
357 : 0 : pPopupMenu = (PopupMenu*) pMenu;
358 : : }
359 : : }
360 : :
361 [ # # ]: 0 : pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl));
362 : :
363 [ # # ]: 0 : pPopupMenu->Execute( this, aPoint );
364 [ # # ][ # # ]: 0 : delete pPopupMenu;
365 [ # # ]: 0 : bForwardEvt = false;
366 : : }
367 [ # # ]: 0 : else if (rCEvt.GetCommand() == COMMAND_WHEEL)
368 : 0 : bForwardEvt = !HandleWheelCommands( rCEvt );
369 : :
370 [ # # ]: 0 : if (bForwardEvt)
371 : : {
372 [ # # ]: 0 : if (pEditView)
373 : 0 : pEditView->Command( rCEvt );
374 : : else
375 : 0 : Window::Command (rCEvt);
376 : : }
377 : 0 : }
378 : :
379 : :
380 : 0 : bool SmEditWindow::HandleWheelCommands( const CommandEvent &rCEvt )
381 : : {
382 : 0 : bool bCommandHandled = false; // true if the CommandEvent needs not
383 : : // to be passed on (because it has fully
384 : : // been taken care of).
385 : :
386 : 0 : const CommandWheelData* pWData = rCEvt.GetWheelData();
387 [ # # ]: 0 : if (pWData)
388 : : {
389 [ # # ]: 0 : if (COMMAND_WHEEL_ZOOM == pWData->GetMode())
390 : 0 : bCommandHandled = true; // no zooming in Command window
391 : : else
392 : 0 : bCommandHandled = HandleScrollCommand( rCEvt, pHScrollBar, pVScrollBar);
393 : : }
394 : :
395 : 0 : return bCommandHandled;
396 : : }
397 : :
398 : :
399 : 0 : IMPL_LINK_INLINE_START( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
400 : : {
401 : 0 : SmViewShell *pViewSh = rCmdBox.GetView();
402 [ # # ]: 0 : if (pViewSh)
403 : : pViewSh->GetViewFrame()->GetDispatcher()->Execute(
404 : : SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
405 [ # # ]: 0 : new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
406 : 0 : return 0;
407 : : }
408 : 0 : IMPL_LINK_INLINE_END( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
409 : :
410 : 0 : void SmEditWindow::KeyInput(const KeyEvent& rKEvt)
411 : : {
412 [ # # ]: 0 : if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
413 : : {
414 : 0 : bool bCallBase = true;
415 : 0 : SfxViewShell* pViewShell = GetView();
416 [ # # ][ # # ]: 0 : if ( pViewShell && pViewShell->ISA(SmViewShell) )
[ # # ]
417 : : {
418 : : // Terminate possible InPlace mode
419 : 0 : bCallBase = !pViewShell->Escape();
420 : : }
421 [ # # ]: 0 : if ( bCallBase )
422 : 0 : Window::KeyInput( rKEvt );
423 : : }
424 : : else
425 : : {
426 : 0 : StartCursorMove();
427 : :
428 [ # # ]: 0 : if (!pEditView)
429 : 0 : CreateEditView();
430 [ # # ]: 0 : if ( !pEditView->PostKeyEvent(rKEvt) )
431 : : {
432 : 0 : SmViewShell *pView = GetView();
433 [ # # ][ # # ]: 0 : if ( pView && !pView->KeyInput(rKEvt) )
[ # # ]
434 : : {
435 : : // F1 (help) leads to the destruction of this
436 : 0 : Flush();
437 [ # # ]: 0 : if ( aModifyTimer.IsActive() )
438 : 0 : aModifyTimer.Stop();
439 : 0 : Window::KeyInput(rKEvt);
440 : : }
441 : : else
442 : : {
443 : : // SFX has maybe called a slot of the view and thus (because of a hack in SFX)
444 : : // set the focus to the view
445 : 0 : SfxViewShell* pVShell = GetView();
446 [ # # # # ]: 0 : if ( pVShell && pVShell->ISA(SmViewShell) &&
[ # # ][ # # ]
447 : 0 : ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() )
448 : : {
449 : 0 : GrabFocus();
450 : : }
451 : : }
452 : : }
453 : : else
454 : : {
455 : : // have doc-shell modified only for formula input/change and not
456 : : // cursor travelling and such things...
457 : 0 : SmDocShell *pDocShell = GetDoc();
458 [ # # ]: 0 : if (pDocShell)
459 : 0 : pDocShell->SetModified( GetEditEngine()->IsModified() );
460 : :
461 : 0 : aModifyTimer.Start();
462 : : }
463 : :
464 : 0 : InvalidateSlots();
465 : : }
466 : 0 : }
467 : :
468 : 35 : void SmEditWindow::Paint(const Rectangle& rRect)
469 : : {
470 [ - + ]: 35 : if (!pEditView)
471 : 0 : CreateEditView();
472 : 35 : pEditView->Paint(rRect);
473 : 35 : }
474 : :
475 : 34 : void SmEditWindow::CreateEditView()
476 : : {
477 : 34 : EditEngine *pEditEngine = GetEditEngine();
478 : :
479 : : //! pEditEngine and pEditView may be 0.
480 : : //! For example when the program is used by the document-converter
481 [ + - ][ + - ]: 34 : if (!pEditView && pEditEngine)
482 : : {
483 [ + - ][ + - ]: 34 : pEditView = new EditView( pEditEngine, this );
484 [ + - ]: 34 : pEditEngine->InsertView( pEditView );
485 : :
486 [ + - ]: 34 : if (!pVScrollBar)
487 [ + - ][ + - ]: 34 : pVScrollBar = new ScrollBar(this, WinBits(WB_VSCROLL));
488 [ + - ]: 34 : if (!pHScrollBar)
489 [ + - ][ + - ]: 34 : pHScrollBar = new ScrollBar(this, WinBits(WB_HSCROLL));
490 [ + - ]: 34 : if (!pScrollBox)
491 [ + - ][ + - ]: 34 : pScrollBox = new ScrollBarBox(this);
492 [ + - ]: 34 : pVScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
493 [ + - ]: 34 : pHScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
494 : 34 : pVScrollBar->EnableDrag( true );
495 : 34 : pHScrollBar->EnableDrag( true );
496 : :
497 [ + - ][ + - ]: 34 : pEditView->SetOutputArea(AdjustScrollBars());
498 : :
499 : 34 : ESelection eSelection;
500 : :
501 [ + - ]: 34 : pEditView->SetSelection(eSelection);
502 [ + - ]: 34 : Update();
503 [ + - ]: 34 : pEditView->ShowCursor(true, true);
504 : :
505 [ + - ][ + - ]: 34 : pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
506 [ + - ][ + - ]: 34 : SetPointer(pEditView->GetPointer());
507 : :
508 [ + - ]: 34 : SetScrollBarRanges();
509 : : }
510 : 34 : }
511 : :
512 : :
513 : 6 : IMPL_LINK( SmEditWindow, EditStatusHdl, EditStatus *, EMPTYARG /*pStat*/ )
514 : : {
515 [ - + ]: 6 : if (!pEditView)
516 : 0 : return 1;
517 : : else
518 : : {
519 : 6 : Resize();
520 : 6 : return 0;
521 : : }
522 : : }
523 : :
524 : 0 : IMPL_LINK_INLINE_START( SmEditWindow, ScrollHdl, ScrollBar *, EMPTYARG /*pScrollBar*/ )
525 : : {
526 : : OSL_ENSURE(pEditView, "EditView missing");
527 [ # # ]: 0 : if (pEditView)
528 : : {
529 : : pEditView->SetVisArea(Rectangle(Point(pHScrollBar->GetThumbPos(),
530 : : pVScrollBar->GetThumbPos()),
531 [ # # ][ # # ]: 0 : pEditView->GetVisArea().GetSize()));
532 : 0 : pEditView->Invalidate();
533 : : }
534 : 0 : return 0;
535 : : }
536 : 0 : IMPL_LINK_INLINE_END( SmEditWindow, ScrollHdl, ScrollBar *, pScrollBar )
537 : :
538 : 108 : Rectangle SmEditWindow::AdjustScrollBars()
539 : : {
540 : 108 : const Size aOut( GetOutputSizePixel() );
541 : 108 : Point aPoint;
542 [ + - ]: 108 : Rectangle aRect( aPoint, aOut );
543 : :
544 [ + - ][ + - ]: 108 : if (pVScrollBar && pHScrollBar && pScrollBox)
[ + - ]
545 : : {
546 : 108 : const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
547 [ + - ]: 108 : Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L;
548 [ + - ]: 108 : pVScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp));
549 : :
550 [ + - ]: 108 : aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L;
551 [ + - ]: 108 : pHScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp));
552 : :
553 [ + - ]: 108 : aPt.X() = pHScrollBar->GetSizePixel().Width();
554 [ + - ]: 108 : aPt.Y() = pVScrollBar->GetSizePixel().Height();
555 [ + - ]: 108 : pScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp ));
556 : :
557 : 108 : aRect.Right() = aPt.X() - 2;
558 : 108 : aRect.Bottom() = aPt.Y() - 2;
559 : : }
560 : 108 : return aRect;
561 : : }
562 : :
563 : 108 : void SmEditWindow::SetScrollBarRanges()
564 : : {
565 : : // Extra method, not InitScrollBars, since it's also being used for EditEngine events
566 : 108 : EditEngine *pEditEngine = GetEditEngine();
567 [ + - ][ + - ]: 108 : if (pVScrollBar && pHScrollBar && pEditEngine && pEditView)
[ + - ][ + - ]
568 : : {
569 : 108 : long nTmp = pEditEngine->GetTextHeight();
570 [ + - ]: 108 : pVScrollBar->SetRange(Range(0, nTmp));
571 : 108 : pVScrollBar->SetThumbPos(pEditView->GetVisArea().Top());
572 : :
573 : 108 : nTmp = pEditEngine->GetPaperSize().Width();
574 [ + - ]: 108 : pHScrollBar->SetRange(Range(0,nTmp));
575 : 108 : pHScrollBar->SetThumbPos(pEditView->GetVisArea().Left());
576 : : }
577 : 108 : }
578 : :
579 : 74 : void SmEditWindow::InitScrollBars()
580 : : {
581 [ + - ][ + - ]: 74 : if (pVScrollBar && pHScrollBar && pScrollBox && pEditView)
[ + - ][ + - ]
582 : : {
583 [ + - ][ + - ]: 74 : const Size aOut( pEditView->GetOutputArea().GetSize() );
584 [ + - ]: 74 : pVScrollBar->SetVisibleSize(aOut.Height());
585 : 74 : pVScrollBar->SetPageSize(aOut.Height() * 8 / 10);
586 : 74 : pVScrollBar->SetLineSize(aOut.Height() * 2 / 10);
587 : :
588 [ + - ]: 74 : pHScrollBar->SetVisibleSize(aOut.Width());
589 : 74 : pHScrollBar->SetPageSize(aOut.Width() * 8 / 10);
590 : 74 : pHScrollBar->SetLineSize(SCROLL_LINE );
591 : :
592 [ + - ]: 74 : SetScrollBarRanges();
593 : :
594 [ + - ]: 74 : pVScrollBar->Show();
595 [ + - ]: 74 : pHScrollBar->Show();
596 [ + - ]: 74 : pScrollBox->Show();
597 : : }
598 : 74 : }
599 : :
600 : :
601 : 7 : String SmEditWindow::GetText() const
602 : : {
603 : 7 : String aText;
604 [ + - ]: 7 : EditEngine *pEditEngine = const_cast< SmEditWindow* >(this)->GetEditEngine();
605 : : OSL_ENSURE( pEditEngine, "EditEngine missing" );
606 [ + - ]: 7 : if (pEditEngine)
607 [ + - ][ + - ]: 7 : aText = pEditEngine->GetText( LINEEND_LF );
[ + - ]
608 : 7 : return aText;
609 : : }
610 : :
611 : :
612 : 6 : void SmEditWindow::SetText(const XubString& rText)
613 : : {
614 : 6 : EditEngine *pEditEngine = GetEditEngine();
615 : : OSL_ENSURE( pEditEngine, "EditEngine missing" );
616 [ + - ][ + - ]: 6 : if (pEditEngine && !pEditEngine->IsModified())
[ + - ]
617 : : {
618 [ - + ]: 6 : if (!pEditView)
619 [ # # ]: 0 : CreateEditView();
620 : :
621 [ + - ]: 6 : ESelection eSelection = pEditView->GetSelection();
622 : :
623 [ + - ]: 6 : pEditEngine->SetText(rText);
624 [ + - ]: 6 : pEditEngine->ClearModifyFlag();
625 : :
626 : : // Restarting the timer here, prevents calling the handlers for other (currently inactive)
627 : : // math tasks
628 [ + - ]: 6 : aModifyTimer.Start();
629 : :
630 [ + - ]: 6 : pEditView->SetSelection(eSelection);
631 : : }
632 : 6 : }
633 : :
634 : :
635 : 33 : void SmEditWindow::GetFocus()
636 : : {
637 : 33 : Window::GetFocus();
638 : :
639 [ - + ]: 33 : if (xAccessible.is())
640 : : {
641 : : // Note: will implicitly send the AccessibleStateType::FOCUSED event
642 : 0 : ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
643 [ # # ]: 0 : if (pHelper)
644 : 0 : pHelper->SetFocus( sal_True );
645 : : }
646 : :
647 [ - + ]: 33 : if (!pEditView)
648 : 0 : CreateEditView();
649 : 33 : EditEngine *pEditEngine = GetEditEngine();
650 [ + - ]: 33 : if (pEditEngine)
651 [ + - ]: 33 : pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
652 : :
653 : : //Let SmViewShell know we got focus
654 [ + - ][ - + ]: 33 : if(GetView() && IsInlineEditEnabled())
[ - + ]
655 : 0 : GetView()->SetInsertIntoEditWindow(true);
656 : 33 : }
657 : :
658 : :
659 : 2 : void SmEditWindow::LoseFocus()
660 : : {
661 : 2 : EditEngine *pEditEngine = GetEditEngine();
662 [ + - ]: 2 : if (pEditEngine)
663 [ + - ]: 2 : pEditEngine->SetStatusEventHdl( Link() );
664 : :
665 : 2 : Window::LoseFocus();
666 : :
667 [ - + ]: 2 : if (xAccessible.is())
668 : : {
669 : : // Note: will implicitly send the AccessibleStateType::FOCUSED event
670 : 0 : ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
671 [ # # ]: 0 : if (pHelper)
672 : 0 : pHelper->SetFocus( sal_False );
673 : : }
674 : 2 : }
675 : :
676 : :
677 : 0 : bool SmEditWindow::IsAllSelected() const
678 : : {
679 : 0 : bool bRes = false;
680 : 0 : EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
681 : : OSL_ENSURE( pEditView, "NULL pointer" );
682 : : OSL_ENSURE( pEditEngine, "NULL pointer" );
683 [ # # ][ # # ]: 0 : if (pEditEngine && pEditView)
684 : : {
685 [ # # ]: 0 : ESelection eSelection( pEditView->GetSelection() );
686 [ # # ]: 0 : sal_Int32 nParaCnt = pEditEngine->GetParagraphCount();
687 [ # # ]: 0 : if (!(nParaCnt - 1))
688 : : {
689 [ # # ]: 0 : String Text( pEditEngine->GetText( LINEEND_LF ) );
690 [ # # ][ # # ]: 0 : bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1);
[ # # ]
691 : : }
692 : : else
693 : : {
694 [ # # ][ # # ]: 0 : bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
695 : : }
696 : : }
697 : 0 : return bRes;
698 : : }
699 : :
700 : 0 : void SmEditWindow::SelectAll()
701 : : {
702 : : OSL_ENSURE( pEditView, "NULL pointer" );
703 [ # # ]: 0 : if (pEditView)
704 : : {
705 : : // 0xFFFF as last two parameters refers to the end of the text
706 [ # # ]: 0 : pEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
707 : : }
708 : 0 : }
709 : :
710 : 0 : void SmEditWindow::InsertCommand(sal_uInt16 nCommand)
711 : : {
712 : : OSL_ENSURE( pEditView, "EditView missing" );
713 [ # # ]: 0 : if (pEditView)
714 : : {
715 : : // Remember start of the selection and move the cursor there afterwards.
716 : : // Only this way the SelNextMark() makes sense...
717 [ # # ]: 0 : ESelection aSelection = pEditView->GetSelection();
718 : 0 : aSelection.nEndPos = aSelection.nStartPos;
719 : 0 : aSelection.nEndPara = aSelection.nStartPara;
720 : :
721 : : OSL_ENSURE( pEditView, "NULL pointer" );
722 [ # # ][ # # ]: 0 : String aText = String(SmResId(nCommand));
723 [ # # ]: 0 : pEditView->InsertText(aText);
724 : :
725 [ # # ][ # # ]: 0 : if (HasMark(aText))
726 : : { // set selection to next mark
727 [ # # ]: 0 : pEditView->SetSelection(aSelection);
728 [ # # ]: 0 : SelNextMark();
729 : : }
730 : : else
731 : : { // set selection after inserted text
732 : 0 : aSelection.nEndPos = aSelection.nEndPos + sal::static_int_cast< xub_StrLen >(aText.Len());
733 : 0 : aSelection.nStartPos = aSelection.nEndPos;
734 [ # # ]: 0 : pEditView->SetSelection(aSelection);
735 : : }
736 : :
737 [ # # ]: 0 : aModifyTimer.Start();
738 [ # # ]: 0 : StartCursorMove();
739 [ # # ][ # # ]: 0 : GrabFocus();
740 : : }
741 : 0 : }
742 : :
743 : 0 : void SmEditWindow::MarkError(const Point &rPos)
744 : : {
745 : : OSL_ENSURE( pEditView, "EditView missing" );
746 [ # # ]: 0 : if (pEditView)
747 : : {
748 : 0 : const xub_StrLen nCol = sal::static_int_cast< xub_StrLen >(rPos.X());
749 : 0 : const sal_uInt16 nRow = sal::static_int_cast< sal_uInt16 >(rPos.Y() - 1);
750 : :
751 [ # # ]: 0 : pEditView->SetSelection(ESelection(nRow, nCol - 1, nRow, nCol));
752 : 0 : GrabFocus();
753 : : }
754 : 0 : }
755 : :
756 : 0 : void SmEditWindow::SelNextMark()
757 : : {
758 : 0 : EditEngine *pEditEngine = GetEditEngine();
759 : : OSL_ENSURE( pEditView, "NULL pointer" );
760 : : OSL_ENSURE( pEditEngine, "NULL pointer" );
761 [ # # ][ # # ]: 0 : if (pEditEngine && pEditView)
762 : : {
763 [ # # ]: 0 : ESelection eSelection = pEditView->GetSelection();
764 : 0 : sal_uInt16 Pos = eSelection.nEndPos;
765 : 0 : rtl::OUString aMark("<?>");
766 [ # # ]: 0 : String aText;
767 [ # # ]: 0 : sal_uInt16 nCounts = pEditEngine->GetParagraphCount();
768 : :
769 [ # # ]: 0 : while (eSelection.nEndPara < nCounts)
770 : : {
771 [ # # ][ # # ]: 0 : aText = pEditEngine->GetText( eSelection.nEndPara );
[ # # ]
772 [ # # ][ # # ]: 0 : Pos = aText.Search(aMark, Pos);
[ # # ]
773 : :
774 [ # # ]: 0 : if (Pos != STRING_NOTFOUND)
775 : : {
776 [ # # ]: 0 : pEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3));
777 : 0 : break;
778 : : }
779 : :
780 : 0 : Pos = 0;
781 : 0 : eSelection.nEndPara++;
782 [ # # ]: 0 : }
783 : : }
784 : 0 : }
785 : :
786 : 0 : void SmEditWindow::SelPrevMark()
787 : : {
788 : 0 : EditEngine *pEditEngine = GetEditEngine();
789 : : OSL_ENSURE( pEditEngine, "NULL pointer" );
790 : : OSL_ENSURE( pEditView, "NULL pointer" );
791 [ # # ][ # # ]: 0 : if (pEditEngine && pEditView)
792 : : {
793 [ # # ]: 0 : ESelection eSelection = pEditView->GetSelection();
794 : 0 : sal_uInt16 Pos = STRING_NOTFOUND;
795 : 0 : xub_StrLen Max = eSelection.nStartPos;
796 [ # # ]: 0 : String Text( pEditEngine->GetText( eSelection.nStartPara ) );
797 : 0 : rtl::OUString aMark("<?>");
798 [ # # ]: 0 : sal_uInt16 nCounts = pEditEngine->GetParagraphCount();
799 : :
800 [ # # ][ # # ]: 0 : do
[ # # ]
801 : : {
802 [ # # ][ # # ]: 0 : sal_uInt16 Fnd = Text.Search(aMark, 0);
[ # # ]
803 : :
804 [ # # ][ # # ]: 0 : while ((Fnd < Max) && (Fnd != STRING_NOTFOUND))
[ # # ]
805 : : {
806 : 0 : Pos = Fnd;
807 [ # # ][ # # ]: 0 : Fnd = Text.Search(aMark, Fnd + 1);
[ # # ]
808 : : }
809 : :
810 [ # # ]: 0 : if (Pos == STRING_NOTFOUND)
811 : : {
812 : 0 : eSelection.nStartPara--;
813 [ # # ][ # # ]: 0 : Text = pEditEngine->GetText( eSelection.nStartPara );
[ # # ]
814 : 0 : Max = Text.Len();
815 : : }
816 : : }
817 : : while ((eSelection.nStartPara < nCounts) &&
818 : : (Pos == STRING_NOTFOUND));
819 : :
820 [ # # ]: 0 : if (Pos != STRING_NOTFOUND)
821 : : {
822 [ # # ]: 0 : pEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3));
823 [ # # ]: 0 : }
824 : : }
825 : 0 : }
826 : :
827 : 0 : bool SmEditWindow::HasMark(const String& rText) const
828 : : // returns true iff 'rText' contains a mark
829 : : {
830 : 0 : return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND;
831 : : }
832 : :
833 : 0 : void SmEditWindow::MouseMove(const MouseEvent &rEvt)
834 : : {
835 [ # # ]: 0 : if (pEditView)
836 : 0 : pEditView->MouseMove(rEvt);
837 : 0 : }
838 : :
839 : 0 : sal_Int8 SmEditWindow::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
840 : : {
841 : 0 : return pEditView ? /*pEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE;
842 : : }
843 : :
844 : 0 : sal_Int8 SmEditWindow::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
845 : : {
846 : 0 : return pEditView ? /*pEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE;
847 : : }
848 : :
849 : 39 : ESelection SmEditWindow::GetSelection() const
850 : : {
851 : : // pointer may be 0 when reloading a document and the old view
852 : : // was already destroyed
853 : : //(OSL_ENSURE( pEditView, "NULL pointer" );
854 : 39 : ESelection eSel;
855 [ + - ]: 39 : if (pEditView)
856 : 39 : eSel = pEditView->GetSelection();
857 : 39 : return eSel;
858 : : }
859 : :
860 : 0 : void SmEditWindow::SetSelection(const ESelection &rSel)
861 : : {
862 : : OSL_ENSURE( pEditView, "NULL pointer" );
863 [ # # ]: 0 : if (pEditView)
864 : 0 : pEditView->SetSelection(rSel);
865 : 0 : InvalidateSlots();
866 : 0 : }
867 : :
868 : 26 : bool SmEditWindow::IsEmpty() const
869 : : {
870 : 26 : EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
871 [ + + ][ + - ]: 26 : bool bEmpty = ( pEditEngine ? pEditEngine->GetTextLen() == 0 : false);
872 : 26 : return bEmpty;
873 : : }
874 : :
875 : 52 : bool SmEditWindow::IsSelected() const
876 : : {
877 [ + - ][ - + ]: 52 : return pEditView ? pEditView->HasSelection() : false;
878 : : }
879 : :
880 : 0 : void SmEditWindow::Cut()
881 : : {
882 : : OSL_ENSURE( pEditView, "EditView missing" );
883 [ # # ]: 0 : if (pEditView)
884 : : {
885 : 0 : pEditView->Cut();
886 : 0 : GetDoc()->SetModified( true );
887 : : }
888 : 0 : }
889 : :
890 : 0 : void SmEditWindow::Copy()
891 : : {
892 : : OSL_ENSURE( pEditView, "EditView missing" );
893 [ # # ]: 0 : if (pEditView)
894 : 0 : pEditView->Copy();
895 : 0 : }
896 : :
897 : 0 : void SmEditWindow::Paste()
898 : : {
899 : : OSL_ENSURE( pEditView, "EditView missing" );
900 [ # # ]: 0 : if (pEditView)
901 : : {
902 : 0 : pEditView->Paste();
903 : 0 : GetDoc()->SetModified( true );
904 : : }
905 : 0 : }
906 : :
907 : 0 : void SmEditWindow::Delete()
908 : : {
909 : : OSL_ENSURE( pEditView, "EditView missing" );
910 [ # # ]: 0 : if (pEditView)
911 : : {
912 : 0 : pEditView->DeleteSelected();
913 : 0 : GetDoc()->SetModified( true );
914 : : }
915 : 0 : }
916 : :
917 : 0 : void SmEditWindow::InsertText(const String& Text)
918 : : {
919 : : OSL_ENSURE( pEditView, "EditView missing" );
920 [ # # ]: 0 : if (pEditView)
921 : : {
922 : 0 : pEditView->InsertText(Text);
923 : 0 : aModifyTimer.Start();
924 : 0 : StartCursorMove();
925 : : }
926 : 0 : }
927 : :
928 : 4 : void SmEditWindow::Flush()
929 : : {
930 : 4 : EditEngine *pEditEngine = GetEditEngine();
931 [ - + ][ - + ]: 4 : if (pEditEngine && pEditEngine->IsModified())
[ + - ]
932 : : {
933 : 0 : pEditEngine->ClearModifyFlag();
934 : 0 : SmViewShell *pViewSh = rCmdBox.GetView();
935 [ # # ]: 0 : if (pViewSh)
936 : : {
937 : : pViewSh->GetViewFrame()->GetDispatcher()->Execute(
938 : : SID_TEXT, SFX_CALLMODE_STANDARD,
939 [ # # ][ # # ]: 0 : new SfxStringItem(SID_TEXT, GetText()), 0L);
[ # # ]
940 : : }
941 : : }
942 [ - + ]: 4 : if (aCursorMoveTimer.IsActive())
943 : : {
944 : 0 : aCursorMoveTimer.Stop();
945 : 0 : CursorMoveTimerHdl(&aCursorMoveTimer);
946 : : }
947 : 4 : }
948 : :
949 : :
950 : 0 : void SmEditWindow::DeleteEditView( SmViewShell & /*rView*/ )
951 : : {
952 [ # # ]: 0 : if (pEditView)
953 : : {
954 : 0 : EditEngine *pEditEngine = pEditView->GetEditEngine();
955 [ # # ]: 0 : if (pEditEngine)
956 : : {
957 [ # # ]: 0 : pEditEngine->SetStatusEventHdl( Link() );
958 : 0 : pEditEngine->RemoveView( pEditView );
959 : : }
960 [ # # ]: 0 : delete pEditView;
961 : 0 : pEditView = 0;
962 : : }
963 : 0 : }
964 : :
965 : :
966 : 4 : uno::Reference< XAccessible > SmEditWindow::CreateAccessible()
967 : : {
968 [ + - ]: 4 : if (!pAccessible)
969 : : {
970 [ + - ]: 4 : pAccessible = new SmEditAccessible( this );
971 [ + - ]: 4 : xAccessible = pAccessible;
972 : 4 : pAccessible->Init();
973 : : }
974 : 4 : return xAccessible;
975 [ + - ][ + - ]: 30 : }
976 : :
977 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|