Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / svtools / editbrowsebox.hxx
blobc89a396a9dc7c6b1bfae40d382547574490c7dcd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <memory>
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>
33 class BrowserDataWin;
35 // EditBrowseBoxFlags (EBBF)
36 enum class EditBrowseBoxFlags
38 NONE = 0x0000,
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)
56 gets activated.
57 @see Window::GetGetFocusFlags
58 @see GETFOCUS_*
60 SMART_TAB_TRAVEL = 0x0008,
63 namespace o3tl
65 template<> struct typed_flags<EditBrowseBoxFlags> : is_typed_flags<EditBrowseBoxFlags, 0x0f> {};
68 namespace svt
70 class ControlBase;
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
80 public:
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!
95 void suspend( );
96 void resume( );
97 bool isSuspended( ) const { return bSuspended; }
99 protected:
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
113 public:
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;
155 private:
156 Link<LinkParamNone*,void> m_aModify1Hdl;
157 Link<LinkParamNone*,void> m_aModify2Hdl;
159 protected:
160 void CallModifyHdls()
162 m_aModify1Hdl.Call(nullptr);
163 m_aModify2Hdl.Call(nullptr);
167 class SVT_DLLPUBLIC ControlBase : public InterimItemWindow
169 public:
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;
215 protected:
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);
223 private:
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
235 public:
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;
257 protected:
258 void InitEditControlBase(weld::Entry* pEntry);
260 private:
261 weld::Entry* m_pEntry;
264 class SVT_DLLPUBLIC EditControl : public EditControlBase
266 public:
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);
291 protected:
292 std::unique_ptr<weld::Entry> m_xWidget;
295 class SVT_DLLPUBLIC EntryImplementation final : public IEditImplementation
297 EditControlBase& m_rEdit;
298 int m_nMaxTextLen;
300 DECL_LINK(ModifyHdl, weld::Entry&, void);
301 public:
302 EntryImplementation(EditControlBase& rEdit)
303 : m_rEdit(rEdit)
304 , m_nMaxTextLen(0)
306 m_rEdit.connect_changed(LINK(this, EntryImplementation, ModifyHdl));
309 virtual ControlBase& GetControl() override
311 return m_rEdit;
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
386 return false;
389 virtual bool CanDown() const override
391 return false;
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
416 public:
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; }
440 private:
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;
449 int m_nMaxTextLen;
451 DECL_LINK(ModifyHdl, weld::TextView&, void);
452 public:
453 MultiLineEditImplementation(MultiLineTextCell& rEdit)
454 : m_rEdit(rEdit)
455 , m_nMaxTextLen(0)
457 m_rEdit.connect_changed(LINK(this, MultiLineEditImplementation, ModifyHdl));
460 virtual ControlBase& GetControl() override
462 return m_rEdit;
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?
557 public:
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;
568 void Modify()
570 ModifyHdl(nullptr);
573 protected:
574 virtual bool MoveAllowed(const KeyEvent& rEvt) const override;
575 private:
576 DECL_LINK(ModifyHdl, LinkParamNone*, void);
579 //= CheckBoxControl
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;
588 public:
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
618 // it was clicked on
619 void Clicked();
621 private:
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
634 public:
636 CheckBoxCellController(CheckBoxControl* pWin);
637 weld::CheckButton& GetCheckBox() const;
639 virtual bool IsValueChangedFromSaved() const override;
640 virtual void SaveValue() override;
642 private:
643 virtual void ActivatingMouseEvent(const BrowserMouseEvent& rEvt, bool bUp) override;
644 DECL_DLLPRIVATE_LINK(ModifyHdl, LinkParamNone*, void);
647 //= ComboBoxControl
648 class SVT_DLLPUBLIC ComboBoxControl final : public ControlBase
650 private:
651 std::unique_ptr<weld::ComboBox> m_xWidget;
652 Link<LinkParamNone*,void> m_aModify1Hdl;
653 Link<bool,void> m_aModify2Hdl;
655 friend class ComboBoxCellController;
657 public:
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;
689 private:
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
702 public:
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;
710 private:
711 virtual bool MoveAllowed(const KeyEvent& rEvt) const override;
712 DECL_DLLPRIVATE_LINK(ModifyHdl, LinkParamNone*, void);
715 //= ListBoxControl
716 class SVT_DLLPUBLIC ListBoxControl final : public ControlBase
718 private:
719 std::unique_ptr<weld::ComboBox> m_xWidget;
720 Link<LinkParamNone*,void> m_aModify1Hdl;
721 Link<bool,void> m_aModify2Hdl;
723 friend class ListBoxCellController;
725 public:
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;
751 private:
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
764 public:
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;
772 protected:
773 virtual bool MoveAllowed(const KeyEvent& rEvt) const override;
774 private:
775 DECL_DLLPRIVATE_LINK(ListBoxSelectHdl, LinkParamNone*, void);
778 class SVT_DLLPUBLIC FormattedControlBase : public EditControlBase
780 public:
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();
792 protected:
793 bool m_bSpinVariant;
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
803 public:
804 FormattedControl(BrowserDataWin* pParent, bool bSpinVariant);
807 class SVT_DLLPUBLIC DoubleNumericControl final : public FormattedControlBase
809 public:
810 DoubleNumericControl(BrowserDataWin* pParent, bool bSpinVariant);
813 class SVT_DLLPUBLIC LongCurrencyControl final : public FormattedControlBase
815 public:
816 LongCurrencyControl(BrowserDataWin* pParent, bool bSpinVariant);
819 class SVT_DLLPUBLIC TimeControl final : public FormattedControlBase
821 public:
822 TimeControl(BrowserDataWin* pParent, bool bSpinVariant);
825 class SVT_DLLPUBLIC DateControl final : public FormattedControlBase
827 public:
828 DateControl(BrowserDataWin* pParent, bool bDropDown);
830 void SetDate(const Date& rDate);
832 virtual void dispose() override;
833 private:
834 std::unique_ptr<weld::MenuButton> m_xMenuButton;
835 std::unique_ptr<weld::Builder> m_xCalendarBuilder;
836 std::unique_ptr<weld::Widget> m_xTopLevel;
837 std::unique_ptr<weld::Calendar> m_xCalendar;
838 std::unique_ptr<weld::Widget> m_xExtras;
839 std::unique_ptr<weld::Button> m_xTodayBtn;
840 std::unique_ptr<weld::Button> m_xNoneBtn;
842 DECL_DLLPRIVATE_LINK(ToggleHdl, weld::Toggleable&, void);
843 DECL_DLLPRIVATE_LINK(ActivateHdl, weld::Calendar&, void);
844 DECL_DLLPRIVATE_LINK(ImplClickHdl, weld::Button&, void);
847 class SVT_DLLPUBLIC PatternControl final : public EditControlBase
849 public:
850 PatternControl(BrowserDataWin* pParent);
852 weld::PatternFormatter& get_formatter() { return *m_xEntryFormatter; }
854 virtual void connect_changed(const Link<weld::Entry&, void>& rLink) override;
855 virtual void connect_focus_in(const Link<weld::Widget&, void>& rLink) override;
856 virtual void connect_focus_out(const Link<weld::Widget&, void>& rLink) override;
857 virtual void connect_key_press(const Link<const KeyEvent&, bool>& rLink) override;
859 virtual void dispose() override;
860 private:
861 std::unique_ptr<weld::Entry> m_xWidget;
862 std::unique_ptr<weld::PatternFormatter> m_xEntryFormatter;
865 //= FormattedFieldCellController
866 class SVT_DLLPUBLIC FormattedFieldCellController final : public EditCellController
868 public:
869 FormattedFieldCellController( FormattedControlBase* _pFormatted );
871 virtual void CommitModifications() override;
874 //= EditBrowserHeader
875 class SVT_DLLPUBLIC EditBrowserHeader : public BrowserHeader
877 public:
878 EditBrowserHeader( BrowseBox* pParent, WinBits nWinBits = WB_BUTTONSTYLE )
879 :BrowserHeader(pParent, nWinBits){}
881 protected:
882 virtual void DoubleClick() override;
886 //= EditBrowseBox
887 class EditBrowseBoxImpl;
888 class SVT_DLLPUBLIC EditBrowseBox: public BrowseBox
890 friend class EditBrowserHeader;
892 enum BrowseInfo
894 COLSELECT = 1,
895 ROWSELECT = 2,
896 ROWCHANGE = 4,
897 COLCHANGE = 8
900 public:
901 enum RowStatus
903 CLEAN = 0,
904 CURRENT = 1,
905 CURRENTNEW = 2,
906 MODIFIED = 3,
907 NEW = 4,
908 DELETED = 5,
909 PRIMARYKEY = 6,
910 CURRENT_PRIMARYKEY = 7,
911 FILTER = 8,
912 HEADERFOOTER = 9
915 private:
916 EditBrowseBox(EditBrowseBox const &) = delete;
917 EditBrowseBox& operator=(EditBrowseBox const &) = delete;
919 class BrowserMouseEventPtr
921 std::unique_ptr<BrowserMouseEvent> pEvent;
922 bool bDown;
924 public:
925 BrowserMouseEventPtr()
926 : bDown(false)
930 bool Is() const {return pEvent != nullptr;}
931 bool IsDown() const {return bDown;}
932 const BrowserMouseEvent* operator->() const {return pEvent.get();}
934 SVT_DLLPUBLIC void Clear();
935 void Set(const BrowserMouseEvent* pEvt, bool bIsDown);
936 } aMouseEvent;
938 CellControllerRef aController,
939 aOldController;
941 ImplSVEvent * nStartEvent, * nEndEvent, * nCellModifiedEvent; // event ids
942 VclPtr<vcl::Window> m_pFocusWhileRequest;
943 // In ActivateCell, we grab the focus asynchronously, but if between requesting activation
944 // and the asynchronous event the focus has changed, we won't grab it for ourself.
946 sal_Int32 nPaintRow; // row being painted
947 sal_Int32 nEditRow;
948 sal_uInt16 nEditCol;
950 bool bHasFocus : 1;
951 mutable bool bPaintStatus : 1; // paint a status (image) in the handle column
952 bool bActiveBeforeTracking;
954 VclPtr<CheckBoxControl> pCheckBoxPaint;
956 EditBrowseBoxFlags m_nBrowserFlags;
957 std::unique_ptr< EditBrowseBoxImpl> m_aImpl;
959 protected:
960 VclPtr<BrowserHeader> pHeader;
962 BrowserMouseEventPtr& getMouseEvent() { return aMouseEvent; }
964 protected:
965 BrowserHeader* GetHeaderBar() const {return pHeader;}
967 virtual VclPtr<BrowserHeader> CreateHeaderBar(BrowseBox* pParent) override;
969 // if you want to have an own header ...
970 virtual VclPtr<BrowserHeader> imp_CreateHeaderBar(BrowseBox* pParent);
972 virtual void ColumnMoved(sal_uInt16 nId) override;
973 virtual void ColumnResized(sal_uInt16 nColId) override;
974 virtual void Resize() override;
975 virtual void ArrangeControls(sal_uInt16& nX, sal_uInt16 nY);
976 virtual bool SeekRow(sal_Int32 nRow) override;
978 virtual void GetFocus() override;
979 virtual void LoseFocus() override;
980 virtual void KeyInput(const KeyEvent& rEvt) override;
981 virtual void MouseButtonDown(const BrowserMouseEvent& rEvt) override;
982 virtual void MouseButtonUp(const BrowserMouseEvent& rEvt) override;
983 virtual void StateChanged( StateChangedType nType ) override;
984 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
986 using BrowseBox::MouseButtonUp;
987 using BrowseBox::MouseButtonDown;
989 virtual bool PreNotify(NotifyEvent& rNEvt ) override;
990 virtual bool EventNotify(NotifyEvent& rNEvt) override;
992 virtual void EndScroll() override;
994 // should be used instead of GetFieldRectPixel, 'cause this method here takes into account the borders
995 tools::Rectangle GetCellRect(sal_Int32 nRow, sal_uInt16 nColId, bool bRelToBrowser = true) const;
996 virtual sal_uInt32 GetTotalCellWidth(sal_Int32 nRow, sal_uInt16 nColId);
997 sal_uInt32 GetAutoColumnWidth(sal_uInt16 nColId);
999 virtual void PaintStatusCell(OutputDevice& rDev, const tools::Rectangle& rRect) const;
1000 virtual void PaintCell(OutputDevice& rDev, const tools::Rectangle& rRect, sal_uInt16 nColId) const = 0;
1002 virtual RowStatus GetRowStatus(sal_Int32 nRow) const;
1004 virtual void RowHeightChanged() override;
1006 // callbacks for the data window
1007 virtual void ImplStartTracking() override;
1008 virtual void ImplEndTracking() override;
1010 // when changing a row:
1011 // CursorMoving: cursor is being moved, but GetCurRow() still provides the old row
1012 virtual bool CursorMoving(sal_Int32 nNewRow, sal_uInt16 nNewCol);
1014 // cursor has been moved
1015 virtual void CursorMoved() override;
1017 virtual void CellModified(); // called whenever a cell has been modified
1018 virtual bool SaveModified(); // called whenever a cell should be left, and it's content should be saved
1019 // return sal_False prevents leaving the cell
1020 virtual bool SaveRow(); // commit the current row
1022 virtual bool IsModified() const {return aController.is() && aController->IsValueChangedFromSaved();}
1024 virtual CellController* GetController(sal_Int32 nRow, sal_uInt16 nCol);
1025 virtual void InitController(CellControllerRef& rController, sal_Int32 nRow, sal_uInt16 nCol);
1026 static void ResizeController(CellControllerRef const & rController, const tools::Rectangle&);
1027 virtual void DoubleClick(const BrowserMouseEvent&) override;
1029 void ActivateCell() { ActivateCell(GetCurRow(), GetCurColumnId()); }
1031 // retrieve the image for the row status
1032 Image GetImage(RowStatus) const;
1034 // inserting columns
1035 // if you don't set a width, this will be calculated automatically
1036 // if the id isn't set the smallest unused will do it ...
1037 virtual sal_uInt16 AppendColumn(const OUString& rName, sal_uInt16 nWidth, sal_uInt16 nPos = HEADERBAR_APPEND, sal_uInt16 nId = sal_uInt16(-1));
1039 // called whenever (Shift)Tab or Enter is pressed. If true is returned, these keys
1040 // result in traveling to the next or to th previous cell
1041 virtual bool IsTabAllowed(bool bForward) const;
1043 virtual bool IsCursorMoveAllowed(sal_Int32 nNewRow, sal_uInt16 nNewColId) const override;
1045 void PaintTristate(const tools::Rectangle& rRect, const TriState& eState, bool _bEnabled=true) const;
1047 void AsynchGetFocus();
1048 // secure starting of StartEditHdl
1050 public:
1051 EditBrowseBox(vcl::Window* pParent, EditBrowseBoxFlags nBrowserFlags, WinBits nBits, BrowserMode nMode = BrowserMode::NONE );
1052 virtual ~EditBrowseBox() override;
1053 virtual void dispose() override;
1055 bool IsEditing() const {return aController.is();}
1056 void InvalidateStatusCell(sal_Int32 nRow) {RowModified(nRow, 0);}
1057 void InvalidateHandleColumn();
1059 // late construction
1060 virtual void Init();
1061 virtual void RemoveRows();
1062 virtual void Dispatch(sal_uInt16 nId);
1064 const CellControllerRef& Controller() const { return aController; }
1065 EditBrowseBoxFlags GetBrowserFlags() const { return m_nBrowserFlags; }
1066 void SetBrowserFlags(EditBrowseBoxFlags nFlags);
1068 virtual void ActivateCell(sal_Int32 nRow, sal_uInt16 nCol, bool bSetCellFocus = true);
1069 virtual void DeactivateCell(bool bUpdate = true);
1070 // Children ---------------------------------------------------------------
1072 /** @return The count of additional controls of the control area. */
1073 virtual sal_Int32 GetAccessibleControlCount() const override;
1075 /** Creates the accessible object of an additional control.
1076 @param nIndex
1077 The 0-based index of the control.
1078 @return
1079 The XAccessible interface of the specified control. */
1080 virtual css::uno::Reference< css::accessibility::XAccessible >
1081 CreateAccessibleControl( sal_Int32 nIndex ) override;
1083 /** Sets focus to current cell of the data table. */
1084 virtual void GrabTableFocus() override;
1086 virtual tools::Rectangle GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex) override;
1087 virtual sal_Int32 GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint) override;
1089 virtual bool ProcessKey(const KeyEvent& rEvt) override;
1091 virtual void ChildFocusIn() override;
1092 virtual void ChildFocusOut() override;
1094 css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleCheckBoxCell(sal_Int32 _nRow, sal_uInt16 _nColumnPos,const TriState& eState);
1095 bool ControlHasFocus() const;
1096 protected:
1097 // creates the accessible which wraps the active cell
1098 void implCreateActiveAccessible( );
1100 private:
1101 virtual void PaintField(vcl::RenderContext& rDev, const tools::Rectangle& rRect,
1102 sal_uInt16 nColumnId ) const override;
1103 using Control::ImplInitSettings;
1104 SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
1105 SVT_DLLPRIVATE void DetermineFocus( const GetFocusFlags _nGetFocusFlags = GetFocusFlags::NONE);
1106 inline void EnableAndShow() const;
1108 SVT_DLLPRIVATE void implActivateCellOnMouseEvent(const BrowserMouseEvent& _rEvt, bool _bUp);
1110 DECL_DLLPRIVATE_LINK( ModifyHdl, LinkParamNone*, void );
1111 DECL_DLLPRIVATE_LINK( StartEditHdl, void*, void );
1112 DECL_DLLPRIVATE_LINK( EndEditHdl, void*, void );
1113 DECL_DLLPRIVATE_LINK( CellModifiedHdl, void*, void );
1117 } // namespace svt
1119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */