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