1 /************************************************************************* * 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_sd.hxx" 29 30 #include <editeng/fontitem.hxx> 31 #include <editeng/eeitem.hxx> 32 #include <editeng/fhgtitem.hxx> 33 #include <editeng/bulitem.hxx> 34 #include <editeng/udlnitem.hxx> 35 #include <editeng/shdditem.hxx> 36 #include <editeng/flditem.hxx> 37 #include <editeng/frmdir.hxx> 38 #include <editeng/frmdiritem.hxx> 39 #include <editeng/langitem.hxx> 40 #include <editeng/adjitem.hxx> 41 #include <editeng/editview.hxx> 42 #include <svx/svdview.hxx> 43 #include <svx/sdrpaintwindow.hxx> 44 #include <svx/sdr/overlay/overlaymanager.hxx> 45 #include <editeng/editstat.hxx> //EditEngine flags 46 #include <editeng/outliner.hxx> 47 #include <editeng/editeng.hxx> 48 #include <editeng/editobj.hxx> 49 #include <editeng/unolingu.hxx> 50 #include <editeng/outlobj.hxx> 51 #include <editeng/postitem.hxx> 52 #include <editeng/wghtitem.hxx> 53 #include <editeng/udlnitem.hxx> 54 #include <editeng/crsditem.hxx> 55 #include <svx/svxids.hrc> 56 #include <svtools/langtab.hxx> 57 #include <svl/slstitm.hxx> 58 #include <unotools/securityoptions.hxx> 59 #include <unotools/useroptions.hxx> 60 #include <svl/languageoptions.hxx> 61 #include <svl/zforlist.hxx> 62 #include <svtools/svmedit.hxx> 63 64 #include <linguistic/lngprops.hxx> 65 66 #include <sfx2/request.hxx> 67 #include <sfx2/viewfrm.hxx> 68 #include <sfx2/bindings.hxx> 69 #include <sfx2/dispatch.hxx> 70 #include <sfx2/mnumgr.hxx> 71 72 #include <vcl/vclenum.hxx> 73 #include <vcl/edit.hxx> 74 #include <vcl/help.hxx> 75 #include <vcl/scrbar.hxx> 76 #include <vcl/button.hxx> 77 #include <vcl/svapp.hxx> 78 #include <vcl/gradient.hxx> 79 #include <vcl/salbtype.hxx> // FRound 80 #include <vcl/cursor.hxx> 81 82 #include <basegfx/matrix/b2dhommatrix.hxx> 83 #include <basegfx/tuple/b2dtuple.hxx> 84 #include <basegfx/polygon/b2dpolygontools.hxx> 85 86 #include "annotations.hrc" 87 #include "annotationwindow.hxx" 88 #include "annotationmanagerimpl.hxx" 89 90 #include "DrawDocShell.hxx" 91 #include "ViewShell.hxx" 92 #include "drawdoc.hxx" 93 #include "View.hxx" 94 #include "textapi.hxx" 95 #include "sdresid.hxx" 96 97 using rtl::OUString; 98 using namespace ::sd; 99 using namespace ::com::sun::star; 100 using namespace ::com::sun::star::uno; 101 using namespace ::com::sun::star::office; 102 using namespace ::com::sun::star::text; 103 104 #define METABUTTON_WIDTH 16 105 #define METABUTTON_HEIGHT 18 106 #define METABUTTON_AREA_WIDTH 30 107 #define POSTIT_META_HEIGHT (sal_Int32) 30 108 109 #define EMPTYSTRING rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("")) 110 111 namespace sd { 112 113 extern OUString getAnnotationDateTimeString( const Reference< XAnnotation >& xAnnotation ); 114 extern SfxItemPool* GetAnnotationPool(); 115 extern com::sun::star::util::DateTime getCurrentDateTime(); 116 117 Color ColorFromAlphaColor(sal_uInt8 aTransparency, Color &aFront, Color &aBack ) 118 { 119 return Color((sal_uInt8)(aFront.GetRed() * aTransparency/(double)255 + aBack.GetRed() * (1-aTransparency/(double)255)), 120 (sal_uInt8)(aFront.GetGreen() * aTransparency/(double)255 + aBack.GetGreen() * (1-aTransparency/(double)255)), 121 (sal_uInt8)(aFront.GetBlue() * aTransparency/(double)255 + aBack.GetBlue() * (1-aTransparency/(double)255))); 122 } 123 124 /************ AnnotationTextWindow **********************************/ 125 126 AnnotationTextWindow::AnnotationTextWindow( AnnotationWindow* pParent, WinBits nBits ) 127 : Control(pParent, nBits) 128 , mpOutlinerView(0) 129 , mpAnnotationWindow( pParent ) 130 { 131 } 132 133 AnnotationTextWindow::~AnnotationTextWindow() 134 { 135 } 136 137 void AnnotationTextWindow::Paint( const Rectangle& rRect) 138 { 139 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 140 if ( !bHighContrast ) 141 { 142 DrawGradient(Rectangle(Point(0,0),PixelToLogic(GetSizePixel())), 143 Gradient(GRADIENT_LINEAR,mpAnnotationWindow->maColorLight,mpAnnotationWindow->maColor)); 144 } 145 146 if( mpOutlinerView ) 147 { 148 Color aBackgroundColor( mpAnnotationWindow->maColor ); 149 if( bHighContrast ) 150 { 151 aBackgroundColor = GetSettings().GetStyleSettings().GetWindowColor(); 152 } 153 154 mpOutlinerView->SetBackgroundColor( aBackgroundColor ); 155 156 mpOutlinerView->Paint( rRect ); 157 } 158 } 159 160 void AnnotationTextWindow::KeyInput( const KeyEvent& rKeyEvt ) 161 { 162 const KeyCode& rKeyCode = rKeyEvt.GetKeyCode(); 163 sal_uInt16 nKey = rKeyCode.GetCode(); 164 165 if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN))) 166 { 167 SfxDispatcher* pDispatcher = mpAnnotationWindow->DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher(); 168 if( pDispatcher ) 169 pDispatcher->Execute( nKey == KEY_PAGEDOWN ? SID_NEXT_POSTIT : SID_PREVIOUS_POSTIT ); 170 } 171 else if (nKey == KEY_INSERT) 172 { 173 if (!rKeyCode.IsMod1() && !rKeyCode.IsMod2()) 174 mpAnnotationWindow->ToggleInsMode(); 175 } 176 else 177 { 178 long aOldHeight = mpAnnotationWindow->GetPostItTextHeight(); 179 bool bDone = false; 180 181 /// HACK: need to switch off processing of Undo/Redo in Outliner 182 if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) ) 183 { 184 bool bIsProtected = mpAnnotationWindow->IsProtected(); 185 if (!bIsProtected || (bIsProtected && !mpAnnotationWindow->Engine()->GetEditEngine().DoesKeyChangeText(rKeyEvt)) ) 186 187 bDone = mpOutlinerView->PostKeyEvent( rKeyEvt ); 188 } 189 if (bDone) 190 { 191 mpAnnotationWindow->ResizeIfNeccessary(aOldHeight,mpAnnotationWindow->GetPostItTextHeight()); 192 } 193 else 194 { 195 Control::KeyInput(rKeyEvt); 196 } 197 } 198 } 199 200 void AnnotationTextWindow::MouseMove( const MouseEvent& rMEvt ) 201 { 202 if ( mpOutlinerView ) 203 { 204 mpOutlinerView->MouseMove( rMEvt ); 205 SetPointer( mpOutlinerView->GetPointer( rMEvt.GetPosPixel() ) ); 206 } 207 } 208 209 void AnnotationTextWindow::MouseButtonDown( const MouseEvent& rMEvt ) 210 { 211 GrabFocus(); 212 if ( mpOutlinerView ) 213 mpOutlinerView->MouseButtonDown( rMEvt ); 214 // todo mpOutlinerView->DocView()->GetViewFrame()->GetBindings().InvalidateAll(sal_False); 215 } 216 217 void AnnotationTextWindow::MouseButtonUp( const MouseEvent& rMEvt ) 218 { 219 if ( mpOutlinerView ) 220 mpOutlinerView->MouseButtonUp( rMEvt ); 221 } 222 223 void AnnotationTextWindow::Command( const CommandEvent& rCEvt ) 224 { 225 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 226 { 227 mpAnnotationWindow->Command(rCEvt); 228 } 229 else 230 { 231 if ( mpOutlinerView ) 232 mpOutlinerView->Command( rCEvt ); 233 else 234 Window::Command(rCEvt); 235 } 236 } 237 238 void AnnotationTextWindow::GetFocus() 239 { 240 Window::GetFocus(); 241 } 242 243 void AnnotationTextWindow::LoseFocus() 244 { 245 // if ( mpAnnotationWindow ) 246 // mpAnnotationWindow->UpdateAnnotation(); 247 248 Window::LoseFocus(); 249 } 250 251 XubString AnnotationTextWindow::GetSurroundingText() const 252 { 253 if( mpOutlinerView ) 254 { 255 EditEngine *aEditEngine = mpOutlinerView->GetEditView().GetEditEngine(); 256 if( mpOutlinerView->HasSelection() ) 257 return mpOutlinerView->GetSelected(); 258 else 259 { 260 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection(); 261 XubString aStr = aEditEngine->GetText(aSelection.nStartPara); 262 return aStr; 263 } 264 } 265 else 266 return XubString::EmptyString(); 267 } 268 269 Selection AnnotationTextWindow::GetSurroundingTextSelection() const 270 { 271 if( mpOutlinerView ) 272 { 273 if( mpOutlinerView->HasSelection() ) 274 return Selection( 0, mpOutlinerView->GetSelected().Len() ); 275 else 276 { 277 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection(); 278 return Selection( aSelection.nStartPos, aSelection.nEndPos ); 279 } 280 } 281 else 282 return Selection( 0, 0 ); 283 } 284 285 /************** AnnotationWindow***********************************++*/ 286 287 AnnotationWindow::AnnotationWindow( AnnotationManagerImpl& rManager, DrawDocShell* pDocShell, Window* pParent ) 288 : FloatingWindow(pParent, WB_SYSTEMWINDOW|WB_BORDER|WB_NEEDSFOCUS) 289 , mrManager( rManager ) 290 , mpDocShell( pDocShell ) 291 , mpView( pDocShell->GetViewShell()->GetView() ) 292 , mpDoc( pDocShell->GetDoc() ) 293 , mpOutlinerView(0) 294 , mpOutliner(0) 295 , mpVScrollbar(0) 296 , mbReadonly(pDocShell->IsReadOnly()) 297 , mbProtected(false) 298 , mbMouseOverButton(false) 299 , mpTextWindow(0) 300 , mpMeta(0) 301 { 302 } 303 304 AnnotationWindow::~AnnotationWindow() 305 { 306 delete mpMeta; 307 delete mpOutlinerView; 308 delete mpOutliner; 309 delete mpVScrollbar; 310 delete mpTextWindow; 311 } 312 313 void AnnotationWindow::InitControls() 314 { 315 // actual window which holds the user text 316 mpTextWindow = new AnnotationTextWindow(this, WB_NODIALOGCONTROL); 317 mpTextWindow->SetPointer(Pointer(POINTER_TEXT)); 318 319 // window control for author and date 320 mpMeta = new MultiLineEdit(this,0); 321 mpMeta->SetReadOnly(); 322 mpMeta->SetRightToLeft(Application::GetSettings().GetLayoutRTL()); 323 mpMeta->AlwaysDisableInput(true); 324 mpMeta->SetCallHandlersOnInputDisabled(true); 325 326 // mpMeta->AddEventListener( LINK( mpPostItTxt, PostItTxt, WindowEventListener ) ); 327 // AddEventListener( LINK( mpTextWindow, PostItTxt, WindowEventListener ) ); 328 329 // we should leave this setting alone, but for this we need a better layout algo 330 // with variable meta size height 331 AllSettings aSettings = mpMeta->GetSettings(); 332 StyleSettings aStyleSettings = aSettings.GetStyleSettings(); 333 Font aFont = aStyleSettings.GetFieldFont(); 334 aFont.SetHeight(8); 335 aStyleSettings.SetFieldFont(aFont); 336 aSettings.SetStyleSettings(aStyleSettings); 337 mpMeta->SetSettings(aSettings); 338 339 mpOutliner = new ::Outliner(GetAnnotationPool(),OUTLINERMODE_TEXTOBJECT); 340 Doc()->SetCalcFieldValueHdl( mpOutliner ); 341 mpOutliner->SetUpdateMode( sal_True ); 342 Rescale(); 343 344 OutputDevice* pDev = Doc()->GetRefDevice(); 345 if( pDev ) 346 { 347 mpOutliner->SetRefDevice( pDev ); 348 } 349 350 mpOutlinerView = new OutlinerView ( mpOutliner, mpTextWindow ); 351 mpOutliner->InsertView(mpOutlinerView ); 352 mpTextWindow->SetOutlinerView(mpOutlinerView); 353 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,1,1) ) ); 354 355 // SfxItemSet item(DocShell()->GetPool()); 356 // item.Put(SvxFontHeightItem(352,100,EE_CHAR_FONTHEIGHT)); 357 // mpOutlinerView->SetAttribs(item); 358 359 // TODO: ?? 360 EEHorizontalTextDirection aDefHoriTextDir = Application::GetSettings().GetLayoutRTL() ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R; 361 mpOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir ); 362 363 //create Scrollbars 364 mpVScrollbar = new ScrollBar(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG); 365 mpVScrollbar->EnableNativeWidget(false); 366 mpVScrollbar->EnableRTL( false ); 367 mpVScrollbar->SetScrollHdl(LINK(this, AnnotationWindow, ScrollHdl)); 368 mpVScrollbar->EnableDrag(); 369 // mpVScrollbar->AddEventListener( LINK( this, AnnotationWindow, WindowEventListener ) ); 370 371 sal_uLong nCntrl = mpOutliner->GetControlWord(); 372 nCntrl |= EE_CNTRL_PASTESPECIAL | EE_CNTRL_AUTOCORRECT | EV_CNTRL_AUTOSCROLL | EE_CNTRL_NOCOLORS; 373 /* 374 if (pVOpt->IsFieldShadings()) 375 nCntrl |= EE_CNTRL_MARKFIELDS; 376 else 377 nCntrl &= ~EE_CNTRL_MARKFIELDS; 378 if (pVOpt->IsOnlineSpell()) 379 nCntrl |= EE_CNTRL_ONLINESPELLING; 380 else 381 nCntrl &= ~EE_CNTRL_ONLINESPELLING; 382 */ 383 mpOutliner->SetControlWord(nCntrl); 384 // mpOutliner->SetFlatMode( sal_True ); 385 386 Engine()->SetModifyHdl( Link() ); 387 Engine()->EnableUndo( sal_False ); 388 389 Engine()->ClearModifyFlag(); 390 Engine()->GetUndoManager().Clear(); 391 Engine()->EnableUndo( sal_True ); 392 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) ); 393 394 Invalidate(); 395 396 SetLanguage(GetLanguage()); 397 398 mpMeta->Show(); 399 mpVScrollbar->Show(); 400 mpTextWindow->Show(); 401 } 402 403 void AnnotationWindow::StartEdit() 404 { 405 getView()->SetSelection(ESelection(0xFFFF,0xFFFF,0xFFFF,0xFFFF)); 406 getView()->ShowCursor(); 407 } 408 409 void AnnotationWindow::Rescale() 410 { 411 MapMode aMode(MAP_100TH_MM); 412 aMode.SetOrigin( Point() ); 413 //aMode.SetScaleX( aMode.GetScaleX() * Fraction( 8, 10 ) ); 414 //aMode.SetScaleY( aMode.GetScaleY() * Fraction( 8, 10 ) ); 415 mpOutliner->SetRefMapMode( aMode ); 416 SetMapMode( aMode ); 417 mpTextWindow->SetMapMode( aMode ); 418 if ( mpMeta ) 419 { 420 Font aFont( mpMeta->GetSettings().GetStyleSettings().GetFieldFont() ); 421 sal_Int32 nHeight = aFont.GetHeight(); 422 nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator(); 423 aFont.SetHeight( nHeight ); 424 mpMeta->SetControlFont( aFont ); 425 } 426 } 427 428 void AnnotationWindow::DoResize() 429 { 430 unsigned long aWidth = GetSizePixel().Width(); 431 long aHeight = GetSizePixel().Height() - POSTIT_META_HEIGHT; 432 433 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ; 434 long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height(); 435 436 if( aTextHeight > aHeight ) 437 { // we need vertical scrollbars and have to reduce the width 438 aWidth -= GetScrollbarWidth(); 439 mpVScrollbar->Show(); 440 } 441 else 442 { 443 mpVScrollbar->Hide(); 444 } 445 446 mpTextWindow->SetPosSizePixel(0,0,aWidth, aHeight); 447 448 if( mbReadonly ) 449 mpMeta->SetPosSizePixel(0,aHeight,GetSizePixel().Width(),POSTIT_META_HEIGHT); 450 else 451 mpMeta->SetPosSizePixel(0,aHeight,GetSizePixel().Width()-METABUTTON_AREA_WIDTH,POSTIT_META_HEIGHT); 452 453 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ; 454 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) ); 455 if (!mpVScrollbar->IsVisible()) 456 { // if we do not have a scrollbar anymore, we want to see the complete text 457 mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) ); 458 } 459 mpVScrollbar->SetPosSizePixel( 0 + aWidth, 0, GetScrollbarWidth(), aHeight ); 460 mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() ); 461 mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 ); 462 mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 ); 463 SetScrollbar(); 464 mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight())); 465 466 Point aPos( mpMeta->GetPosPixel()); 467 Point aBase( aPos.X() + aPos.X() + GetSizePixel().Width(), aPos.Y() ); 468 Point aLeft = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+5), aBase.Y()+17 ) ); 469 Point aRight = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH-1), aBase.Y()+17 ) ); 470 Point aBottom = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+2), aBase.Y()+20 ) ); 471 472 maPopupTriangle.clear(); 473 maPopupTriangle.append(basegfx::B2DPoint(aLeft.X(),aLeft.Y())); 474 maPopupTriangle.append(basegfx::B2DPoint(aRight.X(),aRight.Y())); 475 maPopupTriangle.append(basegfx::B2DPoint(aBottom.X(),aBottom.Y())); 476 maPopupTriangle.setClosed(true); 477 maRectMetaButton = PixelToLogic( Rectangle( Point( 478 aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10), 479 aPos.Y()+5 ), 480 Size( METABUTTON_WIDTH, METABUTTON_HEIGHT ) ) ); 481 482 } 483 484 void AnnotationWindow::SetSizePixel( const Size& rNewSize ) 485 { 486 Window::SetSizePixel(rNewSize); 487 } 488 489 void AnnotationWindow::SetScrollbar() 490 { 491 mpVScrollbar->SetThumbPos( mpOutlinerView->GetVisArea().Top()+ mpOutlinerView->GetEditView().GetCursor()->GetOffsetY()); 492 } 493 494 void AnnotationWindow::ResizeIfNeccessary(long aOldHeight, long aNewHeight) 495 { 496 if (aOldHeight != aNewHeight) 497 { 498 DoResize(); 499 Invalidate(); 500 } 501 else 502 { 503 SetScrollbar(); 504 } 505 } 506 507 void AnnotationWindow::SetLanguage(const SvxLanguageItem aNewItem) 508 { 509 Engine()->SetModifyHdl( Link() ); 510 ESelection aOld = getView()->GetSelection(); 511 512 ESelection aNewSelection( 0, 0, (sal_uInt16)Engine()->GetParagraphCount()-1, USHRT_MAX ); 513 getView()->SetSelection( aNewSelection ); 514 SfxItemSet aEditAttr(getView()->GetAttribs()); 515 aEditAttr.Put(aNewItem); 516 getView()->SetAttribs( aEditAttr ); 517 518 getView()->SetSelection(aOld); 519 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) ); 520 521 Invalidate(); 522 } 523 524 void AnnotationWindow::ToggleInsMode() 525 { 526 if( mpOutlinerView ) 527 { 528 SfxBindings &rBnd = mpDocShell->GetViewShell()->GetViewFrame()->GetBindings(); 529 rBnd.Invalidate(SID_ATTR_INSERT); 530 rBnd.Update(SID_ATTR_INSERT); 531 } 532 } 533 534 long AnnotationWindow::GetPostItTextHeight() 535 { 536 return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0; 537 } 538 539 IMPL_LINK(AnnotationWindow, ScrollHdl, ScrollBar*, pScroll) 540 { 541 long nDiff = getView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos(); 542 getView()->Scroll( 0, nDiff ); 543 return 0; 544 } 545 546 IMPL_LINK(AnnotationWindow, ModifyHdl, void*, EMPTYARG) 547 { 548 return 0; 549 } 550 551 sal_Int32 AnnotationWindow::GetScrollbarWidth() 552 { 553 return 16; 554 // return mpView->GetWrtShell().GetViewOptions()->GetZoom() / 10; 555 } 556 557 SvxLanguageItem AnnotationWindow::GetLanguage(void) 558 { 559 return SvxLanguageItem( Doc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE ); 560 } 561 562 // -------------------------------------------------------------------- 563 564 TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation ) 565 { 566 if( xAnnotation.is() ) 567 { 568 Reference< XText > xText( xAnnotation->getTextRange() ); 569 return TextApiObject::getImplementation( xText ); 570 } 571 return 0; 572 } 573 574 // -------------------------------------------------------------------- 575 576 void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotation, bool bGrabFocus ) 577 { 578 if( (xAnnotation != mxAnnotation) && xAnnotation.is() ) 579 { 580 mxAnnotation = xAnnotation; 581 582 SetColor(); 583 584 SvtUserOptions aUserOptions; 585 mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor(); 586 587 Engine()->Clear(); 588 TextApiObject* pTextApi = getTextApiObject( mxAnnotation ); 589 590 if( pTextApi ) 591 { 592 std::auto_ptr< OutlinerParaObject > pOPO( pTextApi->CreateText() ); 593 Engine()->SetText( *pOPO.get() ); 594 } 595 596 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) ); 597 Engine()->ClearModifyFlag(); 598 Engine()->GetUndoManager().Clear(); 599 600 Invalidate(); 601 602 OUString sMeta( xAnnotation->getAuthor() ); 603 OUString sDateTime( getAnnotationDateTimeString(xAnnotation) ); 604 605 if( sDateTime.getLength() != 0 ) 606 { 607 if( sMeta.getLength() != 0 ) 608 sMeta += OUString( RTL_CONSTASCII_USTRINGPARAM( "\n" ) ); 609 610 sMeta += sDateTime; 611 } 612 mpMeta->SetText(sMeta); 613 614 if( bGrabFocus ) 615 GrabFocus(); 616 } 617 } 618 619 void AnnotationWindow::SetColor() 620 { 621 sal_uInt16 nAuthorIdx = mpDoc->GetAnnotationAuthorIndex( mxAnnotation->getAuthor() ); 622 623 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 624 if( bHighContrast ) 625 { 626 StyleSettings aStyleSettings = GetSettings().GetStyleSettings(); 627 628 maColor = aStyleSettings.GetWindowColor(); 629 maColorDark = maColor; 630 maColorLight = aStyleSettings.GetWindowTextColor(); 631 } 632 else 633 { 634 maColor = mrManager.GetColor( nAuthorIdx ); 635 maColorDark = mrManager.GetColorDark( nAuthorIdx ); 636 maColorLight = mrManager.GetColorLight( nAuthorIdx ); 637 } 638 639 mpOutlinerView->SetBackgroundColor(maColor); 640 Engine()->SetBackgroundColor(maColor); 641 642 { 643 SvtAccessibilityOptions aOptions; 644 Engine()->ForceAutoColor( bHighContrast || aOptions.GetIsAutomaticFontColor() ); 645 } 646 647 mpMeta->SetControlBackground(maColor); 648 AllSettings aSettings = mpMeta->GetSettings(); 649 StyleSettings aStyleSettings = aSettings.GetStyleSettings(); 650 aStyleSettings.SetFieldTextColor( bHighContrast ? maColorLight : maColorDark); 651 aSettings.SetStyleSettings(aStyleSettings); 652 mpMeta->SetSettings(aSettings); 653 654 AllSettings aSettings2 = mpVScrollbar->GetSettings(); 655 StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings(); 656 aStyleSettings2.SetButtonTextColor(Color(0,0,0)); 657 aStyleSettings2.SetCheckedColor(maColorLight); //hintergund 658 aStyleSettings2.SetShadowColor(maColorDark); 659 aStyleSettings2.SetFaceColor(maColor); 660 aSettings2.SetStyleSettings(aStyleSettings2); 661 mpVScrollbar->SetSettings(aSettings2); 662 } 663 664 void AnnotationWindow::Deactivate() 665 { 666 Reference< XAnnotation > xAnnotation( mxAnnotation ); 667 668 // write changed text back to annotation 669 if ( Engine()->IsModified() ) 670 { 671 TextApiObject* pTextApi = getTextApiObject( xAnnotation ); 672 673 if( pTextApi ) 674 { 675 OutlinerParaObject* pOPO = Engine()->CreateParaObject(); 676 if( pOPO ) 677 { 678 if( mpDoc->IsUndoEnabled() ) 679 mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_EDIT ) ) ); 680 681 pTextApi->SetText( *pOPO ); 682 delete pOPO; 683 684 // set current time to changed annotation 685 xAnnotation->setDateTime( getCurrentDateTime() ); 686 687 if( mpDoc->IsUndoEnabled() ) 688 mpDoc->EndUndo(); 689 690 DocView()->GetDocSh()->SetModified(sal_True); 691 } 692 693 } 694 } 695 Engine()->ClearModifyFlag(); 696 697 Engine()->GetUndoManager().Clear(); 698 } 699 700 void AnnotationWindow::Paint( const Rectangle& rRect) 701 { 702 FloatingWindow::Paint( rRect ); 703 704 if(mpMeta->IsVisible() && !mbReadonly) 705 { 706 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 707 //draw left over space 708 if ( bHighContrast ) 709 SetFillColor(COL_BLACK); 710 else 711 SetFillColor(maColor); 712 SetLineColor(); 713 DrawRect(PixelToLogic(Rectangle(Point(mpMeta->GetPosPixel().X()+mpMeta->GetSizePixel().Width(),mpMeta->GetPosPixel().Y()),Size(METABUTTON_AREA_WIDTH,mpMeta->GetSizePixel().Height())))); 714 715 if ( bHighContrast ) 716 { 717 //draw rect around button 718 SetFillColor(COL_BLACK); 719 SetLineColor(COL_WHITE); 720 } 721 else 722 { 723 //draw button 724 Gradient aGradient; 725 if (mbMouseOverButton) 726 aGradient = Gradient(GRADIENT_LINEAR,ColorFromAlphaColor(80,maColorDark,maColor),ColorFromAlphaColor(15,maColorDark,maColor)); 727 else 728 aGradient = Gradient(GRADIENT_LINEAR,ColorFromAlphaColor(15,maColorDark,maColor),ColorFromAlphaColor(80,maColorDark,maColor)); 729 DrawGradient(maRectMetaButton,aGradient); 730 //draw rect around button 731 SetFillColor(); 732 SetLineColor(ColorFromAlphaColor(90,maColorDark,maColor)); 733 } 734 DrawRect(maRectMetaButton); 735 736 //draw arrow 737 if( bHighContrast ) 738 SetFillColor(COL_WHITE); 739 else 740 SetFillColor(COL_BLACK); 741 SetLineColor(); 742 DrawPolygon(Polygon(maPopupTriangle)); 743 } 744 } 745 746 void AnnotationWindow::MouseMove( const MouseEvent& rMEvt ) 747 { 748 if( !mbReadonly ) 749 { 750 if (maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel()))) 751 { 752 if (!mbMouseOverButton) 753 { 754 Invalidate(maRectMetaButton); 755 mbMouseOverButton = true; 756 } 757 } 758 else 759 { 760 if (mbMouseOverButton) 761 { 762 Invalidate(maRectMetaButton); 763 mbMouseOverButton = false; 764 } 765 } 766 } 767 } 768 769 void AnnotationWindow::MouseButtonDown( const MouseEvent& rMEvt ) 770 { 771 if (!mbReadonly && maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft()) 772 { 773 // context menu 774 Rectangle aRect(LogicToPixel(maRectMetaButton.BottomLeft()),LogicToPixel(maRectMetaButton.BottomLeft())); 775 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, (::Window*)this, aRect, true ); 776 } 777 } 778 779 void AnnotationWindow::Command( const CommandEvent& rCEvt ) 780 { 781 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 782 { 783 if( mpMeta->IsVisible() &&(mpMeta->GetPosPixel().Y() < rCEvt.GetMousePosPixel().Y()) ) 784 return; 785 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, this, Rectangle(rCEvt.GetMousePosPixel(),Size(1,1)) ); 786 } 787 else 788 { 789 FloatingWindow::Command(rCEvt); 790 } 791 } 792 793 void AnnotationWindow::GetFocus() 794 { 795 if( mpTextWindow ) 796 mpTextWindow->GrabFocus(); 797 else 798 FloatingWindow::GetFocus(); 799 } 800 801 void AnnotationWindow::ExecuteSlot( sal_uInt16 nSID ) 802 { 803 if( nSID == SID_COPY ) 804 { 805 getView()->Copy(); 806 } 807 else if( nSID == SID_PASTE ) 808 { 809 getView()->PasteSpecial(); 810 DoResize(); 811 } 812 else 813 { 814 SfxItemSet aEditAttr(getView()->GetAttribs()); 815 SfxItemSet aNewAttr(mpOutliner->GetEmptyItemSet()); 816 817 switch( nSID ) 818 { 819 case SID_ATTR_CHAR_WEIGHT: 820 { 821 FontWeight eFW = ( (const SvxWeightItem&) aEditAttr.Get( EE_CHAR_WEIGHT ) ).GetWeight(); 822 aNewAttr.Put( SvxWeightItem( eFW == WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) ); 823 } 824 break; 825 case SID_ATTR_CHAR_POSTURE: 826 { 827 FontItalic eFI = ( (const SvxPostureItem&) aEditAttr.Get( EE_CHAR_ITALIC ) ).GetPosture(); 828 aNewAttr.Put( SvxPostureItem( eFI == ITALIC_NORMAL ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) ); 829 } 830 break; 831 case SID_ATTR_CHAR_UNDERLINE: 832 { 833 FontUnderline eFU = ( (const SvxUnderlineItem&) aEditAttr. Get( EE_CHAR_UNDERLINE ) ).GetLineStyle(); 834 aNewAttr.Put( SvxUnderlineItem( eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE ) ); 835 } 836 break; 837 case SID_ATTR_CHAR_STRIKEOUT: 838 { 839 FontStrikeout eFSO = ( ( (const SvxCrossedOutItem&) aEditAttr.Get( EE_CHAR_STRIKEOUT ) ).GetStrikeout() ); 840 aNewAttr.Put( SvxCrossedOutItem( eFSO == STRIKEOUT_SINGLE ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) ); 841 } 842 break; 843 } 844 getView()->SetAttribs( aNewAttr ); 845 } 846 } 847 848 } 849