1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "formbrowsertools.hxx"
31 #include <com/sun/star/form/FormComponentType.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
35 #include "formresid.hrc"
36 #endif
37 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
38 #include "modulepcr.hxx"
39 #endif
40 #include <tools/string.hxx>
41 #include "formstrings.hxx"
42 
43 //............................................................................
44 namespace pcr
45 {
46 //............................................................................
47 
48 	using namespace ::com::sun::star::uno;
49 	using namespace ::com::sun::star::form;
50 	using namespace ::com::sun::star::lang;
51 	using namespace ::com::sun::star::beans;
52 
53     //------------------------------------------------------------------------
54 	::rtl::OUString GetUIHeadlineName(sal_Int16 nClassId, const Any& aUnoObj)
55 	{
56 		PcrClient aResourceAccess;
57 			// this ensures that we have our resource file loaded
58 
59 		::rtl::OUString sClassName;
60 		switch (nClassId)
61 		{
62 			case FormComponentType::TEXTFIELD:
63 			{
64 				Reference< XInterface >  xIFace;
65 				aUnoObj >>= xIFace;
66 				sClassName = String(PcrRes(RID_STR_PROPTITLE_EDIT));
67 				if (xIFace.is())
68 				{	// we have a chance to check if it's a formatted field model
69 					Reference< XServiceInfo >  xInfo(xIFace, UNO_QUERY);
70 					if (xInfo.is() && (xInfo->supportsService(SERVICE_COMPONENT_FORMATTEDFIELD)))
71 						sClassName = String(PcrRes(RID_STR_PROPTITLE_FORMATTED));
72 					else if (!xInfo.is())
73 					{
74 						// couldn't distinguish between formatted and edit with the service name, so try with the properties
75 						Reference< XPropertySet >  xProps(xIFace, UNO_QUERY);
76 						if (xProps.is())
77 						{
78 							Reference< XPropertySetInfo >  xPropsInfo = xProps->getPropertySetInfo();
79 							if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(PROPERTY_FORMATSSUPPLIER))
80 								sClassName = String(PcrRes(RID_STR_PROPTITLE_FORMATTED));
81 						}
82 					}
83 				}
84 			}
85 			break;
86 
87 			case FormComponentType::COMMANDBUTTON:
88 				sClassName = String(PcrRes(RID_STR_PROPTITLE_PUSHBUTTON)); break;
89 			case FormComponentType::RADIOBUTTON:
90 				sClassName = String(PcrRes(RID_STR_PROPTITLE_RADIOBUTTON)); break;
91 			case FormComponentType::CHECKBOX:
92 				sClassName = String(PcrRes(RID_STR_PROPTITLE_CHECKBOX)); break;
93 			case FormComponentType::LISTBOX:
94 				sClassName = String(PcrRes(RID_STR_PROPTITLE_LISTBOX)); break;
95 			case FormComponentType::COMBOBOX:
96 				sClassName = String(PcrRes(RID_STR_PROPTITLE_COMBOBOX)); break;
97 			case FormComponentType::GROUPBOX:
98 				sClassName = String(PcrRes(RID_STR_PROPTITLE_GROUPBOX)); break;
99 			case FormComponentType::IMAGEBUTTON:
100 				sClassName = String(PcrRes(RID_STR_PROPTITLE_IMAGEBUTTON)); break;
101 			case FormComponentType::FIXEDTEXT:
102 				sClassName = String(PcrRes(RID_STR_PROPTITLE_FIXEDTEXT)); break;
103 			case FormComponentType::GRIDCONTROL:
104 				sClassName = String(PcrRes(RID_STR_PROPTITLE_DBGRID)); break;
105 			case FormComponentType::FILECONTROL:
106 				sClassName = String(PcrRes(RID_STR_PROPTITLE_FILECONTROL)); break;
107 
108 			case FormComponentType::DATEFIELD:
109 				sClassName = String(PcrRes(RID_STR_PROPTITLE_DATEFIELD)); break;
110 			case FormComponentType::TIMEFIELD:
111 				sClassName = String(PcrRes(RID_STR_PROPTITLE_TIMEFIELD)); break;
112 			case FormComponentType::NUMERICFIELD:
113 				sClassName = String(PcrRes(RID_STR_PROPTITLE_NUMERICFIELD)); break;
114 			case FormComponentType::CURRENCYFIELD:
115 				sClassName = String(PcrRes(RID_STR_PROPTITLE_CURRENCYFIELD)); break;
116 			case FormComponentType::PATTERNFIELD:
117 				sClassName = String(PcrRes(RID_STR_PROPTITLE_PATTERNFIELD)); break;
118 			case FormComponentType::IMAGECONTROL:
119 				sClassName = String(PcrRes(RID_STR_PROPTITLE_IMAGECONTROL)); break;
120 			case FormComponentType::HIDDENCONTROL:
121 				sClassName = String(PcrRes(RID_STR_PROPTITLE_HIDDENCONTROL)); break;
122 
123 			case FormComponentType::CONTROL:
124 			default:
125 				sClassName = String(PcrRes(RID_STR_PROPTITLE_UNKNOWNCONTROL)); break;
126 		}
127 
128 		return sClassName;
129 	}
130 
131     //------------------------------------------------------------------------
132     sal_Int16 classifyComponent( const Reference< XInterface >& _rxComponent )
133     {
134         Reference< XPropertySet > xComponentProps( _rxComponent, UNO_QUERY_THROW );
135         Reference< XPropertySetInfo > xPSI( xComponentProps->getPropertySetInfo(), UNO_SET_THROW );
136 
137         sal_Int16 nControlType( FormComponentType::CONTROL );
138         if ( xPSI->hasPropertyByName( PROPERTY_CLASSID ) )
139         {
140             OSL_VERIFY( xComponentProps->getPropertyValue( PROPERTY_CLASSID ) >>= nControlType );
141         }
142         return nControlType;
143     }
144 
145 //............................................................................
146 } // namespace pcr
147 //............................................................................
148 
149