GME  13
SyncObjsListCtrl.cpp
Go to the documentation of this file.
00001 // SyncObjsListCtrl.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "GMEApp.h"
00006 #include "SyncObjsListCtrl.h"
00007 #include "GMEstd.h"
00008 #include "GuiObject.h"
00009 
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015 
00017 // CSyncObjsListCtrl
00018 
00019 bool CSyncObjsListCtrl::isAscending[] = {true, true, true};
00020 
00021 CSyncObjsListCtrl::CSyncObjsListCtrl()
00022 {
00023 }
00024 
00025 CSyncObjsListCtrl::~CSyncObjsListCtrl()
00026 {
00027 }
00028 
00029 
00030 BEGIN_MESSAGE_MAP(CSyncObjsListCtrl, CListCtrl)
00031         //{{AFX_MSG_MAP(CSyncObjsListCtrl)
00032         ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
00033         //}}AFX_MSG_MAP
00034 END_MESSAGE_MAP()
00035 
00037 // CSyncObjsListCtrl message handlers
00038 
00039 void CSyncObjsListCtrl::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult) 
00040 {
00041         NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
00042         
00043         SortItems(ObjsCompare, pNMListView->iSubItem);
00044         
00045         *pResult = 0;
00046 }
00047 
00048 int CALLBACK CSyncObjsListCtrl::ObjsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
00049 {
00050         CGuiObject* pItem1 = (CGuiObject*) lParam1;
00051         CGuiObject* pItem2 = (CGuiObject*) lParam2;
00052         int nResult = 0;
00053 
00054         switch (lParamSort) {
00055 
00056         case 0: // Object name.
00057                 nResult = (isAscending[0] ? 1 : -1) * pItem1->name.CompareNoCase(pItem2->name);
00058                 isAscending[0] = !isAscending[0];
00059                 break;
00060         case 1: // Kind name.
00061                 nResult = (isAscending[1] ? 1 : -1) * pItem1->kindName.CompareNoCase(pItem2->kindName);
00062                 isAscending[1] = !isAscending[1];
00063                 break;
00064         case 2: // Role name.
00065                 nResult = (isAscending[2] ? 1 : -1) * pItem1->roleName.CompareNoCase(pItem2->roleName);
00066                 isAscending[2] = !isAscending[2];
00067                 break;
00068         }
00069         return nResult;
00070 }