OptionsQuickPaste.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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_CTRL_CLICK, m_btUseCtrlNum);
  46. DDX_Control(pDX, IDC_DESC_SHOW_LEADING_WHITESPACE, m_btDescShowLeadingWhiteSpace);
  47. //}}AFX_DATA_MAP
  48. DDX_Control(pDX, IDC_CHECK_PROMPT_DELETE_CLIP, m_PromptForDelete);
  49. DDX_Control(pDX, IDC_COMBO_THEME, m_cbTheme);
  50. DDX_Control(pDX, IDC_CHECK_SHOW_SCROLL_BAR, m_alwaysShowScrollBar);
  51. DDX_Control(pDX, IDC_CHECK_ELEVATE_PRIVILEGES, m_elevatedPrivileges);
  52. DDX_Control(pDX, IDC_CHECK_SHOW_IN_TASKBAR, m_showInTaskBar);
  53. DDX_Control(pDX, IDC_EDIT_DIFF_PATH, m_diffPathEditBox);
  54. }
  55. BEGIN_MESSAGE_MAP(COptionsQuickPaste, CPropertyPage)
  56. //{{AFX_MSG_MAP(COptionsQuickPaste)
  57. ON_BN_CLICKED(IDC_BUTTON_FONT, OnButtonFont)
  58. ON_BN_CLICKED(IDC_BUTTON_DEFAULT_FAULT, OnButtonDefaultFault)
  59. //}}AFX_MSG_MAP
  60. ON_BN_CLICKED(IDC_BUTTON_THEME, OnBnClickedButtonTheme)
  61. ON_BN_CLICKED(IDC_BUTTON_DIFF_BROWSE, &COptionsQuickPaste::OnBnClickedButtonDiffBrowse)
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // COptionsQuickPaste message handlers
  65. BOOL COptionsQuickPaste::OnInitDialog()
  66. {
  67. CPropertyPage::OnInitDialog();
  68. m_pParent = (COptionsSheet *)GetParent();
  69. m_btEnableTransparency.SetCheck(CGetSetOptions::GetEnableTransparency());
  70. m_eTransparencyPercent.SetNumber(CGetSetOptions::GetTransparencyPercent());
  71. m_eLinesPerRow.SetNumber(CGetSetOptions::GetLinesPerRow());
  72. m_alwaysShowScrollBar.SetCheck(CGetSetOptions::GetShowScrollBar());
  73. m_btShowThumbnails.SetCheck(g_Opt.m_bDrawThumbnail);
  74. m_btDrawRTF.SetCheck(g_Opt.m_bDrawRTF);
  75. m_EnsureEntireWindowVisible.SetCheck(g_Opt.m_bEnsureEntireWindowCanBeSeen);
  76. m_ShowAllInMainList.SetCheck(g_Opt.m_bShowAllClipsInMainList);
  77. m_FindAsYouType.SetCheck(g_Opt.m_bFindAsYouType);
  78. if(CGetSetOptions::GetQuickPastePosition() == POS_AT_CARET)
  79. CheckDlgButton(IDC_AT_CARET, BST_CHECKED);
  80. else if(CGetSetOptions::GetQuickPastePosition() == POS_AT_CURSOR)
  81. CheckDlgButton(IDC_AT_CURSOR, BST_CHECKED);
  82. else if(CGetSetOptions::GetQuickPastePosition() == POS_AT_PREVIOUS)
  83. CheckDlgButton(IDC_AT_PREVIOUS, BST_CHECKED);
  84. m_btDescShowLeadingWhiteSpace.SetCheck(g_Opt.m_bDescShowLeadingWhiteSpace);
  85. m_btUseCtrlNum.SetCheck(CGetSetOptions::GetUseCtrlNumForFirstTenHotKeys());
  86. m_btShowText.SetCheck(CGetSetOptions::GetShowTextForFirstTenHotKeys());
  87. m_PromptForDelete.SetCheck(CGetSetOptions::GetPromptWhenDeletingClips());
  88. m_elevatedPrivileges.SetCheck(CGetSetOptions::GetPasteAsAdmin());
  89. m_showInTaskBar.SetCheck(CGetSetOptions::GetShowInTaskBar());
  90. if(CGetSetOptions::GetFont(m_LogFont))
  91. {
  92. m_Font.CreateFontIndirect(&m_LogFont);
  93. m_btFont.SetFont(&m_Font);
  94. }
  95. else
  96. {
  97. CFont *ft = m_btFont.GetFont();
  98. ft->GetLogFont(&m_LogFont);
  99. }
  100. m_diffPathEditBox.SetWindowText(CGetSetOptions::GetDiffApp());
  101. CString cs;
  102. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  103. m_btFont.SetWindowText(cs);
  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::SetUseCtrlNumForFirstTenHotKeys(m_btUseCtrlNum.GetCheck());
  122. CGetSetOptions::SetShowTextForFirstTenHotKeys(m_btShowText.GetCheck());
  123. CGetSetOptions::SetDrawThumbnail(m_btShowThumbnails.GetCheck());
  124. CGetSetOptions::SetDrawRTF(m_btDrawRTF.GetCheck());
  125. CGetSetOptions::SetEnsureEntireWindowCanBeSeen(m_EnsureEntireWindowVisible.GetCheck());
  126. CGetSetOptions::SetShowAllClipsInMainList(m_ShowAllInMainList.GetCheck());
  127. CGetSetOptions::SetFindAsYouType(m_FindAsYouType.GetCheck());
  128. CGetSetOptions::SetPromptWhenDeletingClips(m_PromptForDelete.GetCheck());
  129. CGetSetOptions::SetPasteAsAdmin(m_elevatedPrivileges.GetCheck());
  130. BOOL prevValue = CGetSetOptions::GetShowInTaskBar();
  131. CGetSetOptions::SetShowInTaskBar(m_showInTaskBar.GetCheck());
  132. if(CGetSetOptions::GetShowInTaskBar() != prevValue)
  133. {
  134. theApp.RefreshShowInTaskBar();
  135. }
  136. if(m_LogFont.lfWeight != 0)
  137. {
  138. CGetSetOptions::SetFont(m_LogFont);
  139. }
  140. CString csTheme;
  141. if(m_cbTheme.GetCurSel() >= 0)
  142. {
  143. m_cbTheme.GetLBText(m_cbTheme.GetCurSel(), csTheme);
  144. if(csTheme == DEFAULT_THEME)
  145. g_Opt.SetTheme("");
  146. else
  147. g_Opt.SetTheme(csTheme);
  148. }
  149. else
  150. {
  151. g_Opt.SetTheme("");
  152. }
  153. CString diffPath;
  154. m_diffPathEditBox.GetWindowText(diffPath);
  155. g_Opt.SetDiffApp(diffPath);
  156. return CPropertyPage::OnApply();
  157. }
  158. void COptionsQuickPaste::OnButtonFont()
  159. {
  160. CFontDialog dlg(&m_LogFont, (CF_TTONLY | CF_SCREENFONTS));
  161. if(dlg.DoModal() == IDOK)
  162. {
  163. m_Font.DeleteObject();
  164. memcpy(&m_LogFont, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
  165. m_Font.CreateFontIndirect(&m_LogFont);
  166. m_btFont.SetFont(&m_Font);
  167. CString cs;
  168. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  169. m_btFont.SetWindowText(cs);
  170. }
  171. }
  172. void COptionsQuickPaste::OnButtonDefaultFault()
  173. {
  174. CFont *ft = m_btDefaultButton.GetFont();
  175. ft->GetLogFont(&m_LogFont);
  176. memset(&m_LogFont, 0, sizeof(m_LogFont));
  177. m_LogFont.lfHeight = -11;
  178. m_LogFont.lfWeight = 400;
  179. m_LogFont.lfCharSet = 1;
  180. STRCPY(m_LogFont.lfFaceName, _T("Arial Unicode MS"));
  181. m_Font.DeleteObject();
  182. m_Font.CreateFontIndirect(&m_LogFont);
  183. m_btFont.SetFont(&m_Font);
  184. CString cs;
  185. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  186. m_btFont.SetWindowText(cs);
  187. }
  188. void COptionsQuickPaste::FillThemes()
  189. {
  190. CString csFile = CGetSetOptions::GetPath(PATH_THEMES);
  191. csFile += "*.xml";
  192. CString csTheme = CGetSetOptions::GetTheme();
  193. CFileFind find;
  194. BOOL bCont = find.FindFile(csFile);
  195. bool bSetCurSel = false;
  196. while(bCont)
  197. {
  198. bCont = find.FindNextFile();
  199. int nIndex = m_cbTheme.AddString(find.GetFileTitle());
  200. if(find.GetFileTitle() == csTheme)
  201. {
  202. m_cbTheme.SetCurSel(nIndex);
  203. bSetCurSel = true;
  204. }
  205. }
  206. int nIndex = m_cbTheme.AddString(DEFAULT_THEME);
  207. if(bSetCurSel == false)
  208. {
  209. m_cbTheme.SetCurSel(nIndex);
  210. }
  211. }
  212. void COptionsQuickPaste::OnBnClickedButtonTheme()
  213. {
  214. CTheme theme;
  215. CString csTheme;
  216. m_cbTheme.GetLBText(m_cbTheme.GetCurSel(), csTheme);
  217. if(csTheme == DEFAULT_THEME)
  218. return;
  219. if(theme.Load(csTheme, true, false))
  220. {
  221. CString csMessage;
  222. csMessage.Format(_T("Theme - %s\n")
  223. _T("Version - %d\n")
  224. _T("Author - %s\n")
  225. _T("Notes - %s"), csTheme,
  226. theme.FileVersion(),
  227. theme.Author(),
  228. theme.Notes());
  229. MessageBox(csMessage, _T("Ditto"), MB_OK);
  230. }
  231. else
  232. {
  233. CString csError;
  234. csError.Format(_T("Error loading theme file - %s - reason = "), csTheme, theme.LastError());
  235. MessageBox(csError, _T("Ditto"), MB_OK);
  236. }
  237. }
  238. void COptionsQuickPaste::OnBnClickedButtonDiffBrowse()
  239. {
  240. OPENFILENAME FileName;
  241. TCHAR szFileName[400];
  242. TCHAR szDir[400];
  243. memset(&FileName, 0, sizeof(FileName));
  244. memset(szFileName, 0, sizeof(szFileName));
  245. memset(&szDir, 0, sizeof(szDir));
  246. FileName.lStructSize = sizeof(FileName);
  247. FileName.lpstrTitle = _T("Diff Application");
  248. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  249. FileName.nMaxFile = 400;
  250. FileName.lpstrFile = szFileName;
  251. FileName.lpstrInitialDir = szDir;
  252. FileName.lpstrFilter = _T("*.exe");
  253. FileName.lpstrDefExt = _T("");
  254. if(GetOpenFileName(&FileName) == 0)
  255. return;
  256. CString csPath(FileName.lpstrFile);
  257. m_diffPathEditBox.SetWindowText(csPath);
  258. }