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.
31 #include "openwidedll.h"
32 #include "openwideres.h"
34 #include "owSharedUtil.h"
36 #include "openwide_proto.h"
39 #define SETDLGRESULT(hw, x) SetWindowLong((hw), DWL_MSGRESULT, (LONG)(x))
40 static int gIdxLastSheet
= 0;
43 static void setTabChanged(HWND hwnd
, BOOL bChanged
)
46 PropSheet_Changed(ghwPropSheet
, hwnd
);
48 PropSheet_UnChanged(ghwPropSheet
, hwnd
);
51 int savePrefsToRegistry(void)
53 HKEY hk
= regCreateKey(HKEY_CURRENT_USER
, OW_REGKEY_NAME
);
56 regWriteDWORD(hk
, NULL
, sizeof(OWSharedData
));
57 regWriteBinaryData(hk
, "OWData", (byte
*)gPowData
, sizeof(OWSharedData
));
66 int initPrefs(HWND hwnd
)
68 if(!initSharedMem(NULL
))
71 CheckDlgButton(hwnd
, IDC_WSTARTUP
, isStartupApp(hwnd
));
72 CheckDlgButton(hwnd
, IDC_LOG
, BST_CHECKED
);
77 CheckDlgButton(hwnd
, IDC_STARTMIN
, gPowData
->bStartMin
);
78 CheckDlgButton(hwnd
, IDC_SHOWICON
, gPowData
->bShowIcon
);
84 SendMessage(ghwMain, WM_SYSCOMMAND, SC_MINIMIZE, 0);
90 SetFocus(GetDlgItem(hwnd, IDB_SETPLACEMENT));
91 ShowWindow(hwnd, SW_SHOWNORMAL);
96 static void onPrefsTabCommand(HWND hwnd
, WPARAM wp
, LPARAM lp
)
103 setTabChanged(hwnd
, HIWORD(wp
)==BN_CLICKED
);
108 static BOOL CALLBACK
wpPrefs(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
116 onPrefsTabCommand(hwnd
, wp
, lp
);
120 LPNMHDR pnh
= (LPNMHDR
)lp
;
121 if( pnh
->hwndFrom
== ghwPropSheet
)
126 SETDLGRESULT(hwnd
, FALSE
);
133 //Warn("Couldn't get access to shared memory!");
134 SETDLGRESULT(hwnd
, PSNRET_INVALID
);
138 gPowData
->bStartMin
= (IsDlgButtonChecked(hwnd
, IDC_STARTMIN
) == BST_CHECKED
);
139 BOOL bShowIcon
= gPowData
->bShowIcon
= (IsDlgButtonChecked(hwnd
, IDC_SHOWICON
) == BST_CHECKED
);
140 BOOL bWinStart
= IsDlgButtonChecked(hwnd
, IDC_WSTARTUP
) == BST_CHECKED
;
142 savePrefsToRegistry();
146 setStartupApp(hwnd
, bWinStart
);
148 addTrayIcon(ghwMain
);
150 remTrayIcon(ghwMain
);
151 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
169 static int enumExcludes(HKEY hkRoot
, const char *szKey
, DWORD dwType
, LPVOID pParm
)
171 if( dwType
== REG_DWORD
)
172 SendMessage((HWND
)pParm
, LB_ADDSTRING
, 0, (LPARAM
)szKey
);
176 static int addExcludes2LB(HWND hwnd
, UINT uID
)
178 HWND hwLB
= GetDlgItem(hwnd
, uID
);
181 HKEY hk
= regOpenKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
184 regEnumValues(hk
, enumExcludes
, (LPVOID
)hwLB
);
191 static int initExcludes(HWND hwnd
)
193 return addExcludes2LB(hwnd
, IDL_EXCLUDES
);
196 static int addExclude(HWND hwnd
)
198 const char *szEx
= Prompt_File_Name(OPEN
, hwnd
, "Executable Files\0*.exe;*.com", "Choose program to exclude");
201 // PathStripPath((char *)szEx);
202 int idx
= SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_FINDSTRINGEXACT
, -1, (LPARAM
)szEx
);
204 Warn("This program is already excluded");
206 SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_ADDSTRING
, 0, (LPARAM
)szEx
);
211 static int rmvExclude(HWND hwnd
)
213 int idx
= SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_GETCURSEL
, 0,0);
215 SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_DELETESTRING
, idx
, 0);
219 static int saveExcludes2Registry(HWND hwnd
, UINT uID
)
221 HWND hwLB
= GetDlgItem(hwnd
, uID
);
224 // static char szKey[32];
225 regDeleteKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
226 HKEY hk
= regCreateKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
229 int num
= SendMessage(hwLB
, LB_GETCOUNT
,0,0);
232 for(int i
=0; i
< num
; i
++)
234 char *szEx
= lbGetItemText(hwLB
, i
);
237 regWriteDWORD(hk
, szEx
, 1);
248 static void onExTabCmd(HWND hwnd
, WPARAM wp
, LPARAM lp
)
261 static BOOL CALLBACK
wpExcludes(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
269 onExTabCmd(hwnd
, wp
, lp
);
273 LPNMHDR pnh
= (LPNMHDR
)lp
;
274 if( pnh
->hwndFrom
== ghwPropSheet
)
279 SETDLGRESULT(hwnd
, FALSE
);
284 saveExcludes2Registry(hwnd
, IDL_EXCLUDES
);
285 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
299 static void onOSTabCommand(HWND hwnd
, WPARAM wp
, LPARAM lp
)
305 if( HIWORD(wp
) == CBN_SELCHANGE
)
306 setTabChanged(hwnd
, TRUE
);
312 if( HIWORD(wp
) == EN_CHANGE
)
313 setTabChanged(hwnd
, TRUE
);
318 case IDB_SETPLACEMENT
:
321 r
.left
= GetDlgItemInt(hwnd
, IDE_LEFT
, NULL
, TRUE
);
322 r
.top
= GetDlgItemInt(hwnd
, IDE_TOP
, NULL
, TRUE
);
323 r
.right
= max( GetDlgItemInt(hwnd
, IDE_WIDTH
, NULL
, FALSE
), 100 );
324 r
.bottom
= max( GetDlgItemInt(hwnd
, IDE_HEIGHT
, NULL
, FALSE
), 100 );
326 if( DialogBoxParam(ghInstance
, MAKEINTRESOURCE(IDD_PLACEMENT
), hwnd
, wpPlacement
, (LPARAM
)&r
) )
328 SetDlgItemInt(hwnd
, IDE_LEFT
, r
.left
, TRUE
);
329 SetDlgItemInt(hwnd
, IDE_TOP
, r
.top
, TRUE
);
330 SetDlgItemInt(hwnd
, IDE_WIDTH
, r
.right
- r
.left
, TRUE
);
331 SetDlgItemInt(hwnd
, IDE_HEIGHT
, r
.bottom
- r
.top
, TRUE
);
332 setTabChanged(hwnd
, TRUE
);
337 Prompt_File_Name(0, hwnd
, NULL
, NULL
);
342 void fillFocusCB(HWND hwnd
, UINT uID
)
344 HWND hwCB
= GetDlgItem(hwnd
, uID
);
347 SendMessage(hwCB
, CB_RESETCONTENT
, 0,0);
348 cbAddString(hwCB
, "Directory listing", F_DIRLIST
);
349 cbAddString(hwCB
, "File name", F_FNAME
);
350 cbAddString(hwCB
, "File type", F_FTYPE
);
351 cbAddString(hwCB
, "Places bar", F_PLACES
);
352 cbAddString(hwCB
, "Look in", F_LOOKIN
);
356 void fillViewCB(HWND hwnd
, UINT uID
)
358 HWND hwCB
= GetDlgItem(hwnd
, uID
);
361 SendMessage(hwCB
, CB_RESETCONTENT
, 0,0);
362 cbAddString(hwCB
, "Large Icons", V_LGICONS
);
364 cbAddString(hwCB
, "Tiles", V_TILES
);
366 cbAddString(hwCB
, "Small Icons", V_SMICONS
);
367 cbAddString(hwCB
, "List", V_LIST
);
368 cbAddString(hwCB
, "Details", V_DETAILS
);
369 cbAddString(hwCB
, "Thumbnails", V_THUMBS
);
372 void selectCBView(HWND hwnd
, UINT uID
, int iView
)
374 HWND hwCB
= GetDlgItem(hwnd
, uID
);
377 int nItems
= SendMessage(hwCB
, CB_GETCOUNT
, 0,0);
378 for(int i
=0; i
< nItems
; i
++)
380 int ivItem
= (int)SendMessage(hwCB
, CB_GETITEMDATA
, i
, 0);
383 SendMessage(hwCB
, CB_SETCURSEL
, i
, 0);
389 static int initOSTab(HWND hwnd
)
391 CheckDlgButton(hwnd
, IDC_WSTARTUP
, isStartupApp(hwnd
));
392 CheckDlgButton(hwnd
, IDC_LOG
, BST_CHECKED
);
393 fillViewCB(hwnd
, IDCB_VIEW
);
394 fillFocusCB(hwnd
, IDCB_FOCUS
);
398 // bMinimize = gPowData->bStartMin;
400 SetDlgItemInt(hwnd
, IDE_LEFT
, gPowData
->ptOrg
.x
, TRUE
);
401 SetDlgItemInt(hwnd
, IDE_TOP
, gPowData
->ptOrg
.y
, TRUE
);
402 SetDlgItemInt(hwnd
, IDE_WIDTH
, gPowData
->szDim
.cx
, FALSE
);
403 SetDlgItemInt(hwnd
, IDE_HEIGHT
, gPowData
->szDim
.cy
, FALSE
);
405 selectCBView(hwnd
, IDCB_VIEW
, gPowData
->iView
);
406 SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_SETCURSEL
, gPowData
->iFocus
, 0);
408 /// released shared data
413 static BOOL CALLBACK
wpOSDlgs(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
424 ShowWindow(hwnd
, SW_SHOWNORMAL
);
425 EnableWindow(hwnd
, TRUE
);
431 /* case WM_SYSCOMMAND:
432 if( wp == SC_MINIMIZE )
434 EnableWindow(hwnd, FALSE);
435 ShowWindow(hwnd, SW_HIDE);
440 return DefWindowProc(hwnd, uMsg, wp, lp);
443 onOSTabCommand(hwnd
, wp
, lp
);
447 LPNMHDR pnh
= (LPNMHDR
)lp
;
448 if( pnh
->hwndFrom
== ghwPropSheet
)
453 SETDLGRESULT(hwnd
, FALSE
);
460 //Warn("Couldn't get access to shared memory!");
461 SETDLGRESULT(hwnd
, PSNRET_INVALID
);
465 int i
= GetDlgItemInt(hwnd
, IDE_LEFT
, &bOK
, TRUE
);
467 gPowData
->ptOrg
.x
= i
;
468 i
= GetDlgItemInt(hwnd
, IDE_TOP
, &bOK
, TRUE
);
470 gPowData
->ptOrg
.y
= i
;
471 i
= GetDlgItemInt(hwnd
, IDE_WIDTH
, &bOK
, TRUE
);
473 gPowData
->szDim
.cx
= i
;
474 i
= GetDlgItemInt(hwnd
, IDE_HEIGHT
, &bOK
, TRUE
);
476 gPowData
->szDim
.cy
= i
;
477 int idx
= SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_GETCURSEL
, 0, 0);
480 int f
= SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_GETITEMDATA
, idx
, 0);
481 if( f
>= 0 && f
< F_MAX
)
482 gPowData
->iFocus
= f
;
484 idx
= SendDlgItemMessage(hwnd
, IDCB_VIEW
, CB_GETCURSEL
, 0, 0);
487 int v
= SendDlgItemMessage(hwnd
, IDCB_VIEW
, CB_GETITEMDATA
, idx
, 0);
488 if( v
>= 0 && v
< V_MAX
)
492 savePrefsToRegistry();
495 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
508 static BOOL CALLBACK
wpApps(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
516 LPNMHDR pnh
= (LPNMHDR
)lp
;
517 if( pnh
->hwndFrom
== ghwPropSheet
)
522 SETDLGRESULT(hwnd
, FALSE
);
527 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
543 static void fillSheet(PROPSHEETPAGE
* psp
, int idDlg
, DLGPROC pfnDlgProc
)
545 memset(psp
, 0, sizeof(PROPSHEETPAGE
));
546 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
547 psp
->dwFlags
= PSP_DEFAULT
; // | PSP_USEICONID;
548 psp
->hInstance
= ghInstance
;
549 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
550 //psp->pszIcon = (LPSTR) MAKEINTRESOURCE(IDI_DOC);
551 psp
->pfnDlgProc
= pfnDlgProc
;
558 int CALLBACK WINAPI
initPropSheets(HWND hwnd
, UINT msg
, LPARAM lp
)
560 //dbg("initPropSheets: %p, %d", hwnd, msg);
561 if (msg
!= PSCB_INITIALIZED
)
564 PropSheet_SetCurSel(ghwPropSheet
, gIdxLastSheet
, gIdxLastSheet
);
569 HWND
showDlg(HWND hwParent
)
572 PROPSHEETPAGE pages
[4];
575 fillSheet(&pages
[k
++], IDD_OSDIALOGS
, wpOSDlgs
);
576 fillSheet(&pages
[k
++], IDD_EXCLUDES
, wpExcludes
);
577 // fillSheet(&pages[k++], IDD_APPS, wpApps);
578 fillSheet(&pages
[k
++], IDD_PREFS
, wpPrefs
);
580 memset(&psh
, 0, sizeof(PROPSHEETHEADER
));
581 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
582 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_USEHICON
| PSH_USECALLBACK
| PSH_MODELESS
; // |
587 psh
.hwndParent
= hwParent
;
588 psh
.hInstance
= ghInstance
;
589 psh
.hIcon
= ghIconSm
;
590 psh
.pszCaption
= (LPSTR
) "OpenWide Settings";
591 psh
.nPages
= k
; //sizeof(pages) / sizeof(PROPSHEETPAGE);
592 psh
.ppsp
= (LPCPROPSHEETPAGE
) pages
;
593 psh
.pfnCallback
= initPropSheets
;
596 return (HWND
)PropertySheet(&psh
);