-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSearch.h
More file actions
196 lines (155 loc) · 4.78 KB
/
Search.h
File metadata and controls
196 lines (155 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef AFX_SEARCH_H__201E0D70_9C20_420A_8600_966D2BA23010__INCLUDED_
#define AFX_SEARCH_H__201E0D70_9C20_420A_8600_966D2BA23010__INCLUDED_
#include "editwing/editwing.h"
#include "kilib/window.h"
#include "kilib/memory.h"
#include "kilib/kstring.h"
#include "kilib/registry.h"
//=========================================================================
//@{ @pkg Gp.Search //@}
//@{
// 検索オブジェクト
//@}
//=========================================================================
class Searchable
{
public:
//@{
// 検索を行う
// @param str 対象文字列
// @param len 対象文字列の長さ
// @param stt 検索開始index。0なら先頭から
// @param mbg マッチ結果の先頭index
// @param med マッチ結果の終端indexの1個後ろ
// @return マッチしたかどうか
//
// 下方向サーチオブジェクトの場合、stt <= *beg の範囲
// 上方向サーチオブジェクトの場合、*beg <= stt の範囲を検索
//@}
virtual bool Search( const unicode* str, ulong len, ulong stt,
ulong* mbg, ulong* med ) = 0;
virtual ~Searchable() {};
};
//=========================================================================
//@{
// 検索管理人
//
// 前回検索したときのオプションや検索文字列を覚えておくのが
// このクラスの担当。検索・置換ダイアログの表示等もここで
// やるかもしれない。
//@}
//=========================================================================
class SearchManager A_FINAL: public ki::DlgImpl
{
typedef editwing::DPos DPos;
public:
//@{ コンストラクタ。特記事項無し //@}
SearchManager( ki::Window& w, editwing::EwEdit& e );
//@{ デストラクタ。特記事項無し //@}
~SearchManager();
//@{ 検索ダイアログ表示 //@}
void ShowDlg();
//@{ [次を検索]コマンド //@}
void FindNext();
//@{ [前を検索]コマンド //@}
void FindPrev();
//@{ 今すぐ検索可能か? //@}
bool isReady() const
{ return searcher_ != NULL; }
//@{ 設定Save //@}
void SaveToINI();
//@{ 設定Load //@}
void LoadFromINI();
//@{ 苦肉の策^^; //@}
bool TrapMsg(MSG* msg);
//@{ 見つかりませんでしたダイアログ //@}
void NotFound(bool GoingDown=false);
private:
//@{ [置換]コマンド //@}
void ReplaceImpl();
//@{ [全置換]コマンド //@}
void ReplaceAllImpl();
private:
void on_init() override;
void on_destroy() override;
bool on_command( UINT cmd, UINT id, HWND ctrl ) override;
bool on_cancel() override;
void on_findnext();
void on_findprev();
void on_replacenext();
void on_replaceall();
void UpdateData();
void ConstructSearcher( bool down=true );
void FindNextImpl( bool redo=false );
void FindPrevImpl();
bool FindNextFromImpl( DPos s, DPos* beg, DPos* end );
bool FindPrevFromImpl( DPos s, DPos* beg, DPos* end );
void AddToComboBoxHistoric(UINT idc_cbb, const TCHAR *str)
{
if( !str || !*str )
return;
// Save edit selection state:
HRESULT oldsel = SendMsgToItem( idc_cbb, CB_GETEDITSEL, 0, 0 );
int found_index = SendMsgToItem( idc_cbb, CB_FINDSTRINGEXACT, 0, (LPARAM)str );
if( found_index == CB_ERR )
{
// Item was not found in historic.
int item_count = SendMsgToItem( idc_cbb, CB_GETCOUNT, 0, 0);
if( item_count > 15 )
SendMsgToItem( idc_cbb, CB_DELETESTRING, item_count-1, 0);
}
else
{
// Item was found in historic.
// Remove old entry
SendMsgToItem( idc_cbb, CB_DELETESTRING, found_index, 0);
}
// Alway Insert last searched string at the begining of the list
SendMsgToItem( idc_cbb, CB_INSERTSTRING, /*index*/0, (LPARAM)str );
// Restore combobox edit state
SendMsgToItem( idc_cbb, CB_SETCURSEL, 0, 0 );
SendMsgToItem( idc_cbb, CB_SETEDITSEL, 0, (LPARAM)oldsel );
}
void fillFromHistoric( UINT idc_cbb, ki::String *hist, size_t hist_len )
{
for( size_t i=0; i < hist_len; i++ )
{
if( hist[i].len() > 0 )
SendMsgToItem( idc_cbb, CB_ADDSTRING, 0, (LPARAM)hist[i].c_str() );
}
}
void saveToHistoric( UINT idc_cbb, ki::String *hist, size_t hist_len )
{
int item_count = SendMsgToItem( idc_cbb, CB_GETCOUNT, 0, 0);
if(item_count <= 0)
return;
for( size_t i=0; i < Min((size_t)item_count, hist_len) ; i++ )
{
LPARAM txtlen = SendMsgToItem(idc_cbb, CB_GETLBTEXTLEN, i, 0);
TCHAR *txt = (TCHAR *)ki::TS.alloc( txtlen+1 );
if( txt )
{
SendMsgToItem(idc_cbb, CB_GETLBTEXT, i, (LPARAM)txt);
hist[i] = txt; // save
ki::TS.freelast( txt, txtlen+1 );
}
}
}
private:
editwing::EwEdit& edit_;
Searchable *searcher_;
ki::Window& mainWnd_;
bool bIgnoreCase_; // 大文字小文字を同一視?
bool bRegExp_; // 正規表現?
bool bDownSearch_; // 検索方向
bool bChanged_; // 前回のsearcher構築時から変更があったらtrue
bool inichanged_; // Set to true when the ini must be saved
ki::String findStr_;
ki::String replStr_;
ki::String findHistoric_[16];
ki::String replHistoric_[16];
private:
NOCOPY(SearchManager);
};
//=========================================================================
#endif // AFX_SEARCH_H__201E0D70_9C20_420A_8600_966D2BA23010__INCLUDED_