home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Snippets / AppendDITL 1.0.2 / AppendDITL.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-15  |  3.7 KB  |  156 lines  |  [TEXT/CWIE]

  1. // AppendDITL
  2. // version 1.0.2
  3. // updated for CW7 on 951215
  4.  
  5. /*
  6.     This shell was created to demonstrate the correct way to use AppendDITL(), CountDITL(),
  7.     and ShortenDITL() Dialog Manager calls in System7.  This shell also show how to corectly
  8.     use the WindowFont for drawing text in a dialog This demo creates a sample dialog which 
  9.     contains a checkbox control using the WindowFont.  This checkbox appends and shortens the
  10.     dialogs DITL.  
  11.     
  12.     This sample is provided with the following files:
  13.     testShell.µ        // CodeWarroir 1.1.1.2 project file
  14.     testShell.c        // source for this demo
  15.     testShell.rsrc    // resources for this demo
  16.     AppendDITLDem    // sample compiled app
  17.     
  18.     !!!NOTE: The correct way to do this is to use overlayDITL if you plan on
  19.     shrinking the dialog back and forth between the appended and normal length.  I far as
  20.     I can tell this is not fully documanted anywhere!!!
  21.     
  22.     This code was provided to me by Phil Kearney, III (otherwise known as just plain "Dude")
  23.     
  24.     Thanks Dude :)
  25.     
  26.     - Marty Wachter
  27.     mrw@welchgate.welch.jhu.edu or afaMarty@aol.com
  28.     
  29.  
  30. */
  31.  
  32.  
  33. void             main(void);
  34. static void        ToolboxInit(void);
  35. void             DoTestDialog(void);
  36.  
  37. // • main
  38. //
  39. void main(void)
  40. {
  41.     ToolboxInit();
  42.     DoTestDialog();
  43.     ExitToShell();
  44. }
  45.  
  46.  
  47. // • DoTestDialog
  48. //
  49. void DoTestDialog(void)
  50. {
  51.     DialogPtr    theDialog = nil;
  52.     short        item, wide, high, origCnt;
  53.     Handle        ditlHndl = nil;
  54.     FontInfo    fInfo;
  55.     
  56.     // get the dialog from the resource fork
  57.     theDialog = GetNewDialog(1025, nil, (WindowPtr)-1L);
  58.     if(!theDialog)
  59.         return;
  60.     
  61.     // save the original item count for later shortening of the DITL
  62.     origCnt = CountDITL(theDialog);
  63.     
  64.     // get a handle to the DITL to append
  65.     ditlHndl = Get1Resource('DITL', 1026);
  66.     if(!ditlHndl)
  67.         return;
  68.     
  69.     // lock it down until we are through with the dialog
  70.     HLock(ditlHndl);
  71.     
  72.     SetPort(theDialog);
  73.     
  74.     // the proper way to set the dialog's text to be drawn
  75.     // in some other font chicago.
  76.     TextFont(geneva);
  77.     TextSize(9);
  78.     GetFontInfo(&fInfo);
  79.     
  80.     (**(((DialogPeek)theDialog)->textH)).txFont = geneva;
  81.     (**(((DialogPeek)theDialog)->textH)).txSize = 9;
  82.     
  83.     (**(((DialogPeek)theDialog)->textH)).lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  84.     (**(((DialogPeek)theDialog)->textH)).fontAscent = fInfo.ascent;
  85.     
  86.     // save the original width and height for later shortening
  87.     wide = theDialog->portRect.right - theDialog->portRect.left;
  88.     high = theDialog->portRect.bottom - theDialog->portRect.top;
  89.     
  90.     // show our dialog
  91.     ShowWindow(theDialog);
  92.     
  93.     do {
  94.     
  95.         ModalDialog(nil, &item);
  96.         
  97.         if(item == 3) {        // our checkbox
  98.         
  99.             short    iType, numAppended;
  100.             Rect    iRect;
  101.             Handle    iHandle;
  102.             Boolean    checked;
  103.             
  104.             // see if the checkbox is checked or not
  105.             GetDItem(theDialog, item, &iType, &iHandle, &iRect);
  106.             checked = GetCtlValue((ControlHandle)iHandle);
  107.             
  108.             if(!checked) {
  109.                 // append the DITL using overlayDITL mode
  110.                 AppendDITL(theDialog, ditlHndl, overlayDITL);
  111.                 
  112.             } else {
  113.                 // shorten the DITL to it's original size
  114.                 
  115.                 // get the differnece of items in the dialog - the original count
  116.                 numAppended = CountDITL(theDialog) - origCnt;
  117.                 
  118.                 // shorten the DITL
  119.                 ShortenDITL(theDialog, numAppended);
  120.                 
  121.                 // resize the dialog to it's original dimensions
  122.                 SizeWindow(theDialog, wide, high, true);
  123.             }
  124.             
  125.             // reset the control's value
  126.             SetCtlValue((ControlHandle)iHandle, !checked);
  127.         }
  128.         
  129.     } while(item > ok);
  130.     
  131.     // unlock and release
  132.     HUnlock(ditlHndl);
  133.     ReleaseResource(ditlHndl);
  134.     
  135.     // get rid of our dialog
  136.     DisposeDialog(theDialog);
  137. }
  138.  
  139.  
  140. // • ToolboxInit
  141. // Standard set of calls to enable all the toolbox calls
  142. //
  143. static void ToolboxInit(void)
  144. {
  145.     InitGraf((Ptr)&qd.thePort);
  146.     InitFonts();
  147.     InitWindows();
  148.     InitMenus();
  149.     TEInit();
  150.     InitDialogs(0L);
  151.     InitCursor();
  152.     MaxApplZone();
  153.     MoreMasters();
  154.     MoreMasters();
  155.     MoreMasters();
  156.  }