OwnerDraw decription

A rendering mode in which you take responsibility for drawing a control, rather than relying on the control’s default rendering behavior.

Typically, Windows handles painting automatically by using property settings such as BackColor to determine the appearance of a control. With owner drawing, you take over the painting process, changing elements of appearance that are not available by using properties. For example, many controls let you set the color of the text that is displayed, but you are limited to a single color. Owner drawing enables you to do things like display part of the text in black and part in red.

In practice, owner drawing is similar to drawing graphics on a form. For example, you could use graphics methods in a handler for the form's Paint event to emulate a ListBox control, but you would have to write your own code to handle all user interaction. With owner drawing, the control uses your code to draw its contents but otherwise retains all its intrinsic capabilities. You can use OwnerDrawContext methods to draw each item in the control or to customize some aspects of each item while you use the default appearance for other aspects of each item.  OwnerDrawContext methods based on Device context API methods and GDI+ methods. Please, feel free for ask to add new methods if need.

To perform owner drawing in controls that support it, you will typically set one property and write OnerDraw context script.

Most controls that support owner drawing have an OwnerDraw property that indicates whether the control will raise its drawing-related event or events when it paints itself.

There are many different kinds of drawing events, but a typical drawing event occurs in order to draw a single item within a control. BRIZ provides automaticaly binding of Your OnerDrawContext script when receives an OwnerDraw events. BRIZ sets variables to drawing. For example, variables typically contains the item's index number, a Rectangle that indicates the item's display boundaries and for some objects provides additional information about the item, such as the background or a focus state.

OnerDrawContext script is reusable (You can use one context with many objects).

Most controls that support owner drawing have an OwnerDraw property that indicates whether the control will raise its drawing-related event or events when it paints itself.

There are many different kinds of drawing events, but a typical drawing event occurs in order to draw a single item within a control. BRIZ provides automaticaly binding of Your OnerDraw context script when receives an OwnerDraw events. BRIZ sets variables to drawing. For example, variables typically contains the item's index number, a Rectangle that indicates the item's display boundaries and for some objects provides additional information about the item such as the background or a focus rectangle.

OwnerDrawContext decription

The following Objects support owner drawing:

How it works

BRIZ handles Windows messages WM_DRAWITEM and WM_MEASUREITEM . BRIZ executes OwnerDrawContext script on each message. You can manage OwnerDrawContext by sytem methods through subroutines GP.SystemSub( SubStr ) and GP.SystemFn( SubStr, Ret )

Setting the Owner-Drawn Flag

For menu You should use the Menu subroutines to specify an owner-drawn menu item, just add option 'O' to flag and define OwnerDrawContext name after flag. For example "EO;CONTEXT=MyMenu"

For objects You should specify ownerdraw style and define OwnerDrawContext name with help of method "SetDrawContext ContextName" or DRAWCONTEXT=xxxxx; option in intial string.

OwnerDraw styles for objects:

 

Owner-Drawn Menus and the WM_MEASUREITEM Message

Before the system displays an owner-drawn menu item for the first time, it sends the WM_MEASUREITEM message to the window procedure of the window that owns the item's menu. BRIZ automaticaly calls DrawContext that  must fill the itemWidth and itemHeight members before returning. The system uses the information in these members when creating the bounding rectangle in which an application draws the menu item. It also uses the information to detect when the user chooses the item.

Owner-Drawn Menus and the DRAWITEM

Whenever the item must be drawn (for example, when it is first displayed or when the user selects it), the system calls the DrawContext. DrawContext contains flags that indicate the state of the item (such as whether it is grayed or selected) as well as a bounding rectangle and a device context that the application uses to draw the item.

An application must do the following while processing the DRAWITEM:

If the user selects the menu item, the system sets the itemAction member to the ODA_SELECT value and sets the ODS_SELECTED value in the itemState member. This is an application's cue to redraw the menu item to indicate that it is selected.

DrawContext script predefined values

Specific predefine values by ControlType

  • ODT_BUTTON    (4) Owner-drawn button
  • ODT_COMBOBOX    (3) Owner-drawn combo box
  • ODT_LISTBOX (2)  Owner-drawn list box
  • ODT_MENU    (1) Owner-drawn menu
  • ODT_LISTVIEW (102)  List view control
  • ODT_STATIC (5)  Owner-drawn static control
  • ODT_TAB    (101) Tab control
  • ODT_HEADER  (100) Tab control  

     

    Owner-drawn List Boxes

    An application can create an owner-drawn list box to take responsibility for painting list items. The parent window or dialog box of an owner-drawn list box (its owner) receives WM_DRAWITEM messages when a portion of the list box needs to be painted. An owner-drawn list box can list information other than, or in addition to, text strings.

    The owner of an owner-drawn list box must process the WM_DRAWITEM message. This message is sent whenever a portion of the list box must be redrawn. The owner may need to process other messages, depending on the styles specified for the list box.

    An application can create an owner-drawn list box by specifying the LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE style. If all list items in the list box are the same height, such as strings or icons, an application can use the LBS_OWNERDRAWFIXED style. If list items are of varying height, bitmaps of different size, for example, an application can use the LBS_OWNERDRAWVARIABLE style.

    The owner of an owner-drawn list box can process a WM_MEASUREITEM message to specify the dimensions of list items. If the application creates the list box by using the LBS_OWNERDRAWFIXED style, the system sends the WM_MEASUREITEM message only once. The dimensions specified by the owner are used for all list items. If the LBS_OWNERDRAWVARIABLE style is used, the system sends a WM_MEASUREITEM message for each list item added to the list box. The owner can determine or set the height of a list item at any time by using the LB_GETITEMHEIGHT and LB_SETITEMHEIGHT messages, respectively.

    If the information displayed in an owner-drawn list box includes text, an application can keep track of the text for each list item by specifying the LBS_HASSTRINGS style. List boxes with the LBS_SORT style are sorted based on this text. If a list box is sorted, but is not of the LBS_HASSTRINGS style, the owner must process the WM_COMPAREITEM message.

    In an owner-drawn list box, the owner must keep track of list items containing information other than or in addition to text. One convenient way to do this is to save the handle to the information as item data using the LB_SETITEMDATA message. To free data objects associated with items in a list box, the owner can process the WM_DELETEITEM message.

    For an example of an owner-drawn list box, see OwnerDrawContext examples .

    Owner-Drawn Combo Boxes

    An application can create an owner-drawn combo box to take responsibility for painting list items. The parent window or dialog box of an owner-drawn combo box (its owner) receives WM_DRAWITEM messages when a portion of the combo box needs to be painted. An owner-drawn combo box can list information other than, or in addition to, text strings. Owner-drawn combo boxes can be of any type. However, the edit control in a simple or drop-down combo box can only display text, while the owner paints the selection field in a drop-down list box.

    The owner of an owner-drawn combo box must process the WM_DRAWITEM message. This message is sent whenever a portion of the combo box must be redrawn. The owner may need to process other messages, depending on the styles specified for the combo box.

    An application can create an owner-drawn combo box by specifying the CBS_OWNERDRAWFIXED or CBS_OWNERDRAWVARIABLE style. If all list items in the combo box are the same height, such as strings or icons, an application can use the CBS_OWNERDRAWFIXED style. If list items are of varying height, like bitmaps of different size, an application can use the CBS_OWNERDRAWVARIABLE style.

    The owner of an owner-drawn combo box can process a WM_MEASUREITEM message to specify the dimensions of list items in the combo box. If the application creates the combo box by using the CBS_OWNERDRAWFIXED style, the system sends the WM_MEASUREITEM message only once. The dimensions specified by the owner are used for all list items. If the CBS_OWNERDRAWVARIABLE style is used, the system sends a WM_MEASUREITEM message for each list item added to the combo box. The owner can determine or set the height of a list item at any time by using the CB_GETITEMHEIGHT and CB_SETITEMHEIGHT messages, respectively.

    If the information displayed in an owner-drawn combo box includes text, an application can keep track of the text for each list item by specifying the CBS_HASSTRINGS style. Combo boxes with the CBS_SORT style are sorted based on this text. If a combo box is sorted and not of the CBS_HASSTRINGS style, the owner must process the WM_COMPAREITEM message.

    In an owner-drawn combo box, the owner must keep track of list items containing information other than or in addition to text. One convenient way to do this is to save the handle to the information as item data. To free data objects associated with items in a combo box, the owner can process the WM_DELETEITEM message.

    Owner-Drawn Tabs

    If a tab control has the TCS_OWNERDRAWFIXED style, the parent window must paint tabs by processing the WM_DRAWITEM message. The tab control sends this message whenever a tab needs to be painted. The lParam parameter specifies the address of a DRAWITEMSTRUCT structure, which contains the index of the tab, its bounding rectangle, and the device context (DC) in which to draw.

    By default, the itemData member of DRAWITEMSTRUCT contains the value of the lParam member of the TCITEM structure. However, if you change the amount of application-defined data per tab, itemData contains the address of the data instead. You can change the amount of application-defined data per tab by using the TCM_SETITEMEXTRA message.

    To specify the size of items in a tab control, the parent window must process the WM_MEASUREITEM message. Because all tabs in an owner-drawn tab control are the same size, this message is sent only once. There is no tab control style for owner-drawn tabs of varying size. You can also set the width and height of tabs by using the TCM_SETITEMSIZE message.