1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef DBAUI_APPDETAILPAGEHELPER_HXX
24 #define DBAUI_APPDETAILPAGEHELPER_HXX
25 
26 #include <vector>
27 
28 #ifndef _RTL_USTRING_HXX_
29 #include <rtl/ustring.hxx>
30 #endif
31 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
32 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
33 #endif
34 #ifndef _COM_SUN_STAR_SDB_APPLICATION_NAMEDDATABASEOBJECT_HPP_
35 #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
36 #endif
37 #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
38 #include <com/sun/star/ucb/XContent.hpp>
39 #endif
40 #ifndef DBAUI_APPELEMENTTYPE_HXX
41 #include "AppElementType.hxx"
42 #endif
43 #ifndef _SVTREEBOX_HXX
44 #include <svtools/svtreebx.hxx>
45 #endif
46 #ifndef SVTOOLS_DOCUMENTINFOPREVIEW_HXX
47 #include <svtools/DocumentInfoPreview.hxx>
48 #endif
49 #ifndef _SV_FIXED_HXX
50 #include <vcl/fixed.hxx>
51 #endif
52 #ifndef _SV_TOOLBOX_HXX
53 #include <vcl/toolbox.hxx>
54 #endif
55 #ifndef _SV_CVTGRF_HXX
56 #include <vcl/cvtgrf.hxx>
57 #endif
58 #ifndef _SV_GRAPH_HXX
59 #include <vcl/graph.hxx>
60 #endif
61 #ifndef _GRFMGR_HXX
62 #include <svtools/grfmgr.hxx>
63 #endif
64 #include "callbacks.hxx"
65 #include <memory>
66 
67 namespace com{ namespace sun { namespace star { namespace awt   { class XWindow; } } } }
68 namespace com{ namespace sun { namespace star { namespace frame { class XFrame; } } } }
69 namespace com{ namespace sun { namespace star { namespace io    { class XPersist; } } } }
70 
71 #define ELEMENT_COUNT   size_t(E_ELEMENT_TYPE_COUNT)
72 
73 namespace dbaui
74 {
75 	class OAppBorderWindow;
76 	class DBTreeListBox;
77 
78 	class OPreviewWindow : public Window
79 	{
80 		GraphicObject		m_aGraphicObj;
81 		Rectangle			m_aPreviewRect;
82 
83 		/** gets the graphic cnter rect
84 			@param	rGraphic
85 				the graphic
86 			@param	rResultRect
87 				the resulting rectangle
88 
89 			@return
90 				<TRUE/> when successfull
91 		*/
92 		sal_Bool ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const;
93 		void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
94 	protected:
95 		virtual void DataChanged(const DataChangedEvent& rDCEvt);
96 	public:
97 		OPreviewWindow(Window* _pParent);
98 
99 		// window overloads
100 		virtual void Paint(const Rectangle& rRect);
101 
setGraphic(const Graphic & _rGraphic)102 		void setGraphic(const Graphic& _rGraphic ) { m_aGraphicObj.SetGraphic(_rGraphic); }
103 	};
104 	//==================================================================
105 	// A helper class for the controls in the detail page.
106 	// Combines general functionality.
107 	//==================================================================
108 	class OAppDetailPageHelper : public Window
109 	{
110 		DBTreeListBox*		m_pLists[ELEMENT_COUNT];
111 		OAppBorderWindow&	m_rBorderWin;
112 		FixedLine			m_aFL;
113 		ToolBox				m_aTBPreview;
114 		Window				m_aBorder;
115 		OPreviewWindow		m_aPreview;
116 		::svtools::ODocumentInfoPreview
117 							m_aDocumentInfo;
118 		Window*				m_pTablePreview;
119 		::std::auto_ptr<PopupMenu> m_aMenu;
120 		PreviewMode			m_ePreviewMode;
121 		::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >
122 							m_xFrame;
123 		::com::sun::star::uno::Reference < ::com::sun::star::io::XPersist >
124 							m_xDocInfo;
125 		::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >
126 							m_xWindow;
127 
128 		/// returns the index of the visible control
129 		int getVisibleControlIndex() const;
130 
131 		/** sorts the entries in the tree list box.
132 			@param	_nPos
133 				Which list should be sorted.
134 			@param	_eSortMode
135 				How should be sorted.
136 		*/
137 		void sort(int _nPos,SvSortMode _eSortMode );
138 
139         /** retrieves the resource ids of the images representing elements of the given type
140         */
141         void getElementIcons( ElementType _eType, sal_uInt16& _rImageId, sal_uInt16& _rHighContrastImageId );
142 
143 		/** fills the names in the listbox
144 			@param	_xContainer
145 				This can either be the queries, forms or report names.
146 			@param	_eType
147 				the type of elements which are being filled
148             @param _nImageId
149                 the resource id of the image to use for non-container entries
150             @param _nHighContrastImageId
151                 the resource id of the high contrast image to use for non-container entries
152 			@param	_pParent
153 				The parent of the entries to be inserted.
154 		*/
155 		void fillNames( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer,
156 						const ElementType _eType,
157 						const sal_uInt16 _nImageId,
158 						const sal_uInt16 _nHighContrastImageId,
159 						SvLBoxEntry* _pParent );
160 
161 		/** sets the detail page
162 			@param	_pWindow
163 				The control which should be visible.
164 		*/
165 		void setDetailPage(Window* _pWindow);
166 
167 		/** sets all HandleCallbacks
168 			@param	_pTreeView
169 				The newly created DBTreeListBox
170 			@param	_rImage
171 				the resource id of the default icon
172 			@param	_rImageHC
173 				the resource id of the default icon (HC version)
174 			@return
175 				The new tree.
176 		*/
177         DBTreeListBox* createTree( DBTreeListBox* _pTreeView, const Image& _rImage, const Image& _rImageHC );
178 
179 		/** creates the tree and sets all HandleCallbacks
180 			@param	_nHelpId
181 				The help id of the control
182 			@param	_nCollapsedBitmap
183 				The image to use for tree entries.
184 			@param	_rImageHC
185 				The image to use in high contrast mode.
186 			@return
187 				The new tree.
188 		*/
189 		DBTreeListBox* createSimpleTree( const rtl::OString& _sHelpId, const Image& _rImage, const Image& _rImageHC );
190 
191 		DECL_LINK( OnEntryDoubleClick,			SvTreeListBox* );
192 		DECL_LINK( OnEntrySelChange,			void* );
193 
194 		DECL_LINK( OnCutEntry,					void* );
195 		DECL_LINK( OnCopyEntry, 				void* );
196 		DECL_LINK( OnPasteEntry,				void* );
197 		DECL_LINK( OnDeleteEntry,				void* );
198 
199 		DECL_LINK(PreviewChangeHdl, void*);
200 		// click a TB slot
201 		DECL_LINK(OnDropdownClickHdl, ToolBox*);
202 
getBorderWin() const203 		inline OAppBorderWindow& getBorderWin() const { return m_rBorderWin; }
204 		void ImplInitSettings();
205 
206     public:
207 		OAppDetailPageHelper(Window* _pParent,OAppBorderWindow& _rBorderWin,PreviewMode _ePreviewMode);
208 		virtual ~OAppDetailPageHelper();
209 
210 		// window overloads
211 		virtual void Resize();
212 		virtual void KeyInput( const KeyEvent& rKEvt );
213 
214         sal_Bool isCutAllowed();
215 		sal_Bool isCopyAllowed();
216 		sal_Bool isPasteAllowed();
217 		void copy();
218 		void cut();
219 		void paste();
220 
221 		/** creates the tables page
222 			@param	_xConnection
223 				The connection to get the table names
224 		*/
225 		void createTablesPage(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection);
226 
227 		/** creates the page for the specific type.
228 			@param	_eType
229 				The type which should be created. E_TABLE isn't allowed.
230 			@param	_xContainer
231 				The container of the elements to be inserted.
232 		*/
233 		void createPage(ElementType _eType,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer);
234 
235 		/** returns the current visible tree list box
236 		*/
getCurrentView() const237 		inline DBTreeListBox* getCurrentView() const
238 		{
239 			ElementType eType = getElementType();
240 			return (eType != E_NONE ) ? m_pLists[static_cast<sal_Int32>(eType)] : NULL;
241 		}
242 
243 		/// select all entries in the visible control
244 		void selectAll();
245 
246 		/// returns <TRUE/> if it sorts ascending
247 		sal_Bool isSortUp() const;
248 
249 		/// sorts all entries ascending
250 		void sortDown();
251 
252 		/// sorts all entries descending
253 		void sortUp();
254 
255 		/** returns the element names which are selected
256 			@param	_rNames
257 				The list will be filled.
258 		*/
259 		void getSelectionElementNames( ::std::vector< ::rtl::OUString>& _rNames ) const;
260 
261         /** describes the current selection for the given control
262         */
263         void    describeCurrentSelectionForControl(
264                     const Control& _rControl,
265                     ::com::sun::star::uno::Sequence< ::com::sun::star::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
266                 );
267 
268         /** describes the current selection for the given ElementType
269         */
270         void    describeCurrentSelectionForType(
271                     const ElementType _eType,
272                     ::com::sun::star::uno::Sequence< ::com::sun::star::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
273                 );
274 
275         /** select all names on the currently selected container. Non existence names where ignored.
276         *
277         * \param _aNames the element names
278         */
279         void selectElements(const ::com::sun::star::uno::Sequence< ::rtl::OUString>& _aNames);
280 
281 		/** return the qualified name.
282 			@param	_pEntry
283 				The entry of a table, or query, form, report to get the qualified name.
284 				If the entry is <NULL/>, the first selected is chosen.
285 			@return
286 				the qualified name
287 		*/
288 		::rtl::OUString getQualifiedName( SvLBoxEntry* _pEntry ) const;
289 
290 		/// return the element of currently select entry
291 		ElementType getElementType() const;
292 
293 		/// returns the count of selected entries
294 		sal_Int32 getSelectionCount();
295 
296 		/// returns the count of entries
297 		sal_Int32 getElementCount();
298 
299 		/** returns if an entry is a leaf
300 			@param _pEntry
301 				The entry to check
302 			@return
303 				<TRUE/> if the entry is a leaf, otherwise <FALSE/>
304 		*/
305 		bool    isLeaf(SvLBoxEntry* _pEntry) const;
306 
307 		/** returns if one of the selected entries is a leaf
308 			@return
309 				<TRUE/> if the entry is a leaf, otherwise <FALSE/>
310 		*/
311 		sal_Bool isALeafSelected() const;
312 
313 		SvLBoxEntry* getEntry( const Point& _aPosPixel ) const;
314 
315 		/// clears the detail pages
316 		void clearPages();
317 
318 		/// returns <TRUE/> when a detail page was filled
319 		sal_Bool isFilled() const;
320 
321 		/** adds a new object to the detail page.
322 			@param	_eType
323 				The type where the entry shold be appended.
324 			@param	_rName
325 				The name of the object to be inserted
326 			@param	_rObject
327 				The object to add.
328 			@param	_rxConn
329 				If we insert a table, the connection must be set.
330 		*/
331 		SvLBoxEntry*  elementAdded(ElementType eType
332 						,const ::rtl::OUString& _rName
333 						,const ::com::sun::star::uno::Any& _rObject );
334 
335 		/** replaces a objects name with a new one
336 			@param	_eType
337 				The type where the entry shold be appended.
338 			@param	_rOldName
339 				The old name of the object to be replaced
340 			@param	_rNewName
341 				The new name of the object to be replaced
342 			@param	_rxConn
343 				If we insert a table, the connection must be set.
344 		*/
345 		void elementReplaced(ElementType eType
346 						,const ::rtl::OUString& _rOldName
347 						,const ::rtl::OUString& _rNewName );
348 
349 		/** removes an element from the detail page.
350 			@param	_eType
351 				The type where the entry shold be appended.
352 			@param	_rName
353 				The name of the element to be removed.
354 			@param	_rxConn
355 				If we remove a table, the connection must be set.
356 		*/
357 		void elementRemoved(ElementType _eType
358 							,const ::rtl::OUString& _rName );
359 
360 
361 		/// returns the preview mode
362 		PreviewMode getPreviewMode();
363 
364 		/// <TRUE/> if the preview is enabled
365 		sal_Bool isPreviewEnabled();
366 
367 		/** switches to the given preview mode
368 			@param	_eMode
369 				the mode to set for the preview
370 			@param	_bForce
371 				Force the preview to be resetted
372 		*/
373 		void switchPreview(PreviewMode _eMode,sal_Bool _bForce = sal_False);
374 
375 		/** shows the Preview of the content when it is enabled.
376 			@param	_xContent
377 				The content which must support the "preview" command.
378 		*/
379 		void showPreview(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xContent);
380 
381 		/** shows the Preview of a table or query
382 			@param	_sDataSourceName
383 				the name of the data source
384 			@param	_sName
385 				the name of table or query
386 			@param	_bTable
387 				<TRUE/> if it is a table, otherwise <FALSE/>
388 			@return	void
389 		*/
390 		void showPreview(	const ::rtl::OUString& _sDataSourceName,
391 							const ::rtl::OUString& _sName,
392 							sal_Bool _bTable);
393 
394     protected:
395         void DataChanged( const DataChangedEvent& rDCEvt );
396 	};
397 }
398 #endif // DBAUI_APPDETAILPAGEHELPER_HXX
399 
400