LibreOffice Module extensions (master) 1
formbrowsertools.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 "formbrowsertools.hxx"
21#include <com/sun/star/form/FormComponentType.hpp>
22#include <com/sun/star/lang/XServiceInfo.hpp>
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <osl/diagnose.h>
25#include <strings.hrc>
26#include "modulepcr.hxx"
27#include "formstrings.hxx"
28
29
30namespace pcr
31{
32
33
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::form;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::beans;
38
39
40 OUString GetUIHeadlineName(sal_Int16 nClassId, const Any& aUnoObj)
41 {
42 OUString sClassName;
43 switch (nClassId)
44 {
45 case FormComponentType::TEXTFIELD:
46 {
48 aUnoObj >>= xIFace;
49 sClassName = PcrRes(RID_STR_PROPTITLE_EDIT);
50 if (xIFace.is())
51 { // we have a chance to check if it's a formatted field model
52 Reference< XServiceInfo > xInfo(xIFace, UNO_QUERY);
53 if (xInfo.is() && (xInfo->supportsService(SERVICE_COMPONENT_FORMATTEDFIELD)))
54 sClassName = PcrRes(RID_STR_PROPTITLE_FORMATTED);
55 else if (!xInfo.is())
56 {
57 // couldn't distinguish between formatted and edit with the service name, so try with the properties
58 Reference< XPropertySet > xProps(xIFace, UNO_QUERY);
59 if (xProps.is())
60 {
61 Reference< XPropertySetInfo > xPropsInfo = xProps->getPropertySetInfo();
62 if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(PROPERTY_FORMATSSUPPLIER))
63 sClassName = PcrRes(RID_STR_PROPTITLE_FORMATTED);
64 }
65 }
66 }
67 }
68 break;
69
70 case FormComponentType::COMMANDBUTTON:
71 sClassName = PcrRes(RID_STR_PROPTITLE_PUSHBUTTON); break;
72 case FormComponentType::RADIOBUTTON:
73 sClassName = PcrRes(RID_STR_PROPTITLE_RADIOBUTTON); break;
74 case FormComponentType::CHECKBOX:
75 sClassName = PcrRes(RID_STR_PROPTITLE_CHECKBOX); break;
76 case FormComponentType::LISTBOX:
77 sClassName = PcrRes(RID_STR_PROPTITLE_LISTBOX); break;
78 case FormComponentType::COMBOBOX:
79 sClassName = PcrRes(RID_STR_PROPTITLE_COMBOBOX); break;
80 case FormComponentType::GROUPBOX:
81 sClassName = PcrRes(RID_STR_PROPTITLE_GROUPBOX); break;
82 case FormComponentType::IMAGEBUTTON:
83 sClassName = PcrRes(RID_STR_PROPTITLE_IMAGEBUTTON); break;
84 case FormComponentType::FIXEDTEXT:
85 sClassName = PcrRes(RID_STR_PROPTITLE_FIXEDTEXT); break;
86 case FormComponentType::GRIDCONTROL:
87 sClassName = PcrRes(RID_STR_PROPTITLE_DBGRID); break;
88 case FormComponentType::FILECONTROL:
89 sClassName = PcrRes(RID_STR_PROPTITLE_FILECONTROL); break;
90
91 case FormComponentType::DATEFIELD:
92 sClassName = PcrRes(RID_STR_PROPTITLE_DATEFIELD); break;
93 case FormComponentType::TIMEFIELD:
94 sClassName = PcrRes(RID_STR_PROPTITLE_TIMEFIELD); break;
95 case FormComponentType::NUMERICFIELD:
96 sClassName = PcrRes(RID_STR_PROPTITLE_NUMERICFIELD); break;
97 case FormComponentType::CURRENCYFIELD:
98 sClassName = PcrRes(RID_STR_PROPTITLE_CURRENCYFIELD); break;
99 case FormComponentType::PATTERNFIELD:
100 sClassName = PcrRes(RID_STR_PROPTITLE_PATTERNFIELD); break;
101 case FormComponentType::IMAGECONTROL:
102 sClassName = PcrRes(RID_STR_PROPTITLE_IMAGECONTROL); break;
103 case FormComponentType::HIDDENCONTROL:
104 sClassName = PcrRes(RID_STR_PROPTITLE_HIDDENCONTROL); break;
105
106 case FormComponentType::CONTROL:
107 default:
108 sClassName = PcrRes(RID_STR_PROPTITLE_UNKNOWNCONTROL); break;
109 }
110
111 return sClassName;
112 }
113
114
115 sal_Int16 classifyComponent( const Reference< XInterface >& _rxComponent )
116 {
117 Reference< XPropertySet > xComponentProps( _rxComponent, UNO_QUERY_THROW );
118 Reference< XPropertySetInfo > xPSI( xComponentProps->getPropertySetInfo(), UNO_SET_THROW );
119
120 sal_Int16 nControlType( FormComponentType::CONTROL );
121 if ( xPSI->hasPropertyByName( PROPERTY_CLASSID ) )
122 {
123 OSL_VERIFY( xComponentProps->getPropertyValue( PROPERTY_CLASSID ) >>= nControlType );
124 }
125 return nControlType;
126 }
127
128
129} // namespace pcr
130
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral SERVICE_COMPONENT_FORMATTEDFIELD
constexpr OUStringLiteral PROPERTY_CLASSID
Definition: formstrings.hxx:30
constexpr OUStringLiteral PROPERTY_FORMATSSUPPLIER
Definition: formstrings.hxx:65
a property handler for any virtual string properties
Definition: browserline.cxx:39
sal_Int16 classifyComponent(const Reference< XInterface > &_rxComponent)
OUString PcrRes(TranslateId aId)
Definition: modulepcr.cxx:26
OUString GetUIHeadlineName(sal_Int16 nClassId, const Any &aUnoObj)