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 .
20 #include <comphelper/processfactory.hxx>
21 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
22 #include <com/sun/star/form/XBoundComponent.hpp>
23 #include <com/sun/star/sdbc/XRowSet.hpp>
24 #include <com/sun/star/sdb/XColumn.hpp>
25 #include <com/sun/star/sdb/CommandType.hpp>
26 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
27 #include <com/sun/star/uri/UriReferenceFactory.hpp>
29 #include <o3tl/safeint.hxx>
30 #include <o3tl/string_view.hxx>
31 #include <sal/log.hxx>
32 #include <osl/diagnose.h>
33 #include <cppuhelper/implbase.hxx>
35 #include <vcl/event.hxx>
36 #include <vcl/mnemonic.hxx>
37 #include "general.hxx"
38 #include "bibresid.hxx"
40 #include "bibconfig.hxx"
41 #include <strings.hrc>
45 #include <sfx2/filedlghelper.hxx>
46 #include <sfx2/objsh.hxx>
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::form
;
51 using namespace ::com::sun::star::sdb
;
55 /// Tries to split rText into rURL and nPageNumber.
56 bool SplitUrlAndPage(const OUString
& rText
, OUString
& rUrl
, int& nPageNumber
)
58 uno::Reference
<uri::XUriReferenceFactory
> xUriReferenceFactory
59 = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
60 uno::Reference
<uri::XUriReference
> xUriRef
;
63 xUriRef
= xUriReferenceFactory
->parse(rText
);
65 catch (const uno::Exception
& rException
)
67 SAL_WARN("extensions.biblio",
68 "SplitUrlAndPage: failed to parse url: " << rException
.Message
);
72 OUString
aPagePrefix(u
"page="_ustr
);
73 if (!xUriRef
->getFragment().startsWith(aPagePrefix
))
78 nPageNumber
= o3tl::toInt32(xUriRef
->getFragment().subView(aPagePrefix
.getLength()));
79 xUriRef
->clearFragment();
80 rUrl
= xUriRef
->getUriReference();
84 /// Merges rUrl and rPageSB to a URL string.
85 OUString
MergeUrlAndPage(const OUString
& rUrl
, const weld::SpinButton
& rPageSB
)
87 if (!rPageSB
.get_sensitive())
92 uno::Reference
<uri::XUriReferenceFactory
> xUriReferenceFactory
93 = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
94 uno::Reference
<uri::XUriReference
> xUriRef
;
97 xUriRef
= xUriReferenceFactory
->parse(rUrl
);
99 catch (const uno::Exception
& rException
)
101 SAL_WARN("extensions.biblio",
102 "MergeUrlAndPage: failed to parse url: " << rException
.Message
);
106 OUString
aFragment("page=" + OUString::number(rPageSB
.get_value()));
107 xUriRef
->setFragment(aFragment
);
108 return xUriRef
->getUriReference();
112 static OUString
lcl_GetColumnName( const Mapping
* pMapping
, sal_uInt16 nIndexPos
)
114 BibConfig
* pBibConfig
= BibModul::GetConfig();
115 OUString sRet
= pBibConfig
->GetDefColumnName(nIndexPos
);
117 for(const auto & aColumnPair
: pMapping
->aColumnPairs
)
119 if(aColumnPair
.sLogicalColumnName
== sRet
)
121 sRet
= aColumnPair
.sRealColumnName
;
128 BibGeneralPage::BibGeneralPage(vcl::Window
* pParent
, BibDataManager
* pMan
)
129 : InterimItemWindow(pParent
, u
"modules/sbibliography/ui/generalpage.ui"_ustr
, u
"GeneralPage"_ustr
)
130 , BibShortCutHandler(this)
131 , xScrolledWindow(m_xBuilder
->weld_scrolled_window(u
"scrolledwindow"_ustr
))
132 , xGrid(m_xBuilder
->weld_widget(u
"grid"_ustr
))
133 , xIdentifierFT(m_xBuilder
->weld_label(u
"shortname"_ustr
))
134 , xIdentifierED(m_xBuilder
->weld_entry(u
"shortnamecontrol"_ustr
))
135 , xAuthTypeFT(m_xBuilder
->weld_label(u
"authtype"_ustr
))
136 , xAuthTypeLB(m_xBuilder
->weld_combo_box(u
"authtypecontrol"_ustr
))
137 , xYearFT(m_xBuilder
->weld_label(u
"year"_ustr
))
138 , xYearED(m_xBuilder
->weld_entry(u
"yearcontrol"_ustr
))
139 , xAuthorFT(m_xBuilder
->weld_label(u
"authors"_ustr
))
140 , xAuthorED(m_xBuilder
->weld_entry(u
"authorscontrol"_ustr
))
141 , xTitleFT(m_xBuilder
->weld_label(u
"title"_ustr
))
142 , xTitleED(m_xBuilder
->weld_entry(u
"titlecontrol"_ustr
))
143 , xPublisherFT(m_xBuilder
->weld_label(u
"publisher"_ustr
))
144 , xPublisherED(m_xBuilder
->weld_entry(u
"publishercontrol"_ustr
))
145 , xAddressFT(m_xBuilder
->weld_label(u
"address"_ustr
))
146 , xAddressED(m_xBuilder
->weld_entry(u
"addresscontrol"_ustr
))
147 , xISBNFT(m_xBuilder
->weld_label(u
"isbn"_ustr
))
148 , xISBNED(m_xBuilder
->weld_entry(u
"isbncontrol"_ustr
))
149 , xChapterFT(m_xBuilder
->weld_label(u
"chapter"_ustr
))
150 , xChapterED(m_xBuilder
->weld_entry(u
"chaptercontrol"_ustr
))
151 , xPagesFT(m_xBuilder
->weld_label(u
"pages"_ustr
))
152 , xPagesED(m_xBuilder
->weld_entry(u
"pagescontrol"_ustr
))
153 , xEditorFT(m_xBuilder
->weld_label(u
"editor"_ustr
))
154 , xEditorED(m_xBuilder
->weld_entry(u
"editorcontrol"_ustr
))
155 , xEditionFT(m_xBuilder
->weld_label(u
"edition"_ustr
))
156 , xEditionED(m_xBuilder
->weld_entry(u
"editioncontrol"_ustr
))
157 , xBooktitleFT(m_xBuilder
->weld_label(u
"booktitle"_ustr
))
158 , xBooktitleED(m_xBuilder
->weld_entry(u
"booktitlecontrol"_ustr
))
159 , xVolumeFT(m_xBuilder
->weld_label(u
"volume"_ustr
))
160 , xVolumeED(m_xBuilder
->weld_entry(u
"volumecontrol"_ustr
))
161 , xHowpublishedFT(m_xBuilder
->weld_label(u
"publicationtype"_ustr
))
162 , xHowpublishedED(m_xBuilder
->weld_entry(u
"publicationtypecontrol"_ustr
))
163 , xOrganizationsFT(m_xBuilder
->weld_label(u
"organization"_ustr
))
164 , xOrganizationsED(m_xBuilder
->weld_entry(u
"organizationcontrol"_ustr
))
165 , xInstitutionFT(m_xBuilder
->weld_label(u
"institution"_ustr
))
166 , xInstitutionED(m_xBuilder
->weld_entry(u
"institutioncontrol"_ustr
))
167 , xSchoolFT(m_xBuilder
->weld_label(u
"university"_ustr
))
168 , xSchoolED(m_xBuilder
->weld_entry(u
"universitycontrol"_ustr
))
169 , xReportTypeFT(m_xBuilder
->weld_label(u
"reporttype"_ustr
))
170 , xReportTypeED(m_xBuilder
->weld_entry(u
"reporttypecontrol"_ustr
))
171 , xMonthFT(m_xBuilder
->weld_label(u
"month"_ustr
))
172 , xMonthED(m_xBuilder
->weld_entry(u
"monthcontrol"_ustr
))
173 , xJournalFT(m_xBuilder
->weld_label(u
"journal"_ustr
))
174 , xJournalED(m_xBuilder
->weld_entry(u
"journalcontrol"_ustr
))
175 , xNumberFT(m_xBuilder
->weld_label(u
"number"_ustr
))
176 , xNumberED(m_xBuilder
->weld_entry(u
"numbercontrol"_ustr
))
177 , xSeriesFT(m_xBuilder
->weld_label(u
"series"_ustr
))
178 , xSeriesED(m_xBuilder
->weld_entry(u
"seriescontrol"_ustr
))
179 , xAnnoteFT(m_xBuilder
->weld_label(u
"annotation"_ustr
))
180 , xAnnoteED(m_xBuilder
->weld_entry(u
"annotationcontrol"_ustr
))
181 , xNoteFT(m_xBuilder
->weld_label(u
"note"_ustr
))
182 , xNoteED(m_xBuilder
->weld_entry(u
"notecontrol"_ustr
))
183 , xURLFT(m_xBuilder
->weld_label(u
"url"_ustr
))
184 , xURLED(m_xBuilder
->weld_entry(u
"urlcontrol"_ustr
))
185 , xCustom1FT(m_xBuilder
->weld_label(u
"custom1"_ustr
))
186 , xCustom1ED(m_xBuilder
->weld_entry(u
"custom1control"_ustr
))
187 , xCustom2FT(m_xBuilder
->weld_label(u
"custom2"_ustr
))
188 , xCustom2ED(m_xBuilder
->weld_entry(u
"custom2control"_ustr
))
189 , xCustom3FT(m_xBuilder
->weld_label(u
"custom3"_ustr
))
190 , xCustom3ED(m_xBuilder
->weld_entry(u
"custom3control"_ustr
))
191 , xCustom4FT(m_xBuilder
->weld_label(u
"custom4"_ustr
))
192 , xCustom4ED(m_xBuilder
->weld_entry(u
"custom4control"_ustr
))
193 , xCustom5FT(m_xBuilder
->weld_label(u
"custom5"_ustr
))
194 , xCustom5ED(m_xBuilder
->weld_entry(u
"custom5control"_ustr
))
195 , m_xLocalURLFT(m_xBuilder
->weld_label(u
"localurl"_ustr
))
196 , m_xLocalURLED(m_xBuilder
->weld_entry(u
"localurlcontrol"_ustr
))
197 , m_xLocalBrowseButton(m_xBuilder
->weld_button(u
"localbrowse"_ustr
))
198 , m_xLocalPageCB(m_xBuilder
->weld_check_button(u
"localpagecb"_ustr
))
199 , m_xLocalPageSB(m_xBuilder
->weld_spin_button(u
"localpagesb"_ustr
))
202 SetStyle(GetStyle() | WB_DIALOGCONTROL
);
204 BibConfig
* pBibConfig
= BibModul::GetConfig();
205 BibDBDescriptor aDesc
;
206 aDesc
.sDataSource
= pDatMan
->getActiveDataSource();
207 aDesc
.sTableOrQuery
= pDatMan
->getActiveDataTable();
208 aDesc
.nCommandType
= CommandType::TABLE
;
209 const Mapping
* pMapping
= pBibConfig
->GetMapping(aDesc
);
211 xIdentifierED
->connect_key_press(LINK(this, BibGeneralPage
, FirstElementKeyInputHdl
));
213 AddControlWithError(lcl_GetColumnName(pMapping
, IDENTIFIER_POS
),
214 xIdentifierFT
->get_label(), *xIdentifierED
,
215 sTableErrorString
, HID_BIB_IDENTIFIER_POS
);
217 AddControlWithError(lcl_GetColumnName(pMapping
, AUTHORITYTYPE_POS
),
218 xAuthTypeFT
->get_label(), *xAuthTypeLB
,
219 sTableErrorString
, HID_BIB_AUTHORITYTYPE_POS
);
221 AddControlWithError(lcl_GetColumnName(pMapping
, YEAR_POS
),
222 xYearFT
->get_label(), *xYearED
,
223 sTableErrorString
, HID_BIB_YEAR_POS
);
225 AddControlWithError(lcl_GetColumnName(pMapping
, AUTHOR_POS
),
226 xAuthorFT
->get_label(), *xAuthorED
,
227 sTableErrorString
, HID_BIB_AUTHOR_POS
);
229 AddControlWithError(lcl_GetColumnName(pMapping
, TITLE_POS
),
230 xTitleFT
->get_label(), *xTitleED
,
231 sTableErrorString
, HID_BIB_TITLE_POS
);
233 AddControlWithError(lcl_GetColumnName(pMapping
, PUBLISHER_POS
),
234 xPublisherFT
->get_label(), *xPublisherED
,
235 sTableErrorString
, HID_BIB_PUBLISHER_POS
);
237 AddControlWithError(lcl_GetColumnName(pMapping
, ADDRESS_POS
),
238 xAddressFT
->get_label(), *xAddressED
,
239 sTableErrorString
, HID_BIB_ADDRESS_POS
);
241 AddControlWithError(lcl_GetColumnName(pMapping
, ISBN_POS
),
242 xISBNFT
->get_label(), *xISBNED
,
243 sTableErrorString
, HID_BIB_ISBN_POS
);
245 AddControlWithError(lcl_GetColumnName(pMapping
, CHAPTER_POS
),
246 xChapterFT
->get_label(), *xChapterED
,
247 sTableErrorString
, HID_BIB_CHAPTER_POS
);
249 AddControlWithError(lcl_GetColumnName(pMapping
, PAGES_POS
),
250 xPagesFT
->get_label(), *xPagesED
,
251 sTableErrorString
, HID_BIB_PAGES_POS
);
253 AddControlWithError(lcl_GetColumnName(pMapping
, EDITOR_POS
),
254 xEditorFT
->get_label(), *xEditorED
,
255 sTableErrorString
, HID_BIB_EDITOR_POS
);
257 AddControlWithError(lcl_GetColumnName(pMapping
, EDITION_POS
),
258 xEditionFT
->get_label(), *xEditionED
,
259 sTableErrorString
, HID_BIB_EDITION_POS
);
261 AddControlWithError(lcl_GetColumnName(pMapping
, BOOKTITLE_POS
),
262 xBooktitleFT
->get_label(), *xBooktitleED
,
263 sTableErrorString
, HID_BIB_BOOKTITLE_POS
);
265 AddControlWithError(lcl_GetColumnName(pMapping
, VOLUME_POS
),
266 xVolumeFT
->get_label(), *xVolumeED
,
267 sTableErrorString
, HID_BIB_VOLUME_POS
);
269 AddControlWithError(lcl_GetColumnName(pMapping
, HOWPUBLISHED_POS
),
270 xHowpublishedFT
->get_label(), *xHowpublishedED
,
271 sTableErrorString
, HID_BIB_HOWPUBLISHED_POS
);
273 AddControlWithError(lcl_GetColumnName(pMapping
, ORGANIZATIONS_POS
),
274 xOrganizationsFT
->get_label(), *xOrganizationsED
,
275 sTableErrorString
, HID_BIB_ORGANIZATIONS_POS
);
277 AddControlWithError(lcl_GetColumnName(pMapping
, INSTITUTION_POS
),
278 xInstitutionFT
->get_label(), *xInstitutionED
,
279 sTableErrorString
, HID_BIB_INSTITUTION_POS
);
281 AddControlWithError(lcl_GetColumnName(pMapping
, SCHOOL_POS
),
282 xSchoolFT
->get_label(), *xSchoolED
,
283 sTableErrorString
, HID_BIB_SCHOOL_POS
);
285 AddControlWithError(lcl_GetColumnName(pMapping
, REPORTTYPE_POS
),
286 xReportTypeFT
->get_label(), *xReportTypeED
,
287 sTableErrorString
, HID_BIB_REPORTTYPE_POS
);
289 AddControlWithError(lcl_GetColumnName(pMapping
, MONTH_POS
),
290 xMonthFT
->get_label(), *xMonthED
,
291 sTableErrorString
, HID_BIB_MONTH_POS
);
293 AddControlWithError(lcl_GetColumnName(pMapping
, JOURNAL_POS
),
294 xJournalFT
->get_label(), *xJournalED
,
295 sTableErrorString
, HID_BIB_JOURNAL_POS
);
297 AddControlWithError(lcl_GetColumnName(pMapping
, NUMBER_POS
),
298 xNumberFT
->get_label(), *xNumberED
,
299 sTableErrorString
, HID_BIB_NUMBER_POS
);
301 AddControlWithError(lcl_GetColumnName(pMapping
, SERIES_POS
),
302 xSeriesFT
->get_label(), *xSeriesED
,
303 sTableErrorString
, HID_BIB_SERIES_POS
);
305 AddControlWithError(lcl_GetColumnName(pMapping
, ANNOTE_POS
),
306 xAnnoteFT
->get_label(), *xAnnoteED
,
307 sTableErrorString
, HID_BIB_ANNOTE_POS
);
309 AddControlWithError(lcl_GetColumnName(pMapping
, NOTE_POS
),
310 xNoteFT
->get_label(), *xNoteED
,
311 sTableErrorString
, HID_BIB_NOTE_POS
);
313 AddControlWithError(lcl_GetColumnName(pMapping
, URL_POS
),
314 xURLFT
->get_label(), *xURLED
,
315 sTableErrorString
, HID_BIB_URL_POS
);
317 AddControlWithError(lcl_GetColumnName(pMapping
, CUSTOM1_POS
),
318 xCustom1FT
->get_label(), *xCustom1ED
,
319 sTableErrorString
, HID_BIB_CUSTOM1_POS
);
321 AddControlWithError(lcl_GetColumnName(pMapping
, CUSTOM2_POS
),
322 xCustom2FT
->get_label(), *xCustom2ED
,
323 sTableErrorString
, HID_BIB_CUSTOM2_POS
);
325 AddControlWithError(lcl_GetColumnName(pMapping
, CUSTOM3_POS
),
326 xCustom3FT
->get_label(), *xCustom3ED
,
327 sTableErrorString
, HID_BIB_CUSTOM3_POS
);
329 AddControlWithError(lcl_GetColumnName(pMapping
, CUSTOM4_POS
),
330 xCustom4FT
->get_label(), *xCustom4ED
,
331 sTableErrorString
, HID_BIB_CUSTOM4_POS
);
333 AddControlWithError(lcl_GetColumnName(pMapping
, CUSTOM5_POS
),
334 xCustom5FT
->get_label(), *xCustom5ED
,
335 sTableErrorString
, HID_BIB_CUSTOM5_POS
);
337 AddControlWithError(lcl_GetColumnName(pMapping
, LOCAL_URL_POS
),
338 m_xLocalURLFT
->get_label(), *m_xLocalURLED
,
339 sTableErrorString
, HID_BIB_LOCAL_URL_POS
);
341 m_xLocalBrowseButton
->connect_clicked(LINK(this, BibGeneralPage
, BrowseHdl
));
342 m_xLocalPageCB
->connect_toggled(LINK(this, BibGeneralPage
, PageNumHdl
));
344 m_xLocalURLED
->connect_key_press(LINK(this, BibGeneralPage
, LastElementKeyInputHdl
));
346 if(!sTableErrorString
.isEmpty())
347 sTableErrorString
= BibResId(ST_ERROR_PREFIX
) + sTableErrorString
;
349 SetText(BibResId(ST_TYPE_TITLE
));
351 Size
aSize(LogicToPixel(Size(0, 209), MapMode(MapUnit::MapAppFont
)));
352 set_height_request(aSize
.Height());
355 IMPL_LINK_NOARG(BibGeneralPage
, BrowseHdl
, weld::Button
&, void)
357 sfx2::FileDialogHelper
aFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
358 FileDialogFlags::NONE
, GetFrameWeld());
359 OUString aPath
= m_xLocalURLED
->get_text();
360 if (!aPath
.isEmpty())
362 aFileDlg
.SetDisplayDirectory(aPath
);
367 if (SfxObjectShell
* pShell
= SfxObjectShell::Current())
369 aBaseURL
= pShell
->getDocumentBaseURL();
371 if (!aBaseURL
.isEmpty())
373 aFileDlg
.SetDisplayDirectory(aBaseURL
);
377 if (aFileDlg
.Execute() != ERRCODE_NONE
)
382 weld::Entry
& rEntry
= *m_xLocalURLED
;
383 rEntry
.set_text(aFileDlg
.GetPath());
386 IMPL_LINK(BibGeneralPage
, PageNumHdl
, weld::Toggleable
&, rPageCB
, void)
388 weld::SpinButton
& rPageSB
= *m_xLocalPageSB
;
389 if (rPageCB
.get_active())
391 rPageSB
.set_sensitive(true);
392 rPageSB
.set_value(1);
396 rPageSB
.set_sensitive(false);
400 IMPL_LINK(BibGeneralPage
, FirstElementKeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
402 sal_uInt16 nCode
= rKeyEvent
.GetKeyCode().GetCode();
403 bool bShift
= rKeyEvent
.GetKeyCode().IsShift();
404 bool bCtrl
= rKeyEvent
.GetKeyCode().IsMod1();
405 bool bAlt
= rKeyEvent
.GetKeyCode().IsMod2();
406 if (KEY_TAB
== nCode
&& bShift
&& !bCtrl
&& !bAlt
)
409 uno::Reference
<sdbc::XRowSet
> xRowSet(pDatMan
->getForm(), UNO_QUERY
);
410 if (xRowSet
.is() && !xRowSet
->isFirst())
412 m_xLocalURLED
->grab_focus();
413 m_xLocalURLED
->select_region(0, -1);
414 GainFocusHdl(*m_xLocalURLED
);
420 void BibGeneralPage::SaveChanges()
422 Reference
< XForm
> xForm
= pDatMan
->getForm();
423 Reference
< beans::XPropertySet
> xProps( xForm
, UNO_QUERY
);
424 Reference
< sdbc::XResultSetUpdate
> xResUpd( xProps
, UNO_QUERY
);
428 Any aModified
= xProps
->getPropertyValue( u
"IsModified"_ustr
);
430 if ( !( aModified
>>= bFlag
) || !bFlag
)
435 Any aNew
= xProps
->getPropertyValue( u
"IsNew"_ustr
);
438 xResUpd
->insertRow();
440 xResUpd
->updateRow();
442 catch( const uno::Exception
&) {}
445 IMPL_LINK(BibGeneralPage
, LastElementKeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
447 sal_uInt16 nCode
= rKeyEvent
.GetKeyCode().GetCode();
448 bool bShift
= rKeyEvent
.GetKeyCode().IsShift();
449 bool bCtrl
= rKeyEvent
.GetKeyCode().IsMod1();
450 bool bAlt
= rKeyEvent
.GetKeyCode().IsMod2();
451 if (KEY_TAB
!= nCode
|| bShift
|| bCtrl
|| bAlt
)
454 uno::Reference
<sdbc::XRowSet
> xRowSet(pDatMan
->getForm(), UNO_QUERY
);
457 if (xRowSet
->isLast())
459 uno::Reference
<sdbc::XResultSetUpdate
> xUpdateCursor(xRowSet
, UNO_QUERY
);
460 if (xUpdateCursor
.is())
461 xUpdateCursor
->moveToInsertRow();
464 (void)xRowSet
->next();
466 xIdentifierED
->grab_focus();
467 xIdentifierED
->select_region(0, -1);
468 GainFocusHdl(*xIdentifierED
);
472 BibGeneralPage::~BibGeneralPage()
477 class ChangeListener
: public cppu::WeakImplHelper
<css::beans::XPropertyChangeListener
>
480 explicit ChangeListener(css::uno::Reference
<css::beans::XPropertySet
> xPropSet
)
481 : m_xPropSet(std::move(xPropSet
))
482 , m_bSelfChanging(false)
486 virtual void SAL_CALL
disposing(lang::EventObject
const &) override
490 virtual void start() = 0;
496 virtual void WriteBack() = 0;
499 css::uno::Reference
<css::beans::XPropertySet
> m_xPropSet
;
500 bool m_bSelfChanging
;
505 class EntryChangeListener
: public ChangeListener
508 explicit EntryChangeListener(weld::Entry
& rEntry
, const css::uno::Reference
<css::beans::XPropertySet
>& rPropSet
,
509 BibGeneralPage
& rPage
)
510 : ChangeListener(rPropSet
)
514 rEntry
.connect_focus_out(LINK(this, EntryChangeListener
, LoseFocusHdl
));
515 setValue(rPropSet
->getPropertyValue(u
"Text"_ustr
));
518 virtual void SAL_CALL
propertyChange(const css::beans::PropertyChangeEvent
& evt
) override
522 setValue(evt
.NewValue
);
525 virtual void start() override
527 m_xPropSet
->addPropertyChangeListener(u
"Text"_ustr
, this);
530 virtual void stop() override
532 m_xPropSet
->removePropertyChangeListener(u
"Text"_ustr
, this);
533 ChangeListener::stop();
537 weld::Entry
& m_rEntry
;
538 BibGeneralPage
& m_rPage
;
540 DECL_LINK(LoseFocusHdl
, weld::Widget
&, void);
542 /// Updates the UI widget(s) based on rValue.
543 void setValue(const css::uno::Any
& rValue
)
547 if (&m_rEntry
== &m_rPage
.GetLocalURLED())
551 if (SplitUrlAndPage(sNewName
, aUrl
, nPageNumber
))
553 m_rEntry
.set_text(aUrl
);
554 m_rPage
.GetLocalPageCB().set_active(true);
555 m_rPage
.GetLocalPageSB().set_sensitive(true);
556 m_rPage
.GetLocalPageSB().set_value(nPageNumber
);
560 m_rEntry
.set_text(sNewName
);
561 m_rPage
.GetLocalPageCB().set_active(false);
562 m_rPage
.GetLocalPageSB().set_sensitive(false);
563 m_rPage
.GetLocalPageSB().set_value(0);
568 m_rEntry
.set_text(sNewName
);
571 m_rEntry
.save_value();
572 if (&m_rEntry
== &m_rPage
.GetLocalURLED())
574 m_rPage
.GetLocalPageSB().save_value();
578 /// Updates m_xPropSet based on the UI widget(s).
579 virtual void WriteBack() override
581 bool bLocalURL
= &m_rEntry
== &m_rPage
.GetLocalURLED()
582 && m_rPage
.GetLocalPageSB().get_value_changed_from_saved();
583 if (!m_rEntry
.get_value_changed_from_saved() && !bLocalURL
)
586 m_bSelfChanging
= true;
589 if (&m_rEntry
== &m_rPage
.GetLocalURLED())
591 aText
= MergeUrlAndPage(m_rEntry
.get_text(), m_rPage
.GetLocalPageSB());
595 aText
= m_rEntry
.get_text();
597 m_xPropSet
->setPropertyValue(u
"Text"_ustr
, Any(aText
));
599 css::uno::Reference
<css::form::XBoundComponent
> xBound(m_xPropSet
, css::uno::UNO_QUERY
);
603 m_bSelfChanging
= false;
604 m_rEntry
.save_value();
605 if (&m_rEntry
== &m_rPage
.GetLocalURLED())
607 m_rPage
.GetLocalPageSB().save_value();
613 IMPL_LINK_NOARG(EntryChangeListener
, LoseFocusHdl
, weld::Widget
&, void)
618 class ComboBoxChangeListener
: public ChangeListener
621 explicit ComboBoxChangeListener(weld::ComboBox
& rComboBox
, const css::uno::Reference
<css::beans::XPropertySet
>& rPropSet
)
622 : ChangeListener(rPropSet
)
623 , m_rComboBox(rComboBox
)
625 rComboBox
.connect_changed(LINK(this, ComboBoxChangeListener
, ChangeHdl
));
626 setValue(rPropSet
->getPropertyValue(u
"SelectedItems"_ustr
));
629 virtual void SAL_CALL
propertyChange(const css::beans::PropertyChangeEvent
& evt
) override
633 setValue(evt
.NewValue
);
636 virtual void start() override
638 m_xPropSet
->addPropertyChangeListener(u
"SelectedItems"_ustr
, this);
641 virtual void stop() override
643 m_xPropSet
->removePropertyChangeListener(u
"SelectedItems"_ustr
, this);
644 ChangeListener::stop();
648 weld::ComboBox
& m_rComboBox
;
650 DECL_LINK(ChangeHdl
, weld::ComboBox
&, void);
652 void setValue(const css::uno::Any
& rValue
)
654 sal_Int16 nSelection
= -1;
655 Sequence
<sal_Int16
> aSelection
;
656 rValue
>>= aSelection
;
657 if (aSelection
.hasElements())
658 nSelection
= aSelection
[0];
660 m_rComboBox
.set_active(nSelection
);
661 m_rComboBox
.save_value();
664 virtual void WriteBack() override
666 if (!m_rComboBox
.get_value_changed_from_saved())
668 m_bSelfChanging
= true;
670 Sequence
<sal_Int16
> aSelection
{ o3tl::narrowing
<sal_Int16
>(m_rComboBox
.get_active()) };
671 m_xPropSet
->setPropertyValue(u
"SelectedItems"_ustr
, Any(aSelection
));
673 css::uno::Reference
<css::form::XBoundComponent
> xBound(m_xPropSet
, css::uno::UNO_QUERY
);
677 m_bSelfChanging
= false;
678 m_rComboBox
.save_value();
682 IMPL_LINK_NOARG(ComboBoxChangeListener
, ChangeHdl
, weld::ComboBox
&, void)
688 void BibGeneralPage::dispose()
690 for (auto& listener
: maChangeListeners
)
692 maChangeListeners
.clear();
696 xScrolledWindow
.reset();
698 xIdentifierFT
.reset();
699 xIdentifierED
.reset();
708 xPublisherFT
.reset();
709 xPublisherED
.reset();
722 xBooktitleFT
.reset();
723 xBooktitleED
.reset();
726 xHowpublishedFT
.reset();
727 xHowpublishedED
.reset();
728 xOrganizationsFT
.reset();
729 xOrganizationsED
.reset();
730 xInstitutionFT
.reset();
731 xInstitutionED
.reset();
734 xReportTypeFT
.reset();
735 xReportTypeED
.reset();
760 m_xLocalURLFT
.reset();
761 m_xLocalURLED
.reset();
762 m_xLocalBrowseButton
.reset();
763 m_xLocalPageCB
.reset();
764 m_xLocalPageSB
.reset();
765 InterimItemWindow::dispose();
768 weld::Entry
& BibGeneralPage::GetLocalURLED() { return *m_xLocalURLED
; }
770 weld::CheckButton
& BibGeneralPage::GetLocalPageCB() { return *m_xLocalPageCB
; }
772 weld::SpinButton
& BibGeneralPage::GetLocalPageSB() { return *m_xLocalPageSB
; }
774 bool BibGeneralPage::AddXControl(const OUString
& rName
, weld::Entry
& rEntry
)
776 uno::Reference
< awt::XControlModel
> xCtrModel
;
779 xCtrModel
= pDatMan
->loadControlModel(rName
, false);
780 if ( xCtrModel
.is() )
782 uno::Reference
< beans::XPropertySet
> xPropSet( xCtrModel
, UNO_QUERY
);
786 maChangeListeners
.emplace_back(new EntryChangeListener(rEntry
, xPropSet
, *this));
787 maChangeListeners
.back()->start();
788 if (&rEntry
== m_xLocalURLED
.get())
790 m_aURLListener
= maChangeListeners
.back();
791 m_xLocalPageSB
->connect_focus_out(LINK(this, BibGeneralPage
, LosePageFocusHdl
));
796 catch(const Exception
&)
798 OSL_FAIL("BibGeneralPage::AddXControl: something went wrong!");
800 return xCtrModel
.is();
803 IMPL_LINK_NOARG(BibGeneralPage
, LosePageFocusHdl
, weld::Widget
&, void)
805 m_aURLListener
->WriteBack();
808 IMPL_LINK(BibGeneralPage
, GainFocusHdl
, weld::Widget
&, rWidget
, void)
810 int x
, y
, width
, height
;
811 if (!rWidget
.get_extents_relative_to(*xGrid
, x
, y
, width
, height
))
814 int bottom
= y
+ height
;
815 int nVScrollPos
= xScrolledWindow
->vadjustment_get_value();
816 if (y
< nVScrollPos
|| bottom
> nVScrollPos
+ xScrolledWindow
->vadjustment_get_page_size())
817 xScrolledWindow
->vadjustment_set_value(y
);
819 int right
= x
+ width
;
820 int nHScrollPos
= xScrolledWindow
->hadjustment_get_value();
821 if (x
< nHScrollPos
|| right
> nHScrollPos
+ xScrolledWindow
->hadjustment_get_page_size())
822 xScrolledWindow
->hadjustment_set_value(x
);
825 template<class Target
> void BibGeneralPage::AddControlWithError(const OUString
& rColumnName
, const OUString
& rColumnUIName
,
826 Target
& rWidget
, OUString
& rErrorString
, const OUString
& rHelpId
)
828 rWidget
.set_help_id(rHelpId
);
829 rWidget
.connect_focus_in(LINK(this, BibGeneralPage
, GainFocusHdl
));
830 bool bSuccess
= AddXControl(rColumnName
, rWidget
);
833 if( !rErrorString
.isEmpty() )
834 rErrorString
+= "\n";
836 rErrorString
+= MnemonicGenerator::EraseAllMnemonicChars(rColumnUIName
);
840 bool BibGeneralPage::AddXControl(const OUString
& rName
, weld::ComboBox
& rList
)
842 uno::Reference
< awt::XControlModel
> xCtrModel
;
845 xCtrModel
= pDatMan
->loadControlModel(rName
, true);
846 if ( xCtrModel
.is() )
848 uno::Reference
< beans::XPropertySet
> xPropSet( xCtrModel
, UNO_QUERY
);
852 css::uno::Sequence
<OUString
> aEntries
;
853 xPropSet
->getPropertyValue(u
"StringItemList"_ustr
) >>= aEntries
;
854 for (const OUString
& rString
: aEntries
)
855 rList
.append_text(rString
);
857 sal_Int16 nSelection
= -1;
858 Sequence
<sal_Int16
> aSelection
;
859 xPropSet
->getPropertyValue(u
"SelectedItems"_ustr
) >>= aSelection
;
860 if (aSelection
.hasElements())
861 nSelection
= aSelection
[0];
863 rList
.set_active(nSelection
);
866 maChangeListeners
.emplace_back(new ComboBoxChangeListener(rList
, xPropSet
));
867 maChangeListeners
.back()->start();
871 catch(const Exception
&)
873 OSL_FAIL("BibGeneralPage::AddXControl: something went wrong!");
875 return xCtrModel
.is();
878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */