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