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