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