merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / annotations / annotationwindow.cxx
blob17ba21aa8079aea71547c22ec95736eae59e807e
1 /************************************************************************* *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: postit.cxx,v $
10 * $Revision: 1.8.42.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include <svx/fontitem.hxx>
34 #include <svx/eeitem.hxx>
35 #include <svx/fhgtitem.hxx>
36 #include <svx/bulitem.hxx>
37 #include <svx/udlnitem.hxx>
38 #include <svx/shdditem.hxx>
39 #include <svx/flditem.hxx>
40 #include <svx/frmdir.hxx>
41 #include <svx/frmdiritem.hxx>
42 #include <svx/langitem.hxx>
43 #include <svx/adjitem.hxx>
44 #include <svx/editview.hxx>
45 #include <svx/svdview.hxx>
46 #include <svx/sdrpaintwindow.hxx>
47 #include <svx/sdr/overlay/overlaymanager.hxx>
48 #include <svx/editstat.hxx> //EditEngine flags
49 #include <svx/outliner.hxx>
50 #include <svx/editeng.hxx>
51 #include <svx/editobj.hxx>
52 #include <svx/unolingu.hxx>
53 #include <svx/outlobj.hxx>
54 #include <svx/postitem.hxx>
55 #include <svx/wghtitem.hxx>
56 #include <svx/udlnitem.hxx>
57 #include <svx/crsditem.hxx>
59 #include <svtools/langtab.hxx>
60 #include <svtools/slstitm.hxx>
61 #include <svtools/securityoptions.hxx>
62 #include <svtools/useroptions.hxx>
63 #include <svtools/languageoptions.hxx>
64 #include <svtools/zforlist.hxx>
65 #include <svtools/svmedit.hxx>
67 #include <linguistic/lngprops.hxx>
69 #include <sfx2/request.hxx>
70 #include <sfx2/viewfrm.hxx>
71 #include <sfx2/bindings.hxx>
72 #include <sfx2/dispatch.hxx>
73 #include <sfx2/mnumgr.hxx>
75 #include <vcl/vclenum.hxx>
76 #include <vcl/edit.hxx>
77 #include <vcl/help.hxx>
78 #include <vcl/scrbar.hxx>
79 #include <vcl/button.hxx>
80 #include <vcl/svapp.hxx>
81 #include <vcl/gradient.hxx>
82 #include <vcl/salbtype.hxx> // FRound
83 #include <vcl/cursor.hxx>
85 #include <basegfx/matrix/b2dhommatrix.hxx>
86 #include <basegfx/tuple/b2dtuple.hxx>
87 #include <basegfx/polygon/b2dpolygontools.hxx>
89 #include "annotations.hrc"
90 #include "annotationwindow.hxx"
91 #include "annotationmanagerimpl.hxx"
93 #include "DrawDocShell.hxx"
94 #include "ViewShell.hxx"
95 #include "drawdoc.hxx"
96 #include "View.hxx"
97 #include "textapi.hxx"
98 #include "sdresid.hxx"
100 using rtl::OUString;
101 using namespace ::sd;
102 using namespace ::com::sun::star;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star::office;
105 using namespace ::com::sun::star::text;
107 #define METABUTTON_WIDTH 16
108 #define METABUTTON_HEIGHT 18
109 #define METABUTTON_AREA_WIDTH 30
110 #define POSTIT_META_HEIGHT (sal_Int32) 30
112 #define EMPTYSTRING rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(""))
114 namespace sd {
116 extern OUString getAnnotationDateTimeString( const Reference< XAnnotation >& xAnnotation );
117 extern SfxItemPool* GetAnnotationPool();
118 extern com::sun::star::util::DateTime getCurrentDateTime();
120 Color ColorFromAlphaColor(UINT8 aTransparency, Color &aFront, Color &aBack )
122 return Color((UINT8)(aFront.GetRed() * aTransparency/(double)255 + aBack.GetRed() * (1-aTransparency/(double)255)),
123 (UINT8)(aFront.GetGreen() * aTransparency/(double)255 + aBack.GetGreen() * (1-aTransparency/(double)255)),
124 (UINT8)(aFront.GetBlue() * aTransparency/(double)255 + aBack.GetBlue() * (1-aTransparency/(double)255)));
127 /************ AnnotationTextWindow **********************************/
129 AnnotationTextWindow::AnnotationTextWindow( AnnotationWindow* pParent, WinBits nBits )
130 : Control(pParent, nBits)
131 , mpOutlinerView(0)
132 , mpAnnotationWindow( pParent )
136 AnnotationTextWindow::~AnnotationTextWindow()
140 void AnnotationTextWindow::Paint( const Rectangle& rRect)
142 if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
144 DrawGradient(Rectangle(Point(0,0),PixelToLogic(GetSizePixel())),
145 Gradient(GRADIENT_LINEAR,mpAnnotationWindow->maColorLight,mpAnnotationWindow->maColor));
148 if( mpOutlinerView )
149 mpOutlinerView->Paint( rRect );
152 void AnnotationTextWindow::KeyInput( const KeyEvent& rKeyEvt )
154 const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
155 USHORT nKey = rKeyCode.GetCode();
157 if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN)))
159 SfxDispatcher* pDispatcher = mpAnnotationWindow->DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher();
160 if( pDispatcher )
161 pDispatcher->Execute( nKey == KEY_PAGEDOWN ? SID_NEXT_POSTIT : SID_PREVIOUS_POSTIT );
163 else if (nKey == KEY_INSERT)
165 if (!rKeyCode.IsMod1() && !rKeyCode.IsMod2())
166 mpAnnotationWindow->ToggleInsMode();
168 else
170 long aOldHeight = mpAnnotationWindow->GetPostItTextHeight();
171 bool bDone = false;
173 /// HACK: need to switch off processing of Undo/Redo in Outliner
174 if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
176 bool bIsProtected = mpAnnotationWindow->IsProtected();
177 if (!bIsProtected || (bIsProtected && !mpAnnotationWindow->Engine()->GetEditEngine().DoesKeyChangeText(rKeyEvt)) )
179 bDone = mpOutlinerView->PostKeyEvent( rKeyEvt );
181 if (bDone)
183 mpAnnotationWindow->ResizeIfNeccessary(aOldHeight,mpAnnotationWindow->GetPostItTextHeight());
185 else
187 Control::KeyInput(rKeyEvt);
192 void AnnotationTextWindow::MouseMove( const MouseEvent& rMEvt )
194 if ( mpOutlinerView )
196 mpOutlinerView->MouseMove( rMEvt );
197 SetPointer( mpOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
201 void AnnotationTextWindow::MouseButtonDown( const MouseEvent& rMEvt )
203 GrabFocus();
204 if ( mpOutlinerView )
205 mpOutlinerView->MouseButtonDown( rMEvt );
206 // todo mpOutlinerView->DocView()->GetViewFrame()->GetBindings().InvalidateAll(FALSE);
209 void AnnotationTextWindow::MouseButtonUp( const MouseEvent& rMEvt )
211 if ( mpOutlinerView )
212 mpOutlinerView->MouseButtonUp( rMEvt );
215 void AnnotationTextWindow::Command( const CommandEvent& rCEvt )
217 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
219 mpAnnotationWindow->Command(rCEvt);
221 else
223 if ( mpOutlinerView )
224 mpOutlinerView->Command( rCEvt );
225 else
226 Window::Command(rCEvt);
230 void AnnotationTextWindow::GetFocus()
232 Window::GetFocus();
235 void AnnotationTextWindow::LoseFocus()
237 // if ( mpAnnotationWindow )
238 // mpAnnotationWindow->UpdateAnnotation();
240 Window::LoseFocus();
243 XubString AnnotationTextWindow::GetSurroundingText() const
245 if( mpOutlinerView )
247 EditEngine *aEditEngine = mpOutlinerView->GetEditView().GetEditEngine();
248 if( mpOutlinerView->HasSelection() )
249 return mpOutlinerView->GetSelected();
250 else
252 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
253 XubString aStr = aEditEngine->GetText(aSelection.nStartPara);
254 return aStr;
257 else
258 return XubString::EmptyString();
261 Selection AnnotationTextWindow::GetSurroundingTextSelection() const
263 if( mpOutlinerView )
265 if( mpOutlinerView->HasSelection() )
266 return Selection( 0, mpOutlinerView->GetSelected().Len() );
267 else
269 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
270 return Selection( aSelection.nStartPos, aSelection.nEndPos );
273 else
274 return Selection( 0, 0 );
277 /************** AnnotationWindow***********************************++*/
279 AnnotationWindow::AnnotationWindow( AnnotationManagerImpl& rManager, DrawDocShell* pDocShell, Window* pParent )
280 : FloatingWindow(pParent, WB_SYSTEMWINDOW|WB_BORDER|WB_NEEDSFOCUS)
281 , mrManager( rManager )
282 , mpDocShell( pDocShell )
283 , mpView( pDocShell->GetViewShell()->GetView() )
284 , mpDoc( pDocShell->GetDoc() )
285 , mpOutlinerView(0)
286 , mpOutliner(0)
287 , mpVScrollbar(0)
288 , mbReadonly(pDocShell->IsReadOnly())
289 , mbProtected(false)
290 , mbMouseOverButton(false)
291 , mpTextWindow(0)
292 , mpMeta(0)
296 AnnotationWindow::~AnnotationWindow()
298 delete mpMeta;
299 delete mpOutlinerView;
300 delete mpOutliner;
301 delete mpVScrollbar;
302 delete mpTextWindow;
305 void AnnotationWindow::InitControls()
307 // actual window which holds the user text
308 mpTextWindow = new AnnotationTextWindow(this, WB_NODIALOGCONTROL);
309 mpTextWindow->SetPointer(Pointer(POINTER_TEXT));
311 // window control for author and date
312 mpMeta = new MultiLineEdit(this,0);
313 mpMeta->SetReadOnly();
314 mpMeta->SetRightToLeft(Application::GetSettings().GetLayoutRTL());
315 mpMeta->AlwaysDisableInput(true);
316 mpMeta->SetCallHandlersOnInputDisabled(true);
318 // mpMeta->AddEventListener( LINK( mpPostItTxt, PostItTxt, WindowEventListener ) );
319 // AddEventListener( LINK( mpTextWindow, PostItTxt, WindowEventListener ) );
321 // we should leave this setting alone, but for this we need a better layout algo
322 // with variable meta size height
323 AllSettings aSettings = mpMeta->GetSettings();
324 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
325 Font aFont = aStyleSettings.GetFieldFont();
326 aFont.SetHeight(8);
327 aStyleSettings.SetFieldFont(aFont);
328 aSettings.SetStyleSettings(aStyleSettings);
329 mpMeta->SetSettings(aSettings);
331 mpOutliner = new ::Outliner(GetAnnotationPool(),OUTLINERMODE_TEXTOBJECT);
332 Doc()->SetCalcFieldValueHdl( mpOutliner );
333 mpOutliner->SetUpdateMode( TRUE );
334 Rescale();
336 OutputDevice* pDev = Doc()->GetRefDevice();
337 if( pDev )
339 mpOutliner->SetRefDevice( pDev );
342 mpOutlinerView = new OutlinerView ( mpOutliner, mpTextWindow );
343 mpOutliner->InsertView(mpOutlinerView );
344 mpTextWindow->SetOutlinerView(mpOutlinerView);
345 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,1,1) ) );
347 // SfxItemSet item(DocShell()->GetPool());
348 // item.Put(SvxFontHeightItem(352,100,EE_CHAR_FONTHEIGHT));
349 // mpOutlinerView->SetAttribs(item);
351 // TODO: ??
352 EEHorizontalTextDirection aDefHoriTextDir = Application::GetSettings().GetLayoutRTL() ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
353 mpOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir );
355 //create Scrollbars
356 mpVScrollbar = new ScrollBar(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
357 mpVScrollbar->EnableNativeWidget(false);
358 mpVScrollbar->EnableRTL( false );
359 mpVScrollbar->SetScrollHdl(LINK(this, AnnotationWindow, ScrollHdl));
360 mpVScrollbar->EnableDrag();
361 // mpVScrollbar->AddEventListener( LINK( this, AnnotationWindow, WindowEventListener ) );
363 ULONG nCntrl = mpOutliner->GetControlWord();
364 nCntrl |= EE_CNTRL_PASTESPECIAL | EE_CNTRL_AUTOCORRECT | EV_CNTRL_AUTOSCROLL | EE_CNTRL_NOCOLORS;
366 if (pVOpt->IsFieldShadings())
367 nCntrl |= EE_CNTRL_MARKFIELDS;
368 else
369 nCntrl &= ~EE_CNTRL_MARKFIELDS;
370 if (pVOpt->IsOnlineSpell())
371 nCntrl |= EE_CNTRL_ONLINESPELLING;
372 else
373 nCntrl &= ~EE_CNTRL_ONLINESPELLING;
375 mpOutliner->SetControlWord(nCntrl);
376 // mpOutliner->SetFlatMode( TRUE );
378 Engine()->SetModifyHdl( Link() );
379 Engine()->EnableUndo( FALSE );
381 Engine()->ClearModifyFlag();
382 Engine()->GetUndoManager().Clear();
383 Engine()->EnableUndo( TRUE );
384 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
386 Invalidate();
388 SetLanguage(GetLanguage());
390 mpMeta->Show();
391 mpVScrollbar->Show();
392 mpTextWindow->Show();
395 void AnnotationWindow::StartEdit()
397 getView()->SetSelection(ESelection(0xFFFF,0xFFFF,0xFFFF,0xFFFF));
398 getView()->ShowCursor();
401 void AnnotationWindow::Rescale()
403 MapMode aMode(MAP_100TH_MM);
404 aMode.SetOrigin( Point() );
405 //aMode.SetScaleX( aMode.GetScaleX() * Fraction( 8, 10 ) );
406 //aMode.SetScaleY( aMode.GetScaleY() * Fraction( 8, 10 ) );
407 mpOutliner->SetRefMapMode( aMode );
408 SetMapMode( aMode );
409 mpTextWindow->SetMapMode( aMode );
410 if ( mpMeta )
412 Font aFont( mpMeta->GetSettings().GetStyleSettings().GetFieldFont() );
413 sal_Int32 nHeight = aFont.GetHeight();
414 nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator();
415 aFont.SetHeight( nHeight );
416 mpMeta->SetControlFont( aFont );
420 void AnnotationWindow::DoResize()
422 unsigned long aWidth = GetSizePixel().Width();
423 long aHeight = GetSizePixel().Height() - POSTIT_META_HEIGHT;
425 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
426 long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height();
428 if( aTextHeight > aHeight )
429 { // we need vertical scrollbars and have to reduce the width
430 aWidth -= GetScrollbarWidth();
431 mpVScrollbar->Show();
433 else
435 mpVScrollbar->Hide();
438 mpTextWindow->SetPosSizePixel(0,0,aWidth, aHeight);
440 if( mbReadonly )
441 mpMeta->SetPosSizePixel(0,aHeight,GetSizePixel().Width(),POSTIT_META_HEIGHT);
442 else
443 mpMeta->SetPosSizePixel(0,aHeight,GetSizePixel().Width()-METABUTTON_AREA_WIDTH,POSTIT_META_HEIGHT);
445 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
446 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
447 if (!mpVScrollbar->IsVisible())
448 { // if we do not have a scrollbar anymore, we want to see the complete text
449 mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
451 mpVScrollbar->SetPosSizePixel( 0 + aWidth, 0, GetScrollbarWidth(), aHeight );
452 mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
453 mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
454 mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
455 SetScrollbar();
456 mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
458 Point aPos( mpMeta->GetPosPixel());
459 Point aBase( aPos.X() + aPos.X() + GetSizePixel().Width(), aPos.Y() );
460 Point aLeft = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+5), aBase.Y()+17 ) );
461 Point aRight = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH-1), aBase.Y()+17 ) );
462 Point aBottom = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+2), aBase.Y()+20 ) );
464 maPopupTriangle.clear();
465 maPopupTriangle.append(basegfx::B2DPoint(aLeft.X(),aLeft.Y()));
466 maPopupTriangle.append(basegfx::B2DPoint(aRight.X(),aRight.Y()));
467 maPopupTriangle.append(basegfx::B2DPoint(aBottom.X(),aBottom.Y()));
468 maPopupTriangle.setClosed(true);
469 maRectMetaButton = PixelToLogic( Rectangle( Point(
470 aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10),
471 aPos.Y()+5 ),
472 Size( METABUTTON_WIDTH, METABUTTON_HEIGHT ) ) );
476 void AnnotationWindow::SetSizePixel( const Size& rNewSize )
478 Window::SetSizePixel(rNewSize);
481 void AnnotationWindow::SetScrollbar()
483 mpVScrollbar->SetThumbPos( mpOutlinerView->GetVisArea().Top()+ mpOutlinerView->GetEditView().GetCursor()->GetOffsetY());
486 void AnnotationWindow::ResizeIfNeccessary(long aOldHeight, long aNewHeight)
488 if (aOldHeight != aNewHeight)
490 DoResize();
491 Invalidate();
493 else
495 SetScrollbar();
499 void AnnotationWindow::SetReadonly(bool bSet)
501 mbReadonly = bSet;
502 getView()->SetReadOnly(bSet);
505 void AnnotationWindow::SetLanguage(const SvxLanguageItem aNewItem)
507 Engine()->SetModifyHdl( Link() );
508 ESelection aOld = getView()->GetSelection();
510 ESelection aNewSelection( 0, 0, (USHORT)Engine()->GetParagraphCount()-1, USHRT_MAX );
511 getView()->SetSelection( aNewSelection );
512 SfxItemSet aEditAttr(getView()->GetAttribs());
513 aEditAttr.Put(aNewItem);
514 getView()->SetAttribs( aEditAttr );
516 getView()->SetSelection(aOld);
517 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
519 Invalidate();
522 void AnnotationWindow::ToggleInsMode()
524 if( mpOutlinerView )
526 SfxBindings &rBnd = mpDocShell->GetViewShell()->GetViewFrame()->GetBindings();
527 rBnd.Invalidate(SID_ATTR_INSERT);
528 rBnd.Update(SID_ATTR_INSERT);
532 long AnnotationWindow::GetPostItTextHeight()
534 return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
537 IMPL_LINK(AnnotationWindow, ScrollHdl, ScrollBar*, pScroll)
539 long nDiff = getView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
540 getView()->Scroll( 0, nDiff );
541 return 0;
544 IMPL_LINK(AnnotationWindow, ModifyHdl, void*, EMPTYARG)
546 return 0;
549 sal_Int32 AnnotationWindow::GetScrollbarWidth()
551 return 16;
552 // return mpView->GetWrtShell().GetViewOptions()->GetZoom() / 10;
555 SvxLanguageItem AnnotationWindow::GetLanguage(void)
557 return SvxLanguageItem( Doc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE );
560 // --------------------------------------------------------------------
562 TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation )
564 if( xAnnotation.is() )
566 Reference< XText > xText( xAnnotation->getTextRange() );
567 return TextApiObject::getImplementation( xText );
569 return 0;
572 // --------------------------------------------------------------------
574 void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotation, bool bGrabFocus )
576 if( (xAnnotation != mxAnnotation) && xAnnotation.is() )
578 mxAnnotation = xAnnotation;
580 SetColor();
582 SvtUserOptions aUserOptions;
583 mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor();
585 Engine()->Clear();
586 TextApiObject* pTextApi = getTextApiObject( mxAnnotation );
588 if( pTextApi )
590 std::auto_ptr< OutlinerParaObject > pOPO( pTextApi->CreateText() );
591 Engine()->SetText( *pOPO.get() );
594 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
595 Engine()->ClearModifyFlag();
596 Engine()->GetUndoManager().Clear();
598 Invalidate();
600 OUString sMeta( xAnnotation->getAuthor() );
601 OUString sDateTime( getAnnotationDateTimeString(xAnnotation) );
603 if( sDateTime.getLength() != 0 )
605 if( sMeta.getLength() != 0 )
606 sMeta += OUString( RTL_CONSTASCII_USTRINGPARAM( "\n" ) );
608 sMeta += sDateTime;
610 mpMeta->SetText(sMeta);
612 if( bGrabFocus )
613 GrabFocus();
617 void AnnotationWindow::SetColor()
619 sal_uInt16 nAuthorIdx = mpDoc->GetAnnotationAuthorIndex( mxAnnotation->getAuthor() );
621 maColor = mrManager.GetColor( nAuthorIdx );
622 maColorDark = mrManager.GetColorDark( nAuthorIdx );
623 maColorLight = mrManager.GetColorLight( nAuthorIdx );
625 mpOutlinerView->SetBackgroundColor(maColor);
627 mpMeta->SetControlBackground(maColor);
628 AllSettings aSettings = mpMeta->GetSettings();
629 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
630 aStyleSettings.SetFieldTextColor(maColorDark);
631 aSettings.SetStyleSettings(aStyleSettings);
632 mpMeta->SetSettings(aSettings);
634 AllSettings aSettings2 = mpVScrollbar->GetSettings();
635 StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
636 aStyleSettings2.SetButtonTextColor(Color(0,0,0));
637 aStyleSettings2.SetCheckedColor(maColorLight); //hintergund
638 aStyleSettings2.SetShadowColor(maColorDark);
639 aStyleSettings2.SetFaceColor(maColor);
640 aSettings2.SetStyleSettings(aStyleSettings2);
641 mpVScrollbar->SetSettings(aSettings2);
644 void AnnotationWindow::Deactivate()
646 Reference< XAnnotation > xAnnotation( mxAnnotation );
648 // check if text is empty
649 Paragraph* p1stPara=Engine()->GetParagraph( 0 );
650 ULONG nParaAnz=Engine()->GetParagraphCount();
651 if(p1stPara==NULL)
652 nParaAnz=0;
654 if(nParaAnz==1)
656 // if it is only one paragraph, check if that paragraph is empty
657 XubString aStr(Engine()->GetText(p1stPara));
659 if(!aStr.Len())
660 nParaAnz = 0;
663 if( nParaAnz == 0 )
665 // text is empty, delete postit
666 DeleteAnnotation( xAnnotation );
668 else
671 // write changed text back to annotation
672 if ( Engine()->IsModified() )
674 TextApiObject* pTextApi = getTextApiObject( xAnnotation );
676 if( pTextApi )
678 OutlinerParaObject* pOPO = Engine()->CreateParaObject();
679 if( pOPO )
681 if( mpDoc->IsUndoEnabled() )
682 mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_EDIT ) ) );
684 pTextApi->SetText( *pOPO );
685 delete pOPO;
687 // set current time to changed annotation
688 xAnnotation->setDateTime( getCurrentDateTime() );
690 if( mpDoc->IsUndoEnabled() )
691 mpDoc->EndUndo();
693 DocView()->GetDocSh()->SetModified(sal_True);
698 Engine()->ClearModifyFlag();
701 Engine()->GetUndoManager().Clear();
704 void AnnotationWindow::Paint( const Rectangle& rRect)
706 FloatingWindow::Paint( rRect );
708 if(mpMeta->IsVisible() && !mbReadonly)
710 //draw left over space
711 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
712 SetFillColor(COL_BLACK);
713 else
714 SetFillColor(maColor);
715 SetLineColor();
716 DrawRect(PixelToLogic(Rectangle(Point(mpMeta->GetPosPixel().X()+mpMeta->GetSizePixel().Width(),mpMeta->GetPosPixel().Y()),Size(METABUTTON_AREA_WIDTH,mpMeta->GetSizePixel().Height()))));
718 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode())
720 //draw rect around button
721 SetFillColor(COL_BLACK);
722 SetLineColor(COL_WHITE);
724 else
726 //draw button
727 Gradient aGradient;
728 if (mbMouseOverButton)
729 aGradient = Gradient(GRADIENT_LINEAR,ColorFromAlphaColor(80,maColorDark,maColor),ColorFromAlphaColor(15,maColorDark,maColor));
730 else
731 aGradient = Gradient(GRADIENT_LINEAR,ColorFromAlphaColor(15,maColorDark,maColor),ColorFromAlphaColor(80,maColorDark,maColor));
732 DrawGradient(maRectMetaButton,aGradient);
733 //draw rect around button
734 SetFillColor();
735 SetLineColor(ColorFromAlphaColor(90,maColorDark,maColor));
737 DrawRect(maRectMetaButton);
739 //draw arrow
740 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
741 SetFillColor(COL_WHITE);
742 else
743 SetFillColor(COL_BLACK);
744 SetLineColor();
745 DrawPolygon(Polygon(maPopupTriangle));
749 void AnnotationWindow::MouseMove( const MouseEvent& rMEvt )
751 if( !mbReadonly )
753 if (maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())))
755 if (!mbMouseOverButton)
757 Invalidate(maRectMetaButton);
758 mbMouseOverButton = true;
761 else
763 if (mbMouseOverButton)
765 Invalidate(maRectMetaButton);
766 mbMouseOverButton = false;
772 void AnnotationWindow::MouseButtonDown( const MouseEvent& rMEvt )
774 if (!mbReadonly && maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft())
776 // context menu
777 Rectangle aRect(LogicToPixel(maRectMetaButton.BottomLeft()),LogicToPixel(maRectMetaButton.BottomLeft()));
778 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, (::Window*)this, aRect, true );
782 void AnnotationWindow::Command( const CommandEvent& rCEvt )
784 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
786 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, this, Rectangle(rCEvt.GetMousePosPixel(),Size(1,1)) );
788 else
790 FloatingWindow::Command(rCEvt);
794 void AnnotationWindow::GetFocus()
796 if( mpTextWindow )
797 mpTextWindow->GrabFocus();
798 else
799 FloatingWindow::GetFocus();
802 void AnnotationWindow::ExecuteSlot( USHORT nSID )
804 if( nSID == SID_COPY )
806 getView()->Copy();
808 else if( nSID == SID_PASTE )
810 getView()->PasteSpecial();
811 DoResize();
813 else
815 SfxItemSet aEditAttr(getView()->GetAttribs());
816 SfxItemSet aNewAttr(mpOutliner->GetEmptyItemSet());
818 switch( nSID )
820 case SID_ATTR_CHAR_WEIGHT:
822 FontWeight eFW = ( (const SvxWeightItem&) aEditAttr.Get( EE_CHAR_WEIGHT ) ).GetWeight();
823 aNewAttr.Put( SvxWeightItem( eFW == WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
825 break;
826 case SID_ATTR_CHAR_POSTURE:
828 FontItalic eFI = ( (const SvxPostureItem&) aEditAttr.Get( EE_CHAR_ITALIC ) ).GetPosture();
829 aNewAttr.Put( SvxPostureItem( eFI == ITALIC_NORMAL ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
831 break;
832 case SID_ATTR_CHAR_UNDERLINE:
834 FontUnderline eFU = ( (const SvxUnderlineItem&) aEditAttr. Get( EE_CHAR_UNDERLINE ) ).GetLineStyle();
835 aNewAttr.Put( SvxUnderlineItem( eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE ) );
837 break;
838 case SID_ATTR_CHAR_STRIKEOUT:
840 FontStrikeout eFSO = ( ( (const SvxCrossedOutItem&) aEditAttr.Get( EE_CHAR_STRIKEOUT ) ).GetStrikeout() );
841 aNewAttr.Put( SvxCrossedOutItem( eFSO == STRIKEOUT_SINGLE ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
843 break;
845 getView()->SetAttribs( aNewAttr );