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