OptionsQuickPaste.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. // OptionsQuickPaste.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "OptionsQuickPaste.h"
  6. #include ".\optionsquickpaste.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define DEFAULT_THEME _T("(Default)")
  13. /////////////////////////////////////////////////////////////////////////////
  14. // COptionsQuickPaste property page
  15. IMPLEMENT_DYNCREATE(COptionsQuickPaste, CPropertyPage)
  16. COptionsQuickPaste::COptionsQuickPaste() : CPropertyPage(COptionsQuickPaste::IDD)
  17. {
  18. m_csTitle = theApp.m_Language.GetString("QuickPasteTitle", "Quick Paste");
  19. m_psp.pszTitle = m_csTitle;
  20. m_psp.dwFlags |= PSP_USETITLE;
  21. //{{AFX_DATA_INIT(COptionsQuickPaste)
  22. // NOTE: the ClassWizard will add member initialization here
  23. //}}AFX_DATA_INIT
  24. memset(&m_LogFont, 0, sizeof(LOGFONT));
  25. }
  26. COptionsQuickPaste::~COptionsQuickPaste()
  27. {
  28. m_Font.DeleteObject();
  29. }
  30. void COptionsQuickPaste::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CPropertyPage::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(COptionsQuickPaste)
  34. DDX_Control(pDX, IDC_CHECK_ENTIRE_WINDOW_IS_VISIBLE, m_EnsureEntireWindowVisible);
  35. DDX_Control(pDX, IDC_CHECK_SHOW_ALL_IN_MAIN_LIST, m_ShowAllInMainList);
  36. DDX_Control(pDX, IDC_CHECK_FIND_AS_YOU_TYPE, m_FindAsYouType);
  37. DDX_Control(pDX, IDC_DRAW_RTF, m_btDrawRTF);
  38. DDX_Control(pDX, IDC_SHOW_THUMBNAILS, m_btShowThumbnails);
  39. DDX_Control(pDX, IDC_BUTTON_DEFAULT_FAULT, m_btDefaultButton);
  40. DDX_Control(pDX, IDC_BUTTON_FONT, m_btFont);
  41. DDX_Control(pDX, IDC_SHOW_TEXT_FOR_FIRST_TEN_HOT_KEYS, m_btShowText);
  42. DDX_Control(pDX, IDC_LINES_ROW, m_eLinesPerRow);
  43. DDX_Control(pDX, IDC_TRANS_PERC, m_eTransparencyPercent);
  44. DDX_Control(pDX, IDC_TRANSPARENCY, m_btEnableTransparency);
  45. DDX_Control(pDX, IDC_DESC_SHOW_LEADING_WHITESPACE, m_btDescShowLeadingWhiteSpace);
  46. //}}AFX_DATA_MAP
  47. DDX_Control(pDX, IDC_CHECK_PROMPT_DELETE_CLIP, m_PromptForDelete);
  48. DDX_Control(pDX, IDC_COMBO_THEME, m_cbTheme);
  49. DDX_Control(pDX, IDC_CHECK_SHOW_SCROLL_BAR, m_alwaysShowScrollBar);
  50. DDX_Control(pDX, IDC_CHECK_ELEVATE_PRIVILEGES, m_elevatedPrivileges);
  51. DDX_Control(pDX, IDC_CHECK_SHOW_IN_TASKBAR, m_showInTaskBar);
  52. DDX_Control(pDX, IDC_EDIT_DIFF_PATH, m_diffPathEditBox);
  53. }
  54. BEGIN_MESSAGE_MAP(COptionsQuickPaste, CPropertyPage)
  55. //{{AFX_MSG_MAP(COptionsQuickPaste)
  56. ON_BN_CLICKED(IDC_BUTTON_FONT, OnButtonFont)
  57. ON_BN_CLICKED(IDC_BUTTON_DEFAULT_FAULT, OnButtonDefaultFault)
  58. //}}AFX_MSG_MAP
  59. ON_BN_CLICKED(IDC_BUTTON_THEME, OnBnClickedButtonTheme)
  60. ON_BN_CLICKED(IDC_BUTTON_DIFF_BROWSE, &COptionsQuickPaste::OnBnClickedButtonDiffBrowse)
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // COptionsQuickPaste message handlers
  64. BOOL COptionsQuickPaste::OnInitDialog()
  65. {
  66. CPropertyPage::OnInitDialog();
  67. m_pParent = (COptionsSheet *)GetParent();
  68. m_btEnableTransparency.SetCheck(CGetSetOptions::GetEnableTransparency());
  69. m_eTransparencyPercent.SetNumber(CGetSetOptions::GetTransparencyPercent());
  70. m_eLinesPerRow.SetNumber(CGetSetOptions::GetLinesPerRow());
  71. m_alwaysShowScrollBar.SetCheck(CGetSetOptions::GetShowScrollBar());
  72. m_btShowThumbnails.SetCheck(g_Opt.m_bDrawThumbnail);
  73. m_btDrawRTF.SetCheck(g_Opt.m_bDrawRTF);
  74. m_EnsureEntireWindowVisible.SetCheck(g_Opt.m_bEnsureEntireWindowCanBeSeen);
  75. m_ShowAllInMainList.SetCheck(g_Opt.m_bShowAllClipsInMainList);
  76. m_FindAsYouType.SetCheck(g_Opt.m_bFindAsYouType);
  77. if(CGetSetOptions::GetQuickPastePosition() == POS_AT_CARET)
  78. CheckDlgButton(IDC_AT_CARET, BST_CHECKED);
  79. else if(CGetSetOptions::GetQuickPastePosition() == POS_AT_CURSOR)
  80. CheckDlgButton(IDC_AT_CURSOR, BST_CHECKED);
  81. else if(CGetSetOptions::GetQuickPastePosition() == POS_AT_PREVIOUS)
  82. CheckDlgButton(IDC_AT_PREVIOUS, BST_CHECKED);
  83. m_btDescShowLeadingWhiteSpace.SetCheck(g_Opt.m_bDescShowLeadingWhiteSpace);
  84. m_btShowText.SetCheck(CGetSetOptions::GetShowTextForFirstTenHotKeys());
  85. m_PromptForDelete.SetCheck(CGetSetOptions::GetPromptWhenDeletingClips());
  86. m_elevatedPrivileges.SetCheck(CGetSetOptions::GetPasteAsAdmin());
  87. m_showInTaskBar.SetCheck(CGetSetOptions::GetShowInTaskBar());
  88. if(CGetSetOptions::GetFont(m_LogFont))
  89. {
  90. m_Font.CreateFontIndirect(&m_LogFont);
  91. m_btFont.SetFont(&m_Font);
  92. }
  93. else
  94. {
  95. CFont *ft = m_btFont.GetFont();
  96. ft->GetLogFont(&m_LogFont);
  97. }
  98. m_diffPathEditBox.SetWindowText(CGetSetOptions::GetDiffApp());
  99. CString cs;
  100. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  101. m_btFont.SetWindowText(cs);
  102. if (CGetSetOptions::GetShowIfClipWasPasted())
  103. CheckDlgButton(IDC_CHECK_SHOW_CLIP_WAS_PASTED, BST_CHECKED);
  104. FillThemes();
  105. theApp.m_Language.UpdateOptionQuickPaste(this);
  106. return FALSE;
  107. }
  108. BOOL COptionsQuickPaste::OnApply()
  109. {
  110. CGetSetOptions::SetEnableTransparency(m_btEnableTransparency.GetCheck());
  111. CGetSetOptions::SetTransparencyPercent(m_eTransparencyPercent.GetNumber());
  112. CGetSetOptions::SetLinesPerRow(m_eLinesPerRow.GetNumber());
  113. CGetSetOptions::SetShowScrollBar(m_alwaysShowScrollBar.GetCheck());
  114. if(IsDlgButtonChecked(IDC_AT_CARET))
  115. CGetSetOptions::SetQuickPastePosition(POS_AT_CARET);
  116. else if(IsDlgButtonChecked(IDC_AT_CURSOR))
  117. CGetSetOptions::SetQuickPastePosition(POS_AT_CURSOR);
  118. else if(IsDlgButtonChecked(IDC_AT_PREVIOUS))
  119. CGetSetOptions::SetQuickPastePosition(POS_AT_PREVIOUS);
  120. g_Opt.SetDescShowLeadingWhiteSpace(m_btDescShowLeadingWhiteSpace.GetCheck());
  121. CGetSetOptions::SetShowTextForFirstTenHotKeys(m_btShowText.GetCheck());
  122. CGetSetOptions::SetDrawThumbnail(m_btShowThumbnails.GetCheck());
  123. CGetSetOptions::SetDrawRTF(m_btDrawRTF.GetCheck());
  124. CGetSetOptions::SetEnsureEntireWindowCanBeSeen(m_EnsureEntireWindowVisible.GetCheck());
  125. CGetSetOptions::SetShowAllClipsInMainList(m_ShowAllInMainList.GetCheck());
  126. CGetSetOptions::SetFindAsYouType(m_FindAsYouType.GetCheck());
  127. CGetSetOptions::SetPromptWhenDeletingClips(m_PromptForDelete.GetCheck());
  128. CGetSetOptions::SetPasteAsAdmin(m_elevatedPrivileges.GetCheck());
  129. BOOL prevValue = CGetSetOptions::GetShowInTaskBar();
  130. CGetSetOptions::SetShowInTaskBar(m_showInTaskBar.GetCheck());
  131. if(CGetSetOptions::GetShowInTaskBar() != prevValue)
  132. {
  133. theApp.RefreshShowInTaskBar();
  134. }
  135. if(m_LogFont.lfWeight != 0)
  136. {
  137. CGetSetOptions::SetFont(m_LogFont);
  138. }
  139. CString currentTheme = g_Opt.GetTheme();
  140. CString csTheme;
  141. if(m_cbTheme.GetCurSel() >= 0)
  142. {
  143. m_cbTheme.GetLBText(m_cbTheme.GetCurSel(), csTheme);
  144. if (csTheme == DEFAULT_THEME)
  145. {
  146. g_Opt.SetTheme("");
  147. csTheme = _T("");
  148. }
  149. else
  150. g_Opt.SetTheme(csTheme);
  151. }
  152. else
  153. {
  154. g_Opt.SetTheme("");
  155. }
  156. if (currentTheme != csTheme)
  157. {
  158. m_pParent->m_themeChanged = TRUE;
  159. }
  160. CString diffPath;
  161. m_diffPathEditBox.GetWindowText(diffPath);
  162. g_Opt.SetDiffApp(diffPath);
  163. if (IsDlgButtonChecked(IDC_CHECK_SHOW_CLIP_WAS_PASTED))
  164. CGetSetOptions::SetShowIfClipWasPasted(TRUE);
  165. else
  166. CGetSetOptions::SetShowIfClipWasPasted(FALSE);
  167. return CPropertyPage::OnApply();
  168. }
  169. void COptionsQuickPaste::OnButtonFont()
  170. {
  171. CFontDialog dlg(&m_LogFont, (CF_TTONLY | CF_SCREENFONTS), 0, this);
  172. if(dlg.DoModal() == IDOK)
  173. {
  174. m_Font.DeleteObject();
  175. memcpy(&m_LogFont, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
  176. m_Font.CreateFontIndirect(&m_LogFont);
  177. m_btFont.SetFont(&m_Font);
  178. CString cs;
  179. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  180. m_btFont.SetWindowText(cs);
  181. }
  182. }
  183. void COptionsQuickPaste::OnButtonDefaultFault()
  184. {
  185. CFont *ft = m_btDefaultButton.GetFont();
  186. ft->GetLogFont(&m_LogFont);
  187. memset(&m_LogFont, 0, sizeof(m_LogFont));
  188. m_LogFont.lfHeight = -10;
  189. m_LogFont.lfWeight = 400;
  190. m_LogFont.lfCharSet = 1;
  191. STRCPY(m_LogFont.lfFaceName, _T("Segoe UI"));
  192. m_Font.DeleteObject();
  193. m_Font.CreateFontIndirect(&m_LogFont);
  194. m_btFont.SetFont(&m_Font);
  195. CString cs;
  196. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  197. m_btFont.SetWindowText(cs);
  198. }
  199. void COptionsQuickPaste::FillThemes()
  200. {
  201. CString csFile = CGetSetOptions::GetPath(PATH_THEMES);
  202. csFile += "*.xml";
  203. CString csTheme = CGetSetOptions::GetTheme();
  204. CFileFind find;
  205. BOOL bCont = find.FindFile(csFile);
  206. bool bSetCurSel = false;
  207. while(bCont)
  208. {
  209. bCont = find.FindNextFile();
  210. CTheme theme;
  211. if (theme.Load(find.GetFileTitle(), true, false))
  212. {
  213. if (theme.FileVersion() >= 2 && theme.FileVersion() < 100)
  214. {
  215. int nIndex = m_cbTheme.AddString(find.GetFileTitle());
  216. if (find.GetFileTitle() == csTheme)
  217. {
  218. m_cbTheme.SetCurSel(nIndex);
  219. bSetCurSel = true;
  220. }
  221. }
  222. }
  223. }
  224. int nIndex = m_cbTheme.AddString(DEFAULT_THEME);
  225. if(bSetCurSel == false)
  226. {
  227. m_cbTheme.SetCurSel(nIndex);
  228. }
  229. }
  230. void COptionsQuickPaste::OnBnClickedButtonTheme()
  231. {
  232. CTheme theme;
  233. CString csTheme;
  234. m_cbTheme.GetLBText(m_cbTheme.GetCurSel(), csTheme);
  235. if(csTheme == DEFAULT_THEME)
  236. return;
  237. if(theme.Load(csTheme, true, false))
  238. {
  239. CString csMessage;
  240. csMessage.Format(_T("Theme - %s\n")
  241. _T("Version - %d\n")
  242. _T("Author - %s\n")
  243. _T("Notes - %s"), csTheme,
  244. theme.FileVersion(),
  245. theme.Author(),
  246. theme.Notes());
  247. MessageBox(csMessage, _T("Ditto"), MB_OK);
  248. }
  249. else
  250. {
  251. CString csError;
  252. csError.Format(_T("Error loading theme file - %s - reason = "), csTheme, theme.LastError());
  253. MessageBox(csError, _T("Ditto"), MB_OK);
  254. }
  255. }
  256. void COptionsQuickPaste::OnBnClickedButtonDiffBrowse()
  257. {
  258. OPENFILENAME FileName;
  259. TCHAR szFileName[400];
  260. TCHAR szDir[400];
  261. memset(&FileName, 0, sizeof(FileName));
  262. memset(szFileName, 0, sizeof(szFileName));
  263. memset(&szDir, 0, sizeof(szDir));
  264. FileName.lStructSize = sizeof(FileName);
  265. FileName.lpstrTitle = _T("Diff Application");
  266. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR;
  267. FileName.nMaxFile = 400;
  268. FileName.lpstrFile = szFileName;
  269. FileName.lpstrInitialDir = szDir;
  270. FileName.lpstrFilter = _T("*.exe");
  271. FileName.lpstrDefExt = _T("");
  272. FileName.hwndOwner = m_hWnd;
  273. if(GetOpenFileName(&FileName) == 0)
  274. return;
  275. CString csPath(FileName.lpstrFile);
  276. m_diffPathEditBox.SetWindowText(csPath);
  277. }