⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wwdbcomb.pas

📁 InfoPower_Studio 2007 v5.0.1.3 banben
💻 PAS
📖 第 1 页 / 共 5 页
字号:
//       else I:= ListBox.Items.IndexOf(Value);
    end;

    // 2/22/02
    if (FListbox=nil) or (not FListbox.HandleAllocated) then
      FItemIndex:= I
    else ItemIndex := I;

    if I >= 0 then Exit;
    if ItemIndex<0 then Text:= ''
  end
end;

procedure TwwDBCustomComboBox.SetItemList(Value: TStrings);
begin
  FItems.Assign(Value);
  DataLink.OnDataChange(Self);
end;

procedure TwwDBCustomComboBox.Loaded;
begin
  inherited;
//  FHistoryList.Source := FItems;
end;

Function TwwDBCustomComboBox.GetSorted: boolean;
begin
   result:= (FItems as TStringList).Sorted;
end;

Procedure TwwDBCustomComboBox.SetSorted(val: boolean);
begin
   (FItems as TStringList).sorted:= val;
{   FItems.Sorted:= val;}
end;

procedure TwwDBCustomComboBox.ApplyList;
var i, curpos: integer;
   TempList:TStringList;
   token1,token2:string;
begin
  ListBoxNeeded;  { 8/16/96 - Listbox needed before applying list }
  (FListbox.Items).clear;

  // 11/16/03
  // In case sorted was cleared.
  // Problem occured for instance in filterdialog when sort set to false for combo
  // but set to true for another field
  if Listbox.sorted and (not Sorted) then Listbox.sorted:= False;

  for i:= 0 to FItems.count-1 do
  begin
     curPos:= 1;
     if MapList then
       (FListbox.Items).add(strGetToken(FItems[i], #9, curPos))
     else begin
       token1:= strGetToken(FItems[i], #9, curPos);
       token2:= strGetToken(FItems[i], #9, curPos);
       if (token2='') then
          (FListbox.Items).add(token1)
       else
          (FListbox.Items).add(token2)
     end;
//     (FListbox.Items).add(strGetToken(FItems[i], #9, curPos));
  end;

  if HistoryList.enabled then
    HistoryList.Load(FListbox.Items);

  if HistoryList.enabled and HistoryList.MRUEnabled then
  begin
      TempList := TStringList.create;
      TempList.assign(FListBox.Items);
      TempList.Sorted := Sorted; //True;

      FListbox.sorted:= false;
      FListBox.Items.Clear;
      FListBox.Items.assign(TempList);

      with HistoryList do begin
         if (List.Count>EffectiveMRUCount) then begin
            for i:= List.Count-EffectiveMRUCount to List.Count - 1 do
                FListBox.Items.Insert(0, List[i]);
         end
         else begin
             for i:= 0 to List.count-1 do FListBox.Items.Insert(0, List[i]);
         end;
      end;
      Templist.free;
  end;

  DirtyListBox:= False; // 10/4/01 - Listbox is accurate after applying list
end;

function TwwDBCustomComboBox.CalcItemHeight: integer;
begin
   result:= FListbox.Canvas.TextHeight('A') + 2
end;

procedure TwwDBCustomComboBox.SetDroppedDown(val: boolean);
begin
   if IsDroppedDown then
   begin
      if (not val) then CloseUp(True)
   end
   else if val then DropDown;
end;

procedure TwwDBCustomComboBox.DropDown;
var
  P: TPoint;
  X, Y: Integer;
  WinAttribute: HWnd;
  ListBoxWidth, ListBoxHeight: integer;
{  parentForm: TCustomForm;}
   function GetDeskTopHeight:Integer;
   var Rect1:TRect;
   begin
      if SystemParametersInfo(SPI_GETWORKAREA,0,@Rect1,0) Then
         GetDeskTopHeight:=Rect1.Bottom-Rect1.Top
      else
         GetDeskTopHeight:=Screen.Height;
   end;
begin
   if FListVisible or (Style=csSimple) then exit;
   Invalidate;
{   EnableEdit;}  { 6/4/97 - Don't enter edit mode - Let EditCanModify handle it in CloseUp event}

   ApplyList;
   //11/05/2001 - Allow overriding of Listbox Color and Font.
   FListBox.Color := Color;
   FListBox.Font := Font;

   if Assigned(FOnDropDown) then
   begin
      FOnDropDown(Self);
      if DisableDropDownList then exit;
      ApplyList;  { In case the list was modified }
   end
   else if DisableDropDownList then exit;

   case Style of
      csOwnerDrawFixed: FListBox.Style:= lbOwnerDrawFixed;
      csOwnerDrawVariable: FListBox.Style:= lbOwnerDrawVariable;
      else begin
         if (HistoryList.Enabled and HistoryList.MRUEnabled) or TwoColumnDisplay then
            FListbox.Style:= lbOwnerDrawFixed;
      end
   end;
   if wwIsClass(self.classtype, 'TwwImageCombo') then
      FListBox.Style:= lbOwnerDrawFixed;

   if HistoryList.enabled and HistoryList.MRUEnabled then
      FListBox.Sorted:= False
   else FListBox.Sorted:= Sorted;
//   FListBox.Color := Color;
//   FListBox.Font := Font;
   if FItemHeight=0 then
     FListBox.ItemHeight:= CalcItemHeight //FListbox.Canvas.TextHeight('A') + 2
   else
     FListBox.ItemHeight:= FItemHeight;

   if FListBox.Items.Count >= DropDownCount then
     ListBoxHeight:= DropDownCount * FListBox.ItemHeight + 4
   else
     ListBoxHeight:= FListBox.Items.Count * FListBox.ItemHeight + 4;

   if FDropDownWidth=0 then
   begin
      if Column1Width = 0 then
         ListBoxWidth:= Width
      else
         ListBoxWidth:= Column1Width * 3 div 2;//ListBoxWidth:= Width
   end
   else ListBoxWidth:= FDropDownWidth;

   { Pre-select record }
   if OwnerDraw and (DataLink.Field<>Nil) then
      //SetListBoxItemIndex(IndexOf(DataLink.Field.asString))
      //11/05/2001 - Not taking into account maplist when owner draw.
      SetListBoxItemIndex(IndexOf(Text))
//      SetListBoxItemIndex(FListBox.Items.IndexOf(DataLink.Field.asString))
   else if Text='' then
      SetListBoxItemIndex(-1)
   else begin
     if Field<>Nil then
        SetListBoxItemIndex(IndexOf(Text))
//        SetListBoxItemIndex(FListBox.Items.IndexOf(Text))
     else
        SetListBoxItemIndex(IndexOf(Text))
//        SetListBoxItemIndex(FListBox.Items.IndexOf(Text))
   end;

   P := Parent.ClientToScreen(Point(Left, Top));
   Y := P.Y + Height - 1;
   if BorderStyle = bsNone then y:= y + 1;

  { 11/28/2000 - PYW - Check based on actual work area. }
   if Y + ListBoxHeight > GetDeskTopHeight then Y := P.Y - ListBoxHeight;

   { 4/1/97 - Expand list to left since it goes past edge of screen }
   X := P.X ;
   if P.X + ListBoxWidth >= Screen.Width then X := P.X + Width - 1 - ListBoxWidth;

   { 3/13/97 - Always Top so that drop-down is not hidden under taskbar}
   WinAttribute:= HWND_TOPMOST;
   SetWindowPos(FListBox.Handle, WinAttribute, X, Y, ListBoxWidth, ListBoxHeight,
    {  SWP_NOSIZE or} SWP_NOACTIVATE or SWP_SHOWWINDOW);
   FListVisible := True;
   FNoKeysEnteredYet:= True;

   Windows.SetFocus(Handle);
   if not inAutoDropDown then DoSelectAll;
   if Editable then ShowCaret(Handle);

   LastShowHint:= ShowHint;
   ShowHint:= False;
   Invalidate;

   {$ifdef wwDelphi4up}
   if wwHook=0 then
      wwHook := SetWindowsHookEx(WH_MOUSE, @wwHookProc, HINSTANCE, GetCurrentThreadID);
   {$endif}

   PreDropDownText:= Text;

end;

procedure TwwDBCustomComboBox.CloseUp(Accept: Boolean);
var
  ListValue: String;
begin
  if FListVisible then
  begin
    ListValue:= '';
    if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
    if (not ReadOnly) and Accept and (FListbox.ItemIndex <> -1) and (FListbox.items.count>0) then
        ListValue := FListbox.Items[FListbox.ItemIndex]
   { 9/26/97 - Prevents going into edit mode  if ListValue=Text}
    else if style=csDropDown then ListValue:= Text
    else if style=csDropDownList then begin
       if FListBox.ItemIndex=-1 then ListValue:= Text { don't clear if item not found }
    end;

    SetWindowPos(FListbox.Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or
      SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
    FListVisible := False;
    if Accept then
    begin
      if (DataLink.Field=Nil) and (inherited ReadOnly) then // 2/22/02 - do nothing if unbound and readonly
      else try
        Patch[1]:= True;
        if (ListValue<>PreDropDownText) and EditCanModify then { 6/5/97 - Only update if changed }
        begin
           FItemIndex:= FListBox.itemIndex; // 6/16/03 - Update FItemIndex before Text

           if ListValue<>'' then begin
              Text:= ListValue;
           end
           else if (Style=csDropDownList) or FMapList then Text:= '';
           FItemIndex:= FListBox.itemIndex;
           SetModified(True);  {1/21/97}

           if FHistoryList.Enabled and Modified then
           begin
              AddItem(Text, True);
              HistoryList.Save;
           end;

        end;
      finally
        Patch[1]:= False;
      end
    end;
    if (not Editable) then HideCaret(Handle);
    Invalidate;
    DoSelectAll;
{    FListBox.Free;
    FListBox:= Nil; } { 5/2/97}
    if self is TwwDBComboBox then
      if Assigned(FOnCloseUp) then FOnCloseUp(TwwDBComboBox(Self), Accept);
    ShowHint:= LastShowHint; { 10/12/98 }
  end
  else if Accept and (not MapList) then begin // 7/12/02 - Clear itemindex if user cleared text
     if Text='' then
       ItemIndex:= -1;
  end;


   {$ifdef wwDelphi4up}
{   if wwHook<>0 then
   begin
     UnhookWindowsHookEx(wwHook);
     wwHook:= 0;
   end;
}
   {$endif}

end;

Procedure TwwDBCustomComboBox.DoSelectAll;
begin
   if Editable then SelectAll;
end;

Function TwwDBCustomComboBox.GetItemIndex: integer;

  function FindItemIndex : integer;
  var i,j,curpos: integer;
      NewText: string;
  begin
    if (Text = '') and (not MapList) then I := -1
    else begin
          i:= -1;
          for j:= 0 to FItems.count-1 do begin
             curpos:= 1;
             NewText:= strGetToken(FItems[j], #9, curPos);
             if NewText=Text then
             begin
                i:= IndexOf(NewText);
                break;
             end
          end;
    end;
    result:= i;
  end;

begin
   // 6/12/03 - Refer to FItemIndex unless it is dropped down so itemindex is accurate
   if (FListBox<>Nil) and IsDroppedDown then
      result:= FListbox.itemIndex
   else begin
      if Patch[5] then
      begin
        FItemIndex:= FindItemIndex;
      end;
      result:= FItemIndex;
   end
end;

{Function TwwDBCustomComboBox.GetItemIndex: integer;
begin
   if (FListBox<>Nil) then result:= FListbox.itemIndex
   else result:= FItemIndex;
end;
}

procedure TwwDBCustomComboBox.SetListBoxItemIndex(val: integer);
begin
   { workaround for Delphi 4 bug in listbox/combo-box}
   {$ifdef wwdelphi4up}
   SendMessage(FListbox.Handle, LB_SETCURSEL, Val, 0);
   {$endif}
   FListbox.ItemIndex:= val;
end;

procedure TwwDBCustomComboBox.SetItemIndex(val: integer);
begin
   FItemIndex:= val;
   ListBoxItemsNeeded;
   if (FListBox<>Nil) then SetListBoxItemIndex(Val);
   if (val>=0) and (val<FListBox.Items.count) then
   begin
      Text:= FListBox.Items[val];
   end
   else if val=-1 then Text:= '' { 12/6/98 }
end;

Function TwwDBCustomComboBox.isDroppedDown: boolean;
begin
    result:= FListVisible;
end;

procedure TwwDBCustomComboBox.CMCancelMode(var Message: TCMCancelMode);
begin
  if (Message.Sender <> Self) and (Message.Sender <> FListBox) and
     (Message.Sender <> Button) then
    CloseUp(True);
end;

procedure TwwDBCustomComboBox.WMKillFocus(var Message: TWMKillFocus);
begin
  inherited;
  CloseUp(True);
  if FHistoryList.Enabled and Modified then
  begin
     AddItem(Text, True);
     HistoryList.Save;
  end
end;

procedure TwwDBCustomComboBox.ListMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Button = mbLeft) and PtInRect((Sender as TCustomListBox).ClientRect, Point(x,y)) then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -