📄 wwidlg.pas
字号:
begin
if not InShow then { 2/23/00 - Don't clear search text during initialization }
wwIncrementalSearch1.clear;
AdjustColumnsToIndex;
ResizeControls(True);
if not wwKeyCombo1.droppedDown then wwIncrementalSearch1.setFocus;
if Assigned(FOnSortChange) then FOnSortChange(self);
end;
procedure TwwLookupDlg.ResizeControls(padOnly: boolean);
const spacing = 13;
var
i,growByWidth, desiredSize: integer;
lastHeight: integer;
minWidth: integer;
UserButtonX: integer;
bottomPad: integer;
totalColWidth: integer;
temp: integer;
Function max(x,y: integer): integer;
begin
if x>y then result:=x
else result:= y;
end;
Function min(x,y: integer): integer;
begin
if x<y then result:=x
else result:= y;
end;
begin
bottomPad := {36;}
1 +
GetSystemMetrics(SM_CYDLGFRAME)*2 + 8 +
GetSystemMetrics(SM_CYCAPTION); {Win95 fix }
desiredSize:= GetSystemMetrics(SM_CXHThumb) + 1; {Win95 fix }
{$ifdef win32}
inc(desiredSize,3);
{$endif}
minWidth:= SortByLabel.width + SortByLabel.Left + 3;
if opShowOKCancel in Options then begin
minWidth:= OkBtn.width + CancelBtn.width + Spacing + 5;
if (UserButton1.caption<>'') then minWidth:= minWidth + UserButton1.width + 30;
if (UserButton2.caption<>'') then minWidth:= minWidth + UserButton2.width + 30;
end
else begin
if (UserButton1.caption<>'') and (UserButton2.caption<>'') then
minWidth:= max(minWidth, UserButton1.width + UserButton2.width + 35)
else if (UserButton1.caption<>'') or (UserButton2.caption<>'') then
minWidth:= max(minWidth, UserButton1.width + 35)
end;
if (opShowStatusBar in Options) then
minWidth:= max(minWidth, StatusHeader.width);
for i:= 0 to wwDBGrid1.getColCount-1 do
desiredSize:= desiredSize + wwDBGrid1.colWidths[i] + wwDBGrid1.GridLineWidth;
TotalColWidth:= desiredSize;
if (desiredSize < minWidth) then {pad last field }
begin
{ 4/30/98 - ColWidths is rounded to character boundary so expand grid by difference }
temp:= wwDBGrid1.colWidths[wwDBGrid1.getColCount-1] + (minWidth - desiredSize);
wwDBGrid1.colWidths[wwDBGrid1.getColCount-1]:= temp;
desiredSize:= minWidth + wwDBGrid1.colWidths[wwDBGrid1.getColCount-1]-temp;
end;
if padOnly then exit;
If MaxWidth= 0 then MaxWidth:= Screen.width-40
else MaxWidth:= min(MaxWidth, screen.width - 40);
If MaxHeight= 0 then MaxHeight:= Screen.height-200
else MaxHeight:= min(MaxHeight, screen.height - 200);
wwDBGrid1.height:= MaxHeight;
desiredSize:= min(desiredSize, MaxWidth);
desiredSize:= max(desiredSize, minWidth);
GrowByWidth:= desiredSize - wwDBGrid1.width;
wwDBGrid1.width:= wwDBGrid1.width + GrowByWidth;
if TotalColWidth <= wwDBGrid1.width then { Don't show horizontal scroll bar }
wwDBGrid1.ShowHorzScrollBar:= False;
wwDBGrid1.DoPerfectFit; { Adjust size before its shown }
self.width:= self.width + GrowByWidth;
if OrigLeft>=0 then
self.left:= OrigLeft
else
self.left:= (Screen.width - self.width) div 2;
lastHeight:= 8;
SearchCharacterLabel.Top:= lastHeight;
{ lastHeight:= SearchCharacterLabel.Top + SearchCharacterLabel.height + 3; ?????}
lastHeight:= SearchCharacterLabel.Top + ((13 * PixelsPerInch) div 96) + 3;
wwIncrementalSearch1.Top:= lastHeight;
lastHeight:= wwIncrementalSearch1.Top + wwIncrementalSearch1.height + 8;
wwDBGrid1.Top:= lastHeight;
lastHeight:= wwDBGrid1.top + wwDBGrid1.height;
{ Handle status bar }
if (opShowStatusBar in Options) then with DataSource1 do
begin
if (dataSet<>Nil) and (dataSet is TTable) then begin
with (dataSet as TTable) do
begin
if (database<>Nil) and (isSequenced) then
StatusHeader.visible:= True
end
end
end;
if StatusHeader.visible then begin
if (opShowOKCancel in Options) or
(UserButton1.caption<>'') or (UserButton2.caption<>'') then
{$ifdef win32}
statusHeader.top:= lastHeight + -1 { Seems to look aesthetically better in Win32}
{$else}
statusHeader.top:= lastHeight + 1
{$endif}
else statusHeader.top:= lastHeight + 10;
statusHeader.left:= wwDBGrid1.left;
statusHeader.width:= wwDBGrid1.width;
lastHeight:= statusHeader.top + statusHeader.height ;
end;
if opShowSearchBy in Options then begin
if opGroupControls in Options then begin
wwIncrementalSearch1.width := (wwDBGrid1.width-20) div 2;
SortbyLabel.visible:= True;
wwKeyCombo1.visible:= True;
SortByLabel.top:= SearchCharacterLabel.top;
wwKeyCombo1.top:= wwIncrementalSearch1.top;
wwKeyCombo1.width:= (wwDBGrid1.width - 20) div 2;
wwKeyCombo1.left:= wwIncrementalSearch1.left + wwIncrementalSearch1.width + 20;
SortbyLabel.left:= SearchCharacterLabel.left + wwIncrementalSearch1.width + 20;
wwKeyCombo1.tabOrder:= 1;
end
else begin
wwIncrementalSearch1.width := wwDBGrid1.width;
SortbyLabel.visible:= True;
wwKeyCombo1.visible:= True;
SortByLabel.top:= lastHeight + 8;
SortByLabel.left:= SearchCharacterLabel.left;
wwKeyCombo1.top:= SortByLabel.height + SortBylabel.top + 3;
wwKeyCombo1.width:= wwDBGrid1.width;
wwKeyCombo1.left:= wwDBGrid1.left;
lastHeight:= wwKeyCombo1.top + wwKeyCombo1.height;
end
end
else begin
wwIncrementalSearch1.width := wwDBGrid1.width;
end;
if (UserButton1.caption<>'') or (UserButton2.caption<>'') then begin
UserButtonPanel.visible:= True;
UserButtonPanel.top:= lastHeight + 5;
UserButtonX:= 0;
if UserButton1.caption<>'' then begin
UserButton1.visible:= True;
UserButton1.left:= UserButtonX + 10;
UserButtonX := UserButton1.left + UserButton1.width;
end;
if UserButton2.caption<>'' then begin
UserButton2.visible:= True;
UserButton2.left:= UserButtonX + 15;
UserButtonX := UserButton2.left + UserButton2.width;
end;
if opShowOKCancel in Options then
UserButtonPanel.width:= UserButtonX + 10
else UserButtonPanel.width:= wwDBGrid1.width;
end;
if opShowOKCancel in Options then begin
CancelBtn.tabStop:= True;
OkBtn.tabStop:= True;
OkBtn.top:= lastHeight + 13;
CancelBtn.top:= lastHeight + 13;
OKBtn.Left:= (self.Width - 10) - ((OKBtn.Width + Spacing) * 2);
CancelBtn.Left:= (self.Width-10) - ((OKBtn.Width + Spacing) * 1);
if (desiredSize = minWidth) then begin
OKBtn.Left:= OkBtn.Left + 5;
CancelBtn.Left:= CancelBtn.Left + 5;
end;
self.height:= OkBtn.Top + OkBtn.height + BottomPad;
end
else begin
if (UserButton1.caption<>'') or (UserButton2.caption<>'') then
self.height:= UserButtonPanel.Top + UserButtonPanel.height + BottomPad
else self.height:= lastHeight+BottomPad;
end;
if (SearchCharacterLabel.width>wwIncrementalSearch1.width) then begin
if (opShowSearchBy in Options) and (opGroupControls in Options) then
SearchCharacterlabel.caption:= wwInternational.SearchDialog.SearchCharShortLabel;
end;
end;
procedure TwwLookupDlg.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if ActiveControl=wwKeyCombo1 then begin
exit;
end;
if Key=VK_RETURN then begin
OkBtn.setFocus;
ModalResult:= mrOK;
end
else if (Key in [VK_UP, VK_DOWN, VK_NEXT, VK_PRIOR] ) then
begin
wwDBGrid1.KeyDown(Key, Shift);
Key := 0;
end
end;
procedure Register;
begin
{ RegisterPropertyEditor(TypeInfo(TStrings),
TwwLookupDialog, '', TwwLookupDialogProperty);
RegisterComponents('InfoPower', [TwwLookupDialog]);
RegisterComponentEditor(TwwLookupDialog, TwwLookupDialogComponentEditor);
}
end;
procedure TwwLookupDlg.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if wwKeyCombo1.droppedDown then canClose:= False;
if canClose then begin
wwIncrementalSearch1.onEditTimerEvent(Sender);
if Assigned(FOnCloseDialog) then FOnCloseDialog(self);
end;
end;
{ Allow drop-down to close on Escape or Return }
procedure TwwLookupDlg.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ActiveControl=wwKeyCombo1) AND
((key = VK_RETURN) or (key = VK_ESCAPE)) then
begin
wwKeyCombo1.DroppedDown:= False;
wwIncrementalSearch1.setFocus;
end;
end;
procedure TwwLookupDlg.wwKeyCombo1Enter(Sender: TObject);
begin
{ wwKeyCombo1.DroppedDown:= True;}
end;
procedure TwwLookupDlg.DoShow;
var wRect: TRect;
origTop, OrigMaxWidth, OrigMaxHeight: integer;
begin
InShow:= True;
if (not (wwIsClass(ThisDataSet.classType, 'TTable') or
wwIsClass(ThisDataSet.classType, 'TClientDataSet'))) and
(Typinfo.GetPropInfo(ThisDataSet.ClassInfo,'IndexDefs')=Nil) and
not wwKeyCombo1.UseAllFields(ThisDataSet) then
begin
Options:= Options - [opShowSearchBy];
end;
wRect:= wwGetWorkingRect;
{ 6/27/97 - Support modification of top, left, MaxHeight, MaxWidth during runtime }
If MaxWidth= 0 then MaxWidth:= Screen.width-40
else MaxWidth:= wwmin(MaxWidth, screen.width - 40);
If MaxHeight= 0 then MaxHeight:= Screen.height-200
else MaxHeight:= wwmin(MaxHeight, screen.height - 200);
Top:= wwMax(0, ((wRect.top + wRect.bottom)-(MaxHeight+200)) div 2);
Left:= ((wRect.left + wRect.right)-(MaxWidth+40)) div 2;
OrigTop:= Top;
OrigLeft:= Left;
OrigMaxWidth:= MaxWidth;
OrigMaxHeight:= MaxHeight;
if CallingComponent is TwwDBLookupComboDlg then
wwIncrementalSearch1.SearchDelay:= (CallingComponent as TwwDBLookupComboDlg).SearchDelay;
// 8/20/02 - Support OnPerformCustomSearch event
wwIncrementalSearch1.OnPerformCustomSearch:= wwGetOnPerformCustomSearch(CallingComponent);
if Assigned(FOnInitDialog) and (not initialized) then begin
FOnInitDialog(self);
if (MaxWidth<>OrigMaxWidth) and (Left=OrigLeft) then
Left:= ((wRect.left + wRect.right)-(MaxWidth+40)) div 2;
if (MaxHeight<>OrigMaxHeight) and (top=OrigTop) then
Top:= ((wRect.top + wRect.bottom)-(MaxHeight+200)) div 2;
if Left<>OrigLeft then begin
OrigLeft:= Left;
end
else OrigLeft:= -1;
end
else OrigLeft:= -1;
{ 12/18/98 - Clear keycombo datasource if its not visible }
if not (opShowSearchBy in Options) then wwKeyCombo1.datasource:= nil;
DataSource1.DataSet:= ThisDataSet;
ApplyIntl;
AdjustColumnsToIndex;
wwIncrementalSearch1.PictureMaskFromField:= PictureMaskFromField;
ResizeControls(False);
if opShowSearchBy in Options then wwKeyCombo1.InitComboWithGrid(wwDBGrid1);
inherited DoShow;
InShow:= False;
end;
procedure TwwLookupDlg.wwDBGrid1DblClick(Sender: TObject);
begin
if (not wwDBGrid1.canEditGrid) then
if (not ClickedMemoField) or (mDisableDialog in wwDBGrid1.MemoAttributes) then
ModalResult := mrOK;
end;
procedure TwwLookupDlg.DataSource1DataChange(Sender: TObject;
Field: TField);
begin
if not StatusHeader.visible then exit;
writeStatusInfo;
end;
{procedure TwwLookupDlg.wwKeyCombo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (not (ssAlt in shift)) and (key=vk_down) and (not wwKeyCombo1.DroppedDown) then begin
wwKeyCombo1.setFocus;
wwKeyCombo1.DroppedDown:= True
end
end;
}
procedure TwwLookupDlg.UserButton1Click(Sender: TObject);
begin
if Assigned(FUserButton1Click) then
FUserButton1Click(self, DataSource1.dataSet);
end;
procedure TwwLookupDlg.UserButton2Click(Sender: TObject);
begin
if Assigned(FUserButton2Click) then
FUserButton2Click(self, DataSource1.dataSet);
end;
procedure TwwLookupDlg.wwDBGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var coord: TGridCoord;
begin
coord := wwDBGrid1.MouseCoord(x,y);
clickedMemoField:= wwDBGrid1.isMemoField(Coord.x, Coord.y);
end;
procedure TwwLookupDlg.ApplyIntl;
begin
Font.Style:= wwInternational.DialogFontStyle;
with wwInternational.SearchDialog do begin
SearchCharacterLabel.caption:= SearchCharLabel;
SortBylabel.caption:= SearchByLabel;
wwIncrementalSearch1.Hint:= SearchCharHint;
wwKeyCombo1.Hint:= SearchByHint;
end
end;
procedure TwwLookupDlg.CMShowingChanged(var Message: TMessage);
{$ifdef win32}
Function isWinNT: boolean;
var vers: TOSVersionInfo;
begin
vers.dwOSVersionInfoSize := sizeOf(TOSVersionInfo);
GetVersionEx(vers);
result:= (vers.dwPlatformID = VER_PLATFORM_WIN32_NT);
end;
{$endif}
begin
{$ifdef win32}
if isWinNT then begin
if not FShowingChanged then begin
FShowingChanged:= True;
RecreateWnd; {Avoid WinNT redraw bug }
end
else inherited;
end
else inherited;
{$else}
inherited;
{$endif}
end;
procedure TwwCustomLookupDialog.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) then begin
if (FLookupTable<>Nil) and (AComponent = FLookupTable) then
FLookupTable:=Nil;
if (FSyncTable<>Nil) and (AComponent = FSyncTable) then
FSyncTable:=Nil;
end
end;
function TwwSearchDialog.GetPrimaryDataSet: TDataSet;
begin
result := SearchTable;
end;
{$ifdef win32}
procedure TwwLookupDlg.wwDBGrid1ColumnMoved(Sender: TObject; FromIndex,
ToIndex: Integer);
begin
UpdateSearchField;
end;
{$else}
procedure TwwLookupDlg.wwDBGrid1ColumnMoved(Sender: TObject; FromIndex,
ToIndex: Longint);
begin
UpdateSearchField;
end;
{$endif}
procedure TwwCustomLookupDialog.SetPictureMasks(val: TStrings);
begin
FPictureMasks.assign(val);
end;
procedure TwwCustomLookupDialog.SetControlType(val: TStrings);
begin
ControlType.assign(val);
end;
Procedure TwwCustomLookupDialog.DoSyncDataSets(tempLookupTable, FSyncTable : TDataSet);
begin
if Assigned(FOnSyncDataSets) then
FOnSyncDataSets(self, tempLookupTable, FSyncTable);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -