30 |
|
interface |
31 |
|
|
32 |
|
uses |
33 |
< |
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DbCtrls, |
33 |
> |
Classes, SysUtils, LCLType, LResources, Forms, Controls, Graphics, Dialogs, DbCtrls, |
34 |
|
ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet, LCLVersion; |
35 |
|
|
36 |
|
type |
77 |
|
|
78 |
|
TIBLookupComboEditBox = class(TDBLookupComboBox) |
79 |
|
private |
80 |
– |
FCanAutoInsert: TCanAutoInsert; |
80 |
|
{ Private declarations } |
81 |
|
FDataLink: TIBLookupComboDataLink; |
82 |
|
FIBLookupControlLink: TIBLookupControlLink; |
117 |
|
procedure CheckAndInsert; |
118 |
|
procedure DoEnter; override; |
119 |
|
procedure DoExit; override; |
120 |
+ |
{$if lcl_fullversion >= 2000000} |
121 |
+ |
{Deferred update changes in Lazarus 2.0 stop the combo box working when |
122 |
+ |
the datasource is nil. We thus have to reverse out the changes :(} |
123 |
+ |
function DoEdit: boolean; override; |
124 |
+ |
procedure Change; override; |
125 |
+ |
procedure CloseUp; override; |
126 |
+ |
procedure Select; override; |
127 |
+ |
procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override; |
128 |
+ |
{$ifend} |
129 |
|
procedure KeyUp(var Key: Word; Shift: TShiftState); override; |
130 |
|
procedure Loaded; override; |
131 |
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override; |
156 |
|
|
157 |
|
implementation |
158 |
|
|
159 |
< |
uses IBQuery, LCLType, Variants, LCLProc, LazUTF8; |
159 |
> |
uses Variants, LCLProc, LazUTF8; |
160 |
|
|
161 |
|
{ TIBLookupControlLink } |
162 |
|
|
204 |
|
{ TIBLookupComboEditBox } |
205 |
|
|
206 |
|
procedure TIBLookupComboEditBox.HandleTimer(Sender: TObject); |
199 |
– |
var ActiveState: boolean; |
207 |
|
begin |
208 |
|
FTimer.Interval := 0; |
209 |
|
FFiltered := Text <> ''; |
354 |
|
sCompleteText := ListSource.DataSet.FieldByName(ListField).AsString; |
355 |
|
if (sCompleteText <> FCurText) then |
356 |
|
begin |
357 |
+ |
KeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; |
358 |
|
sResultText := sCompleteText; |
359 |
|
if ((cbactEndOfLineComplete in AutoCompleteText) and |
360 |
|
(cbactRetainPrefixCase in AutoCompleteText)) then |
364 |
|
end; |
365 |
|
Text := sResultText; |
366 |
|
SelStart := iSelStart; |
367 |
< |
SelLength := UTF8Length(Text); |
367 |
> |
SelLength := UTF8Length(Text) - iSelStart; |
368 |
|
end; |
361 |
– |
KeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; |
369 |
|
end |
370 |
|
else |
371 |
|
begin |
510 |
|
procedure TIBLookupComboEditBox.KeyUp(var Key: Word; Shift: TShiftState); |
511 |
|
begin |
512 |
|
inherited KeyUp(Key, Shift); |
506 |
– |
if Key = VK_RETURN then |
507 |
– |
EditingDone |
508 |
– |
else |
513 |
|
if Key = VK_ESCAPE then |
514 |
|
begin |
515 |
|
SelStart := UTF8Length(Text); {Ensure end of line selection} |
518 |
|
SelectAll; |
519 |
|
end |
520 |
|
else |
521 |
+ |
if AutoComplete and (Style <> csDropDownList) then |
522 |
|
begin |
523 |
< |
FTimer.Interval := 0; |
524 |
< |
if (IsEditableTextKey(Key) or (Key = VK_BACK)) |
525 |
< |
and AutoComplete and (Style <> csDropDownList) and |
526 |
< |
(not (cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then |
523 |
> |
if (Key = VK_BACK) or (Key = VK_DELETE) then |
524 |
> |
begin |
525 |
> |
if SelStart = 0 then |
526 |
> |
begin |
527 |
> |
SelStart := UTF8Length(Text); |
528 |
> |
SelLength := 0; |
529 |
> |
end; |
530 |
> |
FTimer.Interval := 0; |
531 |
> |
end |
532 |
> |
else |
533 |
> |
if IsEditableTextKey(Key) and |
534 |
> |
(not(cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then |
535 |
> |
begin |
536 |
> |
FTimer.Interval := 0; |
537 |
|
FTimer.Interval := FKeyPressInterval; |
538 |
+ |
end; |
539 |
|
end; |
540 |
|
end; |
541 |
|
|
555 |
|
|
556 |
|
procedure TIBLookupComboEditBox.SetItemIndex(const Val: integer); |
557 |
|
begin |
558 |
+ |
if Val > 0 then |
559 |
+ |
FCurText := ''; |
560 |
|
inherited SetItemIndex(Val); |
561 |
|
FLastKeyValue := KeyValue; |
562 |
|
end; |
582 |
|
procedure TIBLookupComboEditBox.UpdateData(Sender: TObject); |
583 |
|
begin |
584 |
|
inherited UpdateData(Sender); |
585 |
+ |
if FCurText <> '' then |
586 |
+ |
Text := FCurText + Text; |
587 |
|
FModified := false; |
588 |
|
end; |
589 |
|
|
590 |
+ |
{$if lcl_fullversion >= 2000000} |
591 |
+ |
type |
592 |
+ |
|
593 |
+ |
{ THackedCustomComboBox } |
594 |
+ |
|
595 |
+ |
THackedCustomComboBox = class(TCustomComboBox) |
596 |
+ |
private |
597 |
+ |
procedure CallUTF8KeyPress(var UTF8Key: TUTF8Char); |
598 |
+ |
procedure CallChange; |
599 |
+ |
end; |
600 |
+ |
|
601 |
+ |
{ THackedCustomComboBox } |
602 |
+ |
|
603 |
+ |
procedure THackedCustomComboBox.CallUTF8KeyPress(var UTF8Key: TUTF8Char); |
604 |
+ |
begin |
605 |
+ |
inherited UTF8KeyPress(UTF8Key); |
606 |
+ |
end; |
607 |
+ |
|
608 |
+ |
procedure THackedCustomComboBox.CallChange; |
609 |
+ |
begin |
610 |
+ |
inherited Change; |
611 |
+ |
end; |
612 |
+ |
|
613 |
+ |
procedure TIBLookupComboEditBox.UTF8KeyPress(var UTF8Key: TUTF8Char); |
614 |
+ |
begin |
615 |
+ |
{TDBLookupComboBox.UTF8KeyPress will swallow the character if |
616 |
+ |
the datalink is not editable. hence to enable writing we must override it} |
617 |
+ |
if ((DataSource = nil) or (Field = nil)) and not ReadOnly then |
618 |
+ |
THackedCustomComboBox(self).CallUTF8KeyPress(UTF8Key) |
619 |
+ |
else |
620 |
+ |
inherited; |
621 |
+ |
end; |
622 |
+ |
|
623 |
+ |
procedure TIBLookupComboEditBox.Change; |
624 |
+ |
begin |
625 |
+ |
THackedCustomComboBox(self).CallChange; |
626 |
+ |
end; |
627 |
+ |
|
628 |
+ |
procedure TIBLookupComboEditBox.CloseUp; |
629 |
+ |
begin |
630 |
+ |
inherited CloseUp; |
631 |
+ |
inherited DoEdit; |
632 |
+ |
end; |
633 |
+ |
|
634 |
+ |
procedure TIBLookupComboEditBox.Select; |
635 |
+ |
begin |
636 |
+ |
inherited Select; |
637 |
+ |
inherited DoEdit; |
638 |
+ |
end; |
639 |
+ |
|
640 |
+ |
function TIBLookupComboEditBox.DoEdit: boolean; |
641 |
+ |
begin |
642 |
+ |
{DoEdit will swallow characters if no editable Field. Hence, to enabled |
643 |
+ |
writing we must avoid calling the inherited method.} |
644 |
+ |
if ((DataSource = nil) or (Field = nil)) and not ReadOnly then |
645 |
+ |
Result := true |
646 |
+ |
else |
647 |
+ |
Result := inherited DoEdit; |
648 |
+ |
end; |
649 |
+ |
{$ifend} |
650 |
+ |
|
651 |
|
constructor TIBLookupComboEditBox.Create(TheComponent: TComponent); |
652 |
|
begin |
653 |
|
inherited Create(TheComponent); |
680 |
|
FForceAutoComplete := false; |
681 |
|
end; |
682 |
|
CheckAndInsert; |
683 |
+ |
FCurText := ''; |
684 |
|
if FModified then |
685 |
|
Change; {ensure Update} |
686 |
|
inherited EditingDone; |