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 .
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/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
;
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)
58 m_aFormControlContainer
.connectForm( m_xDatMan
);
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!" );
80 Any aModified
= xProps
->getPropertyValue( "IsModified" );
82 if ( ( aModified
>>= bFlag
) && bFlag
)
87 Any aNew
= xProps
->getPropertyValue( "IsNew" );
94 catch( const uno::Exception
& 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()
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();
124 m_pGeneralPage
= VclPtr
<BibGeneralPage
>::Create( this, m_pDatMan
);
125 m_xGeneralPage
= m_pGeneralPage
->GetFocusListener().get();
126 m_pGeneralPage
->Show();
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();
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
)
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
);
172 void BibViewFormControlContainer::_reloaded( const EventObject
& _rEvent
)
174 mpBibView
->UpdatePages();
175 FormControlContainer::_loaded( _rEvent
);
179 IMPL_LINK( BibView
, CallMappingHdl
, BibView
*, )
181 m_pDatMan
->CreateMappingDialog( this );
185 void BibView::Resize()
187 if ( m_pGeneralPage
)
189 ::Size
aSz( GetOutputSizePixel() );
190 m_pGeneralPage
->SetSizePixel( aSz
);
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();
208 void BibView::GetFocus()
211 m_pGeneralPage
->GrabFocus();
214 bool BibView::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
216 return m_pGeneralPage
&& m_pGeneralPage
->HandleShortCutKey( rKeyEvent
);
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */