00001
00002
00003
00004 #include "stdafx.h"
00005 #include "inplaceedit.h"
00006 #include "inplacelist.h"
00007 #include "aspectspectbl.h"
00008 #include "aspectspecdlg.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00017
00018
00019 CAspectSpecTbl::CAspectSpecTbl()
00020 {
00021 }
00022
00023 CAspectSpecTbl::~CAspectSpecTbl()
00024 {
00025 }
00026
00027
00028 BEGIN_MESSAGE_MAP(CAspectSpecTbl, CListCtrl)
00029
00030 ON_NOTIFY_REFLECT(LVN_ENDLABELEDIT, OnEndlabeledit)
00031 ON_WM_HSCROLL()
00032 ON_WM_VSCROLL()
00033 ON_WM_LBUTTONDOWN()
00034 ON_WM_CREATE()
00035
00036 END_MESSAGE_MAP()
00037
00039
00040
00041 void CAspectSpecTbl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
00042 {
00043 LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
00044
00045
00046 LV_ITEM *plvItem = &pDispInfo->item;
00047
00048 if (plvItem->pszText != NULL)
00049 {
00050 SetItemText(plvItem->iItem, plvItem->iSubItem, plvItem->pszText);
00051 }
00052
00053 *pResult = TRUE;
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 int CAspectSpecTbl::HitTestEx(CPoint &point, int *col) const
00065 {
00066 int colnum = 0;
00067 int row = HitTest( point, NULL );
00068
00069 if( col ) *col = 0;
00070
00071
00072 if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
00073 return row;
00074
00075
00076 row = GetTopIndex();
00077 int bottom = row + GetCountPerPage();
00078 if( bottom > GetItemCount() )
00079 bottom = GetItemCount();
00080
00081
00082 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
00083 int nColumnCount = pHeader->GetItemCount();
00084
00085
00086 for( ;row <=bottom;row++)
00087 {
00088
00089 CRect rect;
00090 GetItemRect( row, &rect, LVIR_BOUNDS );
00091 if( rect.PtInRect(point) )
00092 {
00093
00094 for( colnum = 0; colnum < nColumnCount; colnum++ )
00095 {
00096 int colwidth = GetColumnWidth(colnum);
00097 if( point.x >= rect.left
00098 && point.x <= (rect.left + colwidth ) )
00099 {
00100 if( col ) *col = colnum;
00101 return row;
00102 }
00103 rect.left += colwidth;
00104 }
00105 }
00106 }
00107 return -1;
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 CComboBox* CAspectSpecTbl::ShowInPlaceList( int nItem, int nCol,
00119 CStringList &lstItems, int nSel )
00120 {
00121
00122
00123
00124 if( !EnsureVisible( nItem, TRUE ) ) return NULL;
00125
00126
00127 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
00128 int nColumnCount = pHeader->GetItemCount();
00129 if( nCol >= nColumnCount || GetColumnWidth(nCol) < 10 )
00130 return NULL;
00131
00132
00133 int offset = 0;
00134 for( int i = 0; i < nCol; i++ )
00135 offset += GetColumnWidth( i );
00136
00137 CRect rect;
00138 GetItemRect( nItem, &rect, LVIR_BOUNDS );
00139
00140
00141 CRect rcClient;
00142 GetClientRect( &rcClient );
00143 if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
00144 {
00145 CSize size;
00146 size.cx = offset + rect.left;
00147 size.cy = 0;
00148 Scroll( size );
00149 rect.left -= size.cx;
00150 }
00151
00152 rect.left += offset+4;
00153 rect.right = rect.left + GetColumnWidth( nCol ) - 3 ;
00154 int height = rect.bottom-rect.top;
00155 rect.bottom += (lstItems.GetCount()+1)*height;
00156 if( rect.right > rcClient.right) rect.right = rcClient.right;
00157
00158 DWORD dwStyle = WS_BORDER|WS_CHILD|WS_VISIBLE
00159 |CBS_DROPDOWNLIST|CBS_DISABLENOSCROLL;
00160 if( rect.bottom > rcClient.bottom + 4*height)
00161 {
00162 rect.bottom = rcClient.bottom + 4*height;
00163 dwStyle |= WS_VSCROLL;
00164 }
00165
00166 CComboBox *pList = new CInPlaceList(nItem, nCol, &lstItems, nSel);
00167 pList->Create( dwStyle, rect, this, IDC_IPEDIT );
00168 pList->SetItemHeight( -1, height);
00169 pList->SetHorizontalExtent( GetColumnWidth( nCol ));
00170
00171
00172 return pList;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181 CEdit* CAspectSpecTbl::EditSubLabel( int nItem, int nCol )
00182 {
00183
00184
00185
00186 if( !EnsureVisible( nItem, TRUE ) ) return NULL;
00187
00188
00189 CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
00190 int nColumnCount = pHeader->GetItemCount();
00191 if( nCol >= nColumnCount || GetColumnWidth(nCol) < 5 )
00192 return NULL;
00193
00194
00195 int offset = 0;
00196 for( int i = 0; i < nCol; i++ )
00197 offset += GetColumnWidth( i );
00198
00199 CRect rect;
00200 GetItemRect( nItem, &rect, LVIR_BOUNDS );
00201
00202
00203 CRect rcClient;
00204 GetClientRect( &rcClient );
00205 if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
00206 {
00207 CSize size;
00208 size.cx = offset + rect.left;
00209 size.cy = 0;
00210 Scroll( size );
00211 rect.left -= size.cx;
00212 }
00213
00214
00215 LV_COLUMN lvcol;
00216 lvcol.mask = LVCF_FMT;
00217 GetColumn( nCol, &lvcol );
00218 DWORD dwStyle ;
00219 if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
00220 dwStyle = ES_LEFT;
00221 else if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT)
00222 dwStyle = ES_RIGHT;
00223 else dwStyle = ES_CENTER;
00224
00225 rect.left += offset+4;
00226 rect.right = rect.left + GetColumnWidth( nCol ) - 3 ;
00227 if( rect.right > rcClient.right) rect.right = rcClient.right;
00228
00229 dwStyle |= WS_BORDER|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL;
00230 CEdit *pEdit = new CInPlaceEdit(nItem, nCol, GetItemText( nItem, nCol ));
00231 pEdit->Create( dwStyle, rect, this, IDC_IPEDIT );
00232
00233
00234 return pEdit;
00235 }
00236
00237 void CAspectSpecTbl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00238 {
00239
00240 if( GetFocus() != this ) SetFocus();
00241 CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
00242 }
00243
00244
00245
00246 void CAspectSpecTbl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00247 {
00248
00249 if( GetFocus() != this ) SetFocus();
00250 CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 void CAspectSpecTbl::OnLButtonDown(UINT nFlags, CPoint point)
00280 {
00281 int index;
00282 CListCtrl::OnLButtonDown(nFlags, point);
00283
00284 int colnum;
00285 if( ( index = HitTestEx( point, &colnum )) != -1 )
00286 {
00287 UINT flag = LVIS_FOCUSED;
00288 if( (GetItemState( index, flag ) & flag) == flag )
00289 {
00290
00291
00292 if(colnum==1)
00293 {
00294 char buff[64];
00295 LVITEM item;
00296 item.mask = LVIF_TEXT;
00297 item.iItem = index;
00298 item.iSubItem = 1;
00299 item.pszText = buff;
00300 item.cchTextMax = 63;
00301 if (GetItem(&item) && CString(item.pszText) != "N/A") {
00302 CStringList lstItems;
00303 int rowID = GetItemData( index);
00304
00305 theAspectDlg->GetAspects( rowID, lstItems);
00306 ShowInPlaceList( index, colnum, lstItems, 0 );
00307 }
00308 }
00309 if(colnum==2)
00310 {
00311 char buff[64];
00312 LVITEM item;
00313 item.mask = LVIF_TEXT;
00314 item.iItem = index;
00315 item.iSubItem = 2;
00316 item.pszText = buff;
00317 item.cchTextMax = 63;
00318 if (GetItem(&item) && CString(item.pszText) != "N/A") {
00319 CStringList lstItems;
00320 lstItems.AddTail("yes");
00321 lstItems.AddTail("no");
00322 ShowInPlaceList( index, colnum, lstItems, 0 );
00323 }
00324 }
00325
00326 }
00327 else
00328 SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED ,
00329 LVIS_SELECTED | LVIS_FOCUSED);
00330 }
00331 }
00332
00333
00334
00335 void CAspectSpecTbl::AddRow(int rowID, CString& role, CString& kindAspect, CString& isPrimary)
00336 {
00337 LV_ITEM lvItem;
00338 lvItem.mask = LVIF_TEXT;
00339 lvItem.iItem = GetItemCount();
00340 lvItem.iSubItem = 0;
00341 lvItem.pszText = role.GetBuffer(role.GetLength());
00342 int index = InsertItem(&lvItem);
00343
00344
00345 lvItem.iSubItem = 1;
00346 lvItem.pszText = kindAspect.GetBuffer( kindAspect.GetLength());
00347 SetItem(&lvItem);
00348
00349 lvItem.iSubItem = 2;
00350 lvItem.pszText = isPrimary.GetBuffer( isPrimary.GetLength());
00351
00352
00353
00354
00355 SetItem(&lvItem);
00356
00357 SetItemData(index, rowID);
00358
00359 }
00360
00361 int CAspectSpecTbl::OnCreate(LPCREATESTRUCT lpCreateStruct)
00362 {
00363 if (CListCtrl::OnCreate(lpCreateStruct) == -1)
00364 return -1;
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 int col1size = 3*GetStringWidth("TipicalContainerN::LongRoleName")/2;
00386 int col2size = 3*GetStringWidth("LongAspectName")/2;
00387 int col3size = 3*GetStringWidth("Primary")/2;
00388
00389 InsertColumn(0, _T("Role"), LVCFMT_LEFT, col1size, -1);
00390 InsertColumn(1, _T("KindAspect"), LVCFMT_LEFT, col2size, -1);
00391 InsertColumn(2, _T("Primary"), LVCFMT_LEFT, col3size, -1);
00392
00393 return 0;
00394 }
00395
00396 bool CAspectSpecTbl::GetRow(int rowID, CString &role, CString &kindAspect, CString& isPrimary)
00397 {
00398
00399 LVFINDINFO lvFind;
00400 lvFind.flags = LVFI_PARAM;
00401 lvFind.lParam = rowID;
00402 int idx = FindItem(&lvFind);
00403
00404 if (idx == -1)
00405 return false;
00406
00407
00408 LV_ITEM lvItem;
00409 lvItem.mask = LVIF_TEXT;
00410 lvItem.iItem = idx;
00411 lvItem.pszText = role.GetBuffer(255);
00412 lvItem.cchTextMax = 254;
00413 lvItem.iSubItem = 0;
00414 GetItem(&lvItem);
00415
00416
00417
00418 lvItem.iSubItem = 1;
00419 lvItem.pszText = kindAspect.GetBuffer(255);
00420 lvItem.cchTextMax = 254;
00421 GetItem(&lvItem);
00422
00423
00424
00425 lvItem.pszText = isPrimary.GetBuffer(10);
00426 lvItem.cchTextMax = 9;
00427 lvItem.iSubItem = 2;
00428 GetItem(&lvItem);
00429
00430
00431 return true;
00432 }
00433