-
Notifications
You must be signed in to change notification settings - Fork 0
/
HistoryComboBox.cpp
74 lines (63 loc) · 2.36 KB
/
HistoryComboBox.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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DotMatrix.h"
#include "Lcd.h"
#include "DigiClock.h"
#include "HistoryComboBox.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(THistoryComboBox *)
{
new THistoryComboBox(NULL);
}
//---------------------------------------------------------------------------
__fastcall THistoryComboBox::THistoryComboBox(TComponent* Owner)
: TComboBox(Owner)
{
if (HistorySize < DropDownCount)
HistorySize = DropDownCount;
}
//---------------------------------------------------------------------------
namespace Historycombobox
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[4] = {{__classid(THistoryComboBox)},
{__classid(TDotMatrix)},
{__classid(TLcd)},
{__classid(TDigiClock)}};
RegisterComponents("Celestial", classes, 3);
}
}
//---------------------------------------------------------------------------
int __fastcall THistoryComboBox::GetHistorySize() {
return FHistorySize;
}
//---------------------------------------------------------------------------
void __fastcall THistoryComboBox::SetHistorySize(int ACount) {
FHistorySize = ACount;
}
//---------------------------------------------------------------------------
void __fastcall THistoryComboBox::KeyPress(char &Key) {
TComboBox::KeyPress(Key); // perform standard handling, including calling handler
if (Key != NULL)
if (Key == 0x0d) // Carriage return...
UpdateHistory(Key);
}
//---------------------------------------------------------------------------
void __fastcall THistoryComboBox::UpdateHistory(char Key) {
if (!Text.IsEmpty()) {
int i = Items->IndexOf(Text); // Is string in list?
if (i != -1) // If yes, remove it...
Items->Delete(i);
if (Items->Count >= HistorySize) // Trim the list...
Items->Delete(Items->Count - 1);
Items->Insert(0, Text); // Add to top of list...
SelectAll(); // Select the entire string...
}
}
//---------------------------------------------------------------------------