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 .
20 #ifndef INCLUDED_TOOLS_RESID_HXX
21 #define INCLUDED_TOOLS_RESID_HXX
23 #include <osl/diagnose.h>
24 #include <rtl/ustring.hxx>
25 #include <tools/solar.h>
26 #include <tools/toolsdllapi.h>
29 typedef sal_uInt32 RESOURCE_TYPE
;
30 #define RSC_NOTYPE 0x100
31 #define RSC_DONTRELEASE (sal_uInt32(1U << 31))
40 (a) m_pResource is valid and points to a resource data buffer;
41 then m_nResId and m_pResMgr are not used and may be 0 and nullptr respectively
43 (b) m_pResource is NULL, then m_nResId and m_pResMgr must be valid.
44 In this case the highest bit, if set, decides whether or not to
45 release the Resource context after loading this id.
47 RSHEADER_TYPE
* m_pResource
;
48 mutable sal_uInt32 m_nResId
; // Resource Identifier
49 mutable RESOURCE_TYPE m_nRT
; // type for loading (mutable to be set later)
50 mutable ResMgr
* m_pResMgr
; // load from this ResMgr (mutable for setting on demand)
52 void ImplInit( sal_uInt32 nId
, ResMgr
& rMgr
, RSHEADER_TYPE
* pRes
)
54 m_pResource
= pRes
; m_nResId
= nId
; m_nRT
= RSC_NOTYPE
; m_pResMgr
= &rMgr
;
55 OSL_ENSURE( m_pResMgr
!= nullptr, "ResId without ResMgr created" );
59 ResId( RSHEADER_TYPE
* pRc
, ResMgr
& rMgr
)
61 ImplInit( 0, rMgr
, pRc
);
63 ResId( sal_uInt32 nId
, ResMgr
& rMgr
)
65 ImplInit( nId
, rMgr
, nullptr );
68 RESOURCE_TYPE
GetRT() const { return m_nRT
; }
70 /** Set the type if not already set. Ask for type with GetRT()
74 aId.SetRT( RSC_RESOURCE ); // settype window Resource
75 //aId.GetRT() == RSC_RESOURCE is true
78 ResId::GetRT2(), ResId::GetRT()
80 const ResId
& SetRT( RESOURCE_TYPE nType
) const
82 if( RSC_NOTYPE
== m_nRT
)
87 ResMgr
* GetResMgr() const { return m_pResMgr
; }
88 void ClearResMgr() const { m_pResMgr
= nullptr; }
90 const ResId
& SetAutoRelease(bool bRelease
) const
93 m_nResId
&= ~RSC_DONTRELEASE
;
95 m_nResId
|= RSC_DONTRELEASE
;
99 bool IsAutoRelease() const { return !(m_nResId
& RSC_DONTRELEASE
); }
101 sal_uInt32
GetId() const { return m_nResId
& ~RSC_DONTRELEASE
; }
102 RSHEADER_TYPE
* GetpResource() const { return m_pResource
; }
104 TOOLS_DLLPUBLIC OUString
toString() const;
105 TOOLS_DLLPUBLIC
operator OUString() const { return toString(); }
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */