Source code of Windows XP (NT5)
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.

189 lines
5.6 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. /*** sciset.c ***/
  7. /*** ***/
  8. /*** Functions contained: ***/
  9. /*** SetRadix--Changes the number base and the radiobuttons. ***/
  10. /*** SetBox--Handles the checkboxes for inv/hyp. ***/
  11. /*** ***/
  12. /*** Functions called: ***/
  13. /*** none ***/
  14. /*** ***/
  15. /*** History:
  16. *** 12-Dec-1996 JonPa - Added SetMaxIntDigits
  17. *** Whenever-97 ToddB - Removed SetMaxIntDigits
  18. ***/
  19. /**************************************************************************/
  20. #include "scicalc.h"
  21. #include "unifunc.h"
  22. extern TCHAR szBlank[6];
  23. extern INT gcIntDigits;
  24. extern TCHAR *rgpsz[CSTRINGS];
  25. extern TCHAR szDec[];
  26. extern RECT rcDeg[6];
  27. extern HMENU g_hDecMenu;
  28. extern HMENU g_hHexMenu;
  29. long oldRadix = (unsigned)-1;
  30. void ActivateButtons()
  31. {
  32. static int aDecOnlyKeys[] = { IDC_FE, IDC_DMS, IDC_SIN, IDC_COS, IDC_TAN, IDC_EXP, IDC_PI }; // controls used only in Decimal mode
  33. if (oldRadix != nRadix)
  34. {
  35. int i;
  36. BOOL bDecMode = (nRadix == 10);
  37. // Only send messages to the the "Decimal Only keys" if this change in
  38. // base effects those keys
  39. if ((oldRadix == 10) || bDecMode)
  40. {
  41. // we are changing to or from decimal mode
  42. for ( i = 0; i <= ARRAYSIZE(aDecOnlyKeys) ; i++ )
  43. {
  44. EnableWindow( GetDlgItem(g_hwndDlg, aDecOnlyKeys[i]),
  45. bDecMode );
  46. }
  47. }
  48. // insure that nRadix is within the allowed range
  49. ASSERT( (nRadix >= 2) && (nRadix <= 16) );
  50. // turn on digit keys less than nRadix and turn off digit keys >= nRadix
  51. for (i=2; i<nRadix; i++)
  52. EnableWindow( GetDlgItem(g_hwndDlg, IDC_0+i), TRUE );
  53. for ( ; i<16; i++ )
  54. EnableWindow( GetDlgItem(g_hwndDlg, IDC_0+i), FALSE );
  55. }
  56. oldRadix = nRadix;
  57. }
  58. // SetRadix sets the display mode according to the selected button.
  59. // ToddB: As a hack to allow setting other bases, wRadix can be one of
  60. // the base buttons OR it can be the desired nRadix.
  61. // MAXIUM: for Dec the precision is limited to the nPrecision,
  62. // otherwise it is limited to the word size.
  63. VOID NEAR SetRadix(DWORD wRadix)
  64. {
  65. static INT nRadish[4]={2,8,10,16}; /* Number bases. */
  66. int id=IDM_DEC;
  67. // convert special bases into symbolic values
  68. switch ( wRadix )
  69. {
  70. case 2:
  71. id=IDM_BIN;
  72. break;
  73. case 8:
  74. id=IDM_OCT;
  75. break;
  76. case 10:
  77. id=IDM_DEC;
  78. break;
  79. case 16:
  80. id=IDM_HEX;
  81. break;
  82. case IDM_HEX:
  83. case IDM_DEC:
  84. case IDM_OCT:
  85. case IDM_BIN:
  86. id=wRadix;
  87. wRadix = nRadish[IDM_BIN - wRadix];
  88. break;
  89. }
  90. // we select which group of toggles we are setting, decimal mode gets the
  91. // angular notation buttons (deg, rad, grad) otherwise we get the word size
  92. // buttons (dword, word, byte)
  93. SwitchModes(wRadix, nDecMode, nHexMode);
  94. CheckMenuRadioItem(GetSubMenu(GetMenu(g_hwndDlg),1),IDM_HEX,IDM_BIN,id,
  95. MF_BYCOMMAND);
  96. CheckRadioButton(g_hwndDlg,IDM_HEX, IDM_BIN, id);
  97. nRadix = wRadix;
  98. // inform ratpak that a change in base or precision has occured
  99. BaseOrPrecisionChanged();
  100. // update the UI elements to the correct state
  101. ActivateButtons();
  102. // display the correct number for the new state (ie convert displayed
  103. // number to correct base)
  104. DisplayNum();
  105. }
  106. // Check/uncheck the visible inverse/hyperbolic
  107. VOID NEAR SetBox (int id, BOOL bOnOff)
  108. {
  109. CheckDlgButton(g_hwndDlg, id, (WORD) bOnOff);
  110. return;
  111. }
  112. //
  113. // Description:
  114. // This will switch the displayed/enabled mode buttons. This also updates
  115. // The switches the menu under view and sets the correct state.
  116. //
  117. void
  118. SwitchModes(DWORD wRadix, int nDecMode, int nHexMode)
  119. {
  120. int iID, id;
  121. if (10 == wRadix)
  122. {
  123. id=IDM_DEG+nDecMode;
  124. if (NULL != g_hDecMenu)
  125. SetMenu(g_hwndDlg, g_hDecMenu);
  126. CheckMenuRadioItem(g_hDecMenu, IDM_DEG, IDM_GRAD, id, MF_BYCOMMAND);
  127. CheckRadioButton(g_hwndDlg,IDC_DEG, IDC_GRAD, id);
  128. }
  129. else
  130. {
  131. id=IDM_QWORD+nHexMode;
  132. if (NULL != g_hHexMenu)
  133. SetMenu(g_hwndDlg, g_hHexMenu);
  134. CheckMenuRadioItem(g_hHexMenu, IDM_QWORD, IDM_BYTE, id, MF_BYCOMMAND);
  135. CheckRadioButton(g_hwndDlg,IDC_QWORD, IDC_BYTE, id);
  136. }
  137. for (iID = IDC_QWORD; iID <= IDC_BYTE; iID++)
  138. {
  139. EnableWindow( GetDlgItem( g_hwndDlg, iID ), (wRadix != 10) );
  140. ShowWindow( GetDlgItem( g_hwndDlg, iID ),
  141. (wRadix == 10) ? SW_HIDE : SW_SHOW );
  142. }
  143. for (iID = IDC_DEG; iID <= IDC_GRAD; iID++)
  144. {
  145. EnableWindow( GetDlgItem( g_hwndDlg, iID ), (wRadix == 10) );
  146. ShowWindow( GetDlgItem( g_hwndDlg, iID ),
  147. (wRadix != 10) ? SW_HIDE : SW_SHOW );
  148. }
  149. }