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/AccessibleEventId.hpp>
21 : #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
22 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
23 : #include <com/sun/star/accessibility/XAccessible.hpp>
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 : #include <com/sun/star/frame/XDesktop.hpp>
26 : #include <com/sun/star/frame/XFramesSupplier.hpp>
27 : #include <com/sun/star/container/XChild.hpp>
28 :
29 : #include <comphelper/processfactory.hxx>
30 : #include <comphelper/storagehelper.hxx>
31 : #include <comphelper/string.hxx>
32 : #include <rtl/logfile.hxx>
33 : #include <sfx2/app.hxx>
34 : #include <sfx2/dispatch.hxx>
35 : #include <sfx2/docfile.hxx>
36 : #include <sfx2/docfilt.hxx>
37 : #include <sfx2/docinsert.hxx>
38 : #include <sfx2/filedlghelper.hxx>
39 : #include <sfx2/msg.hxx>
40 : #include <sfx2/objface.hxx>
41 : #include <sfx2/printer.hxx>
42 : #include <sfx2/request.hxx>
43 : #include <svl/eitem.hxx>
44 : #include <svl/intitem.hxx>
45 : #include <svl/itemset.hxx>
46 : #include <svl/poolitem.hxx>
47 : #include <svl/ptitem.hxx>
48 : #include <svl/stritem.hxx>
49 : #include <svtools/transfer.hxx>
50 : #include <svtools/miscopt.hxx>
51 : #include <svl/undo.hxx>
52 : #include <svl/whiter.hxx>
53 : #include <svx/dialogs.hrc>
54 : #include <editeng/editeng.hxx>
55 : #include <svx/svxdlg.hxx>
56 : #include <sfx2/zoomitem.hxx>
57 : #include <vcl/decoview.hxx>
58 : #include <vcl/menu.hxx>
59 : #include <vcl/msgbox.hxx>
60 : #include <vcl/wrkwin.hxx>
61 : #include <fstream>
62 :
63 : #include "unomodel.hxx"
64 : #include "view.hxx"
65 : #include "config.hxx"
66 : #include "dialog.hxx"
67 : #include "document.hxx"
68 : #include "starmath.hrc"
69 : #include "toolbox.hxx"
70 : #include "mathmlimport.hxx"
71 : #include "cursor.hxx"
72 : #include "accessibility.hxx"
73 :
74 : #define MINZOOM 25
75 : #define MAXZOOM 800
76 :
77 : // space around the edit window, in pixels
78 : #define CMD_BOX_PADDING 4
79 :
80 : #define SmViewShell
81 : #include "smslots.hxx"
82 :
83 : using namespace com::sun::star;
84 : using namespace com::sun::star::accessibility;
85 : using namespace com::sun::star::uno;
86 :
87 : //////////////////////////////////////////////////////////////////////
88 :
89 8 : SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell):
90 8 : ScrollableWindow(&pShell->GetViewFrame()->GetWindow(), 0),
91 : pAccessible(0),
92 : pViewShell(pShell),
93 8 : nZoom(100)
94 : {
95 : // docking windows are usually hidden (often already done in the
96 : // resource) and will be shown by the sfx framework.
97 8 : Hide();
98 :
99 8 : const Fraction aFraction (1,1);
100 8 : SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction));
101 :
102 8 : ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
103 :
104 8 : SetTotalSize();
105 :
106 8 : SetHelpId(HID_SMA_WIN_DOCUMENT);
107 8 : SetUniqueId(HID_SMA_WIN_DOCUMENT);
108 :
109 8 : ShowLine(false);
110 8 : CaretBlinkInit();
111 8 : }
112 :
113 0 : SmGraphicWindow::~SmGraphicWindow()
114 : {
115 0 : if (pAccessible)
116 0 : pAccessible->ClearWin(); // make Accessible defunctional
117 : // Note: memory for pAccessible will be freed when the reference
118 : // xAccessible is released.
119 0 : CaretBlinkStop();
120 0 : }
121 :
122 16 : void SmGraphicWindow::StateChanged( StateChangedType eType )
123 : {
124 16 : if ( eType == STATE_CHANGE_INITSHOW )
125 0 : Show();
126 16 : ScrollableWindow::StateChanged( eType );
127 16 : }
128 :
129 :
130 8 : void SmGraphicWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
131 : {
132 : // Note: SetTextColor not necessary since the nodes that
133 : // get painted have the color information.
134 : #if OSL_DEBUG_LEVEL > 1
135 : // ColorData nVal = rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor;
136 : #endif
137 8 : SetBackground( Color( (ColorData) rColorCfg.GetColorValue(svtools::DOCCOLOR).nColor ) );
138 8 : Invalidate();
139 8 : }
140 :
141 :
142 0 : void SmGraphicWindow::DataChanged( const DataChangedEvent& rEvt )
143 : {
144 0 : ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
145 :
146 0 : ScrollableWindow::DataChanged( rEvt );
147 0 : }
148 :
149 :
150 0 : void SmGraphicWindow::MouseButtonDown(const MouseEvent& rMEvt)
151 : {
152 0 : ScrollableWindow::MouseButtonDown(rMEvt);
153 :
154 0 : GrabFocus();
155 :
156 : //
157 : // set formula-cursor and selection of edit window according to the
158 : // position clicked at
159 : //
160 : OSL_ENSURE(rMEvt.GetClicks() > 0, "Sm : 0 clicks");
161 0 : if ( rMEvt.IsLeft() )
162 : {
163 : // get click position relativ to formula
164 0 : Point aPos (PixelToLogic(rMEvt.GetPosPixel())
165 0 : - GetFormulaDrawPos());
166 :
167 0 : const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
168 0 : if (!pTree)
169 : return;
170 :
171 0 : if (IsInlineEditEnabled()) {
172 0 : pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, !rMEvt.IsShift());
173 : return;
174 : }
175 0 : const SmNode *pNode = 0;
176 : // if it was clicked inside the formula then get the appropriate node
177 0 : if (pTree->OrientedDist(aPos) <= 0)
178 0 : pNode = pTree->FindRectClosestTo(aPos);
179 :
180 0 : if (pNode)
181 0 : { SmEditWindow *pEdit = pViewShell->GetEditWindow();
182 0 : if (!pEdit)
183 : return;
184 0 : const SmToken aToken (pNode->GetToken());
185 :
186 : // set selection to the beginning of the token
187 0 : ESelection aSel (aToken.nRow - 1, aToken.nCol - 1);
188 :
189 0 : if (rMEvt.GetClicks() != 1 || aToken.eType == TPLACE)
190 0 : aSel.nEndPos = aSel.nEndPos + sal::static_int_cast< sal_uInt16 >(aToken.aText.getLength());
191 :
192 0 : pEdit->SetSelection(aSel);
193 0 : SetCursor(pNode);
194 :
195 : // allow for immediate editing and
196 : //! implicitly synchronize the cursor position mark in this window
197 0 : pEdit->GrabFocus();
198 : }
199 : }
200 : }
201 :
202 0 : void SmGraphicWindow::MouseMove(const MouseEvent &rMEvt)
203 : {
204 0 : ScrollableWindow::MouseMove(rMEvt);
205 :
206 0 : if (rMEvt.IsLeft() && IsInlineEditEnabled())
207 : {
208 0 : Point aPos(PixelToLogic(rMEvt.GetPosPixel()) - GetFormulaDrawPos());
209 0 : pViewShell->GetDoc()->GetCursor().MoveTo(this, aPos, false);
210 :
211 0 : CaretBlinkStop();
212 0 : SetIsCursorVisible(true);
213 0 : CaretBlinkStart();
214 0 : RepaintViewShellDoc();
215 : }
216 0 : }
217 :
218 8 : bool SmGraphicWindow::IsInlineEditEnabled() const
219 : {
220 8 : return pViewShell->IsInlineEditEnabled();
221 : }
222 :
223 0 : void SmGraphicWindow::GetFocus()
224 : {
225 0 : if (!IsInlineEditEnabled())
226 0 : return;
227 0 : if (pViewShell->GetEditWindow())
228 0 : pViewShell->GetEditWindow()->Flush();
229 : //Let view shell know what insertions should be done in visual editor
230 0 : pViewShell->SetInsertIntoEditWindow(false);
231 0 : SetIsCursorVisible(true);
232 0 : ShowLine(true);
233 0 : CaretBlinkStart();
234 0 : RepaintViewShellDoc();
235 : }
236 :
237 0 : void SmGraphicWindow::LoseFocus()
238 : {
239 0 : ScrollableWindow::LoseFocus();
240 0 : if (xAccessible.is())
241 : {
242 0 : uno::Any aOldValue, aNewValue;
243 0 : aOldValue <<= AccessibleStateType::FOCUSED;
244 : // aNewValue remains empty
245 : pAccessible->LaunchEvent( AccessibleEventId::STATE_CHANGED,
246 0 : aOldValue, aNewValue );
247 : }
248 0 : if (!IsInlineEditEnabled())
249 0 : return;
250 0 : SetIsCursorVisible(false);
251 0 : ShowLine(false);
252 0 : CaretBlinkStop();
253 0 : RepaintViewShellDoc();
254 : }
255 :
256 0 : void SmGraphicWindow::RepaintViewShellDoc()
257 : {
258 0 : SmDocShell &rDoc = *pViewShell->GetDoc();
259 0 : rDoc.Repaint();
260 0 : }
261 :
262 0 : IMPL_LINK_NOARG(SmGraphicWindow, CaretBlinkTimerHdl)
263 : {
264 0 : if (IsCursorVisible())
265 0 : SetIsCursorVisible(false);
266 : else
267 0 : SetIsCursorVisible(true);
268 :
269 0 : RepaintViewShellDoc();
270 :
271 0 : return 0;
272 : }
273 :
274 8 : void SmGraphicWindow::CaretBlinkInit()
275 : {
276 8 : aCaretBlinkTimer.SetTimeoutHdl(LINK(this, SmGraphicWindow, CaretBlinkTimerHdl));
277 8 : aCaretBlinkTimer.SetTimeout( ScrollableWindow::GetSettings().GetStyleSettings().GetCursorBlinkTime() );
278 8 : }
279 :
280 0 : void SmGraphicWindow::CaretBlinkStart()
281 : {
282 0 : if (!IsInlineEditEnabled())
283 0 : return;
284 0 : if ( aCaretBlinkTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME )
285 0 : aCaretBlinkTimer.Start();
286 : }
287 :
288 0 : void SmGraphicWindow::CaretBlinkStop()
289 : {
290 0 : if (!IsInlineEditEnabled())
291 0 : return;
292 0 : aCaretBlinkTimer.Stop();
293 : }
294 :
295 0 : void SmGraphicWindow::ShowCursor(bool bShow)
296 : // shows or hides the formula-cursor depending on 'bShow' is true or not
297 : {
298 0 : if (IsInlineEditEnabled())
299 0 : return;
300 :
301 0 : bool bInvert = bShow != IsCursorVisible();
302 :
303 0 : if (bInvert)
304 0 : InvertTracking(aCursorRect, SHOWTRACK_SMALL | SHOWTRACK_WINDOW);
305 :
306 0 : SetIsCursorVisible(bShow);
307 : }
308 :
309 8 : void SmGraphicWindow::ShowLine(bool bShow)
310 : {
311 8 : if (!IsInlineEditEnabled())
312 16 : return;
313 :
314 0 : bIsLineVisible = bShow;
315 : }
316 :
317 0 : void SmGraphicWindow::SetCursor(const SmNode *pNode)
318 : {
319 0 : if (IsInlineEditEnabled())
320 0 : return;
321 :
322 0 : const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree();
323 :
324 : // get appropriate rectangle
325 0 : Point aOffset (pNode->GetTopLeft() - pTree->GetTopLeft()),
326 0 : aTLPos (GetFormulaDrawPos() + aOffset);
327 0 : aTLPos.X() -= pNode->GetItalicLeftSpace();
328 0 : Size aSize (pNode->GetItalicSize());
329 :
330 0 : SetCursor(Rectangle(aTLPos, aSize));
331 : }
332 :
333 0 : void SmGraphicWindow::SetCursor(const Rectangle &rRect)
334 : // sets cursor to new position (rectangle) 'rRect'.
335 : // The old cursor will be removed, and the new one will be shown if
336 : // that is activated in the ConfigItem
337 : {
338 0 : if (IsInlineEditEnabled())
339 0 : return;
340 :
341 0 : SmModule *pp = SM_MOD();
342 :
343 0 : if (IsCursorVisible())
344 0 : ShowCursor(false); // clean up remainings of old cursor
345 0 : aCursorRect = rRect;
346 0 : if (pp->GetConfig()->IsShowFormulaCursor())
347 0 : ShowCursor(true); // draw new cursor
348 : }
349 :
350 0 : const SmNode * SmGraphicWindow::SetCursorPos(sal_uInt16 nRow, sal_uInt16 nCol)
351 : // looks for a VISIBLE node in the formula tree with it's token at
352 : // (or around) the position 'nRow', 'nCol' in the edit window
353 : // (row and column numbering starts with 1 there!).
354 : // If there is such a node the formula-cursor is set to cover that nodes
355 : // rectangle. If not the formula-cursor will be hidden.
356 : // In any case the search result is being returned.
357 : {
358 0 : if (IsInlineEditEnabled())
359 0 : return NULL;
360 :
361 : // find visible node with token at nRow, nCol
362 0 : const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree(),
363 0 : *pNode = 0;
364 0 : if (pTree)
365 0 : pNode = pTree->FindTokenAt(nRow, nCol);
366 :
367 0 : if (pNode)
368 0 : SetCursor(pNode);
369 : else
370 0 : ShowCursor(false);
371 :
372 0 : return pNode;
373 : }
374 :
375 0 : void SmGraphicWindow::Paint(const Rectangle&)
376 : {
377 : OSL_ENSURE(pViewShell, "Sm : NULL pointer");
378 :
379 0 : SmDocShell &rDoc = *pViewShell->GetDoc();
380 0 : Point aPoint;
381 :
382 0 : rDoc.DrawFormula(*this, aPoint, true); //! modifies aPoint to be the topleft
383 : //! corner of the formula
384 0 : SetFormulaDrawPos(aPoint);
385 0 : if(IsInlineEditEnabled()) {
386 : //Draw cursor if any...
387 0 : if(pViewShell->GetDoc()->HasCursor() && IsLineVisible())
388 0 : pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint, IsCursorVisible());
389 : } else {
390 0 : SetIsCursorVisible(false); // (old) cursor must be drawn again
391 :
392 0 : const SmEditWindow *pEdit = pViewShell->GetEditWindow();
393 0 : if (pEdit)
394 : { // get new position for formula-cursor (for possible altered formula)
395 : sal_uInt16 nRow, nCol;
396 0 : SmGetLeftSelectionPart(pEdit->GetSelection(), nRow, nCol);
397 0 : nRow++;
398 0 : nCol++;
399 0 : const SmNode *pFound = SetCursorPos(nRow, nCol);
400 :
401 0 : SmModule *pp = SM_MOD();
402 0 : if (pFound && pp->GetConfig()->IsShowFormulaCursor())
403 0 : ShowCursor(true);
404 : }
405 : }
406 0 : }
407 :
408 :
409 26 : void SmGraphicWindow::SetTotalSize ()
410 : {
411 26 : SmDocShell &rDoc = *pViewShell->GetDoc();
412 26 : const Size aTmp( PixelToLogic( LogicToPixel( rDoc.GetSize() )));
413 26 : if ( aTmp != ScrollableWindow::GetTotalSize() )
414 22 : ScrollableWindow::SetTotalSize( aTmp );
415 26 : }
416 :
417 0 : void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
418 : {
419 0 : if (!IsInlineEditEnabled()) {
420 0 : if (! (GetView() && GetView()->KeyInput(rKEvt)) )
421 0 : ScrollableWindow::KeyInput(rKEvt);
422 0 : return;
423 : }
424 :
425 0 : SmCursor& rCursor = pViewShell->GetDoc()->GetCursor();
426 0 : KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction();
427 0 : if (eFunc == KEYFUNC_COPY)
428 0 : rCursor.Copy();
429 0 : else if (eFunc == KEYFUNC_CUT)
430 0 : rCursor.Cut();
431 0 : else if (eFunc == KEYFUNC_PASTE)
432 0 : rCursor.Paste();
433 : else {
434 0 : sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
435 0 : switch(nCode)
436 : {
437 : case KEY_LEFT:
438 : {
439 0 : rCursor.Move(this, MoveLeft, !rKEvt.GetKeyCode().IsShift());
440 0 : }break;
441 : case KEY_RIGHT:
442 : {
443 0 : rCursor.Move(this, MoveRight, !rKEvt.GetKeyCode().IsShift());
444 0 : }break;
445 : case KEY_UP:
446 : {
447 0 : rCursor.Move(this, MoveUp, !rKEvt.GetKeyCode().IsShift());
448 0 : }break;
449 : case KEY_DOWN:
450 : {
451 0 : rCursor.Move(this, MoveDown, !rKEvt.GetKeyCode().IsShift());
452 0 : }break;
453 : case KEY_RETURN:
454 : {
455 0 : if(!rKEvt.GetKeyCode().IsShift())
456 0 : rCursor.InsertRow();
457 : #ifdef DEBUG_ENABLE_DUMPASDOT
458 : else {
459 : SmNode *pTree = (SmNode*)pViewShell->GetDoc()->GetFormulaTree();
460 : std::fstream file("/tmp/smath-dump.gv", std::fstream::out);
461 : OUString label(pViewShell->GetDoc()->GetText());
462 : pTree->DumpAsDot(file, &label);
463 : file.close();
464 : }
465 : #endif /* DEBUG_ENABLE_DUMPASDOT */
466 0 : }break;
467 : case KEY_DELETE:
468 : {
469 0 : if(!rCursor.HasSelection()){
470 0 : rCursor.Move(this, nCode == KEY_DELETE ? MoveRight : MoveLeft, false);
471 0 : if(rCursor.HasComplexSelection()) break;
472 : }
473 0 : rCursor.Delete();
474 0 : }break;
475 : case KEY_BACKSPACE:
476 : {
477 0 : rCursor.DeletePrev(this);
478 0 : }break;
479 : case KEY_ADD:
480 0 : rCursor.InsertElement(PlusElement);
481 0 : break;
482 : case KEY_SUBTRACT:
483 0 : if(rKEvt.GetKeyCode().IsShift())
484 0 : rCursor.InsertSubSup(RSUB);
485 : else
486 0 : rCursor.InsertElement(MinusElement);
487 0 : break;
488 : case KEY_MULTIPLY:
489 0 : rCursor.InsertElement(CDotElement);
490 0 : break;
491 : case KEY_DIVIDE:
492 0 : rCursor.InsertFraction();
493 0 : break;
494 : case KEY_LESS:
495 0 : rCursor.InsertElement(LessThanElement);
496 0 : break;
497 : case KEY_GREATER:
498 0 : rCursor.InsertElement(GreaterThanElement);
499 0 : break;
500 : case KEY_EQUAL:
501 0 : rCursor.InsertElement(EqualElement);
502 0 : break;
503 : default:
504 : {
505 0 : sal_Unicode code = rKEvt.GetCharCode();
506 0 : SmBraceNode* pBraceNode = NULL;
507 :
508 0 : if(code == ' ') {
509 0 : rCursor.InsertElement(BlankElement);
510 0 : }else if(code == '^') {
511 0 : rCursor.InsertSubSup(RSUP);
512 0 : }else if(code == '(') {
513 0 : rCursor.InsertBrackets(RoundBrackets);
514 0 : }else if(code == '[') {
515 0 : rCursor.InsertBrackets(SquareBrackets);
516 0 : }else if(code == '{') {
517 0 : rCursor.InsertBrackets(CurlyBrackets);
518 0 : }else if(code == '!') {
519 0 : rCursor.InsertElement(FactorialElement);
520 0 : }else if(code == '%') {
521 0 : rCursor.InsertElement(PercentElement);
522 0 : }else if(code == ')' && rCursor.IsAtTailOfBracket(RoundBrackets, &pBraceNode)) {
523 0 : rCursor.MoveAfterBracket(pBraceNode);
524 0 : }else if(code == ']' && rCursor.IsAtTailOfBracket(SquareBrackets, &pBraceNode)) {
525 0 : rCursor.MoveAfterBracket(pBraceNode);
526 0 : }else if(code == '}' && rCursor.IsAtTailOfBracket(CurlyBrackets, &pBraceNode)) {
527 0 : rCursor.MoveAfterBracket(pBraceNode);
528 : }else{
529 0 : if(code != 0){
530 0 : rCursor.InsertText(rtl::OUString(code));
531 0 : }else if (! (GetView() && GetView()->KeyInput(rKEvt)) )
532 0 : ScrollableWindow::KeyInput(rKEvt);
533 : }
534 : }
535 : }
536 : }
537 0 : CaretBlinkStop();
538 0 : CaretBlinkStart();
539 0 : SetIsCursorVisible(true);
540 0 : RepaintViewShellDoc();
541 : }
542 :
543 :
544 0 : void SmGraphicWindow::Command(const CommandEvent& rCEvt)
545 : {
546 0 : bool bCallBase = true;
547 0 : if ( !pViewShell->GetViewFrame()->GetFrame().IsInPlace() )
548 : {
549 0 : switch ( rCEvt.GetCommand() )
550 : {
551 : case COMMAND_CONTEXTMENU:
552 : {
553 0 : GetParent()->ToTop();
554 0 : SmResId aResId( RID_VIEWMENU );
555 0 : PopupMenu* pPopupMenu = new PopupMenu(aResId);
556 0 : pPopupMenu->SetSelectHdl(LINK(this, SmGraphicWindow, MenuSelectHdl));
557 0 : Point aPos(5, 5);
558 0 : if (rCEvt.IsMouseEvent())
559 0 : aPos = rCEvt.GetMousePosPixel();
560 : OSL_ENSURE( pViewShell, "view shell missing" );
561 :
562 : // added for replaceability of context menus
563 0 : pViewShell->GetViewFrame()->GetBindings().GetDispatcher()
564 0 : ->ExecutePopup( aResId, this, &aPos );
565 :
566 0 : delete pPopupMenu;
567 0 : bCallBase = false;
568 : }
569 0 : break;
570 :
571 : case COMMAND_WHEEL:
572 : {
573 0 : const CommandWheelData* pWData = rCEvt.GetWheelData();
574 0 : if ( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
575 : {
576 0 : sal_uInt16 nTmpZoom = GetZoom();
577 0 : if( 0L > pWData->GetDelta() )
578 0 : nTmpZoom -= 10;
579 : else
580 0 : nTmpZoom += 10;
581 0 : SetZoom( nTmpZoom );
582 0 : bCallBase = false;
583 : }
584 : }
585 0 : break;
586 : }
587 : }
588 0 : if ( bCallBase )
589 0 : ScrollableWindow::Command (rCEvt);
590 0 : }
591 :
592 :
593 0 : IMPL_LINK_INLINE_START( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
594 : {
595 0 : SmViewShell *pViewSh = GetView();
596 0 : if (pViewSh)
597 0 : pViewSh->GetViewFrame()->GetDispatcher()->Execute( pMenu->GetCurItemId() );
598 0 : return 0;
599 : }
600 0 : IMPL_LINK_INLINE_END( SmGraphicWindow, MenuSelectHdl, Menu *, pMenu )
601 :
602 :
603 18 : void SmGraphicWindow::SetZoom(sal_uInt16 Factor)
604 : {
605 18 : nZoom = Min(Max((sal_uInt16) Factor, (sal_uInt16) MINZOOM), (sal_uInt16) MAXZOOM);
606 18 : Fraction aFraction (nZoom, 100);
607 18 : SetMapMode( MapMode(MAP_100TH_MM, Point(), aFraction, aFraction) );
608 18 : SetTotalSize();
609 18 : SmViewShell *pViewSh = GetView();
610 18 : if (pViewSh)
611 18 : pViewSh->GetViewFrame()->GetBindings().Invalidate(SID_ATTR_ZOOM);
612 18 : Invalidate();
613 18 : }
614 :
615 :
616 6 : void SmGraphicWindow::ZoomToFitInWindow()
617 : {
618 6 : SmDocShell &rDoc = *pViewShell->GetDoc();
619 :
620 : // set defined mapmode before calling 'LogicToPixel' below
621 6 : SetMapMode(MapMode(MAP_100TH_MM));
622 :
623 6 : Size aSize (LogicToPixel(rDoc.GetSize()));
624 6 : Size aWindowSize (GetSizePixel());
625 :
626 6 : if (aSize.Width() > 0 && aSize.Height() > 0)
627 : {
628 12 : long nVal = Min ((85 * aWindowSize.Width()) / aSize.Width(),
629 18 : (85 * aWindowSize.Height()) / aSize.Height());
630 6 : SetZoom ( sal::static_int_cast< sal_uInt16 >(nVal) );
631 : }
632 6 : }
633 :
634 0 : uno::Reference< XAccessible > SmGraphicWindow::CreateAccessible()
635 : {
636 0 : if (!pAccessible)
637 : {
638 0 : pAccessible = new SmGraphicAccessible( this );
639 0 : xAccessible = pAccessible;
640 : }
641 0 : return xAccessible;
642 : }
643 :
644 : /**************************************************************************/
645 :
646 :
647 8 : SmGraphicController::SmGraphicController(SmGraphicWindow &rSmGraphic,
648 : sal_uInt16 nId_,
649 : SfxBindings &rBindings) :
650 : SfxControllerItem(nId_, rBindings),
651 8 : rGraphic(rSmGraphic)
652 : {
653 8 : }
654 :
655 :
656 0 : void SmGraphicController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
657 : {
658 0 : rGraphic.SetTotalSize();
659 0 : rGraphic.Invalidate();
660 0 : SfxControllerItem::StateChanged (nSID, eState, pState);
661 0 : }
662 :
663 :
664 : /**************************************************************************/
665 :
666 :
667 8 : SmEditController::SmEditController(SmEditWindow &rSmEdit,
668 : sal_uInt16 nId_,
669 : SfxBindings &rBindings) :
670 : SfxControllerItem(nId_, rBindings),
671 8 : rEdit(rSmEdit)
672 : {
673 8 : }
674 :
675 :
676 : #if OSL_DEBUG_LEVEL > 1
677 : SmEditController::~SmEditController()
678 : {
679 : }
680 : #endif
681 :
682 :
683 0 : void SmEditController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
684 : {
685 0 : const SfxStringItem *pItem = PTR_CAST(SfxStringItem, pState);
686 :
687 0 : if ((pItem != NULL) && (rEdit.GetText() != pItem->GetValue()))
688 0 : rEdit.SetText(pItem->GetValue());
689 0 : SfxControllerItem::StateChanged (nSID, eState, pState);
690 0 : }
691 :
692 :
693 : /**************************************************************************/
694 :
695 8 : SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings *pBindings_, SfxChildWindow *pChildWindow,
696 : Window *pParent) :
697 : SfxDockingWindow(pBindings_, pChildWindow, pParent, SmResId(RID_CMDBOXWINDOW)),
698 : aEdit (*this),
699 : aController (aEdit, SID_TEXT, *pBindings_),
700 8 : bExiting (false)
701 : {
702 8 : Hide ();
703 :
704 8 : aInitialFocusTimer.SetTimeoutHdl(LINK(this, SmCmdBoxWindow, InitialFocusTimerHdl));
705 8 : aInitialFocusTimer.SetTimeout(100);
706 8 : }
707 :
708 :
709 24 : SmCmdBoxWindow::~SmCmdBoxWindow ()
710 : {
711 8 : aInitialFocusTimer.Stop();
712 8 : bExiting = true;
713 16 : }
714 :
715 :
716 70 : SmViewShell * SmCmdBoxWindow::GetView()
717 : {
718 70 : SfxDispatcher *pDispatcher = GetBindings().GetDispatcher();
719 70 : SfxViewShell *pView = pDispatcher ? pDispatcher->GetFrame()->GetViewShell() : NULL;
720 70 : return PTR_CAST(SmViewShell, pView);
721 : }
722 :
723 0 : void SmCmdBoxWindow::Resize()
724 : {
725 0 : Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
726 0 : aRect.Left() += CMD_BOX_PADDING;
727 0 : aRect.Top() += CMD_BOX_PADDING;
728 0 : aRect.Right() -= CMD_BOX_PADDING;
729 0 : aRect.Bottom() -= CMD_BOX_PADDING;
730 :
731 0 : DecorationView aView(this);
732 0 : aRect = aView.DrawFrame( aRect, FRAME_DRAW_IN | FRAME_DRAW_NODRAW );
733 :
734 0 : aEdit.SetPosSizePixel(aRect.TopLeft(), aRect.GetSize());
735 0 : SfxDockingWindow::Resize();
736 0 : Invalidate();
737 0 : }
738 :
739 :
740 0 : void SmCmdBoxWindow::Paint(const Rectangle& /*rRect*/)
741 : {
742 0 : Rectangle aRect = Rectangle(Point(0, 0), GetOutputSizePixel());
743 0 : aRect.Left() += CMD_BOX_PADDING;
744 0 : aRect.Top() += CMD_BOX_PADDING;
745 0 : aRect.Right() -= CMD_BOX_PADDING;
746 0 : aRect.Bottom() -= CMD_BOX_PADDING;
747 :
748 0 : DecorationView aView(this);
749 0 : aView.DrawFrame( aRect, FRAME_DRAW_IN );
750 0 : }
751 :
752 :
753 0 : Size SmCmdBoxWindow::CalcDockingSize(SfxChildAlignment eAlign)
754 : {
755 0 : switch (eAlign)
756 : {
757 : case SFX_ALIGN_LEFT:
758 : case SFX_ALIGN_RIGHT:
759 0 : return Size();
760 : default:
761 0 : break;
762 : }
763 0 : return SfxDockingWindow::CalcDockingSize(eAlign);
764 : }
765 :
766 :
767 0 : SfxChildAlignment SmCmdBoxWindow::CheckAlignment(SfxChildAlignment eActual,
768 : SfxChildAlignment eWish)
769 : {
770 0 : switch (eWish)
771 : {
772 : case SFX_ALIGN_TOP:
773 : case SFX_ALIGN_BOTTOM:
774 : case SFX_ALIGN_NOALIGNMENT:
775 0 : return eWish;
776 : default:
777 0 : break;
778 : }
779 :
780 0 : return eActual;
781 : }
782 :
783 :
784 8 : void SmCmdBoxWindow::StateChanged( StateChangedType nStateChange )
785 : {
786 8 : if (STATE_CHANGE_INITSHOW == nStateChange)
787 : {
788 0 : Resize(); // avoid SmEditWindow not being painted correctly
789 :
790 : // set initial position of window in floating mode
791 0 : if (IsFloatingMode())
792 0 : AdjustPosition(); //! don't change pos in docking-mode !
793 :
794 0 : aInitialFocusTimer.Start();
795 : }
796 :
797 8 : SfxDockingWindow::StateChanged( nStateChange );
798 8 : }
799 :
800 :
801 0 : IMPL_LINK( SmCmdBoxWindow, InitialFocusTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
802 : {
803 : // We want to have the focus in the edit window once Math has been opened
804 : // to allow for immediate typing.
805 : // Problem: There is no proper way to do this
806 : // Thus: this timer based soultion has been implemented (see GrabFocus below)
807 : //
808 : // Follow-up problem (#i114910): grabing the focus may bust the help system since
809 : // it relies on getting the current frame which conflicts with grabbing the focus.
810 : // Thus aside from the 'GrabFocus' call everything else is to get the
811 : // help reliably working despite using 'GrabFocus'.
812 :
813 : try
814 : {
815 0 : uno::Reference< frame::XDesktop > xDesktop;
816 0 : uno::Reference< lang::XMultiServiceFactory > xSMGR( comphelper::getProcessServiceFactory() );
817 0 : if (xSMGR.is())
818 : {
819 : xDesktop = uno::Reference< frame::XDesktop >(
820 0 : xSMGR->createInstance( "com.sun.star.frame.Desktop"), uno::UNO_QUERY_THROW );
821 : }
822 :
823 0 : aEdit.GrabFocus();
824 :
825 0 : if (xDesktop.is())
826 : {
827 0 : bool bInPlace = GetView()->GetViewFrame()->GetFrame().IsInPlace();
828 0 : uno::Reference< frame::XFrame > xFrame( GetBindings().GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface());
829 0 : if ( bInPlace )
830 : {
831 0 : uno::Reference< container::XChild > xModel( GetView()->GetDoc()->GetModel(), uno::UNO_QUERY_THROW );
832 0 : uno::Reference< frame::XModel > xParent( xModel->getParent(), uno::UNO_QUERY_THROW );
833 0 : uno::Reference< frame::XController > xParentCtrler( xParent->getCurrentController() );
834 0 : uno::Reference< frame::XFramesSupplier > xParentFrame( xParentCtrler->getFrame(), uno::UNO_QUERY_THROW );
835 0 : xParentFrame->setActiveFrame( xFrame );
836 : }
837 : else
838 : {
839 0 : uno::Reference< frame::XFramesSupplier > xFramesSupplier( xDesktop, uno::UNO_QUERY );
840 0 : xFramesSupplier->setActiveFrame( xFrame );
841 0 : }
842 0 : }
843 : }
844 0 : catch (uno::Exception &)
845 : {
846 : OSL_FAIL( "failed to properly set initial focus to edit window" );
847 : }
848 0 : return 0;
849 : }
850 :
851 :
852 0 : void SmCmdBoxWindow::AdjustPosition()
853 : {
854 0 : Point aPt;
855 0 : const Rectangle aRect( aPt, GetParent()->GetOutputSizePixel() );
856 : Point aTopLeft( Point( aRect.Left(),
857 0 : aRect.Bottom() - GetSizePixel().Height() ) );
858 0 : Point aPos( GetParent()->OutputToScreenPixel( aTopLeft ) );
859 0 : if (aPos.X() < 0)
860 0 : aPos.X() = 0;
861 0 : if (aPos.Y() < 0)
862 0 : aPos.Y() = 0;
863 0 : SetPosPixel( aPos );
864 0 : }
865 :
866 :
867 0 : void SmCmdBoxWindow::ToggleFloatingMode()
868 : {
869 0 : SfxDockingWindow::ToggleFloatingMode();
870 :
871 0 : if (GetFloatingWindow())
872 0 : GetFloatingWindow()->SetMinOutputSizePixel(Size (200, 50));
873 0 : }
874 :
875 :
876 0 : void SmCmdBoxWindow::GetFocus()
877 : {
878 0 : if (!bExiting)
879 0 : aEdit.GrabFocus();
880 0 : }
881 :
882 : /**************************************************************************/
883 :
884 :
885 30 : SFX_IMPL_DOCKINGWINDOW_WITHID(SmCmdBoxWrapper, SID_CMDBOXWINDOW);
886 :
887 0 : SmCmdBoxWrapper::SmCmdBoxWrapper(Window *pParentWindow, sal_uInt16 nId,
888 : SfxBindings *pBindings,
889 : SfxChildWinInfo *pInfo) :
890 0 : SfxChildWindow(pParentWindow, nId)
891 : {
892 0 : pWindow = new SmCmdBoxWindow(pBindings, this, pParentWindow);
893 :
894 : // make window docked to the bottom initially (after first start)
895 0 : eChildAlignment = SFX_ALIGN_BOTTOM;
896 0 : ((SfxDockingWindow *)pWindow)->Initialize(pInfo);
897 0 : }
898 :
899 :
900 : #if OSL_DEBUG_LEVEL > 1
901 : SmCmdBoxWrapper::~SmCmdBoxWrapper()
902 : {
903 : }
904 : #endif
905 :
906 :
907 : /**************************************************************************/
908 :
909 : struct SmViewShell_Impl
910 : {
911 : sfx2::DocumentInserter* pDocInserter;
912 : SfxRequest* pRequest;
913 : SvtMiscOptions aOpts;
914 :
915 8 : SmViewShell_Impl() :
916 : pDocInserter( NULL )
917 8 : , pRequest( NULL )
918 8 : {}
919 :
920 0 : ~SmViewShell_Impl()
921 0 : {
922 0 : delete pDocInserter;
923 0 : delete pRequest;
924 0 : }
925 : };
926 :
927 1286 : TYPEINIT1( SmViewShell, SfxViewShell );
928 :
929 46 : SFX_IMPL_INTERFACE(SmViewShell, SfxViewShell, SmResId(0))
930 : {
931 12 : SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS | SFX_VISIBILITY_STANDARD |
932 : SFX_VISIBILITY_FULLSCREEN | SFX_VISIBILITY_SERVER,
933 6 : SmResId(RID_MATH_TOOLBOX ));
934 : //Dummy-Objectbar, to avoid quiver while activating
935 :
936 6 : SFX_CHILDWINDOW_REGISTRATION(SID_TASKPANE);
937 6 : SFX_CHILDWINDOW_REGISTRATION(SmToolBoxWrapper::GetChildWindowId());
938 6 : SFX_CHILDWINDOW_REGISTRATION(SmCmdBoxWrapper::GetChildWindowId());
939 6 : }
940 :
941 :
942 20 : SFX_IMPL_NAMED_VIEWFACTORY(SmViewShell, "Default")
943 : {
944 6 : SFX_VIEW_REGISTRATION(SmDocShell);
945 6 : }
946 :
947 :
948 0 : Size SmViewShell::GetOptimalSizePixel() const
949 : {
950 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetOptimalSizePixel" );
951 :
952 0 : return aGraphic.LogicToPixel( ((SmViewShell*)this)->GetDoc()->GetSize() );
953 : }
954 :
955 :
956 0 : void SmViewShell::AdjustPosSizePixel(const Point &rPos, const Size &rSize)
957 : {
958 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::AdjustPosSizePixel" );
959 :
960 0 : aGraphic.SetPosSizePixel(rPos, rSize);
961 0 : }
962 :
963 :
964 0 : void SmViewShell::InnerResizePixel(const Point &rOfs, const Size &rSize)
965 : {
966 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::InnerResizePixel" );
967 :
968 0 : Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
969 0 : if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
970 : {
971 0 : Size aProvidedSize = GetWindow()->PixelToLogic( rSize, MAP_100TH_MM );
972 0 : SfxViewShell::SetZoomFactor( Fraction( aProvidedSize.Width(), aObjSize.Width() ),
973 0 : Fraction( aProvidedSize.Height(), aObjSize.Height() ) );
974 : }
975 :
976 0 : SetBorderPixel( SvBorder() );
977 0 : GetGraphicWindow().SetPosSizePixel(rOfs, rSize);
978 0 : GetGraphicWindow().SetTotalSize();
979 0 : }
980 :
981 :
982 8 : void SmViewShell::OuterResizePixel(const Point &rOfs, const Size &rSize)
983 : {
984 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::OuterResizePixel" );
985 :
986 8 : SmGraphicWindow &rWin = GetGraphicWindow();
987 8 : rWin.SetPosSizePixel(rOfs, rSize);
988 8 : if (GetDoc()->IsPreview())
989 0 : rWin.ZoomToFitInWindow();
990 8 : rWin.Update();
991 8 : }
992 :
993 :
994 0 : void SmViewShell::QueryObjAreaPixel( Rectangle& rRect ) const
995 : {
996 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::QueryObjAreaPixel" );
997 :
998 0 : rRect.SetSize( GetGraphicWindow().GetSizePixel() );
999 0 : }
1000 :
1001 :
1002 0 : void SmViewShell::SetZoomFactor( const Fraction &rX, const Fraction &rY )
1003 : {
1004 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetZoomFactor" );
1005 :
1006 0 : const Fraction &rFrac = rX < rY ? rX : rY;
1007 0 : GetGraphicWindow().SetZoom( (sal_uInt16) long(rFrac * Fraction( 100, 1 )) );
1008 :
1009 : //To avoid rounding errors base class regulates crooked values too
1010 : //if necessary
1011 0 : SfxViewShell::SetZoomFactor( rX, rY );
1012 0 : }
1013 :
1014 :
1015 0 : Size SmViewShell::GetTextLineSize(OutputDevice& rDevice, const String& rLine)
1016 : {
1017 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetTextLineSize" );
1018 :
1019 0 : Size aSize(rDevice.GetTextWidth(rLine), rDevice.GetTextHeight());
1020 0 : sal_uInt16 nTabs = comphelper::string::getTokenCount(rLine, '\t');
1021 :
1022 0 : if (nTabs > 0)
1023 : {
1024 0 : long TabPos = rDevice.GetTextWidth(rtl::OUString('n')) * 8;
1025 :
1026 0 : aSize.Width() = 0;
1027 :
1028 0 : for (sal_uInt16 i = 0; i < nTabs; i++)
1029 : {
1030 0 : if (i > 0)
1031 0 : aSize.Width() = ((aSize.Width() / TabPos) + 1) * TabPos;
1032 :
1033 0 : OUString aText = rLine.GetToken(i, '\t');
1034 0 : aText = comphelper::string::stripStart(aText, '\t');
1035 0 : aText = comphelper::string::stripEnd(aText, '\t');
1036 0 : aSize.Width() += rDevice.GetTextWidth(aText);
1037 0 : }
1038 : }
1039 :
1040 0 : return aSize;
1041 : }
1042 :
1043 :
1044 0 : Size SmViewShell::GetTextSize(OutputDevice& rDevice, const String& rText, long MaxWidth)
1045 : {
1046 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetTextSize" );
1047 :
1048 0 : Size aSize;
1049 0 : Size TextSize;
1050 0 : sal_uInt16 nLines = comphelper::string::getTokenCount(rText, '\n');
1051 :
1052 0 : for (sal_uInt16 i = 0; i < nLines; i++)
1053 : {
1054 0 : OUString aLine = rText.GetToken(i, '\n');
1055 0 : aLine = comphelper::string::remove(aLine, '\r');
1056 0 : aLine = comphelper::string::stripStart(aLine, '\n');
1057 0 : aLine = comphelper::string::stripEnd(aLine, '\n');
1058 :
1059 0 : aSize = GetTextLineSize(rDevice, aLine);
1060 :
1061 0 : if (aSize.Width() > MaxWidth)
1062 : {
1063 0 : do
1064 : {
1065 0 : OUString aText;
1066 0 : sal_Int32 m = aLine.getLength();
1067 0 : sal_Int32 nLen = m;
1068 :
1069 0 : for (sal_Int32 n = 0; n < nLen; n++)
1070 : {
1071 0 : sal_Unicode cLineChar = aLine[n];
1072 0 : if ((cLineChar == ' ') || (cLineChar == '\t'))
1073 : {
1074 0 : aText = aLine.copy(0, n);
1075 0 : if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
1076 0 : m = n;
1077 : else
1078 0 : break;
1079 : }
1080 : }
1081 :
1082 0 : aText = aLine.copy(0, m);
1083 0 : aLine = aLine.replaceAt(0, m, "");
1084 0 : aSize = GetTextLineSize(rDevice, aText);
1085 0 : TextSize.Height() += aSize.Height();
1086 0 : TextSize.Width() = Max(TextSize.Width(), Min(aSize.Width(), MaxWidth));
1087 :
1088 0 : aLine = comphelper::string::stripStart(aLine, ' ');
1089 0 : aLine = comphelper::string::stripStart(aLine, '\t');
1090 0 : aLine = comphelper::string::stripStart(aLine, ' ');
1091 : }
1092 0 : while (!aLine.isEmpty());
1093 : }
1094 : else
1095 : {
1096 0 : TextSize.Height() += aSize.Height();
1097 0 : TextSize.Width() = Max(TextSize.Width(), aSize.Width());
1098 : }
1099 0 : }
1100 :
1101 0 : return TextSize;
1102 : }
1103 :
1104 :
1105 0 : void SmViewShell::DrawTextLine(OutputDevice& rDevice, const Point& rPosition, const String& rLine)
1106 : {
1107 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::DrawTextLine" );
1108 :
1109 0 : Point aPoint (rPosition);
1110 0 : sal_uInt16 nTabs = comphelper::string::getTokenCount(rLine, '\t');
1111 :
1112 0 : if (nTabs > 0)
1113 : {
1114 0 : long TabPos = rDevice.GetTextWidth(rtl::OUString('n')) * 8;
1115 :
1116 0 : for (sal_uInt16 i = 0; i < nTabs; i++)
1117 : {
1118 0 : if (i > 0)
1119 0 : aPoint.X() = ((aPoint.X() / TabPos) + 1) * TabPos;
1120 :
1121 0 : OUString aText = rLine.GetToken(i, '\t');
1122 0 : aText = comphelper::string::stripStart(aText, '\t');
1123 0 : aText = comphelper::string::stripEnd(aText, '\t');
1124 0 : rDevice.DrawText(aPoint, aText);
1125 0 : aPoint.X() += rDevice.GetTextWidth(aText);
1126 0 : }
1127 : }
1128 : else
1129 0 : rDevice.DrawText(aPoint, rLine);
1130 0 : }
1131 :
1132 :
1133 0 : void SmViewShell::DrawText(OutputDevice& rDevice, const Point& rPosition, const String& rText, sal_uInt16 MaxWidth)
1134 : {
1135 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::DrawText" );
1136 :
1137 0 : sal_uInt16 nLines = comphelper::string::getTokenCount(rText, '\n');
1138 0 : Point aPoint (rPosition);
1139 0 : Size aSize;
1140 :
1141 0 : for (sal_uInt16 i = 0; i < nLines; i++)
1142 : {
1143 0 : OUString aLine = rText.GetToken(i, '\n');
1144 0 : aLine = comphelper::string::remove(aLine, '\r');
1145 0 : aLine = comphelper::string::stripEnd(aLine, '\n');
1146 0 : aLine = comphelper::string::stripEnd(aLine, '\n');
1147 0 : aSize = GetTextLineSize(rDevice, aLine);
1148 0 : if (aSize.Width() > MaxWidth)
1149 : {
1150 0 : do
1151 : {
1152 0 : OUString aText;
1153 0 : sal_Int32 m = aLine.getLength();
1154 0 : sal_Int32 nLen = m;
1155 :
1156 0 : for (sal_Int32 n = 0; n < nLen; n++)
1157 : {
1158 0 : sal_Unicode cLineChar = aLine[n];
1159 0 : if ((cLineChar == ' ') || (cLineChar == '\t'))
1160 : {
1161 0 : aText = aLine.copy(0, n);
1162 0 : if (GetTextLineSize(rDevice, aText).Width() < MaxWidth)
1163 0 : m = n;
1164 : else
1165 0 : break;
1166 : }
1167 : }
1168 0 : aText = aLine.copy(0, m);
1169 0 : aLine = aLine.replaceAt(0, m, "");
1170 :
1171 0 : DrawTextLine(rDevice, aPoint, aText);
1172 0 : aPoint.Y() += aSize.Height();
1173 :
1174 0 : aLine = comphelper::string::stripStart(aLine, ' ');
1175 0 : aLine = comphelper::string::stripStart(aLine, '\t');
1176 0 : aLine = comphelper::string::stripStart(aLine, ' ');
1177 : }
1178 0 : while (GetTextLineSize(rDevice, aLine).Width() > MaxWidth);
1179 :
1180 : // print the remaining text
1181 0 : if (!aLine.isEmpty())
1182 : {
1183 0 : DrawTextLine(rDevice, aPoint, aLine);
1184 0 : aPoint.Y() += aSize.Height();
1185 : }
1186 : }
1187 : else
1188 : {
1189 0 : DrawTextLine(rDevice, aPoint, aLine);
1190 0 : aPoint.Y() += aSize.Height();
1191 : }
1192 0 : }
1193 0 : }
1194 :
1195 0 : void SmViewShell::Impl_Print(
1196 : OutputDevice &rOutDev,
1197 : const SmPrintUIOptions &rPrintUIOptions,
1198 : Rectangle aOutRect, Point aZeroPoint )
1199 : {
1200 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Impl_Print" );
1201 :
1202 0 : const bool bIsPrintTitle = rPrintUIOptions.getBoolValue( PRTUIOPT_TITLE_ROW, sal_True );
1203 0 : const bool bIsPrintFrame = rPrintUIOptions.getBoolValue( PRTUIOPT_BORDER, sal_True );
1204 0 : const bool bIsPrintFormulaText = rPrintUIOptions.getBoolValue( PRTUIOPT_FORMULA_TEXT, sal_True );
1205 0 : SmPrintSize ePrintSize( static_cast< SmPrintSize >( rPrintUIOptions.getIntValue( PRTUIOPT_PRINT_FORMAT, PRINT_SIZE_NORMAL ) ));
1206 0 : const sal_uInt16 nZoomFactor = static_cast< sal_uInt16 >(rPrintUIOptions.getIntValue( PRTUIOPT_PRINT_SCALE, 100 ));
1207 :
1208 0 : rOutDev.Push();
1209 0 : rOutDev.SetLineColor( Color(COL_BLACK) );
1210 :
1211 : // output text on top
1212 0 : if (bIsPrintTitle)
1213 : {
1214 0 : Size aSize600 (0, 600);
1215 0 : Size aSize650 (0, 650);
1216 0 : Font aFont(FAMILY_DONTKNOW, aSize600);
1217 :
1218 0 : aFont.SetAlign(ALIGN_TOP);
1219 0 : aFont.SetWeight(WEIGHT_BOLD);
1220 0 : aFont.SetSize(aSize650);
1221 0 : aFont.SetColor( Color(COL_BLACK) );
1222 0 : rOutDev.SetFont(aFont);
1223 :
1224 0 : Size aTitleSize (GetTextSize(rOutDev, GetDoc()->GetTitle(), aOutRect.GetWidth() - 200));
1225 :
1226 0 : aFont.SetWeight(WEIGHT_NORMAL);
1227 0 : aFont.SetSize(aSize600);
1228 0 : rOutDev.SetFont(aFont);
1229 :
1230 0 : Size aDescSize (GetTextSize(rOutDev, GetDoc()->GetComment(), aOutRect.GetWidth() - 200));
1231 :
1232 0 : if (bIsPrintFrame)
1233 : rOutDev.DrawRect(Rectangle(aOutRect.TopLeft(),
1234 0 : Size(aOutRect.GetWidth(), 100 + aTitleSize.Height() + 200 + aDescSize.Height() + 100)));
1235 0 : aOutRect.Top() += 200;
1236 :
1237 : // output title
1238 0 : aFont.SetWeight(WEIGHT_BOLD);
1239 0 : aFont.SetSize(aSize650);
1240 0 : rOutDev.SetFont(aFont);
1241 0 : Point aPoint(aOutRect.Left() + (aOutRect.GetWidth() - aTitleSize.Width()) / 2,
1242 0 : aOutRect.Top());
1243 0 : DrawText(rOutDev, aPoint, GetDoc()->GetTitle(),
1244 0 : sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
1245 0 : aOutRect.Top() += aTitleSize.Height() + 200;
1246 :
1247 : // output description
1248 0 : aFont.SetWeight(WEIGHT_NORMAL);
1249 0 : aFont.SetSize(aSize600);
1250 0 : rOutDev.SetFont(aFont);
1251 0 : aPoint.X() = aOutRect.Left() + (aOutRect.GetWidth() - aDescSize.Width()) / 2;
1252 0 : aPoint.Y() = aOutRect.Top();
1253 : DrawText(rOutDev, aPoint, GetDoc()->GetComment(),
1254 0 : sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
1255 0 : aOutRect.Top() += aDescSize.Height() + 300;
1256 : }
1257 :
1258 : // output text on bottom
1259 0 : if (bIsPrintFormulaText)
1260 : {
1261 0 : Font aFont(FAMILY_DONTKNOW, Size(0, 600));
1262 0 : aFont.SetAlign(ALIGN_TOP);
1263 0 : aFont.SetColor( Color(COL_BLACK) );
1264 :
1265 : // get size
1266 0 : rOutDev.SetFont(aFont);
1267 :
1268 0 : Size aSize (GetTextSize(rOutDev, GetDoc()->GetText(), aOutRect.GetWidth() - 200));
1269 :
1270 0 : aOutRect.Bottom() -= aSize.Height() + 600;
1271 :
1272 0 : if (bIsPrintFrame)
1273 : rOutDev.DrawRect(Rectangle(aOutRect.BottomLeft(),
1274 0 : Size(aOutRect.GetWidth(), 200 + aSize.Height() + 200)));
1275 :
1276 0 : Point aPoint (aOutRect.Left() + (aOutRect.GetWidth() - aSize.Width()) / 2,
1277 0 : aOutRect.Bottom() + 300);
1278 0 : DrawText(rOutDev, aPoint, GetDoc()->GetText(),
1279 0 : sal::static_int_cast< sal_uInt16 >(aOutRect.GetWidth() - 200));
1280 0 : aOutRect.Bottom() -= 200;
1281 : }
1282 :
1283 0 : if (bIsPrintFrame)
1284 0 : rOutDev.DrawRect(aOutRect);
1285 :
1286 0 : aOutRect.Top() += 100;
1287 0 : aOutRect.Left() += 100;
1288 0 : aOutRect.Bottom() -= 100;
1289 0 : aOutRect.Right() -= 100;
1290 :
1291 0 : Size aSize (GetDoc()->GetSize());
1292 :
1293 0 : MapMode OutputMapMode;
1294 : // PDF export should always use PRINT_SIZE_NORMAL ...
1295 0 : if (!rPrintUIOptions.getBoolValue( "IsPrinter", sal_False ) )
1296 0 : ePrintSize = PRINT_SIZE_NORMAL;
1297 0 : switch (ePrintSize)
1298 : {
1299 : case PRINT_SIZE_NORMAL:
1300 0 : OutputMapMode = MapMode(MAP_100TH_MM);
1301 0 : break;
1302 :
1303 : case PRINT_SIZE_SCALED:
1304 0 : if ((aSize.Width() > 0) && (aSize.Height() > 0))
1305 : {
1306 : Size OutputSize (rOutDev.LogicToPixel(Size(aOutRect.GetWidth(),
1307 0 : aOutRect.GetHeight()), MapMode(MAP_100TH_MM)));
1308 0 : Size GraphicSize (rOutDev.LogicToPixel(aSize, MapMode(MAP_100TH_MM)));
1309 0 : sal_uInt16 nZ = (sal_uInt16) Min((long)Fraction(OutputSize.Width() * 100L, GraphicSize.Width()),
1310 0 : (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
1311 0 : Fraction aFraction ((sal_uInt16) Max ((sal_uInt16) MINZOOM, Min((sal_uInt16) MAXZOOM, (sal_uInt16) (nZ - 10))), (sal_uInt16) 100);
1312 :
1313 0 : OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
1314 : }
1315 : else
1316 0 : OutputMapMode = MapMode(MAP_100TH_MM);
1317 0 : break;
1318 :
1319 : case PRINT_SIZE_ZOOMED:
1320 : {
1321 0 : Fraction aFraction( nZoomFactor, 100 );
1322 :
1323 0 : OutputMapMode = MapMode(MAP_100TH_MM, aZeroPoint, aFraction, aFraction);
1324 : break;
1325 : }
1326 : }
1327 :
1328 : aSize = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aSize, OutputMapMode),
1329 0 : MapMode(MAP_100TH_MM));
1330 :
1331 0 : Point aPos (aOutRect.Left() + (aOutRect.GetWidth() - aSize.Width()) / 2,
1332 0 : aOutRect.Top() + (aOutRect.GetHeight() - aSize.Height()) / 2);
1333 :
1334 0 : aPos = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aPos, MapMode(MAP_100TH_MM)),
1335 0 : OutputMapMode);
1336 0 : aOutRect = rOutDev.PixelToLogic(rOutDev.LogicToPixel(aOutRect, MapMode(MAP_100TH_MM)),
1337 0 : OutputMapMode);
1338 :
1339 0 : rOutDev.SetMapMode(OutputMapMode);
1340 0 : rOutDev.SetClipRegion(Region(aOutRect));
1341 0 : GetDoc()->DrawFormula(rOutDev, aPos, false);
1342 0 : rOutDev.SetClipRegion();
1343 :
1344 0 : rOutDev.Pop();
1345 0 : }
1346 :
1347 0 : sal_uInt16 SmViewShell::Print(SfxProgress & /*rProgress*/, sal_Bool /*bIsAPI*/)
1348 : {
1349 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Print" );
1350 : OSL_FAIL( "SmViewShell::Print: no longer used with new UI print dialog. Should be removed!!" );
1351 0 : return 0;
1352 : }
1353 :
1354 :
1355 0 : SfxPrinter* SmViewShell::GetPrinter(sal_Bool bCreate)
1356 : {
1357 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetPrinter" );
1358 :
1359 0 : SmDocShell *pDoc = GetDoc();
1360 0 : if ( pDoc->HasPrinter() || bCreate )
1361 0 : return pDoc->GetPrinter();
1362 0 : return 0;
1363 : }
1364 :
1365 :
1366 0 : sal_uInt16 SmViewShell::SetPrinter(SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
1367 : {
1368 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetPrinter" );
1369 0 : SfxPrinter *pOld = GetDoc()->GetPrinter();
1370 0 : if ( pOld && pOld->IsPrinting() )
1371 0 : return SFX_PRINTERROR_BUSY;
1372 :
1373 0 : if ((nDiffFlags & SFX_PRINTER_PRINTER) == SFX_PRINTER_PRINTER)
1374 0 : GetDoc()->SetPrinter( pNewPrinter );
1375 :
1376 0 : if ((nDiffFlags & SFX_PRINTER_OPTIONS) == SFX_PRINTER_OPTIONS)
1377 : {
1378 0 : SmModule *pp = SM_MOD();
1379 0 : pp->GetConfig()->ItemSetToConfig(pNewPrinter->GetOptions());
1380 : }
1381 0 : return 0;
1382 : }
1383 :
1384 0 : bool SmViewShell::HasPrintOptionsPage() const
1385 : {
1386 0 : return true;
1387 : }
1388 :
1389 0 : SfxTabPage* SmViewShell::CreatePrintOptionsPage(Window *pParent,
1390 : const SfxItemSet &rOptions)
1391 : {
1392 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::CreatePrintOptionsPage" );
1393 :
1394 0 : return SmPrintOptionsTabPage::Create(pParent, rOptions);
1395 : }
1396 :
1397 :
1398 18 : SmEditWindow *SmViewShell::GetEditWindow()
1399 : {
1400 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetEditWindow" );
1401 :
1402 : SmCmdBoxWrapper *pWrapper = (SmCmdBoxWrapper *) GetViewFrame()->
1403 18 : GetChildWindow( SmCmdBoxWrapper::GetChildWindowId() );
1404 :
1405 18 : if (pWrapper != NULL)
1406 : {
1407 0 : SmEditWindow *pEditWin = pWrapper->GetEditWindow();
1408 : OSL_ENSURE( pEditWin, "SmEditWindow missing" );
1409 0 : return pEditWin;
1410 : }
1411 :
1412 18 : return NULL;
1413 : }
1414 :
1415 :
1416 8 : void SmViewShell::SetStatusText(const OUString& rText)
1417 : {
1418 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SetStatusText" );
1419 :
1420 8 : aStatusText = rText;
1421 8 : GetViewFrame()->GetBindings().Invalidate(SID_TEXTSTATUS);
1422 8 : }
1423 :
1424 :
1425 0 : void SmViewShell::ShowError( const SmErrorDesc *pErrorDesc )
1426 : {
1427 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::ShowError" );
1428 :
1429 : OSL_ENSURE(GetDoc(), "Sm : Document missing");
1430 0 : if (pErrorDesc || 0 != (pErrorDesc = GetDoc()->GetParser().GetError(0)) )
1431 : {
1432 0 : SetStatusText( pErrorDesc->Text );
1433 0 : GetEditWindow()->MarkError( Point( pErrorDesc->pNode->GetColumn(),
1434 0 : pErrorDesc->pNode->GetRow()));
1435 : }
1436 0 : }
1437 :
1438 :
1439 0 : void SmViewShell::NextError()
1440 : {
1441 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::NextError" );
1442 :
1443 : OSL_ENSURE(GetDoc(), "Sm : Document missing");
1444 0 : const SmErrorDesc *pErrorDesc = GetDoc()->GetParser().NextError();
1445 :
1446 0 : if (pErrorDesc)
1447 0 : ShowError( pErrorDesc );
1448 0 : }
1449 :
1450 :
1451 0 : void SmViewShell::PrevError()
1452 : {
1453 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::PrevError" );
1454 :
1455 : OSL_ENSURE(GetDoc(), "Sm : Document missing");
1456 0 : const SmErrorDesc *pErrorDesc = GetDoc()->GetParser().PrevError();
1457 :
1458 0 : if (pErrorDesc)
1459 0 : ShowError( pErrorDesc );
1460 0 : }
1461 :
1462 :
1463 0 : bool SmViewShell::Insert( SfxMedium& rMedium )
1464 : {
1465 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Insert" );
1466 :
1467 0 : SmDocShell *pDoc = GetDoc();
1468 0 : bool bRet = false;
1469 :
1470 0 : uno::Reference < embed::XStorage > xStorage = rMedium.GetStorage();
1471 0 : uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
1472 0 : if ( xNameAccess.is() && xNameAccess->getElementNames().getLength() )
1473 : {
1474 0 : if ( xNameAccess->hasByName( rtl::OUString("content.xml") ) || xNameAccess->hasByName( rtl::OUString("Content.xml") ))
1475 : {
1476 : // is this a fabulous math package ?
1477 0 : Reference<com::sun::star::frame::XModel> xModel(pDoc->GetModel());
1478 0 : SmXMLImportWrapper aEquation(xModel); //!! modifies the result of pDoc->GetText() !!
1479 0 : bRet = 0 == aEquation.Import(rMedium);
1480 : }
1481 : }
1482 :
1483 0 : if( bRet )
1484 : {
1485 0 : OUString aText = pDoc->GetText();
1486 0 : SmEditWindow *pEditWin = GetEditWindow();
1487 0 : if (pEditWin)
1488 0 : pEditWin->InsertText( aText );
1489 : else
1490 : {
1491 : OSL_FAIL( "EditWindow missing" );
1492 : }
1493 :
1494 0 : pDoc->Parse();
1495 0 : pDoc->SetModified(true);
1496 :
1497 0 : SfxBindings &rBnd = GetViewFrame()->GetBindings();
1498 0 : rBnd.Invalidate(SID_GAPHIC_SM);
1499 0 : rBnd.Invalidate(SID_TEXT);
1500 : }
1501 0 : return bRet;
1502 : }
1503 :
1504 :
1505 0 : bool SmViewShell::InsertFrom(SfxMedium &rMedium)
1506 : {
1507 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::InsertFrom" );
1508 :
1509 0 : bool bSuccess = false;
1510 0 : SmDocShell *pDoc = GetDoc();
1511 0 : SvStream *pStream = rMedium.GetInStream();
1512 :
1513 0 : if (pStream)
1514 : {
1515 0 : const OUString& rFltName = rMedium.GetFilter()->GetFilterName();
1516 0 : if ( rFltName == MATHML_XML )
1517 : {
1518 0 : Reference<com::sun::star::frame::XModel> xModel( pDoc->GetModel() );
1519 0 : SmXMLImportWrapper aEquation(xModel); //!! modifies the result of pDoc->GetText() !!
1520 0 : bSuccess = 0 == aEquation.Import(rMedium);
1521 0 : }
1522 : }
1523 :
1524 0 : if( bSuccess )
1525 : {
1526 0 : OUString aText = pDoc->GetText();
1527 0 : SmEditWindow *pEditWin = GetEditWindow();
1528 0 : if (pEditWin)
1529 0 : pEditWin->InsertText( aText );
1530 : else
1531 : {
1532 : OSL_FAIL( "EditWindow missing" );
1533 : }
1534 :
1535 0 : pDoc->Parse();
1536 0 : pDoc->SetModified(true);
1537 :
1538 0 : SfxBindings &rBnd = GetViewFrame()->GetBindings();
1539 0 : rBnd.Invalidate(SID_GAPHIC_SM);
1540 0 : rBnd.Invalidate(SID_TEXT);
1541 : }
1542 :
1543 0 : return bSuccess;
1544 : }
1545 :
1546 :
1547 18 : void SmViewShell::Execute(SfxRequest& rReq)
1548 : {
1549 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Execute" );
1550 :
1551 18 : SmEditWindow *pWin = GetEditWindow();
1552 :
1553 18 : switch (rReq.GetSlot())
1554 : {
1555 : case SID_FORMULACURSOR:
1556 : {
1557 0 : SmModule *pp = SM_MOD();
1558 :
1559 0 : const SfxItemSet *pArgs = rReq.GetArgs();
1560 : const SfxPoolItem *pItem;
1561 :
1562 : bool bVal;
1563 0 : if ( pArgs &&
1564 0 : SFX_ITEM_SET == pArgs->GetItemState( SID_FORMULACURSOR, false, &pItem))
1565 0 : bVal = ((SfxBoolItem *) pItem)->GetValue();
1566 : else
1567 0 : bVal = !pp->GetConfig()->IsShowFormulaCursor();
1568 :
1569 0 : pp->GetConfig()->SetShowFormulaCursor(bVal);
1570 0 : if (!IsInlineEditEnabled())
1571 0 : GetGraphicWindow().ShowCursor(bVal);
1572 : break;
1573 : }
1574 : case SID_DRAW:
1575 0 : if (pWin)
1576 : {
1577 0 : GetDoc()->SetText( pWin->GetText() );
1578 0 : SetStatusText(OUString());
1579 0 : ShowError( 0 );
1580 0 : GetDoc()->Repaint();
1581 : }
1582 0 : break;
1583 :
1584 : case SID_ADJUST:
1585 : case SID_FITINWINDOW:
1586 4 : aGraphic.ZoomToFitInWindow();
1587 4 : break;
1588 :
1589 : case SID_VIEW050:
1590 0 : aGraphic.SetZoom(50);
1591 0 : break;
1592 :
1593 : case SID_VIEW100:
1594 0 : aGraphic.SetZoom(100);
1595 0 : break;
1596 :
1597 : case SID_VIEW200:
1598 0 : aGraphic.SetZoom(200);
1599 0 : break;
1600 :
1601 : case SID_ZOOMIN:
1602 2 : aGraphic.SetZoom(aGraphic.GetZoom() + 25);
1603 2 : break;
1604 :
1605 : case SID_ZOOMOUT:
1606 : OSL_ENSURE(aGraphic.GetZoom() >= 25, "Sm: incorrect sal_uInt16 argument");
1607 4 : aGraphic.SetZoom(aGraphic.GetZoom() - 25);
1608 4 : break;
1609 :
1610 : case SID_COPYOBJECT:
1611 : {
1612 : //TODO/LATER: does not work because of UNO Tunneling - will be fixed later
1613 0 : Reference< datatransfer::XTransferable > xTrans( GetDoc()->GetModel(), uno::UNO_QUERY );
1614 0 : if( xTrans.is() )
1615 : {
1616 0 : Reference< lang::XUnoTunnel> xTnnl( xTrans, uno::UNO_QUERY);
1617 0 : if( xTnnl.is() )
1618 : {
1619 : TransferableHelper* pTrans = reinterpret_cast< TransferableHelper * >(
1620 : sal::static_int_cast< sal_uIntPtr >(
1621 0 : xTnnl->getSomething( TransferableHelper::getUnoTunnelId() )));
1622 0 : if( pTrans )
1623 0 : pTrans->CopyToClipboard( this ? GetEditWindow() : 0 );
1624 0 : }
1625 0 : }
1626 : }
1627 0 : break;
1628 :
1629 : case SID_PASTEOBJECT:
1630 : {
1631 0 : TransferableDataHelper aData( TransferableDataHelper::CreateFromSystemClipboard(this ? GetEditWindow(): 0) );
1632 0 : uno::Reference < io::XInputStream > xStrm;
1633 : SotFormatStringId nId;
1634 0 : if( aData.GetTransferable().is() &&
1635 0 : ( aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
1636 0 : (aData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) &&
1637 0 : aData.HasFormat( nId = SOT_FORMATSTR_ID_EMBED_SOURCE ))) &&
1638 0 : aData.GetInputStream( nId, xStrm ) && xStrm.is() )
1639 : {
1640 : try
1641 : {
1642 : uno::Reference < embed::XStorage > xStorage =
1643 0 : ::comphelper::OStorageHelper::GetStorageFromInputStream( xStrm, ::comphelper::getProcessComponentContext() );
1644 0 : uno::Reference < beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY );
1645 0 : SfxMedium aMedium( xStorage, OUString() );
1646 0 : Insert( aMedium );
1647 0 : GetDoc()->UpdateText();
1648 : }
1649 0 : catch (uno::Exception &)
1650 : {
1651 : OSL_FAIL( "SmViewShell::Execute (SID_PASTEOBJECT): failed to get storage from input stream" );
1652 : }
1653 0 : }
1654 : }
1655 0 : break;
1656 :
1657 :
1658 : case SID_CUT:
1659 0 : if (pWin)
1660 0 : pWin->Cut();
1661 0 : break;
1662 :
1663 : case SID_COPY:
1664 0 : if (pWin)
1665 : {
1666 0 : if (pWin->IsAllSelected())
1667 : {
1668 : GetViewFrame()->GetDispatcher()->Execute(
1669 : SID_COPYOBJECT, SFX_CALLMODE_STANDARD,
1670 0 : new SfxVoidItem(SID_COPYOBJECT), 0L);
1671 : }
1672 : else
1673 0 : pWin->Copy();
1674 : }
1675 0 : break;
1676 :
1677 : case SID_PASTE:
1678 : {
1679 0 : bool bCallExec = 0 == pWin;
1680 0 : if( !bCallExec )
1681 : {
1682 : TransferableDataHelper aDataHelper(
1683 : TransferableDataHelper::CreateFromSystemClipboard(
1684 0 : GetEditWindow()) );
1685 :
1686 0 : if( aDataHelper.GetTransferable().is() &&
1687 0 : aDataHelper.HasFormat( FORMAT_STRING ))
1688 0 : pWin->Paste();
1689 : else
1690 0 : bCallExec = true;
1691 : }
1692 0 : if( bCallExec )
1693 : {
1694 : GetViewFrame()->GetDispatcher()->Execute(
1695 : SID_PASTEOBJECT, SFX_CALLMODE_STANDARD,
1696 0 : new SfxVoidItem(SID_PASTEOBJECT), 0L);
1697 : }
1698 : }
1699 0 : break;
1700 :
1701 : case SID_DELETE:
1702 0 : if (pWin)
1703 0 : pWin->Delete();
1704 0 : break;
1705 :
1706 : case SID_SELECT:
1707 0 : if (pWin)
1708 0 : pWin->SelectAll();
1709 0 : break;
1710 :
1711 : case SID_INSERTCOMMAND:
1712 : {
1713 : const SfxInt16Item& rItem =
1714 0 : (const SfxInt16Item&)rReq.GetArgs()->Get(SID_INSERTCOMMAND);
1715 :
1716 0 : if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
1717 0 : pWin->InsertCommand(rItem.GetValue());
1718 0 : if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow)) {
1719 0 : GetDoc()->GetCursor().InsertCommand(rItem.GetValue());
1720 0 : GetGraphicWindow().GrabFocus();
1721 : }
1722 0 : break;
1723 : }
1724 :
1725 : case SID_INSERTSYMBOL:
1726 : {
1727 : const SfxStringItem& rItem =
1728 0 : (const SfxStringItem&)rReq.GetArgs()->Get(SID_INSERTSYMBOL);
1729 :
1730 0 : if (pWin && (bInsertIntoEditWindow || !IsInlineEditEnabled()))
1731 0 : pWin->InsertText(rItem.GetValue());
1732 0 : if (IsInlineEditEnabled() && (GetDoc() && !bInsertIntoEditWindow))
1733 0 : GetDoc()->GetCursor().InsertSpecial(rItem.GetValue());
1734 0 : break;
1735 : }
1736 :
1737 : case SID_IMPORT_FORMULA:
1738 : {
1739 0 : delete pImpl->pRequest;
1740 0 : pImpl->pRequest = new SfxRequest( rReq );
1741 0 : delete pImpl->pDocInserter;
1742 : pImpl->pDocInserter = new ::sfx2::DocumentInserter(
1743 0 : GetDoc()->GetFactory().GetFactoryName(), 0 );
1744 0 : pImpl->pDocInserter->StartExecuteModal( LINK( this, SmViewShell, DialogClosedHdl ) );
1745 0 : break;
1746 : }
1747 :
1748 : case SID_NEXTERR:
1749 0 : NextError();
1750 0 : if (pWin)
1751 0 : pWin->GrabFocus();
1752 0 : break;
1753 :
1754 : case SID_PREVERR:
1755 0 : PrevError();
1756 0 : if (pWin)
1757 0 : pWin->GrabFocus();
1758 0 : break;
1759 :
1760 : case SID_NEXTMARK:
1761 0 : if (pWin)
1762 : {
1763 0 : pWin->SelNextMark();
1764 0 : pWin->GrabFocus();
1765 : }
1766 0 : break;
1767 :
1768 : case SID_PREVMARK:
1769 0 : if (pWin)
1770 : {
1771 0 : pWin->SelPrevMark();
1772 0 : pWin->GrabFocus();
1773 : }
1774 0 : break;
1775 :
1776 : case SID_TEXTSTATUS:
1777 : {
1778 0 : if (rReq.GetArgs() != NULL)
1779 : {
1780 : const SfxStringItem& rItem =
1781 0 : (const SfxStringItem&)rReq.GetArgs()->Get(SID_TEXTSTATUS);
1782 :
1783 0 : SetStatusText(rItem.GetValue());
1784 : }
1785 :
1786 0 : break;
1787 : }
1788 :
1789 : case SID_GETEDITTEXT:
1790 0 : if (pWin)
1791 0 : if (pWin->GetText ().Len ()) GetDoc()->SetText( pWin->GetText() );
1792 0 : break;
1793 :
1794 : case SID_ATTR_ZOOM:
1795 : {
1796 8 : if ( !GetViewFrame()->GetFrame().IsInPlace() )
1797 : {
1798 8 : AbstractSvxZoomDialog *pDlg = 0;
1799 8 : const SfxItemSet *pSet = rReq.GetArgs();
1800 8 : if ( !pSet )
1801 : {
1802 0 : SfxItemSet aSet( GetDoc()->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
1803 0 : aSet.Put( SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
1804 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1805 0 : if(pFact)
1806 : {
1807 0 : pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aSet);
1808 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
1809 0 : pDlg->SetLimits( MINZOOM, MAXZOOM );
1810 0 : if( pDlg->Execute() != RET_CANCEL )
1811 0 : pSet = pDlg->GetOutputItemSet();
1812 0 : }
1813 : }
1814 8 : if ( pSet )
1815 : {
1816 8 : const SvxZoomItem &rZoom = (const SvxZoomItem &)pSet->Get(SID_ATTR_ZOOM);
1817 8 : switch( rZoom.GetType() )
1818 : {
1819 : case SVX_ZOOM_PERCENT:
1820 6 : aGraphic.SetZoom((sal_uInt16)rZoom.GetValue ());
1821 6 : break;
1822 :
1823 : case SVX_ZOOM_OPTIMAL:
1824 2 : aGraphic.ZoomToFitInWindow();
1825 2 : break;
1826 :
1827 : case SVX_ZOOM_PAGEWIDTH:
1828 : case SVX_ZOOM_WHOLEPAGE:
1829 : {
1830 0 : const MapMode aMap( MAP_100TH_MM );
1831 0 : SfxPrinter *pPrinter = GetPrinter( true );
1832 0 : Point aPoint;
1833 0 : Rectangle OutputRect(aPoint, pPrinter->GetOutputSize());
1834 : Size OutputSize(pPrinter->LogicToPixel(Size(OutputRect.GetWidth(),
1835 0 : OutputRect.GetHeight()), aMap));
1836 0 : Size GraphicSize(pPrinter->LogicToPixel(GetDoc()->GetSize(), aMap));
1837 0 : sal_uInt16 nZ = (sal_uInt16) Min((long)Fraction(OutputSize.Width() * 100L, GraphicSize.Width()),
1838 0 : (long)Fraction(OutputSize.Height() * 100L, GraphicSize.Height()));
1839 0 : aGraphic.SetZoom (nZ);
1840 0 : break;
1841 : }
1842 : default:
1843 0 : break;
1844 : }
1845 : }
1846 8 : delete pDlg;
1847 : }
1848 : }
1849 8 : break;
1850 :
1851 : case SID_TOOLBOX:
1852 : {
1853 0 : GetViewFrame()->ToggleChildWindow( SmToolBoxWrapper::GetChildWindowId() );
1854 : }
1855 0 : break;
1856 :
1857 : case SID_SYMBOLS_CATALOGUE:
1858 : {
1859 :
1860 : // get device used to retrieve the FontList
1861 0 : SmDocShell *pDoc = GetDoc();
1862 0 : OutputDevice *pDev = pDoc->GetPrinter();
1863 0 : if (!pDev || pDev->GetDevFontCount() == 0)
1864 0 : pDev = &SM_MOD()->GetDefaultVirtualDev();
1865 : OSL_ENSURE (pDev, "device for font list missing" );
1866 :
1867 0 : SmModule *pp = SM_MOD();
1868 0 : SmSymbolDialog( NULL, pDev, pp->GetSymbolManager(), *this ).Execute();
1869 : }
1870 0 : break;
1871 : }
1872 18 : rReq.Done();
1873 18 : }
1874 :
1875 :
1876 0 : void SmViewShell::GetState(SfxItemSet &rSet)
1877 : {
1878 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::GetState" );
1879 :
1880 0 : SfxWhichIter aIter(rSet);
1881 :
1882 0 : SmEditWindow *pEditWin = GetEditWindow();
1883 0 : for (sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich())
1884 : {
1885 0 : switch (nWh)
1886 : {
1887 : case SID_CUT:
1888 : case SID_COPY:
1889 : case SID_DELETE:
1890 0 : if (! pEditWin || ! pEditWin->IsSelected())
1891 0 : rSet.DisableItem(nWh);
1892 0 : break;
1893 :
1894 : case SID_PASTE:
1895 0 : if( !xClipEvtLstnr.is() && pEditWin)
1896 : {
1897 : TransferableDataHelper aDataHelper(
1898 : TransferableDataHelper::CreateFromSystemClipboard(
1899 0 : pEditWin) );
1900 :
1901 0 : bPasteState = aDataHelper.GetTransferable().is() &&
1902 0 : ( aDataHelper.HasFormat( FORMAT_STRING ) ||
1903 0 : aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
1904 0 : (aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
1905 0 : && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE )));
1906 : }
1907 0 : if( !bPasteState )
1908 0 : rSet.DisableItem( nWh );
1909 0 : break;
1910 :
1911 : case SID_ATTR_ZOOM:
1912 0 : rSet.Put(SvxZoomItem( SVX_ZOOM_PERCENT, aGraphic.GetZoom()));
1913 : /* no break here */
1914 : case SID_VIEW050:
1915 : case SID_VIEW100:
1916 : case SID_VIEW200:
1917 : case SID_ADJUST:
1918 : case SID_ZOOMIN:
1919 : case SID_ZOOMOUT:
1920 : case SID_FITINWINDOW:
1921 0 : if ( GetViewFrame()->GetFrame().IsInPlace() )
1922 0 : rSet.DisableItem( nWh );
1923 0 : break;
1924 :
1925 : case SID_NEXTERR:
1926 : case SID_PREVERR:
1927 : case SID_NEXTMARK:
1928 : case SID_PREVMARK:
1929 : case SID_DRAW:
1930 : case SID_SELECT:
1931 0 : if (! pEditWin || pEditWin->IsEmpty())
1932 0 : rSet.DisableItem(nWh);
1933 0 : break;
1934 :
1935 : case SID_TEXTSTATUS:
1936 : {
1937 0 : rSet.Put(SfxStringItem(nWh, aStatusText));
1938 : }
1939 0 : break;
1940 :
1941 : case SID_FORMULACURSOR:
1942 : {
1943 0 : SmModule *pp = SM_MOD();
1944 0 : rSet.Put(SfxBoolItem(nWh, pp->GetConfig()->IsShowFormulaCursor()));
1945 : }
1946 0 : break;
1947 :
1948 : case SID_TOOLBOX:
1949 : {
1950 0 : bool bState = false;
1951 : SfxChildWindow *pChildWnd = GetViewFrame()->
1952 0 : GetChildWindow( SmToolBoxWrapper::GetChildWindowId() );
1953 0 : if (pChildWnd && pChildWnd->GetWindow()->IsVisible())
1954 0 : bState = true;
1955 0 : rSet.Put(SfxBoolItem(SID_TOOLBOX, bState));
1956 : }
1957 0 : break;
1958 :
1959 : }
1960 0 : }
1961 0 : }
1962 :
1963 :
1964 8 : SmViewShell::SmViewShell(SfxViewFrame *pFrame_, SfxViewShell *):
1965 : SfxViewShell(pFrame_, SFX_VIEW_HAS_PRINTOPTIONS | SFX_VIEW_CAN_PRINT),
1966 8 : pImpl( new SmViewShell_Impl ),
1967 : aGraphic(this),
1968 16 : aGraphicController(aGraphic, SID_GAPHIC_SM, pFrame_->GetBindings())
1969 : {
1970 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::SmViewShell" );
1971 :
1972 8 : SetStatusText(OUString());
1973 8 : SetWindow(&aGraphic);
1974 8 : SfxShell::SetName(rtl::OUString("SmView"));
1975 8 : SfxShell::SetUndoManager( &GetDoc()->GetEditEngine().GetUndoManager() );
1976 8 : SetHelpId( HID_SMA_VIEWSHELL_DOCUMENT );
1977 8 : }
1978 :
1979 :
1980 0 : SmViewShell::~SmViewShell()
1981 : {
1982 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::~SmViewShell" );
1983 :
1984 : //!! this view shell is not active anymore !!
1985 : // Thus 'SmGetActiveView' will give a 0 pointer.
1986 : // Thus we need to supply this view as argument
1987 0 : SmEditWindow *pEditWin = GetEditWindow();
1988 0 : if (pEditWin)
1989 0 : pEditWin->DeleteEditView( *this );
1990 0 : delete pImpl;
1991 0 : }
1992 :
1993 0 : void SmViewShell::Deactivate( sal_Bool bIsMDIActivate )
1994 : {
1995 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Deactivate" );
1996 :
1997 0 : SmEditWindow *pEdit = GetEditWindow();
1998 0 : if ( pEdit )
1999 0 : pEdit->Flush();
2000 :
2001 0 : SfxViewShell::Deactivate( bIsMDIActivate );
2002 0 : }
2003 :
2004 :
2005 0 : void SmViewShell::Activate( sal_Bool bIsMDIActivate )
2006 : {
2007 : RTL_LOGFILE_CONTEXT( aLog, "starmath: SmViewShell::Activate" );
2008 :
2009 0 : SfxViewShell::Activate( bIsMDIActivate );
2010 :
2011 0 : SmEditWindow *pEdit = GetEditWindow();
2012 0 : if ( pEdit )
2013 : {
2014 : //! Since there is no way to be informed if a "drag and drop"
2015 : //! event has taken place, we call SetText here in order to
2016 : //! syncronize the GraphicWindow display with the text in the
2017 : //! EditEngine.
2018 0 : SmDocShell *pDoc = GetDoc();
2019 0 : pDoc->SetText( pDoc->GetEditEngine().GetText( LINEEND_LF ) );
2020 :
2021 0 : if ( bIsMDIActivate )
2022 0 : pEdit->GrabFocus();
2023 : }
2024 0 : }
2025 :
2026 0 : IMPL_LINK( SmViewShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
2027 : {
2028 : OSL_ENSURE( _pFileDlg, "SmViewShell::DialogClosedHdl(): no file dialog" );
2029 : OSL_ENSURE( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2030 :
2031 0 : if ( ERRCODE_NONE == _pFileDlg->GetError() )
2032 : {
2033 0 : SfxMedium* pMedium = pImpl->pDocInserter->CreateMedium();
2034 :
2035 0 : if ( pMedium != NULL )
2036 : {
2037 0 : if ( pMedium->IsStorage() )
2038 0 : Insert( *pMedium );
2039 : else
2040 0 : InsertFrom( *pMedium );
2041 0 : delete pMedium;
2042 :
2043 0 : SmDocShell* pDoc = GetDoc();
2044 0 : pDoc->UpdateText();
2045 0 : pDoc->ArrangeFormula();
2046 0 : pDoc->Repaint();
2047 : // adjust window, repaint, increment ModifyCount,...
2048 0 : GetViewFrame()->GetBindings().Invalidate(SID_GAPHIC_SM);
2049 : }
2050 : }
2051 :
2052 0 : pImpl->pRequest->SetReturnValue( SfxBoolItem( pImpl->pRequest->GetSlot(), true ) );
2053 0 : pImpl->pRequest->Done();
2054 0 : return 0;
2055 : }
2056 :
2057 56 : void SmViewShell::Notify( SfxBroadcaster& , const SfxHint& rHint )
2058 : {
2059 56 : if ( rHint.IsA(TYPE(SfxSimpleHint)) )
2060 : {
2061 32 : switch( ( (SfxSimpleHint&) rHint ).GetId() )
2062 : {
2063 : case SFX_HINT_MODECHANGED:
2064 : case SFX_HINT_DOCCHANGED:
2065 24 : GetViewFrame()->GetBindings().InvalidateAll(false);
2066 24 : break;
2067 : default:
2068 8 : break;
2069 : }
2070 : }
2071 56 : }
2072 :
2073 46 : bool SmViewShell::IsInlineEditEnabled() const
2074 : {
2075 46 : return pImpl->aOpts.IsExperimentalMode();
2076 18 : }
2077 :
2078 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|