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 
28 #ifndef _DBAUI_INDEXDIALOG_HXX_
29 #define _DBAUI_INDEXDIALOG_HXX_
30 
31 #ifndef _SV_DIALOG_HXX
32 #include <vcl/dialog.hxx>
33 #endif
34 #ifndef _SV_FIXED_HXX
35 #include <vcl/fixed.hxx>
36 #endif
37 #ifndef _SV_LSTBOX_HXX
38 #include <vcl/lstbox.hxx>
39 #endif
40 #ifndef _SV_BUTTON_HXX
41 #include <vcl/button.hxx>
42 #endif
43 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
44 #include <com/sun/star/container/XNameAccess.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #endif
49 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
50 #include <com/sun/star/sdbc/XConnection.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
53 #include <com/sun/star/uno/Sequence.hxx>
54 #endif
55 #ifndef _SV_TOOLBOX_HXX
56 #include <vcl/toolbox.hxx>
57 #endif
58 #ifndef _SVTREEBOX_HXX
59 #include <svtools/svtreebx.hxx>
60 #endif
61 #ifndef INCLUDED_SVTOOLS_VIEWOPTIONS_HXX
62 #include <unotools/viewoptions.hxx>
63 #endif
64 #ifndef _DBAUI_INDEXES_HXX_
65 #include "indexes.hxx"
66 #endif
67 #ifndef DBAUI_TOOLBOXHELPER_HXX
68 #include "ToolBoxHelper.hxx"
69 #endif
70 
71 //......................................................................
72 namespace dbaui
73 {
74 //......................................................................
75 
76 	//==================================================================
77 	//= DbaIndexList
78 	//==================================================================
79 	class DbaIndexList : public SvTreeListBox
80 	{
81 	protected:
82 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xConnection;
83 		Link		m_aSelectHdl;
84 		Link		m_aEndEditHdl;
85 		sal_Bool	m_bSuspendSelectHdl;
86 
87 	public:
88 		DbaIndexList(Window* _pParent, const ResId& _rId);
89 
90 		void SetSelectHdl(const Link& _rHdl) { m_aSelectHdl = _rHdl; }
91 		Link GetSelectHdl() const { return m_aSelectHdl; }
92 
93 		void SetEndEditHdl(const Link& _rHdl) { m_aEndEditHdl = _rHdl; }
94 		Link GetEndEditHdl() const { return m_aEndEditHdl; }
95 
96 		virtual sal_Bool Select( SvLBoxEntry* pEntry, sal_Bool bSelect );
97 
98 		void enableSelectHandler();
99 		void disableSelectHandler();
100 
101 		void SelectNoHandlerCall( SvLBoxEntry* pEntry );
102 
103 		inline void setConnection(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection)
104 		{
105 			 m_xConnection = _rxConnection;
106 		}
107 
108 	protected:
109 		virtual sal_Bool EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText );
110 
111     private:
112         using SvTreeListBox::Select;
113 	};
114 
115 	//==================================================================
116 	//= DbaIndexDialog
117 	//==================================================================
118 	class IndexFieldsControl;
119 	class OIndexCollection;
120 	class DbaIndexDialog :	public ModalDialog,
121 							public OToolBoxHelper
122 	{
123 	protected:
124 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xConnection;
125 		SvtViewOptions			m_aGeometrySettings;
126 
127 		ToolBox					m_aActions;
128 		DbaIndexList			m_aIndexes;
129 		FixedLine				m_aIndexDetails;
130 		FixedText				m_aDescriptionLabel;
131 		FixedText				m_aDescription;
132 		CheckBox				m_aUnique;
133 		FixedText				m_aFieldsLabel;
134 		IndexFieldsControl*		m_pFields;
135 		PushButton				m_aClose;
136 		HelpButton				m_aHelp;
137 
138 		OIndexCollection*		m_pIndexes;
139 		SvLBoxEntry*			m_pPreviousSelection;
140 		sal_Bool				m_bEditAgain;
141 
142 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
143 								m_xORB;
144 	public:
145 		DbaIndexDialog(
146 			Window* _pParent,
147 			const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rFieldNames,
148 			const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxIndexes,
149 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
150 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
151 			sal_Int32 _nMaxColumnsInIndex
152 			);
153 		virtual ~DbaIndexDialog();
154 
155 		virtual void StateChanged( StateChangedType nStateChange );
156 		virtual void DataChanged( const DataChangedEvent& rDCEvt );
157 
158 		/** will be called whenthe id of the image list is needed.
159 			@param	_eBitmapSet
160 				<svtools/imgdef.hxx>
161 			@param	_bHiContast
162 				<TRUE/> when in high contrast mode.
163 		*/
164 		virtual ImageList getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const;
165 
166 		/** will be called when the controls need to be resized.
167 		*/
168 		virtual void resizeControls(const Size& _rDiff);
169 
170 	protected:
171 		void fillIndexList();
172 		void updateToolbox();
173 		void updateControls(const SvLBoxEntry* _pEntry);
174 
175 	protected:
176 		DECL_LINK( OnIndexSelected, DbaIndexList* );
177 		DECL_LINK( OnIndexAction, ToolBox* );
178 		DECL_LINK( OnEntryEdited, SvLBoxEntry* );
179 		DECL_LINK( OnModified, void* );
180 		DECL_LINK( OnCloseDialog, void* );
181 
182 		DECL_LINK( OnEditIndexAgain, SvLBoxEntry* );
183 
184 	private:
185 		void OnNewIndex();
186 		void OnDropIndex(sal_Bool _bConfirm = sal_True);
187 		void OnRenameIndex();
188 		void OnSaveIndex();
189 		void OnResetIndex();
190 
191 		sal_Bool implCommit(SvLBoxEntry* _pEntry);
192 		sal_Bool implSaveModified(sal_Bool _bPlausibility = sal_True);
193 		sal_Bool implCommitPreviouslySelected();
194 
195 		sal_Bool implDropIndex(SvLBoxEntry* _pEntry, sal_Bool _bRemoveFromCollection);
196 
197 		sal_Bool implCheckPlausibility(const ConstIndexesIterator& _rPos);
198 
199 		/** checks if the controls have to be replaced and moved.
200 		*/
201 		void checkControls();
202 	};
203 
204 //......................................................................
205 }	// namespace dbaui
206 //......................................................................
207 
208 #endif // _DBAUI_INDEXDIALOG_HXX_
209 
210