Leaked source code of windows server 2003
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.

321 lines
8.7 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. WCHAR szTempBuffer[ 256 ];
  106. WCHAR szTmp[ 128 ];
  107. WCHAR 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. Edit_LimitText( GetDlgItem( hDlg, IDC_E_DESCRIPTION), REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT - 1 );
  119. Edit_LimitText( GetDlgItem( hDlg, IDC_E_HELP), REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT - 1 );
  120. FileTimeToLocalFileTime( &_pSIF->ftLastWrite, &ftLocal);
  121. FileTimeToSystemTime( &ftLocal, &stSystem);
  122. if ( !GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stSystem, NULL, szTmp, ARRAYSIZE(szTmp)) ||
  123. !GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stSystem, NULL, szTmp2, ARRAYSIZE(szTmp2)) ||
  124. _snwprintf( szTempBuffer,
  125. ARRAYSIZE(szTempBuffer),
  126. L"%s, %s",
  127. szTmp, szTmp2) < 0 ) {
  128. hr = E_INVALIDARG;
  129. } else {
  130. SetDlgItemText( hDlg, IDC_S_LASTMODIFIED, szTempBuffer );
  131. }
  132. HRETURN(hr);
  133. }
  134. //
  135. // _OnCommand( )
  136. //
  137. INT
  138. THISCLASS::_OnCommand( WPARAM wParam, LPARAM lParam )
  139. {
  140. TraceClsFunc( "_OnCommand( " );
  141. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  142. HRESULT hr = S_FALSE;
  143. HWND hwndCtl = (HWND) lParam;
  144. switch( LOWORD(wParam) )
  145. {
  146. case IDOK:
  147. if ( HIWORD( wParam ) == BN_CLICKED )
  148. {
  149. Assert( _pSIF );
  150. WCHAR szTempBuffer[ REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT + 2 +1 ]; // +2 = the "Quotes" + NULL
  151. Assert( REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT <= REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT ); // paranoid
  152. szTempBuffer[0] = L'\"';
  153. GetDlgItemText( _hDlg, IDC_E_DESCRIPTION, &szTempBuffer[1], REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT );
  154. wcscat( szTempBuffer, L"\"" );
  155. if ( VerifySIFText( szTempBuffer ) )
  156. {
  157. if (!WritePrivateProfileString( OSCHOOSER_SIF_SECTION,
  158. OSCHOOSER_DESCRIPTION_ENTRY,
  159. szTempBuffer,
  160. _pSIF->pszFilePath)) {
  161. MessageBoxFromError( _hDlg, NULL, GetLastError());
  162. break;
  163. }
  164. }
  165. else
  166. {
  167. MessageBoxFromStrings( _hDlg, IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE, IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT, MB_OK );
  168. SetFocus( GetDlgItem( _hDlg, IDC_E_DESCRIPTION ) );
  169. break;
  170. }
  171. szTempBuffer[0] = L'\"';
  172. GetDlgItemText( _hDlg, IDC_E_HELP, &szTempBuffer[1], REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT );
  173. wcscat( szTempBuffer, L"\"" );
  174. if ( VerifySIFText( szTempBuffer ) )
  175. {
  176. if (!WritePrivateProfileString( OSCHOOSER_SIF_SECTION,
  177. OSCHOOSER_HELPTEXT_ENTRY,
  178. szTempBuffer,
  179. _pSIF->pszFilePath)) {
  180. MessageBoxFromError( _hDlg, NULL, GetLastError());
  181. }
  182. }
  183. else
  184. {
  185. MessageBoxFromStrings( _hDlg, IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE, IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT, MB_OK );
  186. SetFocus( GetDlgItem( _hDlg, IDC_E_HELP ) );
  187. break;
  188. }
  189. EndDialog( _hDlg, LOWORD( wParam ) );
  190. }
  191. break;
  192. case IDCANCEL:
  193. if ( HIWORD( wParam ) == BN_CLICKED )
  194. {
  195. EndDialog( _hDlg, LOWORD( wParam ) );
  196. }
  197. break;
  198. case IDC_E_DESCRIPTION:
  199. case IDC_E_HELP:
  200. if ( HIWORD( wParam ) == EN_CHANGE ) {
  201. DWORD dwLen1 = Edit_GetTextLength( GetDlgItem( _hDlg, IDC_E_DESCRIPTION) );
  202. DWORD dwLen2 = Edit_GetTextLength( GetDlgItem( _hDlg, IDC_E_HELP) );
  203. EnableWindow( GetDlgItem( _hDlg, IDOK ), !( dwLen1==0 || dwLen2==0) );
  204. }
  205. break;
  206. case IDC_BUTTON1:
  207. if ( HIWORD(wParam) == BN_CLICKED )
  208. {
  209. SHELLEXECUTEINFO shexinfo = { 0 };
  210. Assert( _pSIF );
  211. shexinfo.cbSize = sizeof(shexinfo);
  212. shexinfo.fMask = SEE_MASK_INVOKEIDLIST;
  213. shexinfo.hwnd = hwndCtl;
  214. shexinfo.nShow = SW_SHOWNORMAL;
  215. shexinfo.lpFile = _pSIF->pszFilePath;
  216. shexinfo.lpVerb = L"properties";
  217. ShellExecuteEx(&shexinfo);
  218. }
  219. break;
  220. }
  221. RETURN((SUCCEEDED(hr) ? TRUE : FALSE));
  222. }
  223. //
  224. // PropSheetDlgProc()
  225. //
  226. INT_PTR CALLBACK
  227. THISCLASS::PropSheetDlgProc(
  228. HWND hDlg,
  229. UINT uMsg,
  230. WPARAM wParam,
  231. LPARAM lParam )
  232. {
  233. // TraceFunc( "PropSheetDlgProc()\n" );
  234. // TraceMsg( TF_WM, "hDlg = 0x%08x, uMsg = 0x%08x, wParam = 0x%08x, lParam = 0x%08x\n",
  235. // hDlg, uMsg, wParam, lParam );
  236. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  237. if ( uMsg == WM_INITDIALOG )
  238. {
  239. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  240. Assert( lParam );
  241. SetWindowLongPtr( hDlg, GWLP_USERDATA, lParam );
  242. lpc = (LPTHISCLASS) lParam;
  243. lpc->_InitDialog( hDlg );
  244. return TRUE;
  245. }
  246. if ( lpc )
  247. {
  248. switch( uMsg )
  249. {
  250. case WM_COMMAND:
  251. TraceMsg( TF_WM, "WM_COMMAND\n" );
  252. return lpc->_OnCommand( wParam, lParam );
  253. case WM_HELP:// F1
  254. {
  255. LPHELPINFO phelp = (LPHELPINFO) lParam;
  256. WinHelp( (HWND) phelp->hItemHandle, g_cszHelpFile, HELP_WM_HELP, (DWORD_PTR) &aSifHelpMap );
  257. }
  258. break;
  259. case WM_CONTEXTMENU: // right mouse click
  260. WinHelp((HWND) wParam, g_cszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR) &aSifHelpMap );
  261. break;
  262. }
  263. }
  264. return FALSE;
  265. }