PageRenderTime 159ms CodeModel.GetById 64ms RepoModel.GetById 1ms app.codeStats 1ms

/vcl/source/window/toolbox.cxx

https://bitbucket.org/mst/ooo340
C++ | 6336 lines | 4948 code | 840 blank | 548 comment | 1285 complexity | 2d38d34c54a5464c50efa1bc8961fb0d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * Copyright 2000, 2010 Oracle and/or its affiliates.
  6. *
  7. * OpenOffice.org - a multi-platform office productivity suite
  8. *
  9. * This file is part of OpenOffice.org.
  10. *
  11. * OpenOffice.org is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License version 3
  13. * only, as published by the Free Software Foundation.
  14. *
  15. * OpenOffice.org is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License version 3 for more details
  19. * (a copy is included in the LICENSE file that accompanied this code).
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * version 3 along with OpenOffice.org. If not, see
  23. * <http://www.openoffice.org/license.html>
  24. * for a copy of the LGPLv3 License.
  25. *
  26. ************************************************************************/
  27. // MARKER(update_precomp.py): autogen include statement, do not remove
  28. #include "precompiled_vcl.hxx"
  29. #ifndef _SV_SVSYS_HXX
  30. #include <svsys.h>
  31. #endif
  32. #include <rtl/logfile.hxx>
  33. #include <tools/list.hxx>
  34. #include <tools/debug.hxx>
  35. #ifndef _SV_RC_H
  36. #include <tools/rc.h>
  37. #endif
  38. #include <vcl/svdata.hxx>
  39. #include <vcl/event.hxx>
  40. #include <vcl/decoview.hxx>
  41. #include <vcl/accel.hxx>
  42. #include <vcl/svapp.hxx>
  43. #include <vcl/help.hxx>
  44. #include <vcl/sound.hxx>
  45. #include <vcl/virdev.hxx>
  46. #include <vcl/spin.h>
  47. #include <vcl/toolbox.hxx>
  48. #include <vcl/toolbox.h>
  49. #include <vcl/bitmap.hxx>
  50. #include <tools/poly.hxx>
  51. #include <vcl/salframe.hxx>
  52. #include <vcl/mnemonic.hxx>
  53. #include <vcl/gradient.hxx>
  54. #include <vcl/menu.hxx>
  55. #include <vcl/window.h>
  56. #include <string.h>
  57. #include <vector>
  58. #include <math.h>
  59. // =======================================================================
  60. DBG_NAMEEX( Window )
  61. // =======================================================================
  62. #define SMALLBUTTON_HSIZE 7
  63. #define SMALLBUTTON_VSIZE 7
  64. #define SMALLBUTTON_OFF_NORMAL_X 3
  65. #define SMALLBUTTON_OFF_NORMAL_Y 3
  66. #define SMALLBUTTON_OFF_CHECKED_X 4
  67. #define SMALLBUTTON_OFF_CHECKED_Y 4
  68. #define SMALLBUTTON_OFF_PRESSED_X 5
  69. #define SMALLBUTTON_OFF_PRESSED_Y 5
  70. #define OUTBUTTON_SIZE 6
  71. #define OUTBUTTON_BORDER 4
  72. #define OUTBUTTON_OFF_NORMAL_X 1
  73. #define OUTBUTTON_OFF_NORMAL_Y 1
  74. // -----------------------------------------------------------------------
  75. #define DEF_MIN_WIDTH 8
  76. #define DEF_MIN_HEIGHT 8
  77. #define DEF_TEXT_WIDTH 40
  78. #define TB_TEXTOFFSET 2
  79. #define TB_IMAGETEXTOFFSET 3
  80. #define TB_LINESPACING 3
  81. #define TB_SPIN_SIZE 14
  82. #define TB_SPIN_OFFSET 2
  83. #define TB_NEXT_SIZE 22
  84. #define TB_NEXT_OFFSET 2
  85. #define TB_BORDER_OFFSET1 4
  86. #define TB_BORDER_OFFSET2 2
  87. #define TB_CUSTOMIZE_OFFSET 2
  88. #define TB_RESIZE_OFFSET 3
  89. #define TB_MAXLINES 5
  90. #define TB_MAXNOSCROLL 32765
  91. #define TB_MIN_WIN_WIDTH 20
  92. #define TB_CALCMODE_HORZ 1
  93. #define TB_CALCMODE_VERT 2
  94. #define TB_CALCMODE_FLOAT 3
  95. #define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
  96. #define TB_MAX_GROUPS 100
  97. #define DOCK_LINEHSIZE ((USHORT)0x0001)
  98. #define DOCK_LINEVSIZE ((USHORT)0x0002)
  99. #define DOCK_LINERIGHT ((USHORT)0x1000)
  100. #define DOCK_LINEBOTTOM ((USHORT)0x2000)
  101. #define DOCK_LINELEFT ((USHORT)0x4000)
  102. #define DOCK_LINETOP ((USHORT)0x8000)
  103. #define DOCK_LINEOFFSET 3
  104. // -----------------------------------------------------------------------
  105. static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, USHORT highlight, BOOL bChecked, BOOL bEnabled, BOOL bIsWindow );
  106. // -----------------------------------------------------------------------
  107. struct ImplToolSize
  108. {
  109. long mnWidth;
  110. long mnHeight;
  111. USHORT mnLines;
  112. };
  113. struct ImplToolSizeArray
  114. {
  115. long mnLength;
  116. long mnLastEntry;
  117. ImplToolSize* mpSize;
  118. ImplToolSizeArray() { mpSize = NULL; mnLength = 0; mnLastEntry = 0; }
  119. ~ImplToolSizeArray() { if( mpSize ) delete [] mpSize; mnLength = 0; }
  120. };
  121. // -----------------------------------------------------------------------
  122. DECLARE_LIST( ImplTBList, ToolBox* )
  123. class ImplTBDragMgr
  124. {
  125. private:
  126. ImplTBList* mpBoxList;
  127. ToolBox* mpDragBox;
  128. Point maMouseOff;
  129. Rectangle maRect;
  130. Rectangle maStartRect;
  131. Accelerator maAccel;
  132. long mnMinWidth;
  133. long mnMaxWidth;
  134. USHORT mnLineMode;
  135. USHORT mnStartLines;
  136. void* mpCustomizeData;
  137. BOOL mbCustomizeMode;
  138. BOOL mbResizeMode;
  139. BOOL mbShowDragRect;
  140. public:
  141. ImplTBDragMgr();
  142. ~ImplTBDragMgr();
  143. void Insert( ToolBox* pBox )
  144. { mpBoxList->Insert( pBox ); }
  145. void Remove( ToolBox* pBox )
  146. { mpBoxList->Remove( pBox ); }
  147. ULONG Count() const
  148. { return mpBoxList->Count(); }
  149. ToolBox* FindToolBox( const Rectangle& rRect );
  150. void StartDragging( ToolBox* pDragBox,
  151. const Point& rPos, const Rectangle& rRect,
  152. USHORT nLineMode, BOOL bResizeItem,
  153. void* pData = NULL );
  154. void Dragging( const Point& rPos );
  155. void EndDragging( BOOL bOK = TRUE );
  156. void HideDragRect() { if ( mbShowDragRect ) mpDragBox->HideTracking(); }
  157. void UpdateDragRect();
  158. DECL_LINK( SelectHdl, Accelerator* );
  159. void StartCustomizeMode();
  160. void EndCustomizeMode();
  161. BOOL IsCustomizeMode() { return mbCustomizeMode; }
  162. BOOL IsResizeMode() { return mbResizeMode; }
  163. };
  164. // -----------------------------------------------------------------------
  165. static ImplTBDragMgr* ImplGetTBDragMgr()
  166. {
  167. ImplSVData* pSVData = ImplGetSVData();
  168. if ( !pSVData->maCtrlData.mpTBDragMgr )
  169. pSVData->maCtrlData.mpTBDragMgr = new ImplTBDragMgr;
  170. return pSVData->maCtrlData.mpTBDragMgr;
  171. }
  172. // -----------------------------------------------------------------------
  173. int ToolBox::ImplGetDragWidth( ToolBox* pThis )
  174. {
  175. #define TB_DRAGWIDTH 8 // the default width of the grip
  176. int width = TB_DRAGWIDTH;
  177. if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
  178. {
  179. ImplControlValue aControlValue;
  180. Point aPoint;
  181. Region aContent, aBound;
  182. Region aArea( Rectangle(aPoint, pThis->GetOutputSizePixel()) );
  183. if ( pThis->GetNativeControlRegion(CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
  184. aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
  185. {
  186. width = pThis->mbHorz ? aContent.GetBoundRect().GetWidth() : aContent.GetBoundRect().GetHeight();
  187. }
  188. }
  189. return width;
  190. }
  191. ButtonType determineButtonType( ImplToolItem* pItem, ButtonType defaultType )
  192. {
  193. ButtonType tmpButtonType = defaultType;
  194. ToolBoxItemBits nBits( pItem->mnBits & 0x300 );
  195. if ( nBits & TIB_TEXTICON ) // item has custom setting
  196. {
  197. tmpButtonType = BUTTON_SYMBOLTEXT;
  198. if ( nBits == TIB_TEXT_ONLY )
  199. tmpButtonType = BUTTON_TEXT;
  200. else if ( nBits == TIB_ICON_ONLY )
  201. tmpButtonType = BUTTON_SYMBOL;
  202. }
  203. return tmpButtonType;
  204. }
  205. // -----------------------------------------------------------------------
  206. void ToolBox::ImplUpdateDragArea( ToolBox *pThis )
  207. {
  208. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  209. if( pWrapper )
  210. {
  211. if ( pThis->ImplIsFloatingMode() || pWrapper->IsLocked() )
  212. pWrapper->SetDragArea( Rectangle() );
  213. else
  214. {
  215. if( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
  216. pWrapper->SetDragArea( Rectangle( 0, 0, ImplGetDragWidth( pThis ), pThis->GetOutputSizePixel().Height() ) );
  217. else
  218. pWrapper->SetDragArea( Rectangle( 0, 0, pThis->GetOutputSizePixel().Width(), ImplGetDragWidth( pThis ) ) );
  219. }
  220. }
  221. }
  222. // -----------------------------------------------------------------------
  223. void ToolBox::ImplCalcBorder( WindowAlign eAlign, long& rLeft, long& rTop,
  224. long& rRight, long& rBottom, const ToolBox *pThis )
  225. {
  226. if( pThis->ImplIsFloatingMode() || !(pThis->mnWinStyle & WB_BORDER) )
  227. {
  228. // no border in floating mode
  229. rLeft = rTop = rRight = rBottom = 0;
  230. return;
  231. }
  232. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  233. // reserve dragarea only for dockable toolbars
  234. int dragwidth = ( pWrapper && !pWrapper->IsLocked() ) ? ImplGetDragWidth( (ToolBox*)pThis ) : 0;
  235. // no shadow border for dockable toolbars
  236. int borderwidth = pWrapper ? 0: 2;
  237. if ( eAlign == WINDOWALIGN_TOP )
  238. {
  239. rLeft = borderwidth+dragwidth;
  240. rTop = borderwidth;
  241. rRight = borderwidth;
  242. rBottom = 0;
  243. }
  244. else if ( eAlign == WINDOWALIGN_LEFT )
  245. {
  246. rLeft = borderwidth;
  247. rTop = borderwidth+dragwidth;
  248. rRight = 0;
  249. rBottom = borderwidth;
  250. }
  251. else if ( eAlign == WINDOWALIGN_BOTTOM )
  252. {
  253. rLeft = borderwidth+dragwidth;
  254. rTop = 0;
  255. rRight = borderwidth;
  256. rBottom = borderwidth;
  257. }
  258. else
  259. {
  260. rLeft = 0;
  261. rTop = borderwidth+dragwidth;
  262. rRight = borderwidth;
  263. rBottom = borderwidth;
  264. }
  265. }
  266. // -----------------------------------------------------------------------
  267. static void ImplCheckUpdate( ToolBox *pThis )
  268. {
  269. // remove any pending invalidates to avoid
  270. // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
  271. // which would result in erasing the background only and not painting any items
  272. // this must not be done when we're already in Paint()
  273. // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
  274. if( !pThis->IsBackground() && pThis->HasPaintEvent() && !pThis->IsInPaint() )
  275. pThis->Update();
  276. }
  277. // -----------------------------------------------------------------------
  278. void ToolBox::ImplDrawGrip( ToolBox* pThis )
  279. {
  280. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  281. if( pWrapper && !pWrapper->GetDragArea().IsEmpty() )
  282. {
  283. // execute pending paint requests
  284. ImplCheckUpdate( pThis );
  285. BOOL bNativeOk = FALSE;
  286. if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_HORZ : PART_THUMB_VERT ) )
  287. {
  288. ImplControlValue aControlValue;
  289. ToolbarValue aToolbarValue;
  290. aToolbarValue.maGripRect = pWrapper->GetDragArea();
  291. aControlValue.setOptionalVal( (void *)(&aToolbarValue) );
  292. Point aPt;
  293. Region aCtrlRegion( Rectangle( aPt, pThis->GetOutputSizePixel() ) );
  294. ControlState nState = CTRL_STATE_ENABLED;
  295. bNativeOk = pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
  296. aCtrlRegion, nState, aControlValue, rtl::OUString() );
  297. }
  298. if( bNativeOk )
  299. return;
  300. const StyleSettings& rStyleSettings = pThis->GetSettings().GetStyleSettings();
  301. pThis->SetLineColor( rStyleSettings.GetShadowColor() );
  302. Size aSz ( pThis->GetOutputSizePixel() );
  303. if ( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
  304. {
  305. int height = (int) (0.6 * aSz.Height() + 0.5);
  306. int i = (aSz.Height() - height) / 2;
  307. height += i;
  308. while( i <= height )
  309. {
  310. int x = ImplGetDragWidth( pThis ) / 2;
  311. pThis->DrawPixel( Point(x, i), rStyleSettings.GetDarkShadowColor() );
  312. pThis->DrawPixel( Point(x+1, i), rStyleSettings.GetShadowColor() );
  313. pThis->DrawPixel( Point(x, i+1), rStyleSettings.GetShadowColor() );
  314. pThis->DrawPixel( Point(x+1, i+1), rStyleSettings.GetFaceColor() );
  315. pThis->DrawPixel( Point(x+2, i+1), Color(COL_WHITE) );
  316. pThis->DrawPixel( Point(x+1, i+2), Color(COL_WHITE) );
  317. pThis->DrawPixel( Point(x+2, i+2), Color(COL_WHITE) );
  318. i+=4;
  319. }
  320. }
  321. else
  322. {
  323. int width = (int) (0.6 * aSz.Width() + 0.5);
  324. int i = (aSz.Width() - width) / 2;
  325. width += i;
  326. while( i <= width )
  327. {
  328. int y = ImplGetDragWidth(pThis) / 2;
  329. pThis->DrawPixel( Point(i, y), rStyleSettings.GetDarkShadowColor() );
  330. pThis->DrawPixel( Point(i+1, y), rStyleSettings.GetShadowColor() );
  331. pThis->DrawPixel( Point(i, y+1), rStyleSettings.GetShadowColor() );
  332. pThis->DrawPixel( Point(i+1, y+1), rStyleSettings.GetFaceColor() );
  333. pThis->DrawPixel( Point(i+2, y+1), Color(COL_WHITE) );
  334. pThis->DrawPixel( Point(i+1, y+2), Color(COL_WHITE) );
  335. pThis->DrawPixel( Point(i+2, y+2), Color(COL_WHITE) );
  336. i+=4;
  337. }
  338. }
  339. }
  340. }
  341. void ToolBox::ImplDrawGradientBackground( ToolBox* pThis, ImplDockingWindowWrapper * )
  342. {
  343. // draw a nice gradient
  344. Color startCol, endCol;
  345. startCol = pThis->GetSettings().GetStyleSettings().GetFaceGradientColor();
  346. endCol = pThis->GetSettings().GetStyleSettings().GetFaceColor();
  347. if( pThis->GetSettings().GetStyleSettings().GetHighContrastMode() )
  348. // no 'extreme' gradient when high contrast
  349. startCol = endCol;
  350. Gradient g;
  351. g.SetAngle( pThis->mbHorz ? 0 : 900 );
  352. g.SetStyle( GRADIENT_LINEAR );
  353. g.SetStartColor( startCol );
  354. g.SetEndColor( endCol );
  355. BOOL bLineColor = pThis->IsLineColor();
  356. Color aOldCol = pThis->GetLineColor();
  357. pThis->SetLineColor( pThis->GetSettings().GetStyleSettings().GetShadowColor() );
  358. Size aFullSz( pThis->GetOutputSizePixel() );
  359. Size aLineSz( aFullSz );
  360. // use the linesize only when floating
  361. // full window height is used when docked (single line)
  362. if( pThis->ImplIsFloatingMode() )
  363. {
  364. long nLineSize;
  365. if( pThis->mbHorz )
  366. {
  367. nLineSize = pThis->mnMaxItemHeight;
  368. if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
  369. nLineSize = pThis->mnWinHeight;
  370. aLineSz.Height() = nLineSize;
  371. }
  372. else
  373. {
  374. nLineSize = pThis->mnMaxItemWidth;
  375. aLineSz.Width() = nLineSize;
  376. }
  377. }
  378. long nLeft, nTop, nRight, nBottom;
  379. ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
  380. Size aTopLineSz( aLineSz );
  381. Size aBottomLineSz( aLineSz );
  382. if ( pThis->mnWinStyle & WB_BORDER )
  383. {
  384. if( pThis->mbHorz )
  385. {
  386. aTopLineSz.Height() += TB_BORDER_OFFSET2 + nTop;
  387. aBottomLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
  388. if( pThis->mnCurLines == 1 )
  389. aTopLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
  390. }
  391. else
  392. {
  393. aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
  394. aBottomLineSz.Width() += TB_BORDER_OFFSET1 + nRight;
  395. if( pThis->mnCurLines == 1 )
  396. aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
  397. }
  398. }
  399. if( pThis->mbHorz )
  400. {
  401. aTopLineSz.Height() += pThis->mnBorderY;
  402. if( pThis->mnCurLines == 1 )
  403. aTopLineSz.Height() += pThis->mnBorderY;
  404. aBottomLineSz.Height() += pThis->mnBorderY;
  405. }
  406. else
  407. {
  408. aTopLineSz.Width() += pThis->mnBorderX;
  409. if( pThis->mnCurLines == 1 )
  410. aTopLineSz.Width() += pThis->mnBorderX;
  411. aBottomLineSz.Width() += pThis->mnBorderX;
  412. }
  413. if ( pThis->mnWinStyle & WB_LINESPACING )
  414. {
  415. if( pThis->mbHorz )
  416. {
  417. aLineSz.Height() += TB_LINESPACING;
  418. if( pThis->mnCurLines > 1 )
  419. aTopLineSz.Height() += TB_LINESPACING;
  420. }
  421. else
  422. {
  423. aLineSz.Width() += TB_LINESPACING;
  424. if( pThis->mnCurLines > 1 )
  425. aTopLineSz.Width() += TB_LINESPACING;
  426. }
  427. }
  428. if( pThis->mbHorz )
  429. {
  430. long y = 0;
  431. BOOL bDrawSep = FALSE; // pThis->ImplIsFloatingMode() && ( pThis->mnWinStyle & WB_LINESPACING );
  432. pThis->DrawGradient( Rectangle( 0, y, aTopLineSz.Width(), y+aTopLineSz.Height()), g );
  433. y += aTopLineSz.Height();
  434. if ( bDrawSep )
  435. pThis->DrawLine( Point(0, y-2), Point(aTopLineSz.Width(), y-2) );
  436. while( y < (pThis->mnDY - aBottomLineSz.Height()) )
  437. {
  438. pThis->DrawGradient( Rectangle( 0, y, aLineSz.Width(), y+aLineSz.Height()), g);
  439. y += aLineSz.Height();
  440. if ( bDrawSep )
  441. pThis->DrawLine( Point(0, y-2), Point(aLineSz.Width(), y-2) );
  442. }
  443. pThis->DrawGradient( Rectangle( 0, y, aBottomLineSz.Width(), y+aBottomLineSz.Height()), g );
  444. if ( bDrawSep )
  445. pThis->DrawLine( Point(0, y-2), Point(aBottomLineSz.Width(), y-2) );
  446. }
  447. else
  448. {
  449. long x = 0;
  450. pThis->DrawGradient( Rectangle( x, 0, x+aTopLineSz.Width(), aTopLineSz.Height()), g );
  451. x += aTopLineSz.Width();
  452. while( x < (pThis->mnDX - aBottomLineSz.Width()) )
  453. {
  454. pThis->DrawGradient( Rectangle( x, 0, x+aLineSz.Width(), aLineSz.Height()), g);
  455. x += aLineSz.Width();
  456. }
  457. pThis->DrawGradient( Rectangle( x, 0, x+aBottomLineSz.Width(), aBottomLineSz.Height()), g );
  458. }
  459. if( bLineColor )
  460. pThis->SetLineColor( aOldCol );
  461. }
  462. BOOL ToolBox::ImplDrawNativeBackground( ToolBox* pThis, const Region & )
  463. {
  464. // use NWF
  465. Point aPt;
  466. Region aCtrlRegion( Rectangle( aPt, pThis->GetOutputSizePixel() ) );
  467. ControlState nState = CTRL_STATE_ENABLED;
  468. return pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
  469. aCtrlRegion, nState, ImplControlValue(), rtl::OUString() );
  470. }
  471. void ToolBox::ImplDrawTransparentBackground( ToolBox* pThis, const Region &rRegion )
  472. {
  473. // just invalidate to trigger paint of the parent
  474. const bool bOldPaintLock = pThis->mpData->mbIsPaintLocked;
  475. pThis->mpData->mbIsPaintLocked = true;
  476. // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
  477. pThis->Invalidate( rRegion, INVALIDATE_UPDATE|INVALIDATE_NOCLIPCHILDREN );
  478. pThis->mpData->mbIsPaintLocked = bOldPaintLock;
  479. }
  480. void ToolBox::ImplDrawConstantBackground( ToolBox* pThis, const Region &rRegion, BOOL bIsInPopupMode )
  481. {
  482. // draw a constant color
  483. if( !bIsInPopupMode )
  484. // default background
  485. pThis->Erase( rRegion.GetBoundRect() );
  486. else
  487. {
  488. // use different color in popupmode
  489. pThis->DrawWallpaper( rRegion.GetBoundRect(),
  490. Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() ) );
  491. }
  492. }
  493. void ToolBox::ImplDrawBackground( ToolBox* pThis, const Rectangle &rRect )
  494. {
  495. // execute pending paint requests
  496. ImplCheckUpdate( pThis );
  497. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  498. BOOL bIsInPopupMode = pThis->ImplIsInPopupMode();
  499. Region aPaintRegion( rRect );
  500. // make sure we do not invalidate/erase too much
  501. if( pThis->IsInPaint() )
  502. aPaintRegion.Intersect( pThis->GetActiveClipRegion() );
  503. pThis->Push( PUSH_CLIPREGION );
  504. pThis->IntersectClipRegion( aPaintRegion );
  505. if( !pWrapper /*|| bIsInPopupMode*/ )
  506. {
  507. // no gradient for ordinary toolbars (not dockable)
  508. if( !pThis->IsBackground() && !pThis->IsInPaint() )
  509. ImplDrawTransparentBackground( pThis, aPaintRegion );
  510. else
  511. ImplDrawConstantBackground( pThis, aPaintRegion, bIsInPopupMode );
  512. }
  513. else
  514. {
  515. // toolbars known to the dockingmanager will be drawn using NWF or a gradient
  516. // docked toolbars are transparent and NWF is already used in the docking area which is their common background
  517. // so NWF is used here for floating toolbars only
  518. BOOL bNativeOk = FALSE;
  519. if( pThis->ImplIsFloatingMode() && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL) )
  520. bNativeOk = ImplDrawNativeBackground( pThis, aPaintRegion );
  521. if( !bNativeOk )
  522. {
  523. if( !pThis->IsBackground() )
  524. {
  525. if( !pThis->IsInPaint() )
  526. ImplDrawTransparentBackground( pThis, aPaintRegion );
  527. }
  528. else
  529. ImplDrawGradientBackground( pThis, pWrapper );
  530. }
  531. }
  532. // restore clip region
  533. pThis->Pop();
  534. }
  535. void ToolBox::ImplErase( ToolBox* pThis, const Rectangle &rRect, BOOL bHighlight, BOOL bHasOpenPopup )
  536. {
  537. // the background of non NWF buttons is painted in a constant color
  538. // to have the same highlight color (transparency in DrawSelectionBackground())
  539. // items with open popups will also painted using a constant color
  540. if( !pThis->mpData->mbNativeButtons &&
  541. (bHighlight || ! (((Window*) pThis)->GetStyle() & WB_3DLOOK ) ) )
  542. {
  543. if( (((Window*) pThis)->GetStyle() & WB_3DLOOK ) )
  544. {
  545. pThis->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
  546. pThis->SetLineColor();
  547. if( bHasOpenPopup )
  548. // choose the same color as the popup will use
  549. pThis->SetFillColor( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() );
  550. else
  551. pThis->SetFillColor( Color( COL_WHITE ) );
  552. pThis->DrawRect( rRect );
  553. pThis->Pop();
  554. }
  555. else
  556. ImplDrawBackground( pThis, rRect );
  557. }
  558. else
  559. ImplDrawBackground( pThis, rRect );
  560. }
  561. void ToolBox::ImplDrawBorder( ToolBox* pWin )
  562. {
  563. const StyleSettings& rStyleSettings = pWin->GetSettings().GetStyleSettings();
  564. long nDX = pWin->mnDX;
  565. long nDY = pWin->mnDY;
  566. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pWin );
  567. // draw borders for ordinary toolbars only (not dockable)
  568. if( pWrapper )
  569. return;
  570. if ( pWin->meAlign == WINDOWALIGN_BOTTOM )
  571. {
  572. // draw bottom border
  573. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  574. pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
  575. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  576. pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
  577. }
  578. else
  579. {
  580. // draw top border
  581. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  582. pWin->DrawLine( Point( 0, 0 ), Point( nDX-1, 0 ) );
  583. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  584. pWin->DrawLine( Point( 0, 1 ), Point( nDX-1, 1 ) );
  585. if ( (pWin->meAlign == WINDOWALIGN_LEFT) || (pWin->meAlign == WINDOWALIGN_RIGHT) )
  586. {
  587. if ( pWin->meAlign == WINDOWALIGN_LEFT )
  588. {
  589. // draw left-bottom border
  590. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  591. pWin->DrawLine( Point( 0, 0 ), Point( 0, nDY-1 ) );
  592. pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
  593. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  594. pWin->DrawLine( Point( 1, 1 ), Point( 1, nDY-3 ) );
  595. pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
  596. }
  597. else
  598. {
  599. // draw right-bottom border
  600. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  601. pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-3 ) );
  602. pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-2, nDY-2 ) );
  603. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  604. pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
  605. pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
  606. }
  607. }
  608. }
  609. if ( pWin->meAlign == WINDOWALIGN_BOTTOM || pWin->meAlign == WINDOWALIGN_TOP )
  610. {
  611. // draw right border
  612. pWin->SetLineColor( rStyleSettings.GetShadowColor() );
  613. pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-1 ) );
  614. pWin->SetLineColor( rStyleSettings.GetLightColor() );
  615. pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
  616. }
  617. }
  618. // -----------------------------------------------------------------------
  619. static bool ImplIsFixedControl( const ImplToolItem *pItem )
  620. {
  621. return ( pItem->mpWindow &&
  622. (pItem->mpWindow->GetType() == WINDOW_FIXEDTEXT ||
  623. pItem->mpWindow->GetType() == WINDOW_FIXEDLINE ||
  624. pItem->mpWindow->GetType() == WINDOW_GROUPBOX) );
  625. }
  626. // -----------------------------------------------------------------------
  627. const ImplToolItem *ToolBox::ImplGetFirstClippedItem( const ToolBox* pThis )
  628. {
  629. std::vector< ImplToolItem >::const_iterator it;
  630. it = pThis->mpData->m_aItems.begin();
  631. while ( it != pThis->mpData->m_aItems.end() )
  632. {
  633. if( it->IsClipped() )
  634. return &(*it);
  635. ++it;
  636. }
  637. return NULL;
  638. }
  639. // -----------------------------------------------------------------------
  640. Size ToolBox::ImplCalcSize( const ToolBox* pThis, USHORT nCalcLines, USHORT nCalcMode )
  641. {
  642. long nMax;
  643. long nLeft = 0;
  644. long nTop = 0;
  645. long nRight = 0;
  646. long nBottom = 0;
  647. Size aSize;
  648. WindowAlign eOldAlign = pThis->meAlign;
  649. BOOL bOldHorz = pThis->mbHorz;
  650. BOOL bOldAssumeDocked = pThis->mpData->mbAssumeDocked;
  651. BOOL bOldAssumeFloating = pThis->mpData->mbAssumeFloating;
  652. if ( nCalcMode )
  653. {
  654. BOOL bOldFloatingMode = pThis->ImplIsFloatingMode();
  655. pThis->mpData->mbAssumeDocked = FALSE;
  656. pThis->mpData->mbAssumeFloating = FALSE;
  657. if ( nCalcMode == TB_CALCMODE_HORZ )
  658. {
  659. pThis->mpData->mbAssumeDocked = TRUE; // force non-floating mode during calculation
  660. ImplCalcBorder( WINDOWALIGN_TOP, nLeft, nTop, nRight, nBottom, pThis );
  661. ((ToolBox*)pThis)->mbHorz = TRUE;
  662. if ( pThis->mbHorz != bOldHorz )
  663. ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
  664. }
  665. else if ( nCalcMode == TB_CALCMODE_VERT )
  666. {
  667. pThis->mpData->mbAssumeDocked = TRUE; // force non-floating mode during calculation
  668. ImplCalcBorder( WINDOWALIGN_LEFT, nLeft, nTop, nRight, nBottom, pThis );
  669. ((ToolBox*)pThis)->mbHorz = FALSE;
  670. if ( pThis->mbHorz != bOldHorz )
  671. ((ToolBox*)pThis)->meAlign = WINDOWALIGN_LEFT;
  672. }
  673. else if ( nCalcMode == TB_CALCMODE_FLOAT )
  674. {
  675. pThis->mpData->mbAssumeFloating = TRUE; // force non-floating mode during calculation
  676. nLeft = nTop = nRight = nBottom = 0;
  677. ((ToolBox*)pThis)->mbHorz = TRUE;
  678. if ( pThis->mbHorz != bOldHorz )
  679. ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
  680. }
  681. if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) ||
  682. (pThis->ImplIsFloatingMode() != bOldFloatingMode ) )
  683. ((ToolBox*)pThis)->mbCalc = TRUE;
  684. }
  685. else
  686. ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
  687. ((ToolBox*)pThis)->ImplCalcItem();
  688. if( !nCalcMode && pThis->ImplIsFloatingMode() )
  689. {
  690. aSize = ImplCalcFloatSize( ((ToolBox*)pThis), nCalcLines );
  691. }
  692. else
  693. {
  694. if ( pThis->mbHorz )
  695. {
  696. if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
  697. aSize.Height() = nCalcLines * pThis->mnWinHeight;
  698. else
  699. aSize.Height() = nCalcLines * pThis->mnMaxItemHeight;
  700. if ( pThis->mnWinStyle & WB_LINESPACING )
  701. aSize.Height() += (nCalcLines-1)*TB_LINESPACING;
  702. if ( pThis->mnWinStyle & WB_BORDER )
  703. aSize.Height() += (TB_BORDER_OFFSET2*2) + nTop + nBottom;
  704. nMax = 0;
  705. ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
  706. if ( nMax )
  707. aSize.Width() += nMax;
  708. if ( pThis->mnWinStyle & WB_BORDER )
  709. aSize.Width() += (TB_BORDER_OFFSET1*2) + nLeft + nRight;
  710. }
  711. else
  712. {
  713. aSize.Width() = nCalcLines * pThis->mnMaxItemWidth;
  714. if ( pThis->mnWinStyle & WB_LINESPACING )
  715. aSize.Width() += (nCalcLines-1)*TB_LINESPACING;
  716. if ( pThis->mnWinStyle & WB_BORDER )
  717. aSize.Width() += (TB_BORDER_OFFSET2*2) + nLeft + nRight;
  718. nMax = 0;
  719. ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
  720. if ( nMax )
  721. aSize.Height() += nMax;
  722. if ( pThis->mnWinStyle & WB_BORDER )
  723. aSize.Height() += (TB_BORDER_OFFSET1*2) + nTop + nBottom;
  724. }
  725. }
  726. // restore previous values
  727. if ( nCalcMode )
  728. {
  729. pThis->mpData->mbAssumeDocked = bOldAssumeDocked;
  730. pThis->mpData->mbAssumeFloating = bOldAssumeFloating;
  731. if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) )
  732. {
  733. ((ToolBox*)pThis)->meAlign = eOldAlign;
  734. ((ToolBox*)pThis)->mbHorz = bOldHorz;
  735. ((ToolBox*)pThis)->mbCalc = TRUE;
  736. }
  737. }
  738. if ( aSize.Width() )
  739. aSize.Width() += pThis->mnBorderX*2;
  740. if ( aSize.Height() )
  741. aSize.Height() += pThis->mnBorderY*2;
  742. return aSize;
  743. }
  744. // -----------------------------------------------------------------------
  745. void ToolBox::ImplCalcFloatSizes( ToolBox* pThis )
  746. {
  747. if ( pThis->mpFloatSizeAry )
  748. return;
  749. // calculate the minimal size, i.e. where the biggest item just fits
  750. long nCalcSize = 0;
  751. std::vector< ImplToolItem >::const_iterator it;
  752. it = pThis->mpData->m_aItems.begin();
  753. while ( it != pThis->mpData->m_aItems.end() )
  754. {
  755. if ( it->mbVisible )
  756. {
  757. if ( it->mpWindow )
  758. {
  759. long nTempSize = it->mpWindow->GetSizePixel().Width();
  760. if ( nTempSize > nCalcSize )
  761. nCalcSize = nTempSize;
  762. }
  763. else
  764. {
  765. if( it->maItemSize.Width() > nCalcSize )
  766. nCalcSize = it->maItemSize.Width();
  767. }
  768. }
  769. ++it;
  770. }
  771. // calc an upper bound for ImplCalcBreaks below
  772. long upperBoundWidth = nCalcSize * pThis->mpData->m_aItems.size();
  773. USHORT i;
  774. USHORT nLines;
  775. USHORT nCalcLines;
  776. USHORT nTempLines;
  777. long nHeight;
  778. long nMaxLineWidth;
  779. nCalcLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, TRUE );
  780. pThis->mpFloatSizeAry = new ImplToolSizeArray;
  781. pThis->mpFloatSizeAry->mpSize = new ImplToolSize[nCalcLines];
  782. pThis->mpFloatSizeAry->mnLength = nCalcLines;
  783. memset( pThis->mpFloatSizeAry->mpSize, 0, sizeof( ImplToolSize )*nCalcLines );
  784. i = 0;
  785. nTempLines = nLines = nCalcLines;
  786. while ( nLines )
  787. {
  788. nHeight = ImplCalcSize( pThis, nTempLines, TB_CALCMODE_FLOAT ).Height();
  789. pThis->mpFloatSizeAry->mnLastEntry = i;
  790. pThis->mpFloatSizeAry->mpSize[i].mnHeight = nHeight;
  791. pThis->mpFloatSizeAry->mpSize[i].mnLines = nTempLines;
  792. pThis->mpFloatSizeAry->mpSize[i].mnWidth = nMaxLineWidth+(TB_BORDER_OFFSET1*2);
  793. nLines--;
  794. if ( nLines )
  795. {
  796. do
  797. {
  798. nCalcSize += pThis->mnMaxItemWidth;
  799. nTempLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, TRUE );
  800. }
  801. while ( (nCalcSize < upperBoundWidth) && (nLines < nTempLines) && (nTempLines != 1) );
  802. if ( nTempLines < nLines )
  803. nLines = nTempLines;
  804. }
  805. i++;
  806. }
  807. }
  808. // -----------------------------------------------------------------------
  809. Size ToolBox::ImplCalcFloatSize( ToolBox* pThis, USHORT& rLines )
  810. {
  811. ImplCalcFloatSizes( pThis );
  812. if ( !rLines )
  813. {
  814. rLines = pThis->mnFloatLines;
  815. if ( !rLines )
  816. rLines = pThis->mnLines;
  817. }
  818. USHORT i = 0;
  819. while ( i < pThis->mpFloatSizeAry->mnLastEntry &&
  820. rLines < pThis->mpFloatSizeAry->mpSize[i].mnLines )
  821. i++;
  822. Size aSize( pThis->mpFloatSizeAry->mpSize[i].mnWidth,
  823. pThis->mpFloatSizeAry->mpSize[i].mnHeight );
  824. rLines = pThis->mpFloatSizeAry->mpSize[i].mnLines;
  825. if ( pThis->maNextToolBoxStr.Len() && pThis->mbScroll )
  826. aSize.Width() += TB_NEXT_SIZE-TB_NEXT_OFFSET;
  827. return aSize;
  828. }
  829. // -----------------------------------------------------------------------
  830. void ToolBox::ImplCalcMinMaxFloatSize( ToolBox* pThis, Size& rMinSize, Size& rMaxSize )
  831. {
  832. ImplCalcFloatSizes( pThis );
  833. USHORT i = 0;
  834. rMinSize = Size( pThis->mpFloatSizeAry->mpSize[i].mnWidth, pThis->mpFloatSizeAry->mpSize[i].mnHeight );
  835. rMaxSize = Size( pThis->mpFloatSizeAry->mpSize[i].mnWidth, pThis->mpFloatSizeAry->mpSize[i].mnHeight );
  836. while ( ++i <= pThis->mpFloatSizeAry->mnLastEntry )
  837. {
  838. if( pThis->mpFloatSizeAry->mpSize[i].mnWidth < rMinSize.Width() )
  839. rMinSize.Width() = pThis->mpFloatSizeAry->mpSize[i].mnWidth;
  840. if( pThis->mpFloatSizeAry->mpSize[i].mnHeight < rMinSize.Height() )
  841. rMinSize.Height() = pThis->mpFloatSizeAry->mpSize[i].mnHeight;
  842. if( pThis->mpFloatSizeAry->mpSize[i].mnWidth > rMaxSize.Width() )
  843. rMaxSize.Width() = pThis->mpFloatSizeAry->mpSize[i].mnWidth;
  844. if( pThis->mpFloatSizeAry->mpSize[i].mnHeight > rMaxSize.Height() )
  845. rMaxSize.Height() = pThis->mpFloatSizeAry->mpSize[i].mnHeight;
  846. }
  847. }
  848. void ToolBox::ImplSetMinMaxFloatSize( ToolBox *pThis )
  849. {
  850. ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
  851. Size aMinSize, aMaxSize;
  852. ImplCalcMinMaxFloatSize( pThis, aMinSize, aMaxSize );
  853. if( pWrapper )
  854. {
  855. pWrapper->SetMinOutputSizePixel( aMinSize );
  856. pWrapper->SetMaxOutputSizePixel( aMaxSize );
  857. pWrapper->ShowTitleButton( TITLE_BUTTON_MENU, ( pThis->GetMenuType() & TOOLBOX_MENUTYPE_CUSTOMIZE) ? TRUE : FALSE );
  858. }
  859. else
  860. {
  861. // TODO: change SetMinOutputSizePixel to be not inline
  862. pThis->SetMinOutputSizePixel( aMinSize );
  863. pThis->SetMaxOutputSizePixel( aMaxSize );
  864. }
  865. }
  866. // -----------------------------------------------------------------------
  867. USHORT ToolBox::ImplCalcLines( ToolBox* pThis, long nToolSize )
  868. {
  869. long nLineHeight;
  870. if ( pThis->mbHorz )
  871. {
  872. if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
  873. nLineHeight = pThis->mnWinHeight;
  874. else
  875. nLineHeight = pThis->mnMaxItemHeight;
  876. }
  877. else
  878. nLineHeight = pThis->mnMaxItemWidth;
  879. if ( pThis->mnWinStyle & WB_BORDER )
  880. nToolSize -= TB_BORDER_OFFSET2*2;
  881. if ( pThis->mnWinStyle & WB_LINESPACING )
  882. {
  883. nLineHeight += TB_LINESPACING;
  884. nToolSize += TB_LINESPACING;
  885. }
  886. // #i91917# always report at least one line
  887. long nLines = nToolSize/nLineHeight;
  888. if( nLines < 1 )
  889. nLines = 1;
  890. return static_cast<USHORT>(nLines);
  891. }
  892. // -----------------------------------------------------------------------
  893. USHORT ToolBox::ImplTestLineSize( ToolBox* pThis, const Point& rPos )
  894. {
  895. if ( !pThis->ImplIsFloatingMode() &&
  896. (!pThis->mbScroll || (pThis->mnLines > 1) || (pThis->mnCurLines > pThis->mnVisLines)) )
  897. {
  898. WindowAlign eAlign = pThis->GetAlign();
  899. if ( eAlign == WINDOWALIGN_LEFT )
  900. {
  901. if ( rPos.X() > pThis->mnDX-DOCK_LINEOFFSET )
  902. return DOCK_LINEHSIZE | DOCK_LINERIGHT;
  903. }
  904. else if ( eAlign == WINDOWALIGN_TOP )
  905. {
  906. if ( rPos.Y() > pThis->mnDY-DOCK_LINEOFFSET )
  907. return DOCK_LINEVSIZE | DOCK_LINEBOTTOM;
  908. }
  909. else if ( eAlign == WINDOWALIGN_RIGHT )
  910. {
  911. if ( rPos.X() < DOCK_LINEOFFSET )
  912. return DOCK_LINEHSIZE | DOCK_LINELEFT;
  913. }
  914. else if ( eAlign == WINDOWALIGN_BOTTOM )
  915. {
  916. if ( rPos.Y() < DOCK_LINEOFFSET )
  917. return DOCK_LINEVSIZE | DOCK_LINETOP;
  918. }
  919. }
  920. return 0;
  921. }
  922. // -----------------------------------------------------------------------
  923. void ToolBox::ImplLineSizing( ToolBox* pThis, const Point& rPos, Rectangle& rRect,
  924. USHORT nLineMode )
  925. {
  926. BOOL mbHorz;
  927. long nOneLineSize;
  928. long nCurSize;
  929. long nMaxSize;
  930. long nSize;
  931. Size aSize;
  932. if ( nLineMode & DOCK_LINERIGHT )
  933. {
  934. nCurSize = rPos.X() - rRect.Left();
  935. mbHorz = FALSE;
  936. }
  937. else if ( nLineMode & DOCK_LINEBOTTOM )
  938. {
  939. nCurSize = rPos.Y() - rRect.Top();
  940. mbHorz = TRUE;
  941. }
  942. else if ( nLineMode & DOCK_LINELEFT )
  943. {
  944. nCurSize = rRect.Right() - rPos.X();
  945. mbHorz = FALSE;
  946. }
  947. else if ( nLineMode & DOCK_LINETOP )
  948. {
  949. nCurSize = rRect.Bottom() - rPos.Y();
  950. mbHorz = TRUE;
  951. }
  952. else {
  953. DBG_ERROR( "ImplLineSizing: Trailing else" );
  954. nCurSize = 0;
  955. mbHorz = FALSE;
  956. }
  957. Size aWinSize = pThis->GetSizePixel();
  958. USHORT nMaxLines = (pThis->mnLines > pThis->mnCurLines) ? pThis->mnLines : pThis->mnCurLines;
  959. if ( nMaxLines > TB_MAXLINES )
  960. nMaxLines = TB_MAXLINES;
  961. if ( mbHorz )
  962. {
  963. nOneLineSize = ImplCalcSize( pThis, 1 ).Height();
  964. nMaxSize = pThis->maOutDockRect.GetHeight() - 20;
  965. if ( nMaxSize < aWinSize.Height() )
  966. nMaxSize = aWinSize.Height();
  967. }
  968. else
  969. {
  970. nOneLineSize = ImplCalcSize( pThis, 1 ).Width();
  971. nMaxSize = pThis->maOutDockRect.GetWidth() - 20;
  972. if ( nMaxSize < aWinSize.Width() )
  973. nMaxSize = aWinSize.Width();
  974. }
  975. USHORT i = 1;
  976. if ( nCurSize <= nOneLineSize )
  977. nSize = nOneLineSize;
  978. else
  979. {
  980. nSize = 0;
  981. while ( (nSize < nCurSize) && (i < nMaxLines) )
  982. {
  983. i++;
  984. aSize = ImplCalcSize( pThis, i );
  985. if ( mbHorz )
  986. nSize = aSize.Height();
  987. else
  988. nSize = aSize.Width();
  989. if ( nSize > nMaxSize )
  990. {
  991. i--;
  992. aSize = ImplCalcSize( pThis, i );
  993. if ( mbHorz )
  994. nSize = aSize.Height();
  995. else
  996. nSize = aSize.Width();
  997. break;
  998. }
  999. }
  1000. }
  1001. if ( nLineMode & DOCK_LINERIGHT )
  1002. rRect.Right() = rRect.Left()+nSize-1;
  1003. else if ( nLineMode & DOCK_LINEBOTTOM )
  1004. rRect.Bottom() = rRect.Top()+nSize-1;
  1005. else if ( nLineMode & DOCK_LINELEFT )
  1006. rRect.Left() = rRect.Right()-nSize;
  1007. else //if ( nLineMode & DOCK_LINETOP )
  1008. rRect.Top() = rRect.Bottom()-nSize;
  1009. pThis->mnDockLines = i;
  1010. }
  1011. // -----------------------------------------------------------------------
  1012. USHORT ToolBox::ImplFindItemPos( ToolBox* pBox, const Point& rPos )
  1013. {
  1014. USHORT nPos = 0;
  1015. long nLast = 0;
  1016. Point aPos = rPos;
  1017. Size aSize( pBox->mnDX, pBox->mnDY );
  1018. if ( aPos.X() > aSize.Width()-TB_BORDER_OFFSET1 )
  1019. aPos.X() = aSize.Width()-TB_BORDER_OFFSET1;
  1020. if ( aPos.Y() > aSize.Height()-TB_BORDER_OFFSET1 )
  1021. aPos.Y() = aSize.Height()-TB_BORDER_OFFSET1;
  1022. // Item suchen, das geklickt wurde
  1023. std::vector< ImplToolItem >::const_iterator it = pBox->mpData->m_aItems.begin();
  1024. while ( it != pBox->mpData->m_aItems.end() )
  1025. {
  1026. if ( it->mbVisible )
  1027. {
  1028. if ( nLast || !it->maRect.IsEmpty() )
  1029. {
  1030. if ( pBox->mbHorz )
  1031. {
  1032. if ( nLast &&
  1033. ((nLast < it->maRect.Top()) || it->maRect.IsEmpty()) )
  1034. return nPos;
  1035. if ( aPos.Y() <= it->maRect.Bottom() )
  1036. {
  1037. if ( aPos.X() < it->maRect.Left() )
  1038. return nPos;
  1039. else if ( aPos.X() < it->maRect.Right() )
  1040. return nPos+1;
  1041. else if ( !nLast )
  1042. nLast = it->maRect.Bottom();
  1043. }
  1044. }
  1045. else
  1046. {
  1047. if ( nLast &&
  1048. ((nLast < it->maRect.Left()) || it->maRect.IsEmpty()) )
  1049. return nPos;
  1050. if ( aPos.X() <= it->maRect.Right() )
  1051. {
  1052. if ( aPos.Y() < it->maRect.Top() )
  1053. return nPos;
  1054. else if ( aPos.Y() < it->maRect.Bottom() )
  1055. return nPos+1;
  1056. else if ( !nLast )
  1057. nLast = it->maRect.Right();
  1058. }
  1059. }
  1060. }
  1061. }
  1062. nPos++;
  1063. ++it;
  1064. }
  1065. return nPos;
  1066. }
  1067. // -----------------------------------------------------------------------
  1068. ImplTBDragMgr::ImplTBDragMgr()
  1069. {
  1070. mpBoxList = new ImplTBList( 4, 4 );
  1071. mnLineMode = 0;
  1072. mnStartLines = 0;
  1073. mbCustomizeMode = FALSE;
  1074. mbResizeMode = FALSE;
  1075. mbShowDragRect = FALSE;
  1076. mpDragBox = NULL;
  1077. maAccel.InsertItem( KEY_RETURN, KeyCode( KEY_RETURN ) );
  1078. maAccel.InsertItem( KEY_ESCAPE, KeyCode( KEY_ESCAPE ) );
  1079. maAccel.SetSelectHdl( LINK( this, ImplTBDragMgr, SelectHdl ) );
  1080. }
  1081. // -----------------------------------------------------------------------
  1082. ImplTBDragMgr::~ImplTBDragMgr()
  1083. {
  1084. delete mpBoxList;
  1085. }
  1086. // -----------------------------------------------------------------------
  1087. ToolBox* ImplTBDragMgr::FindToolBox( const Rectangle& rRect )
  1088. {
  1089. ToolBox* pBox = mpBoxList->First();
  1090. while ( pBox )
  1091. {
  1092. /*
  1093. * FIXME: since we can have multiple frames now we cannot
  1094. * find the drag target by its position alone.
  1095. * As long as the toolbar config dialogue is not a system window
  1096. * this works in one frame only anyway. If the dialogue
  1097. * changes to a system window, we need a new implementation here
  1098. */
  1099. if ( pBox->IsReallyVisible() && pBox->ImplGetWindowImpl()->mpFrame == mpDragBox->ImplGetWindowImpl()->mpFrame )
  1100. {
  1101. if ( !pBox->ImplIsFloatingMode() )
  1102. {
  1103. Point aPos = pBox->GetPosPixel();
  1104. aPos = pBox->GetParent()->OutputToScreenPixel( aPos );
  1105. Rectangle aTempRect( aPos, pBox->GetSizePixel() );
  1106. if ( aTempRect.IsOver( rRect ) )
  1107. return pBox;
  1108. }
  1109. }
  1110. pBox = mpBoxList->Next();
  1111. }
  1112. return pBox;
  1113. }
  1114. // -----------------------------------------------------------------------
  1115. void ImplTBDragMgr::StartDragging( ToolBox* pToolBox,
  1116. const Point& rPos, const Rectangle& rRect,
  1117. USHORT nDragLineMode, BOOL bResizeItem,
  1118. void* pData )
  1119. {
  1120. mpDragBox = pToolBox;
  1121. pToolBox->CaptureMouse();
  1122. pToolBox->mbDragging = TRUE;
  1123. Application::InsertAccel( &maAccel );
  1124. if ( nDragLineMode )
  1125. {
  1126. mnLineMode = nDragLineMode;
  1127. mnStartLines = pToolBox->mnDockLines;
  1128. }
  1129. else
  1130. {
  1131. mpCustomizeData = pData;
  1132. mbResizeMode = bResizeItem;
  1133. pToolBox->Activate();
  1134. pToolBox->mnCurItemId = pToolBox->mnConfigItem;
  1135. pToolBox->Highlight();
  1136. pToolBox->mnCurItemId = 0;
  1137. if ( mbResizeMode )
  1138. {
  1139. if ( rRect.GetWidth() < TB_MIN_WIN_WIDTH )
  1140. mnMinWidth = rRect.GetWidth();
  1141. else
  1142. mnMinWidth = TB_MIN_WIN_WIDTH;
  1143. mnMaxWidth = pToolBox->GetSizePixel().Width()-rRect.Left()-
  1144. TB_SPIN_SIZE-TB_BORDER_OFFSET1-(TB_SPIN_OFFSET*2);
  1145. }
  1146. }
  1147. // MouseOffset berechnen
  1148. maMouseOff.X() = rRect.Left() - rPos.X();
  1149. maMouseOff.Y() = rRect.Top() - rPos.Y();
  1150. maRect = rRect;
  1151. maStartRect = rRect;
  1152. mbShowDragRect = TRUE;
  1153. pToolBox->ShowTracking( maRect );
  1154. }
  1155. // -----------------------------------------------------------------------
  1156. void ImplTBDragMgr::Dragging( const Point& rPos )
  1157. {
  1158. if ( mnLineMode )
  1159. {
  1160. ToolBox::ImplLineSizing( mpDragBox, rPos, maRect, mnLineMode );
  1161. Point aOff = mpDragBox->OutputToScreenPixel( Point() );
  1162. maRect.Move( aOff.X(), aOff.Y() );
  1163. mpDragBox->Docking( rPos, maRect );
  1164. maRect.Move( -aOff.X(), -aOff.Y() );
  1165. mpDragBox->ShowTracking( maRect );
  1166. }
  1167. else
  1168. {
  1169. if ( mbResizeMode )
  1170. {
  1171. long nXOff = rPos.X()-maStartRect.Left();
  1172. nXOff += maMouseOff.X()+(maStartRect.Right()-maStartRect.Left());
  1173. if ( nXOff < mnMinWidth )
  1174. nXOff = mnMinWidth;
  1175. if ( nXOff > mnMaxWidth )
  1176. nXOff = mnMaxWidth;
  1177. maRect.Right() = maStartRect.Left()+nXOff;
  1178. }
  1179. else
  1180. {
  1181. maRect.SetPos( rPos );
  1182. maRect.Move( maMouseOff.X(), maMouseOff.Y() );
  1183. }
  1184. mpDragBox->ShowTracking( maRect );
  1185. }
  1186. }
  1187. // -----------------------------------------------------------------------
  1188. void ImplTBDragMgr::EndDragging( BOOL bOK )
  1189. {
  1190. mpDragBox->HideTracking();
  1191. mpDragBox->ReleaseMouse();
  1192. mpDragBox->mbDragging = FALSE;
  1193. mbShowDragRect = FALSE;
  1194. Application::RemoveAccel( &maAccel );
  1195. if ( mnLineMode )
  1196. {
  1197. if ( !bOK )
  1198. {
  1199. mpDragBox->mnDockLines = mnStartLines;
  1200. mpDragBox->EndDocking( maStartRect, FALSE );
  1201. }
  1202. else
  1203. mpDragBox->EndDocking( maRect, FALSE );
  1204. mnLineMode = 0;
  1205. mnStartLines = 0;
  1206. }
  1207. else
  1208. {
  1209. USHORT nTempItem = mpDragBox->mnConfigItem;
  1210. if ( nTempItem )
  1211. {
  1212. mpDragBox->mnConfigItem = 0;
  1213. if ( !mbResizeMode )
  1214. mpDragBox->Invalidate( mpDragBox->GetItemRect( nTempItem ) );
  1215. }
  1216. if ( bOK && (maRect != maStartRect) )
  1217. {
  1218. if ( mbResizeMode )
  1219. {
  1220. ImplToolItem* pItem = mpDragBox->ImplGetItem( nTempItem );
  1221. Size aSize = pItem->mpWindow->GetSizePixel();
  1222. aSize.Width() = maRect.GetWidth();
  1223. pItem->mpWindow->SetSizePixel( aSize );
  1224. // ToolBox neu brechnen und neu ausgeben
  1225. mpDragBox->ImplInvalidate( TRUE );
  1226. mpDragBox->Customize( ToolBoxCustomizeEvent( mpDragBox, nTempItem,
  1227. TOOLBOX_CUSTOMIZE_RESIZE,
  1228. mpCustomizeData ) );
  1229. }
  1230. else
  1231. {
  1232. Point aOff = mpDragBox->OutputToScreenPixel( Point() );
  1233. Rectangle aScreenRect( maRect );
  1234. aScreenRect.Move( aOff.X(), aOff.Y() );
  1235. ToolBox* pDropBox = FindToolBox( aScreenRect );
  1236. if ( pDropBox )
  1237. {
  1238. // Such-Position bestimmen
  1239. Point aPos;
  1240. if ( pDropBox->mbHorz )
  1241. {
  1242. aPos.X() = aScreenRect.Left()-TB_CUSTOMIZE_OFFSET;
  1243. aPos.Y() = aScreenRect.Center().Y();
  1244. }
  1245. else
  1246. {
  1247. aPos.X() = aScreenRect.Center().X();
  1248. aPos.Y() = aScreenRect.Top()-TB_CUSTOMIZE_OFFSET;
  1249. }
  1250. aPos = pDropBox->ScreenToOutputPixel( aPos );
  1251. USHORT nPos = ToolBox::ImplFindItemPos( pDropBox, aPos );
  1252. mpDragBox->Customize( ToolBoxCustomizeEvent( pDropBox, nTempItem,
  1253. nPos, mpCustomizeData ) );
  1254. }
  1255. else
  1256. {
  1257. mpDragBox->Customize( ToolBoxCustomizeEvent( NULL, nTempItem,
  1258. 0, mpCustomizeData ) );
  1259. }
  1260. }
  1261. }
  1262. mpCustomizeData = NULL;
  1263. mbResizeMode = FALSE;
  1264. mpDragBox->Deactivate();
  1265. }
  1266. mpDragBox = NULL;
  1267. }
  1268. // -----------------------------------------------------------------------
  1269. void ImplTBDragMgr::UpdateDragRect()
  1270. {
  1271. // Nur Updaten, wenn wir schon im Dragging sind
  1272. if ( !mbShowDragRect )
  1273. return;
  1274. mpDragBox->ShowTracking( maRect );
  1275. }
  1276. // -----------------------------------------------------------------------
  1277. IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator*, pAccel )
  1278. {
  1279. if ( pAccel->GetCurItemId() == KEY_ESCAPE )
  1280. EndDragging( FALSE );
  1281. else
  1282. EndDragging( TRUE );
  1283. return TRUE;
  1284. }
  1285. // -----------------------------------------------------------------------
  1286. void ImplTBDragMgr::StartC

Large files files are truncated, but you can click here to view the full file