1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_vcl.hxx" 26 27 #include <tools/debug.hxx> 28 #include <tools/svwin.h> 29 #include <win/saldata.hxx> 30 31 // ======================================================================= 32 33 SalShlData aSalShlData; 34 35 // ======================================================================= 36 37 #ifdef WNT 38 39 extern "C" 40 { 41 42 #ifdef __MINGW32__ 43 sal_Bool WINAPI DllMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved ) 44 #else 45 #ifdef ICC 46 int _CRT_init(void); 47 #else 48 BOOL WINAPI _CRT_INIT( HINSTANCE hInst, DWORD nReason, LPVOID pReserved ); 49 #endif 50 51 BOOL WINAPI LibMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved ) 52 #endif 53 { 54 // Unsere DLL-Initialisierung 55 if ( nReason == DLL_PROCESS_ATTACH ) 56 aSalShlData.mhInst = hInst; 57 58 #ifndef __MINGW32__ 59 #ifdef ICC 60 if ( _CRT_init() == -1 ) 61 #else 62 if ( !_CRT_INIT( hInst, nReason, pReserved ) ) 63 #endif 64 return 0; 65 #endif 66 67 return 1; 68 } 69 70 } 71 72 #endif 73 74 // ======================================================================= 75 76 HCURSOR ImplLoadSalCursor( int nId ) 77 { 78 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" ); 79 80 HCURSOR hCursor = LoadCursor( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) ); 81 82 DBG_ASSERT( hCursor, "cursor not found in sal resource" ); 83 84 return hCursor; 85 } 86 87 // ----------------------------------------------------------------------- 88 89 HBITMAP ImplLoadSalBitmap( int nId ) 90 { 91 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" ); 92 93 HBITMAP hBitmap = LoadBitmap( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) ); 94 95 DBG_ASSERT( hBitmap, "bitmap not found in sal resource" ); 96 97 return hBitmap; 98 } 99 100 // ----------------------------------------------------------------------- 101 102 sal_Bool ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon ) 103 { 104 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" ); 105 106 SalData* pSalData = GetSalData(); 107 108 // check the cache first 109 SalIcon *pSalIcon = pSalData->mpFirstIcon; 110 while( pSalIcon ) 111 { 112 if( pSalIcon->nId != nId ) 113 pSalIcon = pSalIcon->pNext; 114 else 115 { 116 rIcon = pSalIcon->hIcon; 117 rSmallIcon = pSalIcon->hSmallIcon; 118 return (rSmallIcon != 0); 119 } 120 } 121 122 // Try at first to load the icons from the application exe file 123 rIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ), 124 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ), 125 LR_DEFAULTCOLOR ); 126 if ( !rIcon ) 127 { 128 // If the application don't provide these icons, then we try 129 // to load the icon from the VCL resource 130 rIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ), 131 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ), 132 LR_DEFAULTCOLOR ); 133 if ( rIcon ) 134 { 135 rSmallIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ), 136 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), 137 LR_DEFAULTCOLOR ); 138 } 139 else 140 rSmallIcon = 0; 141 } 142 else 143 { 144 rSmallIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ), 145 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), 146 LR_DEFAULTCOLOR ); 147 } 148 149 if( rIcon ) 150 { 151 // add to icon cache 152 pSalIcon = new SalIcon(); 153 pSalIcon->nId = nId; 154 pSalIcon->hIcon = rIcon; 155 pSalIcon->hSmallIcon = rSmallIcon; 156 pSalIcon->pNext = pSalData->mpFirstIcon; 157 pSalData->mpFirstIcon = pSalIcon; 158 } 159 160 return (rSmallIcon != 0); 161 } 162