Accessing the Interfaces directly/pt

From Free Pascal wiki
Revision as of 22:50, 19 June 2007 by Antoniog (talk | contribs)
Jump to navigationJump to search

English (en) português (pt)

Esta página descreve como ter acesso direto de escrita ao widgeset subjacente usado pelo Lazarus (por exemplo: a API do Windows, ou GTK ou QT, etc). Pode-se sempre tentar evitar de confiar nas especifidades do widgeset. Este documento está aqui para as pessoas melhorarem o widgeset e para quem escreve componentes e realmente precisa acessar os widgeset diretamente.

Visão Geral

Cada TWinControl tem um handle e a LCL não precisa saber o que é um handle. O significado de um handle é totalmente assunto da interface:

  • em Gtk um handle é freqüentemente um PGtkWidget.
  • em Windows um handle é freqüentemente um HWnd.
  • em Carbon um handle é freqüentemente um objeto descendente de TCarbonWidget.
  • em Qt um handle é freqüentemente um ponteiro para um objeto descendente de TQtWidget.

Detalhes de cada Widgetset

Qt

Handles on Qt are mostly pointers to objects. Every time a control is created, a helper object is also created and both are connected. The helper object is necessary to receive events from Qt. After receiving a event it will send it to the LCL.

Most of those objects are descendents from TQtWidget as declared below:

 { TQtWidget }

 TQtWidget = class(TObject)
 private
 public
   Widget: QWidgetH;
   LCLObject: TWinControl;
 end;

Notice the two variables they all contain:

  • Widget - This is a connect to the Qt object for this Widget
  • LCLObject - Is a bridge with the LCL object it is linked to.

Carbon

Handles on Carbon are very similar to Qt ones. The helper classes are descended from abstract class TCarbonWidget.

 { TCarbonWidget }

 TCarbonWidget = class(TObject)
 private
 public
   Widget: Pointer;
   LCLObject: TWinControl;
 end;

Notice the two variables they all contain:

  • Widget - This is a connect to the Carbon object for this Widget: ControlRef (TCarbonControl descendants) or WindowRef (TCarbonWindow descendants).
  • LCLObject - Is a bridge with the LCL object it is linked to.

Windows

Handles on Win32 or WinCE are almost always the same as their relative win api handles,For example handle of tmenu is HMENU,handle of TBrush is HBRUSH,so you can easily use them and pass them to windows apis.

List of Handles on various LCL classes

TFont

  • Win32, WinCE: HFONT
  • Qt: A TQtFont object from qtprivate.pas
  • Carbon: A TCarbonFont object from carbongdiobjects.pp

TCanvas

  • Win32, WinCE: HDC
  • Gtk: A TDeviceContext object from gtkdef.pp
    • You can get a drawable, for example with: TDeviceContext(MyCanvas.Handle).Drawable
  • Qt: A TQtDeviceContext object from qtprivate.pas
  • Carbon: A TCarbonDeviceContext object from carboncanvas.pp
    • The native handle can be accessed with TCarbonDeviceContext(MyCanvas.Handle).CGContext of type CGContextRef

TBrush

  • Win32, WinCE: HBRUSH
  • Qt: A TQtBrush object from qtprivate.pas
  • Carbon: A TCarbonBrush object from carbongdiobjects.pp

TBitmap

  • Win32, WinCE: HBITMAP
  • Gtk: PGDIObject (defined on unit GtkDef)
  • Qt: A TQtImage object from qtobjects.pas unit
  • Carbon: A TCarbonBitmap object from carbongdiobjects.pp

You can access this on Gtk using:

var
  GDIObject: PGDIObject;
  Bitmap: TBitmap;
  AImage: PGtkWidget;
begin
  ...

  GDIObject := PgdiObject(Bitmap.Handle);

  AImage := gtk_image_new_from_pixmap(GDIObject^.GDIPixmapObject,
   GDIObject^.GDIBitmapMaskObject);

  gtk_widget_show(AImage);

  gtk_container_add(GTK_CONTAINER(MyForm.Handle), AImage);
end;

TCustomForm

  • Win32, WinCE: it´s a HWND, a native window handle
  • Gtk: It´s a pointer to a structure.
  • Qt: The Handle is a pointer to a object from the TQtMainWindow class declared at qtwidgets.pas. To have access to the QMainWindow Qt object it represents do: TQtMainWindow(Handle).Widget
  • Carbon: TCarbonWindow from carbonprivate.pp

TMenu, TMainMenu, TMenuItem and TPopUpMenu

  • Win32, WinCE : HMENU
  • Qt: TMainMenu is a pointer to a TQtMenuBar object. TPopUpMenu is a TQtMenu object. TMenuItem can either be a TQtAction if it represents a clickable item or a separator or a TQtMenu if it is an item that has submenus.
  • Carbon: TMenuItem is a TCarbonMenu object, TMenu (TMainMenu and TPopupMenu) is represented by its root menu item