bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / bibliography / bibview.cxx
blob23d4186f753750d32b49ab6ade522007ca69e2fb
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 "bibconfig.hxx"
32 #include <vcl/svapp.hxx>
33 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
34 #include <com/sun/star/form/XLoadable.hpp>
35 #include <vcl/msgbox.hxx>
36 #include <tools/debug.hxx>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::form;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::uno;
45 namespace bib
50 BibView::BibView( vcl::Window* _pParent, BibDataManager* _pManager, WinBits _nStyle )
51 :BibWindow( _pParent, _nStyle )
52 ,m_pDatMan( _pManager )
53 ,m_xDatMan( _pManager )
54 ,m_pGeneralPage( NULL )
55 ,m_aFormControlContainer(this)
57 if ( m_xDatMan.is() )
58 m_aFormControlContainer.connectForm( m_xDatMan );
62 BibView::~BibView()
64 disposeOnce();
67 void BibView::dispose()
69 VclPtr<BibGeneralPage> pGeneralPage = m_pGeneralPage;
70 m_pGeneralPage.clear();
72 pGeneralPage->CommitActiveControl();
73 Reference< XForm > xForm = m_pDatMan->getForm();
74 Reference< XPropertySet > xProps( xForm, UNO_QUERY );
75 Reference< sdbc::XResultSetUpdate > xResUpd( xProps, UNO_QUERY );
76 DBG_ASSERT( xResUpd.is(), "BibView::~BibView: invalid form!" );
78 if ( xResUpd.is() )
80 Any aModified = xProps->getPropertyValue( "IsModified" );
81 bool bFlag = false;
82 if ( ( aModified >>= bFlag ) && bFlag )
85 try
87 Any aNew = xProps->getPropertyValue( "IsNew" );
88 aNew >>= bFlag;
89 if ( bFlag )
90 xResUpd->insertRow();
91 else
92 xResUpd->updateRow();
94 catch( const uno::Exception& rEx)
96 (void) rEx;
101 if ( m_aFormControlContainer.isFormConnected() )
102 m_aFormControlContainer.disconnectForm();
104 pGeneralPage->RemoveListeners();
105 pGeneralPage.disposeAndClear();
106 m_xGeneralPage = NULL;
107 BibWindow::dispose();
110 void BibView::UpdatePages()
112 // TODO:
113 // this is _strange_: Why not updating the existent general page?
114 // I consider the current behaviour a HACK.
115 // frank.schoenheit@sun.com
116 if ( m_pGeneralPage )
118 m_pGeneralPage->Hide();
119 m_pGeneralPage->RemoveListeners();
120 m_pGeneralPage.disposeAndClear();
121 m_xGeneralPage = 0;
124 m_pGeneralPage = VclPtr<BibGeneralPage>::Create( this, m_pDatMan );
125 m_xGeneralPage = m_pGeneralPage->GetFocusListener().get();
126 m_pGeneralPage->Show();
128 if( HasFocus() )
129 // "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
130 m_pGeneralPage->GrabFocus();
132 OUString sErrorString( m_pGeneralPage->GetErrorString() );
133 if ( !sErrorString.isEmpty() )
135 bool bExecute = BibModul::GetConfig()->IsShowColumnAssignmentWarning();
136 if(!m_pDatMan->HasActiveConnection())
138 //no connection is available -> the data base has to be assigned
139 m_pDatMan->DispatchDBChangeDialog();
140 bExecute = false;
142 else if(bExecute)
144 sErrorString += "\n";
145 sErrorString += BIB_RESSTR(RID_MAP_QUESTION);
146 ScopedVclPtrInstance< QueryBox > aQuery(this, WB_YES_NO, sErrorString);
147 aQuery->SetDefaultCheckBoxText();
148 short nResult = aQuery->Execute();
149 BibModul::GetConfig()->SetShowColumnAssignmentWarning(
150 !aQuery->GetCheckBoxState());
151 if( RET_YES != nResult )
153 bExecute = false;
156 if(bExecute)
158 Application::PostUserEvent( LINK( this, BibView, CallMappingHdl ), NULL, true );
163 BibViewFormControlContainer::BibViewFormControlContainer(BibView *pBibView) : mpBibView(pBibView) {}
165 void BibViewFormControlContainer::_loaded( const EventObject& _rEvent )
167 mpBibView->UpdatePages();
168 FormControlContainer::_loaded( _rEvent );
169 mpBibView->Resize();
172 void BibViewFormControlContainer::_reloaded( const EventObject& _rEvent )
174 mpBibView->UpdatePages();
175 FormControlContainer::_loaded( _rEvent );
176 mpBibView->Resize();
179 IMPL_LINK( BibView, CallMappingHdl, BibView*, )
181 m_pDatMan->CreateMappingDialog( this );
182 return 0;
185 void BibView::Resize()
187 if ( m_pGeneralPage )
189 ::Size aSz( GetOutputSizePixel() );
190 m_pGeneralPage->SetSizePixel( aSz );
192 Window::Resize();
195 Reference< awt::XControlContainer > BibViewFormControlContainer::getControlContainer()
197 return mpBibView->getControlContainer();
200 Reference< awt::XControlContainer > BibView::getControlContainer()
202 Reference< awt::XControlContainer > xReturn;
203 if ( m_pGeneralPage )
204 xReturn = m_pGeneralPage->GetControlContainer();
205 return xReturn;
208 void BibView::GetFocus()
210 if( m_pGeneralPage )
211 m_pGeneralPage->GrabFocus();
214 bool BibView::HandleShortCutKey( const KeyEvent& rKeyEvent )
216 return m_pGeneralPage && m_pGeneralPage->HandleShortCutKey( rKeyEvent );
220 } // namespace bib
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */