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.
25 #include "openwidedll.h"
26 #include "openwideres.h"
28 #include "owSharedUtil.h"
30 #include "openwide_proto.h"
33 #define SETDLGRESULT(hw, x) SetWindowLong((hw), DWL_MSGRESULT, (LONG)(x))
34 static int gIdxLastSheet
= 0;
37 static void setTabChanged(HWND hwnd
, BOOL bChanged
)
40 PropSheet_Changed(ghwPropSheet
, hwnd
);
42 PropSheet_UnChanged(ghwPropSheet
, hwnd
);
45 int savePrefsToRegistry(void)
47 HKEY hk
= regCreateKey(HKEY_CURRENT_USER
, OW_REGKEY_NAME
);
50 regWriteDWORD(hk
, NULL
, sizeof(OWSharedData
));
51 regWriteBinaryData(hk
, "OWData", (byte
*)gPowData
, sizeof(OWSharedData
));
60 int initPrefs(HWND hwnd
)
62 if(!initSharedMem(NULL
))
65 CheckDlgButton(hwnd
, IDC_WSTARTUP
, isStartupApp(hwnd
));
66 CheckDlgButton(hwnd
, IDC_LOG
, BST_CHECKED
);
71 CheckDlgButton(hwnd
, IDC_STARTMIN
, gPowData
->bStartMin
);
72 CheckDlgButton(hwnd
, IDC_SHOWICON
, gPowData
->bShowIcon
);
78 SendMessage(ghwMain, WM_SYSCOMMAND, SC_MINIMIZE, 0);
84 SetFocus(GetDlgItem(hwnd, IDB_SETPLACEMENT));
85 ShowWindow(hwnd, SW_SHOWNORMAL);
90 static void onPrefsTabCommand(HWND hwnd
, WPARAM wp
, LPARAM lp
)
97 setTabChanged(hwnd
, HIWORD(wp
)==BN_CLICKED
);
102 static BOOL CALLBACK
wpPrefs(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
110 onPrefsTabCommand(hwnd
, wp
, lp
);
114 LPNMHDR pnh
= (LPNMHDR
)lp
;
115 if( pnh
->hwndFrom
== ghwPropSheet
)
120 SETDLGRESULT(hwnd
, FALSE
);
127 //Warn("Couldn't get access to shared memory!");
128 SETDLGRESULT(hwnd
, PSNRET_INVALID
);
132 gPowData
->bStartMin
= (IsDlgButtonChecked(hwnd
, IDC_STARTMIN
) == BST_CHECKED
);
133 BOOL bShowIcon
= gPowData
->bShowIcon
= (IsDlgButtonChecked(hwnd
, IDC_SHOWICON
) == BST_CHECKED
);
134 BOOL bWinStart
= IsDlgButtonChecked(hwnd
, IDC_WSTARTUP
) == BST_CHECKED
;
136 savePrefsToRegistry();
140 setStartupApp(hwnd
, bWinStart
);
142 addTrayIcon(ghwMain
);
144 remTrayIcon(ghwMain
);
145 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
163 static int enumExcludes(HKEY hkRoot
, const char *szKey
, DWORD dwType
, LPVOID pParm
)
165 if( dwType
== REG_DWORD
)
166 SendMessage((HWND
)pParm
, LB_ADDSTRING
, 0, (LPARAM
)szKey
);
170 static int addExcludes2LB(HWND hwnd
, UINT uID
)
172 HWND hwLB
= GetDlgItem(hwnd
, uID
);
175 HKEY hk
= regOpenKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
178 regEnumValues(hk
, enumExcludes
, (LPVOID
)hwLB
);
185 static int initExcludes(HWND hwnd
)
187 return addExcludes2LB(hwnd
, IDL_EXCLUDES
);
190 static int addExclude(HWND hwnd
)
192 const char *szEx
= Prompt_File_Name(OPEN
, hwnd
, "Executable Files\0*.exe;*.com", "Choose program to exclude");
195 // PathStripPath((char *)szEx);
196 int idx
= SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_FINDSTRINGEXACT
, -1, (LPARAM
)szEx
);
198 Warn("This program is already excluded");
200 SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_ADDSTRING
, 0, (LPARAM
)szEx
);
205 static int rmvExclude(HWND hwnd
)
207 int idx
= SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_GETCURSEL
, 0,0);
209 SendDlgItemMessage(hwnd
, IDL_EXCLUDES
, LB_DELETESTRING
, idx
, 0);
213 static int saveExcludes2Registry(HWND hwnd
, UINT uID
)
215 HWND hwLB
= GetDlgItem(hwnd
, uID
);
218 // static char szKey[32];
219 regDeleteKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
220 HKEY hk
= regCreateKey(HKEY_CURRENT_USER
, OW_REGKEY_EXCLUDES_NAME
);
223 int num
= SendMessage(hwLB
, LB_GETCOUNT
,0,0);
226 for(int i
=0; i
< num
; i
++)
228 char *szEx
= lbGetItemText(hwLB
, i
);
231 regWriteDWORD(hk
, szEx
, 1);
242 static void onExTabCmd(HWND hwnd
, WPARAM wp
, LPARAM lp
)
255 static BOOL CALLBACK
wpExcludes(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
263 onExTabCmd(hwnd
, wp
, lp
);
267 LPNMHDR pnh
= (LPNMHDR
)lp
;
268 if( pnh
->hwndFrom
== ghwPropSheet
)
273 SETDLGRESULT(hwnd
, FALSE
);
278 saveExcludes2Registry(hwnd
, IDL_EXCLUDES
);
279 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
293 static void onOSTabCommand(HWND hwnd
, WPARAM wp
, LPARAM lp
)
299 if( HIWORD(wp
) == CBN_SELCHANGE
)
300 setTabChanged(hwnd
, TRUE
);
306 if( HIWORD(wp
) == EN_CHANGE
)
307 setTabChanged(hwnd
, TRUE
);
312 case IDB_SETPLACEMENT
:
315 r
.left
= GetDlgItemInt(hwnd
, IDE_LEFT
, NULL
, TRUE
);
316 r
.top
= GetDlgItemInt(hwnd
, IDE_TOP
, NULL
, TRUE
);
317 r
.right
= max( GetDlgItemInt(hwnd
, IDE_WIDTH
, NULL
, FALSE
), 100 );
318 r
.bottom
= max( GetDlgItemInt(hwnd
, IDE_HEIGHT
, NULL
, FALSE
), 100 );
320 if( DialogBoxParam(ghInstance
, MAKEINTRESOURCE(IDD_PLACEMENT
), hwnd
, wpPlacement
, (LPARAM
)&r
) )
322 SetDlgItemInt(hwnd
, IDE_LEFT
, r
.left
, TRUE
);
323 SetDlgItemInt(hwnd
, IDE_TOP
, r
.top
, TRUE
);
324 SetDlgItemInt(hwnd
, IDE_WIDTH
, r
.right
- r
.left
, TRUE
);
325 SetDlgItemInt(hwnd
, IDE_HEIGHT
, r
.bottom
- r
.top
, TRUE
);
326 setTabChanged(hwnd
, TRUE
);
331 Prompt_File_Name(0, hwnd
, NULL
, NULL
);
336 void fillFocusCB(HWND hwnd
, UINT uID
)
338 HWND hwCB
= GetDlgItem(hwnd
, uID
);
341 SendMessage(hwCB
, CB_RESETCONTENT
, 0,0);
342 cbAddString(hwCB
, "Directory listing", F_DIRLIST
);
343 cbAddString(hwCB
, "File name", F_FNAME
);
344 cbAddString(hwCB
, "File type", F_FTYPE
);
345 cbAddString(hwCB
, "Places bar", F_PLACES
);
346 cbAddString(hwCB
, "Look in", F_LOOKIN
);
350 void fillViewCB(HWND hwnd
, UINT uID
)
352 HWND hwCB
= GetDlgItem(hwnd
, uID
);
355 SendMessage(hwCB
, CB_RESETCONTENT
, 0,0);
356 cbAddString(hwCB
, "Large Icons", V_LGICONS
);
358 cbAddString(hwCB
, "Tiles", V_TILES
);
360 cbAddString(hwCB
, "Small Icons", V_SMICONS
);
361 cbAddString(hwCB
, "List", V_LIST
);
362 cbAddString(hwCB
, "Details", V_DETAILS
);
363 cbAddString(hwCB
, "Thumbnails", V_THUMBS
);
366 void selectCBView(HWND hwnd
, UINT uID
, int iView
)
368 HWND hwCB
= GetDlgItem(hwnd
, uID
);
371 int nItems
= SendMessage(hwCB
, CB_GETCOUNT
, 0,0);
372 for(int i
=0; i
< nItems
; i
++)
374 int ivItem
= (int)SendMessage(hwCB
, CB_GETITEMDATA
, i
, 0);
377 SendMessage(hwCB
, CB_SETCURSEL
, i
, 0);
383 static int initOSTab(HWND hwnd
)
385 CheckDlgButton(hwnd
, IDC_WSTARTUP
, isStartupApp(hwnd
));
386 CheckDlgButton(hwnd
, IDC_LOG
, BST_CHECKED
);
387 fillViewCB(hwnd
, IDCB_VIEW
);
388 fillFocusCB(hwnd
, IDCB_FOCUS
);
392 // bMinimize = gPowData->bStartMin;
394 SetDlgItemInt(hwnd
, IDE_LEFT
, gPowData
->ptOrg
.x
, TRUE
);
395 SetDlgItemInt(hwnd
, IDE_TOP
, gPowData
->ptOrg
.y
, TRUE
);
396 SetDlgItemInt(hwnd
, IDE_WIDTH
, gPowData
->szDim
.cx
, FALSE
);
397 SetDlgItemInt(hwnd
, IDE_HEIGHT
, gPowData
->szDim
.cy
, FALSE
);
399 selectCBView(hwnd
, IDCB_VIEW
, gPowData
->iView
);
400 SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_SETCURSEL
, gPowData
->iFocus
, 0);
402 /// released shared data
407 static BOOL CALLBACK
wpOSDlgs(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
418 ShowWindow(hwnd
, SW_SHOWNORMAL
);
419 EnableWindow(hwnd
, TRUE
);
425 /* case WM_SYSCOMMAND:
426 if( wp == SC_MINIMIZE )
428 EnableWindow(hwnd, FALSE);
429 ShowWindow(hwnd, SW_HIDE);
434 return DefWindowProc(hwnd, uMsg, wp, lp);
437 onOSTabCommand(hwnd
, wp
, lp
);
441 LPNMHDR pnh
= (LPNMHDR
)lp
;
442 if( pnh
->hwndFrom
== ghwPropSheet
)
447 SETDLGRESULT(hwnd
, FALSE
);
454 //Warn("Couldn't get access to shared memory!");
455 SETDLGRESULT(hwnd
, PSNRET_INVALID
);
459 int i
= GetDlgItemInt(hwnd
, IDE_LEFT
, &bOK
, TRUE
);
461 gPowData
->ptOrg
.x
= i
;
462 i
= GetDlgItemInt(hwnd
, IDE_TOP
, &bOK
, TRUE
);
464 gPowData
->ptOrg
.y
= i
;
465 i
= GetDlgItemInt(hwnd
, IDE_WIDTH
, &bOK
, TRUE
);
467 gPowData
->szDim
.cx
= i
;
468 i
= GetDlgItemInt(hwnd
, IDE_HEIGHT
, &bOK
, TRUE
);
470 gPowData
->szDim
.cy
= i
;
471 int idx
= SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_GETCURSEL
, 0, 0);
474 int f
= SendDlgItemMessage(hwnd
, IDCB_FOCUS
, CB_GETITEMDATA
, idx
, 0);
475 if( f
>= 0 && f
< F_MAX
)
476 gPowData
->iFocus
= f
;
478 idx
= SendDlgItemMessage(hwnd
, IDCB_VIEW
, CB_GETCURSEL
, 0, 0);
481 int v
= SendDlgItemMessage(hwnd
, IDCB_VIEW
, CB_GETITEMDATA
, idx
, 0);
482 if( v
>= 0 && v
< V_MAX
)
486 savePrefsToRegistry();
489 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
502 static BOOL CALLBACK
wpApps(HWND hwnd
, UINT uMsg
, WPARAM wp
, LPARAM lp
)
510 LPNMHDR pnh
= (LPNMHDR
)lp
;
511 if( pnh
->hwndFrom
== ghwPropSheet
)
516 SETDLGRESULT(hwnd
, FALSE
);
521 SETDLGRESULT(hwnd
, PSNRET_NOERROR
);
537 static void fillSheet(PROPSHEETPAGE
* psp
, int idDlg
, DLGPROC pfnDlgProc
)
539 memset(psp
, 0, sizeof(PROPSHEETPAGE
));
540 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
541 psp
->dwFlags
= PSP_DEFAULT
; // | PSP_USEICONID;
542 psp
->hInstance
= ghInstance
;
543 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
544 //psp->pszIcon = (LPSTR) MAKEINTRESOURCE(IDI_DOC);
545 psp
->pfnDlgProc
= pfnDlgProc
;
552 int CALLBACK WINAPI
initPropSheets(HWND hwnd
, UINT msg
, LPARAM lp
)
554 //dbg("initPropSheets: %p, %d", hwnd, msg);
555 if (msg
!= PSCB_INITIALIZED
)
558 PropSheet_SetCurSel(ghwPropSheet
, gIdxLastSheet
, gIdxLastSheet
);
563 HWND
showDlg(HWND hwParent
)
566 PROPSHEETPAGE pages
[4];
569 fillSheet(&pages
[k
++], IDD_OSDIALOGS
, wpOSDlgs
);
570 fillSheet(&pages
[k
++], IDD_EXCLUDES
, wpExcludes
);
571 // fillSheet(&pages[k++], IDD_APPS, wpApps);
572 fillSheet(&pages
[k
++], IDD_PREFS
, wpPrefs
);
574 memset(&psh
, 0, sizeof(PROPSHEETHEADER
));
575 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
576 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_USEHICON
| PSH_USECALLBACK
| PSH_MODELESS
; // |
581 psh
.hwndParent
= hwParent
;
582 psh
.hInstance
= ghInstance
;
583 psh
.hIcon
= ghIconSm
;
584 psh
.pszCaption
= (LPSTR
) "OpenWide Settings";
585 psh
.nPages
= k
; //sizeof(pages) / sizeof(PROPSHEETPAGE);
586 psh
.ppsp
= (LPCPROPSHEETPAGE
) pages
;
587 psh
.pfnCallback
= initPropSheets
;
590 return (HWND
)PropertySheet(&psh
);