1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#include <strings.hrc>
#include "bibcont.hxx"
#include "bibbeam.hxx"
#include "general.hxx"
#include "bibview.hxx"
#include "datman.hxx"
#include "bibresid.hxx"
#include "bibmod.hxx"
#include "bibconfig.hxx"


#include <vcl/svapp.hxx>
#include <com/sun/star/sdbc/XResultSetUpdate.hpp>
#include <com/sun/star/form/XLoadable.hpp>
#include <vcl/weld.hxx>
#include <tools/debug.hxx>

using namespace ::com::sun::star;
using namespace ::com::sun::star::form;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;

namespace
{
    class MessageWithCheck : public weld::MessageDialogController
    {
    private:
        std::unique_ptr<weld::CheckButton> m_xWarningOnBox;
    public:
        MessageWithCheck(weld::Window *pParent)
            : MessageDialogController(pParent, "modules/sbibliography/ui/querydialog.ui", "QueryDialog", "ask")
            , m_xWarningOnBox(m_xBuilder->weld_check_button("ask"))
        {
        }
        bool get_active() const { return m_xWarningOnBox->get_active(); }
    };
}

namespace bib
{


    BibView::BibView( vcl::Window* _pParent, BibDataManager* _pManager, WinBits _nStyle )
        :BibWindow( _pParent, _nStyle )
        ,m_pDatMan( _pManager )
        ,m_xDatMan( _pManager )
        ,m_pGeneralPage( nullptr )
        ,m_aFormControlContainer(this)
    {
        if ( m_xDatMan.is() )
            m_aFormControlContainer.connectForm( m_xDatMan );
    }


    BibView::~BibView()
    {
        disposeOnce();
    }

    void BibView::dispose()
    {
        VclPtr<BibGeneralPage> pGeneralPage = m_pGeneralPage;
        m_pGeneralPage.clear();

        pGeneralPage->CommitActiveControl();
        Reference< XForm > xForm = m_pDatMan->getForm();
        Reference< XPropertySet > xProps( xForm, UNO_QUERY );
        Reference< sdbc::XResultSetUpdate > xResUpd( xProps, UNO_QUERY );
        DBG_ASSERT( xResUpd.is(), "BibView::~BibView: invalid form!" );

        if ( xResUpd.is() )
        {
            Any aModified = xProps->getPropertyValue( "IsModified" );
            bool bFlag = false;
            if ( ( aModified >>= bFlag ) && bFlag )
            {

                try
                {
                    Any aNew = xProps->getPropertyValue( "IsNew" );
                    aNew >>= bFlag;
                    if ( bFlag )
                        xResUpd->insertRow();
                    else
                        xResUpd->updateRow();
                }
                catch( const uno::Exception&) {}
            }
        }

        if ( m_aFormControlContainer.isFormConnected() )
            m_aFormControlContainer.disconnectForm();

        pGeneralPage->RemoveListeners();
        pGeneralPage.disposeAndClear();
        BibWindow::dispose();
    }

    void BibView::UpdatePages()
    {
        // TODO:
        // this is _strange_: Why not updating the existent general page?
        // I consider the current behaviour a HACK.
        if ( m_pGeneralPage )
        {
            m_pGeneralPage->Hide();
            m_pGeneralPage->RemoveListeners();
            m_pGeneralPage.disposeAndClear();
        }

        m_pGeneralPage = VclPtr<BibGeneralPage>::Create( this, m_pDatMan );
        m_pGeneralPage->Show();

        if( HasFocus() )
            // "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
            m_pGeneralPage->GrabFocus();

        OUString sErrorString( m_pGeneralPage->GetErrorString() );
        if ( !sErrorString.isEmpty() )
        {
            bool bExecute = BibModul::GetConfig()->IsShowColumnAssignmentWarning();
            if(!m_pDatMan->HasActiveConnection())
            {
                //no connection is available -> the data base has to be assigned
                m_pDatMan->DispatchDBChangeDialog();
                bExecute = false;
            }
            else if(bExecute)
            {
                sErrorString += "\n";
                sErrorString += BibResId(RID_MAP_QUESTION);

                MessageWithCheck aQueryBox(GetFrameWeld());
                aQueryBox.set_primary_text(sErrorString);

                short nResult = aQueryBox.run();
                BibModul::GetConfig()->SetShowColumnAssignmentWarning(!aQueryBox.get_active());

                if( RET_YES != nResult )
                {
                    bExecute = false;
                }
            }
            if(bExecute)
            {
                Application::PostUserEvent( LINK( this, BibView, CallMappingHdl ), nullptr, true );
            }
        }
    }

    BibViewFormControlContainer::BibViewFormControlContainer(BibView *pBibView) : mpBibView(pBibView) {}

    void BibViewFormControlContainer::_loaded( const EventObject& _rEvent )
    {
        mpBibView->UpdatePages();
        FormControlContainer::_loaded( _rEvent );
        mpBibView->Resize();
    }

    void BibViewFormControlContainer::_reloaded( const EventObject& _rEvent )
    {
        mpBibView->UpdatePages();
        FormControlContainer::_loaded( _rEvent );
        mpBibView->Resize();
    }

    IMPL_LINK_NOARG( BibView, CallMappingHdl, void*, void)<--- syntax error
    {
        m_pDatMan->CreateMappingDialog(GetFrameWeld());
    }

    void BibView::Resize()
    {
        if ( m_pGeneralPage )
        {
            ::Size aSz( GetOutputSizePixel() );
            m_pGeneralPage->SetSizePixel( aSz );
        }
        Window::Resize();
    }

    Reference< awt::XControlContainer > BibViewFormControlContainer::getControlContainer()
    {
        return mpBibView->getControlContainer();
    }

    Reference< awt::XControlContainer > BibView::getControlContainer()
    {
        Reference< awt::XControlContainer > xReturn;
        if ( m_pGeneralPage )
            xReturn = m_pGeneralPage->GetControlContainer();
        return xReturn;
    }

    void BibView::GetFocus()
    {
        if( m_pGeneralPage )
            m_pGeneralPage->GrabFocus();
    }

    bool BibView::HandleShortCutKey( const KeyEvent& rKeyEvent )
    {
        return m_pGeneralPage && m_pGeneralPage->HandleShortCutKey( rKeyEvent );
    }


}   // namespace bib


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */