merged tag ooo/DEV300_m102
[LibreOffice.git] / vcl / win / source / app / salshl.cxx
blob578b3cb804bd4b3f117b2f2040a8c33194f04b31
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 #include <tools/svwin.h>
31 #include <saldata.hxx>
32 #include <tools/debug.hxx>
34 // =======================================================================
36 SalShlData aSalShlData;
38 // =======================================================================
40 #ifdef WNT
42 extern "C"
45 #ifdef __MINGW32__
46 sal_Bool WINAPI DllMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
47 #else
48 #ifdef ICC
49 int _CRT_init(void);
50 #else
51 BOOL WINAPI _CRT_INIT( HINSTANCE hInst, DWORD nReason, LPVOID pReserved );
52 #endif
54 BOOL WINAPI LibMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
55 #endif
57 // Unsere DLL-Initialisierung
58 if ( nReason == DLL_PROCESS_ATTACH )
59 aSalShlData.mhInst = hInst;
61 #ifndef __MINGW32__
62 #ifdef ICC
63 if ( _CRT_init() == -1 )
64 #else
65 if ( !_CRT_INIT( hInst, nReason, pReserved ) )
66 #endif
67 return 0;
68 #endif
70 return 1;
75 #endif
77 // =======================================================================
79 HCURSOR ImplLoadSalCursor( int nId )
81 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
83 HCURSOR hCursor = LoadCursor( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
85 DBG_ASSERT( hCursor, "cursor not found in sal resource" );
87 return hCursor;
90 // -----------------------------------------------------------------------
92 HBITMAP ImplLoadSalBitmap( int nId )
94 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
96 HBITMAP hBitmap = LoadBitmap( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
98 DBG_ASSERT( hBitmap, "bitmap not found in sal resource" );
100 return hBitmap;
103 // -----------------------------------------------------------------------
105 sal_Bool ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon )
107 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
109 SalData* pSalData = GetSalData();
111 // check the cache first
112 SalIcon *pSalIcon = pSalData->mpFirstIcon;
113 while( pSalIcon )
115 if( pSalIcon->nId != nId )
116 pSalIcon = pSalIcon->pNext;
117 else
119 rIcon = pSalIcon->hIcon;
120 rSmallIcon = pSalIcon->hSmallIcon;
121 return (rSmallIcon != 0);
125 // Try at first to load the icons from the application exe file
126 rIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
127 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
128 LR_DEFAULTCOLOR );
129 if ( !rIcon )
131 // If the application don't provide these icons, then we try
132 // to load the icon from the VCL resource
133 rIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
134 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
135 LR_DEFAULTCOLOR );
136 if ( rIcon )
138 rSmallIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
139 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
140 LR_DEFAULTCOLOR );
142 else
143 rSmallIcon = 0;
145 else
147 rSmallIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
148 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
149 LR_DEFAULTCOLOR );
152 if( rIcon )
154 // add to icon cache
155 pSalIcon = new SalIcon();
156 pSalIcon->nId = nId;
157 pSalIcon->hIcon = rIcon;
158 pSalIcon->hSmallIcon = rSmallIcon;
159 pSalIcon->pNext = pSalData->mpFirstIcon;
160 pSalData->mpFirstIcon = pSalIcon;
163 return (rSmallIcon != 0);