13 #include "openwidedll.h"
14 #include "openwideres.h"
16 #include "owSharedUtil.h"
18 #include "openwide_proto.h"
21 #define SETDLGRESULT(hw, x) SetWindowLong((hw), DWL_MSGRESULT, (LONG)(x))
22 static int gIdxLastSheet
= 0;
25 static void setTabChanged(HWND hwnd
, BOOL bChanged
)
28 PropSheet_Changed(ghwPropSheet
, hwnd
);
30 PropSheet_UnChanged(ghwPropSheet
, hwnd
);
33 int savePrefsToRegistry(void)
35 HKEY hk
= regCreateKey(HKEY_CURRENT_USER
, OW_REGKEY_NAME
);
38 regWriteDWORD(hk
, NULL
, sizeof(OWSharedData
));
39 regWriteBinaryData(hk
, "OWData", (byte
*)gPowData
, sizeof(OWSharedData
));
48 int initPrefs(HWND hwnd
)
50 if(!initSharedMem(NULL
))
53 CheckDlgButton(hwnd
, IDC_WSTARTUP
, isStartupApp(hwnd
));
54 CheckDlgButton(hwnd
, IDC_LOG
, BST_CHECKED
);
59 CheckDlgButton(hwnd
, IDC_STARTMIN
, gPowData
->bStartMin
);
60 CheckDlgButton(hwnd
, IDC_SHOWICON
, gPowData
->bShowIcon
);
66 SendMessage(ghwMain, WM_SYSCOMMAND, SC_MINIMIZE, 0);
72 SetFocus(GetDlgItem(hwnd, IDB_SETPLACEMENT));
73 ShowWindow(hwnd, SW_SHOWNORMAL);
78 static void onPrefsTabCommand(HWND hwnd
, WPARAM wp
, LPARAM lp
)
85 setTabChanged(hwnd
, HIWORD(wp
)==BN_CLICKED
);
90 static BOOL CALLBACK
wpPrefs(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
98 onPrefsTabCommand(hwnd
, wp
, lp
);
102 LPNMHDR pnh
= (LPNMHDR
)lp
;
103 if( pnh
->hwndFrom
== ghwPropSheet
)
108 SETDLGRESULT(hwnd
, FALSE
);
115 //Warn("Couldn't get access to shared memory!");
116 SETDLGRESULT(hwnd
, PSNRET_INVALID
);
120 gPowData
->bStartMin
= (IsDlgButtonChecked(hwnd
, IDC_STARTMIN
) == BST_CHECKED
);
121 BOOL bShowIcon
= gPowData
->bShowIcon
= (IsDlgButtonChecked(hwnd
, IDC_SHOWICON
) == BST_CHECKED
);
122 BOOL bWinStart
= IsDlgButtonChecked(hwnd
, IDC_WSTARTUP
) == BST_CHECKED
;
124 savePrefsToRegistry();
128 setStartupApp(hwnd
, bWinStart
);
130 addTrayIcon(ghwMain
);
132 remTrayIcon(ghwMain
);
133 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
151 static int enumExcludes(HKEY hkRoot
, const char *szKey
, DWORD dwType
, LPVOID pParm
)
153 if( dwType
== REG_DWORD
)
154 SendMessage((HWND
)pParm
, LB_ADDSTRING
, 0, (LPARAM
)szKey
);
158 static int addExcludes2LB(HWND hwnd
, UINT uID
)
160 HWND hwLB
= GetDlgItem(hwnd
, uID
);
163 HKEY hk
= regOpenKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
166 regEnumValues(hk
, enumExcludes
, (LPVOID
)hwLB
);
173 static int initExcludes(HWND hwnd
)
175 return addExcludes2LB(hwnd
, IDL_EXCLUDES
);
178 static int addExclude(HWND hwnd
)
180 const char *szEx
= Prompt_File_Name(OPEN
, hwnd
, "Executable Files\0*.exe;*.com", "Choose program to exclude");
183 // PathStripPath((char *)szEx);
184 int idx
= SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_FINDSTRINGEXACT
, -1, (LPARAM
)szEx
);
186 Warn("This program is already excluded");
188 SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_ADDSTRING
, 0, (LPARAM
)szEx
);
193 static int rmvExclude(HWND hwnd
)
195 int idx
= SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_GETCURSEL
, 0,0);
197 SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_DELETESTRING
, idx
, 0);
201 static int saveExcludes2Registry(HWND hwnd
, UINT uID
)
203 HWND hwLB
= GetDlgItem(hwnd
, uID
);
206 static char szKey
[32];
207 regDeleteKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
208 HKEY hk
= regCreateKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
211 int num
= SendMessage(hwLB
, LB_GETCOUNT
,0,0);
214 for(int i
=0; i
< num
; i
++)
216 char *szEx
= lbGetItemText(hwLB
, i
);
219 regWriteDWORD(hk
, szEx
, 1);
230 static void onExTabCmd(HWND hwnd
, WPARAM wp
, LPARAM lp
)
243 static BOOL CALLBACK
wpExcludes(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
251 onExTabCmd(hwnd
, wp
, lp
);
255 LPNMHDR pnh
= (LPNMHDR
)lp
;
256 if( pnh
->hwndFrom
== ghwPropSheet
)
261 SETDLGRESULT(hwnd
, FALSE
);
266 saveExcludes2Registry(hwnd
, IDL_EXCLUDES
);
267 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
281 static void onOSTabCommand(HWND hwnd
, WPARAM wp
, LPARAM lp
)
287 if( HIWORD(wp
) == CBN_SELCHANGE
)
288 setTabChanged(hwnd
, TRUE
);
294 if( HIWORD(wp
) == EN_CHANGE
)
295 setTabChanged(hwnd
, TRUE
);
300 case IDB_SETPLACEMENT
:
303 r
.left
= GetDlgItemInt(hwnd
, IDE_LEFT
, NULL
, TRUE
);
304 r
.top
= GetDlgItemInt(hwnd
, IDE_TOP
, NULL
, TRUE
);
305 r
.right
= max( GetDlgItemInt(hwnd
, IDE_WIDTH
, NULL
, FALSE
), 100 );
306 r
.bottom
= max( GetDlgItemInt(hwnd
, IDE_HEIGHT
, NULL
, FALSE
), 100 );
308 if( DialogBoxParam(ghInstance
, MAKEINTRESOURCE(IDD_PLACEMENT
), hwnd
, wpPlacement
, (LPARAM
)&r
) )
310 SetDlgItemInt(hwnd
, IDE_LEFT
, r
.left
, TRUE
);
311 SetDlgItemInt(hwnd
, IDE_TOP
, r
.top
, TRUE
);
312 SetDlgItemInt(hwnd
, IDE_WIDTH
, r
.right
- r
.left
, TRUE
);
313 SetDlgItemInt(hwnd
, IDE_HEIGHT
, r
.bottom
- r
.top
, TRUE
);
314 setTabChanged(hwnd
, TRUE
);
319 Prompt_File_Name(0, hwnd
, NULL
, NULL
);
324 void fillFocusCB(HWND hwnd
, UINT uID
)
326 HWND hwCB
= GetDlgItem(hwnd
, uID
);
329 SendMessage(hwCB
, CB_RESETCONTENT
, 0,0);
330 cbAddString(hwCB
, "Directory listing", F_DIRLIST
);
331 cbAddString(hwCB
, "File name", F_FNAME
);
332 cbAddString(hwCB
, "File type", F_FTYPE
);
333 cbAddString(hwCB
, "Places bar", F_PLACES
);
334 cbAddString(hwCB
, "Look in", F_LOOKIN
);
338 void fillViewCB(HWND hwnd
, UINT uID
)
340 HWND hwCB
= GetDlgItem(hwnd
, uID
);
343 SendMessage(hwCB
, CB_RESETCONTENT
, 0,0);
344 cbAddString(hwCB
, "Large Icons", V_LGICONS
);
346 cbAddString(hwCB
, "Tiles", V_TILES
);
348 cbAddString(hwCB
, "Small Icons", V_SMICONS
);
349 cbAddString(hwCB
, "List", V_LIST
);
350 cbAddString(hwCB
, "Details", V_DETAILS
);
351 cbAddString(hwCB
, "Thumbnails", V_THUMBS
);
354 void selectCBView(HWND hwnd
, UINT uID
, int iView
)
356 HWND hwCB
= GetDlgItem(hwnd
, uID
);
359 int nItems
= SendMessage(hwCB
, CB_GETCOUNT
, 0,0);
360 for(int i
=0; i
< nItems
; i
++)
362 int ivItem
= (int)SendMessage(hwCB
, CB_GETITEMDATA
, i
, 0);
365 SendMessage(hwCB
, CB_SETCURSEL
, i
, 0);
371 static int initOSTab(HWND hwnd
)
373 CheckDlgButton(hwnd
, IDC_WSTARTUP
, isStartupApp(hwnd
));
374 CheckDlgButton(hwnd
, IDC_LOG
, BST_CHECKED
);
375 fillViewCB(hwnd
, IDCB_VIEW
);
376 fillFocusCB(hwnd
, IDCB_FOCUS
);
380 // bMinimize = gPowData->bStartMin;
382 SetDlgItemInt(hwnd
, IDE_LEFT
, gPowData
->ptOrg
.x
, TRUE
);
383 SetDlgItemInt(hwnd
, IDE_TOP
, gPowData
->ptOrg
.y
, TRUE
);
384 SetDlgItemInt(hwnd
, IDE_WIDTH
, gPowData
->szDim
.cx
, FALSE
);
385 SetDlgItemInt(hwnd
, IDE_HEIGHT
, gPowData
->szDim
.cy
, FALSE
);
387 selectCBView(hwnd
, IDCB_VIEW
, gPowData
->iView
);
388 SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_SETCURSEL
, gPowData
->iFocus
, 0);
390 /// released shared data
395 static BOOL CALLBACK
wpOSDlgs(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
406 ShowWindow(hwnd
, SW_SHOWNORMAL
);
407 EnableWindow(hwnd
, TRUE
);
413 /* case WM_SYSCOMMAND:
414 if( wp == SC_MINIMIZE )
416 EnableWindow(hwnd, FALSE);
417 ShowWindow(hwnd, SW_HIDE);
422 return DefWindowProc(hwnd, uMsg, wp, lp);
425 onOSTabCommand(hwnd
, wp
, lp
);
429 LPNMHDR pnh
= (LPNMHDR
)lp
;
430 if( pnh
->hwndFrom
== ghwPropSheet
)
435 SETDLGRESULT(hwnd
, FALSE
);
442 //Warn("Couldn't get access to shared memory!");
443 SETDLGRESULT(hwnd
, PSNRET_INVALID
);
447 int i
= GetDlgItemInt(hwnd
, IDE_LEFT
, &bOK
, TRUE
);
449 gPowData
->ptOrg
.x
= i
;
450 i
= GetDlgItemInt(hwnd
, IDE_TOP
, &bOK
, TRUE
);
452 gPowData
->ptOrg
.y
= i
;
453 i
= GetDlgItemInt(hwnd
, IDE_WIDTH
, &bOK
, TRUE
);
455 gPowData
->szDim
.cx
= i
;
456 i
= GetDlgItemInt(hwnd
, IDE_HEIGHT
, &bOK
, TRUE
);
458 gPowData
->szDim
.cy
= i
;
459 int idx
= SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_GETCURSEL
, 0, 0);
462 int f
= SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_GETITEMDATA
, idx
, 0);
463 if( f
>= 0 && f
< F_MAX
)
464 gPowData
->iFocus
= f
;
466 idx
= SendDlgItemMessage(hwnd
, IDCB_VIEW
, CB_GETCURSEL
, 0, 0);
469 int v
= SendDlgItemMessage(hwnd
, IDCB_VIEW
, CB_GETITEMDATA
, idx
, 0);
470 if( v
>= 0 && v
< V_MAX
)
474 savePrefsToRegistry();
477 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
490 static BOOL CALLBACK
wpApps(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
498 LPNMHDR pnh
= (LPNMHDR
)lp
;
499 if( pnh
->hwndFrom
== ghwPropSheet
)
504 SETDLGRESULT(hwnd
, FALSE
);
509 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
525 static void fillSheet(PROPSHEETPAGE
* psp
, int idDlg
, DLGPROC pfnDlgProc
)
527 memset(psp
, 0, sizeof(PROPSHEETPAGE
));
528 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
529 psp
->dwFlags
= PSP_DEFAULT
; // | PSP_USEICONID;
530 psp
->hInstance
= ghInstance
;
531 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
532 //psp->pszIcon = (LPSTR) MAKEINTRESOURCE(IDI_DOC);
533 psp
->pfnDlgProc
= pfnDlgProc
;
540 int CALLBACK WINAPI
initPropSheets(HWND hwnd
, UINT msg
, LPARAM lp
)
542 //dbg("initPropSheets: %p, %d", hwnd, msg);
543 if (msg
!= PSCB_INITIALIZED
)
546 PropSheet_SetCurSel(ghwPropSheet
, gIdxLastSheet
, gIdxLastSheet
);
551 HWND
showDlg(HWND hwParent
)
554 PROPSHEETPAGE pages
[4];
557 fillSheet(&pages
[k
++], IDD_OSDIALOGS
, wpOSDlgs
);
558 fillSheet(&pages
[k
++], IDD_EXCLUDES
, wpExcludes
);
559 // fillSheet(&pages[k++], IDD_APPS, wpApps);
560 fillSheet(&pages
[k
++], IDD_PREFS
, wpPrefs
);
562 memset(&psh
, 0, sizeof(PROPSHEETHEADER
));
563 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
564 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_USEHICON
| PSH_USECALLBACK
| PSH_MODELESS
; // |
569 psh
.hwndParent
= hwParent
;
570 psh
.hInstance
= ghInstance
;
571 psh
.hIcon
= ghIconSm
;
572 psh
.pszCaption
= (LPSTR
) "OpenWide Settings";
573 psh
.nPages
= k
; //sizeof(pages) / sizeof(PROPSHEETPAGE);
574 psh
.ppsp
= (LPCPROPSHEETPAGE
) pages
;
575 psh
.pfnCallback
= initPropSheets
;
578 return (HWND
)PropertySheet(&psh
);