LCOV - code coverage report
Current view: top level - tools/inc/tools - resid.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 11 21 52.4 %
Date: 2012-08-25 Functions: 6 10 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 4 75.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       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/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      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 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #ifndef _TOOLS_RESID_HXX
      21                 :            : #define _TOOLS_RESID_HXX
      22                 :            : 
      23                 :            : #include <osl/diagnose.h>
      24                 :            : #include <rtl/ustring.hxx>
      25                 :            : #include <tools/solar.h>
      26                 :            : #include "tools/toolsdllapi.h"
      27                 :            : 
      28                 :            : struct RSHEADER_TYPE;
      29                 :            : typedef sal_uInt32 RESOURCE_TYPE;
      30                 :            : #define RSC_NOTYPE              0x100
      31                 :            : #define RSC_DONTRELEASE         (sal_uInt32(1 << 31))
      32                 :            : 
      33                 :            : class ResMgr;
      34                 :            : 
      35                 :            : class ResId
      36                 :            : {
      37                 :            :     /*
      38                 :            :     consider two cases: either m_pResource is valid and points
      39                 :            :     two a resource data buffer; then m_nResId and m_pResMgr are
      40                 :            :     not used and may be 0 resp. NULL
      41                 :            :     or m_pResource is NULL, the m_nResId and m_pResMgr must be valid.
      42                 :            :     In this case the highest bit if set decides whether to
      43                 :            :     not to release the Resource context after loading this id
      44                 :            :     */
      45                 :            :     RSHEADER_TYPE*          m_pResource;
      46                 :            : 
      47                 :            :     mutable sal_uInt32      m_nResId;      // Resource Identifier
      48                 :            :     mutable RESOURCE_TYPE   m_nRT;         // type for loading (mutable to be set later)
      49                 :            :     mutable ResMgr *        m_pResMgr;     // load from this ResMgr (mutable for setting on demand)
      50                 :            :     mutable RESOURCE_TYPE   m_nRT2;        // type for loading (supercedes m_nRT)
      51                 :            :     mutable sal_uInt32      m_nWinBits;    // container for original style bits on a window in a resource
      52                 :            : 
      53                 :          0 :     void ImplInit( sal_uInt32 nId, ResMgr& rMgr, RSHEADER_TYPE* pRes )
      54                 :            :     {
      55                 :          0 :         m_pResource = pRes; m_nResId = nId; m_nRT = RSC_NOTYPE; m_pResMgr = &rMgr; m_nRT2 = RSC_NOTYPE; m_nWinBits = 0;
      56                 :            :         OSL_ENSURE( m_pResMgr != NULL, "ResId without ResMgr created" );
      57                 :          0 :     }
      58                 :            : 
      59                 :            : public:
      60                 :            :     ResId( RSHEADER_TYPE * pRc, ResMgr& rMgr )
      61                 :            :     {
      62                 :            :         ImplInit( 0, rMgr, pRc );
      63                 :            :     }
      64                 :          0 :     ResId( sal_uInt32 nId, ResMgr& rMgr )
      65                 :            :     {
      66                 :          0 :         ImplInit( nId, rMgr, NULL );
      67                 :          0 :     }
      68                 :            :     // backwards compatibility; avoid ambiguities
      69                 :            :     ResId( sal_uInt16 nId, ResMgr& rMgr )
      70                 :            :     {
      71                 :            :         ImplInit( sal_uInt32(nId), rMgr, NULL );
      72                 :            :     }
      73                 :            :     ResId( int nId, ResMgr& rMgr )
      74                 :            :     {
      75                 :            :         ImplInit( sal_uInt32(nId), rMgr, NULL );
      76                 :            :     }
      77                 :            :     ResId( long nId, ResMgr& rMgr )
      78                 :            :     {
      79                 :            :         ImplInit( sal_uInt32(nId), rMgr, NULL );
      80                 :            :     }
      81                 :            : 
      82                 :            :     sal_uInt32 GetWinBits() const { return m_nWinBits; }
      83                 :            :     void SetWinBits( sal_uInt32 nBits ) const { m_nWinBits = nBits; }
      84                 :            : 
      85                 :          0 :     RESOURCE_TYPE   GetRT() const { return( m_nRT ); }
      86                 :            : 
      87                 :            :     /** Set the type if not already set. Ask for tye with GetRT()
      88                 :            : 
      89                 :            :     [Example]
      90                 :            :     ResId aId( 1000 );
      91                 :            :     aId.SetRT( RSC_WINDOW );    // settype window Window
      92                 :            :     aId.SetRT( RSC_BUTTON );    // will not set type Button
      93                 :            :     //aId.GetRT() == RSC_WINDOW is true
      94                 :            : 
      95                 :            :     @see
      96                 :            :     ResId::GetRT2(), ResId::GetRT()
      97                 :            :     */
      98                 :    1996205 :     const ResId &   SetRT( RESOURCE_TYPE nType ) const
      99                 :            :     {
     100         [ +  + ]:    1996205 :         if( RSC_NOTYPE == m_nRT )
     101                 :    1792275 :             m_nRT = nType;
     102                 :    1996205 :         return *this;
     103                 :            :     }
     104                 :            : 
     105                 :            :     /** Get the effective type (m_nRT2 or m_nRT1)
     106                 :            : 
     107                 :            :     A second resource type is used to supercede settings
     108                 :            :     of the base class ( e.g. Window )
     109                 :            :     */
     110                 :    2331626 :     RESOURCE_TYPE   GetRT2() const
     111                 :            :     {
     112         [ +  - ]:    2331626 :         return (RSC_NOTYPE == m_nRT2) ? m_nRT : m_nRT2;
     113                 :            :     }
     114                 :            : 
     115                 :            :     /** Set the superceding type. Ask spcifically for it with GetRT2()
     116                 :            : 
     117                 :            :     SetRT2() may only be called if no derived class calls SetRT in its
     118                 :            :     Resource constructor.
     119                 :            :     */
     120                 :            :     const ResId &   SetRT2( RESOURCE_TYPE nTyp ) const
     121                 :            :     {
     122                 :            :         if( RSC_NOTYPE == m_nRT2 )
     123                 :            :             m_nRT2 = nTyp;
     124                 :            :         return *this;
     125                 :            :     }
     126                 :            : 
     127                 :    4438851 :     ResMgr *        GetResMgr() const { return m_pResMgr; }
     128                 :          0 :     const ResId &   SetResMgr( ResMgr * pMgr ) const
     129                 :            :     {
     130                 :          0 :         m_pResMgr = pMgr;
     131                 :            :         OSL_ENSURE( m_pResMgr != NULL, "invalid ResMgr set on ResId" );
     132                 :          0 :         return *this;
     133                 :            :     }
     134                 :            : 
     135                 :            :     const ResId &  SetAutoRelease(sal_Bool bRelease) const
     136                 :            :     {
     137                 :            :         if( bRelease )
     138                 :            :             m_nResId &= ~RSC_DONTRELEASE;
     139                 :            :         else
     140                 :            :             m_nResId |= RSC_DONTRELEASE;
     141                 :            :         return *this;
     142                 :            :     }
     143                 :            : 
     144                 :    2079034 :     sal_Bool        IsAutoRelease()  const
     145                 :    2079034 :     { return !(m_nResId & RSC_DONTRELEASE); }
     146                 :            : 
     147                 :    2331626 :     sal_uInt32      GetId()        const { return m_nResId & ~RSC_DONTRELEASE; }
     148                 :    2331626 :     RSHEADER_TYPE*  GetpResource() const { return m_pResource; }
     149                 :            : 
     150                 :            :     TOOLS_DLLPUBLIC rtl::OUString toString() const;
     151                 :            :     TOOLS_DLLPUBLIC operator rtl::OUString() const { return toString(); }
     152                 :            : };
     153                 :            : 
     154                 :            : #endif
     155                 :            : 
     156                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10