bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / bibliography / bibview.cxx
blob63e14b82141e14576ef9ebbf24e6f8e4865ffba7
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 <strings.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/weld.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;
44 namespace
46 class MessageWithCheck : public weld::MessageDialogController
48 private:
49 std::unique_ptr<weld::CheckButton> m_xWarningOnBox;
50 public:
51 MessageWithCheck(weld::Window *pParent)
52 : MessageDialogController(pParent, "modules/sbibliography/ui/querydialog.ui", "QueryDialog", "ask")
53 , m_xWarningOnBox(m_xBuilder->weld_check_button("ask"))
56 bool get_active() const { return m_xWarningOnBox->get_active(); }
60 namespace bib
64 BibView::BibView( vcl::Window* _pParent, BibDataManager* _pManager, WinBits _nStyle )
65 :BibWindow( _pParent, _nStyle )
66 ,m_pDatMan( _pManager )
67 ,m_xDatMan( _pManager )
68 ,m_pGeneralPage( nullptr )
69 ,m_aFormControlContainer(this)
71 if ( m_xDatMan.is() )
72 m_aFormControlContainer.connectForm( m_xDatMan );
76 BibView::~BibView()
78 disposeOnce();
81 void BibView::dispose()
83 VclPtr<BibGeneralPage> pGeneralPage = m_pGeneralPage;
84 m_pGeneralPage.clear();
86 pGeneralPage->CommitActiveControl();
87 Reference< XForm > xForm = m_pDatMan->getForm();
88 Reference< XPropertySet > xProps( xForm, UNO_QUERY );
89 Reference< sdbc::XResultSetUpdate > xResUpd( xProps, UNO_QUERY );
90 DBG_ASSERT( xResUpd.is(), "BibView::~BibView: invalid form!" );
92 if ( xResUpd.is() )
94 Any aModified = xProps->getPropertyValue( "IsModified" );
95 bool bFlag = false;
96 if ( ( aModified >>= bFlag ) && bFlag )
99 try
101 Any aNew = xProps->getPropertyValue( "IsNew" );
102 aNew >>= bFlag;
103 if ( bFlag )
104 xResUpd->insertRow();
105 else
106 xResUpd->updateRow();
108 catch( const uno::Exception&) {}
112 if ( m_aFormControlContainer.isFormConnected() )
113 m_aFormControlContainer.disconnectForm();
115 pGeneralPage->RemoveListeners();
116 pGeneralPage.disposeAndClear();
117 BibWindow::dispose();
120 void BibView::UpdatePages()
122 // TODO:
123 // this is _strange_: Why not updating the existent general page?
124 // I consider the current behaviour a HACK.
125 if ( m_pGeneralPage )
127 m_pGeneralPage->Hide();
128 m_pGeneralPage->RemoveListeners();
129 m_pGeneralPage.disposeAndClear();
132 m_pGeneralPage = VclPtr<BibGeneralPage>::Create( this, m_pDatMan );
133 m_pGeneralPage->Show();
135 if( HasFocus() )
136 // "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
137 m_pGeneralPage->GrabFocus();
139 OUString sErrorString( m_pGeneralPage->GetErrorString() );
140 if ( !sErrorString.isEmpty() )
142 bool bExecute = BibModul::GetConfig()->IsShowColumnAssignmentWarning();
143 if(!m_pDatMan->HasActiveConnection())
145 //no connection is available -> the data base has to be assigned
146 m_pDatMan->DispatchDBChangeDialog();
147 bExecute = false;
149 else if(bExecute)
151 sErrorString += "\n";
152 sErrorString += BibResId(RID_MAP_QUESTION);
154 MessageWithCheck aQueryBox(GetFrameWeld());
155 aQueryBox.set_primary_text(sErrorString);
157 short nResult = aQueryBox.run();
158 BibModul::GetConfig()->SetShowColumnAssignmentWarning(!aQueryBox.get_active());
160 if( RET_YES != nResult )
162 bExecute = false;
165 if(bExecute)
167 Application::PostUserEvent( LINK( this, BibView, CallMappingHdl ), nullptr, true );
172 BibViewFormControlContainer::BibViewFormControlContainer(BibView *pBibView) : mpBibView(pBibView) {}
174 void BibViewFormControlContainer::_loaded( const EventObject& _rEvent )
176 mpBibView->UpdatePages();
177 FormControlContainer::_loaded( _rEvent );
178 mpBibView->Resize();
181 void BibViewFormControlContainer::_reloaded( const EventObject& _rEvent )
183 mpBibView->UpdatePages();
184 FormControlContainer::_loaded( _rEvent );
185 mpBibView->Resize();
188 IMPL_LINK_NOARG( BibView, CallMappingHdl, void*, void)
190 m_pDatMan->CreateMappingDialog(GetFrameWeld());
193 void BibView::Resize()
195 if ( m_pGeneralPage )
197 ::Size aSz( GetOutputSizePixel() );
198 m_pGeneralPage->SetSizePixel( aSz );
200 Window::Resize();
203 Reference< awt::XControlContainer > BibViewFormControlContainer::getControlContainer()
205 return mpBibView->getControlContainer();
208 Reference< awt::XControlContainer > BibView::getControlContainer()
210 Reference< awt::XControlContainer > xReturn;
211 if ( m_pGeneralPage )
212 xReturn = m_pGeneralPage->GetControlContainer();
213 return xReturn;
216 void BibView::GetFocus()
218 if( m_pGeneralPage )
219 m_pGeneralPage->GrabFocus();
222 bool BibView::HandleShortCutKey( const KeyEvent& rKeyEvent )
224 return m_pGeneralPage && m_pGeneralPage->HandleShortCutKey( rKeyEvent );
228 } // namespace bib
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */