Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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 "sections.hrc"
30 : #include "bibconfig.hxx"
31 :
32 :
33 : #include <vcl/svapp.hxx>
34 : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
35 : #include <com/sun/star/form/XLoadable.hpp>
36 : #include <vcl/msgbox.hxx>
37 : #include <tools/debug.hxx>
38 :
39 : using namespace ::com::sun::star;
40 : using namespace ::com::sun::star::form;
41 : using namespace ::com::sun::star::beans;
42 : using namespace ::com::sun::star::lang;
43 : using namespace ::com::sun::star::uno;
44 :
45 :
46 : namespace bib
47 : {
48 :
49 :
50 :
51 0 : BibView::BibView( Window* _pParent, BibDataManager* _pManager, WinBits _nStyle )
52 : :BibWindow( _pParent, _nStyle )
53 : ,m_pDatMan( _pManager )
54 : ,m_xDatMan( _pManager )
55 0 : ,m_pGeneralPage( NULL )
56 : {
57 0 : if ( m_xDatMan.is() )
58 0 : connectForm( m_xDatMan );
59 0 : }
60 :
61 :
62 0 : BibView::~BibView()
63 : {
64 0 : BibGeneralPage* pGeneralPage = m_pGeneralPage;
65 0 : m_pGeneralPage = NULL;
66 :
67 0 : pGeneralPage->CommitActiveControl();
68 0 : Reference< XForm > xForm = m_pDatMan->getForm();
69 0 : Reference< XPropertySet > xProps( xForm, UNO_QUERY );
70 0 : Reference< sdbc::XResultSetUpdate > xResUpd( xProps, UNO_QUERY );
71 : DBG_ASSERT( xResUpd.is(), "BibView::~BibView: invalid form!" );
72 :
73 0 : if ( xResUpd.is() )
74 : {
75 0 : Any aModified = xProps->getPropertyValue( "IsModified" );
76 0 : sal_Bool bFlag = sal_False;
77 0 : if ( ( aModified >>= bFlag ) && bFlag )
78 : {
79 :
80 : try
81 : {
82 0 : Any aNew = xProps->getPropertyValue( "IsNew" );
83 0 : aNew >>= bFlag;
84 0 : if ( bFlag )
85 0 : xResUpd->insertRow();
86 : else
87 0 : xResUpd->updateRow();
88 : }
89 0 : catch( const uno::Exception& rEx)
90 : {
91 : (void) rEx;
92 : }
93 0 : }
94 : }
95 :
96 0 : if ( isFormConnected() )
97 0 : disconnectForm();
98 :
99 0 : pGeneralPage->RemoveListeners();
100 0 : m_xGeneralPage = NULL;
101 0 : }
102 :
103 0 : void BibView::UpdatePages()
104 : {
105 : // TODO:
106 : // this is _strange_: Why not updating the existent general page?
107 : // I consider the current behaviour a HACK.
108 : // frank.schoenheit@sun.com
109 0 : if ( m_pGeneralPage )
110 : {
111 0 : m_pGeneralPage->Hide();
112 0 : m_pGeneralPage->RemoveListeners();
113 0 : m_xGeneralPage = 0;
114 : }
115 :
116 0 : m_xGeneralPage = m_pGeneralPage = new BibGeneralPage( this, m_pDatMan );
117 :
118 0 : Resize();
119 :
120 0 : if( HasFocus() )
121 : // "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
122 0 : m_pGeneralPage->GrabFocus();
123 :
124 0 : OUString sErrorString( m_pGeneralPage->GetErrorString() );
125 0 : if ( !sErrorString.isEmpty() )
126 : {
127 0 : sal_Bool bExecute = BibModul::GetConfig()->IsShowColumnAssignmentWarning();
128 0 : if(!m_pDatMan->HasActiveConnection())
129 : {
130 : //no connection is available -> the data base has to be assigned
131 0 : m_pDatMan->DispatchDBChangeDialog();
132 0 : bExecute = sal_False;
133 : }
134 0 : else if(bExecute)
135 : {
136 0 : sErrorString += "\n";
137 0 : sErrorString += BIB_RESSTR(RID_MAP_QUESTION);
138 0 : QueryBox aQuery( this, WB_YES_NO, sErrorString );
139 0 : aQuery.SetDefaultCheckBoxText();
140 0 : short nResult = aQuery.Execute();
141 : BibModul::GetConfig()->SetShowColumnAssignmentWarning(
142 0 : !aQuery.GetCheckBoxState());
143 0 : if( RET_YES != nResult )
144 : {
145 0 : bExecute = sal_False;
146 0 : }
147 : }
148 0 : if(bExecute)
149 : {
150 0 : Application::PostUserEvent( STATIC_LINK( this, BibView, CallMappingHdl ) );
151 : }
152 0 : }
153 0 : }
154 :
155 0 : void BibView::_loaded( const EventObject& _rEvent )
156 : {
157 0 : UpdatePages();
158 0 : FormControlContainer::_loaded( _rEvent );
159 0 : }
160 :
161 0 : void BibView::_reloaded( const EventObject& _rEvent )
162 : {
163 0 : UpdatePages();
164 0 : FormControlContainer::_loaded( _rEvent );
165 0 : }
166 :
167 0 : IMPL_STATIC_LINK( BibView, CallMappingHdl, BibView*, EMPTYARG )
168 : {
169 0 : pThis->m_pDatMan->CreateMappingDialog( pThis );
170 0 : return 0;
171 : }
172 :
173 0 : void BibView::Resize()
174 : {
175 0 : if ( m_pGeneralPage )
176 : {
177 0 : ::Size aSz( GetOutputSizePixel() );
178 0 : m_pGeneralPage->SetSizePixel( aSz );
179 : }
180 0 : Window::Resize();
181 0 : }
182 :
183 0 : Reference< awt::XControlContainer > BibView::getControlContainer()
184 : {
185 0 : Reference< awt::XControlContainer > xReturn;
186 0 : if ( m_pGeneralPage )
187 0 : xReturn = m_pGeneralPage->GetControlContainer();
188 0 : return xReturn;
189 : }
190 :
191 0 : void BibView::GetFocus()
192 : {
193 0 : if( m_pGeneralPage )
194 0 : m_pGeneralPage->GrabFocus();
195 0 : }
196 :
197 0 : sal_Bool BibView::HandleShortCutKey( const KeyEvent& rKeyEvent )
198 : {
199 0 : return m_pGeneralPage? m_pGeneralPage->HandleShortCutKey( rKeyEvent ) : sal_False;
200 : }
201 :
202 :
203 : } // namespace bib
204 :
205 :
206 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|