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