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 .
23 #include <svtools/svtdllapi.h>
24 #include <tools/ref.hxx>
26 #include <svtools/brwbox.hxx>
27 #include <svtools/brwhead.hxx>
28 #include <tools/lineend.hxx>
29 #include <vcl/InterimItemWindow.hxx>
30 #include <vcl/weldutils.hxx>
31 #include <o3tl/typed_flags_set.hxx>
35 // EditBrowseBoxFlags (EBBF)
36 enum class EditBrowseBoxFlags
39 /** if this bit is _not_ set, the handle column will be invalidated upon
40 changing the row in the browse box. This is for forcing the row picture to
41 be repainted. If you do not have row pictures or text, you don't need this
42 invalidation, then you would specify this bit to prevent flicker
44 NO_HANDLE_COLUMN_CONTENT
= 0x0001,
45 /** set this bit to activate the cell on a MouseButtonDown, not a MouseButtonUp event
47 ACTIVATE_ON_BUTTONDOWN
= 0x0002,
48 /** if this bit is set and EditBrowseBoxFlags::NO_HANDLE_COLUMN_CONTENT is _not_ set, the handle
49 column is drawn with the text contained in column 0 instead of an image
51 HANDLE_COLUMN_TEXT
= 0x0004,
53 /** If this bit is set, tab traveling is somewhat modified<br/>
54 If the control gets the focus because the user pressed the TAB key, then the
55 first or last cell (depending on whether the traveling was cycling forward or backward)
57 @see Window::GetGetFocusFlags
60 SMART_TAB_TRAVEL
= 0x0008,
65 template<> struct typed_flags
<EditBrowseBoxFlags
> : is_typed_flags
<EditBrowseBoxFlags
, 0x0f> {};
72 class SVT_DLLPUBLIC CellController
: public SvRefBase
74 friend class EditBrowseBox
;
75 Link
<LinkParamNone
*, void> maModifyHdl
;
77 VclPtr
<ControlBase
> pWindow
;
78 bool bSuspended
; // <true> if the window is hidden and disabled
82 CellController(ControlBase
* pW
);
83 virtual ~CellController() override
;
85 ControlBase
& GetWindow() const { return *const_cast<CellController
*>(this)->pWindow
; }
87 virtual void SaveValue() = 0;
88 virtual bool IsValueChangedFromSaved() const = 0;
90 // commit any current changes. Especially, do any reformatting you need (from input formatting
91 // to output formatting) here
92 virtual void CommitModifications();
94 // suspending the controller is not cumulative!
97 bool isSuspended( ) const { return bSuspended
; }
100 virtual bool MoveAllowed(const KeyEvent
& rEvt
) const;
101 void SetModifyHdl(const Link
<LinkParamNone
*,void>& rLink
) { maModifyHdl
= rLink
; }
102 virtual void ActivatingMouseEvent(const BrowserMouseEvent
& rEvt
, bool bUp
);
103 virtual void callModifyHdl() { maModifyHdl
.Call(nullptr); }
106 typedef tools::SvRef
<CellController
> CellControllerRef
;
109 //= IEditImplementation
111 class SVT_DLLPUBLIC IEditImplementation
114 virtual ~IEditImplementation() = 0;
116 virtual ControlBase
& GetControl() = 0;
118 virtual OUString
GetText( LineEnd aSeparator
) const = 0;
119 virtual void SetText( const OUString
& _rStr
) = 0;
121 virtual bool IsReadOnly() const = 0;
122 virtual void SetReadOnly( bool bReadOnly
) = 0;
124 virtual sal_Int32
GetMaxTextLen() const = 0;
125 virtual void SetMaxTextLen( sal_Int32 _nMaxLen
) = 0;
127 virtual Selection
GetSelection() const = 0;
128 virtual void SetSelection( const Selection
& _rSelection
) = 0;
130 virtual void ReplaceSelected( const OUString
& _rStr
) = 0;
131 virtual OUString
GetSelected( LineEnd aSeparator
) const = 0;
133 virtual bool IsValueChangedFromSaved() const = 0;
134 virtual void SaveValue() = 0;
136 virtual bool CanUp() const = 0;
137 virtual bool CanDown() const = 0;
139 virtual void Cut() = 0;
140 virtual void Copy() = 0;
141 virtual void Paste() = 0;
143 // sets a link to call when the text is changed by the user
144 void SetModifyHdl(const Link
<LinkParamNone
*,void>& rLink
)
146 m_aModify1Hdl
= rLink
;
149 // sets an additional link to call when the text is changed by the user
150 void SetAuxModifyHdl(const Link
<LinkParamNone
*,void>& rLink
)
152 m_aModify2Hdl
= rLink
;
156 Link
<LinkParamNone
*,void> m_aModify1Hdl
;
157 Link
<LinkParamNone
*,void> m_aModify2Hdl
;
160 void CallModifyHdls()
162 m_aModify1Hdl
.Call(nullptr);
163 m_aModify2Hdl
.Call(nullptr);
167 class SVT_DLLPUBLIC ControlBase
: public InterimItemWindow
170 ControlBase(BrowserDataWin
* pParent
, const OUString
& rUIXMLDescription
, const OUString
& rID
);
172 virtual void SetEditableReadOnly(bool bReadOnly
);
174 virtual bool ProcessKey(const KeyEvent
& rKEvt
);
176 virtual void SetPointFont(const vcl::Font
& rFont
) = 0;
178 // chain after the FocusInHdl
179 void SetFocusInHdl(const Link
<LinkParamNone
*,void>& rHdl
)
181 m_aFocusInHdl
= rHdl
;
184 // chain after the FocusOutHdl
185 void SetFocusOutHdl(const Link
<LinkParamNone
*,void>& rHdl
)
187 m_aFocusOutHdl
= rHdl
;
190 void SetMousePressHdl(const Link
<const MouseEvent
&,void>& rHdl
)
192 m_aMousePressHdl
= rHdl
;
195 void SetMouseReleaseHdl(const Link
<const MouseEvent
&,void>& rHdl
)
197 m_aMouseReleaseHdl
= rHdl
;
200 void SetMouseMoveHdl(const Link
<const MouseEvent
&,void>& rHdl
)
202 m_aMouseMoveHdl
= rHdl
;
205 void SetKeyInputHdl(const Link
<const KeyEvent
&,void>& rHdl
)
207 m_aKeyInputHdl
= rHdl
;
210 void SetKeyReleaseHdl(const Link
<const KeyEvent
&,void>& rHdl
)
212 m_aKeyReleaseHdl
= rHdl
;
216 DECL_DLLPRIVATE_LINK(KeyInputHdl
, const KeyEvent
&, bool);
217 DECL_DLLPRIVATE_LINK(KeyReleaseHdl
, const KeyEvent
&, bool);
218 DECL_DLLPRIVATE_LINK(FocusInHdl
, weld::Widget
&, void);
219 DECL_DLLPRIVATE_LINK(FocusOutHdl
, weld::Widget
&, void);
220 DECL_DLLPRIVATE_LINK(MousePressHdl
, const MouseEvent
&, bool);
221 DECL_DLLPRIVATE_LINK(MouseReleaseHdl
, const MouseEvent
&, bool);
222 DECL_DLLPRIVATE_LINK(MouseMoveHdl
, const MouseEvent
&, bool);
224 Link
<LinkParamNone
*,void> m_aFocusInHdl
;
225 Link
<LinkParamNone
*,void> m_aFocusOutHdl
;
226 Link
<const MouseEvent
&,void> m_aMousePressHdl
;
227 Link
<const MouseEvent
&,void> m_aMouseReleaseHdl
;
228 Link
<const MouseEvent
&,void> m_aMouseMoveHdl
;
229 Link
<const KeyEvent
&,void> m_aKeyInputHdl
;
230 Link
<const KeyEvent
&,void> m_aKeyReleaseHdl
;
233 class SVT_DLLPUBLIC EditControlBase
: public ControlBase
236 EditControlBase(BrowserDataWin
* pParent
);
238 virtual void SetEditableReadOnly(bool bReadOnly
) override
240 m_pEntry
->set_editable(!bReadOnly
);
243 virtual void SetPointFont(const vcl::Font
& rFont
) override
245 m_pEntry
->set_font(rFont
);
248 virtual void dispose() override
;
250 weld::Entry
& get_widget() { return *m_pEntry
; }
252 virtual void connect_changed(const Link
<weld::Entry
&, void>& rLink
) = 0;
253 virtual void connect_focus_in(const Link
<weld::Widget
&, void>& rLink
) = 0;
254 virtual void connect_focus_out(const Link
<weld::Widget
&, void>& rLink
) = 0;
255 virtual void connect_key_press(const Link
<const KeyEvent
&, bool>& rLink
) = 0;
258 void InitEditControlBase(weld::Entry
* pEntry
);
261 weld::Entry
* m_pEntry
;
264 class SVT_DLLPUBLIC EditControl
: public EditControlBase
267 EditControl(BrowserDataWin
* pParent
);
269 virtual void dispose() override
;
271 virtual void connect_changed(const Link
<weld::Entry
&, void>& rLink
) override
273 m_xWidget
->connect_changed(rLink
);
276 virtual void connect_focus_in(const Link
<weld::Widget
&, void>& rLink
) override
278 m_xWidget
->connect_focus_in(rLink
);
281 virtual void connect_focus_out(const Link
<weld::Widget
&, void>& rLink
) override
283 m_xWidget
->connect_focus_out(rLink
);
286 virtual void connect_key_press(const Link
<const KeyEvent
&, bool>& rLink
) override
288 m_xWidget
->connect_key_press(rLink
);
292 std::unique_ptr
<weld::Entry
> m_xWidget
;
295 class SVT_DLLPUBLIC EntryImplementation final
: public IEditImplementation
297 EditControlBase
& m_rEdit
;
300 DECL_LINK(ModifyHdl
, weld::Entry
&, void);
302 EntryImplementation(EditControlBase
& rEdit
)
306 m_rEdit
.connect_changed(LINK(this, EntryImplementation
, ModifyHdl
));
309 virtual ControlBase
& GetControl() override
314 virtual OUString
GetText( LineEnd
/*aSeparator*/ ) const override
316 // ignore the line end - this base implementation does not support it
317 return m_rEdit
.get_widget().get_text();
320 virtual void SetText( const OUString
& _rStr
) override
322 return m_rEdit
.get_widget().set_text(_rStr
);
325 virtual bool IsReadOnly() const override
327 return !m_rEdit
.get_widget().get_editable();
330 virtual void SetReadOnly( bool bReadOnly
) override
332 m_rEdit
.SetEditableReadOnly(bReadOnly
);
335 virtual sal_Int32
GetMaxTextLen() const override
337 return m_nMaxTextLen
;
340 virtual void SetMaxTextLen( sal_Int32 nMaxLen
) override
342 m_nMaxTextLen
= nMaxLen
;
343 m_rEdit
.get_widget().set_max_length(m_nMaxTextLen
);
346 virtual Selection
GetSelection() const override
348 int nStartPos
, nEndPos
;
349 m_rEdit
.get_widget().get_selection_bounds(nStartPos
, nEndPos
);
350 return Selection(nStartPos
, nEndPos
);
353 virtual void SetSelection( const Selection
& rSelection
) override
355 auto nMin
= rSelection
.Min();
356 auto nMax
= rSelection
.Max();
357 m_rEdit
.get_widget().select_region(nMin
< 0 ? 0 : nMin
, nMax
== SELECTION_MAX
? -1 : nMax
);
360 virtual void ReplaceSelected( const OUString
& rStr
) override
362 m_rEdit
.get_widget().replace_selection(rStr
);
365 virtual OUString
GetSelected( LineEnd
/*aSeparator*/ ) const override
366 // ignore the line end - this base implementation does not support it
368 int nStartPos
, nEndPos
;
369 weld::Entry
& rEntry
= m_rEdit
.get_widget();
370 rEntry
.get_selection_bounds(nStartPos
, nEndPos
);
371 return rEntry
.get_text().copy(std::min(nStartPos
, nEndPos
), std::abs(nEndPos
- nStartPos
));
374 virtual bool IsValueChangedFromSaved() const override
376 return m_rEdit
.get_widget().get_value_changed_from_saved();
379 virtual void SaveValue() override
381 m_rEdit
.get_widget().save_value();
384 virtual bool CanUp() const override
389 virtual bool CanDown() const override
394 virtual void Cut() override
396 m_rEdit
.get_widget().cut_clipboard();
399 virtual void Copy() override
401 m_rEdit
.get_widget().copy_clipboard();
404 virtual void Paste() override
406 m_rEdit
.get_widget().paste_clipboard();
410 //= MultiLineTextCell
412 /** a multi line edit which can be used in a cell of an EditBrowseBox
414 class SVT_DLLPUBLIC MultiLineTextCell final
: public ControlBase
417 MultiLineTextCell(BrowserDataWin
* pParent
);
419 virtual void SetEditableReadOnly(bool bReadOnly
) override
421 m_xWidget
->set_editable(!bReadOnly
);
424 virtual void SetPointFont(const vcl::Font
& rFont
) override
426 m_xWidget
->set_font(rFont
);
429 virtual void GetFocus() override
;
431 virtual void dispose() override
;
433 void connect_changed(const Link
<weld::TextView
&, void>& rLink
)
435 m_xWidget
->connect_changed(rLink
);
438 weld::TextView
& get_widget() { return *m_xWidget
; }
441 std::unique_ptr
<weld::TextView
> m_xWidget
;
443 virtual bool ProcessKey(const KeyEvent
& rKEvt
) override
;
446 class SVT_DLLPUBLIC MultiLineEditImplementation final
: public IEditImplementation
448 MultiLineTextCell
& m_rEdit
;
451 DECL_LINK(ModifyHdl
, weld::TextView
&, void);
453 MultiLineEditImplementation(MultiLineTextCell
& rEdit
)
457 m_rEdit
.connect_changed(LINK(this, MultiLineEditImplementation
, ModifyHdl
));
460 virtual ControlBase
& GetControl() override
465 virtual OUString
GetText(LineEnd aSeparator
) const override
;
467 virtual void SetText(const OUString
& rStr
) override
469 return m_rEdit
.get_widget().set_text(rStr
);
472 virtual bool IsReadOnly() const override
474 return !m_rEdit
.get_widget().get_editable();
477 virtual void SetReadOnly( bool bReadOnly
) override
479 m_rEdit
.SetEditableReadOnly(bReadOnly
);
482 virtual sal_Int32
GetMaxTextLen() const override
484 return m_nMaxTextLen
;
487 virtual void SetMaxTextLen( sal_Int32 nMaxLen
) override
489 m_nMaxTextLen
= nMaxLen
;
490 m_rEdit
.get_widget().set_max_length(m_nMaxTextLen
);
493 virtual Selection
GetSelection() const override
495 int nStartPos
, nEndPos
;
496 m_rEdit
.get_widget().get_selection_bounds(nStartPos
, nEndPos
);
497 return Selection(nStartPos
, nEndPos
);
500 virtual void SetSelection( const Selection
& rSelection
) override
502 auto nMin
= rSelection
.Min();
503 auto nMax
= rSelection
.Max();
504 m_rEdit
.get_widget().select_region(nMin
< 0 ? 0 : nMin
, nMax
== SELECTION_MAX
? -1 : nMax
);
507 virtual void ReplaceSelected( const OUString
& rStr
) override
509 m_rEdit
.get_widget().replace_selection(rStr
);
512 virtual OUString
GetSelected( LineEnd aSeparator
) const override
;
514 virtual bool IsValueChangedFromSaved() const override
516 return m_rEdit
.get_widget().get_value_changed_from_saved();
519 virtual void SaveValue() override
521 m_rEdit
.get_widget().save_value();
524 virtual bool CanUp() const override
526 return m_rEdit
.get_widget().can_move_cursor_with_up();
529 virtual bool CanDown() const override
531 return m_rEdit
.get_widget().can_move_cursor_with_down();
534 virtual void Cut() override
536 m_rEdit
.get_widget().cut_clipboard();
539 virtual void Copy() override
541 m_rEdit
.get_widget().copy_clipboard();
544 virtual void Paste() override
546 m_rEdit
.get_widget().paste_clipboard();
551 //= EditCellController
552 class SVT_DLLPUBLIC EditCellController
: public CellController
554 IEditImplementation
* m_pEditImplementation
;
555 bool m_bOwnImplementation
; // did we create m_pEditImplementation?
558 EditCellController( EditControlBase
* _pEdit
);
559 EditCellController( IEditImplementation
* _pImplementation
);
560 virtual ~EditCellController( ) override
;
562 const IEditImplementation
* GetEditImplementation( ) const { return m_pEditImplementation
; }
563 IEditImplementation
* GetEditImplementation( ) { return m_pEditImplementation
; }
565 virtual bool IsValueChangedFromSaved() const override
;
566 virtual void SaveValue() override
;
574 virtual bool MoveAllowed(const KeyEvent
& rEvt
) const override
;
576 DECL_LINK(ModifyHdl
, LinkParamNone
*, void);
580 class SVT_DLLPUBLIC CheckBoxControl final
: public ControlBase
582 std::unique_ptr
<weld::CheckButton
> m_xBox
;
583 weld::TriStateEnabled m_aModeState
;
584 Link
<weld::CheckButton
&,void> m_aToggleLink
;
585 Link
<LinkParamNone
*,void> m_aModify1Hdl
;
586 Link
<LinkParamNone
*,void> m_aModify2Hdl
;
589 CheckBoxControl(BrowserDataWin
* pParent
);
590 virtual ~CheckBoxControl() override
;
591 virtual void dispose() override
;
593 virtual void SetPointFont(const vcl::Font
& rFont
) override
;
595 void SetToggleHdl(const Link
<weld::CheckButton
&,void>& rHdl
) {m_aToggleLink
= rHdl
;}
597 // sets a link to call when the text is changed by the user
598 void SetModifyHdl(const Link
<LinkParamNone
*,void>& rHdl
)
600 m_aModify1Hdl
= rHdl
;
603 // sets an additional link to call when the text is changed by the user
604 void SetAuxModifyHdl(const Link
<LinkParamNone
*,void>& rLink
)
606 m_aModify2Hdl
= rLink
;
609 void SetState(TriState eState
);
610 TriState
GetState() const { return m_xBox
->get_state(); }
612 void EnableTriState(bool bTriState
);
614 weld::CheckButton
& GetBox() {return *m_xBox
;};
616 // for pseudo-click when initially clicking in a cell activates
617 // the cell and performs a state change on the button as if
622 DECL_DLLPRIVATE_LINK(OnToggle
, weld::Toggleable
&, void);
624 void CallModifyHdls()
626 m_aModify1Hdl
.Call(nullptr);
627 m_aModify2Hdl
.Call(nullptr);
631 //= CheckBoxCellController
632 class SVT_DLLPUBLIC CheckBoxCellController final
: public CellController
636 CheckBoxCellController(CheckBoxControl
* pWin
);
637 weld::CheckButton
& GetCheckBox() const;
639 virtual bool IsValueChangedFromSaved() const override
;
640 virtual void SaveValue() override
;
643 virtual void ActivatingMouseEvent(const BrowserMouseEvent
& rEvt
, bool bUp
) override
;
644 DECL_DLLPRIVATE_LINK(ModifyHdl
, LinkParamNone
*, void);
648 class SVT_DLLPUBLIC ComboBoxControl final
: public ControlBase
651 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
652 Link
<LinkParamNone
*,void> m_aModify1Hdl
;
653 Link
<bool,void> m_aModify2Hdl
;
655 friend class ComboBoxCellController
;
658 ComboBoxControl(BrowserDataWin
* pParent
);
660 virtual void SetPointFont(const vcl::Font
& rFont
) override
;
662 virtual void SetEditableReadOnly(bool bReadOnly
) override
664 m_xWidget
->set_entry_editable(!bReadOnly
);
667 weld::ComboBox
& get_widget() { return *m_xWidget
; }
669 // sets a link to call when the selection is changed by the user
670 void SetModifyHdl(const Link
<LinkParamNone
*,void>& rHdl
)
672 m_aModify1Hdl
= rHdl
;
675 // sets an additional link to call when the selection is changed by the user
676 // bool arg is true when triggered interactively by the user
677 void SetAuxModifyHdl(const Link
<bool,void>& rLink
)
679 m_aModify2Hdl
= rLink
;
682 void TriggerAuxModify()
684 m_aModify2Hdl
.Call(false);
687 virtual void dispose() override
;
690 DECL_DLLPRIVATE_LINK(SelectHdl
, weld::ComboBox
&, void);
692 void CallModifyHdls()
694 m_aModify1Hdl
.Call(nullptr);
695 m_aModify2Hdl
.Call(true);
699 //= ComboBoxCellController
700 class SVT_DLLPUBLIC ComboBoxCellController final
: public CellController
704 ComboBoxCellController(ComboBoxControl
* pParent
);
705 weld::ComboBox
& GetComboBox() const { return static_cast<ComboBoxControl
&>(GetWindow()).get_widget(); }
707 virtual bool IsValueChangedFromSaved() const override
;
708 virtual void SaveValue() override
;
711 virtual bool MoveAllowed(const KeyEvent
& rEvt
) const override
;
712 DECL_DLLPRIVATE_LINK(ModifyHdl
, LinkParamNone
*, void);
716 class SVT_DLLPUBLIC ListBoxControl final
: public ControlBase
719 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
720 Link
<LinkParamNone
*,void> m_aModify1Hdl
;
721 Link
<bool,void> m_aModify2Hdl
;
723 friend class ListBoxCellController
;
726 ListBoxControl(BrowserDataWin
* pParent
);
728 virtual void SetPointFont(const vcl::Font
& rFont
) override
;
730 weld::ComboBox
& get_widget() { return *m_xWidget
; }
732 // sets a link to call when the selection is changed by the user
733 void SetModifyHdl(const Link
<LinkParamNone
*,void>& rHdl
)
735 m_aModify1Hdl
= rHdl
;
738 // sets an additional link to call when the selection is changed,
739 // bool arg is true when triggered interactively by the user
740 void SetAuxModifyHdl(const Link
<bool,void>& rLink
)
742 m_aModify2Hdl
= rLink
;
745 void TriggerAuxModify()
747 m_aModify2Hdl
.Call(false);
750 virtual void dispose() override
;
752 DECL_DLLPRIVATE_LINK(SelectHdl
, weld::ComboBox
&, void);
754 void CallModifyHdls()
756 m_aModify1Hdl
.Call(nullptr);
757 m_aModify2Hdl
.Call(true);
761 //= ListBoxCellController
762 class SVT_DLLPUBLIC ListBoxCellController
: public CellController
766 ListBoxCellController(ListBoxControl
* pParent
);
767 weld::ComboBox
& GetListBox() const { return static_cast<ListBoxControl
&>(GetWindow()).get_widget(); }
769 virtual bool IsValueChangedFromSaved() const override
;
770 virtual void SaveValue() override
;
773 virtual bool MoveAllowed(const KeyEvent
& rEvt
) const override
;
775 DECL_DLLPRIVATE_LINK(ListBoxSelectHdl
, LinkParamNone
*, void);
778 class SVT_DLLPUBLIC FormattedControlBase
: public EditControlBase
781 FormattedControlBase(BrowserDataWin
* pParent
, bool bSpinVariant
);
783 virtual void dispose() override
;
785 virtual void connect_changed(const Link
<weld::Entry
&, void>& rLink
) override
;
786 virtual void connect_focus_in(const Link
<weld::Widget
&, void>& rLink
) override
;
787 virtual void connect_focus_out(const Link
<weld::Widget
&, void>& rLink
) override
;
788 virtual void connect_key_press(const Link
<const KeyEvent
&, bool>& rLink
) override
;
790 weld::EntryFormatter
& get_formatter();
794 std::unique_ptr
<weld::Entry
> m_xEntry
;
795 std::unique_ptr
<weld::FormattedSpinButton
> m_xSpinButton
;
796 std::unique_ptr
<weld::EntryFormatter
> m_xEntryFormatter
;
798 void InitFormattedControlBase();
801 class SVT_DLLPUBLIC FormattedControl final
: public FormattedControlBase
804 FormattedControl(BrowserDataWin
* pParent
, bool bSpinVariant
);
807 class SVT_DLLPUBLIC DoubleNumericControl final
: public FormattedControlBase
810 DoubleNumericControl(BrowserDataWin
* pParent
, bool bSpinVariant
);
813 class SVT_DLLPUBLIC LongCurrencyControl final
: public FormattedControlBase
816 LongCurrencyControl(BrowserDataWin
* pParent
, bool bSpinVariant
);
819 class SVT_DLLPUBLIC TimeControl final
: public FormattedControlBase
822 TimeControl(BrowserDataWin
* pParent
, bool bSpinVariant
);
825 class SVT_DLLPUBLIC DateControl final
: public FormattedControlBase
828 DateControl(BrowserDataWin
* pParent
, bool bDropDown
);
830 void SetDate(const Date
& rDate
);
832 virtual void SetEditableReadOnly(bool bReadOnly
) override
;
834 virtual void dispose() override
;
836 std::unique_ptr
<weld::MenuButton
> m_xMenuButton
;
837 std::unique_ptr
<weld::Builder
> m_xCalendarBuilder
;
838 std::unique_ptr
<weld::Widget
> m_xTopLevel
;
839 std::unique_ptr
<weld::Calendar
> m_xCalendar
;
840 std::unique_ptr
<weld::Widget
> m_xExtras
;
841 std::unique_ptr
<weld::Button
> m_xTodayBtn
;
842 std::unique_ptr
<weld::Button
> m_xNoneBtn
;
844 DECL_DLLPRIVATE_LINK(ToggleHdl
, weld::Toggleable
&, void);
845 DECL_DLLPRIVATE_LINK(ActivateHdl
, weld::Calendar
&, void);
846 DECL_DLLPRIVATE_LINK(ImplClickHdl
, weld::Button
&, void);
849 class SVT_DLLPUBLIC PatternControl final
: public EditControlBase
852 PatternControl(BrowserDataWin
* pParent
);
854 weld::PatternFormatter
& get_formatter() { return *m_xEntryFormatter
; }
856 virtual void connect_changed(const Link
<weld::Entry
&, void>& rLink
) override
;
857 virtual void connect_focus_in(const Link
<weld::Widget
&, void>& rLink
) override
;
858 virtual void connect_focus_out(const Link
<weld::Widget
&, void>& rLink
) override
;
859 virtual void connect_key_press(const Link
<const KeyEvent
&, bool>& rLink
) override
;
861 virtual void dispose() override
;
863 std::unique_ptr
<weld::Entry
> m_xWidget
;
864 std::unique_ptr
<weld::PatternFormatter
> m_xEntryFormatter
;
867 //= FormattedFieldCellController
868 class SVT_DLLPUBLIC FormattedFieldCellController final
: public EditCellController
871 FormattedFieldCellController( FormattedControlBase
* _pFormatted
);
873 virtual void CommitModifications() override
;
876 //= EditBrowserHeader
877 class SVT_DLLPUBLIC EditBrowserHeader
: public BrowserHeader
880 EditBrowserHeader( BrowseBox
* pParent
, WinBits nWinBits
= WB_BUTTONSTYLE
)
881 :BrowserHeader(pParent
, nWinBits
){}
884 virtual void DoubleClick() override
;
889 class EditBrowseBoxImpl
;
890 class SVT_DLLPUBLIC EditBrowseBox
: public BrowseBox
892 friend class EditBrowserHeader
;
912 CURRENT_PRIMARYKEY
= 7,
918 EditBrowseBox(EditBrowseBox
const &) = delete;
919 EditBrowseBox
& operator=(EditBrowseBox
const &) = delete;
921 class SAL_DLLPRIVATE BrowserMouseEventPtr
923 std::unique_ptr
<BrowserMouseEvent
> pEvent
;
927 BrowserMouseEventPtr()
932 bool Is() const {return pEvent
!= nullptr;}
933 bool IsDown() const {return bDown
;}
934 const BrowserMouseEvent
* operator->() const {return pEvent
.get();}
936 SVT_DLLPUBLIC
void Clear();
937 void Set(const BrowserMouseEvent
* pEvt
, bool bIsDown
);
940 CellControllerRef aController
,
943 ImplSVEvent
* nStartEvent
, * nEndEvent
, * nCellModifiedEvent
; // event ids
944 VclPtr
<vcl::Window
> m_pFocusWhileRequest
;
945 // In ActivateCell, we grab the focus asynchronously, but if between requesting activation
946 // and the asynchronous event the focus has changed, we won't grab it for ourself.
948 sal_Int32 nPaintRow
; // row being painted
953 mutable bool bPaintStatus
: 1; // paint a status (image) in the handle column
954 bool bActiveBeforeTracking
;
956 VclPtr
<CheckBoxControl
> pCheckBoxPaint
;
958 EditBrowseBoxFlags m_nBrowserFlags
;
959 std::unique_ptr
< EditBrowseBoxImpl
> m_aImpl
;
962 VclPtr
<BrowserHeader
> pHeader
;
964 BrowserMouseEventPtr
& getMouseEvent() { return aMouseEvent
; }
967 BrowserHeader
* GetHeaderBar() const {return pHeader
;}
969 virtual VclPtr
<BrowserHeader
> CreateHeaderBar(BrowseBox
* pParent
) override
;
971 // if you want to have an own header ...
972 virtual VclPtr
<BrowserHeader
> imp_CreateHeaderBar(BrowseBox
* pParent
);
974 virtual void ColumnMoved(sal_uInt16 nId
) override
;
975 virtual void ColumnResized(sal_uInt16 nColId
) override
;
976 virtual void Resize() override
;
977 virtual void ArrangeControls(sal_uInt16
& nX
, sal_uInt16 nY
);
978 virtual bool SeekRow(sal_Int32 nRow
) override
;
980 virtual void GetFocus() override
;
981 virtual void LoseFocus() override
;
982 virtual void KeyInput(const KeyEvent
& rEvt
) override
;
983 virtual void MouseButtonDown(const BrowserMouseEvent
& rEvt
) override
;
984 virtual void MouseButtonUp(const BrowserMouseEvent
& rEvt
) override
;
985 virtual void StateChanged( StateChangedType nType
) override
;
986 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
988 using BrowseBox::MouseButtonUp
;
989 using BrowseBox::MouseButtonDown
;
991 virtual bool PreNotify(NotifyEvent
& rNEvt
) override
;
992 virtual bool EventNotify(NotifyEvent
& rNEvt
) override
;
994 virtual void EndScroll() override
;
996 // should be used instead of GetFieldRectPixel, 'cause this method here takes into account the borders
997 tools::Rectangle
GetCellRect(sal_Int32 nRow
, sal_uInt16 nColId
, bool bRelToBrowser
= true) const;
998 virtual sal_uInt32
GetTotalCellWidth(sal_Int32 nRow
, sal_uInt16 nColId
);
999 sal_uInt32
GetAutoColumnWidth(sal_uInt16 nColId
);
1001 virtual void PaintStatusCell(OutputDevice
& rDev
, const tools::Rectangle
& rRect
) const;
1002 virtual void PaintCell(OutputDevice
& rDev
, const tools::Rectangle
& rRect
, sal_uInt16 nColId
) const = 0;
1004 virtual RowStatus
GetRowStatus(sal_Int32 nRow
) const;
1006 virtual void RowHeightChanged() override
;
1008 // callbacks for the data window
1009 virtual void ImplStartTracking() override
;
1010 virtual void ImplEndTracking() override
;
1012 // when changing a row:
1013 // CursorMoving: cursor is being moved, but GetCurRow() still provides the old row
1014 virtual bool CursorMoving(sal_Int32 nNewRow
, sal_uInt16 nNewCol
);
1016 // cursor has been moved
1017 virtual void CursorMoved() override
;
1019 virtual void CellModified(); // called whenever a cell has been modified
1020 virtual bool SaveModified(); // called whenever a cell should be left, and it's content should be saved
1021 // return sal_False prevents leaving the cell
1022 virtual bool SaveRow(); // commit the current row
1024 virtual bool IsModified() const {return aController
.is() && aController
->IsValueChangedFromSaved();}
1026 virtual CellController
* GetController(sal_Int32 nRow
, sal_uInt16 nCol
);
1027 virtual void InitController(CellControllerRef
& rController
, sal_Int32 nRow
, sal_uInt16 nCol
);
1028 static void ResizeController(CellControllerRef
const & rController
, const tools::Rectangle
&);
1029 virtual void DoubleClick(const BrowserMouseEvent
&) override
;
1031 void ActivateCell() { ActivateCell(GetCurRow(), GetCurColumnId()); }
1033 // retrieve the image for the row status
1034 Image
GetImage(RowStatus
) const;
1036 // inserting columns
1037 // if you don't set a width, this will be calculated automatically
1038 // if the id isn't set the smallest unused will do it ...
1039 virtual sal_uInt16
AppendColumn(const OUString
& rName
, sal_uInt16 nWidth
, sal_uInt16 nPos
= HEADERBAR_APPEND
, sal_uInt16 nId
= sal_uInt16(-1));
1041 // called whenever (Shift)Tab or Enter is pressed. If true is returned, these keys
1042 // result in traveling to the next or to th previous cell
1043 virtual bool IsTabAllowed(bool bForward
) const;
1045 virtual bool IsCursorMoveAllowed(sal_Int32 nNewRow
, sal_uInt16 nNewColId
) const override
;
1047 void PaintTristate(const tools::Rectangle
& rRect
, const TriState
& eState
, bool _bEnabled
=true) const;
1049 void AsynchGetFocus();
1050 // secure starting of StartEditHdl
1053 EditBrowseBox(vcl::Window
* pParent
, EditBrowseBoxFlags nBrowserFlags
, WinBits nBits
, BrowserMode nMode
= BrowserMode::NONE
);
1054 virtual ~EditBrowseBox() override
;
1055 virtual void dispose() override
;
1057 bool IsEditing() const {return aController
.is();}
1058 void InvalidateStatusCell(sal_Int32 nRow
) {RowModified(nRow
, 0);}
1059 void InvalidateHandleColumn();
1061 // late construction
1062 virtual void Init();
1063 virtual void RemoveRows();
1064 virtual void Dispatch(sal_uInt16 nId
);
1066 const CellControllerRef
& Controller() const { return aController
; }
1067 EditBrowseBoxFlags
GetBrowserFlags() const { return m_nBrowserFlags
; }
1068 void SetBrowserFlags(EditBrowseBoxFlags nFlags
);
1070 virtual void ActivateCell(sal_Int32 nRow
, sal_uInt16 nCol
, bool bSetCellFocus
= true);
1071 virtual void DeactivateCell(bool bUpdate
= true);
1072 // Children ---------------------------------------------------------------
1074 /** @return The count of additional controls of the control area. */
1075 virtual sal_Int32
GetAccessibleControlCount() const override
;
1077 /** Creates the accessible object of an additional control.
1079 The 0-based index of the control.
1081 The XAccessible interface of the specified control. */
1082 virtual css::uno::Reference
< css::accessibility::XAccessible
>
1083 CreateAccessibleControl( sal_Int32 nIndex
) override
;
1085 /** Sets focus to current cell of the data table. */
1086 virtual void GrabTableFocus() override
;
1088 virtual tools::Rectangle
GetFieldCharacterBounds(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,sal_Int32 nIndex
) override
;
1089 virtual sal_Int32
GetFieldIndexAtPoint(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,const Point
& _rPoint
) override
;
1091 virtual bool ProcessKey(const KeyEvent
& rEvt
) override
;
1093 virtual void ChildFocusIn() override
;
1094 virtual void ChildFocusOut() override
;
1096 css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessibleCheckBoxCell(sal_Int32 _nRow
, sal_uInt16 _nColumnPos
,const TriState
& eState
);
1097 bool ControlHasFocus() const;
1099 // creates the accessible which wraps the active cell
1100 void implCreateActiveAccessible( );
1103 virtual void PaintField(vcl::RenderContext
& rDev
, const tools::Rectangle
& rRect
,
1104 sal_uInt16 nColumnId
) const override
;
1105 using Control::ImplInitSettings
;
1106 SVT_DLLPRIVATE
void ImplInitSettings( bool bFont
, bool bForeground
, bool bBackground
);
1107 SVT_DLLPRIVATE
void DetermineFocus( const GetFocusFlags _nGetFocusFlags
= GetFocusFlags::NONE
);
1108 inline void EnableAndShow() const;
1110 SVT_DLLPRIVATE
void implActivateCellOnMouseEvent(const BrowserMouseEvent
& _rEvt
, bool _bUp
);
1112 DECL_DLLPRIVATE_LINK( ModifyHdl
, LinkParamNone
*, void );
1113 DECL_DLLPRIVATE_LINK( StartEditHdl
, void*, void );
1114 DECL_DLLPRIVATE_LINK( EndEditHdl
, void*, void );
1115 DECL_DLLPRIVATE_LINK( CellModifiedHdl
, void*, void );
1121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */