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_sw.hxx" 25 26 #include <SidebarWin.hxx> 27 #include <SidebarWinAcc.hxx> 28 #include <PostItMgr.hxx> 29 30 #include <SidebarTxtControl.hxx> 31 #include <AnchorOverlayObject.hxx> 32 #include <ShadowOverlayObject.hxx> 33 #include <OverlayRanges.hxx> 34 35 #include <annotation.hrc> 36 #include <popup.hrc> 37 #include <docvw.hrc> 38 #include <app.hrc> 39 #include <access.hrc> 40 41 #include <viewopt.hxx> 42 #include <cmdid.h> 43 44 #include <editeng/fontitem.hxx> 45 #include <editeng/fhgtitem.hxx> 46 #include <editeng/langitem.hxx> 47 #include <editeng/editview.hxx> 48 #include <editeng/outliner.hxx> 49 #include <editeng/editeng.hxx> 50 #include <editeng/eeitem.hxx> 51 52 #include <svl/zforlist.hxx> 53 #include <svl/undo.hxx> 54 #include <svl/stritem.hxx> 55 56 #include <sfx2/viewfrm.hxx> 57 #include <sfx2/bindings.hxx> 58 #include <sfx2/dispatch.hxx> 59 60 #include <vcl/scrbar.hxx> 61 #include <vcl/svapp.hxx> 62 #include <vcl/menubtn.hxx> 63 64 #include <edtwin.hxx> 65 #include <view.hxx> 66 #include <docsh.hxx> 67 #include <wrtsh.hxx> 68 #include <doc.hxx> 69 #include <swmodule.hxx> 70 #include <langhelper.hxx> 71 72 #include <txtannotationfld.hxx> 73 #include <ndtxt.hxx> 74 75 #include <sw_primitivetypes2d.hxx> 76 #include <drawinglayer/primitive2d/primitivetools2d.hxx> 77 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx> 78 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 79 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 80 #include <drawinglayer/primitive2d/shadowprimitive2d.hxx> 81 82 namespace css = ::com::sun::star; 83 84 namespace sw { namespace sidebarwindows { 85 86 #define METABUTTON_WIDTH 16 87 #define METABUTTON_HEIGHT 18 88 #define METABUTTON_AREA_WIDTH 30 89 #define POSTIT_META_HEIGHT (sal_Int32) 30 90 #define POSTIT_MINIMUMSIZE_WITHOUT_META 50 91 92 #define POSTIT_SHADOW_BRIGHT Color(180,180,180) 93 #define POSTIT_SHADOW_DARK Color(83,83,83) 94 95 #define EMPTYSTRING rtl::OUString::createFromAscii("") 96 97 /************** SwSidebarWin************************************/ 98 SwSidebarWin::SwSidebarWin( SwEditWin& rEditWin, 99 WinBits nBits, 100 SwPostItMgr& aMgr, 101 SwPostItBits aBits, 102 SwSidebarItem& rSidebarItem ) 103 : Window(&rEditWin, nBits) 104 , mrMgr(aMgr) 105 , mrView( rEditWin.GetView() ) 106 , nFlags(aBits) 107 , mnEventId(0) 108 , mpOutlinerView(0) 109 , mpOutliner(0) 110 , mpSidebarTxtControl(0) 111 , mpVScrollbar(0) 112 , mpMetadataAuthor(0) 113 , mpMetadataDate(0) 114 , mpMenuButton(0) 115 , mpAnchor( NULL ) 116 , mpShadow( NULL ) 117 , mpTextRangeOverlay( NULL ) 118 , mColorAnchor() 119 , mColorDark() 120 , mColorLight() 121 , mChangeColor() 122 , meSidebarPosition( sw::sidebarwindows::SIDEBAR_NONE ) 123 , mPosSize() 124 , mAnchorRect() 125 , mPageBorder( 0 ) 126 , mbMouseOver( false ) 127 , mLayoutStatus( SwPostItHelper::INVISIBLE ) 128 , mbReadonly( false ) 129 , mbIsFollow( false ) 130 , mrSidebarItem( rSidebarItem ) 131 , mpAnchorFrm( rSidebarItem.maLayoutInfo.mpAnchorFrm ) 132 { 133 mpShadow = ShadowOverlayObject::CreateShadowOverlayObject( mrView ); 134 if ( mpShadow ) 135 { 136 mpShadow->setVisible(false); 137 } 138 139 mrMgr.ConnectSidebarWinToFrm( *(mrSidebarItem.maLayoutInfo.mpAnchorFrm), 140 mrSidebarItem.GetFmtFld(), 141 *this ); 142 } 143 144 SwSidebarWin::~SwSidebarWin() 145 { 146 mrMgr.DisconnectSidebarWinFromFrm( *(mrSidebarItem.maLayoutInfo.mpAnchorFrm), 147 *this ); 148 149 Disable(); 150 151 if ( mpSidebarTxtControl ) 152 { 153 if ( mpOutlinerView ) 154 { 155 mpOutlinerView->SetWindow( 0 ); 156 } 157 delete mpSidebarTxtControl; 158 mpSidebarTxtControl = 0; 159 } 160 161 if ( mpOutlinerView ) 162 { 163 delete mpOutlinerView; 164 mpOutlinerView = 0; 165 } 166 167 if (mpOutliner) 168 { 169 delete mpOutliner; 170 mpOutliner = 0; 171 } 172 173 if (mpMetadataAuthor) 174 { 175 mpMetadataAuthor->RemoveEventListener( LINK( this, SwSidebarWin, WindowEventListener ) ); 176 delete mpMetadataAuthor; 177 mpMetadataAuthor = 0; 178 } 179 180 if (mpMetadataDate) 181 { 182 mpMetadataDate->RemoveEventListener( LINK( this, SwSidebarWin, WindowEventListener ) ); 183 delete mpMetadataDate; 184 mpMetadataDate = 0; 185 } 186 187 if (mpVScrollbar) 188 { 189 mpVScrollbar->RemoveEventListener( LINK( this, SwSidebarWin, WindowEventListener ) ); 190 delete mpVScrollbar; 191 mpVScrollbar = 0; 192 } 193 194 AnchorOverlayObject::DestroyAnchorOverlayObject( mpAnchor ); 195 mpAnchor = NULL; 196 197 ShadowOverlayObject::DestroyShadowOverlayObject( mpShadow ); 198 mpShadow = NULL; 199 200 delete mpTextRangeOverlay; 201 mpTextRangeOverlay = NULL; 202 203 delete mpMenuButton; 204 mpMenuButton = 0; 205 206 if (mnEventId) 207 Application::RemoveUserEvent( mnEventId ); 208 } 209 210 void SwSidebarWin::Paint( const Rectangle& rRect) 211 { 212 Window::Paint(rRect); 213 214 if (mpMetadataAuthor->IsVisible() ) 215 { 216 //draw left over space 217 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) 218 { 219 SetFillColor(COL_BLACK); 220 } 221 else 222 { 223 SetFillColor(mColorDark); 224 } 225 SetLineColor(); 226 DrawRect( PixelToLogic( 227 Rectangle( Point( mpMetadataAuthor->GetPosPixel().X() + 228 mpMetadataAuthor->GetSizePixel().Width(), 229 mpMetadataAuthor->GetPosPixel().Y() ), 230 Size( GetMetaButtonAreaWidth(), 231 mpMetadataAuthor->GetSizePixel().Height() + 232 mpMetadataDate->GetSizePixel().Height() ) ) ) ); 233 } 234 } 235 236 void SwSidebarWin::SetPosSizePixelRect( long nX, 237 long nY, 238 long nWidth, 239 long nHeight, 240 const SwRect& aAnchorRect, 241 const long aPageBorder) 242 { 243 mPosSize = Rectangle(Point(nX,nY),Size(nWidth,nHeight)); 244 mAnchorRect = aAnchorRect; 245 mPageBorder = aPageBorder; 246 } 247 248 void SwSidebarWin::SetSize( const Size& rNewSize ) 249 { 250 mPosSize.SetSize(rNewSize); 251 } 252 253 void SwSidebarWin::SetVirtualPosSize( const Point& aPoint, const Size& aSize) 254 { 255 mPosSize = Rectangle(aPoint,aSize); 256 } 257 258 void SwSidebarWin::TranslateTopPosition(const long aAmount) 259 { 260 mPosSize.Move(0,aAmount); 261 } 262 263 void SwSidebarWin::ShowAnchorOnly(const Point &aPoint) 264 { 265 HideNote(); 266 SetPosAndSize(); 267 if (mpAnchor) 268 { 269 mpAnchor->SetSixthPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y())); 270 mpAnchor->SetSeventhPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y())); 271 mpAnchor->SetAnchorState(AS_ALL); 272 mpAnchor->setVisible(true); 273 } 274 if (mpShadow) 275 mpShadow->setVisible(false); 276 } 277 278 SfxItemSet SwSidebarWin::DefaultItem() 279 { 280 SfxItemSet aItem( mrView.GetDocShell()->GetPool() ); 281 aItem.Put(SvxFontHeightItem(200,100,EE_CHAR_FONTHEIGHT)); 282 aItem.Put(SvxFontItem(FAMILY_SWISS,GetSettings().GetStyleSettings().GetFieldFont().GetName(), 283 EMPTYSTRING,PITCH_DONTKNOW,RTL_TEXTENCODING_DONTKNOW,EE_CHAR_FONTINFO)); 284 return aItem; 285 } 286 287 void SwSidebarWin::InitControls() 288 { 289 AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) ); 290 291 // actual window which holds the user text 292 mpSidebarTxtControl = new SidebarTxtControl( *this, 293 WB_NODIALOGCONTROL, 294 mrView, mrMgr ); 295 mpSidebarTxtControl->SetPointer(Pointer(POINTER_TEXT)); 296 297 // window controls for author and date 298 mpMetadataAuthor = new Edit( this, 0 ); 299 mpMetadataAuthor->SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_AUTHOR_NAME ) ); 300 mpMetadataAuthor->SetReadOnly(); 301 mpMetadataAuthor->AlwaysDisableInput(true); 302 mpMetadataAuthor->SetCallHandlersOnInputDisabled(true); 303 mpMetadataAuthor->AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) ); 304 // we should leave this setting alone, but for this we need a better layout algo 305 // with variable meta size height 306 { 307 AllSettings aSettings = mpMetadataAuthor->GetSettings(); 308 StyleSettings aStyleSettings = aSettings.GetStyleSettings(); 309 Font aFont = aStyleSettings.GetFieldFont(); 310 aFont.SetHeight(8); 311 aStyleSettings.SetFieldFont(aFont); 312 aSettings.SetStyleSettings(aStyleSettings); 313 mpMetadataAuthor->SetSettings(aSettings); 314 } 315 316 mpMetadataDate = new Edit( this, 0 ); 317 mpMetadataDate->SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_DATE_NAME ) ); 318 mpMetadataDate->SetReadOnly(); 319 mpMetadataDate->AlwaysDisableInput(true); 320 mpMetadataDate->SetCallHandlersOnInputDisabled(true); 321 mpMetadataDate->AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) ); 322 // we should leave this setting alone, but for this we need a better layout algo 323 // with variable meta size height 324 { 325 AllSettings aSettings = mpMetadataDate->GetSettings(); 326 StyleSettings aStyleSettings = aSettings.GetStyleSettings(); 327 Font aFont = aStyleSettings.GetFieldFont(); 328 aFont.SetHeight(8); 329 aStyleSettings.SetFieldFont(aFont); 330 aSettings.SetStyleSettings(aStyleSettings); 331 mpMetadataDate->SetSettings(aSettings); 332 } 333 334 335 SwDocShell* aShell = mrView.GetDocShell(); 336 mpOutliner = new Outliner(&aShell->GetPool(),OUTLINERMODE_TEXTOBJECT); 337 aShell->GetDoc()->SetCalcFieldValueHdl( mpOutliner ); 338 mpOutliner->SetUpdateMode( sal_True ); 339 Rescale(); 340 341 mpOutlinerView = new OutlinerView ( mpOutliner, mpSidebarTxtControl ); 342 mpOutlinerView->SetBackgroundColor(COL_TRANSPARENT); 343 mpOutliner->InsertView(mpOutlinerView ); 344 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,1,1) ) ); 345 346 mpOutlinerView->SetAttribs(DefaultItem()); 347 348 // TODO: ?? 349 EEHorizontalTextDirection aDefHoriTextDir = Application::GetSettings().GetLayoutRTL() ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R; 350 mpOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir ); 351 352 //create Scrollbars 353 mpVScrollbar = new ScrollBar(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG); 354 mpVScrollbar->EnableNativeWidget(false); 355 mpVScrollbar->EnableRTL( false ); 356 mpVScrollbar->SetScrollHdl(LINK(this, SwSidebarWin, ScrollHdl)); 357 mpVScrollbar->EnableDrag(); 358 mpVScrollbar->AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) ); 359 360 const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions(); 361 sal_uLong nCntrl = mpOutliner->GetControlWord(); 362 // TODO: crash when AUTOCOMPLETE enabled 363 nCntrl |= EE_CNTRL_MARKFIELDS | EE_CNTRL_PASTESPECIAL | EE_CNTRL_AUTOCORRECT | EV_CNTRL_AUTOSCROLL | EE_CNTRL_URLSFXEXECUTE; // | EE_CNTRL_AUTOCOMPLETE; 364 if (pVOpt->IsFieldShadings()) 365 nCntrl |= EE_CNTRL_MARKFIELDS; 366 else 367 nCntrl &= ~EE_CNTRL_MARKFIELDS; 368 if (pVOpt->IsOnlineSpell()) 369 nCntrl |= EE_CNTRL_ONLINESPELLING; 370 else 371 nCntrl &= ~EE_CNTRL_ONLINESPELLING; 372 mpOutliner->SetControlWord(nCntrl); 373 374 sal_uInt16 aIndex = SW_MOD()->InsertRedlineAuthor(GetAuthor()); 375 SetColor( mrMgr.GetColorDark(aIndex), 376 mrMgr.GetColorLight(aIndex), 377 mrMgr.GetColorAnchor(aIndex)); 378 379 CheckMetaText(); 380 381 mpMenuButton = CreateMenuButton(); 382 383 SetLanguage(GetLanguage()); 384 GetOutlinerView()->StartSpeller(); 385 SetPostItText(); 386 Engine()->CompleteOnlineSpelling(); 387 388 mpSidebarTxtControl->Show(); 389 mpMetadataAuthor->Show(); 390 mpMetadataDate->Show(); 391 mpVScrollbar->Show(); 392 } 393 394 void SwSidebarWin::CheckMetaText() 395 { 396 const SvtSysLocale aSysLocale; 397 const LocaleDataWrapper& rLocalData = aSysLocale.GetLocaleData(); 398 String sMeta = GetAuthor(); 399 if (sMeta.Len() == 0) 400 { 401 sMeta = String(SW_RES(STR_NOAUTHOR)); 402 } 403 else if (sMeta.Len() > 22) 404 { 405 sMeta.Erase(20); 406 sMeta = sMeta + rtl::OUString::createFromAscii("..."); 407 } 408 if ( mpMetadataAuthor->GetText() != sMeta ) 409 { 410 mpMetadataAuthor->SetText(sMeta); 411 } 412 413 Date aDate = GetDate(); 414 if (aDate==Date()) 415 { 416 sMeta = String(SW_RES(STR_POSTIT_TODAY)); 417 } 418 else if (aDate == Date(Date()-1)) 419 { 420 sMeta = String(SW_RES(STR_POSTIT_YESTERDAY)); 421 } 422 else if (aDate.IsValid() ) 423 { 424 sMeta = rLocalData.getDate(aDate); 425 } 426 else 427 { 428 sMeta = String(SW_RES(STR_NODATE)); 429 } 430 if (GetTime()!=0) 431 { 432 sMeta = sMeta + rtl::OUString::createFromAscii(" ") + rLocalData.getTime( GetTime(),false ); 433 } 434 if ( mpMetadataDate->GetText() != sMeta ) 435 { 436 mpMetadataDate->SetText(sMeta); 437 } 438 439 } 440 441 void SwSidebarWin::Rescale() 442 { 443 MapMode aMode = GetParent()->GetMapMode(); 444 aMode.SetOrigin( Point() ); 445 mpOutliner->SetRefMapMode( aMode ); 446 SetMapMode( aMode ); 447 mpSidebarTxtControl->SetMapMode( aMode ); 448 if ( mpMetadataAuthor ) 449 { 450 Font aFont( mpMetadataAuthor->GetSettings().GetStyleSettings().GetFieldFont() ); 451 sal_Int32 nHeight = aFont.GetHeight(); 452 nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator(); 453 aFont.SetHeight( nHeight ); 454 mpMetadataAuthor->SetControlFont( aFont ); 455 } 456 if ( mpMetadataDate ) 457 { 458 Font aFont( mpMetadataDate->GetSettings().GetStyleSettings().GetFieldFont() ); 459 sal_Int32 nHeight = aFont.GetHeight(); 460 nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator(); 461 aFont.SetHeight( nHeight ); 462 mpMetadataDate->SetControlFont( aFont ); 463 } 464 } 465 466 void SwSidebarWin::SetPosAndSize() 467 { 468 bool bChange = false; 469 470 if (GetSizePixel() != mPosSize.GetSize()) 471 { 472 bChange = true; 473 SetSizePixel(mPosSize.GetSize()); 474 DoResize(); 475 } 476 477 if (GetPosPixel().X() != mPosSize.TopLeft().X() || (abs(GetPosPixel().Y() - mPosSize.TopLeft().Y()) > 5) ) 478 { 479 bChange = true; 480 SetPosPixel(mPosSize.TopLeft()); 481 482 Point aLineStart; 483 Point aLineEnd ; 484 switch ( meSidebarPosition ) 485 { 486 case sw::sidebarwindows::SIDEBAR_LEFT: 487 { 488 aLineStart = EditWin()->PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) ); 489 aLineEnd = EditWin()->PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) ); 490 } 491 break; 492 case sw::sidebarwindows::SIDEBAR_RIGHT: 493 { 494 aLineStart = EditWin()->PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) ); 495 aLineEnd = EditWin()->PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) ); 496 } 497 break; 498 default: 499 ASSERT( false, 500 "<SwSidebarWin::SetPosAndSize()> - unexpected position of sidebar" ); 501 break; 502 } 503 504 if (!IsPreview()) 505 { 506 if (mpAnchor) 507 { 508 mpAnchor->SetAllPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15), 509 basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15), 510 basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15), 511 basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15), 512 basegfx::B2DPoint( mPageBorder ,mAnchorRect.Bottom()+2*15), 513 basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()), 514 basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y())); 515 mpAnchor->SetHeight(mAnchorRect.Height()); 516 } 517 else 518 { 519 mpAnchor = AnchorOverlayObject::CreateAnchorOverlayObject( mrView, 520 mAnchorRect, 521 mPageBorder, 522 aLineStart, 523 aLineEnd, 524 mColorAnchor ); 525 if ( mpAnchor ) 526 { 527 mpAnchor->SetHeight(mAnchorRect.Height()); 528 mpAnchor->setVisible(true); 529 mpAnchor->SetAnchorState(AS_TRI); 530 if (HasChildPathFocus()) 531 { 532 mpAnchor->setLineSolid(true); 533 } 534 } 535 } 536 } 537 } 538 else 539 { 540 if ( mpAnchor && 541 ( mpAnchor->getBasePosition() != basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom()-5*15) ) ) 542 { 543 mpAnchor->SetTriPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15), 544 basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15), 545 basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15), 546 basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15), 547 basegfx::B2DPoint( mPageBorder , mAnchorRect.Bottom()+2*15)); 548 } 549 } 550 551 if (bChange) 552 { 553 Point aStart = EditWin()->PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height())); 554 Point aEnd = EditWin()->PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height())); 555 mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y())); 556 } 557 558 if (mrMgr.ShowNotes()) 559 { 560 if (IsFollow() && !HasChildPathFocus()) 561 { 562 if ( mpAnchor ) 563 { 564 mpAnchor->SetAnchorState(AS_END); 565 } 566 } 567 else 568 { 569 if ( mpAnchor ) 570 { 571 mpAnchor->SetAnchorState(AS_ALL); 572 } 573 SwSidebarWin* pWin = GetTopReplyNote(); 574 if ( pWin && pWin->Anchor() ) 575 { 576 pWin->Anchor()->SetAnchorState(AS_END); 577 } 578 } 579 } 580 581 // text range overlay 582 if ( mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0 583 && mrSidebarItem.maLayoutInfo.mnStartContent != STRING_NOTFOUND ) 584 { 585 std::vector< basegfx::B2DRange > aAnnotationTextRanges; 586 { 587 const SwTxtAnnotationFld* pTxtAnnotationFld = 588 dynamic_cast< const SwTxtAnnotationFld* >( mrSidebarItem.GetFmtFld().GetTxtFld() ); 589 if ( pTxtAnnotationFld != NULL 590 && pTxtAnnotationFld->GetpTxtNode() != NULL ) 591 { 592 SwTxtNode* pTxtNode = pTxtAnnotationFld->GetpTxtNode(); 593 SwNodes& rNds = pTxtNode->GetDoc()->GetNodes(); 594 SwCntntNode* const pCntntNd = rNds[mrSidebarItem.maLayoutInfo.mnStartNodeIdx]->GetCntntNode(); 595 SwPosition aStartPos( *pCntntNd, mrSidebarItem.maLayoutInfo.mnStartContent ); 596 SwShellCrsr* pTmpCrsr = NULL; 597 const bool bTableCrsrNeeded = pTxtNode->FindTableBoxStartNode() != pCntntNd->FindTableBoxStartNode(); 598 if ( bTableCrsrNeeded ) 599 { 600 SwShellTableCrsr* pTableCrsr = new SwShellTableCrsr( DocView().GetWrtShell(), aStartPos ); 601 pTableCrsr->SetMark(); 602 pTableCrsr->GetMark()->nNode = *pTxtNode; 603 pTableCrsr->GetMark()->nContent.Assign( pTxtNode, *(pTxtAnnotationFld->GetStart())+1 ); 604 pTableCrsr->NewTableSelection(); 605 pTmpCrsr = pTableCrsr; 606 } 607 else 608 { 609 SwShellCrsr* pCrsr = new SwShellCrsr( DocView().GetWrtShell(), aStartPos ); 610 pCrsr->SetMark(); 611 pCrsr->GetMark()->nNode = *pTxtNode; 612 pCrsr->GetMark()->nContent.Assign( pTxtNode, *(pTxtAnnotationFld->GetStart())+1 ); 613 pTmpCrsr = pCrsr; 614 } 615 ::boost::scoped_ptr<SwShellCrsr> pTmpCrsrForAnnotationTextRange( pTmpCrsr ); 616 617 pTmpCrsrForAnnotationTextRange->FillRects(); 618 619 for( sal_uInt16 a(0); a < pTmpCrsrForAnnotationTextRange->Count(); ++a ) 620 { 621 const SwRect aNextRect((*pTmpCrsrForAnnotationTextRange)[a]); 622 const Rectangle aPntRect(aNextRect.SVRect()); 623 624 aAnnotationTextRanges.push_back(basegfx::B2DRange( 625 aPntRect.Left(), aPntRect.Top(), 626 aPntRect.Right() + 1, aPntRect.Bottom() + 1)); 627 } 628 } 629 } 630 631 if ( mpTextRangeOverlay != NULL ) 632 { 633 mpTextRangeOverlay->setRanges( aAnnotationTextRanges ); 634 if ( mpAnchor != NULL && mpAnchor->getLineSolid() ) 635 { 636 mpTextRangeOverlay->ShowSolidBorder(); 637 } 638 else 639 { 640 mpTextRangeOverlay->HideSolidBorder(); 641 } 642 } 643 else 644 { 645 mpTextRangeOverlay = 646 sw::overlay::OverlayRanges::CreateOverlayRange( 647 DocView(), 648 mColorAnchor, 649 aAnnotationTextRanges, 650 mpAnchor != NULL ? mpAnchor->getLineSolid() : false ); 651 } 652 } 653 else 654 { 655 delete mpTextRangeOverlay; 656 mpTextRangeOverlay = NULL; 657 } 658 } 659 660 void SwSidebarWin::DoResize() 661 { 662 long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height(); 663 long aHeight = GetSizePixel().Height(); 664 unsigned long aWidth = GetSizePixel().Width(); 665 666 aHeight -= GetMetaHeight(); 667 mpMetadataAuthor->Show(); 668 mpMetadataDate->Show(); 669 mpSidebarTxtControl->SetQuickHelpText(EMPTYSTRING); 670 671 if ((aTextHeight > aHeight) && !IsPreview()) 672 { // we need vertical scrollbars and have to reduce the width 673 aWidth -= GetScrollbarWidth(); 674 mpVScrollbar->Show(); 675 } 676 else 677 { 678 mpVScrollbar->Hide(); 679 } 680 681 { 682 const Size aSizeOfMetadataControls( GetSizePixel().Width() - GetMetaButtonAreaWidth(), 683 GetMetaHeight()/2 ); 684 mpMetadataAuthor->SetPosSizePixel( 0, 685 aHeight, 686 aSizeOfMetadataControls.Width(), 687 aSizeOfMetadataControls.Height() ); 688 mpMetadataDate->SetPosSizePixel( 0, 689 aHeight + aSizeOfMetadataControls.Height(), 690 aSizeOfMetadataControls.Width(), 691 aSizeOfMetadataControls.Height() ); 692 } 693 694 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ; 695 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) ); 696 if (!mpVScrollbar->IsVisible()) 697 { // if we do not have a scrollbar anymore, we want to see the complete text 698 mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) ); 699 } 700 701 if (!Application::GetSettings().GetLayoutRTL()) 702 { 703 mpSidebarTxtControl->SetPosSizePixel(0, 0, aWidth, aHeight); 704 mpVScrollbar->SetPosSizePixel( aWidth, 0, GetScrollbarWidth(), aHeight); 705 } 706 else 707 { 708 mpSidebarTxtControl->SetPosSizePixel( ( (aTextHeight > aHeight) && !IsPreview() 709 ? GetScrollbarWidth() : 0 ) , 0, 710 aWidth, aHeight); 711 mpVScrollbar->SetPosSizePixel( 0, 0, GetScrollbarWidth(), aHeight); 712 } 713 714 mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() ); 715 mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 ); 716 mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 ); 717 SetScrollbar(); 718 mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight())); 719 720 //calculate rects for meta- button 721 const Fraction& fx( GetMapMode().GetScaleX() ); 722 const Fraction& fy( GetMapMode().GetScaleY() ); 723 724 const Point aPos( mpMetadataAuthor->GetPosPixel()); 725 Rectangle aRectMetaButton; 726 if (IsPreview()) 727 { 728 aRectMetaButton = PixelToLogic( 729 Rectangle( Point( aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH*4+10)*fx.GetNumerator()/fx.GetDenominator(), 730 aPos.Y()+5*fy.GetNumerator()/fy.GetDenominator() ), 731 Size( METABUTTON_WIDTH*4*fx.GetNumerator()/fx.GetDenominator(), 732 METABUTTON_HEIGHT*fy.GetNumerator()/fy.GetDenominator() ) ) ); 733 } 734 else 735 { 736 aRectMetaButton = PixelToLogic( 737 Rectangle( Point( aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10)*fx.GetNumerator()/fx.GetDenominator(), 738 aPos.Y()+5*fy.GetNumerator()/fy.GetDenominator() ), 739 Size( METABUTTON_WIDTH*fx.GetNumerator()/fx.GetDenominator(), 740 METABUTTON_HEIGHT*fy.GetNumerator()/fy.GetDenominator() ) ) ); 741 } 742 743 { 744 const Rectangle aRectMetaButtonPixel( LogicToPixel( aRectMetaButton ) ); 745 mpMenuButton->SetPosSizePixel( aRectMetaButtonPixel.Left(), 746 aRectMetaButtonPixel.Top(), 747 aRectMetaButtonPixel.GetWidth(), 748 aRectMetaButtonPixel.GetHeight() ); 749 } 750 } 751 752 void SwSidebarWin::SetSizePixel( const Size& rNewSize ) 753 { 754 Window::SetSizePixel(rNewSize); 755 756 if (mpShadow) 757 { 758 Point aStart = EditWin()->PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height())); 759 Point aEnd = EditWin()->PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height())); 760 mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y())); 761 } 762 } 763 764 void SwSidebarWin::SetScrollbar() 765 { 766 mpVScrollbar->SetThumbPos( mpOutlinerView->GetVisArea().Top()+ mpOutlinerView->GetEditView().GetCursor()->GetOffsetY()); 767 } 768 769 void SwSidebarWin::ResizeIfNeccessary(long aOldHeight, long aNewHeight) 770 { 771 if (aOldHeight != aNewHeight) 772 { 773 //check for lower border or next note 774 long aBorder = mrMgr.GetNextBorder(); 775 if (aBorder != -1) 776 { 777 if (aNewHeight > GetMinimumSizeWithoutMeta()) 778 { 779 long aNewLowerValue = GetPosPixel().Y() + aNewHeight + GetMetaHeight(); 780 if (aNewLowerValue < aBorder) 781 SetSizePixel(Size(GetSizePixel().Width(),aNewHeight+GetMetaHeight())); 782 else 783 SetSizePixel(Size(GetSizePixel().Width(),aBorder - GetPosPixel().Y())); 784 DoResize(); 785 Invalidate(); 786 } 787 else 788 { 789 if (GetSizePixel().Height() != GetMinimumSizeWithoutMeta() + GetMetaHeight()) 790 SetSizePixel(Size(GetSizePixel().Width(),GetMinimumSizeWithoutMeta() + GetMetaHeight())); 791 DoResize(); 792 Invalidate(); 793 } 794 } 795 else 796 { 797 DoResize(); 798 Invalidate(); 799 } 800 } 801 else 802 { 803 SetScrollbar(); 804 } 805 } 806 807 void SwSidebarWin::SetColor(Color aColorDark,Color aColorLight, Color aColorAnchor) 808 { 809 mColorDark = aColorDark; 810 mColorLight = aColorLight; 811 mColorAnchor = aColorAnchor; 812 813 if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) 814 { 815 { 816 mpMetadataAuthor->SetControlBackground(mColorDark); 817 AllSettings aSettings = mpMetadataAuthor->GetSettings(); 818 StyleSettings aStyleSettings = aSettings.GetStyleSettings(); 819 aStyleSettings.SetFieldTextColor(aColorAnchor); 820 aSettings.SetStyleSettings(aStyleSettings); 821 mpMetadataAuthor->SetSettings(aSettings); 822 } 823 824 { 825 mpMetadataDate->SetControlBackground(mColorDark); 826 AllSettings aSettings = mpMetadataDate->GetSettings(); 827 StyleSettings aStyleSettings = aSettings.GetStyleSettings(); 828 aStyleSettings.SetFieldTextColor(aColorAnchor); 829 aSettings.SetStyleSettings(aStyleSettings); 830 mpMetadataDate->SetSettings(aSettings); 831 } 832 833 AllSettings aSettings2 = mpVScrollbar->GetSettings(); 834 StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings(); 835 aStyleSettings2.SetButtonTextColor(Color(0,0,0)); 836 aStyleSettings2.SetCheckedColor(mColorLight); //hintergund 837 aStyleSettings2.SetShadowColor(mColorAnchor); 838 aStyleSettings2.SetFaceColor(mColorDark); 839 aSettings2.SetStyleSettings(aStyleSettings2); 840 mpVScrollbar->SetSettings(aSettings2); 841 } 842 } 843 844 void SwSidebarWin::SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition) 845 { 846 meSidebarPosition = eSidebarPosition; 847 } 848 849 void SwSidebarWin::SetReadonly(sal_Bool bSet) 850 { 851 mbReadonly = bSet; 852 GetOutlinerView()->SetReadOnly(bSet); 853 } 854 855 void SwSidebarWin::SetLanguage(const SvxLanguageItem aNewItem) 856 { 857 Link pLink = Engine()->GetModifyHdl(); 858 Engine()->SetModifyHdl( Link() ); 859 ESelection aOld = GetOutlinerView()->GetSelection(); 860 861 ESelection aNewSelection( 0, 0, (sal_uInt16)Engine()->GetParagraphCount()-1, USHRT_MAX ); 862 GetOutlinerView()->SetSelection( aNewSelection ); 863 SfxItemSet aEditAttr(GetOutlinerView()->GetAttribs()); 864 aEditAttr.Put(aNewItem); 865 GetOutlinerView()->SetAttribs( aEditAttr ); 866 867 GetOutlinerView()->SetSelection(aOld); 868 Engine()->SetModifyHdl( pLink ); 869 870 const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions(); 871 sal_uLong nCntrl = Engine()->GetControlWord(); 872 // turn off 873 if (!pVOpt->IsOnlineSpell()) 874 nCntrl &= ~EE_CNTRL_ONLINESPELLING; 875 else 876 nCntrl &= ~EE_CNTRL_ONLINESPELLING; 877 Engine()->SetControlWord(nCntrl); 878 879 //turn back on 880 if (pVOpt->IsOnlineSpell()) 881 nCntrl |= EE_CNTRL_ONLINESPELLING; 882 else 883 nCntrl &= ~EE_CNTRL_ONLINESPELLING; 884 Engine()->SetControlWord(nCntrl); 885 886 Engine()->CompleteOnlineSpelling(); 887 Invalidate(); 888 } 889 890 void SwSidebarWin::DataChanged( const DataChangedEvent& aEvent) 891 { 892 Window::DataChanged( aEvent ); 893 } 894 895 void SwSidebarWin::GetFocus() 896 { 897 if (mpSidebarTxtControl) 898 mpSidebarTxtControl->GrabFocus(); 899 } 900 901 void SwSidebarWin::LoseFocus() 902 { 903 } 904 905 void SwSidebarWin::ShowNote() 906 { 907 SetPosAndSize(); 908 if (!IsVisible()) 909 Window::Show(); 910 if (mpShadow && !mpShadow->isVisible()) 911 mpShadow->setVisible(true); 912 if (mpAnchor && !mpAnchor->isVisible()) 913 mpAnchor->setVisible(true); 914 } 915 916 void SwSidebarWin::HideNote() 917 { 918 if (IsVisible()) 919 Window::Hide(); 920 if (mpAnchor) 921 { 922 if (mrMgr.IsShowAnchor()) 923 mpAnchor->SetAnchorState(AS_TRI); 924 else 925 mpAnchor->setVisible(false); 926 } 927 if (mpShadow && mpShadow->isVisible()) 928 mpShadow->setVisible(false); 929 } 930 931 void SwSidebarWin::ActivatePostIt() 932 { 933 mrMgr.AssureStdModeAtShell(); 934 935 mpOutliner->ClearModifyFlag(); 936 mpOutliner->GetUndoManager().Clear(); 937 938 CheckMetaText(); 939 SetViewState(VS_EDIT); 940 GetOutlinerView()->ShowCursor(); 941 942 mpOutlinerView->GetEditView().SetInsertMode(mrView.GetWrtShellPtr()->IsInsMode()); 943 944 if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) 945 GetOutlinerView()->SetBackgroundColor(mColorDark); 946 } 947 948 void SwSidebarWin::DeactivatePostIt() 949 { 950 // remove selection, #i87073# 951 if (GetOutlinerView()->GetEditView().HasSelection()) 952 { 953 ESelection aSelection = GetOutlinerView()->GetEditView().GetSelection(); 954 aSelection.nEndPara = aSelection.nStartPara; 955 aSelection.nEndPos = aSelection.nStartPos; 956 GetOutlinerView()->GetEditView().SetSelection(aSelection); 957 } 958 959 mpOutliner->CompleteOnlineSpelling(); 960 961 SetViewState(VS_NORMAL); 962 // write the visible text back into the SwField 963 UpdateData(); 964 965 if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) 966 GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT); 967 968 969 if ( !IsProtected() && 970 Engine()->GetEditEngine().GetText()==String(EMPTYSTRING) ) 971 { 972 mnEventId = Application::PostUserEvent( LINK( this, SwSidebarWin, DeleteHdl), 0 ); 973 } 974 } 975 976 void SwSidebarWin::ToggleInsMode() 977 { 978 if (!mrView.GetWrtShell().IsRedlineOn()) 979 { 980 //change outliner 981 mpOutlinerView->GetEditView().SetInsertMode(!mpOutlinerView->GetEditView().IsInsertMode()); 982 //change documnet 983 mrView.GetWrtShell().ToggleInsMode(); 984 //update statusbar 985 SfxBindings &rBnd = mrView.GetViewFrame()->GetBindings(); 986 rBnd.Invalidate(SID_ATTR_INSERT); 987 rBnd.Update(SID_ATTR_INSERT); 988 } 989 } 990 991 void SwSidebarWin::ExecuteCommand(sal_uInt16 nSlot) 992 { 993 mrMgr.AssureStdModeAtShell(); 994 995 switch (nSlot) 996 { 997 case FN_POSTIT: 998 case FN_REPLY: 999 { 1000 // if this note is empty, it will be deleted once losing the focus, so no reply, but only a new note 1001 // will be created 1002 if (Engine()->GetEditEngine().GetText() != String(EMPTYSTRING)) 1003 { 1004 OutlinerParaObject* pPara = new OutlinerParaObject(*GetOutlinerView()->GetEditView().CreateTextObject()); 1005 mrMgr.RegisterAnswer(pPara); 1006 } 1007 if (mrMgr.HasActiveSidebarWin()) 1008 mrMgr.SetActiveSidebarWin(0); 1009 SwitchToFieldPos(); 1010 mrView.GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT); 1011 break; 1012 } 1013 case FN_DELETE_COMMENT: 1014 1015 //Delete(); // do not kill the parent of our open popup menu 1016 mnEventId = Application::PostUserEvent( LINK( this, SwSidebarWin, DeleteHdl), 0 ); 1017 break; 1018 case FN_DELETE_ALL_NOTES: 1019 case FN_HIDE_ALL_NOTES: 1020 // not possible as slot as this would require that "this" is the active postit 1021 mrView.GetViewFrame()->GetBindings().Execute( nSlot, 0, 0, SFX_CALLMODE_ASYNCHRON ); 1022 break; 1023 case FN_DELETE_NOTE_AUTHOR: 1024 case FN_HIDE_NOTE_AUTHOR: 1025 { 1026 // not possible as slot as this would require that "this" is the active postit 1027 SfxStringItem aItem( nSlot, GetAuthor() ); 1028 const SfxPoolItem* aItems[2]; 1029 aItems[0] = &aItem; 1030 aItems[1] = 0; 1031 mrView.GetViewFrame()->GetBindings().Execute( nSlot, aItems, 0, SFX_CALLMODE_ASYNCHRON ); 1032 } 1033 default: 1034 mrView.GetViewFrame()->GetBindings().Execute( nSlot ); 1035 break; 1036 } 1037 } 1038 1039 SwEditWin* SwSidebarWin::EditWin() 1040 { 1041 return &mrView.GetEditWin(); 1042 } 1043 1044 long SwSidebarWin::GetPostItTextHeight() 1045 { 1046 return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0; 1047 } 1048 1049 void SwSidebarWin::SwitchToPostIt(sal_uInt16 aDirection) 1050 { 1051 SwSidebarWin* pPostIt = mrMgr.GetNextPostIt(aDirection, this); 1052 if (pPostIt) 1053 pPostIt->GrabFocus(); 1054 } 1055 1056 IMPL_LINK( SwSidebarWin, WindowEventListener, VclSimpleEvent*, pEvent ) 1057 { 1058 VclWindowEvent* pWinEvent = dynamic_cast<VclWindowEvent*>(pEvent); 1059 if ( pWinEvent ) 1060 { 1061 if ( pWinEvent->GetId() == VCLEVENT_WINDOW_MOUSEMOVE ) 1062 { 1063 MouseEvent* pMouseEvt = (MouseEvent*)pWinEvent->GetData(); 1064 if ( pMouseEvt->IsEnterWindow() ) 1065 { 1066 mbMouseOver = true; 1067 if ( !HasFocus() ) 1068 { 1069 SetViewState(VS_VIEW); 1070 Invalidate(); 1071 } 1072 } 1073 else if ( pMouseEvt->IsLeaveWindow()) 1074 { 1075 if (IsPreview()) 1076 { 1077 //doLazyDelete(); 1078 } 1079 else 1080 { 1081 mbMouseOver = false; 1082 if ( !HasFocus() ) 1083 { 1084 SetViewState(VS_NORMAL); 1085 Invalidate(); 1086 } 1087 } 1088 } 1089 } 1090 else if ( pWinEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE && 1091 pWinEvent->GetWindow() == mpSidebarTxtControl ) 1092 { 1093 const sal_Bool bLockView = mrView.GetWrtShell().IsViewLocked(); 1094 mrView.GetWrtShell().LockView( sal_True ); 1095 1096 if ( !IsPreview() ) 1097 { 1098 mrMgr.SetActiveSidebarWin( this ); 1099 } 1100 1101 mrView.GetWrtShell().LockView( bLockView ); 1102 mrMgr.MakeVisible( this ); 1103 } 1104 else if ( pWinEvent->GetWindow() == mpSidebarTxtControl ) 1105 { 1106 int i = 5; 1107 ++i; 1108 } 1109 } 1110 return sal_True; 1111 } 1112 1113 void SwSidebarWin::Delete() 1114 { 1115 if ( mrMgr.GetActiveSidebarWin() == this) 1116 { 1117 mrMgr.SetActiveSidebarWin(0); 1118 // if the note is empty, the previous line will send a delete event, but we are already there 1119 if (mnEventId) 1120 { 1121 Application::RemoveUserEvent( mnEventId ); 1122 mnEventId = 0; 1123 } 1124 } 1125 } 1126 1127 IMPL_LINK(SwSidebarWin, ScrollHdl, ScrollBar*, pScroll) 1128 { 1129 long nDiff = GetOutlinerView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos(); 1130 GetOutlinerView()->Scroll( 0, nDiff ); 1131 return 0; 1132 } 1133 1134 IMPL_LINK(SwSidebarWin, ModifyHdl, void*, pVoid) 1135 { 1136 // no warnings, please 1137 pVoid=0; 1138 mrView.GetDocShell()->SetModified(sal_True); 1139 return 0; 1140 } 1141 1142 IMPL_LINK(SwSidebarWin, DeleteHdl, void*, pVoid) 1143 { 1144 // no warnings, please 1145 pVoid=0; 1146 mnEventId = 0; 1147 Delete(); 1148 return 0; 1149 } 1150 1151 1152 void SwSidebarWin::ResetAttributes() 1153 { 1154 mpOutlinerView->RemoveAttribsKeepLanguages(sal_True); 1155 mpOutliner->RemoveFields(sal_True); 1156 mpOutlinerView->SetAttribs(DefaultItem()); 1157 } 1158 1159 sal_Int32 SwSidebarWin::GetScrollbarWidth() 1160 { 1161 return mrView.GetWrtShell().GetViewOptions()->GetZoom() / 10; 1162 } 1163 1164 sal_Int32 SwSidebarWin::GetMetaButtonAreaWidth() 1165 { 1166 const Fraction& f( GetMapMode().GetScaleX() ); 1167 if (IsPreview()) 1168 return 3 * METABUTTON_AREA_WIDTH * f.GetNumerator() / f.GetDenominator(); 1169 else 1170 return METABUTTON_AREA_WIDTH * f.GetNumerator() / f.GetDenominator(); 1171 } 1172 1173 sal_Int32 SwSidebarWin::GetMetaHeight() 1174 { 1175 const Fraction& f( GetMapMode().GetScaleY() ); 1176 return POSTIT_META_HEIGHT * f.GetNumerator() / f.GetDenominator(); 1177 } 1178 1179 sal_Int32 SwSidebarWin::GetMinimumSizeWithMeta() 1180 { 1181 return mrMgr.GetMinimumSizeWithMeta(); 1182 } 1183 1184 sal_Int32 SwSidebarWin::GetMinimumSizeWithoutMeta() 1185 { 1186 const Fraction& f( GetMapMode().GetScaleY() ); 1187 return POSTIT_MINIMUMSIZE_WITHOUT_META * f.GetNumerator() / f.GetDenominator(); 1188 } 1189 1190 void SwSidebarWin::SetSpellChecking() 1191 { 1192 const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions(); 1193 sal_uLong nCntrl = mpOutliner->GetControlWord(); 1194 if (pVOpt->IsOnlineSpell()) 1195 nCntrl |= EE_CNTRL_ONLINESPELLING; 1196 else 1197 nCntrl &= ~EE_CNTRL_ONLINESPELLING; 1198 mpOutliner->SetControlWord(nCntrl); 1199 1200 mpOutliner->CompleteOnlineSpelling(); 1201 Invalidate(); 1202 } 1203 1204 void SwSidebarWin::SetViewState(ViewState bViewState) 1205 { 1206 switch (bViewState) 1207 { 1208 case VS_EDIT: 1209 { 1210 if (mpAnchor) 1211 { 1212 mpAnchor->SetAnchorState(AS_ALL); 1213 SwSidebarWin* pWin = GetTopReplyNote(); 1214 // --> OD 2010-06-03 #i111964# 1215 if ( pWin && pWin->Anchor() ) 1216 // <-- 1217 { 1218 pWin->Anchor()->SetAnchorState(AS_END); 1219 } 1220 mpAnchor->setLineSolid(true); 1221 if ( mpTextRangeOverlay != NULL ) 1222 { 1223 mpTextRangeOverlay->ShowSolidBorder(); 1224 } 1225 } 1226 if (mpShadow) 1227 mpShadow->SetShadowState(SS_EDIT); 1228 break; 1229 } 1230 case VS_VIEW: 1231 { 1232 if (mpAnchor) 1233 { 1234 mpAnchor->setLineSolid(true); 1235 if ( mpTextRangeOverlay != NULL ) 1236 { 1237 mpTextRangeOverlay->ShowSolidBorder(); 1238 } 1239 } 1240 if (mpShadow) 1241 mpShadow->SetShadowState(SS_VIEW); 1242 break; 1243 } 1244 case VS_NORMAL: 1245 { 1246 if (mpAnchor) 1247 { 1248 if (IsFollow()) 1249 { 1250 // if there is no visible parent note, we want to see the complete anchor ?? 1251 //if (IsAnyStackParentVisible()) 1252 mpAnchor->SetAnchorState(AS_END); 1253 SwSidebarWin* pTopWinSelf = GetTopReplyNote(); 1254 SwSidebarWin* pTopWinActive = mrMgr.HasActiveSidebarWin() 1255 ? mrMgr.GetActiveSidebarWin()->GetTopReplyNote() 1256 : 0; 1257 if ( pTopWinSelf && ( pTopWinSelf != pTopWinActive ) && 1258 pTopWinSelf->Anchor() ) 1259 { 1260 if ( pTopWinSelf != mrMgr.GetActiveSidebarWin() ) 1261 { 1262 pTopWinSelf->Anchor()->setLineSolid(false); 1263 if ( pTopWinSelf->TextRange() != NULL ) 1264 { 1265 pTopWinSelf->TextRange()->HideSolidBorder(); 1266 } 1267 } 1268 pTopWinSelf->Anchor()->SetAnchorState(AS_ALL); 1269 } 1270 } 1271 mpAnchor->setLineSolid(false); 1272 if ( mpTextRangeOverlay != NULL ) 1273 { 1274 mpTextRangeOverlay->HideSolidBorder(); 1275 } 1276 } 1277 if ( mpShadow ) 1278 { 1279 mpShadow->SetShadowState(SS_NORMAL); 1280 } 1281 break; 1282 } 1283 } 1284 } 1285 1286 SwSidebarWin* SwSidebarWin::GetTopReplyNote() 1287 { 1288 SwSidebarWin* pTopNote = 0; 1289 SwSidebarWin* pSidebarWin = IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, this) : 0; 1290 while (pSidebarWin) 1291 { 1292 pTopNote = pSidebarWin; 1293 pSidebarWin = pSidebarWin->IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, pSidebarWin) : 0; 1294 } 1295 return pTopNote; 1296 } 1297 1298 void SwSidebarWin::SwitchToFieldPos() 1299 { 1300 if ( mrMgr.GetActiveSidebarWin() == this ) 1301 mrMgr.SetActiveSidebarWin(0); 1302 GotoPos(); 1303 sal_uInt32 aCount = MoveCaret(); 1304 if (aCount) 1305 mrView.GetDocShell()->GetWrtShell()->SwCrsrShell::Right(aCount, 0, sal_False); 1306 GrabFocusToDocument(); 1307 } 1308 1309 SvxLanguageItem SwSidebarWin::GetLanguage(void) 1310 { 1311 return SvxLanguageItem(SwLangHelper::GetLanguage(mrView.GetWrtShell(),RES_CHRATR_LANGUAGE),RES_CHRATR_LANGUAGE); 1312 } 1313 1314 void SwSidebarWin::SetChangeTracking( const SwPostItHelper::SwLayoutStatus aLayoutStatus, 1315 const Color& aChangeColor ) 1316 { 1317 if ( (mLayoutStatus != aLayoutStatus) || 1318 (mChangeColor != aChangeColor) ) 1319 { 1320 mLayoutStatus = aLayoutStatus; 1321 mChangeColor = aChangeColor; 1322 Invalidate(); 1323 } 1324 } 1325 1326 bool SwSidebarWin::HasScrollbar() const 1327 { 1328 return mpVScrollbar != 0; 1329 } 1330 1331 bool SwSidebarWin::IsScrollbarVisible() const 1332 { 1333 return HasScrollbar() && mpVScrollbar->IsVisible(); 1334 } 1335 1336 void SwSidebarWin::ChangeSidebarItem( SwSidebarItem& rSidebarItem ) 1337 { 1338 const bool bAnchorChanged = mpAnchorFrm != rSidebarItem.maLayoutInfo.mpAnchorFrm; 1339 if ( bAnchorChanged ) 1340 { 1341 mrMgr.DisconnectSidebarWinFromFrm( *(mpAnchorFrm), *this ); 1342 } 1343 1344 mrSidebarItem = rSidebarItem; 1345 mpAnchorFrm = mrSidebarItem.maLayoutInfo.mpAnchorFrm; 1346 1347 if ( GetWindowPeer() ) 1348 { 1349 SidebarWinAccessible* pAcc = 1350 static_cast<SidebarWinAccessible*>( GetWindowPeer() ); 1351 ASSERT( dynamic_cast<SidebarWinAccessible*>( GetWindowPeer() ), 1352 "<SwSidebarWin::ChangeSidebarItem(..)> - unexpected type of window peer -> crash possible!" ); 1353 pAcc->ChangeSidebarItem( mrSidebarItem ); 1354 } 1355 1356 if ( bAnchorChanged ) 1357 { 1358 mrMgr.ConnectSidebarWinToFrm( *(mrSidebarItem.maLayoutInfo.mpAnchorFrm), 1359 mrSidebarItem.GetFmtFld(), 1360 *this ); 1361 } 1362 } 1363 1364 css::uno::Reference< css::accessibility::XAccessible > SwSidebarWin::CreateAccessible() 1365 { 1366 SidebarWinAccessible* pAcc( new SidebarWinAccessible( *this, 1367 mrView.GetWrtShell(), 1368 mrSidebarItem ) ); 1369 css::uno::Reference< css::awt::XWindowPeer > xWinPeer( pAcc ); 1370 SetWindowPeer( xWinPeer, pAcc ); 1371 1372 css::uno::Reference< css::accessibility::XAccessible > xAcc( xWinPeer, css::uno::UNO_QUERY ); 1373 return xAcc; 1374 } 1375 1376 } } // eof of namespace sw::sidebarwindows 1377 1378 /********** SwRedComment**************/ 1379 /* 1380 SwRedComment::SwRedComment( Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits,SwRedline* pRed) 1381 : SwSidebarWin(pParent,nBits,aMgr,aBits), 1382 pRedline(pRed) 1383 { 1384 } 1385 1386 void SwRedComment::SetPopup() 1387 { 1388 mpButtonPopup = new PopupMenu(SW_RES(MN_REDCOMMENT_BUTTON)); 1389 //mpButtonPopup->SetMenuFlags(MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES); 1390 } 1391 1392 void SwRedComment::UpdateData() 1393 { 1394 if ( Engine()->IsModified() ) 1395 { 1396 // so we get a new layout of notes (Anchor position is still the same and we would otherwise not get one) 1397 Mgr()->SetLayout(); 1398 // SetRedline is calling SetModified already 1399 DocView()->GetWrtShell().SetRedlineComment(Engine()->GetEditEngine().GetText()); 1400 } 1401 Engine()->ClearModifyFlag(); 1402 Engine()->GetUndoManager().Clear(); 1403 } 1404 1405 void SwRedComment::SetPostItText() 1406 { 1407 Engine()->SetModifyHdl( Link() ); 1408 Engine()->EnableUndo( sal_False ); 1409 1410 Engine()->Clear(); 1411 View()->SetAttribs(DefaultItem()); 1412 View()->InsertText(pRedline->GetComment(),false); 1413 1414 Engine()->ClearModifyFlag(); 1415 Engine()->GetUndoManager().Clear(); 1416 Engine()->EnableUndo( sal_True ); 1417 Engine()->SetModifyHdl( LINK( this, SwSidebarWin, ModifyHdl ) ); 1418 Invalidate(); 1419 } 1420 1421 void SwRedComment::DeactivatePostIt() 1422 { 1423 SwSidebarWin::DeactivatePostIt(); 1424 // current Redline is still selected 1425 DocView()->GetWrtShellPtr()->ClearMark(); 1426 } 1427 1428 void SwRedComment::ActivatePostIt() 1429 { 1430 SwSidebarWin::ActivatePostIt(); 1431 1432 // do we want the redline selected? 1433 // otherwise, SwRedComment::ActivatePostIt() as well as SwRedComment::DeactivatePostIt() 1434 // can be thrown out completly 1435 DocView()->GetDocShell()->GetWrtShell()->GotoRedline( 1436 DocView()->GetDocShell()->GetWrtShell()->FindRedlineOfData(pRedline->GetRedlineData()),true); 1437 } 1438 1439 void SwRedComment::MouseButtonDown( const MouseEvent& rMEvt ) 1440 { 1441 if (mRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft()) 1442 { 1443 ExecuteCommand( mpButtonPopup->Execute( this,Rectangle(LogicToPixel(mRectMetaButton.BottomLeft()),LogicToPixel(mRectMetaButton.BottomLeft())),POPUPMENU_EXECUTE_DOWN | POPUPMENU_NOMOUSEUPCLOSE) ); 1444 } 1445 } 1446 1447 void SwRedComment::Delete() 1448 { 1449 SwSidebarWin::Delete(); 1450 // we are not neccessarily on our redline, so let's move there 1451 GotoPos(); 1452 DocView()->GetWrtShell().SetRedlineComment(EMPTYSTRING); 1453 DocView()->GetWrtShell().ClearMark(); 1454 // so we get a new layout of notes (Anchor position is still the same and we would otherwise not get one) 1455 Mgr()->SetLayout(); 1456 Mgr()->RemoveItem(pRedline); 1457 } 1458 1459 void SwRedComment::GotoPos() 1460 { 1461 DocView()->GetDocShell()->GetWrtShell()->GotoRedline( 1462 DocView()->GetDocShell()->GetWrtShell()->FindRedlineOfData(pRedline->GetRedlineData())); 1463 } 1464 1465 String SwRedComment::GetAuthor() 1466 { 1467 return pRedline->GetAuthorString(); 1468 } 1469 1470 Date SwRedComment::GetDate() 1471 { 1472 return pRedline->GetTimeStamp().GetDate(); 1473 } 1474 1475 Time SwRedComment::GetTime() 1476 { 1477 return pRedline->GetTimeStamp().GetTime(); 1478 } 1479 1480 bool SwRedComment::IsProtected() 1481 { 1482 return SwSidebarWin::IsProtected() || pRedline->Start()->nNode.GetNode().GetTxtNode()->IsInProtectSect(); 1483 } 1484 */ 1485