update dev300-m58
[ooovba.git] / applied_patches / 0506-svx-hacky-htmlselect-control-import.diff
blob2e1322d356c4e566d976ce49f7a4aa1168103fcc
1 diff --git svx/inc/svx/msocximex.hxx svx/inc/svx/msocximex.hxx
2 index c56be5f..ef28415 100644
3 --- svx/inc/svx/msocximex.hxx
4 +++ svx/inc/svx/msocximex.hxx
5 @@ -1384,6 +1384,41 @@ public:
6 const com::sun::star::awt::Size& rSize );
7 };
9 +class HTML_Select : public OCX_ModernControl
11 +public:
12 + HTML_Select() : OCX_ModernControl(rtl::OUString::createFromAscii("TextBox")) {
13 + msFormType = rtl::OUString::createFromAscii("com.sun.star.form.component.ListBox");
14 + msDialogType = rtl::OUString::createFromAscii("com.sun.star.form.component.ListBox");
15 + mnBackColor = 0x80000005L;
16 + mnForeColor = 0x80000008L;
17 + nBorderColor = 0x80000006L;
18 + aFontData.SetHasAlign(TRUE);
19 + fEnabled = true;
20 + nMultiState =false;
21 + }
23 + using OCX_ModernControl::Import; // to not hide the other two import methods
24 + virtual sal_Bool Import(com::sun::star::uno::Reference<
25 + com::sun::star::beans::XPropertySet> &rPropSet);
26 + /*
27 + sal_Bool Export(SotStorageRef &rObj,
28 + const com::sun::star::uno::Reference<
29 + com::sun::star::beans::XPropertySet> &rPropSet,
30 + const com::sun::star::awt::Size& rSize);
31 + sal_Bool WriteContents(SotStorageStreamRef &rObj,
32 + const com::sun::star::uno::Reference<
33 + com::sun::star::beans::XPropertySet> &rPropSet,
34 + const com::sun::star::awt::Size& rSize);
35 + */
36 + static OCX_Control *Create() { return new HTML_Select;}
38 + virtual sal_Bool Read(SotStorageStream *pS);
39 + virtual sal_Bool ReadFontData(SotStorageStream *pS);
40 + com::sun::star::uno::Sequence< rtl::OUString > msListData;
41 + com::sun::star::uno::Sequence< sal_Int16 > msIndices;
42 +};
45 class HTML_TextBox : public OCX_ModernControl
47 diff --git svx/source/msfilter/msocximex.cxx svx/source/msfilter/msocximex.cxx
48 index ca53640..e00e942 100644
49 --- svx/source/msfilter/msocximex.cxx
50 +++ svx/source/msfilter/msocximex.cxx
51 @@ -98,7 +98,7 @@
52 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
53 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
54 #include <svtools/filterutils.hxx>
57 #ifndef C2S
58 #define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
59 #endif
60 @@ -4642,7 +4642,8 @@ OCX_map aOCXTab[] =
61 form::FormComponentType::GROUPBOX,""},
62 {&OCX_ProgressBar::Create,"", form::FormComponentType::CONTROL,""},
63 {&HTML_TextBox::Create,"5512D11A-5CC6-11CF-8d67-00aa00bdce1d", form::FormComponentType::TEXTFIELD,"TextBox"},
64 - {&HTML_TextBox::Create,"5512D124-5CC6-11CF-8d67-00aa00bdce1d", form::FormComponentType::TEXTFIELD,"TextBox"}
65 + {&HTML_Select::Create,"5512D122-5CC6-11CF-8d67-00aa00bdce1d",
66 + form::FormComponentType::LISTBOX,"ListBox"},
69 const int NO_OCX = sizeof( aOCXTab ) / sizeof( *aOCXTab );
70 @@ -6250,5 +6251,140 @@ sal_Bool HTML_TextBox::ReadFontData(SotStorageStream *pS)
71 return sal_True;
74 +// HTML_Select
75 +sal_Bool HTML_Select::Import(com::sun::star::uno::Reference<
76 + com::sun::star::beans::XPropertySet> &rPropSet)
78 + uno::Any aTmp(&sName,getCppuType((OUString *)0));
79 + rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
81 + sal_Bool bTmp=fEnabled;
82 + aTmp = bool2any(bTmp);
83 + rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
85 + bTmp=fLocked;
86 + aTmp = bool2any(bTmp);
87 + rPropSet->setPropertyValue( WW8_ASCII2STR("ReadOnly"), aTmp);
89 + aTmp <<= ImportColor(mnForeColor);
90 + rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
92 + sal_Bool bTemp = nMultiState;
93 + aTmp = bool2any(bTemp);
94 + rPropSet->setPropertyValue( WW8_ASCII2STR("MultiSelection"), aTmp);
96 + aTmp <<= ImportColor(mnBackColor);
97 + rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
99 + aTmp <<= ImportBorder(nSpecialEffect,nBorderStyle);
100 + rPropSet->setPropertyValue( WW8_ASCII2STR("Border"), aTmp);
102 + aTmp <<= ImportColor( nBorderColor );
103 + rPropSet->setPropertyValue( WW8_ASCII2STR("BorderColor"), aTmp);
105 + if ( msListData.getLength() )
107 + aTmp <<= msListData;
108 + rPropSet->setPropertyValue( WW8_ASCII2STR("StringItemList"), aTmp);
109 + if ( msIndices.getLength() )
111 + aTmp <<= msIndices;
112 + rPropSet->setPropertyValue( WW8_ASCII2STR("SelectedItems"), aTmp);
115 + rPropSet->setPropertyValue( WW8_ASCII2STR("Dropdown"), uno::makeAny( sal_True ));
117 + return sal_True;
120 +sal_Bool HTML_Select::Read(SotStorageStream *pS)
122 + static rtl::OUString sTerm( RTL_CONSTASCII_USTRINGPARAM("</SELECT") );
123 + static String sMultiple( RTL_CONSTASCII_USTRINGPARAM("<SELECT MULTIPLE") );
124 + static String sSelected( RTL_CONSTASCII_USTRINGPARAM("OPTION SELECTED") );
126 + // we should be positioned at the html fragment ( really we should
127 + // reorganise the reading of controls from excel such that the position and
128 + // lenght of the associated record in the Ctls stream is available
129 + // But since we don't know about the lenght of the stream lets read the stream
130 + // until we reach the end of the fragment
131 + // I wish I know where there was a html parser in openoffice
132 + OUStringBuffer buf(40);
133 + bool bTerminate = false;
134 + do
136 + sal_uInt16 ch = 0;
137 + *pS >> ch;
138 + sal_Unicode uni = static_cast< sal_Unicode >( ch );
139 + // if the buffer ends with </SELECT> we are done
140 + if ( uni == '>' )
142 + rtl::OUString bufContents( buf.getStr() );
143 + if ( bufContents.indexOf( sTerm ) != -1 )
144 + bTerminate = true;
147 + buf.append( &uni, 1 );
149 + } while ( !pS->IsEof() && !bTerminate );
150 + String data = buf.makeStringAndClear();
152 + // replace crlf with lf
153 + data.SearchAndReplaceAll( String( RTL_CONSTASCII_USTRINGPARAM( "\x0D\x0A" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "\x0A" ) ) );
154 + std::vector< rtl::OUString > listValues;
155 + std::vector< sal_Int16 > selectedIndices;
157 + // Ultra hacky parser for the info
158 + sal_Int32 nTokenCount = data.GetTokenCount( '\n' );
160 + for ( sal_Int32 nToken = 0; nToken < nTokenCount; ++nToken )
162 + String sLine( data.GetToken( nToken, '\n' ) );
163 + if ( !nToken ) // first line will tell us if multiselect is enabled
165 + if ( sLine.CompareTo( sMultiple, sMultiple.Len() ) == COMPARE_EQUAL )
166 + nMultiState = true;
168 + // skip first and last lines, no data there
169 + else if ( nToken < nTokenCount - 1)
171 + if ( sLine.GetTokenCount( '>' ) )
173 + String displayValue = sLine.GetToken( 1, '>' );
174 + if ( displayValue.Len() )
175 + {
176 + // Really we should be using a proper html parser
177 + // escaping some common bits to be escaped
178 + displayValue.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "&lt;" ) ), String( RTL_CONSTASCII_USTRINGPARAM("<") ) );
179 + displayValue.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "&gt;" ) ), String( RTL_CONSTASCII_USTRINGPARAM(">") ) );
180 + displayValue.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "&quot;" ) ), String( RTL_CONSTASCII_USTRINGPARAM("\"") ) );
181 + displayValue.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "&amp;" ) ), String( RTL_CONSTASCII_USTRINGPARAM("&") ) );
182 + listValues.push_back( displayValue );
183 + if( sLine.Search( sSelected ) != STRING_NOTFOUND )
184 + selectedIndices.push_back( static_cast< sal_Int16 >( listValues.size() ) - 1 );
185 + }
189 + if ( listValues.size() )
191 + msListData.realloc( listValues.size() );
192 + sal_Int32 index = 0;
193 + for( std::vector< rtl::OUString >::iterator it = listValues.begin(); it != listValues.end(); ++it, ++index )
194 + msListData[ index ] = *it;
195 + }
196 + if ( selectedIndices.size() )
198 + msIndices.realloc( selectedIndices.size() );
199 + sal_Int32 index = 0;
200 + for( std::vector< sal_Int16 >::iterator it = selectedIndices.begin(); it != selectedIndices.end(); ++it, ++index )
201 + msIndices[ index ] = *it;
202 + }
203 + return sal_True;
206 +sal_Bool HTML_Select::ReadFontData(SotStorageStream *pS)
208 + return sal_True;
210 /* vi:set tabstop=4 shiftwidth=4 expandtab: */