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 #ifndef DBAUI_TABLEWINDOW_HXX
28*cdf0e10cSrcweir #define DBAUI_TABLEWINDOW_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
32*cdf0e10cSrcweir #include "TableWindowTitle.hxx"
33*cdf0e10cSrcweir #include <tools/rtti.hxx>
34*cdf0e10cSrcweir #include <rtl/ref.hxx>
35*cdf0e10cSrcweir #include "TableWindowData.hxx"
36*cdf0e10cSrcweir #include <vector>
37*cdf0e10cSrcweir #include <vcl/window.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <comphelper/containermultiplexer.hxx>
40*cdf0e10cSrcweir #include "cppuhelper/basemutex.hxx"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir class SvLBoxEntry;
43*cdf0e10cSrcweir namespace dbaui
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////////
46*cdf0e10cSrcweir 	// Flags fuer die Groessenanpassung der SbaJoinTabWins
47*cdf0e10cSrcweir 	const sal_uInt16 SIZING_NONE	= 0x0000;
48*cdf0e10cSrcweir 	const sal_uInt16 SIZING_TOP		= 0x0001;
49*cdf0e10cSrcweir 	const sal_uInt16 SIZING_BOTTOM	= 0x0002;
50*cdf0e10cSrcweir 	const sal_uInt16 SIZING_LEFT	= 0x0004;
51*cdf0e10cSrcweir 	const sal_uInt16 SIZING_RIGHT	= 0x0008;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 	class OTableWindowListBox;
54*cdf0e10cSrcweir 	class OJoinDesignView;
55*cdf0e10cSrcweir 	class OJoinTableView;
56*cdf0e10cSrcweir 	class OTableWindowAccess;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	class OTableWindow : public ::cppu::BaseMutex
59*cdf0e10cSrcweir                         ,public ::comphelper::OContainerListener
60*cdf0e10cSrcweir                         ,public Window
61*cdf0e10cSrcweir 	{
62*cdf0e10cSrcweir 		friend class OTableWindowTitle;
63*cdf0e10cSrcweir 		friend class OTableWindowListBox;
64*cdf0e10cSrcweir     protected:
65*cdf0e10cSrcweir 		// und die Tabelle selber (brauche ich, da ich sie locken will, solange das Fenster lebt)
66*cdf0e10cSrcweir         FixedImage              m_aTypeImage;
67*cdf0e10cSrcweir 		OTableWindowTitle		m_aTitle;
68*cdf0e10cSrcweir 		OTableWindowListBox*	m_pListBox;
69*cdf0e10cSrcweir 		OTableWindowAccess*		m_pAccessible;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	private:
72*cdf0e10cSrcweir         TTableWindowData::value_type
73*cdf0e10cSrcweir                                 m_pData;
74*cdf0e10cSrcweir         ::rtl::Reference< comphelper::OContainerListenerAdapter>
75*cdf0e10cSrcweir                                 m_pContainerListener;
76*cdf0e10cSrcweir 		sal_Int32				m_nMoveCount;			// how often the arrow keys was pressed
77*cdf0e10cSrcweir 		sal_Int32				m_nMoveIncrement;		// how many pixel we should move
78*cdf0e10cSrcweir 		sal_uInt16					m_nSizingFlags;
79*cdf0e10cSrcweir 		sal_Bool					m_bActive;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 		void Draw3DBorder( const Rectangle& rRect );
82*cdf0e10cSrcweir         // OContainerListener
83*cdf0e10cSrcweir         virtual void _elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException);
84*cdf0e10cSrcweir 	    virtual void _elementRemoved( const  ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException);
85*cdf0e10cSrcweir 	    virtual void _elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException);
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	protected:
88*cdf0e10cSrcweir 		virtual void	Resize();
89*cdf0e10cSrcweir 		virtual void	Paint( const Rectangle& rRect );
90*cdf0e10cSrcweir 		virtual void	MouseMove( const MouseEvent& rEvt );
91*cdf0e10cSrcweir 		virtual void	MouseButtonDown( const MouseEvent& rEvt );
92*cdf0e10cSrcweir 		virtual void	DataChanged( const DataChangedEvent& rDCEvt );
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 		virtual OTableWindowListBox*	CreateListBox();
95*cdf0e10cSrcweir 			// wird im ERSTEN Init aufgerufen
96*cdf0e10cSrcweir 		sal_Bool FillListBox();
97*cdf0e10cSrcweir 			// wird in JEDEM Init aufgerufen
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 		virtual void OnEntryDoubleClicked(SvLBoxEntry* /*pEntry*/) { }
100*cdf0e10cSrcweir 			// wird aus dem DoubleClickHdl der ListBox heraus aufgerufen
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 		/** HandleKeyInput triues to handle the KeyEvent. Movement or deletion
103*cdf0e10cSrcweir 			@param	rEvt
104*cdf0e10cSrcweir 				The KEyEvent
105*cdf0e10cSrcweir 			@return
106*cdf0e10cSrcweir 				<TRUE/> when the table could handle the keyevent.
107*cdf0e10cSrcweir 		*/
108*cdf0e10cSrcweir 		sal_Bool			HandleKeyInput( const KeyEvent& rEvt );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 		/** delete the user data with the equal type as created within createUserData
111*cdf0e10cSrcweir 			@param	_pUserData
112*cdf0e10cSrcweir 				The user data store in the listbox entries. Created with a call to createUserData.
113*cdf0e10cSrcweir 				_pUserData may be <NULL/>. _pUserData will be set to <NULL/> after call.
114*cdf0e10cSrcweir 		*/
115*cdf0e10cSrcweir 		virtual void deleteUserData(void*& _pUserData);
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 		/** creates user information that will be append at the ListBoxentry
118*cdf0e10cSrcweir 			@param	_xColumn
119*cdf0e10cSrcweir 				The corresponding column, can be <NULL/>.
120*cdf0e10cSrcweir 			@param	_bPrimaryKey
121*cdf0e10cSrcweir 				<TRUE/> when the column belongs to the primary key
122*cdf0e10cSrcweir 			@return
123*cdf0e10cSrcweir 				the user data which will be append at the listbox entry, may be <NULL/>
124*cdf0e10cSrcweir 		*/
125*cdf0e10cSrcweir 		virtual void* createUserData(const ::com::sun::star::uno::Reference<
126*cdf0e10cSrcweir 									::com::sun::star::beans::XPropertySet>& _xColumn,
127*cdf0e10cSrcweir 									bool _bPrimaryKey);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         /** updates m_aTypeImage
130*cdf0e10cSrcweir         */
131*cdf0e10cSrcweir         void    impl_updateImage();
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 		OTableWindow( Window* pParent, const TTableWindowData::value_type& pTabWinData );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	public:
136*cdf0e10cSrcweir 		virtual ~OTableWindow();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 		// spaeter Constructor, siehe auch CreateListbox und FillListbox
139*cdf0e10cSrcweir 		virtual sal_Bool Init();
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 		OJoinTableView*				getTableView();
142*cdf0e10cSrcweir 		const OJoinTableView*		getTableView() const;
143*cdf0e10cSrcweir 		OJoinDesignView*			getDesignView();
144*cdf0e10cSrcweir 		void						SetPosPixel( const Point& rNewPos );
145*cdf0e10cSrcweir 		void						SetSizePixel( const Size& rNewSize );
146*cdf0e10cSrcweir 		void						SetPosSizePixel( const Point& rNewPos, const Size& rNewSize );
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 		String						getTitle() const;
149*cdf0e10cSrcweir 		void						SetBoldTitle( sal_Bool bBold );
150*cdf0e10cSrcweir 		void						setActive(sal_Bool _bActive = sal_True);
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 		void						Remove();
153*cdf0e10cSrcweir 		sal_Bool						IsActiveWindow(){ return m_bActive; }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 		::rtl::OUString				GetTableName() const { return m_pData->GetTableName(); }
156*cdf0e10cSrcweir 		::rtl::OUString				GetWinName() const { return m_pData->GetWinName(); }
157*cdf0e10cSrcweir 		::rtl::OUString				GetComposedName() const { return m_pData->GetComposedName(); }
158*cdf0e10cSrcweir 		OTableWindowListBox*		GetListBox() const { return m_pListBox; }
159*cdf0e10cSrcweir 		TTableWindowData::value_type GetData() const { return m_pData; }
160*cdf0e10cSrcweir 		OTableWindowTitle*			GetTitleCtrl() { return &m_aTitle; }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 		/** returns the name which should be used when displaying join or relations
163*cdf0e10cSrcweir 			@return
164*cdf0e10cSrcweir 				The composed name or the window name.
165*cdf0e10cSrcweir 		*/
166*cdf0e10cSrcweir 		virtual ::rtl::OUString		GetName() const = 0;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         inline ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > GetOriginalColumns() const { return m_pData->getColumns(); }
169*cdf0e10cSrcweir         inline ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >    GetTable() const { return m_pData->getTable(); }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 		sal_uInt16						GetSizingFlags() const { return m_nSizingFlags; }
172*cdf0e10cSrcweir 		/** set the sizing flag to the direction
173*cdf0e10cSrcweir 			@param	_rPos
174*cdf0e10cSrcweir 				The EndPosition after resizing.
175*cdf0e10cSrcweir 		*/
176*cdf0e10cSrcweir 		void						setSizingFlag(const Point& _rPos);
177*cdf0e10cSrcweir 		/** set the rsizing flag to NONE.
178*cdf0e10cSrcweir 		*/
179*cdf0e10cSrcweir 		void						resetSizingFlag() { m_nSizingFlags = SIZING_NONE; }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 		/** returns the new sizing
182*cdf0e10cSrcweir 		*/
183*cdf0e10cSrcweir 		Rectangle getSizingRect(const Point& _rPos,const Size& _rOutputSize) const;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 		// window override
186*cdf0e10cSrcweir 		virtual void				StateChanged( StateChangedType nStateChange );
187*cdf0e10cSrcweir 		virtual void				GetFocus();
188*cdf0e10cSrcweir 		virtual long				PreNotify( NotifyEvent& rNEvt );
189*cdf0e10cSrcweir 		virtual void				Command(const CommandEvent& rEvt);
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 		// Accessibility
192*cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 		// habe ich Connections nach aussen ?
195*cdf0e10cSrcweir 		sal_Bool ExistsAConn() const;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 		void EnumValidFields(::std::vector< ::rtl::OUString>& arrstrFields);
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 		/** clears the listbox inside. Must be called be the dtor is called.
200*cdf0e10cSrcweir 		*/
201*cdf0e10cSrcweir 		void clearListBox();
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     protected:
204*cdf0e10cSrcweir         using Window::SetPosSizePixel;
205*cdf0e10cSrcweir 	};
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir #endif //DBAUI_TABLEWINDOW_HXX
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 
210