Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

340 lines
8.6 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. //
  5. // SIFPROP.CPP - Handles the "SIF Properties" IDC_SIF_PROP_IMAGES
  6. // and IDD_SIF_PROP_TOOLS dialogs
  7. //
  8. #include "pch.h"
  9. #include "sifprop.h"
  10. #include "utils.h"
  11. #include "shellapi.h"
  12. DEFINE_MODULE("IMADMUI")
  13. DEFINE_THISCLASS("CSifProperties")
  14. #define THISCLASS CSifProperties
  15. #define LPTHISCLASS CSifProperties*
  16. #define NUM_COLUMNS 3
  17. DWORD aSifHelpMap[] = {
  18. IDC_E_DESCRIPTION, HIDC_E_DESCRIPTION,
  19. IDC_E_HELP, HIDC_E_HELP,
  20. IDC_S_VERSION, HIDC_S_VERSION,
  21. IDC_S_LANGUAGE, HIDC_S_LANGUAGE,
  22. IDC_S_LASTMODIFIED, HIDC_S_LASTMODIFIED,
  23. IDC_S_IMAGETYPE, HIDC_S_IMAGETYPE,
  24. IDC_S_DIRECTORY, HIDC_S_DIRECTORY,
  25. IDC_G_IMAGEDETAILS, HIDC_G_IMAGEDETAILS,
  26. NULL, NULL
  27. };
  28. //
  29. // CreateInstance()
  30. //
  31. HRESULT
  32. CSifProperties_CreateInstance(
  33. HWND hParent,
  34. LPCTSTR lpszTemplate,
  35. LPSIFINFO pSIF )
  36. {
  37. TraceFunc( "CSifProperties_CreateInstance( )\n" );
  38. LPTHISCLASS lpcc = new THISCLASS( );
  39. HRESULT hr = lpcc->Init( hParent, lpszTemplate, pSIF );
  40. delete lpcc;
  41. HRETURN(hr);
  42. }
  43. //
  44. // Constructor
  45. //
  46. THISCLASS::THISCLASS( )
  47. {
  48. TraceClsFunc( "CSifProperties()\n" );
  49. InterlockIncrement( g_cObjects );
  50. TraceFuncExit();
  51. }
  52. //
  53. // Init()
  54. //
  55. STDMETHODIMP
  56. THISCLASS::Init(
  57. HWND hParent,
  58. LPCTSTR lpszTemplate,
  59. LPSIFINFO pSIF )
  60. {
  61. HRESULT hr;
  62. TraceClsFunc( "Init( ... )\n" );
  63. Assert( pSIF );
  64. _pSIF = pSIF;
  65. INT i = (INT)DialogBoxParam( g_hInstance, lpszTemplate, hParent, PropSheetDlgProc, (LPARAM) this );
  66. switch( i )
  67. {
  68. case IDOK:
  69. hr = S_OK;
  70. break;
  71. case IDCANCEL:
  72. hr = S_FALSE;
  73. break;
  74. #ifdef DEBUG
  75. default:
  76. hr = THR(E_FAIL);
  77. break;
  78. #endif // DEBUG
  79. }
  80. HRETURN(hr);
  81. }
  82. //
  83. // Destructor
  84. //
  85. THISCLASS::~THISCLASS( )
  86. {
  87. TraceClsFunc( "~CSifProperties()\n" );
  88. InterlockDecrement( g_cObjects );
  89. TraceFuncExit();
  90. };
  91. // ************************************************************************
  92. //
  93. // Property Sheet Functions
  94. //
  95. // ************************************************************************
  96. //
  97. // _InitDialog( )
  98. //
  99. HRESULT
  100. THISCLASS::_InitDialog(
  101. HWND hDlg )
  102. {
  103. TraceClsFunc( "_InitDialog( )\n" );
  104. HRESULT hr = S_OK;
  105. TCHAR szTempBuffer[ 256 ];
  106. TCHAR szTmp[ 128 ];
  107. TCHAR szTmp2[ 128 ];
  108. FILETIME ftLocal;
  109. SYSTEMTIME stSystem;
  110. _hDlg = hDlg;
  111. Assert( _pSIF );
  112. SetDlgItemText( hDlg, IDC_E_DESCRIPTION, _pSIF->pszDescription);
  113. SetDlgItemText( hDlg, IDC_E_HELP, _pSIF->pszHelpText);
  114. SetDlgItemText( hDlg, IDC_S_IMAGETYPE, _pSIF->pszImageType);
  115. SetDlgItemText( hDlg, IDC_S_LANGUAGE, _pSIF->pszLanguage);
  116. SetDlgItemText( hDlg, IDC_S_VERSION, _pSIF->pszVersion);
  117. SetDlgItemText( hDlg, IDC_S_DIRECTORY, _pSIF->pszDirectory );
  118. FileTimeToLocalFileTime( &_pSIF->ftLastWrite, &ftLocal);
  119. FileTimeToSystemTime( &ftLocal, &stSystem);
  120. GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stSystem, NULL, szTmp, ARRAYSIZE(szTmp));
  121. GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stSystem, NULL, szTmp2, ARRAYSIZE(szTmp2));
  122. wsprintf(szTempBuffer, L"%s, %s", szTmp, szTmp2);
  123. SetDlgItemText( hDlg, IDC_S_LASTMODIFIED, szTempBuffer );
  124. Edit_LimitText( GetDlgItem( hDlg, IDC_E_DESCRIPTION), REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT - 1 );
  125. Edit_LimitText( GetDlgItem( hDlg, IDC_E_HELP), REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT - 1 );
  126. HRETURN(hr);
  127. }
  128. //
  129. // _OnCommand( )
  130. //
  131. INT
  132. THISCLASS::_OnCommand( WPARAM wParam, LPARAM lParam )
  133. {
  134. TraceClsFunc( "_OnCommand( " );
  135. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  136. HRESULT hr = S_FALSE;
  137. HWND hwndCtl = (HWND) lParam;
  138. switch( LOWORD(wParam) )
  139. {
  140. case IDOK:
  141. if ( HIWORD( wParam ) == BN_CLICKED )
  142. {
  143. Assert( _pSIF );
  144. TCHAR szTempBuffer[ REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT + 2 ]; // +2 = the "Quotes"
  145. Assert( REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT <= REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT ); // paranoid
  146. szTempBuffer[0] = L'\"';
  147. GetDlgItemText( _hDlg, IDC_E_DESCRIPTION, &szTempBuffer[1], REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT );
  148. wcscat( szTempBuffer, L"\"" );
  149. if ( VerifySIFText( szTempBuffer ) )
  150. {
  151. if (!WritePrivateProfileString( OSCHOOSER_SIF_SECTION,
  152. OSCHOOSER_DESCRIPTION_ENTRY,
  153. szTempBuffer,
  154. _pSIF->pszFilePath)) {
  155. MessageBoxFromError( _hDlg, NULL, GetLastError());
  156. break;
  157. }
  158. }
  159. else
  160. {
  161. MessageBoxFromStrings( _hDlg, IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE, IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT, MB_OK );
  162. SetFocus( GetDlgItem( _hDlg, IDC_E_DESCRIPTION ) );
  163. break;
  164. }
  165. szTempBuffer[0] = L'\"';
  166. GetDlgItemText( _hDlg, IDC_E_HELP, &szTempBuffer[1], REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT );
  167. wcscat( szTempBuffer, L"\"" );
  168. if ( VerifySIFText( szTempBuffer ) )
  169. {
  170. if (!WritePrivateProfileString( OSCHOOSER_SIF_SECTION,
  171. OSCHOOSER_HELPTEXT_ENTRY,
  172. szTempBuffer,
  173. _pSIF->pszFilePath)) {
  174. MessageBoxFromError( _hDlg, NULL, GetLastError());
  175. }
  176. }
  177. else
  178. {
  179. MessageBoxFromStrings( _hDlg, IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE, IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT, MB_OK );
  180. SetFocus( GetDlgItem( _hDlg, IDC_E_HELP ) );
  181. break;
  182. }
  183. EndDialog( _hDlg, LOWORD( wParam ) );
  184. }
  185. break;
  186. case IDCANCEL:
  187. if ( HIWORD( wParam ) == BN_CLICKED )
  188. {
  189. EndDialog( _hDlg, LOWORD( wParam ) );
  190. }
  191. break;
  192. case IDC_E_DESCRIPTION:
  193. case IDC_E_HELP:
  194. if ( HIWORD( wParam ) == EN_CHANGE ) {
  195. DWORD dwLen1 = Edit_GetTextLength( GetDlgItem( _hDlg, IDC_E_DESCRIPTION) );
  196. DWORD dwLen2 = Edit_GetTextLength( GetDlgItem( _hDlg, IDC_E_HELP) );
  197. EnableWindow( GetDlgItem( _hDlg, IDOK ), !( dwLen1==0 || dwLen2==0) );
  198. }
  199. break;
  200. case IDC_BUTTON1:
  201. if ( HIWORD(wParam) == BN_CLICKED )
  202. {
  203. SHELLEXECUTEINFO shexinfo = { 0 };
  204. Assert( _pSIF );
  205. shexinfo.cbSize = sizeof(shexinfo);
  206. shexinfo.fMask = SEE_MASK_INVOKEIDLIST;
  207. shexinfo.hwnd = hwndCtl;
  208. shexinfo.nShow = SW_SHOWNORMAL;
  209. shexinfo.lpFile = _pSIF->pszFilePath;
  210. shexinfo.lpVerb = TEXT("properties");
  211. ShellExecuteEx(&shexinfo);
  212. }
  213. break;
  214. }
  215. RETURN((SUCCEEDED(hr) ? TRUE : FALSE));
  216. }
  217. //
  218. // _OnNotify( )
  219. //
  220. INT
  221. THISCLASS::_OnNotify(
  222. WPARAM wParam,
  223. LPARAM lParam )
  224. {
  225. TraceClsFunc( "_OnNotify( " );
  226. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  227. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  228. #if 0
  229. switch( lpnmhdr->code )
  230. {
  231. }
  232. #endif
  233. RETURN(FALSE);
  234. }
  235. //
  236. // PropSheetDlgProc()
  237. //
  238. INT_PTR CALLBACK
  239. THISCLASS::PropSheetDlgProc(
  240. HWND hDlg,
  241. UINT uMsg,
  242. WPARAM wParam,
  243. LPARAM lParam )
  244. {
  245. // TraceFunc( "PropSheetDlgProc()\n" );
  246. // TraceMsg( TF_WM, "hDlg = 0x%08x, uMsg = 0x%08x, wParam = 0x%08x, lParam = 0x%08x\n",
  247. // hDlg, uMsg, wParam, lParam );
  248. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  249. if ( uMsg == WM_INITDIALOG )
  250. {
  251. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  252. Assert( lParam );
  253. SetWindowLongPtr( hDlg, GWLP_USERDATA, lParam );
  254. lpc = (LPTHISCLASS) lParam;
  255. lpc->_InitDialog( hDlg );
  256. return TRUE;
  257. }
  258. if ( lpc )
  259. {
  260. switch( uMsg )
  261. {
  262. case WM_NOTIFY:
  263. TraceMsg( TF_WM, "WM_NOTIFY\n" );
  264. return lpc->_OnNotify( wParam, lParam );
  265. case WM_COMMAND:
  266. TraceMsg( TF_WM, "WM_COMMAND\n" );
  267. return lpc->_OnCommand( wParam, lParam );
  268. case WM_HELP:// F1
  269. {
  270. LPHELPINFO phelp = (LPHELPINFO) lParam;
  271. WinHelp( (HWND) phelp->hItemHandle, g_cszHelpFile, HELP_WM_HELP, (DWORD_PTR) &aSifHelpMap );
  272. }
  273. break;
  274. case WM_CONTEXTMENU: // right mouse click
  275. WinHelp((HWND) wParam, g_cszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR) &aSifHelpMap );
  276. break;
  277. }
  278. }
  279. return FALSE;
  280. }