Counter Strike : Global Offensive Source Code
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.

237 lines
5.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include <commctrl.h>
  9. #include "mxtk/mx.h"
  10. #include "resource.h"
  11. #include "CCLookup.h"
  12. #include "mdlviewer.h"
  13. #include "addsoundentry.h"
  14. #include <vgui/ILocalize.h>
  15. using namespace vgui;
  16. static CCloseCaptionLookupParams g_Params;
  17. static HFONT g_UnicodeFont = NULL;
  18. static void InsertTextColumn( HWND listcontrol, int column, int width, char const *label )
  19. {
  20. LVCOLUMN col;
  21. memset( &col, 0, sizeof( col ) );
  22. col.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_ORDER;
  23. col.iOrder = column;
  24. col.pszText = (char *)label;
  25. col.cchTextMax = 256;
  26. col.iSubItem = column;
  27. col.cx = width;
  28. ListView_InsertColumn( listcontrol, column, &col );
  29. }
  30. static void PopulateCloseCaptionTokenList( HWND wnd, CCloseCaptionLookupParams *params )
  31. {
  32. HWND control = GetDlgItem( wnd, IDC_CCTOKENLIST );
  33. if ( !control )
  34. return;
  35. InsertTextColumn( control, 0, 200, "CloseCaption Token" );
  36. InsertTextColumn( control, 1, 800, "Text" );
  37. ListView_DeleteAllItems( control );
  38. SendMessage( control, WM_SETFONT, (WPARAM)g_UnicodeFont, MAKELPARAM (TRUE, 0) );
  39. StringIndex_t i = g_pLocalize->GetFirstStringIndex();
  40. int saveSelected = -1;
  41. while ( INVALID_STRING_INDEX != i )
  42. {
  43. char const *name = g_pLocalize->GetNameByIndex( i );
  44. LV_ITEMW lvItem;
  45. memset( &lvItem, 0, sizeof( lvItem ) );
  46. lvItem.iItem = ListView_GetItemCount( control );
  47. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  48. lvItem.lParam = (LPARAM)i;
  49. wchar_t label[ 256 ];
  50. g_pLocalize->ConvertANSIToUnicode( name, label, sizeof( label ) );
  51. lvItem.pszText = label;
  52. lvItem.cchTextMax = 256;
  53. SendMessage( control, LVM_INSERTITEMW, 0, (LPARAM)(const LV_ITEMW FAR*)(&lvItem));
  54. lvItem.mask = LVIF_TEXT;
  55. lvItem.iSubItem = 1;
  56. wchar_t *value = g_pLocalize->GetValueByIndex( i );
  57. lvItem.pszText = (wchar_t *)value;
  58. lvItem.cchTextMax = 1024;
  59. SendMessage( control, LVM_SETITEMW, 0, (LPARAM)(const LV_ITEMW FAR*)(&lvItem));
  60. if ( !Q_stricmp( name, params->m_szCCToken ) )
  61. {
  62. ListView_SetItemState( control, lvItem.iItem, LVIS_SELECTED, LVIS_STATEIMAGEMASK );
  63. saveSelected = lvItem.iItem;
  64. }
  65. i = g_pLocalize->GetNextStringIndex( i );
  66. }
  67. if ( saveSelected != -1 )
  68. {
  69. ListView_EnsureVisible(control, saveSelected, FALSE );
  70. }
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose:
  74. // Input : hwndDlg -
  75. // uMsg -
  76. // wParam -
  77. // lParam -
  78. // Output : static BOOL CALLBACK
  79. //-----------------------------------------------------------------------------
  80. static BOOL CALLBACK CloseCaptionLookupDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  81. {
  82. switch(uMsg)
  83. {
  84. case WM_INITDIALOG:
  85. // Insert code here to put the string (to find and replace with)
  86. // into the edit controls.
  87. // ...
  88. {
  89. g_Params.PositionSelf( hwndDlg );
  90. HWND control = GetDlgItem( hwndDlg, IDC_CCTOKENLIST );
  91. DWORD exStyle = GetWindowLong( control, GWL_EXSTYLE );
  92. exStyle |= LVS_EX_FULLROWSELECT;
  93. SetWindowLong( control, GWL_EXSTYLE, exStyle );
  94. PopulateCloseCaptionTokenList( hwndDlg, &g_Params );
  95. SetWindowText( hwndDlg, g_Params.m_szDialogTitle );
  96. SetDlgItemText( hwndDlg, IDC_CCTOKEN, g_Params.m_szCCToken );
  97. SetFocus( GetDlgItem( hwndDlg, IDC_CCTOKENLIST ) );
  98. }
  99. return FALSE;
  100. case WM_COMMAND:
  101. switch (LOWORD(wParam))
  102. {
  103. case IDOK:
  104. {
  105. /*
  106. //int selindex = SendMessage( GetDlgItem( hwndDlg, IDC_CCTOKENLIST ), LB_GETCURSEL, 0, 0 );
  107. if ( selindex == LB_ERR )
  108. {
  109. mxMessageBox( NULL, "You must select an entry from the list", g_appTitle, MB_OK );
  110. return TRUE;
  111. }
  112. */
  113. SendMessage( GetDlgItem( hwndDlg, IDC_CCTOKEN ), WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szCCToken ), (LPARAM)g_Params.m_szCCToken );
  114. EndDialog( hwndDlg, 1 );
  115. }
  116. break;
  117. case IDCANCEL:
  118. EndDialog( hwndDlg, 0 );
  119. break;
  120. }
  121. return TRUE;
  122. case WM_NOTIFY:
  123. {
  124. if ( wParam == IDC_CCTOKENLIST )
  125. {
  126. NMHDR *hdr = ( NMHDR * )lParam;
  127. if ( hdr->code == LVN_ITEMCHANGED )
  128. {
  129. HWND control = GetDlgItem( hwndDlg, IDC_CCTOKENLIST );
  130. NM_LISTVIEW *nmlv = ( NM_LISTVIEW * )lParam;
  131. int item = nmlv->iItem;
  132. if ( item >= 0 )
  133. {
  134. // look up the lparam value
  135. LVITEM lvi;
  136. memset( &lvi, 0, sizeof( lvi ) );
  137. lvi.mask = LVIF_PARAM;
  138. lvi.iItem = item;
  139. if ( ListView_GetItem( control, &lvi ) )
  140. {
  141. char const *name = g_pLocalize->GetNameByIndex( lvi.lParam );
  142. if ( name )
  143. {
  144. Q_strncpy( g_Params.m_szCCToken, name, sizeof( g_Params.m_szCCToken ) );
  145. SendMessage( GetDlgItem( hwndDlg, IDC_CCTOKEN ), WM_SETTEXT, (WPARAM)sizeof( g_Params.m_szCCToken ), (LPARAM)g_Params.m_szCCToken );
  146. }
  147. }
  148. }
  149. return FALSE;
  150. }
  151. if ( hdr->code == NM_DBLCLK )
  152. {
  153. SendMessage( GetDlgItem( hwndDlg, IDC_CCTOKEN ), WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szCCToken ), (LPARAM)g_Params.m_szCCToken );
  154. EndDialog( hwndDlg, 1 );
  155. return FALSE;
  156. }
  157. }
  158. }
  159. return TRUE;
  160. }
  161. return FALSE;
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose:
  165. // Input : *view -
  166. // *actor -
  167. // Output : int
  168. //-----------------------------------------------------------------------------
  169. int CloseCaptionLookup( CCloseCaptionLookupParams *params )
  170. {
  171. g_Params = *params;
  172. g_UnicodeFont = CreateFont(
  173. -10,
  174. 0,
  175. 0,
  176. 0,
  177. FW_NORMAL,
  178. FALSE,
  179. FALSE,
  180. FALSE,
  181. ANSI_CHARSET,
  182. OUT_TT_PRECIS,
  183. CLIP_DEFAULT_PRECIS,
  184. ANTIALIASED_QUALITY,
  185. DEFAULT_PITCH,
  186. "Tahoma" );
  187. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  188. MAKEINTRESOURCE( IDD_CCLOOKUP ),
  189. (HWND)g_MDLViewer->getHandle(),
  190. (DLGPROC)CloseCaptionLookupDialogProc );
  191. DeleteObject( g_UnicodeFont );
  192. g_UnicodeFont = NULL;
  193. *params = g_Params;
  194. return retval;
  195. }