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_APPDETAILVIEW_HXX
28 #define DBAUI_APPDETAILVIEW_HXX
29 
30 #ifndef _COM_SUN_STAR_FRAME_XCONTROLLER_HPP_
31 #include <com/sun/star/frame/XController.hpp>
32 #endif
33 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
37 #include <com/sun/star/sdbc/XConnection.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
40 #include <com/sun/star/ucb/XContent.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_SDB_APPLICATION_NAMEDDATABASEOBJECT_HPP_
43 #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
44 #endif
45 #ifndef _SV_SPLIT_HXX
46 #include <vcl/split.hxx>
47 #endif
48 #ifndef _SV_FIXED_HXX
49 #include <vcl/fixed.hxx>
50 #endif
51 #ifndef _SV_MNEMONIC_HXX
52 #include <vcl/mnemonic.hxx>
53 #endif
54 #ifndef DBACCESS_TABLEDESIGN_ICLIPBOARDTEST_HXX
55 #include "IClipBoardTest.hxx"
56 #endif
57 #ifndef DBAUI_TITLE_WINDOW_HXX
58 #include "AppTitleWindow.hxx"
59 #endif
60 #ifndef DBAUI_APPELEMENTTYPE_HXX
61 #include "AppElementType.hxx"
62 #endif
63 #ifndef _SVTREEBOX_HXX
64 #include <svtools/svtreebx.hxx>
65 #endif
66 #ifndef DBAUI_VERTSPLITVIEW_HXX
67 #include "VertSplitView.hxx"
68 #endif
69 
70 #include <vector>
71 
72 class SvLBoxEntry;
73 
74 namespace dbaui
75 {
76 	class OAppBorderWindow;
77 	class OApplicationDetailView;
78 	class OAppDetailPageHelper;
79 	class OTasksWindow;
80 
81 	class OCreationList : public SvTreeListBox
82 	{
83 		OTasksWindow&   m_rTaskWindow;
84 
85         // members related to drawing the currently hovered/selected entry
86         SvLBoxEntry*        m_pMouseDownEntry;
87         SvLBoxEntry*        m_pLastActiveEntry;
88         Color               m_aOriginalBackgroundColor;
89         Font                m_aOriginalFont;
90 
91 	public:
92 		OCreationList( OTasksWindow& _rParent );
93 		// window overloads
94 		virtual void MouseMove( const MouseEvent& rMEvt );
95 		virtual void MouseButtonDown( const MouseEvent& rMEvt );
96 		virtual void MouseButtonUp( const MouseEvent& rMEvt );
97 		virtual void KeyInput( const KeyEvent& rKEvt );
98         virtual void Paint( const Rectangle& rRect );
99 	    virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel );
100         virtual void GetFocus();
101         virtual void LoseFocus();
102 
103         inline void resetLastActive() { m_pLastActiveEntry = NULL;}
104 
105         void    updateHelpText();
106 
107     protected:
108 	    virtual void	    PreparePaint( SvLBoxEntry* _pEntry );
109 	    virtual Rectangle   GetFocusRect( SvLBoxEntry* _pEntry, long _nLine );
110         virtual void        ModelHasCleared();
111 
112         // IMnemonicEntryList
113         virtual void        SelectSearchEntry( const void* _pEntry );
114         virtual void        ExecuteSearchEntry( const void* _pEntry ) const;
115 
116     private:
117         void    onSelected( SvLBoxEntry* _pEntry ) const;
118         /** sets a new current entry, and invalidates the old and the new one, if necessary
119             @return <TRUE/> if and only if the "current entry" changed
120         */
121         bool    setCurrentEntryInvalidate( SvLBoxEntry* _pEntry );
122 	};
123 
124     struct TaskEntry
125     {
126         ::rtl::OUString sUNOCommand;
127         sal_uInt16          nHelpID;
128         String          sTitle;
129         bool            bHideWhenDisabled;
130             // TODO: we should be consistent in the task pane and the menus/toolbars:
131             // If an entry is disabled in the latter, it should also be disabled in the former.
132             // If an entry is *hidden* in the former, it should also be hidden in the latter.
133 
134         TaskEntry( const sal_Char* _pAsciiUNOCommand, sal_uInt16 _nHelpID, sal_uInt16 _nTitleResourceID, bool _bHideWhenDisabled = false );
135     };
136 	typedef ::std::vector< TaskEntry >	TaskEntryList;
137 
138     struct TaskPaneData
139     {
140         /// the tasks available in the pane
141         TaskEntryList   aTasks;
142         /// the resource ID for the title of the pane
143         sal_uInt16          nTitleId;
144     };
145 
146 	class OTasksWindow : public Window
147 	{
148 		OCreationList						m_aCreation;
149 		FixedText							m_aDescription;
150 		FixedText							m_aHelpText;
151 		FixedLine							m_aFL;
152 		OApplicationDetailView*				m_pDetailView;
153 
154 		DECL_LINK( OnEntrySelectHdl,		SvTreeListBox* );
155 		void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
156 	protected:
157 		virtual void DataChanged(const DataChangedEvent& rDCEvt);
158 	public:
159 		OTasksWindow(Window* _pParent,OApplicationDetailView* _pDetailView);
160 		virtual ~OTasksWindow();
161 
162 		// window overloads
163 		virtual void Resize();
164 
165 		OApplicationDetailView*	getDetailView() const { return m_pDetailView; }
166 
167 		/// fills the Creation listbox with the necessary strings and images
168 		void fillTaskEntryList( const TaskEntryList& _rList );
169 
170 	    inline bool HandleKeyInput( const KeyEvent& _rKEvt )
171         {
172             return m_aCreation.HandleKeyInput( _rKEvt );
173         }
174 
175         void Clear();
176 		void setHelpText(sal_uInt16 _nId);
177 	};
178 	//==================================================================
179 	class OApplicationDetailView : public OSplitterView
180 								 , public IClipboardTest
181 	{
182 		Splitter							m_aHorzSplitter;
183 		OTitleWindow						m_aTasks;
184 		OTitleWindow						m_aContainer;
185 		OAppBorderWindow&					m_rBorderWin;		// my parent
186 		OAppDetailPageHelper*				m_pControlHelper;
187         ::std::vector< TaskPaneData >       m_aTaskPaneData;
188         MnemonicGenerator                   m_aExternalMnemonics;
189 
190 		void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
191 
192     protected:
193 		virtual void DataChanged(const DataChangedEvent& rDCEvt);
194 
195     public:
196 		OApplicationDetailView(OAppBorderWindow& _rParent,PreviewMode _ePreviewMode);
197 		virtual ~OApplicationDetailView();
198 		// window overloads
199 		//	virtual void Resize();
200 		virtual void GetFocus();
201 
202 		/** creates the tables page
203 			@param	_xConnection
204 				The connection to get the table names
205 		*/
206 		void createTablesPage(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection);
207 
208 		/** creates the page for the specific type.
209 			@param	_eType
210 				The type which should be created. E_TABLE isn't allowed.
211 			@param	_xContainer
212 				The container of the elements to be inserted.
213 		*/
214 		void createPage(ElementType _eType,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer);
215 
216         void setTaskExternalMnemonics( MnemonicGenerator& _rMnemonics );
217 
218         /** called to give the window the chance to intercept key events, while it has not
219             the focus
220 
221             @return <TRUE/> if and only if the event has been handled, and should not
222                 not be further processed
223         */
224         bool    interceptKeyInput( const KeyEvent& _rEvent );
225 
226         inline OAppBorderWindow& getBorderWin() const { return m_rBorderWin; }
227         inline OTasksWindow& getTasksWindow() const { return *static_cast< OTasksWindow* >( m_aTasks.getChildWindow() ); }
228 
229 		sal_Bool isCutAllowed()	;
230 		sal_Bool isCopyAllowed()	;
231 		sal_Bool isPasteAllowed();
232 		virtual sal_Bool hasChildPathFocus() { return HasChildPathFocus(); }
233 		void copy();
234 		void cut();
235 		void paste();
236 
237 		/** return the qualified name.
238 			@param	_pEntry
239 				The entry of a table, or query, form, report to get the qualified name.
240 				If the entry is <NULL/>, the first selected is chosen.
241 			@return
242 				the qualified name
243 		*/
244 		::rtl::OUString getQualifiedName( SvLBoxEntry* _pEntry ) const;
245 
246 		/** returns if an entry is a leaf
247 			@param _pEntry
248 				The entry to check
249 			@return
250 				<TRUE/> if the entry is a leaf, otherwise <FALSE/>
251 		*/
252 		sal_Bool isLeaf(SvLBoxEntry* _pEntry) const;
253 
254 		/** returns if one of the selected entries is a leaf
255 			@return
256 				<TRUE/> if the entry is a leaf, otherwise <FALSE/>
257 		*/
258 		sal_Bool isALeafSelected() const;
259 
260 		/** select all entries in the detail page
261 		*/
262 		void selectAll();
263 
264 		/// returns <TRUE/> if it sorts ascending
265 		sal_Bool isSortUp() const;
266 
267 		/// sort the entries in the detail page down
268 		void sortDown();
269 
270 		/// sort the entries in the detail page up
271 		void sortUp();
272 
273 		/// returns <TRUE/> when a detail page was filled
274 		sal_Bool isFilled() const;
275 
276 		/// return the element of currently select entry
277 		ElementType getElementType() const;
278 
279 		/** clears the detail pages.
280 			@param	_bTaskAlso
281 				If <TRUE/> the task window will also be cleared.
282 		*/
283 		void clearPages(sal_Bool _bTaskAlso = sal_True);
284 
285 		/// returns the count of entries
286 		sal_Int32 getElementCount();
287 
288 		/// returns the count of selected entries
289 		sal_Int32 getSelectionCount();
290 
291 		/** returns the element names which are selected
292 			@param	_rNames
293 				The list will be filled.
294 		*/
295 		void getSelectionElementNames(::std::vector< ::rtl::OUString>& _rNames ) const;
296 
297         /** describes the current selection for the given control
298         */
299         void    describeCurrentSelectionForControl(
300                     const Control& _rControl,
301                     ::com::sun::star::uno::Sequence< ::com::sun::star::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
302                 );
303 
304         /** describes the current selection for the given ElementType
305         */
306         void    describeCurrentSelectionForType(
307                     const ElementType _eType,
308                     ::com::sun::star::uno::Sequence< ::com::sun::star::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
309                 );
310 
311         /** select all names on the currently selected container. Non existence names where ignored.
312         *
313         * \param _aNames the element names
314         */
315         void selectElements(const ::com::sun::star::uno::Sequence< ::rtl::OUString>& _aNames);
316 
317 		/** adds a new object to the detail page.
318 			@param	_eType
319 				The type where the entry shold be appended.
320 			@param	_rName
321 				The name of the object to be inserted
322 			@param	_rObject
323 				The object to add.
324 			@param	_rxConn
325 				If we insert a table, the connection must be set.
326 		*/
327 		SvLBoxEntry* elementAdded(ElementType eType
328 						,const ::rtl::OUString& _rName
329 						,const ::com::sun::star::uno::Any& _rObject );
330 
331 		/** replaces a objects name with a new one
332 			@param	_eType
333 				The type where the entry shold be appended.
334 			@param	_rOldName
335 				The old name of the object to be replaced
336 			@param	_rNewName
337 				The new name of the object to be replaced
338 			@param	_rxConn
339 				If we insert a table, the connection must be set.
340             @param  _xObject
341                 The object which was replaced
342 		*/
343 		void elementReplaced(ElementType eType
344 						,const ::rtl::OUString& _rOldName
345 						,const ::rtl::OUString& _rNewName );
346 
347 		/** removes an element from the detail page.
348 			@param	_eType
349 				The type where the entry shold be appended.
350 			@param	_rName
351 				The name of the element to be removed.
352 			@param	_rxConn
353 				If we remove a table, the connection must be set.
354 		*/
355 		void elementRemoved(ElementType _eType
356 							,const ::rtl::OUString& _rName );
357 
358 		/// returns the preview mode
359 		PreviewMode getPreviewMode();
360 
361 		/// <TRUE/> if the preview is enabled
362 		sal_Bool isPreviewEnabled();
363 
364 
365 		/** switches to the given preview mode
366 			@param	_eMode
367 				the mode to set for the preview
368 		*/
369 		void switchPreview(PreviewMode _eMode);
370 
371 		/** shows the Preview of the content when it is enabled.
372 			@param	_xContent
373 				The content which must support the "preview" command.
374 		*/
375 		void showPreview(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xContent);
376 
377 		/** shows the Preview of a table or query
378 			@param	_sDataSourceName
379 				the name of the data source
380 			@param	_sName
381 				the name of table or query
382 			@param	_bTable
383 				<TRUE/> if it is a table, otherwise <FALSE/>
384 			@return	void
385 		*/
386 		void showPreview(	const ::rtl::OUString& _sDataSourceName,
387 							const ::rtl::OUString& _sName,
388 							sal_Bool _bTable);
389 
390 		SvLBoxEntry* getEntry( const Point& _aPoint ) const;
391 
392 		Window* getTreeWindow() const;
393     private:
394         void                impl_createPage(
395                                 ElementType _eType,
396                                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
397                                 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxNonTableElements
398                             );
399 
400         const TaskPaneData& impl_getTaskPaneData( ElementType _eType );
401         void                impl_fillTaskPaneData( ElementType _eType, TaskPaneData& _rData ) const;
402 	};
403 }
404 #endif // DBAUI_APPDETAILVIEW_HXX
405 
406