1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
21 #define _SVTOOLS_EDITBROWSEBOX_HXX_
22 #define SVTOOLS_IN_EDITBROWSEBOX_HXX
24 #include "svtools/svtdllapi.h"
25 #include <tools/ref.hxx>
26 #include <tools/rtti.hxx>
27 #include <vcl/window.hxx>
28 #include <vcl/combobox.hxx>
29 #include <vcl/lstbox.hxx>
31 #include <vcl/button.hxx>
32 #include <svtools/brwbox.hxx>
33 #include <vcl/timer.hxx>
34 #include <svtools/brwhead.hxx>
35 #include <svtools/svmedit.hxx>
36 #include <vcl/svapp.hxx>
38 //==================================================================
39 // EditBrowseBoxFlags (EBBF)
41 #define EBBF_NONE ((sal_Int32)0x0000)
42 /** if this bit is _not_ set, the handle column will be invalidated upon
43 changing the row in the browse box. This is for forcing the row picture to
44 be repainted. If you do not have row pictures or text, you don't need this
45 invalidation, then you would specify this bit to prevent flicker
47 #define EBBF_NO_HANDLE_COLUMN_CONTENT ((sal_Int32)0x0001)
48 /** set this bit to activate the cell on a MouseButtonDown, not a MouseButtonUp event
50 #define EBBF_ACTIVATE_ON_BUTTONDOWN ((sal_Int32)0x0002)
51 /** if this bit is set and EBBF_NO_HANDLE_COLUMN_CONTENT is _not_ set, the handle
52 column is drawn with the text contained in column 0 instead of an image
54 #define EBBF_HANDLE_COLUMN_TEXT ((sal_Int32)0x0004)
56 /** If this bit is set, tab traveling is somewhat modified<br/>
57 If the control gets the focus because the user pressed the TAB key, then the
58 first or last cell (depending on whether the traveling was cycling forward or backward)
60 @see Window::GetGetFocusFlags
63 #define EBBF_SMART_TAB_TRAVEL ((sal_Int32)0x0008)
66 #define EBBF_NOROWPICTURE EBBF_NO_HANDLE_COLUMN_CONTENT
68 //==================================================================
74 // .......................................................................
77 // .......................................................................
79 class CellControllerRef
;
81 //==================================================================
83 //==================================================================
84 class SVT_DLLPUBLIC CellController
: public SvRefBase
86 friend class EditBrowseBox
;
90 sal_Bool bSuspended
; // <sal_True> if the window is hidden and disabled
95 CellController(Control
* pW
);
96 virtual ~CellController();
98 Control
& GetWindow() const { return *const_cast< CellController
* >( this )->pWindow
; }
100 virtual void SetModified();
101 virtual void ClearModified() = 0;
102 virtual sal_Bool
IsModified() const = 0;
104 // commit any current changes. Especially, do any reformatting you need (from input formatting
105 // to output formatting) here
106 virtual void CommitModifications();
108 // suspending the controller is not culmulative!
111 inline sal_Bool
isSuspended( ) const { return bSuspended
; }
114 virtual sal_Bool
MoveAllowed(const KeyEvent
& rEvt
) const;
115 virtual void SetModifyHdl(const Link
& rLink
) = 0;
116 virtual sal_Bool
WantMouseEvent() const;
119 SV_DECL_IMPL_REF(CellController
);
121 //==================================================================
122 //= IEditImplementation
123 //==================================================================
124 class SVT_DLLPUBLIC IEditImplementation
127 virtual ~IEditImplementation() = 0;
129 virtual Control
& GetControl() = 0;
131 virtual String
GetText( LineEnd aSeparator
) const = 0;
132 virtual void SetText( const OUString
& _rStr
) = 0;
134 virtual sal_Bool
IsReadOnly() const = 0;
135 virtual void SetReadOnly( sal_Bool bReadOnly
) = 0;
137 virtual xub_StrLen
GetMaxTextLen() const = 0;
138 virtual void SetMaxTextLen( xub_StrLen _nMaxLen
) = 0;
140 virtual Selection
GetSelection() const = 0;
141 virtual void SetSelection( const Selection
& _rSelection
) = 0;
143 virtual void ReplaceSelected( const String
& _rStr
) = 0;
144 virtual void DeleteSelected() = 0;
145 virtual String
GetSelected( LineEnd aSeparator
) const = 0;
147 virtual void SetModified() = 0;
148 virtual sal_Bool
IsModified() const = 0;
149 virtual void ClearModified() = 0;
150 virtual void SetModifyHdl( const Link
& _rLink
) = 0;
153 //==================================================================
154 //= GenericEditImplementation
155 //==================================================================
156 template <class EDIT
>
157 class GenericEditImplementation
: public IEditImplementation
161 GenericEditImplementation( EDIT
& _rEdit
);
163 EDIT
& GetEditWindow() { return static_cast< EDIT
& >( GetControl() ); }
165 virtual Control
& GetControl();
167 virtual String
GetText( LineEnd aSeparator
) const;
168 virtual void SetText( const OUString
& _rStr
);
170 virtual sal_Bool
IsReadOnly() const;
171 virtual void SetReadOnly( sal_Bool bReadOnly
);
173 virtual xub_StrLen
GetMaxTextLen() const;
174 virtual void SetMaxTextLen( xub_StrLen _nMaxLen
);
176 virtual Selection
GetSelection() const;
177 virtual void SetSelection( const Selection
& _rSelection
);
179 virtual void ReplaceSelected( const String
& _rStr
);
180 virtual void DeleteSelected();
181 virtual String
GetSelected( LineEnd aSeparator
) const;
183 virtual void SetModified();
184 virtual sal_Bool
IsModified() const;
185 virtual void ClearModified();
186 virtual void SetModifyHdl( const Link
& _rLink
);
189 #include <svtools/editimplementation.hxx>
191 //==================================================================
192 //= MultiLineTextCell
193 //==================================================================
194 /** a multi line edit which can be used in a cell of a EditBrowseBox
196 class SVT_DLLPUBLIC MultiLineTextCell
: public MultiLineEdit
199 MultiLineTextCell( Window
* _pParent
, WinBits _nStyle
)
200 :MultiLineEdit( _pParent
, _nStyle
)
205 // Window overridables
206 virtual long PreNotify( NotifyEvent
& rNEvt
);
208 // MultiLineEdit overridables
209 virtual void Modify();
212 sal_Bool
dispatchKeyEvent( const KeyEvent
& _rEvent
);
215 //==================================================================
216 //= concrete edit implementations
217 //==================================================================
218 typedef GenericEditImplementation
< Edit
> EditImplementation
;
220 typedef GenericEditImplementation
< MultiLineTextCell
> MultiLineEditImplementation_Base
;
221 class SVT_DLLPUBLIC MultiLineEditImplementation
: public MultiLineEditImplementation_Base
224 MultiLineEditImplementation( MultiLineTextCell
& _rEdit
) : MultiLineEditImplementation_Base( _rEdit
)
228 virtual String
GetText( LineEnd aSeparator
) const;
229 virtual String
GetSelected( LineEnd aSeparator
) const;
232 //==================================================================
233 //= EditCellController
234 //==================================================================
235 class SVT_DLLPUBLIC EditCellController
: public CellController
237 IEditImplementation
* m_pEditImplementation
;
238 sal_Bool m_bOwnImplementation
; // did we create m_pEditImplementation?
242 EditCellController( Edit
* _pEdit
);
243 EditCellController( IEditImplementation
* _pImplementation
);
244 ~EditCellController( );
246 const IEditImplementation
* GetEditImplementation( ) const { return m_pEditImplementation
; }
247 IEditImplementation
* GetEditImplementation( ) { return m_pEditImplementation
; }
249 virtual void SetModified();
250 virtual sal_Bool
IsModified() const;
251 virtual void ClearModified();
254 virtual sal_Bool
MoveAllowed(const KeyEvent
& rEvt
) const;
255 virtual void SetModifyHdl(const Link
& rLink
);
258 //==================================================================
259 //= SpinCellController
260 //==================================================================
261 class SVT_DLLPUBLIC SpinCellController
: public CellController
265 SpinCellController(SpinField
* pSpinField
);
266 SpinField
& GetSpinWindow() const {return (SpinField
&)GetWindow();}
268 virtual void SetModified();
269 virtual sal_Bool
IsModified() const;
270 virtual void ClearModified();
273 virtual sal_Bool
MoveAllowed(const KeyEvent
& rEvt
) const;
274 virtual void SetModifyHdl(const Link
& rLink
);
277 //==================================================================
279 //==================================================================
280 class SVT_DLLPUBLIC CheckBoxControl
: public Control
283 Rectangle aFocusRect
;
284 Link m_aClickLink
,m_aModifyLink
;
287 CheckBoxControl(Window
* pParent
, WinBits nWinStyle
= 0);
290 virtual void GetFocus();
291 virtual long PreNotify(NotifyEvent
& rEvt
);
292 virtual void Paint(const Rectangle
& rClientRect
);
293 virtual void Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
, sal_uLong nFlags
);
294 virtual void StateChanged( StateChangedType nStateChange
);
295 virtual void DataChanged( const DataChangedEvent
& _rEvent
);
296 virtual void Resize();
298 void SetClickHdl(const Link
& rHdl
) {m_aClickLink
= rHdl
;}
299 const Link
& GetClickHdl() const {return m_aClickLink
;}
301 void SetModifyHdl(const Link
& rHdl
) {m_aModifyLink
= rHdl
;}
302 const Link
& GetModifyHdl() const {return m_aModifyLink
;}
304 CheckBox
& GetBox() {return *pBox
;};
307 DECL_LINK( OnClick
, void* );
310 //==================================================================
311 //= CheckBoxCellController
312 //==================================================================
313 class SVT_DLLPUBLIC CheckBoxCellController
: public CellController
318 CheckBoxCellController(CheckBoxControl
* pWin
):CellController(pWin
){}
319 CheckBox
& GetCheckBox() const;
321 virtual sal_Bool
IsModified() const;
322 virtual void ClearModified();
325 virtual void SetModifyHdl(const Link
& rLink
);
326 virtual sal_Bool
WantMouseEvent() const;
329 //==================================================================
331 //==================================================================
332 class SVT_DLLPUBLIC ComboBoxControl
: public ComboBox
334 friend class ComboBoxCellController
;
337 ComboBoxControl(Window
* pParent
, WinBits nWinStyle
= 0);
340 virtual long PreNotify( NotifyEvent
& rNEvt
);
343 //==================================================================
344 //= ComboBoxCellController
345 //==================================================================
346 class SVT_DLLPUBLIC ComboBoxCellController
: public CellController
351 ComboBoxCellController(ComboBoxControl
* pParent
);
352 ComboBoxControl
& GetComboBox() const {return (ComboBoxControl
&)GetWindow();}
354 virtual sal_Bool
IsModified() const;
355 virtual void ClearModified();
358 virtual sal_Bool
MoveAllowed(const KeyEvent
& rEvt
) const;
359 virtual void SetModifyHdl(const Link
& rLink
);
362 //==================================================================
364 //==================================================================
365 class SVT_DLLPUBLIC ListBoxControl
: public ListBox
367 friend class ListBoxCellController
;
370 ListBoxControl(Window
* pParent
, WinBits nWinStyle
= 0);
373 virtual long PreNotify( NotifyEvent
& rNEvt
);
376 //==================================================================
377 //= ListBoxCellController
378 //==================================================================
379 class SVT_DLLPUBLIC ListBoxCellController
: public CellController
384 ListBoxCellController(ListBoxControl
* pParent
);
385 ListBoxControl
& GetListBox() const {return (ListBoxControl
&)GetWindow();}
387 virtual sal_Bool
IsModified() const;
388 virtual void ClearModified();
391 virtual sal_Bool
MoveAllowed(const KeyEvent
& rEvt
) const;
392 virtual void SetModifyHdl(const Link
& rLink
);
395 //==================================================================
396 //= FormattedFieldCellController
397 //==================================================================
398 class SVT_DLLPUBLIC FormattedFieldCellController
: public EditCellController
402 FormattedFieldCellController( FormattedField
* _pFormatted
);
404 virtual void CommitModifications();
407 //==================================================================
408 //= EditBrowserHeader
409 //==================================================================
410 class SVT_DLLPUBLIC EditBrowserHeader
: public BrowserHeader
413 EditBrowserHeader( BrowseBox
* pParent
, WinBits nWinBits
= WB_BUTTONSTYLE
)
414 :BrowserHeader(pParent
, nWinBits
){}
417 virtual void DoubleClick();
420 //==================================================================
422 //==================================================================
423 class EditBrowseBoxImpl
;
424 class SVT_DLLPUBLIC EditBrowseBox
: public BrowseBox
426 friend class EditBrowserHeader
;
446 CURRENT_PRIMARYKEY
= 7,
453 EditBrowseBox(EditBrowseBox
&);
454 EditBrowseBox
& operator=(EditBrowseBox
&);
456 class BrowserMouseEventPtr
458 BrowserMouseEvent
* pEvent
;
462 BrowserMouseEventPtr():pEvent(NULL
){}
463 ~BrowserMouseEventPtr(){Clear();}
465 sal_Bool
Is() const {return pEvent
!= NULL
;}
466 sal_Bool
IsDown() const {return bDown
;}
467 const BrowserMouseEvent
* operator->() const {return pEvent
;}
468 const BrowserMouseEvent
& operator*() const {return *pEvent
;}
470 SVT_DLLPUBLIC
void Clear();
471 void Set(const BrowserMouseEvent
* pEvt
, sal_Bool bIsDown
);
474 const BrowserMouseEvent
* pMouseEvent
; // is set during a mouse event
475 CellControllerRef aController
,
478 sal_uLong nStartEvent
, nEndEvent
, nCellModifiedEvent
; // event ids
479 Window
* m_pFocusWhileRequest
;
480 // In ActivateCell, we grab the focus asynchronously, but if between requesting activation
481 // and the asynchornous event the focus has changed, we won't grab it for ourself.
483 long nPaintRow
; // row beeing painted
484 long nEditRow
, nOldEditRow
;
485 sal_uInt16 nEditCol
, nOldEditCol
;
487 sal_Bool bHasFocus
: 1;
488 mutable sal_Bool bPaintStatus
: 1; // paint a status (image) in the handle column
489 sal_Bool bActiveBeforeTracking
;
491 CheckBoxControl
* pCheckBoxPaint
;
493 sal_Int32 m_nBrowserFlags
;
494 ImageList m_aStatusImages
;
495 ::std::auto_ptr
< EditBrowseBoxImpl
> m_aImpl
;
498 BrowserHeader
* pHeader
;
500 sal_Bool
isGetCellFocusPending() const { return nStartEvent
!= 0; }
501 void cancelGetCellFocus() { if (nStartEvent
) Application::RemoveUserEvent(nStartEvent
); nStartEvent
= 0; }
502 void forceGetCellFocus() { cancelGetCellFocus(); LINK(this, EditBrowseBox
, StartEditHdl
).Call((void*)NULL
); }
504 BrowserMouseEventPtr
& getMouseEvent() { return aMouseEvent
; }
507 BrowserHeader
* GetHeaderBar() const {return pHeader
;}
509 virtual BrowserHeader
* CreateHeaderBar(BrowseBox
* pParent
);
511 // if you want to have an own header ...
512 virtual BrowserHeader
* imp_CreateHeaderBar(BrowseBox
* pParent
);
514 virtual void ColumnMoved(sal_uInt16 nId
);
515 virtual void ColumnResized(sal_uInt16 nColId
);
516 virtual void Resize();
517 virtual void ArrangeControls(sal_uInt16
& nX
, sal_uInt16 nY
);
518 virtual sal_Bool
SeekRow(long nRow
);
520 virtual void GetFocus();
521 virtual void LoseFocus();
522 virtual void KeyInput(const KeyEvent
& rEvt
);
523 virtual void MouseButtonDown(const BrowserMouseEvent
& rEvt
);
524 virtual void MouseButtonUp(const BrowserMouseEvent
& rEvt
);
525 virtual void StateChanged( StateChangedType nType
);
526 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
528 using BrowseBox::MouseButtonUp
;
529 using BrowseBox::MouseButtonDown
;
531 virtual long PreNotify(NotifyEvent
& rNEvt
);
532 virtual long Notify(NotifyEvent
& rNEvt
);
534 virtual void EndScroll();
536 // should be used instead of GetFieldRectPixel, 'cause this method here takes into account the borders
537 Rectangle
GetCellRect(long nRow
, sal_uInt16 nColId
, sal_Bool bRelToBrowser
= sal_True
) const;
538 virtual sal_uInt32
GetTotalCellWidth(long nRow
, sal_uInt16 nColId
);
539 virtual sal_uInt32
GetAutoColumnWidth(sal_uInt16 nColId
);
541 virtual void PaintStatusCell(OutputDevice
& rDev
, const Rectangle
& rRect
) const;
542 virtual void PaintCell(OutputDevice
& rDev
, const Rectangle
& rRect
, sal_uInt16 nColId
) const = 0;
544 virtual RowStatus
GetRowStatus(long nRow
) const;
546 virtual void RowHeightChanged();
548 // callbacks for the data window
549 virtual void ImplStartTracking();
550 virtual void ImplTracking();
551 virtual void ImplEndTracking();
553 // when changing a row:
554 // CursorMoving: cursor is beeing moved, but GetCurRow() still provides the old row
555 virtual sal_Bool
CursorMoving(long nNewRow
, sal_uInt16 nNewCol
);
557 // cursor has been moved
558 virtual void CursorMoved();
560 virtual void CellModified(); // called whenever a cell has been modified
561 virtual sal_Bool
SaveModified(); // called whenever a cell should be left, and it's content should be saved
562 // return sal_False prevents leaving the cell
563 virtual sal_Bool
SaveRow(); // commit the current row
565 virtual sal_Bool
IsModified() const {return aController
.Is() && aController
->IsModified();}
567 virtual CellController
* GetController(long nRow
, sal_uInt16 nCol
);
568 virtual void InitController(CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
);
569 virtual void ResizeController(CellControllerRef
& rController
, const Rectangle
&);
570 virtual void ReleaseController(CellControllerRef
& pController
, long nRow
, sal_uInt16 nCol
);
571 virtual void DoubleClick(const BrowserMouseEvent
&);
573 void ActivateCell() { ActivateCell(GetCurRow(), GetCurColumnId()); }
575 // retrieve the image for the row status
576 virtual Image
GetImage(RowStatus
) const;
579 // if you don't set a width, this will be calculated automatically
580 // if the id isn't set the smallest unused will do it ...
581 virtual sal_uInt16
AppendColumn(const String
& rName
, sal_uInt16 nWidth
= 0, sal_uInt16 nPos
= HEADERBAR_APPEND
, sal_uInt16 nId
= (sal_uInt16
)-1);
583 // called whenever (Shift)Tab or Enter is pressed. If true is returned, these keys
584 // result in traveling to the next or to th previous cell
585 virtual sal_Bool
IsTabAllowed(sal_Bool bForward
) const;
587 virtual sal_Bool
IsCursorMoveAllowed(long nNewRow
, sal_uInt16 nNewColId
) const;
589 void PaintTristate(OutputDevice
& rDev
, const Rectangle
& rRect
,const TriState
& eState
,sal_Bool _bEnabled
=sal_True
) const;
591 void AsynchGetFocus();
592 // secure starting of StartEditHdl
595 EditBrowseBox(Window
* pParent
, sal_Int32 nBrowserFlags
= EBBF_NONE
, WinBits nBits
= WB_TABSTOP
, BrowserMode nMode
= 0 );
596 EditBrowseBox(Window
* pParent
, const ResId
& rId
, sal_Int32 nBrowserFlags
= EBBF_NONE
, BrowserMode nMode
= 0 );
599 sal_Bool
IsEditing() const {return aController
.Is();}
600 void InvalidateStatusCell(long nRow
) {RowModified(nRow
, 0);}
601 void InvalidateHandleColumn();
605 virtual void RemoveRows();
606 virtual void Dispatch(sal_uInt16 nId
);
608 CellControllerRef
Controller() const { return aController
; }
609 sal_Int32
GetBrowserFlags() const { return m_nBrowserFlags
; }
610 void SetBrowserFlags(sal_Int32 nFlags
);
612 virtual void ActivateCell(long nRow
, sal_uInt16 nCol
, sal_Bool bSetCellFocus
= sal_True
);
613 virtual void DeactivateCell(sal_Bool bUpdate
= sal_True
);
614 // Children ---------------------------------------------------------------
616 /** Creates the accessible object of a data table cell.
618 The row index of the cell.
620 The column ID of the cell.
622 The XAccessible interface of the specified cell. */
623 virtual ::com::sun::star::uno::Reference
<
624 ::com::sun::star::accessibility::XAccessible
>
625 CreateAccessibleCell( sal_Int32 nRow
, sal_uInt16 nColumnPos
);
627 /** @return The count of additional controls of the control area. */
628 virtual sal_Int32
GetAccessibleControlCount() const;
630 /** Creates the accessible object of an additional control.
632 The 0-based index of the control.
634 The XAccessible interface of the specified control. */
635 virtual ::com::sun::star::uno::Reference
<
636 ::com::sun::star::accessibility::XAccessible
>
637 CreateAccessibleControl( sal_Int32 nIndex
);
639 /** Creates the accessible object of a column header.
641 The column ID of the header.
643 The XAccessible interface of the specified column header. */
644 virtual ::com::sun::star::uno::Reference
<
645 ::com::sun::star::accessibility::XAccessible
>
646 CreateAccessibleRowHeader( sal_Int32 _nRow
);
648 /** Sets focus to current cell of the data table. */
649 virtual void GrabTableFocus();
651 virtual Rectangle
GetFieldCharacterBounds(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,sal_Int32 nIndex
);
652 virtual sal_Int32
GetFieldIndexAtPoint(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,const Point
& _rPoint
);
654 ::com::sun::star::uno::Reference
<
655 ::com::sun::star::accessibility::XAccessible
> CreateAccessibleCheckBoxCell(long _nRow
, sal_uInt16 _nColumnPos
,const TriState
& eState
);
657 // creates the accessible which wraps the active cell
658 void implCreateActiveAccessible( );
661 virtual void PaintField(OutputDevice
& rDev
, const Rectangle
& rRect
,
662 sal_uInt16 nColumnId
) const;
663 using Control::ImplInitSettings
;
664 SVT_DLLPRIVATE
void ImplInitSettings( sal_Bool bFont
, sal_Bool bForeground
, sal_Bool bBackground
);
665 SVT_DLLPRIVATE
void DetermineFocus( const sal_uInt16 _nGetFocusFlags
= 0);
666 inline void HideAndDisable(CellControllerRef
& rController
);
667 inline void EnableAndShow() const;
669 SVT_DLLPRIVATE
void implActivateCellOnMouseEvent(const BrowserMouseEvent
& _rEvt
, sal_Bool _bUp
);
670 SVT_DLLPRIVATE
void impl_construct();
672 DECL_DLLPRIVATE_LINK(ModifyHdl
, void* );
673 DECL_DLLPRIVATE_LINK(StartEditHdl
, void* );
674 DECL_DLLPRIVATE_LINK(EndEditHdl
, void* );
675 DECL_DLLPRIVATE_LINK(CellModifiedHdl
, void* );
678 // .......................................................................
680 // .......................................................................
682 #undef SVTOOLS_IN_EDITBROWSEBOX_HXX
683 #endif // _SVTOOLS_EDITBROWSEBOX_HXX_
685 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */