-
Notifications
You must be signed in to change notification settings - Fork 5
/
lea_gwin-search_box.adb
190 lines (171 loc) · 7.17 KB
/
lea_gwin-search_box.adb
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
with LEA_Common;
with LEA_GWin.MDI_Main;
with GWindows.Buttons,
GWindows.Key_States,
GWindows.Scintilla;
package body LEA_GWin.Search_Box is
use LEA_Common, LEA_GWin.MDI_Main, GWindows.Key_States;
procedure Update_Drop_Downs (SB : in out LEA_Search_Box_Type) is
procedure Update_Drop_Down (DD : in out Find_Replace_Box_Type) is
max : constant := 10;
dd_text : constant GString := DD.Text;
begin
if dd_text'Length = 0 or else DD.Find_Exact (dd_text) > 0 then
-- If the text is empty or already in the list, do nothing.
null;
else
-- We limit the list to a convenient maximum amount.
if DD.Count >= max then
DD.Delete (max);
end if;
DD.Add (1, dd_text);
end if;
end Update_Drop_Down;
begin
Update_Drop_Down (SB.Find_box);
Update_Drop_Down (SB.Replace_box);
end Update_Drop_Downs;
procedure Any_Search_Button_Clicked (
Window : GWindows.Base.Base_Window_Type'Class;
action : Search_action
)
is
use GWindows.Base;
Parent : constant Pointer_To_Base_Window_Class := Window.Parent;
begin
if Parent /= null and then Parent.all in LEA_Search_Box_Type'Class then -- Should be always the case.
declare
SB : LEA_Search_Box_Type renames LEA_Search_Box_Type (Parent.all);
MDI_Top : MDI_Main_Type renames MDI_Main_Type (SB.The_real_MDI_parent.all);
begin
-- Ooof.. pointers are behind, we are back into the strong-typed value-type OO world.
Update_Drop_Downs (SB);
MDI_Top.Perform_Search (action);
end;
end if;
end Any_Search_Button_Clicked;
procedure Find_Next_Button_Clicked (Window : in out GWindows.Base.Base_Window_Type'Class) is
begin
Any_Search_Button_Clicked (Window, find_next);
end Find_Next_Button_Clicked;
procedure Find_Previous_Button_Clicked (Window : in out GWindows.Base.Base_Window_Type'Class) is
begin
Any_Search_Button_Clicked (Window, find_previous);
end Find_Previous_Button_Clicked;
procedure Find_All_Button_Clicked (Window : in out GWindows.Base.Base_Window_Type'Class) is
begin
Any_Search_Button_Clicked (Window, find_all);
end Find_All_Button_Clicked;
procedure Replace_And_Find_Next_Button_Clicked (Window : in out GWindows.Base.Base_Window_Type'Class) is
begin
Any_Search_Button_Clicked (Window, replace_and_find_next);
end Replace_And_Find_Next_Button_Clicked;
procedure Replace_All_Button_Clicked (Window : in out GWindows.Base.Base_Window_Type'Class) is
begin
Any_Search_Button_Clicked (Window, replace_all);
end Replace_All_Button_Clicked;
procedure On_Message
(FRB : in out Find_Replace_Box_Type;
message : in Interfaces.C.unsigned;
wParam : in GWindows.Types.Wparam;
lParam : in GWindows.Types.Lparam;
Return_Value : in out GWindows.Types.Lresult)
is
CB_GETDROPPEDSTATE : constant := 343;
do_find_next : Boolean := False;
use Interfaces.C;
begin
if message = CB_GETDROPPEDSTATE then
if Is_Key_Down (VK_ESCAPE) then
-- FRB.parent_SB.Hide works, but LEA window's focus is lost!
MDI_Main_Type (FRB.parent_SB.The_real_MDI_parent.all).close_this_search_box := True;
elsif Is_Key_Down (VK_RETURN) then
do_find_next := True;
end if;
end if;
GWindows.Combo_Boxes.Drop_Down_Combo_Box_Type
(FRB).On_Message (message, wParam, lParam, Return_Value);
if do_find_next then
Update_Drop_Downs (FRB.parent_SB.all);
MDI_Main_Type (FRB.parent_SB.The_real_MDI_parent.all).Perform_Search (find_next);
end if;
end On_Message;
procedure On_Message
(SB : in out LEA_Search_Box_Type;
message : in Interfaces.C.unsigned;
wParam : in GWindows.Types.Wparam;
lParam : in GWindows.Types.Lparam;
Return_Value : in out GWindows.Types.Lresult)
is
begin
if Is_Key_Down (VK_ESCAPE) then
-- SB.Hide works, but LEA window's focus is lost!
MDI_Main_Type (SB.The_real_MDI_parent.all).close_this_search_box := True;
end if;
LEA_Resource_GUI.Search_box_Type (SB).On_Message (message, wParam, lParam, Return_Value);
end On_Message;
procedure On_Close (SB : in out LEA_Search_Box_Type;
Can_Close : out Boolean)
is
begin
Can_Close := False;
SB.Hide;
end On_Close;
procedure Create_as_Search_Box
(SB : in out LEA_Search_Box_Type;
Parent : in out GWindows.Base.Base_Window_Type'Class)
is
begin
SB.The_real_MDI_parent := Parent'Unrestricted_Access;
SB.Create_Full_Dialog (Parent);
-- The dialog is now created. We customize it a bit...
SB.Small_Icon ("Binoculars_Icon_Small");
-- Create text box for searching a text.
SB.Find_box.Create (SB, "",
SB.Model_find_box.Left, SB.Model_find_box.Top,
SB.Model_find_box.Width, SB.Model_find_box.Height,
False, ID => LEA_Resource_GUI.Model_find_box);
-- Find_box is identical to Model_find_box, but with new methods.
SB.Model_find_box.Hide;
SB.Find_box.parent_SB := SB'Unrestricted_Access;
-- Create text box for replacing a text with another one.
SB.Replace_box.Create (SB, "",
SB.Model_replace_box.Left, SB.Model_replace_box.Top,
SB.Model_replace_box.Width, SB.Model_replace_box.Height,
False, ID => LEA_Resource_GUI.Model_replace_box);
-- Replace_box is identical to Model_replace_box, but with new methods.
SB.Model_replace_box.Hide;
SB.Replace_box.parent_SB := SB'Unrestricted_Access;
-- Hide the versions of the buttons that would close the dialog.
SB.Find_next_button.Hide;
SB.Find_next_button_permanent.Show;
SB.Find_next_button_permanent.On_Click_Handler (Find_Next_Button_Clicked'Unrestricted_Access);
SB.Find_previous_button_permanent.On_Click_Handler (Find_Previous_Button_Clicked'Unrestricted_Access);
SB.Find_all_button_permanent.On_Click_Handler (Find_All_Button_Clicked'Unrestricted_Access);
SB.Replace_and_find_next_button_permanent.On_Click_Handler (Replace_And_Find_Next_Button_Clicked'Unrestricted_Access);
SB.Replace_all_button_permanent.On_Click_Handler (Replace_All_Button_Clicked'Unrestricted_Access);
SB.Find_previous_button.Hide;
SB.Find_previous_button_permanent.Show;
SB.Find_all_button.Hide;
SB.Find_all_button_permanent.Show;
SB.Replace_and_find_next_button.Hide;
SB.Replace_and_find_next_button_permanent.Show;
SB.Replace_all_button.Hide;
SB.Replace_all_button_permanent.Show;
--
SB.Center (Parent);
SB.Keyboard_Support;
end Create_as_Search_Box;
function Compose_Scintilla_Search_Flags (SB : in LEA_Search_Box_Type) return Integer is
flags : Integer := 0;
use GWindows.Scintilla, GWindows.Buttons;
begin
if SB.Match_case.State = Checked then
flags := flags + SCFIND_MATCHCASE;
end if;
if SB.Whole_word.State = Checked then
flags := flags + SCFIND_WHOLEWORD;
end if;
return flags;
end Compose_Scintilla_Search_Flags;
end LEA_GWin.Search_Box;