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