1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef BIB_HRC
28cdf0e10cSrcweir #include "bib.hrc"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include "bibcont.hxx"
31cdf0e10cSrcweir #include "bibbeam.hxx"
32cdf0e10cSrcweir #include "bibmod.hxx"
33cdf0e10cSrcweir #include "general.hxx"
34cdf0e10cSrcweir #include "bibview.hxx"
35cdf0e10cSrcweir #include "datman.hxx"
36cdf0e10cSrcweir #include "bibresid.hxx"
37cdf0e10cSrcweir #include "bibmod.hxx"
38cdf0e10cSrcweir #include "sections.hrc"
39cdf0e10cSrcweir #include "bibconfig.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <vcl/svapp.hxx>
43cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
44cdf0e10cSrcweir #include <com/sun/star/form/XLoadable.hpp>
45cdf0e10cSrcweir #include <vcl/msgbox.hxx>
46cdf0e10cSrcweir #include <tools/debug.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using namespace ::com::sun::star;
49cdf0e10cSrcweir using namespace ::com::sun::star::form;
50cdf0e10cSrcweir using namespace ::com::sun::star::beans;
51cdf0e10cSrcweir using namespace ::com::sun::star::lang;
52cdf0e10cSrcweir using namespace ::com::sun::star::uno;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #define C2U( cChar ) ::rtl::OUString::createFromAscii( cChar )
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //.........................................................................
57cdf0e10cSrcweir namespace bib
58cdf0e10cSrcweir {
59cdf0e10cSrcweir //.........................................................................
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	// -----------------------------------------------------------------------
BibView(Window * _pParent,BibDataManager * _pManager,WinBits _nStyle)62cdf0e10cSrcweir 	BibView::BibView( Window* _pParent, BibDataManager* _pManager, WinBits _nStyle )
63cdf0e10cSrcweir 		:BibWindow( _pParent, _nStyle )
64cdf0e10cSrcweir 		,m_pDatMan( _pManager )
65cdf0e10cSrcweir 		,m_xDatMan( _pManager )
66cdf0e10cSrcweir 		,m_pGeneralPage( NULL )
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir 		if ( m_xDatMan.is() )
69cdf0e10cSrcweir 			connectForm( m_xDatMan );
70cdf0e10cSrcweir 	}
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	// -----------------------------------------------------------------------
~BibView()73cdf0e10cSrcweir 	BibView::~BibView()
74cdf0e10cSrcweir 	{
75cdf0e10cSrcweir 		BibGeneralPage* pGeneralPage = m_pGeneralPage;
76cdf0e10cSrcweir 		m_pGeneralPage = NULL;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 		pGeneralPage->CommitActiveControl();
79cdf0e10cSrcweir 		Reference< XForm > xForm = m_pDatMan->getForm();
80cdf0e10cSrcweir 		Reference< XPropertySet > xProps( xForm, UNO_QUERY );
81cdf0e10cSrcweir 		Reference< sdbc::XResultSetUpdate > xResUpd( xProps, UNO_QUERY );
82cdf0e10cSrcweir 		DBG_ASSERT( xResUpd.is(), "BibView::~BibView: invalid form!" );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		if ( xResUpd.is() )
85cdf0e10cSrcweir 		{
86cdf0e10cSrcweir 			Any aModified = xProps->getPropertyValue( C2U( "IsModified" ) );
87cdf0e10cSrcweir 			sal_Bool bFlag = sal_False;
88cdf0e10cSrcweir 			if ( ( aModified >>= bFlag ) && bFlag )
89cdf0e10cSrcweir 			{
90cdf0e10cSrcweir 
91cdf0e10cSrcweir                 try
92cdf0e10cSrcweir                 {
93cdf0e10cSrcweir                     Any aNew = xProps->getPropertyValue( C2U( "IsNew" ) );
94cdf0e10cSrcweir                     aNew >>= bFlag;
95cdf0e10cSrcweir                     if ( bFlag )
96cdf0e10cSrcweir                         xResUpd->insertRow();
97cdf0e10cSrcweir                     else
98cdf0e10cSrcweir                         xResUpd->updateRow();
99cdf0e10cSrcweir                 }
100cdf0e10cSrcweir                 catch( const uno::Exception& rEx)
101cdf0e10cSrcweir                 {
102cdf0e10cSrcweir                    (void) rEx;
103cdf0e10cSrcweir                 }
104cdf0e10cSrcweir 			}
105cdf0e10cSrcweir 		}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		if ( isFormConnected() )
108cdf0e10cSrcweir 			disconnectForm();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		pGeneralPage->RemoveListeners();
111cdf0e10cSrcweir 		m_xGeneralPage = NULL;
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	/* -----------------16.11.99 13:13-------------------
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	 --------------------------------------------------*/
UpdatePages()117cdf0e10cSrcweir 	void BibView::UpdatePages()
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		// TODO:
120cdf0e10cSrcweir 		// this is _strange_: Why not updating the existent general page?
121cdf0e10cSrcweir 		// I consider the current behaviour a HACK.
122cdf0e10cSrcweir 		// frank.schoenheit@sun.com
123cdf0e10cSrcweir 		if ( m_pGeneralPage )
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 			m_pGeneralPage->Hide();
126cdf0e10cSrcweir 			m_pGeneralPage->RemoveListeners();
127cdf0e10cSrcweir 			m_xGeneralPage = 0;
128cdf0e10cSrcweir 		}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 		m_xGeneralPage = m_pGeneralPage = new BibGeneralPage( this, m_pDatMan );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 		Resize();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 		if( HasFocus() )
135cdf0e10cSrcweir 			// "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
136cdf0e10cSrcweir 			m_pGeneralPage->GrabFocus();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 		String sErrorString( m_pGeneralPage->GetErrorString() );
139cdf0e10cSrcweir 		if ( sErrorString.Len() )
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir             sal_Bool bExecute = BibModul::GetConfig()->IsShowColumnAssignmentWarning();
142cdf0e10cSrcweir             if(!m_pDatMan->HasActiveConnection())
143cdf0e10cSrcweir             {
144cdf0e10cSrcweir                 //no connection is available -> the data base has to be assigned
145cdf0e10cSrcweir                 m_pDatMan->DispatchDBChangeDialog();
146cdf0e10cSrcweir                 bExecute = sal_False;
147cdf0e10cSrcweir             }
148cdf0e10cSrcweir             else if(bExecute)
149cdf0e10cSrcweir             {
150cdf0e10cSrcweir                 sErrorString += '\n';
151cdf0e10cSrcweir                 sErrorString += String( BibResId( RID_MAP_QUESTION ) );
152cdf0e10cSrcweir                 QueryBox aQuery( this, WB_YES_NO, sErrorString );
153cdf0e10cSrcweir                 aQuery.SetDefaultCheckBoxText();
154cdf0e10cSrcweir                 short nResult = aQuery.Execute();
155cdf0e10cSrcweir                 BibModul::GetConfig()->SetShowColumnAssignmentWarning(
156cdf0e10cSrcweir                     !aQuery.GetCheckBoxState());
157cdf0e10cSrcweir                 if( RET_YES != nResult )
158cdf0e10cSrcweir                 {
159cdf0e10cSrcweir                     bExecute = sal_False;
160cdf0e10cSrcweir                 }
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir             if(bExecute)
163cdf0e10cSrcweir 			{
164cdf0e10cSrcweir 				Application::PostUserEvent( STATIC_LINK( this, BibView, CallMappingHdl ) );
165cdf0e10cSrcweir 			}
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 	//---------------------------------------------------------------------
169cdf0e10cSrcweir 	//--- 19.10.01 16:55:49 -----------------------------------------------
170cdf0e10cSrcweir 
_loaded(const EventObject & _rEvent)171cdf0e10cSrcweir 	void BibView::_loaded( const EventObject& _rEvent )
172cdf0e10cSrcweir 	{
173cdf0e10cSrcweir 		UpdatePages();
174cdf0e10cSrcweir 		FormControlContainer::_loaded( _rEvent );
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 
_reloaded(const EventObject & _rEvent)177cdf0e10cSrcweir 	void BibView::_reloaded( const EventObject& _rEvent )
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir 		UpdatePages();
180cdf0e10cSrcweir 		FormControlContainer::_loaded( _rEvent );
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	/* -----------------------------02.02.00 16:49--------------------------------
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	 ---------------------------------------------------------------------------*/
IMPL_STATIC_LINK(BibView,CallMappingHdl,BibView *,EMPTYARG)186cdf0e10cSrcweir 	IMPL_STATIC_LINK( BibView, CallMappingHdl, BibView*, EMPTYARG )
187cdf0e10cSrcweir 	{
188cdf0e10cSrcweir 		pThis->m_pDatMan->CreateMappingDialog( pThis );
189cdf0e10cSrcweir 		return 0;
190cdf0e10cSrcweir 	}
191cdf0e10cSrcweir 	/* -----------------------------13.04.00 16:12--------------------------------
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	 ---------------------------------------------------------------------------*/
Resize()194cdf0e10cSrcweir 	void BibView::Resize()
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 		if ( m_pGeneralPage )
197cdf0e10cSrcweir 		{
198cdf0e10cSrcweir 			::Size aSz( GetOutputSizePixel() );
199cdf0e10cSrcweir 			m_pGeneralPage->SetSizePixel( aSz );
200cdf0e10cSrcweir 		}
201cdf0e10cSrcweir 		Window::Resize();
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	//---------------------------------------------------------------------
205cdf0e10cSrcweir 	//--- 18.10.01 18:52:45 -----------------------------------------------
206cdf0e10cSrcweir 
getControlContainer()207cdf0e10cSrcweir 	Reference< awt::XControlContainer > BibView::getControlContainer()
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		Reference< awt::XControlContainer > xReturn;
210cdf0e10cSrcweir 		if ( m_pGeneralPage )
211cdf0e10cSrcweir 			xReturn = m_pGeneralPage->GetControlContainer();
212cdf0e10cSrcweir 		return xReturn;
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir 
GetFocus()215cdf0e10cSrcweir 	void BibView::GetFocus()
216cdf0e10cSrcweir 	{
217cdf0e10cSrcweir 		if( m_pGeneralPage )
218cdf0e10cSrcweir 			m_pGeneralPage->GrabFocus();
219cdf0e10cSrcweir 	}
220cdf0e10cSrcweir 
HandleShortCutKey(const KeyEvent & rKeyEvent)221cdf0e10cSrcweir 	sal_Bool BibView::HandleShortCutKey( const KeyEvent& rKeyEvent )
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		return m_pGeneralPage? m_pGeneralPage->HandleShortCutKey( rKeyEvent ) : sal_False;
224cdf0e10cSrcweir 	}
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //.........................................................................
227cdf0e10cSrcweir }	// namespace bib
228cdf0e10cSrcweir //.........................................................................
229