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