home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / TextPane.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  4.8 KB  |  188 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TextPane.cp
  3.  
  4.     Contains:    Class to drive our text pane in MegaDialog.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <2>     9/25/97    edv        Use an STR# to get the list box items. Pretty it up.
  25.          <1>     9/11/97    edv        First checked in.
  26. */
  27.  
  28. #include <Sound.h>
  29. #include <TextUtils.h>
  30. #include "TextPane.h"
  31. #include "Appearance.h"
  32. #include "AppearanceHelpers.h"
  33. #include <string.h>
  34.  
  35. //——————————————————————————————————————————————————————————————————————————————————————
  36. //    Enums, etc.
  37. //——————————————————————————————————————————————————————————————————————————————————————
  38.  
  39. enum
  40. {
  41.     kStaticText            = 1,
  42.     kDisabledStaticText    = 2,
  43.     kEditText             = 3,
  44.     kPasswordEditText    = 4,
  45.     kEditFilterText        = 5,
  46.     kClock                = 6,
  47.     kListBox            = 7,
  48.     kShowPasswordButton    = 8,
  49.     kPasswordStaticText    = 10
  50. };
  51.  
  52. enum
  53. {
  54.     kLeftArrow        = 0x1C,
  55.     kRightArrow        = 0x1D,
  56.     kUpArrow        = 0x1E,
  57.     kDownArrow        = 0x1F,
  58.     kBackspace        = 0x08
  59. };
  60.  
  61. enum
  62. {
  63.     kListBoxStringsID    = 130
  64. };
  65.  
  66. //——————————————————————————————————————————————————————————————————————————————————————
  67. //    Our keyfilter callback.
  68. //——————————————————————————————————————————————————————————————————————————————————————
  69.  
  70. ControlKeyFilterUPP TextPane::fFilterProc = NewControlKeyFilterProc( TextPane::NumericFilter );
  71.  
  72. //——————————————————————————————————————————————————————————————————————————————————————
  73. //    • TextPane
  74. //——————————————————————————————————————————————————————————————————————————————————————
  75. //    Constructor. Append our DITL and load our list box, etc.
  76. //
  77. TextPane::TextPane( DialogPtr dialog, SInt16 items ) : MegaPane( dialog, items )
  78. {
  79.     ControlHandle        control;
  80.     ListHandle            list;
  81.     OSErr                err;
  82.     
  83.     AppendDialogItemList( dialog, 6004, overlayDITL );
  84.     
  85.     GetDialogItemAsControl( dialog, items + kDisabledStaticText, &control );
  86.     DeactivateControl( control );
  87.     
  88.     GetDialogItemAsControl( dialog, items + kListBox, &control );
  89.     err = GetListBoxListHandle( control, &list );
  90.     if ( err == noErr )
  91.     {
  92.         Cell        cell;
  93.         SInt16        i;
  94.         Str255        string;
  95.         
  96.         cell.h = 0;
  97.         
  98.         for ( i = 1; true; i++ )
  99.         {
  100.             GetIndString( string, kListBoxStringsID, i );
  101.             if ( string[0] == 0 ) break;
  102.         
  103.             LAddRow( 1, (**list).dataBounds.bottom, list );
  104.             cell.v = (**list).dataBounds.bottom - 1;
  105.             LSetCell( (Ptr)(string + 1), string[0], cell, list );
  106.         }
  107.     }
  108.     
  109.     GetDialogItemAsControl( dialog, items + kEditFilterText, &control );
  110.     SetEditTextKeyFilter( control, fFilterProc );
  111. }
  112.  
  113. //——————————————————————————————————————————————————————————————————————————————————————
  114. //    • ~TextPane
  115. //——————————————————————————————————————————————————————————————————————————————————————
  116. //    Destructor. Get rid of our DITL items.
  117. //
  118. TextPane::~TextPane()
  119. {
  120.     ShortenDITL( fDialog, CountDITL( fDialog ) - fOrigItems );
  121. }
  122.  
  123. //——————————————————————————————————————————————————————————————————————————————————————
  124. //    • Idle
  125. //——————————————————————————————————————————————————————————————————————————————————————
  126. //    Give our dialog some idle time.
  127. //
  128. void
  129. TextPane::Idle()
  130. {
  131.     IdleControls( fDialog );
  132. }
  133.  
  134. //——————————————————————————————————————————————————————————————————————————————————————
  135. //    • ItemHit
  136. //——————————————————————————————————————————————————————————————————————————————————————
  137. //    Our item hit handler. Here we handle clicks on our items.
  138. //
  139. void
  140. TextPane::ItemHit( SInt16 itemHit )
  141. {
  142.     SInt16            localItem = itemHit - fOrigItems;
  143.     ControlHandle    control;
  144.     Str255            text;
  145.     
  146.     switch ( localItem )
  147.     {
  148.         case kShowPasswordButton:
  149.             GetDialogItemAsControl( fDialog, fOrigItems + kPasswordEditText, &control );
  150.             GetEditTextPasswordText( control, text );
  151.             GetDialogItemAsControl( fDialog, fOrigItems + kPasswordStaticText, &control );
  152.             SetStaticTextText( control, text, true );
  153.             break;
  154.     }
  155. }
  156.  
  157. //——————————————————————————————————————————————————————————————————————————————————————
  158. //    • NumericFilter                                                            CALLBACK
  159. //——————————————————————————————————————————————————————————————————————————————————————
  160. //    Our numeric key filter. This is called each time the edit field this controls is
  161. //    attached to receives a keystroke. We can either accept the keystroke or block it.
  162. //    To do this, we return either kControlKeyFilterPassKey or kControlKeyFilterBlockKey.
  163. //
  164. pascal ControlKeyFilterResult
  165. TextPane::NumericFilter( ControlHandle control, SInt16* keyCode, SInt16* charCode, SInt16* modifiers)
  166. {
  167.     #pragma unused( control, keyCode, modifiers )
  168.  
  169.     if ( ((char)*charCode >= '0') && ((char)*charCode <= '9') )
  170.         return kControlKeyFilterPassKey;
  171.     
  172.     switch ( *charCode )
  173.     {
  174.         case '-':
  175.         case kLeftArrow:
  176.         case kRightArrow:
  177.         case kUpArrow:
  178.         case kDownArrow:
  179.         case kBackspace:
  180.             return kControlKeyFilterPassKey;
  181.  
  182.         default:
  183.             SysBeep( 10 );
  184.             return kControlKeyFilterBlockKey;
  185.     }
  186. }
  187.  
  188.