SearchOptionsPane.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:11k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // SearchOptionsPane.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "searchoptions.h"
  22. #include "SearchOptionsPane.h"
  23. #include "MainFrm.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CSearchOptionsPane
  31. IMPLEMENT_DYNCREATE(CSearchOptionsPane, CXTSearchOptionsView)
  32. CSearchOptionsPane::CSearchOptionsPane()
  33. : CXTSearchOptionsView(CSearchOptionsPane::IDD)
  34. , m_bFirstTime(true)
  35. {
  36. //{{AFX_DATA_INIT(CSearchOptionsPane)
  37. //}}AFX_DATA_INIT
  38. // load the search icon that is displayed in the upper left corner.
  39. m_hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
  40. MAKEINTRESOURCE(IDI_SEARCH), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
  41. }
  42. CSearchOptionsPane::~CSearchOptionsPane()
  43. {
  44. // free GDI
  45. if (m_hIcon != NULL)
  46. ::DestroyIcon(m_hIcon);
  47. CXTRegistryManager regManager;
  48. regManager.WriteProfileInt(_T("Settings"), _T("Keyword"), m_expKeywords.IsExpanded());
  49. regManager.WriteProfileInt(_T("Settings"), _T("Filters"), m_expFilters.IsExpanded());
  50. }
  51. void CSearchOptionsPane::DoDataExchange(CDataExchange* pDX)
  52. {
  53. CXTSearchOptionsView::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(CSearchOptionsPane)
  55. DDX_Control(pDX, IDC_TXT_SEP, m_txtSep);
  56. DDX_Control(pDX, IDC_EXP_KEYWORD, m_expKeywords);
  57. DDX_Control(pDX, IDC_EXP_FILTERS, m_expFilters);
  58. DDX_Control(pDX, IDC_COMBO_FAVORITES, m_combFavorites);
  59. DDX_Control(pDX, IDC_COMBO_ATMOST, m_combAtMost);
  60. DDX_Control(pDX, IDC_COMBO_ATLEAST, m_combAtLeast);
  61. DDX_Control(pDX, IDC_CHK_ATMOST, m_chkAtMost);
  62. DDX_Control(pDX, IDC_CHK_ATLEAST, m_chkAtLeast);
  63. DDX_Control(pDX, IDC_BTN_SEARCH, m_btnSearch);
  64. DDX_Control(pDX, IDC_BTN_SAVE, m_btnSave);
  65. DDX_Control(pDX, IDC_BTN_DELETE, m_btnDelete);
  66. DDX_Control(pDX, IDC_BTN_CLEAR, m_btnClear);
  67. DDX_Control(pDX, IDC_TXT_BUTNOT, m_txtButNot);
  68. DDX_Control(pDX, IDC_TXT_CONTAINING, m_txtContaining);
  69. DDX_Control(pDX, IDC_ICO_SEARCH, m_icoSearch);
  70. DDX_Control(pDX, IDC_TXT_WORDS, m_txtWords);
  71. DDX_Control(pDX, IDC_TXT_LETTERS, m_txtLetters);
  72. DDX_Control(pDX, IDC_TXT_HIDE_WORDS, m_txtHideWords);
  73. DDX_Control(pDX, IDC_TXT_HIDE_LETTERS, m_txtHideLetters);
  74. DDX_Control(pDX, IDC_TXT_FAVORITES, m_txtFavorites);
  75. DDX_Control(pDX, IDC_EDIT_WORDS, m_editWords);
  76. DDX_Control(pDX, IDC_EDIT_LETTERS, m_editLetters);
  77. DDX_Control(pDX, IDC_EDIT_CONTAINING, m_editContaining);
  78. DDX_Control(pDX, IDC_EDIT_BUTNOT, m_editButNot);
  79. DDX_Control(pDX, IDC_EDIT_ATMOST, m_editAtMost);
  80. DDX_Control(pDX, IDC_EDIT_ATLEAST, m_editAtLeast);
  81. DDX_Control(pDX, IDC_TXT_SEARCHTITLE, m_txtTitle);
  82. //}}AFX_DATA_MAP
  83. }
  84. BEGIN_MESSAGE_MAP(CSearchOptionsPane, CXTSearchOptionsView)
  85. //{{AFX_MSG_MAP(CSearchOptionsPane)
  86. ON_WM_CREATE()
  87. //}}AFX_MSG_MAP
  88. ON_BN_CLICKED(IDC_CAPTION, OnCaptionClose)
  89. ON_SON_XT_ITEMCONTRACTING(IDC_EXP_FILTERS, OnFiltersContracting)
  90. ON_SON_XT_ITEMCONTRACT(IDC_EXP_FILTERS, OnFiltersContract)
  91. ON_SON_XT_ITEMEXPANDING(IDC_EXP_FILTERS, OnFiltersExpanding)
  92. ON_SON_XT_ITEMEXPAND(IDC_EXP_FILTERS, OnFiltersExpand)
  93. ON_SON_XT_ITEMCONTRACTING(IDC_EXP_KEYWORD, OnKeywordContracting)
  94. ON_SON_XT_ITEMCONTRACT(IDC_EXP_KEYWORD, OnKeywordContract)
  95. ON_SON_XT_ITEMEXPANDING(IDC_EXP_KEYWORD, OnKeywordExpanding)
  96. ON_SON_XT_ITEMEXPAND(IDC_EXP_KEYWORD, OnKeywordExpand)
  97. END_MESSAGE_MAP()
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CSearchOptionsPane diagnostics
  100. #ifdef _DEBUG
  101. void CSearchOptionsPane::AssertValid() const
  102. {
  103. CXTSearchOptionsView::AssertValid();
  104. }
  105. void CSearchOptionsPane::Dump(CDumpContext& dc) const
  106. {
  107. CXTSearchOptionsView::Dump(dc);
  108. }
  109. #endif //_DEBUG
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CSearchOptionsPane message handlers
  112. int CSearchOptionsPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
  113. {
  114. if (CXTSearchOptionsView::OnCreate(lpCreateStruct) == -1)
  115. return -1;
  116. // Create the caption.
  117. if (!m_wndCaption.Create(this, _T("Search"), CPWS_EX_RAISED_EDGE|CPWS_EX_CLOSEBUTTON,
  118. WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|SS_CENTER|SS_CENTERIMAGE, CRect(0,0,0,0), IDC_CAPTION))
  119. {
  120. TRACE0( "Unable to create caption.n" );
  121. return -1;
  122. }
  123. // Move the caption to its default location.
  124. CRect rect;
  125. GetClientRect(&rect);
  126. rect.bottom = 19;
  127. rect.right += 2;
  128. m_wndCaption.MoveWindow(&rect);
  129. return 0;
  130. }
  131. void CSearchOptionsPane::OnCaptionClose()
  132. {
  133. // get a pointer to the application's frame window
  134. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  135. ASSERT_VALID(pMainFrame);
  136. // hide this pane.
  137. pMainFrame->ToggleSearchPane();
  138. }
  139. void CSearchOptionsPane::OnInitialUpdate()
  140. {
  141. CXTSearchOptionsView::OnInitialUpdate();
  142. if ( m_bFirstTime )
  143. {
  144. // set the title icon.
  145. m_icoSearch.SetIcon(m_hIcon);
  146. // set the font for the search title.
  147. m_txtTitle.SetFont(&XTAuxData().fontBold);
  148. m_txtTitle.ModifyStyle(NULL, SS_ELLIPSISMASK);
  149. m_txtContaining.ModifyStyle(NULL, SS_ELLIPSISMASK);
  150. m_txtButNot.ModifyStyle(NULL, SS_ELLIPSISMASK);
  151. // Set control resizing.
  152. SetResize(IDC_CAPTION,         SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  153. SetResize(IDC_TXT_SEARCHTITLE, SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  154. SetResize(IDC_TXT_SEP,         SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  155. SetResize(IDC_TXT_CONTAINING,  SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  156. SetResize(IDC_EDIT_CONTAINING, SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  157. SetResize(IDC_TXT_BUTNOT,      SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  158. SetResize(IDC_EDIT_BUTNOT,     SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  159. SetResize(IDC_BTN_SEARCH,      SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  160. SetResize(IDC_EXP_FILTERS,     SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  161. SetResize(IDC_EDIT_ATLEAST,    SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  162. SetResize(IDC_COMBO_ATLEAST,   SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  163. SetResize(IDC_EDIT_ATMOST,     SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  164. SetResize(IDC_COMBO_ATMOST,    SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  165. SetResize(IDC_EXP_KEYWORD,     SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  166. SetResize(IDC_EDIT_WORDS,      SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  167. SetResize(IDC_TXT_WORDS,       SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  168. SetResize(IDC_EDIT_LETTERS,    SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  169. SetResize(IDC_TXT_LETTERS,     SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  170. SetResize(IDC_TXT_FAVORITES,   SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  171. SetResize(IDC_COMBO_FAVORITES, SZ_TOP_LEFT,  SZ_TOP_RIGHT);
  172. SetResize(IDC_BTN_DELETE,      SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  173. SetResize(IDC_BTN_SAVE,        SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  174. // initialize the file and keyword filters search
  175. // option controls.
  176. InitFileFilters();
  177. InitKeywordFilters();
  178. // Show keywords conracted?
  179. CXTRegistryManager regManager;
  180. if (!regManager.GetProfileInt(_T("Settings"), _T("Keyword"), FALSE)) {
  181. m_expKeywords.Contract();
  182. }
  183. // Show filters conracted?
  184. if (!regManager.GetProfileInt(_T("Settings"), _T("Filters"), FALSE)) {
  185. m_expFilters.Contract();
  186. }
  187. m_bFirstTime = false;
  188. }
  189. }
  190. void CSearchOptionsPane::InitFileFilters()
  191. {
  192. // set the expand / contract text labels.
  193. m_expFilters.SetLabelText(
  194. _T("File Filters <<"), _T("File Filters >>"));
  195. // add the controls to the search options control,
  196. // these are the controls that are show and hidden when
  197. // the search options control is expanded or contracted.
  198. m_expFilters.AddControl(&m_chkAtLeast);
  199. m_expFilters.AddControl(&m_editAtLeast);
  200. m_expFilters.AddControl(&m_combAtLeast);
  201. m_expFilters.AddControl(&m_chkAtMost);
  202. m_expFilters.AddControl(&m_editAtMost);
  203. m_expFilters.AddControl(&m_combAtMost);
  204. // add the controls to the search options control that
  205. // are to be moved up or down in relation to the search
  206. // options control whenever the control is expanded or
  207. // contracted.
  208. m_expFilters.MoveControl(&m_expKeywords);
  209. m_expFilters.MoveControl(&m_txtHideWords);
  210. m_expFilters.MoveControl(&m_editWords);
  211. m_expFilters.MoveControl(&m_txtWords);
  212. m_expFilters.MoveControl(&m_txtHideLetters);
  213. m_expFilters.MoveControl(&m_editLetters);
  214. m_expFilters.MoveControl(&m_txtLetters);
  215. m_expFilters.MoveControl(&m_txtFavorites);
  216. m_expFilters.MoveControl(&m_combFavorites);
  217. m_expFilters.MoveControl(&m_btnDelete);
  218. m_expFilters.MoveControl(&m_btnSave);
  219. }
  220. void CSearchOptionsPane::InitKeywordFilters()
  221. {
  222. // set the expand / contract text labels.
  223. m_expKeywords.SetLabelText(
  224. _T("Keyword / Spam Filters <<"), _T("Keyword / Spam Filters >>"));
  225. // add the controls to the search options control,
  226. // these are the controls that are show and hidden when
  227. // the search options control is expanded or contracted.
  228. m_expKeywords.AddControl(&m_txtHideWords);
  229. m_expKeywords.AddControl(&m_editWords);
  230. m_expKeywords.AddControl(&m_txtWords);
  231. m_expKeywords.AddControl(&m_txtHideLetters);
  232. m_expKeywords.AddControl(&m_editLetters);
  233. m_expKeywords.AddControl(&m_txtLetters);
  234. // add the controls to the search options control that
  235. // are to be moved up or down in relation to the search
  236. // options control whenever the control is expanded or
  237. // contracted.
  238. m_expKeywords.MoveControl(&m_txtFavorites);
  239. m_expKeywords.MoveControl(&m_combFavorites);
  240. m_expKeywords.MoveControl(&m_btnDelete);
  241. m_expKeywords.MoveControl(&m_btnSave);
  242. }
  243. void CSearchOptionsPane::OnFiltersContracting()
  244. {
  245. //TODO: handle notification
  246. }
  247. void CSearchOptionsPane::OnFiltersContract()
  248. {
  249. AdjustScrollSizes(&m_expFilters, false);
  250. }
  251. void CSearchOptionsPane::OnFiltersExpanding()
  252. {
  253. //TODO: handle notification
  254. }
  255. void CSearchOptionsPane::OnFiltersExpand()
  256. {
  257. AdjustScrollSizes(&m_expFilters, true);
  258. }
  259. void CSearchOptionsPane::OnKeywordContracting()
  260. {
  261. //TODO: handle notification
  262. }
  263. void CSearchOptionsPane::OnKeywordContract()
  264. {
  265. AdjustScrollSizes(&m_expKeywords, false);
  266. }
  267. void CSearchOptionsPane::OnKeywordExpanding()
  268. {
  269. //TODO: handle notification
  270. }
  271. void CSearchOptionsPane::OnKeywordExpand()
  272. {
  273. AdjustScrollSizes(&m_expKeywords, true);
  274. }