PageRenderTime 126ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/libreoffice-3.6.0.2/vcl/source/window/toolbox.cxx

#
C++ | 6042 lines | 4738 code | 796 blank | 508 comment | 1275 complexity | 8dc7e982bf22d4305b194966b59a74b2 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, LGPL-3.0
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*************************************************************************
  3. *
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * Copyright 2000, 2010 Oracle and/or its affiliates.
  7. *
  8. * OpenOffice.org - a multi-platform office productivity suite
  9. *
  10. * This file is part of OpenOffice.org.
  11. *
  12. * OpenOffice.org is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License version 3
  14. * only, as published by the Free Software Foundation.
  15. *
  16. * OpenOffice.org is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License version 3 for more details
  20. * (a copy is included in the LICENSE file that accompanied this code).
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * version 3 along with OpenOffice.org. If not, see
  24. * <http://www.openoffice.org/license.html>
  25. * for a copy of the LGPLv3 License.
  26. *
  27. ************************************************************************/
  28. #include <rtl/logfile.hxx>
  29. #include <tools/debug.hxx>
  30. #include <tools/rc.h>
  31. #include <tools/poly.hxx>
  32. #include <vcl/event.hxx>
  33. #include <vcl/decoview.hxx>
  34. #include <vcl/accel.hxx>
  35. #include <vcl/svapp.hxx>
  36. #include <vcl/help.hxx>
  37. #include <vcl/sound.hxx>
  38. #include <vcl/virdev.hxx>
  39. #include <vcl/spin.h>
  40. #include <vcl/toolbox.hxx>
  41. #include <vcl/bitmap.hxx>
  42. #include <vcl/mnemonic.hxx>
  43. #include <vcl/gradient.hxx>
  44. #include <vcl/menu.hxx>
  45. #include <svdata.hxx>
  46. #include <window.h>
  47. #include <toolbox.h>
  48. #include <salframe.hxx>
  49. #if defined WNT
  50. #include <svsys.h>
  51. #endif
  52. #include <string.h>
  53. #include <vector>
  54. #include <math.h>
  55. // =======================================================================
  56. DBG_NAMEEX( Window )
  57. // =======================================================================
  58. #define SMALLBUTTON_HSIZE 7
  59. #define SMALLBUTTON_VSIZE 7
  60. #define SMALLBUTTON_OFF_NORMAL_X 3
  61. #define SMALLBUTTON_OFF_NORMAL_Y 3
  62. #define SMALLBUTTON_OFF_PRESSED_X 5
  63. #define SMALLBUTTON_OFF_PRESSED_Y 5
  64. #define OUTBUTTON_SIZE 6
  65. #define OUTBUTTON_BORDER 4
  66. #define OUTBUTTON_OFF_NORMAL_X 1
  67. #define OUTBUTTON_OFF_NORMAL_Y 1
  68. // -----------------------------------------------------------------------
  69. #define TB_TEXTOFFSET 2
  70. #define TB_IMAGETEXTOFFSET 3
  71. #define TB_LINESPACING 3
  72. #define TB_SPIN_SIZE 14
  73. #define TB_SPIN_OFFSET 2
  74. #define TB_NEXT_SIZE 22
  75. #define TB_NEXT_OFFSET 2
  76. #define TB_BORDER_OFFSET1 4
  77. #define TB_BORDER_OFFSET2 2
  78. #define TB_CUSTOMIZE_OFFSET 2
  79. #define TB_RESIZE_OFFSET 3
  80. #define TB_MAXLINES 5
  81. #define TB_MAXNOSCROLL 32765
  82. #define TB_MIN_WIN_WIDTH 20
  83. #define TB_CALCMODE_HORZ 1
  84. #define TB_CALCMODE_VERT 2
  85. #define TB_CALCMODE_FLOAT 3
  86. #define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
  87. #define DOCK_LINEHSIZE ((sal_uInt16)0x0001)
  88. #define DOCK_LINEVSIZE ((sal_uInt16)0x0002)
  89. #define DOCK_LINERIGHT ((sal_uInt16)0x1000)
  90. #define DOCK_LINEBOTTOM ((sal_uInt16)0x2000)
  91. #define DOCK_LINELEFT ((sal_uInt16)0x4000)
  92. #define DOCK_LINETOP ((sal_uInt16)0x8000)
  93. #define DOCK_LINEOFFSET 3
  94. // -----------------------------------------------------------------------
  95. static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, sal_uInt16 highlight, sal_Bool bChecked, sal_Bool bEnabled, sal_Bool bIsWindow );
  96. // -----------------------------------------------------------------------
  97. struct ImplToolSize
  98. {
  99. long mnWidth;
  100. long mnHeight;
  101. sal_uInt16 mnLines;
  102. };
  103. struct ImplToolSizeArray
  104. {
  105. long mnLength;
  106. long mnLastEntry;
  107. ImplToolSize* mpSize;
  108. ImplToolSizeArray() { mpSize = NULL; mnLength = 0; mnLastEntry = 0; }
  109. ~ImplToolSizeArray() { if( mpSize ) delete [] mpSize; mnLength = 0; }
  110. };
  111. // -----------------------------------------------------------------------
  112. typedef ::std::vector< ToolBox* > ImplTBList;
  113. class ImplTBDragMgr
  114. {
  115. private:
  116. ImplTBList* mpBoxList;
  117. ToolBox* mpDragBox;
  118. Point maMouseOff;
  119. Rectangle maRect;
  120. Rectangle maStartRect;
  121. Accelerator maAccel;
  122. long mnMinWidth;
  123. long mnMaxWidth;
  124. sal_uInt16 mnLineMode;
  125. sal_uInt16 mnStartLines;
  126. void* mpCustomizeData;
  127. sal_Bool mbCustomizeMode;
  128. sal_Bool mbResizeMode;
  129. sal_Bool mbShowDragRect;
  130. public:
  131. ImplTBDragMgr();
  132. ~ImplTBDragMgr();
  133. void push_back( ToolBox* pBox )
  134. { mpBoxList->push_back( pBox ); }
  135. void erase( ToolBox* pBox )
  136. {
  137. for ( ImplTBList::iterator it = mpBoxList->begin(); it != mpBoxList->end(); ++it ) {
  138. if ( *it == pBox ) {
  139. mpBoxList->erase( it );
  140. break;
  141. }
  142. }
  143. }
  144. size_t size() const
  145. { return mpBoxList->size(); }
  146. ToolBox* FindToolBox( const Rectangle& rRect );
  147. void StartDragging( ToolBox* pDragBox,
  148. const Point& rPos, const Rectangle& rRect,
  149. sal_uInt16 nLineMode, sal_Bool bResizeItem,
  150. void* pData = NULL );
  151. void Dragging( const Point& rPos );
  152. void EndDragging( sal_Bool bOK = sal_True );
  153. void HideDragRect() { if ( mbShowDragRect ) mpDragBox->HideTracking(); }
  154. void UpdateDragRect();
  155. DECL_LINK( SelectHdl, Accelerator* );
  156. sal_Bool IsCustomizeMode() { return mbCustomizeMode; }
  157. sal_Bool IsResizeMode() { return mbResizeMode; }
  158. };
  159. // -----------------------------------------------------------------------
  160. static ImplTBDragMgr* ImplGetTBDragMgr()
  161. {
  162. ImplSVData* pSVData = ImplGetSVData();
  163. if ( !pSVData->maCtrlData.mpTBDragMgr )
  164. pSVData->maCtrlData.mpTBDragMgr = new ImplTBDragMgr;
  165. return pSVData->maCtrlData.mpTBDragMgr;
  166. }
  167. // -----------------------------------------------------------------------
  168. int ToolBox::ImplGetDragWidth( ToolBox* pThis )
  169. {
  170. #define TB_DRAGWIDTH 8 // the default width of the grip
  171. int width = TB_DRAGWIDTH;
  172. if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
  173. {
  174. ImplControlValue aControlValue;
  175. Point aPoint;
  176. Rectangle aContent, aBound;
  177. Rectangle aArea( aPoint, pThis->GetOutputSizePixel() );
  178. if ( pThis->GetNativeControlRegion(CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
  179. aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
  180. {
  181. width = pThis->mbHorz ? aContent.GetWidth() : aContent.GetHeight();
  182. }
  183. }
  184. return width;
  185. }
  186. ButtonType determineButtonType( ImplToolItem* pItem, ButtonType defaultType )
  187. {
  188. ButtonType tmpButtonType = defaultType;
  189. ToolBoxItemBits nBits( pItem->mnBits & 0x300 );
  190. if ( nBits & TIB_TEXTICON ) // item has custom setting
  191. {
  192. tmpButtonType = BUTTON_SYMBOLTEXT;
  193. if ( nBits == TIB_TEXT_ONLY )
  194. tmpButtonType = BUTTON_TEXT;
  195. else if ( nBits == TIB_ICON_ONLY )
  196. tmpButtonType = BUTTON_SYMBOL;
  197. }
  198. return tmpButtonType;
  199. }
  200. // -----------------------------------------------------------------------
  201. void ToolBox::ImplUpdateDragArea( ToolBox *pThis )
  202. {
  203. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  204. if( pWrapper )
  205. {
  206. if ( pThis->ImplIsFloatingMode() || pWrapper->IsLocked() )
  207. pWrapper->SetDragArea( Rectangle() );
  208. else
  209. {
  210. if( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
  211. pWrapper->SetDragArea( Rectangle( 0, 0, ImplGetDragWidth( pThis ), pThis->GetOutputSizePixel().Height() ) );
  212. else
  213. pWrapper->SetDragArea( Rectangle( 0, 0, pThis->GetOutputSizePixel().Width(), ImplGetDragWidth( pThis ) ) );
  214. }
  215. }
  216. }
  217. // -----------------------------------------------------------------------
  218. void ToolBox::ImplCalcBorder( WindowAlign eAlign, long& rLeft, long& rTop,
  219. long& rRight, long& rBottom, const ToolBox *pThis )
  220. {
  221. if( pThis->ImplIsFloatingMode() || !(pThis->mnWinStyle & WB_BORDER) )
  222. {
  223. // no border in floating mode
  224. rLeft = rTop = rRight = rBottom = 0;
  225. return;
  226. }
  227. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  228. // reserve dragarea only for dockable toolbars
  229. int dragwidth = ( pWrapper && !pWrapper->IsLocked() ) ? ImplGetDragWidth( (ToolBox*)pThis ) : 0;
  230. // no shadow border for dockable toolbars
  231. int borderwidth = pWrapper ? 0: 2;
  232. if ( eAlign == WINDOWALIGN_TOP )
  233. {
  234. rLeft = borderwidth+dragwidth;
  235. rTop = borderwidth;
  236. rRight = borderwidth;
  237. rBottom = 0;
  238. }
  239. else if ( eAlign == WINDOWALIGN_LEFT )
  240. {
  241. rLeft = borderwidth;
  242. rTop = borderwidth+dragwidth;
  243. rRight = 0;
  244. rBottom = borderwidth;
  245. }
  246. else if ( eAlign == WINDOWALIGN_BOTTOM )
  247. {
  248. rLeft = borderwidth+dragwidth;
  249. rTop = 0;
  250. rRight = borderwidth;
  251. rBottom = borderwidth;
  252. }
  253. else
  254. {
  255. rLeft = 0;
  256. rTop = borderwidth+dragwidth;
  257. rRight = borderwidth;
  258. rBottom = borderwidth;
  259. }
  260. }
  261. // -----------------------------------------------------------------------
  262. static void ImplCheckUpdate( ToolBox *pThis )
  263. {
  264. // remove any pending invalidates to avoid
  265. // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
  266. // which would result in erasing the background only and not painting any items
  267. // this must not be done when we're already in Paint()
  268. // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
  269. if( !pThis->IsBackground() && pThis->HasPaintEvent() && !pThis->IsInPaint() )
  270. pThis->Update();
  271. }
  272. // -----------------------------------------------------------------------
  273. void ToolBox::ImplDrawGrip( ToolBox* pThis )
  274. {
  275. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  276. if( pWrapper && !pWrapper->GetDragArea().IsEmpty() )
  277. {
  278. // execute pending paint requests
  279. ImplCheckUpdate( pThis );
  280. sal_Bool bNativeOk = sal_False;
  281. if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_HORZ : PART_THUMB_VERT ) )
  282. {
  283. ToolbarValue aToolbarValue;
  284. aToolbarValue.maGripRect = pWrapper->GetDragArea();
  285. Point aPt;
  286. Rectangle aCtrlRegion( aPt, pThis->GetOutputSizePixel() );
  287. ControlState nState = CTRL_STATE_ENABLED;
  288. bNativeOk = pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
  289. aCtrlRegion, nState, aToolbarValue, rtl::OUString() );
  290. }
  291. if( bNativeOk )
  292. return;
  293. const StyleSettings& rStyleSettings = pThis->GetSettings().GetStyleSettings();
  294. pThis->SetLineColor( rStyleSettings.GetShadowColor() );
  295. Size aSz ( pThis->GetOutputSizePixel() );
  296. if ( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
  297. {
  298. int height = (int) (0.6 * aSz.Height() + 0.5);
  299. int i = (aSz.Height() - height) / 2;
  300. height += i;
  301. while( i <= height )
  302. {
  303. int x = ImplGetDragWidth( pThis ) / 2;
  304. pThis->DrawPixel( Point(x, i), rStyleSettings.GetDarkShadowColor() );
  305. pThis->DrawPixel( Point(x+1, i), rStyleSettings.GetShadowColor() );
  306. pThis->DrawPixel( Point(x, i+1), rStyleSettings.GetShadowColor() );
  307. pThis->DrawPixel( Point(x+1, i+1), rStyleSettings.GetFaceColor() );
  308. pThis->DrawPixel( Point(x+2, i+1), Color(COL_WHITE) );
  309. pThis->DrawPixel( Point(x+1, i+2), Color(COL_WHITE) );
  310. pThis->DrawPixel( Point(x+2, i+2), Color(COL_WHITE) );
  311. i+=4;
  312. }
  313. }
  314. else
  315. {
  316. int width = (int) (0.6 * aSz.Width() + 0.5);
  317. int i = (aSz.Width() - width) / 2;
  318. width += i;
  319. while( i <= width )
  320. {
  321. int y = ImplGetDragWidth(pThis) / 2;
  322. pThis->DrawPixel( Point(i, y), rStyleSettings.GetDarkShadowColor() );
  323. pThis->DrawPixel( Point(i+1, y), rStyleSettings.GetShadowColor() );
  324. pThis->DrawPixel( Point(i, y+1), rStyleSettings.GetShadowColor() );
  325. pThis->DrawPixel( Point(i+1, y+1), rStyleSettings.GetFaceColor() );
  326. pThis->DrawPixel( Point(i+2, y+1), Color(COL_WHITE) );
  327. pThis->DrawPixel( Point(i+1, y+2), Color(COL_WHITE) );
  328. pThis->DrawPixel( Point(i+2, y+2), Color(COL_WHITE) );
  329. i+=4;
  330. }
  331. }
  332. }
  333. }
  334. void ToolBox::ImplDrawGradientBackground( ToolBox* pThis, ImplDockingWindowWrapper * )
  335. {
  336. // draw a nice gradient
  337. Color startCol, endCol;
  338. startCol = pThis->GetSettings().GetStyleSettings().GetFaceGradientColor();
  339. endCol = pThis->GetSettings().GetStyleSettings().GetFaceColor();
  340. if( pThis->GetSettings().GetStyleSettings().GetHighContrastMode() )
  341. // no 'extreme' gradient when high contrast
  342. startCol = endCol;
  343. Gradient g;
  344. g.SetAngle( pThis->mbHorz ? 0 : 900 );
  345. g.SetStyle( GradientStyle_LINEAR );
  346. g.SetStartColor( startCol );
  347. g.SetEndColor( endCol );
  348. sal_Bool bLineColor = pThis->IsLineColor();
  349. Color aOldCol = pThis->GetLineColor();
  350. pThis->SetLineColor( pThis->GetSettings().GetStyleSettings().GetShadowColor() );
  351. Size aFullSz( pThis->GetOutputSizePixel() );
  352. Size aLineSz( aFullSz );
  353. // use the linesize only when floating
  354. // full window height is used when docked (single line)
  355. if( pThis->ImplIsFloatingMode() )
  356. {
  357. long nLineSize;
  358. if( pThis->mbHorz )
  359. {
  360. nLineSize = pThis->mnMaxItemHeight;
  361. if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
  362. nLineSize = pThis->mnWinHeight;
  363. aLineSz.Height() = nLineSize;
  364. }
  365. else
  366. {
  367. nLineSize = pThis->mnMaxItemWidth;
  368. aLineSz.Width() = nLineSize;
  369. }
  370. }
  371. long nLeft, nTop, nRight, nBottom;
  372. ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
  373. Size aTopLineSz( aLineSz );
  374. Size aBottomLineSz( aLineSz );
  375. if ( pThis->mnWinStyle & WB_BORDER )
  376. {
  377. if( pThis->mbHorz )
  378. {
  379. aTopLineSz.Height() += TB_BORDER_OFFSET2 + nTop;
  380. aBottomLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
  381. if( pThis->mnCurLines == 1 )
  382. aTopLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
  383. }
  384. else
  385. {
  386. aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
  387. aBottomLineSz.Width() += TB_BORDER_OFFSET1 + nRight;
  388. if( pThis->mnCurLines == 1 )
  389. aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
  390. }
  391. }
  392. if( pThis->mbHorz )
  393. {
  394. aTopLineSz.Height() += pThis->mnBorderY;
  395. if( pThis->mnCurLines == 1 )
  396. aTopLineSz.Height() += pThis->mnBorderY;
  397. aBottomLineSz.Height() += pThis->mnBorderY;
  398. }
  399. else
  400. {
  401. aTopLineSz.Width() += pThis->mnBorderX;
  402. if( pThis->mnCurLines == 1 )
  403. aTopLineSz.Width() += pThis->mnBorderX;
  404. aBottomLineSz.Width() += pThis->mnBorderX;
  405. }
  406. if ( pThis->mnWinStyle & WB_LINESPACING )
  407. {
  408. if( pThis->mbHorz )
  409. {
  410. aLineSz.Height() += TB_LINESPACING;
  411. if( pThis->mnCurLines > 1 )
  412. aTopLineSz.Height() += TB_LINESPACING;
  413. }
  414. else
  415. {
  416. aLineSz.Width() += TB_LINESPACING;
  417. if( pThis->mnCurLines > 1 )
  418. aTopLineSz.Width() += TB_LINESPACING;
  419. }
  420. }
  421. if( pThis->mbHorz )
  422. {
  423. long y = 0;
  424. sal_Bool bDrawSep = sal_False; // pThis->ImplIsFloatingMode() && ( pThis->mnWinStyle & WB_LINESPACING );
  425. pThis->DrawGradient( Rectangle( 0, y, aTopLineSz.Width(), y+aTopLineSz.Height()), g );
  426. y += aTopLineSz.Height();
  427. if ( bDrawSep )
  428. pThis->DrawLine( Point(0, y-2), Point(aTopLineSz.Width(), y-2) );
  429. while( y < (pThis->mnDY - aBottomLineSz.Height()) )
  430. {
  431. pThis->DrawGradient( Rectangle( 0, y, aLineSz.Width(), y+aLineSz.Height()), g);
  432. y += aLineSz.Height();
  433. if ( bDrawSep )
  434. pThis->DrawLine( Point(0, y-2), Point(aLineSz.Width(), y-2) );
  435. }
  436. pThis->DrawGradient( Rectangle( 0, y, aBottomLineSz.Width(), y+aBottomLineSz.Height()), g );
  437. if ( bDrawSep )
  438. pThis->DrawLine( Point(0, y-2), Point(aBottomLineSz.Width(), y-2) );
  439. }
  440. else
  441. {
  442. long x = 0;
  443. pThis->DrawGradient( Rectangle( x, 0, x+aTopLineSz.Width(), aTopLineSz.Height()), g );
  444. x += aTopLineSz.Width();
  445. while( x < (pThis->mnDX - aBottomLineSz.Width()) )
  446. {
  447. pThis->DrawGradient( Rectangle( x, 0, x+aLineSz.Width(), aLineSz.Height()), g);
  448. x += aLineSz.Width();
  449. }
  450. pThis->DrawGradient( Rectangle( x, 0, x+aBottomLineSz.Width(), aBottomLineSz.Height()), g );
  451. }
  452. if( bLineColor )
  453. pThis->SetLineColor( aOldCol );
  454. }
  455. sal_Bool ToolBox::ImplDrawNativeBackground( ToolBox* pThis, const Region & )
  456. {
  457. // use NWF
  458. Point aPt;
  459. Rectangle aCtrlRegion( aPt, pThis->GetOutputSizePixel() );
  460. ControlState nState = CTRL_STATE_ENABLED;
  461. return pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
  462. aCtrlRegion, nState, ImplControlValue(), rtl::OUString() );
  463. }
  464. void ToolBox::ImplDrawTransparentBackground( ToolBox* pThis, const Region &rRegion )
  465. {
  466. // just invalidate to trigger paint of the parent
  467. const bool bOldPaintLock = pThis->mpData->mbIsPaintLocked;
  468. pThis->mpData->mbIsPaintLocked = true;
  469. // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
  470. pThis->Invalidate( rRegion, INVALIDATE_UPDATE|INVALIDATE_NOCLIPCHILDREN );
  471. pThis->mpData->mbIsPaintLocked = bOldPaintLock;
  472. }
  473. void ToolBox::ImplDrawConstantBackground( ToolBox* pThis, const Region &rRegion, sal_Bool bIsInPopupMode )
  474. {
  475. // draw a constant color
  476. if( !bIsInPopupMode )
  477. // default background
  478. pThis->Erase( rRegion.GetBoundRect() );
  479. else
  480. {
  481. // use different color in popupmode
  482. pThis->DrawWallpaper( rRegion.GetBoundRect(),
  483. Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() ) );
  484. }
  485. }
  486. void ToolBox::ImplDrawBackground( ToolBox* pThis, const Rectangle &rRect )
  487. {
  488. // execute pending paint requests
  489. ImplCheckUpdate( pThis );
  490. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  491. sal_Bool bIsInPopupMode = pThis->ImplIsInPopupMode();
  492. Region aPaintRegion( rRect );
  493. // make sure we do not invalidate/erase too much
  494. if( pThis->IsInPaint() )
  495. aPaintRegion.Intersect( pThis->GetActiveClipRegion() );
  496. pThis->Push( PUSH_CLIPREGION );
  497. pThis->IntersectClipRegion( aPaintRegion );
  498. if( !pWrapper /*|| bIsInPopupMode*/ )
  499. {
  500. // no gradient for ordinary toolbars (not dockable)
  501. if( !pThis->IsBackground() && !pThis->IsInPaint() )
  502. ImplDrawTransparentBackground( pThis, aPaintRegion );
  503. else
  504. ImplDrawConstantBackground( pThis, aPaintRegion, bIsInPopupMode );
  505. }
  506. else
  507. {
  508. // toolbars known to the dockingmanager will be drawn using NWF or a gradient
  509. // docked toolbars are transparent and NWF is already used in the docking area which is their common background
  510. // so NWF is used here for floating toolbars only
  511. sal_Bool bNativeOk = sal_False;
  512. if( pThis->ImplIsFloatingMode() && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL) )
  513. bNativeOk = ImplDrawNativeBackground( pThis, aPaintRegion );
  514. if( !bNativeOk )
  515. {
  516. if( !pThis->IsBackground() )
  517. {
  518. if( !pThis->IsInPaint() )
  519. ImplDrawTransparentBackground( pThis, aPaintRegion );
  520. }
  521. else
  522. ImplDrawGradientBackground( pThis, pWrapper );
  523. }
  524. }
  525. // restore clip region
  526. pThis->Pop();
  527. }
  528. void ToolBox::ImplErase( ToolBox* pThis, const Rectangle &rRect, sal_Bool bHighlight, sal_Bool bHasOpenPopup )
  529. {
  530. // the background of non NWF buttons is painted in a constant color
  531. // to have the same highlight color (transparency in DrawSelectionBackground())
  532. // items with open popups will also painted using a constant color
  533. if( !pThis->mpData->mbNativeButtons &&
  534. (bHighlight || ! (((Window*) pThis)->GetStyle() & WB_3DLOOK ) ) )
  535. {
  536. if( (((Window*) pThis)->GetStyle() & WB_3DLOOK ) )
  537. {
  538. pThis->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
  539. pThis->SetLineColor();
  540. if( bHasOpenPopup )
  541. // choose the same color as the popup will use
  542. pThis->SetFillColor( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() );
  543. else
  544. pThis->SetFillColor( Color( COL_WHITE ) );
  545. pThis->DrawRect( rRect );
  546. pThis->Pop();
  547. }
  548. else
  549. ImplDrawBackground( pThis, rRect );
  550. }
  551. else
  552. ImplDrawBackground( pThis, rRect );
  553. }
  554. void ToolBox::ImplDrawBorder( ToolBox* pWin )
  555. {
  556. const StyleSettings& rStyleSettings = pWin->GetSettings().GetStyleSettings();
  557. long nDX = pWin->mnDX;
  558. long nDY = pWin->mnDY;
  559. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pWin );
  560. // draw borders for ordinary toolbars only (not dockable)
  561. if( pWrapper )
  562. return;
  563. if ( pWin->meAlign == WINDOWALIGN_BOTTOM )
  564. {
  565. // draw bottom border
  566. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  567. pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
  568. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  569. pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
  570. }
  571. else
  572. {
  573. // draw top border
  574. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  575. pWin->DrawLine( Point( 0, 0 ), Point( nDX-1, 0 ) );
  576. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  577. pWin->DrawLine( Point( 0, 1 ), Point( nDX-1, 1 ) );
  578. if ( (pWin->meAlign == WINDOWALIGN_LEFT) || (pWin->meAlign == WINDOWALIGN_RIGHT) )
  579. {
  580. if ( pWin->meAlign == WINDOWALIGN_LEFT )
  581. {
  582. // draw left-bottom border
  583. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  584. pWin->DrawLine( Point( 0, 0 ), Point( 0, nDY-1 ) );
  585. pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
  586. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  587. pWin->DrawLine( Point( 1, 1 ), Point( 1, nDY-3 ) );
  588. pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
  589. }
  590. else
  591. {
  592. // draw right-bottom border
  593. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  594. pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-3 ) );
  595. pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-2, nDY-2 ) );
  596. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  597. pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
  598. pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
  599. }
  600. }
  601. }
  602. if ( pWin->meAlign == WINDOWALIGN_BOTTOM || pWin->meAlign == WINDOWALIGN_TOP )
  603. {
  604. // draw right border
  605. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  606. pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-1 ) );
  607. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  608. pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
  609. }
  610. }
  611. // -----------------------------------------------------------------------
  612. static bool ImplIsFixedControl( const ImplToolItem *pItem )
  613. {
  614. return ( pItem->mpWindow &&
  615. (pItem->mpWindow->GetType() == WINDOW_FIXEDTEXT ||
  616. pItem->mpWindow->GetType() == WINDOW_FIXEDLINE ||
  617. pItem->mpWindow->GetType() == WINDOW_GROUPBOX) );
  618. }
  619. // -----------------------------------------------------------------------
  620. const ImplToolItem *ToolBox::ImplGetFirstClippedItem( const ToolBox* pThis )
  621. {
  622. std::vector< ImplToolItem >::const_iterator it;
  623. it = pThis->mpData->m_aItems.begin();
  624. while ( it != pThis->mpData->m_aItems.end() )
  625. {
  626. if( it->IsClipped() )
  627. return &(*it);
  628. ++it;
  629. }
  630. return NULL;
  631. }
  632. // -----------------------------------------------------------------------
  633. Size ToolBox::ImplCalcSize( const ToolBox* pThis, sal_uInt16 nCalcLines, sal_uInt16 nCalcMode )
  634. {
  635. long nMax;
  636. long nLeft = 0;
  637. long nTop = 0;
  638. long nRight = 0;
  639. long nBottom = 0;
  640. Size aSize;
  641. WindowAlign eOldAlign = pThis->meAlign;
  642. sal_Bool bOldHorz = pThis->mbHorz;
  643. sal_Bool bOldAssumeDocked = pThis->mpData->mbAssumeDocked;
  644. sal_Bool bOldAssumeFloating = pThis->mpData->mbAssumeFloating;
  645. if ( nCalcMode )
  646. {
  647. sal_Bool bOldFloatingMode = pThis->ImplIsFloatingMode();
  648. pThis->mpData->mbAssumeDocked = sal_False;
  649. pThis->mpData->mbAssumeFloating = sal_False;
  650. if ( nCalcMode == TB_CALCMODE_HORZ )
  651. {
  652. pThis->mpData->mbAssumeDocked = sal_True; // force non-floating mode during calculation
  653. ImplCalcBorder( WINDOWALIGN_TOP, nLeft, nTop, nRight, nBottom, pThis );
  654. ((ToolBox*)pThis)->mbHorz = sal_True;
  655. if ( pThis->mbHorz != bOldHorz )
  656. ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
  657. }
  658. else if ( nCalcMode == TB_CALCMODE_VERT )
  659. {
  660. pThis->mpData->mbAssumeDocked = sal_True; // force non-floating mode during calculation
  661. ImplCalcBorder( WINDOWALIGN_LEFT, nLeft, nTop, nRight, nBottom, pThis );
  662. ((ToolBox*)pThis)->mbHorz = sal_False;
  663. if ( pThis->mbHorz != bOldHorz )
  664. ((ToolBox*)pThis)->meAlign = WINDOWALIGN_LEFT;
  665. }
  666. else if ( nCalcMode == TB_CALCMODE_FLOAT )
  667. {
  668. pThis->mpData->mbAssumeFloating = sal_True; // force non-floating mode during calculation
  669. nLeft = nTop = nRight = nBottom = 0;
  670. ((ToolBox*)pThis)->mbHorz = sal_True;
  671. if ( pThis->mbHorz != bOldHorz )
  672. ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
  673. }
  674. if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) ||
  675. (pThis->ImplIsFloatingMode() != bOldFloatingMode ) )
  676. ((ToolBox*)pThis)->mbCalc = sal_True;
  677. }
  678. else
  679. ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
  680. ((ToolBox*)pThis)->ImplCalcItem();
  681. if( !nCalcMode && pThis->ImplIsFloatingMode() )
  682. {
  683. aSize = ImplCalcFloatSize( ((ToolBox*)pThis), nCalcLines );
  684. }
  685. else
  686. {
  687. if ( pThis->mbHorz )
  688. {
  689. if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
  690. aSize.Height() = nCalcLines * pThis->mnWinHeight;
  691. else
  692. aSize.Height() = nCalcLines * pThis->mnMaxItemHeight;
  693. if ( pThis->mnWinStyle & WB_LINESPACING )
  694. aSize.Height() += (nCalcLines-1)*TB_LINESPACING;
  695. if ( pThis->mnWinStyle & WB_BORDER )
  696. aSize.Height() += (TB_BORDER_OFFSET2*2) + nTop + nBottom;
  697. nMax = 0;
  698. ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
  699. if ( nMax )
  700. aSize.Width() += nMax;
  701. if ( pThis->mnWinStyle & WB_BORDER )
  702. aSize.Width() += (TB_BORDER_OFFSET1*2) + nLeft + nRight;
  703. }
  704. else
  705. {
  706. aSize.Width() = nCalcLines * pThis->mnMaxItemWidth;
  707. if ( pThis->mnWinStyle & WB_LINESPACING )
  708. aSize.Width() += (nCalcLines-1)*TB_LINESPACING;
  709. if ( pThis->mnWinStyle & WB_BORDER )
  710. aSize.Width() += (TB_BORDER_OFFSET2*2) + nLeft + nRight;
  711. nMax = 0;
  712. ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
  713. if ( nMax )
  714. aSize.Height() += nMax;
  715. if ( pThis->mnWinStyle & WB_BORDER )
  716. aSize.Height() += (TB_BORDER_OFFSET1*2) + nTop + nBottom;
  717. }
  718. }
  719. // restore previous values
  720. if ( nCalcMode )
  721. {
  722. pThis->mpData->mbAssumeDocked = bOldAssumeDocked;
  723. pThis->mpData->mbAssumeFloating = bOldAssumeFloating;
  724. if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) )
  725. {
  726. ((ToolBox*)pThis)->meAlign = eOldAlign;
  727. ((ToolBox*)pThis)->mbHorz = bOldHorz;
  728. ((ToolBox*)pThis)->mbCalc = sal_True;
  729. }
  730. }
  731. if ( aSize.Width() )
  732. aSize.Width() += pThis->mnBorderX*2;
  733. if ( aSize.Height() )
  734. aSize.Height() += pThis->mnBorderY*2;
  735. return aSize;
  736. }
  737. // -----------------------------------------------------------------------
  738. void ToolBox::ImplCalcFloatSizes( ToolBox* pThis )
  739. {
  740. if ( pThis->mpFloatSizeAry )
  741. return;
  742. // calculate the minimal size, i.e. where the biggest item just fits
  743. long nCalcSize = 0;
  744. std::vector< ImplToolItem >::const_iterator it;
  745. it = pThis->mpData->m_aItems.begin();
  746. while ( it != pThis->mpData->m_aItems.end() )
  747. {
  748. if ( it->mbVisible )
  749. {
  750. if ( it->mpWindow )
  751. {
  752. long nTempSize = it->mpWindow->GetSizePixel().Width();
  753. if ( nTempSize > nCalcSize )
  754. nCalcSize = nTempSize;
  755. }
  756. else
  757. {
  758. if( it->maItemSize.Width() > nCalcSize )
  759. nCalcSize = it->maItemSize.Width();
  760. }
  761. }
  762. ++it;
  763. }
  764. // calc an upper bound for ImplCalcBreaks below
  765. long upperBoundWidth = nCalcSize * pThis->mpData->m_aItems.size();
  766. sal_uInt16 i;
  767. sal_uInt16 nLines;
  768. sal_uInt16 nCalcLines;
  769. sal_uInt16 nTempLines;
  770. long nHeight;
  771. long nMaxLineWidth;
  772. nCalcLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, sal_True );
  773. pThis->mpFloatSizeAry = new ImplToolSizeArray;
  774. pThis->mpFloatSizeAry->mpSize = new ImplToolSize[nCalcLines];
  775. pThis->mpFloatSizeAry->mnLength = nCalcLines;
  776. memset( pThis->mpFloatSizeAry->mpSize, 0, sizeof( ImplToolSize )*nCalcLines );
  777. i = 0;
  778. nTempLines = nLines = nCalcLines;
  779. while ( nLines )
  780. {
  781. nHeight = ImplCalcSize( pThis, nTempLines, TB_CALCMODE_FLOAT ).Height();
  782. pThis->mpFloatSizeAry->mnLastEntry = i;
  783. pThis->mpFloatSizeAry->mpSize[i].mnHeight = nHeight;
  784. pThis->mpFloatSizeAry->mpSize[i].mnLines = nTempLines;
  785. pThis->mpFloatSizeAry->mpSize[i].mnWidth = nMaxLineWidth+(TB_BORDER_OFFSET1*2);
  786. nLines--;
  787. if ( nLines )
  788. {
  789. do
  790. {
  791. nCalcSize += pThis->mnMaxItemWidth;
  792. nTempLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, sal_True );
  793. }
  794. while ( (nCalcSize < upperBoundWidth) && (nLines < nTempLines) && (nTempLines != 1) );
  795. if ( nTempLines < nLines )
  796. nLines = nTempLines;
  797. }
  798. i++;
  799. }
  800. }
  801. // -----------------------------------------------------------------------
  802. Size ToolBox::ImplCalcFloatSize( ToolBox* pThis, sal_uInt16& rLines )
  803. {
  804. ImplCalcFloatSizes( pThis );
  805. if ( !rLines )
  806. {
  807. rLines = pThis->mnFloatLines;
  808. if ( !rLines )
  809. rLines = pThis->mnLines;
  810. }
  811. sal_uInt16 i = 0;
  812. while ( i < pThis->mpFloatSizeAry->mnLastEntry &&
  813. rLines < pThis->mpFloatSizeAry->mpSize[i].mnLines )
  814. i++;
  815. Size aSize( pThis->mpFloatSizeAry->mpSize[i].mnWidth,
  816. pThis->mpFloatSizeAry->mpSize[i].mnHeight );
  817. rLines = pThis->mpFloatSizeAry->mpSize[i].mnLines;
  818. if ( pThis->maNextToolBoxStr.Len() && pThis->mbScroll )
  819. aSize.Width() += TB_NEXT_SIZE-TB_NEXT_OFFSET;
  820. return aSize;
  821. }
  822. // -----------------------------------------------------------------------
  823. void ToolBox::ImplCalcMinMaxFloatSize( ToolBox* pThis, Size& rMinSize, Size& rMaxSize )
  824. {
  825. ImplCalcFloatSizes( pThis );
  826. sal_uInt16 i = 0;
  827. rMinSize = Size( pThis->mpFloatSizeAry->mpSize[i].mnWidth, pThis->mpFloatSizeAry->mpSize[i].mnHeight );
  828. rMaxSize = Size( pThis->mpFloatSizeAry->mpSize[i].mnWidth, pThis->mpFloatSizeAry->mpSize[i].mnHeight );
  829. while ( ++i <= pThis->mpFloatSizeAry->mnLastEntry )
  830. {
  831. if( pThis->mpFloatSizeAry->mpSize[i].mnWidth < rMinSize.Width() )
  832. rMinSize.Width() = pThis->mpFloatSizeAry->mpSize[i].mnWidth;
  833. if( pThis->mpFloatSizeAry->mpSize[i].mnHeight < rMinSize.Height() )
  834. rMinSize.Height() = pThis->mpFloatSizeAry->mpSize[i].mnHeight;
  835. if( pThis->mpFloatSizeAry->mpSize[i].mnWidth > rMaxSize.Width() )
  836. rMaxSize.Width() = pThis->mpFloatSizeAry->mpSize[i].mnWidth;
  837. if( pThis->mpFloatSizeAry->mpSize[i].mnHeight > rMaxSize.Height() )
  838. rMaxSize.Height() = pThis->mpFloatSizeAry->mpSize[i].mnHeight;
  839. }
  840. }
  841. void ToolBox::ImplSetMinMaxFloatSize( ToolBox *pThis )
  842. {
  843. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  844. Size aMinSize, aMaxSize;
  845. ImplCalcMinMaxFloatSize( pThis, aMinSize, aMaxSize );
  846. if( pWrapper )
  847. {
  848. pWrapper->SetMinOutputSizePixel( aMinSize );
  849. pWrapper->SetMaxOutputSizePixel( aMaxSize );
  850. pWrapper->ShowTitleButton( TITLE_BUTTON_MENU, ( pThis->GetMenuType() & TOOLBOX_MENUTYPE_CUSTOMIZE) ? sal_True : sal_False );
  851. }
  852. else
  853. {
  854. // TODO: change SetMinOutputSizePixel to be not inline
  855. pThis->SetMinOutputSizePixel( aMinSize );
  856. pThis->SetMaxOutputSizePixel( aMaxSize );
  857. }
  858. }
  859. // -----------------------------------------------------------------------
  860. sal_uInt16 ToolBox::ImplCalcLines( ToolBox* pThis, long nToolSize )
  861. {
  862. long nLineHeight;
  863. if ( pThis->mbHorz )
  864. {
  865. if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
  866. nLineHeight = pThis->mnWinHeight;
  867. else
  868. nLineHeight = pThis->mnMaxItemHeight;
  869. }
  870. else
  871. nLineHeight = pThis->mnMaxItemWidth;
  872. if ( pThis->mnWinStyle & WB_BORDER )
  873. nToolSize -= TB_BORDER_OFFSET2*2;
  874. if ( pThis->mnWinStyle & WB_LINESPACING )
  875. {
  876. nLineHeight += TB_LINESPACING;
  877. nToolSize += TB_LINESPACING;
  878. }
  879. // #i91917# always report at least one line
  880. long nLines = nToolSize/nLineHeight;
  881. if( nLines < 1 )
  882. nLines = 1;
  883. return static_cast<sal_uInt16>(nLines);
  884. }
  885. // -----------------------------------------------------------------------
  886. sal_uInt16 ToolBox::ImplTestLineSize( ToolBox* pThis, const Point& rPos )
  887. {
  888. if ( !pThis->ImplIsFloatingMode() &&
  889. (!pThis->mbScroll || (pThis->mnLines > 1) || (pThis->mnCurLines > pThis->mnVisLines)) )
  890. {
  891. WindowAlign eAlign = pThis->GetAlign();
  892. if ( eAlign == WINDOWALIGN_LEFT )
  893. {
  894. if ( rPos.X() > pThis->mnDX-DOCK_LINEOFFSET )
  895. return DOCK_LINEHSIZE | DOCK_LINERIGHT;
  896. }
  897. else if ( eAlign == WINDOWALIGN_TOP )
  898. {
  899. if ( rPos.Y() > pThis->mnDY-DOCK_LINEOFFSET )
  900. return DOCK_LINEVSIZE | DOCK_LINEBOTTOM;
  901. }
  902. else if ( eAlign == WINDOWALIGN_RIGHT )
  903. {
  904. if ( rPos.X() < DOCK_LINEOFFSET )
  905. return DOCK_LINEHSIZE | DOCK_LINELEFT;
  906. }
  907. else if ( eAlign == WINDOWALIGN_BOTTOM )
  908. {
  909. if ( rPos.Y() < DOCK_LINEOFFSET )
  910. return DOCK_LINEVSIZE | DOCK_LINETOP;
  911. }
  912. }
  913. return 0;
  914. }
  915. // -----------------------------------------------------------------------
  916. void ToolBox::ImplLineSizing( ToolBox* pThis, const Point& rPos, Rectangle& rRect,
  917. sal_uInt16 nLineMode )
  918. {
  919. sal_Bool mbHorz;
  920. long nOneLineSize;
  921. long nCurSize;
  922. long nMaxSize;
  923. long nSize;
  924. Size aSize;
  925. if ( nLineMode & DOCK_LINERIGHT )
  926. {
  927. nCurSize = rPos.X() - rRect.Left();
  928. mbHorz = sal_False;
  929. }
  930. else if ( nLineMode & DOCK_LINEBOTTOM )
  931. {
  932. nCurSize = rPos.Y() - rRect.Top();
  933. mbHorz = sal_True;
  934. }
  935. else if ( nLineMode & DOCK_LINELEFT )
  936. {
  937. nCurSize = rRect.Right() - rPos.X();
  938. mbHorz = sal_False;
  939. }
  940. else if ( nLineMode & DOCK_LINETOP )
  941. {
  942. nCurSize = rRect.Bottom() - rPos.Y();
  943. mbHorz = sal_True;
  944. }
  945. else {
  946. OSL_FAIL( "ImplLineSizing: Trailing else" );
  947. nCurSize = 0;
  948. mbHorz = sal_False;
  949. }
  950. Size aWinSize = pThis->GetSizePixel();
  951. sal_uInt16 nMaxLines = (pThis->mnLines > pThis->mnCurLines) ? pThis->mnLines : pThis->mnCurLines;
  952. if ( nMaxLines > TB_MAXLINES )
  953. nMaxLines = TB_MAXLINES;
  954. if ( mbHorz )
  955. {
  956. nOneLineSize = ImplCalcSize( pThis, 1 ).Height();
  957. nMaxSize = pThis->maOutDockRect.GetHeight() - 20;
  958. if ( nMaxSize < aWinSize.Height() )
  959. nMaxSize = aWinSize.Height();
  960. }
  961. else
  962. {
  963. nOneLineSize = ImplCalcSize( pThis, 1 ).Width();
  964. nMaxSize = pThis->maOutDockRect.GetWidth() - 20;
  965. if ( nMaxSize < aWinSize.Width() )
  966. nMaxSize = aWinSize.Width();
  967. }
  968. sal_uInt16 i = 1;
  969. if ( nCurSize <= nOneLineSize )
  970. nSize = nOneLineSize;
  971. else
  972. {
  973. nSize = 0;
  974. while ( (nSize < nCurSize) && (i < nMaxLines) )
  975. {
  976. i++;
  977. aSize = ImplCalcSize( pThis, i );
  978. if ( mbHorz )
  979. nSize = aSize.Height();
  980. else
  981. nSize = aSize.Width();
  982. if ( nSize > nMaxSize )
  983. {
  984. i--;
  985. aSize = ImplCalcSize( pThis, i );
  986. if ( mbHorz )
  987. nSize = aSize.Height();
  988. else
  989. nSize = aSize.Width();
  990. break;
  991. }
  992. }
  993. }
  994. if ( nLineMode & DOCK_LINERIGHT )
  995. rRect.Right() = rRect.Left()+nSize-1;
  996. else if ( nLineMode & DOCK_LINEBOTTOM )
  997. rRect.Bottom() = rRect.Top()+nSize-1;
  998. else if ( nLineMode & DOCK_LINELEFT )
  999. rRect.Left() = rRect.Right()-nSize;
  1000. else
  1001. rRect.Top() = rRect.Bottom()-nSize;
  1002. pThis->mnDockLines = i;
  1003. }
  1004. // -----------------------------------------------------------------------
  1005. sal_uInt16 ToolBox::ImplFindItemPos( ToolBox* pBox, const Point& rPos )
  1006. {
  1007. sal_uInt16 nPos = 0;
  1008. long nLast = 0;
  1009. Point aPos = rPos;
  1010. Size aSize( pBox->mnDX, pBox->mnDY );
  1011. if ( aPos.X() > aSize.Width()-TB_BORDER_OFFSET1 )
  1012. aPos.X() = aSize.Width()-TB_BORDER_OFFSET1;
  1013. if ( aPos.Y() > aSize.Height()-TB_BORDER_OFFSET1 )
  1014. aPos.Y() = aSize.Height()-TB_BORDER_OFFSET1;
  1015. // Item suchen, das geklickt wurde
  1016. std::vector< ImplToolItem >::const_iterator it = pBox->mpData->m_aItems.begin();
  1017. while ( it != pBox->mpData->m_aItems.end() )
  1018. {
  1019. if ( it->mbVisible )
  1020. {
  1021. if ( nLast || !it->maRect.IsEmpty() )
  1022. {
  1023. if ( pBox->mbHorz )
  1024. {
  1025. if ( nLast &&
  1026. ((nLast < it->maRect.Top()) || it->maRect.IsEmpty()) )
  1027. return nPos;
  1028. if ( aPos.Y() <= it->maRect.Bottom() )
  1029. {
  1030. if ( aPos.X() < it->maRect.Left() )
  1031. return nPos;
  1032. else if ( aPos.X() < it->maRect.Right() )
  1033. return nPos+1;
  1034. else if ( !nLast )
  1035. nLast = it->maRect.Bottom();
  1036. }
  1037. }
  1038. else
  1039. {
  1040. if ( nLast &&
  1041. ((nLast < it->maRect.Left()) || it->maRect.IsEmpty()) )
  1042. return nPos;
  1043. if ( aPos.X() <= it->maRect.Right() )
  1044. {
  1045. if ( aPos.Y() < it->maRect.Top() )
  1046. return nPos;
  1047. else if ( aPos.Y() < it->maRect.Bottom() )
  1048. return nPos+1;
  1049. else if ( !nLast )
  1050. nLast = it->maRect.Right();
  1051. }
  1052. }
  1053. }
  1054. }
  1055. nPos++;
  1056. ++it;
  1057. }
  1058. return nPos;
  1059. }
  1060. // -----------------------------------------------------------------------
  1061. ImplTBDragMgr::ImplTBDragMgr()
  1062. {
  1063. mpBoxList = new ImplTBList();
  1064. mnLineMode = 0;
  1065. mnStartLines = 0;
  1066. mbCustomizeMode = sal_False;
  1067. mbResizeMode = sal_False;
  1068. mbShowDragRect = sal_False;
  1069. mpDragBox = NULL;
  1070. maAccel.InsertItem( KEY_RETURN, KeyCode( KEY_RETURN ) );
  1071. maAccel.InsertItem( KEY_ESCAPE, KeyCode( KEY_ESCAPE ) );
  1072. maAccel.SetSelectHdl( LINK( this, ImplTBDragMgr, SelectHdl ) );
  1073. }
  1074. // -----------------------------------------------------------------------
  1075. ImplTBDragMgr::~ImplTBDragMgr()
  1076. {
  1077. delete mpBoxList;
  1078. }
  1079. // -----------------------------------------------------------------------
  1080. ToolBox* ImplTBDragMgr::FindToolBox( const Rectangle& rRect )
  1081. {
  1082. for ( size_t i = 0, n = mpBoxList->size(); i < n; ++i )
  1083. {
  1084. ToolBox* pBox = (*mpBoxList)[ i ];
  1085. /*
  1086. * FIXME: since we can have multiple frames now we cannot
  1087. * find the drag target by its position alone.
  1088. * As long as the toolbar config dialogue is not a system window
  1089. * this works in one frame only anyway. If the dialogue
  1090. * changes to a system window, we need a new implementation here
  1091. */
  1092. if ( pBox->IsReallyVisible()
  1093. && pBox->ImplGetWindowImpl()->mpFrame == mpDragBox->ImplGetWindowImpl()->mpFrame
  1094. ) {
  1095. if ( !pBox->ImplIsFloatingMode() )
  1096. {
  1097. Point aPos = pBox->GetPosPixel();
  1098. aPos = pBox->GetParent()->OutputToScreenPixel( aPos );
  1099. Rectangle aTempRect( aPos, pBox->GetSizePixel() );
  1100. if ( aTempRect.IsOver( rRect ) )
  1101. return pBox;
  1102. }
  1103. }
  1104. }
  1105. return NULL;
  1106. }
  1107. // -----------------------------------------------------------------------
  1108. void ImplTBDragMgr::StartDragging( ToolBox* pToolBox,
  1109. const Point& rPos, const Rectangle& rRect,
  1110. sal_uInt16 nDragLineMode, sal_Bool bResizeItem,
  1111. void* pData )
  1112. {
  1113. mpDragBox = pToolBox;
  1114. pToolBox->CaptureMouse();
  1115. pToolBox->mbDragging = sal_True;
  1116. Application::InsertAccel( &maAccel );
  1117. if ( nDragLineMode )
  1118. {
  1119. mnLineMode = nDragLineMode;
  1120. mnStartLines = pToolBox->mnDockLines;
  1121. }
  1122. else
  1123. {
  1124. mpCustomizeData = pData;
  1125. mbResizeMode = bResizeItem;
  1126. pToolBox->Activate();
  1127. pToolBox->mnCurItemId = pToolBox->mnConfigItem;
  1128. pToolBox->Highlight();
  1129. pToolBox->mnCurItemId = 0;
  1130. if ( mbResizeMode )
  1131. {
  1132. if ( rRect.GetWidth() < TB_MIN_WIN_WIDTH )
  1133. mnMinWidth = rRect.GetWidth();
  1134. else
  1135. mnMinWidth = TB_MIN_WIN_WIDTH;
  1136. mnMaxWidth = pToolBox->GetSizePixel().Width()-rRect.Left()-
  1137. TB_SPIN_SIZE-TB_BORDER_OFFSET1-(TB_SPIN_OFFSET*2);
  1138. }
  1139. }
  1140. // MouseOffset berechnen
  1141. maMouseOff.X() = rRect.Left() - rPos.X();
  1142. maMouseOff.Y() = rRect.Top() - rPos.Y();
  1143. maRect = rRect;
  1144. maStartRect = rRect;
  1145. mbShowDragRect = sal_True;
  1146. pToolBox->ShowTracking( maRect );
  1147. }
  1148. // -----------------------------------------------------------------------
  1149. void ImplTBDragMgr::Dragging( const Point& rPos )
  1150. {
  1151. if ( mnLineMode )
  1152. {
  1153. ToolBox::ImplLineSizing( mpDragBox, rPos, maRect, mnLineMode );
  1154. Point aOff = mpDragBox->OutputToScreenPixel( Point() );
  1155. maRect.Move( aOff.X(), aOff.Y() );
  1156. mpDragBox->Docking( rPos, maRect );
  1157. maRect.Move( -aOff.X(), -aOff.Y() );
  1158. mpDragBox->ShowTracking( maRect );
  1159. }
  1160. else
  1161. {
  1162. if ( mbResizeMode )
  1163. {
  1164. long nXOff = rPos.X()-maStartRect.Left();
  1165. nXOff += maMouseOff.X()+(maStartRect.Right()-maStartRect.Left());
  1166. if ( nXOff < mnMinWidth )
  1167. nXOff = mnMinWidth;
  1168. if ( nXOff > mnMaxWidth )
  1169. nXOff = mnMaxWidth;
  1170. maRect.Right() = maStartRect.Left()+nXOff;
  1171. }
  1172. else
  1173. {
  1174. maRect.SetPos( rPos );
  1175. maRect.Move( maMouseOff.X(), maMouseOff.Y() );
  1176. }
  1177. mpDragBox->ShowTracking( maRect );
  1178. }
  1179. }
  1180. // -----------------------------------------------------------------------
  1181. void ImplTBDragMgr::EndDragging( sal_Bool bOK )
  1182. {
  1183. mpDragBox->HideTracking();
  1184. mpDragBox->ReleaseMouse();
  1185. mpDragBox->mbDragging = sal_False;
  1186. mbShowDragRect = sal_False;
  1187. Application::RemoveAccel( &maAccel );
  1188. if ( mnLineMode )
  1189. {
  1190. if ( !bOK )
  1191. {
  1192. mpDragBox->mnDockLines = mnStartLines;
  1193. mpDragBox->EndDocking( maStartRect, sal_False );
  1194. }
  1195. else
  1196. mpDragBox->EndDocking( maRect, sal_False );
  1197. mnLineMode = 0;
  1198. mnStartLines = 0;
  1199. }
  1200. else
  1201. {
  1202. sal_uInt16 nTempItem = mpDragBox->mnConfigItem;
  1203. if ( nTempItem )
  1204. {
  1205. mpDragBox->mnConfigItem = 0;
  1206. if ( !mbResizeMode )
  1207. mpDragBox->Invalidate( mpDragBox->GetItemRect( nTempItem ) );
  1208. }
  1209. if ( bOK && (maRect != maStartRect) )
  1210. {
  1211. if ( mbResizeMode )
  1212. {
  1213. ImplToolItem* pItem = mpDragBox->ImplGetItem( nTempItem );
  1214. Size aSize = pItem->mpWindow->GetSizePixel();
  1215. aSize.Width() = maRect.GetWidth();
  1216. pItem->mpWindow->SetSizePixel( aSize );
  1217. // re-calculate and show ToolBox
  1218. mpDragBox->ImplInvalidate( sal_True );
  1219. mpDragBox->Customize( ToolBoxCustomizeEvent( mpDragBox, nTempItem,
  1220. TOOLBOX_CUSTOMIZE_RESIZE,
  1221. mpCustomizeData ) );
  1222. }
  1223. else
  1224. {
  1225. Point aOff = mpDragBox->OutputToScreenPixel( Point() );
  1226. Rectangle aScreenRect( maRect );
  1227. aScreenRect.Move( aOff.X(), aOff.Y() );
  1228. ToolBox* pDropBox = FindToolBox( aScreenRect );
  1229. if ( pDropBox )
  1230. {
  1231. // Determine search position
  1232. Point aPos;
  1233. if ( pDropBox->mbHorz )
  1234. {
  1235. aPos.X() = aScreenRect.Left()-TB_CUSTOMIZE_OFFSET;
  1236. aPos.Y() = aScreenRect.Center().Y();
  1237. }
  1238. else
  1239. {
  1240. aPos.X() = aScreenRect.Center().X();
  1241. aPos.Y() = aScreenRect.Top()-TB_CUSTOMIZE_OFFSET;
  1242. }
  1243. aPos = pDropBox->ScreenToOutputPixel( aPos );
  1244. sal_uInt16 nPos = ToolBox::ImplFindItemPos( pDropBox, aPos );
  1245. mpDragBox->Customize( ToolBoxCustomizeEvent( pDropBox, nTempItem,
  1246. nPos, mpCustomizeData ) );
  1247. }
  1248. else
  1249. {
  1250. mpDragBox->Customize( ToolBoxCustomizeEvent( NULL, nTempItem,
  1251. 0, mpCustomizeData ) );
  1252. }
  1253. }
  1254. }
  1255. mpCustomizeData = NULL;
  1256. mbResizeMode = sal_False;
  1257. mpDragBox->Deactivate();
  1258. }
  1259. mpDragBox = NULL;
  1260. }
  1261. // -----------------------------------------------------------------------
  1262. void ImplTBDragMgr::UpdateDragRect()
  1263. {
  1264. // Only update if we're already dragging
  1265. if ( !mbShowDragRect )
  1266. return;
  1267. mpDragBox->ShowTracking( maRect );
  1268. }
  1269. // -----------------------------------------------------------------------
  1270. IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator*, pAccel )
  1271. {
  1272. if ( pAccel->GetCurItemId() == KEY_ESCAPE )
  1273. EndDragging( sal_False );
  1274. else
  1275. EndDragging( sal_True );
  1276. return sal_True;
  1277. }
  1278. // -----------------------------------------------------------------------
  1279. static void ImplDrawOutButton( OutputDevice* pOutDev, const Rectangle& rRect,
  1280. sal_uInt16 nStyle )
  1281. {
  1282. const StyleSettings& rStyleSettings = pOutDev->GetSettings().GetStyleSettings();
  1283. Color aShadowColor = rStyleSettings.GetShadowColor();
  1284. Point aPos( rRect.TopLeft() );
  1285. Size aSize( rRect.GetSize() );
  1286. long nOffset = 0;
  1287. if ( pOutDev->GetBackground().GetColor() == aShadowColor )
  1288. aShadowColor = rStyleSettings.GetDarkShadowColor();
  1289. if ( nStyle & BUTTON_DRAW_PRESSED )
  1290. {
  1291. aPos.X()++;
  1292. aPos.Y()++;
  1293. nOffset++;
  1294. }
  1295. // delete background
  1296. pOutDev->Erase( rRect );
  1297. // draw button
  1298. pOutDev->SetLineColor( rStyleSettings.GetLightColor() );
  1299. pOutDev->DrawLine( aPos,
  1300. Point( aPos.X()+aSize.Width()-OUTBUTTON_BORDER, aPos.Y() ) );
  1301. pOutDev->DrawLine( aPos,
  1302. Point( aPos.X(), aPos.Y()+aSize.Height()-OUTBUTTON_BORDER ) );
  1303. pOutDev->SetLineColor( aShadowColor );
  1304. pOutDev->DrawLine( Point( aPos.X()+aSize.Width()-OUTBUTTON_BORDER, aPos.Y() ),
  1305. Point( aPos.X()+aSize.Width()-OUTBUTTON_BORDER, aPos.Y()+aSize.Height()-OUTBUTTON_BORDER ) );
  1306. pOutDev->DrawLine( Point( aPos.X(), aPos.Y()+aSize.Height()-OUTBUTTON_BORDER ),
  1307. Point( aPos.X()+aSize.Width()-OUTBUTTON_BORDER, aPos.Y()+aSize.Height()-OUTBUTTON_BORDER ) );
  1308. for ( long i = 0; i < OUTBUTTON_BORDER-1-nOffset; i++ )
  1309. {
  1310. pOutDev->DrawLine( Point( aPos.X()+aSize.Width()-(OUTBUTTON_BORDER-i-1), aPos.Y()+OUTBUTTON_BORDER ),
  1311. Point( aPos.X()+aSize.Width()-(OUTBUTTON_BORDER-i-1), aPos.Y()+aSize.Height()-1 ) );
  1312. pOutDev->DrawLine( Point( aPos.X()+OUTBUTTON_BORDER, aPos.Y()+aSize.Height()-(OUTBUTTON_BORDER-i-1) ),
  1313. Point( aPos.X()+aSize.Width()-1, aPos.Y()+aSize.Height()-(OUTBUTTON_BORDER-i-1) ) );
  1314. }
  1315. }
  1316. // -----------------------------------------------------------------------
  1317. void ToolBox::ImplInit( Window* pParent, WinBits nStyle )
  1318. {
  1319. // initialize variables
  1320. ImplGetWindowImpl()->mbToolBox = sal_True;
  1321. mpBtnDev = NULL;
  1322. mpFloatSizeAry = NULL;
  1323. mpData = new ImplToolBoxPrivateData;
  1324. mpFloatWin = NULL;
  1325. mnDX = 0;
  1326. mnDY = 0;
  1327. mnMaxItemWidth = 0;
  1328. mnMaxItemHeight = 0;
  1329. mnWinHeight = 0;
  1330. mnBorderX = 0;
  1331. mnBorderY = 0;
  1332. mnLeftBorder = 0;
  1333. mnTopBorder = 0;
  1334. mnRightBorder = 0;
  1335. mnBottomBorder = 0;
  1336. mnLastResizeDY = 0;
  1337. mnOutStyle = TOOLBOX_STYLE_FLAT; // force flat buttons since NWF
  1338. mnHighItemId = 0;
  1339. mnCurItemId = 0;
  1340. mnDownItemId = 0;
  1341. mnCurPos = TOOLBOX_ITEM_NOTFOUND;
  1342. mnFocusPos = TOOLBOX_ITEM_NOTFOUND; // current position during keyboard access
  1343. mnLines = 1;
  1344. mnCurLine = 1;
  1345. mnCurLines = 1;
  1346. mnVisLines = 1;
  1347. mnFloatLines = 0;
  1348. mnConfigItem = 0;
  1349. mnMouseClicks = 0;
  1350. mnMouseModifier = 0;
  1351. mbDrag = sal_False;
  1352. mbSelection = sal_False;
  1353. mbCommandDrag = sal_False;
  1354. mbUpper = sal_False;
  1355. mbLower = sal_False;
  1356. mbNextTool = sal_False;
  1357. mbIn = sal_False;
  1358. mbCalc = sal_True;
  1359. mbFormat = sal_False;
  1360. mbFullPaint = sal_False;
  1361. mbHorz = sal_True;
  1362. mbScroll = (nStyle & WB_SCROLL) != 0;
  1363. mbCustomize = sal_False;
  1364. mbCustomizeMode = sal_False;
  1365. mbDragging = sal_False;
  1366. mbMenuStrings = sal_False;
  1367. mbIsShift = sal_False;
  1368. mbIsKeyEvent = sal_False;
  1369. mbChangingHighlight = sal_False;
  1370. meButtonType = BUTTON_SYMBOL;
  1371. meAlign = WINDOWALIGN_TOP;
  1372. meLastStyle = POINTER_ARROW;
  1373. mnWinStyle = nStyle;
  1374. meLayoutMode = TBX_LAYOUT_NORMAL;
  1375. mnLastFocusItemId = 0;
  1376. mnKeyModifier = 0;
  1377. mnActivateCount = 0;
  1378. maTimer.SetTimeout( 50 );
  1379. maTimer.SetTimeoutHdl( LINK( this, ToolBox, ImplUpdateHdl ) );
  1380. // set timeout and handler for dropdown items
  1381. mpData->maDropdownTimer.SetTimeout( 250 );
  1382. mpData->maDropdownTimer.SetTimeoutHdl( LINK( this, ToolBox, ImplDropdownLongClickHdl ) );
  1383. DockingWindow::ImplInit( pParent, nStyle & ~(WB_BORDER) );
  1384. // always set WB_TABSTOP for ToolBars !!! if( mnWinStyle & WB_TABSTOP )
  1385. {
  1386. // dockingwindow's ImplInit removes some bits, so restore them here
  1387. // to allow keyboard handling for toolbars
  1388. ImplGetWindowImpl()->mnStyle |= WB_TABSTOP|WB_NODIALOGCONTROL;
  1389. ImplGetWindowImpl()->mnStyle &= ~WB_DIALOGCONTROL;
  1390. }
  1391. ImplInitSettings( sal_True, sal_True, sal_True );
  1392. }
  1393. // -----------------------------------------------------------------------
  1394. void ToolBox::ImplInitSettings( sal_Bool bFont,
  1395. sal_Bool bForeground, sal_Bool bBackground )
  1396. {
  1397. mpData->mbNativeButtons = IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON );
  1398. const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
  1399. if ( bFont )
  1400. {
  1401. Font aFont = rStyleSettings.GetToolFont();
  1402. if ( IsControlFont() )
  1403. aFont.Merge( GetControlFont() );
  1404. SetZoomedPointFont( aFont );
  1405. }
  1406. if ( bForeground || bFont )
  1407. {
  1408. Color aColor;
  1409. if ( IsControlForeground() )
  1410. aColor = GetControlForeground();
  1411. else if ( Window::GetStyle() & WB_3DLOOK )
  1412. aColor = rStyleSettings.GetButtonTextColor();
  1413. else
  1414. aColor = rStyleSettings.GetWindowTextColor();
  1415. SetTextColor( aColor );
  1416. SetTextFillColor();
  1417. }
  1418. if ( bBackground )
  1419. {
  1420. Color aColor;
  1421. if ( IsControlBackground() )
  1422. {
  1423. aColor = GetControlBackground();
  1424. SetBackground( aColor );
  1425. SetPaintTransparent( sal_False );
  1426. SetParentClipMode( 0 );
  1427. }
  1428. else
  1429. {
  1430. if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
  1431. {
  1432. SetBackground();
  1433. SetPaintTransparent( sal_True );
  1434. SetParentClipMode( PARENTCLIPMODE_NOCLIP );
  1435. mpData->maDisplayBackground = Wallpaper( rStyleSettings.GetFaceColor() );
  1436. }
  1437. else
  1438. {
  1439. if ( Window::GetStyle() & WB_3DLOOK )
  1440. aColor = rStyleSettings.GetFaceColor();
  1441. else
  1442. aColor = rStyleSettings.GetWindowColor();
  1443. SetBackground( aColor );
  1444. SetPaintTransparent( sal_False );
  1445. SetParentClipMode( 0 );
  1446. ImplUpdateImageList();
  1447. }
  1448. }
  1449. }
  1450. }
  1451. // -----------------------------------------------------------------------
  1452. void ToolBox::ImplLoadRes( const ResId& rResId )
  1453. {
  1454. ResMgr* pMgr = rResId.GetResMgr();
  1455. if( ! pMgr )
  1456. return;
  1457. DockingWindow::ImplLoadRes( rResId );
  1458. sal_uLong nObjMask;
  1459. nObjMask = ReadLongRes();
  1460. if ( nObjMask & RSC_TOOLBOX_BUTTONTYPE )
  1461. SetButtonType( (ButtonType)ReadLongRes() );
  1462. if ( nObjMask & RSC_TOOLBOX_ALIGN )
  1463. SetAlign( (WindowAlign)ReadLongRes() );
  1464. if ( nObjMask & RSC_TOOLBOX_LINECOUNT )
  1465. SetLineCount( sal::static_int_cast<sal_uInt16>(ReadLongRes()) );
  1466. if ( nObjMask & RSC_TOOLBOX_CUSTOMIZE )
  1467. {
  1468. sal_Bool bCust = (sal_Bool)ReadShortRes();
  1469. EnableCustomize( bCust );
  1470. }
  1471. if ( nObjMask & RSC_TOOLBOX_MENUSTRINGS )
  1472. {
  1473. sal_Bool bCust = (sal_Bool)ReadShortRes();
  1474. EnableMenuStrings( bCust );
  1475. }
  1476. if ( nObjMask & RSC_TOOLBOX_FLOATLINES )
  1477. SetFloatingLines( ReadShortRes() );
  1478. if ( nObjMask & RSC_TOOLBOX_ITEMIMAGELIST )
  1479. {
  1480. maImageList = ImageList( ResId( (RSHEADER_TYPE*)GetClassRes(), *pMgr ) );
  1481. IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
  1482. }
  1483. if ( nObjMask & RSC_TOOLBOX_ITEMLIST )
  1484. {
  1485. sal_uLong nEle = ReadLongRes();
  1486. // insert item
  1487. for ( sal_uLong i = 0; i < nEle; i++ )
  1488. {
  1489. InsertItem( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) );
  1490. IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
  1491. }
  1492. }
  1493. }
  1494. // -----------------------------------------------------------------------
  1495. ToolBox::ToolBox( Window* pParent, WinBits nStyle ) :
  1496. DockingWindow( WINDOW_TOOLBOX )
  1497. {
  1498. ImplInit( pParent, nStyle );
  1499. }
  1500. // -----------------------------------------------------------------------
  1501. ToolBox::ToolBox( Window* pParent, const ResId& rResId ) :
  1502. DockingWindow( WINDOW_TOOLBOX )
  1503. {
  1504. RTL_LOGFILE_CONTEXT( aLog, "vcl: ToolBox::ToolBox( Window* pParent, const ResId& rResId )" );
  1505. rResId.SetRT( RSC_TOOLBOX );
  1506. WinBits nStyle = ImplInitRes( rResId );
  1507. ImplInit( pParent, nStyle );
  1508. ImplLoadRes( rResId );
  1509. // calculate size of floating windows and switch if the
  1510. // toolbox is initially in floating mode
  1511. if ( ImplIsFloatingMode() )
  1512. mbHorz = sal_True;
  1513. else
  1514. Resize();
  1515. if ( !(nStyle & WB_HIDE) )
  1516. Show();
  1517. }
  1518. // -----------------------------------------------------------------------
  1519. ToolBox::~ToolBox()
  1520. {
  1521. // custom menu event still running?
  1522. if( mpData->mnEventId )
  1523. Application::RemoveUserEvent( mpData->mnEventId );
  1524. // #103005# make sure our activate/deactivate balance is right
  1525. while( mnActivateCount > 0 )
  1526. Deactivate();
  1527. // terminate popupmode if the floating window is
  1528. // still connected
  1529. if ( mpFloatWin )
  1530. mpFloatWin->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
  1531. // delete private data
  1532. delete mpData;
  1533. // delete FloatSizeAry if required
  1534. delete mpFloatSizeAry;
  1535. // remove the lists when there are no more toolbox references to
  1536. // the lists
  1537. ImplSVData* pSVData = ImplGetSVData();
  1538. if ( pSVData->maCtrlData.mpTBDragMgr )
  1539. {
  1540. // remove if in TBDrag-Manager
  1541. if ( mbCustomize )
  1542. pSVData->maCtrlData.mpTBDragMgr->erase( this );
  1543. if ( !pSVData->maCtrlData.mpTBDragMgr->size() )
  1544. {
  1545. delete pSVData->maCtrlData.mpTBDragMgr;
  1546. pSVData->maCtrlData.mpTBDragMgr = NULL;
  1547. }
  1548. }
  1549. }
  1550. // -----------------------------------------------------------------------
  1551. ImplToolItem* ToolBox::ImplGetItem( sal_uInt16 nItemId ) const
  1552. {
  1553. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
  1554. while ( it != mpData->m_aItems.end() )
  1555. {
  1556. if ( it->mnId == nItemId )
  1557. return &(*it);
  1558. ++it;
  1559. }
  1560. return NULL;
  1561. }
  1562. // -----------------------------------------------------------------------
  1563. static void ImplAddButtonBorder( long &rWidth, long& rHeight, sal_uInt16 aOutStyle, sal_Bool bNativeButtons )
  1564. {
  1565. if ( aOutStyle & TOOLBOX_STYLE_OUTBUTTON )
  1566. {
  1567. rWidth += OUTBUTTON_SIZE;
  1568. rHeight += OUTBUTTON_SIZE;
  1569. }
  1570. else
  1571. {
  1572. rWidth += SMALLBUTTON_HSIZE;
  1573. rHeight += SMALLBUTTON_VSIZE;
  1574. }
  1575. if( bNativeButtons )
  1576. {
  1577. // give more border space for rounded buttons
  1578. rWidth += 2;
  1579. rHeight += 4;
  1580. }
  1581. }
  1582. // -----------------------------------------------------------------------
  1583. sal_Bool ToolBox::ImplCalcItem()
  1584. {
  1585. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  1586. // recalc required ?
  1587. if ( !mbCalc )
  1588. return sal_False;
  1589. ImplDisableFlatButtons();
  1590. long nDefWidth;
  1591. long nDefHeight;
  1592. long nMaxWidth = 0;
  1593. long nMaxHeight = 0;
  1594. long nMinWidth = 6;
  1595. long nMinHeight = 6;
  1596. long nDropDownArrowWidth = TB_DROPDOWNARROWWIDTH;
  1597. // set defaults if image or text is needed but empty
  1598. nDefWidth = GetDefaultImageSize().Width();
  1599. nDefHeight = GetDefaultImageSize().Height();
  1600. mnWinHeight = 0;
  1601. // determine minimum size necessary in NWF
  1602. {
  1603. Rectangle aRect( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
  1604. Rectangle aReg( aRect );
  1605. ImplControlValue aVal;
  1606. Rectangle aNativeBounds, aNativeContent;
  1607. if( IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
  1608. {
  1609. if( GetNativeControlRegion( CTRL_TOOLBAR, PART_BUTTON,
  1610. aReg,
  1611. CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
  1612. aVal, OUString(),
  1613. aNativeBounds, aNativeContent ) )
  1614. {
  1615. aRect = aNativeBounds;
  1616. if( aRect.GetWidth() > nMinWidth )
  1617. nMinWidth = aRect.GetWidth();
  1618. if( aRect.GetHeight() > nMinHeight )
  1619. nMinHeight = aRect.GetHeight();
  1620. if( nDropDownArrowWidth < nMinWidth )
  1621. nDropDownArrowWidth = nMinWidth;
  1622. if( nMinWidth > mpData->mnMenuButtonWidth )
  1623. mpData->mnMenuButtonWidth = nMinWidth;
  1624. else if( nMinWidth < TB_MENUBUTTON_SIZE )
  1625. mpData->mnMenuButtonWidth = TB_MENUBUTTON_SIZE;
  1626. }
  1627. }
  1628. // also calculate the area for comboboxes, drop down list boxes and spinfields
  1629. // as these are often inserted into toolboxes; set mnWinHeight to the
  1630. // greater of those values to prevent toolbar flickering (#i103385#)
  1631. aRect = Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
  1632. aReg = aRect;
  1633. if( GetNativeControlRegion( CTRL_COMBOBOX, PART_ENTIRE_CONTROL,
  1634. aReg,
  1635. CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
  1636. aVal, OUString(),
  1637. aNativeBounds, aNativeContent ) )
  1638. {
  1639. aRect = aNativeBounds;
  1640. if( aRect.GetHeight() > mnWinHeight )
  1641. mnWinHeight = aRect.GetHeight();
  1642. }
  1643. aRect = Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
  1644. aReg = aRect;
  1645. if( GetNativeControlRegion( CTRL_LISTBOX, PART_ENTIRE_CONTROL,
  1646. aReg,
  1647. CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
  1648. aVal, OUString(),
  1649. aNativeBounds, aNativeContent ) )
  1650. {
  1651. aRect = aNativeBounds;
  1652. if( aRect.GetHeight() > mnWinHeight )
  1653. mnWinHeight = aRect.GetHeight();
  1654. }
  1655. aRect = Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
  1656. aReg = aRect;
  1657. if( GetNativeControlRegion( CTRL_SPINBOX, PART_ENTIRE_CONTROL,
  1658. aReg,
  1659. CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
  1660. aVal, OUString(),
  1661. aNativeBounds, aNativeContent ) )
  1662. {
  1663. aRect = aNativeBounds;
  1664. if( aRect.GetHeight() > mnWinHeight )
  1665. mnWinHeight = aRect.GetHeight();
  1666. }
  1667. }
  1668. if ( ! mpData->m_aItems.empty() )
  1669. {
  1670. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
  1671. while ( it != mpData->m_aItems.end() )
  1672. {
  1673. sal_Bool bImage;
  1674. sal_Bool bText;
  1675. it->mbVisibleText = sal_False; // indicates if text will definitely be drawn, influences dropdown pos
  1676. if ( it->meType == TOOLBOXITEM_BUTTON )
  1677. {
  1678. // check if image and/or text exists
  1679. if ( !(it->maImage) )
  1680. bImage = sal_False;
  1681. else
  1682. bImage = sal_True;
  1683. if ( !it->maText.Len() )
  1684. bText = sal_False;
  1685. else
  1686. bText = sal_True;
  1687. ButtonType tmpButtonType = determineButtonType( &(*it), meButtonType ); // default to toolbox setting
  1688. if ( bImage || bText )
  1689. {
  1690. it->mbEmptyBtn = sal_False;
  1691. if ( tmpButtonType == BUTTON_SYMBOL )
  1692. {
  1693. // we're drawing images only
  1694. if ( bImage || !bText )
  1695. {
  1696. it->maItemSize = it->maImage.GetSizePixel();
  1697. }
  1698. else
  1699. {
  1700. it->maItemSize = Size( GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET,
  1701. GetTextHeight() );
  1702. it->mbVisibleText = sal_True;
  1703. }
  1704. }
  1705. else if ( tmpButtonType == BUTTON_TEXT )
  1706. {
  1707. // we're drawing text only
  1708. if ( bText || !bImage )
  1709. {
  1710. it->maItemSize = Size( GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET,
  1711. GetTextHeight() );
  1712. it->mbVisibleText = sal_True;
  1713. }
  1714. else
  1715. {
  1716. it->maItemSize = it->maImage.GetSizePixel();
  1717. }
  1718. }
  1719. else
  1720. {
  1721. // we're drawing images and text
  1722. it->maItemSize.Width() = bText ? GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET : 0;
  1723. it->maItemSize.Height() = bText ? GetTextHeight() : 0;
  1724. // leave space between image and text
  1725. if( bText )
  1726. it->maItemSize.Width() += TB_IMAGETEXTOFFSET;
  1727. // image and text side by side
  1728. it->maItemSize.Width() += it->maImage.GetSizePixel().Width();
  1729. if ( it->maImage.GetSizePixel().Height() > it->maItemSize.Height() )
  1730. it->maItemSize.Height() = it->maImage.GetSizePixel().Height();
  1731. it->mbVisibleText = bText;
  1732. }
  1733. }
  1734. else
  1735. { // no image and no text
  1736. it->maItemSize = Size( nDefWidth, nDefHeight );
  1737. it->mbEmptyBtn = sal_True;
  1738. }
  1739. // if required, take window height into consideration
  1740. if ( it->mpWindow )
  1741. {
  1742. long nHeight = it->mpWindow->GetSizePixel().Height();
  1743. if ( nHeight > mnWinHeight )
  1744. mnWinHeight = nHeight;
  1745. }
  1746. // add in drop down arrow
  1747. if( it->mnBits & TIB_DROPDOWN )
  1748. {
  1749. it->maItemSize.Width() += nDropDownArrowWidth;
  1750. it->mnDropDownArrowWidth = nDropDownArrowWidth;
  1751. }
  1752. // text items will be rotated in vertical mode
  1753. // -> swap width and height
  1754. if( it->mbVisibleText && !mbHorz )
  1755. {
  1756. long tmp = it->maItemSize.Width();
  1757. it->maItemSize.Width() = it->maItemSize.Height();
  1758. it->maItemSize.Height() = tmp;
  1759. }
  1760. }
  1761. else if ( it->meType == TOOLBOXITEM_SPACE )
  1762. {
  1763. it->maItemSize = Size( nDefWidth, nDefHeight );
  1764. }
  1765. if ( it->meType == TOOLBOXITEM_BUTTON || it->meType == TOOLBOXITEM_SPACE )
  1766. {
  1767. // add borders
  1768. ImplAddButtonBorder( it->maItemSize.Width(), it->maItemSize.Height(), mnOutStyle, mpData->mbNativeButtons );
  1769. if( it->meType == TOOLBOXITEM_BUTTON )
  1770. {
  1771. if( it->maItemSize.Width() < nMinWidth )
  1772. it->maItemSize.Width() = nMinWidth;
  1773. if( it->maItemSize.Height() < nMinHeight )
  1774. it->maItemSize.Height() = nMinHeight;
  1775. }
  1776. // keep track of max item size
  1777. if ( it->maItemSize.Width() > nMaxWidth )
  1778. nMaxWidth = it->maItemSize.Width();
  1779. if ( it->maItemSize.Height() > nMaxHeight )
  1780. nMaxHeight = it->maItemSize.Height();
  1781. }
  1782. ++it;
  1783. }
  1784. }
  1785. else
  1786. {
  1787. nMaxWidth = nDefWidth;
  1788. nMaxHeight = nDefHeight;
  1789. ImplAddButtonBorder( nMaxWidth, nMaxHeight, mnOutStyle, mpData->mbNativeButtons );
  1790. }
  1791. if( !ImplIsFloatingMode() && GetToolboxButtonSize() != TOOLBOX_BUTTONSIZE_DONTCARE )
  1792. {
  1793. // make sure all vertical toolbars have the same width and horizontal have the same height
  1794. // this depends on the used button sizes
  1795. // as this is used for alignement of multiple toolbars
  1796. // it is only required for docked toolbars
  1797. long nFixedWidth = nDefWidth+nDropDownArrowWidth;
  1798. long nFixedHeight = nDefHeight;
  1799. ImplAddButtonBorder( nFixedWidth, nFixedHeight, mnOutStyle, mpData->mbNativeButtons );
  1800. if( mbHorz )
  1801. nMaxHeight = nFixedHeight;
  1802. else
  1803. nMaxWidth = nFixedWidth;
  1804. }
  1805. mbCalc = sal_False;
  1806. mbFormat = sal_True;
  1807. // do we have to recalc the sizes ?
  1808. if ( (nMaxWidth != mnMaxItemWidth) || (nMaxHeight != mnMaxItemHeight) )
  1809. {
  1810. mnMaxItemWidth = nMaxWidth;
  1811. mnMaxItemHeight = nMaxHeight;
  1812. return sal_True;
  1813. }
  1814. else
  1815. return sal_False;
  1816. }
  1817. // -----------------------------------------------------------------------
  1818. sal_uInt16 ToolBox::ImplCalcBreaks( long nWidth, long* pMaxLineWidth, sal_Bool bCalcHorz )
  1819. {
  1820. sal_uLong nLineStart = 0;
  1821. sal_uLong nGroupStart = 0;
  1822. long nLineWidth = 0;
  1823. long nCurWidth;
  1824. long nLastGroupLineWidth = 0;
  1825. long nMaxLineWidth = 0;
  1826. sal_uInt16 nLines = 1;
  1827. sal_Bool bWindow;
  1828. sal_Bool bBreak = sal_False;
  1829. long nWidthTotal = nWidth;
  1830. long nMenuWidth = 0;
  1831. // when docked the menubutton will be in the first line
  1832. if( IsMenuEnabled() && !ImplIsFloatingMode() )
  1833. nMenuWidth = mpData->maMenubuttonItem.maItemSize.Width();
  1834. // we need to know which item is the last visible one to be able to add
  1835. // the menu width in case we are unable to show all the items
  1836. std::vector< ImplToolItem >::iterator it, lastVisible;
  1837. for ( it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it )
  1838. {
  1839. if ( it->mbVisible )
  1840. lastVisible = it;
  1841. }
  1842. it = mpData->m_aItems.begin();
  1843. while ( it != mpData->m_aItems.end() )
  1844. {
  1845. it->mbBreak = bBreak;
  1846. bBreak = sal_False;
  1847. if ( it->mbVisible )
  1848. {
  1849. bWindow = sal_False;
  1850. bBreak = sal_False;
  1851. nCurWidth = 0;
  1852. if ( it->meType == TOOLBOXITEM_BUTTON || it->meType == TOOLBOXITEM_SPACE )
  1853. {
  1854. if ( bCalcHorz )
  1855. nCurWidth = it->maItemSize.Width();
  1856. else
  1857. nCurWidth = it->maItemSize.Height();
  1858. if ( it->mpWindow && bCalcHorz )
  1859. {
  1860. long nWinItemWidth = it->mpWindow->GetSizePixel().Width();
  1861. if ( !mbScroll || (nWinItemWidth <= nWidthTotal) )
  1862. {
  1863. nCurWidth = nWinItemWidth;
  1864. bWindow = sal_True;
  1865. }
  1866. else
  1867. {
  1868. if ( it->mbEmptyBtn )
  1869. {
  1870. nCurWidth = 0;
  1871. }
  1872. }
  1873. }
  1874. // in case we are able to show all the items, we do not want
  1875. // to show the toolbar's menu; otherwise yes
  1876. if ( ( ( it == lastVisible ) && (nLineWidth+nCurWidth > nWidthTotal) && mbScroll ) ||
  1877. ( ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) && mbScroll ) )
  1878. bBreak = sal_True;
  1879. }
  1880. else if ( it->meType == TOOLBOXITEM_SEPARATOR )
  1881. {
  1882. nCurWidth = it->mnSepSize;
  1883. if ( !ImplIsFloatingMode() && ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) )
  1884. bBreak = sal_True;
  1885. }
  1886. // treat breaks as separators, except when using old style toolbars (ie. no menu button)
  1887. else if ( (it->meType == TOOLBOXITEM_BREAK) && !IsMenuEnabled() )
  1888. bBreak = sal_True;
  1889. if ( bBreak )
  1890. {
  1891. nLines++;
  1892. // Add break before the entire group or take group apart?
  1893. if ( (it->meType == TOOLBOXITEM_BREAK) ||
  1894. (nLineStart == nGroupStart) )
  1895. {
  1896. if ( nLineWidth > nMaxLineWidth )
  1897. nMaxLineWidth = nLineWidth;
  1898. nLineWidth = 0;
  1899. nLineStart = it - mpData->m_aItems.begin();
  1900. nGroupStart = nLineStart;
  1901. it->mbBreak = sal_True;
  1902. bBreak = sal_False;
  1903. }
  1904. else
  1905. {
  1906. if ( nLastGroupLineWidth > nMaxLineWidth )
  1907. nMaxLineWidth = nLastGroupLineWidth;
  1908. // if the break is added before the group, set it to
  1909. // beginning of line and re-calculate
  1910. nLineWidth = 0;
  1911. nLineStart = nGroupStart;
  1912. it = mpData->m_aItems.begin() + nGroupStart;
  1913. continue;
  1914. }
  1915. }
  1916. else
  1917. {
  1918. if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
  1919. {
  1920. if ( (it->meType != TOOLBOXITEM_BUTTON) || bWindow )
  1921. {
  1922. // found separator or break
  1923. nLastGroupLineWidth = nLineWidth;
  1924. nGroupStart = it - mpData->m_aItems.begin();
  1925. if ( !bWindow )
  1926. nGroupStart++;
  1927. }
  1928. }
  1929. }
  1930. nLineWidth += nCurWidth;
  1931. }
  1932. ++it;
  1933. }
  1934. if ( pMaxLineWidth )
  1935. {
  1936. if ( nLineWidth > nMaxLineWidth )
  1937. nMaxLineWidth = nLineWidth;
  1938. if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
  1939. {
  1940. // leave enough space to display buttons in the decoration
  1941. long aMinWidth = 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
  1942. if( nMaxLineWidth < aMinWidth )
  1943. nMaxLineWidth = aMinWidth;
  1944. }
  1945. *pMaxLineWidth = nMaxLineWidth;
  1946. }
  1947. return nLines;
  1948. }
  1949. // -----------------------------------------------------------------------
  1950. Size ToolBox::ImplGetOptimalFloatingSize( FloatingSizeMode eMode )
  1951. {
  1952. if( !ImplIsFloatingMode() )
  1953. return Size();
  1954. Size aCurrentSize( mnDX, mnDY );
  1955. Size aSize1( aCurrentSize );
  1956. Size aSize2( aCurrentSize );
  1957. // try to preserve current height
  1958. if( eMode == FSMODE_AUTO || eMode == FSMODE_FAVOURHEIGHT )
  1959. {
  1960. // calc number of floating lines for current window height
  1961. sal_uInt16 nFloatLinesHeight = ImplCalcLines( this, mnDY );
  1962. // calc window size according to this number
  1963. aSize1 = ImplCalcFloatSize( this, nFloatLinesHeight );
  1964. if( eMode == FSMODE_FAVOURHEIGHT || aCurrentSize == aSize1 )
  1965. return aSize1;
  1966. }
  1967. if( eMode == FSMODE_AUTO || eMode == FSMODE_FAVOURWIDTH )
  1968. {
  1969. // try to preserve current width
  1970. long nLineHeight = ( mnWinHeight > mnMaxItemHeight ) ? mnWinHeight : mnMaxItemHeight;
  1971. int nBorderX = 2*TB_BORDER_OFFSET1 + mnLeftBorder + mnRightBorder + 2*mnBorderX;
  1972. int nBorderY = 2*TB_BORDER_OFFSET2 + mnTopBorder + mnBottomBorder + 2*mnBorderY;
  1973. Size aSz( aCurrentSize );
  1974. long maxX;
  1975. sal_uInt16 nLines = ImplCalcBreaks( aSz.Width()-nBorderX, &maxX, mbHorz );
  1976. sal_uInt16 manyLines = 1000;
  1977. Size aMinimalFloatSize = ImplCalcFloatSize( this, manyLines );
  1978. aSz.Height() = nBorderY + nLineHeight * nLines;
  1979. // line space when more than one line
  1980. if ( mnWinStyle & WB_LINESPACING )
  1981. aSz.Height() += (nLines-1)*TB_LINESPACING;
  1982. aSz.Width() = nBorderX + maxX;
  1983. // avoid clipping of any items
  1984. if( aSz.Width() < aMinimalFloatSize.Width() )
  1985. aSize2 = ImplCalcFloatSize( this, nLines );
  1986. else
  1987. aSize2 = aSz;
  1988. if( eMode == FSMODE_FAVOURWIDTH || aCurrentSize == aSize2 )
  1989. return aSize2;
  1990. else
  1991. {
  1992. // set the size with the smallest delta as the current size
  1993. long dx1 = abs( mnDX - aSize1.Width() );
  1994. long dy1 = abs( mnDY - aSize1.Height() );
  1995. long dx2 = abs( mnDX - aSize2.Width() );
  1996. long dy2 = abs( mnDY - aSize2.Height() );
  1997. if( dx1*dy1 < dx2*dy2 )
  1998. aCurrentSize = aSize1;
  1999. else
  2000. aCurrentSize = aSize2;
  2001. }
  2002. }
  2003. return aCurrentSize;
  2004. }
  2005. namespace
  2006. {
  2007. static void lcl_hideDoubleSeparators( std::vector< ImplToolItem >& rItems )
  2008. {
  2009. bool bLastSep( true );
  2010. std::vector< ImplToolItem >::iterator it;
  2011. for ( it = rItems.begin(); it != rItems.end(); ++it )
  2012. {
  2013. if ( it->meType == TOOLBOXITEM_SEPARATOR )
  2014. {
  2015. it->mbVisible = sal_False;
  2016. if ( !bLastSep )
  2017. {
  2018. // check if any visible items have to appear behind it
  2019. std::vector< ImplToolItem >::iterator temp_it;
  2020. for ( temp_it = it+1; temp_it != rItems.end(); ++temp_it )
  2021. {
  2022. if ( ((temp_it->meType == TOOLBOXITEM_BUTTON) &&
  2023. temp_it->mbVisible) )
  2024. {
  2025. it->mbVisible = sal_True;
  2026. break;
  2027. }
  2028. }
  2029. }
  2030. bLastSep = true;
  2031. }
  2032. else if ( it->mbVisible )
  2033. bLastSep = false;
  2034. }
  2035. }
  2036. }
  2037. void ToolBox::ImplFormat( sal_Bool bResize )
  2038. {
  2039. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  2040. // Has to re-formatted
  2041. if ( !mbFormat )
  2042. return;
  2043. mpData->ImplClearLayoutData();
  2044. // recalulate positions and sizes
  2045. Rectangle aEmptyRect;
  2046. long nLineSize;
  2047. long nLeft;
  2048. long nTop;
  2049. long nMax; // width of layoutarea in pixels
  2050. sal_uInt16 nFormatLine;
  2051. sal_Bool bMustFullPaint;
  2052. std::vector< ImplToolItem >::iterator it;
  2053. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
  2054. sal_Bool bIsInPopupMode = ImplIsInPopupMode();
  2055. // delete FloatSizeAry if required
  2056. if ( mpFloatSizeAry )
  2057. {
  2058. delete mpFloatSizeAry;
  2059. mpFloatSizeAry = NULL;
  2060. }
  2061. // compute border sizes
  2062. ImplCalcBorder( meAlign, mnLeftBorder, mnTopBorder, mnRightBorder, mnBottomBorder, this );
  2063. // update drag area (where the 'grip' will be placed)
  2064. Rectangle aOldDragRect;
  2065. if( pWrapper )
  2066. aOldDragRect = pWrapper->GetDragArea();
  2067. ImplUpdateDragArea( this );
  2068. if ( ImplCalcItem() )
  2069. bMustFullPaint = sal_True;
  2070. else
  2071. bMustFullPaint = sal_False;
  2072. // calculate new size during interactive resize or
  2073. // set computed size when formatting only
  2074. if ( ImplIsFloatingMode() )
  2075. {
  2076. if ( bResize )
  2077. mnFloatLines = ImplCalcLines( this, mnDY );
  2078. else
  2079. SetOutputSizePixel( ImplGetOptimalFloatingSize( FSMODE_AUTO ) );
  2080. }
  2081. // Horizontal
  2082. if ( mbHorz )
  2083. {
  2084. long nBottom;
  2085. // nLineSize: height of a single line, will fit highest item
  2086. nLineSize = mnMaxItemHeight;
  2087. if ( mnWinHeight > mnMaxItemHeight )
  2088. nLineSize = mnWinHeight;
  2089. if ( mbScroll )
  2090. {
  2091. nMax = mnDX;
  2092. mnVisLines = ImplCalcLines( this, mnDY );
  2093. }
  2094. else
  2095. {
  2096. // layout over all lines
  2097. mnVisLines = mnLines;
  2098. nMax = TB_MAXNOSCROLL;
  2099. }
  2100. // add in all border offsets
  2101. // inner border as well as custom border (mnBorderX, mnBorderY)
  2102. if ( mnWinStyle & WB_BORDER )
  2103. {
  2104. nLeft = TB_BORDER_OFFSET1 + mnLeftBorder;
  2105. nTop = TB_BORDER_OFFSET2 + mnTopBorder;
  2106. nBottom = TB_BORDER_OFFSET1 + mnBottomBorder;
  2107. nMax -= nLeft + TB_BORDER_OFFSET1 + mnRightBorder;
  2108. }
  2109. else
  2110. {
  2111. nLeft = 0;
  2112. nTop = 0;
  2113. nBottom = 0;
  2114. }
  2115. nLeft += mnBorderX;
  2116. nTop += mnBorderY;
  2117. nBottom += mnBorderY;
  2118. nMax -= mnBorderX*2;
  2119. // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
  2120. // we have to center all items in the window height
  2121. if( IsMenuEnabled() && !ImplIsFloatingMode() )
  2122. {
  2123. long nWinHeight = mnDY - nTop - nBottom;
  2124. if( nWinHeight > nLineSize )
  2125. nLineSize = nWinHeight;
  2126. }
  2127. }
  2128. else
  2129. {
  2130. long nRight;
  2131. nLineSize = mnMaxItemWidth;
  2132. if ( mbScroll )
  2133. {
  2134. mnVisLines = ImplCalcLines( this, mnDX );
  2135. nMax = mnDY;
  2136. }
  2137. else
  2138. {
  2139. mnVisLines = mnLines;
  2140. nMax = TB_MAXNOSCROLL;
  2141. }
  2142. if ( mnWinStyle & WB_BORDER )
  2143. {
  2144. nTop = TB_BORDER_OFFSET1 + mnTopBorder;
  2145. nLeft = TB_BORDER_OFFSET2 + mnLeftBorder;
  2146. nRight = TB_BORDER_OFFSET2 + mnRightBorder;
  2147. nMax -= nTop + TB_BORDER_OFFSET1 + mnBottomBorder;
  2148. }
  2149. else
  2150. {
  2151. nLeft = 0;
  2152. nTop = 0;
  2153. nRight = 0;
  2154. }
  2155. nLeft += mnBorderX;
  2156. nRight+= mnBorderX;
  2157. nTop += mnBorderY;
  2158. nMax -= mnBorderY*2;
  2159. // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
  2160. // we have to center all items in the window height
  2161. if( !ImplIsFloatingMode() && IsMenuEnabled() )
  2162. {
  2163. long nWinWidth = mnDX - nLeft - nRight;
  2164. if( nWinWidth > nLineSize )
  2165. nLineSize = nWinWidth;
  2166. }
  2167. }
  2168. // no calculation if the window has no size (nMax=0)
  2169. // non scrolling toolboxes must be computed though
  2170. if ( (nMax <= 0) && mbScroll )
  2171. {
  2172. mnVisLines = 1;
  2173. mnCurLine = 1;
  2174. mnCurLines = 1;
  2175. it = mpData->m_aItems.begin();
  2176. while ( it != mpData->m_aItems.end() )
  2177. {
  2178. it->maRect = aEmptyRect;
  2179. ++it;
  2180. }
  2181. maLowerRect = aEmptyRect;
  2182. maUpperRect = aEmptyRect;
  2183. maNextToolRect = aEmptyRect;
  2184. }
  2185. else
  2186. {
  2187. // init start values
  2188. long nX = nLeft; // top-left offset
  2189. long nY = nTop;
  2190. nFormatLine = 1;
  2191. // save old scroll rectangles and reset them
  2192. Rectangle aOldLowerRect = maLowerRect;
  2193. Rectangle aOldUpperRect = maUpperRect;
  2194. Rectangle aOldNextToolRect = maNextToolRect;
  2195. Rectangle aOldMenubuttonRect = mpData->maMenubuttonItem.maRect;
  2196. maUpperRect = aEmptyRect;
  2197. maLowerRect = aEmptyRect;
  2198. maNextToolRect = aEmptyRect;
  2199. mpData->maMenubuttonItem.maRect = aEmptyRect;
  2200. // additional toolboxes require a toggle button (maNextToolRect)
  2201. if ( maNextToolBoxStr.Len() && mbScroll )
  2202. {
  2203. nMax -= TB_NEXT_SIZE-TB_NEXT_OFFSET;
  2204. if ( mbHorz )
  2205. {
  2206. maNextToolRect.Left() = nLeft+nMax;
  2207. maNextToolRect.Right() = maNextToolRect.Left()+TB_NEXT_SIZE-1;
  2208. maNextToolRect.Top() = nTop;
  2209. maNextToolRect.Bottom() = mnDY-mnBottomBorder-mnBorderY-TB_BORDER_OFFSET2-1;
  2210. }
  2211. else
  2212. {
  2213. maNextToolRect.Top() = nTop+nMax;
  2214. maNextToolRect.Bottom() = maNextToolRect.Top()+TB_NEXT_SIZE-1;
  2215. maNextToolRect.Left() = nLeft;
  2216. maNextToolRect.Right() = mnDX-mnRightBorder-mnBorderX-TB_BORDER_OFFSET2-1;
  2217. }
  2218. }
  2219. // do we have any toolbox items at all ?
  2220. if ( !mpData->m_aItems.empty() || IsMenuEnabled() )
  2221. {
  2222. lcl_hideDoubleSeparators( mpData->m_aItems );
  2223. // compute line breaks and visible lines give the current window width (nMax)
  2224. // the break indicators will be stored within each item (it->mbBreak)
  2225. mnCurLines = ImplCalcBreaks( nMax, NULL, mbHorz );
  2226. // check for scrollbar buttons or dropdown menu
  2227. // (if a menu is enabled, this will be used to store clipped
  2228. // items and no scroll buttons will appear)
  2229. if ( (!ImplIsFloatingMode() && (mnCurLines > mnVisLines) && mbScroll ) ||
  2230. IsMenuEnabled() )
  2231. {
  2232. // compute linebreaks again, incorporating scrollbar buttons
  2233. if( !IsMenuEnabled() )
  2234. {
  2235. nMax -= TB_SPIN_SIZE+TB_SPIN_OFFSET;
  2236. mnCurLines = ImplCalcBreaks( nMax, NULL, mbHorz );
  2237. }
  2238. // compute scroll rectangles or menu button
  2239. if ( mbHorz )
  2240. {
  2241. if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
  2242. {
  2243. if( !ImplIsFloatingMode() )
  2244. {
  2245. mpData->maMenubuttonItem.maRect.Right() = mnDX - 2;
  2246. mpData->maMenubuttonItem.maRect.Top() = nTop;
  2247. mpData->maMenubuttonItem.maRect.Bottom() = mnDY-mnBottomBorder-mnBorderY-TB_BORDER_OFFSET2-1;
  2248. }
  2249. else
  2250. {
  2251. mpData->maMenubuttonItem.maRect.Right() = mnDX - mnRightBorder-mnBorderX-TB_BORDER_OFFSET1-1;
  2252. mpData->maMenubuttonItem.maRect.Top() = nTop;
  2253. mpData->maMenubuttonItem.maRect.Bottom() = mnDY-mnBottomBorder-mnBorderY-TB_BORDER_OFFSET2-1;
  2254. }
  2255. mpData->maMenubuttonItem.maRect.Left() = mpData->maMenubuttonItem.maRect.Right() - mpData->mnMenuButtonWidth;
  2256. }
  2257. else
  2258. {
  2259. maUpperRect.Left() = nLeft+nMax+TB_SPIN_OFFSET;
  2260. maUpperRect.Right() = maUpperRect.Left()+TB_SPIN_SIZE-1;
  2261. maUpperRect.Top() = nTop;
  2262. maLowerRect.Bottom() = mnDY-mnBottomBorder-mnBorderY-TB_BORDER_OFFSET2-1;
  2263. maLowerRect.Left() = maUpperRect.Left();
  2264. maLowerRect.Right() = maUpperRect.Right();
  2265. maUpperRect.Bottom() = maUpperRect.Top() +
  2266. (maLowerRect.Bottom()-maUpperRect.Top())/2;
  2267. maLowerRect.Top() = maUpperRect.Bottom();
  2268. }
  2269. }
  2270. else
  2271. {
  2272. if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
  2273. {
  2274. if( !ImplIsFloatingMode() )
  2275. {
  2276. mpData->maMenubuttonItem.maRect.Bottom() = mnDY - 2;
  2277. mpData->maMenubuttonItem.maRect.Left() = nLeft;
  2278. mpData->maMenubuttonItem.maRect.Right() = mnDX-mnRightBorder-mnBorderX-TB_BORDER_OFFSET2-1;
  2279. }
  2280. else
  2281. {
  2282. mpData->maMenubuttonItem.maRect.Bottom() = mnDY - mnBottomBorder-mnBorderY-TB_BORDER_OFFSET1-1;
  2283. mpData->maMenubuttonItem.maRect.Left() = nLeft;
  2284. mpData->maMenubuttonItem.maRect.Right() = mnDX-mnRightBorder-mnBorderX-TB_BORDER_OFFSET2-1;
  2285. }
  2286. mpData->maMenubuttonItem.maRect.Top() = mpData->maMenubuttonItem.maRect.Bottom() - mpData->mnMenuButtonWidth;
  2287. }
  2288. else
  2289. {
  2290. maUpperRect.Top() = nTop+nMax+TB_SPIN_OFFSET;
  2291. maUpperRect.Bottom() = maUpperRect.Top()+TB_SPIN_SIZE-1;
  2292. maUpperRect.Left() = nLeft;
  2293. maLowerRect.Right() = mnDX-mnRightBorder-mnBorderX-TB_BORDER_OFFSET2-1;
  2294. maLowerRect.Top() = maUpperRect.Top();
  2295. maLowerRect.Bottom() = maUpperRect.Bottom();
  2296. maUpperRect.Right() = maUpperRect.Left() +
  2297. (maLowerRect.Right()-maUpperRect.Left())/2;
  2298. maLowerRect.Left() = maUpperRect.Right();
  2299. }
  2300. }
  2301. }
  2302. // no scrolling when there is a "more"-menu
  2303. // anything will "fit" in a single line then
  2304. if( IsMenuEnabled() )
  2305. mnCurLines = 1;
  2306. // determine the currently visible line
  2307. if ( mnVisLines >= mnCurLines )
  2308. mnCurLine = 1;
  2309. else if ( mnCurLine+mnVisLines-1 > mnCurLines )
  2310. mnCurLine = mnCurLines - (mnVisLines-1);
  2311. it = mpData->m_aItems.begin();
  2312. while ( it != mpData->m_aItems.end() )
  2313. {
  2314. it->mbShowWindow = sal_False;
  2315. // check for line break and advance nX/nY accordingly
  2316. if ( it->mbBreak )
  2317. {
  2318. nFormatLine++;
  2319. // increment starting with the second line
  2320. if ( nFormatLine > mnCurLine )
  2321. {
  2322. if ( mbHorz )
  2323. {
  2324. nX = nLeft;
  2325. if ( mnWinStyle & WB_LINESPACING )
  2326. nY += nLineSize+TB_LINESPACING;
  2327. else
  2328. nY += nLineSize;
  2329. }
  2330. else
  2331. {
  2332. nY = nTop;
  2333. if ( mnWinStyle & WB_LINESPACING )
  2334. nX += nLineSize+TB_LINESPACING;
  2335. else
  2336. nX += nLineSize;
  2337. }
  2338. }
  2339. }
  2340. if ( !it->mbVisible || (nFormatLine < mnCurLine) ||
  2341. (nFormatLine > mnCurLine+mnVisLines-1) )
  2342. // item is not visible
  2343. it->maCalcRect = aEmptyRect;
  2344. else
  2345. {
  2346. // 1. determine current item width/height
  2347. // take window size and orientation into account, because this affects the size of item windows
  2348. Size aCurrentItemSize( it->GetSize( mbHorz, mbScroll, nMax, Size(mnMaxItemWidth, mnMaxItemHeight) ) );
  2349. // 2. position item rect and use size from step 1
  2350. // items will be centered horizontally (if mbHorz) or vertically
  2351. // advance nX and nY accordingly
  2352. if ( mbHorz )
  2353. {
  2354. it->maCalcRect.Left() = nX;
  2355. // if special TBX_LAYOUT_LOCKVERT lock vertical position
  2356. // don't recalulate the vertical position of the item
  2357. if ( meLayoutMode == TBX_LAYOUT_LOCKVERT && mnLines == 1 )
  2358. {
  2359. // Somewhat of a hack here, calc deletes and re-adds
  2360. // the sum/assign & ok/cancel items dynamically.
  2361. // Because TBX_LAYOUT_LOCKVERT effectively prevents
  2362. // recalculation of the vertical pos of an item the
  2363. // it->maRect.Top() for those newly added items is
  2364. // 0. The hack here is that we want to effectively
  2365. // recalculate the vertical pos for those added
  2366. // items here. ( Note: assume mnMaxItemHeight is
  2367. // equal to the LineSize when multibar has a single
  2368. // line size )
  2369. it->maCalcRect.Top() = it->maRect.Top() ? it->maRect.Top() : ( nY + ( mnMaxItemHeight-aCurrentItemSize.Height())/2 );
  2370. }
  2371. else
  2372. it->maCalcRect.Top() = nY+(nLineSize-aCurrentItemSize.Height())/2;
  2373. it->maCalcRect.Right() = nX+aCurrentItemSize.Width()-1;
  2374. it->maCalcRect.Bottom() = it->maCalcRect.Top()+aCurrentItemSize.Height()-1;
  2375. nX += aCurrentItemSize.Width();
  2376. }
  2377. else
  2378. {
  2379. it->maCalcRect.Left() = nX+(nLineSize-aCurrentItemSize.Width())/2;
  2380. it->maCalcRect.Top() = nY;
  2381. it->maCalcRect.Right() = it->maCalcRect.Left()+aCurrentItemSize.Width()-1;
  2382. it->maCalcRect.Bottom() = nY+aCurrentItemSize.Height()-1;
  2383. nY += aCurrentItemSize.Height();
  2384. }
  2385. }
  2386. // position window items into calculated item rect
  2387. if ( it->mpWindow )
  2388. {
  2389. if ( it->mbShowWindow )
  2390. {
  2391. Point aPos( it->maCalcRect.Left(), it->maCalcRect.Top() );
  2392. it->mpWindow->SetPosPixel( aPos );
  2393. if ( !mbCustomizeMode )
  2394. it->mpWindow->Show();
  2395. }
  2396. else
  2397. it->mpWindow->Hide();
  2398. }
  2399. ++it;
  2400. } // end of loop over all items
  2401. }
  2402. else
  2403. // we have no toolbox items
  2404. mnCurLines = 1;
  2405. if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
  2406. {
  2407. // custom menu will be the last button in floating mode
  2408. ImplToolItem &rIt = mpData->maMenubuttonItem;
  2409. if ( mbHorz )
  2410. {
  2411. rIt.maRect.Left() = nX+TB_MENUBUTTON_OFFSET;
  2412. rIt.maRect.Top() = nY;
  2413. rIt.maRect.Right() = rIt.maRect.Left() + mpData->mnMenuButtonWidth;
  2414. rIt.maRect.Bottom() = nY+nLineSize-1;
  2415. nX += rIt.maItemSize.Width();
  2416. }
  2417. else
  2418. {
  2419. rIt.maRect.Left() = nX;
  2420. rIt.maRect.Top() = nY+TB_MENUBUTTON_OFFSET;
  2421. rIt.maRect.Right() = nX+nLineSize-1;
  2422. rIt.maRect.Bottom() = rIt.maRect.Top() + mpData->mnMenuButtonWidth;
  2423. nY += rIt.maItemSize.Height();
  2424. }
  2425. }
  2426. // if toolbox visible trigger paint for changed regions
  2427. if ( IsVisible() && !mbFullPaint )
  2428. {
  2429. if ( bMustFullPaint )
  2430. {
  2431. maPaintRect = Rectangle( mnLeftBorder, mnTopBorder,
  2432. mnDX-mnRightBorder, mnDY-mnBottomBorder );
  2433. }
  2434. else
  2435. {
  2436. if ( aOldLowerRect != maLowerRect )
  2437. {
  2438. maPaintRect.Union( maLowerRect );
  2439. maPaintRect.Union( aOldLowerRect );
  2440. }
  2441. if ( aOldUpperRect != maUpperRect )
  2442. {
  2443. maPaintRect.Union( maUpperRect );
  2444. maPaintRect.Union( aOldUpperRect );
  2445. }
  2446. if ( aOldNextToolRect != maNextToolRect )
  2447. {
  2448. maPaintRect.Union( maNextToolRect );
  2449. maPaintRect.Union( aOldNextToolRect );
  2450. }
  2451. if ( aOldMenubuttonRect != mpData->maMenubuttonItem.maRect )
  2452. {
  2453. maPaintRect.Union( mpData->maMenubuttonItem.maRect );
  2454. maPaintRect.Union( aOldMenubuttonRect );
  2455. }
  2456. if ( pWrapper && aOldDragRect != pWrapper->GetDragArea() )
  2457. {
  2458. maPaintRect.Union( pWrapper->GetDragArea() );
  2459. maPaintRect.Union( aOldDragRect );
  2460. }
  2461. it = mpData->m_aItems.begin();
  2462. while ( it != mpData->m_aItems.end() )
  2463. {
  2464. if ( it->maRect != it->maCalcRect )
  2465. {
  2466. maPaintRect.Union( it->maRect );
  2467. maPaintRect.Union( it->maCalcRect );
  2468. }
  2469. ++it;
  2470. }
  2471. }
  2472. Invalidate( maPaintRect );
  2473. }
  2474. // store the new calculated item rects
  2475. maPaintRect = aEmptyRect;
  2476. Rectangle aVisibleRect(Point(0, 0), GetOutputSizePixel());
  2477. it = mpData->m_aItems.begin();
  2478. while ( it != mpData->m_aItems.end() )
  2479. {
  2480. it->maRect = it->maCalcRect;
  2481. it->maRect.IsOver(aVisibleRect);
  2482. ++it;
  2483. }
  2484. }
  2485. // indicate formatting is done
  2486. mbFormat = sal_False;
  2487. }
  2488. // -----------------------------------------------------------------------
  2489. IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl)
  2490. {
  2491. if( mnCurPos != TOOLBOX_ITEM_NOTFOUND &&
  2492. (mpData->m_aItems[ mnCurPos ].mnBits & TIB_DROPDOWN)
  2493. )
  2494. {
  2495. mpData->mbDropDownByKeyboard = sal_False;
  2496. GetDropdownClickHdl().Call( this );
  2497. // do not reset data if the dropdown handler opened a floating window
  2498. // see ImplFloatControl()
  2499. if( mpFloatWin == NULL )
  2500. {
  2501. // no floater was opened
  2502. Deactivate();
  2503. ImplDrawItem( mnCurPos, 0 );
  2504. mnCurPos = TOOLBOX_ITEM_NOTFOUND;
  2505. mnCurItemId = 0;
  2506. mnDownItemId = 0;
  2507. mnMouseClicks = 0;
  2508. mnMouseModifier = 0;
  2509. mnHighItemId = 0;
  2510. }
  2511. }
  2512. return 0;
  2513. }
  2514. // -----------------------------------------------------------------------
  2515. IMPL_LINK_NOARG(ToolBox, ImplUpdateHdl)
  2516. {
  2517. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  2518. if( mbFormat )
  2519. ImplFormat();
  2520. return 0;
  2521. }
  2522. // -----------------------------------------------------------------------
  2523. static void ImplDrawMoreIndicator( ToolBox *pBox, const Rectangle& rRect, sal_Bool bSetColor, sal_Bool bRotate )
  2524. {
  2525. Color aOldFillColor = pBox->GetFillColor();
  2526. Color aOldLineColor = pBox->GetLineColor();
  2527. pBox->SetLineColor();
  2528. if ( bSetColor )
  2529. {
  2530. if ( pBox->GetSettings().GetStyleSettings().GetFaceColor().IsDark() )
  2531. pBox->SetFillColor( Color( COL_WHITE ) );
  2532. else
  2533. pBox->SetFillColor( Color( COL_BLACK ) );
  2534. }
  2535. if( !bRotate )
  2536. {
  2537. long width = 8;
  2538. long height = 5;
  2539. long x = rRect.Left() + (rRect.getWidth() - width)/2 + 1;
  2540. long y = rRect.Top() + (rRect.getHeight() - height)/2 + 1;
  2541. while( height >= 1)
  2542. {
  2543. pBox->DrawRect( Rectangle( x, y, x+1, y ) );
  2544. x+=4;
  2545. pBox->DrawRect( Rectangle( x, y, x+1, y ) );
  2546. x-=4;
  2547. y++;
  2548. if( height <= 3) x--;
  2549. else x++;
  2550. height--;
  2551. }
  2552. }
  2553. else
  2554. {
  2555. long width = 5;
  2556. long height = 8;
  2557. long x = rRect.Left() + (rRect.getWidth() - width)/2 + 1;
  2558. long y = rRect.Top() + (rRect.getHeight() - height)/2 + 1;
  2559. while( width >= 1)
  2560. {
  2561. pBox->DrawRect( Rectangle( x, y, x, y+1 ) );
  2562. y+=4;
  2563. pBox->DrawRect( Rectangle( x, y, x, y+1 ) );
  2564. y-=4;
  2565. x++;
  2566. if( width <= 3) y--;
  2567. else y++;
  2568. width--;
  2569. }
  2570. }
  2571. pBox->SetFillColor( aOldFillColor );
  2572. pBox->SetLineColor( aOldLineColor );
  2573. }
  2574. static void ImplDrawDropdownArrow( ToolBox *pBox, const Rectangle& rDropDownRect, sal_Bool bSetColor, sal_Bool bRotate )
  2575. {
  2576. sal_Bool bLineColor = pBox->IsLineColor();
  2577. sal_Bool bFillColor = pBox->IsFillColor();
  2578. Color aOldFillColor = pBox->GetFillColor();
  2579. Color aOldLineColor = pBox->GetLineColor();
  2580. pBox->SetLineColor();
  2581. if ( bSetColor )
  2582. {
  2583. if ( pBox->GetSettings().GetStyleSettings().GetFaceColor().IsDark() )
  2584. pBox->SetFillColor( Color( COL_WHITE ) );
  2585. else
  2586. pBox->SetFillColor( Color( COL_BLACK ) );
  2587. }
  2588. if( !bRotate )
  2589. {
  2590. long width = 5;
  2591. long height = 3;
  2592. long x = rDropDownRect.Left() + (rDropDownRect.getWidth() - width)/2;
  2593. long y = rDropDownRect.Top() + (rDropDownRect.getHeight() - height)/2;
  2594. while( width >= 1)
  2595. {
  2596. pBox->DrawRect( Rectangle( x, y, x+width-1, y ) );
  2597. y++; x++;
  2598. width -= 2;
  2599. }
  2600. }
  2601. else
  2602. {
  2603. long width = 3;
  2604. long height = 5;
  2605. long x = rDropDownRect.Left() + (rDropDownRect.getWidth() - width)/2;
  2606. long y = rDropDownRect.Top() + (rDropDownRect.getHeight() - height)/2;
  2607. while( height >= 1)
  2608. {
  2609. pBox->DrawRect( Rectangle( x, y, x, y+height-1 ) );
  2610. y++; x++;
  2611. height -= 2;
  2612. }
  2613. }
  2614. if( bFillColor )
  2615. pBox->SetFillColor( aOldFillColor );
  2616. else
  2617. pBox->SetFillColor();
  2618. if( bLineColor )
  2619. pBox->SetLineColor( aOldLineColor );
  2620. else
  2621. pBox->SetLineColor( );
  2622. }
  2623. void ToolBox::ImplDrawToolArrow( ToolBox* pBox, long nX, long nY, sal_Bool bBlack, sal_Bool bColTransform,
  2624. sal_Bool bLeft, sal_Bool bTop, long nSize )
  2625. {
  2626. Color aOldFillColor = pBox->GetFillColor();
  2627. WindowAlign eAlign = pBox->meAlign;
  2628. long n = 0;
  2629. long nHalfSize;
  2630. if ( bLeft )
  2631. eAlign = WINDOWALIGN_RIGHT;
  2632. else if ( bTop )
  2633. eAlign = WINDOWALIGN_BOTTOM;
  2634. nHalfSize = nSize/2;
  2635. switch ( eAlign )
  2636. {
  2637. case WINDOWALIGN_LEFT:
  2638. if ( bBlack )
  2639. pBox->SetFillColor( Color( bColTransform ? COL_WHITE : COL_BLACK ) );
  2640. while ( n <= nHalfSize )
  2641. {
  2642. pBox->DrawRect( Rectangle( nX+n, nY+n, nX+n, nY+nSize-n ) );
  2643. n++;
  2644. }
  2645. if ( bBlack )
  2646. {
  2647. pBox->SetFillColor( aOldFillColor );
  2648. n = 1;
  2649. while ( n < nHalfSize )
  2650. {
  2651. pBox->DrawRect( Rectangle( nX+n, nY+1+n, nX+n, nY+nSize-1-n ) );
  2652. n++;
  2653. }
  2654. }
  2655. break;
  2656. case WINDOWALIGN_TOP:
  2657. if ( bBlack )
  2658. pBox->SetFillColor( Color( bColTransform ? COL_WHITE : COL_BLACK ) );
  2659. while ( n <= nHalfSize )
  2660. {
  2661. pBox->DrawRect( Rectangle( nX+n, nY+n, nX+nSize-n, nY+n ) );
  2662. n++;
  2663. }
  2664. if ( bBlack )
  2665. {
  2666. pBox->SetFillColor( aOldFillColor );
  2667. n = 1;
  2668. while ( n < nHalfSize )
  2669. {
  2670. pBox->DrawRect( Rectangle( nX+1+n, nY+n, nX+nSize-1-n, nY+n ) );
  2671. n++;
  2672. }
  2673. }
  2674. break;
  2675. case WINDOWALIGN_RIGHT:
  2676. if ( bBlack )
  2677. pBox->SetFillColor( Color( bColTransform ? COL_WHITE : COL_BLACK ) );
  2678. while ( n <= nHalfSize )
  2679. {
  2680. pBox->DrawRect( Rectangle( nX+nHalfSize-n, nY+n, nX+nHalfSize-n, nY+nSize-n ) );
  2681. n++;
  2682. }
  2683. if ( bBlack )
  2684. {
  2685. pBox->SetFillColor( aOldFillColor );
  2686. n = 1;
  2687. while ( n < nHalfSize )
  2688. {
  2689. pBox->DrawRect( Rectangle( nX+nHalfSize-n, nY+1+n, nX+nHalfSize-n, nY+nSize-1-n ) );
  2690. n++;
  2691. }
  2692. }
  2693. break;
  2694. case WINDOWALIGN_BOTTOM:
  2695. if ( bBlack )
  2696. pBox->SetFillColor( Color( bColTransform ? COL_WHITE : COL_BLACK ) );
  2697. while ( n <= nHalfSize )
  2698. {
  2699. pBox->DrawRect( Rectangle( nX+n, nY+nHalfSize-n, nX+nSize-n, nY+nHalfSize-n ) );
  2700. n++;
  2701. }
  2702. if ( bBlack )
  2703. {
  2704. pBox->SetFillColor( aOldFillColor );
  2705. n = 1;
  2706. while ( n < nHalfSize )
  2707. {
  2708. pBox->DrawRect( Rectangle( nX+1+n, nY+nHalfSize-n, nX+nSize-1-n, nY+nHalfSize-n ) );
  2709. n++;
  2710. }
  2711. }
  2712. break;
  2713. }
  2714. }
  2715. // -----------------------------------------------------------------------
  2716. void ToolBox::ImplDrawMenubutton( ToolBox *pThis, sal_Bool bHighlight )
  2717. {
  2718. if( !pThis->mpData->maMenubuttonItem.maRect.IsEmpty() )
  2719. {
  2720. // #i53937# paint menu button only if necessary
  2721. if( !pThis->ImplHasClippedItems() )
  2722. return;
  2723. // execute pending paint requests
  2724. ImplCheckUpdate( pThis );
  2725. sal_Bool bFillColor = pThis->IsFillColor();
  2726. sal_Bool bLineColor = pThis->IsLineColor();
  2727. Color aOldFillCol = pThis->GetFillColor();
  2728. Color aOldLineCol = pThis->GetLineColor();
  2729. // draw the 'more' indicator / button (>>)
  2730. ImplErase( pThis, pThis->mpData->maMenubuttonItem.maRect, bHighlight );
  2731. if( bHighlight )
  2732. ImplDrawButton( pThis, pThis->mpData->maMenubuttonItem.maRect, 2, sal_False, sal_True, sal_False );
  2733. if( pThis->ImplHasClippedItems() )
  2734. ImplDrawMoreIndicator( pThis, pThis->mpData->maMenubuttonItem.maRect, sal_True, !pThis->mbHorz );
  2735. // store highlight state
  2736. pThis->mpData->mbMenubuttonSelected = bHighlight;
  2737. // restore colors
  2738. if( bFillColor )
  2739. pThis->SetFillColor( aOldFillCol );
  2740. else
  2741. pThis->SetFillColor();
  2742. if( bLineColor )
  2743. pThis->SetLineColor( aOldLineCol );
  2744. else
  2745. pThis->SetLineColor();
  2746. }
  2747. }
  2748. // -----------------------------------------------------------------------
  2749. void ToolBox::ImplDrawSpin( sal_Bool bUpperIn, sal_Bool bLowerIn )
  2750. {
  2751. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  2752. sal_Bool bTmpUpper;
  2753. sal_Bool bTmpLower;
  2754. if ( maUpperRect.IsEmpty() || maLowerRect.IsEmpty() )
  2755. return;
  2756. if ( mnCurLine > 1 )
  2757. bTmpUpper = sal_True;
  2758. else
  2759. bTmpUpper = sal_False;
  2760. if ( mnCurLine+mnVisLines-1 < mnCurLines )
  2761. bTmpLower = sal_True;
  2762. else
  2763. bTmpLower = sal_False;
  2764. if ( !IsEnabled() )
  2765. {
  2766. bTmpUpper = sal_False;
  2767. bTmpLower = sal_False;
  2768. }
  2769. ImplDrawSpinButton( this, maUpperRect, maLowerRect,
  2770. bUpperIn, bLowerIn, bTmpUpper, bTmpLower, !mbHorz );
  2771. }
  2772. // -----------------------------------------------------------------------
  2773. void ToolBox::ImplDrawNext( sal_Bool bIn )
  2774. {
  2775. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  2776. if ( maNextToolRect.IsEmpty() )
  2777. return;
  2778. DecorationView aDecoView( this );
  2779. // Button malen
  2780. long nX = SMALLBUTTON_OFF_NORMAL_X;
  2781. long nY = SMALLBUTTON_OFF_NORMAL_Y;
  2782. sal_uInt16 nStyle = 0;
  2783. if ( bIn == 1 )
  2784. {
  2785. nStyle |= BUTTON_DRAW_PRESSED;
  2786. nX = SMALLBUTTON_OFF_PRESSED_X;
  2787. nY = SMALLBUTTON_OFF_PRESSED_Y;
  2788. }
  2789. aDecoView.DrawButton( maNextToolRect, nStyle );
  2790. // Inhalt ausgeben
  2791. sal_Bool bLeft = sal_False;
  2792. sal_Bool bTop = sal_False;
  2793. if ( mbHorz )
  2794. {
  2795. bLeft = sal_True;
  2796. nX += (maNextToolRect.GetWidth()-6)/2-4;
  2797. nY += (maNextToolRect.GetHeight()-6)/2-6;
  2798. }
  2799. else
  2800. {
  2801. bTop = sal_True;
  2802. nY += (maNextToolRect.GetHeight()-6)/2-4;
  2803. nX += (maNextToolRect.GetWidth()-6)/2-6;
  2804. }
  2805. nX += maNextToolRect.Left();
  2806. nY += maNextToolRect.Top();
  2807. SetLineColor();
  2808. SetFillColor( COL_LIGHTBLUE );
  2809. ImplDrawToolArrow( this, nX, nY, sal_True, sal_False, bLeft, bTop, 10 );
  2810. }
  2811. // -----------------------------------------------------------------------
  2812. void ToolBox::ImplDrawSeparator( sal_uInt16 nPos, Rectangle rRect )
  2813. {
  2814. bool bNativeOk = false;
  2815. ImplToolItem* pItem = &mpData->m_aItems[nPos];
  2816. ControlPart nPart = IsHorizontal() ? PART_SEPARATOR_VERT : PART_SEPARATOR_HORZ;
  2817. if( IsNativeControlSupported( CTRL_TOOLBAR, nPart ) )
  2818. {
  2819. ImplControlValue aControlValue;
  2820. ControlState nState = 0;
  2821. bNativeOk = DrawNativeControl( CTRL_TOOLBAR, nPart,
  2822. rRect, nState, aControlValue, rtl::OUString() );
  2823. }
  2824. /* Draw the widget only if it can't be drawn natively. */
  2825. if( !bNativeOk )
  2826. {
  2827. const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
  2828. ImplToolItem* pTempItem = &mpData->m_aItems[nPos-1];
  2829. // no separator before or after windows or at breaks
  2830. if ( pTempItem && !pTempItem->mbShowWindow && nPos < mpData->m_aItems.size()-1 )
  2831. {
  2832. pTempItem = &mpData->m_aItems[nPos+1];
  2833. if ( !pTempItem->mbShowWindow && !pTempItem->mbBreak )
  2834. {
  2835. long nCenterPos, nSlim;
  2836. SetLineColor( rStyleSettings.GetSeparatorColor() );
  2837. if ( IsHorizontal() )
  2838. {
  2839. nSlim = (pItem->maRect.Bottom() - pItem->maRect.Top ()) / 4;
  2840. nCenterPos = pItem->maRect.Center().X();
  2841. DrawLine( Point( nCenterPos, pItem->maRect.Top() + nSlim ),
  2842. Point( nCenterPos, pItem->maRect.Bottom() - nSlim ) );
  2843. }
  2844. else
  2845. {
  2846. nSlim = (pItem->maRect.Right() - pItem->maRect.Left ()) / 4;
  2847. nCenterPos = pItem->maRect.Center().Y();
  2848. DrawLine( Point( pItem->maRect.Left() + nSlim, nCenterPos ),
  2849. Point( pItem->maRect.Right() - nSlim, nCenterPos ) );
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. // -----------------------------------------------------------------------
  2856. static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, sal_uInt16 highlight, sal_Bool bChecked, sal_Bool bEnabled, sal_Bool bIsWindow )
  2857. {
  2858. // draws toolbar button background either native or using a coloured selection
  2859. // if bIsWindow is sal_True, the corresponding item is a control and only a selection border will be drawn
  2860. sal_Bool bNativeOk = sal_False;
  2861. if( !bIsWindow && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
  2862. {
  2863. ImplControlValue aControlValue;
  2864. ControlState nState = 0;
  2865. if ( highlight == 1 ) nState |= CTRL_STATE_PRESSED;
  2866. if ( highlight == 2 ) nState |= CTRL_STATE_ROLLOVER;
  2867. if ( bEnabled ) nState |= CTRL_STATE_ENABLED;
  2868. aControlValue.setTristateVal( bChecked ? BUTTONVALUE_ON : BUTTONVALUE_OFF );
  2869. bNativeOk = pThis->DrawNativeControl( CTRL_TOOLBAR, PART_BUTTON,
  2870. rRect, nState, aControlValue, rtl::OUString() );
  2871. }
  2872. if( !bNativeOk )
  2873. pThis->DrawSelectionBackground( rRect, bIsWindow ? 3 : highlight, bChecked, sal_True, bIsWindow, 2, NULL, NULL );
  2874. }
  2875. void ToolBox::ImplDrawItem( sal_uInt16 nPos, sal_uInt16 nHighlight, sal_Bool bPaint, sal_Bool bLayout )
  2876. {
  2877. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  2878. if( nPos >= mpData->m_aItems.size() )
  2879. return;
  2880. // execute pending paint requests
  2881. ImplCheckUpdate( this );
  2882. ImplDisableFlatButtons();
  2883. SetFillColor();
  2884. ImplToolItem* pItem = &mpData->m_aItems[nPos];
  2885. MetricVector* pVector = bLayout ? &mpData->m_pLayoutData->m_aUnicodeBoundRects : NULL;
  2886. String* pDisplayText = bLayout ? &mpData->m_pLayoutData->m_aDisplayText : NULL;
  2887. if(!pItem->mbEnabled)
  2888. nHighlight = 0;
  2889. // if the rectangle is outside visible area
  2890. if ( pItem->maRect.IsEmpty() )
  2891. return;
  2892. const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
  2893. // no gradient background for items that have a popup open
  2894. sal_Bool bHasOpenPopup = (mpFloatWin != NULL) && (mnDownItemId==pItem->mnId);
  2895. sal_Bool bHighContrastWhite = sal_False;
  2896. // check the face color as highcontrast indicator
  2897. // because the toolbox itself might have a gradient
  2898. if( rStyleSettings.GetFaceColor() == Color( COL_WHITE ) )
  2899. bHighContrastWhite = sal_True;
  2900. // Compute buttons area.
  2901. Size aBtnSize = pItem->maRect.GetSize();
  2902. if( ImplGetSVData()->maNWFData.mbToolboxDropDownSeparate )
  2903. {
  2904. // separate button not for dropdown only where the whole button is painted
  2905. if ( pItem->mnBits & TIB_DROPDOWN &&
  2906. ((pItem->mnBits & TIB_DROPDOWNONLY) != TIB_DROPDOWNONLY) )
  2907. {
  2908. Rectangle aArrowRect = pItem->GetDropDownRect( mbHorz );
  2909. if( aArrowRect.Top() == pItem->maRect.Top() ) // dropdown arrow on right side
  2910. aBtnSize.Width() -= aArrowRect.GetWidth();
  2911. else // dropdown arrow on bottom side
  2912. aBtnSize.Height() -= aArrowRect.GetHeight();
  2913. }
  2914. }
  2915. /* Compute the button/separator rectangle here, we'll need it for
  2916. * both the buttons and the separators. */
  2917. Rectangle aButtonRect( pItem->maRect.TopLeft(), aBtnSize );
  2918. long nOffX = SMALLBUTTON_OFF_NORMAL_X;
  2919. long nOffY = SMALLBUTTON_OFF_NORMAL_Y;
  2920. long nImageOffX = 0;
  2921. long nImageOffY = 0;
  2922. sal_uInt16 nStyle = 0;
  2923. // draw separators in flat style only
  2924. if ( !bLayout &&
  2925. (mnOutStyle & TOOLBOX_STYLE_FLAT) &&
  2926. (pItem->meType == TOOLBOXITEM_SEPARATOR) &&
  2927. nPos > 0
  2928. )
  2929. {
  2930. ImplDrawSeparator( nPos, aButtonRect );
  2931. }
  2932. // do nothing if item is no button or will be displayed as window
  2933. if ( (pItem->meType != TOOLBOXITEM_BUTTON) ||
  2934. (pItem->mbShowWindow && !mbCustomizeMode) )
  2935. return;
  2936. // we need a TBDragMananger to draw the configuration item
  2937. ImplTBDragMgr* pMgr;
  2938. if ( pItem->mnId == mnConfigItem )
  2939. {
  2940. pMgr = ImplGetTBDragMgr();
  2941. pMgr->HideDragRect();
  2942. }
  2943. else
  2944. pMgr = NULL;
  2945. // during configuration mode visible windows will be drawn in a special way
  2946. if ( mbCustomizeMode && pItem->mbShowWindow )
  2947. {
  2948. Font aOldFont = GetFont();
  2949. Color aOldTextColor = GetTextColor();
  2950. SetZoomedPointFont( rStyleSettings.GetAppFont() );
  2951. SetLineColor( Color( COL_BLACK ) );
  2952. SetFillColor( rStyleSettings.GetFieldColor() );
  2953. SetTextColor( rStyleSettings.GetFieldTextColor() );
  2954. if( !bLayout )
  2955. DrawRect( pItem->maRect );
  2956. Size aSize( GetCtrlTextWidth( pItem->maText ), GetTextHeight() );
  2957. Point aPos( pItem->maRect.Left()+2, pItem->maRect.Top() );
  2958. aPos.Y() += (pItem->maRect.GetHeight()-aSize.Height())/2;
  2959. sal_Bool bClip;
  2960. if ( (aSize.Width() > pItem->maRect.GetWidth()-2) ||
  2961. (aSize.Height() > pItem->maRect.GetHeight()-2) )
  2962. {
  2963. bClip = sal_True;
  2964. Rectangle aTempRect( pItem->maRect.Left()+1, pItem->maRect.Top()+1,
  2965. pItem->maRect.Right()-1, pItem->maRect.Bottom()-1 );
  2966. Region aTempRegion( aTempRect );
  2967. SetClipRegion( aTempRegion );
  2968. }
  2969. else
  2970. bClip = sal_False;
  2971. if( bLayout )
  2972. {
  2973. mpData->m_pLayoutData->m_aLineIndices.push_back( mpData->m_pLayoutData->m_aDisplayText.Len() );
  2974. mpData->m_pLayoutData->m_aLineItemIds.push_back( pItem->mnId );
  2975. mpData->m_pLayoutData->m_aLineItemPositions.push_back( nPos );
  2976. }
  2977. DrawCtrlText( aPos, pItem->maText, 0, STRING_LEN, TEXT_DRAW_MNEMONIC, pVector, pDisplayText );
  2978. if ( bClip )
  2979. SetClipRegion();
  2980. SetFont( aOldFont );
  2981. SetTextColor( aOldTextColor );
  2982. // draw Config-Frame if required
  2983. if ( pMgr && !bLayout)
  2984. pMgr->UpdateDragRect();
  2985. return;
  2986. }
  2987. if ( pItem->meState == STATE_CHECK )
  2988. {
  2989. nStyle |= BUTTON_DRAW_CHECKED;
  2990. }
  2991. else if ( pItem->meState == STATE_DONTKNOW )
  2992. {
  2993. nStyle |= BUTTON_DRAW_DONTKNOW;
  2994. }
  2995. if ( nHighlight == 1 )
  2996. {
  2997. nStyle |= BUTTON_DRAW_PRESSED;
  2998. }
  2999. if ( mnOutStyle & TOOLBOX_STYLE_OUTBUTTON )
  3000. {
  3001. nOffX = OUTBUTTON_OFF_NORMAL_X;
  3002. nOffY = OUTBUTTON_OFF_NORMAL_Y;
  3003. if ( nHighlight != 0 )
  3004. {
  3005. nOffX++;
  3006. nOffY++;
  3007. }
  3008. }
  3009. if( ! bLayout )
  3010. {
  3011. if ( mnOutStyle & TOOLBOX_STYLE_FLAT )
  3012. {
  3013. if ( (pItem->meState != STATE_NOCHECK) || !bPaint )
  3014. {
  3015. ImplErase( this, pItem->maRect, nHighlight != 0, bHasOpenPopup );
  3016. }
  3017. }
  3018. else
  3019. {
  3020. if ( mnOutStyle & TOOLBOX_STYLE_OUTBUTTON )
  3021. ImplDrawOutButton( this, aButtonRect, nStyle );
  3022. else
  3023. {
  3024. DecorationView aDecoView( this );
  3025. aDecoView.DrawButton( aButtonRect, nStyle );
  3026. }
  3027. }
  3028. }
  3029. nOffX += pItem->maRect.Left();
  3030. nOffY += pItem->maRect.Top();
  3031. // determine what has to be drawn on the button: image, text or both
  3032. sal_Bool bImage;
  3033. sal_Bool bText;
  3034. ButtonType tmpButtonType = determineButtonType( pItem, meButtonType ); // default to toolbox setting
  3035. pItem->DetermineButtonDrawStyle( tmpButtonType, bImage, bText );
  3036. // compute output values
  3037. long nBtnWidth = aBtnSize.Width()-SMALLBUTTON_HSIZE;
  3038. long nBtnHeight = aBtnSize.Height()-SMALLBUTTON_VSIZE;
  3039. Size aImageSize;
  3040. Size aTxtSize;
  3041. if ( bText )
  3042. {
  3043. aTxtSize.Width() = GetCtrlTextWidth( pItem->maText );
  3044. aTxtSize.Height() = GetTextHeight();
  3045. }
  3046. if ( bImage && ! bLayout )
  3047. {
  3048. const Image* pImage;
  3049. if ( (nHighlight != 0) && (!(pItem->maHighImage)) == sal_False )
  3050. pImage = &(pItem->maHighImage);
  3051. else
  3052. pImage = &(pItem->maImage);
  3053. aImageSize = pImage->GetSizePixel();
  3054. // determine drawing flags
  3055. sal_uInt16 nImageStyle = 0;
  3056. if ( !pItem->mbEnabled || !IsEnabled() )
  3057. nImageStyle |= IMAGE_DRAW_DISABLE;
  3058. // #i35563# the dontknow state indicates different states at the same time
  3059. // which should not be rendered disabled but normal
  3060. // draw the image
  3061. nImageOffX = nOffX;
  3062. nImageOffY = nOffY;
  3063. if ( (pItem->mnBits & (TIB_LEFT|TIB_DROPDOWN)) || bText )
  3064. {
  3065. // left align also to leave space for drop down arrow
  3066. // and when drawing text+image
  3067. // just center in y, except for vertical (ie rotated text)
  3068. if( mbHorz || !bText )
  3069. nImageOffY += (nBtnHeight-aImageSize.Height())/2;
  3070. }
  3071. else
  3072. {
  3073. nImageOffX += (nBtnWidth-aImageSize.Width())/2;
  3074. nImageOffY += (nBtnHeight-aImageSize.Height())/2;
  3075. }
  3076. if ( nHighlight != 0 || (pItem->meState == STATE_CHECK) )
  3077. {
  3078. if( bHasOpenPopup )
  3079. ImplDrawFloatwinBorder( pItem );
  3080. else
  3081. ImplDrawButton( this, aButtonRect, nHighlight, pItem->meState == STATE_CHECK, pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow ? sal_True : sal_False );
  3082. if( nHighlight != 0 )
  3083. {
  3084. if( bHighContrastWhite )
  3085. nImageStyle |= IMAGE_DRAW_COLORTRANSFORM;
  3086. }
  3087. }
  3088. DrawImage( Point( nImageOffX, nImageOffY ), *pImage, nImageStyle );
  3089. }
  3090. // draw the text
  3091. sal_Bool bRotate = sal_False;
  3092. if ( bText )
  3093. {
  3094. long nTextOffX = nOffX;
  3095. long nTextOffY = nOffY;
  3096. // rotate text when vertically docked
  3097. Font aOldFont = GetFont();
  3098. if( pItem->mbVisibleText && !ImplIsFloatingMode() &&
  3099. ((meAlign == WINDOWALIGN_LEFT) || (meAlign == WINDOWALIGN_RIGHT)) )
  3100. {
  3101. bRotate = sal_True;
  3102. Font aRotateFont = aOldFont;
  3103. aRotateFont.SetOrientation( 2700 );
  3104. // center horizontally
  3105. nTextOffX += aTxtSize.Height();
  3106. nTextOffX += (nBtnWidth-aTxtSize.Height())/2;
  3107. // add in image offset
  3108. if( bImage )
  3109. nTextOffY = nImageOffY + aImageSize.Height() + TB_IMAGETEXTOFFSET;
  3110. SetFont( aRotateFont );
  3111. }
  3112. else
  3113. {
  3114. // center vertically
  3115. nTextOffY += (nBtnHeight-aTxtSize.Height())/2;
  3116. // add in image offset
  3117. if( bImage )
  3118. nTextOffX = nImageOffX + aImageSize.Width() + TB_IMAGETEXTOFFSET;
  3119. }
  3120. // draw selection only if not already drawn during image output (see above)
  3121. if ( !bLayout && !bImage && (nHighlight != 0 || (pItem->meState == STATE_CHECK) ) )
  3122. {
  3123. if( bHasOpenPopup )
  3124. ImplDrawFloatwinBorder( pItem );
  3125. else
  3126. ImplDrawButton( this, pItem->maRect, nHighlight, pItem->meState == STATE_CHECK, pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow ? sal_True : sal_False );
  3127. }
  3128. sal_uInt16 nTextStyle = 0;
  3129. if ( !pItem->mbEnabled )
  3130. nTextStyle |= TEXT_DRAW_DISABLE;
  3131. if( bLayout )
  3132. {
  3133. mpData->m_pLayoutData->m_aLineIndices.push_back( mpData->m_pLayoutData->m_aDisplayText.Len() );
  3134. mpData->m_pLayoutData->m_aLineItemIds.push_back( pItem->mnId );
  3135. mpData->m_pLayoutData->m_aLineItemPositions.push_back( nPos );
  3136. }
  3137. DrawCtrlText( Point( nTextOffX, nTextOffY ), pItem->maText,
  3138. 0, STRING_LEN, nTextStyle, pVector, pDisplayText );
  3139. if ( bRotate )
  3140. SetFont( aOldFont );
  3141. }
  3142. if( bLayout )
  3143. return;
  3144. // paint optional drop down arrow
  3145. if ( pItem->mnBits & TIB_DROPDOWN )
  3146. {
  3147. Rectangle aDropDownRect( pItem->GetDropDownRect( mbHorz ) );
  3148. sal_Bool bSetColor = sal_True;
  3149. if ( !pItem->mbEnabled || !IsEnabled() )
  3150. {
  3151. bSetColor = sal_False;
  3152. SetFillColor( rStyleSettings.GetShadowColor() );
  3153. }
  3154. // dropdown only will be painted without inner border
  3155. if( (pItem->mnBits & TIB_DROPDOWNONLY) != TIB_DROPDOWNONLY )
  3156. {
  3157. ImplErase( this, aDropDownRect, nHighlight != 0, bHasOpenPopup );
  3158. if( nHighlight != 0 || (pItem->meState == STATE_CHECK) )
  3159. {
  3160. if( bHasOpenPopup )
  3161. ImplDrawFloatwinBorder( pItem );
  3162. else
  3163. ImplDrawButton( this, aDropDownRect, nHighlight, pItem->meState == STATE_CHECK, pItem->mbEnabled && IsEnabled(), sal_False );
  3164. }
  3165. }
  3166. ImplDrawDropdownArrow( this, aDropDownRect, bSetColor, bRotate );
  3167. }
  3168. // draw config-frame if required
  3169. if ( pMgr )
  3170. pMgr->UpdateDragRect();
  3171. }
  3172. // -----------------------------------------------------------------------
  3173. void ToolBox::ImplDrawFloatwinBorder( ImplToolItem* pItem )
  3174. {
  3175. if ( !pItem->maRect.IsEmpty() )
  3176. {
  3177. Rectangle aRect( mpFloatWin->ImplGetItemEdgeClipRect() );
  3178. aRect.SetPos( AbsoluteScreenToOutputPixel( aRect.TopLeft() ) );
  3179. SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
  3180. Point p1, p2;
  3181. p1 = pItem->maRect.TopLeft();
  3182. p1.X()++;
  3183. p2 = pItem->maRect.TopRight();
  3184. p2.X()--;
  3185. DrawLine( p1, p2);
  3186. p1 = pItem->maRect.BottomLeft();
  3187. p1.X()++;
  3188. p2 = pItem->maRect.BottomRight();
  3189. p2.X()--;
  3190. DrawLine( p1, p2);
  3191. p1 = pItem->maRect.TopLeft();
  3192. p1.Y()++;
  3193. p2 = pItem->maRect.BottomLeft();
  3194. p2.Y()--;
  3195. DrawLine( p1, p2);
  3196. p1 = pItem->maRect.TopRight();
  3197. p1.Y()++;
  3198. p2 = pItem->maRect.BottomRight();
  3199. p2.Y()--;
  3200. DrawLine( p1, p2);
  3201. //DrawRect( pItem->maRect );
  3202. }
  3203. }
  3204. void ToolBox::ImplFloatControl( sal_Bool bStart, FloatingWindow* pFloatWindow )
  3205. {
  3206. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  3207. if ( bStart )
  3208. {
  3209. mpFloatWin = pFloatWindow;
  3210. // redraw item, to trigger drawing of a special border
  3211. ImplDrawItem( mnCurPos, 1 );
  3212. mbDrag = sal_False;
  3213. EndTracking();
  3214. ReleaseMouse();
  3215. }
  3216. else
  3217. {
  3218. mpFloatWin = NULL;
  3219. // if focus is still in this toolbox, then the floater was opened by keyboard
  3220. // draw current item with highlight and keep old state
  3221. sal_Bool bWasKeyboardActivate = mpData->mbDropDownByKeyboard;
  3222. if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
  3223. ImplDrawItem( mnCurPos, bWasKeyboardActivate ? 2 : 0 );
  3224. Deactivate();
  3225. if( !bWasKeyboardActivate )
  3226. {
  3227. mnCurPos = TOOLBOX_ITEM_NOTFOUND;
  3228. mnCurItemId = 0;
  3229. mnHighItemId = 0;
  3230. }
  3231. mnDownItemId = 0;
  3232. }
  3233. }
  3234. // -----------------------------------------------------------------------
  3235. void ToolBox::ShowLine( sal_Bool bNext )
  3236. {
  3237. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  3238. mbFormat = sal_True;
  3239. if ( mpData->mbPageScroll )
  3240. {
  3241. sal_uInt16 delta = mnVisLines;
  3242. if ( bNext )
  3243. {
  3244. mnCurLine = mnCurLine + delta;
  3245. if ( mnCurLine+mnVisLines-1 > mnCurLines )
  3246. mnCurLine = mnCurLines - mnVisLines+1;
  3247. }
  3248. else
  3249. {
  3250. if( mnCurLine >= delta+1 )
  3251. mnCurLine = mnCurLine - delta;
  3252. else
  3253. mnCurLine = 1;
  3254. }
  3255. }
  3256. else
  3257. {
  3258. if ( bNext )
  3259. mnCurLine++;
  3260. else
  3261. mnCurLine--;
  3262. }
  3263. ImplFormat();
  3264. }
  3265. // -----------------------------------------------------------------------
  3266. sal_Bool ToolBox::ImplHandleMouseMove( const MouseEvent& rMEvt, sal_Bool bRepeat )
  3267. {
  3268. Point aMousePos = rMEvt.GetPosPixel();
  3269. // ToolBox active?
  3270. if ( mbDrag && mnCurPos != TOOLBOX_ITEM_NOTFOUND )
  3271. {
  3272. // is the cursor over the item?
  3273. ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
  3274. if ( pItem->maRect.IsInside( aMousePos ) )
  3275. {
  3276. if ( !mnCurItemId )
  3277. {
  3278. ImplDrawItem( mnCurPos, 1 );
  3279. mnCurItemId = pItem->mnId;
  3280. Highlight();
  3281. }
  3282. if ( (pItem->mnBits & TIB_REPEAT) && bRepeat )
  3283. Select();
  3284. }
  3285. else
  3286. {
  3287. if ( mnCurItemId )
  3288. {
  3289. ImplDrawItem( mnCurPos );
  3290. mnCurItemId = 0;
  3291. ImplDrawItem( mnCurPos );
  3292. Highlight();
  3293. }
  3294. }
  3295. return sal_True;
  3296. }
  3297. if ( mbUpper )
  3298. {
  3299. sal_Bool bNewIn = maUpperRect.IsInside( aMousePos );
  3300. if ( bNewIn != mbIn )
  3301. {
  3302. mbIn = bNewIn;
  3303. ImplDrawSpin( mbIn, sal_False );
  3304. }
  3305. return sal_True;
  3306. }
  3307. if ( mbLower )
  3308. {
  3309. sal_Bool bNewIn = maLowerRect.IsInside( aMousePos );
  3310. if ( bNewIn != mbIn )
  3311. {
  3312. mbIn = bNewIn;
  3313. ImplDrawSpin( sal_False, mbIn );
  3314. }
  3315. return sal_True;
  3316. }
  3317. if ( mbNextTool )
  3318. {
  3319. sal_Bool bNewIn = maNextToolRect.IsInside( aMousePos );
  3320. if ( bNewIn != mbIn )
  3321. {
  3322. mbIn = bNewIn;
  3323. ImplDrawNext( mbIn );
  3324. }
  3325. return sal_True;
  3326. }
  3327. return sal_False;
  3328. }
  3329. // -----------------------------------------------------------------------
  3330. sal_Bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent& rMEvt, sal_Bool bCancel )
  3331. {
  3332. ImplDisableFlatButtons();
  3333. // stop eventual running dropdown timer
  3334. if( mnCurPos < mpData->m_aItems.size() &&
  3335. (mpData->m_aItems[mnCurPos].mnBits & TIB_DROPDOWN ) )
  3336. {
  3337. mpData->maDropdownTimer.Stop();
  3338. }
  3339. if ( mbDrag || mbSelection )
  3340. {
  3341. // set mouse data if in selection mode, as then
  3342. // the MouseButtonDown handler cannot be called
  3343. if ( mbSelection )
  3344. {
  3345. mnMouseClicks = rMEvt.GetClicks();
  3346. mnMouseModifier = rMEvt.GetModifier();
  3347. }
  3348. Deactivate();
  3349. if ( mbDrag )
  3350. mbDrag = sal_False;
  3351. else
  3352. {
  3353. mbSelection = sal_False;
  3354. if ( mnCurPos == TOOLBOX_ITEM_NOTFOUND )
  3355. return sal_True;
  3356. }
  3357. // has mouse been released on top of item?
  3358. if( mnCurPos < mpData->m_aItems.size() )
  3359. {
  3360. ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
  3361. if ( pItem->maRect.IsInside( rMEvt.GetPosPixel() ) )
  3362. {
  3363. mnCurItemId = pItem->mnId;
  3364. if ( !bCancel )
  3365. {
  3366. // execute AutoCheck if required
  3367. if ( pItem->mnBits & TIB_AUTOCHECK )
  3368. {
  3369. if ( pItem->mnBits & TIB_RADIOCHECK )
  3370. {
  3371. if ( pItem->meState != STATE_CHECK )
  3372. SetItemState( pItem->mnId, STATE_CHECK );
  3373. }
  3374. else
  3375. {
  3376. if ( pItem->meState != STATE_CHECK )
  3377. pItem->meState = STATE_CHECK;
  3378. else
  3379. pItem->meState = STATE_NOCHECK;
  3380. }
  3381. }
  3382. // do not call Select when Repeat is active, as in this
  3383. // case that was triggered already in MouseButtonDown
  3384. if ( !(pItem->mnBits & TIB_REPEAT) )
  3385. {
  3386. // prevent from being destroyed in the select handler
  3387. ImplDelData aDelData;
  3388. ImplAddDel( &aDelData );
  3389. Select();
  3390. if ( aDelData.IsDelete() )
  3391. return sal_True;
  3392. ImplRemoveDel( &aDelData );
  3393. }
  3394. }
  3395. {
  3396. DBG_CHKTHIS( Window, ImplDbgCheckWindow );
  3397. }
  3398. // Items not destroyed, in Select handler
  3399. if ( mnCurItemId )
  3400. {
  3401. sal_uInt16 nHighlight;
  3402. if ( (mnCurItemId == mnHighItemId) && (mnOutStyle & TOOLBOX_STYLE_FLAT) )
  3403. nHighlight = 2;
  3404. else
  3405. nHighlight = 0;
  3406. // Get current pos for the case that items are inserted/removed
  3407. // in the toolBox
  3408. mnCurPos = GetItemPos( mnCurItemId );
  3409. if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
  3410. {
  3411. ImplDrawItem( mnCurPos, nHighlight );
  3412. Flush();
  3413. }
  3414. }
  3415. }
  3416. }
  3417. mnCurPos = TOOLBOX_ITEM_NOTFOUND;
  3418. mnCurItemId = 0;
  3419. mnDownItemId = 0;
  3420. mnMouseClicks = 0;
  3421. mnMouseModifier = 0;
  3422. return sal_True;
  3423. }
  3424. else if ( mbUpper || mbLower )
  3425. {
  3426. if ( mbIn )
  3427. ShowLine( !mbUpper );
  3428. mbUpper = sal_False;
  3429. mbLower = sal_False;
  3430. mbIn = sal_False;
  3431. ImplDrawSpin( sal_False, sal_False );
  3432. return sal_True;
  3433. }
  3434. else if ( mbNextTool )
  3435. {
  3436. mbNextTool = sal_False;
  3437. mbIn = sal_False;
  3438. ImplDrawNext( sal_False );
  3439. NextToolBox();
  3440. return sal_True;
  3441. }
  3442. return sal_False;
  3443. }
  3444. // -----------------------------------------------------------------------
  3445. void ToolBox::MouseMove( const MouseEvent& rMEvt )
  3446. {
  3447. // pressing a modifier generates synthetic mouse moves
  3448. // ignore it if keyboard selection is acive
  3449. if( HasFocus() && ( rMEvt.GetMode() & MOUSE_MODIFIERCHANGED ) )
  3450. return;
  3451. if ( ImplHandleMouseMove( rMEvt ) )
  3452. return;
  3453. ImplDisableFlatButtons();
  3454. Point aMousePos = rMEvt.GetPosPixel();
  3455. // only highlight when the focus is not inside a child window of a toolbox
  3456. // eg, in a edit control
  3457. // and do not hilight when focus is in a different toolbox
  3458. sal_Bool bDrawHotSpot = sal_True;
  3459. Window *pWin = Application::GetFocusWindow();
  3460. if( pWin && pWin->ImplGetWindowImpl()->mbToolBox && pWin != this )
  3461. bDrawHotSpot = sal_False;
  3462. if ( mbSelection && bDrawHotSpot )
  3463. {
  3464. sal_uInt16 i = 0;
  3465. sal_uInt16 nNewPos = TOOLBOX_ITEM_NOTFOUND;
  3466. // search the item that has been clicked
  3467. std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
  3468. while ( it != mpData->m_aItems.end() )
  3469. {
  3470. // if the mouse position is in this item,
  3471. // we can stop the search
  3472. if ( it->maRect.IsInside( aMousePos ) )
  3473. {
  3474. // select it if it is a button
  3475. if ( it->meType == TOOLBOXITEM_BUTTON )
  3476. {
  3477. // if button is disabled, do not
  3478. // change it
  3479. if ( !it->mbEnabled || it->mbShowWindow )
  3480. nNewPos = mnCurPos;
  3481. else
  3482. nNewPos = i;
  3483. }
  3484. break;
  3485. }
  3486. i++;
  3487. ++it;
  3488. }
  3489. // was a new entery selected ?
  3490. // don't change selection if keyboard selection is active and
  3491. // mouse leaves the toolbox
  3492. if ( nNewPos != mnCurPos && !( HasFocus() && nNewPos == TOOLBOX_ITEM_NOTFOUND ) )
  3493. {
  3494. if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
  3495. {
  3496. ImplDrawItem( mnCurPos );
  3497. ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( mnCurPos ) );
  3498. }
  3499. mnCurPos = nNewPos;
  3500. if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
  3501. {
  3502. mnCurItemId = mnHighItemId = it->mnId;
  3503. ImplDrawItem( mnCurPos, 2 ); // always use shadow effect (2)
  3504. }
  3505. else
  3506. mnCurItemId = mnHighItemId = 0;
  3507. Highlight();
  3508. }
  3509. return;
  3510. }
  3511. if ( mbDragging )
  3512. {
  3513. ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
  3514. pMgr->Dragging( aMousePos );
  3515. return;
  3516. }
  3517. PointerStyle eStyle = POINTER_ARROW;
  3518. // change mouse cursor over drag area
  3519. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
  3520. if( pWrapper && pWrapper->GetDragArea().IsInside( rMEvt.GetPosPixel() ) )
  3521. eStyle = POINTER_MOVE;
  3522. if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
  3523. {
  3524. if ( rMEvt.GetMode() & MOUSE_SIMPLEMOVE )
  3525. {
  3526. sal_uInt16 nLinePtr = ImplTestLineSize( this, rMEvt.GetPosPixel() );
  3527. if ( nLinePtr & DOCK_LINEHSIZE )
  3528. {
  3529. if ( meAlign == WINDOWALIGN_LEFT )
  3530. eStyle = POINTER_WINDOW_ESIZE;
  3531. else
  3532. eStyle = POINTER_WINDOW_WSIZE;
  3533. }
  3534. else if ( nLinePtr & DOCK_LINEVSIZE )
  3535. {
  3536. if ( meAlign == WINDOWALIGN_TOP )
  3537. eStyle = POINTER_WINDOW_SSIZE;
  3538. else
  3539. eStyle = POINTER_WINDOW_NSIZE;
  3540. }
  3541. }
  3542. }
  3543. if ( (eStyle == POINTER_ARROW) && mbCustomizeMode )
  3544. {
  3545. // search the item which was clicked
  3546. std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
  3547. while ( it != mpData->m_aItems.end() )
  3548. {
  3549. // show resize pointer if it is a customize window
  3550. if ( it->mbShowWindow )
  3551. {
  3552. if ( it->maRect.IsInside( aMousePos ) )
  3553. {
  3554. if ( it->maRect.Right()-TB_RESIZE_OFFSET <= aMousePos.X() )
  3555. eStyle = POINTER_HSIZEBAR;
  3556. break;
  3557. }
  3558. }
  3559. ++it;
  3560. }
  3561. }
  3562. if ( bDrawHotSpot && ( ((eStyle == POINTER_ARROW) && (mnOutStyle & TOOLBOX_STYLE_HANDPOINTER)) ||
  3563. (mnOutStyle & TOOLBOX_STYLE_FLAT) || !mnOutStyle ) )
  3564. {
  3565. sal_Bool bClearHigh = sal_True;
  3566. if ( !rMEvt.IsLeaveWindow() && (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
  3567. {
  3568. std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
  3569. while ( it != mpData->m_aItems.end() )
  3570. {
  3571. if ( it->maRect.IsInside( aMousePos ) )
  3572. {
  3573. if ( (it->meType == TOOLBOXITEM_BUTTON) && it->mbEnabled )
  3574. {
  3575. if ( !mnOutStyle || (mnOutStyle & TOOLBOX_STYLE_FLAT) )
  3576. {
  3577. bClearHigh = sal_False;
  3578. if ( mnHighItemId != it->mnId )
  3579. {
  3580. sal_uInt16 nTempPos = sal::static_int_cast<sal_uInt16>(it - mpData->m_aItems.begin());
  3581. if ( mnHighItemId )
  3582. {
  3583. ImplHideFocus();
  3584. sal_uInt16 nPos = GetItemPos( mnHighItemId );
  3585. ImplDrawItem( nPos );
  3586. ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( nPos ) );
  3587. }
  3588. if ( mpData->mbMenubuttonSelected )
  3589. {
  3590. // remove highlight from menubutton
  3591. ImplDrawMenubutton( this, sal_False );
  3592. }
  3593. mnHighItemId = it->mnId;
  3594. ImplDrawItem( nTempPos, 2 );
  3595. ImplShowFocus();
  3596. ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHT );
  3597. }
  3598. }
  3599. if ( mnOutStyle & TOOLBOX_STYLE_HANDPOINTER )
  3600. eStyle = POINTER_REFHAND;
  3601. }
  3602. break;
  3603. }
  3604. ++it;
  3605. }
  3606. }
  3607. // only clear highlight when focus is not in toolbar
  3608. sal_Bool bMenuButtonHit = mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems();
  3609. if ( bClearHigh || bMenuButtonHit )
  3610. {
  3611. if ( !bMenuButtonHit && mpData->mbMenubuttonSelected )
  3612. {
  3613. // remove highlight from menubutton
  3614. ImplDrawMenubutton( this, sal_False );
  3615. }
  3616. if( mnHighItemId )
  3617. {
  3618. sal_uInt16 nClearPos = GetItemPos( mnHighItemId );
  3619. if ( nClearPos != TOOLBOX_ITEM_NOTFOUND )
  3620. {
  3621. ImplDrawItem( nClearPos, (nClearPos == mnCurPos) ? 1 : 0 );
  3622. if( nClearPos != mnCurPos )
  3623. ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( nClearPos ) );
  3624. }
  3625. ImplHideFocus();
  3626. mnHighItemId = 0;
  3627. }
  3628. if( bMenuButtonHit )
  3629. {
  3630. ImplDrawMenubutton( this, sal_True );
  3631. }
  3632. }
  3633. }
  3634. if ( meLastStyle != eStyle )
  3635. {
  3636. meLastStyle = eStyle;
  3637. Pointer aPtr( eStyle );
  3638. SetPointer( aPtr );
  3639. }
  3640. DockingWindow::MouseMove( rMEvt );
  3641. }
  3642. // -----------------------------------------------------------------------
  3643. void ToolBox::MouseButtonDown( const MouseEvent& rMEvt )
  3644. {
  3645. // only trigger toolbox for left mouse button and when
  3646. // we're not in normal operation
  3647. if ( rMEvt.IsLeft() && !mbDrag && (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
  3648. {
  3649. // call activate already here, as items could
  3650. // be exchanged
  3651. Activate();
  3652. // update ToolBox here, such that user knows it
  3653. if ( mbFormat )
  3654. {
  3655. ImplFormat();
  3656. Update();
  3657. }
  3658. Point aMousePos = rMEvt.GetPosPixel();
  3659. sal_uInt16 i = 0;
  3660. sal_uInt16 nNewPos = TOOLBOX_ITEM_NOTFOUND;
  3661. // search for item that was clicked
  3662. std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
  3663. while ( it != mpData->m_aItems.end() )
  3664. {
  3665. // is this the item?
  3666. if ( it->maRect.IsInside( aMousePos ) )
  3667. {
  3668. // do nothing if it is a separator or
  3669. // if the item has been disabled
  3670. if ( (it->meType == TOOLBOXITEM_BUTTON) &&
  3671. (!it->mbShowWindow || mbCustomizeMode) )
  3672. nNewPos = i;
  3673. break;
  3674. }
  3675. i++;
  3676. ++it;
  3677. }
  3678. // item found
  3679. if ( nNewPos != TOOLBOX_ITEM_NOTFOUND )
  3680. {
  3681. if ( mbCustomize )
  3682. {
  3683. if ( rMEvt.IsMod2() || mbCustomizeMode )
  3684. {
  3685. Deactivate();
  3686. ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
  3687. Rectangle aItemRect = GetItemRect( it->mnId );
  3688. mnConfigItem = it->mnId;
  3689. sal_Bool bResizeItem;
  3690. if ( mbCustomizeMode && it->mbShowWindow &&
  3691. (it->maRect.Right()-TB_RESIZE_OFFSET <= aMousePos.X()) )
  3692. bResizeItem = sal_True;
  3693. else
  3694. bResizeItem = sal_False;
  3695. pMgr->StartDragging( this, aMousePos, aItemRect, 0, bResizeItem );
  3696. return;
  3697. }
  3698. }
  3699. if ( !it->mbEnabled )
  3700. {
  3701. Deactivate();
  3702. return;
  3703. }
  3704. // update actual data
  3705. sal_uInt16 nTrackFlags = 0;
  3706. mnCurPos = i;
  3707. mnCurItemId = it->mnId;
  3708. mnDownItemId = mnCurItemId;
  3709. mnMouseClicks = rMEvt.GetClicks();
  3710. mnMouseModifier = rMEvt.GetModifier();
  3711. if ( it->mnBits & TIB_REPEAT )
  3712. nTrackFlags |= STARTTRACK_BUTTONREPEAT;
  3713. if ( mbSelection )
  3714. {
  3715. ImplDrawItem( mnCurPos, 1 );
  3716. Highlight();
  3717. }
  3718. else
  3719. {
  3720. // update bDrag here, as it is evaluated in the EndSelection
  3721. mbDrag = sal_True;
  3722. // on double-click: only call the handler, but do so before the button
  3723. // is hit, as in the handler dragging
  3724. // can be terminated
  3725. if ( rMEvt.GetClicks() == 2 )
  3726. DoubleClick();
  3727. if ( mbDrag )
  3728. {
  3729. ImplDrawItem( mnCurPos, 1 );
  3730. Highlight();
  3731. }
  3732. // was dropdown arrow pressed
  3733. if( (it->mnBits & TIB_DROPDOWN) )
  3734. {
  3735. if( ( (it->mnBits & TIB_DROPDOWNONLY) == TIB_DROPDOWNONLY) || it->GetDropDownRect( mbHorz ).IsInside( aMousePos ))
  3736. {
  3737. // dropdownonly always triggers the dropdown handler, over the whole button area
  3738. // the drop down arrow should not trigger the item action
  3739. mpData->mbDropDownByKeyboard = sal_False;
  3740. GetDropdownClickHdl().Call( this );
  3741. // do not reset data if the dropdown handler opened a floating window
  3742. // see ImplFloatControl()
  3743. if( mpFloatWin == NULL )
  3744. {
  3745. // no floater was opened
  3746. Deactivate();
  3747. ImplDrawItem( mnCurPos, 0 );
  3748. mnCurPos = TOOLBOX_ITEM_NOTFOUND;
  3749. mnCurItemId = 0;
  3750. mnDownItemId = 0;
  3751. mnMouseClicks = 0;
  3752. mnMouseModifier = 0;
  3753. mnHighItemId = 0;
  3754. }
  3755. return;
  3756. }
  3757. else // activate long click timer
  3758. mpData->maDropdownTimer.Start();
  3759. }
  3760. // call Click handler
  3761. if ( rMEvt.GetClicks() != 2 )
  3762. Click();
  3763. // also call Select handler at repeat
  3764. if ( nTrackFlags & STARTTRACK_BUTTONREPEAT )
  3765. Select();
  3766. // if the actions was not aborted in Click handler
  3767. if ( mbDrag )
  3768. StartTracking( nTrackFlags );
  3769. }
  3770. // if mouse was clicked over an item we
  3771. // can abort here
  3772. return;
  3773. }
  3774. Deactivate();
  3775. // menu button hit ?
  3776. if( mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems() )
  3777. {
  3778. ExecuteCustomMenu();
  3779. return;
  3780. }
  3781. // check scroll- and next-buttons here
  3782. if ( maUpperRect.IsInside( aMousePos ) )
  3783. {
  3784. if ( mnCurLine > 1 )
  3785. {
  3786. StartTracking();
  3787. mbUpper = sal_True;
  3788. mbIn = sal_True;
  3789. ImplDrawSpin( sal_True, sal_False );
  3790. }
  3791. return;
  3792. }
  3793. if ( maLowerRect.IsInside( aMousePos ) )
  3794. {
  3795. if ( mnCurLine+mnVisLines-1 < mnCurLines )
  3796. {
  3797. StartTracking();
  3798. mbLower = sal_True;
  3799. mbIn = sal_True;
  3800. ImplDrawSpin( sal_False, sal_True );
  3801. }
  3802. return;
  3803. }
  3804. if ( maNextToolRect.IsInside( aMousePos ) )
  3805. {
  3806. StartTracking();
  3807. mbNextTool = sal_True;
  3808. mbIn = sal_True;
  3809. ImplDrawNext( sal_True );
  3810. return;
  3811. }
  3812. // Linesizing testen
  3813. if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
  3814. {
  3815. sal_uInt16 nLineMode = ImplTestLineSize( this, aMousePos );
  3816. if ( nLineMode )
  3817. {
  3818. ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
  3819. // call handler, such that we can set the
  3820. // dock rectangles
  3821. StartDocking();
  3822. Point aPos = GetParent()->OutputToScreenPixel( GetPosPixel() );
  3823. Size aSize = GetSizePixel();
  3824. aPos = ScreenToOutputPixel( aPos );
  3825. // start dragging
  3826. pMgr->StartDragging( this, aMousePos, Rectangle( aPos, aSize ),
  3827. nLineMode, sal_False );
  3828. return;
  3829. }
  3830. }
  3831. // no item, then only click or double click
  3832. if ( rMEvt.GetClicks() == 2 )
  3833. DoubleClick();
  3834. else
  3835. Click();
  3836. }
  3837. if ( !mbDrag && !mbSelection && (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
  3838. DockingWindow::MouseButtonDown( rMEvt );
  3839. }
  3840. // -----------------------------------------------------------------------
  3841. void ToolBox::MouseButtonUp( const MouseEvent& rMEvt )
  3842. {
  3843. if ( ImplHandleMouseButtonUp( rMEvt ) )
  3844. return;
  3845. if ( mbDragging && (rMEvt.IsLeft() || mbCommandDrag) )
  3846. {
  3847. ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
  3848. pMgr->EndDragging();
  3849. return;
  3850. }
  3851. mbCommandDrag = sal_False;
  3852. DockingWindow::MouseButtonUp( rMEvt );
  3853. }
  3854. // -----------------------------------------------------------------------
  3855. void ToolBox::Tracking( const TrackingEvent& rTEvt )
  3856. {
  3857. ImplDelData aDelData;
  3858. ImplAddDel( &aDelData );
  3859. if ( rTEvt.IsTrackingEnded() )
  3860. ImplHandleMouseButtonUp( rTEvt.GetMouseEvent(), rTEvt.IsTrackingCanceled() );
  3861. else
  3862. ImplHandleMouseMove( rTEvt.GetMouseEvent(), rTEvt.IsTrackingRepeat() );
  3863. if ( aDelData.IsDelete() )
  3864. // toolbox was deleted
  3865. return;
  3866. ImplRemoveDel( &aDelData );
  3867. DockingWindow::Tracking( rTEvt );
  3868. }
  3869. // -----------------------------------------------------------------------
  3870. void ToolBox::Paint( const Rectangle& rPaintRect )
  3871. {
  3872. if( mpData->mbIsPaintLocked )
  3873. return;
  3874. if ( rPaintRect == Rectangle( 0, 0, mnDX-1, mnDY-1 ) )
  3875. mbFullPaint = sal_True;
  3876. ImplFormat();
  3877. mbFullPaint = sal_False;
  3878. ImplDrawBackground( this, rPaintRect );
  3879. if ( (mnWinStyle & WB_BORDER) && !ImplIsFloatingMode() )
  3880. ImplDrawBorder( this );
  3881. if( !ImplIsFloatingMode() )
  3882. ImplDrawGrip( this );
  3883. ImplDrawMenubutton( this, mpData->mbMenubuttonSelected );
  3884. // draw SpinButtons
  3885. if ( mnWinStyle & WB_SCROLL )
  3886. {
  3887. if ( mnCurLines > mnLines )
  3888. ImplDrawSpin( sal_False, sal_False );
  3889. }
  3890. // draw NextButton
  3891. ImplDrawNext( sal_False );
  3892. // draw buttons
  3893. sal_uInt16 nHighPos;
  3894. if ( mnHighItemId )
  3895. nHighPos = GetItemPos( mnHighItemId );
  3896. else
  3897. nHighPos = TOOLBOX_ITEM_NOTFOUND;
  3898. sal_uInt16 nCount = (sal_uInt16)mpData->m_aItems.size();
  3899. for( sal_uInt16 i = 0; i < nCount; i++ )
  3900. {
  3901. ImplToolItem* pItem = &mpData->m_aItems[i];
  3902. // only draw when the rectangle is in the draw rectangle
  3903. if ( !pItem->maRect.IsEmpty() && rPaintRect.IsOver( pItem->maRect ) )
  3904. {
  3905. sal_uInt16 nHighlight = 0;
  3906. if ( i == mnCurPos )
  3907. nHighlight = 1;
  3908. else if ( i == nHighPos )
  3909. nHighlight = 2;
  3910. ImplDrawItem( i, nHighlight );
  3911. }
  3912. }
  3913. ImplShowFocus();
  3914. }
  3915. // -----------------------------------------------------------------------
  3916. void ToolBox::Move()
  3917. {
  3918. DockingWindow::Move();
  3919. }
  3920. // -----------------------------------------------------------------------
  3921. void ToolBox::Resize()
  3922. {
  3923. Size aSize = GetOutputSizePixel();
  3924. // #i31422# some WindowManagers send (0,0) sizes when
  3925. // switching virtual desktops - ignore this and avoid reformatting
  3926. if( !aSize.Width() && !aSize.Height() )
  3927. return;
  3928. long nOldDX = mnDX;
  3929. long nOldDY = mnDY;
  3930. mnDX = aSize.Width();
  3931. mnDY = aSize.Height();
  3932. mnLastResizeDY = 0;
  3933. // invalidate everything to have gradient backgrounds properly drawn
  3934. Invalidate();
  3935. // re-format or re-draw
  3936. if ( mbScroll )
  3937. {
  3938. if ( !mbFormat )
  3939. {
  3940. mbFormat = sal_True;
  3941. if( IsReallyVisible() )
  3942. ImplFormat( sal_True );
  3943. }
  3944. }
  3945. // redraw border
  3946. if ( mnWinStyle & WB_BORDER )
  3947. {
  3948. // as otherwise, when painting we might think we have to re-draw everything
  3949. if ( mbFormat && IsReallyVisible() )
  3950. Invalidate();
  3951. else
  3952. {
  3953. if ( mnRightBorder )
  3954. {
  3955. if ( nOldDX > mnDX )
  3956. Invalidate( Rectangle( mnDX-mnRightBorder-1, 0, mnDX, mnDY ) );
  3957. else
  3958. Invalidate( Rectangle( nOldDX-mnRightBorder-1, 0, nOldDX, nOldDY ) );
  3959. }
  3960. if ( mnBottomBorder )
  3961. {
  3962. if ( nOldDY > mnDY )
  3963. Invalidate( Rectangle( 0, mnDY-mnBottomBorder-1, mnDX, mnDY ) );
  3964. else
  3965. Invalidate( Rectangle( 0, nOldDY-mnBottomBorder-1, nOldDX, nOldDY ) );
  3966. }
  3967. }
  3968. }
  3969. }
  3970. // -----------------------------------------------------------------------
  3971. const XubString& ToolBox::ImplGetHelpText( sal_uInt16 nItemId ) const
  3972. {
  3973. ImplToolItem* pItem = ImplGetItem( nItemId );
  3974. if ( pItem )
  3975. {
  3976. if ( !pItem->maHelpText.Len() && ( !pItem->maHelpId.isEmpty() || pItem->maCommandStr.Len() ))
  3977. {
  3978. Help* pHelp = Application::GetHelp();
  3979. if ( pHelp )
  3980. {
  3981. if ( pItem->maCommandStr.Len() )
  3982. pItem->maHelpText = pHelp->GetHelpText( pItem->maCommandStr, this );
  3983. if ( !pItem->maHelpText.Len() && !pItem->maHelpId.isEmpty() )
  3984. pItem->maHelpText = pHelp->GetHelpText( rtl::OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
  3985. }
  3986. }
  3987. return pItem->maHelpText;
  3988. }
  3989. else
  3990. return ImplGetSVEmptyStr();
  3991. }
  3992. // -----------------------------------------------------------------------
  3993. void ToolBox::RequestHelp( const HelpEvent& rHEvt )
  3994. {
  3995. sal_uInt16 nItemId;
  3996. Point aHelpPos;
  3997. if( !rHEvt.KeyboardActivated() )
  3998. {
  3999. nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
  4000. aHelpPos = rHEvt.GetMousePosPixel();
  4001. }
  4002. else
  4003. {
  4004. if( !mnHighItemId )
  4005. return;
  4006. else
  4007. nItemId = mnHighItemId;
  4008. Rectangle aRect( GetItemRect( nItemId ) );
  4009. if( aRect.IsEmpty() )
  4010. return;
  4011. else
  4012. aHelpPos = OutputToScreenPixel( aRect.Center() );
  4013. }
  4014. if ( nItemId )
  4015. {
  4016. if ( rHEvt.GetMode() & (HELPMODE_BALLOON | HELPMODE_QUICK) )
  4017. {
  4018. // get rectangle
  4019. Rectangle aTempRect = GetItemRect( nItemId );
  4020. Point aPt = OutputToScreenPixel( aTempRect.TopLeft() );
  4021. aTempRect.Left() = aPt.X();
  4022. aTempRect.Top() = aPt.Y();
  4023. aPt = OutputToScreenPixel( aTempRect.BottomRight() );
  4024. aTempRect.Right() = aPt.X();
  4025. aTempRect.Bottom() = aPt.Y();
  4026. // get text and display it
  4027. XubString aStr = GetQuickHelpText( nItemId );
  4028. const XubString& rHelpStr = GetHelpText( nItemId );
  4029. if ( !aStr.Len() )
  4030. aStr = MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId ) );
  4031. if ( rHEvt.GetMode() & HELPMODE_BALLOON )
  4032. {
  4033. if ( rHelpStr.Len() )
  4034. aStr = rHelpStr;
  4035. Help::ShowBalloon( this, aHelpPos, aTempRect, aStr );
  4036. }
  4037. else
  4038. Help::ShowQuickHelp( this, aTempRect, aStr, rHelpStr, QUICKHELP_CTRLTEXT );
  4039. return;
  4040. }
  4041. else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
  4042. {
  4043. String aCommand = GetItemCommand( nItemId );
  4044. rtl::OString aHelpId( GetHelpId( nItemId ) );
  4045. if ( aCommand.Len() || !aHelpId.isEmpty() )
  4046. {
  4047. // If help is available then trigger it
  4048. Help* pHelp = Application::GetHelp();
  4049. if ( pHelp )
  4050. {
  4051. if ( aCommand.Len() )
  4052. pHelp->Start( aCommand, this );
  4053. else if ( !aHelpId.isEmpty() )
  4054. pHelp->Start( rtl::OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ), this );
  4055. }
  4056. return;
  4057. }
  4058. }
  4059. }
  4060. else if ( maNextToolRect.IsInside( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) ) )
  4061. {
  4062. if ( rHEvt.GetMode() & (HELPMODE_BALLOON | HELPMODE_QUICK) )
  4063. {
  4064. // get rectangle
  4065. Rectangle aTempRect = maNextToolRect;
  4066. Point aPt = OutputToScreenPixel( aTempRect.TopLeft() );
  4067. aTempRect.Left() = aPt.X();
  4068. aTempRect.Top() = aPt.Y();
  4069. aPt = OutputToScreenPixel( aTempRect.BottomRight() );
  4070. aTempRect.Right() = aPt.X();
  4071. aTempRect.Bottom() = aPt.Y();
  4072. if ( rHEvt.GetMode() & HELPMODE_BALLOON )
  4073. Help::ShowBalloon( this, aTempRect.Center(), aTempRect, maNextToolBoxStr );
  4074. else
  4075. Help::ShowQuickHelp( this, aTempRect, maNextToolBoxStr );
  4076. return;
  4077. }
  4078. }
  4079. DockingWindow::RequestHelp( rHEvt );
  4080. }
  4081. // -----------------------------------------------------------------------
  4082. long ToolBox::Notify( NotifyEvent& rNEvt )
  4083. {
  4084. if ( rNEvt.GetType() == EVENT_KEYINPUT )
  4085. {
  4086. KeyEvent aKEvt = *rNEvt.GetKeyEvent();
  4087. KeyCode aKeyCode = aKEvt.GetKeyCode();
  4088. sal_uInt16 nKeyCode = aKeyCode.GetCode();
  4089. switch( nKeyCode )
  4090. {
  4091. case KEY_TAB:
  4092. {
  4093. // internal TAB cycling only if parent is not a dialog or if we are the ony child
  4094. // otherwise the dialog control will take over
  4095. sal_Bool bNoTabCycling = ( ( ImplGetParent()->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL) ) == WB_DIALOGCONTROL &&
  4096. ImplGetParent()->GetChildCount() != 1 );
  4097. if( bNoTabCycling && ! (GetStyle() & WB_FORCETABCYCLE) )
  4098. return DockingWindow::Notify( rNEvt );
  4099. else if( ImplChangeHighlightUpDn( aKeyCode.IsShift() ? sal_True : sal_False , bNoTabCycling ) )
  4100. return sal_False;
  4101. else
  4102. return DockingWindow::Notify( rNEvt );
  4103. }
  4104. default:
  4105. break;
  4106. };
  4107. }
  4108. else if( rNEvt.GetType() == EVENT_GETFOCUS )
  4109. {
  4110. if( rNEvt.GetWindow() == this )
  4111. {
  4112. // the toolbar itself got the focus
  4113. if( mnLastFocusItemId != 0 )
  4114. {
  4115. // restore last item
  4116. ImplChangeHighlight( ImplGetItem( mnLastFocusItemId ) );
  4117. mnLastFocusItemId = 0;
  4118. }
  4119. else if( (GetGetFocusFlags() & (GETFOCUS_BACKWARD|GETFOCUS_TAB) ) == (GETFOCUS_BACKWARD|GETFOCUS_TAB))
  4120. // Shift-TAB was pressed in the parent
  4121. ImplChangeHighlightUpDn( sal_False );
  4122. else
  4123. ImplChangeHighlightUpDn( sal_True );
  4124. mnLastFocusItemId = 0;
  4125. return true;
  4126. }
  4127. else
  4128. {
  4129. // a child window got the focus so update current item to
  4130. // allow for proper lose focus handling in keyboard navigation
  4131. std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
  4132. while( it != mpData->m_aItems.end() )
  4133. {
  4134. if ( it->mbVisible )
  4135. {
  4136. if ( it->mpWindow && it->mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
  4137. {
  4138. mnHighItemId = it->mnId;
  4139. break;
  4140. }
  4141. }
  4142. ++it;
  4143. }
  4144. return DockingWindow::Notify( rNEvt );
  4145. }
  4146. }
  4147. else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
  4148. {
  4149. // deselect
  4150. ImplHideFocus();
  4151. mnHighItemId = 0;
  4152. mnCurPos = TOOLBOX_ITEM_NOTFOUND;
  4153. }
  4154. return DockingWindow::Notify( rNEvt );
  4155. }
  4156. // -----------------------------------------------------------------------
  4157. void ToolBox::Command( const CommandEvent& rCEvt )
  4158. {
  4159. // depict StartDrag on MouseButton/Left/Alt
  4160. if ( (rCEvt.GetCommand() == COMMAND_STARTDRAG) && rCEvt.IsMouseEvent() &&
  4161. mbCustomize && !mbDragging && !mbDrag && !mbSelection &&
  4162. (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
  4163. {
  4164. // We only allow dragging of items. Therefore, we have to check
  4165. // if an item was clicked, otherwise we could move the window, and
  4166. // this is unwanted.
  4167. // We only do this in customize mode, as otherwise
  4168. // items could be moved accidentally
  4169. if ( mbCustomizeMode )
  4170. {
  4171. Point aMousePos = rCEvt.GetMousePosPixel();
  4172. std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
  4173. while ( it != mpData->m_aItems.end() )
  4174. {
  4175. // is this the item?
  4176. if ( it->maRect.IsInside( aMousePos ) )
  4177. {
  4178. // do nothing if it is a separator or
  4179. // the item has been disabled
  4180. if ( (it->meType == TOOLBOXITEM_BUTTON) &&
  4181. !it->mbShowWindow )
  4182. mbCommandDrag = sal_True;
  4183. break;
  4184. }
  4185. ++it;
  4186. }
  4187. if ( mbCommandDrag )
  4188. {
  4189. MouseEvent aMEvt( aMousePos, 1, MOUSE_SIMPLECLICK,
  4190. MOUSE_LEFT, KEY_MOD2 );
  4191. ToolBox::MouseButtonDown( aMEvt );
  4192. return;
  4193. }
  4194. }
  4195. }
  4196. else if ( rCEvt.GetCommand() == COMMAND_WHEEL )
  4197. {
  4198. if ( (mnCurLine > 1) || (mnCurLine+mnVisLines-1 < mnCurLines) )
  4199. {
  4200. const CommandWheelData* pData = rCEvt.GetWheelData();
  4201. if ( pData->GetMode() == COMMAND_WHEEL_SCROLL )
  4202. {
  4203. if ( (mnCurLine > 1) && (pData->GetDelta() > 0) )
  4204. ShowLine( sal_False );
  4205. else if ( (mnCurLine+mnVisLines-1 < mnCurLines) && (pData->GetDelta() < 0) )
  4206. ShowLine( sal_True );
  4207. ImplDrawSpin( sal_False, sal_False );
  4208. return;
  4209. }
  4210. }
  4211. }
  4212. DockingWindow::Command( rCEvt );
  4213. }
  4214. // -----------------------------------------------------------------------
  4215. void ToolBox::StateChanged( StateChangedType nType )
  4216. {
  4217. DockingWindow::StateChanged( nType );
  4218. if ( nType == STATE_CHANGE_INITSHOW )
  4219. ImplFormat();
  4220. else if ( nType == STATE_CHANGE_ENABLE )
  4221. ImplUpdateItem();
  4222. else if ( nType == STATE_CHANGE_UPDATEMODE )
  4223. {
  4224. if ( IsUpdateMode() )
  4225. Invalidate();
  4226. }
  4227. else if ( (nType == STATE_CHANGE_ZOOM) ||
  4228. (nType == STATE_CHANGE_CONTROLFONT) )
  4229. {
  4230. mbCalc = sal_True;
  4231. mbFormat = sal_True;
  4232. ImplInitSettings( sal_True, sal_False, sal_False );
  4233. Invalidate();
  4234. }
  4235. else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
  4236. {
  4237. ImplInitSettings( sal_False, sal_True, sal_False );
  4238. Invalidate();
  4239. }
  4240. else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
  4241. {
  4242. ImplInitSettings( sal_False, sal_False, sal_True ); // font, foreground, background
  4243. Invalidate();
  4244. }
  4245. }
  4246. // -----------------------------------------------------------------------
  4247. void ToolBox::DataChanged( const DataChangedEvent& rDCEvt )
  4248. {
  4249. DockingWindow::DataChanged( rDCEvt );
  4250. if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
  4251. (rDCEvt.GetType() == DATACHANGED_FONTS) ||
  4252. (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
  4253. ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
  4254. (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
  4255. {
  4256. mbCalc = sal_True;
  4257. mbFormat = sal_True;
  4258. ImplInitSettings( sal_True, sal_True, sal_True );
  4259. Invalidate();
  4260. }
  4261. }
  4262. // -----------------------------------------------------------------------
  4263. sal_Bool ToolBox::PrepareToggleFloatingMode()
  4264. {
  4265. return DockingWindow::PrepareToggleFloatingMode();
  4266. }
  4267. // -----------------------------------------------------------------------
  4268. void ToolBox::ToggleFloatingMode()
  4269. {
  4270. DockingWindow::ToggleFloatingMode();
  4271. sal_Bool mbOldHorz = mbHorz;
  4272. if ( ImplIsFloatingMode() )
  4273. {
  4274. mbHorz = sal_True;
  4275. meAlign = WINDOWALIGN_TOP;
  4276. mbScroll = sal_True;
  4277. if( mbOldHorz != mbHorz )
  4278. mbCalc = sal_True; // orientation was changed !
  4279. ImplSetMinMaxFloatSize( this );
  4280. SetOutputSizePixel( ImplCalcFloatSize( this, mnFloatLines ) );
  4281. }
  4282. else
  4283. {
  4284. mbScroll = (mnWinStyle & WB_SCROLL) ? sal_True : sal_False;
  4285. if ( (meAlign == WINDOWALIGN_TOP) || (meAlign == WINDOWALIGN_BOTTOM) )
  4286. mbHorz = sal_True;
  4287. else
  4288. mbHorz = sal_False;
  4289. // set focus back to document
  4290. ImplGetFrameWindow()->GetWindow( WINDOW_CLIENT )->GrabFocus();
  4291. }
  4292. if( mbOldHorz != mbHorz )
  4293. {
  4294. // if orientation changes, the toolbox has to be initialized again
  4295. // to update the direction of the gradient
  4296. mbCalc = sal_True;
  4297. ImplInitSettings( sal_True, sal_True, sal_True );
  4298. }
  4299. mbFormat = sal_True;
  4300. ImplFormat();
  4301. }
  4302. // -----------------------------------------------------------------------
  4303. void ToolBox::StartDocking()
  4304. {
  4305. meDockAlign = meAlign;
  4306. mnDockLines = mnLines;
  4307. mbLastFloatMode = ImplIsFloatingMode();
  4308. DockingWindow::StartDocking();
  4309. }
  4310. // -----------------------------------------------------------------------
  4311. sal_Bool ToolBox::Docking( const Point& rPos, Rectangle& rRect )
  4312. {
  4313. // do nothing during dragging, it was calculated before
  4314. if ( mbDragging )
  4315. return sal_False;
  4316. sal_Bool bFloatMode = sal_False;
  4317. DockingWindow::Docking( rPos, rRect );
  4318. // if the mouse is outside the area, it can only become a floating window
  4319. Rectangle aDockingRect( rRect );
  4320. if ( !ImplIsFloatingMode() )
  4321. {
  4322. // don't use tracking rectangle for alignment check, because it will be too large
  4323. // to get a floating mode as result - switch to floating size
  4324. // so the calculation only depends on the position of the rectangle, not the current
  4325. // docking state of the window
  4326. sal_uInt16 nTemp = 0;
  4327. aDockingRect.SetSize( ImplCalcFloatSize( this, nTemp ) );
  4328. // in this mode docking is never done by keyboard, so it's OK to use the mouse position
  4329. aDockingRect.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
  4330. }
  4331. Rectangle aIntersection = maOutDockRect.GetIntersection( aDockingRect );
  4332. if ( !aIntersection.IsEmpty() && !IsDockingPrevented() )
  4333. {
  4334. Rectangle aInRect = maInDockRect;
  4335. Size aDockSize;
  4336. aDockSize.Width() = ImplCalcSize( this, mnLines, TB_CALCMODE_VERT ).Width();
  4337. aDockSize.Height() = ImplCalcSize( this, mnLines, TB_CALCMODE_HORZ ).Height();
  4338. aInRect.Left() += aDockSize.Width()/2;
  4339. aInRect.Top() += aDockSize.Height()/2;
  4340. aInRect.Right() -= aDockSize.Width()/2;
  4341. aInRect.Bottom() -= aDockSize.Height()/2;
  4342. // if the window is too small, use the complete InDock-Rect
  4343. if ( aInRect.Left() >= aInRect.Right() )
  4344. {
  4345. aInRect.Left() = maInDockRect.Left();
  4346. aInRect.Right() = maInDockRect.Right();
  4347. }
  4348. if ( aInRect.Top() >= aInRect.Bottom() )
  4349. {
  4350. aInRect.Top() = maInDockRect.Top();
  4351. aInRect.Bottom() = maInDockRect.Bottom();
  4352. }
  4353. // if the mouse is outside the Dock area, it can only
  4354. // become a floating window
  4355. Rectangle aIntersect = aInRect.GetIntersection( aDockingRect );
  4356. if ( aIntersect == aDockingRect )
  4357. bFloatMode = sal_True;
  4358. else
  4359. {
  4360. // docking rectangle is in the "sensible area"
  4361. Point aPos = aDockingRect.TopLeft();
  4362. Point aInPosTL( aPos.X()-aInRect.Left(), aPos.Y()-aInRect.Top() );
  4363. Point aInPosBR( aPos.X()-aInRect.Left() + aDockingRect.GetWidth(), aPos.Y()-aInRect.Top() + aDockingRect.GetHeight() );
  4364. Size aInSize = aInRect.GetSize();
  4365. if ( aInPosTL.X() <= 0 )
  4366. meDockAlign = WINDOWALIGN_LEFT;
  4367. else if ( aInPosTL.Y() <= 0)
  4368. meDockAlign = WINDOWALIGN_TOP;
  4369. else if ( aInPosBR.X() >= aInSize.Width() )
  4370. meDockAlign = WINDOWALIGN_RIGHT;
  4371. else if ( aInPosBR.Y() >= aInSize.Height() )
  4372. meDockAlign = WINDOWALIGN_BOTTOM;
  4373. // update the Dock size if Dock-Align was changed
  4374. if ( (meDockAlign == WINDOWALIGN_TOP) || (meDockAlign == WINDOWALIGN_BOTTOM) )
  4375. aDockSize.Width() = maInDockRect.GetWidth();
  4376. else
  4377. aDockSize.Height() = maInDockRect.GetHeight();
  4378. aDockingRect.SetSize( aDockSize );
  4379. Point aPosTL( maInDockRect.TopLeft() );
  4380. switch ( meDockAlign )
  4381. {
  4382. case WINDOWALIGN_TOP :
  4383. aDockingRect.SetPos( aPosTL );
  4384. break;
  4385. case WINDOWALIGN_LEFT :
  4386. aDockingRect.SetPos( aPosTL );
  4387. break;
  4388. case WINDOWALIGN_BOTTOM :
  4389. {
  4390. Point aPosBL( maInDockRect.BottomLeft() );
  4391. aPosBL.Y() -= aDockingRect.GetHeight();
  4392. aDockingRect.SetPos( aPosBL );
  4393. break;
  4394. }
  4395. case WINDOWALIGN_RIGHT :
  4396. {
  4397. Point aPosTR( maInDockRect.TopRight() );
  4398. aPosTR.X() -= aDockingRect.GetWidth();
  4399. aDockingRect.SetPos( aPosTR );
  4400. break;
  4401. }
  4402. }
  4403. }
  4404. }
  4405. else
  4406. bFloatMode = sal_True;
  4407. if ( bFloatMode )
  4408. {
  4409. meDockAlign = meAlign;
  4410. if ( !mbLastFloatMode )
  4411. {
  4412. sal_uInt16 nTemp = 0;
  4413. aDockingRect.SetSize( ImplCalcFloatSize( this, nTemp ) );
  4414. }
  4415. }
  4416. rRect = aDockingRect;
  4417. mbLastFloatMode = bFloatMode;
  4418. return bFloatMode;
  4419. }
  4420. // -----------------------------------------------------------------------
  4421. void ToolBox::EndDocking( const Rectangle& rRect, sal_Bool bFloatMode )
  4422. {
  4423. if ( !IsDockingCanceled() )
  4424. {
  4425. if ( mnLines != mnDockLines )
  4426. SetLineCount( mnDockLines );
  4427. if ( meAlign != meDockAlign )
  4428. SetAlign( meDockAlign );
  4429. }
  4430. if ( bFloatMode || (bFloatMode != ImplIsFloatingMode()) )
  4431. DockingWindow::EndDocking( rRect, bFloatMode );
  4432. }
  4433. // -----------------------------------------------------------------------
  4434. void ToolBox::Resizing( Size& rSize )
  4435. {
  4436. sal_uInt16 nCalcLines;
  4437. sal_uInt16 nTemp;
  4438. // Alle Floatinggroessen berechnen
  4439. ImplCalcFloatSizes( this );
  4440. if ( !mnLastResizeDY )
  4441. mnLastResizeDY = mnDY;
  4442. // Ist vertikales Resizing angesagt
  4443. if ( (mnLastResizeDY != rSize.Height()) && (mnDY != rSize.Height()) )
  4444. {
  4445. nCalcLines = ImplCalcLines( this, rSize.Height() );
  4446. if ( nCalcLines < 1 )
  4447. nCalcLines = 1;
  4448. rSize = ImplCalcFloatSize( this, nCalcLines );
  4449. }
  4450. else
  4451. {
  4452. nCalcLines = 1;
  4453. nTemp = nCalcLines;
  4454. Size aTempSize = ImplCalcFloatSize( this, nTemp );
  4455. while ( (aTempSize.Width() > rSize.Width()) &&
  4456. (nCalcLines <= mpFloatSizeAry->mpSize[0].mnLines) )
  4457. {
  4458. nCalcLines++;
  4459. nTemp = nCalcLines;
  4460. aTempSize = ImplCalcFloatSize( this, nTemp );
  4461. }
  4462. rSize = aTempSize;
  4463. }
  4464. mnLastResizeDY = rSize.Height();
  4465. }
  4466. // -----------------------------------------------------------------------
  4467. Size ToolBox::CalcWindowSizePixel( sal_uInt16 nCalcLines ) const
  4468. {
  4469. return ImplCalcSize( this, nCalcLines );
  4470. }
  4471. Size ToolBox::CalcWindowSizePixel( sal_uInt16 nCalcLines, WindowAlign eAlign ) const
  4472. {
  4473. return ImplCalcSize( this, nCalcLines,
  4474. (eAlign == WINDOWALIGN_TOP || eAlign == WINDOWALIGN_BOTTOM) ? TB_CALCMODE_HORZ : TB_CALCMODE_VERT );
  4475. }
  4476. sal_uInt16 ToolBox::ImplCountLineBreaks( const ToolBox *pThis )
  4477. {
  4478. sal_uInt16 nLines = 0;
  4479. std::vector< ImplToolItem >::const_iterator it = ((ToolBox*)pThis)->mpData->m_aItems.begin();
  4480. while ( it != ((ToolBox*)pThis)->mpData->m_aItems.end() )
  4481. {
  4482. if( it->meType == TOOLBOXITEM_BREAK )
  4483. ++nLines;
  4484. ++it;
  4485. }
  4486. return nLines;
  4487. }
  4488. Size ToolBox::CalcPopupWindowSizePixel() const
  4489. {
  4490. // count number of breaks and calc corresponding floating window size
  4491. sal_uInt16 nLines = ImplCountLineBreaks( this );
  4492. if( nLines )
  4493. ++nLines; // add the first line
  4494. else
  4495. {
  4496. // no breaks found: use quadratic layout
  4497. nLines = (sal_uInt16) ceil( sqrt( (double) GetItemCount() ) );
  4498. }
  4499. sal_Bool bPopup = mpData->mbAssumePopupMode;
  4500. ToolBox *pThis = (ToolBox*) this;
  4501. pThis->mpData->mbAssumePopupMode = sal_True;
  4502. Size aSize = CalcFloatingWindowSizePixel( nLines );
  4503. pThis->mpData->mbAssumePopupMode = bPopup;
  4504. return aSize;
  4505. }
  4506. Size ToolBox::CalcFloatingWindowSizePixel() const
  4507. {
  4508. sal_uInt16 nLines = ImplCountLineBreaks( this );
  4509. ++nLines; // add the first line
  4510. return CalcFloatingWindowSizePixel( nLines );
  4511. }
  4512. Size ToolBox::CalcFloatingWindowSizePixel( sal_uInt16 nCalcLines ) const
  4513. {
  4514. sal_Bool bFloat = mpData->mbAssumeFloating;
  4515. sal_Bool bDocking = mpData->mbAssumeDocked;
  4516. // simulate floating mode and force reformat before calculating
  4517. ToolBox *pThis = (ToolBox*) this;
  4518. pThis->mpData->mbAssumeFloating = sal_True;
  4519. pThis->mpData->mbAssumeDocked = sal_False;
  4520. Size aSize = ImplCalcFloatSize( (ToolBox*) this, nCalcLines );
  4521. pThis->mbFormat = sal_True;
  4522. pThis->mpData->mbAssumeFloating = bFloat;
  4523. pThis->mpData->mbAssumeDocked = bDocking;
  4524. return aSize;
  4525. }
  4526. // -----------------------------------------------------------------------
  4527. Size ToolBox::CalcMinimumWindowSizePixel() const
  4528. {
  4529. if( ImplIsFloatingMode() )
  4530. return ImplCalcSize( this, mnFloatLines );
  4531. else
  4532. {
  4533. // create dummy toolbox for measurements
  4534. ToolBox *pToolBox = new ToolBox( GetParent(), GetStyle() );
  4535. // copy until first useful item
  4536. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
  4537. while( it != mpData->m_aItems.end() )
  4538. {
  4539. pToolBox->CopyItem( *this, it->mnId );
  4540. if( (it->meType != TOOLBOXITEM_BUTTON) ||
  4541. !it->mbVisible || ImplIsFixedControl( &(*it) ) )
  4542. ++it;
  4543. else
  4544. break;
  4545. }
  4546. // add to docking manager if required to obtain a drag area
  4547. // (which is accounted for in calcwindowsizepixel)
  4548. if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
  4549. ImplGetDockingManager()->AddWindow( pToolBox );
  4550. // account for menu
  4551. if( IsMenuEnabled() )
  4552. pToolBox->SetMenuType( GetMenuType() );
  4553. pToolBox->SetAlign( GetAlign() );
  4554. Size aSize = pToolBox->CalcWindowSizePixel( 1 );
  4555. ImplGetDockingManager()->RemoveWindow( pToolBox );
  4556. pToolBox->Clear();
  4557. delete pToolBox;
  4558. return aSize;
  4559. }
  4560. }
  4561. // -----------------------------------------------------------------------
  4562. void ToolBox::EnableCustomize( sal_Bool bEnable )
  4563. {
  4564. if ( bEnable != mbCustomize )
  4565. {
  4566. mbCustomize = bEnable;
  4567. ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
  4568. if ( bEnable )
  4569. pMgr->push_back( this );
  4570. else
  4571. pMgr->erase( this );
  4572. }
  4573. }
  4574. // -----------------------------------------------------------------------
  4575. void ToolBox::GetFocus()
  4576. {
  4577. DockingWindow::GetFocus();
  4578. }
  4579. // -----------------------------------------------------------------------
  4580. void ToolBox::LoseFocus()
  4581. {
  4582. ImplChangeHighlight( NULL, sal_True );
  4583. DockingWindow::LoseFocus();
  4584. }
  4585. // -----------------------------------------------------------------------
  4586. // performs the action associated with an item, ie simulates clicking the item
  4587. void ToolBox::TriggerItem( sal_uInt16 nItemId, sal_Bool bShift, sal_Bool bCtrl )
  4588. {
  4589. mnHighItemId = nItemId;
  4590. sal_uInt16 nModifier = 0;
  4591. if( bShift )
  4592. nModifier |= KEY_SHIFT;
  4593. if( bCtrl )
  4594. nModifier |= KEY_MOD1;
  4595. KeyCode aKeyCode( 0, nModifier );
  4596. ImplActivateItem( aKeyCode );
  4597. }
  4598. // -----------------------------------------------------------------------
  4599. // calls the button's action handler
  4600. // returns sal_True if action was called
  4601. sal_Bool ToolBox::ImplActivateItem( KeyCode aKeyCode )
  4602. {
  4603. sal_Bool bRet = sal_True;
  4604. if( mnHighItemId )
  4605. {
  4606. ImplToolItem *pToolItem = ImplGetItem( mnHighItemId );
  4607. // #107712#, activate can also be called for disabled entries
  4608. if( pToolItem && !pToolItem->mbEnabled )
  4609. return sal_True;
  4610. if( pToolItem && pToolItem->mpWindow && HasFocus() )
  4611. {
  4612. ImplHideFocus();
  4613. mbChangingHighlight = sal_True; // avoid focus change due to loose focus
  4614. pToolItem->mpWindow->ImplControlFocus( GETFOCUS_TAB );
  4615. mbChangingHighlight = sal_False;
  4616. }
  4617. else
  4618. {
  4619. mnDownItemId = mnCurItemId = mnHighItemId;
  4620. ImplToolItem* pItem = ImplGetItem( mnHighItemId );
  4621. if ( pItem->mnBits & TIB_AUTOCHECK )
  4622. {
  4623. if ( pItem->mnBits & TIB_RADIOCHECK )
  4624. {
  4625. if ( pItem->meState != STATE_CHECK )
  4626. SetItemState( pItem->mnId, STATE_CHECK );
  4627. }
  4628. else
  4629. {
  4630. if ( pItem->meState != STATE_CHECK )
  4631. pItem->meState = STATE_CHECK;
  4632. else
  4633. pItem->meState = STATE_NOCHECK;
  4634. }
  4635. }
  4636. mnMouseModifier = aKeyCode.GetModifier();
  4637. mbIsKeyEvent = sal_True;
  4638. Activate();
  4639. Click();
  4640. // #107776# we might be destroyed in the selecthandler
  4641. ImplDelData aDelData;
  4642. ImplAddDel( &aDelData );
  4643. Select();
  4644. if ( aDelData.IsDelete() )
  4645. return bRet;
  4646. ImplRemoveDel( &aDelData );
  4647. Deactivate();
  4648. mbIsKeyEvent = sal_False;
  4649. mnMouseModifier = 0;
  4650. }
  4651. }
  4652. else
  4653. bRet = sal_False;
  4654. return bRet;
  4655. }
  4656. // -----------------------------------------------------------------------
  4657. sal_Bool ImplCloseLastPopup( Window *pParent )
  4658. {
  4659. // close last popup toolbox (see also:
  4660. // ImplHandleMouseFloatMode(...) in winproc.cxx )
  4661. if( ImplGetSVData()->maWinData.mpFirstFloat )
  4662. {
  4663. FloatingWindow* pLastLevelFloat = ImplGetSVData()->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
  4664. // only close the floater if it is not our direct parent, which would kill ourself
  4665. if( pLastLevelFloat && pLastLevelFloat != pParent )
  4666. {
  4667. pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
  4668. return sal_True;
  4669. }
  4670. }
  4671. return sal_False;
  4672. }
  4673. // opens a drop down toolbox item
  4674. // returns sal_True if item was opened
  4675. sal_Bool ToolBox::ImplOpenItem( KeyCode aKeyCode )
  4676. {
  4677. sal_uInt16 nCode = aKeyCode.GetCode();
  4678. sal_Bool bRet = sal_True;
  4679. // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
  4680. if ( ((nCode == KEY_LEFT || nCode == KEY_RIGHT) && IsHorizontal())
  4681. || ((nCode == KEY_UP || nCode == KEY_DOWN) && !IsHorizontal()) )
  4682. return sal_False;
  4683. if( IsMenuEnabled() && mpData->mbMenubuttonSelected )
  4684. {
  4685. if( ImplCloseLastPopup( GetParent() ) )
  4686. return bRet;
  4687. UpdateCustomMenu();
  4688. Application::PostUserEvent( mpData->mnEventId, LINK( this, ToolBox, ImplCallExecuteCustomMenu ) );
  4689. }
  4690. else if( mnHighItemId && ImplGetItem( mnHighItemId ) &&
  4691. (ImplGetItem( mnHighItemId )->mnBits & TIB_DROPDOWN) )
  4692. {
  4693. if( ImplCloseLastPopup( GetParent() ) )
  4694. return bRet;
  4695. mnDownItemId = mnCurItemId = mnHighItemId;
  4696. mnCurPos = GetItemPos( mnCurItemId );
  4697. mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore
  4698. mnMouseModifier = aKeyCode.GetModifier();
  4699. mbIsShift = sal_True;
  4700. mbIsKeyEvent = sal_True;
  4701. Activate();
  4702. mpData->mbDropDownByKeyboard = sal_True;
  4703. GetDropdownClickHdl().Call( this );
  4704. mbIsKeyEvent = sal_False;
  4705. mbIsShift = sal_False;
  4706. mnMouseModifier = 0;
  4707. }
  4708. else
  4709. bRet = sal_False;
  4710. return bRet;
  4711. }
  4712. // -----------------------------------------------------------------------
  4713. void ToolBox::KeyInput( const KeyEvent& rKEvt )
  4714. {
  4715. KeyCode aKeyCode = rKEvt.GetKeyCode();
  4716. mnKeyModifier = aKeyCode.GetModifier();
  4717. sal_uInt16 nCode = aKeyCode.GetCode();
  4718. sal_Bool bParentIsDialog = ( ( ImplGetParent()->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL) ) == WB_DIALOGCONTROL );
  4719. sal_Bool bForwardKey = sal_False;
  4720. sal_Bool bGrabFocusToDocument = sal_False;
  4721. // #107776# we might be destroyed in the keyhandler
  4722. ImplDelData aDelData;
  4723. ImplAddDel( &aDelData );
  4724. switch ( nCode )
  4725. {
  4726. case KEY_UP:
  4727. {
  4728. // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
  4729. if( aKeyCode.GetModifier() ) // allow only pure cursor keys
  4730. break;
  4731. if( !IsHorizontal() )
  4732. ImplChangeHighlightUpDn( sal_True );
  4733. else
  4734. ImplOpenItem( aKeyCode );
  4735. }
  4736. break;
  4737. case KEY_LEFT:
  4738. {
  4739. if( aKeyCode.GetModifier() ) // allow only pure cursor keys
  4740. break;
  4741. if( IsHorizontal() )
  4742. ImplChangeHighlightUpDn( sal_True );
  4743. else
  4744. ImplOpenItem( aKeyCode );
  4745. }
  4746. break;
  4747. case KEY_DOWN:
  4748. {
  4749. if( aKeyCode.GetModifier() ) // allow only pure cursor keys
  4750. break;
  4751. if( !IsHorizontal() )
  4752. ImplChangeHighlightUpDn( sal_False );
  4753. else
  4754. ImplOpenItem( aKeyCode );
  4755. }
  4756. break;
  4757. case KEY_RIGHT:
  4758. {
  4759. if( aKeyCode.GetModifier() ) // allow only pure cursor keys
  4760. break;
  4761. if( IsHorizontal() )
  4762. ImplChangeHighlightUpDn( sal_False );
  4763. else
  4764. ImplOpenItem( aKeyCode );
  4765. }
  4766. break;
  4767. case KEY_PAGEUP:
  4768. if ( mnCurLine > 1 )
  4769. {
  4770. if( mnCurLine > mnVisLines )
  4771. mnCurLine = mnCurLine - mnVisLines;
  4772. else
  4773. mnCurLine = 1;
  4774. mbFormat = sal_True;
  4775. ImplFormat();
  4776. ImplDrawSpin( sal_False, sal_False );
  4777. ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine ) );
  4778. }
  4779. break;
  4780. case KEY_PAGEDOWN:
  4781. if ( mnCurLine+mnVisLines-1 < mnCurLines )
  4782. {
  4783. if( mnCurLine + 2*mnVisLines-1 < mnCurLines )
  4784. mnCurLine = mnCurLine + mnVisLines;
  4785. else
  4786. mnCurLine = mnCurLines;
  4787. mbFormat = sal_True;
  4788. ImplFormat();
  4789. ImplDrawSpin( sal_False, sal_False );
  4790. ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine ) );
  4791. }
  4792. break;
  4793. case KEY_END:
  4794. {
  4795. ImplChangeHighlight( NULL );
  4796. ImplChangeHighlightUpDn( sal_False );
  4797. }
  4798. break;
  4799. case KEY_HOME:
  4800. {
  4801. ImplChangeHighlight( NULL );
  4802. ImplChangeHighlightUpDn( sal_True );
  4803. }
  4804. break;
  4805. case KEY_ESCAPE:
  4806. {
  4807. if( !ImplIsFloatingMode() && bParentIsDialog )
  4808. DockingWindow::KeyInput( rKEvt );
  4809. else
  4810. {
  4811. // send focus to document pane
  4812. Window *pWin = this;
  4813. while( pWin )
  4814. {
  4815. if( !pWin->GetParent() )
  4816. {
  4817. pWin->ImplGetFrameWindow()->GetWindow( WINDOW_CLIENT )->GrabFocus();
  4818. break;
  4819. }
  4820. pWin = pWin->GetParent();
  4821. }
  4822. }
  4823. }
  4824. break;
  4825. case KEY_RETURN:
  4826. {
  4827. // #107712#, disabled entries are selectable now
  4828. // leave toolbox and move focus to document
  4829. if( mnHighItemId )
  4830. {
  4831. ImplToolItem *pItem = ImplGetItem( mnHighItemId );
  4832. if( !pItem->mbEnabled )
  4833. {
  4834. Sound::Beep( SOUND_DISABLE, this );
  4835. bGrabFocusToDocument = sal_True;
  4836. }
  4837. }
  4838. if( !bGrabFocusToDocument )
  4839. bForwardKey = !ImplActivateItem( aKeyCode );
  4840. }
  4841. break;
  4842. default:
  4843. {
  4844. sal_uInt16 aKeyGroup = aKeyCode.GetGroup();
  4845. ImplToolItem *pItem = NULL;
  4846. if( mnHighItemId )
  4847. pItem = ImplGetItem( mnHighItemId );
  4848. // #i13931# forward alphanum keyinput into embedded control
  4849. if( (aKeyGroup == KEYGROUP_NUM || aKeyGroup == KEYGROUP_ALPHA ) && pItem && pItem->mpWindow && pItem->mbEnabled )
  4850. {
  4851. Window *pFocusWindow = Application::GetFocusWindow();
  4852. ImplHideFocus();
  4853. mbChangingHighlight = sal_True; // avoid focus change due to loose focus
  4854. pItem->mpWindow->ImplControlFocus( GETFOCUS_TAB );
  4855. mbChangingHighlight = sal_False;
  4856. if( pFocusWindow != Application::GetFocusWindow() )
  4857. Application::GetFocusWindow()->KeyInput( rKEvt );
  4858. }
  4859. else
  4860. {
  4861. // do nothing to avoid key presses going into the document
  4862. // while the toolbox has the focus
  4863. // just forward function and special keys and combinations with Alt-key
  4864. if( aKeyGroup == KEYGROUP_FKEYS || aKeyGroup == KEYGROUP_MISC || aKeyCode.IsMod2() )
  4865. bForwardKey = sal_True;
  4866. }
  4867. }
  4868. }
  4869. if ( aDelData.IsDelete() )
  4870. return;
  4871. ImplRemoveDel( &aDelData );
  4872. // #107251# move focus away if this toolbox was disabled during keyinput
  4873. if( HasFocus() && mpData->mbKeyInputDisabled && (ImplGetParent()->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL) ) == WB_DIALOGCONTROL)
  4874. {
  4875. sal_uInt16 n = 0;
  4876. Window *pFocusControl = ImplGetParent()->ImplGetDlgWindow( n, DLGWINDOW_FIRST );
  4877. if ( pFocusControl && pFocusControl != this )
  4878. pFocusControl->ImplControlFocus( GETFOCUS_INIT );
  4879. }
  4880. mnKeyModifier = 0;
  4881. // #107712#, leave toolbox
  4882. if( bGrabFocusToDocument )
  4883. {
  4884. GrabFocusToDocument();
  4885. return;
  4886. }
  4887. if( bForwardKey )
  4888. DockingWindow::KeyInput( rKEvt );
  4889. }
  4890. // -----------------------------------------------------------------------
  4891. // returns the current toolbox line of the item
  4892. sal_uInt16 ToolBox::ImplGetItemLine( ImplToolItem* pCurrentItem )
  4893. {
  4894. std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
  4895. sal_uInt16 nLine = 1;
  4896. while( it != mpData->m_aItems.end() )
  4897. {
  4898. if ( it->mbBreak )
  4899. ++nLine;
  4900. if( &(*it) == pCurrentItem)
  4901. break;
  4902. ++it;
  4903. }
  4904. return nLine;
  4905. }
  4906. // returns the first displayable item in the given line
  4907. ImplToolItem* ToolBox::ImplGetFirstValidItem( sal_uInt16 nLine )
  4908. {
  4909. if( !nLine || nLine > mnCurLines )
  4910. return NULL;
  4911. nLine--;
  4912. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
  4913. while( it != mpData->m_aItems.end() )
  4914. {
  4915. // find correct line
  4916. if ( it->mbBreak )
  4917. nLine--;
  4918. if( !nLine )
  4919. {
  4920. // find first useful item
  4921. while( it != mpData->m_aItems.end() && ((it->meType != TOOLBOXITEM_BUTTON) ||
  4922. /*!it->mbEnabled ||*/ !it->mbVisible || ImplIsFixedControl( &(*it) )) )
  4923. {
  4924. ++it;
  4925. if( it == mpData->m_aItems.end() || it->mbBreak )
  4926. return NULL; // no valid items in this line
  4927. }
  4928. return &(*it);
  4929. }
  4930. ++it;
  4931. }
  4932. return (it == mpData->m_aItems.end()) ? NULL : &(*it);
  4933. }
  4934. // -----------------------------------------------------------------------
  4935. sal_uInt16 ToolBox::ImplFindItemPos( const ImplToolItem* pItem, const std::vector< ImplToolItem >& rList )
  4936. {
  4937. if( pItem )
  4938. {
  4939. sal_uInt16 nPos;
  4940. for( nPos = 0; nPos < rList.size(); ++nPos )
  4941. if( &rList[ nPos ] == pItem )
  4942. return nPos;
  4943. }
  4944. return TOOLBOX_ITEM_NOTFOUND;
  4945. }
  4946. void ToolBox::ChangeHighlight( sal_uInt16 nPos )
  4947. {
  4948. if ( nPos < GetItemCount() ) {
  4949. ImplGrabFocus( 0 );
  4950. ImplChangeHighlight ( ImplGetItem ( GetItemId ( (sal_uInt16) nPos ) ), sal_False );
  4951. }
  4952. }
  4953. void ToolBox::ImplChangeHighlight( ImplToolItem* pItem, sal_Bool bNoGrabFocus )
  4954. {
  4955. // avoid recursion due to focus change
  4956. if( mbChangingHighlight )
  4957. return;
  4958. mbChangingHighlight = sal_True;
  4959. ImplToolItem* pOldItem = NULL;
  4960. if ( mnHighItemId )
  4961. {
  4962. ImplHideFocus();
  4963. sal_uInt16 nPos = GetItemPos( mnHighItemId );
  4964. pOldItem = ImplGetItem( mnHighItemId );
  4965. // #i89962# ImplDrawItem can cause Invalidate/Update
  4966. // which will in turn ImplShowFocus again
  4967. // set mnHighItemId to 0 already to prevent this hen/egg problem
  4968. mnHighItemId = 0;
  4969. ImplDrawItem( nPos, 0 );
  4970. ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( nPos ) );
  4971. }
  4972. if( !bNoGrabFocus && pItem != pOldItem && pOldItem && pOldItem->mpWindow )
  4973. {
  4974. // move focus into toolbox
  4975. GrabFocus();
  4976. }
  4977. if( pItem )
  4978. {
  4979. sal_uInt16 aPos = ToolBox::ImplFindItemPos( pItem, mpData->m_aItems );
  4980. if( aPos != TOOLBOX_ITEM_NOTFOUND)
  4981. {
  4982. // check for line breaks
  4983. sal_uInt16 nLine = ImplGetItemLine( pItem );
  4984. if( nLine >= mnCurLine + mnVisLines )
  4985. {
  4986. mnCurLine = nLine - mnVisLines + 1;
  4987. mbFormat = sal_True;
  4988. }
  4989. else if ( nLine < mnCurLine )
  4990. {
  4991. mnCurLine = nLine;
  4992. mbFormat = sal_True;
  4993. }
  4994. if( mbFormat )
  4995. {
  4996. ImplFormat();
  4997. }
  4998. mnHighItemId = pItem->mnId;
  4999. ImplDrawItem( aPos, 2 ); // always use shadow effect (2)
  5000. if( mbSelection )
  5001. mnCurPos = aPos;
  5002. ImplShowFocus();
  5003. ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHT );
  5004. }
  5005. }
  5006. else
  5007. {
  5008. ImplHideFocus();
  5009. mnHighItemId = 0;
  5010. mnCurPos = TOOLBOX_ITEM_NOTFOUND;
  5011. }
  5012. mbChangingHighlight = sal_False;
  5013. }
  5014. // -----------------------------------------------------------------------
  5015. // check for keyboard accessible items
  5016. static sal_Bool ImplIsValidItem( const ImplToolItem* pItem, sal_Bool bNotClipped )
  5017. {
  5018. sal_Bool bValid = (pItem && pItem->meType == TOOLBOXITEM_BUTTON && pItem->mbVisible && !ImplIsFixedControl( pItem ));
  5019. if( bValid && bNotClipped && pItem->IsClipped() )
  5020. bValid = sal_False;
  5021. return bValid;
  5022. }
  5023. // -----------------------------------------------------------------------
  5024. sal_Bool ToolBox::ImplChangeHighlightUpDn( sal_Bool bUp, sal_Bool bNoCycle )
  5025. {
  5026. ImplToolItem* pToolItem = ImplGetItem( mnHighItemId );
  5027. if( !pToolItem || !mnHighItemId )
  5028. {
  5029. // menubutton highlighted ?
  5030. if( mpData->mbMenubuttonSelected )
  5031. {
  5032. if( bUp )
  5033. {
  5034. // select last valid non-clipped item
  5035. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.end();
  5036. ImplToolItem* pItem = NULL;
  5037. while( it != mpData->m_aItems.begin() )
  5038. {
  5039. --it;
  5040. if ( ImplIsValidItem( &(*it), sal_True ) )
  5041. {
  5042. pItem = &(*it);
  5043. break;
  5044. }
  5045. }
  5046. ImplDrawMenubutton( this, sal_False );
  5047. ImplChangeHighlight( pItem );
  5048. }
  5049. else
  5050. {
  5051. // select first valid non-clipped item
  5052. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
  5053. while( it != mpData->m_aItems.end() )
  5054. {
  5055. if ( ImplIsValidItem( &(*it), sal_True ) )
  5056. break;
  5057. ++it;
  5058. }
  5059. if( it != mpData->m_aItems.end() )
  5060. {
  5061. ImplDrawMenubutton( this, sal_False );
  5062. ImplChangeHighlight( &(*it) );
  5063. }
  5064. }
  5065. return sal_True;
  5066. }
  5067. if( bUp )
  5068. {
  5069. // Select first valid item
  5070. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
  5071. while( it != mpData->m_aItems.end() )
  5072. {
  5073. if ( ImplIsValidItem( &(*it), sal_False ) )
  5074. break;
  5075. ++it;
  5076. }
  5077. // select the menu button if a clipped item would be selected
  5078. if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem( this )) && IsMenuEnabled() )
  5079. {
  5080. ImplChangeHighlight( NULL );
  5081. ImplDrawMenubutton( this, sal_True );
  5082. }
  5083. else
  5084. ImplChangeHighlight( (it != mpData->m_aItems.end()) ? &(*it) : NULL );
  5085. return sal_True;
  5086. }
  5087. else
  5088. {
  5089. // Select last valid item
  5090. // docked toolbars have the menubutton as last item - if this button is enabled
  5091. if( IsMenuEnabled() && !ImplIsFloatingMode() )
  5092. {
  5093. ImplChangeHighlight( NULL );
  5094. ImplDrawMenubutton( this, sal_True );
  5095. }
  5096. else
  5097. {
  5098. std::vector< ImplToolItem >::iterator it = mpData->m_aItems.end();
  5099. ImplToolItem* pItem = NULL;
  5100. while( it != mpData->m_aItems.begin() )
  5101. {
  5102. --it;
  5103. if ( ImplIsValidItem( &(*it), sal_False ) )
  5104. {
  5105. pItem = &(*it);
  5106. break;
  5107. }
  5108. }
  5109. ImplChangeHighlight( pItem );
  5110. }
  5111. return sal_True;
  5112. }
  5113. }
  5114. if( pToolItem )
  5115. {
  5116. sal_uLong pos = ToolBox::ImplFindItemPos( pToolItem, mpData->m_aItems );
  5117. sal_uLong nCount = mpData->m_aItems.size();
  5118. sal_uLong i=0;
  5119. do
  5120. {
  5121. if( bUp )
  5122. {
  5123. if( !pos-- )
  5124. {
  5125. if( bNoCycle )
  5126. return sal_False;
  5127. // highlight the menu button if it is the last item
  5128. if( IsMenuEnabled() && !ImplIsFloatingMode() )
  5129. {
  5130. ImplChangeHighlight( NULL );
  5131. ImplDrawMenubutton( this, sal_True );
  5132. return sal_True;
  5133. }
  5134. else
  5135. pos = nCount-1;
  5136. }
  5137. }
  5138. else
  5139. {
  5140. if( ++pos >= nCount )
  5141. {
  5142. if( bNoCycle )
  5143. return sal_False;
  5144. // highlight the menu button if it is the last item
  5145. if( IsMenuEnabled() && !ImplIsFloatingMode() )
  5146. {
  5147. ImplChangeHighlight( NULL );
  5148. ImplDrawMenubutton( this, sal_True );
  5149. return sal_True;
  5150. }
  5151. else
  5152. pos = 0;
  5153. }
  5154. }
  5155. pToolItem = &mpData->m_aItems[pos];
  5156. if ( ImplIsValidItem( pToolItem, sal_False ) )
  5157. break;
  5158. } while( ++i < nCount);
  5159. if( pToolItem->IsClipped() && IsMenuEnabled() )
  5160. {
  5161. // select the menu button if a clipped item would be selected
  5162. ImplChangeHighlight( NULL );
  5163. ImplDrawMenubutton( this, sal_True );
  5164. }
  5165. else if( i != nCount )
  5166. ImplChangeHighlight( pToolItem );
  5167. else
  5168. return sal_False;
  5169. }
  5170. return sal_True;
  5171. }
  5172. // -----------------------------------------------------------------------
  5173. void ToolBox::ImplShowFocus()
  5174. {
  5175. if( mnHighItemId && HasFocus() )
  5176. {
  5177. ImplToolItem* pItem = ImplGetItem( mnHighItemId );
  5178. if( pItem->mpWindow )
  5179. {
  5180. Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow : pItem->mpWindow;
  5181. pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = sal_True;
  5182. pWin->Invalidate( 0 );
  5183. }
  5184. }
  5185. }
  5186. // -----------------------------------------------------------------------
  5187. void ToolBox::ImplHideFocus()
  5188. {
  5189. if( mnHighItemId )
  5190. {
  5191. ImplToolItem* pItem = ImplGetItem( mnHighItemId );
  5192. if( pItem->mpWindow )
  5193. {
  5194. Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow : pItem->mpWindow;
  5195. pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = sal_False;
  5196. pWin->Invalidate( 0 );
  5197. }
  5198. }
  5199. if ( mpData->mbMenubuttonSelected )
  5200. {
  5201. // remove highlight from menubutton
  5202. ImplDrawMenubutton( this, sal_False );
  5203. }
  5204. }
  5205. // -----------------------------------------------------------------------
  5206. void ToolBox::ImplDisableFlatButtons()
  5207. {
  5208. #ifdef WNT // Check in the Windows registry if an AT tool wants no flat toolboxes
  5209. static bool bInit = false, bValue = false;
  5210. if( ! bInit )
  5211. {
  5212. bInit = true;
  5213. HKEY hkey;
  5214. if( ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER,
  5215. "Software\\LibreOffice\\Accessibility\\AtToolSupport",
  5216. &hkey) )
  5217. {
  5218. DWORD dwType = 0;
  5219. sal_uInt8 Data[6]; // possible values: "true", "false", "1", "0", DWORD
  5220. DWORD cbData = sizeof(Data);
  5221. if( ERROR_SUCCESS == RegQueryValueEx(hkey, "DisableFlatToolboxButtons",
  5222. NULL, &dwType, Data, &cbData) )
  5223. {
  5224. switch (dwType)
  5225. {
  5226. case REG_SZ:
  5227. bValue = ((0 == stricmp((const char *) Data, "1")) || (0 == stricmp((const char *) Data, "true")));
  5228. break;
  5229. case REG_DWORD:
  5230. bValue = (bool)(((DWORD *) Data)[0]);
  5231. break;
  5232. }
  5233. }
  5234. RegCloseKey(hkey);
  5235. }
  5236. }
  5237. if( bValue )
  5238. mnOutStyle &= ~TOOLBOX_STYLE_FLAT;
  5239. #endif
  5240. }
  5241. void ToolBox::SetToolbarLayoutMode( ToolBoxLayoutMode eLayout )
  5242. {
  5243. if ( meLayoutMode != eLayout )
  5244. meLayoutMode = eLayout;
  5245. }
  5246. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */