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 "general.hxx"
23 #include "bibview.hxx"
25 #include "bibresid.hxx"
27 #include "bibconfig.hxx"
30 #include <vcl/svapp.hxx>
31 #include <vcl/weld.hxx>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::form
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::uno
;
41 class MessageWithCheck
: public weld::MessageDialogController
44 std::unique_ptr
<weld::CheckButton
> m_xWarningOnBox
;
46 MessageWithCheck(weld::Window
*pParent
)
47 : MessageDialogController(pParent
, "modules/sbibliography/ui/querydialog.ui", "QueryDialog", "ask")
48 , m_xWarningOnBox(m_xBuilder
->weld_check_button("ask"))
51 bool get_active() const { return m_xWarningOnBox
->get_active(); }
59 BibView::BibView( vcl::Window
* _pParent
, BibDataManager
* _pManager
, WinBits _nStyle
)
60 :BibWindow( _pParent
, _nStyle
)
61 ,m_pDatMan( _pManager
)
62 ,m_xDatMan( _pManager
)
63 ,m_pGeneralPage( nullptr )
64 ,m_aFormControlContainer(this)
67 m_aFormControlContainer
.connectForm( m_xDatMan
);
76 void BibView::dispose()
78 VclPtr
<BibGeneralPage
> pGeneralPage
= m_pGeneralPage
;
79 m_pGeneralPage
.clear();
80 pGeneralPage
.disposeAndClear(); // dispose will commit any uncommitted weld::Entry changes
82 if ( m_aFormControlContainer
.isFormConnected() )
83 m_aFormControlContainer
.disconnectForm();
88 void BibView::UpdatePages()
91 // this is _strange_: Why not updating the existent general page?
92 // I consider the current behaviour a HACK.
95 m_pGeneralPage
->Hide();
96 m_pGeneralPage
.disposeAndClear();
99 m_pGeneralPage
= VclPtr
<BibGeneralPage
>::Create( this, m_pDatMan
);
100 m_pGeneralPage
->Show();
103 // "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
104 m_pGeneralPage
->GrabFocus();
106 OUString
sErrorString( m_pGeneralPage
->GetErrorString() );
107 if ( sErrorString
.isEmpty() )
110 bool bExecute
= BibModul::GetConfig()->IsShowColumnAssignmentWarning();
111 if(!m_pDatMan
->HasActiveConnection())
113 //no connection is available -> the data base has to be assigned
114 m_pDatMan
->DispatchDBChangeDialog();
119 sErrorString
+= "\n" + BibResId(RID_MAP_QUESTION
);
121 MessageWithCheck
aQueryBox(GetFrameWeld());
122 aQueryBox
.set_primary_text(sErrorString
);
124 short nResult
= aQueryBox
.run();
125 BibModul::GetConfig()->SetShowColumnAssignmentWarning(!aQueryBox
.get_active());
127 if( RET_YES
!= nResult
)
134 Application::PostUserEvent( LINK( this, BibView
, CallMappingHdl
), nullptr, true );
138 BibViewFormControlContainer::BibViewFormControlContainer(BibView
*pBibView
) : mpBibView(pBibView
) {}
140 void BibViewFormControlContainer::_loaded( const EventObject
& _rEvent
)
142 mpBibView
->UpdatePages();
143 FormControlContainer::_loaded( _rEvent
);
147 void BibViewFormControlContainer::_reloaded( const EventObject
& _rEvent
)
149 mpBibView
->UpdatePages();
150 FormControlContainer::_loaded( _rEvent
);
154 IMPL_LINK_NOARG( BibView
, CallMappingHdl
, void*, void)
156 m_pDatMan
->CreateMappingDialog(GetFrameWeld());
159 void BibView::Resize()
161 if ( m_pGeneralPage
)
163 ::Size
aSz( GetOutputSizePixel() );
164 m_pGeneralPage
->SetSizePixel( aSz
);
169 Reference
< awt::XControlContainer
> BibViewFormControlContainer::getControlContainer()
174 void BibView::GetFocus()
177 m_pGeneralPage
->GrabFocus();
180 bool BibView::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
182 return m_pGeneralPage
&& m_pGeneralPage
->HandleShortCutKey( rKeyEvent
);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */