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

📄 scombobox.pas

📁 Alpha Controls 界面控件包
💻 PAS
📖 第 1 页 / 共 3 页
字号:

type TAccessCustomComboBox = class(TCustomComboBox);

procedure TsCustomComboBox.CreateWnd;
var
  PreInheritedAnsiText: AnsiString;
begin
  PreInheritedAnsiText := TAccessCustomComboBox(Self).Text;
  inherited;
  TntCombo_AfterInherited_CreateWnd(Self, Items, FSaveItems, FSaveItemIndex, PreInheritedAnsiText);
end;

procedure TsCustomComboBox.DefineProperties(Filer: TFiler);
begin
  inherited;
  TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
{$ENDIF}

destructor TsCustomComboBox.Destroy;
begin
  if lBoxHandle <> 0 then begin
    SetWindowLong(lBoxHandle, GWL_STYLE, GetWindowLong(lBoxHandle, GWL_STYLE) and not WS_THICKFRAME or WS_BORDER);
    UninitializeACScroll(lBoxHandle, True, False, ListSW);
    lBoxHandle := 0;
  end;
  FreeAndNil(FBoundLabel);
  if Assigned(FCommonData) then FreeAndNil(FCommonData);
{$IFDEF TNTUNICODE}
  FreeAndNil(FItems);
  FreeAndNil(FSaveItems);
{$ENDIF}
  inherited Destroy;
end;

{$IFDEF TNTUNICODE}
procedure TsCustomComboBox.DestroyWnd;
var
  SavedText: WideString;
begin
  if not (csDestroyingHandle in ControlState) then begin { avoid recursion when parent is TToolBar and system font changes. }
    TntCombo_BeforeInherited_DestroyWnd(Self, Items, FSaveItems, ItemIndex, FSaveItemIndex, SavedText);
    inherited;
    TntControl_SetStoredText(Self, SavedText);
  end;
end;

procedure TsCustomComboBox.DoEditCharMsg(var Message: TWMChar);
begin
  TntCombo_AutoCompleteKeyPress(Self, Items, Message, GetAutoComplete_UniqueMatchOnly, GetAutoComplete_PreserveDataEntryCase);
end;
{$ENDIF}

procedure TsCustomComboBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  Offset : integer;
begin
  if FCommonData.Skinned and (odComboBoxEdit in State) then begin
    BitBlt(Canvas.Handle, 0, 0, Width, Height, FCommonData.FCacheBmp.Handle, 0, 0, SRCCOPY);
    if not Enabled or ReadOnly then Exit;
    Canvas.Font.Assign(Font);
    if DroppedDown then begin
      if (odComboBoxEdit in State) then begin
        Canvas.Font.Color := Font.Color;
        Canvas.Brush.Style := bsClear;
      end
      else begin
        Canvas.Brush.Style := bsSolid;
        if not DroppedDown then begin
          Canvas.Font.Color := clHighLightText;
          Canvas.Brush.Color := clHighLight;
          Canvas.FillRect(Rect);
        end
        else begin
          Canvas.Font.Color := Font.Color;
          if FCommonData.Skinned or not (odComboBoxEdit in State) then Canvas.Brush.Style := bsClear else begin
            Canvas.Brush.Color := ColorToRGB(Color);
            Canvas.FillRect(Rect);
          end;
        end;
      end;
      if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State) else begin
        TControlCanvas(Canvas).UpdateTextFlags;
        if Text <> '' then begin
          Offset := integer(Style <> csDropDown);
  {$IFDEF TNTUNICODE}
          WideCanvasTextOut(Canvas, Rect.Left + Offset, Rect.Top + Offset, Items[Index]);
  {$ELSE}
          Canvas.TextRect(Rect, Rect.Left + Offset, Rect.Top + Offset, Items[Index]);
  {$ENDIF}
        end;
      end;
      if odFocused in State then Canvas.DrawFocusRect(Rect);
    end
    else begin
      Canvas.Brush.Style := bsSolid;
      if IsOwnerDraw(Self) then begin
        if (odFocused in State) then begin
          Canvas.Font.Color := clHighLightText;
          Canvas.Brush.Color := clHighLight;
        end
        else begin
          Canvas.Font.Color := Font.Color;
          Canvas.Brush.Color := Color;
        end;
        OnDrawItem(Self, Index, Rect, State);
      end
      else begin
        if not ((odSelected in State) or (odFocused in State) or FCommonData.FFocused or Focused) then Exit;
        Canvas.Font.Color := clHighLightText;
        Canvas.Brush.Color := clHighLight;

        Canvas.FillRect(Rect);

        TControlCanvas(Canvas).UpdateTextFlags;
        if Text <> '' then begin
          Offset := integer(Style <> csDropDown);
{$IFDEF TNTUNICODE}
          WideCanvasTextOut(Canvas, Rect.Left + Offset, Rect.Top + Offset, Items[Index]);
{$ELSE}
          Canvas.TextRect(Rect, Rect.Left + Offset, Rect.Top + Offset, Items[Index]);
{$ENDIF}
        end;
      end;
    end;
  end
  else begin
    Canvas.Font.Assign(Font);
    if ((odSelected in State) or (odFocused in State)) then begin
      Canvas.Font.Color := clHighLightText;
      Canvas.Brush.Color := clHighLight;
      Canvas.Brush.Style := bsSolid;
      if not IsOwnerDraw(Self) then Canvas.FillRect(Rect);
    end
    else begin
      if Enabled then Canvas.Font.Color := Font.Color else Canvas.Font.Color := clBtnShadow;
      Canvas.Brush.Color := ColorToRGB(Color);
      Canvas.Brush.Style := bsSolid;
      Canvas.FillRect(Rect);
    end;
    if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State) else begin
      TControlCanvas(Canvas).UpdateTextFlags;
      if Text <> '' then begin
        Offset := integer(Style <> csDropDown);
{$IFDEF TNTUNICODE}
        WideCanvasTextOut(Canvas, Rect.Left + Offset, Rect.Top + Offset, Items[Index]);
{$ELSE}
        Canvas.TextRect(Rect, Rect.Left + Offset, Rect.Top + Offset, Items[Index]);
{$ENDIF}
      end;
    end;
  end;
end;

procedure TsCustomComboBox.DrawSkinItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  Offset : integer;
begin
  FCommonData.FCacheBmp.Canvas.Font.Assign(Font);
  if (odFocused in State) then begin
    FCommonData.FCacheBmp.Canvas.Font.Color := clHighlightText;
    FCommonData.FCacheBmp.Canvas.Brush.Color := clHighlight;
    FCommonData.FCacheBmp.Canvas.Brush.Style := bsSolid;
    FCommonData.FCacheBmp.Canvas.FillRect(Rect);
  end
  else begin
    FCommonData.FCacheBmp.Canvas.Font.Color := Font.Color;
    FCommonData.FCacheBmp.Canvas.Brush.Color := Color;
    FCommonData.FCacheBmp.Canvas.Brush.Style := bsClear;
  end;
  if Text <> '' then begin
    Offset := integer(Style <> csDropDown);
{$IFDEF TNTUNICODE}
    WideCanvasTextOut(FCommonData.FCacheBmp.Canvas, Rect.Left + Offset, Rect.Top + Offset, Text);
{$ELSE}
    FCommonData.FCacheBmp.Canvas.TextRect(Rect, Rect.Left + Offset, Rect.Top + Offset, Text);
{$ENDIF}
  end;
  if odFocused in State then DrawFocusRect(FCommonData.FCacheBmp.Canvas.Handle, Rect);
end;

{
procedure TsCustomComboBox.DropDown;
begin
  FDropDown := True;
  inherited;
end;
}
function TsCustomComboBox.Focused: Boolean;
var
  FocusedWnd: HWND;
begin
  Result := False;
  if HandleAllocated then begin
    FocusedWnd := GetFocus;
    Result := (FocusedWnd <> 0) and ((FocusedWnd = EditHandle) or (FocusedWnd = ListHandle)) or FCommonData.FFocused;
  end;
end;

function TsCustomComboBox.FullPaint: boolean;
begin
  Result := False;
end;

{$IFDEF TNTUNICODE}
function TsCustomComboBox.GetActionLinkClass: TControlActionLinkClass;
begin
  Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;

function TsCustomComboBox.GetAutoComplete_PreserveDataEntryCase: Boolean;
begin
  Result := True;
end;

function TsCustomComboBox.GetAutoComplete_UniqueMatchOnly: Boolean;
begin
  Result := False;
end;

function TsCustomComboBox.GetHint: WideString;
begin
  Result := TntControl_GetHint(Self)
end;

function TsCustomComboBox.GetItems: TTntStrings;
begin
  Result := FItems;
end;

{$IFDEF DELPHI7}
function TsCustomComboBox.GetItemsClass: TCustomComboBoxStringsClass;
begin
  Result := TD7PatchedComboBoxStrings;
end;
{$ENDIF}

function TsCustomComboBox.GetSelLength: Integer;
begin
  Result := TntCombo_GetSelLength(Self);
end;

function TsCustomComboBox.GetSelStart: Integer;
begin
  Result := TntCombo_GetSelStart(Self);
end;

function TsCustomComboBox.GetSelText: WideString;
begin
  Result := TntCombo_GetSelText(Self);
end;

function TsCustomComboBox.GetText: WideString;
begin
  Result := TntControl_GetText(Self);
end;
{$ENDIF}

function TsCustomComboBox.IndexOf(s: string): integer;
var
  i : integer;
begin
  Result := -1;
  for i := 0 to Items.Count - 1 do if Items[i] = s then begin
    Result := i;
    Break;
  end;
end;

procedure TsCustomComboBox.Invalidate;
begin
  if Focused then FCommonData.FFocused := True;
  inherited Invalidate;
end;

{$IFDEF TNTUNICODE}
function TsCustomComboBox.IsHintStored: Boolean;
begin
  Result := TntControl_IsHintStored(Self)
end;

procedure TsCustomComboBox.KeyPress(var Key: AnsiChar);
var
  SaveAutoComplete: Boolean;
begin
  TntCombo_BeforeKeyPress(Self, SaveAutoComplete);
  try
    inherited;
  finally
    TntCombo_AfterKeyPress(Self, SaveAutoComplete);
  end;
end;
{$ENDIF}

procedure TsCustomComboBox.Loaded;
begin
  inherited Loaded;
  FCommonData.Loaded;
  if FCommonData.Skinned then begin
    if not FCommonData.CustomColor then Color := FCommonData.SkinManager.gd[FCommonData.SkinIndex].Color;
    if not FCommonData.CustomFont then Font.Color := FCommonData.SkinManager.gd[FCommonData.SkinIndex].FontColor[1];
  end;
end;

procedure TsCustomComboBox.OurPaintHandler(iDC : hdc);
const
  BordWidth = 3;
var
  DC : hdc;
  R : TRect;
  State : TOwnerDrawState;
begin
  if not Showing then Exit;
  if iDC = 0 then DC := GetDC(Handle) else DC := iDC;
  R := ButtonRect;
  try
    FCommonData.Updating := FCommonData.Updating;
    if not FCommonData.Updating then begin
      FCommonData.BGChanged := FCommonData.BGChanged or FCommonData.HalfVisible or GetBoolMsg(Parent, AC_GETHALFVISIBLE);
      FCommonData.HalfVisible := not RectInRect(Parent.ClientRect, BoundsRect);

      if FCommonData.BGChanged then PrepareCache;
      UpdateCorners(FCommonData, 0);

      if Enabled then case Style of
        csSimple : begin
          BitBltBorder(DC, 0, 0, Width, FCommonData.FCacheBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, BordWidth);
        end;
        csDropDown : begin
          if Focused then begin
            BitBltBorder(DC, 0, 0, Width, FCommonData.FCacheBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, BordWidth);
            R := ButtonRect;
            BitBlt(DC, R.Left, R.Top, WidthOf(R), HeightOf(R), FCommonData.FCacheBmp.Canvas.Handle, R.Left, R.Top, SRCCOPY);
          end
          else BitBlt(DC, 0, 0, Width, FCommonData.FCacheBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
        end;
        csDropDownList : begin
          BitBlt(DC, 0, 0, Width, FCommonData.FCacheBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
        end;
        csOwnerDrawFixed, csOwnerDrawVariable : begin
          BitBltBorder(DC, 0, 0, Width, FCommonData.FCacheBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, BordWidth);
          R := ButtonRect;
          BitBlt(DC, R.Left, R.Top, WidthOf(R), HeightOf(R), FCommonData.FCacheBmp.Canvas.Handle, R.Left, R.Top, SRCCOPY);

//          if not (Focused or FCommonData.FFocused) then begin // v5.13
//            if (ItemIndex > -1) then begin // v5.13
              Canvas.Handle := DC;
              R := Rect(BordWidth, BordWidth, ButtonRect.Left, FCommonData.FCacheBmp.Height - BordWidth);

              State := [odComboBoxEdit];
              if (Focused or SkinData.FFocused) and not (Style in [csDropDown, csSimple]) then State := State + [odFocused, odSelected];
              DrawItem(ItemIndex, R, State);

⌨️ 快捷键说明

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