xref: /AOO41X/main/extensions/source/propctrlr/browserlistbox.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _EXTENSIONS_PROPCTRLR_BROWSERLISTBOX_HXX_
29 #define _EXTENSIONS_PROPCTRLR_BROWSERLISTBOX_HXX_
30 
31 #include "browserline.hxx"
32 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
33 #include "modulepcr.hxx"
34 #endif
35 #include "pcrcommon.hxx"
36 
37 /** === begin UNO includes === **/
38 #include <com/sun/star/inspection/XPropertyControl.hpp>
39 #include <com/sun/star/inspection/XPropertyHandler.hpp>
40 /** === end UNO includes === **/
41 #include <vcl/scrbar.hxx>
42 #include <vcl/lstbox.hxx>
43 #ifndef _SV_BUTTON_HXX
44 #include <vcl/button.hxx>
45 #endif
46 #include <tools/link.hxx>
47 #include <rtl/ref.hxx>
48 
49 #include <set>
50 #include <vector>
51 #include <hash_map>
52 #include <boost/shared_ptr.hpp>
53 
54 //............................................................................
55 namespace pcr
56 {
57 //............................................................................
58 
59     class IPropertyLineListener;
60     class IPropertyControlObserver;
61     struct OLineDescriptor;
62     class InspectorHelpWindow;
63     class PropertyControlContext_Impl;
64 
65     //========================================================================
66     //= administrative structures for OBrowserListBox
67     //========================================================================
68     typedef ::boost::shared_ptr< OBrowserLine > BrowserLinePointer;
69     struct ListBoxLine
70     {
71         BrowserLinePointer                      pLine;
72         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >
73                                                 xHandler;
74 
75         ListBoxLine() { }
76         ListBoxLine( BrowserLinePointer _pLine, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _rxHandler )
77             :pLine( _pLine )
78             ,xHandler( _rxHandler )
79         {
80         }
81     };
82     typedef ::std::hash_map< ::rtl::OUString, ListBoxLine, ::rtl::OUStringHash >    ListBoxLines;
83     typedef ::std::vector< ListBoxLines::iterator >                                 OrderedListBoxLines;
84 
85     //========================================================================
86     //= IControlContext
87     //========================================================================
88     /** non-UNO version of XPropertyControlContext
89     */
90     class SAL_NO_VTABLE IControlContext
91     {
92     public:
93         virtual void SAL_CALL focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException) = 0;
94         virtual void SAL_CALL valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException) = 0;
95         virtual void SAL_CALL activateNextControl( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& CurrentControl ) throw (::com::sun::star::uno::RuntimeException) = 0;
96     };
97 
98     //========================================================================
99     //= OBrowserListBox
100     //========================================================================
101     class OBrowserListBox   :public Control
102                             ,public IButtonClickListener
103                             ,public IControlContext
104                             ,public PcrClient
105     {
106     protected:
107         Window                      m_aLinesPlayground;
108         ScrollBar                   m_aVScroll;
109         ::std::auto_ptr< InspectorHelpWindow >
110                                     m_pHelpWindow;
111         ListBoxLines                m_aLines;
112         OrderedListBoxLines         m_aOrderedLines;
113         IPropertyLineListener*      m_pLineListener;
114         IPropertyControlObserver*   m_pControlObserver;
115         long                        m_nYOffset;
116         long                        m_nCurrentPreferredHelpHeight;
117         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
118                                     m_xActiveControl;
119         sal_uInt16                  m_nTheNameSize;
120         sal_uInt16                  m_nRowHeight;
121         ::std::set< sal_uInt16 >    m_aOutOfDateLines;
122         sal_Bool                    m_bIsActive : 1;
123         sal_Bool                    m_bUpdate : 1;
124         ::rtl::Reference< PropertyControlContext_Impl >
125                                     m_pControlContextImpl;
126 
127     protected:
128         void    PositionLine( sal_uInt16 _nIndex );
129         void    UpdatePosNSize();
130         void    UpdatePlayGround();
131         void    UpdateVScroll();
132         void    ShowEntry(sal_uInt16 nPos);
133         void    MoveThumbTo(sal_Int32 nNewThumbPos);
134         void    Resize();
135 
136     public:
137                                     OBrowserListBox( Window* pParent, WinBits nWinStyle = WB_DIALOGCONTROL );
138 
139                                     ~OBrowserListBox();
140 
141         void                        UpdateAll();
142 
143         void                        ActivateListBox( sal_Bool _bActive );
144 
145         sal_uInt16                  CalcVisibleLines();
146         void                        EnableUpdate();
147         void                        DisableUpdate();
148         long                        Notify( NotifyEvent& _rNEvt );
149         long                        PreNotify( NotifyEvent& _rNEvt );
150 
151         void                        SetListener( IPropertyLineListener* _pListener );
152         void                        SetObserver( IPropertyControlObserver* _pObserver );
153 
154         void                        EnableHelpSection( bool _bEnable );
155         bool                        HasHelpSection() const;
156         void                        SetHelpText( const ::rtl::OUString& _rHelpText );
157         void                        SetHelpLineLimites( sal_Int32 _nMinLines, sal_Int32 _nMaxLines );
158 
159         void                        Clear();
160 
161         sal_uInt16                  InsertEntry( const OLineDescriptor&, sal_uInt16 nPos = EDITOR_LIST_APPEND );
162         sal_Bool                    RemoveEntry( const ::rtl::OUString& _rName );
163         void                        ChangeEntry( const OLineDescriptor&, sal_uInt16 nPos );
164 
165         void                        SetPropertyValue( const ::rtl::OUString& rEntryName, const ::com::sun::star::uno::Any& rValue, bool _bUnknownValue );
166         sal_uInt16                  GetPropertyPos( const ::rtl::OUString& rEntryName ) const;
167         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
168                                     GetPropertyControl( const ::rtl::OUString& rEntryName );
169         void                        EnablePropertyControls( const ::rtl::OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable );
170         void                        EnablePropertyLine( const ::rtl::OUString& _rEntryName, bool _bEnable );
171 
172         sal_Int32                   GetMinimumWidth();
173         sal_Int32                   GetMinimumHeight();
174 
175 
176         sal_Bool    IsModified( ) const;
177         void        CommitModified( );
178 
179     protected:
180         // IControlContext
181         virtual void SAL_CALL focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException);
182         virtual void SAL_CALL valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException);
183         virtual void SAL_CALL activateNextControl( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& CurrentControl ) throw (::com::sun::star::uno::RuntimeException);
184 
185         // IButtonClickListener
186         void    buttonClicked( OBrowserLine* _pLine, sal_Bool _bPrimary );
187 
188         using Window::SetHelpText;
189     private:
190         DECL_LINK( ScrollHdl, ScrollBar* );
191 
192         /** retrieves the index of a given control in our line list
193             @param _rxControl
194                 The control to lookup. Must denote a control of one of the lines in ->m_aLines
195         */
196         sal_uInt16  impl_getControlPos( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _rxControl ) const;
197 
198         /** retrieves (a reference to) the ->ListBoxLine for a given control
199             @param _rxControl
200                 The control to lookup. Must denote a control of one of the lines in ->m_aLines
201         */
202         inline const ListBoxLine&
203                     impl_getControlLine( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _rxControl ) const
204         {
205             return m_aOrderedLines[ impl_getControlPos( _rxControl ) ]->second;
206         }
207 
208         /** sets the given property value at the given control, after converting it as necessary
209             @param _rLine
210                 The line whose at which the value is to be set.
211             @param _rPropertyValue
212                 the property value to set. If it's not compatible with the control value,
213                 it will be converted, using <member>XPropertyHandler::convertToControlValue</member>
214         */
215         void        impl_setControlAsPropertyValue( const ListBoxLine& _rLine, const ::com::sun::star::uno::Any& _rPropertyValue );
216 
217         /** retrieves the value for the given control, as a property value, after converting it as necessary
218             @param _rLine
219                 The line whose at which the value is to be set.
220         */
221         ::com::sun::star::uno::Any
222                     impl_getControlAsPropertyValue( const ListBoxLine& _rLine ) const;
223 
224         /** retrieves the ->BrowserLinePointer for a given entry name
225             @param  _rEntryName
226                 the name whose line is to be looked up
227             @param  _out_rpLine
228                 contains, upon return, the found browser line, if any
229             @return
230                 <TRUE/> if and only if a non-<NULL/> line for the given entry name could be
231                 found.
232         */
233         bool        impl_getBrowserLineForName( const ::rtl::OUString& _rEntryName, BrowserLinePointer& _out_rpLine ) const;
234 
235         /** returns the preferred height (in pixels) of the help section, or 0 if we
236             currently don't have a help section
237         */
238         long        impl_getPrefererredHelpHeight();
239 
240     private:
241         using Window::Activate;
242     };
243 
244 //............................................................................
245 } // namespace pcr
246 //............................................................................
247 
248 #endif // _EXTENSIONS_PROPCTRLR_BROWSERLISTBOX_HXX_
249 
250 
251