Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

Reference: MSEgui/TWidget

TWiget

Ready for revision

Ancestor for visual components.

Reference

Hierarchy

text
 TObject
   │
   ╰─┬─TPersistent
     │
     ╰─┬─TComponent
       │
       ╰─┬─TmseComponent
         │
         ╰─┬─TactComponent
           │
           ╰───TWidget

Properties

Anchors

Anchors combines the traditional Anchors and the traditions Align properties.

pascal
property anchors: anchorsty read fanchors write setanchors default defaultanchors;

By default your anchors are an_left and an_top. Then your widget stays at the same position when sizing the form. When your widget should have a constant distance to the right border of its parent, you add an_right and remove an_left (in this order...). The same you can do with an_bottom and an_top.

If you have only one anchor, and the widget is suitable for this sizing, the widget is using the full size of the not anchored dimension. The behaviour is near the traditional property Align, but the widget is not aligned directly to the border, but you can free position it.

By having no anchors set, the widget fills the client size of its parent (the traditional alClient).

By setting an_left and an_top, the widget change its horizontal size by sizing its parent, the same with the vertical size by setting an_top and an_bottom together.

Bounds

The size and the position of the widget is condensed in the property bounds, but you have also the traditional properties like left an width.

pascal
// the types
sizety = record
  cx, cy: integer;
end;

pointty = record
  x,y: integer;
end;

rectty = record
case integer of
  0: (x, y, cx, cy: integer);
  1: (pos: pointty; size: sizety);
end;

// the properties
property Widgetrect: rectty read FWidgetrect write SetWidgetrect;
property Pos: pointty read FWidgetrect.pos write SetPos;
property Size: sizety read FWidgetrect.size write SetSize;

property Bounds_x: integer read FWidgetrect.x write SetBounds_x;
property Bounds_y: integer read FWidgetrect.y write SetBounds_y;
property Bounds_cx: integer read FWidgetrect.cx write SetBounds_cx
               {default defaultwidgetwidth} stored true;
property Bounds_cy: integer read FWidgetrect.cy write SetBounds_cy
               {default defaultwidgetheight} stored true;
property Bounds_cxmin: integer read FMinSize.cx
                                   write SetBounds_cxmin default 0;
property Bounds_cymin: integer read FMinSize.cy
                                   write SetBounds_cymin default 0;
property Bounds_cxmax: integer read FMaxSize.cx
                                   write SetBounds_cxmax default 0;
property Bounds_cymax: integer read FMaxSize.cy
                                   write SetBounds_cymax default 0;

property Left: integer read FWidgetrect.x write SetBounds_x;
property Right: integer read GetRight write SetRight;
             //widgetrect.x + widgetrect.cx, sets cx if an_left is set
property Top: integer read FWidgetrect.y write SetBounds_y;
property Bottom: integer read GetBottom write SetBottom;
             //widgetrect.y + widgetrect.cy, sets cy if an_top is set
property Width: integer read FWidgetrect.cx write SetBounds_cx;
property Height: integer read FWidgetrect.cy write SetBounds_cy;

property MinSize: sizety read FMinSize write SetMinSize;
function WidgetMinSize: sizety;
        //calls checkwidgetsize and frame.checkwidgetsize
property MaxSize: sizety read FMaxSize write SetMaxSize;

Color

pascal
property Color: colorty default defaultwidgetcolor;

Specifies the color of the widget. With Face and Frame other colors for the whole or a part of the widget can set.

Cursor

pascal
property Cursor: cursorshapety default cr_default;

Specifies the look of the mouse cursor if it is over the widget.

Enabled

pascal
property Enabled: boolean default true;

Sets the widget enabled or not. Some Widgets change their look if they are not enabled, others do not (UPDATE: Meanwhile TSlider change it's look when setting enabled).

Face

See TFace

Font

See TFont

Frame

See TFrame

Hint

A hint is a small text displayed when the mouse cursor is over the widget. With the text editor of the object inspector you can add additional lines (SHIFT+ENTER), you can also use [r[n:

pascal
Label1.Hint := 'This is a simple hin text[r[nof a simple label[r[nwith more than on line.'

See also OnHint

OptionsWidget

pascal
optionwidgetty = (ow_background, ow_top, ow_ultratop,
  ow_noautosizing, //don't use, moved to optionswidget1
  ow_mousefocus, ow_tabfocus, ow_parenttabfocus, ow_arrowfocus,
  ow_arrowfocusin,ow_arrowfocusout,
  ow_subfocus, //reflects focus to children
  ow_focusbackonesc,                   
  ow_keyreturntaborder, //key_return and key_enter work like key_tab
  ow_nochildshortcut,  //do not propagate shortcuts to parent
  ow_noparentshortcut, //do not react to shortcuts from parent
  ow_canclosenil,      // don't use, moved to optionswidget1
  ow_mousetransparent, ow_mousewheel, ow_noscroll,
  ow_nochildpaintclip, ow_nochildclipsiblings,                   
  ow_destroywidgets, ow_nohidewidgets,
  ow_hinton, ow_hintoff, ow_disabledhint, ow_multiplehint, ow_timedhint);
optionswidgetty = set of optionwidgetty;

property OptionsWidget: optionswidgetty;

OptionsWidget1

pascal
optionwidget1ty = (ow1_fontglyphheight, //track font.glyphheight, create fonthighdelta and childscaled events
  ow1_fontlineheight, //track font.linespacing, create fonthighdelta and childscaled events
  ow1_autoscale, //synchronizes bounds_cy or bonds_cx with fontheightdelta
  ow1_autowidth, ow1_autoheight,
  ow1_autosizeanright, ow1_noautosizeanright,
  ow1_autosizeanbottom, ow1_noautosizeanbottom,
  ow1_noparentwidthextend, ow1_noparentheightextend,
  ow1_canclosenil, //call canclose(nil) on exit
  ow1_nocancloseifhidden,
  ow1_modalcallonactivate, ow1_modalcallondeactivate, //used in tactionwidget
  ow1_noautosizing //used in tdockcontroller );                                         
optionswidget1ty = set of optionwidget1ty;

property OptionsWidget1: optionswidget1ty;

PopupMenu

Reference on a TPopupMenu instance, showing with a rightclick on the widget. See also OnPopup

pascal
property PopupMenu: TPopupMenu;

TabOrder

pascal
property TabOrder: integer;

Specifys in which order the widgets get the focus if you use the tab key. (See also ow_tabfocus in OptionsWidget.)

Visible

pascal
property Visible: boolean default true;

Sets the widget visible or hides it.

Methods

Please suggest here methodes to describe wich are used for working with the widget, not for internal.

Events

OnHint

pascal
showhinteventty = procedure(const Sender: TObject; var Info: hintinfoty) of object;

The event OnHint is triggered, when a hint is displayed for the widget. With the var-parameter Info you can specify details of the displayed hint.

pascal
procedure tmainfo.FormShowHint(const Sender: TObject; var Info: hintinfoty);
begin
  Info.Caption := 'Trololo';
  Info.PosRect.X := Info.PosRect.X + 60;
  Info.PosRect.y := Info.PosRect.y - 20;
end;

OnEnter, OnFocus, OnActivate

We have three pairs of events regarding the change of a focus:

pascal
property OnEnter: notifyeventty;
property OnExit: notifyeventty;

property OnFocus: notifyeventty;
property OnDeFocus: notifyeventty;

property OnActivate: notifyeventty;
property OnDeActivate: notifyeventty;

For an example we have two forms with both have two edits. The main form has an memo to log the events (here an example for OnEnter):

pascal
procedure ttestfo.FormEnter(const Sender: TObject);
begin
  MainFo.DoLog((Sender as TWidget).Name + ' OnEnter');
end;

We click on the first form:

Now we click on the second edit of the first form:

Now we click on then second form:

Now we click on the second edit of the first form (which was formerly focused on the first form):

And now we click on the second edit for the second form:

In the last step we see first an complete activation change of the form (goes to Form2_Edit1) and than a complete focus change from Form2_Edit1 to Form2_Edit2.

We see:

OnNavigRequest

If ow_ArrowFocus is in OptionsWidget of the regarding widgets, you can change the focus with the arrow keys. The parent component has an algorithm to select the next widget for each arrow key, and at the end of this algorithm the event OnNavigRequest is fired. Here you can overwrite some values.

pascal
graphicdirectionty = (gd_right,gd_up,gd_left,gd_down,gd_none);

naviginfoty = record
  sender: twidget;
  direction: graphicdirectionty;
  startingrect: rectty;
  distance: integer;
  nearest: twidget;
  down: boolean;
  hastarget: boolean;
end;

navigrequesteventty = procedure(const Sender: twidget; var AInfo: naviginfoty) of object; 

property OnNavigRequest: navigrequesteventty

The most likely case may be, that you want to set the focus to another widget. In the following example the focus goes always to Edit9. Make sure, that you use the OnNavigRequest of the parent widget.

pascal
procedure tmainfo.FormNavigRequest(const Sender: TWidget; var AInfo: naviginfoty);
begin
  AInfo.Nearest := Edit9;
end;

OnPaint, OnPaintBackground, OnAfterPaint, OnPaintBackground

The OnPaint-Events are fired before, while or after the widget is painted.

pascal
painteventty = procedure (const Sender: TWidget; const ACanvas: TCanvas) of object;

property OnBeforePaint: painteventty;
property OnPaintBackground: painteventty;
property OnPaint: painteventty;
property OnAfterPaint: painteventty;

The following example shows, when the events are fired:

pascal
procedure tmainfo.LabelPaint(const Sender: TWidget; const ACanvas: TCanvas);
begin
  ACanvas.DrawLine(mp(-30, -30), mp(150, 150), cl_red);
end;

procedure tmainfo.LabelAfterPaint(const Sender: TWidget; const ACanvas: TCanvas);
begin
  ACanvas.DrawLine(mp(-25, -30), mp(155, 150), cl_blue);
end;

procedure tmainfo.LabelBeforePaint(const Sender: TWidget; const ACanvas: TCanvas);
begin
  ACanvas.LineWidth := 3;
  ACanvas.DrawLine(mp(-20, -30), mp(160, 150), cl_green);
end;

procedure tmainfo.LabelPaintBackground(const Sender: TWidget; const ACanvas: TCanvas);
begin
  ACanvas.DrawLine(mp(-15, -30), mp(165, 150), cl_yellow);
end;

OnPopup

The event OnPopup is fired if you show the PopupMenu by clicking with the right mouse button, but not, if you show the PopupMenu manually by TPopupMenu.Show.

pascal
popupeventty = procedure(const Sender: TObject; var AMenu: TPopupMenu; var MouseInfo: mouseeventinfoty) of object;

You can use AMenu to assign a TPopupMenu-Instance in this moment. With MouseInfo you have some information like Position or shift state and can also change them:

pascal
procedure tmainfo.LabelPopup(const Sender: TObject; var AMenu: TPopupMenu; var MouseInfo: mouseeventinfoty);
begin
  AMenu := PopupMenu1;
  MouseInfo.Pos.X := MouseInfo.Pos.X + 300;
end;

OnBeforeUpdateSkin, OnAfterUpdateSkin

Inherited from TMseComponent: OnBeforeUpdateSkin, OnAfterUpdateSkin

Known issues

Issues of the class

Issues of this documentation

Feel free to add your points here.


From the Free Pascal wiki, page "Reference: MSEgui/TWidget", as it stood on 2020-02-25 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .