update dev300-m58
[ooovba.git] / svtools / source / control / taskmisc.cxx
blobe947eb595beb76ef06c9375cddd84a941717af15
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: taskmisc.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define _TASKBAR_CXX
36 #ifndef _TOOLS_LIST_HXX
37 #include <tools/list.hxx>
38 #endif
39 #include <tools/debug.hxx>
40 #include <vcl/help.hxx>
42 #include <taskbar.hxx>
44 // =======================================================================
46 TaskButtonBar::TaskButtonBar( Window* pParent, WinBits nWinStyle ) :
47 ToolBox( pParent, nWinStyle | WB_3DLOOK )
49 SetAlign( WINDOWALIGN_BOTTOM );
50 SetButtonType( BUTTON_SYMBOLTEXT );
53 // -----------------------------------------------------------------------
55 TaskButtonBar::~TaskButtonBar()
59 // -----------------------------------------------------------------------
61 void TaskButtonBar::RequestHelp( const HelpEvent& rHEvt )
63 ToolBox::RequestHelp( rHEvt );
66 // =======================================================================
68 WindowArrange::WindowArrange()
70 mpWinList = new List;
73 // -----------------------------------------------------------------------
75 WindowArrange::~WindowArrange()
77 delete mpWinList;
80 // -----------------------------------------------------------------------
82 static USHORT ImplCeilSqareRoot( USHORT nVal )
84 USHORT i;
86 // Ueberlauf verhindern
87 if ( nVal > 0xFE * 0xFE )
88 return 0xFE;
90 for ( i=0; i*i < nVal; i++ )
93 return i;
96 // -----------------------------------------------------------------------
98 static void ImplPosSizeWindow( Window* pWindow,
99 long nX, long nY, long nWidth, long nHeight )
101 if ( nWidth < 32 )
102 nWidth = 32;
103 if ( nHeight < 24 )
104 nHeight = 24;
105 pWindow->SetPosSizePixel( nX, nY, nWidth, nHeight );
108 // -----------------------------------------------------------------------
110 void WindowArrange::ImplTile( const Rectangle& rRect )
112 USHORT nCount = (USHORT)mpWinList->Count();
113 if ( nCount < 3 )
115 ImplVert( rRect );
116 return;
119 USHORT i;
120 USHORT j;
121 USHORT nCols;
122 USHORT nRows;
123 USHORT nActRows;
124 USHORT nOffset;
125 long nOverWidth;
126 long nOverHeight;
127 Window* pWindow;
128 long nX = rRect.Left();
129 long nY = rRect.Top();
130 long nWidth = rRect.GetWidth();
131 long nHeight = rRect.GetHeight();
132 long nRectY = nY;
133 long nRectWidth = nWidth;
134 long nRectHeight = nHeight;
135 long nTempWidth;
136 long nTempHeight;
138 nCols = ImplCeilSqareRoot( nCount );
139 nOffset = (nCols*nCols) - nCount;
140 if ( nOffset >= nCols )
142 nRows = nCols -1;
143 nOffset = nOffset - nCols;
145 else
146 nRows = nCols;
148 nWidth /= nCols;
149 if ( nWidth < 1 )
150 nWidth = 1;
151 nOverWidth = nRectWidth-(nWidth*nCols);
153 pWindow = (Window*)mpWinList->First();
154 for ( i = 0; i < nCols; i++ )
156 if ( i < nOffset )
157 nActRows = nRows - 1;
158 else
159 nActRows = nRows;
161 nTempWidth = nWidth;
162 if ( nOverWidth > 0 )
164 nTempWidth++;
165 nOverWidth--;
168 nHeight = nRectHeight / nActRows;
169 if ( nHeight < 1 )
170 nHeight = 1;
171 nOverHeight = nRectHeight-(nHeight*nActRows);
172 for ( j = 0; j < nActRows; j++ )
174 // Ueberhang verteilen
175 nTempHeight = nHeight;
176 if ( nOverHeight > 0 )
178 nTempHeight++;
179 nOverHeight--;
181 ImplPosSizeWindow( pWindow, nX, nY, nTempWidth, nTempHeight );
182 nY += nTempHeight;
184 pWindow = (Window*)mpWinList->Next();
185 if ( !pWindow )
186 break;
189 nX += nWidth;
190 nY = nRectY;
192 if ( !pWindow )
193 break;
197 // -----------------------------------------------------------------------
199 void WindowArrange::ImplHorz( const Rectangle& rRect )
201 long nCount = (long)mpWinList->Count();
202 long nX = rRect.Left();
203 long nY = rRect.Top();
204 long nWidth = rRect.GetWidth();
205 long nHeight = rRect.GetHeight();
206 long nRectHeight = nHeight;
207 long nOver;
208 long nTempHeight;
209 Window* pWindow;
211 nHeight /= nCount;
212 if ( nHeight < 1 )
213 nHeight = 1;
214 nOver = nRectHeight - (nCount*nHeight);
215 pWindow = (Window*)mpWinList->First();
216 while ( pWindow )
218 nTempHeight = nHeight;
219 if ( nOver > 0 )
221 nTempHeight++;
222 nOver--;
224 ImplPosSizeWindow( pWindow, nX, nY, nWidth, nTempHeight );
225 nY += nTempHeight;
227 pWindow = (Window*)mpWinList->Next();
231 // -----------------------------------------------------------------------
233 void WindowArrange::ImplVert( const Rectangle& rRect )
235 long nCount = (long)mpWinList->Count();
236 long nX = rRect.Left();
237 long nY = rRect.Top();
238 long nWidth = rRect.GetWidth();
239 long nHeight = rRect.GetHeight();
240 long nRectWidth = nWidth;
241 long nOver;
242 long nTempWidth;
243 Window* pWindow;
245 nWidth /= nCount;
246 if ( nWidth < 1 )
247 nWidth = 1;
248 nOver = nRectWidth - (nCount*nWidth);
249 pWindow = (Window*)mpWinList->First();
250 while ( pWindow )
252 nTempWidth = nWidth;
253 if ( nOver > 0 )
255 nTempWidth++;
256 nOver--;
258 ImplPosSizeWindow( pWindow, nX, nY, nTempWidth, nHeight );
259 nX += nTempWidth;
261 pWindow = (Window*)mpWinList->Next();
265 // -----------------------------------------------------------------------
267 void WindowArrange::ImplCascade( const Rectangle& rRect )
269 long nX = rRect.Left();
270 long nY = rRect.Top();
271 long nWidth = rRect.GetWidth();
272 long nHeight = rRect.GetHeight();
273 long nRectWidth = nWidth;
274 long nRectHeight = nHeight;
275 long nOff;
276 long nCascadeWins;
277 sal_Int32 nLeftBorder;
278 sal_Int32 nTopBorder;
279 sal_Int32 nRightBorder;
280 sal_Int32 nBottomBorder;
281 long nStartOverWidth;
282 long nStartOverHeight;
283 long nOverWidth = 0;
284 long nOverHeight = 0;
285 long nTempX;
286 long nTempY;
287 long nTempWidth;
288 long nTempHeight;
289 long i;
290 Window* pWindow;
291 Window* pTempWindow;
293 // Border-Fenster suchen um den Versatz zu ermitteln
294 pTempWindow = (Window*)mpWinList->First();
295 pTempWindow->GetBorder( nLeftBorder, nTopBorder, nRightBorder, nBottomBorder );
296 while ( !nTopBorder )
298 Window* pBrdWin = pTempWindow->GetWindow( WINDOW_REALPARENT );
299 if ( !pBrdWin || (pBrdWin->GetWindow( WINDOW_CLIENT ) != pTempWindow) )
300 break;
301 pTempWindow = pBrdWin;
302 pTempWindow->GetBorder( nLeftBorder, nTopBorder, nRightBorder, nBottomBorder );
304 if ( !nTopBorder )
305 nTopBorder = 22;
306 nOff = nTopBorder;
308 nCascadeWins = nRectHeight / 3 / nOff;
309 if ( !nCascadeWins )
310 nCascadeWins = 1;
311 nWidth -= nCascadeWins*nOff;
312 nHeight -= nCascadeWins*nOff;
313 if ( nWidth < 1 )
314 nWidth = 1;
315 if ( nHeight < 1 )
316 nHeight = 1;
318 nStartOverWidth = nRectWidth-(nWidth+(nCascadeWins*nOff));
319 nStartOverHeight = nRectHeight-(nHeight+(nCascadeWins*nOff));
321 i = 0;
322 pWindow = (Window*)mpWinList->First();
323 while ( pWindow )
325 if ( !i )
327 nOverWidth = nStartOverWidth;
328 nOverHeight = nStartOverHeight;
331 // Position
332 nTempX = nX + (i*nOff);
333 nTempY = nY + (i*nOff);
335 // Ueberhang verteilen
336 nTempWidth = nWidth;
337 if ( nOverWidth > 0 )
339 nTempWidth++;
340 nOverWidth--;
342 nTempHeight = nHeight;
343 if ( nOverHeight > 0 )
345 nTempHeight++;
346 nOverHeight--;
349 ImplPosSizeWindow( pWindow, nTempX, nTempY, nTempWidth, nTempHeight );
351 if ( i < nCascadeWins )
352 i++;
353 else
354 i = 0;
356 pWindow = (Window*)mpWinList->Next();
360 // -----------------------------------------------------------------------
362 void WindowArrange::Arrange( USHORT nType, const Rectangle& rRect )
364 if ( !mpWinList->Count() )
365 return;
367 switch ( nType )
369 case WINDOWARRANGE_TILE:
370 ImplTile( rRect );
371 break;
372 case WINDOWARRANGE_HORZ:
373 ImplHorz( rRect );
374 break;
375 case WINDOWARRANGE_VERT:
376 ImplVert( rRect );
377 break;
378 case WINDOWARRANGE_CASCADE:
379 ImplCascade( rRect );
380 break;