Develop and Download Open Source Software

Browse CVS Repository

Contents of /satellite/neuromanager/neuromanager/ListCtrlEdit.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Feb 4 13:38:16 2006 UTC (18 years, 2 months ago) by orrisroot
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-c++src
moved main application sources to neuromanager directory.

1 /* --------------------------------------------------------------------- */
2 /* NeuroManager - A spike train analysis tool */
3 /* Copyright (c) 2005-2006 RIKEN, Japan. All rights reserved. */
4 /* http://satellite.sourceforge.jp/ */
5 /* --------------------------------------------------------------------- */
6 /* This program is free software; you can redistribute it and/or */
7 /* modify it under the terms of the GNU General Public License */
8 /* as published by the Free Software Foundation; either version 2 */
9 /* of the License, or (at your option) any later version. */
10 /* */
11 /* This program is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with this program; see the file COPYING.txt. If not, write */
18 /* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth */
19 /* Floor, Boston, MA 02110-1301, USA. */
20 /* --------------------------------------------------------------------- */
21
22 /* $Id: ListCtrlEdit.cpp,v 1.4 2006/01/24 02:01:12 orrisroot Exp $ */
23
24 // ListCtrlEdit.cpp : implementation of the CListCtrlEdit class
25 //
26
27 #include "stdafx.h"
28 #include "ListCtrlEdit.h"
29 #include ".\listctrledit.h"
30
31
32 #define EDITLABEL_RECT_TOP_OFFSET -1
33 #define EDITLABEL_RECT_BOTTOM_OFFSET 0
34
35 /////////////////////////////////////////////////////////////////////////////
36 // CEditInplace
37 //
38
39 CEditInplace::CEditInplace()
40 {
41 EnableActiveAccessibility();
42 }
43
44 CEditInplace::~CEditInplace()
45 {}
46
47
48 BEGIN_MESSAGE_MAP( CEditInplace, CEdit )
49 ON_WM_GETDLGCODE()
50 ON_WM_KEYDOWN()
51 END_MESSAGE_MAP()
52
53 /////////////////////////////////////////////////////////////////////////////
54 // CEditInplace messages
55 //
56
57 UINT CEditInplace::OnGetDlgCode()
58 {
59 return DLGC_WANTALLKEYS | CEdit::OnGetDlgCode();
60 }
61
62
63 void CEditInplace::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
64 {
65 if ( nChar == VK_RETURN || nChar == VK_ESCAPE )
66 {
67 GetParent() ->SendMessage( WM_KEYDOWN, nChar, MAKELPARAM( nRepCnt, nFlags ) );
68 }
69 else
70 {
71 CEdit::OnKeyDown( nChar, nRepCnt, nFlags );
72 }
73 }
74
75
76 /////////////////////////////////////////////////////////////////////////////
77 // CListCtrlEdit
78
79 IMPLEMENT_DYNAMIC( CListCtrlEdit, CListCtrl )
80 CListCtrlEdit::CListCtrlEdit()
81 {
82 EnableActiveAccessibility();
83 m_bEdit = FALSE;
84 }
85
86 CListCtrlEdit::~CListCtrlEdit()
87 {}
88
89
90 BEGIN_MESSAGE_MAP( CListCtrlEdit, CListCtrl )
91 ON_WM_KEYDOWN()
92 ON_WM_VSCROLL()
93 ON_WM_HSCROLL()
94 ON_EN_KILLFOCUS( IDC_LIST_CTRL_EDIT, OnKillFocusEdit )
95 END_MESSAGE_MAP()
96
97 void CListCtrlEdit::GetEditRect( int iItem, int iSubItem, CRect &rct )
98 {
99 GetSubItemRect( iItem, iSubItem, LVIR_LABEL, rct );
100 rct.top += EDITLABEL_RECT_TOP_OFFSET;
101 rct.bottom += EDITLABEL_RECT_BOTTOM_OFFSET;
102 }
103
104 BOOL CListCtrlEdit::PrepareLabelEdit( NMLVDISPINFO *pDispInfo )
105 {
106 LVHITTESTINFO hitTest;
107 ::GetCursorPos( &hitTest.pt );
108 ScreenToClient( &hitTest.pt );
109
110 hitTest.flags = LVHT_ONITEMLABEL;
111 if ( SubItemHitTest( &hitTest ) < 0 || hitTest.iItem != pDispInfo->item.iItem )
112 {
113 return FALSE;
114 }
115
116 pDispInfo->item.iSubItem = hitTest.iSubItem;
117 return TRUE;
118 }
119
120 void CListCtrlEdit::CancelEdit()
121 {
122 if ( ! m_bEdit )
123 {
124 return ;
125 }
126
127 // set flag to FALSE before call DestroyWindow() method.
128 // DestoryWindow() method will sends EN_KILLFOCUS window message.
129 m_bEdit = FALSE;
130 m_editInline.DestroyWindow();
131
132 if ( m_orgStyle & LVS_SINGLESEL )
133 {
134 ModifyStyle( 0, LVS_SINGLESEL );
135 }
136 else if ( ! GetItemState( m_iItem, LVIS_SELECTED ) )
137 {
138 SetItemState( m_iItem, LVIS_SELECTED, LVIS_SELECTED );
139 }
140 }
141
142 void CListCtrlEdit::BeginLabelEdit( NMLVDISPINFO* pDispInfo, LRESULT* pResult )
143 {
144 if ( pDispInfo->item.iSubItem == 0 )
145 {
146 *pResult = 0;
147 return ;
148 }
149
150 m_bEdit = TRUE;
151 m_iItem = pDispInfo->item.iItem;
152 m_iSubItem = pDispInfo->item.iSubItem;
153
154 m_orgStyle = GetStyle();
155 if ( m_orgStyle & LVS_SINGLESEL )
156 {
157 ModifyStyle( LVS_SINGLESEL, 0 );
158 }
159 SetItemState( m_iItem, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED );
160
161 CRect rct;
162 GetEditRect( m_iItem, m_iSubItem, rct );
163 m_editInline.Create( WS_CHILD | WS_BORDER | WS_VISIBLE | ES_AUTOHSCROLL, rct, this, IDC_LIST_CTRL_EDIT );
164 m_editInline.SetFont( GetFont(), FALSE );
165
166 m_editInline.SetWindowText( GetItemText( m_iItem, m_iSubItem ) );
167 m_editInline.SetSel( 0, -1 );
168 m_editInline.SetFocus();
169
170 *pResult = 1;
171 }
172
173 /////////////////////////////////////////////////////////////////////////////
174 // CListCtrlEdit messages
175
176 void CListCtrlEdit::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
177 {
178 if ( nChar == VK_RETURN )
179 {
180 OnKillFocusEdit();
181 SetItemState( m_iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
182 }
183 else if ( nChar == VK_ESCAPE )
184 {
185 CancelEdit();
186 SetItemState( m_iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
187 }
188 }
189
190 void CListCtrlEdit::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
191 {
192 CListCtrl::OnVScroll( nSBCode, nPos, pScrollBar );
193
194 if ( m_bEdit )
195 {
196 CancelEdit();
197 }
198 }
199
200 void CListCtrlEdit::OnHScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
201 {
202 CListCtrl::OnHScroll( nSBCode, nPos, pScrollBar );
203
204 if ( m_bEdit )
205 {
206 CancelEdit();
207 }
208 }
209
210 void CListCtrlEdit::OnKillFocusEdit()
211 {
212 if ( ! m_bEdit )
213 {
214 return ;
215 }
216
217 CString str;
218 m_editInline.GetWindowText( str );
219 CancelEdit();
220
221 NMLVDISPINFO info;
222 ::ZeroMemory( &info, sizeof( NMLVDISPINFO ) );
223
224 info.hdr.hwndFrom = m_hWnd;
225 info.hdr.idFrom = GetDlgCtrlID();
226 info.hdr.code = LVN_ENDLABELEDIT;
227
228 info.item.mask = LVIF_TEXT;
229 info.item.iItem = m_iItem;
230 info.item.iSubItem = m_iSubItem;
231 info.item.cchTextMax = str.GetLength() + 64;
232 info.item.pszText = str.GetBuffer( info.item.cchTextMax );
233
234 if ( GetParent() ->SendMessage( WM_NOTIFY, GetDlgCtrlID(), ( LPARAM ) & info ) && info.item.pszText != NULL )
235 {
236 SetItemText( m_iItem, m_iSubItem, info.item.pszText );
237 }
238
239 str.ReleaseBuffer();
240 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26