tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / svtools / editbrowsebox.hxx
blob8acd3fd760c96bcc4bd71edfddffed24e398fb19
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 SetEditableReadOnly(bool bReadOnly) override;
834 virtual void dispose() override;
835 private:
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
851 public:
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;
862 private:
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
870 public:
871 FormattedFieldCellController( FormattedControlBase* _pFormatted );
873 virtual void CommitModifications() override;
876 //= EditBrowserHeader
877 class SVT_DLLPUBLIC EditBrowserHeader : public BrowserHeader
879 public:
880 EditBrowserHeader( BrowseBox* pParent, WinBits nWinBits = WB_BUTTONSTYLE )
881 :BrowserHeader(pParent, nWinBits){}
883 protected:
884 virtual void DoubleClick() override;
888 //= EditBrowseBox
889 class EditBrowseBoxImpl;
890 class SVT_DLLPUBLIC EditBrowseBox: public BrowseBox
892 friend class EditBrowserHeader;
894 enum BrowseInfo
896 COLSELECT = 1,
897 ROWSELECT = 2,
898 ROWCHANGE = 4,
899 COLCHANGE = 8
902 public:
903 enum RowStatus
905 CLEAN = 0,
906 CURRENT = 1,
907 CURRENTNEW = 2,
908 MODIFIED = 3,
909 NEW = 4,
910 DELETED = 5,
911 PRIMARYKEY = 6,
912 CURRENT_PRIMARYKEY = 7,
913 FILTER = 8,
914 HEADERFOOTER = 9
917 private:
918 EditBrowseBox(EditBrowseBox const &) = delete;
919 EditBrowseBox& operator=(EditBrowseBox const &) = delete;
921 class SAL_DLLPRIVATE BrowserMouseEventPtr
923 std::unique_ptr<BrowserMouseEvent> pEvent;
924 bool bDown;
926 public:
927 BrowserMouseEventPtr()
928 : bDown(false)
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);
938 } aMouseEvent;
940 CellControllerRef aController,
941 aOldController;
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
949 sal_Int32 nEditRow;
950 sal_uInt16 nEditCol;
952 bool bHasFocus : 1;
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;
961 protected:
962 VclPtr<BrowserHeader> pHeader;
964 BrowserMouseEventPtr& getMouseEvent() { return aMouseEvent; }
966 protected:
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
1052 public:
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.
1078 @param nIndex
1079 The 0-based index of the control.
1080 @return
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;
1098 protected:
1099 // creates the accessible which wraps the active cell
1100 void implCreateActiveAccessible( );
1102 private:
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 );
1119 } // namespace svt
1121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */