Windows NT 4.0 source code leak
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.

576 lines
14 KiB

4 years ago
  1. #include "stdafx.h"
  2. #include "dialogs.h"
  3. #include "WordBase.h"
  4. #include "usermsgs.h"
  5. #include "ftsrch.h"
  6. #include "CSHelp.h"
  7. #define SIZESTRING 256 // max characters in string
  8. #ifndef COLOR_3DFACE // new to Chicago
  9. #define COLOR_3DFACE 15
  10. #define COLOR_3DSHADOW 16
  11. #define COLOR_GRAYTEXT 17
  12. #define COLOR_BTNTEXT 18
  13. #define COLOR_INACTIVECAPTIONTEXT 19
  14. #define COLOR_3DHILIGHT 20
  15. #define COLOR_3DDKSHADOW 21
  16. #define COLOR_3DLIGHT 22
  17. #define COLOR_MSGBOX 23
  18. #define COLOR_MSGBOXTEXT 24
  19. #endif
  20. // extern HINSTANCE hinstDLL;
  21. CWordBase::CWordBase()
  22. {
  23. m_fBoundToDialog = FALSE;
  24. m_ptv = NULL;
  25. m_ptl = NULL;
  26. m_pftl= NULL;
  27. m_hwnd= NULL;
  28. m_clrFace = 0;
  29. m_clrShad = 0;
  30. m_clrDShd = 0;
  31. m_clrHilt = 0;
  32. }
  33. CWordBase *CWordBase::NewWordBase(CTokenList * ptl, HINSTANCE hinst, HWND hwndParent)
  34. {
  35. CWordBase *pwb = NULL;
  36. __try
  37. {
  38. pwb= New CWordBase();
  39. pwb->Initial(ptl, hinst, hwndParent);
  40. }
  41. __finally
  42. {
  43. if (_abnormal_termination() && pwb)
  44. {
  45. delete pwb; pwb= NULL;
  46. }
  47. }
  48. return pwb;
  49. }
  50. void CWordBase::Initial(CTokenList * ptl, HINSTANCE hinst, HWND hwndParent)
  51. {
  52. m_ptv= CTextView::NewTextView();
  53. AttachRef(m_ptl , ptl );
  54. AttachRef(m_pftl, CMaskedTokenList::NewMaskedTokenList(m_ptl));
  55. m_clrFace = ::GetSysColor(COLOR_3DFACE);
  56. m_clrShad = ::GetSysColor(COLOR_3DSHADOW);
  57. m_clrDShd = ::GetSysColor(COLOR_3DDKSHADOW);
  58. m_clrHilt = ::GetSysColor(COLOR_3DHILIGHT);
  59. CreateDialogParam(hinst, MAKEINTRESOURCE(IDD_WORDBASE), hwndParent, (DLGPROC) (CWordBase::DlgProc), LPARAM(this));
  60. }
  61. void CWordBase::SetSubstringFilter(CIndicatorSet *pis)
  62. {
  63. m_pftl->SetSubstringFilter(pis);
  64. }
  65. void CWordBase::SetSubstringFilter(PWCHAR lpsubstring, BOOL fStarting, //rmk
  66. BOOL fEnding,
  67. CIndicatorSet *pisFilter
  68. )
  69. {
  70. if (*lpsubstring)
  71. m_pftl->SetSubstringFilter(m_ptl->TokensContaining(lpsubstring, fStarting, fEnding, pisFilter));
  72. else m_pftl->SetSubstringFilter(NULL);
  73. }
  74. CWordBase::~CWordBase()
  75. {
  76. if (m_ptv)
  77. {
  78. if (m_fBoundToDialog) m_ptv->Unsubclass();
  79. delete m_ptv;
  80. }
  81. m_lsbV.Detach();
  82. if (m_ptl ) DetachRef(m_ptl);
  83. if (m_pftl ) DetachRef(m_pftl);
  84. }
  85. BOOL CWordBase::OnInitDialog()
  86. {
  87. m_ptv->SubclassDlgItem(IDC_WORDBASE_LIST, m_hwnd);
  88. m_lsbV.Attach(GetDlgItem(m_hwnd, IDC_WORDLIST_SB));
  89. m_fBoundToDialog = TRUE;
  90. m_lsbV.Enabled();
  91. m_ptv->SetInterface(this);
  92. m_pftl->SetInterface(this);
  93. m_ptv->SetTextDatabase(m_pftl);
  94. AdjustScrollBars(TRUE);
  95. m_cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
  96. AlignWithTemplate();
  97. SetWindowText(m_hwnd,"WordBase");
  98. return(TRUE);
  99. }
  100. void CWordBase::AlignWithTemplate()
  101. {
  102. RECT rc;
  103. POINT point;
  104. HWND hwndParent = GetParent(m_hwnd);
  105. HWND hwndTemplate = GetDlgItem(hwndParent,IDC_WORDLIST_OD_LIST);
  106. GetWindowRect(hwndTemplate, &rc);
  107. point.x = rc.left;
  108. point.y = rc.top;
  109. ScreenToClient(hwndParent, &point);
  110. // The 4 is to account for the 3d lines which are drawn inside the control...
  111. UINT yHeight = ((rc.bottom - rc.top) - ((rc.bottom - rc.top) % m_ptv->CharHeight())) + m_ptv->TopGap() + 4;
  112. // UINT yHeight = ((rc.bottom - rc.top)) + m_ptv->TopGap() + 4;
  113. SetWindowPos(m_hwnd, hwndTemplate, point.x, point.y, rc.right - rc.left, yHeight,0);
  114. }
  115. void CWordBase::OnSize(UINT nType, int cx, int cy)
  116. {
  117. if (!m_fBoundToDialog) return;
  118. if (nType != SIZEFULLSCREEN && nType != SIZENORMAL) return;
  119. int yBase= 0;
  120. HDWP hdwp= BeginDeferWindowPos(2);
  121. hdwp= DeferWindowPos(hdwp, m_ptv->GetHWnd(), NULL,
  122. 2, yBase+2, (cx-m_cxVScroll) - 4,
  123. cy - 4,
  124. SWP_SHOWWINDOW | SWP_NOZORDER
  125. );
  126. if (!hdwp) return;
  127. hdwp= DeferWindowPos(hdwp, m_lsbV.GetHWnd(), NULL,
  128. (cx-m_cxVScroll) - 2, yBase+2, m_cxVScroll, cy-4,
  129. SWP_SHOWWINDOW | SWP_NOZORDER
  130. );
  131. if (!hdwp) return;
  132. EndDeferWindowPos(hdwp);
  133. m_ptv->DataEvent(CTextMatrix::FocusChange);
  134. AdjustScrollBars(FALSE);
  135. }
  136. void CWordBase::AdjustScrollBars(BOOL fForceTopLeft)
  137. {
  138. if (!m_pftl)
  139. {
  140. // m_lsbV.Disable();
  141. }
  142. else
  143. {
  144. int rowOrg, colOrg;
  145. if (fForceTopLeft)
  146. {
  147. rowOrg= colOrg= 0;
  148. }
  149. else
  150. {
  151. rowOrg= m_ptv->TopRow();
  152. colOrg= m_ptv->LeftColumn();
  153. }
  154. int cDataRows = m_pftl->RowCount();
  155. int cDataCols = m_pftl->ColCount();
  156. int cFullImageRows = m_ptv->FullRows();
  157. int cFullImageCols = m_ptv->FullColumns();
  158. if (rowOrg > cDataRows - cFullImageRows)
  159. {
  160. rowOrg = cDataRows - cFullImageRows;
  161. if (rowOrg < 0) rowOrg= 0;
  162. }
  163. if (colOrg > cDataCols - cFullImageCols)
  164. {
  165. colOrg = cDataCols - cFullImageCols;
  166. if (colOrg < 0) colOrg= 0;
  167. }
  168. if (cDataRows <= long(cFullImageRows)) m_lsbV.Disable();
  169. else
  170. {
  171. m_lsbV.SetPosition(rowOrg, FALSE);
  172. if (uOpSys != WIN40)
  173. m_lsbV.SetMaxValue(cDataRows-cFullImageRows,
  174. long(cFullImageRows), TRUE);
  175. else
  176. m_lsbV.SetMaxValue(cDataRows,
  177. long(cFullImageRows), TRUE);
  178. }
  179. m_ptv->MoveTo(rowOrg, colOrg);
  180. }
  181. }
  182. void CWordBase::OnVScroll(UINT nSBCode, UINT nPos, HWND hwndScrollBar)
  183. {
  184. long vPos= m_lsbV.ScrollAction(nSBCode, nPos);
  185. m_ptv->MoveToRow(vPos, TRUE, FALSE);
  186. }
  187. void CWordBase::RawDataEvent (CTextMatrix * ptm, UINT uEventType)
  188. {
  189. if (ptm != m_pftl) return;
  190. switch (uEventType)
  191. {
  192. case CTextMatrix::SelectionChange:
  193. SendMessage(GetParent(m_hwnd), WM_COMMAND, MAKEWPARAM(IDC_WORDLIST_OD_LIST, LBN_SELCHANGE), LPARAM(m_hwnd));
  194. break;
  195. case CTextMatrix::EndOfSelection:
  196. SendMessage(GetParent(m_hwnd), WM_COMMAND, MAKEWPARAM(IDC_WORDLIST_OD_LIST, LBN_DBLCLK), LPARAM(m_hwnd));
  197. break;
  198. case CTextMatrix::ShapeChange:
  199. AdjustScrollBars(TRUE);
  200. SendMessage(GetParent(m_hwnd), WM_COMMAND, MAKEWPARAM(IDC_WORDLIST_OD_LIST, LBN_SELCANCEL), LPARAM(m_hwnd));
  201. break;
  202. case CTextMatrix::DataDeath:
  203. break;
  204. }
  205. }
  206. void CWordBase::RawViewerEvent(CTextDisplay * ptd, UINT uEventType)
  207. {
  208. switch (uEventType)
  209. {
  210. case CTextDisplay::OriginChange:
  211. long row= m_ptv->TopRow ();
  212. long col= m_ptv->LeftColumn();
  213. if (m_lsbV.Enabled()) m_lsbV.SetPosition(row);
  214. break;
  215. }
  216. }
  217. //
  218. // catch arrow keys and simulate touching scroll bars
  219. //
  220. void
  221. CWordBase::OnKeyDown( UINT wChar, UINT /* nRepCnt */, UINT /* wFlags */)
  222. {
  223. switch( wChar )
  224. {
  225. case VK_HOME:
  226. OnVScroll(SB_TOP, 0L);
  227. break;
  228. case VK_END:
  229. OnVScroll(SB_BOTTOM, 0L);
  230. break;
  231. case VK_PRIOR:
  232. OnVScroll(SB_PAGEUP, 0L);
  233. break;
  234. case VK_NEXT:
  235. OnVScroll(SB_PAGEDOWN, 0L);
  236. break;
  237. case VK_UP:
  238. OnVScroll(SB_LINEUP, 0L);
  239. break;
  240. case VK_DOWN:
  241. OnVScroll(SB_LINEDOWN, 0L);
  242. break;
  243. case VK_RIGHT:
  244. break;
  245. case VK_LEFT:
  246. break;
  247. }
  248. }
  249. void CWordBase::OnWindowPosChanging(WINDOWPOS FAR* lpwpos)
  250. {
  251. // DefDlgProc(m_hwnd, WM_WINDOWPOSCHANGING, 0, LPARAM(lpwpos));
  252. if (lpwpos->flags & SWP_NOSIZE) return;
  253. UINT cy= lpwpos->cy;
  254. if (!cy) return;
  255. UINT cyFixed= m_ptv->TopGap();
  256. UINT cyChar= m_ptv->CharHeight();
  257. UINT cyVariable= cy - cyFixed;
  258. UINT cyResidue = cyVariable % cyChar;
  259. if (cyResidue < cyChar/2) lpwpos->cy-= cyResidue;
  260. else lpwpos->cy+= cyChar - cyResidue;
  261. }
  262. BOOL CWordBase::OnNcActivate(BOOL bActive)
  263. {
  264. if (bActive)
  265. if (GetKeyState(VK_SHIFT) < 0)
  266. m_pftl->OnKeyDown(m_ptv, VK_SHIFT, 1, 0);
  267. else
  268. m_pftl->OnKeyUp(m_ptv, VK_SHIFT, 1, 0);
  269. else
  270. if (GetKeyState(VK_SHIFT) < 0)
  271. m_pftl->OnKeyUp(m_ptv, VK_SHIFT, 1, 0);
  272. return TRUE;
  273. }
  274. BOOL CALLBACK CWordBase::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  275. {
  276. BOOL bStatus = TRUE; // Assume we will process the message
  277. CWordBase *pwb = (CWordBase *) GetWindowLong(hDlg,DWL_USER);
  278. switch (uMsg)
  279. {
  280. case WM_HELP:
  281. case WM_CONTEXTMENU:
  282. SendMessage(GetParent(hDlg), uMsg, wParam, lParam);
  283. break;
  284. case WM_INITDIALOG :
  285. // if focus is set to a control return FALSE
  286. // Otherwise return TRUE;
  287. SetWindowLong(hDlg, DWL_USER, lParam);
  288. pwb = (CWordBase *) lParam;
  289. pwb->m_hwnd = hDlg;
  290. pwb->OnInitDialog();
  291. bStatus = TRUE; // did not set the focus == TRUE
  292. break;
  293. case LB_GETCOUNT :
  294. {
  295. PSZ pszFormat = (PSZ) _alloca(128);
  296. wsprintf(pszFormat,"%ld",pwb->m_pftl->RowCount());
  297. SetWindowText(GetDlgItem(GetParent(hDlg),IDC_TEST_DATA_BOX),pszFormat);
  298. }
  299. break;
  300. case LB_GETITEMDATA :
  301. {
  302. // This code is in place to help automate the testing proceedure
  303. // it is not used by the project otherwise
  304. if (wParam < (WPARAM) pwb->m_pftl->RowCount())
  305. {
  306. int iSizeOfItem = pwb->m_ptl->GetWTokenI(pwb->m_pftl->MapToActualRow(wParam),NULL,0) + 1;
  307. PWCHAR pszwToken = (PWCHAR) _alloca(iSizeOfItem * sizeof(WCHAR));
  308. LPSTR pszToken = (LPSTR) _alloca(iSizeOfItem * sizeof(CHAR));
  309. ASSERT(pszToken);
  310. ASSERT(iSizeOfItem);
  311. pwb->m_ptl->GetWTokenI(pwb->m_pftl->MapToActualRow(wParam),(PWCHAR) pszwToken, iSizeOfItem);
  312. CP cp = GetCPFromCharset(pwb->m_ptl->GetCharSetI(pwb->m_pftl->MapToActualRow(wParam)));
  313. WideCharToMultiByte(cp, 0,pszwToken, iSizeOfItem * sizeof(WCHAR), pszToken, iSizeOfItem, NULL, NULL); //rmk
  314. SetWindowText(GetDlgItem(GetParent(hDlg),IDC_TEST_DATA_BOX),pszToken);
  315. }
  316. else
  317. {
  318. SetWindowText(GetDlgItem(GetParent(hDlg),IDC_TEST_DATA_BOX),"LB_ERR : Attempt to access past end of data");
  319. }
  320. }
  321. break;
  322. case WM_SETFOCUS:
  323. ::SetFocus(pwb->m_ptv->GetHWnd()); // Really give the focus to the control...
  324. break;
  325. case WM_VSCROLL:
  326. pwb->OnVScroll((int) LOWORD(wParam), (short) HIWORD(wParam), HWND(lParam));
  327. break;
  328. case WM_KEYDOWN:
  329. pwb->OnKeyDown(wParam, LOWORD(lParam), HIWORD(lParam));
  330. break;
  331. case WM_KEYUP:
  332. pwb->OnKeyUp(wParam, LOWORD(lParam), HIWORD(lParam));
  333. break;
  334. case WM_CHAR:
  335. pwb->OnChar(wParam, LOWORD(lParam), HIWORD(lParam));
  336. break;
  337. case WM_SIZE:
  338. pwb->OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
  339. break;
  340. case WM_MOUSEACTIVATE:
  341. return MA_ACTIVATEANDEAT;
  342. case WM_PAINT:
  343. {
  344. PAINTSTRUCT ps;
  345. HDC hDC = BeginPaint(hDlg,&ps);
  346. if (hDC)
  347. {
  348. RECT rect;
  349. HBRUSH hbrushSave;
  350. HBRUSH hbrFace;
  351. HBRUSH hbrShad;
  352. HBRUSH hbrDShd;
  353. HBRUSH hbrHilt;
  354. HBRUSH hbrBG = (HBRUSH) ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
  355. COLORREF clrFace = ::GetSysColor(COLOR_3DFACE);
  356. COLORREF clrShad = ::GetSysColor(COLOR_3DSHADOW);
  357. COLORREF clrDShd = ::GetSysColor(COLOR_3DDKSHADOW);
  358. COLORREF clrHilt = ::GetSysColor(COLOR_3DHILIGHT);
  359. hbrFace = (HBRUSH) ::CreateSolidBrush(clrFace);
  360. hbrShad = (HBRUSH) ::CreateSolidBrush(clrShad);
  361. hbrDShd = (HBRUSH) ::CreateSolidBrush(clrDShd);
  362. hbrHilt = (HBRUSH) ::CreateSolidBrush(clrHilt);
  363. if (clrFace != pwb->m_clrFace || clrShad != pwb->m_clrShad || clrDShd != pwb->m_clrDShd || clrHilt != pwb->m_clrHilt)
  364. {
  365. // Ctl3dColorChange();
  366. // InvalidateRect(GetParent(hDlg), NULL, TRUE);
  367. pwb->m_clrFace = clrFace;
  368. pwb->m_clrShad = clrShad;
  369. pwb->m_clrDShd = clrDShd;
  370. pwb->m_clrHilt = clrHilt;
  371. }
  372. ::GetClientRect(hDlg, &rect );
  373. hbrushSave= (HBRUSH) ::SelectObject(hDC, hbrBG);
  374. // Background
  375. ::PatBlt(hDC, rect.left, rect.top, (rect.right - rect.left),
  376. (rect.bottom - rect.top), PATCOPY);
  377. ::SelectObject(hDC, hbrShad);
  378. ::PatBlt(hDC, rect.left, rect.top, (rect.right - rect.left), 1, PATCOPY);
  379. ::PatBlt(hDC, rect.left, rect.top, 1, (rect.bottom - rect.top), PATCOPY);
  380. ::SelectObject(hDC, hbrDShd);
  381. ::PatBlt(hDC, rect.left + 1, rect.top + 1, (rect.right - rect.left), 1, PATCOPY);
  382. ::PatBlt(hDC, rect.left + 1, rect.top + 1, 1, (rect.bottom - rect.top), PATCOPY);
  383. ::SelectObject(hDC, hbrFace);
  384. ::PatBlt(hDC, rect.left + 1, rect.bottom - 2, (rect.right - rect.left), 1, PATCOPY);
  385. ::PatBlt(hDC, rect.right - 2, rect.top + 1, 1,(rect.bottom - rect.top), PATCOPY);
  386. ::SelectObject(hDC, hbrHilt);
  387. ::PatBlt(hDC, rect.left, rect.bottom - 1, (rect.right - rect.left), 1, PATCOPY);
  388. ::PatBlt(hDC, rect.right - 1, rect.top, 1, (rect.bottom - rect.top), PATCOPY);
  389. ::SelectObject(hDC, hbrushSave);
  390. DeleteObject(hbrBG);
  391. DeleteObject(hbrFace);
  392. DeleteObject(hbrShad);
  393. DeleteObject(hbrDShd);
  394. DeleteObject(hbrHilt);
  395. }
  396. EndPaint(hDlg,&ps);
  397. }
  398. break;
  399. case WM_WINDOWPOSCHANGING:
  400. // pwb->OnWindowPosChanging((WINDOWPOS *) lParam);
  401. bStatus= FALSE;
  402. break;
  403. case WM_NCACTIVATE:
  404. return pwb->OnNcActivate(wParam);
  405. default:
  406. bStatus = FALSE;
  407. break;
  408. }
  409. // Note do not call DefWindowProc to process unwanted window messages!
  410. return bStatus;
  411. }
  412. // #endif