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