Basically, a WDEF is a compiled resource that provides the OS9 OS with
a set of defined callbacks to draw parts of the window.

I've included the complete C source for a WDEF below.
If you have any questions....


:-)


Thanks,

Jamie

Software Factory, LLC
Sales     800-539-1780
Support     706-632-3763
Fax         706-632-6498
www.installfactory.com






<Snip ... This is the code for the WDEF9.h File...>
#define _H_WindoidWDEF

                /*** Function Declarations ***/

        void            DrawFrame(short varCode, WindowPeek macWindow);
        void            ToggleZoomBox(short varCode, WindowPeek macWindow);
        void            ToggleCloseBox(short varCode, WindowPeek macWindow);
        short           FindPart(short varCode, WindowPeek macWindow, long 
location);
        void            BuildRegions(short varCode, WindowPeek macWindow);
        void            GetDragBar(short varCode, WindowPeek macWindow, Rect 
*dragBar);
        void            GetCloseBox(short varCode, Rect *dragBar, Rect 
*closeBox);
        void            GetZoomBox(short varCode, Rect *dragBar, Rect *ZoomBox);
        
                /*** Macros ***/
                                                                                
/* Efficient C versions of HiWord       */
                                                                                
/*   and LoWord Traps                           */
#define         HiShort(longNum)        (short)(((longNum) >> 16) & 0xFFFF)
#define         LoShort(longNum)        (short)((longNum) & 0xFFFF)

< END OF CODE FOR HEADER >




#include "WDEF9.h"

/*** Constants ***/

#define         FRAME_WIDTH             1                       /* Thickness of 
frame around window     */
#define         DRAG_WIDTH              14                      /* Thickness of 
drag bar                        */
#define         SHADOW_LENGTH   1                       /* Size of drop shadow  
                        */
#define         DRAG_TOP                0                       /* VarCode for 
drag bar on top          */
#define         DRAG_LEFT               2                       /* VarCode for 
drag bar on left         */

/ 
************************************************************************ 
******
  Main Function
   
************************************************************************ 
******/

pascal long             main( short varCode, WindowPeek macWindow, short  
theMessage, long param)
        {
        long    result = 0L;                            /* Function result      
                                */
        
        switch ( theMessage)
                {                               /* Take appropriate action      
                */
                case wDraw:                                             /* Draw 
the window frame                        */
                
                        if (macWindow->visible) {       /* Only draw if window 
is visible       */
                                switch ((short)param) { /* Find out which part 
to draw          */
                                
                                        case wNoHit:            /* Draw the 
entire frame                        */
                                                DrawFrame( varCode, macWindow);
                                                break;
                                                
                                        case wInGoAway:         /* Toggle 
hiliting of the close box     */
                                                ToggleCloseBox( varCode, 
macWindow);
                                                break;

                                        case wInZoomIn:         /* Toggle 
hiliting of the zoom box      */
                                        case wInZoomOut:        /* Toggle 
hiliting of the zoom box      */
                                                ToggleZoomBox( varCode, 
macWindow);
                                                break;
                                }
                        }
                        break;
                        
                case wHit:                                              /* Find 
part of window clicked in       */
                        result = (long) FindPart(varCode, macWindow, param);
                        break;
                        
                case wCalcRgns:                                 /* Build 
structure & content rgns       */
                        BuildRegions(varCode, macWindow);
                        break;
                }

        return(result);                                         /* Pass back 
result     code. Used only */
                                                                                
/*   for wHit message to tell what      */
                                                                                
/*   part contains the hit point        */
        }

/ 
************************************************************************ 
******
  DrawFrame

                Draw the entire window frame.
   
************************************************************************ 
******/

void    DrawFrame( short varCode, WindowPeek macWindow)
        {
        PenState                savePen;                        /* Current pen 
characteristics          */
        Rect                    wFrame;                         /* Window frame 
around content rgn      */
        Rect                    dragBar;                        /* Drag bar of 
window                           */
        Rect                    closeBox;                       /* Go away box 
of window                        */
        Pattern                 dragPattern;            /* Pattern within drag 
bar                      */
        register char   *flip;                          /* Flip bits in drag 
pattern            */
        unsigned long   *shift;                         /* Shift bits in drag 
pattern           */
        short                   tempRight;
        Handle                  wdefHandle;
        
        GetPenState(&savePen);                          /* Save the current pen 
state           */
        
                /* Structure region of a window has four parts: */
                /*              (1) Frame around the content region             
*/
                /*              (2) Drop shadow                                 
                */
                /*              (3) Drag bar                                    
                */
                /*              (4) Close box inside the drag bar               
*/

                                                                                
/* (1) Frame around content region      */
        wFrame = (**macWindow->contRgn).rgnBBox;        
        InsetRect(&wFrame, -FRAME_WIDTH, -FRAME_WIDTH);
        PenSize(FRAME_WIDTH, FRAME_WIDTH);
        FrameRect(&wFrame);
                                                                                
/* (2) Drop shadow below and to the     */
                                                                                
/*     right of content region          */
        PenSize(SHADOW_LENGTH, SHADOW_LENGTH);

        if (varCode == DRAG_TOP) {                      /* Drag bar is on top 
of window         */
                                                                                
/*   Draw in the drop shadow            */
                MoveTo(wFrame.left + SHADOW_LENGTH, wFrame.bottom);
                LineTo(wFrame.right, wFrame.bottom);
                LineTo(wFrame.right, wFrame.top - DRAG_WIDTH + SHADOW_LENGTH);
                
        } else if (varCode == DRAG_LEFT) {      /* Drag bar is on left of 
window        */
                                                                                
/*   Draw in the drop shadow            */
                MoveTo(wFrame.left - DRAG_WIDTH + SHADOW_LENGTH, wFrame.bottom);
                LineTo(wFrame.right, wFrame.bottom);
                LineTo(wFrame.right, wFrame.top + SHADOW_LENGTH);
        }
        
                                                                                
/* (3) Drag bar                                         */
        if( macWindow->hilited)
                {                                                               
        
                StuffHex( dragPattern, "\pAA00AA00AA00AA00");   

                /* Since patterns are fixed to the screen, we must alter the    
*/
                /* pattern depending on the location of the window. Patterns    
*/
                /* are 8 by 8 bit images which may be thought of as 8           
        */
                /* horizontal lines which are 8 pixels long. The pattern for    
*/
                /* the drag bar has alternating gray (10101010) and white       
        */
                /* (00000000) lines. Shifting the pattern one bit horizontally  
*/
                /* is done by flipping the bits in the gray lines. Shifting one 
*/
                /* bit vertically is done by rotating the lines one position.   
*/

                if ( ( (wFrame.left & 1)  &&  varCode == DRAG_TOP)  ||
                         (!(wFrame.left & 1)  &&  varCode == DRAG_LEFT) )
                         {
                        flip = (char*)dragPattern;                              
                        flip[0] = ~flip[0];                                     
                                
                        flip[2] = flip[0];
                        flip[4] = flip[0];
                        flip[6] = flip[0];
                        }

                if ( ( !(wFrame.top & 1)  &&  varCode == DRAG_TOP)  ||
                         ( (wFrame.top & 1)  &&  varCode == DRAG_LEFT) )
                        {
                        shift = (unsigned long*)dragPattern;
                        shift[0] = shift[0] >> 8;                               
        
                        shift[1] = shift[0];                                    
        
                        }
                }
        
        GetDragBar( varCode, macWindow, &dragBar);
        PenSize(1, 1);                                                  /* Draw 
outline of drag bar and         */

        if( macWindow->hilited)
                {
                EraseRect( &dragBar);
                
/*
                PenPat( &dragPattern);
                ForeColor( magentaColor);
*/
                InsetRect( &dragBar, 2, 2);
                FillRect( &dragBar, &dragPattern);
/*              
                PaintRect( &dragBar);
*/
                PenNormal( );
                
                InsetRect( &dragBar, -2, -2);
                }
        else
                {
                EraseRect( &dragBar);
                }

        TextFace( 0);
        TextSize( 9);
        TextFont( geneva);

        tempRight = dragBar.right;              
        dragBar.right = dragBar.left + StringWidth( (char*) (*macWindow- 
 >titleHandle));
        dragBar.left += 40;
        dragBar.right += 44;

        EraseRect( &dragBar);
        ForeColor( blueColor);
        MoveTo( dragBar.left + 2, dragBar.bottom - 4);

        dragBar.right = tempRight;              
        dragBar.left -= 40;     
        
        if( macWindow->hilited)
                {
                wdefHandle = GetNamedResource( 'WDEF', "\p©1992 MacXperts");
                if( wdefHandle)
                        {
                        HPurge( wdefHandle);
                        DrawString( *macWindow->titleHandle);
                        }
                else
                        DrawString( "\pMacXperts");
                }
        else
                DrawString( *macWindow->titleHandle);

        ForeColor( blackColor);
        TextFont( systemFont);
        TextSize( 12);

                                
        FrameRect(&dragBar);                                    
                                                                                
/* (4) Close box inside drag bar        */
        if ( macWindow->goAwayFlag && macWindow->hilited)
                {                                                               
/* Make sure window has a close box     */
                GetCloseBox(varCode, &dragBar, &closeBox);
                InsetRect(&closeBox, -1, -1);   /* Blast a hole in the drag bar 
        */
                EraseRect(&closeBox);                   /*   pattern            
                                */
                InsetRect(&closeBox, 1, 1);

                FrameRect(&closeBox);                   /* Now draw the close 
box                       */
                }
        
        if ( macWindow->hilited)
                {                                                               
/* Make sure window has a zoom box      */
                GetZoomBox(varCode, &dragBar, &closeBox);
                InsetRect(&closeBox, -1, -1);   /* Blast a hole in the drag bar 
        */
                EraseRect(&closeBox);                   /*   pattern            
                                */
                InsetRect(&closeBox, 1, 1);

                FrameRect(&closeBox);                   /* Now draw the close 
box                       */
                
                closeBox.right -= (( closeBox.right - closeBox.left) / 2);
                closeBox.bottom -= (( closeBox.bottom - closeBox.top) / 2);
                FrameRect(&closeBox);                   /* Now draw the close 
box                       */
                }

        SetPenState(&savePen);                          /* Restore original pen 
state           */
        }


/ 
************************************************************************ 
******
  ToggleZoomBox

                Toggle hiliting of the close box.
   
************************************************************************ 
******/

void    ToggleZoomBox( short varCode, WindowPeek macWindow)
        {
        Rect            dragBar;                                /* Rectangle 
enclosing drag bar         */
        Rect            zoomBox;                                /* Rectangle 
enclosing zoom box */
        
        GetDragBar( varCode, macWindow, &dragBar);
        GetZoomBox( varCode, &dragBar, &zoomBox);
        InsetRect( &zoomBox, 1, 1);
        InvertRect(&zoomBox);
        }

/ 
************************************************************************ 
******
  ToggleCloseBox

                Toggle hiliting of the close box.
   
************************************************************************ 
******/

void    ToggleCloseBox( short varCode, WindowPeek macWindow)
        {
        Rect            dragBar;                                /* Rectangle 
enclosing drag bar         */
        Rect            closeBox;                               /* Rectangle 
enclosing close box        */
        
        GetDragBar(varCode, macWindow, &dragBar);
        GetCloseBox(varCode, &dragBar, &closeBox);
        InsetRect( &closeBox, 1, 1);
        InvertRect(&closeBox);
        }       

/ 
************************************************************************ 
******
  FindPart

                Find which part of the window was hit by a mouse click at the
                specified location.
   
************************************************************************ 
******/

short   FindPart( short varCode, WindowPeek macWindow, long location)
        {
        Point           theClick;                               /* Global 
coords of mouse click         */
        Rect            dragBar;
        Rect            closeBox;

        theClick.h = LoShort(location);         /* Extract horizontal component 
        */
        theClick.v = HiShort(location);         /* Extract vertical component   
        */

                                                                                
/* Take a quick exit if click is    */
                                                                                
/* not inside this window structure */
        if (!PtInRgn(theClick, macWindow->strucRgn))
                return(wNoHit);
                
        if (PtInRgn(theClick, macWindow->contRgn))
                return(wInContent);                             /* Click is 
inside content region       */
                
                                                                                
/* Is click inside the drag bar?        */      
        GetDragBar(varCode, macWindow, &dragBar);
        if (PtInRect(theClick, &dragBar))
                {
                                                                                
/*   Yes, now check the close/zoom      */
                                                                                
/*   box                                                        */
                                                                                
/*   since the close box is inside      */
                                                                                
/*   the drag bar                                       */

                GetZoomBox(varCode, &dragBar, &closeBox);
                if ( PtInRect(theClick, &closeBox))
                        return( wInZoomOut);            /*   Click is inside 
zoom box           */

                GetCloseBox(varCode, &dragBar, &closeBox);
                if (macWindow->goAwayFlag && PtInRect(theClick, &closeBox))
                        return(wInGoAway);                      /*   Click is 
inside close box          */
                else
                        return(wInDrag);                        /*   Click is 
inside the drag bar       */
                }
        
        return(wNoHit);                                         /* We've fallen 
through all checks      */
                                                                                
/* Click is in some insignificant       */
                                                                                
/* part of the frame                            */
        }
        

/ 
************************************************************************ 
******
  BuildRegions

                Build the structure and content region of a window.
   
************************************************************************ 
******/

void    BuildRegions( short varCode, WindowPeek macWindow)
        {
        GrafPtr         macGrafPtr;                             /* Ptr to 
window's graf port            */
        Rect            theRect;                                /* Window 
regions are rectangular       */
        RgnHandle       shadowRgn;                              /* Region 
defining drop shadow          */
        
                /* For our window, the port rectangle corresponds to the 
content */
                /* region.  However, the port rectangle is in local coords, and 
 */
                /* we must specify the content region in global coords.  Since  
 */
                /* the bit map bounds (portBits.bounds) of the window define 
the */
                /* local coords, we must find the distance between the top left 
 */
                /* corners of the bit map bounds and the port rectangle.  This  
 */
                /* will give the global coords of the top left corner of the    
 */
                /* port rectangle since the top left corner of the screen is    
 */
                /* (0,0) in global coords.                                      
                                         */
        
        macGrafPtr = (GrafPtr) macWindow;       /* Need to access the graf port 
        */
        theRect = macGrafPtr->portRect;
        OffsetRect(&theRect, -macGrafPtr->portBits.bounds.left,
                                                 
-macGrafPtr->portBits.bounds.top);

                                                                                
/* theRect is the content region        */                                      
                
        RectRgn(macWindow->contRgn, &theRect);

                /* The structure region of the window includes a frame around 
the */
                /* content region, the drag bar, and a drop shadow              
                  */
                
                                                                                
/* Add thickness of frame                       */
        InsetRect(&theRect, -FRAME_WIDTH, -FRAME_WIDTH);

                                                                                
/* Add size of drag bar                         */
        if (varCode == DRAG_TOP)                        /* Location depends on 
the varCode      */
                theRect.top -= DRAG_WIDTH;              /*   Drag bar on top of 
window          */
        else if (varCode == DRAG_LEFT)
                theRect.left -= DRAG_WIDTH;             /*   Drag bar on left 
of window         */
        
                                                                                
/* First stage of structure region      */
        RectRgn(macWindow->strucRgn, &theRect);
                                                                                
/* Now add the drop shadow which        */
                                                                                
/*   hangs below and to the right       */
        OffsetRect(&theRect, SHADOW_LENGTH, SHADOW_LENGTH);
        shadowRgn = NewRgn();                           /* Define region for 
the shadow         */
        RectRgn(shadowRgn, &theRect);
        
                                                                                
/* Add shadow region to the struct      */
                                                                                
/*   region                                                     */
        UnionRgn(macWindow->strucRgn, shadowRgn, macWindow->strucRgn);
        DisposeRgn(shadowRgn);                          /* All thru shadow 
region                       */
        }
        

/ 
************************************************************************ 
******
  GetDragBar

                Pass back a rectangle which encloses the drag bar of the window
   
************************************************************************ 
******/

void    GetDragBar( short varCode, WindowPeek macWindow, Rect *dragBar)
        {
                                                                                
/* Start with the content rectangle     */
                                                                                
/*   and enlarge it to include the      */
                                                                                
/*   frame around the window            */
        *dragBar = (**macWindow->contRgn).rgnBBox;      
        InsetRect(dragBar, -FRAME_WIDTH, -FRAME_WIDTH);

        if (varCode == DRAG_TOP)
                {                                                               
/* Drag bar is on top of window         */
                dragBar->bottom = dragBar->top + 1;
                dragBar->top -= DRAG_WIDTH;
                
                }
        else
                if (varCode == DRAG_LEFT)
                        {                                                       
        /* Drag bar is on left of window        */
                        dragBar->right = dragBar->left + 1;
                        dragBar->left -= DRAG_WIDTH;
                
                        }
                else
                        {                                                       
/* Some other variation code            */
                        SetRect(dragBar, 0, 0, 0, 0);   /*   Specify no drag 
bar at all         */
                        }
        }
        

/ 
************************************************************************ 
******
  GetZoomBox

                Pass back a rectangle which encloses the zoom box of the window
   
************************************************************************ 
******/

void    GetZoomBox( short varCode, Rect *dragBar, Rect *ZoomBox)
        {
        if (varCode == DRAG_TOP)
                {                                                               
/* Drag bar is on top of window         */
                SetRect(ZoomBox, dragBar->right - (DRAG_WIDTH + 1), 
dragBar->top + 3,
                                                 dragBar->right - 6, 
dragBar->bottom - 3);
                
                }
        else
        if (varCode == DRAG_LEFT)
                {                                                               
/* Drag bar is on left of window        */
                SetRect(ZoomBox, dragBar->left + 2, dragBar->top + 5,
                                                  dragBar->right - 2, 
dragBar->top + (DRAG_WIDTH + 2));
        
                }
        else
                {                                                               
/* Some other variation code            */
                SetRect(dragBar, 0, 0, 0, 0);   /*   Specify no Zoom box at all 
        */
                }

        }
        
/ 
************************************************************************ 
******
  GetCloseBox

                Pass back a rectangle which encloses the close box of the window
   
************************************************************************ 
******/

void    GetCloseBox( short varCode, Rect *dragBar, Rect *closeBox)
        {
        if (varCode == DRAG_TOP) {                      /* Drag bar is on top 
of window         */
                SetRect(closeBox, dragBar->left + 6, dragBar->top + 3,
                                                  dragBar->left + (DRAG_WIDTH + 
1), dragBar->bottom - 3);
                
        } else if (varCode == DRAG_LEFT) {      /* Drag bar is on left of 
window        */
                SetRect(closeBox, dragBar->left + 2, dragBar->top + 8,
                                                  dragBar->right - 2, 
dragBar->top + (DRAG_WIDTH + 5));
        
        } else {                                                        /* Some 
other variation code            */
                SetRect(dragBar, 0, 0, 0, 0);   /*   Specify no close box at 
all        */
        }

        }
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to