summaryrefslogtreecommitdiff
path: root/bf_so3/source/inplace/soconv.cxx
blob: 3b88915e7d0aade78f8f80064d9a89377bebf797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <stdio.h>


#include <vcl/graph.hxx>
#include <bf_so3/svstor.hxx>
#include <bf_so3/embobj.hxx>
#include <bf_so3/ipobj.hxx>
#include <sot/exchange.hxx>

namespace binfilter {

// Vordefinierte OLE-1-IDs
// Unter Windows koennen wir uns noch auf die RegDB stuerzen, sonst
// nehmen wir eben diese IDs
// Standardformat:

//     0003xxxx-0000-0000-C000-000000000046

struct ClsIDs {
    UINT32      nId;
    const sal_Char* pSvrName;
    const sal_Char* pDspName;
} aClsIDs[] = {

    { 0x000212F0, "MSWordArt",          "Microsoft Word Art"            },
    { 0x000212F0, "MSWordArt.2",        "Microsoft Word Art 2.0"        },

    // MS Apps
    { 0x00030000, "ExcelWorksheet",     "Microsoft Excel Worksheet"     },
    { 0x00030001, "ExcelChart",         "Microsoft Excel Chart"         },
    { 0x00030002, "ExcelMacrosheet",    "Microsoft Excel Macro"         },
    { 0x00030003, "WordDocument",       "Microsoft Word Document"       },
    { 0x00030004, "MSPowerPoint",       "Microsoft PowerPoint"          },
    { 0x00030005, "MSPowerPointSho",    "Microsoft PowerPoint Slide Show"},
    { 0x00030006, "MSGraph",            "Microsoft Graph"               },
    { 0x00030007, "MSDraw",             "Microsoft Draw"                },
    { 0x00030008, "Note-It",            "Microsoft Note-It"             },
    { 0x00030009, "WordArt",            "Microsoft Word Art"            },
    { 0x0003000a, "PBrush",             "Microsoft PaintBrush Picture"  },
    { 0x0003000b, "Equation",           "Microsoft Equation Editor"     },
    { 0x0003000c, "Package",            "Package"                       },
    { 0x0003000d, "SoundRec",           "Sound"                         },
    { 0x0003000e, "MPlayer",            "Media Player"                  },
    // MS Demos
    { 0x0003000f, "ServerDemo",         "OLE 1.0 Server Demo"           },
    { 0x00030010, "Srtest",             "OLE 1.0 Test Demo"             },
    { 0x00030011, "SrtInv",             "OLE 1.0 Inv Demo"              },
    { 0x00030012, "OleDemo",            "OLE 1.0 Demo"                  },

    // Coromandel / Dorai Swamy / 718-793-7963
    { 0x00030013, "CoromandelIntegra",  "Coromandel Integra"            },
    { 0x00030014, "CoromandelObjServer","Coromandel Object Server"      },

    // 3-d Visions Corp / Peter Hirsch / 310-325-1339
    { 0x00030015, "StanfordGraphics",   "Stanford Graphics"             },

    // Deltapoint / Nigel Hearne / 408-648-4000
    { 0x00030016, "DGraphCHART",        "DeltaPoint Graph Chart"        },
    { 0x00030017, "DGraphDATA",         "DeltaPoint Graph Data"         },

    // Corel / Richard V. Woodend / 613-728-8200 x1153
    { 0x00030018, "PhotoPaint",         "Corel PhotoPaint"              },
    { 0x00030019, "CShow",              "Corel Show"                    },
    { 0x0003001a, "CorelChart",         "Corel Chart"                   },
    { 0x0003001b, "CDraw",              "Corel Draw"                    },

    // Inset Systems / Mark Skiba / 203-740-2400
    { 0x0003001c, "HJWIN1.0",           "Inset Systems"                 },

    // Mark V Systems / Mark McGraw / 818-995-7671
    { 0x0003001d, "ObjMakerOLE",        "MarkV Systems Object Maker"    },

    // IdentiTech / Mike Gilger / 407-951-9503
    { 0x0003001e, "FYI",                "IdentiTech FYI"                },
    { 0x0003001f, "FYIView",            "IdentiTech FYI Viewer"         },

    // Inventa Corporation / Balaji Varadarajan / 408-987-0220
    { 0x00030020, "Stickynote",         "Inventa Sticky Note"           },

    // ShapeWare Corp. / Lori Pearce / 206-467-6723
    { 0x00030021, "ShapewareVISIO10",   "Shapeware Visio 1.0"           },
    { 0x00030022, "ImportServer",       "Spaheware Import Server"       },

    // test app SrTest
    { 0x00030023, "SrvrTest",           "OLE 1.0 Server Test"           },

    // test app ClTest.  Doesn't really work as a server but is in reg db
    { 0x00030025, "Cltest",             "OLE 1.0 Client Test"           },

    // Microsoft ClipArt Gallery   Sherry Larsen-Holmes
    { 0x00030026, "MS_ClipArt_Gallery", "Microsoft ClipArt Gallery"     },
    // Microsoft Project  Cory Reina
    { 0x00030027, "MSProject",          "Microsoft Project"             },

    // Microsoft Works Chart
    { 0x00030028, "MSWorksChart",       "Microsoft Works Chart"         },

    // Microsoft Works Spreadsheet
    { 0x00030029, "MSWorksSpreadsheet", "Microsoft Works Spreadsheet"   },

    // AFX apps - Dean McCrory
    { 0x0003002A, "MinSvr",             "AFX Mini Server"               },
    { 0x0003002B, "HierarchyList",      "AFX Hierarchy List"            },
    { 0x0003002C, "BibRef",             "AFX BibRef"                    },
    { 0x0003002D, "MinSvrMI",           "AFX Mini Server MI"            },
    { 0x0003002E, "TestServ",           "AFX Test Server"               },

    // Ami Pro
    { 0x0003002F, "AmiProDocument",     "Ami Pro Document"              },

    // WordPerfect Presentations For Windows
    { 0x00030030, "WPGraphics",         "WordPerfect Presentation"      },
    { 0x00030031, "WPCharts",           "WordPerfect Chart"             },

    // MicroGrafx Charisma
    { 0x00030032, "Charisma",           "MicroGrafx Charisma"           },
    { 0x00030033, "Charisma_30",        "MicroGrafx Charisma 3.0"       },
    { 0x00030034, "CharPres_30",        "MicroGrafx Charisma 3.0 Pres"  },
    // MicroGrafx Draw
    { 0x00030035, "Draw",               "MicroGrafx Draw"               },
    // MicroGrafx Designer
    { 0x00030036, "Designer_40",        "MicroGrafx Designer 4.0"       },

    // STAR DIVISION
//  { 0x000424CA, "StarMath",           "StarMath 1.0"                  },
    { 0x00043AD2, "FontWork",           "Star FontWork"                 },
//  { 0x000456EE, "StarMath2",          "StarMath 2.0"                  },

    { 0, "", "" } };

// Da wir nicht die gesamte SO-Lib inklusive OLE1 dran haben wollen,
// sei hier die Leseroutine fuer ein StarObject noch mit drin.

#define SO_SIGNATURE 0x534F6D64             // Signatur ('mdSO' im INTEL-Format)
#define SO_VERSION   0x00000002

struct StarObjectFileHdr
{
    UINT32  nSize;                          // Groesse der Struktur
    UINT32  nSignature;                     // Signatur
    UINT32  nVersion;                       // Version
    UINT32  nWidth;                         // Breite in 1/100 mm
    UINT32  nHeight;                        // Hoehe in 1/100 mm
    UINT32  nObjName;                       // Laenge Objektname
    UINT32  nServerName;                    // Laenge Servername
    UINT32  nPrivData;                      // Laenge private Daten
    UINT32  nPicData;                       // Laenge GDIMetafile
};

// Laden eines StarObjects. Die Daten werden in den Parametern
// uebergeben, der Returnwert ist der Stream-Fehlercode.
#define PIC_READ    1
#define DATA_READ   2
static ULONG LoadStarObject
    ( SvStream& rSrc, String& rSvrName, String& rObjName,
      GDIMetaFile & rPic, SvStream & rDataStm )
{
    ULONG nRet = 0;
    StarObjectFileHdr aHdr;
    long pos = rSrc.Tell();
    aHdr.nSize = 0L;
    rSrc >> aHdr.nSize;
    rSrc.Seek( pos );

    if ( aHdr.nSize != sizeof( aHdr ) )
    {
        rSrc.SetError( SVSTREAM_GENERALERROR );
        return 0;
    }

    rSrc >> aHdr.nSize
         >> aHdr.nSignature
         >> aHdr.nVersion
         >> aHdr.nWidth
         >> aHdr.nHeight
         >> aHdr.nObjName
         >> aHdr.nServerName
         >> aHdr.nPrivData
         >> aHdr.nPicData;

    if ( aHdr.nSignature != SO_SIGNATURE || aHdr.nVersion > SO_VERSION )
    {
        rSrc.SetError( SVSTREAM_GENERALERROR );
        return 0;
    }

    sal_Char cBuf[ 128 ];
    rSrc.Read( cBuf, aHdr.nObjName );
    if ( rSrc.GetError() )
        return 0;
    rObjName = String(
        cBuf, sal::static_int_cast< xub_StrLen >( aHdr.nObjName ),
        osl_getThreadTextEncoding() );

    rSrc.Read( cBuf, aHdr.nServerName );
    if ( rSrc.GetError() )
        return 0;
    rSvrName = String(
        cBuf, sal::static_int_cast< xub_StrLen >( aHdr.nServerName ),
        osl_getThreadTextEncoding() );
    if ( aHdr.nPrivData )
    {
        UINT32 nLen;
        rSrc >> nLen;
        if ( rSrc.GetError() )
            return 0;

        BYTE * pData = new BYTE[ nLen ];
        rDataStm << nLen;
        rSrc.Read( pData, nLen );
        rDataStm.Write( pData, nLen );
        delete [] pData;
        if ( rDataStm.GetError() )
        {
            rSrc.SetError( rDataStm.GetError() );
            return 0;
        }
        nRet = DATA_READ;
    }
    if ( aHdr.nPicData )
    {
        if( aHdr.nVersion < SO_VERSION )
        {
            // Alte Grafiken
            rSrc >> rPic;
        }
        else
        {
            // neue, portable oder nicht portable Grafiken
            Graphic aGrf;
            aGrf.ReadEmbedded( rSrc );
            rPic = aGrf.GetGDIMetaFile();
        }
        nRet |= PIC_READ;
    }
    if ( rSrc.GetError() )
        return 0;
    return nRet;
}

BOOL SvEmbeddedObject::InsertStarObject
    ( const String &rObjName, const String& rStgName,
      SvStream& rSrc, SvPersist* pPersist )
{
    ULONG nRead;
    SvStorageRef rpDst( pPersist->GetStorage() );
    String aObjName, aSvrName;
    GDIMetaFile aPic;
    SvMemoryStream aDataStm;

    nRead = LoadStarObject( rSrc, aSvrName, aObjName, aPic, aDataStm );
    if( rSrc.GetError() != SVSTREAM_OK )
        return FALSE;

    // Es kann losgehen!
    // Erstmal den ClassID sowie die Bschreibung suchen
    ClsIDs* pIds;
    for( pIds = aClsIDs; pIds->nId; pIds++ )
    {
        if( COMPARE_EQUAL == aSvrName.CompareToAscii( pIds->pSvrName ) )
            break;
    }
    SvGlobalName* pClsId = NULL;
    String aShort, aFull;
    if( pIds->nId )
    {
        // gefunden!
        pClsId = new SvGlobalName( pIds->nId, 0, 0, 0xc0,0,0,0,0,0,0,0x46 );
        aFull = String( pIds->pDspName, osl_getThreadTextEncoding() );
        aShort = aSvrName;
    }
    else if( (COMPARE_EQUAL == aSvrName.CompareToAscii( "StarMath2" ))
        || (COMPARE_EQUAL == aSvrName.CompareToAscii( "StarMath" )) )
    {
        // Sonderfall: In StarMath 3 umwandeln
        pClsId = new SvGlobalName;
        pClsId->MakeId( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "D4590460-35FD-101C-B12A-04021C007002" ) ) );
        aFull = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarMath 3.0" ) );
        aShort = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarMath" ) );
    }

    if( !pClsId )
    {
        rpDst->SetError( SVSTREAM_GENERALERROR );
        return FALSE;
    }

    // Class-ID und Daten sind vorhanden. Nun muss noch der Storage
    // aufgebaut werden.
    // Main Storage einrichten
    if( rpDst->IsContained( rStgName ) )
        rpDst->Remove( rStgName );
    SvStorageRef rpObj = rpDst->OpenOLEStorage( rStgName,
                            STREAM_READWRITE| STREAM_SHARE_DENYALL );
//  SvStorageRef rpObj = rpDst->OpenStorage( rStgName,
//                          STREAM_READWRITE| STREAM_SHARE_DENYALL );
    if( rpObj.Is() && rpObj->GetError() )
    {
        rpDst->SetError( rpObj->GetError() ); rpObj.Clear();
    }
    if( rpObj.Is() )
    {
        // 1. die OLE-Daten
        ULONG nCbFmt = SotExchange::RegisterFormatName( aShort );
        rpObj->SetClass( *pClsId, nCbFmt, aFull );
    }
    delete pClsId;

    // 2. Den Daten-Stream aufsetzen
    if( rpObj.Is() && (nRead & DATA_READ) )
    {
        SvStorageStreamRef rpStrm =
            rpObj->OpenStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\1Ole10Native" ) ),
                            STREAM_WRITE| STREAM_SHARE_DENYALL );
        if( rpStrm.Is() && rpStrm->GetError() )
        {
            rpDst->SetError( rpStrm->GetError() ); rpStrm.Clear();
        }
        if( rpStrm.Is() )
        {
            aDataStm.Seek( 0 );
            *rpStrm << aDataStm;
            rpDst->SetError( rpObj->GetError() );
            if( rpDst->GetError() )
                rpObj.Clear();
        }
    }

    // 3. Den Picture-Stream aufsetzen
    if( rpObj.Is() && (nRead & PIC_READ) )
    {
        ULONG nErr = SVSTREAM_OK;
        if( !SvEmbeddedObject::MakeContentStream( rpObj, aPic ) )
            nErr = SVSTREAM_WRITE_ERROR;
        else
            nErr = rpObj->GetError();
        rpDst->SetError( nErr );
        if( nErr != SVSTREAM_OK )
            rpObj.Clear();
    }

    // 4. Alles committen
    if( rpObj.Is() )
    {
        rpObj->Commit();
        rpDst->SetError( rpObj->GetError() );
    }
    // Sonst evtl. den (defekten) Storage weg
    else if( rpDst->IsContained( rStgName ) )
        rpDst->Remove( rStgName );
    rpDst->Commit();
    if( rpDst->GetError() == SVSTREAM_OK )
    {
        SvObjectRef rpOleObj =
            ((SvFactory*)SvInPlaceObject::ClassFactory())->CreateAndLoad( rpObj );
        SvInPlaceObjectRef rpInplaceObj( &rpOleObj );
        if( rpInplaceObj.Is() )
        {
            SvInfoObjectRef rpInfo =
                new SvEmbeddedInfoObject( rpInplaceObj, rObjName );
            return pPersist->Insert( rpInfo );
        }
    }
    return FALSE;
}

// Laden des Pictures eines StarObjects
// (falls es nicht als OLE-Objekt ladbar ist)

BOOL SvEmbeddedObject::LoadStarObjectPicture( SvStream& rSrc, GDIMetaFile& rMTF )
{
    String aObjName, aSvrName;
    GDIMetaFile  aPic;
    SvMemoryStream aDataStm;

    ULONG nErr = LoadStarObject( rSrc, aSvrName, aObjName, aPic, aDataStm );
    (void)nErr;
    if( rSrc.GetError() != SVSTREAM_OK )
        return FALSE;

    rMTF = aPic;
    return TRUE;
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */