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