OptionsQuickPaste.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. }
  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. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // COptionsQuickPaste message handlers
  63. BOOL COptionsQuickPaste::OnInitDialog()
  64. {
  65. CPropertyPage::OnInitDialog();
  66. m_pParent = (COptionsSheet *)GetParent();
  67. m_btEnableTransparency.SetCheck(CGetSetOptions::GetEnableTransparency());
  68. m_eTransparencyPercent.SetNumber(CGetSetOptions::GetTransparencyPercent());
  69. m_eLinesPerRow.SetNumber(CGetSetOptions::GetLinesPerRow());
  70. m_alwaysShowScrollBar.SetCheck(CGetSetOptions::GetShowScrollBar());
  71. m_btShowThumbnails.SetCheck(g_Opt.m_bDrawThumbnail);
  72. m_btDrawRTF.SetCheck(g_Opt.m_bDrawRTF);
  73. m_EnsureEntireWindowVisible.SetCheck(g_Opt.m_bEnsureEntireWindowCanBeSeen);
  74. m_ShowAllInMainList.SetCheck(g_Opt.m_bShowAllClipsInMainList);
  75. m_FindAsYouType.SetCheck(g_Opt.m_bFindAsYouType);
  76. if(CGetSetOptions::GetQuickPastePosition() == POS_AT_CARET)
  77. CheckDlgButton(IDC_AT_CARET, BST_CHECKED);
  78. else if(CGetSetOptions::GetQuickPastePosition() == POS_AT_CURSOR)
  79. CheckDlgButton(IDC_AT_CURSOR, BST_CHECKED);
  80. else if(CGetSetOptions::GetQuickPastePosition() == POS_AT_PREVIOUS)
  81. CheckDlgButton(IDC_AT_PREVIOUS, BST_CHECKED);
  82. m_btDescShowLeadingWhiteSpace.SetCheck(g_Opt.m_bDescShowLeadingWhiteSpace);
  83. m_btUseCtrlNum.SetCheck(CGetSetOptions::GetUseCtrlNumForFirstTenHotKeys());
  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. CString cs;
  99. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  100. m_btFont.SetWindowText(cs);
  101. FillThemes();
  102. theApp.m_Language.UpdateOptionQuickPaste(this);
  103. return FALSE;
  104. }
  105. BOOL COptionsQuickPaste::OnApply()
  106. {
  107. CGetSetOptions::SetEnableTransparency(m_btEnableTransparency.GetCheck());
  108. CGetSetOptions::SetTransparencyPercent(m_eTransparencyPercent.GetNumber());
  109. CGetSetOptions::SetLinesPerRow(m_eLinesPerRow.GetNumber());
  110. CGetSetOptions::SetShowScrollBar(m_alwaysShowScrollBar.GetCheck());
  111. if(IsDlgButtonChecked(IDC_AT_CARET))
  112. CGetSetOptions::SetQuickPastePosition(POS_AT_CARET);
  113. else if(IsDlgButtonChecked(IDC_AT_CURSOR))
  114. CGetSetOptions::SetQuickPastePosition(POS_AT_CURSOR);
  115. else if(IsDlgButtonChecked(IDC_AT_PREVIOUS))
  116. CGetSetOptions::SetQuickPastePosition(POS_AT_PREVIOUS);
  117. g_Opt.SetDescShowLeadingWhiteSpace(m_btDescShowLeadingWhiteSpace.GetCheck());
  118. CGetSetOptions::SetUseCtrlNumForFirstTenHotKeys(m_btUseCtrlNum.GetCheck());
  119. CGetSetOptions::SetShowTextForFirstTenHotKeys(m_btShowText.GetCheck());
  120. CGetSetOptions::SetDrawThumbnail(m_btShowThumbnails.GetCheck());
  121. CGetSetOptions::SetDrawRTF(m_btDrawRTF.GetCheck());
  122. CGetSetOptions::SetEnsureEntireWindowCanBeSeen(m_EnsureEntireWindowVisible.GetCheck());
  123. CGetSetOptions::SetShowAllClipsInMainList(m_ShowAllInMainList.GetCheck());
  124. CGetSetOptions::SetFindAsYouType(m_FindAsYouType.GetCheck());
  125. CGetSetOptions::SetPromptWhenDeletingClips(m_PromptForDelete.GetCheck());
  126. CGetSetOptions::SetPasteAsAdmin(m_elevatedPrivileges.GetCheck());
  127. BOOL prevValue = CGetSetOptions::GetShowInTaskBar();
  128. CGetSetOptions::SetShowInTaskBar(m_showInTaskBar.GetCheck());
  129. if(CGetSetOptions::GetShowInTaskBar() != prevValue)
  130. {
  131. theApp.RefreshShowInTaskBar();
  132. }
  133. if(m_LogFont.lfWeight != 0)
  134. {
  135. CGetSetOptions::SetFont(m_LogFont);
  136. }
  137. CString csTheme;
  138. if(m_cbTheme.GetCurSel() >= 0)
  139. {
  140. m_cbTheme.GetLBText(m_cbTheme.GetCurSel(), csTheme);
  141. if(csTheme == DEFAULT_THEME)
  142. g_Opt.SetTheme("");
  143. else
  144. g_Opt.SetTheme(csTheme);
  145. }
  146. else
  147. {
  148. g_Opt.SetTheme("");
  149. }
  150. return CPropertyPage::OnApply();
  151. }
  152. void COptionsQuickPaste::OnButtonFont()
  153. {
  154. CFontDialog dlg(&m_LogFont, (CF_TTONLY | CF_SCREENFONTS));
  155. if(dlg.DoModal() == IDOK)
  156. {
  157. m_Font.DeleteObject();
  158. memcpy(&m_LogFont, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
  159. m_Font.CreateFontIndirect(&m_LogFont);
  160. m_btFont.SetFont(&m_Font);
  161. CString cs;
  162. cs.Format(_T("Font - %s"), m_LogFont.lfFaceName);
  163. m_btFont.SetWindowText(cs);
  164. }
  165. }
  166. void COptionsQuickPaste::OnButtonDefaultFault()
  167. {
  168. CFont *ft = m_btDefaultButton.GetFont();
  169. ft->GetLogFont(&m_LogFont);
  170. memset(&m_LogFont, 0, sizeof(m_LogFont));
  171. m_LogFont.lfHeight = -11;
  172. m_LogFont.lfWeight = 400;
  173. m_LogFont.lfCharSet = 1;
  174. STRCPY(m_LogFont.lfFaceName, _T("Arial Unicode MS"));
  175. m_Font.DeleteObject();
  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. void COptionsQuickPaste::FillThemes()
  183. {
  184. CString csFile = CGetSetOptions::GetPath(PATH_THEMES);
  185. csFile += "*.xml";
  186. CString csTheme = CGetSetOptions::GetTheme();
  187. CFileFind find;
  188. BOOL bCont = find.FindFile(csFile);
  189. bool bSetCurSel = false;
  190. while(bCont)
  191. {
  192. bCont = find.FindNextFile();
  193. int nIndex = m_cbTheme.AddString(find.GetFileTitle());
  194. if(find.GetFileTitle() == csTheme)
  195. {
  196. m_cbTheme.SetCurSel(nIndex);
  197. bSetCurSel = true;
  198. }
  199. }
  200. int nIndex = m_cbTheme.AddString(DEFAULT_THEME);
  201. if(bSetCurSel == false)
  202. {
  203. m_cbTheme.SetCurSel(nIndex);
  204. }
  205. }
  206. void COptionsQuickPaste::OnBnClickedButtonTheme()
  207. {
  208. CTheme theme;
  209. CString csTheme;
  210. m_cbTheme.GetLBText(m_cbTheme.GetCurSel(), csTheme);
  211. if(csTheme == DEFAULT_THEME)
  212. return;
  213. if(theme.Load(csTheme, true, false))
  214. {
  215. CString csMessage;
  216. csMessage.Format(_T("Theme - %s\n")
  217. _T("Version - %d\n")
  218. _T("Author - %s\n")
  219. _T("Notes - %s"), csTheme,
  220. theme.FileVersion(),
  221. theme.Author(),
  222. theme.Notes());
  223. MessageBox(csMessage, _T("Ditto"), MB_OK);
  224. }
  225. else
  226. {
  227. CString csError;
  228. csError.Format(_T("Error loading theme file - %s - reason = "), csTheme, theme.LastError());
  229. MessageBox(csError, _T("Ditto"), MB_OK);
  230. }
  231. }