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