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 #include <svtools/editbrowsebox.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #ifndef _SVTOOLS_EDITBROWSEBOX_HRC_ 33*cdf0e10cSrcweir #include "editbrowsebox.hrc" 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #ifndef _APP_HXX //autogen 37*cdf0e10cSrcweir #include <vcl/svapp.hxx> 38*cdf0e10cSrcweir #endif 39*cdf0e10cSrcweir #include <tools/debug.hxx> 40*cdf0e10cSrcweir #include <vcl/window.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #ifndef _EDIT_HXX //autogen 43*cdf0e10cSrcweir #include <vcl/edit.hxx> 44*cdf0e10cSrcweir #endif 45*cdf0e10cSrcweir #include <tools/resid.hxx> 46*cdf0e10cSrcweir #include <vcl/spinfld.hxx> 47*cdf0e10cSrcweir #include <svtools/svtdata.hxx> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #ifndef _SVTOOLS_HRC 50*cdf0e10cSrcweir #include <svtools/svtools.hrc> 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include <algorithm> 54*cdf0e10cSrcweir #include <tools/multisel.hxx> 55*cdf0e10cSrcweir #include "editbrowseboximpl.hxx" 56*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp> 58*cdf0e10cSrcweir #include <comphelper/types.hxx> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // ....................................................................... 61*cdf0e10cSrcweir namespace svt 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir // ....................................................................... 64*cdf0e10cSrcweir namespace 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir //.............................................................. 67*cdf0e10cSrcweir sal_Bool isHiContrast(Window* _pWindow) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir OSL_ENSURE(_pWindow,"Window must be not null!"); 70*cdf0e10cSrcweir return _pWindow && _pWindow->GetSettings().GetStyleSettings().GetHighContrastMode(); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //.............................................................. 74*cdf0e10cSrcweir sal_uInt16 getRealGetFocusFlags( Window* _pWindow ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir sal_uInt16 nFlags = 0; 77*cdf0e10cSrcweir while ( _pWindow && !nFlags ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir nFlags = _pWindow->GetGetFocusFlags( ); 80*cdf0e10cSrcweir _pWindow = _pWindow->GetParent(); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir return nFlags; 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 87*cdf0e10cSrcweir using namespace com::sun::star::accessibility::AccessibleEventId; 88*cdf0e10cSrcweir using com::sun::star::accessibility::XAccessible; 89*cdf0e10cSrcweir //================================================================== 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir #define HANDLE_ID 0 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir //================================================================== 94*cdf0e10cSrcweir //= EditBrowserHeader 95*cdf0e10cSrcweir //================================================================== 96*cdf0e10cSrcweir //------------------------------------------------------------------------------ 97*cdf0e10cSrcweir void EditBrowserHeader::DoubleClick() 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir sal_uInt16 nColId = GetCurItemId(); 100*cdf0e10cSrcweir if (nColId) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir sal_uInt32 nAutoWidth = ((EditBrowseBox*)GetParent())->GetAutoColumnWidth(nColId); 103*cdf0e10cSrcweir if (nAutoWidth != ((EditBrowseBox*)GetParent())->GetColumnWidth(nColId)) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir ((EditBrowseBox*)GetParent())->SetColumnWidth(nColId, nAutoWidth); 106*cdf0e10cSrcweir ((EditBrowseBox*)GetParent())->ColumnResized(nColId); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir //================================================================== 113*cdf0e10cSrcweir //= EditBrowseBox 114*cdf0e10cSrcweir //================================================================== 115*cdf0e10cSrcweir //------------------------------------------------------------------------------ 116*cdf0e10cSrcweir void EditBrowseBox::BrowserMouseEventPtr::Clear() 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir DELETEZ(pEvent); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir //------------------------------------------------------------------------------ 122*cdf0e10cSrcweir void EditBrowseBox::BrowserMouseEventPtr::Set(const BrowserMouseEvent* pEvt, sal_Bool bIsDown) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir if (pEvt == pEvent) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir bDown = bIsDown; 127*cdf0e10cSrcweir return; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir Clear(); 130*cdf0e10cSrcweir if (pEvt) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir pEvent = new BrowserMouseEvent(pEvt->GetWindow(), 133*cdf0e10cSrcweir *pEvt, 134*cdf0e10cSrcweir pEvt->GetRow(), 135*cdf0e10cSrcweir pEvt->GetColumn(), 136*cdf0e10cSrcweir pEvt->GetColumnId(), 137*cdf0e10cSrcweir pEvt->GetRect()); 138*cdf0e10cSrcweir bDown = bIsDown; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir //------------------------------------------------------------------------------ 143*cdf0e10cSrcweir DBG_NAME(EditBrowseBox); 144*cdf0e10cSrcweir void EditBrowseBox::impl_construct() 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir m_aImpl = ::std::auto_ptr<EditBrowseBoxImpl>(new EditBrowseBoxImpl()); 147*cdf0e10cSrcweir m_aImpl->m_bHiContrast = isHiContrast(&GetDataWindow()); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir SetCompoundControl(sal_True); 150*cdf0e10cSrcweir SetGridLineColor( Color( COL_LIGHTGRAY ) ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir ImplInitSettings(sal_True, sal_True, sal_True); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir pCheckBoxPaint = new CheckBoxControl(&GetDataWindow()); 155*cdf0e10cSrcweir pCheckBoxPaint->SetPaintTransparent( sal_True ); 156*cdf0e10cSrcweir pCheckBoxPaint->SetBackground(); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir //------------------------------------------------------------------------------ 160*cdf0e10cSrcweir EditBrowseBox::EditBrowseBox(Window* pParent, const ResId& rId, sal_Int32 nBrowserFlags, BrowserMode _nMode ) 161*cdf0e10cSrcweir :BrowseBox( pParent, rId, _nMode ) 162*cdf0e10cSrcweir ,nStartEvent(0) 163*cdf0e10cSrcweir ,nEndEvent(0) 164*cdf0e10cSrcweir ,nCellModifiedEvent(0) 165*cdf0e10cSrcweir ,nPaintRow(-1) 166*cdf0e10cSrcweir ,nEditRow(-1) 167*cdf0e10cSrcweir ,nOldEditRow(-1) 168*cdf0e10cSrcweir ,nEditCol(0) 169*cdf0e10cSrcweir ,nOldEditCol(0) 170*cdf0e10cSrcweir ,bHasFocus(sal_False) 171*cdf0e10cSrcweir ,bPaintStatus(sal_True) 172*cdf0e10cSrcweir ,bActiveBeforeTracking( sal_False ) 173*cdf0e10cSrcweir ,m_nBrowserFlags(nBrowserFlags) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir DBG_CTOR(EditBrowseBox,NULL); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir impl_construct(); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir //================================================================== 181*cdf0e10cSrcweir EditBrowseBox::EditBrowseBox( Window* pParent, sal_Int32 nBrowserFlags, WinBits nBits, BrowserMode _nMode ) 182*cdf0e10cSrcweir :BrowseBox( pParent, nBits, _nMode ) 183*cdf0e10cSrcweir ,nStartEvent(0) 184*cdf0e10cSrcweir ,nEndEvent(0) 185*cdf0e10cSrcweir ,nCellModifiedEvent(0) 186*cdf0e10cSrcweir ,nPaintRow(-1) 187*cdf0e10cSrcweir ,nEditRow(-1) 188*cdf0e10cSrcweir ,nOldEditRow(-1) 189*cdf0e10cSrcweir ,nEditCol(0) 190*cdf0e10cSrcweir ,nOldEditCol(0) 191*cdf0e10cSrcweir ,bHasFocus(sal_False) 192*cdf0e10cSrcweir ,bPaintStatus(sal_True) 193*cdf0e10cSrcweir ,bActiveBeforeTracking( sal_False ) 194*cdf0e10cSrcweir ,m_nBrowserFlags(nBrowserFlags) 195*cdf0e10cSrcweir ,pHeader(NULL) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir DBG_CTOR(EditBrowseBox,NULL); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir impl_construct(); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir //------------------------------------------------------------------------------ 203*cdf0e10cSrcweir void EditBrowseBox::Init() 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir // spaetes Construieren, 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir //------------------------------------------------------------------------------ 209*cdf0e10cSrcweir EditBrowseBox::~EditBrowseBox() 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir if (nStartEvent) 212*cdf0e10cSrcweir Application::RemoveUserEvent(nStartEvent); 213*cdf0e10cSrcweir if (nEndEvent) 214*cdf0e10cSrcweir Application::RemoveUserEvent(nEndEvent); 215*cdf0e10cSrcweir if (nCellModifiedEvent) 216*cdf0e10cSrcweir Application::RemoveUserEvent(nCellModifiedEvent); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir delete pCheckBoxPaint; 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir DBG_DTOR(EditBrowseBox,NULL); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir //------------------------------------------------------------------------------ 224*cdf0e10cSrcweir void EditBrowseBox::RemoveRows() 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir BrowseBox::Clear(); 227*cdf0e10cSrcweir nOldEditRow = nEditRow = nPaintRow = -1; 228*cdf0e10cSrcweir nEditCol = nOldEditCol = 0; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir //------------------------------------------------------------------------------ 232*cdf0e10cSrcweir BrowserHeader* EditBrowseBox::CreateHeaderBar(BrowseBox* pParent) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir pHeader = imp_CreateHeaderBar(pParent); 235*cdf0e10cSrcweir if (!IsUpdateMode()) 236*cdf0e10cSrcweir pHeader->SetUpdateMode(sal_False); 237*cdf0e10cSrcweir return pHeader; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir //------------------------------------------------------------------------------ 241*cdf0e10cSrcweir BrowserHeader* EditBrowseBox::imp_CreateHeaderBar(BrowseBox* pParent) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir return new EditBrowserHeader(pParent); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir //------------------------------------------------------------------------------ 247*cdf0e10cSrcweir void EditBrowseBox::LoseFocus() 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir BrowseBox::LoseFocus(); 250*cdf0e10cSrcweir DetermineFocus( 0 ); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir //------------------------------------------------------------------------------ 254*cdf0e10cSrcweir void EditBrowseBox::GetFocus() 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir BrowseBox::GetFocus(); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // This should handle the case that the BrowseBox (or one of it's children) 259*cdf0e10cSrcweir // gets the focus from outside by pressing Tab 260*cdf0e10cSrcweir if (IsEditing() && Controller()->GetWindow().IsVisible()) 261*cdf0e10cSrcweir Controller()->GetWindow().GrabFocus(); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir DetermineFocus( getRealGetFocusFlags( this ) ); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir //------------------------------------------------------------------------------ 267*cdf0e10cSrcweir sal_Bool EditBrowseBox::SeekRow(long nRow) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir nPaintRow = nRow; 270*cdf0e10cSrcweir return sal_True; 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir //------------------------------------------------------------------------------ 274*cdf0e10cSrcweir IMPL_LINK(EditBrowseBox, StartEditHdl, void*, EMPTYARG) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir nStartEvent = 0; 277*cdf0e10cSrcweir if (IsEditing()) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir EnableAndShow(); 280*cdf0e10cSrcweir if (!aController->GetWindow().HasFocus() && (m_pFocusWhileRequest == Application::GetFocusWindow())) 281*cdf0e10cSrcweir aController->GetWindow().GrabFocus(); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir return 0; 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir //------------------------------------------------------------------------------ 287*cdf0e10cSrcweir void EditBrowseBox::PaintField( OutputDevice& rDev, const Rectangle& rRect, 288*cdf0e10cSrcweir sal_uInt16 nColumnId ) const 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir if (nColumnId == HANDLE_ID) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir if (bPaintStatus) 293*cdf0e10cSrcweir PaintStatusCell(rDev, rRect); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir else 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir // don't paint the current cell 298*cdf0e10cSrcweir if (&rDev == &GetDataWindow()) 299*cdf0e10cSrcweir // but only if we're painting onto our data win (which is the usual painting) 300*cdf0e10cSrcweir if (nPaintRow == nEditRow) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir if (IsEditing() && nEditCol == nColumnId && aController->GetWindow().IsVisible()) 303*cdf0e10cSrcweir return; 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir PaintCell(rDev, rRect, nColumnId); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir //------------------------------------------------------------------------------ 310*cdf0e10cSrcweir Image EditBrowseBox::GetImage(RowStatus eStatus) const 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir sal_Bool bHiContrast = isHiContrast(&GetDataWindow()); 313*cdf0e10cSrcweir if ( !m_aStatusImages.GetImageCount() || (bHiContrast != m_aImpl->m_bHiContrast) ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir m_aImpl->m_bHiContrast = bHiContrast; 316*cdf0e10cSrcweir const_cast<EditBrowseBox*>(this)->m_aStatusImages = ImageList(SvtResId(bHiContrast ? RID_SVTOOLS_IMAGELIST_EDITBWSEBOX_H : RID_SVTOOLS_IMAGELIST_EDITBROWSEBOX)); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir Image aImage; 320*cdf0e10cSrcweir bool bNeedMirror = IsRTLEnabled(); 321*cdf0e10cSrcweir switch (eStatus) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir case CURRENT: 324*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_CURRENT); 325*cdf0e10cSrcweir break; 326*cdf0e10cSrcweir case CURRENTNEW: 327*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_CURRENTNEW); 328*cdf0e10cSrcweir break; 329*cdf0e10cSrcweir case MODIFIED: 330*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_MODIFIED); 331*cdf0e10cSrcweir bNeedMirror = false; // the pen is not mirrored 332*cdf0e10cSrcweir break; 333*cdf0e10cSrcweir case NEW: 334*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_NEW); 335*cdf0e10cSrcweir break; 336*cdf0e10cSrcweir case DELETED: 337*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_DELETED); 338*cdf0e10cSrcweir break; 339*cdf0e10cSrcweir case PRIMARYKEY: 340*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_PRIMARYKEY); 341*cdf0e10cSrcweir break; 342*cdf0e10cSrcweir case CURRENT_PRIMARYKEY: 343*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_CURRENT_PRIMARYKEY); 344*cdf0e10cSrcweir break; 345*cdf0e10cSrcweir case FILTER: 346*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_FILTER); 347*cdf0e10cSrcweir break; 348*cdf0e10cSrcweir case HEADERFOOTER: 349*cdf0e10cSrcweir aImage = m_aStatusImages.GetImage(IMG_EBB_HEADERFOOTER); 350*cdf0e10cSrcweir break; 351*cdf0e10cSrcweir case CLEAN: 352*cdf0e10cSrcweir break; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir if ( bNeedMirror ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir BitmapEx aBitmap( aImage.GetBitmapEx() ); 357*cdf0e10cSrcweir aBitmap.Mirror( BMP_MIRROR_HORZ ); 358*cdf0e10cSrcweir aImage = Image( aBitmap ); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir return aImage; 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir //------------------------------------------------------------------------------ 364*cdf0e10cSrcweir void EditBrowseBox::PaintStatusCell(OutputDevice& rDev, const Rectangle& rRect) const 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir if (nPaintRow < 0) 367*cdf0e10cSrcweir return; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir RowStatus eStatus = GetRowStatus( nPaintRow ); 370*cdf0e10cSrcweir sal_Int32 nBrowserFlags = GetBrowserFlags(); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir if (nBrowserFlags & EBBF_NO_HANDLE_COLUMN_CONTENT) 373*cdf0e10cSrcweir return; 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir // draw the text of the header column 376*cdf0e10cSrcweir if (nBrowserFlags & EBBF_HANDLE_COLUMN_TEXT ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir rDev.DrawText( rRect, GetCellText( nPaintRow, 0 ), 379*cdf0e10cSrcweir TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_CLIP ); 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir // draw an image 382*cdf0e10cSrcweir else if (eStatus != CLEAN && rDev.GetOutDevType() == OUTDEV_WINDOW) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir Image aImage(GetImage(eStatus)); 385*cdf0e10cSrcweir // calc the image position 386*cdf0e10cSrcweir Size aImageSize(aImage.GetSizePixel()); 387*cdf0e10cSrcweir aImageSize.Width() = CalcZoom(aImageSize.Width()); 388*cdf0e10cSrcweir aImageSize.Height() = CalcZoom(aImageSize.Height()); 389*cdf0e10cSrcweir Point aPos( rRect.TopLeft() ); 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir if ( ( aImageSize.Width() > rRect.GetWidth() ) || ( aImageSize.Height() > rRect.GetHeight() ) ) 392*cdf0e10cSrcweir rDev.SetClipRegion(rRect); 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir if ( aImageSize.Width() < rRect.GetWidth() ) 395*cdf0e10cSrcweir aPos.X() += ( rRect.GetWidth() - aImageSize.Width() ) / 2; 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir if ( aImageSize.Height() < rRect.GetHeight() ) 398*cdf0e10cSrcweir aPos.Y() += ( rRect.GetHeight() - aImageSize.Height() ) / 2; 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir if ( IsZoom() ) 401*cdf0e10cSrcweir rDev.DrawImage( aPos, aImageSize, aImage, 0 ); 402*cdf0e10cSrcweir else 403*cdf0e10cSrcweir rDev.DrawImage( aPos, aImage, 0 ); 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir if (rDev.IsClipRegion()) 406*cdf0e10cSrcweir rDev.SetClipRegion(); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir //------------------------------------------------------------------------------ 411*cdf0e10cSrcweir void EditBrowseBox::ImplStartTracking() 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir bActiveBeforeTracking = IsEditing(); 414*cdf0e10cSrcweir if ( bActiveBeforeTracking ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir DeactivateCell(); 417*cdf0e10cSrcweir Update(); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir BrowseBox::ImplStartTracking(); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir //------------------------------------------------------------------------------ 424*cdf0e10cSrcweir void EditBrowseBox::ImplTracking() 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir BrowseBox::ImplTracking(); 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir //------------------------------------------------------------------------------ 430*cdf0e10cSrcweir void EditBrowseBox::ImplEndTracking() 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir if ( bActiveBeforeTracking ) 433*cdf0e10cSrcweir ActivateCell(); 434*cdf0e10cSrcweir bActiveBeforeTracking = sal_False; 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir BrowseBox::ImplEndTracking(); 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir //------------------------------------------------------------------------------ 440*cdf0e10cSrcweir void EditBrowseBox::RowHeightChanged() 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir if ( IsEditing() ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir Rectangle aRect( GetCellRect( nEditRow, nEditCol, sal_False ) ); 445*cdf0e10cSrcweir CellControllerRef aCellController( Controller() ); 446*cdf0e10cSrcweir ResizeController( aCellController, aRect ); 447*cdf0e10cSrcweir aCellController->GetWindow().GrabFocus(); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir BrowseBox::RowHeightChanged(); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir //------------------------------------------------------------------------------ 454*cdf0e10cSrcweir EditBrowseBox::RowStatus EditBrowseBox::GetRowStatus(long) const 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir return CLEAN; 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir //------------------------------------------------------------------------------ 460*cdf0e10cSrcweir void EditBrowseBox::KeyInput( const KeyEvent& rEvt ) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir sal_uInt16 nCode = rEvt.GetKeyCode().GetCode(); 463*cdf0e10cSrcweir sal_Bool bShift = rEvt.GetKeyCode().IsShift(); 464*cdf0e10cSrcweir sal_Bool bCtrl = rEvt.GetKeyCode().IsMod1(); 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir switch (nCode) 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir case KEY_RETURN: 469*cdf0e10cSrcweir if (!bCtrl && !bShift && IsTabAllowed(sal_True)) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir Dispatch(BROWSER_CURSORRIGHT); 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir else 474*cdf0e10cSrcweir BrowseBox::KeyInput(rEvt); 475*cdf0e10cSrcweir return; 476*cdf0e10cSrcweir case KEY_TAB: 477*cdf0e10cSrcweir if (!bCtrl && !bShift) 478*cdf0e10cSrcweir { 479*cdf0e10cSrcweir if (IsTabAllowed(sal_True)) 480*cdf0e10cSrcweir Dispatch(BROWSER_CURSORRIGHT); 481*cdf0e10cSrcweir else 482*cdf0e10cSrcweir // do NOT call BrowseBox::KeyInput : this would handle the tab, but we already now 483*cdf0e10cSrcweir // that tab isn't allowed here. So give the Control class a chance 484*cdf0e10cSrcweir Control::KeyInput(rEvt); 485*cdf0e10cSrcweir return; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir else if (!bCtrl && bShift) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir if (IsTabAllowed(sal_False)) 490*cdf0e10cSrcweir Dispatch(BROWSER_CURSORLEFT); 491*cdf0e10cSrcweir else 492*cdf0e10cSrcweir // do NOT call BrowseBox::KeyInput : this would handle the tab, but we already now 493*cdf0e10cSrcweir // that tab isn't allowed here. So give the Control class a chance 494*cdf0e10cSrcweir Control::KeyInput(rEvt); 495*cdf0e10cSrcweir return; 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir default: 498*cdf0e10cSrcweir BrowseBox::KeyInput(rEvt); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir //------------------------------------------------------------------------------ 503*cdf0e10cSrcweir void EditBrowseBox::MouseButtonDown(const BrowserMouseEvent& rEvt) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir sal_uInt16 nColPos = GetColumnPos( rEvt.GetColumnId() ); 506*cdf0e10cSrcweir long nRow = rEvt.GetRow(); 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir // absorb double clicks 509*cdf0e10cSrcweir if (rEvt.GetClicks() > 1 && rEvt.GetRow() >= 0) 510*cdf0e10cSrcweir return; 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir // change to a new position 513*cdf0e10cSrcweir if (IsEditing() && (nColPos != nEditCol || nRow != nEditRow) && (nColPos != BROWSER_INVALIDID) && (nRow < GetRowCount())) 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir CellControllerRef aCellController(Controller()); 516*cdf0e10cSrcweir HideAndDisable(aCellController); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir // we are about to leave the current cell. If there is a "this cell has been modified" notification 520*cdf0e10cSrcweir // pending (asynchronously), this may be deadly -> do it synchronously 521*cdf0e10cSrcweir // 95826 - 2002-10-14 - fs@openoffice.org 522*cdf0e10cSrcweir if ( nCellModifiedEvent ) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir Application::RemoveUserEvent( nCellModifiedEvent ); 525*cdf0e10cSrcweir nCellModifiedEvent = 0; 526*cdf0e10cSrcweir LINK( this, EditBrowseBox, CellModifiedHdl ).Call( NULL ); 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir if (0 == rEvt.GetColumnId()) 530*cdf0e10cSrcweir { // it was the handle column. save the current cell content if necessary 531*cdf0e10cSrcweir // (clicking on the handle column results in selecting the current row) 532*cdf0e10cSrcweir // 23.01.2001 - 82797 - FS 533*cdf0e10cSrcweir if (IsEditing() && aController->IsModified()) 534*cdf0e10cSrcweir SaveModified(); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir aMouseEvent.Set(&rEvt,sal_True); 538*cdf0e10cSrcweir BrowseBox::MouseButtonDown(rEvt); 539*cdf0e10cSrcweir aMouseEvent.Clear(); 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir if (0 != (m_nBrowserFlags & EBBF_ACTIVATE_ON_BUTTONDOWN)) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir // the base class does not travel upon MouseButtonDown, but implActivateCellOnMouseEvent assumes we traveled ... 544*cdf0e10cSrcweir GoToRowColumnId( rEvt.GetRow(), rEvt.GetColumnId() ); 545*cdf0e10cSrcweir if (rEvt.GetRow() >= 0) 546*cdf0e10cSrcweir implActivateCellOnMouseEvent(rEvt, sal_False); 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir //------------------------------------------------------------------------------ 551*cdf0e10cSrcweir void EditBrowseBox::MouseButtonUp( const BrowserMouseEvent& rEvt ) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir // absorb double clicks 554*cdf0e10cSrcweir if (rEvt.GetClicks() > 1 && rEvt.GetRow() >= 0) 555*cdf0e10cSrcweir return; 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir aMouseEvent.Set(&rEvt,sal_False); 558*cdf0e10cSrcweir BrowseBox::MouseButtonUp(rEvt); 559*cdf0e10cSrcweir aMouseEvent.Clear(); 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir if (0 == (m_nBrowserFlags & EBBF_ACTIVATE_ON_BUTTONDOWN)) 562*cdf0e10cSrcweir if (rEvt.GetRow() >= 0) 563*cdf0e10cSrcweir implActivateCellOnMouseEvent(rEvt, sal_True); 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir //------------------------------------------------------------------------------ 567*cdf0e10cSrcweir void EditBrowseBox::implActivateCellOnMouseEvent(const BrowserMouseEvent& _rEvt, sal_Bool _bUp) 568*cdf0e10cSrcweir { 569*cdf0e10cSrcweir if (!IsEditing()) 570*cdf0e10cSrcweir ActivateCell(); 571*cdf0e10cSrcweir else if (IsEditing() && !aController->GetWindow().IsEnabled()) 572*cdf0e10cSrcweir DeactivateCell(); 573*cdf0e10cSrcweir else if (IsEditing() && !aController->GetWindow().HasChildPathFocus()) 574*cdf0e10cSrcweir AsynchGetFocus(); 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir if (IsEditing() && aController->GetWindow().IsEnabled() && aController->WantMouseEvent()) 577*cdf0e10cSrcweir { // forwards the event to the control 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir // If the field has been moved previously, we have to adjust the position 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir aController->GetWindow().GrabFocus(); 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir // the position of the event relative to the controller's window 584*cdf0e10cSrcweir Point aPos = _rEvt.GetPosPixel() - _rEvt.GetRect().TopLeft(); 585*cdf0e10cSrcweir // the (child) window which should really get the event 586*cdf0e10cSrcweir Window* pRealHandler = aController->GetWindow().FindWindow(aPos); 587*cdf0e10cSrcweir if (pRealHandler) 588*cdf0e10cSrcweir // the coords relative to this real handler 589*cdf0e10cSrcweir aPos -= pRealHandler->GetPosPixel(); 590*cdf0e10cSrcweir else 591*cdf0e10cSrcweir pRealHandler = &aController->GetWindow(); 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir // the faked event 594*cdf0e10cSrcweir MouseEvent aEvent(aPos, _rEvt.GetClicks(), _rEvt.GetMode(), 595*cdf0e10cSrcweir _rEvt.GetButtons(), 596*cdf0e10cSrcweir _rEvt.GetModifier()); 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir pRealHandler->MouseButtonDown(aEvent); 599*cdf0e10cSrcweir if (_bUp) 600*cdf0e10cSrcweir pRealHandler->MouseButtonUp(aEvent); 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir Window *pWin = &aController->GetWindow(); 603*cdf0e10cSrcweir if (!pWin->IsTracking()) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir for (pWin = pWin->GetWindow(WINDOW_FIRSTCHILD); 606*cdf0e10cSrcweir pWin && !pWin->IsTracking(); 607*cdf0e10cSrcweir pWin = pWin->GetWindow(WINDOW_NEXT)) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir } 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir if (pWin && pWin->IsTracking()) 612*cdf0e10cSrcweir pWin->EndTracking(); 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir //------------------------------------------------------------------------------ 617*cdf0e10cSrcweir void EditBrowseBox::Dispatch( sal_uInt16 _nId ) 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir if ( _nId == BROWSER_ENHANCESELECTION ) 620*cdf0e10cSrcweir { // this is a workaround for the bug in the base class: 621*cdf0e10cSrcweir // if the row selection is to be extended (which is what BROWSER_ENHANCESELECTION tells us) 622*cdf0e10cSrcweir // then the base class does not revert any column selections, while, for doing a "simple" 623*cdf0e10cSrcweir // selection (BROWSER_SELECT), it does. In fact, it does not only revert the col selection then, 624*cdf0e10cSrcweir // but also any current row selections. 625*cdf0e10cSrcweir // This clearly tells me that the both ids are for row selection only - there this behaviour does 626*cdf0e10cSrcweir // make sense. 627*cdf0e10cSrcweir // But here, where we have column selection, too, we take care of this ourself. 628*cdf0e10cSrcweir if ( GetSelectColumnCount( ) ) 629*cdf0e10cSrcweir { 630*cdf0e10cSrcweir while ( GetSelectColumnCount( ) ) 631*cdf0e10cSrcweir SelectColumnPos( 632*cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(FirstSelectedColumn()), 633*cdf0e10cSrcweir sal_False ); 634*cdf0e10cSrcweir Select(); 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir BrowseBox::Dispatch( _nId ); 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir //------------------------------------------------------------------------------ 641*cdf0e10cSrcweir long EditBrowseBox::PreNotify(NotifyEvent& rEvt) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir switch (rEvt.GetType()) 644*cdf0e10cSrcweir { 645*cdf0e10cSrcweir case EVENT_KEYINPUT: 646*cdf0e10cSrcweir if ( (IsEditing() && Controller()->GetWindow().HasChildPathFocus()) 647*cdf0e10cSrcweir || rEvt.GetWindow() == &GetDataWindow() 648*cdf0e10cSrcweir || (!IsEditing() && HasChildPathFocus()) 649*cdf0e10cSrcweir ) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir const KeyEvent* pKeyEvent = rEvt.GetKeyEvent(); 652*cdf0e10cSrcweir sal_uInt16 nCode = pKeyEvent->GetKeyCode().GetCode(); 653*cdf0e10cSrcweir sal_Bool bShift = pKeyEvent->GetKeyCode().IsShift(); 654*cdf0e10cSrcweir sal_Bool bCtrl = pKeyEvent->GetKeyCode().IsMod1(); 655*cdf0e10cSrcweir sal_Bool bAlt = pKeyEvent->GetKeyCode().IsMod2(); 656*cdf0e10cSrcweir sal_Bool bLocalSelect= sal_False; 657*cdf0e10cSrcweir sal_Bool bNonEditOnly = sal_False; 658*cdf0e10cSrcweir sal_uInt16 nId = BROWSER_NONE; 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir if (!bAlt && !bCtrl && !bShift ) 661*cdf0e10cSrcweir switch ( nCode ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir case KEY_DOWN: nId = BROWSER_CURSORDOWN; break; 664*cdf0e10cSrcweir case KEY_UP: nId = BROWSER_CURSORUP; break; 665*cdf0e10cSrcweir case KEY_PAGEDOWN: nId = BROWSER_CURSORPAGEDOWN; break; 666*cdf0e10cSrcweir case KEY_PAGEUP: nId = BROWSER_CURSORPAGEUP; break; 667*cdf0e10cSrcweir case KEY_HOME: nId = BROWSER_CURSORHOME; break; 668*cdf0e10cSrcweir case KEY_END: nId = BROWSER_CURSOREND; break; 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir case KEY_TAB: 671*cdf0e10cSrcweir // ask if traveling to the next cell is allowed 672*cdf0e10cSrcweir if (IsTabAllowed(sal_True)) 673*cdf0e10cSrcweir nId = BROWSER_CURSORRIGHT; 674*cdf0e10cSrcweir break; 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir case KEY_RETURN: 677*cdf0e10cSrcweir // save the cell content (if necessary) 678*cdf0e10cSrcweir if (IsEditing() && aController->IsModified() && !((EditBrowseBox *) this)->SaveModified()) 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir // maybe we're not visible ... 681*cdf0e10cSrcweir EnableAndShow(); 682*cdf0e10cSrcweir aController->GetWindow().GrabFocus(); 683*cdf0e10cSrcweir return 1; 684*cdf0e10cSrcweir } 685*cdf0e10cSrcweir // ask if traveling to the next cell is allowed 686*cdf0e10cSrcweir if (IsTabAllowed(sal_True)) 687*cdf0e10cSrcweir nId = BROWSER_CURSORRIGHT; 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir break; 690*cdf0e10cSrcweir case KEY_RIGHT: nId = BROWSER_CURSORRIGHT; break; 691*cdf0e10cSrcweir case KEY_LEFT: nId = BROWSER_CURSORLEFT; break; 692*cdf0e10cSrcweir case KEY_SPACE: nId = BROWSER_SELECT; bNonEditOnly = bLocalSelect = sal_True;break; 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir if ( !bAlt && !bCtrl && bShift ) 696*cdf0e10cSrcweir switch ( nCode ) 697*cdf0e10cSrcweir { 698*cdf0e10cSrcweir case KEY_DOWN: nId = BROWSER_SELECTDOWN; bLocalSelect = sal_True;break; 699*cdf0e10cSrcweir case KEY_UP: nId = BROWSER_SELECTUP; bLocalSelect = sal_True;break; 700*cdf0e10cSrcweir case KEY_HOME: nId = BROWSER_SELECTHOME; bLocalSelect = sal_True;break; 701*cdf0e10cSrcweir case KEY_END: nId = BROWSER_SELECTEND; bLocalSelect = sal_True;break; 702*cdf0e10cSrcweir case KEY_TAB: 703*cdf0e10cSrcweir if (IsTabAllowed(sal_False)) 704*cdf0e10cSrcweir nId = BROWSER_CURSORLEFT; 705*cdf0e10cSrcweir break; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir if ( !bAlt && bCtrl && bShift ) 709*cdf0e10cSrcweir switch ( nCode ) 710*cdf0e10cSrcweir { 711*cdf0e10cSrcweir case KEY_SPACE: nId = BROWSER_SELECTCOLUMN; bLocalSelect = sal_True; break; 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir if ( !bAlt && bCtrl && !bShift ) 716*cdf0e10cSrcweir switch ( nCode ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir case KEY_DOWN: nId = BROWSER_SCROLLUP; break; 719*cdf0e10cSrcweir case KEY_UP: nId = BROWSER_SCROLLDOWN; break; 720*cdf0e10cSrcweir case KEY_PAGEDOWN: nId = BROWSER_CURSORENDOFFILE; break; 721*cdf0e10cSrcweir case KEY_PAGEUP: nId = BROWSER_CURSORTOPOFFILE; break; 722*cdf0e10cSrcweir case KEY_HOME: nId = BROWSER_CURSORTOPOFSCREEN; break; 723*cdf0e10cSrcweir case KEY_END: nId = BROWSER_CURSORENDOFSCREEN; break; 724*cdf0e10cSrcweir case KEY_SPACE: nId = BROWSER_ENHANCESELECTION; bLocalSelect = sal_True;break; 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir if ( ( nId != BROWSER_NONE ) 729*cdf0e10cSrcweir && ( !IsEditing() 730*cdf0e10cSrcweir || ( !bNonEditOnly 731*cdf0e10cSrcweir && aController->MoveAllowed( *pKeyEvent ) 732*cdf0e10cSrcweir ) 733*cdf0e10cSrcweir ) 734*cdf0e10cSrcweir ) 735*cdf0e10cSrcweir { 736*cdf0e10cSrcweir if (nId == BROWSER_SELECT || BROWSER_SELECTCOLUMN == nId ) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir // save the cell content (if necessary) 739*cdf0e10cSrcweir if (IsEditing() && aController->IsModified() && !((EditBrowseBox *) this)->SaveModified()) 740*cdf0e10cSrcweir { 741*cdf0e10cSrcweir // maybe we're not visible ... 742*cdf0e10cSrcweir EnableAndShow(); 743*cdf0e10cSrcweir aController->GetWindow().GrabFocus(); 744*cdf0e10cSrcweir return 1; 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir } 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir Dispatch(nId); 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir if (bLocalSelect && (GetSelectRowCount() || GetSelection() != NULL)) 751*cdf0e10cSrcweir DeactivateCell(); 752*cdf0e10cSrcweir return 1; 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir } 756*cdf0e10cSrcweir return BrowseBox::PreNotify(rEvt); 757*cdf0e10cSrcweir } 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir //------------------------------------------------------------------------------ 760*cdf0e10cSrcweir sal_Bool EditBrowseBox::IsTabAllowed(sal_Bool) const 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir return sal_True; 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir //------------------------------------------------------------------------------ 766*cdf0e10cSrcweir long EditBrowseBox::Notify(NotifyEvent& rEvt) 767*cdf0e10cSrcweir { 768*cdf0e10cSrcweir switch (rEvt.GetType()) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir case EVENT_GETFOCUS: 771*cdf0e10cSrcweir DetermineFocus( getRealGetFocusFlags( this ) ); 772*cdf0e10cSrcweir break; 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir case EVENT_LOSEFOCUS: 775*cdf0e10cSrcweir DetermineFocus( 0 ); 776*cdf0e10cSrcweir break; 777*cdf0e10cSrcweir } 778*cdf0e10cSrcweir return BrowseBox::Notify(rEvt); 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir //------------------------------------------------------------------------------ 782*cdf0e10cSrcweir void EditBrowseBox::StateChanged( StateChangedType nType ) 783*cdf0e10cSrcweir { 784*cdf0e10cSrcweir BrowseBox::StateChanged( nType ); 785*cdf0e10cSrcweir 786*cdf0e10cSrcweir bool bNeedCellReActivation = false; 787*cdf0e10cSrcweir if ( nType == STATE_CHANGE_MIRRORING ) 788*cdf0e10cSrcweir { 789*cdf0e10cSrcweir bNeedCellReActivation = true; 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_ZOOM ) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False ); 794*cdf0e10cSrcweir bNeedCellReActivation = true; 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFONT ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False ); 799*cdf0e10cSrcweir Invalidate(); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir ImplInitSettings( sal_False, sal_True, sal_False ); 804*cdf0e10cSrcweir Invalidate(); 805*cdf0e10cSrcweir } 806*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir ImplInitSettings( sal_False, sal_False, sal_True ); 809*cdf0e10cSrcweir Invalidate(); 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir else if (nType == STATE_CHANGE_STYLE) 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir WinBits nStyle = GetStyle(); 814*cdf0e10cSrcweir if (!(nStyle & WB_NOTABSTOP) ) 815*cdf0e10cSrcweir nStyle |= WB_TABSTOP; 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir SetStyle(nStyle); 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir if ( bNeedCellReActivation ) 820*cdf0e10cSrcweir { 821*cdf0e10cSrcweir if ( IsEditing() ) 822*cdf0e10cSrcweir { 823*cdf0e10cSrcweir DeactivateCell(); 824*cdf0e10cSrcweir ActivateCell(); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir //------------------------------------------------------------------------------ 830*cdf0e10cSrcweir void EditBrowseBox::DataChanged( const DataChangedEvent& rDCEvt ) 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir BrowseBox::DataChanged( rDCEvt ); 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) || 835*cdf0e10cSrcweir ( rDCEvt.GetType() == DATACHANGED_DISPLAY )) && 836*cdf0e10cSrcweir ( rDCEvt.GetFlags() & SETTINGS_STYLE )) 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True ); 839*cdf0e10cSrcweir Invalidate(); 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir //------------------------------------------------------------------------------ 844*cdf0e10cSrcweir void EditBrowseBox::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground ) 845*cdf0e10cSrcweir { 846*cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 847*cdf0e10cSrcweir 848*cdf0e10cSrcweir if (bFont) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir Font aFont = rStyleSettings.GetFieldFont(); 851*cdf0e10cSrcweir if (IsControlFont()) 852*cdf0e10cSrcweir { 853*cdf0e10cSrcweir GetDataWindow().SetControlFont(GetControlFont()); 854*cdf0e10cSrcweir aFont.Merge(GetControlFont()); 855*cdf0e10cSrcweir } 856*cdf0e10cSrcweir else 857*cdf0e10cSrcweir GetDataWindow().SetControlFont(); 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir GetDataWindow().SetZoomedPointFont(aFont); 860*cdf0e10cSrcweir } 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir if ( bFont || bForeground ) 863*cdf0e10cSrcweir { 864*cdf0e10cSrcweir Color aTextColor = rStyleSettings.GetFieldTextColor(); 865*cdf0e10cSrcweir if (IsControlForeground()) 866*cdf0e10cSrcweir { 867*cdf0e10cSrcweir aTextColor = GetControlForeground(); 868*cdf0e10cSrcweir GetDataWindow().SetControlForeground(aTextColor); 869*cdf0e10cSrcweir } 870*cdf0e10cSrcweir else 871*cdf0e10cSrcweir GetDataWindow().SetControlForeground(); 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir GetDataWindow().SetTextColor( aTextColor ); 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir if ( bBackground ) 877*cdf0e10cSrcweir { 878*cdf0e10cSrcweir if (GetDataWindow().IsControlBackground()) 879*cdf0e10cSrcweir { 880*cdf0e10cSrcweir GetDataWindow().SetControlBackground(GetControlBackground()); 881*cdf0e10cSrcweir GetDataWindow().SetBackground(GetDataWindow().GetControlBackground()); 882*cdf0e10cSrcweir GetDataWindow().SetFillColor(GetDataWindow().GetControlBackground()); 883*cdf0e10cSrcweir } 884*cdf0e10cSrcweir else 885*cdf0e10cSrcweir { 886*cdf0e10cSrcweir GetDataWindow().SetControlBackground(); 887*cdf0e10cSrcweir GetDataWindow().SetBackground( rStyleSettings.GetFieldColor() ); 888*cdf0e10cSrcweir GetDataWindow().SetFillColor( rStyleSettings.GetFieldColor() ); 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir } 891*cdf0e10cSrcweir } 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir //------------------------------------------------------------------------------ 894*cdf0e10cSrcweir sal_Bool EditBrowseBox::IsCursorMoveAllowed(long nNewRow, sal_uInt16 nNewColId) const 895*cdf0e10cSrcweir { 896*cdf0e10cSrcweir sal_uInt16 nInfo = 0; 897*cdf0e10cSrcweir 898*cdf0e10cSrcweir if (GetSelectColumnCount() || (aMouseEvent.Is() && aMouseEvent->GetRow() < 0)) 899*cdf0e10cSrcweir nInfo |= COLSELECT; 900*cdf0e10cSrcweir if ((GetSelection() != NULL && GetSelectRowCount()) || 901*cdf0e10cSrcweir (aMouseEvent.Is() && aMouseEvent->GetColumnId() == HANDLE_ID)) 902*cdf0e10cSrcweir nInfo |= ROWSELECT; 903*cdf0e10cSrcweir if (!nInfo && nNewRow != nEditRow) 904*cdf0e10cSrcweir nInfo |= ROWCHANGE; 905*cdf0e10cSrcweir if (!nInfo && nNewColId != nEditCol) 906*cdf0e10cSrcweir nInfo |= COLCHANGE; 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir if (nInfo == 0) // nothing happened 909*cdf0e10cSrcweir return sal_True; 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir // save the cell content 912*cdf0e10cSrcweir if (IsEditing() && aController->IsModified() && !((EditBrowseBox *) this)->SaveModified()) 913*cdf0e10cSrcweir { 914*cdf0e10cSrcweir // maybe we're not visible ... 915*cdf0e10cSrcweir EnableAndShow(); 916*cdf0e10cSrcweir aController->GetWindow().GrabFocus(); 917*cdf0e10cSrcweir return sal_False; 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir EditBrowseBox * pTHIS = (EditBrowseBox *) this; 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir // save the cell content if 923*cdf0e10cSrcweir // a) a selection is beeing made 924*cdf0e10cSrcweir // b) the row is changing 925*cdf0e10cSrcweir if (IsModified() && (nInfo & (ROWCHANGE | COLSELECT | ROWSELECT)) && 926*cdf0e10cSrcweir !pTHIS->SaveRow()) 927*cdf0e10cSrcweir { 928*cdf0e10cSrcweir if (nInfo & COLSELECT || 929*cdf0e10cSrcweir nInfo & ROWSELECT) 930*cdf0e10cSrcweir { 931*cdf0e10cSrcweir // cancel selected 932*cdf0e10cSrcweir pTHIS->SetNoSelection(); 933*cdf0e10cSrcweir } 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir if (IsEditing()) 936*cdf0e10cSrcweir { 937*cdf0e10cSrcweir if (!Controller()->GetWindow().IsVisible()) 938*cdf0e10cSrcweir { 939*cdf0e10cSrcweir EnableAndShow(); 940*cdf0e10cSrcweir } 941*cdf0e10cSrcweir aController->GetWindow().GrabFocus(); 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir return sal_False; 944*cdf0e10cSrcweir } 945*cdf0e10cSrcweir 946*cdf0e10cSrcweir if (nNewRow != nEditRow) 947*cdf0e10cSrcweir { 948*cdf0e10cSrcweir Window& rWindow = GetDataWindow(); 949*cdf0e10cSrcweir // don't paint too much 950*cdf0e10cSrcweir // update the status immediatly if possible 951*cdf0e10cSrcweir if ((nEditRow >= 0) && (GetBrowserFlags() & EBBF_NO_HANDLE_COLUMN_CONTENT) == 0) 952*cdf0e10cSrcweir { 953*cdf0e10cSrcweir Rectangle aRect = GetFieldRectPixel(nEditRow, 0, sal_False ); 954*cdf0e10cSrcweir // status cell should be painted if and only if text is displayed 955*cdf0e10cSrcweir // note: bPaintStatus is mutable, but Solaris has problems with assigning 956*cdf0e10cSrcweir // probably because it is part of a bitfield 957*cdf0e10cSrcweir pTHIS->bPaintStatus = static_cast< sal_Bool > 958*cdf0e10cSrcweir (( GetBrowserFlags() & EBBF_HANDLE_COLUMN_TEXT ) == EBBF_HANDLE_COLUMN_TEXT ); 959*cdf0e10cSrcweir rWindow.Paint(aRect); 960*cdf0e10cSrcweir pTHIS->bPaintStatus = sal_True; 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir // don't paint during row change 964*cdf0e10cSrcweir rWindow.EnablePaint(sal_False); 965*cdf0e10cSrcweir 966*cdf0e10cSrcweir // the last veto chance for derived classes 967*cdf0e10cSrcweir if (!pTHIS->CursorMoving(nNewRow, nNewColId)) 968*cdf0e10cSrcweir { 969*cdf0e10cSrcweir pTHIS->InvalidateStatusCell(nEditRow); 970*cdf0e10cSrcweir rWindow.EnablePaint(sal_True); 971*cdf0e10cSrcweir return sal_False; 972*cdf0e10cSrcweir } 973*cdf0e10cSrcweir else 974*cdf0e10cSrcweir { 975*cdf0e10cSrcweir rWindow.EnablePaint(sal_True); 976*cdf0e10cSrcweir return sal_True; 977*cdf0e10cSrcweir } 978*cdf0e10cSrcweir } 979*cdf0e10cSrcweir else 980*cdf0e10cSrcweir return pTHIS->CursorMoving(nNewRow, nNewColId); 981*cdf0e10cSrcweir } 982*cdf0e10cSrcweir 983*cdf0e10cSrcweir //------------------------------------------------------------------------------ 984*cdf0e10cSrcweir void EditBrowseBox::ColumnMoved(sal_uInt16 nId) 985*cdf0e10cSrcweir { 986*cdf0e10cSrcweir BrowseBox::ColumnMoved(nId); 987*cdf0e10cSrcweir if (IsEditing()) 988*cdf0e10cSrcweir { 989*cdf0e10cSrcweir Rectangle aRect( GetCellRect(nEditRow, nEditCol, sal_False)); 990*cdf0e10cSrcweir CellControllerRef aControllerRef = Controller(); 991*cdf0e10cSrcweir ResizeController(aControllerRef, aRect); 992*cdf0e10cSrcweir Controller()->GetWindow().GrabFocus(); 993*cdf0e10cSrcweir } 994*cdf0e10cSrcweir } 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir //------------------------------------------------------------------------------ 997*cdf0e10cSrcweir sal_Bool EditBrowseBox::SaveRow() 998*cdf0e10cSrcweir { 999*cdf0e10cSrcweir return sal_True; 1000*cdf0e10cSrcweir } 1001*cdf0e10cSrcweir 1002*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1003*cdf0e10cSrcweir sal_Bool EditBrowseBox::CursorMoving(long, sal_uInt16) 1004*cdf0e10cSrcweir { 1005*cdf0e10cSrcweir ((EditBrowseBox *) this)->DeactivateCell(sal_False); 1006*cdf0e10cSrcweir return sal_True; 1007*cdf0e10cSrcweir } 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1010*cdf0e10cSrcweir void EditBrowseBox::CursorMoved() 1011*cdf0e10cSrcweir { 1012*cdf0e10cSrcweir long nNewRow = GetCurRow(); 1013*cdf0e10cSrcweir if (nEditRow != nNewRow) 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir if ((GetBrowserFlags() & EBBF_NO_HANDLE_COLUMN_CONTENT) == 0) 1016*cdf0e10cSrcweir InvalidateStatusCell(nNewRow); 1017*cdf0e10cSrcweir nEditRow = nNewRow; 1018*cdf0e10cSrcweir } 1019*cdf0e10cSrcweir ActivateCell(); 1020*cdf0e10cSrcweir GetDataWindow().EnablePaint(sal_True); 1021*cdf0e10cSrcweir // should not be called here because the descant event is not needed here 1022*cdf0e10cSrcweir //BrowseBox::CursorMoved(); 1023*cdf0e10cSrcweir } 1024*cdf0e10cSrcweir 1025*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1026*cdf0e10cSrcweir void EditBrowseBox::EndScroll() 1027*cdf0e10cSrcweir { 1028*cdf0e10cSrcweir if (IsEditing()) 1029*cdf0e10cSrcweir { 1030*cdf0e10cSrcweir Rectangle aRect = GetCellRect(nEditRow, nEditCol, sal_False); 1031*cdf0e10cSrcweir ResizeController(aController,aRect); 1032*cdf0e10cSrcweir AsynchGetFocus(); 1033*cdf0e10cSrcweir } 1034*cdf0e10cSrcweir BrowseBox::EndScroll(); 1035*cdf0e10cSrcweir } 1036*cdf0e10cSrcweir 1037*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1038*cdf0e10cSrcweir void EditBrowseBox::ActivateCell(long nRow, sal_uInt16 nCol, sal_Bool bCellFocus) 1039*cdf0e10cSrcweir { 1040*cdf0e10cSrcweir if (IsEditing()) 1041*cdf0e10cSrcweir return; 1042*cdf0e10cSrcweir 1043*cdf0e10cSrcweir nEditCol = nCol; 1044*cdf0e10cSrcweir 1045*cdf0e10cSrcweir if ((GetSelectRowCount() && GetSelection() != NULL) || GetSelectColumnCount() || 1046*cdf0e10cSrcweir (aMouseEvent.Is() && (aMouseEvent.IsDown() || aMouseEvent->GetClicks() > 1))) // bei MouseDown passiert noch nichts 1047*cdf0e10cSrcweir { 1048*cdf0e10cSrcweir return; 1049*cdf0e10cSrcweir } 1050*cdf0e10cSrcweir 1051*cdf0e10cSrcweir if (nEditRow >= 0 && nEditCol > HANDLE_ID) 1052*cdf0e10cSrcweir { 1053*cdf0e10cSrcweir aController = GetController(nRow, nCol); 1054*cdf0e10cSrcweir if (aController.Is()) 1055*cdf0e10cSrcweir { 1056*cdf0e10cSrcweir Rectangle aRect( GetCellRect(nEditRow, nEditCol, sal_False)); 1057*cdf0e10cSrcweir ResizeController(aController, aRect); 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir InitController(aController, nEditRow, nEditCol); 1060*cdf0e10cSrcweir 1061*cdf0e10cSrcweir aController->ClearModified(); 1062*cdf0e10cSrcweir aController->SetModifyHdl(LINK(this,EditBrowseBox,ModifyHdl)); 1063*cdf0e10cSrcweir EnableAndShow(); 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir if ( isAccessibleAlive() ) 1066*cdf0e10cSrcweir implCreateActiveAccessible(); 1067*cdf0e10cSrcweir 1068*cdf0e10cSrcweir // activate the cell only of the browser has the focus 1069*cdf0e10cSrcweir if ( bHasFocus && bCellFocus ) 1070*cdf0e10cSrcweir AsynchGetFocus(); 1071*cdf0e10cSrcweir } 1072*cdf0e10cSrcweir else 1073*cdf0e10cSrcweir { 1074*cdf0e10cSrcweir // no controller -> we have a new "active descendant" 1075*cdf0e10cSrcweir if ( isAccessibleAlive() && HasFocus() ) 1076*cdf0e10cSrcweir { 1077*cdf0e10cSrcweir commitTableEvent( 1078*cdf0e10cSrcweir ACTIVE_DESCENDANT_CHANGED, 1079*cdf0e10cSrcweir makeAny( CreateAccessibleCell( nRow, GetColumnPos( nCol ) ) ), 1080*cdf0e10cSrcweir Any() 1081*cdf0e10cSrcweir ); 1082*cdf0e10cSrcweir } 1083*cdf0e10cSrcweir } 1084*cdf0e10cSrcweir } 1085*cdf0e10cSrcweir } 1086*cdf0e10cSrcweir 1087*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1088*cdf0e10cSrcweir void EditBrowseBox::DeactivateCell(sal_Bool bUpdate) 1089*cdf0e10cSrcweir { 1090*cdf0e10cSrcweir if (IsEditing()) 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir if ( isAccessibleAlive() ) 1093*cdf0e10cSrcweir { 1094*cdf0e10cSrcweir commitBrowseBoxEvent( CHILD, Any(), makeAny( m_aImpl->m_xActiveCell ) ); 1095*cdf0e10cSrcweir m_aImpl->clearActiveCell(); 1096*cdf0e10cSrcweir } 1097*cdf0e10cSrcweir 1098*cdf0e10cSrcweir aOldController = aController; 1099*cdf0e10cSrcweir aController.Clear(); 1100*cdf0e10cSrcweir 1101*cdf0e10cSrcweir // reset the modify handler 1102*cdf0e10cSrcweir aOldController->SetModifyHdl(Link()); 1103*cdf0e10cSrcweir 1104*cdf0e10cSrcweir if (bHasFocus) 1105*cdf0e10cSrcweir GrabFocus(); // ensure that we have (and keep) the focus 1106*cdf0e10cSrcweir 1107*cdf0e10cSrcweir HideAndDisable(aOldController); 1108*cdf0e10cSrcweir 1109*cdf0e10cSrcweir // update if requested 1110*cdf0e10cSrcweir if (bUpdate) 1111*cdf0e10cSrcweir Update(); 1112*cdf0e10cSrcweir 1113*cdf0e10cSrcweir nOldEditCol = nEditCol; 1114*cdf0e10cSrcweir nOldEditRow = nEditRow; 1115*cdf0e10cSrcweir 1116*cdf0e10cSrcweir // release the controller (asynchronously) 1117*cdf0e10cSrcweir if (nEndEvent) 1118*cdf0e10cSrcweir Application::RemoveUserEvent(nEndEvent); 1119*cdf0e10cSrcweir nEndEvent = Application::PostUserEvent(LINK(this,EditBrowseBox,EndEditHdl)); 1120*cdf0e10cSrcweir } 1121*cdf0e10cSrcweir } 1122*cdf0e10cSrcweir 1123*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1124*cdf0e10cSrcweir Rectangle EditBrowseBox::GetCellRect(long nRow, sal_uInt16 nColId, sal_Bool bRel) const 1125*cdf0e10cSrcweir { 1126*cdf0e10cSrcweir Rectangle aRect( GetFieldRectPixel(nRow, nColId, bRel)); 1127*cdf0e10cSrcweir if ((GetMode() & BROWSER_CURSOR_WO_FOCUS) == BROWSER_CURSOR_WO_FOCUS) 1128*cdf0e10cSrcweir { 1129*cdf0e10cSrcweir aRect.Top() += 1; 1130*cdf0e10cSrcweir aRect.Bottom() -= 1; 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir return aRect; 1133*cdf0e10cSrcweir } 1134*cdf0e10cSrcweir 1135*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1136*cdf0e10cSrcweir IMPL_LINK(EditBrowseBox, EndEditHdl, void*, EMPTYARG) 1137*cdf0e10cSrcweir { 1138*cdf0e10cSrcweir nEndEvent = 0; 1139*cdf0e10cSrcweir ReleaseController(aOldController, nOldEditRow, nOldEditCol); 1140*cdf0e10cSrcweir 1141*cdf0e10cSrcweir aOldController = CellControllerRef(); 1142*cdf0e10cSrcweir nOldEditRow = -1; 1143*cdf0e10cSrcweir nOldEditCol = 0; 1144*cdf0e10cSrcweir 1145*cdf0e10cSrcweir return 0; 1146*cdf0e10cSrcweir } 1147*cdf0e10cSrcweir 1148*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1149*cdf0e10cSrcweir IMPL_LINK(EditBrowseBox, ModifyHdl, void*, EMPTYARG) 1150*cdf0e10cSrcweir { 1151*cdf0e10cSrcweir if (nCellModifiedEvent) 1152*cdf0e10cSrcweir Application::RemoveUserEvent(nCellModifiedEvent); 1153*cdf0e10cSrcweir nCellModifiedEvent = Application::PostUserEvent(LINK(this,EditBrowseBox,CellModifiedHdl)); 1154*cdf0e10cSrcweir return 0; 1155*cdf0e10cSrcweir } 1156*cdf0e10cSrcweir 1157*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1158*cdf0e10cSrcweir IMPL_LINK(EditBrowseBox, CellModifiedHdl, void*, EMPTYARG) 1159*cdf0e10cSrcweir { 1160*cdf0e10cSrcweir nCellModifiedEvent = 0; 1161*cdf0e10cSrcweir CellModified(); 1162*cdf0e10cSrcweir return 0; 1163*cdf0e10cSrcweir } 1164*cdf0e10cSrcweir 1165*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1166*cdf0e10cSrcweir void EditBrowseBox::ColumnResized( sal_uInt16 ) 1167*cdf0e10cSrcweir { 1168*cdf0e10cSrcweir if (IsEditing()) 1169*cdf0e10cSrcweir { 1170*cdf0e10cSrcweir Rectangle aRect( GetCellRect(nEditRow, nEditCol, sal_False)); 1171*cdf0e10cSrcweir CellControllerRef aControllerRef = Controller(); 1172*cdf0e10cSrcweir ResizeController(aControllerRef, aRect); 1173*cdf0e10cSrcweir Controller()->GetWindow().GrabFocus(); 1174*cdf0e10cSrcweir } 1175*cdf0e10cSrcweir } 1176*cdf0e10cSrcweir 1177*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1178*cdf0e10cSrcweir sal_uInt16 EditBrowseBox::AppendColumn(const String& rName, sal_uInt16 nWidth, sal_uInt16 nPos, sal_uInt16 nId) 1179*cdf0e10cSrcweir { 1180*cdf0e10cSrcweir if (nId == (sal_uInt16)-1) 1181*cdf0e10cSrcweir { 1182*cdf0e10cSrcweir // look for the next free id 1183*cdf0e10cSrcweir for (nId = ColCount(); nId > 0 && GetColumnPos(nId) != BROWSER_INVALIDID; nId--) 1184*cdf0e10cSrcweir ; 1185*cdf0e10cSrcweir 1186*cdf0e10cSrcweir if (!nId) 1187*cdf0e10cSrcweir { 1188*cdf0e10cSrcweir // if there is no handle column 1189*cdf0e10cSrcweir // increment the id 1190*cdf0e10cSrcweir if (!ColCount() || GetColumnId(0)) 1191*cdf0e10cSrcweir nId = ColCount() + 1; 1192*cdf0e10cSrcweir } 1193*cdf0e10cSrcweir } 1194*cdf0e10cSrcweir 1195*cdf0e10cSrcweir DBG_ASSERT(nId, "EditBrowseBox::AppendColumn: invalid id!"); 1196*cdf0e10cSrcweir 1197*cdf0e10cSrcweir long w = nWidth; 1198*cdf0e10cSrcweir if (!w) 1199*cdf0e10cSrcweir w = GetDefaultColumnWidth(rName); 1200*cdf0e10cSrcweir 1201*cdf0e10cSrcweir InsertDataColumn(nId, rName, w, (HIB_CENTER | HIB_VCENTER | HIB_CLICKABLE), nPos); 1202*cdf0e10cSrcweir return nId; 1203*cdf0e10cSrcweir } 1204*cdf0e10cSrcweir 1205*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1206*cdf0e10cSrcweir void EditBrowseBox::Resize() 1207*cdf0e10cSrcweir { 1208*cdf0e10cSrcweir BrowseBox::Resize(); 1209*cdf0e10cSrcweir 1210*cdf0e10cSrcweir // if the window is smaller than "title line height" + "control area", 1211*cdf0e10cSrcweir // do nothing 1212*cdf0e10cSrcweir if (GetOutputSizePixel().Height() < 1213*cdf0e10cSrcweir (GetControlArea().GetHeight() + GetDataWindow().GetPosPixel().Y())) 1214*cdf0e10cSrcweir return; 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir // the size of the control area 1217*cdf0e10cSrcweir Point aPoint(GetControlArea().TopLeft()); 1218*cdf0e10cSrcweir sal_uInt16 nX = (sal_uInt16)aPoint.X(); 1219*cdf0e10cSrcweir 1220*cdf0e10cSrcweir ArrangeControls(nX, (sal_uInt16)aPoint.Y()); 1221*cdf0e10cSrcweir 1222*cdf0e10cSrcweir if (!nX) 1223*cdf0e10cSrcweir nX = USHRT_MAX; 1224*cdf0e10cSrcweir ReserveControlArea((sal_uInt16)nX); 1225*cdf0e10cSrcweir } 1226*cdf0e10cSrcweir 1227*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1228*cdf0e10cSrcweir void EditBrowseBox::ArrangeControls(sal_uInt16&, sal_uInt16) 1229*cdf0e10cSrcweir { 1230*cdf0e10cSrcweir } 1231*cdf0e10cSrcweir 1232*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1233*cdf0e10cSrcweir CellController* EditBrowseBox::GetController(long, sal_uInt16) 1234*cdf0e10cSrcweir { 1235*cdf0e10cSrcweir return NULL; 1236*cdf0e10cSrcweir } 1237*cdf0e10cSrcweir 1238*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1239*cdf0e10cSrcweir void EditBrowseBox::ResizeController(CellControllerRef& rController, const Rectangle& rRect) 1240*cdf0e10cSrcweir { 1241*cdf0e10cSrcweir rController->GetWindow().SetPosSizePixel(rRect.TopLeft(), rRect.GetSize()); 1242*cdf0e10cSrcweir } 1243*cdf0e10cSrcweir 1244*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1245*cdf0e10cSrcweir void EditBrowseBox::InitController(CellControllerRef&, long, sal_uInt16) 1246*cdf0e10cSrcweir { 1247*cdf0e10cSrcweir } 1248*cdf0e10cSrcweir 1249*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1250*cdf0e10cSrcweir void EditBrowseBox::ReleaseController(CellControllerRef&, long, sal_uInt16) 1251*cdf0e10cSrcweir { 1252*cdf0e10cSrcweir } 1253*cdf0e10cSrcweir 1254*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1255*cdf0e10cSrcweir void EditBrowseBox::CellModified() 1256*cdf0e10cSrcweir { 1257*cdf0e10cSrcweir } 1258*cdf0e10cSrcweir 1259*cdf0e10cSrcweir 1260*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1261*cdf0e10cSrcweir sal_Bool EditBrowseBox::SaveModified() 1262*cdf0e10cSrcweir { 1263*cdf0e10cSrcweir return sal_True; 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir 1266*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1267*cdf0e10cSrcweir void EditBrowseBox::DoubleClick(const BrowserMouseEvent& rEvt) 1268*cdf0e10cSrcweir { 1269*cdf0e10cSrcweir // when double clicking on the column, the optimum size will be calculated 1270*cdf0e10cSrcweir sal_uInt16 nColId = rEvt.GetColumnId(); 1271*cdf0e10cSrcweir if (nColId != HANDLE_ID) 1272*cdf0e10cSrcweir SetColumnWidth(nColId, GetAutoColumnWidth(nColId)); 1273*cdf0e10cSrcweir } 1274*cdf0e10cSrcweir 1275*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1276*cdf0e10cSrcweir sal_uInt32 EditBrowseBox::GetAutoColumnWidth(sal_uInt16 nColId) 1277*cdf0e10cSrcweir { 1278*cdf0e10cSrcweir sal_uInt32 nCurColWidth = GetColumnWidth(nColId); 1279*cdf0e10cSrcweir sal_uInt32 nMinColWidth = CalcZoom(20); // minimum 1280*cdf0e10cSrcweir sal_uInt32 nNewColWidth = nMinColWidth; 1281*cdf0e10cSrcweir long nMaxRows = Min(long(GetVisibleRows()), GetRowCount()); 1282*cdf0e10cSrcweir long nLastVisRow = GetTopRow() + nMaxRows - 1; 1283*cdf0e10cSrcweir 1284*cdf0e10cSrcweir if (GetTopRow() <= nLastVisRow) // calc the column with using the cell contents 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir for (long i = GetTopRow(); i <= nLastVisRow; ++i) 1287*cdf0e10cSrcweir nNewColWidth = std::max(nNewColWidth,GetTotalCellWidth(i,nColId) + 12); 1288*cdf0e10cSrcweir 1289*cdf0e10cSrcweir if (nNewColWidth == nCurColWidth) // size has not changed 1290*cdf0e10cSrcweir nNewColWidth = GetDefaultColumnWidth(GetColumnTitle(nColId)); 1291*cdf0e10cSrcweir } 1292*cdf0e10cSrcweir else 1293*cdf0e10cSrcweir nNewColWidth = GetDefaultColumnWidth(GetColumnTitle(nColId)); 1294*cdf0e10cSrcweir return nNewColWidth; 1295*cdf0e10cSrcweir } 1296*cdf0e10cSrcweir 1297*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1298*cdf0e10cSrcweir sal_uInt32 EditBrowseBox::GetTotalCellWidth(long, sal_uInt16) 1299*cdf0e10cSrcweir { 1300*cdf0e10cSrcweir return 0; 1301*cdf0e10cSrcweir } 1302*cdf0e10cSrcweir 1303*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1304*cdf0e10cSrcweir void EditBrowseBox::InvalidateHandleColumn() 1305*cdf0e10cSrcweir { 1306*cdf0e10cSrcweir Rectangle aHdlFieldRect( GetFieldRectPixel( 0, 0 )); 1307*cdf0e10cSrcweir Rectangle aInvalidRect( Point(0,0), GetOutputSizePixel() ); 1308*cdf0e10cSrcweir aInvalidRect.Right() = aHdlFieldRect.Right(); 1309*cdf0e10cSrcweir Invalidate( aInvalidRect ); 1310*cdf0e10cSrcweir } 1311*cdf0e10cSrcweir 1312*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1313*cdf0e10cSrcweir void EditBrowseBox::PaintTristate(OutputDevice&, const Rectangle& rRect,const TriState& eState,sal_Bool _bEnabled) const 1314*cdf0e10cSrcweir { 1315*cdf0e10cSrcweir pCheckBoxPaint->GetBox().SetState(eState); 1316*cdf0e10cSrcweir pCheckBoxPaint->SetPosSizePixel(rRect.TopLeft(), rRect.GetSize()); 1317*cdf0e10cSrcweir 1318*cdf0e10cSrcweir // First update the parent, preventing that while painting this window 1319*cdf0e10cSrcweir // an update for the parent is done (because it's in the queue already) 1320*cdf0e10cSrcweir // which may lead to hiding this window immediately 1321*cdf0e10cSrcweir // #95598# comment out OJ 1322*cdf0e10cSrcweir /* if (pCheckBoxPaint->GetParent()) 1323*cdf0e10cSrcweir pCheckBoxPaint->GetParent()->Update(); 1324*cdf0e10cSrcweir */ 1325*cdf0e10cSrcweir pCheckBoxPaint->GetBox().Enable(_bEnabled); 1326*cdf0e10cSrcweir pCheckBoxPaint->Show(); 1327*cdf0e10cSrcweir pCheckBoxPaint->SetParentUpdateMode( sal_False ); 1328*cdf0e10cSrcweir pCheckBoxPaint->Update(); 1329*cdf0e10cSrcweir pCheckBoxPaint->Hide(); 1330*cdf0e10cSrcweir pCheckBoxPaint->SetParentUpdateMode( sal_True ); 1331*cdf0e10cSrcweir } 1332*cdf0e10cSrcweir 1333*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1334*cdf0e10cSrcweir void EditBrowseBox::AsynchGetFocus() 1335*cdf0e10cSrcweir { 1336*cdf0e10cSrcweir if (nStartEvent) 1337*cdf0e10cSrcweir Application::RemoveUserEvent(nStartEvent); 1338*cdf0e10cSrcweir 1339*cdf0e10cSrcweir m_pFocusWhileRequest = Application::GetFocusWindow(); 1340*cdf0e10cSrcweir nStartEvent = Application::PostUserEvent(LINK(this,EditBrowseBox,StartEditHdl)); 1341*cdf0e10cSrcweir } 1342*cdf0e10cSrcweir 1343*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1344*cdf0e10cSrcweir void EditBrowseBox::SetBrowserFlags(sal_Int32 nFlags) 1345*cdf0e10cSrcweir { 1346*cdf0e10cSrcweir if (m_nBrowserFlags == nFlags) 1347*cdf0e10cSrcweir return; 1348*cdf0e10cSrcweir 1349*cdf0e10cSrcweir sal_Bool RowPicturesChanges = ((m_nBrowserFlags & EBBF_NO_HANDLE_COLUMN_CONTENT) != 1350*cdf0e10cSrcweir (nFlags & EBBF_NO_HANDLE_COLUMN_CONTENT)); 1351*cdf0e10cSrcweir m_nBrowserFlags = nFlags; 1352*cdf0e10cSrcweir 1353*cdf0e10cSrcweir if (RowPicturesChanges) 1354*cdf0e10cSrcweir InvalidateStatusCell(GetCurRow()); 1355*cdf0e10cSrcweir } 1356*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1357*cdf0e10cSrcweir inline void EditBrowseBox::HideAndDisable(CellControllerRef& rController) 1358*cdf0e10cSrcweir { 1359*cdf0e10cSrcweir rController->suspend(); 1360*cdf0e10cSrcweir } 1361*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1362*cdf0e10cSrcweir inline void EditBrowseBox::EnableAndShow() const 1363*cdf0e10cSrcweir { 1364*cdf0e10cSrcweir Controller()->resume(); 1365*cdf0e10cSrcweir } 1366*cdf0e10cSrcweir //=============================================================================== 1367*cdf0e10cSrcweir 1368*cdf0e10cSrcweir DBG_NAME(CellController); 1369*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1370*cdf0e10cSrcweir CellController::CellController(Control* pW) 1371*cdf0e10cSrcweir :pWindow( pW ) 1372*cdf0e10cSrcweir ,bSuspended( sal_True ) 1373*cdf0e10cSrcweir { 1374*cdf0e10cSrcweir DBG_CTOR(CellController,NULL); 1375*cdf0e10cSrcweir 1376*cdf0e10cSrcweir DBG_ASSERT(pWindow, "CellController::CellController: missing the window!"); 1377*cdf0e10cSrcweir DBG_ASSERT(!pWindow->IsVisible(), "CellController::CellController: window should not be visible!"); 1378*cdf0e10cSrcweir } 1379*cdf0e10cSrcweir 1380*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1381*cdf0e10cSrcweir CellController::~CellController() 1382*cdf0e10cSrcweir { 1383*cdf0e10cSrcweir 1384*cdf0e10cSrcweir DBG_DTOR(CellController,NULL); 1385*cdf0e10cSrcweir } 1386*cdf0e10cSrcweir 1387*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1388*cdf0e10cSrcweir void CellController::suspend( ) 1389*cdf0e10cSrcweir { 1390*cdf0e10cSrcweir DBG_ASSERT( bSuspended == !GetWindow().IsVisible(), "CellController::suspend: inconsistence!" ); 1391*cdf0e10cSrcweir if ( !isSuspended( ) ) 1392*cdf0e10cSrcweir { 1393*cdf0e10cSrcweir CommitModifications(); 1394*cdf0e10cSrcweir GetWindow().Hide( ); 1395*cdf0e10cSrcweir GetWindow().Disable( ); 1396*cdf0e10cSrcweir bSuspended = sal_True; 1397*cdf0e10cSrcweir } 1398*cdf0e10cSrcweir } 1399*cdf0e10cSrcweir 1400*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1401*cdf0e10cSrcweir void CellController::resume( ) 1402*cdf0e10cSrcweir { 1403*cdf0e10cSrcweir DBG_ASSERT( bSuspended == !GetWindow().IsVisible(), "CellController::resume: inconsistence!" ); 1404*cdf0e10cSrcweir if ( isSuspended( ) ) 1405*cdf0e10cSrcweir { 1406*cdf0e10cSrcweir GetWindow().Enable( ); 1407*cdf0e10cSrcweir GetWindow().Show( ); 1408*cdf0e10cSrcweir bSuspended = sal_False; 1409*cdf0e10cSrcweir } 1410*cdf0e10cSrcweir } 1411*cdf0e10cSrcweir 1412*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1413*cdf0e10cSrcweir void CellController::CommitModifications() 1414*cdf0e10cSrcweir { 1415*cdf0e10cSrcweir // nothing to do in this base class 1416*cdf0e10cSrcweir } 1417*cdf0e10cSrcweir 1418*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1419*cdf0e10cSrcweir sal_Bool CellController::WantMouseEvent() const 1420*cdf0e10cSrcweir { 1421*cdf0e10cSrcweir return sal_False; 1422*cdf0e10cSrcweir } 1423*cdf0e10cSrcweir 1424*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1425*cdf0e10cSrcweir void CellController::SetModified() 1426*cdf0e10cSrcweir { 1427*cdf0e10cSrcweir } 1428*cdf0e10cSrcweir 1429*cdf0e10cSrcweir //----------------------------------------------------------------------------- 1430*cdf0e10cSrcweir sal_Bool CellController::MoveAllowed(const KeyEvent&) const 1431*cdf0e10cSrcweir { 1432*cdf0e10cSrcweir return sal_True; 1433*cdf0e10cSrcweir } 1434*cdf0e10cSrcweir // ....................................................................... 1435*cdf0e10cSrcweir } // namespace svt 1436*cdf0e10cSrcweir // ....................................................................... 1437*cdf0e10cSrcweir 1438