bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / bibliography / bibview.cxx
blobdac90718d065489158bd14fc00d832bfd5e1bb61
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "bib.hrc"
22 #include "bibcont.hxx"
23 #include "bibbeam.hxx"
24 #include "general.hxx"
25 #include "bibview.hxx"
26 #include "datman.hxx"
27 #include "bibresid.hxx"
28 #include "bibmod.hxx"
29 #include "sections.hrc"
30 #include "bibconfig.hxx"
33 #include <vcl/svapp.hxx>
34 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
35 #include <com/sun/star/form/XLoadable.hpp>
36 #include <vcl/msgbox.hxx>
37 #include <tools/debug.hxx>
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::form;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::uno;
45 //.........................................................................
46 namespace bib
48 //.........................................................................
50 // -----------------------------------------------------------------------
51 BibView::BibView( Window* _pParent, BibDataManager* _pManager, WinBits _nStyle )
52 :BibWindow( _pParent, _nStyle )
53 ,m_pDatMan( _pManager )
54 ,m_xDatMan( _pManager )
55 ,m_pGeneralPage( NULL )
57 if ( m_xDatMan.is() )
58 connectForm( m_xDatMan );
61 // -----------------------------------------------------------------------
62 BibView::~BibView()
64 BibGeneralPage* pGeneralPage = m_pGeneralPage;
65 m_pGeneralPage = NULL;
67 pGeneralPage->CommitActiveControl();
68 Reference< XForm > xForm = m_pDatMan->getForm();
69 Reference< XPropertySet > xProps( xForm, UNO_QUERY );
70 Reference< sdbc::XResultSetUpdate > xResUpd( xProps, UNO_QUERY );
71 DBG_ASSERT( xResUpd.is(), "BibView::~BibView: invalid form!" );
73 if ( xResUpd.is() )
75 Any aModified = xProps->getPropertyValue( "IsModified" );
76 sal_Bool bFlag = sal_False;
77 if ( ( aModified >>= bFlag ) && bFlag )
80 try
82 Any aNew = xProps->getPropertyValue( "IsNew" );
83 aNew >>= bFlag;
84 if ( bFlag )
85 xResUpd->insertRow();
86 else
87 xResUpd->updateRow();
89 catch( const uno::Exception& rEx)
91 (void) rEx;
96 if ( isFormConnected() )
97 disconnectForm();
99 pGeneralPage->RemoveListeners();
100 m_xGeneralPage = NULL;
103 void BibView::UpdatePages()
105 // TODO:
106 // this is _strange_: Why not updating the existent general page?
107 // I consider the current behaviour a HACK.
108 // frank.schoenheit@sun.com
109 if ( m_pGeneralPage )
111 m_pGeneralPage->Hide();
112 m_pGeneralPage->RemoveListeners();
113 m_xGeneralPage = 0;
116 m_xGeneralPage = m_pGeneralPage = new BibGeneralPage( this, m_pDatMan );
118 Resize();
120 if( HasFocus() )
121 // "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
122 m_pGeneralPage->GrabFocus();
124 String sErrorString( m_pGeneralPage->GetErrorString() );
125 if ( sErrorString.Len() )
127 sal_Bool bExecute = BibModul::GetConfig()->IsShowColumnAssignmentWarning();
128 if(!m_pDatMan->HasActiveConnection())
130 //no connection is available -> the data base has to be assigned
131 m_pDatMan->DispatchDBChangeDialog();
132 bExecute = sal_False;
134 else if(bExecute)
136 sErrorString += '\n';
137 sErrorString += String( BibResId( RID_MAP_QUESTION ) );
138 QueryBox aQuery( this, WB_YES_NO, sErrorString );
139 aQuery.SetDefaultCheckBoxText();
140 short nResult = aQuery.Execute();
141 BibModul::GetConfig()->SetShowColumnAssignmentWarning(
142 !aQuery.GetCheckBoxState());
143 if( RET_YES != nResult )
145 bExecute = sal_False;
148 if(bExecute)
150 Application::PostUserEvent( STATIC_LINK( this, BibView, CallMappingHdl ) );
155 void BibView::_loaded( const EventObject& _rEvent )
157 UpdatePages();
158 FormControlContainer::_loaded( _rEvent );
161 void BibView::_reloaded( const EventObject& _rEvent )
163 UpdatePages();
164 FormControlContainer::_loaded( _rEvent );
167 IMPL_STATIC_LINK( BibView, CallMappingHdl, BibView*, EMPTYARG )
169 pThis->m_pDatMan->CreateMappingDialog( pThis );
170 return 0;
173 void BibView::Resize()
175 if ( m_pGeneralPage )
177 ::Size aSz( GetOutputSizePixel() );
178 m_pGeneralPage->SetSizePixel( aSz );
180 Window::Resize();
183 Reference< awt::XControlContainer > BibView::getControlContainer()
185 Reference< awt::XControlContainer > xReturn;
186 if ( m_pGeneralPage )
187 xReturn = m_pGeneralPage->GetControlContainer();
188 return xReturn;
191 void BibView::GetFocus()
193 if( m_pGeneralPage )
194 m_pGeneralPage->GrabFocus();
197 sal_Bool BibView::HandleShortCutKey( const KeyEvent& rKeyEvent )
199 return m_pGeneralPage? m_pGeneralPage->HandleShortCutKey( rKeyEvent ) : sal_False;
202 //.........................................................................
203 } // namespace bib
204 //.........................................................................
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */