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 _EXTENSIONS_DBP_LISTCOMBOWIZARD_HXX_
29 #define _EXTENSIONS_DBP_LISTCOMBOWIZARD_HXX_
30 
31 #include "controlwizard.hxx"
32 #include "commonpagesdbp.hxx"
33 
34 //.........................................................................
35 namespace dbp
36 {
37 //.........................................................................
38 
39 #define LCW_STATE_DATASOURCE_SELECTION	0
40 #define LCW_STATE_TABLESELECTION		1
41 #define LCW_STATE_FIELDSELECTION		2
42 #define LCW_STATE_FIELDLINK				3
43 #define LCW_STATE_COMBODBFIELD			4
44 
45 	//=====================================================================
46 	//= OListComboSettings
47 	//=====================================================================
48 	struct OListComboSettings : public OControlWizardSettings
49 	{
50 		String			sListContentTable;
51 		String			sListContentField;
52 		String			sLinkedFormField;
53 		String			sLinkedListField;
54 	};
55 
56 	//=====================================================================
57 	//= OListComboWizard
58 	//=====================================================================
59 	class OListComboWizard : public OControlWizard
60 	{
61 	protected:
62 		OListComboSettings		m_aSettings;
63 		sal_Bool				m_bListBox : 1;
64 		sal_Bool				m_bHadDataSelection : 1;
65 
66 	public:
67 		OListComboWizard(
68 			Window* _pParent,
69 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObjectModel,
70 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
71 		);
72 
73 		OListComboSettings& getSettings() { return m_aSettings; }
74 
75 		sal_Bool isListBox() const { return m_bListBox; }
76 
77 	protected:
78 		// OWizardMachine overridables
79 		virtual ::svt::OWizardPage*	createPage( WizardState _nState );
80 		virtual WizardState	        determineNextState( WizardState _nCurrentState ) const;
81 		virtual	void			    enterState( WizardState _nState );
82 		virtual	sal_Bool		    leaveState( WizardState _nState );
83 		virtual sal_Bool            onFinish();
84 
85 		virtual sal_Bool approveControl(sal_Int16 _nClassId);
86 
87 		WizardState getFinalState() const { return isListBox() ? LCW_STATE_FIELDLINK : LCW_STATE_COMBODBFIELD; }
88 
89 	private:
90 		void implApplySettings();
91 	};
92 
93 	//=====================================================================
94 	//= OLCPage
95 	//=====================================================================
96 	class OLCPage : public OControlWizardPage
97 	{
98 	public:
99 		OLCPage( OListComboWizard* _pParent, const ResId& _rId ) : OControlWizardPage(_pParent, _rId) { }
100 
101 	protected:
102 		OListComboSettings& getSettings() { return static_cast<OListComboWizard*>(getDialog())->getSettings(); }
103 		sal_Bool isListBox() { return static_cast<OListComboWizard*>(getDialog())->isListBox(); }
104 
105 	protected:
106 		::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
107 			getTables(sal_Bool _bNeedIt);
108 		::com::sun::star::uno::Sequence< ::rtl::OUString >
109 			getTableFields(sal_Bool _bNeedIt);
110 	};
111 
112 	//=====================================================================
113 	//= OContentTableSelection
114 	//=====================================================================
115 	class OContentTableSelection : public OLCPage
116 	{
117 	protected:
118 		FixedLine		m_aFrame;
119 		FixedText		m_aSelectTableLabel;
120 		ListBox			m_aSelectTable;
121 
122 	public:
123 		OContentTableSelection( OListComboWizard* _pParent );
124 
125 	protected:
126 		// TabPage overridables
127 		virtual void ActivatePage();
128 
129 		// OWizardPage overridables
130 		virtual void		initializePage();
131 		virtual sal_Bool	commitPage( ::svt::WizardTypes::CommitPageReason _eReason );
132 		virtual bool        canAdvance() const;
133 
134 	protected:
135 		DECL_LINK( OnTableDoubleClicked, ListBox* );
136 		DECL_LINK( OnTableSelected, ListBox* );
137 	};
138 
139 	//=====================================================================
140 	//= OContentFieldSelection
141 	//=====================================================================
142 	class OContentFieldSelection : public OLCPage
143 	{
144 	protected:
145 		FixedLine		m_aFrame;
146 		FixedText		m_aTableFields;
147 		ListBox			m_aSelectTableField;
148 		FixedText		m_aDisplayedFieldLabel;
149 		Edit			m_aDisplayedField;
150 		FixedText		m_aInfo;
151 
152 
153 	public:
154 		OContentFieldSelection( OListComboWizard* _pParent );
155 
156 	protected:
157 		DECL_LINK( OnFieldSelected, ListBox* );
158 		DECL_LINK( OnTableDoubleClicked, ListBox* );
159 
160 		// TabPage overridables
161 		virtual void ActivatePage();
162 
163 		// OWizardPage overridables
164 		virtual void		initializePage();
165 		virtual sal_Bool	commitPage( ::svt::WizardTypes::CommitPageReason _eReason );
166 		virtual bool        canAdvance() const;
167 	};
168 
169 	//=====================================================================
170 	//= OLinkFieldsPage
171 	//=====================================================================
172 	class OLinkFieldsPage : public OLCPage
173 	{
174 	protected:
175 		FixedText		m_aDescription;
176 		FixedLine		m_aFrame;
177 		FixedText		m_aValueListFieldLabel;
178 		ComboBox		m_aValueListField;
179 		FixedText		m_aTableFieldLabel;
180 		ComboBox		m_aTableField;
181 
182 
183 	public:
184 		OLinkFieldsPage( OListComboWizard* _pParent );
185 
186 	protected:
187 		// TabPage overridables
188 		virtual void ActivatePage();
189 
190 		// OWizardPage overridables
191 		virtual void		initializePage();
192 		virtual sal_Bool	commitPage( ::svt::WizardTypes::CommitPageReason _eReason );
193 		virtual bool        canAdvance() const;
194 
195 	private:
196 		void implCheckFinish();
197 
198 		DECL_LINK(OnSelectionModified, void*);
199 	};
200 
201 	//=====================================================================
202 	//= OComboDBFieldPage
203 	//=====================================================================
204 	class OComboDBFieldPage : public ODBFieldPage
205 	{
206 	public:
207 		OComboDBFieldPage( OControlWizard* _pParent );
208 
209 	protected:
210 		OListComboSettings& getSettings() { return static_cast<OListComboWizard*>(getDialog())->getSettings(); }
211 
212 		// TabPage overridables
213 		virtual void ActivatePage();
214 
215 		// OWizardPage overridables
216 		virtual bool    canAdvance() const;
217 
218 		// ODBFieldPage overridables
219 		virtual String& getDBFieldSetting();
220 	};
221 
222 //.........................................................................
223 }	// namespace dbp
224 //.........................................................................
225 
226 #endif // _EXTENSIONS_DBP_LISTCOMBOWIZARD_HXX_
227 
228