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 _DBACCESS_UI_DIRECTSQL_HXX_
25 #define _DBACCESS_UI_DIRECTSQL_HXX_
26 
27 #ifndef _SV_DIALOG_HXX
28 #include <vcl/dialog.hxx>
29 #endif
30 #ifndef _SVEDIT_HXX
31 #include <svtools/editsyntaxhighlighter.hxx>
32 #endif
33 #ifndef _SV_FIXED_HXX
34 #include <vcl/fixed.hxx>
35 #endif
36 #ifndef _SV_LSTBOX_HXX
37 #include <vcl/lstbox.hxx>
38 #endif
39 #ifndef _SV_BUTTON_HXX
40 #include <vcl/button.hxx>
41 #endif
42 #ifndef _COMPHELPER_STLTYPES_HXX_
43 #include <comphelper/stl_types.hxx>
44 #endif
45 #include <deque>
46 
47 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
48 #include <com/sun/star/sdbc/XConnection.hpp>
49 #endif
50 #ifndef _UNOTOOLS_EVENTLISTENERADAPTER_HXX_
51 #include <unotools/eventlisteneradapter.hxx>
52 #endif
53 #ifndef _DBAUI_MODULE_DBU_HXX_
54 #include "moduledbu.hxx"
55 #endif
56 #ifndef _OSL_MUTEX_HXX_
57 #include <osl/mutex.hxx>
58 #endif
59 
60 //........................................................................
61 namespace dbaui
62 {
63 //........................................................................
64 
65 	//====================================================================
66 	//= DirectSQLDialog
67 	//====================================================================
68 	class DirectSQLDialog
69 			:public ModalDialog
70 			,public ::utl::OEventListenerAdapter
71 	{
72 	protected:
73         OModuleClient m_aModuleClient;
74 		::osl::Mutex	m_aMutex;
75 
76 		FixedLine		m_aFrame;
77 		FixedText		m_aSQLLabel;
78 		MultiLineEditSyntaxHighlight	m_aSQL;
79 		PushButton		m_aExecute;
80 		FixedText		m_aHistoryLabel;
81 		ListBox*		m_pSQLHistory;
82 		FixedLine		m_aStatusFrame;
83 		MultiLineEdit	m_aStatus;
84 		FixedLine		m_aButtonSeparator;
85 		HelpButton		m_aHelp;
86 		PushButton		m_aClose;
87 
88 		typedef ::std::deque< String >	StringQueue;
89 		StringQueue		m_aStatementHistory;	// previous statements
90 		StringQueue		m_aNormalizedHistory;	// previous statements, normalized to be used in the list box
91 
92 		sal_Int32		m_nHistoryLimit;
93 		sal_Int32		m_nStatusCount;
94 
95 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
96 						m_xConnection;
97 
98 	public:
99 		DirectSQLDialog(
100 			Window* _pParent,
101 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn);
102 		~DirectSQLDialog();
103 
104 		/// number of history entries
105 		sal_Int32 getHistorySize() const;
106 
107 	protected:
108 		void executeCurrent();
109 		void switchToHistory(sal_Int32 _nHistoryPos, sal_Bool _bUpdateListBox = sal_True);
110 
111 		// OEventListenerAdapter
112 		virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource );
113 
114 	protected:
115 		DECL_LINK( OnExecute, void* );
116 		DECL_LINK( OnClose, void* );
117 		DECL_LINK( OnListEntrySelected, void* );
118 		DECL_LINK( OnStatementModified, void* );
119 
120 	private:
121 		/// adds a statement to the statement history
122 		void implAddToStatementHistory(const String& _rStatement);
123 
124 		/// ensures that our history has at most m_nHistoryLimit entries
125 		void implEnsureHistoryLimit();
126 
127 		/// executes the statement given, adds the status to the status list
128 		void implExecuteStatement(const String& _rStatement);
129 
130 		/// adds a status text to the status list
131 		void addStatusText(const String& _rMessage);
132 
133 #ifdef DBG_UTIL
134 		const sal_Char* impl_CheckInvariants() const;
135 #endif
136 	};
137 
138 	//====================================================================
139 #ifdef DBG_UTIL
140 #define CHECK_INVARIANTS(methodname)	\
141 	{	\
142 		const sal_Char* pError = impl_CheckInvariants();	\
143 		if (pError)	\
144 			OSL_ENSURE(sal_False, (ByteString(methodname) += ByteString(": ") += ByteString(pError)).GetBuffer());	\
145 	}
146 #else
147 #define CHECK_INVARIANTS(methodname)
148 #endif
149 
150 //........................................................................
151 }	// namespace dbaui
152 //........................................................................
153 
154 #endif // _DBACCESS_UI_DIRECTSQL_HXX_
155 
156