2 * Openwide -- control Windows common dialog
4 * Copyright (c) 2000 Luke Hudson
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.
30 #include "openwidedll.h"
31 #include "openwideres.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
;
45 return SetFocus( GetDlgItem(hwnd
, uID
)) != NULL
;
49 WORD
focusToCtlID(int iFocus
)
51 //BOOL bXP = isWinXP();
69 HWND
getChildWinFromPt(HWND hwnd
)
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
);
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
);
88 ClientToScreen(GetParent(hwnd
), &pt
);
89 ScreenToClient(hw
, &pt
);
90 hw
= ChildWindowFromPointEx(hw
, pt
, CWP_SKIPDISABLED
| CWP_SKIPINVISIBLE
);
97 int subclass(HWND hwnd
, WNDPROC wpNew
, LPARAM lpData
)
99 if( GetProp(hwnd
, OW_PROP_NAME
) != NULL
)
101 POWSubClassData pow
= (POWSubClassData
)malloc(sizeof(OWSubClassData
));
104 ZeroMemory(pow
, sizeof(OWSubClassData
));
105 if( !SetProp(hwnd
, OW_PROP_NAME
, pow
) )
110 pow
->lpData
= lpData
;
111 pow
->wpOrig
= (WNDPROC
)SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
)wpNew
);
116 int unsubclass(HWND hwnd
)
118 POWSubClassData pow
= (POWSubClassData
)GetProp(hwnd
, OW_PROP_NAME
);
121 SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
)pow
->wpOrig
);
122 RemoveProp(hwnd
, OW_PROP_NAME
);
130 WORD
viewToCmdID(int iView
)
132 BOOL bXP
= isWinXP();
136 return CMD_2K_DETAILS
;
138 return (bXP
) ? CMD_XP_LIST
: CMD_2K_LIST
;
140 return (bXP
) ? 0 : CMD_2K_SMICONS
;
142 return (bXP
) ? CMD_XP_LGICONS
: CMD_2K_LGICONS
;
144 return (bXP
) ? CMD_XP_THUMBS
: CMD_2K_THUMBS
;
146 return (bXP
) ? CMD_XP_TILES
: 0;
153 BOOL
waitForMutex(void)
157 ghMutex
= OpenMutex(SYNCHRONIZE
, FALSE
, OW_MUTEX_NAME
);
160 dwRes
= WaitForSingleObject(ghMutex
, INFINITE
);
174 void releaseMutex(void)
178 ReleaseMutex(ghMutex
);
184 BOOL CALLBACK
fpEnumChildren(HWND hwnd
, LPARAM lParam
)
187 if( GetClassName(hwnd
, buf
, 31) )
189 switch(gOwShared
.iFocus
)
192 if( strcmp(buf
, WC_LISTVIEWA
) == 0 && GetDlgCtrlID(hwnd
) == CID_DIRLIST
)
196 if( strcmp(buf
, WC_COMBOBOXEXA
) == 0 && GetDlgCtrlID(hwnd
) == CID_FNAME
)
200 if( strcmp(buf
, WC_COMBOBOXA
) == 0 && GetDlgCtrlID(hwnd
) == CID_FTYPE
)
204 if( IsWindowVisible(hwnd
) && strcmp(buf
, TOOLBARCLASSNAMEA
) == 0 && GetDlgCtrlID(hwnd
) == CID_PLACES
)
208 if( strcmp(buf
, WC_COMBOBOXA
) == 0 && GetDlgCtrlID(hwnd
) == CID_LOOKIN
)
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));
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
;
235 //dbg("Window's class is %s - not what's wanted", buf);
240 HWND
findChildWindow(HWND hwParent
, UINT uID
, const char *szClass
)
244 fData
.szClass
= szClass
;
246 fData
.hwFound
= NULL
;
248 //dbg("findChildWindow: seeking \"%s\", %d", szClass, uID);
250 EnumChildWindows(hwParent
, (WNDENUMPROC
)enumFindChildWindow
, (LPARAM
) & fData
);
252 return fData
.hwFound
;