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.
35 #include "openwidedll.h"
36 #include "openwideres.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
;
50 return SetFocus( GetDlgItem(hwnd
, uID
)) != NULL
;
54 WORD
focusToCtlID(int iFocus
)
56 //BOOL bXP = isWinXP();
74 HWND
getChildWinFromPt(HWND hwnd
)
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
);
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
);
93 ClientToScreen(GetParent(hwnd
), &pt
);
94 ScreenToClient(hw
, &pt
);
95 hw
= ChildWindowFromPointEx(hw
, pt
, CWP_SKIPDISABLED
| CWP_SKIPINVISIBLE
);
102 int subclass(HWND hwnd
, WNDPROC wpNew
, LPARAM lpData
)
104 if( GetProp(hwnd
, OW_PROP_NAME
) != NULL
)
106 POWSubClassData pow
= (POWSubClassData
)malloc(sizeof(OWSubClassData
));
109 ZeroMemory(pow
, sizeof(OWSubClassData
));
110 if( !SetProp(hwnd
, OW_PROP_NAME
, pow
) )
115 pow
->lpData
= lpData
;
116 pow
->wpOrig
= (WNDPROC
)SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
)wpNew
);
121 int unsubclass(HWND hwnd
)
123 POWSubClassData pow
= (POWSubClassData
)GetProp(hwnd
, OW_PROP_NAME
);
126 SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
)pow
->wpOrig
);
127 RemoveProp(hwnd
, OW_PROP_NAME
);
135 WORD
viewToCmdID(int iView
)
137 BOOL bXP
= isWinXP();
141 return CMD_2K_DETAILS
;
143 return (bXP
) ? CMD_XP_LIST
: CMD_2K_LIST
;
145 return (bXP
) ? 0 : CMD_2K_SMICONS
;
147 return (bXP
) ? CMD_XP_LGICONS
: CMD_2K_LGICONS
;
149 return (bXP
) ? CMD_XP_THUMBS
: CMD_2K_THUMBS
;
151 return (bXP
) ? CMD_XP_TILES
: 0;
158 BOOL
waitForMutex(void)
162 ghMutex
= OpenMutex(SYNCHRONIZE
, FALSE
, OW_MUTEX_NAME
);
165 dwRes
= WaitForSingleObject(ghMutex
, INFINITE
);
179 void releaseMutex(void)
183 ReleaseMutex(ghMutex
);
189 BOOL CALLBACK
fpEnumChildren(HWND hwnd
, LPARAM lParam
)
192 if( GetClassName(hwnd
, buf
, 31) )
194 switch(gOwShared
.iFocus
)
197 if( strcmp(buf
, WC_LISTVIEWA
) == 0 && GetDlgCtrlID(hwnd
) == CID_DIRLIST
)
201 if( strcmp(buf
, WC_COMBOBOXEXA
) == 0 && GetDlgCtrlID(hwnd
) == CID_FNAME
)
205 if( strcmp(buf
, WC_COMBOBOXA
) == 0 && GetDlgCtrlID(hwnd
) == CID_FTYPE
)
209 if( IsWindowVisible(hwnd
) && strcmp(buf
, TOOLBARCLASSNAMEA
) == 0 && GetDlgCtrlID(hwnd
) == CID_PLACES
)
213 if( strcmp(buf
, WC_COMBOBOXA
) == 0 && GetDlgCtrlID(hwnd
) == CID_LOOKIN
)
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));
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
;
240 //dbg("Window's class is %s - not what's wanted", buf);
245 HWND
findChildWindow(HWND hwParent
, UINT uID
, const char *szClass
)
249 fData
.szClass
= szClass
;
251 fData
.hwFound
= NULL
;
253 //dbg("findChildWindow: seeking \"%s\", %d", szClass, uID);
255 EnumChildWindows(hwParent
, (WNDENUMPROC
)enumFindChildWindow
, (LPARAM
) & fData
);
257 return fData
.hwFound
;