xref: /aoo41x/main/vcl/win/source/app/salshl.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include <tools/debug.hxx>
32 #include <tools/svwin.h>
33 #include <win/saldata.hxx>
34 
35 // =======================================================================
36 
37 SalShlData aSalShlData;
38 
39 // =======================================================================
40 
41 #ifdef WNT
42 
43 extern "C"
44 {
45 
46 #ifdef __MINGW32__
47 sal_Bool WINAPI DllMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
48 #else
49 #ifdef ICC
50 int _CRT_init(void);
51 #else
52 BOOL WINAPI _CRT_INIT( HINSTANCE hInst, DWORD nReason, LPVOID pReserved );
53 #endif
54 
55 BOOL WINAPI LibMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
56 #endif
57 {
58 	// Unsere DLL-Initialisierung
59 	if ( nReason == DLL_PROCESS_ATTACH )
60 		aSalShlData.mhInst = hInst;
61 
62 #ifndef __MINGW32__
63 #ifdef ICC
64 	if ( _CRT_init() == -1 )
65 #else
66 	if ( !_CRT_INIT( hInst, nReason, pReserved ) )
67 #endif
68 		return 0;
69 #endif
70 
71 	return 1;
72 }
73 
74 }
75 
76 #endif
77 
78 // =======================================================================
79 
80 HCURSOR ImplLoadSalCursor( int nId )
81 {
82 	DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
83 
84 	HCURSOR hCursor = LoadCursor( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
85 
86 	DBG_ASSERT( hCursor, "cursor not found in sal resource" );
87 
88 	return hCursor;
89 }
90 
91 // -----------------------------------------------------------------------
92 
93 HBITMAP ImplLoadSalBitmap( int nId )
94 {
95 	DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
96 
97 	HBITMAP hBitmap = LoadBitmap( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
98 
99 	DBG_ASSERT( hBitmap, "bitmap not found in sal resource" );
100 
101 	return hBitmap;
102 }
103 
104 // -----------------------------------------------------------------------
105 
106 sal_Bool ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon )
107 {
108 	DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
109 
110 	SalData* pSalData = GetSalData();
111 
112     // check the cache first
113     SalIcon *pSalIcon = pSalData->mpFirstIcon;
114     while( pSalIcon )
115     {
116         if( pSalIcon->nId != nId )
117             pSalIcon = pSalIcon->pNext;
118         else
119         {
120             rIcon       = pSalIcon->hIcon;
121             rSmallIcon  = pSalIcon->hSmallIcon;
122             return (rSmallIcon != 0);
123         }
124     }
125 
126 	// Try at first to load the icons from the application exe file
127 	rIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
128 										   IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
129                                            LR_DEFAULTCOLOR );
130 	if ( !rIcon )
131 	{
132 		// If the application don't provide these icons, then we try
133 		// to load the icon from the VCL resource
134 	    rIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
135 										   IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
136                                            LR_DEFAULTCOLOR );
137 		if ( rIcon )
138 		{
139 			rSmallIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
140 										   IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
141                                            LR_DEFAULTCOLOR );
142 		}
143 		else
144 			rSmallIcon = 0;
145 	}
146 	else
147 	{
148 		rSmallIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
149 									   IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
150                                        LR_DEFAULTCOLOR );
151 	}
152 
153     if( rIcon )
154     {
155         // add to icon cache
156         pSalIcon = new SalIcon();
157         pSalIcon->nId = nId;
158         pSalIcon->hIcon = rIcon;
159         pSalIcon->hSmallIcon = rSmallIcon;
160         pSalIcon->pNext = pSalData->mpFirstIcon;
161         pSalData->mpFirstIcon = pSalIcon;
162     }
163 
164 	return (rSmallIcon != 0);
165 }
166