1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 #include "formbrowsertools.hxx"
27 #include <com/sun/star/form/FormComponentType.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
31 #include "formresid.hrc"
32 #endif
33 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
34 #include "modulepcr.hxx"
35 #endif
36 #include <tools/string.hxx>
37 #include "formstrings.hxx"
38 
39 //............................................................................
40 namespace pcr
41 {
42 //............................................................................
43 
44 	using namespace ::com::sun::star::uno;
45 	using namespace ::com::sun::star::form;
46 	using namespace ::com::sun::star::lang;
47 	using namespace ::com::sun::star::beans;
48 
49     //------------------------------------------------------------------------
GetUIHeadlineName(sal_Int16 nClassId,const Any & aUnoObj)50 	::rtl::OUString GetUIHeadlineName(sal_Int16 nClassId, const Any& aUnoObj)
51 	{
52 		PcrClient aResourceAccess;
53 			// this ensures that we have our resource file loaded
54 
55 		::rtl::OUString sClassName;
56 		switch (nClassId)
57 		{
58 			case FormComponentType::TEXTFIELD:
59 			{
60 				Reference< XInterface >  xIFace;
61 				aUnoObj >>= xIFace;
62 				sClassName = String(PcrRes(RID_STR_PROPTITLE_EDIT));
63 				if (xIFace.is())
64 				{	// we have a chance to check if it's a formatted field model
65 					Reference< XServiceInfo >  xInfo(xIFace, UNO_QUERY);
66 					if (xInfo.is() && (xInfo->supportsService(SERVICE_COMPONENT_FORMATTEDFIELD)))
67 						sClassName = String(PcrRes(RID_STR_PROPTITLE_FORMATTED));
68 					else if (!xInfo.is())
69 					{
70 						// couldn't distinguish between formatted and edit with the service name, so try with the properties
71 						Reference< XPropertySet >  xProps(xIFace, UNO_QUERY);
72 						if (xProps.is())
73 						{
74 							Reference< XPropertySetInfo >  xPropsInfo = xProps->getPropertySetInfo();
75 							if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(PROPERTY_FORMATSSUPPLIER))
76 								sClassName = String(PcrRes(RID_STR_PROPTITLE_FORMATTED));
77 						}
78 					}
79 				}
80 			}
81 			break;
82 
83 			case FormComponentType::COMMANDBUTTON:
84 				sClassName = String(PcrRes(RID_STR_PROPTITLE_PUSHBUTTON)); break;
85 			case FormComponentType::RADIOBUTTON:
86 				sClassName = String(PcrRes(RID_STR_PROPTITLE_RADIOBUTTON)); break;
87 			case FormComponentType::CHECKBOX:
88 				sClassName = String(PcrRes(RID_STR_PROPTITLE_CHECKBOX)); break;
89 			case FormComponentType::LISTBOX:
90 				sClassName = String(PcrRes(RID_STR_PROPTITLE_LISTBOX)); break;
91 			case FormComponentType::COMBOBOX:
92 				sClassName = String(PcrRes(RID_STR_PROPTITLE_COMBOBOX)); break;
93 			case FormComponentType::GROUPBOX:
94 				sClassName = String(PcrRes(RID_STR_PROPTITLE_GROUPBOX)); break;
95 			case FormComponentType::IMAGEBUTTON:
96 				sClassName = String(PcrRes(RID_STR_PROPTITLE_IMAGEBUTTON)); break;
97 			case FormComponentType::FIXEDTEXT:
98 				sClassName = String(PcrRes(RID_STR_PROPTITLE_FIXEDTEXT)); break;
99 			case FormComponentType::GRIDCONTROL:
100 				sClassName = String(PcrRes(RID_STR_PROPTITLE_DBGRID)); break;
101 			case FormComponentType::FILECONTROL:
102 				sClassName = String(PcrRes(RID_STR_PROPTITLE_FILECONTROL)); break;
103 
104 			case FormComponentType::DATEFIELD:
105 				sClassName = String(PcrRes(RID_STR_PROPTITLE_DATEFIELD)); break;
106 			case FormComponentType::TIMEFIELD:
107 				sClassName = String(PcrRes(RID_STR_PROPTITLE_TIMEFIELD)); break;
108 			case FormComponentType::NUMERICFIELD:
109 				sClassName = String(PcrRes(RID_STR_PROPTITLE_NUMERICFIELD)); break;
110 			case FormComponentType::CURRENCYFIELD:
111 				sClassName = String(PcrRes(RID_STR_PROPTITLE_CURRENCYFIELD)); break;
112 			case FormComponentType::PATTERNFIELD:
113 				sClassName = String(PcrRes(RID_STR_PROPTITLE_PATTERNFIELD)); break;
114 			case FormComponentType::IMAGECONTROL:
115 				sClassName = String(PcrRes(RID_STR_PROPTITLE_IMAGECONTROL)); break;
116 			case FormComponentType::HIDDENCONTROL:
117 				sClassName = String(PcrRes(RID_STR_PROPTITLE_HIDDENCONTROL)); break;
118 
119 			case FormComponentType::CONTROL:
120 			default:
121 				sClassName = String(PcrRes(RID_STR_PROPTITLE_UNKNOWNCONTROL)); break;
122 		}
123 
124 		return sClassName;
125 	}
126 
127     //------------------------------------------------------------------------
classifyComponent(const Reference<XInterface> & _rxComponent)128     sal_Int16 classifyComponent( const Reference< XInterface >& _rxComponent )
129     {
130         Reference< XPropertySet > xComponentProps( _rxComponent, UNO_QUERY_THROW );
131         Reference< XPropertySetInfo > xPSI( xComponentProps->getPropertySetInfo(), UNO_SET_THROW );
132 
133         sal_Int16 nControlType( FormComponentType::CONTROL );
134         if ( xPSI->hasPropertyByName( PROPERTY_CLASSID ) )
135         {
136             OSL_VERIFY( xComponentProps->getPropertyValue( PROPERTY_CLASSID ) >>= nControlType );
137         }
138         return nControlType;
139     }
140 
141 //............................................................................
142 } // namespace pcr
143 //............................................................................
144 
145