LibreOffice Module dbaccess (master) 1
DocumentInfoPreview.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/document/XDocumentProperties.hpp>
24#include <com/sun/star/script/CannotConvertException.hpp>
25#include <com/sun/star/script/Converter.hpp>
26#include <com/sun/star/script/XTypeConverter.hpp>
28#include <comphelper/string.hxx>
29#include <editeng/eeitem.hxx>
30#include <editeng/wghtitem.hxx>
31#include <rtl/ustring.hxx>
33#include <vcl/settings.hxx>
34#include <vcl/svapp.hxx>
35#include <svl/itemset.hxx>
36#include <tools/datetime.hxx>
39
40#include <templwin.hrc>
41#include "templwin.hxx"
42
43namespace dbaui {
44
46{
47}
48
50{
51 WeldEditView::SetDrawingArea(pDrawingArea);
52 m_xEditView->HideCursor();
53 m_xEditView->SetReadOnly(true);
54}
55
57{
58}
59
61 m_xEditEngine->SetText(OUString());
62}
63
65 css::uno::Reference< css::document::XDocumentProperties > const & xDocProps)
66{
67 assert(xDocProps.is());
68
69 insertNonempty(DI_TITLE, xDocProps->getTitle());
70 insertNonempty(DI_FROM, xDocProps->getAuthor());
71 insertDateTime(DI_DATE, xDocProps->getCreationDate());
72 insertNonempty(DI_MODIFIEDBY, xDocProps->getModifiedBy());
73 insertDateTime(DI_MODIFIEDDATE, xDocProps->getModificationDate());
74 insertNonempty(DI_PRINTBY, xDocProps->getPrintedBy());
75 insertDateTime(DI_PRINTDATE, xDocProps->getPrintDate());
76 insertNonempty(DI_THEME, xDocProps->getSubject());
78 DI_KEYWORDS,
79 comphelper::string::convertCommaSeparated(xDocProps->getKeywords()));
80 insertNonempty(DI_DESCRIPTION, xDocProps->getDescription());
81
82 // User-defined (custom) properties:
83 css::uno::Reference< css::beans::XPropertySet > user(
84 xDocProps->getUserDefinedProperties(), css::uno::UNO_QUERY_THROW);
85 css::uno::Reference< css::beans::XPropertySetInfo > info(
86 user->getPropertySetInfo());
87 const css::uno::Sequence< css::beans::Property > props(info->getProperties());
88 for (const auto& rProp : props) {
89 OUString name(rProp.Name);
90 css::uno::Any aAny(user->getPropertyValue(name));
91 css::uno::Reference< css::script::XTypeConverter > conv(
92 css::script::Converter::create(
94 OUString value;
95 try {
96 value = conv->convertToSimpleType(aAny, css::uno::TypeClass_STRING).
97 get< OUString >();
98 } catch (css::script::CannotConvertException &) {
99 TOOLS_INFO_EXCEPTION("svtools.contnr", "ignored");
100 }
101 if (!value.isEmpty()) {
103 }
104 }
105
106 m_xEditView->SetSelection(ESelection(0, 0, 0, 0));
107}
108
109namespace
110{
111 ESelection InsertAtEnd(const EditEngine& rEditEngine)
112 {
113 const sal_uInt32 nPara = rEditEngine.GetParagraphCount() -1;
114 sal_Int32 nLastLen = rEditEngine.GetText(nPara).getLength();
115 return ESelection(nPara, nLastLen, nPara, nLastLen);
116 }
117}
118
120 std::u16string_view title, OUString const & value)
121{
122 if (!m_xEditEngine->GetText().isEmpty()) {
123 m_xEditEngine->QuickInsertText("\n\n", InsertAtEnd(*m_xEditEngine));
124 }
125
126 OUString caption(OUString::Concat(title) + ":\n");
127 m_xEditEngine->QuickInsertText(caption, InsertAtEnd(*m_xEditEngine));
128
129 SfxItemSet aSet(m_xEditEngine->GetEmptyItemSet());
133 int nCaptionPara = m_xEditEngine->GetParagraphCount() - 2;
134 m_xEditEngine->QuickSetAttribs(aSet, ESelection(nCaptionPara, 0, nCaptionPara, caption.getLength() - 1));
135
136 m_xEditEngine->QuickInsertText(value, InsertAtEnd(*m_xEditEngine));
137}
138
139void ODocumentInfoPreview::insertNonempty(tools::Long id, OUString const & value)
140{
141 if (!value.isEmpty()) {
143 }
144}
145
147 tools::Long id, css::util::DateTime const & value)
148{
149 DateTime aToolsDT(
150 Date(value.Day, value.Month, value.Year),
152 value.Hours, value.Minutes, value.Seconds, value.NanoSeconds));
153 if (aToolsDT.IsValidAndGregorian()) {
155 OUString buf = rLocaleWrapper.getDate(aToolsDT) +
156 ", " +
157 rLocaleWrapper.getTime(aToolsDT);
159 }
160}
161
162}
163
164/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const AllSettings & GetSettings()
bool IsValidAndGregorian() const
OUString GetText(LineEnd eEnd=LINEEND_LF) const
sal_Int32 GetParagraphCount() const
OUString getDate(const Date &rDate) const
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< EditEngine > m_xEditEngine
std::unique_ptr< EditView > m_xEditView
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void insertNonempty(tools::Long id, OUString const &value)
void insertDateTime(tools::Long id, css::util::DateTime const &value)
void fill(css::uno::Reference< css::document::XDocumentProperties > const &xDocProps)
virtual ~ODocumentInfoPreview() override
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void insertEntry(std::u16string_view title, OUString const &value)
Any value
#define TOOLS_INFO_EXCEPTION(area, stream)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CTL(EE_CHAR_START+22)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CJK(EE_CHAR_START+21)
WEIGHT_BOLD
const char * name
OUString GetString(int nId)
Definition: templwin.cxx:27
OUString convertCommaSeparated(uno::Sequence< OUString > const &i_rSeq)
Reference< XComponentContext > getProcessComponentContext()
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
const SwDocInfoSubType DI_TITLE
dictionary props
long Long