2012-09-26 17:53:12 -04:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xmlsourcedlg.hxx"
|
|
|
|
#include "xmlsourcedlg.hrc"
|
|
|
|
|
2012-09-26 21:12:11 -04:00
|
|
|
#include "scresid.hxx"
|
2012-09-28 20:22:23 -04:00
|
|
|
#include "document.hxx"
|
2012-09-28 22:19:46 -04:00
|
|
|
#include "orcusfilters.hxx"
|
|
|
|
#include "filter.hxx"
|
2012-10-10 20:45:55 -04:00
|
|
|
#include "reffact.hxx"
|
2012-09-28 20:22:23 -04:00
|
|
|
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
|
|
|
|
|
|
|
|
using namespace com::sun::star;
|
|
|
|
|
2012-09-26 21:12:11 -04:00
|
|
|
|
2012-09-28 17:51:09 -04:00
|
|
|
ScXMLSourceTree::ScXMLSourceTree(Window* pParent, const ResId& rResId) :
|
2012-10-03 10:33:09 -04:00
|
|
|
SvTreeListBox(pParent, rResId) {}
|
2012-09-28 17:51:09 -04:00
|
|
|
|
2012-10-10 20:45:55 -04:00
|
|
|
ScXMLSourceDlg::ScXMLSourceDlg(
|
|
|
|
SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, ScDocument* pDoc) :
|
|
|
|
ScAnyRefDlg(pB, pCW, pParent, RID_SCDLG_XML_SOURCE),
|
2012-09-28 17:51:09 -04:00
|
|
|
maFlSourceFile(this, ScResId(FL_SOURCE_FILE)),
|
|
|
|
maBtnSelectSource(this, ScResId(BTN_SELECT_SOURCE_FILE)),
|
|
|
|
maFtSourceFile(this, ScResId(FT_SOURCE_FILE)),
|
|
|
|
maFtMapXmlDoc(this, ScResId(FL_MAP_XML_TO_DOCUMENT)),
|
2012-10-10 20:45:55 -04:00
|
|
|
maFtMappedCellTitle(this, ScResId(FT_MAPPED_CELL_TITLE)),
|
2012-10-11 00:20:46 -04:00
|
|
|
maEdit(this, this, ScResId(ED_MAPPED_CELL)),
|
|
|
|
maBtnRb(this, ScResId(BTN_MAPPED_CELL), &maEdit, this),
|
2012-09-28 17:51:09 -04:00
|
|
|
maLbTree(this, ScResId(LB_SOURCE_TREE)),
|
|
|
|
maBtnCancel(this, ScResId(BTN_CANCEL)),
|
2012-09-28 20:22:23 -04:00
|
|
|
maImgFileOpen(ScResId(IMG_FILE_OPEN)),
|
2012-10-03 10:33:09 -04:00
|
|
|
maImgElemDefault(ScResId(IMG_ELEMENT_DEFAULT)),
|
|
|
|
maImgElemRepeat(ScResId(IMG_ELEMENT_REPEAT)),
|
2012-10-05 17:48:48 -04:00
|
|
|
maImgElemAttribute(ScResId(IMG_ELEMENT_ATTRIBUTE)),
|
2012-10-10 20:45:55 -04:00
|
|
|
maStrCellLink(ScResId(STR_CELL_LINK).toString()),
|
|
|
|
maStrRangeLink(ScResId(STR_RANGE_LINK).toString()),
|
|
|
|
mpDoc(pDoc),
|
2012-10-11 00:20:46 -04:00
|
|
|
mpActiveEdit(&maEdit),
|
|
|
|
mbDlgLostFocus(false)
|
2012-09-26 20:13:42 -04:00
|
|
|
{
|
2012-09-28 17:51:09 -04:00
|
|
|
maBtnSelectSource.SetModeImage(maImgFileOpen);
|
2012-09-26 21:12:11 -04:00
|
|
|
FreeResource();
|
2012-09-28 20:22:23 -04:00
|
|
|
|
|
|
|
maBtnSelectSource.SetClickHdl(LINK(this, ScXMLSourceDlg, BtnPressedHdl));
|
2012-10-10 20:45:55 -04:00
|
|
|
|
2012-10-11 00:20:46 -04:00
|
|
|
Link aLink = LINK(this, ScXMLSourceDlg, GetFocusHdl);
|
|
|
|
maEdit.SetGetFocusHdl(aLink);
|
|
|
|
maBtnRb.SetGetFocusHdl(aLink);
|
|
|
|
aLink = LINK(this, ScXMLSourceDlg, LoseFocusHdl);
|
|
|
|
maEdit.SetLoseFocusHdl(aLink);
|
|
|
|
maBtnRb.SetLoseFocusHdl(aLink);
|
|
|
|
|
2012-10-10 20:45:55 -04:00
|
|
|
maFtMappedCellTitle.SetText(maStrCellLink);
|
2012-09-26 20:13:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ScXMLSourceDlg::~ScXMLSourceDlg()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-10 20:45:55 -04:00
|
|
|
sal_Bool ScXMLSourceDlg::IsRefInputMode() const
|
|
|
|
{
|
2012-10-11 00:20:46 -04:00
|
|
|
return mpActiveEdit != NULL;
|
2012-10-10 20:45:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScXMLSourceDlg::SetReference(const ScRange& rRange, ScDocument* pDoc)
|
|
|
|
{
|
2012-10-11 00:20:46 -04:00
|
|
|
if (!mpActiveEdit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rRange.aStart != rRange.aEnd)
|
|
|
|
RefInputStart(mpActiveEdit);
|
|
|
|
|
|
|
|
OUString aStr;
|
|
|
|
rRange.aStart.Format(aStr, SCA_ABS_3D, pDoc, pDoc->GetAddressConvention());
|
|
|
|
mpActiveEdit->SetRefString(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScXMLSourceDlg::Deactivate()
|
|
|
|
{
|
|
|
|
mbDlgLostFocus = true;
|
2012-10-10 20:45:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScXMLSourceDlg::SetActive()
|
|
|
|
{
|
2012-10-11 00:20:46 -04:00
|
|
|
if (mbDlgLostFocus)
|
|
|
|
{
|
|
|
|
mbDlgLostFocus = false;
|
|
|
|
if (mpActiveEdit)
|
|
|
|
{
|
|
|
|
mpActiveEdit->GrabFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GrabFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefInputDone();
|
2012-10-10 20:45:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool ScXMLSourceDlg::Close()
|
|
|
|
{
|
|
|
|
return DoClose(ScXMLSourceDlgWrapper::GetChildWindowId());
|
|
|
|
}
|
|
|
|
|
2012-09-28 20:22:23 -04:00
|
|
|
void ScXMLSourceDlg::SelectSourceFile()
|
|
|
|
{
|
|
|
|
uno::Reference<lang::XMultiServiceFactory> xServiceMgr = mpDoc->GetServiceManager();
|
|
|
|
if (!xServiceMgr.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uno::Reference<ui::dialogs::XFilePicker> xFilePicker(
|
|
|
|
xServiceMgr->createInstance("com.sun.star.ui.dialogs.FilePicker"), uno::UNO_QUERY);
|
|
|
|
|
|
|
|
if (!xFilePicker.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK)
|
|
|
|
// File picker dialog cancelled.
|
|
|
|
return;
|
|
|
|
|
|
|
|
uno::Sequence<OUString> aFiles = xFilePicker->getFiles();
|
|
|
|
if (!aFiles.getLength())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// There should only be one file returned from the file picker.
|
|
|
|
maFtSourceFile.SetText(aFiles[0]);
|
2012-09-28 22:19:46 -04:00
|
|
|
|
|
|
|
LoadSourceFileStructure(aFiles[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScXMLSourceDlg::LoadSourceFileStructure(const OUString& rPath)
|
|
|
|
{
|
|
|
|
ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
|
|
|
|
if (!pOrcus)
|
|
|
|
return;
|
|
|
|
|
2012-10-05 17:48:48 -04:00
|
|
|
pOrcus->loadXMLStructure(
|
|
|
|
maLbTree, rPath, maImgElemDefault, maImgElemRepeat, maImgElemAttribute);
|
2012-09-28 20:22:23 -04:00
|
|
|
}
|
|
|
|
|
2012-10-11 00:20:46 -04:00
|
|
|
void ScXMLSourceDlg::HandleGetFocus(Control* pCtrl)
|
|
|
|
{
|
|
|
|
mpActiveEdit = NULL;
|
|
|
|
if (pCtrl == &maEdit || pCtrl == &maBtnRb)
|
|
|
|
mpActiveEdit = &maEdit;
|
|
|
|
|
|
|
|
if (mpActiveEdit)
|
|
|
|
mpActiveEdit->SetSelection(Selection(0, SELECTION_MAX));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScXMLSourceDlg::HandleLoseFocus(Control* /*pCtrl*/)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK(ScXMLSourceDlg, GetFocusHdl, Control*, pCtrl)
|
|
|
|
{
|
|
|
|
HandleGetFocus(pCtrl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK(ScXMLSourceDlg, LoseFocusHdl, Control*, pCtrl)
|
|
|
|
{
|
|
|
|
HandleLoseFocus(pCtrl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-28 20:22:23 -04:00
|
|
|
IMPL_LINK(ScXMLSourceDlg, BtnPressedHdl, Button*, pBtn)
|
|
|
|
{
|
|
|
|
if (pBtn == &maBtnSelectSource)
|
|
|
|
SelectSourceFile();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-26 17:53:12 -04:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|