home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / numedit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.4 KB  |  95 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. //NumEdit.cpp :implementation file
  19.  
  20. #include "stdafx.h"
  21. #include "numedit.h"
  22.  
  23.  
  24. #ifdef DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28.  
  29.  
  30. CNSNumEdit::CNSNumEdit()
  31. {
  32. }
  33.  
  34.  
  35. //=========================================================== ~CNSNumEdit
  36. CNSNumEdit::~CNSNumEdit()
  37. {
  38. }
  39.  
  40. BOOL CNSNumEdit::PreTranslateMessage( MSG* pMsg )
  41. {
  42.     return CEdit::PreTranslateMessage(pMsg);
  43. }
  44.  
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CNSNumEdit message handlers
  48.  
  49. BEGIN_MESSAGE_MAP(CNSNumEdit, CEdit)
  50.     ON_WM_CHAR()
  51.     ON_WM_SETFOCUS()
  52. END_MESSAGE_MAP()
  53.  
  54. //==================================================================== OnChar
  55. void CNSNumEdit::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags )
  56. {
  57.     if ( ((nChar >= '0') && (nChar <= '9')) || (nChar == 0x08) ) 
  58.     {
  59.         CEdit::OnChar(nChar, nRepCnt, nFlags);
  60.     }
  61.     else
  62.     {
  63.         MessageBeep( MB_OK );
  64.     }
  65. }
  66.  
  67. //=============================================================== OnSetFocus
  68. void CNSNumEdit::OnSetFocus( CWnd* pOldWnd )
  69. {
  70.     CEdit::OnSetFocus( pOldWnd );
  71.     SetSel(0,-1);
  72. }
  73.  
  74. //================================================================== SetValue
  75. int CNSNumEdit::SetValue( int nNewValue )
  76. {
  77.     char buff[10];
  78.     if (nNewValue > 0)
  79.         SetWindowText( itoa( nNewValue, buff, 10 ) );
  80.     else
  81.         SetWindowText("");
  82.     return nNewValue;
  83. }
  84.  
  85.  
  86. //================================================================== GetValue
  87. int CNSNumEdit::GetValue( void )
  88. {
  89.     char buff[10];
  90.     GetWindowText( buff, 10 );
  91.     if ( strlen( buff ) > 0 )
  92.             return atoi( buff );
  93.     return 0;
  94. }
  95.