summaryrefslogtreecommitdiffstats
path: root/bf_sw/source/core/txtnode/sw_fmtatr2.cxx
blob: 0bfc9b68785873596be73823e58c6e5f98b357e8 (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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/* -*- 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 .
 */


#ifdef _MSC_VER
#pragma hdrstop
#endif

#include "unomid.h"

#include <bf_svtools/macitem.hxx>

#include <fchrfmt.hxx>
#include <fmtinfmt.hxx>
#include <txtatr.hxx>
#include <fmtruby.hxx>
#include <charfmt.hxx>

#include <horiornt.hxx>


#include <cppuhelper/implbase4.hxx>

#include <unoevent.hxx>     // SwHyperlinkEventDescriptor
#include <com/sun/star/text/RubyAdjust.hdl>

#include <cmdid.h>
#include <com/sun/star/uno/Any.h>
#include <SwStyleNameMapper.hxx>
namespace binfilter {

using namespace ::com::sun::star;
using namespace ::rtl;

/*************************************************************************
|*
|*    class SwFmtCharFmt
|*
*************************************************************************/

/*N*/ TYPEINIT1_AUTOFACTORY(SwFmtINetFmt, SfxPoolItem);

/*N*/ SwFmtCharFmt::SwFmtCharFmt( SwCharFmt *pFmt )
/*N*/   : SfxPoolItem( RES_TXTATR_CHARFMT ),
/*N*/   SwClient(pFmt),
/*N*/   pTxtAttr( 0 )
/*N*/ {
/*N*/ }



/*N*/ SwFmtCharFmt::SwFmtCharFmt( const SwFmtCharFmt& rAttr )
/*N*/   : SfxPoolItem( RES_TXTATR_CHARFMT ),
/*N*/   SwClient( rAttr.GetCharFmt() ),
/*N*/   pTxtAttr( 0 )
/*N*/ {
/*N*/ }



/*N*/ SwFmtCharFmt::~SwFmtCharFmt() {}



/*N*/ int SwFmtCharFmt::operator==( const SfxPoolItem& rAttr ) const
/*N*/ {
/*N*/   OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
/*N*/   return GetCharFmt() == ((SwFmtCharFmt&)rAttr).GetCharFmt();
/*N*/ }



/*N*/ SfxPoolItem* SwFmtCharFmt::Clone( SfxItemPool* ) const
/*N*/ {
/*N*/   return new SwFmtCharFmt( *this );
/*N*/ }






/*N*/ // weiterleiten an das TextAttribut
/*N*/ BOOL SwFmtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
/*N*/ {
/*N*/   return pTxtAttr ? pTxtAttr->GetInfo( rInfo ) : FALSE;
/*N*/ }

/*N*/ bool SwFmtCharFmt::QueryValue( uno::Any& rVal, BYTE /*nMemberId*/ ) const
/*N*/ {
/*N*/   String sCharFmtName;
/*N*/   if(GetCharFmt())
/*N*/       SwStyleNameMapper::FillProgName(GetCharFmt()->GetName(), sCharFmtName,  GET_POOLID_CHRFMT, sal_True );
/*N*/   rVal <<= OUString( sCharFmtName );
/*N*/   return true;
/*N*/ }

/*************************************************************************
|*
|*    class SwFmtINetFmt
|*
*************************************************************************/

/*N*/ SwFmtINetFmt::SwFmtINetFmt()
/*N*/   : SfxPoolItem( RES_TXTATR_INETFMT ),
/*N*/   pMacroTbl( 0 ),
/*N*/   pTxtAttr( 0 ),
/*N*/   nINetId( 0 ),
/*N*/   nVisitedId( 0 )
/*N*/ {}

/*N*/ SwFmtINetFmt::SwFmtINetFmt( const XubString& rURL, const XubString& rTarget )
/*N*/   : SfxPoolItem( RES_TXTATR_INETFMT ),
/*N*/   aURL( rURL ),
/*N*/   aTargetFrame( rTarget ),
/*N*/   pMacroTbl( 0 ),
/*N*/   pTxtAttr( 0 ),
/*N*/   nINetId( 0 ),
/*N*/   nVisitedId( 0 )
/*N*/ {
/*N*/ }



/*N*/ SwFmtINetFmt::SwFmtINetFmt( const SwFmtINetFmt& rAttr )
/*N*/   : SfxPoolItem( RES_TXTATR_INETFMT ),
/*N*/   aURL( rAttr.GetValue() ),
/*N*/   aTargetFrame( rAttr.aTargetFrame ),
/*N*/   aINetFmt( rAttr.aINetFmt ),
/*N*/   aVisitedFmt( rAttr.aVisitedFmt ),
/*N*/   aName( rAttr.aName ),
/*N*/   pMacroTbl( 0 ),
/*N*/   pTxtAttr( 0 ),
/*N*/   nINetId( rAttr.nINetId ),
/*N*/   nVisitedId( rAttr.nVisitedId )
/*N*/ {
/*N*/   if( rAttr.GetMacroTbl() )
/*?*/       pMacroTbl = new SvxMacroTableDtor( *rAttr.GetMacroTbl() );
/*N*/ }



/*N*/ SwFmtINetFmt::~SwFmtINetFmt()
/*N*/ {
/*N*/   delete pMacroTbl;
/*N*/ }



/*N*/ int SwFmtINetFmt::operator==( const SfxPoolItem& rAttr ) const
/*N*/ {
/*N*/   OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
/*N*/   BOOL bRet = SfxPoolItem::operator==( (SfxPoolItem&) rAttr )
/*N*/               && aURL == ((SwFmtINetFmt&)rAttr).aURL
/*N*/               && aName == ((SwFmtINetFmt&)rAttr).aName
/*N*/               && aTargetFrame == ((SwFmtINetFmt&)rAttr).aTargetFrame
/*N*/               && aINetFmt == ((SwFmtINetFmt&)rAttr).aINetFmt
/*N*/               && aVisitedFmt == ((SwFmtINetFmt&)rAttr).aVisitedFmt
/*N*/               && nINetId == ((SwFmtINetFmt&)rAttr).nINetId
/*N*/               && nVisitedId == ((SwFmtINetFmt&)rAttr).nVisitedId;
/*N*/
/*N*/   if( !bRet )
/*N*/       return FALSE;
/*N*/
/*N*/   const SvxMacroTableDtor* pOther = ((SwFmtINetFmt&)rAttr).pMacroTbl;
/*N*/   if( !pMacroTbl )
/*N*/       return ( !pOther || !pOther->Count() );
/*N*/   if( !pOther )
/*?*/       return 0 == pMacroTbl->Count();
/*?*/
/*?*/   const SvxMacroTableDtor& rOwn = *pMacroTbl;
/*?*/   const SvxMacroTableDtor& rOther = *pOther;
/*?*/
/*?*/   // Anzahl unterschiedlich => auf jeden Fall ungleich
/*?*/   if( rOwn.Count() != rOther.Count() )
/*?*/       return FALSE;
/*?*/
/*?*/   // einzeln vergleichen; wegen Performance ist die Reihenfolge wichtig
/*?*/   for( USHORT nNo = 0; nNo < rOwn.Count(); ++nNo )
/*?*/   {
/*?*/       const SvxMacro *pOwnMac = rOwn.GetObject(nNo);
/*?*/       const SvxMacro *pOtherMac = rOther.GetObject(nNo);
/*?*/       if (    rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac)  ||
/*?*/               pOwnMac->GetLibName() != pOtherMac->GetLibName() ||
/*?*/               pOwnMac->GetMacName() != pOtherMac->GetMacName() )
/*?*/           return FALSE;
/*?*/   }
/*?*/   return TRUE;
/*N*/ }



/*N*/ SfxPoolItem* SwFmtINetFmt::Clone( SfxItemPool* ) const
/*N*/ {
/*N*/   return new SwFmtINetFmt( *this );
/*N*/ }






/*N #i27164#*/ void SwFmtINetFmt::SetMacro( USHORT nEvent, const SvxMacro& rMacro )
/*N #i27164#*/ {
/*N #i27164#*/  if( !pMacroTbl )
/*N #i27164#*/  pMacroTbl = new SvxMacroTableDtor;
/*N #i27164#*/
/*N #i27164#*/  SvxMacro *pOldMacro;
/*N #i27164#*/  if( 0 != ( pOldMacro = pMacroTbl->Get( nEvent )) )
/*N #i27164#*/  {
/*N #i27164#*/  delete pOldMacro;
/*N #i27164#*/  pMacroTbl->Replace( nEvent, new SvxMacro( rMacro ) );
/*N #i27164#*/  }
/*N #i27164#*/  else
/*N #i27164#*/  pMacroTbl->Insert( nEvent, new SvxMacro( rMacro ) );
/*N #i27164#*/ }



/*N*/ const SvxMacro* SwFmtINetFmt::GetMacro( USHORT nEvent ) const
/*N*/ {
/*N*/   const SvxMacro* pRet = 0;
/*N*/   if( pMacroTbl && pMacroTbl->IsKeyValid( nEvent ) )
/*?*/       pRet = pMacroTbl->Get( nEvent );
/*N*/   return pRet;
/*N*/ }



/*N*/ bool SwFmtINetFmt::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
/*N*/ {
/*N*/   bool bRet = true;
/*N*/   XubString sVal;
/*N*/     nMemberId &= ~CONVERT_TWIPS;
/*N*/   switch(nMemberId)
/*N*/   {
/*N*/       case MID_URL_URL:
/*N*/           sVal = aURL;
/*N*/       break;
/*N*/       case MID_URL_TARGET:
/*N*/           sVal = aTargetFrame;
/*N*/       break;
/*N*/       case MID_URL_HYPERLINKNAME:
/*N*/           sVal = aName;
/*N*/       break;
/*N*/       case MID_URL_VISITED_FMT:
/*N*/           sVal = aVisitedFmt;
/*N*/           if( !sVal.Len() && nVisitedId != 0 )
/*?*/               SwStyleNameMapper::FillUIName( nVisitedId, sVal );
/*N*/           if( sVal.Len() )
/*?*/               SwStyleNameMapper::FillProgName( sVal, sVal, GET_POOLID_CHRFMT, sal_True );
/*N*/       break;
/*N*/       case MID_URL_UNVISITED_FMT:
/*N*/           sVal = aINetFmt;
/*N*/           if( !sVal.Len() && nINetId != 0 )
/*?*/               SwStyleNameMapper::FillUIName( nINetId, sVal );
/*N*/           if( sVal.Len() )
/*?*/               SwStyleNameMapper::FillProgName( sVal, sVal, GET_POOLID_CHRFMT, sal_True );
/*N*/       break;
/*N*/       case MID_URL_HYPERLINKEVENTS:
/*N*/       {
/*N*/           // create (and return) event descriptor
/*N*/           SwHyperlinkEventDescriptor* pEvents =
/*N*/               new SwHyperlinkEventDescriptor();
/*N*/           pEvents->copyMacrosFromINetFmt(*this);
/*N*/           uno::Reference<container::XNameReplace> xNameReplace(pEvents);
/*N*/
/*N*/           // all others return a string; so we just set rVal here and exit
/*N*/           rVal <<= xNameReplace;
/*N*/           return bRet;
/*N*/       }
/*N*/       break;
/*N*/       default:
/*N*/           bRet = false;
/*N*/   }
/*N*/   rVal <<= OUString(sVal);
/*N*/   return bRet;
/*N*/ }
/*N*/ bool SwFmtINetFmt::PutValue( const uno::Any& rVal, BYTE nMemberId  )
/*N*/ {
/*N*/   bool bRet = TRUE;
/*N*/     nMemberId &= ~CONVERT_TWIPS;
/*N*/
/*N*/   // all properties except HyperlinkEvents are of type string, hence
/*N*/   // we treat HyperlinkEvents specially
/*N*/   if (MID_URL_HYPERLINKEVENTS == nMemberId)
/*N*/   {
/*?*/       uno::Reference<container::XNameReplace> xReplace;
/*?*/       rVal >>= xReplace;
/*?*/       if (xReplace.is())
/*?*/       {
/*?*/           // Create hyperlink event descriptor. Then copy events
/*?*/           // from argument into descriptor. Then copy events from
/*?*/           // the descriptor into the format.
/*?*/           SwHyperlinkEventDescriptor* pEvents = new SwHyperlinkEventDescriptor();
/*?*/           uno::Reference< ::com::sun::star::lang::XServiceInfo> xHold = pEvents;
/*?*/           pEvents->copyMacrosFromNameReplace(xReplace);
/*?*/           pEvents->copyMacrosIntoINetFmt(*this);
/*?*/       }
/*?*/       else
/*?*/       {
/*?*/           // wrong type!
/*?*/           bRet = false;
/*?*/       }
/*N*/   }
/*N*/   else
/*N*/   {
/*N*/       // all string properties:
/*N*/       if(rVal.getValueType() != ::getCppuType((::rtl::OUString*)0))
/*N*/           return false;
/*N*/       XubString sVal = *(::rtl::OUString*)rVal.getValue();
/*N*/       switch(nMemberId)
/*N*/       {
/*N*/           case MID_URL_URL:
/*N*/               aURL = sVal;
/*N*/               break;
/*N*/           case MID_URL_TARGET:
/*N*/               aTargetFrame = sVal;
/*N*/               break;
/*N*/           case MID_URL_HYPERLINKNAME:
/*N*/               aName = sVal;
/*N*/               break;
/*?*/           case MID_URL_VISITED_FMT:
/*?*/           {
/*?*/               String aString;
/*?*/               SwStyleNameMapper::FillUIName( sVal, aString, GET_POOLID_CHRFMT, sal_True );
/*?*/               aVisitedFmt = OUString ( aString );
/*?*/               nVisitedId = SwStyleNameMapper::GetPoolIdFromUIName( aVisitedFmt,
/*?*/                                              GET_POOLID_CHRFMT );
/*?*/           }
/*?*/           break;
/*?*/           case MID_URL_UNVISITED_FMT:
/*?*/           {
/*?*/               String aString;
/*?*/               SwStyleNameMapper::FillUIName( sVal, aString, GET_POOLID_CHRFMT, sal_True );
/*?*/               aINetFmt = OUString ( aString );
/*?*/               nINetId = SwStyleNameMapper::GetPoolIdFromUIName( aINetFmt, GET_POOLID_CHRFMT );
/*?*/           }
/*?*/           break;
/*?*/           default:
/*?*/               bRet = false;
/*N*/       }
/*N*/   }
/*N*/   return bRet;
/*N*/ }


/*************************************************************************
|*    class SwFmtRuby
*************************************************************************/

/*N*/ SwFmtRuby::SwFmtRuby( const String& rRubyTxt )
/*N*/   : SfxPoolItem( RES_TXTATR_CJK_RUBY ),
/*N*/   sRubyTxt( rRubyTxt ),
/*N*/   pTxtAttr( 0 ),
/*N*/   nCharFmtId( 0 ),
/*N*/   nPosition( 0 ),
/*N*/   nAdjustment( 0 )
/*N*/ {
/*N*/ }

/*?*/ SwFmtRuby::SwFmtRuby( const SwFmtRuby& rAttr )
/*?*/   : SfxPoolItem( RES_TXTATR_CJK_RUBY ),
/*?*/   sRubyTxt( rAttr.sRubyTxt ),
/*?*/   sCharFmtName( rAttr.sCharFmtName ),
/*?*/   pTxtAttr( 0 ),
/*?*/   nCharFmtId( rAttr.nCharFmtId),
/*?*/   nPosition( rAttr.nPosition ),
/*?*/   nAdjustment( rAttr.nAdjustment )
/*?*/ {
/*?*/ }

/*N*/ SwFmtRuby::~SwFmtRuby()
/*N*/ {
/*N*/ }

/*N*/  SwFmtRuby& SwFmtRuby::operator=( const SwFmtRuby& rAttr )
/*N*/  {
/*N*/   sRubyTxt = rAttr.sRubyTxt;
/*N*/   sCharFmtName = rAttr.sCharFmtName;
/*N*/   nCharFmtId = rAttr.nCharFmtId;
/*N*/   nPosition = rAttr.nPosition;
/*N*/   nAdjustment = rAttr.nAdjustment;
/*N*/   pTxtAttr =  0;
/*N*/   return *this;
/*N*/  }

int SwFmtRuby::operator==( const SfxPoolItem& rAttr ) const
{
    OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
    return sRubyTxt == ((SwFmtRuby&)rAttr).sRubyTxt &&
           sCharFmtName == ((SwFmtRuby&)rAttr).sCharFmtName &&
           nCharFmtId == ((SwFmtRuby&)rAttr).nCharFmtId &&
           nPosition == ((SwFmtRuby&)rAttr).nPosition &&
           nAdjustment == ((SwFmtRuby&)rAttr).nAdjustment;
}

SfxPoolItem* SwFmtRuby::Clone( SfxItemPool* ) const
{
    return new SwFmtRuby( *this );
}

bool SwFmtRuby::QueryValue( ::com::sun::star::uno::Any& rVal,
                            BYTE nMemberId ) const
{
    bool bRet = true;
    nMemberId &= ~CONVERT_TWIPS;
    switch( nMemberId )
    {
        case MID_RUBY_TEXT: rVal <<= (OUString)sRubyTxt;                    break;
        case MID_RUBY_ADJUST:   rVal <<= (sal_Int16)nAdjustment;    break;
        case MID_RUBY_CHARSTYLE:
        {
            String aString;
            SwStyleNameMapper::FillProgName(sCharFmtName, aString, GET_POOLID_CHRFMT, sal_True );
            rVal <<= OUString ( aString );
        }
        break;
        case MID_RUBY_ABOVE:
        {
            sal_Bool bAbove = !nPosition;
            rVal.setValue(&bAbove, ::getBooleanCppuType());
        }
        break;
        default:
            bRet = false;
    }
    return bRet;
}
/*N*/ bool SwFmtRuby::PutValue( const ::com::sun::star::uno::Any& rVal,
/*N*/                           BYTE nMemberId  )
/*N*/ {
/*N*/   bool bRet = TRUE;
/*N*/     nMemberId &= ~CONVERT_TWIPS;
/*N*/   switch( nMemberId )
/*N*/   {
/*N*/       case MID_RUBY_TEXT:
/*N*/       {
/*N*/           OUString sTmp;
/*N*/           bRet = rVal >>= sTmp;
/*N*/           sRubyTxt = sTmp;
/*N*/       }
/*N*/       break;
/*N*/       case MID_RUBY_ADJUST:
/*N*/       {
/*N*/           sal_Int16 nSet(0); rVal >>= nSet;
/*N*/           if(nSet >= 0 && nSet <= ::com::sun::star::text::RubyAdjust_INDENT_BLOCK)
/*N*/               nAdjustment = nSet;
/*N*/           else
/*N*/               bRet = sal_False;
/*N*/       }
/*N*/       break;
/*N*/         case MID_RUBY_ABOVE:
/*N*/         {
/*N*/             const uno::Type& rType = ::getBooleanCppuType();
/*N*/             if(rVal.hasValue() && rVal.getValueType() == rType)
/*N*/             {
/*N*/                 sal_Bool bAbove = *(sal_Bool*)rVal.getValue();
/*N*/                 nPosition = bAbove ? 0 : 1;
/*N*/             }
/*N*/         }
/*N*/         break;
/*N*/         case MID_RUBY_CHARSTYLE:
/*N*/         {
/*N*/             OUString sTmp;
/*N*/             bRet = rVal >>= sTmp;
/*N*/             if(bRet)
/*N*/                 sCharFmtName = SwStyleNameMapper::GetUIName(sTmp, GET_POOLID_CHRFMT );
/*N*/         }
/*N*/         break;
/*N*/       default:
/*N*/           bRet = false;
/*N*/   }
/*N*/   return bRet;
/*N*/ }

}

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