TsCombobox

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #34531
    QStorm
    Participant

    Hi,

    I am have a TsComboBox which displays all available fonts. So the user can select a font. I would like to render each combobox item according to the font (like in MS Word). In other words: Each item should be rendered according to it's own font.

    I am using the OnDrawItem and OnMeasureItem events. Unfortunately, I wasn't able to use the style and colors of the current Aplha Skin in that methods. So my custom implementation looks different. Is there any way to use the skin's color scheme in the custom implementation of OnDrawItem and OnMeasureItem?

    Here my code:

    Code:
    procedure MyForm.CBX_FontStyleDrawItem(Control : TWinControl; Index : Integer; Rect : TRect; State : TOwnerDrawState);
    begin
    with Control as TsComboBox do begin
    if (odSelected in State)
    then Canvas.Brush.Color := (clHighlight)
    else Canvas.Brush.Color := (clWindow);

    Canvas.Rectangle (Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
    Canvas.FillRect (Rect);
    Canvas.Font.Name := (CBX_FontStyle.Items[Index]);
    Canvas.Font.Size := (10);
    Canvas.TextOut (Rect.Left + 1, Rect.Top, Items[Index]);
    end;
    end;

    Code:
    procedure MyForm.CBX_FontStyleMeasureItem(Control : TWinControl; Index : Integer; var Height : Integer);
    begin
    if (Index = -1)
    then exit;

    with CBX_FontStyle.Canvas do begin
    Font.Name := (CBX_FontStyle.Items[Index]);
    Font.Size := (10);
    Height := (TextHeight('Xx') + 2);
    end;
    end;

    Thanks in advance!

    Best regards

    QStorm

    #45584
    QStorm
    Participant

    No ideas?

    I would like to hightlight the selected / focused item using the current Alpha Skin properties.

    Thanks 🙂

    #45581
    QStorm
    Participant

    Hi again,

    Does anybody know how to get the styling properties (color, transparence etc.) from the current Alpha Skin?

    It's very urgent, I need a solution as soon as possible.

    Thanks 🙂

    Best regards

    QStorm

    #45653
    Support
    Keymaster

    Hello and I'm sorry for a delay.

    Why you not uses the TsFontComboBox component? Some features are not exists there?

    Here is a code of items drawing from TsFontComboBox :

    Code:
    procedure TsFontComboBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
    var
    Bmp, fBmp : TBitmap;
    aRect, BRect : TRect;
    TmpColor : TColor;
    TmpFontClass : TFontClass;
    ts : TSize;
    sNdx : integer;
    CI : TCacheInfo;
    DrawStyle : longint;
    begin
    TmpFontClass := nil;
    Bmp := nil;
    if (Index >= 0) and (Index < Items.Count) and (Items.Objects[Index] nil) then begin
    TmpFontClass := TFontClass(Items.Objects[Index]);
    fBmp := FBitmaps[ord(TmpFontClass.FntType)];
    fBmp.Transparent := True;
    aRect := Classes.Rect(0, 0, fBmp.Height, fBmp.Width);
    end
    else fBmp := nil;
    if SkinData.Skinned then begin
    Bmp := CreateBmp32(WidthOf(Rect), HeightOf(Rect));
    Bmp.Canvas.Font.Assign(Font);
    if odComboBoxEdit in State then CI := MakeCacheInfo(SkinData.FCacheBmp, Rect.Left, Rect.Top) else begin
    CI.Bmp := nil;
    CI.Ready := False;
    CI.FillColor := Color;
    end;
    if (odSelected in State) then begin
    CI.Bmp := nil;
    CI.Ready := False;
    CI.FillColor := Color;
    sNdx := SkinData.SkinManager.GetSkinIndex(s_Selection);
    if sNdx < 0
    then FillDC(Bmp.Canvas.Handle, Classes.Rect(0, 0, Bmp.Width, Bmp.Height), SkinData.SkinManager.GetHighLightColor(odFocused in State))
    else PaintItem(sNdx, s_Selection, CI, True, integer(odFocused in State), Classes.Rect(0, 0, Bmp.Width, Bmp.Height), Point(0, 0), Bmp, SkinData.SkinManager)
    end
    else begin
    sNdx := -1;
    if CI.Ready
    then BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, CI.Bmp.Canvas.Handle, CI.X, CI.Y, SRCCOPY)
    else FillDC(Bmp.Canvas.Handle, Classes.Rect(0, 0, Bmp.Width, Bmp.Height), Color);
    end;
    if Assigned(TmpFontClass) then begin
    brect := classes.Rect(0, 0, Bmp.Height, Bmp.Height);
    Bmp.Canvas.Draw(bRect.Left, bRect.Top, fBmp);
    aRect.Right := Bmp.Width;
    aRect.Left := brect.right;
    if DrawFont then Bmp.Canvas.Font.Name := TmpFontClass.FntName;
    DrawStyle := DT_NOPREFIX or DT_EXPANDTABS or DT_SINGLELINE or DT_VCENTER or DT_NOCLIP;
    InflateRect(aRect, -1, 0);
    if sNdx = -1 then begin
    if odSelected in State then Bmp.Canvas.Font.Color := SkinData.SkinManager.GetHighLightFontColor(odFocused in State) else begin
    if ControlIsActive(SkinData) and (SkinData.SkinManager.gd[SkinData.SkinIndex].States > 1)
    then Bmp.Canvas.Font.Color := SkinData.SkinManager.gd[SkinData.SkinIndex].HotFontColor[1]
    else Bmp.Canvas.Font.Color := SkinData.SkinManager.gd[SkinData.SkinIndex].FontColor[1];
    end;
    Bmp.Canvas.Brush.Style := bsClear;
    AcDrawText(Bmp.Canvas.Handle, TmpFontClass.FntName, aRect, DrawStyle);
    end
    else WriteTextEx(Bmp.Canvas, PChar(TmpFontClass.FntName), True, aRect, DrawStyle, sNdx, (odFocused in State), SkinData.SkinManager);
    end;
    BitBlt(Canvas.Handle, Rect.Left, Rect.Top, Bmp.Width, Bmp.Height, Bmp.Canvas.Handle, 0, 0, SRCCOPY);
    FreeAndNil(Bmp);
    end
    else begin
    if odSelected in State then TmpColor := ColorToRGB(clHighLight) else TmpColor := ColorToRGB(Color);
    FillDC(Canvas.Handle, Rect, TmpColor);
    if Assigned(TmpFontClass) then begin
    brect := classes.Rect(rect.left, rect.top, rect.bottom – rect.top + rect.left, rect.bottom);
    Canvas.Draw(bRect.Left, bRect.Top, fBmp);
    Rect.Left := Rect.Left + brect.right;
    if DrawFont then Canvas.Font.Name := TmpFontClass.FntName;
    if odSelected in State then Canvas.Font.Color := ColorToRGB(clHighlightText) else Canvas.Font.Color := Font.Color;

    GetTextExtentPoint32(Canvas.Handle, PChar(TmpFontClass.FntName), Length(TmpFontClass.FntName), ts);
    Canvas.Brush.Style := bsClear;
    Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + (HeightOf(Rect) – ts.cy) div 2, TmpFontClass.FntName);
    end;
    end;
    end;

    #54348
    Jimy
    Participant

    very thanks! 😐

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.