1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #define _TASKBAR_CXX 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <tools/list.hxx> 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir #include <vcl/help.hxx> 36*cdf0e10cSrcweir #include <svtools/taskbar.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir // ======================================================================= 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir TaskButtonBar::TaskButtonBar( Window* pParent, WinBits nWinStyle ) : 41*cdf0e10cSrcweir ToolBox( pParent, nWinStyle | WB_3DLOOK ) 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir SetAlign( WINDOWALIGN_BOTTOM ); 44*cdf0e10cSrcweir SetButtonType( BUTTON_SYMBOLTEXT ); 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // ----------------------------------------------------------------------- 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir TaskButtonBar::~TaskButtonBar() 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // ----------------------------------------------------------------------- 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir void TaskButtonBar::RequestHelp( const HelpEvent& rHEvt ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir ToolBox::RequestHelp( rHEvt ); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // ======================================================================= 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir WindowArrange::WindowArrange() 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir mpWinList = new List; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir // ----------------------------------------------------------------------- 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir WindowArrange::~WindowArrange() 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir delete mpWinList; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // ----------------------------------------------------------------------- 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir static sal_uInt16 ImplCeilSqareRoot( sal_uInt16 nVal ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir sal_uInt16 i; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // Ueberlauf verhindern 81*cdf0e10cSrcweir if ( nVal > 0xFE * 0xFE ) 82*cdf0e10cSrcweir return 0xFE; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir for ( i=0; i*i < nVal; i++ ) 85*cdf0e10cSrcweir {} 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir return i; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // ----------------------------------------------------------------------- 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir static void ImplPosSizeWindow( Window* pWindow, 93*cdf0e10cSrcweir long nX, long nY, long nWidth, long nHeight ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir if ( nWidth < 32 ) 96*cdf0e10cSrcweir nWidth = 32; 97*cdf0e10cSrcweir if ( nHeight < 24 ) 98*cdf0e10cSrcweir nHeight = 24; 99*cdf0e10cSrcweir pWindow->SetPosSizePixel( nX, nY, nWidth, nHeight ); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // ----------------------------------------------------------------------- 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void WindowArrange::ImplTile( const Rectangle& rRect ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16)mpWinList->Count(); 107*cdf0e10cSrcweir if ( nCount < 3 ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir ImplVert( rRect ); 110*cdf0e10cSrcweir return; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir sal_uInt16 i; 114*cdf0e10cSrcweir sal_uInt16 j; 115*cdf0e10cSrcweir sal_uInt16 nCols; 116*cdf0e10cSrcweir sal_uInt16 nRows; 117*cdf0e10cSrcweir sal_uInt16 nActRows; 118*cdf0e10cSrcweir sal_uInt16 nOffset; 119*cdf0e10cSrcweir long nOverWidth; 120*cdf0e10cSrcweir long nOverHeight; 121*cdf0e10cSrcweir Window* pWindow; 122*cdf0e10cSrcweir long nX = rRect.Left(); 123*cdf0e10cSrcweir long nY = rRect.Top(); 124*cdf0e10cSrcweir long nWidth = rRect.GetWidth(); 125*cdf0e10cSrcweir long nHeight = rRect.GetHeight(); 126*cdf0e10cSrcweir long nRectY = nY; 127*cdf0e10cSrcweir long nRectWidth = nWidth; 128*cdf0e10cSrcweir long nRectHeight = nHeight; 129*cdf0e10cSrcweir long nTempWidth; 130*cdf0e10cSrcweir long nTempHeight; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir nCols = ImplCeilSqareRoot( nCount ); 133*cdf0e10cSrcweir nOffset = (nCols*nCols) - nCount; 134*cdf0e10cSrcweir if ( nOffset >= nCols ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir nRows = nCols -1; 137*cdf0e10cSrcweir nOffset = nOffset - nCols; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir else 140*cdf0e10cSrcweir nRows = nCols; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir nWidth /= nCols; 143*cdf0e10cSrcweir if ( nWidth < 1 ) 144*cdf0e10cSrcweir nWidth = 1; 145*cdf0e10cSrcweir nOverWidth = nRectWidth-(nWidth*nCols); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir pWindow = (Window*)mpWinList->First(); 148*cdf0e10cSrcweir for ( i = 0; i < nCols; i++ ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir if ( i < nOffset ) 151*cdf0e10cSrcweir nActRows = nRows - 1; 152*cdf0e10cSrcweir else 153*cdf0e10cSrcweir nActRows = nRows; 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir nTempWidth = nWidth; 156*cdf0e10cSrcweir if ( nOverWidth > 0 ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir nTempWidth++; 159*cdf0e10cSrcweir nOverWidth--; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir nHeight = nRectHeight / nActRows; 163*cdf0e10cSrcweir if ( nHeight < 1 ) 164*cdf0e10cSrcweir nHeight = 1; 165*cdf0e10cSrcweir nOverHeight = nRectHeight-(nHeight*nActRows); 166*cdf0e10cSrcweir for ( j = 0; j < nActRows; j++ ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir // Ueberhang verteilen 169*cdf0e10cSrcweir nTempHeight = nHeight; 170*cdf0e10cSrcweir if ( nOverHeight > 0 ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir nTempHeight++; 173*cdf0e10cSrcweir nOverHeight--; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir ImplPosSizeWindow( pWindow, nX, nY, nTempWidth, nTempHeight ); 176*cdf0e10cSrcweir nY += nTempHeight; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir pWindow = (Window*)mpWinList->Next(); 179*cdf0e10cSrcweir if ( !pWindow ) 180*cdf0e10cSrcweir break; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir nX += nWidth; 184*cdf0e10cSrcweir nY = nRectY; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir if ( !pWindow ) 187*cdf0e10cSrcweir break; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // ----------------------------------------------------------------------- 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir void WindowArrange::ImplHorz( const Rectangle& rRect ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir long nCount = (long)mpWinList->Count(); 196*cdf0e10cSrcweir long nX = rRect.Left(); 197*cdf0e10cSrcweir long nY = rRect.Top(); 198*cdf0e10cSrcweir long nWidth = rRect.GetWidth(); 199*cdf0e10cSrcweir long nHeight = rRect.GetHeight(); 200*cdf0e10cSrcweir long nRectHeight = nHeight; 201*cdf0e10cSrcweir long nOver; 202*cdf0e10cSrcweir long nTempHeight; 203*cdf0e10cSrcweir Window* pWindow; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir nHeight /= nCount; 206*cdf0e10cSrcweir if ( nHeight < 1 ) 207*cdf0e10cSrcweir nHeight = 1; 208*cdf0e10cSrcweir nOver = nRectHeight - (nCount*nHeight); 209*cdf0e10cSrcweir pWindow = (Window*)mpWinList->First(); 210*cdf0e10cSrcweir while ( pWindow ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir nTempHeight = nHeight; 213*cdf0e10cSrcweir if ( nOver > 0 ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir nTempHeight++; 216*cdf0e10cSrcweir nOver--; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir ImplPosSizeWindow( pWindow, nX, nY, nWidth, nTempHeight ); 219*cdf0e10cSrcweir nY += nTempHeight; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir pWindow = (Window*)mpWinList->Next(); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir // ----------------------------------------------------------------------- 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void WindowArrange::ImplVert( const Rectangle& rRect ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir long nCount = (long)mpWinList->Count(); 230*cdf0e10cSrcweir long nX = rRect.Left(); 231*cdf0e10cSrcweir long nY = rRect.Top(); 232*cdf0e10cSrcweir long nWidth = rRect.GetWidth(); 233*cdf0e10cSrcweir long nHeight = rRect.GetHeight(); 234*cdf0e10cSrcweir long nRectWidth = nWidth; 235*cdf0e10cSrcweir long nOver; 236*cdf0e10cSrcweir long nTempWidth; 237*cdf0e10cSrcweir Window* pWindow; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir nWidth /= nCount; 240*cdf0e10cSrcweir if ( nWidth < 1 ) 241*cdf0e10cSrcweir nWidth = 1; 242*cdf0e10cSrcweir nOver = nRectWidth - (nCount*nWidth); 243*cdf0e10cSrcweir pWindow = (Window*)mpWinList->First(); 244*cdf0e10cSrcweir while ( pWindow ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir nTempWidth = nWidth; 247*cdf0e10cSrcweir if ( nOver > 0 ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir nTempWidth++; 250*cdf0e10cSrcweir nOver--; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir ImplPosSizeWindow( pWindow, nX, nY, nTempWidth, nHeight ); 253*cdf0e10cSrcweir nX += nTempWidth; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir pWindow = (Window*)mpWinList->Next(); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // ----------------------------------------------------------------------- 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir void WindowArrange::ImplCascade( const Rectangle& rRect ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir long nX = rRect.Left(); 264*cdf0e10cSrcweir long nY = rRect.Top(); 265*cdf0e10cSrcweir long nWidth = rRect.GetWidth(); 266*cdf0e10cSrcweir long nHeight = rRect.GetHeight(); 267*cdf0e10cSrcweir long nRectWidth = nWidth; 268*cdf0e10cSrcweir long nRectHeight = nHeight; 269*cdf0e10cSrcweir long nOff; 270*cdf0e10cSrcweir long nCascadeWins; 271*cdf0e10cSrcweir sal_Int32 nLeftBorder; 272*cdf0e10cSrcweir sal_Int32 nTopBorder; 273*cdf0e10cSrcweir sal_Int32 nRightBorder; 274*cdf0e10cSrcweir sal_Int32 nBottomBorder; 275*cdf0e10cSrcweir long nStartOverWidth; 276*cdf0e10cSrcweir long nStartOverHeight; 277*cdf0e10cSrcweir long nOverWidth = 0; 278*cdf0e10cSrcweir long nOverHeight = 0; 279*cdf0e10cSrcweir long nTempX; 280*cdf0e10cSrcweir long nTempY; 281*cdf0e10cSrcweir long nTempWidth; 282*cdf0e10cSrcweir long nTempHeight; 283*cdf0e10cSrcweir long i; 284*cdf0e10cSrcweir Window* pWindow; 285*cdf0e10cSrcweir Window* pTempWindow; 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir // Border-Fenster suchen um den Versatz zu ermitteln 288*cdf0e10cSrcweir pTempWindow = (Window*)mpWinList->First(); 289*cdf0e10cSrcweir pTempWindow->GetBorder( nLeftBorder, nTopBorder, nRightBorder, nBottomBorder ); 290*cdf0e10cSrcweir while ( !nTopBorder ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir Window* pBrdWin = pTempWindow->GetWindow( WINDOW_REALPARENT ); 293*cdf0e10cSrcweir if ( !pBrdWin || (pBrdWin->GetWindow( WINDOW_CLIENT ) != pTempWindow) ) 294*cdf0e10cSrcweir break; 295*cdf0e10cSrcweir pTempWindow = pBrdWin; 296*cdf0e10cSrcweir pTempWindow->GetBorder( nLeftBorder, nTopBorder, nRightBorder, nBottomBorder ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir if ( !nTopBorder ) 299*cdf0e10cSrcweir nTopBorder = 22; 300*cdf0e10cSrcweir nOff = nTopBorder; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir nCascadeWins = nRectHeight / 3 / nOff; 303*cdf0e10cSrcweir if ( !nCascadeWins ) 304*cdf0e10cSrcweir nCascadeWins = 1; 305*cdf0e10cSrcweir nWidth -= nCascadeWins*nOff; 306*cdf0e10cSrcweir nHeight -= nCascadeWins*nOff; 307*cdf0e10cSrcweir if ( nWidth < 1 ) 308*cdf0e10cSrcweir nWidth = 1; 309*cdf0e10cSrcweir if ( nHeight < 1 ) 310*cdf0e10cSrcweir nHeight = 1; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir nStartOverWidth = nRectWidth-(nWidth+(nCascadeWins*nOff)); 313*cdf0e10cSrcweir nStartOverHeight = nRectHeight-(nHeight+(nCascadeWins*nOff)); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir i = 0; 316*cdf0e10cSrcweir pWindow = (Window*)mpWinList->First(); 317*cdf0e10cSrcweir while ( pWindow ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir if ( !i ) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir nOverWidth = nStartOverWidth; 322*cdf0e10cSrcweir nOverHeight = nStartOverHeight; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir // Position 326*cdf0e10cSrcweir nTempX = nX + (i*nOff); 327*cdf0e10cSrcweir nTempY = nY + (i*nOff); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir // Ueberhang verteilen 330*cdf0e10cSrcweir nTempWidth = nWidth; 331*cdf0e10cSrcweir if ( nOverWidth > 0 ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir nTempWidth++; 334*cdf0e10cSrcweir nOverWidth--; 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir nTempHeight = nHeight; 337*cdf0e10cSrcweir if ( nOverHeight > 0 ) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir nTempHeight++; 340*cdf0e10cSrcweir nOverHeight--; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir ImplPosSizeWindow( pWindow, nTempX, nTempY, nTempWidth, nTempHeight ); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir if ( i < nCascadeWins ) 346*cdf0e10cSrcweir i++; 347*cdf0e10cSrcweir else 348*cdf0e10cSrcweir i = 0; 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir pWindow = (Window*)mpWinList->Next(); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir // ----------------------------------------------------------------------- 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir void WindowArrange::Arrange( sal_uInt16 nType, const Rectangle& rRect ) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir if ( !mpWinList->Count() ) 359*cdf0e10cSrcweir return; 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir switch ( nType ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir case WINDOWARRANGE_TILE: 364*cdf0e10cSrcweir ImplTile( rRect ); 365*cdf0e10cSrcweir break; 366*cdf0e10cSrcweir case WINDOWARRANGE_HORZ: 367*cdf0e10cSrcweir ImplHorz( rRect ); 368*cdf0e10cSrcweir break; 369*cdf0e10cSrcweir case WINDOWARRANGE_VERT: 370*cdf0e10cSrcweir ImplVert( rRect ); 371*cdf0e10cSrcweir break; 372*cdf0e10cSrcweir case WINDOWARRANGE_CASCADE: 373*cdf0e10cSrcweir ImplCascade( rRect ); 374*cdf0e10cSrcweir break; 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378