1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <rtl/ustrbuf.hxx>
22 #include <tools/date.hxx>
23 #include <tools/time.hxx>
24 #include <tools/rc.hxx>
25 #include <tools/rcid.h>
27 Resource::Resource( const ResId
& rResId
)
29 GetRes( rResId
.SetRT( RSC_RESOURCE
) );
32 void Resource::GetRes( const ResId
& rResId
)
34 if( rResId
.GetResMgr() )
35 m_pResMgr
= rResId
.GetResMgr();
37 m_pResMgr
->GetResource( rResId
, this );
38 IncrementRes( sizeof( RSHEADER_TYPE
) );
41 Time::Time( const ResId
& rResId
)
44 rResId
.SetRT( RSC_TIME
);
45 ResMgr
* pResMgr
= NULL
;
47 ResMgr::GetResourceSkipHeader( rResId
, &pResMgr
);
49 sal_uIntPtr nObjMask
= (sal_uInt16
)pResMgr
->ReadLong();
51 if ( 0x01 & nObjMask
)
52 SetHour( (sal_uInt16
)pResMgr
->ReadShort() );
53 if ( 0x02 & nObjMask
)
54 SetMin( (sal_uInt16
)pResMgr
->ReadShort() );
55 if ( 0x04 & nObjMask
)
56 SetSec( (sal_uInt16
)pResMgr
->ReadShort() );
57 if ( 0x08 & nObjMask
)
58 // TODO: when we change the place that writes this binary resource format to match:
59 // SetNanoSec( pResMgr->ReadLong() );
61 SetNanoSec( pResMgr
->ReadShort() * ::Time::nanoPerCenti
);
64 Date::Date( const ResId
& rResId
) : nDate(0)
66 rResId
.SetRT( RSC_DATE
);
67 ResMgr
* pResMgr
= NULL
;
69 ResMgr::GetResourceSkipHeader( rResId
, &pResMgr
);
71 sal_uIntPtr nObjMask
= (sal_uInt16
)pResMgr
->ReadLong();
73 if ( 0x01 & nObjMask
)
74 SetYear( (sal_uInt16
)pResMgr
->ReadShort() );
75 if ( 0x02 & nObjMask
)
76 SetMonth( (sal_uInt16
)pResMgr
->ReadShort() );
77 if ( 0x04 & nObjMask
)
78 SetDay( (sal_uInt16
)pResMgr
->ReadShort() );
81 OUString
ResId::toString() const
84 ResMgr
* pResMgr
= GetResMgr();
86 if ( !pResMgr
|| !pResMgr
->GetResource( *this ) )
90 #if OSL_DEBUG_LEVEL > 0
91 sRet
= OUStringBuffer().
92 append("<resource id ").
93 append(static_cast<sal_Int32
>(GetId())).
94 append(" not found>").
99 pResMgr
->PopContext();
105 RSHEADER_TYPE
* pResHdr
= (RSHEADER_TYPE
*)pResMgr
->GetClass();
107 sal_Int32 nStringLen
= rtl_str_getLength( (char*)(pResHdr
+1) );
108 OUString
sRet((const char*)(pResHdr
+1), nStringLen
, RTL_TEXTENCODING_UTF8
);
110 sal_uInt32 nSize
= sizeof( RSHEADER_TYPE
)
111 + sal::static_int_cast
< sal_uInt32
>(nStringLen
) + 1;
113 pResMgr
->Increment( nSize
);
115 ResHookProc pImplResHookProc
= ResMgr::GetReadStringHook();
116 if ( pImplResHookProc
)
117 sRet
= pImplResHookProc(sRet
);
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */