Update ooo320-m1
[ooovba.git] / vcl / win / source / app / salshl.cxx
blob1f210c9b0676799ccd41bf4c622bdf44786a3247
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salshl.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/svwin.h>
34 #include <saldata.hxx>
35 #include <tools/debug.hxx>
37 // =======================================================================
39 SalShlData aSalShlData;
41 // =======================================================================
43 #ifdef WNT
45 extern "C"
48 #ifdef __MINGW32__
49 BOOL WINAPI DllMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
50 #else
51 #ifdef ICC
52 int _CRT_init(void);
53 #else
54 WIN_BOOL WINAPI _CRT_INIT( HINSTANCE hInst, DWORD nReason, LPVOID pReserved );
55 #endif
57 WIN_BOOL WINAPI LibMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
58 #endif
60 // Unsere DLL-Initialisierung
61 if ( nReason == DLL_PROCESS_ATTACH )
62 aSalShlData.mhInst = hInst;
64 #ifndef __MINGW32__
65 #ifdef ICC
66 if ( _CRT_init() == -1 )
67 #else
68 if ( !_CRT_INIT( hInst, nReason, pReserved ) )
69 #endif
70 return 0;
71 #endif
73 return 1;
78 #endif
80 // =======================================================================
82 HCURSOR ImplLoadSalCursor( int nId )
84 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
86 HCURSOR hCursor = LoadCursor( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
88 DBG_ASSERT( hCursor, "cursor not found in sal resource" );
90 return hCursor;
93 // -----------------------------------------------------------------------
95 HBITMAP ImplLoadSalBitmap( int nId )
97 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
99 HBITMAP hBitmap = LoadBitmap( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
101 DBG_ASSERT( hBitmap, "bitmap not found in sal resource" );
103 return hBitmap;
106 // -----------------------------------------------------------------------
108 BOOL ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon )
110 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
112 SalData* pSalData = GetSalData();
114 // check the cache first
115 SalIcon *pSalIcon = pSalData->mpFirstIcon;
116 while( pSalIcon )
118 if( pSalIcon->nId != nId )
119 pSalIcon = pSalIcon->pNext;
120 else
122 rIcon = pSalIcon->hIcon;
123 rSmallIcon = pSalIcon->hSmallIcon;
124 return (rSmallIcon != 0);
128 // Try at first to load the icons from the application exe file
129 rIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
130 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
131 LR_DEFAULTCOLOR );
132 if ( !rIcon )
134 // If the application don't provide these icons, then we try
135 // to load the icon from the VCL resource
136 rIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
137 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
138 LR_DEFAULTCOLOR );
139 if ( rIcon )
141 rSmallIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
142 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
143 LR_DEFAULTCOLOR );
145 else
146 rSmallIcon = 0;
148 else
150 rSmallIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
151 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
152 LR_DEFAULTCOLOR );
155 if( rIcon )
157 // add to icon cache
158 pSalIcon = new SalIcon();
159 pSalIcon->nId = nId;
160 pSalIcon->hIcon = rIcon;
161 pSalIcon->hSmallIcon = rSmallIcon;
162 pSalIcon->pNext = pSalData->mpFirstIcon;
163 pSalData->mpFirstIcon = pSalIcon;
166 return (rSmallIcon != 0);