MINOR: Change output filename
[openwide.git] / owDLLUtil.c
blob9f750c99cd3b69898dff05942f27ef270cd9e12a
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 /**
25 * @author Luke Hudson
26 * @licence GPL2
29 #include <commctrl.h>
30 #include <shlwapi.h>
31 #include <shellapi.h>
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <dlgs.h>
35 #include "openwidedll.h"
36 #include "openwideres.h"
37 #include "owDllInc.h"
42 int focusDlgItem(HWND hwnd, int iFocus)
44 UINT uID = focusToCtlID(gOwShared.iFocus);
45 if( uID == CID_DIRLIST )
47 return SetFocus( GetDlgItem( GetDlgItem(hwnd, CID_DIRLISTPARENT) , uID) ) != NULL;
49 else
50 return SetFocus( GetDlgItem(hwnd, uID)) != NULL;
54 WORD focusToCtlID(int iFocus)
56 //BOOL bXP = isWinXP();
57 switch( iFocus )
59 case F_DIRLIST:
60 return CID_DIRLIST;
61 case F_FNAME:
62 return CID_FNAME;
63 case F_FTYPE:
64 return CID_FTYPE;
65 case F_PLACES:
66 return CID_PLACES;
67 case F_LOOKIN:
68 return CID_LOOKIN;
70 return CID_DIRLIST;
74 HWND getChildWinFromPt(HWND hwnd)
76 POINT pt;
77 GetCursorPos(&pt);
78 ScreenToClient(GetParent(hwnd), &pt);
80 EnableWindow(hwnd, FALSE);
81 HWND hw = ChildWindowFromPointEx(GetParent(hwnd), pt, CWP_SKIPDISABLED | CWP_SKIPINVISIBLE);
82 EnableWindow(hwnd, TRUE);
83 HWND hwSV = GetDlgItem(GetParent(hwnd), CID_DIRLISTPARENT);
84 if( hw == hwSV )
86 ClientToScreen(GetParent(hwnd), &pt);
87 ScreenToClient(hw, &pt);
88 hw = ChildWindowFromPointEx(hw, pt, CWP_SKIPDISABLED | CWP_SKIPINVISIBLE);
90 HWND hwEd = GetDlgItem(GetParent(hwnd), CID_FNAME);
91 if( hw == hwEd )
93 ClientToScreen(GetParent(hwnd), &pt);
94 ScreenToClient(hw, &pt);
95 hw = ChildWindowFromPointEx(hw, pt, CWP_SKIPDISABLED | CWP_SKIPINVISIBLE);
97 return hw;
102 int subclass(HWND hwnd, WNDPROC wpNew, LPARAM lpData)
104 if( GetProp(hwnd, OW_PROP_NAME) != NULL )
105 return 0;
106 POWSubClassData pow = (POWSubClassData)malloc(sizeof(OWSubClassData));
107 if(!pow)
108 return 0;
109 ZeroMemory(pow, sizeof(OWSubClassData));
110 if( !SetProp(hwnd, OW_PROP_NAME, pow) )
112 free(pow);
113 return 0;
115 pow->lpData = lpData;
116 pow->wpOrig = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG)wpNew);
117 return 1;
121 int unsubclass(HWND hwnd)
123 POWSubClassData pow = (POWSubClassData)GetProp(hwnd, OW_PROP_NAME);
124 if(pow)
126 SetWindowLong(hwnd, GWL_WNDPROC, (LONG)pow->wpOrig);
127 RemoveProp(hwnd, OW_PROP_NAME);
128 free(pow);
129 return 1;
131 return 0;
135 WORD viewToCmdID(int iView)
137 BOOL bXP = isWinXP();
138 switch( iView )
140 case V_DETAILS:
141 return CMD_2K_DETAILS;
142 case V_LIST:
143 return (bXP) ? CMD_XP_LIST : CMD_2K_LIST;
144 case V_SMICONS:
145 return (bXP) ? 0 : CMD_2K_SMICONS;
146 case V_LGICONS:
147 return (bXP) ? CMD_XP_LGICONS : CMD_2K_LGICONS;
148 case V_THUMBS:
149 return (bXP) ? CMD_XP_THUMBS : CMD_2K_THUMBS;
150 case V_TILES:
151 return (bXP) ? CMD_XP_TILES : 0;
153 return CMD_2K_LIST;
158 BOOL waitForMutex(void)
160 DWORD dwRes;
161 if( !ghMutex )
162 ghMutex = OpenMutex(SYNCHRONIZE, FALSE, OW_MUTEX_NAME);
163 if( ghMutex )
165 dwRes = WaitForSingleObject(ghMutex, INFINITE);
166 switch(dwRes)
168 case WAIT_OBJECT_0:
169 // okay, continue
170 break;
171 case WAIT_ABANDONED:
172 default:
173 return FALSE;
176 return TRUE;
179 void releaseMutex(void)
181 if( ghMutex )
183 ReleaseMutex(ghMutex);
184 ghMutex = NULL;
189 BOOL CALLBACK fpEnumChildren(HWND hwnd, LPARAM lParam)
191 static char buf[32];
192 if( GetClassName(hwnd, buf, 31) )
194 switch(gOwShared.iFocus)
196 case F_DIRLIST:
197 if( strcmp(buf, WC_LISTVIEWA) == 0 && GetDlgCtrlID(hwnd) == CID_DIRLIST)
198 SetFocus(hwnd);
199 break;
200 case F_FNAME:
201 if( strcmp(buf, WC_COMBOBOXEXA) == 0 && GetDlgCtrlID(hwnd) == CID_FNAME)
202 SetFocus(hwnd);
203 break;
204 case F_FTYPE:
205 if( strcmp(buf, WC_COMBOBOXA) == 0 && GetDlgCtrlID(hwnd) == CID_FTYPE)
206 SetFocus(hwnd);
207 break;
208 case F_PLACES:
209 if( IsWindowVisible(hwnd) && strcmp(buf, TOOLBARCLASSNAMEA) == 0 && GetDlgCtrlID(hwnd) == CID_PLACES)
210 SetFocus(hwnd);
211 break;
212 case F_LOOKIN:
213 if( strcmp(buf, WC_COMBOBOXA) == 0 && GetDlgCtrlID(hwnd) == CID_LOOKIN)
214 SetFocus(hwnd);
215 break;
218 /* if( GetDlgCtrlID(hwnd) == 0x47c )
220 SetWindowText(hwnd, "C:\\code\\");
221 SendMessage((HWND)lParam, WM_COMMAND, MAKEWPARAM(1, BN_CLICKED), (LPARAM)GetDlgItem((HWND)lParam, 1));
223 return 1;
227 static int CALLBACK WINAPI enumFindChildWindow(HWND hwnd, PFindChildData pData)
229 UINT uID = GetDlgCtrlID(hwnd);
230 static char buf[256];
231 if (uID == pData->uID)
233 //dbg("Found window %p with id %d", hwnd, uID);
234 if (GetClassName(hwnd, buf, 256) && strcmp(buf, pData->szClass) == 0)
236 pData->hwFound = hwnd;
237 return 0;
239 //else
240 //dbg("Window's class is %s - not what's wanted", buf);
242 return 1;
245 HWND findChildWindow(HWND hwParent, UINT uID, const char *szClass)
247 FindChildData fData;
249 fData.szClass = szClass;
250 fData.uID = uID;
251 fData.hwFound = NULL;
253 //dbg("findChildWindow: seeking \"%s\", %d", szClass, uID);
255 EnumChildWindows(hwParent, (WNDENUMPROC)enumFindChildWindow, (LPARAM) & fData);
257 return fData.hwFound;