1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
27 #include "bibresid.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
;
46 class MessageWithCheck
: public weld::MessageDialogController
49 std::unique_ptr
<weld::CheckButton
> m_xWarningOnBox
;
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(); }
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)
72 m_aFormControlContainer
.connectForm( m_xDatMan
);
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!" );
94 Any aModified
= xProps
->getPropertyValue( "IsModified" );
96 if ( ( aModified
>>= bFlag
) && bFlag
)
101 Any aNew
= xProps
->getPropertyValue( "IsNew" );
104 xResUpd
->insertRow();
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()
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();
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();
151 sErrorString
+= "\n" + BibResId(RID_MAP_QUESTION
);
153 MessageWithCheck
aQueryBox(GetFrameWeld());
154 aQueryBox
.set_primary_text(sErrorString
);
156 short nResult
= aQueryBox
.run();
157 BibModul::GetConfig()->SetShowColumnAssignmentWarning(!aQueryBox
.get_active());
159 if( RET_YES
!= nResult
)
166 Application::PostUserEvent( LINK( this, BibView
, CallMappingHdl
), nullptr, true );
171 BibViewFormControlContainer::BibViewFormControlContainer(BibView
*pBibView
) : mpBibView(pBibView
) {}
173 void BibViewFormControlContainer::_loaded( const EventObject
& _rEvent
)
175 mpBibView
->UpdatePages();
176 FormControlContainer::_loaded( _rEvent
);
180 void BibViewFormControlContainer::_reloaded( const EventObject
& _rEvent
)
182 mpBibView
->UpdatePages();
183 FormControlContainer::_loaded( _rEvent
);
187 IMPL_LINK_NOARG( BibView
, CallMappingHdl
, void*, void)
189 m_pDatMan
->CreateMappingDialog(GetFrameWeld());
192 void BibView::Resize()
194 if ( m_pGeneralPage
)
196 ::Size
aSz( GetOutputSizePixel() );
197 m_pGeneralPage
->SetSizePixel( aSz
);
202 Reference
< awt::XControlContainer
> BibViewFormControlContainer::getControlContainer()
204 return mpBibView
->getControlContainer();
207 Reference
< awt::XControlContainer
> BibView::getControlContainer() const
209 Reference
< awt::XControlContainer
> xReturn
;
210 if ( m_pGeneralPage
)
211 xReturn
= m_pGeneralPage
->GetControlContainer();
215 void BibView::GetFocus()
218 m_pGeneralPage
->GrabFocus();
221 bool BibView::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
223 return m_pGeneralPage
&& m_pGeneralPage
->HandleShortCutKey( rKeyEvent
);
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */