CopyProperties.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. // CopyProperties.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "cp_main.h"
  5. #include "CopyProperties.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CCopyProperties dialog
  13. CCopyProperties::CCopyProperties(long lCopyID, CWnd* pParent /*=NULL*/)
  14. : CDialog(CCopyProperties::IDD, pParent)
  15. {
  16. m_lCopyID = lCopyID;
  17. m_bDeletedData = false;
  18. m_bChangedText = false;
  19. m_bHandleKillFocus = false;
  20. m_bHideOnKillFocus = false;
  21. //{{AFX_DATA_INIT(CCopyProperties)
  22. m_eDisplayText = _T("");
  23. m_eDate = _T("");
  24. m_bNeverAutoDelete = FALSE;
  25. //}}AFX_DATA_INIT
  26. }
  27. void CCopyProperties::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CCopyProperties)
  31. DDX_Control(pDX, IDC_HOTKEY, m_HotKey);
  32. DDX_Control(pDX, IDC_COPY_DATA, m_lCopyData);
  33. DDX_Text(pDX, IDC_EDIT_DISPLAY_TEXT, m_eDisplayText);
  34. DDV_MaxChars(pDX, m_eDisplayText, 250);
  35. DDX_Text(pDX, IDC_DATE, m_eDate);
  36. DDX_Check(pDX, IDC_NEVER_AUTO_DELETE, m_bNeverAutoDelete);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CCopyProperties, CDialog)
  40. //{{AFX_MSG_MAP(CCopyProperties)
  41. ON_BN_CLICKED(IDC_DELETE_COPY_DATA, OnDeleteCopyData)
  42. ON_WM_ACTIVATE()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CCopyProperties message handlers
  47. BOOL CCopyProperties::OnInitDialog()
  48. {
  49. CDialog::OnInitDialog();
  50. m_MainTable.Open("SELECT * FROM Main WHERE lID = %d", m_lCopyID);
  51. if(!m_MainTable.IsEOF())
  52. {
  53. CTime time(m_MainTable.m_lDate);
  54. m_eDate = time.Format("%m/%d/%Y %I:%M %p");
  55. m_eDisplayText = m_MainTable.m_strText;
  56. if(m_MainTable.m_lDontAutoDelete)
  57. {
  58. m_bNeverDelete = TRUE;
  59. m_bNeverAutoDelete = TRUE;
  60. }
  61. else
  62. {
  63. m_bNeverAutoDelete = FALSE;
  64. m_bNeverDelete = FALSE;
  65. }
  66. m_HotKey.SetHotKey(LOBYTE(m_MainTable.m_lShortCut), HIBYTE(m_MainTable.m_lShortCut));
  67. m_HotKey.SetRules(HKCOMB_A, 0);
  68. CString cs;
  69. cs.Format("SELECT * FROM Data WHERE lParentID = %d", m_MainTable.m_lID);
  70. m_DataTable.Open(AFX_DAO_USE_DEFAULT_TYPE, cs ,NULL);
  71. while(!m_DataTable.IsEOF())
  72. {
  73. cs.Format("%s, %d", m_DataTable.m_strClipBoardFormat, m_DataTable.m_ooData.m_dwDataLength);
  74. int nIndex = m_lCopyData.AddString(cs);
  75. m_lCopyData.SetItemData(nIndex, m_DataTable.m_lID);
  76. m_DataTable.MoveNext();
  77. }
  78. }
  79. UpdateData(FALSE);
  80. SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
  81. m_HotKey.SetFocus();
  82. return FALSE;
  83. }
  84. void CCopyProperties::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
  85. {
  86. CDialog::OnActivate(nState, pWndOther, bMinimized);
  87. if (nState == WA_INACTIVE)
  88. {
  89. if(m_bHideOnKillFocus)
  90. {
  91. if(!m_bHandleKillFocus)
  92. {
  93. EndDialog(-1);
  94. m_bHandleKillFocus = false;
  95. }
  96. }
  97. }
  98. else if (nState == WA_ACTIVE)
  99. {
  100. SetFocus();
  101. ::SetForegroundWindow(m_hWnd);
  102. }
  103. }
  104. void CCopyProperties::OnOK()
  105. {
  106. UpdateData();
  107. bool bUpdate = false;
  108. long lHotKey = m_HotKey.GetHotKey();
  109. if(lHotKey != m_MainTable.m_lShortCut)
  110. {
  111. if(lHotKey > 0)
  112. {
  113. CMainTable recset;
  114. recset.Open("SELECT * FROM Main WHERE lShortCut = %d", lHotKey);
  115. if(!recset.IsEOF())
  116. {
  117. CString cs;
  118. cs.Format("The shortcut is currently assigned to \n\n%s\n\nAssign to new copy item?", recset.m_strText);
  119. if(MessageBox(cs, "Ditto", MB_YESNO) == IDNO)
  120. return;
  121. recset.Edit();
  122. recset.m_lShortCut = 0;
  123. recset.Update();
  124. }
  125. }
  126. if(!bUpdate)
  127. m_MainTable.Edit();
  128. m_MainTable.m_lShortCut = lHotKey;
  129. bUpdate = true;
  130. }
  131. if(m_eDisplayText != m_MainTable.m_strText)
  132. {
  133. if(!bUpdate)
  134. m_MainTable.Edit();
  135. m_bChangedText = true;
  136. m_MainTable.m_strText = m_eDisplayText;
  137. bUpdate = true;
  138. }
  139. if(m_bNeverAutoDelete != m_bNeverDelete)
  140. {
  141. if(!bUpdate)
  142. m_MainTable.Edit();
  143. if(m_bNeverAutoDelete)
  144. m_MainTable.m_lDontAutoDelete = (long)CTime::GetCurrentTime().GetTime();
  145. else
  146. m_MainTable.m_lDontAutoDelete = 0;
  147. bUpdate = true;
  148. }
  149. if(m_bDeletedData)
  150. {
  151. m_DeletedData.SortAscending();
  152. long lNewTotalSize = 0;
  153. //Go through the data table and find the deleted items
  154. m_DataTable.MoveFirst();
  155. while(!m_DataTable.IsEOF())
  156. {
  157. if(m_DeletedData.Find(m_DataTable.m_lID))
  158. m_DataTable.Delete();
  159. else
  160. lNewTotalSize += m_DataTable.m_ooData.m_dwDataLength;
  161. m_DataTable.MoveNext();
  162. }
  163. if(lNewTotalSize > 0)
  164. {
  165. if(!bUpdate)
  166. m_MainTable.Edit();
  167. m_MainTable.m_lTotalCopySize = lNewTotalSize;
  168. bUpdate = true;
  169. }
  170. }
  171. if(bUpdate)
  172. m_MainTable.Update();
  173. m_bHandleKillFocus = true;
  174. CDialog::OnOK();
  175. }
  176. void CCopyProperties::OnDeleteCopyData()
  177. {
  178. int nCount = m_lCopyData.GetSelCount();
  179. if(nCount)
  180. {
  181. m_bDeletedData = true;
  182. //Get the selected indexes
  183. ARRAY items;
  184. items.SetSize(nCount);
  185. m_lCopyData.GetSelItems(nCount, items.GetData());
  186. items.SortDescending();
  187. //Get the selected itemdata
  188. for(int i = 0; i < nCount; i++)
  189. {
  190. m_DeletedData.Add(m_lCopyData.GetItemData(items[i]));
  191. m_lCopyData.DeleteString(items[i]);
  192. }
  193. }
  194. }
  195. void CCopyProperties::OnCancel()
  196. {
  197. m_bHandleKillFocus = true;
  198. CDialog::OnCancel();
  199. }