1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/log.hxx>
22 #include <win/saldata.hxx>
24 SalShlData aSalShlData
;
26 extern "C" BOOL WINAPI
DllMain(HINSTANCE hInst
, DWORD nReason
, LPVOID
)
28 if ( nReason
== DLL_PROCESS_ATTACH
)
29 aSalShlData
.mhInst
= hInst
;
33 HCURSOR
ImplLoadSalCursor( int nId
)
35 SAL_WARN_IF( !aSalShlData
.mhInst
, "vcl", "no DLL instance handle" );
37 HCURSOR hCursor
= LoadCursorW( aSalShlData
.mhInst
, MAKEINTRESOURCEW( nId
) );
39 SAL_WARN_IF( !hCursor
, "vcl", "cursor not found in sal resource" );
44 HBITMAP
ImplLoadSalBitmap( int nId
)
46 SAL_WARN_IF( !aSalShlData
.mhInst
, "vcl", "no DLL instance handle" );
48 HBITMAP hBitmap
= LoadBitmapW( aSalShlData
.mhInst
, MAKEINTRESOURCEW( nId
) );
50 SAL_WARN_IF( !hBitmap
, "vcl", "bitmap not found in sal resource" );
55 bool ImplLoadSalIcon( int nId
, HICON
& rIcon
, HICON
& rSmallIcon
)
57 SAL_WARN_IF( !aSalShlData
.mhInst
, "vcl", "no DLL instance handle" );
59 SalData
* pSalData
= GetSalData();
61 // check the cache first
62 SalIcon
*pSalIcon
= pSalData
->mpFirstIcon
;
65 if( pSalIcon
->nId
!= nId
)
66 pSalIcon
= pSalIcon
->pNext
;
69 rIcon
= pSalIcon
->hIcon
;
70 rSmallIcon
= pSalIcon
->hSmallIcon
;
71 return (rSmallIcon
!= nullptr);
75 // Try at first to load the icons from the application exe file
76 rIcon
= static_cast<HICON
>(LoadImageW( pSalData
->mhInst
, MAKEINTRESOURCEW( nId
),
77 IMAGE_ICON
, GetSystemMetrics( SM_CXICON
), GetSystemMetrics( SM_CYICON
),
81 // If the application don't provide these icons, then we try
82 // to load the icon from the VCL resource
83 rIcon
= static_cast<HICON
>(LoadImageW( aSalShlData
.mhInst
, MAKEINTRESOURCEW( nId
),
84 IMAGE_ICON
, GetSystemMetrics( SM_CXICON
), GetSystemMetrics( SM_CYICON
),
88 rSmallIcon
= static_cast<HICON
>(LoadImageW( aSalShlData
.mhInst
, MAKEINTRESOURCEW( nId
),
89 IMAGE_ICON
, GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
97 rSmallIcon
= static_cast<HICON
>(LoadImageW( pSalData
->mhInst
, MAKEINTRESOURCEW( nId
),
98 IMAGE_ICON
, GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
105 pSalData
->mpFirstIcon
= new SalIcon
{
106 nId
, rIcon
, rSmallIcon
, pSalData
->mpFirstIcon
};
109 return (rSmallIcon
!= nullptr);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */