summaryrefslogtreecommitdiff
path: root/src/windows-find.adb
blob: 394ce2d23c5433fb2d9230952cc399bc0dfe2f6d (plain)
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


with FLTK.Widgets.Groups.Windows.Double;
with FLTK.Widgets.Inputs;
with FLTK.Widgets.Buttons.Enter;
with FLTK.Widgets.Buttons.Light.Check;


package body Windows.Find is


    package WD renames FLTK.Widgets.Groups.Windows.Double;
    package IP renames FLTK.Widgets.Inputs;
    package BU renames FLTK.Widgets.Buttons;
    package EN renames FLTK.Widgets.Buttons.Enter;
    package LC renames FLTK.Widgets.Buttons.Light.Check;




    procedure Find_M
           (Item : in out FLTK.Widgets.Widget'Class)
    is
        use type BU.State;
        type Find_Window_Access is access all Find_Window;
        Dialog : access Find_Window := Find_Window_Access (Item.Parent);
    begin
        if Dialog.Callback /= null then
            Dialog.Callback.all
                   (Dialog.Find_What.Get_Value,
                    Dialog.Match_Case.Get_State = BU.On,
                    Forward);
        end if;
    end Find_M;




    function Create
        return Find_Window
    is
        My_Width  : Integer := 350;
        My_Height : Integer := 130;

        Button_Width  : Integer := 140;
        Button_Height : Integer := 40;

        Input_Line  : Integer := 10;
        Case_Line   : Integer := 50;
        Button_Line : Integer := 80;

        Input_Width  : Integer := 240;
        Input_Height : Integer := 25;
        Input_Margin_Right : Integer := 10;

        Check_Width  : Integer := 100;
        Check_Height : Integer := 20;
        Case_Margin_Left   : Integer := 50;

        Text_Size : Integer := 12;
    begin
        return This : Find_Window :=
                   (WD.Double_Window'(WD.Create (0, 0, My_Width, My_Height, "Find")) with

                    Find_What => IP.Input'(IP.Create
                        (My_Width - Input_Width - Input_Margin_Right,
                         Input_Line, Input_Width, Input_Height, "Find what:")),
                    Match_Case => LC.Check_Button'(LC.Create
                        (Case_Margin_Left, Case_Line, Check_Width, Check_Height, "Match case")),
                    Cancel => BU.Button'(BU.Create
                        ((My_Width - 2 * Button_Width) / 3,
                         Button_Line, Button_Width, Button_Height, "Cancel")),
                    Start => EN.Enter_Button'(EN.Create
                        ((My_Width - 2 * Button_Width) * 2 / 3 + Button_Width,
                         Button_Line, Button_Width, Button_Height, "Find")),

                    Callback => null) do

            This.Add (This.Find_What);
            This.Add (This.Match_Case);
            This.Add (This.Cancel);
            This.Cancel.Set_Callback (Hide_CB'Access);
            This.Add (This.Start);
            This.Start.Set_Callback (Find_M'Access);

            This.Set_Callback (Hide_CB'Access);
            This.Set_Icon (Logo);
            This.Set_Modal;
        end return;
    end Create;




    function Create
           (X, Y, W, H : in Integer;
            Label_Text : in String)
        return Find_Window is
    begin
        return Create;
    end Create;




    function Create
           (W, H : in Integer)
        return Find_Window is
    begin
        return Create;
    end Create;




    procedure Set_Find_Callback
           (This : in out Find_Window;
            Func : in     Find_Callback) is
    begin
        This.Callback := Func;
    end Set_Find_Callback;




    procedure Do_Callback
           (This : in Find_Window;
            Dir  : in Direction := Forward)
    is
        use type BU.State;
    begin
        if This.Callback /= null then
            This.Callback.all
                   (This.Find_What.Get_Value,
                    This.Match_Case.Get_State = BU.On,
                    Dir);
        end if;
    end Do_Callback;


end Windows.Find;