| 1 |
#include <windows.h> |
| 2 |
#include <tchar.h> |
| 3 |
#include <commctrl.h> |
| 4 |
|
| 5 |
#include "Tombo.h" |
| 6 |
#include "Property.h" |
| 7 |
#include "resource.h" |
| 8 |
#include "SearchDlg.h" |
| 9 |
#include "UniConv.h" |
| 10 |
#include "SipControl.h" |
| 11 |
|
| 12 |
#include "DialogTemplate.h" |
| 13 |
#include "Message.h" |
| 14 |
|
| 15 |
//////////////////////////////////////////////////////////////// |
| 16 |
// ctor & dtor |
| 17 |
//////////////////////////////////////////////////////////////// |
| 18 |
|
| 19 |
SearchDialog::~SearchDialog() |
| 20 |
{ |
| 21 |
if (pSearchStr) delete [] pSearchStr; |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
//////////////////////////////////////////////////////////////// |
| 26 |
// Dialog proc |
| 27 |
//////////////////////////////////////////////////////////////// |
| 28 |
|
| 29 |
static BOOL APIENTRY DlgProc(HWND hDlg, UINT nMessage, WPARAM wParam, LPARAM lParam) |
| 30 |
{ |
| 31 |
SearchDialog *pDlg; |
| 32 |
if (nMessage == WM_INITDIALOG) { |
| 33 |
SetWindowLong(hDlg, DWL_USER, lParam); |
| 34 |
pDlg = (SearchDialog*)lParam; |
| 35 |
|
| 36 |
pDlg->InitDialog(hDlg); |
| 37 |
return TRUE; |
| 38 |
} |
| 39 |
|
| 40 |
pDlg = (SearchDialog*)GetWindowLong(hDlg, DWL_USER); |
| 41 |
if (pDlg == NULL) return FALSE; |
| 42 |
|
| 43 |
switch (nMessage) { |
| 44 |
case WM_COMMAND: |
| 45 |
switch (wParam) { |
| 46 |
case IDOK: |
| 47 |
if (pDlg->OnOK()) { |
| 48 |
EndDialog(hDlg, IDOK); |
| 49 |
} |
| 50 |
break; |
| 51 |
case IDCANCEL: |
| 52 |
EndDialog(hDlg, IDCANCEL); |
| 53 |
break; |
| 54 |
} |
| 55 |
return TRUE; |
| 56 |
} |
| 57 |
return FALSE; |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
//////////////////////////////////////////////////////////////// |
| 62 |
// init |
| 63 |
//////////////////////////////////////////////////////////////// |
| 64 |
|
| 65 |
static DlgMsgRes aMsgRes[] = { |
| 66 |
{ IDC_SEARCH_FIND_LABEL, MSG_ID_DLG_SEARCH_FIND_LABEL }, |
| 67 |
{ IDC_SEARCH_DIRECT_LABEL, MSG_ID_DLG_SEARCH_DIRECTION_LABEL }, |
| 68 |
{ IDC_SEARCH_DIRECTION_UP, MSG_ID_DLG_SEARCH_DIRECTION_UP }, |
| 69 |
{ IDC_SEARCH_DIRECTION_DOWN, MSG_ID_DLG_SEARCH_DIRECTION_DOWN }, |
| 70 |
{ IDC_SEARCH_CASESENSITIVE, MSG_ID_DLG_FILTERDEF_ADD_REGEX_CASESENSITIVE }, |
| 71 |
{ IDC_SEARCH_ENCRYPTMEMO, MSG_ID_DLG_FILTERDEF_ADD_REGEX_INCLUDECRYPTED }, |
| 72 |
{ IDC_FILENAMEONLY, MSG_ID_DLG_FILTERDEF_ADD_REGEX_FORFILENAME }, |
| 73 |
{ IDOK, MSG_ID_DLG_CMN_OK }, |
| 74 |
{ IDCANCEL, MSG_ID_DLG_CMN_CANCEL }, |
| 75 |
}; |
| 76 |
|
| 77 |
void SearchDialog::InitDialog(HWND hDlg) |
| 78 |
{ |
| 79 |
OverrideDlgMsg(hDlg, MSG_ID_DLG_SEARCH_TITLE, aMsgRes, sizeof(aMsgRes)/sizeof(DlgMsgRes)); |
| 80 |
hDialog = hDlg; |
| 81 |
|
| 82 |
HWND hCombo = GetDlgItem(hDlg, IDC_SEARCH_STRING); |
| 83 |
LPCTSTR pHist = g_Property.GetSearchHist(); |
| 84 |
SetHistoryToComboBox(hCombo, pHist); |
| 85 |
|
| 86 |
HWND hCheckEncrypt = GetDlgItem(hDlg, IDC_SEARCH_ENCRYPTMEMO); |
| 87 |
EnableWindow(hCheckEncrypt, bCheckEncrypt); |
| 88 |
HWND hFileNameOnly = GetDlgItem(hDlg, IDC_FILENAMEONLY); |
| 89 |
EnableWindow(hFileNameOnly, bFileNameOnly); |
| 90 |
|
| 91 |
HWND hSearchDirectionUp = GetDlgItem(hDlg, IDC_SEARCH_DIRECTION_UP); |
| 92 |
HWND hSearchDirectionDown = GetDlgItem(hDlg, IDC_SEARCH_DIRECTION_DOWN); |
| 93 |
EnableWindow(hSearchDirectionUp, bEnableDirection); |
| 94 |
EnableWindow(hSearchDirectionDown, bEnableDirection); |
| 95 |
|
| 96 |
CheckRadioButton(hDlg, IDC_SEARCH_DIRECTION_UP, IDC_SEARCH_DIRECTION_DOWN, IDC_SEARCH_DIRECTION_DOWN); |
| 97 |
} |
| 98 |
|
| 99 |
//////////////////////////////////////////////////////////////// |
| 100 |
// popup |
| 101 |
//////////////////////////////////////////////////////////////// |
| 102 |
|
| 103 |
DWORD SearchDialog::Popup(HINSTANCE hInst, HWND hParent, BOOL bCE) |
| 104 |
{ |
| 105 |
hInstance = hInst; |
| 106 |
|
| 107 |
bCheckEncrypt = bFileNameOnly = bCE; |
| 108 |
bEnableDirection = bCE; |
| 109 |
|
| 110 |
SipControl sc; |
| 111 |
BOOL bSipStat, bResult; |
| 112 |
bResult = sc.Init() && sc.GetSipStat(&bSipStat); |
| 113 |
if (bResult) sc.SetSipStat(TRUE); |
| 114 |
|
| 115 |
DWORD result; |
| 116 |
result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SEARCH), |
| 117 |
hParent, (DLGPROC)DlgProc, (LONG)this); |
| 118 |
|
| 119 |
if (bResult) sc.SetSipStat(bSipStat); |
| 120 |
return result; |
| 121 |
} |
| 122 |
|
| 123 |
//////////////////////////////////////////////////////////////// |
| 124 |
// OK |
| 125 |
//////////////////////////////////////////////////////////////// |
| 126 |
|
| 127 |
BOOL SearchDialog::OnOK() |
| 128 |
{ |
| 129 |
// find encrypted notes |
| 130 |
HWND hCheckEncrypt = GetDlgItem(hDialog, IDC_SEARCH_ENCRYPTMEMO); |
| 131 |
bCheckEncrypt = (SendMessage(hCheckEncrypt, BM_GETCHECK, 0, 0) == BST_CHECKED); |
| 132 |
|
| 133 |
// case sensitive |
| 134 |
HWND hCaseSensitive = GetDlgItem(hDialog, IDC_SEARCH_CASESENSITIVE); |
| 135 |
bCaseSensitive = (SendMessage(hCaseSensitive, BM_GETCHECK, 0, 0) == BST_CHECKED); |
| 136 |
|
| 137 |
HWND hFileNameOnly = GetDlgItem(hDialog, IDC_FILENAMEONLY); |
| 138 |
bFileNameOnly = (SendMessage(hFileNameOnly, BM_GETCHECK, 0, 0) == BST_CHECKED); |
| 139 |
|
| 140 |
// Search direction |
| 141 |
HWND hSearchDirectionUp = GetDlgItem(hDialog, IDC_SEARCH_DIRECTION_UP); |
| 142 |
bSearchDirectionUp = (SendMessage(hSearchDirectionUp, BM_GETCHECK, 0, 0) == BST_CHECKED); |
| 143 |
|
| 144 |
// find string |
| 145 |
HWND hSearchWord = GetDlgItem(hDialog, IDC_SEARCH_STRING); |
| 146 |
int n = GetWindowTextLength(hSearchWord); |
| 147 |
|
| 148 |
// ������������������������ |
| 149 |
if (n == 0) return FALSE; |
| 150 |
|
| 151 |
LPTSTR pSearchTextW = new TCHAR[n + 2]; |
| 152 |
if (pSearchTextW == NULL) return FALSE; |
| 153 |
GetWindowText(hSearchWord, pSearchTextW, n + 1); |
| 154 |
|
| 155 |
g_Property.SetSearchHist(GetHistoryFromComboBox(hSearchWord, pSearchTextW, NUM_SEARCH_HISTORY)); |
| 156 |
pSearchStr = pSearchTextW; |
| 157 |
return TRUE; |
| 158 |
} |