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.

293 lines
12 KiB

  1. /**************************************************************************/
  2. /*** SCICALC Scientific Calculator for Windows 3.00.12 ***/
  3. /*** By Kraig Brockschmidt, Microsoft Co-op, Contractor, 1988-1989 ***/
  4. /*** (c)1989 Microsoft Corporation. All Rights Reserved. ***/
  5. /*** ***/
  6. /*** sciproc.c ***/
  7. /*** ***/
  8. /*** Functions contained: ***/
  9. /*** CalcWndProc--Main window procedure. ***/
  10. /*** ***/
  11. /*** Functions called: ***/
  12. /*** SetRadix, ***/
  13. /*** ProcessCommands. ***/
  14. /*** ***/
  15. /*** Last modification Fri 08-Dec-1989 ***/
  16. /*** -by- Amit Chatterjee. [amitc] ***/
  17. /*** Last modification July-21-1994 ***/
  18. /*** -by- Arthur Bierer [t-arthb] or [email protected] ***/
  19. /*** ***/
  20. /*** Modified WM_PAINT processing to display ghnoLastNum rather than ***/
  21. /*** ghnoNum if the last key hit was an operator. ***/
  22. /*** ***/
  23. /**************************************************************************/
  24. #include "scicalc.h"
  25. #include "calchelp.h"
  26. #include "commctrl.h"
  27. extern HWND hStatBox;
  28. extern HBRUSH hBrushBk;
  29. extern BOOL bFocus, bError;
  30. extern TCHAR szDec[5], *rgpsz[CSTRINGS];
  31. extern HNUMOBJ ghnoNum, ghnoLastNum;
  32. extern INT nTempCom ;
  33. extern INT gnPendingError ;
  34. extern BOOL gbRecord;
  35. WNDPROC fpOrgDispEditProc;
  36. LRESULT CALLBACK SubDispEditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  37. BOOL FireUpPopupMenu( HWND hwnd, HINSTANCE hInstanceWin, LPARAM lParam)
  38. {
  39. HMENU hmenu;
  40. if ((hmenu = LoadMenu(hInstanceWin, MAKEINTRESOURCE(IDM_HELPPOPUP))))
  41. {
  42. int cmd = TrackPopupMenuEx(GetSubMenu(hmenu, 0),
  43. TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_RIGHTBUTTON,
  44. LOWORD(lParam), HIWORD(lParam), hwnd, NULL);
  45. DestroyMenu(hmenu);
  46. return ( cmd == HELP_CONTEXTPOPUP ) ? TRUE : FALSE;
  47. }
  48. else
  49. return FALSE;
  50. }
  51. extern BOOL IsValidID( int iID );
  52. LRESULT APIENTRY CalcWndProc (
  53. HWND hWnd,
  54. UINT iMessage,
  55. WPARAM wParam,
  56. LPARAM lParam)
  57. {
  58. INT nID, nTemp; /* Return value from GetKey & temp. */
  59. HANDLE hTempBrush; // a brush to play with in WM_CTLCOLORSTATIC
  60. switch (iMessage)
  61. {
  62. case WM_INITMENUPOPUP:
  63. /* Gray out the PASTE option if CF_TEXT is not available. */
  64. /* nTemp is used here so we only call EnableMenuItem once. */
  65. if (!IsClipboardFormatAvailable(CF_TEXT))
  66. nTemp=MF_GRAYED | MF_DISABLED;
  67. else
  68. nTemp=MF_ENABLED;
  69. EnableMenuItem(GetMenu(hWnd),IDM_PASTE, nTemp);
  70. break;
  71. case WM_CONTEXTMENU:
  72. // If the user clicked on the dialog face and not one of the
  73. // buttons then do nothing. If the id of the button is IDC_STATIC
  74. // then do nothing.
  75. if ( (HWND)wParam == g_hwndDlg )
  76. {
  77. // check for clicks on disabled buttons. These aren't seen
  78. // by WindowFromPoint but are seen by ChildWindowFromPoint.
  79. // As a result, the value of wParam will be g_hwndDlg
  80. // if the WM_RBUTTONUP event occured on a disabled button.
  81. POINT pt;
  82. HWND hwnd;
  83. // convert from short values to long values
  84. pt.x = MAKEPOINTS(lParam).x;
  85. pt.y = MAKEPOINTS(lParam).y;
  86. // then convert to client coordinates
  87. ScreenToClient( g_hwndDlg, &pt );
  88. hwnd = ChildWindowFromPoint( g_hwndDlg, pt );
  89. if ( !hwnd || (hwnd == g_hwndDlg) ||
  90. (IDC_STATIC == GetDlgCtrlID( hwnd )))
  91. {
  92. return (DefWindowProc(hWnd, iMessage, wParam, lParam));
  93. }
  94. wParam = (WPARAM)hwnd;
  95. }
  96. if ( FireUpPopupMenu( g_hwndDlg, hInst, lParam ) )
  97. {
  98. nID = GetDlgCtrlID( (HWND)wParam );
  99. WinHelp((HWND) wParam, rgpsz[IDS_HELPFILE], HELP_CONTEXTPOPUP,
  100. GetHelpID( nID ));
  101. }
  102. break;
  103. case WM_HELP:
  104. HtmlHelp(GetDesktopWindow(), rgpsz[IDS_CHMHELPFILE], HH_DISPLAY_TOPIC, 0L);
  105. return 0;
  106. case WM_COMMAND: /* Interpret all buttons on calculator. */
  107. {
  108. WORD wNotifyCode = HIWORD(wParam); // notification code
  109. WORD wID = LOWORD(wParam); // item, control, or accelerator identifier
  110. // the accelerator table feeds us IDC_MOD in response to the
  111. // "%" key. This same accelerator is used for the percent function
  112. // in Standard view so translate here.
  113. if ( (wID == IDC_MOD) && (nCalc == 1) )
  114. wID = IDC_PERCENT;
  115. // when we get an accelerator keystroke we fake a button press to provide feedback
  116. if ( wNotifyCode == 1 )
  117. {
  118. // For an accelerator the hwnd is not passed in the lParam so ask the dialog
  119. HWND hwndCtl = GetDlgItem( g_hwndDlg, wID );
  120. SendMessage( hwndCtl, BM_SETSTATE, 1, 0 ); // push the button down
  121. Sleep( 20 ); // wait a bit
  122. SendMessage( hwndCtl, BM_SETSTATE, 0, 0 ); // push the button up
  123. }
  124. // we turn on notify for the text controls to automate the handling of context
  125. // help but we don't care about any commands we recieve from these controls. As
  126. // a result, only process commands that are not from a text control.
  127. if ( (wID != IDC_DISPLAY) && (wID != IDC_MEMTEXT) && (wID != IDC_PARTEXT) )
  128. ProcessCommands(wID);
  129. break;
  130. }
  131. case WM_CLOSE:
  132. if ( hStatBox )
  133. {
  134. SendMessage(hStatBox, WM_CLOSE, 0, 0L) ;
  135. hStatBox = NULL;
  136. }
  137. DestroyWindow(g_hwndDlg);
  138. KillTimeCalc();
  139. WinHelp(g_hwndDlg, rgpsz[IDS_HELPFILE], HELP_QUIT, 0L);
  140. PostQuitMessage(0);
  141. break;
  142. case WM_SYSCOMMAND:
  143. if ( (wParam & 0xFFF0) == SC_CLOSE )
  144. {
  145. PostQuitMessage(0);
  146. }
  147. return (DefWindowProc(hWnd, iMessage, wParam, lParam));
  148. case WM_NOTIFY:
  149. {
  150. NMCUSTOMDRAW* nm = (NMCUSTOMDRAW*)lParam;
  151. int iBtnID = (int)nm->hdr.idFrom;
  152. if (nm->hdr.code == NM_CUSTOMDRAW && IsValidID(iBtnID))
  153. {
  154. if (nm->dwDrawStage == CDDS_PREERASE)
  155. {
  156. return CDRF_NOTIFYITEMDRAW;
  157. }
  158. else if (nm->dwDrawStage == CDDS_PREPAINT)
  159. {
  160. int bkMode = SetBkMode(nm->hdc, TRANSPARENT);
  161. LPCTSTR psz = rgpsz[INDEXFROMID(iBtnID)];
  162. SetTextColor( nm->hdc, (nm->uItemState & CDIS_DISABLED)?GetSysColor(COLOR_GRAYTEXT):GetKeyColor( iBtnID ) );
  163. DrawText( nm->hdc, psz, -1, &nm->rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
  164. SetBkMode(nm->hdc, bkMode);
  165. return CDRF_SKIPDEFAULT;
  166. }
  167. }
  168. break;
  169. }
  170. case WM_CTLCOLORSTATIC:
  171. // get the Control's id from its handle in lParam
  172. if ( IDC_DISPLAY == GetWindowID( (HWND) lParam) )
  173. {
  174. // we set this window to a white backround
  175. hTempBrush = GetSysColorBrush( COLOR_WINDOW );
  176. SetBkColor( (HDC) wParam, GetSysColor( COLOR_WINDOW ) );
  177. SetTextColor( (HDC) wParam, GetSysColor( COLOR_WINDOWTEXT ) );
  178. return (LRESULT) hTempBrush;
  179. }
  180. return (DefWindowProc(hWnd, iMessage, wParam, lParam));
  181. case WM_SETTINGCHANGE:
  182. if (lParam!=0)
  183. {
  184. // we only care about changes to color and internation settings, ignore all others
  185. if (lstrcmp((LPCTSTR)lParam, TEXT("colors")) &&
  186. lstrcmp((LPCTSTR)lParam, TEXT("intl")))
  187. break;
  188. }
  189. // Always call if lParam==0. This is simply for safety and isn't strictly needed
  190. InitSciCalc (FALSE);
  191. break;
  192. case WM_SIZE:
  193. {
  194. HWND hwndSizer;
  195. nTemp=SW_SHOW;
  196. if (wParam==SIZEICONIC)
  197. nTemp=SW_HIDE;
  198. if (hStatBox!=0 && (wParam==SIZEICONIC || wParam==SIZENORMAL))
  199. ShowWindow(hStatBox, nTemp);
  200. // A special control has been added to both dialogs with an ID of
  201. // IDC_SIZERCONTROL. This control is possitioned such that the bottom of
  202. // the control determines the height of the dialog. If a really large menu
  203. // font is selected then the menu might wrap to two lines, which exposes a
  204. // bug in Windows that causes the client area to be too small. By checking
  205. // that IDC_SIZERCONTROL is fully visible we can compensate for this bug.
  206. hwndSizer = GetDlgItem( g_hwndDlg, IDC_SIZERCONTROL );
  207. if ( hwndSizer )
  208. {
  209. RECT rc;
  210. int iDelta;
  211. GetClientRect( hwndSizer, &rc );
  212. MapWindowPoints( hwndSizer, g_hwndDlg, (LPPOINT)&rc, 2 );
  213. // if the difference between the current height of the client area
  214. // (MAKEPOINTS(lParam).y) and the desired height of the client
  215. // area (rc.bottom) is non-zero then we must adjust the size of the
  216. // client area. This will enlarge the client area if you switch
  217. // from a regular menu font to a jumbo menu font and shrink the
  218. // client area if you switch from a jumbo menu font to a regular
  219. // menu font.
  220. iDelta = rc.bottom - HIWORD(lParam);
  221. if ( iDelta )
  222. {
  223. GetWindowRect( g_hwndDlg, &rc );
  224. SetWindowPos( g_hwndDlg, NULL,
  225. 0, 0, // these are ingored due to SWP_NOMOVE
  226. rc.right-rc.left, // the width remains the same
  227. rc.bottom-rc.top+iDelta, // the heigth changes by iDelta
  228. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
  229. return 0;
  230. }
  231. }
  232. }
  233. /* Fall through. */
  234. default:
  235. return (DefWindowProc(hWnd, iMessage, wParam, lParam));
  236. }
  237. return 0L;
  238. }
  239. LRESULT CALLBACK SubDispEditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  240. {
  241. // prevent right button to cut/del/paste... messes up the calculation
  242. if (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST)
  243. return 0;
  244. // FEATURE: You can still begin a selection by holding down shift and using the arrow keys. This should also be disabled.
  245. HideCaret(hWnd);
  246. return CallWindowProc(fpOrgDispEditProc, hWnd, uMsg, wParam, lParam);
  247. }