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_filter.hxx"
26 
27 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
28 #include <com/sun/star/uno/Any.h>
29 #include <com/sun/star/text/VertOrientation.hpp>
30 #include <com/sun/star/text/XText.hpp>
31 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HDL_
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #endif
34 #include <com/sun/star/text/TextContentAnchorType.hpp>
35 #include <com/sun/star/drawing/XShape.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/drawing/XDrawPage.hpp>
38 #include <com/sun/star/drawing/XShapes.hpp>
39 #include <com/sun/star/drawing/XControlShape.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/container/XIndexContainer.hpp>
42 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
43 #include <com/sun/star/form/XFormsSupplier.hpp>
44 #include <com/sun/star/form/XForm.hpp>
45 #include <com/sun/star/form/FormComponentType.hpp>
46 #include <com/sun/star/awt/FontWeight.hpp>
47 #include <com/sun/star/awt/FontSlant.hpp>
48 #include <com/sun/star/awt/FontUnderline.hpp>
49 #include <com/sun/star/awt/FontStrikeout.hpp>
50 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
51 #include <com/sun/star/style/VerticalAlignment.hpp>
52 #include <comphelper/extract.hxx>
53 #include <com/sun/star/awt/XControlModel.hpp>
54 #include <com/sun/star/io/XInputStreamProvider.hpp>
55 #include <rtl/ustrbuf.hxx>
56 #include <vcl/svapp.hxx>
57 #include <sfx2/objsh.hxx>
58 #include <xmlscript/xmldlg_imexp.hxx>
59 #include <filter/msfilter/msocximex.hxx>
60 #include <osl/file.hxx>
61 #include <unotools/ucbstreamhelper.hxx>
62 #include <com/sun/star/embed/XStorage.hpp>
63 #include <com/sun/star/embed/XTransactedObject.hpp>
64 #include <com/sun/star/embed/ElementModes.hpp>
65 #include <comphelper/processfactory.hxx> // shouldn't be needed
66 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
67 #include <algorithm>
68 #include <memory>
69 
70 #ifndef C2S
71 #define C2S(cChar)	String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
72 #endif
73 #ifndef C2U
74 #define C2U(cChar)	rtl::OUString::createFromAscii(cChar)
75 #endif
76 
77 using namespace ::com::sun::star;
78 using namespace ::rtl;
79 using namespace cppu;
80 
81 
82 #define WW8_ASCII2STR(s) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(s))
83 
84 
85 static char sWW8_form[] = "WW-Standard";
86 
87 
88 struct SortOrderByTabPos
89 {
operator ()SortOrderByTabPos90     bool operator()( const OCX_Control* a, const OCX_Control* b )
91     {
92         return a->mnTabPos < b->mnTabPos;
93     }
94 };
95 
96 
97 sal_uInt8 __READONLY_DATA OCX_Control::aObjInfo[4] = { 0x00, 0x12, 0x03, 0x00 };
98 
ReadAlign(SvStorageStream * pS,long nPos,int nAmount)99 long ReadAlign(SvStorageStream *pS, long nPos, int nAmount)
100 {
101 	if (long nAlign = nPos % nAmount)
102 	{
103 
104         long nLen = nAmount - nAlign;
105     	pS->SeekRel(nLen);
106         return nLen;
107 	}
108     return 0;
109 }
110 
111 
112 // NP - Images in controls in OO2.0/SO8 exist as links, e.g. they are not part of the document so are
113 // referenced externally. On import from ms document try to save images for controls here.
114 // Images are stored in directory called temp in the user installation directory. Next version of OO/SO
115 // hopefully will address this issue and allow a choice e.g. images for controls to be stored as links
116 // or embedded in the document.
117 
118 // [out]location     path to the stream to where the image is to be stored,
119 //               if same name exists in folder then this function calcuates a new name
120 // [in] data     raw bytes of image to be stored.
121 // [in] dataLen  no. byte to be stored
122 //
123 // returns, true if successful
124 
storePictureInFileSystem(OUString & location,sal_uInt8 * data,sal_uInt32 dataLen)125 bool storePictureInFileSystem( OUString& location, sal_uInt8* data, sal_uInt32 dataLen )
126 {
127     bool result = true;
128     OUString origPath = location;
129     try
130     {
131         uno::Reference<lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory(),
132                                                       uno::UNO_QUERY_THROW );
133         uno::Reference< com::sun::star::ucb::XSimpleFileAccess> xSFA( xMSF->createInstance(
134                                                        OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess") ),
135                                                        uno::UNO_QUERY_THROW );
136         OUString ext;
137         sal_Int32 index = 0;
138         while (  xSFA->exists( location ) )
139         {
140             ext = OUString::valueOf( ++index );
141             location = origPath + ext;
142         }
143 
144         SvStream*  pStream = ::utl::UcbStreamHelper::CreateStream( location, STREAM_WRITE | STREAM_TRUNC );
145         if ( pStream )
146         {
147             pStream->Write(data, dataLen);
148             delete pStream;
149         }
150         else
151         {
152             result = false;
153         }
154     }
155     catch( uno::Exception& )
156     {
157         result = false;
158     }
159     return result;
160 }
161 
162 // NP - Images in controls in OO2.0/SO8 exist as links, e.g. they are not part of the document so are
163 // referenced externally. On import from ms document try to save images from controls here so this
164 // at least a macro programmer has a chance to accessed them manually later. Next version of OO/SO
165 // hopefully will address this issue.
166 // Images will be stored in a top level folder in the document package, folder is named "MigratedImages"
167 
168 // [in] pDocSh*  the document shell.
169 // [in] name     name of stream image to stored in.
170 // [in] data     raw bytes of image to be stored.
171 // [in] dataLen  no. byte to be stored
172 
storePictureInDoc(SfxObjectShell * pDocSh,OUString & name,sal_uInt8 * data,sal_uInt32 dataLen)173 bool storePictureInDoc( SfxObjectShell* pDocSh, OUString& name, sal_uInt8* data, sal_uInt32 dataLen )
174 {
175     uno::Reference < embed::XStorage > xStor;
176     if (pDocSh)
177     {
178         xStor = pDocSh->GetStorage();
179         if( xStor.is() )
180         {
181             try
182             {
183                 uno::Reference< embed::XStorage > xPictures = xStor->openStorageElement(
184                     OUString( RTL_CONSTASCII_USTRINGPARAM( "MigratedImages" ) ),
185                     embed::ElementModes::READWRITE );
186                 uno::Reference< beans::XPropertySet > xPropSet( xPictures, uno::UNO_QUERY );
187 
188                 // Set media type of folder MigratedImages to something ( that is unknown ) so that
189                 // it will get copied to exported OO/SO format after SaveAs
190                 if ( xPropSet.is() )
191                 {
192                     OUString aMediaType = C2U("MigrationImages");
193                     uno::Any a;
194                     a <<= aMediaType;
195                     xPropSet->setPropertyValue( C2U("MediaType"), a );
196                 }
197 
198                 uno::Reference< io::XStream > xObjReplStr = xPictures->openStreamElement(
199                         name,
200                         embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
201                 uno::Reference< io::XOutputStream > xOutStream( xObjReplStr->getOutputStream(), uno::UNO_QUERY_THROW );
202                 uno::Sequence< sal_Int8 > imageBytes( (sal_Int8*)data, dataLen );
203                 xOutStream->writeBytes( imageBytes );
204                 xOutStream->closeOutput();
205 
206                 uno::Reference< embed::XTransactedObject > xTransact( xPictures, uno::UNO_QUERY );
207                 if ( xTransact.is() )
208                 {
209                     xTransact->commit();
210                 }
211             }
212             catch( uno::Exception& )
213             {
214                 return false;
215             }
216 
217         }
218         else
219         {
220             // no storage something wrong
221             return false;
222         }
223     }
224     else
225     {
226         //No doc shell
227         return false;
228     }
229     return true;
230 }
231 
WriteAlign(SvStorageStream * pS,int nAmount)232 long WriteAlign(SvStorageStream *pS, int nAmount)
233 {
234 	if (long nAlign = pS->Tell() % nAmount)
235 	{
236         long nLen = nAmount - nAlign;
237 		for (long i=0; i< nLen; ++i)
238 			*pS << sal_uInt8(0x00);
239         return nLen;
240 	}
241     return 0;
242 }
243 // string import/export =======================================================
244 /** #117832#  import of form control names
245 * control name is located in stream ("\3OCXNAME")
246 * a strings in "\3OCXNAME" stream seem to be terminated by 4 trailing bytes of 0's.
247 *                              ====
248 * Note: If the string in the stream is overwritten by a shorter string
249 * some characters from the original string may remain, the new string however
250 * will still be terminated in the same way e.g. by 4 bytes with value 0.
251 */
252 
writeOCXNAME(const OUString & sOCXName,SvStorageStream * pStream)253 bool writeOCXNAME( const OUString& sOCXName, SvStorageStream* pStream )
254 {
255     const sal_Unicode* buffer = sOCXName.getStr();
256     for ( sal_Int32 index=0; index < sOCXName.getLength(); index++ )
257     {
258         sal_uInt16 ch = static_cast< sal_uInt16 >( buffer[ index ] );
259         *pStream << ch;
260     }
261     // write
262     *pStream << sal_uInt32(0);
263     return ( SVSTREAM_OK == pStream->GetError() );
264 
265 }
266 
readOCXNAME(OUString & sCName,SvStorageStream * pStream)267 bool readOCXNAME( OUString& sCName, SvStorageStream* pStream )
268 {
269     /*
270     * Read uniCode until no data or 0 encountered
271     */
272     OUStringBuffer buf(40);
273     do
274     {
275         sal_uInt16 ch = 0;
276         *pStream >> ch;
277         sal_Unicode uni = static_cast< sal_Unicode >( ch );
278         if ( uni == 0 )
279         {
280             break;
281         }
282         buf.append( &uni, 1 );
283 
284     } while ( !pStream->IsEof() );
285 
286     sCName = buf.makeStringAndClear();
287     return ( SVSTREAM_OK == pStream->GetError() );
288 }
289 
290 
291 /*  #110435# (DR, 2003-11-12) ** Import of Unicode strings in form controls **
292 
293     Strings may be stored either as compressed or uncompressed Unicode
294     character array. There are no encoded byte strings anywhere.
295 
296     The string length field stores the length of the character array (not the
297     character count of the string) in the lower 31 bits, and the compression
298     state in the highest bit.
299 
300     A set bit means the character array is compressed. This means all Unicode
301     characters are <=0xFF. Therefore the high bytes of all characters are left
302     out, and the character array size is equal to the string length.
303 
304     A cleared bit means the character array is not compressed. The buffer
305     contains Little-Endian Unicode characters, and the resulting string length
306     is half the buffer size.
307 
308     TODO: This implementation of the new string import is a hack to keep
309     msocximex.hxx unchanged. A better implementation would replace the char*
310     members of all classes by something more reasonable.
311  */
312 
313 namespace {
314 
315 const sal_uInt32 SVX_MSOCX_SIZEMASK     = 0x7FFFFFFF;   /// Mask for character buffer size.
316 const sal_uInt32 SVX_MSOCX_COMPRESSED   = 0x80000000;   /// 1 = compressed Unicode array.
317 
318 
319 /** Returns true, if the passed length field specifies a compressed character array.
320  */
lclIsCompressed(sal_uInt32 nLenFld)321 inline bool lclIsCompressed( sal_uInt32 nLenFld )
322 {
323     return (nLenFld & SVX_MSOCX_COMPRESSED) != 0;
324 }
325 
326 
327 /** Extracts and returns the memory size of the character buffer.
328     @return  Character buffer size (may differ from resulting string length!).
329  */
lclGetBufferSize(sal_uInt32 nLenFld)330 inline sal_uInt32 lclGetBufferSize( sal_uInt32 nLenFld )
331 {
332     return nLenFld & SVX_MSOCX_SIZEMASK;
333 }
334 
335 
336 // import ---------------------------------------------------------------------
337 
338 /** Reads the character array of a string in a form control.
339 
340     Creates a new character array containing the character data.
341     The length field must be read before and passed to this function.
342     Aligns stream position to multiple of 4 before.
343 
344     @param rStrm
345         The input stream.
346 
347     @param rpcCharArr
348         (out-param) Will point to the created character array,
349         or will be 0 if string is empty. The array is NOT null-terminated.
350         If the passed pointer points to an old existing array, it will be
351         deleted before. Caller must delete the returned array.
352 
353     @param nLenFld
354         The corresponding string length field read somewhere before.
355  */
lclReadCharArray(SvStorageStream & rStrm,char * & rpcCharArr,sal_uInt32 nLenFld,long nPos)356 void lclReadCharArray( SvStorageStream& rStrm, char*& rpcCharArr, sal_uInt32 nLenFld, long nPos )
357 {
358     delete[] rpcCharArr;
359     rpcCharArr = 0;
360     sal_uInt32 nBufSize = lclGetBufferSize( nLenFld );
361     DBG_ASSERT( nBufSize <= 0xFFFF, "lclReadCharArray - possible read error: char array is too big" );
362     if( nBufSize && nBufSize <= 0xFFFF )
363     {
364         rpcCharArr = new char[ nBufSize ];
365         if( rpcCharArr )
366         {
367             ReadAlign( &rStrm, nPos, 4 );
368             rStrm.Read( rpcCharArr, nBufSize );
369         }
370     }
371 }
372 
373 
374 /** Creates an OUString from a character array created with lclReadCharArray().
375 
376     The passed parameters must match, that means the length field must be the
377     same used to create the passed character array.
378 
379     @param pcCharArr
380         The character array returned by lclReadCharArray(). May be compressed
381         or uncompressed, next parameter nLenFld will specify this.
382 
383     @param nLenFld
384         MUST be the same string length field that has been passed to
385         lclReadCharArray() to create the character array in previous parameter
386         pcCharArr.
387 
388     @return
389         An OUString containing the decoded string data. Will be empty if
390         pcCharArr is 0.
391  */
lclCreateOUString(const char * pcCharArr,sal_uInt32 nLenFld)392 OUString lclCreateOUString( const char* pcCharArr, sal_uInt32 nLenFld )
393 {
394     OUStringBuffer aBuffer;
395     sal_uInt32 nBufSize = lclGetBufferSize( nLenFld );
396     if( lclIsCompressed( nLenFld ) )
397     {
398         // buffer contains compressed Unicode, not encoded bytestring
399         sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize );
400         aBuffer.setLength( nStrLen );
401         const char* pcCurrChar = pcCharArr;
402         for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar, ++pcCurrChar )
403             /*  *pcCurrChar may contain negative values and therefore MUST be
404                 casted to unsigned char, before assigned to a sal_Unicode. */
405             aBuffer.setCharAt( nChar, static_cast< unsigned char >( *pcCurrChar ) );
406     }
407     else
408     {
409         // buffer contains Little-Endian Unicode
410         sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize ) / 2;
411         aBuffer.setLength( nStrLen );
412         const char* pcCurrChar = pcCharArr;
413         for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar )
414         {
415             /*  *pcCurrChar may contain negative values and therefore MUST be
416                 casted to unsigned char, before assigned to a sal_Unicode. */
417             sal_Unicode cChar = static_cast< unsigned char >( *pcCurrChar++ );
418             cChar |= (static_cast< unsigned char >( *pcCurrChar++ ) << 8);
419             aBuffer.setCharAt( nChar, cChar );
420         }
421     }
422     return aBuffer.makeStringAndClear();
423 }
424 
425 // export ---------------------------------------------------------------------
426 
427 /** This class implements writing a character array from a Unicode string.
428 
429     Usage:
430     1)  Construct an instance, either directly with an OUString, or with an UNO
431         Any containing an OUString.
432     2)  Check with HasData(), if there is something to write.
433     3)  Write the string length field with WriteLenField() at the right place.
434     4)  Write the encoded character array with WriteCharArray().
435  */
436 class SvxOcxString
437 {
438 public:
439     /** Constructs an empty string. String data may be set later by assignment. */
SvxOcxString()440     inline explicit             SvxOcxString() : mnLenFld( 0 ) {}
441     /** Constructs the string from the passed OUString. */
SvxOcxString(const OUString & rStr)442     inline explicit             SvxOcxString( const OUString& rStr ) { Init( rStr ); }
443     /** Constructs the string from the passed UNO Any. */
SvxOcxString(const uno::Any & rAny)444     inline explicit             SvxOcxString( const uno::Any& rAny ) { Init( rAny ); }
445 
446     /** Assigns the passed string to the object. */
operator =(const OUString & rStr)447     inline SvxOcxString&        operator=( const OUString& rStr ) { Init( rStr ); return *this; }
448     /** Assigns the string in the passed UNO Any to the object. */
operator =(const uno::Any & rAny)449     inline SvxOcxString&        operator=( const uno::Any& rAny ) { Init( rAny ); return *this; }
450 
451     /** Returns true, if the string contains at least one character to write. */
HasData() const452     inline bool                 HasData() const { return maString.getLength() > 0; }
453 
454     /** Writes the encoded 32-bit string length field. Aligns stream position to mult. of 4 before. */
455     void                        WriteLenField( SvStorageStream& rStrm ) const;
456     /** Writes the encoded character array. Aligns stream position to mult. of 4 before. */
457     void                        WriteCharArray( SvStorageStream& rStrm ) const;
458 
459 private:
Init(const OUString & rStr)460     inline void                 Init( const OUString& rStr ) { maString = rStr; Init(); }
461     void                        Init( const uno::Any& rAny );
462     void                        Init();
463 
464     OUString                    maString;       /// The initial string data.
465     sal_uInt32                  mnLenFld;       /// The encoded string length field.
466 };
467 
Init(const uno::Any & rAny)468 void SvxOcxString::Init( const uno::Any& rAny )
469 {
470     if( !(rAny >>= maString) )
471         maString = OUString();
472     Init();
473 }
474 
Init()475 void SvxOcxString::Init()
476 {
477     mnLenFld = static_cast< sal_uInt32 >( maString.getLength() );
478     bool bCompr = true;
479     // try to find a character >= 0x100 -> character array will be stored uncompressed then
480     if( const sal_Unicode* pChar = maString.getStr() )
481         for( const sal_Unicode* pEnd = pChar + maString.getLength(); bCompr && (pChar < pEnd); ++pChar )
482             bCompr = (*pChar < 0x100);
483     if( bCompr )
484         mnLenFld |= SVX_MSOCX_COMPRESSED;
485     else
486         mnLenFld *= 2;
487 }
488 
WriteLenField(SvStorageStream & rStrm) const489 void SvxOcxString::WriteLenField( SvStorageStream& rStrm ) const
490 {
491     if( HasData() )
492     {
493         WriteAlign( &rStrm, 4);
494         rStrm << mnLenFld;
495     }
496 }
497 
WriteCharArray(SvStorageStream & rStrm) const498 void SvxOcxString::WriteCharArray( SvStorageStream& rStrm ) const
499 {
500     if( HasData() )
501     {
502         const sal_Unicode* pChar = maString.getStr();
503         const sal_Unicode* pEnd = pChar + maString.getLength();
504         bool bCompr = lclIsCompressed( mnLenFld );
505 
506         WriteAlign( &rStrm, 4);
507         for( ; pChar < pEnd; ++pChar )
508         {
509             // write compressed Unicode (not encoded bytestring), or Little-Endian Unicode
510             rStrm << static_cast< sal_uInt8 >( *pChar );
511             if( !bCompr )
512                 rStrm << static_cast< sal_uInt8 >( *pChar >> 8 );
513         }
514     }
515 }
516 
517 const sal_uInt16 USERFORM = (sal_uInt16)0xFF;
518 const sal_uInt16 STDCONTAINER = (sal_uInt16)0xFE;
519 
520 const sal_uInt16 PAGE = (sal_uInt16)0x07;
521 
522 const sal_uInt16 IMAGE = (sal_uInt16)0x0C;
523 const sal_uInt16 FRAME = (sal_uInt16)0x0E;
524 
525 const sal_uInt16 SPINBUTTON = (sal_uInt16)0x10;
526 const sal_uInt16 CMDBUTTON = (sal_uInt16)0x11;
527 const sal_uInt16 TABSTRIP = (sal_uInt16)0x12;
528 
529 const sal_uInt16 LABEL = (sal_uInt16)0x15;
530 
531 const sal_uInt16 TEXTBOX = (sal_uInt16)0x17;
532 const sal_uInt16 LISTBOX = (sal_uInt16)0x18;
533 const sal_uInt16 COMBOBOX = (sal_uInt16)0x19;
534 const sal_uInt16 CHECKBOX = (sal_uInt16)0x1A;
535 
536 const sal_uInt16 OPTIONBUTTON = (sal_uInt16)0x1B;
537 const sal_uInt16 TOGGLEBUTTON = (sal_uInt16)0x1C;
538 
539 const sal_uInt16 SCROLLBAR = (sal_uInt16)0x2F;
540 
541 const sal_uInt16 MULTIPAGE = (sal_uInt16)0x39;
542 const sal_uInt16 PROGRESSBAR = (sal_uInt16)0x8000;
543 
544 typedef std::vector< ContainerRecord > ContainerRecordList;
545 
546 class ContainerRecReader
547 {
548     public:
549 
~ContainerRecReader()550     virtual ~ContainerRecReader() {}
551 
Read(OCX_ContainerControl * pContainerControl,SvStorageStream * pS)552     virtual bool Read( OCX_ContainerControl* pContainerControl, SvStorageStream *pS)
553     {
554         *pS >> nNoRecords;
555         *pS >> nTotalLen;
556 
557         if ( isMultiPage )
558         {
559             if ( !handleMultiPageHdr( pS ) )
560             {
561                 return false;
562             }
563         }
564         else
565         {
566             if ( !handleStandardHdr( pS ) )
567             {
568                 return false;
569             }
570         }
571 
572         records.clear();
573         for (sal_uInt32 nRecord = 0; nRecord < nNoRecords; ++nRecord)
574         {
575             // DR #134146# redo loading of FrameChild data
576 
577             ContainerRecord rec;
578 
579             // record header
580             sal_uInt16 nId, nSize;
581             *pS >> nId >> nSize;
582             sal_Size nStartPos = pS->Tell();
583 
584             // content flags
585             sal_uInt32 nContentFlags;
586             *pS >> nContentFlags;
587 
588             // length of control name
589             sal_uInt32 nNameLen = 0;
590             if( nContentFlags & 0x00000001 )
591                 *pS >> nNameLen;
592             // length of control tag
593             sal_uInt32 nTagLen = 0;
594             if( nContentFlags & 0x00000002 )
595                 *pS >> nTagLen;
596             // substorage id for frames
597             if( nContentFlags & 0x00000004 )
598                 *pS >> rec.nSubStorageId;
599             // help-context id
600             if( nContentFlags & 0x00000008 )
601                 pS->SeekRel( 4 );
602             // option flags
603             if( nContentFlags & 0x00000010 )
604             {
605                 sal_uInt32 nBitFlags = 0;
606                 *pS >> nBitFlags;
607                 rec.bVisible = ( ( nBitFlags & 0x02 ) == 0x02 );
608             }
609             // substream size
610             if( nContentFlags & 0x00000020 )
611                 *pS >> rec.nSubStreamLen;
612             // tabstop position
613             if( nContentFlags & 0x00000040 )
614                 *pS >> rec.nTabPos;
615             // control type
616             if( nContentFlags & 0x00000080 )
617                 *pS >> rec.nTypeIdent;
618             // length of infotip
619             sal_uInt32 nTipLen = 0;
620             if( nContentFlags & 0x00000800 )
621             {
622                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
623                 *pS >> nTipLen;
624             }
625 
626             sal_uInt32 nCntrlIdLen = 0;
627             if( nContentFlags & 0x00001000 )
628                 *pS >> nCntrlIdLen;
629 
630             // length of control source name
631             sal_uInt32 nCtrlSrcLen = 0;
632             if( nContentFlags & 0x00002000 )
633             {
634                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
635                 *pS >> nCtrlSrcLen;
636             }
637 
638             // length of row source name
639             sal_uInt32 nRowSrcLen = 0;
640             if( nContentFlags & 0x00004000 )
641             {
642                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
643                 *pS >> nRowSrcLen;
644             }
645 
646             // control name
647             sal_Char* pName = 0;
648             sal_uInt32 nNameBufSize = lclGetBufferSize( nNameLen );
649             if( nNameBufSize > 0 )
650             {
651                 pName = new char[ nNameBufSize ];
652                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
653                 pS->Read( pName, nNameBufSize );
654             }
655             // control tag
656             sal_uInt32 nTagBufSize = lclGetBufferSize( nTagLen );
657             if( nTagBufSize > 0 )
658             {
659                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
660                 pS->SeekRel( nTagBufSize );
661             }
662 
663             // control position
664             if( nContentFlags & 0x00000100 )
665             {
666                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
667                 *pS >> rec.nLeft >> rec.nTop;
668             }
669 
670             // control infotip
671             sal_uInt32 nTipBufSize = lclGetBufferSize( nTipLen );
672             if( nTipBufSize > 0 )
673             {
674                 std::auto_ptr< sal_Char > pTipName;
675                 pTipName.reset( new sal_Char[ nTipBufSize ] );
676                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
677                 pS->Read( pTipName.get(), nTipBufSize );
678             	rec.controlTip = lclCreateOUString( pTipName.get(), nTipLen );
679             }
680             // control id
681             sal_uInt32 nCntrlIdSize = lclGetBufferSize( nCntrlIdLen );
682             if( nCntrlIdSize > 0 )
683             {
684                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
685                 pS->SeekRel( nCntrlIdSize );
686             }
687             // control source name
688             sal_uInt32 nCtrlSrcBufSize = lclGetBufferSize( nCtrlSrcLen );
689             if( nCtrlSrcBufSize > 0 )
690             {
691                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
692                 pS->SeekRel( nCtrlSrcBufSize );
693             }
694             // row source name
695             sal_uInt32 nRowSrcBufSize = lclGetBufferSize( nRowSrcLen );
696             if( nRowSrcBufSize > 0 )
697             {
698                 ReadAlign( pS, pS->Tell() - nStartPos, 4 );
699                 pS->SeekRel( nRowSrcBufSize );
700             }
701 
702             // seek to end of data
703             pS->Seek( nStartPos + nSize );
704 
705             rec.cName = lclCreateOUString(pName, nNameLen);
706             delete[] pName;
707 
708             OCX_Control* pControl = NULL;
709             if( pContainerControl->createFromContainerRecord( rec, pControl ) &&
710                 pControl )
711             {
712                 // propagate doc shell from parent
713                 pControl->pDocSh = pContainerControl->pDocSh;
714                 pContainerControl->ProcessControl( pControl, pS, rec );
715             }
716             else
717             {
718                 DBG_ERROR("Terminating import, unexpected error");
719                 return false;
720             }
721         }
722         return true;
723     }
724 
725     protected:
ContainerRecReader()726     ContainerRecReader() : isMultiPage(false){}
727     bool isMultiPage;
728 	sal_uInt32 nNoRecords;
729 	sal_uInt32 nTotalLen;
730 
731     private:
handleStandardHdr(SvStorageStream * pS)732     bool handleStandardHdr( SvStorageStream* pS )
733     {
734         sal_uInt8 aUnknown11[4];
735         pS->Read(aUnknown11, sizeof(aUnknown11));
736         return true;
737     }
738 
handleMultiPageHdr(SvStorageStream * pS)739     bool handleMultiPageHdr( SvStorageStream* pS )
740     {
741         sal_uInt32 nUnknown_32b; // unknown 32 bit structure, flags ?
742         sal_uInt16 nUnknown_16b; // unknown 16 bit structure
743         sal_uInt16 nMysteryLen; // length of unknown sub record
744 
745         *pS >> nUnknown_32b;
746         *pS >> nUnknown_16b;
747         *pS >> nMysteryLen;
748 
749         pS->SeekRel( nMysteryLen );
750         return true;
751     }
752     ContainerRecordList records;
753 };
754 
755 class StdContainerRecReader : public ContainerRecReader
756 {
757     public:
StdContainerRecReader()758     StdContainerRecReader(){}
759 };
760 
761 class MultiPageContainerRecReader : public ContainerRecReader
762 {
763     public:
MultiPageContainerRecReader()764     MultiPageContainerRecReader()
765     {
766         // NP ( 27-01-05 )
767         // Strictly speaking this approach shouldn't be necessary.
768         // It should be possible to have a common routine read the
769         // container record array and by examining the flags present in
770         // the record to determine we expect to read or not.
771         // In this case for a MultPage control there is no Top or Left
772         // values in the control record array, however time contraints
773         // and associated risk prevent further investigation of this
774         // at the moment.
775         // similar situation exists for the start of the container record
776         // which in the case of the MultiPage is different from
777         // UserForm & Frame ( the other containers )
778 
779         isMultiPage = true; // tell the base class skip
780     }
781 };
782 
783 class ContainerRecordReaderFac
784 {
785     public:
instance(sal_uInt32 containerType)786     static ContainerRecReader* instance( sal_uInt32 containerType )
787     {
788         switch( containerType )
789         {
790             case PAGE:
791             case FRAME:
792             case USERFORM:
793             case STDCONTAINER:
794                 return new StdContainerRecReader();
795             case MULTIPAGE:
796                 return new MultiPageContainerRecReader();
797             default:
798                 DBG_ERROR("Illegal container type for factory");
799                 return NULL;
800         }
801     }
802     private:
803     ContainerRecordReaderFac();
804 };
805 
806 } // namespace
807 
808 // ============================================================================
809 
add(OCX_Control * pRB)810 void RBGroup::add(OCX_Control* pRB)
811 {
812     // The tab index for the group is calculated as
813     // the lowest tab index found in the list of RadioButtons
814     if ( pRB->mnTabPos < mRBGroupPos )
815     {
816         mRBGroupPos = pRB->mnTabPos;
817         CtrlIterator aEnd = mpControls.end();
818         for (CtrlIterator aIter = mpControls.begin(); aIter != aEnd; ++ aIter )
819         {
820             (*aIter)->mnTabPos = mRBGroupPos;
821         }
822     }
823     mpControls.push_back( pRB );
824 }
825 
826 struct SortGroupByTabPos
827 {
operator ()SortGroupByTabPos828     bool operator()( const RBGroup* a, const RBGroup* b )
829     {
830         return a->tabPos() < b->tabPos();
831     }
832 };
833 
RBGroupManager(String & defaultName)834 RBGroupManager::RBGroupManager( String& defaultName ):mSDefaultName( defaultName ),
835     numRadioButtons(0)
836 {
837     groupList.reserve( 8 ); // reserve far more than we expect
838 }
839 
~RBGroupManager()840 RBGroupManager::~RBGroupManager()
841 {
842     for ( GroupIterator gIter=groupList.begin(); gIter!=groupList.end(); ++gIter )
843     {
844         delete( *gIter );
845     }
846 }
847 
848 // Loose description of the method below ( I sure there is a better way to do
849 // this )
850 // In order to "fake" MS grouping behavior for OptionButtons the OptionButtons
851 // in the same group need to have consecutive tab indices ( regardless of the
852 // imported tab indices of the RadioButtons ). Additionally if two
853 // groups of OptionButtons end up having all consecutive indices they
854 // will be treated as a single group by OpenOffice. In this case
855 // a dummy seperator control needs to be inserted between the groups.
856 //
857 // This method returns a new list "destinationList" containing the controls
858 // passed in "sourceList" and the OptionButtons contained in the various
859 // Groups maintained by this  class.
860 // Controls are ordered in the destination list by tab index.
861 // Each RadioButtonGroup has a tab index associated with it.
862 // ( Tab index of a RadioGroup is determined as the tab index of the
863 // OptionButton control with the lowest tab index in the group )
864 
865 
addRadioButton(OCX_OptionButton * pRButton)866 void RBGroupManager::addRadioButton( OCX_OptionButton* pRButton )
867 {
868     if ( pRButton )
869     {
870         OUString groupName = mSDefaultName;
871         if ( pRButton->nGroupNameLen )
872         {
873             groupName =
874                 lclCreateOUString(pRButton->pGroupName,
875                     pRButton->nGroupNameLen);
876         }
877         ++numRadioButtons;
878         RBGroupHash::iterator iter = rbGroups.find( groupName );
879         if ( iter != rbGroups.end() )
880         {
881             iter->second->controls().push_back( pRButton );
882         }
883         else
884         {
885             RBGroup* newGroup = new RBGroup(pRButton->mnTabPos);
886             newGroup->controls().push_back( pRButton );
887             rbGroups[ groupName ] = newGroup;
888             groupList.push_back( newGroup );
889         }
890 
891     }
892 }
893 
insertGroupsIntoControlList(const CtrlList & sourceList)894 CtrlList RBGroupManager::insertGroupsIntoControlList( const CtrlList& sourceList )
895 {
896     ::std::sort( groupList.begin(), groupList.end(), SortGroupByTabPos() );
897     std::vector<OCX_Control*> destinationList;
898     if ( groupList.size() )
899     {
900         destinationList.reserve( sourceList.size() + numRadioButtons );
901 
902         GroupIterator groupEnd = groupList.end();
903         CtrlIteratorConst sourceEnd = sourceList.end();
904 
905         size_t prevGroupListSize = 0;
906 
907         CtrlIteratorConst containees = sourceList.begin();
908         GroupIterator groupIter=groupList.begin();
909         while ( containees != sourceEnd ||
910                 groupIter != groupEnd )
911         {
912             bool addGroupSeperator = false;
913             if ( containees != sourceEnd )
914             {
915                 if ( groupIter != groupEnd )
916                 {
917                     sal_Int16 groupTabPos = (*groupIter)->tabPos();
918                     if ( (*containees)->mnTabPos >= groupTabPos )
919                     {
920                        if ( !(destinationList.size() >=  prevGroupListSize ))
921                         {
922                             addGroupSeperator = true;
923                         }
924                         copyList( (*groupIter)->controls(), destinationList, addGroupSeperator );
925                         ++groupIter;
926 
927                         prevGroupListSize = destinationList.size();
928                     }
929                 }
930                 destinationList.push_back(*containees);
931                 ++containees;
932             }
933             else
934             {
935                if ( groupIter != groupEnd )
936                {
937                     if ( !(destinationList.size() >  prevGroupListSize ))
938                     {
939                         addGroupSeperator = true;
940                     }
941                     copyList( (*groupIter)->controls(), destinationList, addGroupSeperator );
942                     ++groupIter;
943                     prevGroupListSize = destinationList.size();
944                 }
945             }
946         }
947     }
948     else
949     {
950         destinationList = sourceList;
951     }
952     return destinationList;
953 
954 }
955 
956 
addSeperator(std::vector<OCX_Control * > & dest)957 void RBGroupManager::addSeperator( std::vector< OCX_Control* >& dest )
958 {
959     OCX_Control* seperator = new OCX_CommandButton;
960     seperator->SetInDialog(true);
961     seperator->sName = C2S("GroupSeperator");
962     dest.push_back( seperator );
963 }
964 
copyList(std::vector<OCX_Control * > & src,std::vector<OCX_Control * > & dest,bool addGroupSeperator)965 void RBGroupManager::copyList( std::vector< OCX_Control* >& src,
966     std::vector< OCX_Control* >& dest,
967     bool addGroupSeperator )
968 {
969     if ( addGroupSeperator )
970     {
971         addSeperator( dest );
972     }
973 
974     for ( CtrlIterator rbIter = src.begin(); rbIter != src.end(); ++rbIter )
975     {
976         dest.push_back( *rbIter );
977     }
978 }
979 
980 class OCX_UserFormLabel : public OCX_Label
981 {
982 public:
OCX_UserFormLabel(OCX_Control * pParent)983     OCX_UserFormLabel(OCX_Control* pParent ) : OCX_Label( pParent )
984     {
985         mnForeColor = 0x80000012L;
986         mnBackColor = 0x8000000FL;
987     }
988 };
989 
990 
991 sal_uInt16 OCX_Control::nStandardId(0x0200);
992 sal_uInt16 OCX_FontData::nStandardId(0x0200);
993 
994 sal_uInt32 OCX_Control::pColor[25] = {
995 0xC0C0C0, 0x008080, 0x000080, 0x808080, 0xC0C0C0, 0xFFFFFF, 0x000000,
996 0x000000, 0x000000, 0xFFFFFF, 0xC0C0C0, 0xC0C0C0, 0x808080, 0x000080,
997 0xFFFFFF, 0xC0C0C0, 0x808080, 0x808080, 0x000000, 0xC0C0C0, 0xFFFFFF,
998 0x000000, 0xC0C0C0, 0x000000, 0xFFFFC0 };
999 
FillSystemColors()1000 void OCX_Control::FillSystemColors()
1001 {
1002     // overwrite the predefined colors with available system colors
1003     const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
1004 
1005     pColor[ 0x00 ] = rSett.GetFaceColor().GetColor();
1006     pColor[ 0x01 ] = rSett.GetWorkspaceColor().GetColor();
1007     pColor[ 0x02 ] = rSett.GetActiveColor().GetColor();
1008     pColor[ 0x03 ] = rSett.GetDeactiveColor().GetColor();
1009     pColor[ 0x04 ] = rSett.GetMenuBarColor().GetColor();
1010     pColor[ 0x05 ] = rSett.GetWindowColor().GetColor();
1011     pColor[ 0x07 ] = rSett.GetMenuTextColor().GetColor();
1012     pColor[ 0x08 ] = rSett.GetWindowTextColor().GetColor();
1013     pColor[ 0x09 ] = rSett.GetActiveTextColor().GetColor();
1014     pColor[ 0x0A ] = rSett.GetActiveBorderColor().GetColor();
1015     pColor[ 0x0B ] = rSett.GetDeactiveBorderColor().GetColor();
1016     pColor[ 0x0C ] = rSett.GetWorkspaceColor().GetColor();
1017     pColor[ 0x0D ] = rSett.GetHighlightColor().GetColor();
1018     pColor[ 0x0E ] = rSett.GetHighlightTextColor().GetColor();
1019     pColor[ 0x0F ] = rSett.GetFaceColor().GetColor();
1020     pColor[ 0x10 ] = rSett.GetShadowColor().GetColor();
1021     pColor[ 0x12 ] = rSett.GetButtonTextColor().GetColor();
1022     pColor[ 0x13 ] = rSett.GetDeactiveTextColor().GetColor();
1023     pColor[ 0x14 ] = rSett.GetHighlightColor().GetColor();
1024     pColor[ 0x15 ] = rSett.GetDarkShadowColor().GetColor();
1025     pColor[ 0x16 ] = rSett.GetShadowColor().GetColor();
1026     pColor[ 0x17 ] = rSett.GetHelpTextColor().GetColor();
1027     pColor[ 0x18 ] = rSett.GetHelpColor().GetColor();
1028 }
1029 
ImportColor(sal_uInt32 nColor) const1030 sal_uInt32 OCX_Control::ImportColor(sal_uInt32 nColor) const
1031 {
1032 	sal_uInt8 nUpper = (sal_uInt8)( nColor >> 24 );
1033 	if (nUpper & 0x80) //Palette color, should be switch on bottom 24 bits
1034 	{
1035 		/*Might as well use my systems ones in the absence of any other ideas*/
1036 		nColor = nColor&0x00FFFFFF;
1037 		DBG_ASSERT (nColor <= 24,"Unknown Palette Index");
1038 		if (nColor > 24)
1039 			nColor = 0xFFFFFF;
1040 		else
1041 			nColor = pColor[nColor];
1042 	}
1043 	else
1044 	{
1045 		//Stored in bgr! rather than rgb
1046 		nColor = SwapColor(nColor);
1047 	}
1048 	return nColor;
1049 }
1050 
ImportAlign(sal_uInt8 _nJustification) const1051 sal_Int16 OCX_FontData::ImportAlign(sal_uInt8 _nJustification) const
1052 {
1053 	sal_Int16 nRet;
1054 	switch (_nJustification)
1055 	{
1056 	default:
1057 	case 1:
1058 		nRet = 0;
1059 		break;
1060 	case 2:
1061 		nRet = 2;
1062 		break;
1063 	case 3:
1064 		nRet = 1;
1065 		break;
1066 	}
1067 	return nRet;
1068 }
1069 
ExportAlign(sal_Int16 nAlign) const1070 sal_uInt8 OCX_FontData::ExportAlign(sal_Int16 nAlign) const
1071 {
1072 	sal_Int8 nRet;
1073 	switch (nAlign)
1074 	{
1075 	default:
1076 	case 0:
1077 		nRet = 1;
1078 		break;
1079 	case 2:
1080 		nRet = 2;
1081 		break;
1082 	case 1:
1083 		nRet = 3;
1084 		break;
1085 	}
1086 	return nRet;
1087 }
1088 
SwapColor(sal_uInt32 nColor) const1089 sal_uInt32 OCX_Control::SwapColor(sal_uInt32 nColor) const
1090 {
1091 	sal_uInt8
1092 		r(static_cast<sal_uInt8>(nColor&0xFF)),
1093 		g(static_cast<sal_uInt8>(((nColor)>>8)&0xFF)),
1094 		b(static_cast<sal_uInt8>((nColor>>16)&0xFF));
1095 	nColor = (r<<16) + (g<<8) + b;
1096 	return nColor;
1097 }
1098 
ExportColor(sal_uInt32 nColor) const1099 sal_uInt32 OCX_Control::ExportColor(sal_uInt32 nColor) const
1100 {
1101 	sal_uInt8 nUpper = (sal_uInt8)( nColor >> 24 );
1102 	if (nUpper & 0x80) //Palette color, should be switch on bottom 24 bits
1103 	{
1104 		/*Might as well use my systems ones in the absence of any other ideas*/
1105 		nColor = nColor&0x00FFFFFF;
1106 		DBG_ASSERT (nColor <= 24,"Unknown Palette Index");
1107 		if (nColor > 24)
1108 			nColor = 0xFFFFFF;
1109 		else
1110 			nColor = pColor[nColor];
1111 	}
1112 
1113 	//Stored in bgr! rather than rgb
1114 	nColor = SwapColor(nColor);
1115 	return nColor;
1116 }
1117 
Import(const uno::Reference<lang::XMultiServiceFactory> & rServiceFactory,uno::Reference<form::XFormComponent> & rFComp,awt::Size & rSz)1118 sal_Bool OCX_Control::Import(
1119 	const uno::Reference< lang::XMultiServiceFactory > &rServiceFactory,
1120 	uno::Reference< form::XFormComponent >  &rFComp, awt::Size &rSz)
1121 {
1122 
1123     if(msFormType.getLength() == 0)
1124         return sal_False;
1125 
1126 	rSz.Width = nWidth;
1127 	rSz.Height = nHeight;
1128 
1129 	uno::Reference<uno::XInterface> xCreate =
1130 		rServiceFactory->createInstance(msFormType);
1131 	if (!xCreate.is())
1132 		return sal_False;
1133 
1134 	rFComp = uno::Reference<form::XFormComponent>(xCreate,uno::UNO_QUERY);
1135 	if (!rFComp.is())
1136 		return sal_False;
1137     uno::Reference<beans::XPropertySet> xPropSet(xCreate,uno::UNO_QUERY);
1138     if (!xPropSet.is())
1139         return sal_False;
1140     return Import(xPropSet);
1141 }
1142 
Import(uno::Reference<container::XNameContainer> & rDialog)1143 sal_Bool OCX_Control::Import(uno::Reference<container::XNameContainer> &rDialog
1144     )
1145 {
1146     uno::Reference<lang::XMultiServiceFactory>
1147         xFactory(rDialog, uno::UNO_QUERY);
1148 
1149 	uno::Reference<uno::XInterface> xCreate =
1150         xFactory->createInstance(msDialogType);
1151 	if (!xCreate.is())
1152 		return sal_False;
1153 
1154 	uno::Reference<awt::XControlModel> xModel(xCreate, uno::UNO_QUERY);
1155 	if (!xModel.is())
1156 		return sal_False;
1157 
1158     /*  #147900# sometimes insertion of a control fails due to existing name,
1159         do not break entire form import then... */
1160     try
1161     {
1162         rDialog->insertByName(sName, uno::makeAny(xModel));
1163     }
1164     catch( uno::Exception& )
1165     {
1166         DBG_ERRORFILE(
1167             ByteString( "OCX_Control::Import - cannot insert control \"" ).
1168             Append( ByteString( sName, RTL_TEXTENCODING_UTF8 ) ).
1169             Append( '"' ).GetBuffer() );
1170     }
1171 
1172     uno::Reference<beans::XPropertySet> xPropSet(xCreate, uno::UNO_QUERY);
1173     if (!xPropSet.is())
1174         return sal_False;
1175 
1176     if (!Import(xPropSet))
1177         return sal_False;
1178 
1179     uno::Any aTmp;
1180     aTmp <<= sal_Int32((mnLeft * 2) / 100);
1181     xPropSet->setPropertyValue(WW8_ASCII2STR("PositionX"), aTmp);
1182     aTmp <<= sal_Int32((mnTop * 2) / 100);
1183     xPropSet->setPropertyValue(WW8_ASCII2STR("PositionY"), aTmp);
1184     aTmp <<= sal_Int32((nWidth * 2) / 100);
1185     xPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
1186     aTmp <<= sal_Int32((nHeight * 2) / 100);
1187     xPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
1188     if ( msToolTip.Len() > 0 )
1189 		xPropSet->setPropertyValue(WW8_ASCII2STR("HelpText"), uno::Any(OUString(msToolTip)));
1190 
1191     if ( mnStep )
1192     {
1193         aTmp <<= mnStep;
1194         xPropSet->setPropertyValue(WW8_ASCII2STR("Step"), aTmp);
1195     }
1196 
1197     try
1198     {
1199         xPropSet->setPropertyValue(WW8_ASCII2STR("EnableVisible"), uno::makeAny( mbVisible ) );
1200     }
1201     catch( uno::Exception& )
1202     {
1203     }
1204     return sal_True;
1205 }
1206 
ImportBorder(sal_uInt16 nSpecialEffect,sal_uInt16 nBorderStyle) const1207 sal_Int16 OCX_Control::ImportBorder(sal_uInt16 nSpecialEffect,
1208 	sal_uInt16 nBorderStyle) const
1209 {
1210 	if ((nSpecialEffect == 0) && (nBorderStyle == 0))
1211 		return 0;	//No Border
1212 	else if ((nSpecialEffect == 0) && (nBorderStyle == 1))
1213 		return 2;	//Flat Border
1214 	return 1;	//3D Border
1215 }
1216 
ExportBorder(sal_uInt16 nBorder,sal_uInt8 & rBorderStyle) const1217 sal_uInt8 OCX_Control::ExportBorder(sal_uInt16 nBorder,sal_uInt8 &rBorderStyle)
1218 	const
1219 {
1220 	sal_uInt8 nRet;
1221 	switch(nBorder)
1222 	{
1223 		case 0:
1224 			nRet = rBorderStyle = 0;
1225 			break;
1226 		default:
1227 		case 1:
1228 			nRet = 2;
1229             rBorderStyle = 0;
1230 			break;
1231 		case 2:
1232             nRet = 0;
1233 			rBorderStyle = 1;
1234 			break;
1235 	}
1236 	return nRet;
1237 }
1238 
ImportSpecEffect(sal_uInt8 nSpecialEffect) const1239 sal_Int16 OCX_Control::ImportSpecEffect( sal_uInt8 nSpecialEffect ) const
1240 {
1241     return (nSpecialEffect == 0) ? 2 : 1;
1242 }
1243 
ExportSpecEffect(sal_Int16 nApiEffect) const1244 sal_uInt8 OCX_Control::ExportSpecEffect( sal_Int16 nApiEffect ) const
1245 {
1246     return (nApiEffect == 2) ? 0 : 2;
1247 }
1248 
ReadFontData(SvStorageStream * pS)1249 sal_Bool OCX_Control::ReadFontData(SvStorageStream *pS)
1250 {
1251     return aFontData.Read(pS);
1252 }
1253 
1254 
1255 const uno::Reference< drawing::XDrawPage >&
GetDrawPage()1256 	SvxMSConvertOCXControls::GetDrawPage()
1257 {
1258 	if( !xDrawPage.is() && pDocSh )
1259 	{
1260 		uno::Reference< drawing::XDrawPageSupplier > xTxtDoc(pDocSh->GetModel(),
1261 			uno::UNO_QUERY);
1262 		DBG_ASSERT(xTxtDoc.is(),"XDrawPageSupplier nicht vom XModel erhalten");
1263 		xDrawPage = xTxtDoc->getDrawPage();
1264 		DBG_ASSERT( xDrawPage.is(), "XDrawPage nicht erhalten" );
1265 	}
1266 
1267 	return xDrawPage;
1268 }
1269 
1270 
1271 const uno::Reference< lang::XMultiServiceFactory >&
GetServiceFactory()1272 	SvxMSConvertOCXControls::GetServiceFactory()
1273 {
1274 	if( !xServiceFactory.is() && pDocSh )
1275 	{
1276 		xServiceFactory = uno::Reference< lang::XMultiServiceFactory >
1277 			(pDocSh->GetBaseModel(), uno::UNO_QUERY);
1278 		DBG_ASSERT( xServiceFactory.is(),
1279 				"XMultiServiceFactory nicht vom Model erhalten" );
1280 	}
1281 
1282 	return xServiceFactory;
1283 }
1284 
GetShapes()1285 const uno::Reference< drawing::XShapes >& SvxMSConvertOCXControls::GetShapes()
1286 {
1287 	if( !xShapes.is() )
1288 	{
1289 		GetDrawPage();
1290 		if( xDrawPage.is() )
1291 		{
1292 
1293 			xShapes = uno::Reference< drawing::XShapes >(xDrawPage,
1294 				uno::UNO_QUERY);
1295 			DBG_ASSERT( xShapes.is(), "XShapes nicht vom XDrawPage erhalten" );
1296 		}
1297 	}
1298 	return xShapes;
1299 }
1300 
1301 const uno::Reference< container::XIndexContainer >&
GetFormComps()1302 	SvxMSConvertOCXControls::GetFormComps()
1303 {
1304 	if( !xFormComps.is() )
1305 	{
1306 		GetDrawPage();
1307 		if( xDrawPage.is() )
1308 		{
1309 			uno::Reference< form::XFormsSupplier > xFormsSupplier( xDrawPage,
1310 				uno::UNO_QUERY );
1311 			DBG_ASSERT( xFormsSupplier.is(),
1312 					"XFormsSupplier nicht vom XDrawPage erhalten" );
1313 
1314 			uno::Reference< container::XNameContainer >  xNameCont =
1315 				xFormsSupplier->getForms();
1316 
1317 			// Das Formular bekommt einen Namen wie "WW-Standard[n]" und
1318 			// wird in jedem Fall neu angelegt.
1319 			UniString sName( sWW8_form, RTL_TEXTENCODING_MS_1252 );
1320 			sal_uInt16 n = 0;
1321 
1322 			while( xNameCont->hasByName( sName ) )
1323 			{
1324 				sName.AssignAscii( sWW8_form );
1325 				sName += String::CreateFromInt32( ++n );
1326 			}
1327 
1328 			const uno::Reference< lang::XMultiServiceFactory > &rServiceFactory
1329 				= GetServiceFactory();
1330 			if( !rServiceFactory.is() )
1331 				return xFormComps;
1332 
1333 			uno::Reference< uno::XInterface >  xCreate =
1334 				rServiceFactory->createInstance(WW8_ASCII2STR(
1335 					"com.sun.star.form.component.Form"));
1336 			if( xCreate.is() )
1337 			{
1338 				uno::Reference< beans::XPropertySet > xFormPropSet( xCreate,
1339 					uno::UNO_QUERY );
1340 
1341 				uno::Any aTmp(&sName,getCppuType((OUString *)0));
1342 				xFormPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
1343 
1344 				uno::Reference< form::XForm > xForm( xCreate, uno::UNO_QUERY );
1345 				DBG_ASSERT(xForm.is(), "keine Form?");
1346 
1347 				uno::Reference< container::XIndexContainer > xForms( xNameCont,
1348 					uno::UNO_QUERY );
1349 				DBG_ASSERT( xForms.is(), "XForms nicht erhalten" );
1350 
1351 				aTmp.setValue( &xForm,
1352 					::getCppuType((uno::Reference < form::XForm >*)0));
1353 				xForms->insertByIndex( xForms->getCount(), aTmp );
1354 
1355 				xFormComps = uno::Reference< container::XIndexContainer >
1356 					(xCreate, uno::UNO_QUERY);
1357 			}
1358 		}
1359 	}
1360 
1361 	return xFormComps;
1362 }
1363 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)1364 sal_Bool OCX_CommandButton::Import( com::sun::star::uno::Reference<
1365     com::sun::star::beans::XPropertySet> &rPropSet)
1366 {
1367 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
1368 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
1369 
1370 	aTmp <<= ImportColor(mnForeColor);
1371 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
1372 
1373 	//fBackStyle is a flag. 1 means with background color. 0 means default.
1374 	if( fBackStyle )
1375 		aTmp <<= ImportColor(mnBackColor);
1376 	else
1377 		aTmp = uno::Any();
1378 	rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
1379 
1380 	sal_Bool bTemp;
1381 	if ((!(fEnabled)) || (fLocked))
1382 		bTemp = sal_False;
1383 	else
1384 		bTemp = sal_True;
1385 	aTmp = bool2any(bTemp);
1386 
1387 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
1388 
1389     bTemp = fWordWrap != 0;
1390     aTmp = bool2any(bTemp);
1391     rPropSet->setPropertyValue( WW8_ASCII2STR("MultiLine"), aTmp);
1392 
1393 	if (pCaption)
1394 	{
1395         aTmp <<= lclCreateOUString( pCaption, nCaptionLen );
1396 		rPropSet->setPropertyValue( WW8_ASCII2STR("Label"), aTmp);
1397 	}
1398 
1399     aTmp = bool2any( mbTakeFocus );
1400     rPropSet->setPropertyValue( WW8_ASCII2STR( "FocusOnClick" ), aTmp );
1401 
1402 	aFontData.Import(rPropSet);
1403 	return sal_True;
1404 }
1405 
Export(SvStorageRef &,const uno::Reference<beans::XPropertySet> &,const awt::Size &)1406 sal_Bool OCX_GroupBox::Export(SvStorageRef& /* rObj */,
1407 	const uno::Reference< beans::XPropertySet >& /* rPropSet */,
1408 	const awt::Size& /* rSize */ )
1409 {
1410 	sal_Bool bRet=sal_True;
1411 	return bRet;
1412 }
1413 
WriteContents(SvStorageStreamRef &,const uno::Reference<beans::XPropertySet> &,const awt::Size &)1414 sal_Bool OCX_GroupBox::WriteContents(SvStorageStreamRef& /* rObj */,
1415 	const uno::Reference< beans::XPropertySet >& /* rPropSet */,
1416 	const awt::Size& /* rSize */)
1417 {
1418 	sal_Bool bRet=sal_True;
1419 	return bRet;
1420 }
1421 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)1422 sal_Bool OCX_CommandButton::WriteContents(SvStorageStreamRef& rContents,
1423 	const uno::Reference< beans::XPropertySet >& rPropSet,
1424 	const awt::Size& rSize )
1425 {
1426 	sal_Bool bRet=sal_True;
1427 
1428     sal_uInt32 nOldPos = rContents->Tell();
1429 	rContents->SeekRel(8);
1430 
1431 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
1432     if (aTmp.hasValue())
1433 	    aTmp >>= mnForeColor;
1434 	*rContents << ExportColor(mnForeColor);
1435 
1436 	//fBackStyle is a flag. 1 means with background color. 0 means default.
1437 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
1438     if (aTmp.hasValue())
1439 	    aTmp >>= mnBackColor;
1440 	else
1441 		fBackStyle = 0;
1442 	*rContents << ExportColor(mnBackColor);
1443 
1444 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
1445 	fEnabled = any2bool(aTmp);
1446 	sal_uInt8 nTemp=0;//fEnabled;
1447 	if (fEnabled)
1448 		nTemp |= 0x02;//has enabled prop
1449     if (fBackStyle)
1450         nTemp |= 0x08;//has background color
1451 	*rContents << nTemp;
1452 	*rContents << sal_uInt8(0x00);
1453 
1454     nTemp = 0;
1455     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("MultiLine"));
1456     fWordWrap = any2bool(aTmp);
1457     if (fWordWrap)
1458         nTemp |= 0x80;
1459     *rContents << nTemp;
1460 	*rContents << sal_uInt8(0x00);
1461 
1462     SvxOcxString aCaption( rPropSet->getPropertyValue(WW8_ASCII2STR("Label")) );
1463     aCaption.WriteLenField( *rContents );
1464     aCaption.WriteCharArray( *rContents );
1465 
1466 	WriteAlign(rContents,4);
1467 
1468 	*rContents << rSize.Width;
1469 	*rContents << rSize.Height;
1470 
1471     // "take focus on click" is directly in content flags, not in option field...
1472     mbTakeFocus = any2bool( rPropSet->getPropertyValue( WW8_ASCII2STR( "FocusOnClick" ) ) );
1473 
1474     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
1475 	aFontData.nDefaultAlign = 1;
1476 	bRet = aFontData.Export(rContents,rPropSet);
1477 
1478     rContents->Seek(nOldPos);
1479 	*rContents << nStandardId;
1480 	*rContents << nFixedAreaLen;
1481 
1482 	sal_uInt8 nTmp = 0x27;
1483     if (aCaption.HasData())
1484 		nTmp |= 0x08;
1485 	*rContents << nTmp;
1486     nTmp = 0x00;
1487     if( !mbTakeFocus )  // flag is set, if option is off
1488         nTmp |= 0x02;
1489     *rContents << nTmp;
1490 	*rContents << sal_uInt8(0x00);
1491 	*rContents << sal_uInt8(0x00);
1492 
1493 	DBG_ASSERT((rContents.Is() && (SVSTREAM_OK==rContents->GetError())),"damn");
1494 	return bRet;
1495 }
1496 
1497 
1498 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)1499 sal_Bool OCX_CommandButton::Export(SvStorageRef &rObj,
1500 	const uno::Reference< beans::XPropertySet > &rPropSet,
1501 	const awt::Size &rSize)
1502 {
1503 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
1504 			0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1505 			0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x32, 0x05, 0xD7,
1506 			0x69, 0xCE, 0xCD, 0x11, 0xA7, 0x77, 0x00, 0xDD,
1507 			0x01, 0x14, 0x3C, 0x57, 0x22, 0x00, 0x00, 0x00,
1508 			0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1509 			0x74, 0x20, 0x46, 0x6F, 0x72, 0x6d, 0x73, 0x20,
1510 			0x32, 0x2e, 0x30, 0x20, 0x43, 0x6F, 0x6D, 0x6D,
1511 			0x61, 0x6E, 0x64, 0x42, 0x75, 0x74, 0x74, 0x6F,
1512 			0x6E, 0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D,
1513 			0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F,
1514 			0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x16, 0x00,
1515 			0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E,
1516 			0x43, 0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x42,
1517 			0x75, 0x74, 0x74, 0x6F, 0x6E, 0x2E, 0x31, 0x00,
1518 			0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
1519 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1520 		};
1521 
1522 	{
1523 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
1524 	xStor->Write(aCompObj,sizeof(aCompObj));
1525 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
1526 	}
1527 
1528 	{
1529 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
1530 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
1531 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
1532 	}
1533 
1534 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
1535 		0x43, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x6D, 0x00,
1536 		0x61, 0x00, 0x6E, 0x00, 0x64, 0x00, 0x42, 0x00,
1537 		0x75, 0x00, 0x74, 0x00, 0x74, 0x00, 0x6F, 0x00,
1538 		0x6E, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00
1539 	};
1540 
1541 	{
1542 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
1543 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
1544 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
1545 	}
1546 
1547 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
1548 
1549 	return WriteContents(xContents,rPropSet,rSize);
1550 }
1551 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)1552 sal_Bool OCX_ImageButton::WriteContents(SvStorageStreamRef &rContents,
1553 	const uno::Reference< beans::XPropertySet > &rPropSet,
1554 	const awt::Size &rSize)
1555 {
1556 	sal_Bool bRet=sal_True;
1557 
1558     sal_uInt32 nOldPos = rContents->Tell();
1559 	rContents->SeekRel(8);
1560 
1561 	uno::Any aTmp=rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
1562     if (aTmp.hasValue())
1563 	    aTmp >>= mnBackColor;
1564 	*rContents << ExportColor(mnBackColor);
1565 
1566 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
1567 	fEnabled = any2bool(aTmp);
1568 	sal_uInt8 nTemp=0;//fEnabled;
1569 	if (fEnabled)
1570 		nTemp |= 0x02;
1571 	*rContents << nTemp;
1572 	*rContents << sal_uInt8(0x00);
1573 	*rContents << sal_uInt8(0x00);
1574 	*rContents << sal_uInt8(0x00);
1575 
1576 	WriteAlign(rContents,4);
1577 
1578 	*rContents << rSize.Width;
1579 	*rContents << rSize.Height;
1580 
1581     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
1582 
1583 	bRet = aFontData.Export(rContents,rPropSet);
1584 
1585     rContents->Seek(nOldPos);
1586 	*rContents << nStandardId;
1587 	*rContents << nFixedAreaLen;
1588 
1589 	sal_uInt8 nTmp = 0x26;
1590 	*rContents << nTmp;
1591 	*rContents << sal_uInt8(0x00);
1592 	*rContents << sal_uInt8(0x00);
1593 	*rContents << sal_uInt8(0x00);
1594 
1595 	DBG_ASSERT((rContents.Is() && (SVSTREAM_OK==rContents->GetError())),"damn");
1596 	return bRet;
1597 }
1598 
1599 
1600 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)1601 sal_Bool OCX_ImageButton::Export(SvStorageRef &rObj,
1602 	const uno::Reference< beans::XPropertySet > &rPropSet,
1603 	const awt::Size &rSize)
1604 {
1605 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
1606 			0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1607 			0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x32, 0x05, 0xD7,
1608 			0x69, 0xCE, 0xCD, 0x11, 0xA7, 0x77, 0x00, 0xDD,
1609 			0x01, 0x14, 0x3C, 0x57, 0x22, 0x00, 0x00, 0x00,
1610 			0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1611 			0x74, 0x20, 0x46, 0x6F, 0x72, 0x6d, 0x73, 0x20,
1612 			0x32, 0x2e, 0x30, 0x20, 0x43, 0x6F, 0x6D, 0x6D,
1613 			0x61, 0x6E, 0x64, 0x42, 0x75, 0x74, 0x74, 0x6F,
1614 			0x6E, 0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D,
1615 			0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F,
1616 			0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x16, 0x00,
1617 			0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E,
1618 			0x43, 0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x42,
1619 			0x75, 0x74, 0x74, 0x6F, 0x6E, 0x2E, 0x31, 0x00,
1620 			0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
1621 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1622 		};
1623 
1624 	{
1625 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
1626 	xStor->Write(aCompObj,sizeof(aCompObj));
1627 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
1628 	}
1629 
1630 	{
1631 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
1632 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
1633 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
1634 	}
1635 
1636 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
1637 		0x43, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x6D, 0x00,
1638 		0x61, 0x00, 0x6E, 0x00, 0x64, 0x00, 0x42, 0x00,
1639 		0x75, 0x00, 0x74, 0x00, 0x74, 0x00, 0x6F, 0x00,
1640 		0x6E, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00
1641 	};
1642 
1643 	{
1644 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
1645 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
1646 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
1647 	}
1648 
1649 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
1650 	return WriteContents(xContents,rPropSet,rSize);
1651 }
1652 
1653 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)1654 sal_Bool OCX_OptionButton::Import(com::sun::star::uno::Reference<
1655         com::sun::star::beans::XPropertySet> &rPropSet)
1656 {
1657 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
1658 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
1659 
1660     // background color: fBackStyle==0 -> transparent
1661     if( fBackStyle )
1662         aTmp <<= ImportColor(mnBackColor);
1663     else
1664         aTmp = uno::Any();
1665     rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
1666 
1667 	sal_Bool bTemp;
1668 	if ((!(fEnabled)) || (fLocked))
1669 		bTemp = sal_False;
1670 	else
1671 		bTemp = sal_True;
1672 	aTmp = bool2any(bTemp);
1673 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
1674 
1675     bTemp = fWordWrap != 0;
1676     aTmp = bool2any(bTemp);
1677     rPropSet->setPropertyValue( WW8_ASCII2STR("MultiLine"), aTmp);
1678 
1679 	aTmp <<= ImportColor(mnForeColor);
1680 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
1681 
1682     aTmp <<= ImportSpecEffect( nSpecialEffect );
1683     rPropSet->setPropertyValue( WW8_ASCII2STR("VisualEffect"), aTmp);
1684 
1685 	if (pValue && !bSetInDialog)
1686 	{
1687 		sal_Int16 nTmp = pValue[0]-0x30;
1688 		aTmp <<= nTmp;
1689 		rPropSet->setPropertyValue( WW8_ASCII2STR("DefaultState"), aTmp);
1690 	}
1691 
1692 	if (pCaption)
1693 	{
1694         aTmp <<= lclCreateOUString( pCaption, nCaptionLen );
1695 		rPropSet->setPropertyValue( WW8_ASCII2STR("Label"), aTmp);
1696 	}
1697 
1698     // #i40279# always centered vertically
1699     aTmp <<= ::com::sun::star::style::VerticalAlignment_MIDDLE;
1700     rPropSet->setPropertyValue( WW8_ASCII2STR("VerticalAlign"), aTmp );
1701 
1702 	aFontData.Import(rPropSet);
1703 	return sal_True;
1704 }
1705 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)1706 sal_Bool OCX_OptionButton::WriteContents(SvStorageStreamRef &rContents,
1707 	const uno::Reference< beans::XPropertySet > &rPropSet,
1708 	const awt::Size &rSize)
1709 {
1710 	sal_Bool bRet=sal_True;
1711 
1712     sal_uInt32 nOldPos = rContents->Tell();
1713 	rContents->SeekRel(12);
1714 
1715 	pBlockFlags[0] = 0;
1716 	pBlockFlags[1] = 0x01;
1717 	pBlockFlags[2] = 0;
1718 	pBlockFlags[3] = 0x80;
1719 	pBlockFlags[4] = 0;
1720 	pBlockFlags[5] = 0;
1721 	pBlockFlags[6] = 0;
1722 	pBlockFlags[7] = 0;
1723 
1724 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
1725 	fEnabled = any2bool(aTmp);
1726 
1727     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
1728     if (aTmp.hasValue())
1729         aTmp >>= mnBackColor;
1730     else
1731         fBackStyle = 0;
1732 
1733 	sal_uInt8 nTemp=0;//=fEnabled;
1734 	if (fEnabled)
1735 		nTemp |= 0x02;
1736     if (fBackStyle)
1737         nTemp |= 0x08;
1738 	*rContents << nTemp;
1739 	pBlockFlags[0] |= 0x01;
1740 	*rContents << sal_uInt8(0x00);
1741     nTemp = 0;
1742     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("MultiLine"));
1743     fWordWrap = any2bool(aTmp);
1744     if (fWordWrap)
1745         nTemp |= 0x80;
1746     *rContents << nTemp;
1747     *rContents << sal_uInt8(0x00);
1748 
1749     *rContents << ExportColor(mnBackColor);
1750     pBlockFlags[0] |= 0x02;
1751 
1752 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
1753     if (aTmp.hasValue())
1754 	    aTmp >>= mnForeColor;
1755 	*rContents << ExportColor(mnForeColor);
1756 	pBlockFlags[0] |= 0x04;
1757 
1758 	nStyle = 5;
1759 	*rContents << nStyle;
1760 	pBlockFlags[0] |= 0x40;
1761 
1762 	WriteAlign(rContents,4);
1763     nValueLen = 1|SVX_MSOCX_COMPRESSED;
1764 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("DefaultState"));
1765 	sal_Int16 nDefault = sal_Int16();
1766 	aTmp >>= nDefault;
1767 	*rContents << nValueLen;
1768 	pBlockFlags[2] |= 0x40;
1769 
1770 
1771     SvxOcxString aCaption( rPropSet->getPropertyValue(WW8_ASCII2STR("Label")) );
1772     if (aCaption.HasData())
1773 		pBlockFlags[2] |= 0x80;
1774     aCaption.WriteLenField( *rContents );
1775 
1776     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("VisualEffect"));
1777     if (aTmp.hasValue())
1778     {
1779         sal_Int16 nApiSpecEffect = sal_Int16();
1780         aTmp >>= nApiSpecEffect;
1781         nSpecialEffect = ExportSpecEffect( nApiSpecEffect );
1782     }
1783     *rContents << nSpecialEffect;
1784     pBlockFlags[3] |= 0x04;
1785 
1786 	WriteAlign(rContents,4);
1787 	*rContents << rSize.Width;
1788 	*rContents << rSize.Height;
1789 
1790 	nDefault += 0x30;
1791 	*rContents << sal_uInt8(nDefault);
1792 	*rContents << sal_uInt8(0x00);
1793 
1794     aCaption.WriteCharArray( *rContents );
1795 
1796 	WriteAlign(rContents,4);
1797     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
1798 	bRet = aFontData.Export(rContents,rPropSet);
1799 
1800     rContents->Seek(nOldPos);
1801 	*rContents << nStandardId;
1802 	*rContents << nFixedAreaLen;
1803 
1804 	*rContents << pBlockFlags[0];
1805 	*rContents << pBlockFlags[1];
1806 	*rContents << pBlockFlags[2];
1807 	*rContents << pBlockFlags[3];
1808 	*rContents << pBlockFlags[4];
1809 	*rContents << pBlockFlags[5];
1810 	*rContents << pBlockFlags[6];
1811 	*rContents << pBlockFlags[7];
1812 
1813 	DBG_ASSERT((rContents.Is() &&
1814 		(SVSTREAM_OK==rContents->GetError())),"damn");
1815 	return bRet;
1816 }
1817 
1818 
1819 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)1820 sal_Bool OCX_OptionButton::Export(SvStorageRef &rObj,
1821 	const uno::Reference< beans::XPropertySet > &rPropSet,
1822 	const awt::Size &rSize)
1823 {
1824 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
1825 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1826 		0xFF, 0xFF, 0xFF, 0xFF, 0x50, 0x1D, 0xD2, 0x8B,
1827 		0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
1828 		0x00, 0x60, 0x02, 0xF3, 0x21, 0x00, 0x00, 0x00,
1829 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1830 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1831 		0x32, 0x2E, 0x30, 0x20, 0x4F, 0x70, 0x74, 0x69,
1832 		0x6F, 0x6E, 0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E,
1833 		0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D, 0x62,
1834 		0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F, 0x62,
1835 		0x6A, 0x65, 0x63, 0x74, 0x00, 0x15, 0x00, 0x00,
1836 		0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E, 0x4F,
1837 		0x70, 0x74, 0x69, 0x6F, 0x6E, 0x42, 0x75, 0x74,
1838 		0x74, 0x6F, 0x6E, 0x2E, 0x31, 0x00, 0xF4, 0x39,
1839 		0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1840 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1841 		};
1842 
1843 	{
1844 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
1845 	xStor->Write(aCompObj,sizeof(aCompObj));
1846 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
1847 	}
1848 
1849 	{
1850 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
1851 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
1852 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
1853 	}
1854 
1855 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
1856 			0x4F, 0x00, 0x70, 0x00, 0x74, 0x00, 0x69, 0x00,
1857 			0x6F, 0x00, 0x6E, 0x00, 0x42, 0x00, 0x75, 0x00,
1858 			0x74, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x6E, 0x00,
1859 			0x31, 0x00, 0x00, 0x00, 0x00, 0x00
1860 			};
1861 
1862 	{
1863 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
1864 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
1865 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
1866 	}
1867 
1868 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
1869 	return WriteContents(xContents, rPropSet, rSize);
1870 }
1871 
1872 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)1873 sal_Bool OCX_TextBox::Import(com::sun::star::uno::Reference<
1874     com::sun::star::beans::XPropertySet> &rPropSet)
1875 {
1876 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
1877 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
1878 
1879     aTmp = bool2any( fEnabled != 0 );
1880 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
1881 
1882     aTmp = bool2any( fLocked != 0 );
1883 	rPropSet->setPropertyValue( WW8_ASCII2STR("ReadOnly"), aTmp);
1884 
1885     aTmp = bool2any( fHideSelection != 0 );
1886     rPropSet->setPropertyValue( WW8_ASCII2STR( "HideInactiveSelection" ), aTmp);
1887 
1888 	aTmp <<= ImportColor(mnForeColor);
1889 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
1890 
1891 	aTmp <<= ImportColor(mnBackColor);
1892 	rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
1893 
1894     aTmp <<= ImportBorder(nSpecialEffect,nBorderStyle);
1895     rPropSet->setPropertyValue( WW8_ASCII2STR("Border"), aTmp);
1896 
1897     aTmp <<= ImportColor( nBorderColor );
1898     rPropSet->setPropertyValue( WW8_ASCII2STR("BorderColor"), aTmp);
1899 
1900     aTmp = bool2any( fMultiLine != 0 );
1901 	rPropSet->setPropertyValue( WW8_ASCII2STR("MultiLine"), aTmp);
1902 
1903 	sal_uInt16 nTmp = static_cast<sal_uInt16>(nMaxLength);
1904 	aTmp <<= nTmp;
1905 	rPropSet->setPropertyValue( WW8_ASCII2STR("MaxTextLen"), aTmp);
1906 
1907 
1908 	sal_Bool bTemp1,bTemp2;
1909 	uno::Any aBarsH,aBarsV;
1910 	switch(nScrollBars)
1911 	{
1912 		case 1:
1913 			bTemp1 = sal_True;
1914 			bTemp2 = sal_False;
1915 			break;
1916 		case 2:
1917 			bTemp1 = sal_False;
1918 			bTemp2 = sal_True;
1919 			break;
1920 		case 3:
1921 			bTemp1 = sal_True;
1922 			bTemp2 = sal_True;
1923 			break;
1924 		case 0:
1925 		default:
1926 			bTemp1 = sal_False;
1927 			bTemp2 = sal_False;
1928 			break;
1929 	}
1930 
1931 	aBarsH = bool2any(bTemp1);
1932 	aBarsV = bool2any(bTemp2);
1933 	rPropSet->setPropertyValue( WW8_ASCII2STR("HScroll"), aBarsH);
1934 	rPropSet->setPropertyValue( WW8_ASCII2STR("VScroll"), aBarsV);
1935 
1936 	nTmp = nPasswordChar;
1937 	aTmp <<= nTmp;
1938 	rPropSet->setPropertyValue( WW8_ASCII2STR("EchoChar"), aTmp);
1939 
1940 	if (pValue)
1941 	{
1942         aTmp <<= lclCreateOUString( pValue, nValueLen );
1943         // DefaultText seems to no longer be in UnoEditControlModel
1944         if ( bSetInDialog )
1945         {
1946 		    rPropSet->setPropertyValue( WW8_ASCII2STR("Text"), aTmp);
1947         }
1948         else
1949         {
1950 		    rPropSet->setPropertyValue( WW8_ASCII2STR("DefaultText"), aTmp);
1951         }
1952 	}
1953 
1954 	aFontData.Import(rPropSet);
1955 	return sal_True;
1956 }
1957 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)1958 sal_Bool OCX_TextBox::WriteContents(SvStorageStreamRef &rContents,
1959 	const uno::Reference< beans::XPropertySet > &rPropSet,
1960 	const awt::Size &rSize)
1961 {
1962 	sal_Bool bRet=sal_True;
1963     sal_uInt32 nOldPos = rContents->Tell();
1964 	rContents->SeekRel(12);
1965 
1966 	pBlockFlags[0] = 0;
1967 	pBlockFlags[1] = 0x01;
1968 	pBlockFlags[2] = 0x00;
1969 	pBlockFlags[3] = 0x80;
1970 	pBlockFlags[4] = 0;
1971 	pBlockFlags[5] = 0;
1972 	pBlockFlags[6] = 0;
1973 	pBlockFlags[7] = 0;
1974 
1975 
1976 	sal_uInt8 nTemp=0x19;
1977 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
1978 	fEnabled = any2bool(aTmp);
1979 	if (fEnabled)
1980 		nTemp |= 0x02;
1981 
1982 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("ReadOnly"));
1983 	fLocked = any2bool(aTmp);
1984 	if (fLocked)
1985 		nTemp |= 0x04;
1986 
1987 	*rContents << nTemp;
1988 	pBlockFlags[0] |= 0x01;
1989 	*rContents << sal_uInt8(0x48);
1990     *rContents << sal_uInt8(0x80);
1991 
1992     fMultiLine = any2bool(rPropSet->getPropertyValue(WW8_ASCII2STR("MultiLine")));
1993     fHideSelection = any2bool(rPropSet->getPropertyValue(WW8_ASCII2STR("HideInactiveSelection")));
1994     nTemp = 0x0C;
1995 	if (fMultiLine)
1996 		nTemp |= 0x80;
1997     if( fHideSelection )
1998         nTemp |= 0x20;
1999 	*rContents << nTemp;
2000 
2001 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
2002     if (aTmp.hasValue())
2003 	    aTmp >>= mnBackColor;
2004 	*rContents << ExportColor(mnBackColor);
2005 	pBlockFlags[0] |= 0x02;
2006 
2007 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
2008     if (aTmp.hasValue())
2009 	    aTmp >>= mnForeColor;
2010 	*rContents << ExportColor(mnForeColor);
2011 	pBlockFlags[0] |= 0x04;
2012 
2013 	aTmp = rPropSet->getPropertyValue( WW8_ASCII2STR("MaxTextLen"));
2014 	aTmp >>= nMaxLength;
2015 	*rContents << nMaxLength;
2016 	pBlockFlags[0] |= 0x08;
2017 
2018 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Border"));
2019 	sal_Int16 nBorder = sal_Int16();
2020 	aTmp >>= nBorder;
2021 	nSpecialEffect = ExportBorder(nBorder,nBorderStyle);
2022 	*rContents << nBorderStyle;
2023 	pBlockFlags[0] |= 0x10;
2024 
2025 	aTmp = rPropSet->getPropertyValue( WW8_ASCII2STR("HScroll"));
2026 	sal_Bool bTemp1 = any2bool(aTmp);
2027 	aTmp = rPropSet->getPropertyValue( WW8_ASCII2STR("VScroll"));
2028 	sal_Bool bTemp2 = any2bool(aTmp);
2029 	if (!bTemp1 && !bTemp2)
2030 		nScrollBars =0;
2031 	else if (bTemp1 && bTemp2)
2032 		nScrollBars = 3;
2033 	else if (!bTemp1 && bTemp2)
2034 		nScrollBars = 2;
2035 	else
2036 		nScrollBars = 1;
2037 	*rContents << nScrollBars;
2038 	pBlockFlags[0] |= 0x20;
2039 
2040 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("EchoChar"));
2041 	sal_uInt16 nTmp = sal_uInt16();
2042 	aTmp >>= nTmp;
2043 	nPasswordChar = static_cast<sal_uInt8>(nTmp);
2044 	*rContents << nPasswordChar;
2045 	pBlockFlags[1] |= 0x02;
2046 
2047     SvxOcxString aValue( rPropSet->getPropertyValue(WW8_ASCII2STR("DefaultText")) );
2048     aValue.WriteLenField( *rContents );
2049     if (aValue.HasData())
2050 		pBlockFlags[2] |= 0x40;
2051 
2052 	WriteAlign(rContents,4);
2053     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BorderColor"));
2054     if (aTmp.hasValue())
2055         aTmp >>= nBorderColor;
2056     *rContents << ExportColor(nBorderColor);
2057     pBlockFlags[3] |= 0x02;
2058 
2059 	*rContents << nSpecialEffect;
2060 	pBlockFlags[3] |= 0x04;
2061 
2062 	WriteAlign(rContents,4);
2063 	*rContents << rSize.Width;
2064 	*rContents << rSize.Height;
2065 
2066     aValue.WriteCharArray( *rContents );
2067 
2068 	WriteAlign(rContents,4);
2069 
2070     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
2071 
2072 	bRet = aFontData.Export(rContents,rPropSet);
2073 
2074     rContents->Seek(nOldPos);
2075 	*rContents << nStandardId;
2076 	*rContents << nFixedAreaLen;
2077 
2078 	*rContents << pBlockFlags[0];
2079 	*rContents << pBlockFlags[1];
2080 	*rContents << pBlockFlags[2];
2081 	*rContents << pBlockFlags[3];
2082 	*rContents << pBlockFlags[4];
2083 	*rContents << pBlockFlags[5];
2084 	*rContents << pBlockFlags[6];
2085 	*rContents << pBlockFlags[7];
2086 
2087 	DBG_ASSERT((rContents.Is() &&
2088 		(SVSTREAM_OK == rContents->GetError())),"damn");
2089 	return bRet;
2090 }
2091 
2092 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2093 sal_Bool OCX_TextBox::Export(SvStorageRef &rObj,
2094 	const uno::Reference< beans::XPropertySet > &rPropSet,
2095 	const awt::Size &rSize)
2096 {
2097 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
2098 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2099 		0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x1D, 0xD2, 0x8B,
2100 		0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
2101 		0x00, 0x60, 0x02, 0xF3, 0x1C, 0x00, 0x00, 0x00,
2102 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2103 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2104 		0x32, 0x2E, 0x30, 0x20, 0x54, 0x65, 0x78, 0x74,
2105 		0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00, 0x00,
2106 		0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64,
2107 		0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
2108 		0x10, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D,
2109 		0x73, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x42, 0x6F,
2110 		0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71,
2111 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2112 		0x00, 0x00, 0x00, 0x00
2113 		};
2114 
2115 	{
2116 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
2117 	xStor->Write(aCompObj,sizeof(aCompObj));
2118 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
2119 	}
2120 
2121 	{
2122 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
2123 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
2124 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
2125 	}
2126 
2127 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
2128 		0x54, 0x00, 0x65, 0x00, 0x78, 0x00, 0x74, 0x00,
2129 		0x42, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x31, 0x00,
2130 		0x00, 0x00, 0x00, 0x00
2131 		};
2132 
2133 	{
2134 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
2135 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
2136 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
2137 	}
2138 
2139 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
2140 	return WriteContents(xContents, rPropSet, rSize);
2141 }
2142 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2143 sal_Bool OCX_FieldControl::WriteContents(SvStorageStreamRef &rContents,
2144 	const uno::Reference< beans::XPropertySet > &rPropSet,
2145 	const awt::Size &rSize)
2146 {
2147 	sal_Bool bRet=sal_True;
2148     sal_uInt32 nOldPos = rContents->Tell();
2149 	rContents->SeekRel(12);
2150 
2151 	pBlockFlags[0] = 0;
2152 	pBlockFlags[1] = 0x01;
2153 	pBlockFlags[2] = 0x00;
2154 	pBlockFlags[3] = 0x80;
2155 	pBlockFlags[4] = 0;
2156 	pBlockFlags[5] = 0;
2157 	pBlockFlags[6] = 0;
2158 	pBlockFlags[7] = 0;
2159 
2160 
2161 	sal_uInt8 nTemp=0x19;
2162 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
2163 	fEnabled = any2bool(aTmp);
2164 	if (fEnabled)
2165 		nTemp |= 0x02;
2166 
2167 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("ReadOnly"));
2168 	fLocked = any2bool(aTmp);
2169 	if (fLocked)
2170 		nTemp |= 0x04;
2171 
2172 	*rContents << nTemp;
2173 	pBlockFlags[0] |= 0x01;
2174 	*rContents << sal_uInt8(0x48);
2175 	*rContents << sal_uInt8(0x80);
2176 
2177 	nTemp = 0x2C;
2178 	*rContents << nTemp;
2179 
2180 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
2181     if (aTmp.hasValue())
2182 	    aTmp >>= mnBackColor;
2183 	*rContents << ExportColor(mnBackColor);
2184 	pBlockFlags[0] |= 0x02;
2185 
2186 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
2187     if (aTmp.hasValue())
2188 	    aTmp >>= mnForeColor;
2189 	*rContents << ExportColor(mnForeColor);
2190 	pBlockFlags[0] |= 0x04;
2191 
2192 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Border"));
2193 	sal_Int16 nBorder = sal_Int16();
2194 	aTmp >>= nBorder;
2195 	nSpecialEffect = ExportBorder(nBorder,nBorderStyle);
2196 	*rContents << nBorderStyle;
2197 	pBlockFlags[0] |= 0x10;
2198 
2199 #if 0 //Each control has a different Value format, and how to convert each to text has to be found out
2200     SvxOcxString aValue( rPropSet->getPropertyValue(WW8_ASCII2STR("DefaultText")) );
2201     aValue.WriteLenField( *rContents );
2202     if (aValue.HasData())
2203 		pBlockFlags[2] |= 0x40;
2204 #endif
2205 
2206 	*rContents << nSpecialEffect;
2207 	pBlockFlags[3] |= 0x04;
2208 
2209 	WriteAlign(rContents,4);
2210 	*rContents << rSize.Width;
2211 	*rContents << rSize.Height;
2212 
2213 #if 0
2214     aValue.WriteCharArray( *rContents );
2215 #endif
2216 
2217 	WriteAlign(rContents,4);
2218 
2219     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
2220 
2221 	bRet = aFontData.Export(rContents,rPropSet);
2222 
2223     rContents->Seek(nOldPos);
2224 	*rContents << nStandardId;
2225 	*rContents << nFixedAreaLen;
2226 
2227 	*rContents << pBlockFlags[0];
2228 	*rContents << pBlockFlags[1];
2229 	*rContents << pBlockFlags[2];
2230 	*rContents << pBlockFlags[3];
2231 	*rContents << pBlockFlags[4];
2232 	*rContents << pBlockFlags[5];
2233 	*rContents << pBlockFlags[6];
2234 	*rContents << pBlockFlags[7];
2235 
2236 	DBG_ASSERT((rContents.Is() &&
2237 		(SVSTREAM_OK==rContents->GetError())),"damn");
2238 	return bRet;
2239 }
2240 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2241 sal_Bool OCX_FieldControl::Export(SvStorageRef &rObj,
2242 	const uno::Reference< beans::XPropertySet > &rPropSet,
2243 	const awt::Size &rSize)
2244 {
2245 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
2246 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2247 		0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x1D, 0xD2, 0x8B,
2248 		0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
2249 		0x00, 0x60, 0x02, 0xF3, 0x1C, 0x00, 0x00, 0x00,
2250 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2251 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2252 		0x32, 0x2E, 0x30, 0x20, 0x54, 0x65, 0x78, 0x74,
2253 		0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00, 0x00,
2254 		0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64,
2255 		0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
2256 		0x10, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D,
2257 		0x73, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x42, 0x6F,
2258 		0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71,
2259 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2260 		0x00, 0x00, 0x00, 0x00
2261 		};
2262 
2263 	{
2264 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
2265 	xStor->Write(aCompObj,sizeof(aCompObj));
2266 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
2267 	}
2268 
2269 	{
2270 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
2271 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
2272 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
2273 	}
2274 
2275 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
2276 		0x54, 0x00, 0x65, 0x00, 0x78, 0x00, 0x74, 0x00,
2277 		0x42, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x31, 0x00,
2278 		0x00, 0x00, 0x00, 0x00
2279 		};
2280 
2281 	{
2282 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
2283 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
2284 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
2285 	}
2286 
2287 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
2288 	return WriteContents(xContents, rPropSet, rSize);
2289 }
2290 
2291 
2292 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)2293 sal_Bool OCX_ToggleButton::Import(com::sun::star::uno::Reference<
2294     com::sun::star::beans::XPropertySet> &rPropSet)
2295 {
2296 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
2297 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
2298 
2299     aTmp = bool2any(true);
2300     rPropSet->setPropertyValue( WW8_ASCII2STR("Toggle"), aTmp );
2301 
2302 	sal_Bool bTemp;
2303 	if ((!(fEnabled)) || (fLocked))
2304 		bTemp = sal_False;
2305 	else
2306 		bTemp = sal_True;
2307 	aTmp = bool2any(bTemp);
2308 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
2309 
2310     bTemp = fWordWrap != 0;
2311     aTmp = bool2any(bTemp);
2312     rPropSet->setPropertyValue( WW8_ASCII2STR("MultiLine"), aTmp);
2313 
2314 	aTmp <<= ImportColor(mnForeColor);
2315 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
2316 
2317     // fake transparent toggle button by setting window background color
2318     if( !fBackStyle )
2319         mnBackColor = 0x80000005;
2320     aTmp <<= ImportColor(mnBackColor);
2321     rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
2322 
2323 	if (pValue)
2324 	{
2325 		sal_Int16 nTmp=pValue[0]-0x30;
2326         aTmp <<= nTmp == 1;
2327         rPropSet->setPropertyValue( WW8_ASCII2STR("DefaultState"), aTmp);
2328 	}
2329 
2330 	if (pCaption)
2331 	{
2332         aTmp <<= lclCreateOUString( pCaption, nCaptionLen );
2333 		rPropSet->setPropertyValue( WW8_ASCII2STR("Label"), aTmp);
2334 	}
2335 
2336 	aFontData.Import(rPropSet);
2337 	return sal_True;
2338 }
2339 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2340 sal_Bool OCX_ToggleButton::Export(
2341     SvStorageRef &rObj, const uno::Reference< beans::XPropertySet> &rPropSet,
2342     const awt::Size& rSize )
2343 {
2344     static sal_uInt8 __READONLY_DATA aCompObj[] = {
2345             0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2346             0xFF, 0xFF, 0xFF, 0xFF, 0x60, 0x1D, 0xD2, 0x8B,
2347             0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
2348             0x00, 0x60, 0x02, 0xF3, 0x21, 0x00, 0x00, 0x00,
2349             0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2350             0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2351             0x32, 0x2E, 0x30, 0x20, 0x54, 0x6F, 0x67, 0x67,
2352             0x6C, 0x65, 0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E,
2353             0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D, 0x62,
2354             0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F, 0x62,
2355             0x6A, 0x65, 0x63, 0x74, 0x00, 0x15, 0x00, 0x00,
2356             0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E, 0x54,
2357             0x6F, 0x67, 0x67, 0x6C, 0x65, 0x42, 0x75, 0x74,
2358             0x74, 0x6F, 0x6E, 0x2E, 0x31, 0x00, 0xF4, 0x39,
2359             0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2360             0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2361         };
2362 
2363     {
2364     SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
2365     xStor->Write(aCompObj,sizeof(aCompObj));
2366     DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
2367     }
2368 
2369     {
2370     SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
2371     xStor3->Write(aObjInfo,sizeof(aObjInfo));
2372     DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
2373     }
2374 
2375     static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
2376         0x54, 0x00, 0x6F, 0x00, 0x67, 0x00, 0x67, 0x00,
2377         0x6C, 0x00, 0x65, 0x00, 0x42, 0x00, 0x75, 0x00,
2378         0x74, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x6E, 0x00,
2379         0x31, 0x00, 0x00, 0x00, 0x00, 0x00
2380     };
2381 
2382     {
2383     SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
2384     xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
2385     DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
2386     }
2387 
2388     SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
2389 
2390     return WriteContents(xContents,rPropSet,rSize);
2391 }
2392 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2393 sal_Bool OCX_ToggleButton::WriteContents(SvStorageStreamRef &rContents,
2394     const uno::Reference< beans::XPropertySet > &rPropSet,
2395     const awt::Size &rSize)
2396 {
2397     sal_Bool bRet=sal_True;
2398     sal_uInt32 nOldPos = rContents->Tell();
2399     rContents->SeekRel(12);
2400 
2401     pBlockFlags[0] = 0;
2402     pBlockFlags[1] = 0x01;
2403     pBlockFlags[2] = 0;
2404     pBlockFlags[3] = 0x80;
2405     pBlockFlags[4] = 0;
2406     pBlockFlags[5] = 0;
2407     pBlockFlags[6] = 0;
2408     pBlockFlags[7] = 0;
2409 
2410     uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
2411     fEnabled = any2bool(aTmp);
2412 
2413     sal_uInt8 nTemp=fEnabled;
2414     if (fEnabled)
2415         nTemp = nTemp << 1;
2416     if (fBackStyle)
2417         nTemp |= 0x08;
2418     *rContents << nTemp;
2419     pBlockFlags[0] |= 0x01;
2420     *rContents << sal_uInt8(0x00);
2421     nTemp = 0;
2422     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("MultiLine"));
2423     fWordWrap = any2bool(aTmp);
2424     if (fWordWrap)
2425         nTemp |= 0x80;
2426     *rContents << nTemp;
2427     *rContents << sal_uInt8(0x00);
2428 
2429     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
2430     if (aTmp.hasValue())
2431         aTmp >>= mnBackColor;
2432     *rContents << ExportColor(mnBackColor);
2433     pBlockFlags[0] |= 0x02;
2434 
2435     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
2436     if (aTmp.hasValue())
2437         aTmp >>= mnForeColor;
2438     *rContents << ExportColor(mnForeColor);
2439     pBlockFlags[0] |= 0x04;
2440 
2441     nStyle = 6;
2442     *rContents << nStyle;
2443     pBlockFlags[0] |= 0x40;
2444 
2445     WriteAlign(rContents,4);
2446     nValueLen = 1|SVX_MSOCX_COMPRESSED;
2447     bool bDefault = false;
2448     rPropSet->getPropertyValue(WW8_ASCII2STR("DefaultState")) >>= bDefault;
2449     sal_uInt8 nDefault = static_cast< sal_uInt8 >( bDefault ? '1' : '0' );
2450     *rContents << nValueLen;
2451     pBlockFlags[2] |= 0x40;
2452 
2453     SvxOcxString aCaption( rPropSet->getPropertyValue(WW8_ASCII2STR("Label")) );
2454     aCaption.WriteLenField( *rContents );
2455     if (aCaption.HasData())
2456         pBlockFlags[2] |= 0x80;
2457 
2458     WriteAlign(rContents,4);
2459     *rContents << rSize.Width;
2460     *rContents << rSize.Height;
2461 
2462     *rContents << nDefault;
2463     *rContents << sal_uInt8(0x00);
2464 
2465     aCaption.WriteCharArray( *rContents );
2466 
2467     WriteAlign(rContents,4);
2468     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
2469     bRet = aFontData.Export(rContents,rPropSet);
2470     rContents->Seek(nOldPos);
2471     *rContents << nStandardId;
2472     *rContents << nFixedAreaLen;
2473 
2474     *rContents << pBlockFlags[0];
2475     *rContents << pBlockFlags[1];
2476     *rContents << pBlockFlags[2];
2477     *rContents << pBlockFlags[3];
2478     *rContents << pBlockFlags[4];
2479     *rContents << pBlockFlags[5];
2480     *rContents << pBlockFlags[6];
2481     *rContents << pBlockFlags[7];
2482 
2483     DBG_ASSERT((rContents.Is() &&
2484         (SVSTREAM_OK==rContents->GetError())),"damn");
2485     return bRet;
2486 }
2487 
Import(uno::Reference<beans::XPropertySet> & rPropSet)2488 sal_Bool OCX_Label::Import(uno::Reference< beans::XPropertySet > &rPropSet)
2489 {
2490 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
2491 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
2492 
2493 	sal_Bool bTemp;
2494 	if ((!(fEnabled)) || (fLocked))
2495 		bTemp = sal_False;
2496 	else
2497 		bTemp = sal_True;
2498 	aTmp = bool2any(bTemp);
2499 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
2500 
2501 	aTmp <<= ImportColor(mnForeColor);
2502 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
2503 
2504     // background color: fBackStyle==0 -> transparent
2505     if( fBackStyle )
2506     {
2507         aTmp <<= ImportColor(mnBackColor);
2508     }
2509     else
2510     {
2511         // try fake transparent by using parents backColor
2512         if ( bSetInDialog && mpParent != NULL )
2513         {
2514             aTmp <<= ImportColor( mpParent->mnBackColor );
2515         }
2516         else
2517         {
2518             aTmp = uno::Any(); // use SO default
2519         }
2520     }
2521     rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
2522 
2523 	aTmp <<= ImportBorder(nSpecialEffect,nBorderStyle);
2524 	rPropSet->setPropertyValue( WW8_ASCII2STR("Border"), aTmp);
2525 
2526     aTmp <<= ImportColor( nBorderColor );
2527     rPropSet->setPropertyValue( WW8_ASCII2STR("BorderColor"), aTmp);
2528 
2529 	bTemp=fWordWrap;
2530 	aTmp = bool2any(bTemp);
2531 	rPropSet->setPropertyValue( WW8_ASCII2STR("MultiLine"), aTmp);
2532 
2533 	if (pCaption)
2534 	{
2535         aTmp <<= lclCreateOUString( pCaption, nCaptionLen );
2536 		rPropSet->setPropertyValue( WW8_ASCII2STR("Label"), aTmp);
2537 	}
2538 
2539 	aFontData.Import(rPropSet);
2540 	return sal_True;
2541 }
2542 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)2543 sal_Bool OCX_ComboBox::Import(com::sun::star::uno::Reference<
2544     com::sun::star::beans::XPropertySet> &rPropSet)
2545 {
2546 
2547 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
2548 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
2549 
2550     aTmp = bool2any(fEnabled != 0);
2551 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
2552 
2553     aTmp = bool2any(fLocked != 0);
2554 	rPropSet->setPropertyValue( WW8_ASCII2STR("ReadOnly"), aTmp);
2555 
2556     aTmp = bool2any( nDropButtonStyle != 0 );
2557 	rPropSet->setPropertyValue( WW8_ASCII2STR("Dropdown"), aTmp);
2558 
2559     aTmp = bool2any( fHideSelection != 0 );
2560     rPropSet->setPropertyValue( WW8_ASCII2STR( "HideInactiveSelection" ), aTmp);
2561 
2562 	aTmp <<= ImportColor(mnForeColor);
2563 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
2564 
2565 	if (pValue)
2566     {
2567         aTmp <<= lclCreateOUString( pValue, nValueLen );
2568         if ( bSetInDialog )
2569         {
2570             rPropSet->setPropertyValue( WW8_ASCII2STR("Text"), aTmp);
2571         }
2572         else
2573         {
2574             rPropSet->setPropertyValue( WW8_ASCII2STR("DefaultText"), aTmp);
2575         }
2576     }
2577 
2578 	aTmp <<= ImportColor(mnBackColor);
2579 	rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
2580 
2581 	aTmp <<= ImportBorder(nSpecialEffect,nBorderStyle);
2582 	rPropSet->setPropertyValue( WW8_ASCII2STR("Border"), aTmp);
2583 
2584     aTmp <<= ImportColor( nBorderColor );
2585     rPropSet->setPropertyValue( WW8_ASCII2STR("BorderColor"), aTmp);
2586 
2587 	sal_Int16 nTmp=static_cast<sal_Int16>(nMaxLength);
2588 	aTmp <<= nTmp;
2589 	rPropSet->setPropertyValue( WW8_ASCII2STR("MaxTextLen"), aTmp);
2590 
2591 	aFontData.Import(rPropSet);
2592 	return sal_True;
2593 }
2594 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2595 sal_Bool OCX_ComboBox::WriteContents(SvStorageStreamRef &rContents,
2596 	const uno::Reference< beans::XPropertySet > &rPropSet,
2597 	const awt::Size &rSize)
2598 {
2599 	sal_Bool bRet=sal_True;
2600     sal_uInt32 nOldPos = rContents->Tell();
2601 	rContents->SeekRel(12);
2602 
2603 	pBlockFlags[0] = 0;
2604 	pBlockFlags[1] = 0x01;
2605 	pBlockFlags[2] = 0x00;
2606 	pBlockFlags[3] = 0x80;
2607 	pBlockFlags[4] = 0;
2608 	pBlockFlags[5] = 0;
2609 	pBlockFlags[6] = 0;
2610 	pBlockFlags[7] = 0;
2611 
2612 
2613 	sal_uInt8 nTemp=0x19;//fEnabled;
2614 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
2615 	fEnabled = any2bool(aTmp);
2616 	if (fEnabled)
2617 		nTemp |= 0x02;
2618 
2619 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("ReadOnly"));
2620 	fLocked = any2bool(aTmp);
2621 	if (fLocked)
2622 		nTemp |= 0x04;
2623 
2624 	*rContents << nTemp;
2625 	pBlockFlags[0] |= 0x01;
2626 	*rContents << sal_uInt8(0x48);
2627 	*rContents << sal_uInt8(0x80);
2628 
2629     nTemp = 0x0C;
2630     fHideSelection = any2bool(rPropSet->getPropertyValue(WW8_ASCII2STR("HideInactiveSelection")));
2631     if( fHideSelection )
2632         nTemp |= 0x20;
2633     *rContents << nTemp;
2634 
2635 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
2636     if (aTmp.hasValue())
2637 	    aTmp >>= mnBackColor;
2638 	*rContents << ExportColor(mnBackColor);
2639 	pBlockFlags[0] |= 0x02;
2640 
2641 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
2642     if (aTmp.hasValue())
2643 	    aTmp >>= mnForeColor;
2644 	*rContents << ExportColor(mnForeColor);
2645 	pBlockFlags[0] |= 0x04;
2646 
2647 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Border"));
2648 	sal_Int16 nBorder = sal_Int16();
2649 	aTmp >>= nBorder;
2650 	nSpecialEffect = ExportBorder(nBorder,nBorderStyle);
2651 	*rContents << nBorderStyle;
2652 	pBlockFlags[0] |= 0x10;
2653 
2654 	nStyle = 3;
2655 	*rContents << nStyle;
2656 	pBlockFlags[0] |= 0x40;
2657 
2658 	WriteAlign(rContents,2);
2659 
2660 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("LineCount"));
2661 	aTmp >>= nListRows;
2662 	*rContents << nListRows;
2663 	pBlockFlags[1] |= 0x40;
2664 
2665 	*rContents << sal_uInt8(1); //DefaultSelected One
2666 	pBlockFlags[2] |= 0x01;
2667 
2668 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Dropdown"));
2669 	nDropButtonStyle = any2bool(aTmp);
2670 	if (nDropButtonStyle)
2671 		nDropButtonStyle=0x02;
2672 	*rContents << nDropButtonStyle;
2673 	pBlockFlags[2] |= 0x04;
2674 
2675     SvxOcxString aValue( rPropSet->getPropertyValue(WW8_ASCII2STR("Text")) );
2676     aValue.WriteLenField( *rContents );
2677     if (aValue.HasData())
2678 		pBlockFlags[2] |= 0x40;
2679 
2680 	WriteAlign(rContents,4);
2681     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BorderColor"));
2682     if (aTmp.hasValue())
2683         aTmp >>= nBorderColor;
2684     *rContents << ExportColor(nBorderColor);
2685     pBlockFlags[3] |= 0x02;
2686 
2687 	*rContents << nSpecialEffect;
2688 	pBlockFlags[3] |= 0x04;
2689 
2690 	WriteAlign(rContents,4);
2691 	*rContents << rSize.Width;
2692 	*rContents << rSize.Height;
2693 
2694     aValue.WriteCharArray( *rContents );
2695 
2696 	WriteAlign(rContents,4);
2697 
2698     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
2699 
2700 	bRet = aFontData.Export(rContents,rPropSet);
2701 
2702     rContents->Seek(nOldPos);
2703 	*rContents << nStandardId;
2704 	*rContents << nFixedAreaLen;
2705 
2706 	*rContents << pBlockFlags[0];
2707 	*rContents << pBlockFlags[1];
2708 	*rContents << pBlockFlags[2];
2709 	*rContents << pBlockFlags[3];
2710 	*rContents << pBlockFlags[4];
2711 	*rContents << pBlockFlags[5];
2712 	*rContents << pBlockFlags[6];
2713 	*rContents << pBlockFlags[7];
2714 
2715 	DBG_ASSERT((rContents.Is() &&
2716 		(SVSTREAM_OK==rContents->GetError())),"damn");
2717 	return bRet;
2718 }
2719 
2720 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2721 sal_Bool OCX_ComboBox::Export(SvStorageRef &rObj,
2722 	const uno::Reference< beans::XPropertySet > &rPropSet,
2723 	const awt::Size &rSize)
2724 {
2725 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
2726 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2727 		0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x1D, 0xD2, 0x8B,
2728 		0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
2729 		0x00, 0x60, 0x02, 0xF3, 0x1D, 0x00, 0x00, 0x00,
2730 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2731 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2732 		0x32, 0x2E, 0x30, 0x20, 0x43, 0x6F, 0x6D, 0x62,
2733 		0x6F, 0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00,
2734 		0x00, 0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65,
2735 		0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74,
2736 		0x00, 0x11, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72,
2737 		0x6D, 0x73, 0x2E, 0x43, 0x6F, 0x6D, 0x62, 0x6F,
2738 		0x42, 0x6F, 0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39,
2739 		0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2740 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2741 		};
2742 
2743 	{
2744 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
2745 	xStor->Write(aCompObj,sizeof(aCompObj));
2746 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
2747 	}
2748 
2749 	{
2750 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
2751 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
2752 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
2753 	}
2754 
2755 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
2756 		0x43, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x62, 0x00,
2757 		0x6F, 0x00, 0x42, 0x00, 0x6F, 0x00, 0x78, 0x00,
2758 		0x31, 0x00, 0x00, 0x00, 0x00, 0x00
2759 	};
2760 
2761 	{
2762 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
2763 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
2764 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
2765 	}
2766 
2767 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
2768 	return WriteContents(xContents, rPropSet, rSize);
2769 }
2770 
2771 
2772 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)2773 sal_Bool OCX_ListBox::Import(com::sun::star::uno::Reference<
2774     com::sun::star::beans::XPropertySet> &rPropSet)
2775 {
2776 
2777 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
2778 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
2779 
2780 	sal_Bool bTmp=fEnabled;
2781 	aTmp = bool2any(bTmp);
2782 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
2783 
2784 	bTmp=fLocked;
2785 	aTmp = bool2any(bTmp);
2786 	rPropSet->setPropertyValue( WW8_ASCII2STR("ReadOnly"), aTmp);
2787 
2788 	aTmp <<= ImportColor(mnForeColor);
2789 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
2790 
2791 	sal_Bool bTemp = nMultiState;
2792 	aTmp = bool2any(bTemp);
2793 	rPropSet->setPropertyValue( WW8_ASCII2STR("MultiSelection"), aTmp);
2794 
2795 #if 0		//Don't delete this for now until I figure out if I can make this
2796 	if (pValue)
2797     {
2798         aTmp <<= lclCreateOUString( pValue, nValueLen );
2799         xPropSet->setPropertyValue( WW8_ASCII2STR("DefaultText"), aTmp);
2800     }
2801 #endif
2802 
2803 	aTmp <<= ImportColor(mnBackColor);
2804 	rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
2805 
2806 	aTmp <<= ImportBorder(nSpecialEffect,nBorderStyle);
2807 	rPropSet->setPropertyValue( WW8_ASCII2STR("Border"), aTmp);
2808 
2809     aTmp <<= ImportColor( nBorderColor );
2810     rPropSet->setPropertyValue( WW8_ASCII2STR("BorderColor"), aTmp);
2811 
2812 	aFontData.Import(rPropSet);
2813 	return sal_True;
2814 }
2815 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2816 sal_Bool OCX_ListBox::WriteContents(SvStorageStreamRef &rContents,
2817 	const uno::Reference< beans::XPropertySet > &rPropSet,
2818 	const awt::Size &rSize)
2819 {
2820 	sal_Bool bRet=sal_True;
2821     sal_uInt32 nOldPos = rContents->Tell();
2822 	rContents->SeekRel(12);
2823 
2824 	pBlockFlags[0] = 0;
2825 	pBlockFlags[1] = 0x01;
2826 	pBlockFlags[2] = 0x01;
2827 	pBlockFlags[3] = 0x80;
2828 	pBlockFlags[4] = 0;
2829 	pBlockFlags[5] = 0;
2830 	pBlockFlags[6] = 0;
2831 	pBlockFlags[7] = 0;
2832 
2833 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
2834 	fEnabled = any2bool(aTmp);
2835 	sal_uInt8 nTemp=fEnabled;
2836 	if (fEnabled)
2837 		nTemp = nTemp << 1;
2838 
2839 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("ReadOnly"));
2840 	fLocked = any2bool(aTmp);
2841 	if (fLocked)
2842 		nTemp |= 0x04;
2843 
2844 	*rContents << nTemp;
2845 	pBlockFlags[0] |= 0x01;
2846 	*rContents << sal_uInt8(0x00);
2847 	*rContents << sal_uInt8(0x00);
2848 	*rContents << sal_uInt8(0x00);
2849 
2850 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
2851     if (aTmp.hasValue())
2852 	    aTmp >>= mnBackColor;
2853 	*rContents << ExportColor(mnBackColor);
2854 	pBlockFlags[0] |= 0x02;
2855 
2856 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
2857     if (aTmp.hasValue())
2858 	    aTmp >>= mnForeColor;
2859 	*rContents << ExportColor(mnForeColor);
2860 	pBlockFlags[0] |= 0x04;
2861 
2862     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Border"));
2863     sal_Int16 nBorder = sal_Int16();
2864     aTmp >>= nBorder;
2865     nSpecialEffect = ExportBorder(nBorder,nBorderStyle);
2866     WriteAlign(rContents,2);
2867     *rContents << nBorderStyle;
2868     pBlockFlags[0] |= 0x10;
2869 
2870 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("MultiSelection"));
2871 	nMultiState = any2bool(aTmp);
2872 
2873 	if (nMultiState)
2874 	{
2875 		*rContents << nMultiState;
2876 		pBlockFlags[0] |= 0x20;
2877 	}
2878 
2879 	nStyle = 2;
2880 	*rContents << nStyle;
2881 	pBlockFlags[0] |= 0x40;
2882 
2883 
2884 	WriteAlign(rContents,4);
2885 
2886 #if 0
2887     SvxOcxString aValue( rPropSet->getPropertyValue(WW8_ASCII2STR("DefaultText")) );
2888     aValue.WriteLenField( *rContents );
2889     if (aValue.HasData())
2890 		pBlockFlags[2] |= 0x40;
2891 
2892 	WriteAlign(rContents,4);
2893 #endif
2894 
2895     WriteAlign(rContents,4);
2896     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BorderColor"));
2897     if (aTmp.hasValue())
2898         aTmp >>= nBorderColor;
2899     *rContents << ExportColor(nBorderColor);
2900     pBlockFlags[3] |= 0x02;
2901 
2902     *rContents << nSpecialEffect;
2903     pBlockFlags[3] |= 0x04;
2904 
2905     WriteAlign(rContents,4);
2906 	*rContents << rSize.Width;
2907 	*rContents << rSize.Height;
2908 
2909 #if 0
2910     aValue.WriteCharArray( *rContents );
2911 #endif
2912 
2913 	WriteAlign(rContents,4);
2914 
2915     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
2916 
2917 	bRet = aFontData.Export(rContents,rPropSet);
2918 
2919     rContents->Seek(nOldPos);
2920 	*rContents << nStandardId;
2921 	*rContents << nFixedAreaLen;
2922 
2923 	*rContents << pBlockFlags[0];
2924 	*rContents << pBlockFlags[1];
2925 	*rContents << pBlockFlags[2];
2926 	*rContents << pBlockFlags[3];
2927 	*rContents << pBlockFlags[4];
2928 	*rContents << pBlockFlags[5];
2929 	*rContents << pBlockFlags[6];
2930 	*rContents << pBlockFlags[7];
2931 
2932 	DBG_ASSERT((rContents.Is() &&
2933 		(SVSTREAM_OK==rContents->GetError())),"damn");
2934 	return bRet;
2935 }
2936 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)2937 sal_Bool OCX_ListBox::Export(SvStorageRef &rObj,
2938 	const uno::Reference< beans::XPropertySet > &rPropSet,
2939 	const awt::Size &rSize)
2940 {
2941 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
2942 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2943 		0xFF, 0xFF, 0xFF, 0xFF, 0x20, 0x1D, 0xD2, 0x8B,
2944 		0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
2945 		0x00, 0x60, 0x02, 0xF3, 0x1C, 0x00, 0x00, 0x00,
2946 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2947 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2948 		0x32, 0x2E, 0x30, 0x20, 0x4C, 0x69, 0x73, 0x74,
2949 		0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00, 0x00,
2950 		0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64,
2951 		0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
2952 		0x10, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D,
2953 		0x73, 0x2E, 0x4C, 0x69, 0x73, 0x74, 0x42, 0x6F,
2954 		0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71,
2955 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2956 		0x00, 0x00, 0x00, 0x00
2957 		};
2958 
2959 	{
2960 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
2961 	xStor->Write(aCompObj,sizeof(aCompObj));
2962 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
2963 	}
2964 
2965 	{
2966 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
2967 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
2968 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
2969 	}
2970 
2971 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
2972 		0x4C, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74, 0x00,
2973 		0x42, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x31, 0x00,
2974 		0x00, 0x00, 0x00, 0x00
2975 		};
2976 
2977 	{
2978 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
2979 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
2980 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
2981 	}
2982 
2983 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
2984 	return WriteContents(xContents, rPropSet, rSize);
2985 }
2986 
Read(SvStorageStream * pS)2987 sal_Bool OCX_Control::Read(SvStorageStream *pS)
2988 {
2989     sal_uInt16 nIdentifier, nFixedAreaLen;
2990 	*pS >> nIdentifier;
2991 	DBG_ASSERT(nStandardId==nIdentifier,
2992 		"A control that has a different identifier");
2993 	*pS >> nFixedAreaLen;
2994     pS->SeekRel(nFixedAreaLen);
2995     return true;
2996 }
2997 
Read(SvStorageStream * pS)2998 sal_Bool OCX_ModernControl::Read(SvStorageStream *pS)
2999 {
3000     long nStart = pS->Tell();
3001 	*pS >> nIdentifier;
3002 	DBG_ASSERT(nIdentifier==nStandardId,
3003 			"A control that has a different identifier");
3004 	*pS >> nFixedAreaLen;
3005 	pS->Read(pBlockFlags,8);
3006 
3007 	if (pBlockFlags[0] & 0x01)
3008 	{
3009 		sal_uInt8 nTemp;
3010 		*pS >> nTemp;
3011 
3012 		fEnabled = (nTemp & 0x02) >> 1;
3013 		fLocked = (nTemp & 0x04) >> 2;
3014         fBackStyle = (nTemp & 0x08) >> 3;
3015 
3016 		*pS >> nTemp;
3017 
3018 		fColumnHeads = (nTemp & 0x04) >> 2;
3019 		fIntegralHeight = (nTemp & 0x08) >> 3;
3020 		fMatchRequired = (nTemp & 0x10) >> 4;
3021 		fAlignment = (nTemp & 0x20) >> 5;
3022 
3023 		*pS >> nTemp;
3024 
3025 		fDragBehaviour = (nTemp & 0x08) >> 3;
3026 		fEnterKeyBehaviour = (nTemp & 0x10) >> 4;
3027 		fEnterFieldBehaviour = (nTemp & 0x20) >> 5;
3028 		fTabKeyBehaviour = (nTemp & 0x40) >> 6;
3029 		fWordWrap = (nTemp & 0x80) >> 7;
3030 
3031 		*pS >> nTemp;
3032 		fSelectionMargin = (nTemp & 0x04) >> 2;
3033 		fAutoWordSelect = (nTemp & 0x08) >> 3;
3034 		fAutoSize = (nTemp & 0x10) >> 4;
3035 		fHideSelection = (nTemp & 0x20) >> 5;
3036 		fAutoTab = (nTemp & 0x40) >> 6;
3037 		fMultiLine = (nTemp & 0x80) >> 7;
3038 
3039 	}
3040 
3041 	/*If any of these are set they follow eachother in this order one after
3042 	another padded out to the next U32 boundary with 0's
3043 	U8 can abut each other U16 must start on a U16 boundary and are padded to
3044 	that with 0's. A standardish word alignment structure*/
3045 
3046 	if (pBlockFlags[0] & 0x02)
3047 		*pS >> mnBackColor;
3048 	if (pBlockFlags[0] & 0x04)
3049 		*pS >> mnForeColor;
3050 	if (pBlockFlags[0] & 0x08)
3051 		*pS >> nMaxLength;
3052 
3053 	if (pBlockFlags[0] & 0x10)
3054 		*pS >> nBorderStyle;
3055 	if (pBlockFlags[0] & 0x20)
3056 		*pS >> nScrollBars;
3057 	if (pBlockFlags[0] & 0x40)
3058 		*pS >> nStyle;// (UI 0 == Data 3, UI 2 = Data 7)
3059 	if (pBlockFlags[0] & 0x80)
3060 		*pS >> nMousePointer;
3061 
3062 	if (pBlockFlags[1] & 0x02)
3063 		*pS >> nPasswordChar; //HUH ??? always 0 ??? not sure maybe just padding
3064 
3065 	if (pBlockFlags[1] & 0x04)
3066 	{
3067 		ReadAlign(pS, pS->Tell() - nStart, 4);
3068 		*pS >> nListWidth;
3069 	}
3070 
3071 	if (pBlockFlags[1] & 0x08)
3072 	{
3073 		ReadAlign(pS, pS->Tell() - nStart, 2);
3074 		*pS >> nBoundColumn;
3075 	}
3076 	if (pBlockFlags[1] & 0x10)
3077 	{
3078 		ReadAlign(pS, pS->Tell() - nStart, 2);
3079 		*pS >> nTextColumn;
3080 	}
3081 	if (pBlockFlags[1] & 0x20)
3082 	{
3083 		ReadAlign(pS, pS->Tell() - nStart, 2);
3084 		*pS >> nColumnCount;
3085 	}
3086 	if (pBlockFlags[1] & 0x40)
3087 	{
3088 		ReadAlign(pS, pS->Tell() - nStart, 2);
3089 		*pS >> nListRows;
3090 	}
3091 	if (pBlockFlags[1] & 0x80)
3092 	{
3093 		ReadAlign(pS, pS->Tell() - nStart, 2);
3094 		*pS >> nUnknown8; //something to do with ColumnWidths
3095 	}
3096 	if (pBlockFlags[2] & 0x01)
3097 		*pS >> nMatchEntry;
3098 	if (pBlockFlags[2] & 0x02)
3099 		*pS >> nListStyle;
3100 	if (pBlockFlags[2] & 0x04)
3101 		*pS >> nShowDropButtonWhen;
3102 	if (pBlockFlags[2] & 0x10)
3103 		*pS >> nDropButtonStyle;
3104 	if (pBlockFlags[2] & 0x20)
3105 		*pS >> nMultiState;
3106 
3107     bool bValue = (pBlockFlags[2] & 0x40) != 0;
3108     if (bValue)
3109 	{
3110 		ReadAlign(pS, pS->Tell() - nStart, 4);
3111         *pS >> nValueLen;
3112 	}
3113     bool bCaption = (pBlockFlags[2] & 0x80) != 0;
3114     if (bCaption)
3115 	{
3116 		ReadAlign(pS, pS->Tell() - nStart, 4);
3117         *pS >> nCaptionLen;
3118 	}
3119 	if (pBlockFlags[3] & 0x01)
3120 	{
3121 		ReadAlign(pS, pS->Tell() - nStart, 4);
3122 		*pS >> nHorzPos;
3123 		*pS >> nVertPos;
3124 	}
3125 	if (pBlockFlags[3] & 0x02)
3126 	{
3127 		ReadAlign(pS, pS->Tell() - nStart, 4);
3128 		*pS >> nBorderColor;
3129 	}
3130 	if (pBlockFlags[3] & 0x04)
3131 	{
3132 		ReadAlign(pS, pS->Tell() - nStart, 4); // NEW
3133 		*pS >> nSpecialEffect;
3134         pS->SeekRel( 3 );       // special effect is 32bit, not 8bit
3135 	}
3136 	if (pBlockFlags[3] & 0x08)
3137 	{
3138 		ReadAlign(pS, pS->Tell() - nStart, 2);
3139 		*pS >> nIcon;
3140 		DBG_ASSERT(nIcon == 0xFFFF, "Unexpected nIcon");
3141 	}
3142 	if (pBlockFlags[3] & 0x10)
3143 	{
3144 		ReadAlign(pS, pS->Tell() - nStart, 2);
3145 		*pS >> nPicture;
3146 		DBG_ASSERT(nPicture == 0xFFFF, "Unexpected nIcon");
3147 	}
3148 	if (pBlockFlags[3] & 0x20)
3149 		*pS >> nAccelerator;
3150 	/*
3151 	if (pBlockFlags[3] & 0x80)
3152 		*pS >> nUnknown9;
3153 	*/
3154     bool bGroupName = (pBlockFlags[4] & 0x01) != 0;
3155     if (bGroupName)
3156 	{
3157 		ReadAlign(pS, pS->Tell() - nStart, 4);
3158         *pS >> nGroupNameLen;
3159 	}
3160 
3161 	//End
3162 
3163 	ReadAlign(pS, pS->Tell() - nStart, 4);
3164 	*pS >> nWidth;
3165 	*pS >> nHeight;
3166 
3167     if (bValue)
3168         lclReadCharArray( *pS, pValue, nValueLen, pS->Tell() - nStart);
3169 
3170     if (bCaption)
3171         lclReadCharArray( *pS, pCaption, nCaptionLen, pS->Tell() - nStart);
3172 
3173     if (bGroupName)
3174         lclReadCharArray( *pS, pGroupName, nGroupNameLen, pS->Tell() - nStart);
3175 
3176     ReadAlign(pS, pS->Tell() - nStart, 4);
3177 	if (nIcon)
3178 	{
3179 		pS->Read(pIconHeader,20);
3180 		*pS >> nIconLen;
3181 		pIcon = new sal_uInt8[nIconLen];
3182 		pS->Read(pIcon,nIconLen);
3183 	}
3184 
3185 	if (nPicture)
3186 	{
3187 		pS->Read(pPictureHeader,20);
3188 		*pS >> nPictureLen;
3189 		pPicture = new sal_uInt8[nPictureLen];
3190 		pS->Read(pPicture,nPictureLen);
3191 	}
3192 
3193 	return sal_True;
3194 }
3195 
3196 
Read(SvStorageStream * pS)3197 sal_Bool OCX_CommandButton::Read(SvStorageStream *pS)
3198 {
3199     long nStart = pS->Tell();
3200 	*pS >> nIdentifier;
3201 	DBG_ASSERT(nStandardId==nIdentifier,
3202 		"A control that has a different identifier");
3203 	*pS >> nFixedAreaLen;
3204 	pS->Read(pBlockFlags,4);
3205 
3206 
3207 	if (pBlockFlags[0] & 0x01)
3208 		*pS >> mnForeColor;
3209 	if (pBlockFlags[0] & 0x02)
3210 		*pS >> mnBackColor;
3211 
3212 	if (pBlockFlags[0] & 0x04)
3213 	{
3214 		sal_uInt8 nTemp;
3215 		*pS >> nTemp;
3216 		fEnabled = (nTemp&0x02)>>1;
3217 		fLocked = (nTemp&0x04)>>2;
3218 		fBackStyle = (nTemp&0x08)>>3;
3219 		*pS >> nTemp;
3220 		*pS >> nTemp;
3221 		fWordWrap = (nTemp&0x80)>>7;
3222 		*pS >> nTemp;
3223 		fAutoSize = (nTemp&0x10)>>4;
3224 	}
3225 
3226     bool bCaption = (pBlockFlags[0] & 0x08) != 0;
3227     if (bCaption)
3228     {
3229 		*pS >> nCaptionLen;
3230     }
3231 	if (pBlockFlags[0] & 0x10) /*Picture Position, a strange mechanism here*/
3232 	{
3233 		*pS >> nVertPos;
3234 		*pS >> nHorzPos;
3235 	}
3236 
3237 	if (pBlockFlags[0] & 0x40) /*MousePointer*/
3238 		*pS >> nMousePointer;
3239 
3240 	if (pBlockFlags[0] & 0x80)
3241 	{
3242 		ReadAlign(pS, pS->Tell() - nStart, 2);
3243 		*pS >> nPicture;
3244 	}
3245 
3246 	if (pBlockFlags[1] & 0x01)
3247 	{
3248 		ReadAlign(pS, pS->Tell() - nStart, 2);
3249 		*pS >> nAccelerator;
3250 	}
3251 
3252     // "take focus on click" is directly in content flags, not in option field...
3253     mbTakeFocus = (pBlockFlags[1] & 0x02) == 0;     // option is on, if flag is not set
3254 
3255 	if (pBlockFlags[1] & 0x04)
3256 	{
3257 		ReadAlign(pS, pS->Tell() - nStart, 2);
3258 		*pS >> nIcon;
3259 	}
3260 
3261     if (bCaption)
3262         lclReadCharArray( *pS, pCaption, nCaptionLen, pS->Tell() - nStart);
3263 
3264 	ReadAlign(pS, pS->Tell() - nStart, 4);
3265 	*pS >> nWidth;
3266 	*pS >> nHeight;
3267 
3268 	if (nIcon)
3269 	{
3270 		pS->Read(pIconHeader,20);
3271 		*pS >> nIconLen;
3272 		pIcon = new sal_uInt8[nIconLen];
3273 		pS->Read(pIcon,nIconLen);
3274 	}
3275 
3276 	if (nPicture)
3277 	{
3278 		pS->Read(pPictureHeader,20);
3279 		*pS >> nPictureLen;
3280 		pPicture = new sal_uInt8[nPictureLen];
3281 		pS->Read(pPicture,nPictureLen);
3282 	}
3283 
3284 	return sal_True;
3285 }
3286 
Read(SvStorageStream * pS)3287 sal_Bool OCX_Label::Read(SvStorageStream *pS)
3288 {
3289     long nStart = pS->Tell();
3290 	*pS >> nIdentifier;
3291 	DBG_ASSERT(nStandardId==nIdentifier,
3292 			"A control that has a different identifier");
3293 	*pS >> nFixedAreaLen;
3294 	pS->Read(pBlockFlags,4);
3295 
3296 
3297 	if (pBlockFlags[0] & 0x01)
3298 		*pS >> mnForeColor;
3299 	if (pBlockFlags[0] & 0x02)
3300 		*pS >> mnBackColor;
3301 
3302 
3303 	if (pBlockFlags[0] & 0x04)
3304 	{
3305 		sal_uInt8 nTemp;
3306 		*pS >> nTemp;
3307 		fEnabled = (nTemp&0x02)>>1;
3308 		fLocked = (nTemp&0x04)>>2;
3309 		fBackStyle = (nTemp&0x08)>>3;
3310 		*pS >> nTemp;
3311 		*pS >> nTemp;
3312 		fWordWrap = (nTemp&0x80)>>7;
3313 		*pS >> nTemp;
3314 		fAutoSize = (nTemp&0x10)>>4;
3315 	}
3316     bool bCaption = (pBlockFlags[0] & 0x08) != 0;
3317     if (bCaption)
3318 		*pS >> nCaptionLen;
3319 
3320 	if (pBlockFlags[0] & 0x10)
3321 	{
3322 		*pS >> nVertPos;
3323 		*pS >> nHorzPos;
3324 	}
3325 
3326 	if (pBlockFlags[0] & 0x40)
3327 		*pS >> nMousePointer;
3328 
3329 	if (pBlockFlags[0] & 0x80)
3330 	{
3331 		ReadAlign(pS,pS->Tell() - nStart, 4);
3332 		*pS >> nBorderColor;
3333 	}
3334 
3335 	if (pBlockFlags[1] & 0x01)
3336 	{
3337 		ReadAlign(pS, pS->Tell() - nStart, 2);
3338 		*pS >> nBorderStyle;
3339 	}
3340 
3341 	if (pBlockFlags[1] & 0x02)
3342 	{
3343 		ReadAlign(pS, pS->Tell() - nStart, 2);
3344 		*pS >> nSpecialEffect;
3345 	}
3346 
3347 	if (pBlockFlags[1] & 0x04)
3348 	{
3349 		ReadAlign(pS, pS->Tell() - nStart, 2);
3350 		*pS >> nPicture;
3351 	}
3352 
3353 	if (pBlockFlags[1] & 0x08)
3354 	{
3355 		ReadAlign(pS, pS->Tell() - nStart, 2);
3356 		*pS >> nAccelerator;
3357 	}
3358 
3359 	if (pBlockFlags[1] & 0x10)
3360 	{
3361 		ReadAlign(pS, pS->Tell() - nStart, 2);
3362 		*pS >> nIcon;
3363 	}
3364 
3365     if (bCaption)
3366         lclReadCharArray( *pS, pCaption, nCaptionLen, pS->Tell() - nStart);
3367 
3368     ReadAlign(pS, pS->Tell() - nStart, 4);
3369 	*pS >> nWidth;
3370 	*pS >> nHeight;
3371 
3372 	if (nPicture)
3373 	{
3374 		pS->Read(pPictureHeader,20);
3375 		*pS >> nPictureLen;
3376 		pPicture = new sal_uInt8[nPictureLen];
3377 		pS->Read(pPicture,nPictureLen);
3378 	}
3379     if (nIcon)
3380     {
3381         pS->Read(pIconHeader,20);
3382         *pS >> nIconLen;
3383         pIcon = new sal_uInt8[nIconLen];
3384         pS->Read(pIcon,nIconLen);
3385     }
3386 
3387 	return sal_True;
3388 }
3389 
TypeName(sal_Char * pName,sal_uInt32 nStoreId,sal_uInt32 nLen,sal_uInt16 nType,sal_Int32 nLeft,sal_Int32 nTop)3390 TypeName::TypeName(sal_Char *pName, sal_uInt32 nStoreId, sal_uInt32 nLen, sal_uInt16 nType, sal_Int32 nLeft,
3391     sal_Int32 nTop)
3392     : msName(lclCreateOUString(pName, nLen)), mnType(nType), mnLeft(nLeft),
3393     mnTop(nTop),mnStoreId(nStoreId)
3394 {
3395 }
3396 
OCX_ContainerControl(SotStorageRef & parent,const::rtl::OUString & storageName,const::rtl::OUString & sN,const uno::Reference<container::XNameContainer> & rParent,OCX_Control * pParent)3397 OCX_ContainerControl::OCX_ContainerControl( SotStorageRef& parent,
3398             const ::rtl::OUString& storageName,
3399             const ::rtl::OUString& sN,
3400             const uno::Reference< container::XNameContainer >  &rParent,
3401             OCX_Control* pParent ) :
3402                 OCX_Control(sN, pParent), rbGroupMgr( sName ), mxParent(rParent), nNoRecords(0), nTotalLen(0), containerType( STDCONTAINER )
3403 {
3404 
3405     mContainerStorage = parent->OpenSotStorage(storageName,
3406         STREAM_READWRITE |
3407         STREAM_NOCREATE |
3408         STREAM_SHARE_DENYALL);
3409     mContainerStream = mContainerStorage->OpenSotStream(
3410         String(RTL_CONSTASCII_STRINGPARAM("f"),
3411         RTL_TEXTENCODING_MS_1252),
3412         STREAM_STD_READ | STREAM_NOCREATE);
3413     mContainedControlsStream = mContainerStorage->OpenSotStream( String(RTL_CONSTASCII_STRINGPARAM("o"),
3414         RTL_TEXTENCODING_MS_1252),
3415         STREAM_STD_READ | STREAM_NOCREATE);
3416 }
~OCX_ContainerControl()3417 OCX_ContainerControl::~OCX_ContainerControl()
3418 {
3419     CtrlIterator aEnd = mpControls.end();
3420     for (CtrlIterator aIter = mpControls.begin(); aIter != aEnd; ++ aIter )
3421     {
3422         delete *aIter;
3423     }
3424 }
3425 
3426 // Really import should receive the parent e.g. a Userform, Frame or Multi Page
3427 // and call import on its containees with itself  ( up-called from
3428 // the base class ) but... the reality is we have no containment model
3429 // so we make sure rPropSet is always the parent Dialog
3430 
Import(uno::Reference<beans::XPropertySet> &)3431 sal_Bool OCX_ContainerControl::Import(uno::Reference<beans::XPropertySet>& /* rProps */ )
3432 {
3433     if ( !mxParent.is() )
3434     {
3435         return sal_False;
3436     }
3437     CtrlIterator aEnd = mpControls.end();
3438 //    int count = 0;
3439     for (CtrlIterator aIter = mpControls.begin(); aIter != aEnd; ++ aIter )
3440     {
3441         if ( !(*aIter)->Import( mxParent ) )
3442         {
3443             return sal_False;
3444         }
3445     }
3446     return sal_True;
3447 }
3448 
createSubStreamName(const sal_uInt32 & subStorageId)3449 OUString OCX_ContainerControl::createSubStreamName( const sal_uInt32& subStorageId )
3450 {
3451     static OUString sI = OUString::createFromAscii("i");
3452     static OUString sZero = OUString::createFromAscii( "0" );
3453     OUStringBuffer buf( 6 );
3454     buf.append( sI );
3455     // for subStorage id < 10 stream name has leading '0'
3456     // eg "i07"
3457     if ( subStorageId < 10 )
3458     {
3459         buf.append( sZero );
3460     }
3461     buf.append( OUString::valueOf( (sal_Int32)subStorageId ) );
3462     return buf.makeStringAndClear();
3463 }
3464 
createFromContainerRecord(const ContainerRecord & record,OCX_Control * & pControl)3465 bool OCX_ContainerControl::createFromContainerRecord( const ContainerRecord& record, OCX_Control*& pControl )
3466 {
3467     pControl = NULL;
3468     switch ( record.nTypeIdent)
3469         {
3470             case CMDBUTTON:
3471                 pControl = new OCX_CommandButton;
3472                 break;
3473             case LABEL:
3474                 pControl = new OCX_UserFormLabel(this);
3475                 break;
3476             case TEXTBOX:
3477                 pControl = new OCX_TextBox;
3478                 break;
3479             case LISTBOX:
3480                 pControl = new OCX_ListBox;
3481                 break;
3482             case COMBOBOX:
3483                 pControl = new OCX_ComboBox;
3484                 break;
3485             case CHECKBOX:
3486                 pControl =  new OCX_CheckBox;
3487                 break;
3488             case OPTIONBUTTON:
3489                 pControl = new OCX_OptionButton;
3490                 break;
3491             case TOGGLEBUTTON:
3492                 pControl = new OCX_ToggleButton;
3493                 break;
3494             case IMAGE: //Image
3495             {
3496                 pControl = new OCX_Image;
3497                 break;
3498             }
3499             case PAGE: // Page
3500             {
3501                 OUString sMSStore = createSubStreamName( record.nSubStorageId );
3502                 pControl = new OCX_Page(mContainerStorage, sMSStore,
3503                     record.cName, mxParent, this);
3504                 break;
3505             }
3506             case MULTIPAGE: // MultiPage
3507             {
3508                 OUString sMSStore = createSubStreamName( record.nSubStorageId );
3509                 pControl = new OCX_MultiPage( mContainerStorage, sMSStore,
3510                     record.cName, mxParent, this);
3511                 break;
3512             }
3513             case FRAME:  //Frame
3514             {
3515                 OUString sFrameStore = createSubStreamName( record.nSubStorageId );
3516                 pControl = new OCX_Frame(mContainerStorage, sFrameStore,
3517                     record.cName, mxParent, this);
3518 
3519                 break;
3520             }
3521             case SPINBUTTON: //SpinButton
3522             {
3523                 pControl = new OCX_SpinButton;
3524                 break;
3525             }
3526             case TABSTRIP: //TabStrip
3527             {
3528                 pControl = new OCX_TabStrip;
3529                 break;
3530             }
3531             case SCROLLBAR: //ScrollBar
3532                 pControl = new OCX_ScrollBar;
3533                 break;
3534             case PROGRESSBAR: //ProgressBar Active X control
3535                 pControl = new OCX_ProgressBar;
3536                 break;
3537             default:
3538                 OSL_TRACE( "**** Unknown control 0x%x", record.nTypeIdent );
3539                 DBG_ERROR( "Unknown control");
3540                 return false;
3541         }
3542         pControl->sName = record.cName;
3543         return true;
3544 }
3545 
3546 
addSeperator(std::vector<OCX_Control * > & dest)3547 void addSeperator( std::vector< OCX_Control* >& dest )
3548 {
3549     OCX_Control* seperator = new OCX_CommandButton;
3550     seperator->SetInDialog(true);
3551     seperator->sName = C2S("GroupSeperator");
3552     dest.push_back( seperator );
3553 }
3554 
addRButtons(std::vector<OCX_Control * > & src,std::vector<OCX_Control * > & dest,bool addGroupSeperator)3555 void addRButtons( std::vector< OCX_Control* >& src,
3556                   std::vector< OCX_Control* >& dest,
3557                   bool addGroupSeperator )
3558 {
3559     if ( addGroupSeperator )
3560     {
3561         addSeperator( dest );
3562     }
3563 
3564     for ( CtrlIterator rbIter = src.begin(); rbIter != src.end(); ++rbIter )
3565     {
3566         dest.push_back( *rbIter );
3567     }
3568 }
3569 
ProcessControl(OCX_Control * pControl,SvStorageStream *,ContainerRecord & rec)3570 void OCX_ContainerControl::ProcessControl(OCX_Control* pControl,SvStorageStream* /* pS */,  ContainerRecord& rec )
3571 {
3572     SotStorageStreamRef oStream = mContainedControlsStream;
3573 
3574     // can insert into OO Dialog (e.g is this a supported dialog control)??
3575     if ( rec.nTypeIdent == SPINBUTTON ||
3576         rec.nTypeIdent == TABSTRIP)
3577     {
3578         // skip the record in the stream, discard the control
3579         oStream->SeekRel( rec.nSubStreamLen );
3580         delete pControl;
3581     }
3582     else
3583     {
3584         // A container control needs to read the f stream in
3585         // the folder ( substorage ) associated with this control
3586         if (  rec.nTypeIdent ==  FRAME ||
3587             rec.nTypeIdent ==  MULTIPAGE||
3588             rec.nTypeIdent ==  PAGE )
3589         {
3590             OCX_ContainerControl* pContainer =
3591                static_cast< OCX_ContainerControl* >( pControl );
3592             oStream = pContainer->getContainerStream();
3593         }
3594 
3595         pControl->sName = rec.cName;
3596         pControl->msToolTip = rec.controlTip;
3597         // Position of controls is relative to the container
3598         pControl->mnTop = rec.nTop + mnTop;
3599         pControl->mnLeft = rec.nLeft + mnLeft;
3600         // MS tabIndex, pretty useless in OpenOffice land
3601         // as tab indexes in MS are relative to parent container.
3602         // However we need this value in order to set
3603         // OpenOffice tab indices in a sensible way to
3604         // reflect the ms tabbing from orig MS UserForm, see below
3605         pControl->mnTabPos = rec.nTabPos;
3606         pControl->SetInDialog(true);
3607         pControl->mbVisible = rec.bVisible;
3608         if ( mnStep )
3609         {
3610             // If the container has a step then it should be
3611             // applied to all containees
3612             pControl->mnStep = mnStep;
3613         }
3614 
3615         // #117490# DR: container records provide size of substream, use it here...
3616 
3617         // remember initial position to set correct stream position
3618         sal_uLong nStrmPos = oStream->Tell();
3619         // import control, may return with invalid stream position
3620         pControl->FullRead(oStream);
3621         // set stream to position behind substream of this control
3622         oStream->Seek( nStrmPos + rec.nSubStreamLen );
3623 
3624         //need to fake grouping behaviour for radio ( option ) buttons
3625         if ( rec.nTypeIdent == OPTIONBUTTON )
3626         {
3627             OCX_OptionButton* pRButton =
3628                 static_cast< OCX_OptionButton*>(pControl);
3629             rbGroupMgr.addRadioButton( pRButton );
3630         }
3631         else
3632         {
3633             mpControls.push_back( pControl );
3634         }
3635     }
3636 }
3637 
Read(SvStorageStream * pS)3638 sal_Bool OCX_ContainerControl::Read(SvStorageStream *pS)
3639 {
3640 
3641     if ( mpParent )
3642     {
3643         mnBackColor = mpParent->mnBackColor;
3644     }
3645 
3646     std::auto_ptr< ContainerRecReader > reader (
3647         ContainerRecordReaderFac::instance( containerType ) );
3648 
3649     reader->Read( this, pS );
3650     // Need to honour the MS Tab Indexes. However MS tab indexes are
3651     // relative to parent, this hack sorts the controls in each container
3652     // based on the ms tab indexes. When import is called we create the
3653     // controls in Open/Star office based on the order of the tab indexes,
3654     // this ensures that the default tab index created by Star/Open office
3655     // reflects the "flattened" ms tab order.
3656     ::std::sort( mpControls.begin(), mpControls.end(), SortOrderByTabPos() );
3657     mpControls = rbGroupMgr.insertGroupsIntoControlList( mpControls );
3658 	return true;
3659 }
3660 
OCX_MultiPage(SotStorageRef & parent,const::rtl::OUString & storageName,const::rtl::OUString & sN,const uno::Reference<container::XNameContainer> & rDialog,OCX_Control * pParent)3661 OCX_MultiPage::OCX_MultiPage( SotStorageRef& parent,
3662             const ::rtl::OUString& storageName,
3663             const ::rtl::OUString& sN,
3664             const uno::Reference< container::XNameContainer >  &rDialog,
3665             OCX_Control* pParent):
3666 		OCX_ContainerControl(parent, storageName, sN, rDialog, pParent ), fUnknown1(0), fEnabled(1),
3667         fLocked(0), fBackStyle(1), fWordWrap(1), fAutoSize(0), nCaptionLen(0),
3668         nVertPos(1), nHorzPos(7), nMousePointer(0), nBorderColor(0x80000012),
3669 		nKeepScrollBarsVisible(3), nCycle(0), nBorderStyle(0), nSpecialEffect(0),
3670 		nPicture(0), nPictureAlignment(2), nPictureSizeMode(0),
3671 		bPictureTiling(sal_False), nAccelerator(0), nIcon(0), pCaption(0),
3672 		nScrollWidth(0), nScrollHeight(0), nIconLen(0), pIcon(0), nPictureLen(0),
3673 		pPicture(0)
3674 {
3675     msDialogType = C2U("NotSupported");
3676     mnForeColor = 0x80000012L,
3677     mnBackColor = 0x8000000FL;
3678     bSetInDialog = true;// UserForm control only
3679     aFontData.SetHasAlign(sal_True);
3680     containerType = MULTIPAGE;
3681     mnCurrentPageStep = 0;
3682 }
3683 
ProcessControl(OCX_Control * pControl,SvStorageStream *,ContainerRecord & rec)3684 void OCX_MultiPage::ProcessControl(OCX_Control* pControl, SvStorageStream* /* pS */,  ContainerRecord& rec )
3685 {
3686     SotStorageStreamRef oStream = mContainedControlsStream;
3687 
3688     OCX_Page *pPage = NULL;
3689     if ( rec.nTypeIdent == PAGE )
3690         pPage = static_cast< OCX_Page* >( pControl );
3691     if ( pPage != NULL )
3692     {
3693         pPage->mnStep = ++mnCurrentPageStep;
3694 
3695         pPage->mnTop =  mnTop;// move these to Page::import ?
3696         pPage->mnLeft = mnLeft;
3697         pPage->mnBackColor = mnBackColor;
3698 
3699         oStream = pPage->getContainerStream();;
3700         // Position of controls is relative to pos of this MuliPage
3701         // Control
3702         pPage->FullRead( oStream );
3703 
3704         mpControls.push_back( pPage );
3705     }
3706     else
3707     {
3708         OSL_TRACE("!!!! Unsupported Control 0x%x ", rec.nTypeIdent);
3709         DBG_ERROR("MultiPage error expected Page control");
3710     }
3711 
3712 }
3713 
Read(SvStorageStream * pS)3714 sal_Bool OCX_MultiPage::Read(SvStorageStream *pS)
3715 {
3716     // Unlike the other containers e.g. UserForm & Frame
3717     // the o stream is does not contain info for the contained controls
3718     // ( e.g. the pages themselves ) but seems to be for the MultiPage
3719     // itself - need to check this in more detail
3720 
3721     // For the moment skip read of the MultiPage specific properties
3722     // not much point reading these as we can't display the multi page
3723     // control or in fact any sort of tabbed layout, best we can do is
3724     // import just the contained controls of the individual pages
3725     // Note: the record skipped below ( does not contain the expected
3726     // info on this control, that seems to be contained in the o stream,
3727     // see comment above)
3728     OCX_Control skip(C2S("Dummy"));
3729     skip.Read( pS );
3730     mnCurrentPageStep = mnStep; //( set step of of pages relative to step
3731                                 //of this MultiPage ( e.g. emulate containment )
3732     return OCX_ContainerControl::Read(pS);
3733 }
3734 
3735 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)3736 sal_Bool OCX_MultiPage::Import(com::sun::star::uno::Reference<
3737     com::sun::star::beans::XPropertySet> &rPropSet)
3738 {
3739     // Calls import on contained controls
3740     OCX_ContainerControl::Import( rPropSet );
3741     return sal_True;
3742 }
3743 
Import(com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> & rDialog)3744 sal_Bool OCX_MultiPage::Import(com::sun::star::uno::Reference<
3745 		com::sun::star::container::XNameContainer>
3746 		&rDialog)
3747 {
3748     uno::Reference<beans::XPropertySet> xPropSet( rDialog, uno::UNO_QUERY );
3749 
3750     // Although MultiPage is not represeted by a "real" control we still
3751     // need to propagate the backcolor of this logical parent
3752     // ( the dialog or Frame or whatever ) to the children of this control.
3753     // For example the controls contained in the Page of a
3754     // MultiPage control use the parents backcolor ( e,g,
3755     // Pages backcolor ) when trying to fake transparency
3756     mnBackColor = mpParent->mnBackColor;
3757 
3758     if ( xPropSet.is() )
3759     {
3760         // Calls import on contained pages
3761         return OCX_ContainerControl::Import( xPropSet );
3762     }
3763     OSL_TRACE("*** Major problem, no dialog to add controls to ");
3764     DBG_ERROR(" Major problem, no dialog to add controls to ");
3765     return false;
3766 }
3767 
3768 
3769 
OCX_Page(SotStorageRef & parent,const::rtl::OUString & storageName,const::rtl::OUString & sN,const uno::Reference<container::XNameContainer> & rDialog,OCX_Control * pParent)3770 OCX_Page::OCX_Page( SotStorageRef& parent,
3771             const ::rtl::OUString& storageName,
3772             const ::rtl::OUString& sN,
3773             const uno::Reference< container::XNameContainer >  &rDialog,
3774             OCX_Control* pParent):
3775 		OCX_ContainerControl(parent, storageName, sN, rDialog, pParent ),
3776         fUnknown1(0), fEnabled(1), fLocked(0),
3777 		fBackStyle(1), fWordWrap(1), fAutoSize(0), nCaptionLen(0), nVertPos(1),
3778 		nHorzPos(7), nMousePointer(0), nBorderColor(0x80000012),
3779 		nKeepScrollBarsVisible(3), nCycle(0), nBorderStyle(0), nSpecialEffect(0),
3780 		nPicture(0), nPictureAlignment(2), nPictureSizeMode(0),
3781 		bPictureTiling(sal_False), nAccelerator(0), nIcon(0), pCaption(0),
3782 		nScrollWidth(0), nScrollHeight(0), nIconLen(0), pIcon(0), nPictureLen(0),
3783 		pPicture(0)
3784 {
3785     msDialogType = C2U("NotSupported");
3786     mnForeColor = 0x80000012,
3787 	mnBackColor = 0x8000000F,
3788     bSetInDialog = true;// UserForm control only
3789     aFontData.SetHasAlign(sal_True);
3790 }
3791 
3792 
Read(SvStorageStream * pS)3793 sal_Bool OCX_Page::Read(SvStorageStream *pS)
3794 {
3795     long nStart = pS->Tell();
3796 	*pS >> nIdentifier;
3797 	DBG_ASSERT(0x400==nIdentifier,
3798 			"A control that has a different identifier");
3799 	*pS >> nFixedAreaLen;
3800 	pS->Read(pBlockFlags,4);
3801 
3802     pS->SeekRel( nFixedAreaLen - sizeof( pBlockFlags ) );
3803 
3804     ReadAlign( pS, pS->Tell() - nStart, 4);
3805 
3806     if (pBlockFlags[2] & 0x10)
3807     {
3808         //Font Stuff..
3809         pS->SeekRel(0x1a);
3810         sal_uInt8 nFontLen;
3811         *pS >> nFontLen;
3812         pS->SeekRel(nFontLen);
3813     }
3814     return OCX_ContainerControl::Read(pS);
3815 
3816 }
3817 
Import(com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> & rDialog)3818 sal_Bool OCX_Page::Import(com::sun::star::uno::Reference<
3819 		com::sun::star::container::XNameContainer>
3820 		&rDialog)
3821 {
3822 
3823     uno::Reference<beans::XPropertySet> xPropSet( rDialog, uno::UNO_QUERY );
3824     if ( xPropSet.is() )
3825     {
3826         // apply Step to contained controls
3827         CtrlIterator aEnd = mpControls.end();
3828         for (CtrlIterator aIter = mpControls.begin(); aIter != aEnd; ++ aIter )
3829         {
3830             (*aIter)->mnStep = mnStep;
3831         }
3832         // Calls import on contained pages
3833         return OCX_ContainerControl::Import( xPropSet );
3834     }
3835     OSL_TRACE("*** Major problem, no dialog to add controls to ");
3836     DBG_ERROR("*** Major problem, no dialog to add controls to ");
3837     return sal_False;
3838 }
3839 
OCX_Frame(SotStorageRef & parent,const::rtl::OUString & storageName,const::rtl::OUString & sN,const uno::Reference<container::XNameContainer> & rDialog,OCX_Control * pParent)3840 OCX_Frame::OCX_Frame( SotStorageRef& parent,
3841             const ::rtl::OUString& storageName,
3842             const ::rtl::OUString& sN,
3843             const uno::Reference< container::XNameContainer >  &rDialog, OCX_Control* pParent):
3844 		OCX_ContainerControl(parent, storageName, sN, rDialog, pParent ),fUnknown1(0),fEnabled(1), fLocked(0),
3845 		fBackStyle(1), fWordWrap(1), fAutoSize(0), nCaptionLen(0), nVertPos(1),
3846 		nHorzPos(7), nMousePointer(0), nBorderColor(0x80000012),
3847 		nKeepScrollBarsVisible(3), nCycle(0), nBorderStyle(0), nSpecialEffect(0),
3848 		nPicture(0), nPictureAlignment(2), nPictureSizeMode(0),
3849 		bPictureTiling(sal_False), nAccelerator(0), nIcon(0), pCaption(0),
3850 		nScrollWidth(0), nScrollHeight(0), nScrollLeft(0), nScrollTop(0), nIconLen(0), pIcon(0), nPictureLen(0),
3851 		pPicture(0)
3852 {
3853     msDialogType = C2U("com.sun.star.awt.UnoControlGroupBoxModel");
3854     mnForeColor = 0x80000012;
3855 	mnBackColor = 0x8000000F;
3856     bSetInDialog = true;// UserForm control only
3857     aFontData.SetHasAlign(sal_True);
3858 }
3859 
3860 
Read(SvStorageStream * pS)3861 sal_Bool OCX_Frame::Read(SvStorageStream *pS)
3862 {
3863     long nStart = pS->Tell();
3864 	*pS >> nIdentifier;
3865 	DBG_ASSERT(0x400==nIdentifier,
3866 			"A control that has a different identifier");
3867 	*pS >> nFixedAreaLen;
3868 	pS->Read(pBlockFlags,4);
3869 
3870 	if (pBlockFlags[0] & 0x01)
3871     {
3872             DBG_ASSERT(sal_False, "ARSE");
3873     }
3874 	if (pBlockFlags[0] & 0x02)
3875             *pS >> mnBackColor;
3876 	if (pBlockFlags[0] & 0x04)
3877             *pS >> mnForeColor;
3878     if (pBlockFlags[0] & 0x08)
3879         *pS >> fUnknown1;
3880     if (pBlockFlags[0] & 0x40)
3881 	{
3882 		sal_uInt8 nTemp;
3883 		*pS >> nTemp;
3884 		fEnabled = (nTemp&0x04)>>2;
3885 		fBackStyle = (nTemp&0x08)>>3;
3886 		*pS >> nTemp;
3887 		*pS >> nTemp;
3888 		fWordWrap = (nTemp&0x80)>>7;
3889 		*pS >> nTemp;
3890 		fAutoSize = (nTemp&0x10)>>4;
3891     }
3892     if (pBlockFlags[0] & 0x80)
3893     {
3894         *pS >> nBorderStyle;
3895     }
3896 
3897     ReadAlign(pS, pS->Tell() - nStart, 4);
3898 
3899     if (pBlockFlags[1] & 0x01)
3900 		*pS >> nMousePointer;
3901     if (pBlockFlags[1] & 0x02)
3902         *pS >> nKeepScrollBarsVisible;
3903     if (pBlockFlags[1] & 0x20)
3904         *pS >> fUnknown1; // another unknown 32 bit ( or is 8 or 16 bit with padding ? )
3905 
3906     if (pBlockFlags[1] & 0x80)
3907     {
3908         ReadAlign(pS, pS->Tell() - nStart, 2);
3909         *pS >> nIcon;
3910         DBG_ASSERT(nIcon == 0xFFFF, "Unexpected nIcon");
3911     }
3912 
3913     bool bCaption = false;
3914 
3915     if (pBlockFlags[2] & 0x01)
3916         *pS >> nCycle;
3917     if (pBlockFlags[2] & 0x02)
3918 		*pS >> nSpecialEffect;
3919 
3920 	if (pBlockFlags[2] & 0x04)
3921 	{
3922 		ReadAlign(pS, pS->Tell() - nStart, 4);
3923 		*pS >> nBorderColor;
3924 	}
3925 
3926     if (pBlockFlags[2] & 0x08)
3927 	{
3928         ReadAlign(pS, pS->Tell() - nStart, 4);
3929 		*pS >> nCaptionLen;
3930         bCaption = true;
3931 	}
3932 
3933     if (pBlockFlags[2] & 0x10)
3934 	{
3935         ReadAlign(pS, pS->Tell() - nStart, 2);
3936         sal_uInt16 nNoIdea;
3937         *pS >> nNoIdea;
3938         DBG_ASSERT(nNoIdea == 0xFFFF, "Expected 0xFFFF, (related to font ?)");
3939 	}
3940 
3941     if (pBlockFlags[2] & 0x20)
3942 	{
3943         ReadAlign(pS, pS->Tell() - nStart, 2);
3944         *pS >> nPicture;
3945         DBG_ASSERT(nPicture == 0xFFFF, "Unexpected nIcon");
3946 	}
3947 
3948     if (pBlockFlags[2] & 0x80)
3949         *pS >> nPictureAlignment;
3950 
3951     if (pBlockFlags[3] & 0x01)
3952         bPictureTiling = true;
3953 
3954     if (pBlockFlags[3] & 0x02)
3955         *pS >> nPictureSizeMode;
3956 
3957     if (pBlockFlags[3] & 0x04)
3958     {
3959         ReadAlign(pS, pS->Tell() - nStart, 4);
3960         *pS >> fUnknown8;
3961     }
3962 
3963     if (pBlockFlags[3] & 0x08)
3964     {
3965         ReadAlign(pS, pS->Tell() - nStart, 4);
3966         *pS >> fUnknown9;
3967     }
3968 
3969     ReadAlign(pS, pS->Tell() - nStart, 4);
3970 	*pS >> nWidth;
3971 	*pS >> nHeight;
3972     *pS >> nScrollWidth;
3973     *pS >> nScrollHeight;
3974 
3975     if (pBlockFlags[1] & 0x10)
3976     {
3977         *pS >> nScrollLeft;
3978         *pS >> nScrollTop;
3979     }
3980 
3981     if ( bCaption )
3982     {
3983         lclReadCharArray( *pS, pCaption, nCaptionLen, pS->Tell() - nStart);
3984     }
3985 
3986     OUString tempCaption =  lclCreateOUString( pCaption, nCaptionLen );
3987 
3988 	if (nIcon)
3989 	{
3990 		pS->Read(pIconHeader,20);
3991 		*pS >> nIconLen;
3992 		pIcon = new sal_uInt8[nIconLen];
3993 		pS->Read(pIcon,nIconLen);
3994 	}
3995 
3996 	if (nPicture)
3997 	{
3998 		pS->Read(pPictureHeader,20);
3999 		*pS >> nPictureLen;
4000 		pPicture = new sal_uInt8[nPictureLen];
4001 		pS->Read(pPicture,nPictureLen);
4002 	}
4003 
4004     ReadAlign( pS, pS->Tell() - nStart, 4);
4005 
4006     if (pBlockFlags[2] & 0x10)
4007     {
4008         //Font Stuff..
4009         pS->SeekRel(0x1a);
4010         sal_uInt8 nFontLen;
4011         *pS >> nFontLen;
4012         pS->SeekRel(nFontLen);
4013     }
4014 
4015 	return OCX_ContainerControl::Read( pS );
4016 }
4017 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)4018 sal_Bool OCX_Frame::Import(com::sun::star::uno::Reference<
4019     com::sun::star::beans::XPropertySet> &rPropSet)
4020 {
4021     uno::Any aTmp(&sName,getCppuType((OUString *)0));
4022     rPropSet->setPropertyValue(
4023         OUString(RTL_CONSTASCII_USTRINGPARAM("Name")), aTmp);
4024     if ( pCaption )
4025     {
4026         aTmp <<= lclCreateOUString( pCaption, nCaptionLen );
4027 		rPropSet->setPropertyValue( WW8_ASCII2STR("Label"), aTmp);
4028     }
4029 
4030     // Calls import on contained controls
4031     OCX_ContainerControl::Import( rPropSet );
4032     return sal_True;
4033 }
OCX_UserForm(SotStorageRef & parent,const OUString & storageName,const OUString & sN,const::uno::Reference<container::XNameContainer> & rDialog,const::uno::Reference<lang::XMultiServiceFactory> & rMsf)4034 OCX_UserForm::OCX_UserForm( SotStorageRef& parent,
4035             const OUString& storageName,
4036             const OUString& sN,
4037             const ::uno::Reference< container::XNameContainer >  &rDialog,
4038             const ::uno::Reference< lang::XMultiServiceFactory >& rMsf):
4039 		OCX_ContainerControl(parent, storageName, sN, rDialog),
4040         nChildrenA(0), fEnabled(1), fLocked(0),
4041 		fBackStyle(1), fWordWrap(1), fAutoSize(0), nCaptionLen(0), nVertPos(1),
4042 		nHorzPos(7), nMousePointer(0), nBorderColor(0x80000012), nChildrenB(0),
4043 		nKeepScrollBarsVisible(3), nCycle(0), nBorderStyle(0), nSpecialEffect(0),
4044 		nPicture(0), nPictureAlignment(2), nPictureSizeMode(0),
4045 		bPictureTiling(sal_False), nAccelerator(0), nIcon(0), pCaption(0),
4046 		nScrollWidth(0), nScrollHeight(0), nScrollLeft(0), nScrollTop(0), nIconLen(0), pIcon(0), nPictureLen(0),
4047 		pPicture(0)
4048 	{
4049             mnForeColor = 0x80000012;
4050 		    mnBackColor = 0x8000000F;
4051             uno::Reference< beans::XPropertySet> xProps( rMsf, uno::UNO_QUERY);
4052             if ( xProps.is() )
4053             {
4054                 xProps->getPropertyValue(C2S("DefaultContext"))  >>= mxCtx;
4055             }
4056             aFontData.SetHasAlign(sal_True);
4057         }
Read(SvStorageStream * pS)4058 sal_Bool OCX_UserForm::Read(SvStorageStream *pS)
4059 {
4060     long nStart = pS->Tell();
4061 	*pS >> nIdentifier;
4062 	DBG_ASSERT(0x400==nIdentifier,
4063 			"A control that has a different identifier");
4064 	*pS >> nFixedAreaLen;
4065 	pS->Read(pBlockFlags,4);
4066 
4067 	if (pBlockFlags[0] & 0x01)
4068     {
4069             DBG_ASSERT(sal_False, "ARSE");
4070     }
4071 	if (pBlockFlags[0] & 0x02)
4072 		*pS >> mnBackColor;
4073 	if (pBlockFlags[0] & 0x04)
4074         *pS >> mnForeColor;
4075     if (pBlockFlags[0] & 0x08)
4076         *pS >> nChildrenA;
4077     if (pBlockFlags[0] & 0x40)
4078 	{
4079 		sal_uInt8 nTemp;
4080 		*pS >> nTemp;
4081 		fEnabled = (nTemp&0x04)>>2;
4082 		fBackStyle = (nTemp&0x08)>>3;
4083 		*pS >> nTemp;
4084 		*pS >> nTemp;
4085 		fWordWrap = (nTemp&0x80)>>7;
4086 		*pS >> nTemp;
4087 		fAutoSize = (nTemp&0x10)>>4;
4088     }
4089     if (pBlockFlags[0] & 0x80)
4090     {
4091         ReadAlign(pS, pS->Tell() - nStart, 4);
4092         *pS >> nBorderStyle;
4093     }
4094 #if 0
4095         sal_uInt16 nFixedOrAlign;
4096         *pS >> nFixedOrAlign;
4097 #endif
4098     if (pBlockFlags[1] & 0x01)
4099 		*pS >> nMousePointer;
4100     if (pBlockFlags[1] & 0x02)
4101         *pS >> nKeepScrollBarsVisible;
4102     if (pBlockFlags[1] & 0x20)
4103     {
4104         sal_uInt32 nUnknown32;
4105         *pS >> nUnknown32;
4106     }
4107     if (pBlockFlags[1] & 0x80)
4108     {
4109         ReadAlign(pS, pS->Tell() - nStart, 2);
4110         *pS >> nIcon;
4111         DBG_ASSERT(nIcon == 0xFFFF, "Unexpected nIcon");
4112     }
4113     if (pBlockFlags[2] & 0x01)
4114         *pS >> nCycle;
4115     if (pBlockFlags[2] & 0x02)
4116 		*pS >> nSpecialEffect;
4117 
4118 	if (pBlockFlags[2] & 0x04)
4119 	{
4120 		ReadAlign(pS, pS->Tell() - nStart, 4);
4121 		*pS >> nBorderColor;
4122 	}
4123 
4124     if (pBlockFlags[2] & 0x10)
4125 	{
4126         ReadAlign(pS, pS->Tell() - nStart, 2);
4127         sal_uInt16 nNoIdea;
4128         *pS >> nNoIdea;
4129         DBG_ASSERT(nNoIdea == 0xFFFF, "Expected 0xFFFF, (related to font ?)");
4130 	}
4131 
4132     if (pBlockFlags[2] & 0x20)
4133 	{
4134         ReadAlign(pS, pS->Tell() - nStart, 2);
4135         *pS >> nPicture;
4136         DBG_ASSERT(nPicture == 0xFFFF, "Unexpected nIcon");
4137 	}
4138 
4139     if (pBlockFlags[2] & 0x80)
4140         *pS >> nPictureAlignment;
4141 
4142     if (pBlockFlags[3] & 0x01)
4143         bPictureTiling = true;
4144 
4145     if (pBlockFlags[3] & 0x02)
4146         *pS >> nPictureSizeMode;
4147 
4148     if (pBlockFlags[3] & 0x04)
4149     {
4150         ReadAlign(pS, pS->Tell() - nStart, 4);
4151         *pS >> nChildrenB;
4152     }
4153 
4154     ReadAlign(pS, pS->Tell() - nStart, 4);
4155     *pS >> nDrawBuffer;
4156 
4157     ReadAlign(pS, pS->Tell() - nStart, 4);
4158 	*pS >> nWidth;
4159 	*pS >> nHeight;
4160     *pS >> nScrollWidth;
4161     *pS >> nScrollHeight;
4162 
4163     if (pBlockFlags[1] & 0x10)
4164     {
4165         *pS >> nScrollLeft;
4166         *pS >> nScrollTop;
4167     }
4168 
4169 	if (nIcon)
4170 	{
4171 		pS->Read(pIconHeader,20);
4172 		*pS >> nIconLen;
4173 		pIcon = new sal_uInt8[nIconLen];
4174 		pS->Read(pIcon,nIconLen);
4175 	}
4176 
4177 	if (nPicture)
4178 	{
4179 		pS->Read(pPictureHeader,20);
4180 		*pS >> nPictureLen;
4181 		pPicture = new sal_uInt8[nPictureLen];
4182 		pS->Read(pPicture,nPictureLen);
4183 	}
4184 
4185     ReadAlign( pS, pS->Tell() - nStart, 4);
4186 
4187     if (pBlockFlags[2] & 0x10)
4188     {
4189         //Font Stuff..
4190         pS->SeekRel(0x1a);
4191         sal_uInt8 nFontLen;
4192         *pS >> nFontLen;
4193         pS->SeekRel(nFontLen);
4194     }
4195 
4196     sal_Int16 numTrailingRecs = 0;
4197     *pS >> numTrailingRecs;
4198     // seems to be no. of trailing records,
4199     // before container record starts proper
4200     // ( unknown what these trailing records are for)
4201     if ( numTrailingRecs )
4202     {
4203         for ( ; numTrailingRecs ; --numTrailingRecs )
4204         {
4205             OCX_Control skip(C2S("dummy")) ;
4206             skip.Read( pS );
4207         }
4208     }
4209 	return OCX_ContainerControl::Read( pS );
4210 }
4211 
Import(uno::Reference<container::XNameContainer> & rLib)4212 sal_Bool OCX_UserForm::Import(
4213     uno::Reference<container::XNameContainer> &rLib )
4214 {
4215     uno::Reference<beans::XPropertySet>
4216         xDialogPropSet(mxParent, uno::UNO_QUERY);
4217     uno::Any aTmp(&sName,getCppuType((OUString *)0));
4218     xDialogPropSet->setPropertyValue(
4219         OUString(RTL_CONSTASCII_USTRINGPARAM("Name")), aTmp);
4220     xDialogPropSet->setPropertyValue(
4221         OUString(RTL_CONSTASCII_USTRINGPARAM("Title")), aTmp);
4222     aTmp <<= ImportColor(mnBackColor);
4223 	xDialogPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
4224 
4225     aTmp <<= sal_Int32((nWidth * 2) / 100);
4226     xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
4227     aTmp <<= sal_Int32((nHeight * 2) / 100);
4228     xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
4229 
4230     uno::Reference<beans::XPropertySet> xPropSet( mxParent, uno::UNO_QUERY );
4231     OCX_ContainerControl::Import( xPropSet );
4232 
4233     uno::Reference<io::XInputStreamProvider> xSource =
4234         xmlscript::exportDialogModel(mxParent, mxCtx);
4235     uno::Any aSourceAny(uno::makeAny(xSource));
4236     if (rLib->hasByName(sName))
4237         rLib->replaceByName(sName, aSourceAny);
4238     else
4239         rLib->insertByName(sName, aSourceAny);
4240     return sal_True;
4241 }
4242 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)4243 sal_Bool OCX_Label::WriteContents(SvStorageStreamRef &rContents,
4244 	const uno::Reference< beans::XPropertySet > &rPropSet,
4245 	const awt::Size &rSize)
4246 {
4247 	sal_Bool bRet = sal_True;
4248     sal_uInt32 nOldPos = rContents->Tell();
4249 	rContents->SeekRel(8);
4250 	pBlockFlags[0] = 0x20;
4251 	pBlockFlags[1] = 0;
4252 	pBlockFlags[2] = 0;
4253 	pBlockFlags[3] = 0;
4254 
4255 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
4256     if (aTmp.hasValue())
4257 	    aTmp >>= mnForeColor;
4258 	*rContents << ExportColor(mnForeColor);
4259 	pBlockFlags[0] |= 0x01;
4260 
4261 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
4262     if (aTmp.hasValue())
4263 	    aTmp >>= mnBackColor;
4264 	*rContents << ExportColor(mnBackColor);
4265 	pBlockFlags[0] |= 0x02;
4266 
4267 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
4268 	fEnabled = any2bool(aTmp);
4269 	sal_uInt8 nTemp=fEnabled;
4270 	if (fEnabled)
4271 		nTemp = nTemp << 1;
4272 	*rContents << nTemp;
4273 	*rContents << sal_uInt8(0x00);
4274 
4275 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("MultiLine"));
4276 	fWordWrap = any2bool(aTmp);
4277 	nTemp=fWordWrap;
4278 	nTemp = nTemp << 7;
4279 	*rContents << nTemp;
4280 	*rContents << sal_uInt8(0x00);
4281 	pBlockFlags[0] |= 0x04;
4282 
4283     SvxOcxString aCaption( rPropSet->getPropertyValue(WW8_ASCII2STR("Label")) );
4284     aCaption.WriteLenField( *rContents );
4285     if (aCaption.HasData())
4286 		pBlockFlags[0] |= 0x08;
4287 
4288     WriteAlign(rContents,4);
4289     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BorderColor"));
4290     if (aTmp.hasValue())
4291         aTmp >>= nBorderColor;
4292     *rContents << ExportColor(nBorderColor);
4293     pBlockFlags[0] |= 0x80;
4294 
4295 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Border"));
4296 	sal_Int16 nBorder = sal_Int16();
4297 	aTmp >>= nBorder;
4298 	sal_uInt8 nNewBorder;
4299 	nSpecialEffect = ExportBorder(nBorder,nNewBorder);
4300 	nBorderStyle = nNewBorder;
4301 	*rContents << nBorderStyle;
4302 	pBlockFlags[1] |= 0x01;
4303 	*rContents << nSpecialEffect;
4304 	pBlockFlags[1] |= 0x02;
4305 
4306     aCaption.WriteCharArray( *rContents );
4307 
4308 	WriteAlign(rContents,4);
4309 	*rContents << rSize.Width;
4310 	*rContents << rSize.Height;
4311     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
4312 
4313 	bRet = aFontData.Export(rContents,rPropSet);
4314 
4315     rContents->Seek(nOldPos);
4316 	*rContents << nStandardId;
4317 	*rContents << nFixedAreaLen;
4318 
4319 	*rContents << pBlockFlags[0];
4320 	*rContents << pBlockFlags[1];
4321 	*rContents << pBlockFlags[2];
4322 	*rContents << pBlockFlags[3];
4323 
4324 	DBG_ASSERT((rContents.Is() &&
4325 		(SVSTREAM_OK==rContents->GetError())),"damn");
4326 	return bRet;
4327 }
4328 
4329 
4330 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)4331 sal_Bool OCX_Label::Export(SvStorageRef &rObj,
4332 	const uno::Reference< beans::XPropertySet > &rPropSet,
4333 	const awt::Size &rSize)
4334 {
4335 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
4336 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
4337 		0xFF, 0xFF, 0xFF, 0xFF, 0x23, 0x9E, 0x8C, 0x97,
4338 		0xB0, 0xD4, 0xCE, 0x11, 0xBF, 0x2D, 0x00, 0xAA,
4339 		0x00, 0x3F, 0x40, 0xD0, 0x1A, 0x00, 0x00, 0x00,
4340 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
4341 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
4342 		0x32, 0x2E, 0x30, 0x20, 0x4C, 0x61, 0x62, 0x65,
4343 		0x6C, 0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D,
4344 		0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F,
4345 		0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x0E, 0x00,
4346 		0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E,
4347 		0x4C, 0x61, 0x62, 0x65, 0x6C, 0x2E, 0x31, 0x00,
4348 		0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
4349 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4350 		};
4351 
4352 	{
4353 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
4354 	xStor->Write(aCompObj,sizeof(aCompObj));
4355 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
4356 	}
4357 
4358 	{
4359 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
4360 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
4361 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
4362 	}
4363 
4364 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
4365 		0x4C, 0x00, 0x61, 0x00, 0x62, 0x00, 0x65, 0x00,
4366 		0x6C, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00
4367 		};
4368 
4369 	{
4370 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
4371 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
4372 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
4373 	}
4374 /*
4375 	static sal_uInt8 __READONLY_DATA aTest[] = {
4376 		0x00, 0x02, 0x20, 0x00, 0x2B, 0x00, 0x00, 0x00,
4377 		0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00,
4378 		0x06, 0x00, 0x00, 0x80, 0x4C, 0x61, 0x62, 0x65,
4379 		0x6C, 0x31, 0x18, 0x00, 0xEC, 0x09, 0x00, 0x00,
4380 		0x7B, 0x02, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00,
4381 		0x35, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x80,
4382 		0xC3, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
4383 		0x54, 0x69, 0x6D, 0x65, 0x73, 0x20, 0x4E, 0x65,
4384 		0x77, 0x20, 0x52, 0x6F, 0x6D, 0x61, 0x6E, 0x00,
4385 		};
4386 */
4387 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
4388 	return WriteContents(xContents, rPropSet, rSize);
4389 }
4390 
4391 typedef OCX_Control *(*FNCreate)();
4392 
4393 
4394 struct OCX_map
4395 {
4396 	FNCreate pCreate;
4397 	const char *sId;
4398 	sal_Int16 nId;
4399 	const char *sName;
4400 };
4401 
4402 OCX_map aOCXTab[] =
4403 {
4404     // Command button MUST be at index 0
4405     {&OCX_CommandButton::Create,"D7053240-CE69-11CD-a777-00dd01143c57",
4406         form::FormComponentType::COMMANDBUTTON,"CommandButton"},
4407     // Toggle button MUST be at index 1
4408     {&OCX_ToggleButton::Create,"8BD21D60-EC42-11CE-9e0d-00aa006002f3",
4409         form::FormComponentType::COMMANDBUTTON,"ToggleButton"},
4410 	{&OCX_Label::Create, "978C9E23-D4B0-11CE-bf2d-00aa003f40d0",
4411 		form::FormComponentType::FIXEDTEXT,"Label"},
4412 	{&OCX_TextBox::Create,"8BD21D10-EC42-11CE-9e0d-00aa006002f3",
4413 		form::FormComponentType::TEXTFIELD,"TextBox"},
4414 	{&OCX_ListBox::Create,"8BD21D20-EC42-11CE-9e0d-00aa006002f3",
4415 		form::FormComponentType::LISTBOX,"ListBox"},
4416 	{&OCX_ComboBox::Create,"8BD21D30-EC42-11CE-9e0d-00aa006002f3",
4417 		form::FormComponentType::COMBOBOX,"ComboBox"},
4418 	{&OCX_CheckBox::Create,"8BD21D40-EC42-11CE-9e0d-00aa006002f3",
4419 		form::FormComponentType::CHECKBOX,"CheckBox"},
4420 	{&OCX_OptionButton::Create,"8BD21D50-EC42-11CE-9e0d-00aa006002f3",
4421 		form::FormComponentType::RADIOBUTTON,"OptionButton"},
4422 	{&OCX_Image::Create,"4C599241-6926-101B-9992-00000b65c6f9",
4423 		form::FormComponentType::IMAGECONTROL,"Image"},
4424 	{&OCX_FieldControl::Create,"8BD21D10-EC42-11CE-9e0d-00aa006002f3",
4425 		form::FormComponentType::DATEFIELD,"TextBox"},
4426 	{&OCX_FieldControl::Create,"8BD21D10-EC42-11CE-9e0d-00aa006002f3",
4427 		form::FormComponentType::TIMEFIELD,"TextBox"},
4428 	{&OCX_FieldControl::Create,"8BD21D10-EC42-11CE-9e0d-00aa006002f3",
4429 		form::FormComponentType::NUMERICFIELD,"TextBox"},
4430 	{&OCX_FieldControl::Create,"8BD21D10-EC42-11CE-9e0d-00aa006002f3",
4431 		form::FormComponentType::CURRENCYFIELD,"TextBox"},
4432 	{&OCX_FieldControl::Create,"8BD21D10-EC42-11CE-9e0d-00aa006002f3",
4433 		form::FormComponentType::PATTERNFIELD,"TextBox"},
4434 #if 0
4435 	{&OCX_FieldControl::Create,"8BD21D10-EC42-11CE-9e0d-00aa006002f3",
4436 		form::FormComponentType::FORMULAFIELD,"TextBox"},
4437 #endif
4438 	{&OCX_ImageButton::Create,"D7053240-CE69-11CD-a777-00dd01143c57",
4439 		form::FormComponentType::IMAGEBUTTON,"CommandButton"},
4440     {&OCX_SpinButton::Create,"79176FB0-B7F2-11CE-97ef-00aa006d2776",
4441         form::FormComponentType::SPINBUTTON,"SpinButton"},
4442     {&OCX_ScrollBar::Create,"DFD181E0-5E2F-11CE-a449-00aa004a803d",
4443         form::FormComponentType::SCROLLBAR,"ScrollBar"},
4444 	{&OCX_GroupBox::Create,"",
4445 		form::FormComponentType::GROUPBOX,""},
4446     {&OCX_ProgressBar::Create,"",
4447         form::FormComponentType::CONTROL,""}
4448 };
4449 
4450 const int NO_OCX = sizeof( aOCXTab ) / sizeof( *aOCXTab );
4451 
SvxMSConvertOCXControls(SfxObjectShell * pDSh,SwPaM * pP)4452 SvxMSConvertOCXControls::SvxMSConvertOCXControls(SfxObjectShell *pDSh, SwPaM *pP) :
4453     pDocSh(pDSh), pPaM(pP), nEdit(0), nCheckbox(0)
4454 {
4455     DBG_ASSERT( pDocSh, "No DocShell, Cannot do Controls" );
4456     OCX_Control::FillSystemColors();
4457 }
4458 
~SvxMSConvertOCXControls()4459 SvxMSConvertOCXControls::~SvxMSConvertOCXControls()
4460 {
4461 }
4462 
OCX_Factory(const String & sName)4463 OCX_Control * SvxMSConvertOCXControls::OCX_Factory(const String &sName)
4464 {
4465 	for (int i=0;i<NO_OCX;i++)
4466 	{
4467         if ( sName.EqualsIgnoreCaseAscii( aOCXTab[i].sId ))
4468 			return(aOCXTab[i].pCreate());
4469 	}
4470 	return(NULL);
4471 }
4472 
OCX_Factory(const uno::Reference<awt::XControlModel> & rControlModel,String & rId,String & rName)4473 OCX_Control * SvxMSConvertOCXControls::OCX_Factory(
4474 	const uno::Reference< awt::XControlModel > &rControlModel,
4475 	String &rId, String &rName)
4476 {
4477 	rName.Erase();
4478 	rId.Erase();
4479 
4480 	uno::Reference< beans::XPropertySet > xPropSet(
4481 		rControlModel,uno::UNO_QUERY);
4482 
4483 	uno::Any aTmp = xPropSet->getPropertyValue(
4484 		OUString::createFromAscii("ClassId"));
4485 	sal_Int16 nClassId = *(sal_Int16*) aTmp.getValue();
4486 
4487 //Begin nasty hack
4488 	/*
4489 	There is a truly horrible thing with EditControls and FormattedField
4490 	Controls, they both pretend to have an EDITBOX ClassId for compatibility
4491 	reasons, at some stage in the future hopefully there will be a proper
4492 	FormulaField ClassId rather than this piggybacking two controls onto the
4493 	same ClassId, when this happens uncomment the FORMULAFIELD in the OCX_Tab
4494 	and delete this block, cmc.
4495 
4496 	And also the nClassId for ImageControls is being reported as "CONTROL"
4497 	rather than IMAGECONTROL
4498 	*/
4499 	if (nClassId == form::FormComponentType::TEXTFIELD)
4500 	{
4501 		uno::Reference< lang::XServiceInfo > xInfo(rControlModel,
4502 			uno::UNO_QUERY);
4503 		if (xInfo->
4504 			supportsService(OUString::createFromAscii(
4505 				"com.sun.star.form.component.FormattedField")))
4506 		{
4507 			rId.AppendAscii("8BD21D10-EC42-11CE-9e0d-00aa006002f3");
4508 			rName.AppendAscii("TextBox");
4509 			return new OCX_FieldControl;
4510 		}
4511 	}
4512 	else if (nClassId == form::FormComponentType::CONTROL)
4513 	{
4514 		uno::Reference< lang::XServiceInfo > xInfo(rControlModel,
4515 			uno::UNO_QUERY);
4516 		if (xInfo->
4517 			supportsService(OUString::createFromAscii(
4518 				"com.sun.star.form.component.ImageControl")))
4519 		nClassId = form::FormComponentType::IMAGECONTROL;
4520 	}
4521 //End nasty hack
4522 
4523     const OCX_map* pEntry = 0;
4524 
4525     // distinguish between push button and toggle button
4526     if( nClassId == form::FormComponentType::COMMANDBUTTON )
4527     {
4528         pEntry = any2bool(xPropSet->getPropertyValue(WW8_ASCII2STR("Toggle"))) ?
4529             (aOCXTab + 1) : aOCXTab;
4530     }
4531     else
4532     {
4533         for( int i = 2; (i < NO_OCX) && !pEntry; ++i )
4534             if( nClassId == aOCXTab[ i ].nId )
4535                 pEntry = aOCXTab + i;
4536     }
4537 
4538     if( pEntry )
4539     {
4540         rId.AppendAscii( pEntry->sId );
4541         rName.AppendAscii( pEntry->sName );
4542         return pEntry->pCreate();
4543     }
4544 
4545     return 0;
4546 }
4547 
4548 
ReadOCXStream(SvStorageRef & rSrc1,uno::Reference<drawing::XShape> * pShapeRef,sal_Bool bFloatingCtrl)4549 sal_Bool SvxMSConvertOCXControls::ReadOCXStream( SvStorageRef& rSrc1,
4550 		uno::Reference < drawing::XShape > *pShapeRef,sal_Bool bFloatingCtrl)
4551 {
4552 
4553 	SvStorageStreamRef xCrash = rSrc1->OpenSotStream( WW8_ASCII2STR("contents") );
4554 	sal_Bool bRet=sal_False;
4555 
4556 	SvStorageStreamRef xSrc2 = rSrc1->OpenSotStream( WW8_ASCII2STR("\3OCXNAME") );
4557 	SvStorageStream* pSt = xSrc2;
4558 	pSt->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
4559 
4560     /* #117832# import control name */
4561     OUString controlName;
4562     bool hasCName = readOCXNAME( controlName, pSt );
4563 
4564 	xSrc2 = rSrc1->OpenSotStream( WW8_ASCII2STR("contents") );
4565 	pSt = xSrc2;
4566 	pSt->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
4567 
4568 	/*Get Class Id of this object, see if it is one of the types
4569 	 *that this importer can handle, call the appropriate handler
4570 	 to read that control, and call the appropriate handler to
4571 	 insert that control
4572 	 */
4573 
4574 	SvGlobalName aTest = rSrc1->GetClassName();
4575 	OCX_Control *pObj = OCX_Factory(aTest.GetHexName());
4576 	if (pObj)
4577 	{
4578         pObj->pDocSh = pDocSh;
4579         /* #117832# set imported control name */
4580         if ( hasCName )
4581         {
4582             pObj->sName = controlName;
4583         }
4584 		com::sun::star::awt::Size aSz;
4585 		uno::Reference< form::XFormComponent >  xFComp;
4586 		const uno::Reference< lang::XMultiServiceFactory > & rServiceFactory =
4587 			GetServiceFactory();
4588 		if(!rServiceFactory.is())
4589 			return(sal_False);
4590         bRet = pObj->FullRead(pSt);
4591 		if(bRet)
4592 			if (pObj->Import(rServiceFactory,xFComp,aSz))
4593 				bRet = InsertControl( xFComp, aSz,pShapeRef,bFloatingCtrl);
4594 		delete pObj;
4595 	}
4596 	return bRet;
4597 }
4598 
4599 
ReadOCXExcelKludgeStream(SvStorageStreamRef & rSrc1,uno::Reference<drawing::XShape> * pShapeRef,sal_Bool bFloatingCtrl)4600 sal_Bool SvxMSConvertOCXControls::ReadOCXExcelKludgeStream(
4601 	SvStorageStreamRef& rSrc1, uno::Reference < drawing::XShape > *
4602 	pShapeRef,sal_Bool bFloatingCtrl)
4603 {
4604 	sal_Bool bRet=sal_False;
4605 	/*Get Class Id of this object, see if it is one of the types
4606 	 *that this importer can handle, call the appropriate handler
4607 	 to read that control, and call the appropriate handler to
4608 	 insert that control
4609 	 */
4610 	/*The Excel Kludge is to concatenate a class id with a contents
4611 	 * stream, and then concatenate all the controls together,
4612 	 * This means that you should have the cnts stream wound to the
4613 	 * correct location before passing the control stream in here*/
4614 	SvStream *pSt = rSrc1;
4615 	pSt->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
4616 	SvGlobalName aTest;
4617 	*pSt >> aTest;
4618 	OCX_Control *pObj = OCX_Factory(aTest.GetHexName());
4619 	if (pObj)
4620 	{
4621 
4622 		com::sun::star::awt::Size aSz;
4623 		uno::Reference< form::XFormComponent >  xFComp;
4624 		const uno::Reference< lang::XMultiServiceFactory > & rServiceFactory =
4625 			GetServiceFactory();
4626 		if(!rServiceFactory.is())
4627 			return(sal_False);
4628         bRet = pObj->FullRead(rSrc1);
4629 		if(bRet)
4630 			if (pObj->Import(rServiceFactory,xFComp,aSz))
4631 				bRet = InsertControl( xFComp, aSz,pShapeRef,bFloatingCtrl);
4632 		delete pObj;
4633 	}
4634 	return bRet;
4635 }
4636 
4637 
WriteOCXStream(SvStorageRef & rSrc1,const uno::Reference<awt::XControlModel> & rControlModel,const awt::Size & rSize,String & rName)4638 sal_Bool SvxMSConvertOCXControls::WriteOCXStream( SvStorageRef& rSrc1,
4639 	const uno::Reference< awt::XControlModel > &rControlModel,
4640 	const awt::Size &rSize, String &rName)
4641 {
4642 	sal_Bool bRet=sal_False;
4643 
4644 	DBG_ASSERT( rControlModel.is(), "UNO-Control missing Model, panic!" );
4645 	if( !rControlModel.is() )
4646 		return sal_False;
4647 
4648 #if 0
4649 	uno::Any aTmp = xPropSet->getPropertyValue(
4650 		OUString::createFromAscii("ClassId"));
4651 	sal_Int16 nClassId = *(sal_Int16*) aTmp.getValue();
4652 #endif
4653 
4654 	String sId;
4655 	OCX_Control *pObj = OCX_Factory(rControlModel,sId,rName);
4656 	if (pObj != NULL)
4657 	{
4658 		uno::Reference<beans::XPropertySet> xPropSet(rControlModel,
4659 			uno::UNO_QUERY);
4660 
4661         /* #117832# - also enable export of control name  */
4662         OUString sCName;
4663         xPropSet->getPropertyValue(C2S("Name")) >>= sCName;
4664         pObj->sName = sCName;
4665 
4666 		SvGlobalName aName;
4667 		aName.MakeId(sId);
4668 		String sFullName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(
4669 			"Microsoft Forms 2.0 ")));
4670 		sFullName.Append(rName);
4671 		rSrc1->SetClass(aName,0x5C,sFullName);
4672 		//                    ^^^^, this pathetic 0x5c is the magic number
4673 		// which the lack of originally blocked the implementation of
4674 		// the controls export
4675 		// cmc
4676 
4677 		bRet = pObj->Export(rSrc1,xPropSet,rSize);
4678         SvStorageStreamRef xStor2( rSrc1->OpenSotStream( WW8_ASCII2STR("\3OCXNAME")));
4679         /* #117832# - also enable export of control name  */
4680         writeOCXNAME( sCName, xStor2 );
4681 		delete pObj;
4682 	}
4683 	return bRet;
4684 }
4685 
4686 
4687 //I think this should work for excel documents, create the "Ctls" stream
4688 //and give it here as rContents, we'll append out streams ole id and
4689 //contents here and that appears to be what Excel is doing
WriteOCXExcelKludgeStream(SvStorageStreamRef & rContents,const uno::Reference<awt::XControlModel> & rControlModel,const awt::Size & rSize,String & rName)4690 sal_Bool SvxMSConvertOCXControls::WriteOCXExcelKludgeStream(
4691 	SvStorageStreamRef& rContents,
4692 	const uno::Reference< awt::XControlModel > &rControlModel,
4693 	const awt::Size &rSize, String &rName)
4694 {
4695 	sal_Bool bRet=sal_False;
4696 
4697 	DBG_ASSERT( rControlModel.is(), "UNO-Control missing Model, panic!" );
4698 	if( !rControlModel.is() )
4699 		return sal_False;
4700 
4701 	String sId;
4702 	OCX_Control *pObj = OCX_Factory(rControlModel,sId,rName);
4703 	if (pObj != NULL)
4704 	{
4705 		uno::Reference<beans::XPropertySet> xPropSet(rControlModel,
4706 			uno::UNO_QUERY);
4707 
4708 		SvGlobalName aName;
4709 		aName.MakeId(sId);
4710 		String sFullName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(
4711 			"Microsoft Forms 2.0 ")));
4712 		sFullName.Append(rName);
4713 		SvStream *pS=rContents;
4714 		*pS << aName;
4715 		bRet = pObj->WriteContents(rContents,xPropSet,rSize);
4716 		delete pObj;
4717         // export needs correct stream position
4718         rContents->Seek( STREAM_SEEK_TO_END );
4719 	}
4720 	return bRet;
4721 }
4722 
4723 
4724 
4725 
4726 
4727 
4728 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)4729 sal_Bool OCX_CheckBox::Import(com::sun::star::uno::Reference<
4730     com::sun::star::beans::XPropertySet> &rPropSet)
4731 {
4732 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
4733 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
4734 
4735     // background color: fBackStyle==0 -> transparent
4736     if( fBackStyle )
4737         aTmp <<= ImportColor(mnBackColor);
4738     else
4739         aTmp = uno::Any();
4740     rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
4741 
4742 	sal_Bool bTemp;
4743 	if ((!(fEnabled)) || (fLocked))
4744 		bTemp = sal_False;
4745 	else
4746 		bTemp = sal_True;
4747 	aTmp = bool2any(bTemp);
4748 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
4749 
4750     bTemp = fWordWrap != 0;
4751     aTmp = bool2any(bTemp);
4752     rPropSet->setPropertyValue( WW8_ASCII2STR("MultiLine"), aTmp);
4753 
4754 	aTmp <<= ImportColor(mnForeColor);
4755 	rPropSet->setPropertyValue( WW8_ASCII2STR("TextColor"), aTmp);
4756 
4757 	bTemp = nMultiState;
4758 	aTmp = bool2any(bTemp);
4759 	rPropSet->setPropertyValue( WW8_ASCII2STR("TriState"), aTmp);
4760 
4761     aTmp <<= ImportSpecEffect( nSpecialEffect );
4762     rPropSet->setPropertyValue( WW8_ASCII2STR("VisualEffect"), aTmp);
4763 
4764 	if (pValue && !bSetInDialog)
4765 	{
4766 		sal_Int16 nTmp=pValue[0]-0x30;
4767 		aTmp <<= nTmp;
4768 		rPropSet->setPropertyValue( WW8_ASCII2STR("DefaultState"), aTmp);
4769 	}
4770 
4771 	if (pCaption)
4772 	{
4773         aTmp <<= lclCreateOUString( pCaption, nCaptionLen );
4774 		rPropSet->setPropertyValue( WW8_ASCII2STR("Label"), aTmp);
4775 	}
4776 
4777     // #i40279# always centered vertically
4778     aTmp <<= ::com::sun::star::style::VerticalAlignment_MIDDLE;
4779     rPropSet->setPropertyValue( WW8_ASCII2STR("VerticalAlign"), aTmp );
4780 
4781     aFontData.Import(rPropSet);
4782 	return(sal_True);
4783 }
4784 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)4785 sal_Bool OCX_CheckBox::WriteContents(SvStorageStreamRef &rContents,
4786     const uno::Reference< beans::XPropertySet > &rPropSet,
4787 	const awt::Size &rSize)
4788 
4789 {
4790 	sal_Bool bRet=sal_True;
4791     sal_uInt32 nOldPos = rContents->Tell();
4792 	rContents->SeekRel(12);
4793 
4794 	pBlockFlags[0] = 0;
4795 	pBlockFlags[1] = 0x01;
4796 	pBlockFlags[2] = 0;
4797 	pBlockFlags[3] = 0x80;
4798 	pBlockFlags[4] = 0;
4799 	pBlockFlags[5] = 0;
4800 	pBlockFlags[6] = 0;
4801 	pBlockFlags[7] = 0;
4802 
4803 	uno::Any aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
4804 	fEnabled = any2bool(aTmp);
4805 
4806     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("BackgroundColor"));
4807     fBackStyle = aTmp.hasValue() ? 1 : 0;
4808     if (fBackStyle)
4809         aTmp >>= mnBackColor;
4810 
4811 	sal_uInt8 nTemp=fEnabled;
4812 	if (fEnabled)
4813 		nTemp = nTemp << 1;
4814     if (fBackStyle)
4815         nTemp |= 0x08;
4816 	*rContents << nTemp;
4817 	pBlockFlags[0] |= 0x01;
4818 	*rContents << sal_uInt8(0x00);
4819     nTemp = 0;
4820     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("MultiLine"));
4821     fWordWrap = any2bool(aTmp);
4822     if (fWordWrap)
4823         nTemp |= 0x80;
4824     *rContents << nTemp;
4825     *rContents << sal_uInt8(0x00);
4826 
4827     *rContents << ExportColor(mnBackColor);
4828     pBlockFlags[0] |= 0x02;
4829 
4830 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TextColor"));
4831     if (aTmp.hasValue())
4832 	    aTmp >>= mnForeColor;
4833 	*rContents << ExportColor(mnForeColor);
4834 	pBlockFlags[0] |= 0x04;
4835 
4836 	nStyle = 4;
4837 	*rContents << nStyle;
4838 	pBlockFlags[0] |= 0x40;
4839 
4840 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("TriState"));
4841 	nMultiState = any2bool(aTmp);
4842 	*rContents << nMultiState;
4843 	pBlockFlags[2] |= 0x20;
4844 
4845 	WriteAlign(rContents,4);
4846     nValueLen = 1|SVX_MSOCX_COMPRESSED;
4847 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("DefaultState"));
4848 	sal_Int16 nDefault = sal_Int16();
4849 	aTmp >>= nDefault;
4850 	*rContents << nValueLen;
4851 	pBlockFlags[2] |= 0x40;
4852 
4853     SvxOcxString aCaption( rPropSet->getPropertyValue(WW8_ASCII2STR("Label")) );
4854     aCaption.WriteLenField( *rContents );
4855     if (aCaption.HasData())
4856 		pBlockFlags[2] |= 0x80;
4857 
4858     aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("VisualEffect"));
4859     if (aTmp.hasValue())
4860     {
4861         sal_Int16 nApiSpecEffect = sal_Int16();
4862         aTmp >>= nApiSpecEffect;
4863         nSpecialEffect = ExportSpecEffect( nApiSpecEffect );
4864     }
4865 	WriteAlign(rContents,4);
4866     *rContents << nSpecialEffect;
4867     pBlockFlags[3] |= 0x04;
4868 
4869 	WriteAlign(rContents,4);
4870 	*rContents << rSize.Width;
4871 	*rContents << rSize.Height;
4872 
4873 	nDefault += 0x30;
4874 	*rContents << sal_uInt8(nDefault);
4875 	*rContents << sal_uInt8(0x00);
4876 
4877     aCaption.WriteCharArray( *rContents );
4878 
4879 	WriteAlign(rContents,4);
4880     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
4881 	bRet = aFontData.Export(rContents,rPropSet);
4882     rContents->Seek(nOldPos);
4883 	*rContents << nStandardId;
4884 	*rContents << nFixedAreaLen;
4885 
4886 	*rContents << pBlockFlags[0];
4887 	*rContents << pBlockFlags[1];
4888 	*rContents << pBlockFlags[2];
4889 	*rContents << pBlockFlags[3];
4890 	*rContents << pBlockFlags[4];
4891 	*rContents << pBlockFlags[5];
4892 	*rContents << pBlockFlags[6];
4893 	*rContents << pBlockFlags[7];
4894 
4895 	DBG_ASSERT((rContents.Is() &&
4896 		(SVSTREAM_OK==rContents->GetError())),"damn");
4897 	return bRet;
4898 }
4899 
4900 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)4901 sal_Bool OCX_CheckBox::Export(SvStorageRef &rObj,
4902     const uno::Reference< beans::XPropertySet > &rPropSet,
4903 	const awt::Size &rSize)
4904 
4905 {
4906 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
4907 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
4908 		0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x1D, 0xD2, 0x8B,
4909 		0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
4910 		0x00, 0x60, 0x02, 0xF3, 0x1D, 0x00, 0x00, 0x00,
4911 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
4912 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
4913 		0x32, 0x2E, 0x30, 0x20, 0x43, 0x68, 0x65, 0x63,
4914 		0x6B, 0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00,
4915 		0x00, 0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65,
4916 		0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74,
4917 		0x00, 0x11, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72,
4918 		0x6D, 0x73, 0x2E, 0x43, 0x68, 0x65, 0x63, 0x6B,
4919 		0x42, 0x6F, 0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39,
4920 		0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4921 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4922 	};
4923 
4924 	{
4925 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
4926 	xStor->Write(aCompObj,sizeof(aCompObj));
4927 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
4928 	}
4929 
4930 	{
4931 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
4932 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
4933 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
4934 	}
4935 
4936 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
4937 		0x43, 0x00, 0x68, 0x00, 0x65, 0x00, 0x63, 0x00,
4938 		0x6B, 0x00, 0x42, 0x00, 0x6F, 0x00, 0x78, 0x00,
4939 		0x31, 0x00, 0x00, 0x00, 0x00, 0x00
4940 		};
4941 	{
4942 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
4943 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
4944 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
4945 	}
4946 /*
4947 	static sal_uInt8 __READONLY_DATA aTest[] = {
4948 		0x00, 0x02, 0x34, 0x00, 0x46, 0x01, 0xC0, 0x80,
4949 		0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00,
4950 		0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
4951 		0x01, 0x00, 0x00, 0x80, 0x09, 0x00, 0x00, 0x80,
4952 		0xE2, 0x0E, 0x00, 0x00, 0x95, 0x02, 0x00, 0x00,
4953 		0x30, 0x69, 0x1D, 0x00, 0x43, 0x68, 0x65, 0x63,
4954 		0x6B, 0x42, 0x6F, 0x78, 0x31, 0x20, 0x52, 0x6F,
4955 		0x00, 0x02, 0x20, 0x00, 0x35, 0x00, 0x00, 0x00,
4956 		0x0F, 0x00, 0x00, 0x80, 0xC3, 0x00, 0x00, 0x00,
4957 		0x00, 0x02, 0x00, 0x00, 0x54, 0x69, 0x6D, 0x65,
4958 		0x73, 0x20, 0x4E, 0x65, 0x77, 0x20, 0x52, 0x6F,
4959 		0x6D, 0x61, 0x6E, 0x00,
4960 	};
4961 */
4962 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
4963 	return WriteContents(xContents, rPropSet, rSize);
4964 }
4965 
4966 
Read(SvStorageStream * pS)4967 sal_Bool OCX_FontData::Read(SvStorageStream *pS)
4968 {
4969     long nStart = pS->Tell();
4970 	*pS >> nIdentifier;
4971 	*pS >> nFixedAreaLen;
4972 	pS->Read(pBlockFlags,4);
4973 
4974     bool bFontName = (pBlockFlags[0] & 0x01) != 0;
4975     if (bFontName)
4976 		*pS >> nFontNameLen;
4977 	if (pBlockFlags[0] & 0x02)
4978 	{
4979 		sal_uInt8 nTmp;
4980 		*pS >> nTmp;
4981 		fBold = nTmp & 0x01;
4982 		fItalic = (nTmp & 0x02) >> 1;
4983 		fUnderline = (nTmp & 0x04) >> 2;
4984 		fStrike = (nTmp & 0x08) >> 3;
4985 		fUnknown1 = (nTmp & 0xF0) >> 4;
4986 		*pS >> nUnknown2;
4987 		*pS >> nUnknown3;
4988 		*pS >> nUnknown4;
4989 	}
4990 	if (pBlockFlags[0] & 0x04)
4991 	{
4992 		ReadAlign(pS, pS->Tell() - nStart, 4);
4993 		*pS >> nFontSize;
4994 	}
4995     else
4996         nFontSize = 240;
4997 	if (pBlockFlags[0] & 0x10)
4998 	{
4999 		ReadAlign(pS, pS->Tell() - nStart, 2);
5000 		*pS >> nLanguageID;
5001 	}
5002 	if (pBlockFlags[0] & 0x40)
5003     {
5004 		*pS >> nJustification;
5005     }
5006     if (pBlockFlags[0] & 0x80)  // font weight before font name
5007     {
5008         ReadAlign(pS, pS->Tell() - nStart, 2);
5009         *pS >> nFontWeight;
5010     }
5011 
5012     if (bFontName)
5013         lclReadCharArray( *pS, pFontName, nFontNameLen, pS->Tell() - nStart);
5014 
5015 	ReadAlign(pS, pS->Tell() - nStart, 4);
5016 	return(sal_True);
5017 }
5018 
Import(uno::Reference<beans::XPropertySet> & rPropSet)5019 void OCX_FontData::Import(uno::Reference< beans::XPropertySet > &rPropSet)
5020 {
5021 	uno::Any aTmp;
5022 	if (pFontName)
5023 	{
5024         aTmp <<= lclCreateOUString( pFontName, nFontNameLen );
5025 		rPropSet->setPropertyValue( WW8_ASCII2STR("FontName"), aTmp);
5026 	}
5027 
5028 	if (bHasAlign)
5029 	{
5030 		sal_Int16 nAlign = ImportAlign(nJustification);
5031 		aTmp <<= nAlign;
5032 		rPropSet->setPropertyValue( WW8_ASCII2STR("Align"), aTmp);
5033 	}
5034 
5035 	if (fBold)
5036 	{
5037         aTmp <<= awt::FontWeight::BOLD;
5038 		rPropSet->setPropertyValue( WW8_ASCII2STR("FontWeight"), aTmp);
5039 	}
5040 
5041     if (fItalic)
5042     {
5043         aTmp <<= (sal_Int16)awt::FontSlant_ITALIC;
5044         rPropSet->setPropertyValue( WW8_ASCII2STR("FontSlant"), aTmp);
5045     }
5046 
5047     if (fUnderline)
5048     {
5049         aTmp <<= awt::FontUnderline::SINGLE;
5050         rPropSet->setPropertyValue( WW8_ASCII2STR("FontUnderline"), aTmp);
5051     }
5052 
5053     if (fStrike)
5054     {
5055         aTmp <<= awt::FontStrikeout::SINGLE;
5056         rPropSet->setPropertyValue( WW8_ASCII2STR("FontStrikeout"), aTmp);
5057     }
5058 
5059     // 2004-09-17: very strange way of storing font sizes...
5060     // 1pt->30, 2pt->45, 3pt->60, 4pt->75, 5pt->105, 6pt->120, 7pt->135
5061     // 8pt->165, 9pt->180, 10pt->195, 11pt->225, ...
5062     aTmp <<= sal_Int16( (nFontSize <= 30) ? 1 : ((nFontSize + 10) / 20) );
5063     rPropSet->setPropertyValue( WW8_ASCII2STR("FontHeight"), aTmp);
5064 }
5065 
Export(SvStorageStreamRef & rContent,const uno::Reference<beans::XPropertySet> & rPropSet)5066 sal_Bool OCX_FontData::Export(SvStorageStreamRef &rContent,
5067 	const uno::Reference< beans::XPropertySet > &rPropSet)
5068 {
5069 	sal_uInt8 nFlags=0x00;
5070     sal_uInt32 nOldPos = rContent->Tell();
5071 	rContent->SeekRel(8);
5072     SvxOcxString aFontName;
5073 	uno::Any aTmp;
5074 
5075 	if (bHasFont)
5076         aFontName = rPropSet->getPropertyValue(WW8_ASCII2STR("FontName"));
5077     if (!aFontName.HasData())
5078         aFontName = OUString( RTL_CONSTASCII_USTRINGPARAM( "Times New Roman" ) );
5079     aFontName.WriteLenField( *rContent );
5080 	nFlags |= 0x01;
5081 
5082 	if (bHasFont)
5083 	{
5084 		aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("FontWeight"));
5085 		//Export font related props
5086 		if ( aTmp.hasValue() )
5087 		{
5088 			float nBold = 0.0;
5089 			aTmp >>= nBold;
5090 			if ( nBold >= 150 )
5091 				fBold = 1;
5092 		}
5093 
5094 		aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("FontSlant"));
5095 		if ( aTmp.hasValue() )
5096 		{
5097 			short eItalic = 0 ;
5098 			aTmp >>= eItalic ;
5099 			if ( eItalic == awt::FontSlant_ITALIC )
5100 				fItalic = 1;
5101 		}
5102 
5103 		aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("FontUnderline"));
5104 		if ( aTmp.hasValue() )
5105 		{
5106 			short eUnderline = 0 ;
5107 			aTmp >>= eUnderline;
5108 			if ( eUnderline == awt::FontUnderline::SINGLE )
5109 				fUnderline = 1;
5110 		}
5111 
5112 		aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("FontStrikeout"));
5113 		if ( aTmp.hasValue() )
5114 		{
5115 			short eLtStrikeout = 0;
5116 			aTmp >>= eLtStrikeout;
5117 			if ( eLtStrikeout == awt::FontStrikeout::SINGLE )
5118 				fStrike = 1;
5119 		}
5120 
5121 		sal_uInt8 nTmp= 1 * fBold  +  2* fItalic  + 4* fUnderline +  8 * fStrike;
5122 		if ( nTmp > 0 )
5123 		{
5124 			nFlags |= 0x02;
5125 			*rContent << nTmp;
5126 			nTmp=0x00;
5127 			*rContent << nTmp;
5128 			*rContent << nTmp;
5129 			*rContent << nTmp;
5130 		}
5131 
5132         aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("FontHeight"));
5133         float nFontHeight = 0;
5134         aTmp >>= nFontHeight;
5135         if (nFontHeight)
5136         {
5137             nFlags |= 0x04;
5138             // 2004-09-17: very strange way of storing font sizes:
5139             // 1pt->30, 2pt->45, 3pt->60, 4pt->75, 5pt->105, 6pt->120, 7pt->135
5140             // 8pt->165, 9pt->180, 10pt->195, 11pt->225, ...
5141             nFontSize = (nFontHeight == 1) ? 30 : (static_cast<sal_uInt32>((nFontHeight*4+1)/3)*15);
5142             *rContent << nFontSize;
5143         }
5144 
5145 		if (bHasAlign)
5146 		{
5147 			*rContent << sal_uInt16(0x0200);
5148 			nFlags |= 0x10;
5149 
5150 			nFlags |= 0x20; // ?
5151 
5152 			aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Align"));
5153 			nFlags |= 0x40;
5154 			sal_Int16 nAlign = nDefaultAlign;
5155             if (aTmp.hasValue())
5156 			    aTmp >>= nAlign;
5157 			nJustification = ExportAlign(nAlign);
5158 			*rContent << nJustification;
5159 		}
5160 	}
5161 
5162     aFontName.WriteCharArray( *rContent );
5163 	WriteAlign(rContent,4);
5164 
5165     sal_uInt16 nFixedAreaLn = static_cast<sal_uInt16>(rContent->Tell()-nOldPos-4);
5166 	rContent->Seek(nOldPos);
5167 	*rContent << nStandardId;
5168 	*rContent << nFixedAreaLn;
5169 	*rContent << nFlags;
5170 	*rContent << sal_uInt8(0x00);
5171 	*rContent << sal_uInt8(0x00);
5172 	*rContent << sal_uInt8(0x00);
5173 
5174 	WriteAlign(rContent,4);
5175 	return sal_True;
5176 }
5177 
5178 // Doesn't really read anything but just skips the
5179 // record.
Read(SotStorageStream * pS)5180 sal_Bool OCX_TabStrip::Read(SotStorageStream *pS)
5181 {
5182     const long skipLen = 0x18;
5183 	*pS >> nIdentifier;
5184 	DBG_ASSERT(nStandardId==nIdentifier,
5185 		"A control that has a different identifier");
5186 	*pS >> nFixedAreaLen;
5187 
5188     pS->Read(pBlockFlags, sizeof(pBlockFlags));
5189     pS->SeekRel(skipLen);
5190     *pS >> nNumTabs;
5191     // skip to end of control
5192     pS->SeekRel(nFixedAreaLen - sizeof(pBlockFlags) - sizeof(nNumTabs) - skipLen );
5193     return sal_True;
5194 }
5195 
ReadFontData(SotStorageStream * pS)5196 sal_Bool OCX_TabStrip::ReadFontData(SotStorageStream *pS)
5197 {
5198     // Seems like there is a real font record followed by
5199     // a number of blank records ( e.g. nFixedAreaLen = 0 )
5200     // The number of trailing blank records is equal to the number of tabs
5201     OCX_Control::ReadFontData(pS);
5202     for ( sal_uInt16 index = 0; index < nNumTabs; index++ )
5203     {
5204         OCX_Control::Read(pS); // read trailing records
5205     }
5206     return sal_True;
5207 }
5208 
Read(SotStorageStream * pS)5209 sal_Bool OCX_Image::Read(SotStorageStream *pS)
5210 {
5211     if ( !bSetInDialog )
5212     {
5213         // preserve the present behavior at the moment.
5214         // only import image control for UserForms
5215         return sal_False;
5216     }
5217     sal_uLong nStart = pS->Tell();
5218 	*pS >> nIdentifier;
5219 	DBG_ASSERT(nStandardId==nIdentifier,
5220 		"A control that has a different identifier");
5221 	*pS >> nFixedAreaLen;
5222 
5223     pS->Read(pBlockFlags, sizeof(pBlockFlags));
5224 
5225     bool hasEmbeddedImage = false;
5226 
5227     if ( pBlockFlags[0] & 0x04 )
5228     {
5229         bAutoSize = true;
5230     }
5231     if ( pBlockFlags[0] & 0x08 )
5232     {
5233         *pS >> nBorderColor;
5234     }
5235     if ( pBlockFlags[0] & 0x10 )
5236     {
5237         *pS >> mnBackColor;
5238     }
5239     if ( pBlockFlags[0] & 0x20 )
5240     {
5241         *pS >> nBorderStyle;
5242     }
5243     if ( pBlockFlags[0] & 0x40 )
5244     {
5245         *pS >> nMousePointer;
5246     }
5247     if ( pBlockFlags[0] & 0x80 )
5248     {
5249         *pS >> nPictureSizeMode;
5250     }
5251 
5252     if ( pBlockFlags[ 1 ] & 0x1 )
5253     {
5254         *pS >> nSpecialEffect;
5255     }
5256     // investigate if valid also for formcontrols, although for controls
5257     // images themselves seem to come through from escher ( as shape, think
5258     // its probably a preview? )
5259 
5260     // np a bit of a guess ( until proved incorrect )
5261     if ( pBlockFlags[ 1 ] & 0x4 )
5262     {
5263         ReadAlign(pS, pS->Tell() - nStart, 2);
5264         hasEmbeddedImage = true;
5265         sal_uInt16 unknown;
5266         *pS >> unknown;
5267     }
5268 
5269 
5270     if ( pBlockFlags[ 1 ] & 0x8 )
5271     {
5272         ReadAlign(pS, pS->Tell() - nStart, 2);
5273         *pS >> nPictureAlignment;
5274 
5275     }
5276     if ( pBlockFlags[ 1 ] & 0x10 )
5277     {
5278         bPictureTiling = true;
5279     }
5280     if ( pBlockFlags[1] & 0x20 )
5281     {
5282         ReadAlign(pS, pS->Tell() - nStart, 4);
5283         sal_uInt8 nTemp;
5284         *pS >> nTemp;
5285         fEnabled = (nTemp&0x02)>>1;
5286         fBackStyle = (nTemp&0x08)>>3;
5287         // padding?
5288         *pS >> nTemp;
5289         *pS >> nTemp;
5290         *pS >> nTemp;
5291     }
5292     ReadAlign(pS, pS->Tell() - nStart, 4);
5293     *pS >> nWidth;
5294     *pS >> nHeight;
5295 
5296     if ( hasEmbeddedImage )
5297     {
5298         //image follows this block
5299         //len of image is 0x14 relative to end of this block
5300         pS->Seek( pS->Tell() + 0x14 );
5301 
5302         sal_uInt32 nImageLen = 0;
5303         *pS >> nImageLen;
5304 
5305         long imagePos = pS->Tell();
5306 
5307         pS->Seek( imagePos );
5308 
5309         sImageUrl =  C2U("vnd.sun.star.expand:${$OOO_BASE_DIR/program/") + C2U( SAL_CONFIGFILE( "bootstrap" ) ) + C2U("::UserInstallation}/user/temp/") + sName;
5310 
5311         sal_uInt8* pImage = new sal_uInt8[ nImageLen ];
5312         pS->Read(pImage, nImageLen);
5313         bool result = storePictureInFileSystem( sImageUrl, pImage, nImageLen );
5314         OUString pictName = sImageUrl.copy( sImageUrl.lastIndexOf('/') + 1 );
5315         result = storePictureInDoc( pDocSh, pictName, pImage, nImageLen );
5316         delete [] pImage;
5317     }
5318     return sal_True;
5319 }
5320 
Import(uno::Reference<beans::XPropertySet> & rPropSet)5321 sal_Bool OCX_Image::Import( uno::Reference< beans::XPropertySet > &rPropSet )
5322 {
5323 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
5324 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
5325 
5326     if( fBackStyle )
5327         aTmp <<= ImportColor(mnBackColor);
5328     else
5329         aTmp = uno::Any();
5330     rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
5331 
5332 	sal_Bool bTemp;
5333 	if (fEnabled)
5334 		bTemp = sal_True;
5335 	else
5336 		bTemp = sal_False;
5337 	aTmp = bool2any(bTemp);
5338 	rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
5339     if ( sImageUrl.getLength() )
5340     {
5341         aTmp <<= sImageUrl;
5342         rPropSet->setPropertyValue( WW8_ASCII2STR("ImageURL"), aTmp);
5343     }
5344 	return sal_True;
5345 }
5346 
WriteContents(SvStorageStreamRef & rContents,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)5347 sal_Bool OCX_Image::WriteContents(SvStorageStreamRef &rContents,
5348 	const uno::Reference< beans::XPropertySet > &rPropSet,
5349 	const awt::Size &rSize)
5350 {
5351 	sal_Bool bRet=sal_True;
5352     sal_uInt32 nOldPos = rContents->Tell();
5353 	rContents->SeekRel(8);
5354 
5355 	pBlockFlags[0] = 0;
5356 	pBlockFlags[1] = 0x02;
5357 	pBlockFlags[2] = 0;
5358 	pBlockFlags[3] = 0;
5359 
5360 	uno::Any aTmp = rPropSet->getPropertyValue(
5361 		WW8_ASCII2STR("BackgroundColor"));
5362     if (aTmp.hasValue())
5363 	    aTmp >>= mnBackColor;
5364 	*rContents << ExportColor(mnBackColor);
5365 	pBlockFlags[0] |= 0x10;
5366 
5367 
5368 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Border"));
5369 	sal_Int16 nBorder = sal_Int16();
5370 	aTmp >>= nBorder;
5371 	nSpecialEffect = ExportBorder(nBorder,nBorderStyle);
5372 	*rContents << nBorderStyle;
5373 	pBlockFlags[0] |= 0x20;
5374 
5375 	*rContents << nSpecialEffect;
5376 	pBlockFlags[1] |= 0x01;
5377 
5378 	WriteAlign(rContents,4);
5379 
5380 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("Enabled"));
5381 	fEnabled = any2bool(aTmp);
5382 	if (fEnabled)
5383 	{
5384 		sal_uInt8 nTemp = 0x19;
5385 		*rContents << nTemp;
5386 		pBlockFlags[1] |= 0x20;
5387 		*rContents << sal_uInt8(0x00);
5388 		*rContents << sal_uInt8(0x00);
5389 		*rContents << sal_uInt8(0x00);
5390 	}
5391 
5392 	aTmp = rPropSet->getPropertyValue(WW8_ASCII2STR("ImageURL"));
5393 //	OUString *pStr = (OUString *)aTmp.getValue();
5394 	/*Magically fetch that image and turn it into something that
5395 	 *we can store in ms controls, wmf,png,jpg are almost certainly
5396 	 *the options we have for export...*/
5397 
5398 	WriteAlign(rContents,4);
5399 	*rContents << rSize.Width;
5400 	*rContents << rSize.Height;
5401 
5402 	WriteAlign(rContents,4);
5403     nFixedAreaLen = static_cast<sal_uInt16>(rContents->Tell()-nOldPos-4);
5404 
5405     rContents->Seek(nOldPos);
5406 	*rContents << nStandardId;
5407 	*rContents << nFixedAreaLen;
5408 
5409 	*rContents << pBlockFlags[0];
5410 	*rContents << pBlockFlags[1];
5411 	*rContents << pBlockFlags[2];
5412 	*rContents << pBlockFlags[3];
5413 	DBG_ASSERT((rContents.Is() &&
5414 		(SVSTREAM_OK==rContents->GetError())),"damn");
5415 	return bRet;
5416 }
5417 
5418 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)5419 sal_Bool OCX_Image::Export(SvStorageRef &rObj,
5420 	const uno::Reference< beans::XPropertySet > &rPropSet,
5421 	const awt::Size &rSize)
5422 {
5423 	static sal_uInt8 __READONLY_DATA aCompObj[] = {
5424 		0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
5425 		0xFF, 0xFF, 0xFF, 0xFF, 0x41, 0x92, 0x59, 0x4C,
5426 		0x26, 0x69, 0x1B, 0x10, 0x99, 0x92, 0x00, 0x00,
5427 		0x0B, 0x65, 0xC6, 0xF9, 0x1A, 0x00, 0x00, 0x00,
5428 		0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
5429 		0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
5430 		0x32, 0x2E, 0x30, 0x20, 0x49, 0x6D, 0x61, 0x67,
5431 		0x65, 0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D,
5432 		0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F,
5433 		0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x0E, 0x00,
5434 		0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E,
5435 		0x49, 0x6D, 0x61, 0x67, 0x65, 0x2E, 0x31, 0x00,
5436 		0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
5437 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5438 		};
5439 
5440 	{
5441 	SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
5442 	xStor->Write(aCompObj,sizeof(aCompObj));
5443 	DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
5444 	}
5445 
5446 	{
5447 	SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
5448 	xStor3->Write(aObjInfo,sizeof(aObjInfo));
5449 	DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
5450 	}
5451 
5452 	static sal_uInt8 __READONLY_DATA aOCXNAME[] = {
5453 		0x49, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x67, 0x00,
5454 		0x65, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00
5455 		};
5456 
5457 	{
5458 	SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
5459 	xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
5460 	DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
5461 	}
5462 
5463 	SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
5464 	return WriteContents(xContents, rPropSet, rSize);
5465 }
5466 
5467 // ============================================================================
5468 
OCX_SpinButton()5469 OCX_SpinButton::OCX_SpinButton() :
5470     OCX_Control( OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinButton" ) ) ),
5471     mnBlockFlags( 0 ),
5472     mnValue( 0 ),
5473     mnMin( 0 ),
5474     mnMax( 100 ),
5475     mnSmallStep( 1 ),
5476     mnPageStep( 1 ),
5477     mnOrient( -1 ),
5478     mnDelay( 50 ),
5479     mbEnabled( true ),
5480     mbLocked( false ),
5481     mbPropThumb( true )
5482 {
5483     msFormType = C2U("com.sun.star.form.component.SpinButton");
5484     msDialogType = C2U("com.sun.star.awt.UnoControlSpinButtonModel");
5485     mnBackColor = 0x8000000F;
5486     mnForeColor = 0x80000012;
5487 }
5488 
Create()5489 OCX_Control* OCX_SpinButton::Create()
5490 {
5491     return new OCX_SpinButton;
5492 }
5493 
Read(SvStorageStream * pS)5494 sal_Bool OCX_SpinButton::Read( SvStorageStream *pS )
5495 {
5496     if( !pS ) return sal_False;
5497 
5498     SvStream& rStrm = *pS;
5499     sal_uInt16 nId, nSize;
5500     sal_Int32 nIcon = 0;
5501 
5502     rStrm >> nId >> nSize >> mnBlockFlags;
5503 
5504     DBG_ASSERT( nStandardId == nId, "OCX_SpinButton::Read - unknown identifier" );
5505 
5506     if( mnBlockFlags & 0x00000001 )     rStrm >> mnForeColor;
5507     if( mnBlockFlags & 0x00000002 )     rStrm >> mnBackColor;
5508     if( mnBlockFlags & 0x00000004 )
5509     {
5510         sal_Int32 nFlags;
5511         rStrm >> nFlags;
5512         mbEnabled = (nFlags & 0x00000002) != 0;
5513         mbLocked = (nFlags & 0x00000004) != 0;
5514     }
5515     if( mnBlockFlags & 0x00000010 )     rStrm.SeekRel( 4 );     // mouse pointer
5516     if( mnBlockFlags & 0x00000020 )     rStrm >> mnMin;
5517     if( mnBlockFlags & 0x00000040 )     rStrm >> mnMax;
5518     if( mnBlockFlags & 0x00000080 )     rStrm >> mnValue;
5519     if( mnBlockFlags & 0x00000100 )     rStrm.SeekRel( 4 );     // unknown
5520     if( mnBlockFlags & 0x00000200 )     rStrm.SeekRel( 4 );     // unknown
5521     if( mnBlockFlags & 0x00000400 )     rStrm.SeekRel( 4 );     // unknown
5522     if( mnBlockFlags & 0x00000800 )     rStrm >> mnSmallStep;
5523     if( mnBlockFlags & 0x00001000 )     rStrm >> mnPageStep;
5524     if( mnBlockFlags & 0x00002000 )     rStrm >> mnOrient;
5525     if( mnBlockFlags & 0x00004000 )
5526     {
5527         sal_Int32 nThumb;
5528         *pS >> nThumb;
5529         mbPropThumb = nThumb != 0;
5530     }
5531     if( mnBlockFlags & 0x00008000 )     rStrm >> mnDelay;
5532     if( mnBlockFlags & 0x00010000 )     rStrm >> nIcon;
5533     if( mnBlockFlags & 0x00000008 )     rStrm >> nWidth >> nHeight;
5534 
5535     if( nIcon )
5536     {
5537         sal_Int32 nIconSize;
5538         pS->SeekRel( 20 );
5539         *pS >> nIconSize;
5540         pS->SeekRel( nIconSize );
5541     }
5542 
5543     return sal_True;
5544 }
5545 
ReadFontData(SvStorageStream *)5546 sal_Bool OCX_SpinButton::ReadFontData( SvStorageStream* /* pS */ )
5547 {
5548     // spin buttons and scroll bars do not support font data
5549     return sal_True;
5550 }
5551 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)5552 sal_Bool OCX_SpinButton::Import(com::sun::star::uno::Reference<
5553     com::sun::star::beans::XPropertySet> &rPropSet)
5554 {
5555     if( (nWidth < 1) || (nHeight < 1) )
5556         return sal_False;
5557 
5558     uno::Any aTmp( &sName, getCppuType((OUString *)0) );
5559     rPropSet->setPropertyValue( WW8_ASCII2STR( "Name" ), aTmp );
5560 
5561     aTmp <<= ImportColor( mnForeColor );
5562     rPropSet->setPropertyValue( WW8_ASCII2STR("SymbolColor"), aTmp);
5563 
5564     aTmp <<= ImportColor( mnBackColor );
5565     rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
5566 
5567     aTmp = bool2any( mbEnabled && !mbLocked );
5568     rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
5569 
5570     aTmp <<= mnValue;
5571     if ( bSetInDialog )
5572     {
5573         rPropSet->setPropertyValue( WW8_ASCII2STR("SpinValue"), aTmp );
5574     }
5575     else
5576     {
5577         rPropSet->setPropertyValue( WW8_ASCII2STR("DefaultSpinValue"), aTmp );
5578     }
5579 
5580     aTmp <<= mnMin;
5581     rPropSet->setPropertyValue( WW8_ASCII2STR("SpinValueMin"), aTmp );
5582 
5583     aTmp <<= mnMax;
5584     rPropSet->setPropertyValue( WW8_ASCII2STR("SpinValueMax"), aTmp );
5585 
5586     aTmp <<= mnSmallStep;
5587     rPropSet->setPropertyValue( WW8_ASCII2STR("SpinIncrement"), aTmp );
5588 
5589     namespace AwtScrollOrient = ::com::sun::star::awt::ScrollBarOrientation;
5590     switch( mnOrient )
5591     {
5592         case 0:     aTmp <<= AwtScrollOrient::VERTICAL;     break;
5593         case 1:     aTmp <<= AwtScrollOrient::HORIZONTAL;   break;
5594         default:    aTmp <<= (nWidth < nHeight) ? AwtScrollOrient::VERTICAL : AwtScrollOrient::HORIZONTAL;
5595     }
5596     rPropSet->setPropertyValue( WW8_ASCII2STR("Orientation"), aTmp );
5597 
5598     aTmp = bool2any( true );
5599     rPropSet->setPropertyValue( WW8_ASCII2STR("Repeat"), aTmp );
5600 
5601     aTmp <<= mnDelay;
5602     rPropSet->setPropertyValue( WW8_ASCII2STR("RepeatDelay"), aTmp );
5603 
5604     aTmp <<= sal_Int16( 0 );
5605     rPropSet->setPropertyValue( WW8_ASCII2STR("Border"), aTmp);
5606 
5607     return sal_True;
5608 }
5609 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)5610 sal_Bool OCX_SpinButton::Export(
5611         SvStorageRef &rObj,
5612         const uno::Reference< beans::XPropertySet>& rPropSet,
5613         const awt::Size& rSize )
5614 {
5615     static sal_uInt8 __READONLY_DATA aCompObj[] =
5616     {
5617         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
5618         0xFF, 0xFF, 0xFF, 0xFF, 0xB0, 0x6F, 0x17, 0x79,
5619         0xF2, 0xB7, 0xCE, 0x11, 0x97, 0xEF, 0x00, 0xAA,
5620         0x00, 0x6D, 0x27, 0x76, 0x1F, 0x00, 0x00, 0x00,
5621         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
5622         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
5623         0x32, 0x2E, 0x30, 0x20, 0x53, 0x70, 0x69, 0x6E,
5624         0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E, 0x00, 0x10,
5625         0x00, 0x00, 0x00, 0x45, 0x6D, 0x62, 0x65, 0x64,
5626         0x64, 0x65, 0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65,
5627         0x63, 0x74, 0x00, 0x13, 0x00, 0x00, 0x00, 0x46,
5628         0x6F, 0x72, 0x6D, 0x73, 0x2E, 0x53, 0x70, 0x69,//Add those to avoid MS crash when open
5629         0x6E, 0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E, 0x2E,
5630         0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00,
5631         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5632         0x00, 0x00
5633     };
5634 
5635     {
5636         SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
5637         xStor->Write(aCompObj,sizeof(aCompObj));
5638         DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
5639     }
5640 
5641     {
5642         SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
5643         xStor3->Write(aObjInfo,sizeof(aObjInfo));
5644         DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
5645     }
5646 
5647     static sal_uInt8 __READONLY_DATA aOCXNAME[] =
5648     {
5649         0x53, 0x00, 0x70, 0x00, 0x69, 0x00, 0x6E, 0x00,
5650         0x42, 0x00, 0x75, 0x00, 0x74, 0x00, 0x74, 0x00,
5651         0x6F, 0x00, 0x6E, 0x00, 0x31, 0x00, 0x00, 0x00,
5652         0x00, 0x00
5653     };
5654 
5655     {
5656         SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
5657         xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
5658         DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
5659     }
5660 
5661     SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
5662     return WriteContents(xContents, rPropSet, rSize);
5663 }
5664 
WriteContents(SvStorageStreamRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)5665 sal_Bool OCX_SpinButton::WriteContents(
5666         SvStorageStreamRef &rObj,
5667         const uno::Reference< beans::XPropertySet> &rPropSet,
5668         const awt::Size& rSize )
5669 {
5670     if( !rObj.Is() )
5671         return sal_False;
5672 
5673     mnBlockFlags = 0x00000008;
5674     nWidth = rSize.Width;
5675     nHeight = rSize.Height;
5676 
5677     GetInt32Property( mnForeColor, rPropSet, WW8_ASCII2STR( "SymbolColor" ),     0x00000001 );
5678     GetInt32Property( mnBackColor, rPropSet, WW8_ASCII2STR( "BackgroundColor" ), 0x00000002 );
5679     GetBoolProperty(  mbEnabled,   rPropSet, WW8_ASCII2STR( "Enabled" ),         0x00000304 );
5680     GetInt32Property( mnMin,       rPropSet, WW8_ASCII2STR( "SpinValueMin" ),    0x00000020 );
5681     GetInt32Property( mnMax,       rPropSet, WW8_ASCII2STR( "SpinValueMax" ),    0x00000040 );
5682     GetInt32Property( mnValue,     rPropSet, WW8_ASCII2STR( "SpinValue" ),       0x00000080 );
5683     GetInt32Property( mnSmallStep, rPropSet, WW8_ASCII2STR( "SpinIncrement" ),   0x00000800 );
5684     GetInt32Property( mnDelay,     rPropSet, WW8_ASCII2STR( "RepeatDelay" ),     0x00008000 );
5685 
5686     namespace AwtScrollOrient = ::com::sun::star::awt::ScrollBarOrientation;
5687     sal_Int16 nApiOrient = sal_Int16();
5688     if( rPropSet->getPropertyValue( WW8_ASCII2STR( "Orientation" ) ) >>= nApiOrient )
5689         UpdateInt32Property( mnOrient, (nApiOrient == AwtScrollOrient::VERTICAL) ? 0 : 1, 0x00002000 );
5690 
5691     return WriteData( *rObj );
5692 }
5693 
UpdateInt32Property(sal_Int32 & rnCoreValue,sal_Int32 nNewValue,sal_Int32 nBlockFlag)5694 void OCX_SpinButton::UpdateInt32Property(
5695         sal_Int32& rnCoreValue, sal_Int32 nNewValue, sal_Int32 nBlockFlag )
5696 {
5697     if( nNewValue != rnCoreValue )
5698     {
5699         rnCoreValue = nNewValue;
5700         mnBlockFlags |= nBlockFlag;
5701     }
5702 }
5703 
GetInt32Property(sal_Int32 & rnCoreValue,const uno::Reference<beans::XPropertySet> & rxPropSet,const OUString & rPropName,sal_Int32 nBlockFlag)5704 void OCX_SpinButton::GetInt32Property(
5705         sal_Int32& rnCoreValue, const uno::Reference< beans::XPropertySet>& rxPropSet,
5706         const OUString& rPropName, sal_Int32 nBlockFlag )
5707 {
5708     sal_Int32 nNewValue = 0;
5709     if( rxPropSet->getPropertyValue( rPropName ) >>= nNewValue )
5710         UpdateInt32Property( rnCoreValue, nNewValue, nBlockFlag );
5711 }
5712 
UpdateBoolProperty(bool & rbCoreValue,bool bNewValue,sal_Int32 nBlockFlag)5713 void OCX_SpinButton::UpdateBoolProperty(
5714         bool& rbCoreValue, bool bNewValue, sal_Int32 nBlockFlag )
5715 {
5716     if( bNewValue != rbCoreValue )
5717     {
5718         rbCoreValue = bNewValue;
5719         mnBlockFlags |= nBlockFlag;
5720     }
5721 }
5722 
GetBoolProperty(bool & rbCoreValue,const uno::Reference<beans::XPropertySet> & rxPropSet,const OUString & rPropName,sal_Int32 nBlockFlag)5723 void OCX_SpinButton::GetBoolProperty(
5724         bool& rbCoreValue, const uno::Reference< beans::XPropertySet>& rxPropSet,
5725         const OUString& rPropName, sal_Int32 nBlockFlag )
5726 {
5727     UpdateBoolProperty( rbCoreValue,
5728         any2bool( rxPropSet->getPropertyValue( rPropName ) ), nBlockFlag );
5729 }
5730 
WriteData(SvStream & rStrm) const5731 sal_Bool OCX_SpinButton::WriteData( SvStream& rStrm ) const
5732 {
5733     sal_Bool bRet = sal_True;
5734     sal_uLong nStartPos = rStrm.Tell();
5735 
5736     rStrm << sal_Int32( 0 ) << mnBlockFlags;
5737 
5738     if( mnBlockFlags & 0x00000001 )     rStrm << ExportColor( mnForeColor );
5739     if( mnBlockFlags & 0x00000002 )     rStrm << ExportColor( mnBackColor );
5740     if( mnBlockFlags & 0x00000004 )
5741     {
5742         sal_Int32 nFlags = 0x00000019;  // always set
5743         if( mbEnabled ) nFlags |= 0x00000002;
5744         if( mbLocked )  nFlags |= 0x00000004;
5745         rStrm << nFlags;
5746     }
5747     if( mnBlockFlags & 0x00000020 )     rStrm << mnMin;
5748     if( mnBlockFlags & 0x00000040 )     rStrm << mnMax;
5749     if( mnBlockFlags & 0x00000080 )     rStrm << mnValue;
5750     if( mnBlockFlags & 0x00000100 )     rStrm << sal_Int32( 0 );    // unknown
5751     if( mnBlockFlags & 0x00000200 )     rStrm << sal_Int32( 0 );    // unknown
5752     if( mnBlockFlags & 0x00000400 )     rStrm << sal_Int32( 0 );    // unknown
5753     if( mnBlockFlags & 0x00000800 )     rStrm << mnSmallStep;
5754     if( mnBlockFlags & 0x00001000 )     rStrm << mnPageStep;
5755     if( mnBlockFlags & 0x00002000 )     rStrm << mnOrient;
5756     if( mnBlockFlags & 0x00004000 )     rStrm << sal_Int32( mbPropThumb ? 1 : 0 );
5757     if( mnBlockFlags & 0x00008000 )     rStrm << mnDelay;
5758     if( mnBlockFlags & 0x00000008 )     rStrm << nWidth << nHeight;
5759 
5760     sal_uInt16 nSize = static_cast< sal_uInt16 >( rStrm.Tell() - nStartPos - 4 );
5761     rStrm.Seek( nStartPos );
5762     rStrm << nStandardId << nSize;
5763 
5764     DBG_ASSERT( rStrm.GetError() == SVSTREAM_OK, "OCX_SpinButton::WriteData - error in stream" );
5765     return bRet;
5766 }
5767 
5768 // ============================================================================
5769 
OCX_ScrollBar()5770 OCX_ScrollBar::OCX_ScrollBar()
5771 {
5772     sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollBar" ) );
5773     mnMax = 32767;
5774     msFormType = C2U("com.sun.star.form.component.ScrollBar");
5775     msDialogType = C2U("com.sun.star.awt.UnoControlScrollBarModel");
5776 
5777 }
5778 
Create()5779 OCX_Control* OCX_ScrollBar::Create()
5780 {
5781     return new OCX_ScrollBar;
5782 }
5783 
Import(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> & rPropSet)5784 sal_Bool OCX_ScrollBar::Import(com::sun::star::uno::Reference<
5785     com::sun::star::beans::XPropertySet> &rPropSet)
5786 {
5787     if( (nWidth < 1) || (nHeight < 1) )
5788         return sal_False;
5789 
5790     uno::Any aTmp( &sName, getCppuType((OUString *)0) );
5791     rPropSet->setPropertyValue( WW8_ASCII2STR( "Name" ), aTmp );
5792 
5793     aTmp <<= ImportColor( mnForeColor );
5794     rPropSet->setPropertyValue( WW8_ASCII2STR("SymbolColor"), aTmp);
5795 
5796     aTmp <<= ImportColor( mnBackColor );
5797     rPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
5798 
5799     aTmp = bool2any( mbEnabled && !mbLocked );
5800     rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), aTmp);
5801 
5802     aTmp <<= mnValue;
5803     if ( bSetInDialog )
5804     {
5805         rPropSet->setPropertyValue( WW8_ASCII2STR("ScrollValue"), aTmp );
5806     }
5807     else
5808     {
5809         rPropSet->setPropertyValue( WW8_ASCII2STR("DefaultScrollValue"), aTmp );
5810     }
5811 
5812     aTmp <<= mnMin;
5813     rPropSet->setPropertyValue( WW8_ASCII2STR("ScrollValueMin"), aTmp );
5814 
5815     aTmp <<= mnMax;
5816     rPropSet->setPropertyValue( WW8_ASCII2STR("ScrollValueMax"), aTmp );
5817 
5818     aTmp <<= mnSmallStep;
5819     rPropSet->setPropertyValue( WW8_ASCII2STR("LineIncrement"), aTmp );
5820 
5821     aTmp <<= mnPageStep;
5822     rPropSet->setPropertyValue( WW8_ASCII2STR("BlockIncrement"), aTmp );
5823     if( mbPropThumb && (mnPageStep > 0) )
5824         rPropSet->setPropertyValue( WW8_ASCII2STR("VisibleSize"), aTmp );
5825 
5826     namespace AwtScrollOrient = ::com::sun::star::awt::ScrollBarOrientation;
5827     switch( mnOrient )
5828     {
5829         case 0:     aTmp <<= AwtScrollOrient::VERTICAL;     break;
5830         case 1:     aTmp <<= AwtScrollOrient::HORIZONTAL;   break;
5831         default:    aTmp <<= (nWidth < nHeight) ? AwtScrollOrient::VERTICAL : AwtScrollOrient::HORIZONTAL;
5832     }
5833     rPropSet->setPropertyValue( WW8_ASCII2STR("Orientation"), aTmp );
5834 
5835     aTmp <<= mnDelay;
5836     rPropSet->setPropertyValue( WW8_ASCII2STR("RepeatDelay"), aTmp );
5837 
5838     aTmp <<= sal_Int16( 0 );
5839     rPropSet->setPropertyValue( WW8_ASCII2STR("Border"), aTmp);
5840 
5841     return sal_True;
5842 }
5843 
Export(SvStorageRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)5844 sal_Bool OCX_ScrollBar::Export(
5845         SvStorageRef &rObj,
5846         const uno::Reference< beans::XPropertySet>& rPropSet,
5847         const awt::Size& rSize )
5848 {
5849     static sal_uInt8 __READONLY_DATA aCompObj[] =
5850     {
5851         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
5852         0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x81, 0xD1, 0xDF,
5853         0x2F, 0x5E, 0xCE, 0x11, 0xA4, 0x49, 0x00, 0xAA,
5854         0x00, 0x4A, 0x80, 0x3D, 0x1E, 0x00, 0x00, 0x00,
5855         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
5856         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
5857         0x32, 0x2E, 0x30, 0x20, 0x53, 0x63, 0x72, 0x6F,
5858         0x6C, 0x6C, 0x42, 0x61, 0x72, 0x00, 0x10, 0x00,
5859         0x00, 0x00, 0x45, 0x6D, 0x62, 0x65, 0x64, 0x64,
5860         0x65, 0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63,
5861         0x74, 0x00, 0x12, 0x00, 0x00, 0x00, 0x46, 0x6F,
5862         0x72, 0x6D, 0x73, 0x2E, 0x53, 0x63, 0x72, 0x6F,
5863         0x6C, 0x6C, 0x42, 0x61, 0x72, 0x2E, 0x31, 0x00,
5864         0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
5865         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5866     };
5867 
5868     {
5869         SvStorageStreamRef xStor( rObj->OpenSotStream( C2S("\1CompObj")));
5870         xStor->Write(aCompObj,sizeof(aCompObj));
5871         DBG_ASSERT((xStor.Is() && (SVSTREAM_OK == xStor->GetError())),"damn");
5872     }
5873 
5874     {
5875         SvStorageStreamRef xStor3( rObj->OpenSotStream( C2S("\3ObjInfo")));
5876         xStor3->Write(aObjInfo,sizeof(aObjInfo));
5877         DBG_ASSERT((xStor3.Is() && (SVSTREAM_OK == xStor3->GetError())),"damn");
5878     }
5879 
5880     static sal_uInt8 __READONLY_DATA aOCXNAME[] =
5881     {
5882         0x53, 0x00, 0x63, 0x00, 0x72, 0x00, 0x6F, 0x00,
5883         0x6C, 0x00, 0x6C, 0x00, 0x42, 0x00, 0x61, 0x00,
5884         0x72, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00
5885     };
5886 
5887     {
5888         SvStorageStreamRef xStor2( rObj->OpenSotStream( C2S("\3OCXNAME")));
5889         xStor2->Write(aOCXNAME,sizeof(aOCXNAME));
5890         DBG_ASSERT((xStor2.Is() && (SVSTREAM_OK == xStor2->GetError())),"damn");
5891     }
5892 
5893     SvStorageStreamRef xContents( rObj->OpenSotStream( C2S("contents")));
5894     return WriteContents(xContents, rPropSet, rSize);
5895 }
5896 
WriteContents(SvStorageStreamRef & rObj,const uno::Reference<beans::XPropertySet> & rPropSet,const awt::Size & rSize)5897 sal_Bool OCX_ScrollBar::WriteContents(
5898         SvStorageStreamRef &rObj,
5899         const uno::Reference< beans::XPropertySet> &rPropSet,
5900         const awt::Size& rSize )
5901 {
5902     if( !rObj.Is() )
5903         return sal_False;
5904 
5905     mnBlockFlags = 0x00000008;
5906     nWidth = rSize.Width;
5907     nHeight = rSize.Height;
5908 
5909     GetInt32Property( mnForeColor, rPropSet, WW8_ASCII2STR( "SymbolColor" ),     0x00000001 );
5910     GetInt32Property( mnBackColor, rPropSet, WW8_ASCII2STR( "BackgroundColor" ), 0x00000002 );
5911     GetBoolProperty(  mbEnabled,   rPropSet, WW8_ASCII2STR( "Enabled" ),         0x00000304 );
5912     GetInt32Property( mnMin,       rPropSet, WW8_ASCII2STR( "ScrollValueMin" ),  0x00000020 );
5913     GetInt32Property( mnMax,       rPropSet, WW8_ASCII2STR( "ScrollValueMax" ),  0x00000040 );
5914     GetInt32Property( mnValue,     rPropSet, WW8_ASCII2STR( "ScrollValue" ),     0x00000080 );
5915     GetInt32Property( mnSmallStep, rPropSet, WW8_ASCII2STR( "LineIncrement" ),   0x00000800 );
5916     GetInt32Property( mnPageStep,  rPropSet, WW8_ASCII2STR( "BlockIncrement" ),  0x00001000 );
5917     GetInt32Property( mnDelay,     rPropSet, WW8_ASCII2STR( "RepeatDelay" ),     0x00008000 );
5918 
5919     namespace AwtScrollOrient = ::com::sun::star::awt::ScrollBarOrientation;
5920     sal_Int16 nApiOrient = sal_Int16();
5921     if( rPropSet->getPropertyValue( WW8_ASCII2STR( "Orientation" ) ) >>= nApiOrient )
5922         UpdateInt32Property( mnOrient, (nApiOrient == AwtScrollOrient::VERTICAL) ? 0 : 1, 0x00002000 );
5923 
5924     UpdateBoolProperty( mbPropThumb, true, 0x00004000 );
5925 
5926     return WriteData( *rObj );
5927 }
5928 
OCX_ProgressBar()5929 OCX_ProgressBar::OCX_ProgressBar() :
5930     OCX_Control( OUString( RTL_CONSTASCII_USTRINGPARAM( "ProgressBar" ) ) ),
5931     nMin( 0 ),
5932     nMax( 0 ),
5933     bFixedSingle(true),
5934     bEnabled( true ),
5935     b3d( true )
5936 {
5937 	msDialogType = C2U("com.sun.star.awt.UnoControlProgressBarModel");
5938 	bSetInDialog = true;
5939 }
5940 
Read(SvStorageStream * pS)5941 sal_Bool OCX_ProgressBar::Read( SvStorageStream *pS )
5942 {
5943     pS->SeekRel( 8 );
5944     *pS >> nWidth >> nHeight;
5945     pS->SeekRel( 12 );
5946 
5947     float fMin, fMax;
5948     *pS >> fMin >> fMax;
5949     nMin = static_cast< sal_Int32 >( fMin );
5950     nMax = static_cast< sal_Int32 >( fMax );
5951 	bool bVisible = true;
5952 	sal_uInt8 pUnknownFlags[4];
5953 	pS->Read(pUnknownFlags,4);
5954 
5955 	// complete guess, but we don't handle visible anyway
5956 	if ( ( pUnknownFlags[2] & 0x8 ) &&  (  pUnknownFlags[2] & 0x2 ) )
5957 		bVisible = false;
5958 
5959     sal_uInt32 nFlags;
5960     *pS >> nFlags;
5961 
5962 	// seems these work out
5963     bFixedSingle = (nFlags & 0x01) != 0;
5964     bEnabled = (nFlags & 0x02) != 0;
5965     b3d = (nFlags & 0x04) != 0;
5966 
5967 	return true;
5968 }
5969 
Create()5970 OCX_Control* OCX_ProgressBar::Create()
5971 {
5972     return new OCX_ProgressBar;
5973 }
5974 
Import(uno::Reference<beans::XPropertySet> & rPropSet)5975 sal_Bool OCX_ProgressBar::Import(uno::Reference< beans::XPropertySet > &rPropSet)
5976 {
5977 	uno::Any aTmp(&sName,getCppuType((OUString *)0));
5978 	rPropSet->setPropertyValue( WW8_ASCII2STR("Name"), aTmp );
5979 	aTmp <<= nMax;
5980 	rPropSet->setPropertyValue( WW8_ASCII2STR("ProgressValueMax"), aTmp );
5981 	aTmp <<= nMin;
5982 	rPropSet->setPropertyValue( WW8_ASCII2STR("ProgressValueMin"), aTmp );
5983 
5984 	if ( !bEnabled )
5985 		rPropSet->setPropertyValue( WW8_ASCII2STR("Enabled"), uno::makeAny( sal_False ) );
5986 	return sal_True;
5987 }
5988 // ============================================================================
5989 
5990 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
5991