]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/tools/Utils/win32/IntegerEdit.cpp
Initial revision
[karo-tx-redboot.git] / tools / src / tools / Utils / win32 / IntegerEdit.cpp
1 //####COPYRIGHTBEGIN####
2 //                                                                          
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
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) 
11 // any later version.
12 // 
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 
16 // more details.
17 // 
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.
21 //
22 // ----------------------------------------------------------------------------
23 //                                                                          
24 //####COPYRIGHTEND####
25 // IntegerEdit.cpp : implementation file
26 //
27 //
28 //#####DESCRIPTIONBEGIN####
29 //
30 // Author(s):   sdf
31 // Contact(s):  sdf
32 // Date:                1998/08/11
33 // Version:             0.01
34 // Purpose:     
35 // Description: This is the implementation of the masked edit control as used 
36 //                              in integer in-cell edits by the control view.
37 // Requires:    
38 // Provides:    
39 // See also:    
40 // Known bugs:  
41 // Usage:       
42 //
43 //####DESCRIPTIONEND####
44 //
45 //===========================================================================
46
47 #include "stdafx.h"
48 #include "IntegerEdit.h"
49 #include "CTUtils.h"
50
51 #ifdef _DEBUG
52 #define new DEBUG_NEW
53 #undef THIS_FILE
54 static char THIS_FILE[] = __FILE__;
55 #endif
56
57 /////////////////////////////////////////////////////////////////////////////
58 // CIntegerEdit
59
60 CIntegerEdit::CIntegerEdit(__int64 nInitialValue):
61   CCellEdit(CUtils::IntToStr(nInitialValue,false/*bool bHex*/)),
62   m_bInSize(false)
63 {
64 }
65
66 CIntegerEdit::~CIntegerEdit()
67 {
68 }
69
70
71 BEGIN_MESSAGE_MAP(CIntegerEdit, CCellEdit)
72         //{{AFX_MSG_MAP(CIntegerEdit)
73         ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
74         ON_WM_CREATE()
75         ON_WM_SIZE()
76         ON_WM_CHAR()
77         //}}AFX_MSG_MAP
78 END_MESSAGE_MAP()
79
80 /////////////////////////////////////////////////////////////////////////////
81 // CIntegerEdit message handlers
82
83 void CIntegerEdit::OnUpdate()
84 {
85     CString str;
86     GetWindowText(str);
87     __int64 d;
88     if(CUtils::StrToItemIntegerType(str,d)||0==str.CompareNoCase(_T("0X"))||_T("-")==str){
89         // reject all illegal strings except [partially] correct ones
90         m_strPrevText=str;
91     } else {
92         MessageBeep(0xFFFFFFFF);
93         const CPoint pt(GetCaretPos());
94         SetWindowText(m_strPrevText);
95         SetCaretPos(pt);
96     }
97 }
98
99
100 BOOL CIntegerEdit::PreCreateWindow(CREATESTRUCT& cs) 
101 {
102         return CCellEdit::PreCreateWindow(cs);
103 }
104
105 int CIntegerEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) 
106 {
107         if (CCellEdit::OnCreate(lpCreateStruct) == -1)
108                 return -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);
113         return 0;
114 }
115   
116 void CIntegerEdit::OnSize(UINT /*nType*/, int cx, int cy) 
117 {
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);
123   if(bSpin){
124     if(m_bInSize){
125       Default();
126     } else {
127       cx-=(cxSpin+4);
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);
136       m_bInSize=true;
137       rect.InflateRect(cxEdge,cyEdge);
138       MoveWindow(rect);
139       m_bInSize=false;
140     }
141   } else {
142     m_wndSpin.ShowWindow(SW_HIDE);
143     Default();
144   }
145 }