Programming Guide



sm_*attach_drawing_func

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 get drawfunc.

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.

Environment

Motif, Windows

Returns

Description

sm_attach_drawing_func attaches the drawing function pointed to by drawfunc to the specified widget or element on the current screen. The widget must have its customer_drawn property set to PV_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.

Windows Draw Function Declaration

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, the message argument is a WM_PAINT message. If the widget is a push button or toggle button, the message argument is a WM_DRAWITEM message. For dynamic labels, the lParam and wParam arguments are not used. For push buttons or toggle buttons, the wParam argument specifies the identifier of the widget that sent the message, and the lParam argument points to a DRAWITEMSTRUCT structure, which provides information on how to paint the widget.

Refer to the Windows SDK documentation for details on WM_PAINT and WM_DRAWITEM messages, and the DRAWITEMSTRUCT 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 the drawfunc in the rcItem field is reduced slightly to account for the shading. The drawfunc therefore should draw in the entire rectangle that it is passed, and not draw any shading. Furthermore, the hDC 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 the drawfunc. For a push button or toggle button, the palette is selected into the memory device context before drawfunc is called.

After drawfunc returns, Panther draws the cursor or focus rectangle. Panther ignores the return value from drawfunc.

Motif Draw Function Declaration

For Motif, declare the drawing function as follows:

void drawfunc(Widget wdgt, XtPointer xtpUserData, XtPointer xtpCallBackData);

Example

#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 >>
}
...
}