home *** CD-ROM | disk | FTP | other *** search
- // MirrorItView.cpp : implementation of the CMirrorItView class
- //
-
- #include "stdafx.h"
- #include "MirrorIt.h"
-
- #include "MirrorItDoc.h"
- #include "MirrorItView.h"
- #include "SessionPropertiesFileNamePage.h"
- #include "SessionPropertiesMirrorPage.h"
- #include "SessionPropertiesMainPage.h"
- #include "SessionPropertiesFileTypesPage.h"
- #include "SessionPropertiesLimitPage.h"
- #include "SessionPropertiesProxyPage.h"
- #include "SessionPropertiesPasswordPage.h"
- #include "SessionPropertiesAdvancedPage.h"
- #include "SessionPropertiesSheet.h"
- #include "Session.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMirrorItView
-
- IMPLEMENT_DYNCREATE(CMirrorItView, CListView)
-
- BEGIN_MESSAGE_MAP(CMirrorItView, CListView)
- ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopyCut)
- ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCopyCut)
- ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
- ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
- ON_COMMAND(ID_EDIT_CUT, OnEditCut)
- ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
- //{{AFX_MSG_MAP(CMirrorItView)
- ON_COMMAND(IDM_VIEW_DETAILS, OnViewDetails)
- ON_COMMAND(IDM_VIEW_LARGEICONS, OnViewLargeicons)
- ON_COMMAND(IDM_VIEW_LIST, OnViewList)
- ON_COMMAND(IDM_VIEW_SMALLICONS, OnViewSmallicons)
- ON_UPDATE_COMMAND_UI(IDM_VIEW_SMALLICONS, OnUpdateViewSmallicons)
- ON_UPDATE_COMMAND_UI(IDM_VIEW_LIST, OnUpdateViewList)
- ON_UPDATE_COMMAND_UI(IDM_VIEW_LARGEICONS, OnUpdateViewLargeicons)
- ON_UPDATE_COMMAND_UI(IDM_VIEW_DETAILS, OnUpdateViewDetails)
- ON_COMMAND(ID_SESSION_PROPERTIES, OnSessionProperties)
- ON_UPDATE_COMMAND_UI(ID_SESSION_PROPERTIES, OnUpdateSessionProperties)
- ON_COMMAND(ID_SESSION_REMOVE, OnSessionRemove)
- ON_UPDATE_COMMAND_UI(ID_SESSION_REMOVE, OnUpdateSessionRemove)
- ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClear)
- ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
- ON_COMMAND(ID_SESSION_ADD, OnSessionAdd)
- ON_WM_LBUTTONDBLCLK()
- ON_UPDATE_COMMAND_UI(ID_SESSION_MOVEDOWN, OnUpdateSessionMovedown)
- ON_COMMAND(ID_SESSION_MOVEDOWN, OnSessionMovedown)
- ON_COMMAND(ID_SESSION_MOVEUP, OnSessionMoveup)
- ON_UPDATE_COMMAND_UI(ID_SESSION_MOVEUP, OnUpdateSessionMoveup)
- ON_UPDATE_COMMAND_UI(ID_SESSION_START, OnUpdateSessionStart)
- ON_COMMAND(ID_SESSION_START, OnSessionStart)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMirrorItView construction/destruction
-
- CMirrorItView::CMirrorItView()
- {
- // TODO: add construction code here
-
- // CG: This line was added by the Clipboard Assistant component
- m_nClipboardFormat = ::RegisterClipboardFormat(_T("MirrorIt Document"));
- }
-
- CMirrorItView::~CMirrorItView()
- {
- }
-
- BOOL CMirrorItView::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.style = (cs.style & ~LVS_TYPEMASK) | LVS_REPORT;
- cs.style |= LVS_AUTOARRANGE;
- return CListView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMirrorItView drawing
-
- void CMirrorItView::OnDraw(CDC* pDC)
- {
- CMirrorItDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
- }
-
- void CMirrorItView::OnInitialUpdate()
- {
- CListView::OnInitialUpdate();
- GetListCtrl().DeleteAllItems();
-
- CMirrorItDoc *pDoc = GetDocument();
-
- for (int i = 0; i < pDoc -> sessions.GetSize(); i++)
- AddSession((CSession *)pDoc -> sessions.GetAt(i));
-
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMirrorItView diagnostics
-
- #ifdef _DEBUG
- void CMirrorItView::AssertValid() const
- {
- CListView::AssertValid();
- }
-
- void CMirrorItView::Dump(CDumpContext& dc) const
- {
- CListView::Dump(dc);
- }
-
- CMirrorItDoc* CMirrorItView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMirrorItDoc)));
- return (CMirrorItDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMirrorItView message handlers
-
- BOOL CMirrorItView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- BOOL bCreated = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- if ( bCreated )
- {
- CListCtrl& listView = GetListCtrl();
- int aWidths[] = {100, 220, 148};
- CString strHeading;
-
- for (int iCol = 0; iCol < C_COLUMNS; iCol++)
- {
- strHeading.LoadString(IDS_COLUMN0 + iCol);
- listView.InsertColumn(iCol, strHeading, LVCFMT_LEFT,
- aWidths[iCol], iCol);
- }
-
- // Create the full-sized and small icon image lists.
- if ( m_ilLarge.Create( IDB_GLOBE, 32, 1, RGB(255, 0, 0) ) )
- {
- listView.SetImageList( &m_ilLarge, LVSIL_NORMAL );
- }
- if ( m_ilSmall.Create( IDB_GLOBESMALL, 16, 1, RGB(255,0,0) ) )
- {
- listView.SetImageList( &m_ilSmall, LVSIL_SMALL);
- }
-
-
- }
- return bCreated;
- }
-
- void CMirrorItView::SetListView(DWORD dwView)
- {
- CListCtrl& list = GetListCtrl();
- DWORD dwStyle = GetWindowLong(list.m_hWnd, GWL_STYLE);
- if ((dwStyle & LVS_TYPEMASK) != dwView)
- SetWindowLong(list.m_hWnd, GWL_STYLE,
- (dwStyle & ~LVS_TYPEMASK) | dwView);
- }
-
- void CMirrorItView::UpdateListView(CCmdUI * pCmdUI, DWORD dwView)
- {
- CListCtrl& list = GetListCtrl();
- DWORD dwStyle = GetWindowLong(list.m_hWnd, GWL_STYLE) & LVS_TYPEMASK;
- pCmdUI -> SetRadio(dwStyle == dwView);
- }
-
- void CMirrorItView::OnViewDetails()
- {
- SetListView(LVS_REPORT);
- }
-
- void CMirrorItView::OnViewLargeicons()
- {
- SetListView(LVS_ICON);
- }
-
- void CMirrorItView::OnViewList()
- {
- SetListView(LVS_LIST);
- }
-
- void CMirrorItView::OnViewSmallicons()
- {
- SetListView(LVS_SMALLICON);
- }
-
- void CMirrorItView::OnUpdateViewSmallicons(CCmdUI* pCmdUI)
- {
- UpdateListView(pCmdUI, LVS_SMALLICON);
- }
-
- void CMirrorItView::OnUpdateViewList(CCmdUI* pCmdUI)
- {
- UpdateListView(pCmdUI, LVS_LIST);
- }
-
- void CMirrorItView::OnUpdateViewLargeicons(CCmdUI* pCmdUI)
- {
- UpdateListView(pCmdUI, LVS_ICON);
- }
-
- void CMirrorItView::OnUpdateViewDetails(CCmdUI* pCmdUI)
- {
- UpdateListView(pCmdUI, LVS_REPORT);
- }
-
- void CMirrorItView::OnSessionProperties()
- {
- CListCtrl& list = GetListCtrl();
-
- if (list.GetSelectedCount() != 1) return;
-
- CMirrorItDoc *pDoc = GetDocument();
- pDoc -> PropertiesSession(list);
- }
-
- void CMirrorItView::OnUpdateSessionProperties(CCmdUI* pCmdUI)
- {
- pCmdUI -> Enable(GetListCtrl().GetSelectedCount() == 1);
- }
-
- void CMirrorItView::OnSessionRemove()
- {
- CListCtrl & list = GetListCtrl();
-
- int selcount = list.GetSelectedCount();
- if (selcount < 1) return;
-
- CMirrorItDoc *pDoc = GetDocument();
- pDoc -> RemoveSession(list);
- }
-
- void CMirrorItView::OnUpdateSessionRemove(CCmdUI* pCmdUI)
- {
- pCmdUI -> Enable(GetListCtrl().GetSelectedCount());
- }
-
- void CMirrorItView::OnUpdateEditClear(CCmdUI* pCmdUI)
- {
- OnUpdateSessionRemove(pCmdUI);
- }
-
- void CMirrorItView::OnEditClear()
- {
- OnSessionRemove();
- }
-
- void CMirrorItView::AddSession(CSession * session)
- {
- CListCtrl& list = GetListCtrl();
-
- int n = list.GetItemCount();
-
- list.InsertItem(n, session -> m_SessionName);
- list.SetItemText(n, 1, session -> m_BaseURL);
- list.SetItemText(n, 2, session -> m_Comment);
-
- list.SetItemData(n, (DWORD) session);
- }
-
- void CMirrorItView::UpdateSession(int n, CSession * session)
- {
- CListCtrl& list = GetListCtrl();
-
- list.SetItemText(n, 0, (LPCSTR)session -> m_SessionName);
- list.SetItemText(n, 1, (LPCSTR)session -> m_BaseURL);
- list.SetItemText(n, 2, (LPCSTR)session -> m_Comment);
-
- list.SetItemData(n, (DWORD) session);
- }
-
- void CMirrorItView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- LV_FINDINFO fi;
- int res, i, count;
- CSession *session;
- CListCtrl & list = GetListCtrl();
- CPtrArray *items;
- CDWordArray *ditems;
-
- CMirrorItDoc *pDoc = GetDocument();
-
- switch (lHint)
- {
- case UPDATE_ADD:
- if (!pHint) break;
- AddSession((CSession *)pHint);
- return;
- case UPDATE_MODIFY:
- if (!pHint) break;
-
- session = (CSession *)pHint;
-
- fi.flags = LVFI_PARAM;
- fi.lParam = (DWORD) session;
-
- if ((res = list.FindItem(&fi)) != -1)
- UpdateSession(res, session);
- return;
-
- case UPDATE_REMOVE:
- if (!pHint) break;
-
- items = (CPtrArray *)pHint;
- count = items -> GetSize();
- fi.flags = LVFI_PARAM;
-
- for (i = 0; i < count; i++)
- {
- session = (CSession *) items -> GetAt(i);
- fi.lParam = (DWORD) session;
- if ((res = list.FindItem(&fi)) != -1)
- list.DeleteItem(res);
- delete session;
- }
- delete pHint;
- return;
-
- case UPDATE_MOVE:
- if (!pHint) break;
-
- ditems = (CDWordArray *)pHint;
- int item1 = ditems -> GetAt(0);
- int item2 = ditems -> GetAt(1);
- CSession *item1session = (CSession *)list.GetItemData(item1);
- CSession *item2session = (CSession *)list.GetItemData(item2);
- UpdateSession(item1, item2session);
- UpdateSession(item2, item1session);
- list.SetItemState(item1, 0, LVIS_SELECTED | LVIS_FOCUSED);
- list.SetItemState(item2, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
- delete ditems;
-
- return;
- }
-
- list.DeleteAllItems();
- for (i = 0; i < pDoc -> sessions.GetSize(); i++)
- AddSession((CSession *)pDoc -> sessions.GetAt(i));
- }
-
- void CMirrorItView::OnSessionAdd()
- {
- CMirrorItDoc *pDoc = GetDocument();
- pDoc -> AddSession();
- }
-
-
- void CMirrorItView::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
-
- int i = GetListCtrl().HitTest(point);
- if (i != -1)
- {
- CMirrorItDoc *pDoc = GetDocument();
- pDoc -> PropertiesSession(i);
- }
- CListView::OnLButtonDblClk(nFlags, point);
- }
-
-
-
- void CMirrorItView::OnUpdateSessionMovedown(CCmdUI* pCmdUI)
- {
- pCmdUI -> Enable(GetListCtrl().GetSelectedCount() == 1 &&
- GetListCtrl().GetItemCount() > 1);
- }
-
- void CMirrorItView::OnSessionMovedown()
- {
- CListCtrl & list = GetListCtrl();
-
- int selcount = list.GetSelectedCount();
- if (selcount < 1 || list.GetItemCount() < 1) return;
-
- CMirrorItDoc *pDoc = GetDocument();
- pDoc -> MovedownSession(list);
- }
-
- void CMirrorItView::OnSessionMoveup()
- {
- CListCtrl & list = GetListCtrl();
-
- int selcount = list.GetSelectedCount();
- if (selcount < 1 || list.GetItemCount() < 1) return;
-
- CMirrorItDoc *pDoc = GetDocument();
- pDoc -> MoveupSession(list);
- }
-
- void CMirrorItView::OnUpdateSessionMoveup(CCmdUI* pCmdUI)
- {
- pCmdUI -> Enable(GetListCtrl().GetSelectedCount() == 1 &&
- GetListCtrl().GetItemCount() > 1);
- }
-
- void CMirrorItView::OnUpdateSessionStart(CCmdUI* pCmdUI)
- {
- pCmdUI -> Enable(GetListCtrl().GetItemCount());
- }
-
- void CMirrorItView::OnSessionStart()
- {
- CMirrorItDoc *pDoc = GetDocument();
-
- pDoc -> StartSession();
- }
-
- void CMirrorItView::OnUpdateEditCopyCut(CCmdUI* pCmdUI)
- {
- // CG: This function was added by the Clipboard Assistant component
- pCmdUI->Enable(IsSelected());
- }
-
- void CMirrorItView::OnUpdateEditPaste(CCmdUI* pCmdUI)
- {
- // CG: This function was added by the Clipboard Assistant component
- pCmdUI->Enable(::IsClipboardFormatAvailable(m_nClipboardFormat));
- }
-
- void CMirrorItView::OnEditCopy()
- {
- // CG: This block was added by the Clipboard Assistant component
- {
- CSharedFile memFile;
- CArchive ar(&memFile, CArchive::store|CArchive::bNoFlushOnDelete);
-
- // serialize data to archive object
- DoCutCopyPaste(ar, FALSE);
-
- ar.Flush();
-
- HGLOBAL hData = memFile.Detach();
- if (OpenClipboard())
- {
- ::SetClipboardData(m_nClipboardFormat, hData);
- CloseClipboard();
- }
- else
- AfxMessageBox(CG_IDS_CANNOT_OPEN_CLIPBOARD);
- }
- }
-
- void CMirrorItView::OnEditCut()
- {
- // CG: This block was added by the Clipboard Assistant component
- {
- CSharedFile memFile;
- CArchive ar(&memFile, CArchive::store|CArchive::bNoFlushOnDelete);
-
- // serialize data to archive object
- DoCutCopyPaste(ar, TRUE);
-
- ar.Flush();
-
- HGLOBAL hData = memFile.Detach();
- if (OpenClipboard())
- {
- ::SetClipboardData(m_nClipboardFormat, hData);
- CloseClipboard();
- }
- else
- AfxMessageBox(CG_IDS_CANNOT_OPEN_CLIPBOARD);
- }
- }
-
- void CMirrorItView::OnEditPaste()
- {
- // CG: This block was added by the Clipboard Assistant component
- {
- if (OpenClipboard())
- {
- HANDLE hData = ::GetClipboardData(m_nClipboardFormat);
- if (hData != NULL)
- {
- CSharedFile memFile;
- memFile.SetHandle(hData,FALSE);
- CArchive ar(&memFile, CArchive::load);
-
- // serialize data to document
- DoCutCopyPaste(ar, FALSE);
- ar.Close();
- memFile.Detach();
- }
- else
- AfxMessageBox(CG_IDS_CANNOT_GET_CLIPBOARD_DATA);
- CloseClipboard();
- }
- else
- AfxMessageBox(CG_IDS_CANNOT_OPEN_CLIPBOARD);
- }
-
- }
-
- BOOL CMirrorItView::IsSelected()
- {
-
- // TODO: Add/Replace code to selectively enable and disable the copy
- // and cut menu items. Return TRUE when one or more items are
- // selected, and return FALSE when no items are selected.
- return GetListCtrl().GetSelectedCount() > 0;
- }
-
- void CMirrorItView::DoCutCopyPaste(CArchive &ar, BOOL bCut)
- {
-
- // TODO: Add/Replace code to copy the currently selected data to or
- // from the clipboard, via the CArchive object. Note:
- // ar.IsStoring() set to TRUE indicates a copy or cut operation.
-
- ((CMirrorItDoc *) GetDocument()) -> m_ClipboardOperation = TRUE;
- GetDocument()->Serialize(ar);
-
- if (bCut)
- {
- ASSERT(ar.IsStoring()); // no cutting on paste operation
-
- // TODO: Add/Replace code to delete the currently selected items.
-
- GetDocument()->DeleteContents();
- }
-
- // updated view and flag as modified if cut or paste operation
- if (!(ar.IsStoring() && !bCut))
- {
- GetDocument()->UpdateAllViews(NULL);
- GetDocument()->SetModifiedFlag();
- }
- ((CMirrorItDoc *) GetDocument()) -> m_ClipboardOperation = FALSE;
- }
-