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