Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / tools / resid.hxx
blob329f39aaf0c23ff21bcf12ce657e55d3bb4036d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <o3tl/strong_int.hxx>
29 struct RSHEADER_TYPE;
30 struct RESOURCE_TYPE_Tag {};
31 typedef o3tl::strong_int<sal_uInt32, RESOURCE_TYPE_Tag> RESOURCE_TYPE;
32 #define RSC_NOTYPE RESOURCE_TYPE(0x100)
33 #define RSC_DONTRELEASE (sal_uInt32(1U << 31))
35 class ResMgr;
37 class SAL_WARN_UNUSED ResId
40 Consider two cases:
41 either
42 (a) m_pResource is valid and points to a resource data buffer;
43 then m_nResId and m_pResMgr are not used and may be 0 and nullptr respectively
45 (b) m_pResource is NULL, then m_nResId and m_pResMgr must be valid.
46 In this case the highest bit, if set, decides whether or not to
47 release the Resource context after loading this id.
49 RSHEADER_TYPE* m_pResource;
50 mutable sal_uInt32 m_nResId; // Resource Identifier
51 mutable RESOURCE_TYPE m_nRT; // type for loading (mutable to be set later)
52 mutable ResMgr * m_pResMgr; // load from this ResMgr (mutable for setting on demand)
54 void ImplInit( sal_uInt32 nId, ResMgr& rMgr, RSHEADER_TYPE* pRes )
56 m_pResource = pRes; m_nResId = nId; m_nRT = RSC_NOTYPE; m_pResMgr = &rMgr;
57 OSL_ENSURE( m_pResMgr != nullptr, "ResId without ResMgr created" );
60 public:
61 ResId( sal_uInt32 nId, ResMgr& rMgr )
63 ImplInit( nId, rMgr, nullptr );
66 RESOURCE_TYPE GetRT() const { return m_nRT; }
68 /** Set the type if not already set. Ask for type with GetRT()
70 [Example]
71 ResId aId( 1000 );
72 aId.SetRT( RSC_RESOURCE ); // settype window Resource
73 //aId.GetRT() == RSC_RESOURCE is true
75 @see
76 ResId::GetRT2(), ResId::GetRT()
78 const ResId & SetRT( RESOURCE_TYPE nType ) const
80 if( RSC_NOTYPE == m_nRT )
81 m_nRT = nType;
82 return *this;
85 ResMgr * GetResMgr() const { return m_pResMgr; }
86 void ClearResMgr() const { m_pResMgr = nullptr; }
88 bool IsAutoRelease() const { return !(m_nResId & RSC_DONTRELEASE); }
90 sal_uInt32 GetId() const { return m_nResId & ~RSC_DONTRELEASE; }
91 RSHEADER_TYPE* GetpResource() const { return m_pResource; }
93 TOOLS_DLLPUBLIC OUString toString() const;
94 TOOLS_DLLPUBLIC operator OUString() const { return toString(); }
97 #endif
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */