xref: /aoo42x/main/vcl/os2/source/app/salshl.cxx (revision fc9fd3f1)
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 #include <svpm.h>
25 
26 #define _SV_SALSHL_CXX
27 #include <os2/saldata.hxx>
28 #include <tools/debug.hxx>
29 
30 // =======================================================================
31 
32 SalShlData aSalShlData;
33 
34 HMODULE ImplGetModule(void);
35 static HMODULE mhMod = ImplGetModule();
36 
37 // =======================================================================
38 
39 APIRET APIENTRY DosQueryModFromEIP (HMODULE *phMod, ULONG *pObjNum,
40           ULONG BuffLen, PCHAR pBuff, ULONG *pOffset, ULONG Address);
41 
ImplGetModule(void)42 HMODULE ImplGetModule(void)
43 {
44 	HMODULE	hMod;
45 	ULONG	ObjNum;
46 	CHAR	Buff[2*_MAX_PATH];
47 	ULONG	Offset;
48 	APIRET	rc;
49 
50 	// get module handle (and name)
51 	rc = DosQueryModFromEIP( &hMod, &ObjNum, sizeof( Buff), Buff, &Offset, (ULONG)ImplGetModule);
52 	if (rc)
53 		return NULL;
54 	// return module handle
55 	aSalShlData.mhMod = hMod;
56 	return hMod;
57 }
58 
59 // =======================================================================
60 
ImplLoadSalCursor(int nId)61 HPOINTER ImplLoadSalCursor( int nId )
62 {
63 	DBG_ASSERT( aSalShlData.mhMod, "no DLL instance handle" );
64 
65 	HPOINTER hPointer = WinLoadPointer( HWND_DESKTOP, aSalShlData.mhMod, nId );
66 
67 	DBG_ASSERT( hPointer, "pointer not found in sal resource" );
68 #if OSL_DEBUG_LEVEL>0
69 	if (!hPointer)
70 		debug_printf( "ImplLoadSalCursor: pointer %d not found in sal resource\n", nId);
71 #endif
72 	return hPointer;
73 }
74 
75 // -----------------------------------------------------------------------
76 
ImplLoadSalIcon(int nId,HPOINTER & rIcon)77 sal_Bool ImplLoadSalIcon( int nId, HPOINTER& rIcon)
78 {
79 	DBG_ASSERT( aSalShlData.mhMod, "no DLL instance handle" );
80 
81 	SalData* pSalData = GetSalData();
82 
83     // check the cache first
84     SalIcon *pSalIcon = pSalData->mpFirstIcon;
85     while( pSalIcon )
86     {
87         if( pSalIcon->nId != nId )
88             pSalIcon = pSalIcon->pNext;
89         else
90         {
91             rIcon       = pSalIcon->hIcon;
92             return (rIcon != 0);
93         }
94     }
95 
96 	// Try at first to load the icons from the application exe file
97 	rIcon = WinLoadPointer( HWND_DESKTOP, NULL, nId );
98 	if ( !rIcon )
99 	{
100 		// If the application don't provide these icons, then we try
101 		// to load the icon from the VCL resource
102 		rIcon = WinLoadPointer( HWND_DESKTOP, aSalShlData.mhMod, nId );
103 	}
104 
105     if( rIcon )
106     {
107         // add to icon cache
108         pSalIcon = new SalIcon();
109         pSalIcon->nId = nId;
110         pSalIcon->hIcon = rIcon;
111         pSalIcon->pNext = pSalData->mpFirstIcon;
112         pSalData->mpFirstIcon = pSalIcon;
113     }
114 
115 	return (rIcon != 0);
116 }
117 
118 // =======================================================================
119 
120