| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 | 
							- // CopyProperties.cpp : implementation file
 
- //
 
- #include "stdafx.h"
 
- #include "cp_main.h"
 
- #include "CopyProperties.h"
 
- #include ".\copyproperties.h"
 
- #ifdef _DEBUG
 
- #define new DEBUG_NEW
 
- #undef THIS_FILE
 
- static char THIS_FILE[] = __FILE__;
 
- #endif
 
- /////////////////////////////////////////////////////////////////////////////
 
- // CCopyProperties dialog
 
- CCopyProperties::CCopyProperties(long lCopyID, CWnd* pParent /*=NULL*/)
 
- 	: CDialog(CCopyProperties::IDD, pParent)
 
- {
 
- 	m_lCopyID = lCopyID;
 
- 	m_bDeletedData = false;
 
- 	m_bChangedText = false;
 
- 	m_bHandleKillFocus = false;
 
- 	m_bHideOnKillFocus = false;
 
- 	m_lGroupChangedTo = -1;
 
- 	//{{AFX_DATA_INIT(CCopyProperties)
 
- 	m_eDisplayText = _T("");
 
- 	m_eDate = _T("");
 
- 	m_bNeverAutoDelete = FALSE;
 
- 	//}}AFX_DATA_INIT
 
- }
 
- void CCopyProperties::DoDataExchange(CDataExchange* pDX)
 
- {
 
- 	CDialog::DoDataExchange(pDX);
 
- 	//{{AFX_DATA_MAP(CCopyProperties)
 
- 	DDX_Control(pDX, IDC_COMBO1, m_GroupCombo);
 
- 	DDX_Control(pDX, IDC_HOTKEY, m_HotKey);
 
- 	DDX_Control(pDX, IDC_COPY_DATA, m_lCopyData);
 
- 	DDX_Text(pDX, IDC_EDIT_DISPLAY_TEXT, m_eDisplayText);
 
- 	DDV_MaxChars(pDX, m_eDisplayText, 250);
 
- 	DDX_Text(pDX, IDC_DATE, m_eDate);
 
- 	DDX_Check(pDX, IDC_NEVER_AUTO_DELETE, m_bNeverAutoDelete);
 
- 	//}}AFX_DATA_MAP
 
- 	DDX_Control(pDX, IDC_PARSE_EDIT, m_ParseEdit);
 
- 	DDX_Control(pDX, IDC_PARSE_BUTTON, m_ParseButton);
 
- 	DDX_Control(pDX, IDC_EDIT_DISPLAY_TEXT, m_DisplayTextEdit);
 
- }
 
- BEGIN_MESSAGE_MAP(CCopyProperties, CDialog)
 
- 	//{{AFX_MSG_MAP(CCopyProperties)
 
- 	ON_BN_CLICKED(IDC_DELETE_COPY_DATA, OnDeleteCopyData)
 
- 	ON_WM_ACTIVATE()
 
- 	//}}AFX_MSG_MAP
 
- 	ON_BN_CLICKED(IDC_PARSE_BUTTON, OnBnClickedParseButton)
 
- END_MESSAGE_MAP()
 
- /////////////////////////////////////////////////////////////////////////////
 
- // CCopyProperties message handlers
 
- BOOL CCopyProperties::OnInitDialog() 
 
- {
 
- 	CDialog::OnInitDialog();
 
- 	m_ParseEdit.SetWindowText("\\r\\n");
 
- 	m_GroupCombo.FillCombo();
 
- 	m_MainTable.Open("SELECT * FROM Main WHERE lID = %d", m_lCopyID);
 
- 	if(!m_MainTable.IsEOF())
 
- 	{
 
- 		CTime time(m_MainTable.m_lDate);
 
- 		m_eDate = time.Format("%m/%d/%Y %I:%M %p");
 
- 		m_eDisplayText = m_MainTable.m_strText;
 
- 		if(m_MainTable.m_lDontAutoDelete)
 
- 		{
 
- 			m_bNeverDelete = TRUE;
 
- 			m_bNeverAutoDelete = TRUE;
 
- 		}
 
- 		else
 
- 		{
 
- 			m_bNeverAutoDelete = FALSE;
 
- 			m_bNeverDelete = FALSE;
 
- 		}
 
- 		m_GroupCombo.SetCurSelOnItemData(m_MainTable.m_lParentID);
 
- 		m_HotKey.SetHotKey(LOBYTE(m_MainTable.m_lShortCut), HIBYTE(m_MainTable.m_lShortCut));
 
- 		m_HotKey.SetRules(HKCOMB_A, 0);
 
- 		CString cs;
 
- 		cs.Format("SELECT * FROM Data WHERE lDataID = %d", m_MainTable.m_lDataID);
 
- 		m_DataTable.Open(AFX_DAO_USE_DEFAULT_TYPE, cs ,NULL);
 
- 		while(!m_DataTable.IsEOF())
 
- 		{
 
- 			cs.Format("%s, %d", m_DataTable.m_strClipBoardFormat, m_DataTable.m_ooData.m_dwDataLength);
 
- 			int nIndex = m_lCopyData.AddString(cs);
 
- 			m_lCopyData.SetItemData(nIndex, m_DataTable.m_lID);
 
- 			m_DataTable.MoveNext();
 
- 		}
 
- 	}
 
- 	
 
- 	UpdateData(FALSE);
 
- 	SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
 
- 	// if this is a result of a NamedCopy, focus on the hotkey
 
- 	if( theApp.m_bShowCopyProperties )
 
- 		m_HotKey.SetFocus();
 
- 	else
 
- 		m_DisplayTextEdit.SetFocus();
 
- 	return FALSE;
 
- }
 
- void CCopyProperties::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
 
- {
 
- 	CDialog::OnActivate(nState, pWndOther, bMinimized);
 
- 	if (nState == WA_INACTIVE)
 
- 	{
 
- 		if(m_bHideOnKillFocus)
 
- 		{
 
- 			if(!m_bHandleKillFocus)
 
- 			{
 
- 				EndDialog(-1);
 
- 				m_bHandleKillFocus = false;
 
- 			}
 
- 		}
 
- 	}
 
- 	else if (nState == WA_ACTIVE)
 
- 	{
 
- 		SetFocus();
 
- 		::SetForegroundWindow(m_hWnd);
 
- 	}
 
- }
 
- void CCopyProperties::OnOK() 
 
- {
 
- 	UpdateData();
 
- 	bool bUpdate = false;
 
- 	long lHotKey = m_HotKey.GetHotKey();
 
- 		
 
- 	if(lHotKey != m_MainTable.m_lShortCut)
 
- 	{
 
- 		if(lHotKey > 0)
 
- 		{
 
- 			CMainTable recset;
 
- 			recset.Open("SELECT * FROM Main WHERE lShortCut = %d", lHotKey);
 
- 			if(!recset.IsEOF())
 
- 			{
 
- 				CString cs;
 
- 				cs.Format("The shortcut is currently assigned to \n\n%s\n\nAssign to new copy item?", recset.m_strText);
 
- 				if(MessageBox(cs, "Ditto", MB_YESNO) == IDNO)
 
- 					return;
 
- 				recset.Edit();
 
- 				recset.m_lShortCut = 0;
 
- 				recset.Update();
 
- 			}
 
- 		}
 
- 		if(!bUpdate)
 
- 			m_MainTable.Edit();
 
- 		m_MainTable.m_lShortCut = lHotKey;
 
- 		bUpdate = true;
 
- 	}
 
- 	if(m_eDisplayText != m_MainTable.m_strText)
 
- 	{
 
- 		if(!bUpdate)
 
- 			m_MainTable.Edit();
 
- 		m_bChangedText = true;
 
- 		m_MainTable.m_strText = m_eDisplayText;
 
- 		bUpdate = true;
 
- 	}
 
- 	if(m_bNeverAutoDelete != m_bNeverDelete)
 
- 	{
 
- 		if(!bUpdate)
 
- 			m_MainTable.Edit();
 
- 		if(m_bNeverAutoDelete)
 
- 			m_MainTable.m_lDontAutoDelete = (long)CTime::GetCurrentTime().GetTime();
 
- 		else
 
- 			m_MainTable.m_lDontAutoDelete = 0;
 
- 		bUpdate = true;
 
- 	}
 
- 	int nParentID = m_GroupCombo.GetItemDataFromCursel();
 
- 	if(nParentID != m_MainTable.m_lParentID)
 
- 	{
 
- 		bool bCont = true;
 
- 		if(m_MainTable.m_bIsGroup)
 
- 		{
 
- 			if(nParentID == m_MainTable.m_lID)
 
- 				bCont = false;
 
- 		}
 
- 		if(bCont)
 
- 		{
 
- 			if(!bUpdate)
 
- 				m_MainTable.Edit();
 
- 		
 
- 			m_MainTable.m_lParentID = nParentID;
 
- 			m_MainTable.m_lDontAutoDelete = (long)CTime::GetCurrentTime().GetTime();
 
- 			m_lGroupChangedTo = nParentID;
 
- 			bUpdate = true;
 
- 		}
 
- 	}
 
- 	if(bUpdate)
 
- 		m_MainTable.Update();
 
- 	
 
- 	if(m_bDeletedData)
 
- 	{
 
- 		DeleteFormats( m_MainTable.m_lDataID, m_DeletedData );
 
- 	}
 
- 	m_bHandleKillFocus = true;
 
- 	CDialog::OnOK();
 
- }
 
- void CCopyProperties::OnDeleteCopyData() 
 
- {
 
- 	int nCount = m_lCopyData.GetSelCount();
 
- 	if(nCount)
 
- 	{
 
- 		m_bDeletedData = true;
 
- 		//Get the selected indexes
 
- 		ARRAY items;
 
- 		items.SetSize(nCount);
 
- 		m_lCopyData.GetSelItems(nCount, items.GetData()); 
 
- 		items.SortDescending();
 
- 		//Get the selected itemdata
 
- 		for(int i = 0; i < nCount; i++)
 
- 		{
 
- 			m_DeletedData.Add(m_lCopyData.GetItemData(items[i]));
 
- 			m_lCopyData.DeleteString(items[i]);
 
- 		}		
 
- 	}
 
- }
 
- void CCopyProperties::OnCancel() 
 
- {
 
- 	m_bHandleKillFocus = true;
 
- 		
 
- 	CDialog::OnCancel();
 
- }
 
- void CCopyProperties::OnBnClickedParseButton()
 
- {
 
- CPopup status(0,0,m_hWnd);
 
- 	status.Show("Parsing...");
 
- CString delims;
 
- 	m_ParseEdit.GetWindowText(delims);
 
- 	delims = RemoveEscapes( delims );
 
- 	// validate delimiters
 
- int nDelims = delims.GetLength();
 
- 	if( nDelims <= 0 )
 
- 	{
 
- 		::MessageBox( m_hWnd, "Token Delimiters are not valid.", "Parse Failure", MB_OK|MB_ICONINFORMATION );
 
- 		return;
 
- 	}
 
- 	// load the text
 
- HGLOBAL hGlobal = CClip::LoadFormat( m_lCopyID, CF_TEXT );
 
- 	if( !hGlobal )
 
- 	{
 
- 		::MessageBox( m_hWnd, "No CF_TEXT Format Data could be found.", "Parse Failure", MB_OK|MB_ICONINFORMATION );
 
- 		return;
 
- 	}
 
- 	// copy the text from the global into a string
 
- int nDataSize = ::GlobalSize( hGlobal );
 
- char* pData = (char*) ::GlobalLock( hGlobal );
 
- char* pDataEnd = pData + nDataSize;
 
- char* p = pData;
 
- 	ASSERT( pData != NULL && nDataSize > 0 );
 
- 	// Find the terminating NULL
 
- 	while( *p != '\0' && p < pDataEnd ) { p++; }
 
- 	// there was no NULL in the string!
 
- 	if( p >= pDataEnd )
 
- 	{
 
- 		ASSERT(0);
 
- 		return;
 
- 	}
 
- 	// copy the data into a string
 
- CString text = pData;
 
- 	// free the global
 
- 	::GlobalUnlock( hGlobal );
 
- 	::GlobalFree(hGlobal);
 
- 	// tokenize the text
 
- CString token;
 
- CStringArray tokens;
 
- CTokenizer tokenizer(text,delims);
 
- 	while( tokenizer.Next( token ) )
 
- 	{
 
- 		tokens.Add( token );
 
- 	}
 
- 	// save the tokens to the db
 
- CClip clip;
 
- int len;
 
- long lDate = (long) CTime::GetCurrentTime().GetTime();
 
- int count = tokens.GetSize();
 
- 	for( int i = 0; i < count; i++ )
 
- 	{
 
- 		status.Show( StrF("Saving Token %d out of %d", i+1, count) );
 
- 		len = tokens[i].GetLength();
 
- 		// ignore 0 length tokens
 
- 		if( len <= 0 )
 
- 			continue;
 
- 		clip.AddFormat( CF_TEXT, (void*) (LPCTSTR) tokens[i], len+1 );
 
- 		clip.m_Time = lDate;
 
- 		clip.AddToDB( false ); // false = don't check for duplicates
 
- 		clip.Clear();
 
- 		lDate++; // make sure they are sequential
 
- 	}
 
- 	if( count <= 0 )
 
- 		::MessageBox( m_hWnd, "No new tokens found by parsing", "Parse Failed", MB_OK|MB_ICONINFORMATION );
 
- 	else
 
- 	{
 
- 		::MessageBox( m_hWnd, StrF("Successfully parsed %d tokens.", tokens.GetSize()), "Parse Completed", MB_OK|MB_ICONINFORMATION );
 
- 		theApp.RefreshView();
 
- 	}
 
- }
 
 
  |