Programming Guide |
Associates a drawing function with a widget
#include <smmwuser.h>int sm_mw_attach_drawing_func(int widgetnumber, int (*drawfunc));int sm_mwn_attach_drawing_func(char *widgetname, int (*drawfunc));int sm_mwe_attach_drawing_func(char *widgetname, int element, int (*drawfunc));#include <smxmuser.h>int sm_xm_attach_drawing_func(int widgetnumber, void(*drawfunc),
XtPointer data);int sm_xmn_attach_drawing_func(char *widgetname, void(*drawfunc),
XtPointer data);int sm_xme_attach_drawing_func(char *widgetname, int element, void(*drawfunc), XtPointer data);
widgetname
,widgetnumber
- Specifies the widget to get
drawfunc
.element
- If the widget is an array, specifies the element in
widgetname
to getdrawfunc
.drawfunc
- The drawing function to attach to the specified widget. Drawing function declarations for Windows and Motif are shown in Description.
data
- Points to a user-defined structure that contains the data required by the drawing function.
Motif, Windows
sm_attach_drawing_func
attaches the drawing function pointed to bydrawfunc
to the specified widget or element on the current screen. The widget must have itscustomer_drawn
property set toPV_YES
. You can use your own drawing functions with dynamic labels, push buttons, and toggle buttons. Panther handles all processing for these widgets except for drawing them, although it does draw the shading for push button widgets.The most convenient place to attach a drawing function is at screen entry. Once attached, the drawing function is called whenever the widget needs to be painted, drawn or refreshed, regardless of whether the paint message comes from the window manager or from Panther.
For Windows applications, declare the drawing function as follows:
int drawfunc(HWND handle, UINT message, WPARAM wParam,
LPARAM lParam);The
HWND
argument is a handle to the widget. If the widget is a dynamic label, themessage
argument is aWM_PAINT
message. If the widget is a push button or toggle button, themessage
argument is aWM_DRAWITEM
message. For dynamic labels, thelParam
andwParam
arguments are not used. For push buttons or toggle buttons, thewParam
argument specifies the identifier of the widget that sent the message, and thelParam
argument points to aDRAWITEMSTRUCT
structure, which provides information on how to paint the widget.Refer to the Windows SDK documentation for details on
WM_PAINT
andWM_DRAWITEM
messages, and theDRAWITEMSTRUCT
data structure.Note: Because Panther draws the shading on a push button and toggle button, it alters a field in the
DRAWITEMSTRUCT
which specifies the rectangle to draw in. The rectangle passed to thedrawfunc
in thercItem
field is reduced slightly to account for the shading. Thedrawfunc
therefore should draw in the entire rectangle that it is passed, and not draw any shading. Furthermore, thehDC
item in the structure is altered, allowing for faster display and less flashing.Panther selects Panther's color palette into the device context. For a dynamic label, the color palette is selected into the device context during the
BeginPaint()
call in thedrawfunc
. For a push button or toggle button, the palette is selected into the memory device context beforedrawfunc
is called.After
drawfunc
returns, Panther draws the cursor or focus rectangle. Panther ignores the return value fromdrawfunc
.
For Motif, declare the drawing function as follows:
void drawfunc(Widget wdgt, XtPointer xtpUserData, XtPointer xtpCallBackData);
#include <smdefs.h>
#include <smmwuser.h>
int MyDrawingFunc(HWND, UINT, WPARAM, LPARAM);
/* sample drawing function */
int
MyDrawingFunc(hWnd, message, wParam, lParam)
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
PAINTSTRUCT ps;
HBRUSH hBrush;
BeginPaint(hWnd, &ps);
hBrush = CreateSolidBrush(RGB(0, 0, 255));
FillRect(ps.hdc, &ps.rcPaint, hBrush);
DeleteObject(hBrush);
EndPaint(hWnd, &ps);
return(0);
}
{
...
/* attach drawing function to widget number 2 */
if (sm_attach_drawing_func(2, MyDrawingFunc) == -1)
{
<< error handling >>
}
...
}
int MyButtonDrawingFunc(HWND, UINT, WPARAM, LPARAM);
/* sample drawing function */
int
MyButtonDrawingFunc(hWnd, message, wParam, lParam)
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
DRAWITEMSTRUCT *dis;
HBRUSH hBrush;
dis = (DRAWITEMSTRUCT *)lParam;
hBrush = CreateSolidBrush(RGB(0, 0, 255));
FillRect(dis->hDC, &dis->rcItem, hBrush);
DeleteObject(hBrush);
return(0);
}
{
...
/* attach drawing function to widget number 3 */
if (sm_attach_drawing_func(3, MyButtonDrawingFunc) == -1)
{
<< error handling >>
}
...
}