diff options
Diffstat (limited to 'include/vcl/toolkit')
34 files changed, 5929 insertions, 0 deletions
diff --git a/include/vcl/toolkit/README b/include/vcl/toolkit/README new file mode 100644 index 0000000000..889f0b20aa --- /dev/null +++ b/include/vcl/toolkit/README @@ -0,0 +1,2 @@ +These are includes which are now only used by the toolkit module, which exposes +them via uno. Don't use these in any new code. diff --git a/include/vcl/toolkit/button.hxx b/include/vcl/toolkit/button.hxx new file mode 100644 index 0000000000..017c4d06ac --- /dev/null +++ b/include/vcl/toolkit/button.hxx @@ -0,0 +1,511 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <vcl/image.hxx> +#include <vcl/ctrl.hxx> +#include <vcl/vclenum.hxx> +#include <memory> +#include <vector> + +namespace com::sun::star::frame { struct FeatureStateEvent; class XFrame; } +template <class T> class VclPtr; + +class Color; +class ImplCommonButtonData; +enum class DrawButtonFlags; + +class VCL_DLLPUBLIC Button : public Control +{ +private: + std::unique_ptr<ImplCommonButtonData> mpButtonData; + Link<Button*,void> maClickHdl; + + /// Command URL (like .uno:Save) in case the button should handle it. + OUString maCommand; + + Button (const Button &) = delete; + Button & operator= (const Button &) = delete; +public: + SAL_DLLPRIVATE DrawTextFlags ImplGetTextStyle( WinBits nWinStyle, SystemTextColorFlags nSystemTextColorFlags ) const; + SAL_DLLPRIVATE void ImplDrawAlignedImage(OutputDevice* pDev, Point& rPos, Size& rSize, + sal_Int32 nImageSep, + DrawTextFlags nTextStyle, tools::Rectangle *pSymbolRect=nullptr, bool bAddImageSep = false ); + SAL_DLLPRIVATE void ImplSetFocusRect( const tools::Rectangle &rFocusRect ); + SAL_DLLPRIVATE const tools::Rectangle& ImplGetFocusRect() const; + SAL_DLLPRIVATE void ImplSetSymbolAlign( SymbolAlign eAlign ); + /// The x-coordinate of the vertical separator line, use in MenuButton subclass only. + SAL_DLLPRIVATE tools::Long ImplGetSeparatorX() const; + SAL_DLLPRIVATE void ImplSetSeparatorX( tools::Long nX ); + +protected: + explicit Button( WindowType nType ); + + // for drawing RadioButton or CheckButton that has Text and/or Image + SAL_DLLPRIVATE void ImplDrawRadioCheck(OutputDevice* pDev, WinBits nWinStyle, SystemTextColorFlags nSystemTextColorFlags, + const Point& rPos, const Size& rSize, + const Size& rImageSize, tools::Rectangle& rStateRect, + tools::Rectangle& rMouseRect); + SAL_DLLPRIVATE tools::Long ImplGetImageToTextDistance() const; + +public: + virtual ~Button() override; + virtual void dispose() override; + + virtual void Click(); + + void SetClickHdl( const Link<Button*,void>& rLink ) { maClickHdl = rLink; } + const Link<Button*,void>& GetClickHdl() const { return maClickHdl; } + + /// Setup handler for UNO commands so that commands like .uno:Something are handled automagically by this button. + void SetCommandHandler(const OUString& aCommand, const css::uno::Reference<css::frame::XFrame>& rFrame); + OUString const & GetCommand() const { return maCommand; } + + void SetModeImage( const Image& rImage ); + Image const & GetModeImage( ) const; + bool HasImage() const; + void SetImageAlign( ImageAlign eAlign ); + ImageAlign GetImageAlign() const; + DrawButtonFlags GetButtonState() const; + DrawButtonFlags& GetButtonState(); + + /// Set an image to use as the complete render view of a custom button, + /// instead of the usual contents of a button + void SetCustomButtonImage( const Image& rImage ); + Image const & GetCustomButtonImage() const; + + bool IsSmallSymbol() const; + void SetSmallSymbol(); + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + /// Sets the button state according to the FeatureStateEvent emitted by a Uno state change. + virtual void statusChanged(const css::frame::FeatureStateEvent& rEvent); + + virtual FactoryFunction GetUITestFactory() const override; + + virtual void DumpAsPropertyTree(tools::JsonWriter&) override; + +protected: + + /// Handler for click, in case we want the button to handle uno commands (.uno:Something). + DECL_DLLPRIVATE_STATIC_LINK(Button, dispatchCommandHandler, Button*, void); +}; + +enum class PushButtonDropdownStyle +{ + NONE = 0x0000, + MenuButton = 0x0002, //visual down arrow + SplitMenuButton = 0x0003, //visual down arrow and separator line +}; + +class VCL_DLLPUBLIC PushButton : public Button +{ +public: + SAL_DLLPRIVATE void ImplSetDefButton( bool bSet ); + SAL_DLLPRIVATE void ImplDrawPushButtonFrame(vcl::RenderContext& rRenderContext, tools::Rectangle& rRect, DrawButtonFlags nStyle); + SAL_DLLPRIVATE static bool ImplHitTestPushButton(vcl::Window const * pDev, const Point& rPos); + SAL_DLLPRIVATE bool ImplIsDefButton() const; + + explicit PushButton( vcl::Window* pParent, WinBits nStyle = 0 ); + + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void Tracking( const TrackingEvent& rTEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void KeyUp( const KeyEvent& rKEvt ) override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + + void Toggle(); + + void SetSymbol( SymbolType eSymbol ); + SymbolType GetSymbol() const { return meSymbol; } + void SetSymbolAlign( SymbolAlign eAlign ); + + void SetDropDown( PushButtonDropdownStyle nStyle ); + + void SetState( TriState eState ); + TriState GetState() const { return meState; } + virtual void statusChanged(const css::frame::FeatureStateEvent& rEvent) override; + + void Check( bool bCheck = true ); + bool IsChecked() const; + + void SetPressed( bool bPressed ); + bool IsPressed() const { return mbPressed; } + + void EndSelection(); + + Size CalcMinimumSize() const; + virtual Size GetOptimalSize() const override; + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + virtual void ShowFocus(const tools::Rectangle& rRect) override; + + void setAction(bool bIsAction) + { + mbIsAction = bIsAction; + } + + bool isAction() const + { + return mbIsAction; + } + + void DumpAsPropertyTree(tools::JsonWriter&) override; + + bool isToggleButton() { return mbIsToggleButton; } + void setToggleButton(bool bIsToggleButton) { mbIsToggleButton = bIsToggleButton; } + +protected: + PushButtonDropdownStyle mnDDStyle; + bool mbIsActive; + + SAL_DLLPRIVATE void ImplInitPushButtonData(); + SAL_DLLPRIVATE static WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle ); + SAL_DLLPRIVATE void ImplInitSettings( bool bBackground ); + SAL_DLLPRIVATE void ImplDrawPushButtonContent(OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags, + const tools::Rectangle& rRect, bool bMenuBtnSep, + DrawButtonFlags nButtonFlags); + SAL_DLLPRIVATE void ImplDrawPushButton(vcl::RenderContext& rRenderContext); + using Button::ImplGetTextStyle; + SAL_DLLPRIVATE DrawTextFlags ImplGetTextStyle( SystemTextColorFlags nSystemTextColorFlags ) const; + SAL_DLLPRIVATE bool IsSymbol() const { return ( (meSymbol != SymbolType::DONTKNOW) && (meSymbol != SymbolType::IMAGE) ); } + + PushButton( const PushButton & ) = delete; + PushButton& operator=( const PushButton & ) + = delete; + + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + + using Control::ImplInitSettings; + using Window::ImplInit; + + explicit PushButton( WindowType nType ); + + virtual void FillLayoutData() const override; + virtual const vcl::Font& + GetCanonicalFont( const StyleSettings& _rStyle ) const override; + virtual const Color& + GetCanonicalTextColor( const StyleSettings& _rStyle ) const override; + +private: + SymbolType meSymbol; + TriState meState; + bool mbPressed; + bool mbIsAction; + bool mbIsToggleButton = false; +}; + +inline void PushButton::Check( bool bCheck ) +{ + SetState( bCheck ? TRISTATE_TRUE : TRISTATE_FALSE ); +} + +inline bool PushButton::IsChecked() const +{ + return (GetState() == TRISTATE_TRUE); +} + +class VCL_DLLPUBLIC OKButton final : public PushButton +{ +private: + using PushButton::ImplInit; + + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + + OKButton (const OKButton &) = delete; + OKButton & operator= (const OKButton &) = delete; + +public: + explicit OKButton( vcl::Window* pParent, WinBits nStyle = WB_DEFBUTTON ); + + virtual void Click() override; +}; + +class VCL_DLLPUBLIC CancelButton : public PushButton +{ +protected: + using PushButton::ImplInit; +private: + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + + CancelButton (const CancelButton &) = delete; + CancelButton & operator= (const CancelButton &) = delete; + +public: + explicit CancelButton( vcl::Window* pParent, WinBits nStyle = 0 ); + + virtual void Click() override; +}; + +class CloseButton final : public CancelButton +{ +public: + explicit CloseButton(vcl::Window* pParent); +}; + +class VCL_DLLPUBLIC HelpButton final : public PushButton +{ +private: + using PushButton::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + + HelpButton( const HelpButton & ) = delete; + HelpButton & operator= ( const HelpButton & ) = delete; + + virtual void StateChanged( StateChangedType nStateChange ) override; + +public: + explicit HelpButton( vcl::Window* pParent, WinBits nStyle = 0 ); + + virtual void Click() override; +}; + +class VCL_DLLPUBLIC CheckBox : public Button +{ +private: + tools::Rectangle maStateRect; + tools::Rectangle maMouseRect; + TriState meState; + bool mbTriState; + Link<CheckBox&,void> maToggleHdl; + SAL_DLLPRIVATE void ImplInitCheckBoxData(); + SAL_DLLPRIVATE static WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle ); + SAL_DLLPRIVATE void ImplInitSettings( bool bBackground ); + SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags, + const Point& rPos, const Size& rSize, + const Size& rImageSize, tools::Rectangle& rStateRect, + tools::Rectangle& rMouseRect ); + SAL_DLLPRIVATE void ImplDrawCheckBox(vcl::RenderContext& rRenderContext ); + SAL_DLLPRIVATE Size ImplGetCheckImageSize() const; + + CheckBox(const CheckBox &) = delete; + CheckBox& operator= (const CheckBox &) = delete; + +protected: + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + virtual void FillLayoutData() const override; + virtual const vcl::Font& GetCanonicalFont( const StyleSettings& _rStyle ) const override; + virtual const Color& GetCanonicalTextColor( const StyleSettings& _rStyle ) const override; + void ImplAdjustNWFSizes() override; + + virtual void ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext); + SAL_DLLPRIVATE const tools::Rectangle& GetStateRect() const { return maStateRect; } + SAL_DLLPRIVATE const tools::Rectangle& GetMouseRect() const { return maMouseRect; } + +public: + SAL_DLLPRIVATE void ImplCheck(); +public: + explicit CheckBox( vcl::Window* pParent, WinBits nStyle = 0 ); + + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void Tracking( const TrackingEvent& rTEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void KeyUp( const KeyEvent& rKEvt ) override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + + void Toggle(); + + void SetState( TriState eState ); + TriState GetState() const { return meState; } + + void Check( bool bCheck = true ) + { + SetState( bCheck ? TRISTATE_TRUE : TRISTATE_FALSE ); + } + + bool IsChecked() const + { + return (GetState() == TRISTATE_TRUE); + } + + void EnableTriState( bool bTriState = true ); + bool IsTriStateEnabled() const { return mbTriState; } + + static Image GetCheckImage( const AllSettings& rSettings, DrawButtonFlags nFlags ); + + Size CalcMinimumSize( tools::Long nMaxWidth = 0 ) const; + virtual Size GetOptimalSize() const override; + + void SetToggleHdl( const Link<CheckBox&,void>& rLink ) { maToggleHdl = rLink; } + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + virtual void ShowFocus(const tools::Rectangle& rRect) override; + + /// Button has additional stuff that we need to dump too. + void DumpAsPropertyTree(tools::JsonWriter&) override; + + virtual FactoryFunction GetUITestFactory() const override; +}; + +class VCL_DLLPUBLIC RadioButton : public Button +{ +private: + friend class VclBuilder; + + std::shared_ptr< std::vector< VclPtr< RadioButton > > > m_xGroup; + tools::Rectangle maStateRect; + tools::Rectangle maMouseRect; + Image maImage; + bool mbChecked; + bool mbRadioCheck; + bool mbStateChanged; + bool mbUsesExplicitGroup; + Link<RadioButton&,void> maToggleHdl; + SAL_DLLPRIVATE void ImplInitRadioButtonData(); + SAL_DLLPRIVATE WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle ) const; + SAL_DLLPRIVATE void ImplInitSettings( bool bBackground ); + SAL_DLLPRIVATE void ImplDrawRadioButtonState(vcl::RenderContext& rRenderContext); + SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags, + const Point& rPos, const Size& rSize, + const Size& rImageSize, tools::Rectangle& rStateRect, + tools::Rectangle& rMouseRect ); + SAL_DLLPRIVATE void ImplDrawRadioButton(vcl::RenderContext& rRenderContext ); + SAL_DLLPRIVATE void ImplUncheckAllOther(); + SAL_DLLPRIVATE Size ImplGetRadioImageSize() const; + + RadioButton(const RadioButton &) = delete; + RadioButton& operator= (const RadioButton &) = delete; + +protected: + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + +public: + SAL_DLLPRIVATE void ImplCallClick( bool bGrabFocus = false, GetFocusFlags nFocusFlags = GetFocusFlags::NONE ); + +protected: + virtual void FillLayoutData() const override; + virtual const vcl::Font& + GetCanonicalFont( const StyleSettings& _rStyle ) const override; + virtual const Color& + GetCanonicalTextColor( const StyleSettings& _rStyle ) const override; + void ImplAdjustNWFSizes() override; + +public: + /* + bUsesExplicitGroup of true means that group() is used to set what radiobuttons are part of a group + while false means that contiguous radiobuttons are considered part of a group where WB_GROUP designates + the start of the group and all contiguous radiobuttons without WB_GROUP set form the rest of the group. + + true is fairly straightforward, false leads to trick situations and is the legacy case + */ + explicit RadioButton(vcl::Window* pParent, bool bUsesExplicitGroup, WinBits nWinStyle); + virtual ~RadioButton() override; + virtual void dispose() override; + + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void Tracking( const TrackingEvent& rTEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void KeyUp( const KeyEvent& rKEvt ) override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + + void Toggle(); + + bool IsStateChanged() const { return mbStateChanged; } + + void EnableRadioCheck( bool bRadioCheck ) { mbRadioCheck = bRadioCheck; } + bool IsRadioCheckEnabled() const { return mbRadioCheck; } + + void SetModeRadioImage( const Image& rImage ); + + void SetState( bool bCheck ); + void Check( bool bCheck = true ); + bool IsChecked() const { return mbChecked; } + + static Image GetRadioImage( const AllSettings& rSettings, DrawButtonFlags nFlags ); + + Size CalcMinimumSize( tools::Long nMaxWidth = 0 ) const; + virtual Size GetOptimalSize() const override; + + void SetToggleHdl( const Link<RadioButton&,void>& rLink ) { maToggleHdl = rLink; } + + /** GetRadioButtonGroup returns a list of pointers to <code>RadioButton</code>s in the same group. + + The pointers in the returned list are valid at the time call returns. However rescheduling + or giving up the SolarMutex may mean events get executed that lead to the pointers getting + invalid. + + @param bIncludeThis + defines whether <code>this</code> is contained in the returned list + + @return + on return contains the <code>RadioButton</code>s + in the same group as this <code>RadioButton</code>. + */ + std::vector<VclPtr<RadioButton> > GetRadioButtonGroup(bool bIncludeThis = true) const; + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + /* + * Group this RadioButton with another + */ + void group(RadioButton &rOther); + virtual void ShowFocus(const tools::Rectangle& rRect) override; + + /// Button has additional stuff that we need to dump too. + void DumpAsPropertyTree(tools::JsonWriter&) override; + + virtual FactoryFunction GetUITestFactory() const override; +}; + +class VCL_DLLPUBLIC ImageButton final : public PushButton +{ +private: + using PushButton::ImplInitStyle; + + SAL_DLLPRIVATE void ImplInitStyle(); + + ImageButton( const ImageButton & ) = delete; + ImageButton & operator= ( const ImageButton & ) = delete; + +public: + ImageButton( vcl::Window* pParent, WinBits nStyle = 0 ); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/calendar.hxx b/include/vcl/toolkit/calendar.hxx new file mode 100644 index 0000000000..9652bb4464 --- /dev/null +++ b/include/vcl/toolkit/calendar.hxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> + +#include <vcl/toolkit/field.hxx> +#include <vcl/weld.hxx> + +class FloatingWindow; +struct ImplCFieldFloatWin; + +/************************************************************************* + +Description +============ + +class CalendarField + +This class is a DateField with which one can select a date via a DropDownButton +and the CalendarControl. + +-------------------------------------------------------------------------- + +WinBits + +See DateField + +The preferences for the CalendarControl can be set via SetCalendarStyle(). + +-------------------------------------------------------------------------- + +With EnableToday()/EnableNone() we can enable a TodayButton and a NoneButton. + +-------------------------------------------------------------------------- + +Because we only take over the start date into the field, we should query +with GetCalendar() in the SelectHandler and with GetSelectDateCount()/GetSelectDate() +the selected range. We then can e.g. take over that value to another field. + +-------------------------------------------------------------------------- + +If a derived Calendar should be used, we can override the CreateCalendar() +method in CalendarField and create an own calendar there ourselves. + +*************************************************************************/ + + +class VCL_DLLPUBLIC CalendarField final : public DateField +{ +private: + VclPtr<ImplCFieldFloatWin> mpFloatWin; + weld::Button* mpTodayBtn; + weld::Button* mpNoneBtn; + bool mbToday; + bool mbNone; + + DECL_DLLPRIVATE_LINK( ImplSelectHdl, weld::Calendar&, void ); + DECL_DLLPRIVATE_LINK( ImplClickHdl, weld::Button&, void ); + DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, FloatingWindow*, void ); + +public: + CalendarField( vcl::Window* pParent, WinBits nWinStyle ); + virtual ~CalendarField() override; + virtual void dispose() override; + + virtual bool ShowDropDown( bool bShow ) override; + + void EnableToday() { mbToday = true; } + void EnableNone() { mbNone = true; } + +private: + virtual void StateChanged( StateChangedType nStateChange ) override; + virtual bool FocusWindowBelongsToControl(const vcl::Window* pFocusWin) const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/combobox.hxx b/include/vcl/toolkit/combobox.hxx new file mode 100644 index 0000000000..c7628e7321 --- /dev/null +++ b/include/vcl/toolkit/combobox.hxx @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <memory> +#include <vcl/dllapi.h> +#include <vcl/toolkit/edit.hxx> + +#define COMBOBOX_APPEND (SAL_MAX_INT32) +#define COMBOBOX_ENTRY_NOTFOUND (SAL_MAX_INT32) +#define COMBOBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1) + +class ImplListBoxWindow; +class UserDrawEvent; + +/// A widget used to choose from a list of items and which has an entry. +class VCL_DLLPUBLIC ComboBox : public Edit +{ +private: + struct SAL_DLLPRIVATE Impl; + std::unique_ptr<Impl> m_pImpl; + +protected: + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + SAL_DLLPRIVATE void ImplCalcEditHeight(); + SAL_DLLPRIVATE tools::Long getMaxWidthScrollBarAndDownButton() const; + +protected: + bool IsDropDownBox() const; + + virtual void FillLayoutData() const override; + +public: + explicit ComboBox( vcl::Window* pParent, WinBits nStyle = 0 ); + virtual ~ComboBox() override; + virtual void dispose() override; + + virtual void Draw( OutputDevice* pDev, const Point& rPos,SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + void Select(); + void DoubleClick(); + + virtual void Modify() override; + + virtual const Wallpaper& GetDisplayBackground() const override; + + virtual void setPosSizePixel( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override; + + tools::Rectangle GetDropDownPosSizePixel() const; + + void AdaptDropDownLineCountToMaximum(); + void SetDropDownLineCount( sal_uInt16 nLines ); + sal_uInt16 GetDropDownLineCount() const; + + void EnableAutoSize( bool bAuto ); + bool IsAutoSizeEnabled() const; + + virtual void SetText( const OUString& rStr ) override; + virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) override; + + sal_Int32 InsertEntry(const OUString& rStr, sal_Int32 nPos = COMBOBOX_APPEND); + sal_Int32 InsertEntryWithImage( const OUString& rStr, const Image& rImage, sal_Int32 nPos = COMBOBOX_APPEND ); + + void RemoveEntryAt(sal_Int32 nPos); + + void Clear(); + sal_Int32 GetEntryPos( std::u16string_view rStr ) const; + Image GetEntryImage( sal_Int32 nPos ) const; + OUString GetEntry( sal_Int32 nPos ) const; + sal_Int32 GetEntryCount() const; + + bool IsTravelSelect() const; + bool IsInDropDown() const; + void ToggleDropDown(); + + void SetUserItemSize( const Size& rSz ); + void EnableUserDraw( bool bUserDraw ); + bool IsUserDrawEnabled() const; + + void DrawEntry( const UserDrawEvent& rEvt ); + void SetBorderStyle( WindowBorderStyle nBorderStyle ); + void SetHighlightColor(const Color& rColor); + void SetHighlightTextColor(const Color& rColor); + + /** + * Adds a new separator at the given position n. + */ + void AddSeparator( sal_Int32 n ); + + void EnableAutocomplete( bool bEnable, bool bMatchCase = false ); + bool IsAutocompleteEnabled() const; + + bool IsMultiSelectionEnabled() const; + + void SetSelectHdl(const Link<ComboBox&,void>& rLink); + void SetEntryActivateHdl(const Link<Edit&,bool>& rLink); + void SetUserDrawHdl(const Link<UserDrawEvent*, void>& rLink); + + Size CalcMinimumSize() const override; + virtual Size GetOptimalSize() const override; + Size CalcAdjustedSize( const Size& rPrefSize ) const; + Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const; + void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const; + + void SetMRUEntries( std::u16string_view rEntries ); + OUString GetMRUEntries() const; + void SetMaxMRUCount( sal_Int32 n ); + sal_Int32 GetMaxMRUCount() const; + void SetEntryData( sal_Int32 nPos, void* pNewData ); + void* GetEntryData( sal_Int32 nPos ) const; + + sal_Int32 GetTopEntry() const; + + sal_uInt16 GetDisplayLineCount() const; + + sal_Int32 GetSelectedEntryCount() const; + sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const; + bool IsEntryPosSelected( sal_Int32 nPos ) const; + void SelectEntryPos( sal_Int32 nPos, bool bSelect = true ); + void SetNoSelection(); + tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const; + + // determine if Select was called due to typing or cursoring in the + // combobox, as opposed to something selected from the menu or via some + // other route. e.g. the toolbar fontsize combobox wants to immediately + // change size only if something is picked from the combobox menu, other + // changes don't auto-apply until the user presses return + bool IsModifyByKeyboard() const; + + // determine if Edit::Modify was called due to the ComboBox changing the edit area + // itself + bool IsSyntheticModify() const; + + + /** checks whether a certain point lies within the bounds of + a list item and returns the item as well as the character position + the point is at. + + <p>If the point is inside an item the item pos is put into <code>rPos</code> and + the item-relative character index is returned. If the point is not inside + an item -1 is returned and rPos is unchanged.</p> + + @param rPoint + tells the point for which an item is requested. + + @param rPos + gets the item at the specified point <code>rPoint</code> + + @returns + the item-relative character index at point <code>rPos</code> or -1 + if no item is at that point. + */ + using Control::GetIndexForPoint; + tools::Long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const; + + void setMaxWidthChars(sal_Int32 nWidth); + + void SetWidthInChars(sal_Int32 nWidthInChars); + + tools::Long GetDropDownEntryHeight() const; + + // the drop down window container + ImplListBoxWindow* GetMainWindow() const; + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + virtual FactoryFunction GetUITestFactory() const override; + + virtual void DumpAsPropertyTree(tools::JsonWriter&) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/dialog.hxx b/include/vcl/toolkit/dialog.hxx new file mode 100644 index 0000000000..5e11d2f783 --- /dev/null +++ b/include/vcl/toolkit/dialog.hxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <memory> +#include <string_view> + +#include <vcl/dllapi.h> +#include <vcl/syswin.hxx> +#include <vcl/vclptr.hxx> +#include <vcl/abstdlg.hxx> + +struct DialogImpl; +class Button; +class PushButton; +class VclBox; +class VclButtonBox; + +class VCL_DLLPUBLIC Dialog : public SystemWindow +{ +public: + enum class InitFlag + { + /** Use given parent or get a default one using GetDefaultParent(...) */ + Default, + + /** No Parent */ + NoParent + }; + +private: + std::unique_ptr<DialogImpl> mpDialogImpl; + tools::Long mnMousePositioned; + bool mbInExecute; + bool mbInSyncExecute; + bool mbInClose; + bool mbModalMode; + InitFlag mnInitFlag; // used for deferred init + + VclPtr<VclButtonBox> mpActionArea; + VclPtr<VclBox> mpContentArea; + + SAL_DLLPRIVATE void RemoveFromDlgList(); + SAL_DLLPRIVATE void ImplInitDialogData(); + SAL_DLLPRIVATE void ImplInitSettings(); + SAL_DLLPRIVATE VclPtr<vcl::Window> AddBorderWindow(vcl::Window* pParent, WinBits nBits); + + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; + + SAL_DLLPRIVATE Dialog (const Dialog &) = delete; + SAL_DLLPRIVATE Dialog & operator= (const Dialog &) = delete; + + DECL_DLLPRIVATE_LINK(ImplAsyncCloseHdl, void*, void); + DECL_DLLPRIVATE_LINK(ResponseHdl, Button*, void); + + // get the default parent for a dialog as is done in standard initialization + SAL_DLLPRIVATE static vcl::Window* GetDefaultParent(WinBits nStyle); + +protected: + void ImplInitDialog( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag = InitFlag::Default ); + + /// Find and set the LOK notifier according to the pParent. + void ImplLOKNotifier(vcl::Window* pParent); + +public: + SAL_DLLPRIVATE bool IsInClose() const { return mbInClose; } + virtual void doDeferredInit(WinBits nBits) override; + SAL_DLLPRIVATE void disposeOwnedButtons(); + + SAL_DLLPRIVATE static vcl::Window* GetDefDialogParent(); + +protected: + explicit Dialog( WindowType nType ); + explicit Dialog( vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription); + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void settingOptimalLayoutSize(Window *pBox) override; + +protected: + friend class VclBuilder; + friend class SalInstanceBuilder; + void set_action_area(VclButtonBox* pBox); + void set_content_area(VclBox* pBox); + vcl::Window* GetFirstControlForFocus(); + +public: + explicit Dialog( vcl::Window* pParent, WinBits nStyle = WB_STDDIALOG, InitFlag eFlag = InitFlag::Default ); + virtual ~Dialog() override; + virtual void dispose() override; + + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void StateChanged( StateChangedType nStateChange ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual void Command( const CommandEvent& rCEvt ) override; + virtual void PixelInvalidate(const tools::Rectangle* pRectangle) override; + + virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override; + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + VclButtonBox* get_action_area() { return mpActionArea; } + VclBox* get_content_area() { return mpContentArea; } + + virtual bool Close() override; + + short Execute(); + bool IsInExecute() const { return mbInExecute; } + // Return true when dialog is synchronously executed (calling ::Execute()) + bool IsInSyncExecute() const { return mbInSyncExecute; }; + + virtual FactoryFunction GetUITestFactory() const override; + +private: + bool ImplStartExecute(); + static void ImplEndExecuteModal(); + void ImplSetModalInputMode(bool bModal); + +public: + + /// Commence execution of a modal dialog, disposes owner on failure + bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx); + + // Dialog::Execute replacement API + + + void EndDialog( tools::Long nResult = RET_CANCEL ); + + void GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, + sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const; + + void SetModalInputMode( bool bModal ); + bool IsModalInputMode() const { return mbModalMode; } + + void GrabFocusToFirstControl(); + virtual void Resize() override; + + void Activate() override; + + void SetPopupMenuHdl(const Link<const CommandEvent&, bool>& rLink); + void SetInstallLOKNotifierHdl(const Link<void*, vcl::ILibreOfficeKitNotifier*>& rLink); + void SetLOKTunnelingState(bool bEnabled); + + void add_button(PushButton* pButton, int nResponse, bool bTransferOwnership); + void set_default_response(int nResponse); + int get_default_response() const; + vcl::Window* get_widget_for_response(int nResponse); + + void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/edit.hxx b/include/vcl/toolkit/edit.hxx new file mode 100644 index 0000000000..181940b6fe --- /dev/null +++ b/include/vcl/toolkit/edit.hxx @@ -0,0 +1,249 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/ctrl.hxx> +#include <vcl/textfilter.hxx> + +#include <memory> + +#include <rtl/ustrbuf.hxx> +#include <o3tl/deleter.hxx> +#include <vcl/dllapi.h> +#include <vcl/dndhelp.hxx> +#include <vcl/vclptr.hxx> +#include <com/sun/star/uno/Reference.h> + +namespace com::sun::star::i18n { + class XBreakIterator; + class XExtendedInputSequenceChecker; +} +namespace weld { + class Widget; +} + +class PopupMenu; +class VclBuilder; +struct DDInfo; +struct Impl_IMEInfos; + +#define EDIT_NOLIMIT SAL_MAX_INT32 + +class Timer; + +class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient +{ +private: + VclPtr<Edit> mpSubEdit; + TextFilter* mpFilterText; + std::unique_ptr<DDInfo, o3tl::default_delete<DDInfo>> mpDDInfo; + std::unique_ptr<Impl_IMEInfos> mpIMEInfos; + OUStringBuffer maText; + OUString maPlaceholderText; + OUString maSaveValue; + OUString maUndoText; + tools::Long mnXOffset; + Selection maSelection; + sal_uInt16 mnAlign; + sal_Int32 mnMaxTextLen; + sal_Int32 mnWidthInChars; + sal_Int32 mnMaxWidthChars; + sal_Unicode mcEchoChar; + bool mbInternModified:1, + mbReadOnly:1, + mbInsertMode:1, + mbClickedInSelection:1, + mbIsSubEdit:1, + mbActivePopup:1, + mbForceControlBackground:1, + mbPassword; + Link<Edit&,void> maModifyHdl; + Link<Edit&,void> maAutocompleteHdl; + Link<Edit&,bool> maActivateHdl; + std::unique_ptr<VclBuilder> mpUIBuilder; + + css::uno::Reference<css::i18n::XBreakIterator> mxBreakIterator; + css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC; + css::uno::Reference<css::datatransfer::dnd::XDragSourceListener > mxDnDListener; + + SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const; + SAL_DLLPRIVATE void ImplInitEditData(); + SAL_DLLPRIVATE OUString ImplGetText() const; + SAL_DLLPRIVATE void ImplRepaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle); + SAL_DLLPRIVATE void ImplInvalidateOrRepaint(); + SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode ); + SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection ); + SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = nullptr, bool bIsUserInput = false ); + SAL_DLLPRIVATE static OUString ImplGetValidString( const OUString& rString ); + SAL_DLLPRIVATE void ImplClearBackground(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle, tools::Long nXStart, tools::Long nXEnd); + SAL_DLLPRIVATE void ImplPaintBorder(vcl::RenderContext const & rRenderContext); + SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true ); + SAL_DLLPRIVATE void ImplAlign(); + SAL_DLLPRIVATE void ImplAlignAndPaint(); + SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const; + SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect ); + SAL_DLLPRIVATE void ImplShowDDCursor(); + SAL_DLLPRIVATE void ImplHideDDCursor(); + SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt ); + SAL_DLLPRIVATE void ImplCopyToSelectionClipboard(); + SAL_DLLPRIVATE void ImplCopy(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard); + SAL_DLLPRIVATE void ImplPaste(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard); + SAL_DLLPRIVATE tools::Long ImplGetTextYPosition() const; + SAL_DLLPRIVATE css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> const& ImplGetInputSequenceChecker(); + SAL_DLLPRIVATE css::uno::Reference<css::i18n::XBreakIterator> const& ImplGetBreakIterator(); + SAL_DLLPRIVATE void filterText(); + +protected: + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true ); + SAL_DLLPRIVATE ControlType ImplGetNativeControlType() const; + SAL_DLLPRIVATE tools::Long ImplGetExtraXOffset() const; + SAL_DLLPRIVATE tools::Long ImplGetExtraYOffset() const; + static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( vcl::Window* pWin ); + + // DragAndDropClient + using vcl::unohelper::DragAndDropClient::dragEnter; + using vcl::unohelper::DragAndDropClient::dragExit; + using vcl::unohelper::DragAndDropClient::dragOver; + virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override; + virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent& dsde) override; + virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override; + virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee) override; + virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) override; + virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override; + +protected: + Edit(WindowType nType); + virtual void FillLayoutData() const override; + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; +public: + // public because needed in button.cxx + SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext const & rRenderContext, WinBits nStyle) const; + + Edit( vcl::Window* pParent, WinBits nStyle = WB_BORDER ); + virtual ~Edit() override; + virtual void dispose() override; + + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Resize() override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + virtual void Tracking( const TrackingEvent& rTEvt ) override; + virtual void Command( const CommandEvent& rCEvt ) override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual bool PreNotify(NotifyEvent& rNEvt) override; + + virtual void Modify(); + + static bool IsCharInput( const KeyEvent& rKEvt ); + + virtual void SetModifyFlag(); + + void SetEchoChar( sal_Unicode c ); + sal_Unicode GetEchoChar() const { return mcEchoChar; } + + virtual void SetReadOnly( bool bReadOnly = true ); + virtual bool IsReadOnly() const { return mbReadOnly; } + + void SetInsertMode( bool bInsert ); + bool IsInsertMode() const; + + virtual void SetMaxTextLen( sal_Int32 nMaxLen ); + virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; } + + void SetWidthInChars(sal_Int32 nWidthInChars); + sal_Int32 GetWidthInChars() const { return mnWidthInChars; } + + void setMaxWidthChars(sal_Int32 nWidth); + + virtual void SetSelection( const Selection& rSelection ); + virtual const Selection& GetSelection() const; + + virtual void ReplaceSelected( const OUString& rStr ); + virtual void DeleteSelected(); + virtual OUString GetSelected() const; + + virtual void Cut(); + virtual void Copy(); + virtual void Paste(); + void Undo(); + + virtual void SetText( const OUString& rStr ) override; + virtual void SetText( const OUString& rStr, const Selection& rNewSelection ); + virtual OUString GetText() const override; + + void SetCursorAtLast(); + + void SetPlaceholderText( const OUString& rStr ); + + void SaveValue() { maSaveValue = GetText(); } + const OUString& GetSavedValue() const { return maSaveValue; } + + virtual void SetModifyHdl( const Link<Edit&,void>& rLink ) { maModifyHdl = rLink; } + virtual const Link<Edit&,void>& GetModifyHdl() const { return maModifyHdl; } + + void SetActivateHdl(const Link<Edit&,bool>& rLink) { maActivateHdl = rLink; } + + void SetSubEdit( Edit* pEdit ); + Edit* GetSubEdit() const { return mpSubEdit; } + + void SetAutocompleteHdl( const Link<Edit&,void>& rLink ) { maAutocompleteHdl = rLink; } + const Link<Edit&,void>& GetAutocompleteHdl() const { return maAutocompleteHdl; } + + virtual Size CalcMinimumSize() const; + virtual Size CalcMinimumSizeForText(const OUString &rString) const; + virtual Size GetOptimalSize() const override; + virtual Size CalcSize(sal_Int32 nChars) const; + sal_Int32 GetMaxVisChars() const; + + // shows a warning box saying "text too long, truncated" + static void ShowTruncationWarning(weld::Widget* pParent); + + VclPtr<PopupMenu> CreatePopupMenu(); + + virtual OUString GetSurroundingText() const override; + virtual Selection GetSurroundingTextSelection() const override; + virtual bool DeleteSurroundingText(const Selection& rSelection) override; + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; } + + virtual FactoryFunction GetUITestFactory() const override; + + void SetForceControlBackground(bool b) { mbForceControlBackground = b; } + + bool IsPassword() const { return mbPassword; } + + virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/field.hxx b/include/vcl/toolkit/field.hxx new file mode 100644 index 0000000000..71f1bd7033 --- /dev/null +++ b/include/vcl/toolkit/field.hxx @@ -0,0 +1,627 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <sal/config.h> + +#include <string_view> + +#include <config_options.h> +#include <tools/date.hxx> +#include <tools/fldunit.hxx> +#include <tools/time.hxx> +#include <vcl/toolkit/combobox.hxx> +#include <vcl/toolkit/spinfld.hxx> +#include <vcl/formatter.hxx> + +namespace com::sun::star::lang { struct Locale; } + +class CalendarWrapper; +class LocaleDataWrapper; +class LanguageTag; + +class VCL_DLLPUBLIC FormatterBase +{ +private: + VclPtr<Edit> mpField; + mutable std::unique_ptr<LocaleDataWrapper> + mpLocaleDataWrapper; + bool mbReformat; + bool mbStrictFormat; + bool mbEmptyFieldValue; + bool mbEmptyFieldValueEnabled; + +protected: + SAL_DLLPRIVATE void ImplSetText( const OUString& rText, Selection const * pNewSel = nullptr ); + SAL_DLLPRIVATE bool ImplGetEmptyFieldValue() const { return mbEmptyFieldValue; } + + void SetEmptyFieldValueData( bool bValue ) { mbEmptyFieldValue = bValue; } + + SAL_DLLPRIVATE LocaleDataWrapper& ImplGetLocaleDataWrapper() const; + /** reset the LocaleDataWrapper when the language tag changes */ + SAL_DLLPRIVATE void ImplResetLocaleDataWrapper() const; + + Edit* GetField() const { return mpField; } + void ClearField() { mpField.clear(); } + +public: + explicit FormatterBase(Edit* pField); + virtual ~FormatterBase(); + + const LocaleDataWrapper& GetLocaleDataWrapper() const; + + bool MustBeReformatted() const { return mbReformat; } + void MarkToBeReformatted( bool b ) { mbReformat = b; } + + void SetStrictFormat( bool bStrict ); + bool IsStrictFormat() const { return mbStrictFormat; } + + virtual void Reformat(); + virtual void ReformatAll(); + + const css::lang::Locale& GetLocale() const; + const LanguageTag& GetLanguageTag() const; + + void SetEmptyFieldValue(); + bool IsEmptyFieldValue() const; + + void EnableEmptyFieldValue( bool bEnable ) { mbEmptyFieldValueEnabled = bEnable; } + bool IsEmptyFieldValueEnabled() const { return mbEmptyFieldValueEnabled; } +}; + +class VCL_DLLPUBLIC SAL_LOPLUGIN_ANNOTATE("crosscast") NumericFormatter : public FormatterBase +{ +public: + virtual ~NumericFormatter() override; + + virtual void Reformat() override; + + void SetMin( sal_Int64 nNewMin ); + sal_Int64 GetMin() const { return mnMin; } + void SetMax( sal_Int64 nNewMax ); + sal_Int64 GetMax() const { return mnMax; } + + sal_Int64 ClipAgainstMinMax(sal_Int64 nValue) const; + + void SetFirst( sal_Int64 nNewFirst ) { mnFirst = nNewFirst; } + sal_Int64 GetFirst() const { return mnFirst; } + void SetLast( sal_Int64 nNewLast ) { mnLast = nNewLast; } + sal_Int64 GetLast() const { return mnLast; } + void SetSpinSize( sal_Int64 nNewSize ) { mnSpinSize = nNewSize; } + sal_Int64 GetSpinSize() const { return mnSpinSize; } + + void SetDecimalDigits( sal_uInt16 nDigits ); + sal_uInt16 GetDecimalDigits() const { return mnDecimalDigits;} + + void SetUseThousandSep( bool b ); + bool IsUseThousandSep() const { return mbThousandSep; } + + void SetUserValue( sal_Int64 nNewValue ); + virtual void SetValue( sal_Int64 nNewValue ); + sal_Int64 GetValue() const; + virtual OUString CreateFieldText( sal_Int64 nValue ) const; + + sal_Int64 Normalize( sal_Int64 nValue ) const; + sal_Int64 Denormalize( sal_Int64 nValue ) const; + + OUString GetValueString() const; + void SetValueFromString(const OUString& rStr); + +protected: + sal_Int64 mnLastValue; + sal_Int64 mnMin; + sal_Int64 mnMax; + bool mbFormatting; + + // the members below are used in all derivatives of NumericFormatter + // not in NumericFormatter itself. + sal_Int64 mnSpinSize; + sal_Int64 mnFirst; + sal_Int64 mnLast; + + NumericFormatter(Edit* pEdit); + + void FieldUp(); + void FieldDown(); + void FieldFirst(); + void FieldLast(); + void FormatValue(Selection const * pNewSelection = nullptr); + + SAL_DLLPRIVATE void ImplNumericReformat(); + SAL_DLLPRIVATE void ImplNewFieldValue( sal_Int64 nNewValue ); + SAL_DLLPRIVATE void ImplSetUserValue( sal_Int64 nNewValue, Selection const * pNewSelection = nullptr ); + + virtual sal_Int64 GetValueFromString(const OUString& rStr) const; + +private: + sal_uInt16 mnDecimalDigits; + bool mbThousandSep; + +}; + +class VCL_DLLPUBLIC MetricFormatter : public NumericFormatter +{ +public: + virtual ~MetricFormatter() override; + + virtual void Reformat() override; + + virtual void SetUnit( FieldUnit meUnit ); + FieldUnit GetUnit() const { return meUnit; } + void SetCustomUnitText( const OUString& rStr ); + const OUString& GetCustomUnitText() const { return maCustomUnitText; } + + using NumericFormatter::SetMax; + void SetMax( sal_Int64 nNewMax, FieldUnit eInUnit ); + using NumericFormatter::GetMax; + sal_Int64 GetMax( FieldUnit eOutUnit ) const; + using NumericFormatter::SetMin; + void SetMin( sal_Int64 nNewMin, FieldUnit eInUnit ); + using NumericFormatter::GetMin; + sal_Int64 GetMin( FieldUnit eOutUnit ) const; + + void SetValue( sal_Int64 nNewValue, FieldUnit eInUnit ); + virtual void SetValue( sal_Int64 nValue ) override; + using NumericFormatter::SetUserValue; + void SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit ); + using NumericFormatter::GetValue; + sal_Int64 GetValue( FieldUnit eOutUnit ) const; + virtual OUString CreateFieldText( sal_Int64 nValue ) const override; + sal_Int64 GetCorrectedValue( FieldUnit eOutUnit ) const; + +protected: + FieldUnit meUnit; + + MetricFormatter(Edit* pEdit); + + SAL_DLLPRIVATE void ImplMetricReformat( const OUString& rStr, double& rValue, OUString& rOutStr ); + + virtual sal_Int64 GetValueFromString(const OUString& rStr) const override; + sal_Int64 GetValueFromStringUnit(const OUString& rStr, FieldUnit eOutUnit) const; + +private: + OUString maCustomUnitText; +}; + +class VCL_DLLPUBLIC MetricField final : public SpinField, public MetricFormatter +{ +public: + explicit MetricField( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual Size CalcMinimumSize() const override; + + virtual void Modify() override; + + virtual void Up() override; + virtual void Down() override; + virtual void First() override; + virtual void Last() override; + + virtual void SetUnit( FieldUnit meUnit ) override; + + void SetFirst( sal_Int64 nNewFirst, FieldUnit eInUnit ); + sal_Int64 GetFirst( FieldUnit eOutUnit ) const; + void SetLast( sal_Int64 nNewLast, FieldUnit eInUnit ); + sal_Int64 GetLast( FieldUnit eOutUnit ) const; + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + virtual void dispose() override; + + virtual void DumpAsPropertyTree(tools::JsonWriter&) override; + virtual FactoryFunction GetUITestFactory() const override; +}; + +class VCL_DLLPUBLIC MetricBox final : public ComboBox, public MetricFormatter +{ +public: + explicit MetricBox( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual Size CalcMinimumSize() const override; + + virtual void Modify() override; + + virtual void ReformatAll() override; + + // Needed, because GetValue() with nPos hide these functions + using MetricFormatter::GetValue; + + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) CurrencyFormatter : public NumericFormatter +{ +protected: + CurrencyFormatter(Edit* pEdit); + SAL_DLLPRIVATE void ImplCurrencyReformat( const OUString& rStr, OUString& rOutStr ); + virtual sal_Int64 GetValueFromString(const OUString& rStr) const override; + +public: + virtual ~CurrencyFormatter() override; + + virtual void Reformat() override; + + virtual void SetValue( sal_Int64 nNewValue ) override; + virtual OUString CreateFieldText( sal_Int64 nValue ) const override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) CurrencyField final : public SpinField, public CurrencyFormatter +{ +public: + CurrencyField( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void Up() override; + virtual void Down() override; + virtual void First() override; + virtual void Last() override; + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TimeFormatter : public FormatterBase +{ +private: + tools::Time maLastTime; + tools::Time maMin; + tools::Time maMax; + TimeFieldFormat meFormat; + TimeFormat mnTimeFormat; + bool mbDuration; + bool mbEnforceValidValue; + +protected: + tools::Time maFieldTime; + + TimeFormatter(Edit* pEdit); + + SAL_DLLPRIVATE void ImplTimeReformat( std::u16string_view rStr, OUString& rOutStr ); + SAL_DLLPRIVATE void ImplNewFieldValue( const tools::Time& rTime ); + SAL_DLLPRIVATE void ImplSetUserTime( const tools::Time& rNewTime, Selection const * pNewSelection = nullptr ); + SAL_DLLPRIVATE bool ImplAllowMalformedInput() const; + +public: + static OUString FormatTime(const tools::Time& rNewTime, TimeFieldFormat eFormat, TimeFormat eHourFormat, bool bDuration, const LocaleDataWrapper& rLocaleData); + static bool TextToTime(std::u16string_view rStr, tools::Time& rTime, TimeFieldFormat eFormat, bool bDuration, const LocaleDataWrapper& rLocaleDataWrapper, bool _bSkipInvalidCharacters = true); + static int GetTimeArea(TimeFieldFormat eFormat, std::u16string_view rText, int nCursor, + const LocaleDataWrapper& rLocaleDataWrapper); + static tools::Time SpinTime(bool bUp, const tools::Time& rTime, TimeFieldFormat eFormat, + bool bDuration, std::u16string_view rText, int nCursor, + const LocaleDataWrapper& rLocaleDataWrapper); + + virtual ~TimeFormatter() override; + + virtual void Reformat() override; + virtual void ReformatAll() override; + + void SetMin( const tools::Time& rNewMin ); + const tools::Time& GetMin() const { return maMin; } + void SetMax( const tools::Time& rNewMax ); + const tools::Time& GetMax() const { return maMax; } + + void SetTimeFormat( TimeFormat eNewFormat ); + TimeFormat GetTimeFormat() const { return mnTimeFormat;} + + void SetFormat( TimeFieldFormat eNewFormat ); + TimeFieldFormat GetFormat() const { return meFormat; } + + void SetDuration( bool mbDuration ); + bool IsDuration() const { return mbDuration; } + + void SetTime( const tools::Time& rNewTime ); + void SetUserTime( const tools::Time& rNewTime ); + tools::Time GetTime() const; + void SetEmptyTime() { FormatterBase::SetEmptyFieldValue(); } + bool IsEmptyTime() const { return FormatterBase::IsEmptyFieldValue(); } + + /** enables or disables the enforcement of valid values + + If this is set to true (which is the default), then GetTime will always return a valid + time, no matter whether the current text can really be interpreted as time. (Note: this + is the compatible behavior). + + If this is set to false, the GetTime will return GetInvalidTime, in case the current text + cannot be interpreted as time. + + In addition, if this is set to false, the text in the field will <em>not</em> be corrected + when the control loses the focus - instead, the invalid input will be preserved. + */ + void EnforceValidValue( bool _bEnforce ) { mbEnforceValidValue = _bEnforce; } + bool IsEnforceValidValue( ) const { return mbEnforceValidValue; } +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TimeField final : public SpinField, public TimeFormatter +{ +private: + tools::Time maFirst; + tools::Time maLast; + + SAL_DLLPRIVATE void ImplTimeSpinArea( bool bUp ); + +public: + explicit TimeField( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void Up() override; + virtual void Down() override; + virtual void First() override; + virtual void Last() override; + + void SetFirst( const tools::Time& rNewFirst ) { maFirst = rNewFirst; } + const tools::Time& GetFirst() const { return maFirst; } + void SetLast( const tools::Time& rNewLast ) { maLast = rNewLast; } + const tools::Time& GetLast() const { return maLast; } + + void SetExtFormat( ExtTimeFieldFormat eFormat ); + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateFormatter : public FormatterBase +{ +private: + Formatter::StaticFormatter maStaticFormatter; + std::unique_ptr<CalendarWrapper> mxCalendarWrapper; + Date maFieldDate; + Date maLastDate; + Date maMin; + Date maMax; + bool mbLongFormat; + bool mbShowDateCentury; + ExtDateFieldFormat mnExtDateFormat; + bool mbEnforceValidValue; + +protected: + DateFormatter(Edit* pEdit); + + SAL_DLLPRIVATE const Date& ImplGetFieldDate() const { return maFieldDate; } + SAL_DLLPRIVATE void ImplDateReformat( const OUString& rStr, OUString& rOutStr ); + SAL_DLLPRIVATE void ImplSetUserDate( const Date& rNewDate, + Selection const * pNewSelection = nullptr ); + SAL_DLLPRIVATE OUString ImplGetDateAsText( const Date& rDate ) const; + SAL_DLLPRIVATE void ImplNewFieldValue( const Date& rDate ); + CalendarWrapper& GetCalendarWrapper() const; + + SAL_DLLPRIVATE bool ImplAllowMalformedInput() const; + +public: + static OUString FormatDate(const Date& rNewDate, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleData, const Formatter::StaticFormatter& rStaticFormatter); + static bool TextToDate(const OUString& rStr, Date& rTime, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleDataWrapper, const CalendarWrapper& rCalendarWrapper); + static int GetDateArea(ExtDateFieldFormat& eFormat, std::u16string_view rText, int nCursor, const LocaleDataWrapper& rLocaleDataWrapper); + + virtual ~DateFormatter() override; + + virtual void Reformat() override; + virtual void ReformatAll() override; + + void SetExtDateFormat( ExtDateFieldFormat eFormat ); + ExtDateFieldFormat GetExtDateFormat( bool bResolveSystemFormat = false ) const; + + void SetMin( const Date& rNewMin ); + const Date& GetMin() const { return maMin; } + + void SetMax( const Date& rNewMax ); + const Date& GetMax() const { return maMax; } + + + // MT: Remove these methods too, ExtDateFormat should be enough! + // What should happen if using DDMMYYYY, but ShowCentury=false? + + void SetLongFormat( bool bLong ); + bool IsLongFormat() const { return mbLongFormat; } + void SetShowDateCentury( bool bShowCentury ); + bool IsShowDateCentury() const { return mbShowDateCentury; } + + + void SetDate( const Date& rNewDate ); + Date GetDate() const; + void SetEmptyDate(); + bool IsEmptyDate() const; + + void ResetLastDate() { maLastDate = Date( Date::EMPTY ); } + + static void ExpandCentury( Date& rDate ); + static void ExpandCentury( Date& rDate, sal_uInt16 nTwoDigitYearStart ); + + /** enables or disables the enforcement of valid values + + If this is set to true (which is the default), then GetDate will always return a valid + date, no matter whether the current text can really be interpreted as date. (Note: this + is the compatible behavior). + + If this is set to false, the GetDate will return GetInvalidDate, in case the current text + cannot be interpreted as date. + + In addition, if this is set to false, the text in the field will \em not be corrected + when the control loses the focus - instead, the invalid input will be preserved. + */ + void EnforceValidValue( bool _bEnforce ) { mbEnforceValidValue = _bEnforce; } + bool IsEnforceValidValue( ) const { return mbEnforceValidValue; } +}; + +class SAL_DLLPUBLIC_RTTI DateField : public SpinField, public DateFormatter +{ +private: + Date maFirst; + Date maLast; + +protected: + void ImplDateSpinArea( bool bUp ); + +public: + explicit DateField( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void Up() override; + virtual void Down() override; + virtual void First() override; + virtual void Last() override; + + void SetFirst( const Date& rNewFirst ) { maFirst = rNewFirst; } + const Date& GetFirst() const { return maFirst; } + void SetLast( const Date& rNewLast ) { maLast = rNewLast; } + const Date& GetLast() const { return maLast; } + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) NumericBox final : public ComboBox, public NumericFormatter +{ + SAL_DLLPRIVATE void ImplNumericReformat( const OUString& rStr, sal_Int64& rValue, OUString& rOutStr ); +public: + explicit NumericBox( vcl::Window* pParent, WinBits nWinStyle ); + + virtual Size CalcMinimumSize() const override; + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void ReformatAll() override; + + virtual void dispose() override; +}; + +#define PATTERN_FORMAT_EMPTYLITERALS (sal_uInt16(0x0001)) + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) PatternFormatter : public FormatterBase +{ +private: + OString m_aEditMask; + OUString maLiteralMask; + bool mbSameMask; + bool mbInPattKeyInput; + +protected: + PatternFormatter(Edit* pEdit); + + SAL_DLLPRIVATE bool ImplIsSameMask() const { return mbSameMask; } + SAL_DLLPRIVATE bool& ImplGetInPattKeyInput() { return mbInPattKeyInput; } + +public: + virtual ~PatternFormatter() override; + + virtual void Reformat() override; + + void SetMask(const OString& rEditMask, const OUString& rLiteralMask ); + const OString& GetEditMask() const { return m_aEditMask; } + const OUString& GetLiteralMask() const { return maLiteralMask; } + + void SetString( const OUString& rStr ); + OUString GetString() const; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) PatternField final : public SpinField, public PatternFormatter +{ +public: + explicit PatternField( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void Modify() override; + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) PatternBox final : public ComboBox, public PatternFormatter +{ +public: + PatternBox( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + + virtual void Modify() override; + + virtual void ReformatAll() override; + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) CurrencyBox final : public ComboBox, public CurrencyFormatter +{ +public: + explicit CurrencyBox( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void ReformatAll() override; + + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateBox final : public ComboBox, public DateFormatter +{ +public: + explicit DateBox( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void ReformatAll() override; + virtual void dispose() override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TimeBox final : public ComboBox, public TimeFormatter +{ +public: + explicit TimeBox( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void ReformatAll() override; + virtual void dispose() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/fixed.hxx b/include/vcl/toolkit/fixed.hxx new file mode 100644 index 0000000000..2b88e89518 --- /dev/null +++ b/include/vcl/toolkit/fixed.hxx @@ -0,0 +1,181 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <vcl/toolkit/edit.hxx> +#include <vcl/ctrl.hxx> +#include <vcl/image.hxx> + +class VCL_DLLPUBLIC FixedText : public Control +{ +private: + sal_Int32 m_nMaxWidthChars; + sal_Int32 m_nMinWidthChars; + VclPtr<vcl::Window> m_pMnemonicWindow; + + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags, + const Point& rPos, const Size& rSize, bool bFillLayout = false ) const; +public: + SAL_DLLPRIVATE static DrawTextFlags ImplGetTextStyle( WinBits nWinBits ); +protected: + virtual void FillLayoutData() const override; + virtual const vcl::Font& + GetCanonicalFont( const StyleSettings& _rStyle ) const override; + virtual const Color& + GetCanonicalTextColor( const StyleSettings& _rStyle ) const override; + + virtual vcl::Window* getAccessibleRelationLabelFor() const override; + +public: + explicit FixedText( vcl::Window* pParent, WinBits nStyle = 0 ); + virtual ~FixedText() override; + virtual void dispose() override; + + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + void setMaxWidthChars(sal_Int32 nWidth); + void setMinWidthChars(sal_Int32 nWidth); + static Size CalcMinimumTextSize(Control const* pControl, tools::Long nMaxWidth = 0x7fffffff); + static Size getTextDimensions(Control const *pControl, const OUString &rTxt, tools::Long nMaxWidth); + Size CalcMinimumSize(tools::Long nMaxWidth = 0x7fffffff) const; + virtual Size GetOptimalSize() const override; + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + void set_mnemonic_widget(vcl::Window *pWindow); + vcl::Window* get_mnemonic_widget() const { return m_pMnemonicWindow; } +}; + +class SelectableFixedText final : public Edit +{ +public: + explicit SelectableFixedText( vcl::Window* pParent, WinBits nStyle ); + + virtual void LoseFocus() override; + virtual void ApplySettings(vcl::RenderContext&) override; + virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +class VCL_DLLPUBLIC FixedLine final : public Control +{ +private: + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + SAL_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext); + + virtual void FillLayoutData() const override; + virtual const vcl::Font& + GetCanonicalFont( const StyleSettings& _rStyle ) const override; + virtual const Color& + GetCanonicalTextColor( const StyleSettings& _rStyle ) const override; + +public: + explicit FixedLine( vcl::Window* pParent, WinBits nStyle = WB_HORZ ); + + virtual void ApplySettings(vcl::RenderContext&) override; + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual Size GetOptimalSize() const override; + virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +class VCL_DLLPUBLIC FixedBitmap final : public Control +{ +private: + BitmapEx maBitmap; + + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, const Point& rPos, const Size& rSize ); + +public: + explicit FixedBitmap( vcl::Window* pParent, WinBits nStyle = 0 ); + + virtual void ApplySettings(vcl::RenderContext&) override; + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + void SetBitmap( const BitmapEx& rBitmap ); +}; + +class VCL_DLLPUBLIC FixedImage : public Control +{ +private: + Image maImage; + +private: + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + +protected: + SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, + const Point& rPos, const Size& rSize ); +public: + explicit FixedImage( vcl::Window* pParent, WinBits nStyle = 0 ); + + virtual void ApplySettings(vcl::RenderContext&) override; + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual Size GetOptimalSize() const override; + + void SetImage( const Image& rImage ); + const Image& GetImage() const { return maImage; } + + const Image& GetModeImage( ) const { return maImage;} + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + static Image loadThemeImage(const OUString &rFileName); + + void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/fixedhyper.hxx b/include/vcl/toolkit/fixedhyper.hxx new file mode 100644 index 0000000000..1c199d501a --- /dev/null +++ b/include/vcl/toolkit/fixedhyper.hxx @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/toolkit/fixed.hxx> + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) FixedHyperlink final : public FixedText +{ +private: + tools::Long m_nTextLen; + PointerStyle m_aOldPointer; + Link<FixedHyperlink&,void> m_aClickHdl; + OUString m_sURL; + + /** initializes the font (link color and underline). + + Called by the Ctors. + */ + void Initialize(); + + /** is position X position hitting text */ + SAL_DLLPRIVATE bool ImplIsOverText(Point rPosition) const; + + DECL_DLLPRIVATE_LINK(HandleClick, FixedHyperlink&, void); + + /** overwrites Window::MouseMove(). + + Changes the pointer only over the text. + */ + virtual void MouseMove( const MouseEvent& rMEvt ) override; + + /** overwrites Window::MouseButtonUp(). + + Calls the set link if the mouse is over the text. + */ + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + + /** overwrites Window::RequestHelp(). + + Shows tooltip only if the mouse is over the text. + */ + virtual void RequestHelp( const HelpEvent& rHEvt ) override; + +public: + /** ctors + + With WinBits. + */ + FixedHyperlink( vcl::Window* pParent, WinBits nWinStyle = 0 ); + + /** overwrites Window::GetFocus(). + + Changes the color of the text and shows a focus rectangle. + */ + virtual void GetFocus() override; + + /** overwrites Window::LoseFocus(). + + Changes the color of the text and hides the focus rectangle. + */ + virtual void LoseFocus() override; + + /** overwrites Window::KeyInput(). + + KEY_RETURN and KEY_SPACE calls the link handler. + */ + virtual void KeyInput( const KeyEvent& rKEvt ) override; + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + + /** sets m_aClickHdl with rLink. + + m_aClickHdl is called if the text is clicked. + */ + void SetClickHdl( const Link<FixedHyperlink&,void>& rLink ) { m_aClickHdl = rLink; } + const Link<FixedHyperlink&,void>& GetClickHdl() const { return m_aClickHdl; } + + // ::FixedHyperbaseLink + + /** sets the URL of the hyperlink and uses it as tooltip. */ + void SetURL(const OUString& rNewURL); + + /** returns the URL of the hyperlink. + + @return + m_sURL + */ + const OUString& GetURL() const { return m_sURL;} + + /** sets new text and recalculates the text length. */ + virtual void SetText(const OUString& rNewDescription) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/floatwin.hxx b/include/vcl/toolkit/floatwin.hxx new file mode 100644 index 0000000000..f71d664136 --- /dev/null +++ b/include/vcl/toolkit/floatwin.hxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <vcl/syswin.hxx> +#include <memory> +#include <o3tl/typed_flags_set.hxx> + +class ToolBox; + +enum class FloatWinPopupEndFlags +{ + NONE = 0x00, + Cancel = 0x01, + TearOff = 0x02, + DontCallHdl = 0x04, + CloseAll = 0x08, + NoCloseChildren = 0x10, +}; +namespace o3tl +{ + template<> struct typed_flags<FloatWinPopupEndFlags> : is_typed_flags<FloatWinPopupEndFlags, 0x1f> {}; +} + +enum class FloatWinTitleType +{ + Unknown = 0, + Normal = 1, + TearOff = 2, + Popup = 3, + NONE = 4, +}; + +class VCL_DLLPUBLIC FloatingWindow : public SystemWindow +{ + class SAL_DLLPRIVATE ImplData; +private: + VclPtr<FloatingWindow> mpNextFloat; + VclPtr<vcl::Window> mpFirstPopupModeWin; + VclPtr<vcl::Window> mxPrevFocusWin; + std::unique_ptr<ImplData> mpImplData; + AbsoluteScreenPixelRectangle maFloatRect; + ImplSVEvent * mnPostId; + FloatWinPopupFlags mnPopupModeFlags; + FloatWinTitleType mnTitle; + FloatWinTitleType mnOldTitle; + bool mbInPopupMode; + bool mbPopupMode; + bool mbPopupModeCanceled; + bool mbPopupModeTearOff; + bool mbMouseDown; + bool mbGrabFocus; // act as key input window, although focus is not set + bool mbInCleanUp; + Link<FloatingWindow*,void> maPopupModeEndHdl; + + SAL_DLLPRIVATE void ImplCallPopupModeEnd(); + DECL_DLLPRIVATE_LINK( ImplEndPopupModeHdl, void*, void ); + + FloatingWindow (const FloatingWindow &) = delete; + FloatingWindow & operator= (const FloatingWindow &) = delete; + +protected: + SAL_DLLPRIVATE void ImplInitFloating( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE void ImplInitSettings(); + + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; + +public: + SAL_DLLPRIVATE FloatingWindow* ImplFloatHitTest( vcl::Window* pReference, const Point& rPos, bool& rbHitTestInsideRect ); + SAL_DLLPRIVATE FloatingWindow* ImplFindLastLevelFloat(); + SAL_DLLPRIVATE bool ImplIsFloatPopupModeWindow( const vcl::Window* pWindow ); + SAL_DLLPRIVATE void ImplSetMouseDown() { mbMouseDown = true; } + SAL_DLLPRIVATE bool ImplIsMouseDown() const { return mbMouseDown; } + static Point ImplCalcPos(vcl::Window* pWindow, + const tools::Rectangle& rRect, FloatWinPopupFlags nFlags, + sal_uInt16& rArrangeIndex, Point* pLOKTwipsPos = nullptr); + static AbsoluteScreenPixelPoint ImplConvertToAbsPos(vcl::Window* pReference, const Point& rPos); + static AbsoluteScreenPixelRectangle ImplConvertToAbsPos(vcl::Window* pReference, const tools::Rectangle& rRect); + static tools::Rectangle ImplConvertToRelPos(vcl::Window* pReference, const AbsoluteScreenPixelRectangle& rRect); + SAL_DLLPRIVATE void ImplEndPopupMode( FloatWinPopupEndFlags nFlags, const VclPtr<vcl::Window>& xFocusId ); + SAL_DLLPRIVATE AbsoluteScreenPixelRectangle ImplGetItemEdgeClipRect(); + SAL_DLLPRIVATE bool ImplIsInPrivatePopupMode() const { return mbInPopupMode; } + virtual void doDeferredInit(WinBits nBits) override; + void PixelInvalidate(const tools::Rectangle* pRectangle) override; + +public: + explicit FloatingWindow(vcl::Window* pParent, WinBits nStyle); + explicit FloatingWindow(vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription, + const css::uno::Reference<css::frame::XFrame> &rFrame = css::uno::Reference<css::frame::XFrame>()); + virtual ~FloatingWindow() override; + virtual void dispose() override; + + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void PopupModeEnd(); + + void SetTitleType( FloatWinTitleType nTitle ); + FloatWinTitleType GetTitleType() const { return mnTitle; } + + void StartPopupMode( const tools::Rectangle& rRect, FloatWinPopupFlags nFlags ); + void StartPopupMode( ToolBox* pBox, FloatWinPopupFlags nFlags ); + void EndPopupMode( FloatWinPopupEndFlags nFlags = FloatWinPopupEndFlags::NONE ); + void AddPopupModeWindow( vcl::Window* pWindow ); + FloatWinPopupFlags GetPopupModeFlags() const { return mnPopupModeFlags; } + void SetPopupModeFlags( FloatWinPopupFlags nFlags ) { mnPopupModeFlags = nFlags; } + bool IsInPopupMode() const { return mbPopupMode; } + bool IsInCleanUp() const { return mbInCleanUp; } + bool IsPopupModeCanceled() const { return mbPopupModeCanceled; } + bool IsPopupModeTearOff() const { return mbPopupModeTearOff; } + + void SetPopupModeEndHdl( const Link<FloatingWindow*,void>& rLink ) { maPopupModeEndHdl = rLink; } + + bool GrabsFocus() const { return mbGrabFocus; } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/fmtfield.hxx b/include/vcl/toolkit/fmtfield.hxx new file mode 100644 index 0000000000..34b7ea7557 --- /dev/null +++ b/include/vcl/toolkit/fmtfield.hxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/formatter.hxx> +#include <vcl/toolkit/spinfld.hxx> + +class VCL_DLLPUBLIC FormattedField : public SpinField +{ +public: + FormattedField(vcl::Window* pParent, WinBits nStyle); + + virtual void dispose() override; + + // Spin-Handling + virtual void Up() override; + virtual void Down() override; + // Default Implementation: +/- default spin size to the double value + virtual void First() override; + virtual void Last() override; + // Default Implementation: Current double is set to the first or last value + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; +public: + virtual void SetText( const OUString& rStr ) override; + virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) override; + + void SetValueFromString(const OUString& rStr); // currently used by online + + virtual void DumpAsPropertyTree(tools::JsonWriter&) override; + + virtual FactoryFunction GetUITestFactory() const override; + + Formatter& GetFormatter(); + void SetFormatter(Formatter* pFormatter); + +protected: + std::unique_ptr<Formatter> m_xOwnFormatter; + Formatter* m_pFormatter; + + virtual bool EventNotify(NotifyEvent& rNEvt) override; + virtual void Modify() override; + + bool PreNotify(NotifyEvent& rNEvt) override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DoubleNumericField final : public FormattedField +{ +public: + DoubleNumericField(vcl::Window* pParent, WinBits nStyle); + + virtual ~DoubleNumericField() override; + + validation::NumberValidator& GetNumberValidator() { return *m_pNumberValidator; } + void ResetConformanceTester(); + +private: + + std::unique_ptr<validation::NumberValidator> m_pNumberValidator; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DoubleCurrencyField final : public FormattedField +{ +public: + DoubleCurrencyField(vcl::Window* pParent, WinBits nStyle); + + const OUString& getCurrencySymbol() const { return m_sCurrencySymbol; } + void setCurrencySymbol(const OUString& rSymbol); + + bool getPrependCurrSym() const { return m_bPrependCurrSym; } + void setPrependCurrSym(bool _bPrepend); + + void UpdateCurrencyFormat(); +private: + OUString m_sCurrencySymbol; + bool m_bPrependCurrSym; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/group.hxx b/include/vcl/toolkit/group.hxx new file mode 100644 index 0000000000..81e595ec2d --- /dev/null +++ b/include/vcl/toolkit/group.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/ctrl.hxx> + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) GroupBox final : public Control +{ +private: + using Control::ImplInitSettings; + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + SAL_DLLPRIVATE void ImplInitSettings( bool bBackground ); + SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags, + const Point& rPos, const Size& rSize, bool bLayout = false ); + + virtual void FillLayoutData() const override; + virtual const vcl::Font& + GetCanonicalFont( const StyleSettings& _rStyle ) const override; + virtual const Color& + GetCanonicalTextColor( const StyleSettings& _rStyle ) const override; + +public: + explicit GroupBox( vcl::Window* pParent, WinBits nStyle ); + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/imgctrl.hxx b/include/vcl/toolkit/imgctrl.hxx new file mode 100644 index 0000000000..20b1863a00 --- /dev/null +++ b/include/vcl/toolkit/imgctrl.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/toolkit/fixed.hxx> + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) ImageControl : public FixedImage +{ +private: + ::sal_Int16 mnScaleMode; + +public: + ImageControl( vcl::Window* pParent, WinBits nStyle ); + + // set/get the scale mode. This is one of the css.awt.ImageScaleMode constants + void SetScaleMode( const ::sal_Int16 _nMode ); + ::sal_Int16 GetScaleMode() const { return mnScaleMode; } + + virtual void Resize() override; + virtual void Draw( OutputDevice* pDev, const Point& rPos,SystemTextColorFlags nFlags ) override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + +protected: + void ImplDraw( OutputDevice& rDev, const Point& rPos, const Size& rSize ) const; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/ivctrl.hxx b/include/vcl/toolkit/ivctrl.hxx new file mode 100644 index 0000000000..ca96bc8e57 --- /dev/null +++ b/include/vcl/toolkit/ivctrl.hxx @@ -0,0 +1,259 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <memory> +#include <vcl/dllapi.h> +#include <vcl/ctrl.hxx> +#include <tools/link.hxx> +#include <vcl/image.hxx> +#include <o3tl/deleter.hxx> +#include <o3tl/typed_flags_set.hxx> + +class SvxIconChoiceCtrl_Impl; + +enum class SvxIconViewFlags +{ + NONE = 0x0000, + POS_LOCKED = 0x0001, + SELECTED = 0x0002, + FOCUSED = 0x0004, + POS_MOVED = 0x0008, // Moved by Drag and Drop, but not logged +}; +namespace o3tl +{ + template<> struct typed_flags<SvxIconViewFlags> : is_typed_flags<SvxIconViewFlags, 0x000f> {}; +} + +enum class SvxIconChoiceCtrlTextMode +{ + Full = 1, // Enlarge BoundRect southwards + Short // Shorten with "..." +}; + +enum class SvxIconChoiceCtrlPositionMode +{ + Free, // Free pixel-perfect positioning + AutoArrange, // Auto arrange +}; + +class SvxIconChoiceCtrlEntry +{ + Image aImage; + + OUString aText; + OUString aQuickHelpText; + + friend class SvxIconChoiceCtrl_Impl; + friend class IcnCursor_Impl; + friend class EntryList_Impl; + friend class IcnGridMap_Impl; + + tools::Rectangle aRect; // Bounding-Rectangle of the entry + tools::Rectangle aGridRect; // Only valid in Grid-mode + sal_Int32 nPos; + + /* + The insert position in the Insertlist is equal to the (sort) order stated at the Insert + (-> Order of the anchors in the anchors-list!). In "AutoArrange" mode the visible order + can differ. The entries will be linked because of this. + */ + SvxIconChoiceCtrlEntry* pblink; // backward (linker neighbour) + SvxIconChoiceCtrlEntry* pflink; // forward (rechter neighbour) + + SvxIconChoiceCtrlTextMode eTextMode; + sal_uInt16 nX,nY; // for keyboard control + SvxIconViewFlags nFlags; + + void ClearFlags( SvxIconViewFlags nMask ) { nFlags &= ~nMask; } + void SetFlags( SvxIconViewFlags nMask ) { nFlags |= nMask; } + void AssignFlags( SvxIconViewFlags _nFlags ) { nFlags = _nFlags; } + + // set left neighbour (A <-> B ==> A <-> this <-> B) + void SetBacklink( SvxIconChoiceCtrlEntry* pA ) + { + pA->pflink->pblink = this; // X <- B + this->pflink = pA->pflink; // X -> B + this->pblink = pA; // A <- X + pA->pflink = this; // A -> X + } + // Unlink (A <-> this <-> B ==> A <-> B) + void Unlink() + { + this->pblink->pflink = this->pflink; + this->pflink->pblink = this->pblink; + this->pflink = nullptr; + this->pblink = nullptr; + } + +public: + SvxIconChoiceCtrlEntry( OUString aText, Image aImage ); + + const Image& GetImage () const { return aImage; } + void SetText ( const OUString& rText ) { aText = rText; } + const OUString& GetText () const { return aText; } + OUString VCL_DLLPUBLIC GetDisplayText() const; + void SetQuickHelpText( const OUString& rText ) { aQuickHelpText = rText; } + const OUString& GetQuickHelpText() const { return aQuickHelpText; } + + SvxIconChoiceCtrlTextMode GetTextMode() const { return eTextMode; } + SvxIconViewFlags GetFlags() const { return nFlags; } + bool IsSelected() const { return bool(nFlags & SvxIconViewFlags::SELECTED); } + bool IsFocused() const { return bool(nFlags & SvxIconViewFlags::FOCUSED); } + bool IsPosLocked() const { return bool(nFlags & SvxIconViewFlags::POS_LOCKED); } +}; + +class SvxIconChoiceCtrlColumnInfo +{ + tools::Long nWidth; + +public: + SvxIconChoiceCtrlColumnInfo() : + nWidth( 100 ) {} + SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& ); + + void SetWidth( tools::Long nWd ) { nWidth = nWd; } + tools::Long GetWidth() const { return nWidth; } +}; + + +/* + Window-Bits: + WB_ICON // Text beneath the icon + WB_SMALL_ICON // Text right to the icon, position does not mind + WB_DETAILS // Text right to the icon, limited positioning + WB_BORDER + WB_NOHIDESELECTION // Draw selection inactively, if not focused. + WB_NOHSCROLL + WB_NOVSCROLL + WB_NOSELECTION + WB_SMART_ARRANGE // Keep Visible-Area at arrange + WB_ALIGN_TOP // Align line vy line LTR + WB_ALIGN_LEFT // Align columns from top to bottom + WB_NODRAGSELECTION // No selection with tracking rectangle + WB_NOCOLUMNHEADER // No Headerbar in Details view (Headerbar not implemented) + WB_NOPOINTERFOCUS // No GrabFocus at MouseButtonDown + WB_HIGHLIGHTFRAME // The entry beneath the mouse will be highlighted + WB_NOASYNCSELECTHDL // Do not collect events -> Selection handlers will be called synchronously +*/ + +#define WB_ICON WB_RECTSTYLE +#define WB_SMALLICON WB_SMALLSTYLE +#define WB_DETAILS WB_VCENTER +#define WB_NOHSCROLL WB_SPIN +#define WB_NOVSCROLL WB_DRAG +#define WB_NOSELECTION WB_REPEAT +#define WB_NODRAGSELECTION WB_PATHELLIPSIS +#define WB_SMART_ARRANGE 0x01000000 // used to be WB_PASSWORD +#define WB_ALIGN_TOP WB_TOP +#define WB_ALIGN_LEFT WB_LEFT +#define WB_NOCOLUMNHEADER WB_CENTER +#define WB_HIGHLIGHTFRAME WB_IGNORETAB +#define WB_NOASYNCSELECTHDL WB_NOLABEL + +class MnemonicGenerator; + +class VCL_DLLPUBLIC SvtIconChoiceCtrl final : public Control +{ + friend class SvxIconChoiceCtrl_Impl; + + Link<SvtIconChoiceCtrl*,void> _aClickIconHdl; + std::unique_ptr<SvxIconChoiceCtrl_Impl, o3tl::default_delete<SvxIconChoiceCtrl_Impl>> _pImpl; + + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void Command( const CommandEvent& rCEvt ) override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + virtual void MouseMove( const MouseEvent& rMEvt ) override; + virtual void Resize() override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + void ClickIcon(); + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual void RequestHelp( const HelpEvent& rHEvt ) override; + static void DrawEntryImage( + SvxIconChoiceCtrlEntry const * pEntry, + const Point& rPos, + OutputDevice& rDev ); + + static OUString GetEntryText( SvxIconChoiceCtrlEntry const * pEntry ); + + virtual void FillLayoutData() const override; + + void CallImplEventListeners(VclEventId nEvent, void* pData); + +public: + + SvtIconChoiceCtrl( vcl::Window* pParent, WinBits nWinStyle ); + virtual ~SvtIconChoiceCtrl() override; + virtual void dispose() override; + + WinBits GetStyle() const; + void SetSelectionMode(SelectionMode eMode); + + void SetFont( const vcl::Font& rFont ); + void SetPointFont( const vcl::Font& rFont ); + + void SetClickHdl( const Link<SvtIconChoiceCtrl*,void>& rLink ) { _aClickIconHdl = rLink; } + + using Window::SetBackground; + void SetBackground( const Wallpaper& rWallpaper ); + + void ArrangeIcons(); + + + SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText, + const Image& rImage); + + void RemoveEntry(sal_Int32 nEntryListPos); + + bool DoKeyInput( const KeyEvent& rKEvt ); + + sal_Int32 GetEntryCount() const; + SvxIconChoiceCtrlEntry* GetEntry( sal_Int32 nPos ) const; + sal_Int32 GetEntryListPos( SvxIconChoiceCtrlEntry const * pEntry ) const; + using Window::SetCursor; + void SetCursor( SvxIconChoiceCtrlEntry* pEntry ); + SvxIconChoiceCtrlEntry* GetCursor() const; + + // sal_uLong is the position of the selected element in the list + SvxIconChoiceCtrlEntry* GetSelectedEntry() const; + +#ifdef DBG_UTIL + void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry ); +#endif + + tools::Rectangle GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const; + tools::Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const; + + void SetNoSelection(); + + // ACCESSIBILITY ========================================================== + + /** Creates and returns the accessible object of the Box. */ + virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/longcurr.hxx b/include/vcl/toolkit/longcurr.hxx new file mode 100644 index 0000000000..3206f39806 --- /dev/null +++ b/include/vcl/toolkit/longcurr.hxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <tools/bigint.hxx> +#include <vcl/toolkit/field.hxx> + +class LocaleDataWrapper; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) LongCurrencyFormatter : public FormatterBase +{ +public: + virtual ~LongCurrencyFormatter() override; + + virtual void Reformat() override; + virtual void ReformatAll() override; + + OUString const & GetCurrencySymbol() const; + + void SetDecimalDigits( sal_uInt16 nDigits ); + sal_uInt16 GetDecimalDigits() const { return mnDecimalDigits;} + void SetValue(const BigInt& rNewValue); + void SetUserValue( BigInt nNewValue ); + BigInt GetValue() const; + +protected: + BigInt mnLastValue; + BigInt mnMin; + BigInt mnMax; + + LongCurrencyFormatter(Edit* pEdit); +private: + friend bool ImplLongCurrencyReformat( const OUString&, BigInt const &, BigInt const &, sal_uInt16, const LocaleDataWrapper&, OUString&, LongCurrencyFormatter const & ); + SAL_DLLPRIVATE void ImpInit(); + + sal_uInt16 mnDecimalDigits; + +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) LongCurrencyBox final : public ComboBox, public LongCurrencyFormatter +{ +public: + LongCurrencyBox( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + + void Modify() override; + void ReformatAll() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/lstbox.hxx b/include/vcl/toolkit/lstbox.hxx new file mode 100644 index 0000000000..197122c254 --- /dev/null +++ b/include/vcl/toolkit/lstbox.hxx @@ -0,0 +1,268 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <sal/types.h> +#include <o3tl/typed_flags_set.hxx> +#include <vcl/dllapi.h> +#include <vcl/ctrl.hxx> + +class DataChangedEvent; +class NotifyEvent; +class UserDrawEvent; + +#define LISTBOX_APPEND (SAL_MAX_INT32) +#define LISTBOX_ENTRY_NOTFOUND (SAL_MAX_INT32) +#define LISTBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1) + +// the following defines can be used for the SetEntryFlags() +// and GetEntryFlags() methods + +// !! Do not use these flags for user data as they are reserved !! +// !! to change the internal behaviour of the ListBox implementation !! +// !! for specific entries. !! + +enum class ListBoxEntryFlags +{ + NONE = 0x0000, +/** this flag disables a selection of an entry completely. It is not + possible to select such entries either from the user interface + nor from the ListBox methods. Cursor traveling is handled correctly. + This flag can be used to add titles to a ListBox. +*/ + DisableSelection = 0x0001, + +/** this flag can be used to make an entry multiline capable + A normal entry is single line and will therefore be clipped + at the right listbox border. Setting this flag enables + word breaks for the entry text. +*/ + MultiLine = 0x0002, + +/** this flags lets the item be drawn disabled (e.g. in grey text) + usage only guaranteed with ListBoxEntryFlags::DisableSelection +*/ + DrawDisabled = 0x0004, +}; +namespace o3tl +{ + template<> struct typed_flags<ListBoxEntryFlags> : is_typed_flags<ListBoxEntryFlags, 0x0007> {}; +} + +class Image; +class ImplListBox; +class ImplListBoxFloatingWindow; +class ImplBtn; +class ImplWin; +class ImplListBoxWindow; + +/// A widget used to choose from a list of items and which has no entry. +class VCL_DLLPUBLIC ListBox : public Control +{ +private: + VclPtr<ImplListBox> mpImplLB; + VclPtr<ImplListBoxFloatingWindow> mpFloatWin; + VclPtr<ImplWin> mpImplWin; + VclPtr<ImplBtn> mpBtn; + sal_uInt16 mnDDHeight; + sal_Int32 m_nMaxWidthChars; + Link<ListBox&,void> maSelectHdl; + sal_uInt16 mnLineCount; + + bool mbDDAutoSize : 1; + +private: + SAL_DLLPRIVATE void ImplInitListBoxData(); + + DECL_DLLPRIVATE_LINK( ImplSelectHdl, LinkParamNone*, void ); + DECL_DLLPRIVATE_LINK( ImplScrollHdl, ImplListBox*, void ); + DECL_DLLPRIVATE_LINK( ImplCancelHdl, LinkParamNone*, void ); + DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, ImplListBoxWindow*, void ); + DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, FloatingWindow*, void ); + DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, sal_Int32, void ); + DECL_DLLPRIVATE_LINK( ImplFocusHdl, sal_Int32, void ); + DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl, LinkParamNone*, void ); + + DECL_DLLPRIVATE_LINK( ImplClickBtnHdl, void*, void ); + +protected: + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); + bool IsDropDownBox() const { return mpFloatWin != nullptr; } + +protected: + explicit ListBox( WindowType nType ); + + virtual void FillLayoutData() const override; + +public: + explicit ListBox( vcl::Window* pParent, WinBits nStyle = WB_BORDER ); + virtual ~ListBox() override; + virtual void dispose() override; + + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + void Select(); + void DoubleClick(); + virtual void GetFocus() override; + virtual void LoseFocus() override; + + virtual const Wallpaper& GetDisplayBackground() const override; + + virtual void setPosSizePixel( tools::Long nX, tools::Long nY, + tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override; + + tools::Rectangle GetDropDownPosSizePixel() const; + + void AdaptDropDownLineCountToMaximum(); + void SetDropDownLineCount( sal_uInt16 nLines ); + sal_uInt16 GetDropDownLineCount() const; + + void EnableAutoSize( bool bAuto ); + bool IsAutoSizeEnabled() const { return mbDDAutoSize; } + + sal_Int32 InsertEntry( const OUString& rStr, sal_Int32 nPos = LISTBOX_APPEND ); + sal_Int32 InsertEntry( const OUString& rStr, const Image& rImage, sal_Int32 nPos = LISTBOX_APPEND ); + void RemoveEntry( sal_Int32 nPos ); + + void Clear(); + + sal_Int32 GetEntryPos( std::u16string_view rStr ) const; + Image GetEntryImage( sal_Int32 nPos ) const; + OUString GetEntry( sal_Int32 nPos ) const; + sal_Int32 GetEntryCount() const; + + void SelectEntry( std::u16string_view rStr, bool bSelect = true ); + void SelectEntryPos( sal_Int32 nPos, bool bSelect = true ); + void SelectEntriesPos( const std::vector<sal_Int32>& rPositions, bool bSelect = true ); + + sal_Int32 GetSelectedEntryCount() const; + OUString GetSelectedEntry( sal_Int32 nSelIndex = 0 ) const; + sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const; + + bool IsEntryPosSelected( sal_Int32 nPos ) const; + void SetNoSelection(); + + void SetEntryData( sal_Int32 nPos, void* pNewData ); + void* GetEntryData( sal_Int32 nPos ) const; + + /** this methods stores a combination of flags from the + ListBoxEntryFlags::* defines at the given entry. + See description of the possible ListBoxEntryFlags::* flags + for details. + Do not use these flags for user data as they are reserved + to change the internal behaviour of the ListBox implementation + for specific entries. + */ + void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags ); + + void SetTopEntry( sal_Int32 nPos ); + sal_Int32 GetTopEntry() const; + + /** + * Removes existing separators, and sets the position of the + * one and only separator. + */ + void SetSeparatorPos( sal_Int32 n ); + /** + * Gets the position of the separator which was added first. + * Returns LISTBOX_ENTRY_NOTFOUND if there is no separator. + */ + sal_Int32 GetSeparatorPos() const; + + /** + * Adds a new separator at the given position n. + */ + void AddSeparator( sal_Int32 n ); + + bool IsTravelSelect() const; + bool IsInDropDown() const; + void ToggleDropDown(); + + void EnableMultiSelection( bool bMulti ); + bool IsMultiSelectionEnabled() const; + void SetHighlightColor(const Color& rColor); + void SetHighlightTextColor(const Color& rColor); + + void SetReadOnly( bool bReadOnly = true ); + bool IsReadOnly() const; + + tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const; + + void SetSelectHdl( const Link<ListBox&,void>& rLink ) { maSelectHdl = rLink; } + + Size CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown + Size CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown + virtual Size GetOptimalSize() const override; + Size CalcAdjustedSize( const Size& rPrefSize ) const; + Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const; + void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const; + + sal_uInt16 GetDisplayLineCount() const; + + /** checks whether a certain point lies within the bounds of + a listbox item and returns the item as well as the character position + the point is at. + + <p>If the point is inside an item the item pos is put into <code>rPos</code> and + the item-relative character index is returned. If the point is not inside + an item -1 is returned and rPos is unchanged.</p> + + @param rPoint + tells the point for which an item is requested. + + @param rPos + gets the item at the specified point <code>rPoint</code> + + @returns + the item-relative character index at point <code>rPos</code> or -1 + if no item is at that point. + */ + using Control::GetIndexForPoint; + tools::Long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const; + + void setMaxWidthChars(sal_Int32 nWidth); + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + virtual FactoryFunction GetUITestFactory() const override; + + virtual void DumpAsPropertyTree(tools::JsonWriter&) override; +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) MultiListBox final : public ListBox +{ +public: + explicit MultiListBox( vcl::Window* pParent, WinBits nStyle ); + +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/menubtn.hxx b/include/vcl/toolkit/menubtn.hxx new file mode 100644 index 0000000000..2af263fae2 --- /dev/null +++ b/include/vcl/toolkit/menubtn.hxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/toolkit/button.hxx> +#include <vcl/dllapi.h> +#include <memory> + +class Timer; +class PopupMenu; + +class VCL_DLLPUBLIC MenuButton : public PushButton +{ +private: + friend class VclBuilder; + + std::unique_ptr<Timer> mpMenuTimer; + VclPtr<PopupMenu> mpMenu; + VclPtr<Window> mpFloatingWindow; + OUString msCurItemIdent; + sal_uInt16 mnCurItemId; + bool mbDelayMenu; + bool mbStartingMenu; + Link<MenuButton*,void> maActivateHdl; + Link<MenuButton*,void> maSelectHdl; + + DECL_DLLPRIVATE_LINK( ImplMenuTimeoutHdl, Timer*, void ); + + MenuButton( const MenuButton & ) = delete; + MenuButton& operator=( const MenuButton & ) = delete; + +protected: + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + // override in derived classes to set up anything needed to execute menu + virtual void PrepareExecute() {}; + +public: + explicit MenuButton( vcl::Window* pParent, WinBits nStyle = 0 ); + virtual ~MenuButton() override; + virtual void dispose() override; + + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + + virtual void Activate() override; + void Select(); + + void ExecuteMenu(); + bool InPopupMode() const; + void CancelMenu(); + + //if false then the whole button launches the menu + //if true, then the button has a separator + //where the right portion launches the menu immediately + //where the left portion activates the underlying Button handlers + //before launching the menu in an idle, allowing it to be cancelled + //before being shown + void SetDelayMenu(bool bDelay) { mbDelayMenu = bDelay; } + + void SetPopupMenu(PopupMenu* pNewMenu); + PopupMenu* GetPopupMenu() const { return mpMenu; } + + void SetPopover(Window* pWindow); + Window* GetPopover() { return mpFloatingWindow.get(); } + + OUString const& GetCurItemIdent() const { return msCurItemIdent; } + + void SetActivateHdl( const Link<MenuButton *, void>& rLink ) { maActivateHdl = rLink; } + void SetSelectHdl( const Link<MenuButton *, void>& rLink ) { maSelectHdl = rLink; } + + virtual FactoryFunction GetUITestFactory() const override; + + void SetCurItemId(); + + virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/morebtn.hxx b/include/vcl/toolkit/morebtn.hxx new file mode 100644 index 0000000000..ca2a4b21d8 --- /dev/null +++ b/include/vcl/toolkit/morebtn.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/toolkit/button.hxx> +#include <memory> + +struct ImplMoreButtonData; + + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) MoreButton final : public PushButton +{ + std::unique_ptr<ImplMoreButtonData> mpMBData; + bool mbState; + + MoreButton( const MoreButton & ) = delete; + MoreButton& operator=( const MoreButton & ) = delete; + SAL_DLLPRIVATE void ShowState(); + + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + +public: + explicit MoreButton( vcl::Window* pParent, WinBits nStyle ); + virtual ~MoreButton() override; + virtual void dispose() override; + + void Click() override; + + using PushButton::SetState; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/prgsbar.hxx b/include/vcl/toolkit/prgsbar.hxx new file mode 100644 index 0000000000..1fcba74fda --- /dev/null +++ b/include/vcl/toolkit/prgsbar.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/window.hxx> + +/************************************************************************* + * + * class ProgressBar + * + * this class is used to display the ProgressBar + * + * ----------------------------------------------------------------------- + * + * WinBits + * + * WB_BORDER border around the window + * WB_3DLOOK 3D representation + * + * ----------------------------------------------------------------------- + * + * Methods + * + * Use SetValue() to set a percentage between 0 and 100. A value larger + * than 100 will cause the last rectangle to start flashing + * + ************************************************************************/ + + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) ProgressBar final : public vcl::Window +{ +public: + enum class BarStyle + { + Progress, + Level, + }; + +private: + Point maPos; + tools::Long mnPrgsWidth; + tools::Long mnPrgsHeight; + sal_uInt16 mnPercent; + sal_uInt16 mnPercentCount; + bool mbCalcNew; + BarStyle meBarStyle; + + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit(); + SAL_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground ); + SAL_DLLPRIVATE void ImplDrawProgress(vcl::RenderContext& rRenderContext, sal_uInt16 nNewPerc); + +public: + ProgressBar( vcl::Window* pParent, WinBits nWinBits, BarStyle eBarStyle ); + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nStateChange ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual Size GetOptimalSize() const override; + + void SetValue( sal_uInt16 nNewPercent ); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/roadmap.hxx b/include/vcl/toolkit/roadmap.hxx new file mode 100644 index 0000000000..ef1cec2501 --- /dev/null +++ b/include/vcl/toolkit/roadmap.hxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/ctrl.hxx> +#include <vcl/toolkit/imgctrl.hxx> +#include <memory> + +class Bitmap; + +namespace vcl +{ + +struct RoadmapTypes +{ +public: + typedef sal_Int16 ItemId; + typedef sal_Int32 ItemIndex; +}; + +class HyperLabel; +class RoadmapImpl; +class RoadmapItem; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) ORoadmap final : public Control, public RoadmapTypes +{ +public: + ORoadmap( vcl::Window* _pParent, WinBits _nWinStyle ); + virtual ~ORoadmap( ) override; + virtual void dispose() override; + + void SetRoadmapBitmap( const BitmapEx& maBitmap ); + + void EnableRoadmapItem( ItemId _nItemId, bool _bEnable ); + + void ChangeRoadmapItemLabel( ItemId _nID, const OUString& sLabel ); + void ChangeRoadmapItemID( ItemId _nID, ItemId NewID ); + + void SetRoadmapInteractive( bool _bInteractive ); + bool IsRoadmapInteractive() const; + + void SetRoadmapComplete( bool _bComplete ); + bool IsRoadmapComplete() const; + + ItemIndex GetItemCount() const; + ItemId GetItemID( ItemIndex _nIndex ) const; + + void InsertRoadmapItem( ItemIndex Index, const OUString& RoadmapItem, ItemId _nUniqueId, bool _bEnabled ); + void ReplaceRoadmapItem( ItemIndex Index, const OUString& RoadmapItem, ItemId _nUniqueId, bool _bEnabled ); + void DeleteRoadmapItem( ItemIndex _nIndex ); + + ItemId GetCurrentRoadmapItemID() const; + bool SelectRoadmapItemByID(ItemId nItemID, bool bGrabFocus = true); + + void SetItemSelectHdl( const Link<LinkParamNone*,void>& _rHdl ); + Link<LinkParamNone*,void> const & GetItemSelectHdl( ) const; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual void GetFocus() override; + virtual void ApplySettings( vcl::RenderContext& rRenderContext ) override; + +private: + bool PreNotify( NotifyEvent& rNEvt ) override; + + /// called when an item has been selected by any means + void Select(); + + DECL_DLLPRIVATE_LINK(ImplClickHdl, HyperLabel*, void); + + RoadmapItem* GetByIndex( ItemIndex _nItemIndex ); + const RoadmapItem* GetByIndex( ItemIndex _nItemIndex ) const; + + RoadmapItem* GetByID( ItemId _nID ); + const RoadmapItem* GetByID( ItemId _nID ) const; + RoadmapItem* GetPreviousHyperLabel( ItemIndex Index); + + void DrawHeadline(vcl::RenderContext& rRenderContext); + void DeselectOldRoadmapItems(); + ItemId GetNextAvailableItemId( ItemIndex NewIndex ); + ItemId GetPreviousAvailableItemId( ItemIndex NewIndex ); + RoadmapItem* GetByPointer(vcl::Window const * pWindow); + RoadmapItem* InsertHyperLabel( ItemIndex Index, const OUString& _aStr, ItemId RMID, bool _bEnabled, bool _bIncomplete ); + void UpdatefollowingHyperLabels( ItemIndex Index ); + + // Window overridables + void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect) override; + void implInit(vcl::RenderContext& rRenderContext); + + std::unique_ptr<RoadmapImpl> m_pImpl; +}; + +} // namespace vcl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/scrbar.hxx b/include/vcl/toolkit/scrbar.hxx new file mode 100644 index 0000000000..6981b64fa6 --- /dev/null +++ b/include/vcl/toolkit/scrbar.hxx @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <vcl/ctrl.hxx> +#include <vcl/scrollable.hxx> +#include <memory> + +struct ImplScrollBarData; + +class VCL_DLLPUBLIC ScrollBar final : public Control + , public Scrollable +{ +private: + tools::Rectangle maBtn1Rect; + tools::Rectangle maBtn2Rect; + tools::Rectangle maPage1Rect; + tools::Rectangle maPage2Rect; + tools::Rectangle maThumbRect; + tools::Rectangle maTrackRect; + std::unique_ptr<ImplScrollBarData> mpData; + tools::Long mnStartPos; + tools::Long mnMouseOff; + tools::Long mnThumbPixRange; + tools::Long mnThumbPixPos; + tools::Long mnThumbPixSize; + tools::Long mnMinRange; + tools::Long mnMaxRange; + tools::Long mnThumbPos; + tools::Long mnVisibleSize; + tools::Long mnLineSize; + tools::Long mnPageSize; + tools::Long mnDelta; + sal_uInt16 mnStateFlags; + ScrollType meScrollType; + bool mbCalcSize; + bool mbFullDrag; + Link<ScrollBar*,void> maScrollHdl; + Link<ScrollBar*,void> maEndScrollHdl; + + SAL_DLLPRIVATE tools::Rectangle* ImplFindPartRect( const Point& rPt ); + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + SAL_DLLPRIVATE void ImplInitStyle( WinBits nStyle ); + SAL_DLLPRIVATE void ImplUpdateRects( bool bUpdate = true ); + SAL_DLLPRIVATE tools::Long ImplCalcThumbPos( tools::Long nPixPos ) const; + SAL_DLLPRIVATE tools::Long ImplCalcThumbPosPix( tools::Long nPos ) const; + SAL_DLLPRIVATE void ImplCalc( bool bUpdate = true ); + SAL_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext); + using Window::ImplScroll; + SAL_DLLPRIVATE tools::Long ImplScroll( tools::Long nNewPos, bool bCallEndScroll ); + SAL_DLLPRIVATE tools::Long ImplDoAction( bool bCallEndScroll ); + SAL_DLLPRIVATE void ImplDoMouseAction( const Point& rPos, bool bCallAction = true ); + SAL_DLLPRIVATE void ImplInvert(); + SAL_DLLPRIVATE bool ImplDrawNative(vcl::RenderContext& rRenderContext, sal_uInt16 SystemTextColorFlags); + SAL_DLLPRIVATE void ImplDragThumb( const Point& rMousePos ); + SAL_DLLPRIVATE Size getCurrentCalcSize() const; + DECL_DLLPRIVATE_LINK( ImplAutoTimerHdl, Timer*, void ); + +public: + explicit ScrollBar( vcl::Window* pParent, WinBits nStyle = WB_VERT ); + virtual ~ScrollBar() override; + virtual void dispose() override; + + virtual void MouseButtonDown(const MouseEvent& rMEvt) override; + virtual void Tracking(const TrackingEvent& rTEvt) override; + virtual void KeyInput(const KeyEvent& rKEvt) override; + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; + virtual void Draw(OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags) override; + virtual void Move() override; + virtual void Resize() override; + virtual void StateChanged(StateChangedType nType) override; + virtual void DataChanged(const DataChangedEvent& rDCEvt) override; + virtual bool PreNotify(NotifyEvent& rNEvt) override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; + + using Window::Scroll; + void Scroll(); + void EndScroll(); + + tools::Long DoScroll( tools::Long nNewPos ) override; + tools::Long DoScrollAction( ScrollType eScrollType ); + + void EnableDrag() { mbFullDrag = true; } + + void SetRangeMin( tools::Long nNewRange ) override; + tools::Long GetRangeMin() const override { return mnMinRange; } + void SetRangeMax( tools::Long nNewRange ) override; + tools::Long GetRangeMax() const override { return mnMaxRange; } + void SetRange( const Range& rRange ) override; + Range GetRange() const override { return Range( GetRangeMin(), GetRangeMax() ); } + void SetThumbPos( tools::Long nThumbPos ) override; + tools::Long GetThumbPos() const override { return mnThumbPos; } + void SetLineSize( tools::Long nNewSize ) override { mnLineSize = nNewSize; } + tools::Long GetLineSize() const override { return mnLineSize; } + void SetPageSize( tools::Long nNewSize ) override { mnPageSize = nNewSize; } + tools::Long GetPageSize() const override { return mnPageSize; } + void SetVisibleSize( tools::Long nNewSize ) override; + tools::Long GetVisibleSize() const override { return mnVisibleSize; } + + bool Inactive() const override; + + tools::Long GetDelta() const { return mnDelta; } + ScrollType GetType() const { return meScrollType; } + + void SetScrollHdl( const Link<ScrollBar*,void>& rLink ) { maScrollHdl = rLink; } + const Link<ScrollBar*,void>& GetScrollHdl() const { return maScrollHdl; } + void SetEndScrollHdl( const Link<ScrollBar*,void>& rLink ) { maEndScrollHdl = rLink; } + + virtual Size GetOptimalSize() const override; +}; + + +class VCL_DLLPUBLIC ScrollBarBox final : public vcl::Window +{ +private: + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; + +public: + explicit ScrollBarBox( vcl::Window* pParent, WinBits nStyle = 0 ); + + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/spin.hxx b/include/vcl/toolkit/spin.hxx new file mode 100644 index 0000000000..bc1e14109f --- /dev/null +++ b/include/vcl/toolkit/spin.hxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/ctrl.hxx> +#include <vcl/timer.hxx> + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) SpinButton final : public Control +{ +private: + AutoTimer maRepeatTimer; + tools::Rectangle maUpperRect; + tools::Rectangle maLowerRect; + tools::Rectangle maFocusRect; + bool mbRepeat : 1; + bool mbUpperIn : 1; + bool mbLowerIn : 1; + bool mbInitialUp : 1; + bool mbInitialDown : 1; + bool mbHorz : 1; + bool mbUpperIsFocused : 1; + tools::Long mnMinRange; + tools::Long mnMaxRange; + tools::Long mnValue; + tools::Long mnValueStep; + + SAL_DLLPRIVATE tools::Rectangle* ImplFindPartRect( const Point& rPt ); + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + DECL_DLLPRIVATE_LINK( ImplTimeout, Timer*, void ); + +public: + explicit SpinButton( vcl::Window* pParent, WinBits nStyle ); + + void Up(); + void Down(); + + virtual void Resize() override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + virtual void MouseMove( const MouseEvent& rMEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void StateChanged( StateChangedType nStateChange ) override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + + void SetRangeMin( tools::Long nNewRange ); + tools::Long GetRangeMin() const { return mnMinRange; } + void SetRangeMax( tools::Long nNewRange ); + tools::Long GetRangeMax() const { return mnMaxRange; } + void SetRange( const Range& rRange ); + void SetValue( tools::Long nValue ); + tools::Long GetValue() const { return mnValue; } + void SetValueStep( tools::Long nNewStep ) { mnValueStep = nNewStep; } + tools::Long GetValueStep() const { return mnValueStep; } + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + +private: + // moves the focus to the upper or lower rect. Return sal_True if the focus rect actually changed. + SAL_DLLPRIVATE bool ImplMoveFocus( bool _bUpper ); + SAL_DLLPRIVATE void ImplCalcFocusRect( bool _bUpper ); + + SAL_DLLPRIVATE bool ImplIsUpperEnabled( ) const + { + return mnValue + mnValueStep <= mnMaxRange; + } + SAL_DLLPRIVATE bool ImplIsLowerEnabled( ) const + { + return mnValue >= mnMinRange + mnValueStep; + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/spinfld.hxx b/include/vcl/toolkit/spinfld.hxx new file mode 100644 index 0000000000..499baa4ff5 --- /dev/null +++ b/include/vcl/toolkit/spinfld.hxx @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <vcl/toolkit/edit.hxx> +#include <vcl/timer.hxx> + +class VCL_DLLPUBLIC SpinField : public Edit +{ +public: + explicit SpinField( vcl::Window* pParent, WinBits nWinStyle, WindowType nType = WindowType::SPINFIELD ); + virtual ~SpinField() override; + virtual void dispose() override; + + virtual bool ShowDropDown( bool bShow ); + + virtual void Up(); + virtual void Down(); + virtual void First(); + virtual void Last(); + + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + virtual void MouseMove( const MouseEvent& rMEvt ) override; + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void Draw( OutputDevice* pDev, const Point& rPos,SystemTextColorFlags nFlags ) override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nType ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + + void SetUpHdl( const Link<SpinField&,void>& rLink ) { maUpHdlLink = rLink; } + void SetDownHdl( const Link<SpinField&,void>& rLink ) { maDownHdlLink = rLink; } + + virtual Size CalcMinimumSize() const override; + virtual Size CalcMinimumSizeForText(const OUString &rString) const override; + virtual Size GetOptimalSize() const override; + virtual Size CalcSize(sal_Int32 nChars) const override; + + virtual FactoryFunction GetUITestFactory() const override; + + SAL_DLLPRIVATE void SetUpperEnabled(bool bEnabled); + SAL_DLLPRIVATE void SetLowerEnabled(bool bEnabled); + SAL_DLLPRIVATE bool IsUpperEnabled() const { return mbUpperEnabled; } + SAL_DLLPRIVATE bool IsLowerEnabled() const { return mbLowerEnabled; } + +protected: + using Window::ImplInit; + SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); + + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + + void EndDropDown(); + + virtual void FillLayoutData() const override; + tools::Rectangle * ImplFindPartRect( const Point& rPt ); + +private: + DECL_DLLPRIVATE_LINK( ImplTimeout, Timer*, void ); + SAL_DLLPRIVATE void ImplInitSpinFieldData(); + SAL_DLLPRIVATE void ImplCalcButtonAreas( const OutputDevice* pDev, const Size& rOutSz, tools::Rectangle& rDDArea, tools::Rectangle& rSpinUpArea, tools::Rectangle& rSpinDownArea ); + + tools::Rectangle maUpperRect; + tools::Rectangle maLowerRect; + tools::Rectangle maDropDownRect; // not yet attached ... + + VclPtr<Edit> mpEdit; + AutoTimer maRepeatTimer; + Link<SpinField&,void> maUpHdlLink; + Link<SpinField&,void> maDownHdlLink; + bool mbRepeat:1, + mbSpin:1, + mbInitialUp:1, + mbInitialDown:1, + mbUpperIn:1, + mbLowerIn:1, + mbInDropDown:1, + mbUpperEnabled:1, + mbLowerEnabled:1; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/svlbitm.hxx b/include/vcl/toolkit/svlbitm.hxx new file mode 100644 index 0000000000..c9aaaa46d9 --- /dev/null +++ b/include/vcl/toolkit/svlbitm.hxx @@ -0,0 +1,287 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <memory> +#include <vcl/dllapi.h> +#include <tools/link.hxx> +#include <vcl/image.hxx> +#include <vcl/toolkit/treelistbox.hxx> +#include <o3tl/typed_flags_set.hxx> + +class SvTreeListEntry; +class SvLBoxButton; + + +enum class SvBmp +{ + UNCHECKED = 0, + CHECKED = 1, + TRISTATE = 2, + HIUNCHECKED = 3, + HICHECKED = 4, + HITRISTATE = 5 +}; + +enum class SvItemStateFlags +{ + NONE = 0x00, + UNCHECKED = 0x01, + CHECKED = 0x02, + TRISTATE = 0x04, + HIGHLIGHTED = 0x08 +}; +namespace o3tl +{ + template<> struct typed_flags<SvItemStateFlags> : is_typed_flags<SvItemStateFlags, 0x0f> {}; +} + +struct SvLBoxButtonData_Impl; + +class SvLBoxButtonData +{ +private: + Link<SvLBoxButtonData*,void> aLink; + tools::Long nWidth; + tools::Long nHeight; + std::unique_ptr<SvLBoxButtonData_Impl> pImpl; + bool bDataOk; + std::vector<Image> aBmps; // indices s. constants BMP_... + + void SetWidthAndHeight(); + void InitData( bool _bRadioBtn, const Control* pControlForSettings ); +public: + // include creating default images (CheckBox or RadioButton) + SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn ); + + ~SvLBoxButtonData(); + + static SvBmp GetIndex( SvItemStateFlags nItemState ); + tools::Long Width(); + tools::Long Height(); + void SetLink( const Link<SvLBoxButtonData*,void>& rLink) { aLink=rLink; } + bool IsRadio() const; + // as buttons are not derived from LinkHdl + void CallLink(); + + void StoreButtonState(SvTreeListEntry* pActEntry, SvLBoxButton* pActBox); + static SvButtonState ConvertToButtonState( SvItemStateFlags nItemFlags ); + + SvTreeListEntry* GetActEntry() const; + SvLBoxButton* GetActBox() const; + + void SetImage(SvBmp nIndex, const Image& aImage) { aBmps[static_cast<int>(nIndex)] = aImage; } + Image& GetImage(SvBmp nIndex) { return aBmps[static_cast<int>(nIndex)]; } + + void SetDefaultImages( const Control* pControlForSettings ); + // set images according to the color scheme of the Control + // pControlForSettings == NULL: settings are taken from Application + bool HasDefaultImages() const; +}; + +// ********************************************************************** + +class VCL_DLLPUBLIC SvLBoxString : public SvLBoxItem +{ +private: + bool mbEmphasized; + bool mbCustom; + double mfAlign; +protected: + OUString maText; + +public: + SvLBoxString(OUString aText); + SvLBoxString(); + virtual ~SvLBoxString() override; + + virtual SvLBoxItemType GetType() const override; + virtual void InitViewData(SvTreeListBox* pView, + SvTreeListEntry* pEntry, + SvViewDataItem* pViewData = nullptr) override; + + virtual int CalcWidth(const SvTreeListBox* pView) const override; + + void Align(double fAlign) { mfAlign = fAlign; } + + void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; } + bool IsEmphasized() const { return mbEmphasized; } + + void SetCustomRender() { mbCustom = true; } + + const OUString& GetText() const + { + return maText; + } + void SetText(const OUString& rText) + { + maText = rText; + } + + virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev, + vcl::RenderContext& rRenderContext, + const SvViewDataEntry* pView, + const SvTreeListEntry& rEntry) override; + + virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override; +}; + +class SvLBoxButton final : public SvLBoxItem +{ + bool isVis; + SvLBoxButtonData* pData; + SvItemStateFlags nItemFlags; + + static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::RenderContext const & pRenderContext); +public: + // An SvLBoxButton can be of two different kinds: an + // enabled checkbox (the normal kind), or a static image + // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored + // for that kind). + SvLBoxButton( SvLBoxButtonData* pBData ); + SvLBoxButton(); + virtual ~SvLBoxButton() override; + virtual void InitViewData(SvTreeListBox* pView, + SvTreeListEntry* pEntry, + SvViewDataItem* pViewData = nullptr) override; + + virtual SvLBoxItemType GetType() const override; + void ClickHdl( SvTreeListEntry* ); + + virtual void Paint(const Point& rPos, + SvTreeListBox& rOutDev, + vcl::RenderContext& rRenderContext, + const SvViewDataEntry* pView, + const SvTreeListEntry& rEntry) override; + + virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override; + + SvItemStateFlags GetButtonFlags() const + { + return nItemFlags; + } + bool IsStateChecked() const + { + return bool(nItemFlags & SvItemStateFlags::CHECKED); + } + bool IsStateUnchecked() const + { + return bool(nItemFlags & SvItemStateFlags::UNCHECKED); + } + bool IsStateTristate() const + { + return bool(nItemFlags & SvItemStateFlags::TRISTATE); + } + bool IsStateHilighted() const + { + return bool(nItemFlags & SvItemStateFlags::HIGHLIGHTED); + } + void SetStateChecked(); + void SetStateUnchecked(); + void SetStateTristate(); + void SetStateHilighted(bool bHilight); +}; + +inline void SvLBoxButton::SetStateChecked() +{ + nItemFlags &= SvItemStateFlags::HIGHLIGHTED; + nItemFlags |= SvItemStateFlags::CHECKED; +} + +inline void SvLBoxButton::SetStateUnchecked() +{ + nItemFlags &= SvItemStateFlags::HIGHLIGHTED; + nItemFlags |= SvItemStateFlags::UNCHECKED; +} +inline void SvLBoxButton::SetStateTristate() +{ + nItemFlags &= SvItemStateFlags::HIGHLIGHTED; + nItemFlags |= SvItemStateFlags::TRISTATE; +} +inline void SvLBoxButton::SetStateHilighted( bool bHilight ) +{ + if ( bHilight ) + nItemFlags |= SvItemStateFlags::HIGHLIGHTED; + else + nItemFlags &= ~SvItemStateFlags::HIGHLIGHTED; +} + +struct SvLBoxContextBmp_Impl; + +class VCL_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem +{ + std::unique_ptr<SvLBoxContextBmp_Impl> m_pImpl; +public: + SvLBoxContextBmp(const Image& aBmp1, + const Image& aBmp2, + bool bExpanded); + SvLBoxContextBmp(); + virtual ~SvLBoxContextBmp() override; + + virtual SvLBoxItemType GetType() const override; + virtual void InitViewData(SvTreeListBox* pView, + SvTreeListEntry* pEntry, + SvViewDataItem* pViewData = nullptr) override; + virtual void Paint(const Point& rPos, + SvTreeListBox& rOutDev, + vcl::RenderContext& rRenderContext, + const SvViewDataEntry* pView, + const SvTreeListEntry& rEntry) override; + + virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override; + + void SetModeImages(const Image& rBitmap1, const Image& rBitmap2); + + inline void SetBitmap1(const Image& rImage); + inline void SetBitmap2(const Image& rImage); + inline const Image& GetBitmap1() const; + inline const Image& GetBitmap2() const; + +private: + Image& implGetImageStore(bool bFirst); +}; + +inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage) +{ + implGetImageStore(true) = _rImage; +} + +inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage) +{ + implGetImageStore(false) = _rImage; +} + +inline const Image& SvLBoxContextBmp::GetBitmap1() const +{ + Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true); + return rImage; +} + +inline const Image& SvLBoxContextBmp::GetBitmap2() const +{ + Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false); + return rImage; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/svtabbx.hxx b/include/vcl/toolkit/svtabbx.hxx new file mode 100644 index 0000000000..1fd7b8b16e --- /dev/null +++ b/include/vcl/toolkit/svtabbx.hxx @@ -0,0 +1,207 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <vcl/toolkit/treelistbox.hxx> +#include <vcl/accessibletableprovider.hxx> + +#include <tools/debug.hxx> + +#include <memory> +#include <vector> + +enum class SvTabJustify +{ + AdjustRight = static_cast<int>(SvLBoxTabFlags::ADJUST_RIGHT), + AdjustLeft = static_cast<int>(SvLBoxTabFlags::ADJUST_LEFT), + AdjustCenter = static_cast<int>(SvLBoxTabFlags::ADJUST_CENTER) +}; + +class VCL_DLLPUBLIC SvTabListBox : public SvTreeListBox +{ +private: + std::vector<SvLBoxTab> mvTabList; + OUString aCurEntry; + +protected: + static std::u16string_view GetToken( std::u16string_view sStr, sal_Int32 &nIndex ); + + virtual void SetTabs() override; + virtual void InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&) override; + + OUString GetTabEntryText( sal_uInt32 nPos, sal_uInt16 nCol ) const; + SvTreeListEntry* GetEntryOnPos( sal_uInt32 _nEntryPos ) const; + SvTreeListEntry* GetChildOnPos( SvTreeListEntry* _pParent, sal_uInt32 _nEntryPos, sal_uInt32& _rPos ) const; + +public: + SvTabListBox( vcl::Window* pParent, WinBits ); + virtual ~SvTabListBox() override; + virtual void dispose() override; + void SetTabs(sal_uInt16 nTabs, tools::Long const pTabPositions[], MapUnit = MapUnit::MapAppFont); + using SvTreeListBox::GetTab; + tools::Long GetLogicTab( sal_uInt16 nTab ); + + virtual SvTreeListEntry* InsertEntry( const OUString& rText, SvTreeListEntry* pParent = nullptr, + bool bChildrenOnDemand = false, + sal_uInt32 nPos=TREELIST_APPEND, void* pUserData = nullptr ) override; + + virtual SvTreeListEntry* InsertEntryToColumn( const OUString&, SvTreeListEntry* pParent, + sal_uInt32 nPos, sal_uInt16 nCol, void* pUserData = nullptr ); + + virtual OUString GetEntryText( SvTreeListEntry* pEntry ) const override; + static OUString GetEntryText( const SvTreeListEntry*, sal_uInt16 nCol ); + OUString GetEntryText( sal_uInt32 nPos, sal_uInt16 nCol = 0xffff ) const; + using SvTreeListBox::SetEntryText; + OUString GetCellText( sal_uInt32 nPos, sal_uInt16 nCol ) const; + sal_uInt32 GetEntryPos( const SvTreeListEntry* pEntry ) const; + + void SetTabJustify( sal_uInt16 nTab, SvTabJustify ); + void SetTabEditable( sal_uInt16 nTab, bool bEditable ); + + virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +// class SvHeaderTabListBox --------------------------------------------------- + +class HeaderBar; +namespace vcl { + struct SvHeaderTabListBoxImpl; +} + +class VCL_DLLPUBLIC SvHeaderTabListBox : public SvTabListBox, public vcl::IAccessibleTableProvider +{ +private: + bool m_bFirstPaint; + std::unique_ptr<::vcl::SvHeaderTabListBoxImpl> m_pImpl; + ::vcl::IAccessibleTabListBox* m_pAccessible; + std::vector<css::uno::Reference<css::accessibility::XAccessible>> m_aAccessibleChildren; + + DECL_DLLPRIVATE_LINK( ScrollHdl_Impl, SvTreeListBox*, void ); + DECL_DLLPRIVATE_LINK( CreateAccessibleHdl_Impl, HeaderBar*, void ); + + void RecalculateAccessibleChildren(); + +public: + SvHeaderTabListBox( vcl::Window* pParent, WinBits nBits ); + virtual ~SvHeaderTabListBox() override; + virtual void dispose() override; + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override; + + void InitHeaderBar(HeaderBar* pHeaderBar); + HeaderBar* GetHeaderBar(); + static bool IsItemChecked( SvTreeListEntry* pEntry, sal_uInt16 nCol ); + + virtual SvTreeListEntry* InsertEntryToColumn( const OUString&, SvTreeListEntry* pParent, + sal_uInt32 nPos, sal_uInt16 nCol, void* pUserData = nullptr ) override; + virtual sal_uInt32 Insert( SvTreeListEntry* pEnt,SvTreeListEntry* pPar,sal_uInt32 nPos=TREELIST_APPEND) override; + virtual sal_uInt32 Insert( SvTreeListEntry* pEntry, sal_uInt32 nRootPos = TREELIST_APPEND ) override; + + // Accessible ------------------------------------------------------------- + + bool IsCellCheckBox( sal_Int32 _nRow, sal_uInt16 _nColumn, TriState& _rState ) const; + + /** @return The count of the rows. */ + virtual sal_Int32 GetRowCount() const override; + /** @return The count of the columns. */ + virtual sal_uInt16 GetColumnCount() const override; + + /** @return The position of the current row. */ + virtual sal_Int32 GetCurrRow() const override; + /** @return The position of the current column. */ + virtual sal_uInt16 GetCurrColumn() const override; + + /** @return The description of a row. + @param _nRow The row which description is in demand. */ + virtual OUString GetRowDescription( sal_Int32 _nRow ) const override; + /** @return The description of a column. + @param _nColumn The column which description is in demand. */ + virtual OUString GetColumnDescription( sal_uInt16 _nColumn ) const override; + + /** @return <TRUE/>, if the object has a row header. */ + virtual bool HasRowHeader() const override; //GetColumnId + /** @return <TRUE/>, if the object can focus a cell. */ + virtual bool GoToCell( sal_Int32 _nRow, sal_uInt16 _nColumn ) override; + + virtual void SetNoSelection() override; + using SvTabListBox::SelectAll; + virtual void SelectAll() override; + virtual void SelectRow( sal_Int32 _nRow, bool _bSelect = true, bool bExpand = true ) override; + virtual void SelectColumn( sal_uInt16 _nColumn, bool _bSelect = true ) override; + virtual sal_Int32 GetSelectedRowCount() const override; + virtual sal_Int32 GetSelectedColumnCount() const override; + /** @return <TRUE/>, if the row is selected. */ + virtual bool IsRowSelected( sal_Int32 _nRow ) const override; + virtual bool IsColumnSelected( sal_Int32 _nColumn ) const override; + virtual void GetAllSelectedRows( css::uno::Sequence< sal_Int32 >& _rRows ) const override; + virtual void GetAllSelectedColumns( css::uno::Sequence< sal_Int32 >& _rColumns ) const override; + + /** @return <TRUE/>, if the cell is visible. */ + virtual bool IsCellVisible( sal_Int32 _nRow, sal_uInt16 _nColumn ) const override; + virtual OUString GetAccessibleCellText( sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const override; + + virtual tools::Rectangle calcHeaderRect( bool _bIsColumnBar, bool _bOnScreen = true ) override; + virtual tools::Rectangle calcTableRect( bool _bOnScreen = true ) override; + virtual tools::Rectangle GetFieldRectPixel( sal_Int32 _nRow, sal_uInt16 _nColumn, bool _bIsHeader, bool _bOnScreen ) override; + + virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumn ) override; + virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleRowHeader( sal_Int32 _nRow ) override; + virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos ) override; + + virtual sal_Int32 GetAccessibleControlCount() const override; + virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleControl( sal_Int32 _nIndex ) override; + virtual bool ConvertPointToControlIndex( sal_Int32& _rnIndex, const Point& _rPoint ) override; + + virtual bool ConvertPointToCellAddress( sal_Int32& _rnRow, sal_uInt16& _rnColPos, const Point& _rPoint ) override; + virtual bool ConvertPointToRowHeader( sal_Int32& _rnRow, const Point& _rPoint ) override; + virtual bool ConvertPointToColumnHeader( sal_uInt16& _rnColPos, const Point& _rPoint ) override; + + virtual OUString GetAccessibleObjectName( AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos = -1 ) const override; + virtual OUString GetAccessibleObjectDescription( AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos = -1 ) const override; + virtual vcl::Window* GetWindowInstance() override; + + virtual void FillAccessibleStateSet( sal_Int64& _rStateSet, AccessibleBrowseBoxObjType _eType ) const override; + virtual void FillAccessibleStateSetForCell( sal_Int64& _rStateSet, sal_Int32 _nRow, sal_uInt16 _nColumn ) const override; + virtual void GrabTableFocus() override; + + // OutputDevice + virtual bool GetGlyphBoundRects( const Point& rOrigin, const OUString& rStr, int nIndex, int nLen, std::vector< tools::Rectangle >& rVector ) override; + + // Window + virtual AbsoluteScreenPixelRectangle GetWindowExtentsAbsolute() const override; + virtual tools::Rectangle GetWindowExtentsRelative(const vcl::Window& rRelativeWindow) const override; + virtual void GrabFocus() override; + virtual css::uno::Reference< css::accessibility::XAccessible > GetAccessible() override; + /** Creates and returns the accessible object of the whole BrowseBox. */ + virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override; + virtual vcl::Window* GetAccessibleParentWindow() const override; + + virtual tools::Rectangle GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex) override; + virtual sal_Int32 GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint) override; + + virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/tabdlg.hxx b/include/vcl/toolkit/tabdlg.hxx new file mode 100644 index 0000000000..48fab3174e --- /dev/null +++ b/include/vcl/toolkit/tabdlg.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/toolkit/dialog.hxx> + +class FixedLine; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TabDialog final : public Dialog +{ +private: + VclPtr<FixedLine> mpFixedLine; + bool mbPosControls; + + SAL_DLLPRIVATE void ImplInitTabDialogData(); + SAL_DLLPRIVATE void ImplPosControls(); + +public: + TabDialog( vcl::Window* pParent, WinBits nStyle ); + virtual ~TabDialog() override; + virtual void dispose() override; + + virtual void StateChanged( StateChangedType nStateChange ) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/throbber.hxx b/include/vcl/toolkit/throbber.hxx new file mode 100644 index 0000000000..ff1240074b --- /dev/null +++ b/include/vcl/toolkit/throbber.hxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <vcl/dllapi.h> +#include <vcl/toolkit/imgctrl.hxx> +#include <vcl/timer.hxx> + +#include <vector> + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) Throbber final : public ImageControl +{ +public: + enum class ImageSet + { + /// default images, 16x16 pixels + N16px, + /// default images, 32x32 pixels + N32px, + /// default images, 64x64 pixels + N64px, + }; + +public: + Throbber(vcl::Window* i_parentWindow, WinBits i_style); + virtual ~Throbber() override; + virtual void dispose() override; + + // Properties + void setStepTime( sal_Int32 nStepTime ) { mnStepTime = nStepTime; } + sal_Int32 getStepTime() const { return mnStepTime; } + + void setRepeat( bool bRepeat ) { mbRepeat = bRepeat; } + bool getRepeat() const { return mbRepeat; } + + // animation control + void start(); + void stop(); + bool isRunning() const; + + void setImageList( ::std::vector< Image > && i_images ); + + // default images + static ::std::vector< OUString > + getDefaultImageURLs( const ImageSet i_imageSet ); + +private: + // Window overridables + virtual void Resize() override; + + SAL_DLLPRIVATE void initImages(); + + ::std::vector< Image > maImageList; + + bool mbRepeat; + sal_Int32 mnStepTime; + sal_Int32 mnCurStep; + AutoTimer maWaitTimer; + + DECL_DLLPRIVATE_LINK( TimeOutHdl, Timer*, void ); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/treelist.hxx b/include/vcl/toolkit/treelist.hxx new file mode 100644 index 0000000000..d0306ce915 --- /dev/null +++ b/include/vcl/toolkit/treelist.hxx @@ -0,0 +1,295 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <vcl/toolkit/treelistentries.hxx> + +#include <tools/link.hxx> +#include <tools/contnr.hxx> + +#include <memory> + +enum class SvListAction +{ + INSERTED = 1, + REMOVING = 2, + REMOVED = 3, + MOVING = 4, + MOVED = 5, + CLEARING = 6, + INSERTED_TREE = 7, + INVALIDATE_ENTRY = 8, + RESORTING = 9, + RESORTED = 10, + CLEARED = 11 +}; + +class SvTreeListEntry; +class SvListView; +class SvViewDataEntry; + +enum class SvSortMode { Ascending, Descending, None }; + +// For the return values of Sortlink: +// See International::Compare( pLeft, pRight ) +// ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) ) +struct SvSortData +{ + const SvTreeListEntry* pLeft; + const SvTreeListEntry* pRight; +}; + +class VCL_DLLPUBLIC SvTreeList final +{ + friend class SvListView; + + SvListView& mrOwnerListView; + sal_uInt32 nEntryCount; + + Link<SvTreeListEntry*, SvTreeListEntry*> aCloneLink; + Link<const SvSortData&, sal_Int32> aCompareLink; + SvSortMode eSortMode; + + bool bAbsPositionsValid; + + bool mbEnableInvalidate; + + SvTreeListEntry* FirstVisible() const { return First(); } + SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const; + SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry ) const; + SvTreeListEntry* LastVisible( const SvListView* ) const; + SvTreeListEntry* NextVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const; + SvTreeListEntry* PrevVisible( const SvListView*,SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const; + + bool IsEntryVisible( const SvListView*,SvTreeListEntry* pEntry ) const; + SvTreeListEntry* GetEntryAtVisPos( const SvListView*, sal_uInt32 nVisPos ) const; + sal_uInt32 GetVisiblePos( const SvListView*,SvTreeListEntry const * pEntry ) const; + sal_uInt32 GetVisibleCount( SvListView* ) const; + sal_uInt32 GetVisibleChildCount( const SvListView*,SvTreeListEntry* pParent ) const; + + SvTreeListEntry* FirstSelected( const SvListView*) const; + SvTreeListEntry* NextSelected( const SvListView*,SvTreeListEntry* pEntry ) const; + + sal_uInt32 GetChildSelectionCount( const SvListView*,SvTreeListEntry* pParent ) const; + + VCL_DLLPRIVATE void SetAbsolutePositions(); + + VCL_DLLPRIVATE void CloneChildren( + SvTreeListEntries& rDst, sal_uInt32& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry& rNewParent) const; + + /** + * Invalidate the cached position data to have them re-generated before + * the next access. + */ + VCL_DLLPRIVATE static void SetListPositions( SvTreeListEntries& rEntries ); + + // rPos is not changed for SortModeNone + VCL_DLLPRIVATE void GetInsertionPos( + SvTreeListEntry const * pEntry, + SvTreeListEntry* pParent, + sal_uInt32& rPos + ); + + VCL_DLLPRIVATE void ResortChildren( SvTreeListEntry* pParent ); + + SvTreeList(const SvTreeList&) = delete; + SvTreeList& operator= (const SvTreeList&) = delete; + + std::unique_ptr<SvTreeListEntry> pRootItem; + +public: + + SvTreeList() = delete; + SvTreeList(SvListView&); + ~SvTreeList(); + + void Broadcast( + SvListAction nActionId, + SvTreeListEntry* pEntry1=nullptr, + SvTreeListEntry* pEntry2=nullptr, + sal_uInt32 nPos=0 + ); + + void EnableInvalidate( bool bEnable ); + bool IsEnableInvalidate() const { return mbEnableInvalidate; } + + // Notify all Listeners + void InvalidateEntry( SvTreeListEntry* ); + + sal_uInt32 GetEntryCount() const { return nEntryCount; } + SvTreeListEntry* First() const; + SvTreeListEntry* Next( SvTreeListEntry* pEntry, sal_uInt16* pDepth=nullptr ) const; + SvTreeListEntry* Prev( SvTreeListEntry* pEntry ) const; + SvTreeListEntry* Last() const; + + SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const; + + sal_uInt32 Insert( SvTreeListEntry* pEntry,SvTreeListEntry* pPar,sal_uInt32 nPos = TREELIST_APPEND); + sal_uInt32 Insert( SvTreeListEntry* pEntry,sal_uInt32 nRootPos = TREELIST_APPEND ) + { return Insert(pEntry, pRootItem.get(), nRootPos ); } + + void InsertTree( SvTreeListEntry* pTree, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos ); + + // Entries need to be in the same Model! + void Move( SvTreeListEntry* pSource, SvTreeListEntry* pTarget ); + + // Creates ChildList if needed + sal_uInt32 Move( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos); + sal_uInt32 Copy( SvTreeListEntry* pSource, SvTreeListEntry* pTargetParent, sal_uInt32 nListPos); + + bool Remove( const SvTreeListEntry* pEntry ); + void Clear(); + + bool IsChild(const SvTreeListEntry* pParent, const SvTreeListEntry* pChild) const; + SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uInt32 nPos ) const; + SvTreeListEntry* GetEntry( sal_uInt32 nRootPos ) const; + SvTreeListEntry* GetEntryAtAbsPos( sal_uInt32 nAbsPos ) const; + + const SvTreeListEntry* GetParent( const SvTreeListEntry* pEntry ) const; + SvTreeListEntry* GetParent( SvTreeListEntry* pEntry ); + + const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const; + SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ); + + sal_uInt32 GetAbsPos( const SvTreeListEntry* pEntry ) const; + static sal_uInt32 GetRelPos( const SvTreeListEntry* pChild ); + + sal_uInt32 GetChildCount( const SvTreeListEntry* pParent ) const; + sal_uInt16 GetDepth( const SvTreeListEntry* pEntry ) const; + bool IsAtRootDepth( const SvTreeListEntry* pEntry ) const; + + // The Model calls the Clone Link to clone Entries. + // Thus we do not need to derive from the Model if we derive from SvTreeListEntry. + // The Handler needs to return a SvTreeListEntry* + SvTreeListEntry* Clone( SvTreeListEntry* pEntry, sal_uInt32& nCloneCount ) const; + void SetCloneLink( const Link<SvTreeListEntry*,SvTreeListEntry*>& rLink ) + { aCloneLink=rLink; } + + const Link<SvTreeListEntry*,SvTreeListEntry*>& GetCloneLink() const + { return aCloneLink; } + + SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link + + void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; } + SvSortMode GetSortMode() const { return eSortMode; } + sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const; + void SetCompareHdl( const Link<const SvSortData&, sal_Int32>& rLink ) { aCompareLink = rLink; } + void Resort(); +}; + +class VCL_DLLPUBLIC SvListView +{ + friend class SvTreeList; + + struct SAL_DLLPRIVATE Impl; + std::unique_ptr<Impl> m_pImpl; + +protected: + std::unique_ptr<SvTreeList> pModel; + + void ExpandListEntry( SvTreeListEntry* pParent ); + void CollapseListEntry( SvTreeListEntry* pParent ); + bool SelectListEntry( SvTreeListEntry* pEntry, bool bSelect ); + +public: + SvListView(); // Sets the Model to 0 + void dispose(); + virtual ~SvListView(); + void Clear(); + virtual void ModelNotification( + SvListAction nActionId, + SvTreeListEntry* pEntry1, + SvTreeListEntry* pEntry2, + sal_uInt32 nPos + ); + + sal_uInt32 GetVisibleCount() const + { return pModel->GetVisibleCount( const_cast<SvListView*>(this) ); } + + SvTreeListEntry* FirstVisible() const + { return pModel->FirstVisible(); } + + SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry ) const + { return pModel->NextVisible(this,pEntry); } + + SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry ) const + { return pModel->PrevVisible(this,pEntry); } + + SvTreeListEntry* LastVisible() const + { return pModel->LastVisible(this); } + + SvTreeListEntry* NextVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const + { return pModel->NextVisible(this,pEntry,rDelta); } + + SvTreeListEntry* PrevVisible( SvTreeListEntry* pEntry, sal_uInt16& rDelta ) const + { return pModel->PrevVisible(this,pEntry,rDelta); } + + sal_uInt32 GetSelectionCount() const; + + SvTreeListEntry* FirstSelected() const + { return pModel->FirstSelected(this); } + + SvTreeListEntry* NextSelected( SvTreeListEntry* pEntry ) const + { return pModel->NextSelected(this,pEntry); } + + SvTreeListEntry* GetEntryAtAbsPos( sal_uInt32 nAbsPos ) const + { return pModel->GetEntryAtAbsPos(nAbsPos); } + + SvTreeListEntry* GetEntryAtVisPos( sal_uInt32 nVisPos ) const + { return pModel->GetEntryAtVisPos(this,nVisPos); } + + sal_uInt32 GetAbsPos( SvTreeListEntry const * pEntry ) const + { return pModel->GetAbsPos(pEntry); } + + sal_uInt32 GetVisiblePos( SvTreeListEntry const * pEntry ) const + { return pModel->GetVisiblePos(this,pEntry); } + + sal_uInt32 GetVisibleChildCount(SvTreeListEntry* pParent ) const + { return pModel->GetVisibleChildCount(this,pParent); } + + bool IsEntryVisible( SvTreeListEntry* pEntry ) const + { return pModel->IsEntryVisible(this,pEntry); } + + bool IsExpanded( SvTreeListEntry* pEntry ) const; + bool IsAllExpanded( SvTreeListEntry* pEntry) const; + bool IsSelected(const SvTreeListEntry* pEntry) const; + void SetEntryFocus( SvTreeListEntry* pEntry, bool bFocus ); + const SvViewDataEntry* GetViewData( const SvTreeListEntry* pEntry ) const; + SvViewDataEntry* GetViewData( SvTreeListEntry* pEntry ); + bool HasViewData() const; + + virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry ); + + virtual void ModelHasCleared(); + virtual void ModelHasInserted( SvTreeListEntry* pEntry ); + virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry ); + virtual void ModelIsMoving( SvTreeListEntry* pSource ); + virtual void ModelHasMoved( SvTreeListEntry* pSource ); + virtual void ModelIsRemoving( SvTreeListEntry* pEntry ); + virtual void ModelHasRemoved( SvTreeListEntry* pEntry ); + virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry ); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/treelistbox.hxx b/include/vcl/toolkit/treelistbox.hxx new file mode 100644 index 0000000000..ecbd489fd8 --- /dev/null +++ b/include/vcl/toolkit/treelistbox.hxx @@ -0,0 +1,684 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> + +#include <deque> +#include <memory> +#include <vector> + +#include <vcl/ctrl.hxx> +#include <vcl/quickselectionengine.hxx> +#include <vcl/image.hxx> +#include <tools/gen.hxx> +#include <tools/contnr.hxx> +#include <vcl/toolkit/treelist.hxx> +#include <vcl/transfer.hxx> +#include <o3tl/typed_flags_set.hxx> + +class SvTreeListBox; +class SvTreeListEntry; +struct SvViewDataItem; +class SvViewDataEntry; +class SvInplaceEdit2; +class SvLBoxString; +class SvImpLBox; +class SvLBoxButtonData; +class Timer; +class Edit; + +enum class SvButtonState { Unchecked, Checked, Tristate }; + +// ********************************************************************* +// *************************** Tabulators ****************************** +// ********************************************************************* + +enum class SvLBoxTabFlags +{ + NONE = 0x0000, + DYNAMIC = 0x0001, // Item's output column changes according to the Child Depth + ADJUST_RIGHT = 0x0002, // Item's right margin at the tabulator + ADJUST_LEFT = 0x0004, // Left margin + ADJUST_CENTER = 0x0008, // Center the item at the tabulator + + SHOW_SELECTION = 0x0010, // Visualize selection state + // Item needs to be able to return the surrounding polygon (D'n'D cursor) + EDITABLE = 0x0020, // Item editable at the tabulator + FORCE = 0x0040, // Switch off the default calculation of the first tabulator + // (on which Abo Tabpage/Extras/Option/Customize, etc. rely on) + // The first tab's position corresponds precisely to the Flags set + // and column widths +}; +namespace o3tl +{ + template<> struct typed_flags<SvLBoxTabFlags> : is_typed_flags<SvLBoxTabFlags, 0x007f> {}; +} + +#define SV_TAB_BORDER 8 + +#define SV_ENTRYHEIGHTOFFS_PIXEL 2 + +enum class SvTreeFlags +{ + CHKBTN = 0x01, + USESEL = 0x02, + MANINS = 0x04, + RECALCTABS = 0x08, + FIXEDHEIGHT = 0x10, +}; +namespace o3tl +{ + template<> struct typed_flags<SvTreeFlags> : is_typed_flags<SvTreeFlags, 0x1f> {}; +} + +enum class SvLBoxItemType {String, Button, ContextBmp}; + +class SvLBoxTab +{ + tools::Long nPos; +public: + SvLBoxTab(); + SvLBoxTab( tools::Long nPos, SvLBoxTabFlags nFlags ); + SvLBoxTab( const SvLBoxTab& ); + + SvLBoxTabFlags nFlags; + + bool IsDynamic() const { return bool(nFlags & SvLBoxTabFlags::DYNAMIC); } + void SetPos( tools::Long nNewPos) { nPos = nNewPos; } + tools::Long GetPos() const { return nPos; } + tools::Long CalcOffset( tools::Long nItemLength, tools::Long nTabWidth ); + bool IsEditable() const { return bool(nFlags & SvLBoxTabFlags::EDITABLE); } +}; + +class VCL_DLLPUBLIC SvLBoxItem +{ +protected: + bool mbDisabled; + +public: + SvLBoxItem(); + virtual ~SvLBoxItem(); + virtual SvLBoxItemType GetType() const = 0; + virtual int CalcWidth(const SvTreeListBox* pView) const; + int GetWidth(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const; + int GetWidth(const SvTreeListBox* pView, const SvViewDataEntry* pData, sal_uInt16 nItemPos) const; + int GetHeight(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const; + static int GetHeight(const SvViewDataEntry* pData, sal_uInt16 nItemPos); + void Enable(bool bEnabled) { mbDisabled = !bEnabled; } + bool isEnable() const { return !mbDisabled; } + + virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev, vcl::RenderContext& rRenderContext, const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) = 0; + + virtual void InitViewData(SvTreeListBox* pView, SvTreeListEntry* pEntry, + // If != 0: this Pointer must be used! + // If == 0: it needs to be retrieved via the View + SvViewDataItem* pViewData = nullptr) = 0; + // View-dependent data is not cloned + virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const = 0; +}; + +enum class DragDropMode +{ + NONE = 0x0000, + CTRL_MOVE = 0x0001, + APP_COPY = 0x0004, + // Entries may be dropped via the uppermost Entry + // The DropTarget is 0 in that case + ENABLE_TOP = 0x0010, + ALL = 0x0015, +}; +namespace o3tl +{ + template<> struct typed_flags<DragDropMode> : is_typed_flags<DragDropMode, 0x0015> {}; +} + +enum class SvTreeListBoxFlags +{ + NONE = 0x0000, + IN_EDT = 0x0001, + EDT_ENABLED = 0x0002, + TARGEMPH_VIS = 0x0004, + EDTEND_CALLED = 0x0008, +}; +namespace o3tl +{ + template<> struct typed_flags<SvTreeListBoxFlags> : is_typed_flags<SvTreeListBoxFlags, 0x000f> {}; +} + +struct SvTreeListBoxImpl; + +typedef std::pair<vcl::RenderContext&, const SvTreeListEntry&> svtree_measure_args; +typedef std::tuple<vcl::RenderContext&, const tools::Rectangle&, const SvTreeListEntry&> svtree_render_args; + +class VCL_DLLPUBLIC SvTreeListBox + :public Control + ,public SvListView + ,public DropTargetHelper + ,public DragSourceHelper + ,public vcl::ISearchableStringList +{ + friend class SvImpLBox; + friend class SvLBoxString; + friend class IconViewImpl; + friend class TreeControlPeer; + friend class SalInstanceIconView; + friend class SalInstanceTreeView; + friend class SalInstanceEntryTreeView; + + std::unique_ptr<SvTreeListBoxImpl> mpImpl; + Link<SvTreeListBox*,void> aScrolledHdl; + Link<SvTreeListBox*,void> aExpandedHdl; + Link<SvTreeListBox*,bool> aExpandingHdl; + Link<SvTreeListBox*,void> aSelectHdl; + Link<SvTreeListBox*,void> aDeselectHdl; + Link<const CommandEvent&, bool> aPopupMenuHdl; + Link<SvTreeListEntry*, OUString> aTooltipHdl; + Link<svtree_render_args, void> aCustomRenderHdl; + Link<svtree_measure_args, Size> aCustomMeasureHdl; + + Image aPrevInsertedExpBmp; + Image aPrevInsertedColBmp; + Image aCurInsertedExpBmp; + Image aCurInsertedColBmp; + + short nContextBmpWidthMax; + short nEntryHeightOffs; + short nIndent; + short nFocusWidth; + sal_uInt16 nFirstSelTab; + sal_uInt16 nLastSelTab; + tools::Long mnCheckboxItemWidth; + bool mbContextBmpExpanded; + bool mbQuickSearch; // Enables type-ahead search in the check list box. + bool mbActivateOnSingleClick; // Make single click "activate" a row like a double-click normally does + bool mbHoverSelection; // Make mouse over a row "select" a row like a single-click normally does + bool mbSelectingByHover; // true during "Select" if it was due to hover + sal_Int8 mnClicksToToggle; // 0 == Click on a row not toggle its checkbox. + // 1 == Every click on row toggle its checkbox. + // 2 == First click select, second click toggle. + + SvTreeListEntry* pHdlEntry; + + DragDropMode nDragDropMode; + DragDropMode nOldDragMode; + SelectionMode eSelMode; + sal_Int32 nMinWidthInChars; + + sal_Int8 mnDragAction; + + SvTreeListEntry* pEdEntry; + SvLBoxString* pEdItem; + + rtl::Reference<TransferDataContainer> m_xTransferHelper; + +protected: + std::unique_ptr<SvImpLBox> pImpl; + short nColumns; + short nEntryHeight; + short nEntryWidth; + bool mbCenterAndClipText; + + Link<SvTreeListBox*,bool> aDoubleClickHdl; + SvTreeListEntry* pTargetEntry; + SvLBoxButtonData* pCheckButtonData; + std::vector<std::unique_ptr<SvLBoxTab>> aTabs; + SvTreeFlags nTreeFlags; + SvTreeListBoxFlags nImpFlags; + // Move/CopySelection: Position of the current Entry in SelectionList + sal_uInt16 nCurEntrySelPos; + +private: + DECL_DLLPRIVATE_LINK( CheckButtonClick, SvLBoxButtonData *, void ); + DECL_DLLPRIVATE_LINK( TextEditEndedHdl_Impl, SvInplaceEdit2&, void ); + // Handler that is called by TreeList to clone an Entry + DECL_DLLPRIVATE_LINK( CloneHdl_Impl, SvTreeListEntry*, SvTreeListEntry* ); + + // Handler and methods for Drag - finished handler. + // The Handle retrieved by GetDragFinishedHdl can be set on the + // TransferDataContainer. This link is a callback for the DragFinished + // call. The AddBox method is called from the GetDragFinishedHdl() and the + // remove is called in the link callback and in the dtor. So it can't be + // called for a deleted object. + VCL_DLLPRIVATE static void AddBoxToDDList_Impl( const SvTreeListBox& rB ); + VCL_DLLPRIVATE static void RemoveBoxFromDDList_Impl( const SvTreeListBox& rB ); + DECL_DLLPRIVATE_LINK( DragFinishHdl_Impl, sal_Int8, void ); + + // after a checkbox entry is inserted, use this to get its width to support + // autowidth for the 1st checkbox column + VCL_DLLPRIVATE void CheckBoxInserted(SvTreeListEntry* pEntry); + + VCL_DLLPRIVATE void DrawCustomEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const SvTreeListEntry& rEntry); + VCL_DLLPRIVATE Size MeasureCustomEntry(vcl::RenderContext& rRenderContext, const SvTreeListEntry& rEntry) const; + + /** Handles the given key event. + + At the moment this merely does typeahead if typeahead is enabled. + + @return + <TRUE/> if the event has been consumed, <FALSE/> otherwise. + */ + VCL_DLLPRIVATE bool HandleKeyInput(const KeyEvent& rKEvt); + + void UnsetDropTarget(); + +protected: + + bool CheckDragAndDropMode( SvTreeListBox const * pSource, sal_Int8 ); + void ImplShowTargetEmphasis( SvTreeListEntry* pEntry, bool bShow); + void EnableSelectionAsDropTarget( bool bEnable = true ); + // Standard impl returns 0; derived classes which support D'n'D must override + using Window::GetDropTarget; + virtual SvTreeListEntry* GetDropTarget( const Point& ); + + // Invalidate children on enable/disable + virtual void StateChanged( StateChangedType eType ) override; + + virtual sal_uInt32 Insert( SvTreeListEntry* pEnt,SvTreeListEntry* pPar,sal_uInt32 nPos=TREELIST_APPEND); + virtual sal_uInt32 Insert( SvTreeListEntry* pEntry,sal_uInt32 nRootPos = TREELIST_APPEND ); + + // In-place editing + std::unique_ptr<SvInplaceEdit2> pEdCtrl; + void EditText( const OUString&, const tools::Rectangle&,const Selection&); + void CancelTextEditing(); + + // InitViewData is called right after CreateViewData + // The Entry is has not yet been added to the View in InitViewData! + virtual void InitViewData( SvViewDataEntry*, SvTreeListEntry* pEntry ) override; + // Calls InitViewData for all Items + void RecalcViewData(); + + // Handler and methods for Drag - finished handler. This link can be set + // to the TransferDataContainer. The AddBox/RemoveBox methods must be + // called before the StartDrag call. + // The Remove will be called from the handler, which then calls DragFinish. + // The Remove is also called in the DTOR of the SvTreeListBox - + // so it can't be called for a deleted object. + Link<sal_Int8,void> GetDragFinishedHdl() const; + + // For asynchronous D'n'D + sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt, SvTreeListBox* pSourceView ); + + void OnCurrentEntryChanged(); + + // ISearchableStringList + virtual vcl::StringEntryIdentifier CurrentEntry( OUString& _out_entryText ) const override; + virtual vcl::StringEntryIdentifier NextEntry( vcl::StringEntryIdentifier _currentEntry, OUString& _out_entryText ) const override; + virtual void SelectEntry( vcl::StringEntryIdentifier _entry ) override; + +public: + + SvTreeListBox( vcl::Window* pParent, WinBits nWinStyle=0 ); + virtual ~SvTreeListBox() override; + virtual void dispose() override; + + SvTreeList* GetModel() const + { + return pModel.get(); + } + + sal_uInt32 GetEntryCount() const + { + return pModel ? pModel->GetEntryCount() : 0; + } + SvTreeListEntry* First() const + { + return pModel ? pModel->First() : nullptr; + } + SvTreeListEntry* Next( SvTreeListEntry* pEntry ) const + { + return pModel->Next(pEntry); + } + SvTreeListEntry* Prev( SvTreeListEntry* pEntry ) const + { + return pModel->Prev(pEntry); + } + SvTreeListEntry* Last() const + { + return pModel ? pModel->Last() : nullptr; + } + + SvTreeListEntry* FirstChild( SvTreeListEntry* pParent ) const; + + bool CopySelection( SvTreeListBox* pSource, SvTreeListEntry* pTarget ); + bool MoveSelectionCopyFallbackPossible( SvTreeListBox* pSource, SvTreeListEntry* pTarget, bool bAllowCopyFallback ); + void RemoveSelection(); + /** + * Removes the entry along with all of its descendants + */ + void RemoveEntry(SvTreeListEntry const * pEntry); + + DragDropMode GetDragDropMode() const { return nDragDropMode; } + SelectionMode GetSelectionMode() const { return eSelMode; } + + // pParent == 0 -> Root level + SvTreeListEntry* GetEntry( SvTreeListEntry* pParent, sal_uInt32 nPos ) const; + SvTreeListEntry* GetEntry( sal_uInt32 nRootPos ) const; + + SvTreeListEntry* GetEntryFromPath( const ::std::deque< sal_Int32 >& _rPath ) const; + void FillEntryPath( SvTreeListEntry* pEntry, ::std::deque< sal_Int32 >& _rPath ) const; + + using Window::GetParent; + SvTreeListEntry* GetParent( SvTreeListEntry* pEntry ) const; + + using Window::GetChildCount; + sal_uInt32 GetChildCount( SvTreeListEntry const * pParent ) const; + sal_uInt32 GetLevelChildCount( SvTreeListEntry* pParent ) const; + + SvViewDataEntry* GetViewDataEntry( SvTreeListEntry const * pEntry ) const; + SvViewDataItem* GetViewDataItem(SvTreeListEntry const *, SvLBoxItem const *); + const SvViewDataItem* GetViewDataItem(const SvTreeListEntry*, const SvLBoxItem*) const; + + OUString GetEntryTooltip(SvTreeListEntry* pEntry) const { return aTooltipHdl.Call(pEntry); } + + VclPtr<Edit> GetEditWidget() const; // for UITest + bool IsInplaceEditingEnabled() const { return bool(nImpFlags & SvTreeListBoxFlags::EDT_ENABLED); } + bool IsEditingActive() const { return bool(nImpFlags & SvTreeListBoxFlags::IN_EDT); } + void EndEditing( bool bCancel = false ); + + void Clear(); + + bool TextCenterAndClipEnabled() const { return mbCenterAndClipText; } + + void SetSelectHdl( const Link<SvTreeListBox*,void>& rNewHdl ) {aSelectHdl=rNewHdl; } + void SetDeselectHdl( const Link<SvTreeListBox*,void>& rNewHdl ) {aDeselectHdl=rNewHdl; } + void SetDoubleClickHdl(const Link<SvTreeListBox*,bool>& rNewHdl) {aDoubleClickHdl=rNewHdl;} + void SetExpandingHdl(const Link<SvTreeListBox*,bool>& rNewHdl){aExpandingHdl=rNewHdl;} + void SetExpandedHdl(const Link<SvTreeListBox*,void>& rNewHdl){aExpandedHdl=rNewHdl;} + void SetPopupMenuHdl(const Link<const CommandEvent&, bool>& rLink) { aPopupMenuHdl = rLink; } + void SetTooltipHdl(const Link<SvTreeListEntry*, OUString>& rLink) { aTooltipHdl = rLink; } + void SetCustomRenderHdl(const Link<svtree_render_args, void>& rLink) { aCustomRenderHdl = rLink; } + void SetCustomMeasureHdl(const Link<svtree_measure_args, Size>& rLink) { aCustomMeasureHdl = rLink; } + + void ExpandedHdl(); + bool ExpandingHdl(); + void SelectHdl(); + void DeselectHdl(); + bool DoubleClickHdl(); + SvTreeListEntry* GetHdlEntry() const { return pHdlEntry; } + + // Is called for an Entry that gets expanded with the Flag + // ENTRYFLAG_CHILDREN_ON_DEMAND set. + virtual void RequestingChildren( SvTreeListEntry* pParent ); + + // Drag & Drop + // New D'n'D API + virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; + virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; + virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override; + virtual DragDropMode NotifyStartDrag(); + virtual void DragFinished( sal_Int8 nDropAction ); + + SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ); + + // Return value: TRISTATE_TRUE == Ok, TRISTATE_FALSE == Cancel, TRISTATE_INDET == Ok and Make visible moved entry + TriState NotifyMoving( + SvTreeListEntry* pTarget, // D'n'D DropPosition in GetModel() + const SvTreeListEntry* pEntry, // Entry to be moved from GetSourceListBox()->GetModel() + SvTreeListEntry*& rpNewParent, // New TargetParent + sal_uInt32& rNewChildPos); // The TargetParent's position in Childlist + + // Return value: TRISTATE_TRUE == Ok, TRISTATE_FALSE == Cancel, TRISTATE_INDET == Ok and Make visible moved entry + TriState NotifyCopying( + SvTreeListEntry* pTarget, // D'n'D DropPosition in GetModel() + const SvTreeListEntry* pEntry, // Entry to be copied from GetSourceListBox()->GetModel() + SvTreeListEntry*& rpNewParent, // New TargetParent + sal_uInt32& rNewChildPos); // The TargetParent's position in Childlist + + // ACCESSIBILITY ========================================================== + + /** Creates and returns the accessible object of the Box. */ + virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override; + + /** Fills the StateSet of one entry. */ + void FillAccessibleEntryStateSet( SvTreeListEntry* pEntry, sal_Int64& rStateSet ) const; + + virtual OUString GetEntryAccessibleDescription(SvTreeListEntry* pEntry) const; + + /** Calculate and return the bounding rectangle of an entry. + @param pEntry + The entry. + @return The bounding rectangle of an entry. */ + tools::Rectangle GetBoundingRect(const SvTreeListEntry* pEntry); + + SvTreeFlags GetTreeFlags() const {return nTreeFlags;} + + static OUString SearchEntryTextWithHeadTitle(SvTreeListEntry* pEntry); + + void set_min_width_in_chars(sal_Int32 nChars); + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + VCL_DLLPRIVATE void SetCollapsedNodeBmp( const Image& ); + VCL_DLLPRIVATE void SetExpandedNodeBmp( const Image& ); + VCL_DLLPRIVATE Image const & GetExpandedNodeBmp( ) const; + +protected: + + virtual void CalcEntryHeight(SvTreeListEntry const* pEntry); + void AdjustEntryHeight( const Image& rBmp ); + VCL_DLLPRIVATE void AdjustEntryHeight(); + + VCL_DLLPRIVATE void ImpEntryInserted( SvTreeListEntry* pEntry ); + VCL_DLLPRIVATE void PaintEntry1( SvTreeListEntry&, tools::Long nLine, vcl::RenderContext& rRenderContext ); + + VCL_DLLPRIVATE void InitTreeView(); + VCL_DLLPRIVATE SvLBoxItem* GetItem_Impl( SvTreeListEntry*, tools::Long nX, SvLBoxTab** ppTab ); + VCL_DLLPRIVATE void ImplInitStyle(); + + void SetupDragOrigin(); + void EditItemText( SvTreeListEntry* pEntry, SvLBoxString* pItem, + const Selection& ); + void EditedText(const OUString&); + + // Recalculate all tabs depending on TreeListStyle and Bitmap sizes + // Is called automatically when inserting/changing Bitmaps, changing the Model etc. + virtual void SetTabs(); + void AddTab( tools::Long nPos, SvLBoxTabFlags nFlags ); + sal_uInt16 TabCount() const { return aTabs.size(); } + SvLBoxTab* GetFirstDynamicTab() const; + SvLBoxTab* GetFirstDynamicTab( sal_uInt16& rTabPos ) const; + SvLBoxTab* GetFirstTab( SvLBoxTabFlags nFlagMask, sal_uInt16& rTabPos ); + void GetLastTab( SvLBoxTabFlags nFlagMask, sal_uInt16& rTabPos ); + SvLBoxTab* GetTab( SvTreeListEntry const *, SvLBoxItem const * ) const; + void ClearTabList(); + + virtual void InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&); + + void NotifyScrolled(); + void SetScrolledHdl( const Link<SvTreeListBox*,void>& rLink ) { aScrolledHdl = rLink; } + tools::Long GetXOffset() const { return GetMapMode().GetOrigin().X(); } + + virtual void Command( const CommandEvent& rCEvt ) override; + + virtual void RequestHelp( const HelpEvent& rHEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + void InitSettings(); + + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; + + void CallImplEventListeners(VclEventId nEvent, void* pData); + + void ImplEditEntry( SvTreeListEntry* pEntry ); + + void AdjustEntryHeightAndRecalc(); + + // true if rPos is over the SvTreeListBox body, i.e. not over a + // scrollbar + VCL_DLLPRIVATE bool PosOverBody(const Point& rPos) const; +public: + + void SetNoAutoCurEntry( bool b ); + + void EnableCheckButton( SvLBoxButtonData* ); + void SetCheckButtonData( SvLBoxButtonData* ); + + /** Returns the default image which clients should use for expanded nodes, to have a consistent user + interface experience in the whole product. + */ + static const Image& GetDefaultExpandedNodeImage( ); + + /** Returns the default image which clients should use for expanded nodes, to have a consistent user + interface experience in the whole product. + */ + static const Image& GetDefaultCollapsedNodeImage( ); + + /** Sets default bitmaps for collapsed and expanded nodes. + */ + void SetNodeDefaultImages(); + + virtual SvTreeListEntry* InsertEntry( const OUString& rText, SvTreeListEntry* pParent = nullptr, + bool bChildrenOnDemand = false, + sal_uInt32 nPos=TREELIST_APPEND, void* pUserData = nullptr); + + const Image& GetDefaultExpandedEntryBmp( ) const; + const Image& GetDefaultCollapsedEntryBmp( ) const; + + void SetDefaultExpandedEntryBmp( const Image& rBmp ); + void SetDefaultCollapsedEntryBmp( const Image& rBmp ); + + void SetCheckButtonState( SvTreeListEntry*, SvButtonState ); + SvButtonState GetCheckButtonState( SvTreeListEntry* ) const; + + void SetEntryText(SvTreeListEntry*, const OUString& ); + void SetExpandedEntryBmp( SvTreeListEntry* _pEntry, const Image& _rImage ); + void SetCollapsedEntryBmp( SvTreeListEntry* _pEntry, const Image& _rImage ); + + virtual OUString GetEntryText( SvTreeListEntry* pEntry ) const; + static const Image& GetExpandedEntryBmp(const SvTreeListEntry* _pEntry ); + static const Image& GetCollapsedEntryBmp(const SvTreeListEntry* _pEntry ); + + void CheckButtonHdl(); + + void SetSublistOpenWithLeftRight(); // open/close sublist with cursor left/right + + void EnableInplaceEditing( bool bEnable ); + // Edits the Entry's first StringItem, 0 == Cursor + void EditEntry( SvTreeListEntry* pEntry ); + virtual bool EditingEntry( SvTreeListEntry* pEntry ); + virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ); + + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + virtual void MouseMove( const MouseEvent& rMEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void Resize() override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + void SetUpdateMode( bool ); + + virtual void ModelHasCleared() override; + virtual void ModelHasInserted( SvTreeListEntry* pEntry ) override; + virtual void ModelHasInsertedTree( SvTreeListEntry* pEntry ) override; + virtual void ModelIsMoving(SvTreeListEntry* pSource ) override; + virtual void ModelHasMoved(SvTreeListEntry* pSource ) override; + virtual void ModelIsRemoving( SvTreeListEntry* pEntry ) override; + virtual void ModelHasRemoved( SvTreeListEntry* pEntry ) override; + void ModelHasEntryInvalidated( SvTreeListEntry* pEntry ) override; + + void ScrollOutputArea( short nDeltaEntries ); + + short GetColumnsCount() const { return nColumns; } + short GetEntryHeight() const { return nEntryHeight; } + void SetEntryHeight( short nHeight ); + short GetEntryWidth() const { return nEntryWidth; } + void SetEntryWidth( short nWidth ); + Size GetOutputSizePixel() const; + short GetIndent() const { return nIndent; } + void SetSpaceBetweenEntries( short nSpace ); + Point GetEntryPosition(const SvTreeListEntry*) const; + void MakeVisible( SvTreeListEntry* pEntry ); + void MakeVisible( SvTreeListEntry* pEntry, bool bMoveToTop ); + + void SetFont( const vcl::Font& rFont ); + + SvTreeListEntry* GetEntry( const Point& rPos, bool bHit = false ) const; + + virtual tools::Rectangle GetFocusRect(const SvTreeListEntry*, tools::Long nLine ); + // Respects indentation + sal_IntPtr GetTabPos(const SvTreeListEntry*, const SvLBoxTab*) const; + void InvalidateEntry( SvTreeListEntry* ); + SvLBoxItem* GetItem( SvTreeListEntry*, tools::Long nX, SvLBoxTab** ppTab); + SvLBoxItem* GetItem( SvTreeListEntry*, tools::Long nX ); + std::pair<tools::Long, tools::Long> GetItemPos(SvTreeListEntry* pEntry, sal_uInt16 nTabIdx); + + void SetDragDropMode( DragDropMode ); + void SetSelectionMode( SelectionMode ); + + bool Expand( SvTreeListEntry* pParent ); + bool Collapse( SvTreeListEntry* pParent ); + bool Select( SvTreeListEntry* pEntry, bool bSelect=true ); + sal_uInt32 SelectChildren( SvTreeListEntry* pParent, bool bSelect ); + void SelectAll( bool bSelect ); + + void SetCurEntry( SvTreeListEntry* _pEntry ); + SvTreeListEntry* GetCurEntry() const; + + virtual void ImplInvalidate( const vcl::Region* rRegion, InvalidateFlags nFlags ) override; + + void SetHighlightRange(sal_uInt16 nFirstTab=0, sal_uInt16 nLastTab=0xffff); + + sal_Int32 DefaultCompare(const SvLBoxString* pLeftText, const SvLBoxString* pRightText); + + DECL_DLLPRIVATE_LINK( DefaultCompare, const SvSortData&, sal_Int32 ); + virtual void ModelNotification( SvListAction nActionId, SvTreeListEntry* pEntry1, + SvTreeListEntry* pEntry2, sal_uInt32 nPos ) override; + + SvTreeListEntry* GetFirstEntryInView() const; + SvTreeListEntry* GetNextEntryInView(SvTreeListEntry*) const; + void ScrollToAbsPos( tools::Long nPos ); + + tools::Long getPreferredDimensions(std::vector<tools::Long> &rWidths) const; + + virtual Size GetOptimalSize() const override; + + // Enables type-ahead search in the check list box. + void SetQuickSearch(bool bEnable) { mbQuickSearch = bEnable; } + + // Make single click "activate" a row like a double-click normally does + void SetActivateOnSingleClick(bool bEnable) { mbActivateOnSingleClick = bEnable; } + bool GetActivateOnSingleClick() const { return mbActivateOnSingleClick; } + + // Make mouse over a row "select" a row like a single-click normally does + void SetHoverSelection(bool bEnable) { mbHoverSelection = bEnable; } + bool GetHoverSelection() const { return mbHoverSelection; } + + // only true during Select if the Select is due to a Hover + bool IsSelectDueToHover() const { return mbSelectingByHover; } + + // Set when clicks toggle the checkbox of the row. + void SetClicksToToggle(sal_Int8 nCount) { mnClicksToToggle = nCount; } + + void SetForceMakeVisible(bool bEnable); + + virtual FactoryFunction GetUITestFactory() const override; + + void SetDragHelper(const rtl::Reference<TransferDataContainer>& rHelper, sal_uInt8 eDNDConstants); + + virtual void EnableRTL(bool bEnable = true) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/treelistentries.hxx b/include/vcl/toolkit/treelistentries.hxx new file mode 100644 index 0000000000..fdd86dbfaf --- /dev/null +++ b/include/vcl/toolkit/treelistentries.hxx @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) \ + && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vector> +#include <memory> + +class SvTreeListEntry; +typedef std::vector<std::unique_ptr<SvTreeListEntry>> SvTreeListEntries; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/treelistentry.hxx b/include/vcl/toolkit/treelistentry.hxx new file mode 100644 index 0000000000..b8bffecefd --- /dev/null +++ b/include/vcl/toolkit/treelistentry.hxx @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <vcl/dllapi.h> +#include <tools/color.hxx> +#include <vcl/toolkit/treelistbox.hxx> +#include <vcl/toolkit/treelistentries.hxx> +#include <o3tl/typed_flags_set.hxx> + +#include <optional> +#include <vector> +#include <memory> + +// flags related to the model +enum class SvTLEntryFlags +{ + NONE = 0x0000, + CHILDREN_ON_DEMAND = 0x0001, + DISABLE_DROP = 0x0002, + // is set if RequestingChildren has not set any children + NO_NODEBMP = 0x0004, + // is set if this is a separator line + IS_SEPARATOR = 0x0008, + // entry had or has children + HAD_CHILDREN = 0x0010, + SEMITRANSPARENT = 0x8000, // draw semi-transparent entry bitmaps +}; +namespace o3tl +{ + template<> struct typed_flags<SvTLEntryFlags> : is_typed_flags<SvTLEntryFlags, 0x801f> {}; +} + +class VCL_DLLPUBLIC SvTreeListEntry +{ + friend class SvTreeList; + friend class SvListView; + friend class SvTreeListBox; + + typedef std::vector<std::unique_ptr<SvLBoxItem>> ItemsType; + + SvTreeListEntry* pParent; + SvTreeListEntries m_Children; + sal_uInt32 nAbsPos; + sal_uInt32 nListPos; + sal_uInt32 mnExtraIndent; + ItemsType m_Items; + void* pUserData; + SvTLEntryFlags nEntryFlags; + std::optional<Color> mxTextColor; + +private: + void ClearChildren(); + void SetListPositions(); + void InvalidateChildrensListPositions(); + + SvTreeListEntry(const SvTreeListEntry& r) = delete; + void operator=(SvTreeListEntry const&) = delete; + +public: + static const size_t ITEM_NOT_FOUND = SAL_MAX_SIZE; + + SvTreeListEntry(); + virtual ~SvTreeListEntry(); + + bool HasChildren() const; + bool HasChildListPos() const; + sal_uInt32 GetChildListPos() const; + + SvTreeListEntries& GetChildEntries() { return m_Children; } + const SvTreeListEntries& GetChildEntries() const { return m_Children; } + + void Clone(SvTreeListEntry* pSource); + + size_t ItemCount() const; + + // MAY ONLY BE CALLED IF THE ENTRY HAS NOT YET BEEN INSERTED INTO + // THE MODEL, AS OTHERWISE NO VIEW-DEPENDENT DATA ARE ALLOCATED + // FOR THE ITEM! + void AddItem(std::unique_ptr<SvLBoxItem> pItem); + void ReplaceItem(std::unique_ptr<SvLBoxItem> pNewItem, size_t nPos); + const SvLBoxItem& GetItem( size_t nPos ) const; + SvLBoxItem& GetItem( size_t nPos ); + const SvLBoxItem* GetFirstItem(SvLBoxItemType eType) const; + SvLBoxItem* GetFirstItem(SvLBoxItemType eType); + size_t GetPos( const SvLBoxItem* pItem ) const; + void* GetUserData() const { return pUserData;} + void SetUserData( void* pPtr ); + void EnableChildrenOnDemand( bool bEnable=true ); + bool HasChildrenOnDemand() const; + + SvTLEntryFlags GetFlags() const { return nEntryFlags;} + void SetFlags( SvTLEntryFlags nFlags ); + + void SetTextColor( std::optional<Color> xColor ) { mxTextColor = xColor; } + std::optional<Color> const & GetTextColor() const { return mxTextColor; } + + void SetExtraIndent(sal_uInt32 nExtraIndent) { mnExtraIndent = nExtraIndent; } + sal_uInt32 GetExtraIndent() const { return mnExtraIndent; } + + SvTreeListEntry* NextSibling() const; + SvTreeListEntry* PrevSibling() const; + SvTreeListEntry* LastSibling() const; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/unowrap.hxx b/include/vcl/toolkit/unowrap.hxx new file mode 100644 index 0000000000..359810652e --- /dev/null +++ b/include/vcl/toolkit/unowrap.hxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <config_options.h> +#include <com/sun/star/uno/Reference.h> +#include <vcl/dllapi.h> +#include <vcl/vclptr.hxx> + +namespace vcl { class Window; } +class Menu; +class OutputDevice; +class PopupMenu; +namespace com::sun::star::awt { + class XGraphics; + class XPopupMenu; + class XToolkit; + class XWindow; + class XVclWindowPeer; +} +namespace com::sun::star::accessibility { + class XAccessible; +} + +class VCL_DLLPUBLIC UnoWrapperBase +{ +public: + virtual void Destroy() = 0; + + // Toolkit + virtual css::uno::Reference< css::awt::XToolkit > GetVCLToolkit() = 0; + + // Graphics + virtual css::uno::Reference< css::awt::XGraphics > CreateGraphics( OutputDevice* pOutDev ) = 0; + virtual void ReleaseAllGraphics( OutputDevice* pOutDev ) = 0; + + // Window + virtual css::uno::Reference<css::awt::XVclWindowPeer> GetWindowInterface( vcl::Window* pWindow ) = 0; + virtual void SetWindowInterface( vcl::Window* pWindow, const css::uno::Reference< css::awt::XVclWindowPeer > & xIFace ) = 0; + virtual VclPtr<vcl::Window> GetWindow(const css::uno::Reference<css::awt::XWindow>& rxWindow) = 0; + + // PopupMenu + virtual css::uno::Reference<css::awt::XPopupMenu> CreateMenuInterface( PopupMenu* pPopupMenu ) = 0; + + virtual void WindowDestroyed( vcl::Window* pWindow ) = 0; + + // Accessibility + virtual css::uno::Reference< css::accessibility::XAccessible > + CreateAccessible( Menu* pMenu, bool bIsMenuBar ) = 0; + + /** Get the application's UNO wrapper object. + + Note that this static function will only ever try to create UNO wrapper object once, and + if it fails then it will not ever try again, even if the function is called multiple times. + + @param bCreateIfNotExists Create the UNO wrapper object if it doesn't exist when true. + + @return UNO wrapper object. + */ + static UnoWrapperBase* GetUnoWrapper( bool bCreateIfNotExists = true ); + + /** Sets the application's UNO Wrapper object. + + @param pWrapper Pointer to UNO wrapper object. + */ + static void SetUnoWrapper( UnoWrapperBase* pWrapper ); + +protected: + ~UnoWrapperBase() {} +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/vclmedit.hxx b/include/vcl/toolkit/vclmedit.hxx new file mode 100644 index 0000000000..2ca0104519 --- /dev/null +++ b/include/vcl/toolkit/vclmedit.hxx @@ -0,0 +1,173 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <tools/lineend.hxx> +#include <vcl/wintypes.hxx> +#include <vcl/toolkit/edit.hxx> +#include <vcl/dllapi.h> +#include <vcl/timer.hxx> +#include <memory> + +class ImpVclMEdit; +class ExtTextEngine; +class TextView; + +class TextWindow final : public vcl::Window +{ +private: + VclPtr<Edit> mxParent; + std::unique_ptr<ExtTextEngine> mpExtTextEngine; + std::unique_ptr<TextView> mpExtTextView; + + bool mbInMBDown; + bool mbFocusSelectionHide; + bool mbIgnoreTab; + bool mbActivePopup; + bool mbSelectOnTab; + +public: + explicit TextWindow(Edit* pParent); + virtual ~TextWindow() override; + virtual void dispose() override; + + ExtTextEngine* GetTextEngine() const { return mpExtTextEngine.get(); } + TextView* GetTextView() const { return mpExtTextView.get(); } + + virtual void MouseMove( const MouseEvent& rMEvt ) override; + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvent ) override; + + virtual void Command( const CommandEvent& rCEvt ) override; + + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; + virtual void Resize() override; + + virtual void GetFocus() override; + virtual void LoseFocus() override; + + void SetAutoFocusHide( bool bAutoHide ) { mbFocusSelectionHide = bAutoHide; } + + void SetIgnoreTab( bool bIgnore ) { mbIgnoreTab = bIgnore; } + + void DisableSelectionOnFocus() { mbSelectOnTab = false; } +}; + +class VCL_DLLPUBLIC VclMultiLineEdit : public Edit +{ + friend class VCLXAccessibleEdit; + +private: + std::unique_ptr<ImpVclMEdit> pImpVclMEdit; + + Link<Edit&,void> aModifyHdlLink; + +protected: + + void StateChanged( StateChangedType nType ) override; + void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + using Control::ImplInitSettings; + void ImplInitSettings( bool bBackground ); + static WinBits ImplInitStyle( WinBits nStyle ); + + TextView* GetTextView() const; + ExtTextEngine* GetTextEngine() const; + + virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; +public: + VclMultiLineEdit( vcl::Window* pParent, + WinBits nWinStyle ); + virtual ~VclMultiLineEdit() override; + virtual void dispose() override; + + void SelectionChanged(); + void CaretChanged(); + virtual void Modify() override; + + virtual void SetModifyFlag() override; + + virtual void SetReadOnly( bool bReadOnly = true ) override; + virtual bool IsReadOnly() const override; + + void EnableFocusSelectionHide( bool bHide ); + + virtual void SetMaxTextLen(sal_Int32 nMaxLen) override; + virtual sal_Int32 GetMaxTextLen() const override; + + void SetMaxTextWidth(tools::Long nMaxWidth); + + virtual void SetSelection( const Selection& rSelection ) override; + virtual const Selection& GetSelection() const override; + + virtual void ReplaceSelected( const OUString& rStr ) override; + virtual void DeleteSelected() override; + virtual OUString GetSelected() const override; + OUString GetSelected( LineEnd aSeparator ) const; + + bool CanUp() const; + bool CanDown() const; + + virtual void Cut() override; + virtual void Copy() override; + virtual void Paste() override; + + virtual void SetText( const OUString& rStr ) override; + virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) override + { SetText( rStr ); SetSelection( rNewSelection ); } + OUString GetText() const override; + OUString GetText( LineEnd aSeparator ) const; + OUString GetTextLines( LineEnd aSeparator ) const; + + void SetModifyHdl( const Link<Edit&,void>& rLink ) override { aModifyHdlLink = rLink; } + const Link<Edit&,void>& GetModifyHdl() const override { return aModifyHdlLink; } + + virtual void Resize() override; + virtual void GetFocus() override; + + virtual Size CalcMinimumSize() const override; + Size CalcAdjustedSize( const Size& rPrefSize ) const; + Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const; + void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const; + + void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; + + void DisableSelectionOnFocus(); + + void EnableCursor( bool bEnable ); + + ScrollBar& GetVScrollBar() const; + + TextWindow* GetTextWindow(); + + virtual FactoryFunction GetUITestFactory() const override; + + virtual bool set_property(const OUString &rKey, const OUString &rValue) override; + + virtual void DumpAsPropertyTree(tools::JsonWriter&) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/toolkit/viewdataentry.hxx b/include/vcl/toolkit/viewdataentry.hxx new file mode 100644 index 0000000000..b34a8e3ef5 --- /dev/null +++ b/include/vcl/toolkit/viewdataentry.hxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + +#include <sal/types.h> +#include <vector> + +class SvTreeListBox; + +struct SvViewDataItem +{ + int mnWidth = 0; + int mnHeight = 0; +}; + +/** + * View-dependent data for a tree list entry created in the virtual function + * SvTreeListBox::CreateViewData(). The item array contains the same number + * of items as that of the items in its corresponding tree list entry. + * + * When an entry is selected, it is logically selected and visually + * highlighted. When an entry is only highlighted, it looks visually + * highlighted, but not logically selected. + */ +class SvViewDataEntry +{ + friend class SvTreeList; + + std::vector<SvViewDataItem> maItems; + sal_uInt32 nVisPos; + bool mbSelected:1; + bool mbHighlighted:1; + bool mbExpanded:1; + bool mbFocused:1; + bool mbSelectable:1; + bool mbDragTarget:1; + +public: + SvViewDataEntry(); + SvViewDataEntry( const SvViewDataEntry& ); + ~SvViewDataEntry(); + + bool IsSelected() const { return mbSelected;} + bool IsHighlighted() const { return mbHighlighted;} + bool IsExpanded() const { return mbExpanded;} + bool HasFocus() const { return mbFocused;} + bool IsSelectable() const { return mbSelectable;} + bool IsDragTarget() const { return mbDragTarget;} + void SetFocus( bool bFocus ); + void SetSelected( bool bSelected ); + void SetExpanded( bool bExpanded ); + void SetSelectable( bool bSelectable ); + void SetDragTarget( bool bDragTarget ) + { + mbDragTarget = bDragTarget; + } + + void Init(size_t nSize); + + const SvViewDataItem& GetItem(size_t nPos) const; + SvViewDataItem& GetItem(size_t nPos); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |