Team Fortress 2 Source Code as on 22/4/2020
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.

239 lines
5.9 KiB

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