1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // IntegerEdit.cpp : implementation file
28 //#####DESCRIPTIONBEGIN####
35 // Description: This is the implementation of the masked edit control as used
36 // in integer in-cell edits by the control view.
43 //####DESCRIPTIONEND####
45 //===========================================================================
48 #include "IntegerEdit.h"
54 static char THIS_FILE[] = __FILE__;
57 /////////////////////////////////////////////////////////////////////////////
60 CIntegerEdit::CIntegerEdit(__int64 nInitialValue):
61 CCellEdit(CUtils::IntToStr(nInitialValue,false/*bool bHex*/)),
66 CIntegerEdit::~CIntegerEdit()
71 BEGIN_MESSAGE_MAP(CIntegerEdit, CCellEdit)
72 //{{AFX_MSG_MAP(CIntegerEdit)
73 ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
80 /////////////////////////////////////////////////////////////////////////////
81 // CIntegerEdit message handlers
83 void CIntegerEdit::OnUpdate()
88 if(CUtils::StrToItemIntegerType(str,d)||0==str.CompareNoCase(_T("0X"))||_T("-")==str){
89 // reject all illegal strings except [partially] correct ones
92 MessageBeep(0xFFFFFFFF);
93 const CPoint pt(GetCaretPos());
94 SetWindowText(m_strPrevText);
100 BOOL CIntegerEdit::PreCreateWindow(CREATESTRUCT& cs)
102 return CCellEdit::PreCreateWindow(cs);
105 int CIntegerEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
107 if (CCellEdit::OnCreate(lpCreateStruct) == -1)
109 m_wndSpin.Create(WS_CHILD|UDS_NOTHOUSANDS|UDS_ARROWKEYS|UDS_SETBUDDYINT,CRect(0,0,1,1),GetParent(),1);
110 m_wndSpin.SetBuddy(this);
111 m_wndSpin.SetRange32(0,0x7fffffff);
112 m_wndSpin.SetWindowPos(this,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
116 void CIntegerEdit::OnSize(UINT /*nType*/, int cx, int cy)
118 int cxSpin=::GetSystemMetrics(SM_CXVSCROLL);
119 int cySpin=::GetSystemMetrics(SM_CYVSCROLL);
120 int cxEdge=::GetSystemMetrics(SM_CXEDGE);
121 int cyEdge=::GetSystemMetrics(SM_CYEDGE);
122 bool bSpin=(cx>3*cxSpin);
128 CRect rect(cx+4,-cyEdge,cx+4+cxSpin,min(cySpin,cy+2*cyEdge));
129 ClientToScreen(rect);
130 GetParent()->ScreenToClient(rect);
131 m_wndSpin.MoveWindow(rect,true);
132 m_wndSpin.ShowWindow(SW_SHOW);
133 rect=CRect(0,0,cx,cy);
134 ClientToScreen(rect);
135 GetParent()->ScreenToClient(rect);
137 rect.InflateRect(cxEdge,cyEdge);
142 m_wndSpin.ShowWindow(SW_HIDE);