Bump version to 4.1-6
[LibreOffice.git] / vcl / win / source / app / salshl.cxx
blob67feefc0b0ff6b7d5f840f11ee3aed59daf7f512
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svsys.h>
22 #include <tools/debug.hxx>
23 #include <win/saldata.hxx>
25 // =======================================================================
27 SalShlData aSalShlData;
29 // =======================================================================
31 extern "C"
34 #ifdef __MINGW32__
35 sal_Bool WINAPI DllMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
36 #else
37 #ifdef ICC
38 int _CRT_init(void);
39 #else
40 BOOL WINAPI _CRT_INIT( HINSTANCE hInst, DWORD nReason, LPVOID pReserved );
41 #endif
43 BOOL WINAPI LibMain( HINSTANCE hInst, DWORD nReason, LPVOID pReserved )
44 #endif
46 // Unsere DLL-Initialisierung
47 if ( nReason == DLL_PROCESS_ATTACH )
48 aSalShlData.mhInst = hInst;
50 #ifndef __MINGW32__
51 #ifdef ICC
52 if ( _CRT_init() == -1 )
53 #else
54 if ( !_CRT_INIT( hInst, nReason, pReserved ) )
55 #endif
56 return 0;
57 #else
58 (void)pReserved;
59 #endif
60 return 1;
65 // =======================================================================
67 HCURSOR ImplLoadSalCursor( int nId )
69 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
71 HCURSOR hCursor = LoadCursor( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
73 DBG_ASSERT( hCursor, "cursor not found in sal resource" );
75 return hCursor;
78 // -----------------------------------------------------------------------
80 HBITMAP ImplLoadSalBitmap( int nId )
82 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
84 HBITMAP hBitmap = LoadBitmap( aSalShlData.mhInst, MAKEINTRESOURCE( nId ) );
86 DBG_ASSERT( hBitmap, "bitmap not found in sal resource" );
88 return hBitmap;
91 // -----------------------------------------------------------------------
93 sal_Bool ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon )
95 DBG_ASSERT( aSalShlData.mhInst, "no DLL instance handle" );
97 SalData* pSalData = GetSalData();
99 // check the cache first
100 SalIcon *pSalIcon = pSalData->mpFirstIcon;
101 while( pSalIcon )
103 if( pSalIcon->nId != nId )
104 pSalIcon = pSalIcon->pNext;
105 else
107 rIcon = pSalIcon->hIcon;
108 rSmallIcon = pSalIcon->hSmallIcon;
109 return (rSmallIcon != 0);
113 // Try at first to load the icons from the application exe file
114 rIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
115 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
116 LR_DEFAULTCOLOR );
117 if ( !rIcon )
119 // If the application don't provide these icons, then we try
120 // to load the icon from the VCL resource
121 rIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
122 IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ),
123 LR_DEFAULTCOLOR );
124 if ( rIcon )
126 rSmallIcon = (HICON)LoadImage( aSalShlData.mhInst, MAKEINTRESOURCE( nId ),
127 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
128 LR_DEFAULTCOLOR );
130 else
131 rSmallIcon = 0;
133 else
135 rSmallIcon = (HICON)LoadImage( pSalData->mhInst, MAKEINTRESOURCE( nId ),
136 IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
137 LR_DEFAULTCOLOR );
140 if( rIcon )
142 // add to icon cache
143 pSalIcon = new SalIcon();
144 pSalIcon->nId = nId;
145 pSalIcon->hIcon = rIcon;
146 pSalIcon->hSmallIcon = rSmallIcon;
147 pSalIcon->pNext = pSalData->mpFirstIcon;
148 pSalData->mpFirstIcon = pSalIcon;
151 return (rSmallIcon != 0);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */