Removed Pro2 comments
[openwide.git] / owDLLUtil.c
blob28c2716e0367c330cc503f0d1486c0b8d40c5fac
1 /*
2 * Openwide -- control Windows common dialog
3 *
4 * Copyright (c) 2000 Luke Hudson
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <windows.h>
24 #include <commctrl.h>
25 #include <shlwapi.h>
26 #include <shellapi.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <dlgs.h>
30 #include "openwidedll.h"
31 #include "openwideres.h"
32 #include "owDllInc.h"
37 int focusDlgItem(HWND hwnd, int iFocus)
39 UINT uID = focusToCtlID(gOwShared.iFocus);
40 if( uID == CID_DIRLIST )
42 return SetFocus( GetDlgItem( GetDlgItem(hwnd, CID_DIRLISTPARENT) , uID) ) != NULL;
44 else
45 return SetFocus( GetDlgItem(hwnd, uID)) != NULL;
49 WORD focusToCtlID(int iFocus)
51 //BOOL bXP = isWinXP();
52 switch( iFocus )
54 case F_DIRLIST:
55 return CID_DIRLIST;
56 case F_FNAME:
57 return CID_FNAME;
58 case F_FTYPE:
59 return CID_FTYPE;
60 case F_PLACES:
61 return CID_PLACES;
62 case F_LOOKIN:
63 return CID_LOOKIN;
65 return CID_DIRLIST;
69 HWND getChildWinFromPt(HWND hwnd)
71 POINT pt;
72 GetCursorPos(&pt);
73 ScreenToClient(GetParent(hwnd), &pt);
75 EnableWindow(hwnd, FALSE);
76 HWND hw = ChildWindowFromPointEx(GetParent(hwnd), pt, CWP_SKIPDISABLED | CWP_SKIPINVISIBLE);
77 EnableWindow(hwnd, TRUE);
78 HWND hwSV = GetDlgItem(GetParent(hwnd), CID_DIRLISTPARENT);
79 if( hw == hwSV )
81 ClientToScreen(GetParent(hwnd), &pt);
82 ScreenToClient(hw, &pt);
83 hw = ChildWindowFromPointEx(hw, pt, CWP_SKIPDISABLED | CWP_SKIPINVISIBLE);
85 HWND hwEd = GetDlgItem(GetParent(hwnd), CID_FNAME);
86 if( hw == hwEd )
88 ClientToScreen(GetParent(hwnd), &pt);
89 ScreenToClient(hw, &pt);
90 hw = ChildWindowFromPointEx(hw, pt, CWP_SKIPDISABLED | CWP_SKIPINVISIBLE);
92 return hw;
97 int subclass(HWND hwnd, WNDPROC wpNew, LPARAM lpData)
99 if( GetProp(hwnd, OW_PROP_NAME) != NULL )
100 return 0;
101 POWSubClassData pow = (POWSubClassData)malloc(sizeof(OWSubClassData));
102 if(!pow)
103 return 0;
104 ZeroMemory(pow, sizeof(OWSubClassData));
105 if( !SetProp(hwnd, OW_PROP_NAME, pow) )
107 free(pow);
108 return 0;
110 pow->lpData = lpData;
111 pow->wpOrig = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG)wpNew);
112 return 1;
116 int unsubclass(HWND hwnd)
118 POWSubClassData pow = (POWSubClassData)GetProp(hwnd, OW_PROP_NAME);
119 if(pow)
121 SetWindowLong(hwnd, GWL_WNDPROC, (LONG)pow->wpOrig);
122 RemoveProp(hwnd, OW_PROP_NAME);
123 free(pow);
124 return 1;
126 return 0;
130 WORD viewToCmdID(int iView)
132 BOOL bXP = isWinXP();
133 switch( iView )
135 case V_DETAILS:
136 return CMD_2K_DETAILS;
137 case V_LIST:
138 return (bXP) ? CMD_XP_LIST : CMD_2K_LIST;
139 case V_SMICONS:
140 return (bXP) ? 0 : CMD_2K_SMICONS;
141 case V_LGICONS:
142 return (bXP) ? CMD_XP_LGICONS : CMD_2K_LGICONS;
143 case V_THUMBS:
144 return (bXP) ? CMD_XP_THUMBS : CMD_2K_THUMBS;
145 case V_TILES:
146 return (bXP) ? CMD_XP_TILES : 0;
148 return CMD_2K_LIST;
153 BOOL waitForMutex(void)
155 DWORD dwRes;
156 if( !ghMutex )
157 ghMutex = OpenMutex(SYNCHRONIZE, FALSE, OW_MUTEX_NAME);
158 if( ghMutex )
160 dwRes = WaitForSingleObject(ghMutex, INFINITE);
161 switch(dwRes)
163 case WAIT_OBJECT_0:
164 // okay, continue
165 break;
166 case WAIT_ABANDONED:
167 default:
168 return FALSE;
171 return TRUE;
174 void releaseMutex(void)
176 if( ghMutex )
178 ReleaseMutex(ghMutex);
179 ghMutex = NULL;
184 BOOL CALLBACK fpEnumChildren(HWND hwnd, LPARAM lParam)
186 static char buf[32];
187 if( GetClassName(hwnd, buf, 31) )
189 switch(gOwShared.iFocus)
191 case F_DIRLIST:
192 if( strcmp(buf, WC_LISTVIEWA) == 0 && GetDlgCtrlID(hwnd) == CID_DIRLIST)
193 SetFocus(hwnd);
194 break;
195 case F_FNAME:
196 if( strcmp(buf, WC_COMBOBOXEXA) == 0 && GetDlgCtrlID(hwnd) == CID_FNAME)
197 SetFocus(hwnd);
198 break;
199 case F_FTYPE:
200 if( strcmp(buf, WC_COMBOBOXA) == 0 && GetDlgCtrlID(hwnd) == CID_FTYPE)
201 SetFocus(hwnd);
202 break;
203 case F_PLACES:
204 if( IsWindowVisible(hwnd) && strcmp(buf, TOOLBARCLASSNAMEA) == 0 && GetDlgCtrlID(hwnd) == CID_PLACES)
205 SetFocus(hwnd);
206 break;
207 case F_LOOKIN:
208 if( strcmp(buf, WC_COMBOBOXA) == 0 && GetDlgCtrlID(hwnd) == CID_LOOKIN)
209 SetFocus(hwnd);
210 break;
213 /* if( GetDlgCtrlID(hwnd) == 0x47c )
215 SetWindowText(hwnd, "C:\\code\\");
216 SendMessage((HWND)lParam, WM_COMMAND, MAKEWPARAM(1, BN_CLICKED), (LPARAM)GetDlgItem((HWND)lParam, 1));
218 return 1;
222 static int CALLBACK WINAPI enumFindChildWindow(HWND hwnd, PFindChildData pData)
224 UINT uID = GetDlgCtrlID(hwnd);
225 static char buf[256];
226 if (uID == pData->uID)
228 //dbg("Found window %p with id %d", hwnd, uID);
229 if (GetClassName(hwnd, buf, 256) && strcmp(buf, pData->szClass) == 0)
231 pData->hwFound = hwnd;
232 return 0;
234 //else
235 //dbg("Window's class is %s - not what's wanted", buf);
237 return 1;
240 HWND findChildWindow(HWND hwParent, UINT uID, const char *szClass)
242 FindChildData fData;
244 fData.szClass = szClass;
245 fData.uID = uID;
246 fData.hwFound = NULL;
248 //dbg("findChildWindow: seeking \"%s\", %d", szClass, uID);
250 EnumChildWindows(hwParent, (WNDENUMPROC)enumFindChildWindow, (LPARAM) & fData);
252 return fData.hwFound;