-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrmHostList.cpp
105 lines (97 loc) · 3.24 KB
/
FrmHostList.cpp
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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "FrmHostList.h"
#include "FrmRemoteHostInfo.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormHostList *FormHostList;
//---------------------------------------------------------------------------
__fastcall TFormHostList::TFormHostList(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::BtnCancelClick(TObject *Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::BtnApplyClick(TObject *Sender)
{
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::CheckListBoxMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (Button == mbLeft)
LastClick = CheckListBox->ItemAtPos(TPoint(X, Y), true);
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::CheckListBoxClickCheck(TObject *Sender)
{
if (LastClick != -1) {
for (int i = 0; i < CheckListBox->Items->Count; i++) {
CheckListBox->Checked[i] = false;
if (LastClick == i)
CheckListBox->Checked[i] = true;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::SetMyHostList(THostList *src, TRemoteHostInfoPtr hl, int Count)
{
Source = src;
MyHostList = hl;
HostCount = Count;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::BtnEditClick(TObject *Sender)
{
TFormRemoteHostInfo *frm = new TFormRemoteHostInfo(this);
AnsiString *host = new AnsiString();
if (CheckListBox->ItemIndex > -1) {
*host = CheckListBox->Items->Strings[CheckListBox->ItemIndex];
TRemoteHostInfo *ptr;
for (int i = 0; i < HostCount; i++) {
ptr = MyHostList[i];
if (ptr->HostName == *host) {
frm->SetMyHost(ptr);
frm->ShowModal();
break;
}
}
}
delete host;
delete frm;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::FormShow(TObject *Sender)
{
BtnEdit->Enabled = (CheckListBox->Items->Count > 0);
BtnRemove->Enabled = BtnEdit->Enabled;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::BtnAddClick(TObject *Sender)
{
AnsiString *nh = new AnsiString();
*nh = InputBox("Add a host", "Hostname to add?", "");
if (!Source->IsInList(*nh)) {
Source->Add(*nh);
CheckListBox->Items->Add(*nh);
HostCount++;
}
delete nh;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostList::BtnRemoveClick(TObject *Sender)
{
if (CheckListBox->ItemIndex != -1) {
Source->Delete(CheckListBox->Items->Strings[CheckListBox->ItemIndex]);
CheckListBox->Items->Delete(CheckListBox->ItemIndex);
HostCount--;
}
}
//---------------------------------------------------------------------------