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 / DialogWindow.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  5.4 KB  |  178 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        DialogWindow.cp
  3.  
  4.     Contains:    Dialog example using Appearance Manager primitives.
  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.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. #include <MacWindows.h>
  28. #include "DialogWindow.h"
  29. #include "Appearance.h"
  30. #include "ColorPenState.h"
  31.  
  32. DialogWindow::DialogWindow() : BaseWindow( 129 )
  33. {
  34.     ::SetThemeWindowBackground( fWindow, kThemeActiveDialogBackgroundBrush, true );
  35. }
  36.  
  37. DialogWindow::~DialogWindow()
  38. {
  39. }
  40.  
  41. //———————————————————————————————————————————————————————————————————————————————————
  42. //    • Activate
  43. //———————————————————————————————————————————————————————————————————————————————————
  44. //    Activate our window by drawing all of our items in the active state.
  45. //
  46. void
  47. DialogWindow::Activate( EventRecord& )
  48. {
  49.     Rect                editTextRect = { 9, 9, 27, 101 };
  50.  
  51.     ::SetPort( fWindow );
  52.     ::DrawThemeModelessDialogFrame( &fWindow->portRect, kThemeStateActive );
  53.     DrawFakeEditText( kThemeStateActive );
  54.     DrawFakeListBox( kThemeStateActive );
  55.     DrawGroups( kThemeStateActive );
  56.     DrawSeparators( kThemeStateActive );
  57.     ::DrawThemeFocusRect( &editTextRect, true );
  58. }
  59.  
  60. //———————————————————————————————————————————————————————————————————————————————————
  61. //    • Deactivate
  62. //———————————————————————————————————————————————————————————————————————————————————
  63. //    Deactivate our window by drawing all of our items in the inactive state.
  64. //
  65. void
  66. DialogWindow::Deactivate( EventRecord& )
  67. {
  68.     Rect        rect = fWindow->portRect;
  69.     Rect        editTextRect = { 9, 9, 27, 101 };
  70.     
  71.     ::SetPort( fWindow );
  72.     ::DrawThemeModelessDialogFrame( &fWindow->portRect, kThemeStateDisabled );
  73.     DrawFakeEditText( kThemeStateDisabled );
  74.     DrawFakeListBox( kThemeStateDisabled );
  75.     DrawGroups( kThemeStateDisabled );
  76.     DrawSeparators( kThemeStateDisabled );
  77.     ::DrawThemeFocusRect( &editTextRect, false );
  78. }
  79.  
  80. //———————————————————————————————————————————————————————————————————————————————————
  81. //    • Draw
  82. //———————————————————————————————————————————————————————————————————————————————————
  83. //    Draws our dialog frame, edit text, list box, group box frames, as well as visual
  84. //    separators.
  85. //
  86. void
  87. DialogWindow::Draw()
  88. {
  89.     ::SetPort( fWindow );
  90.  
  91.     ::DrawThemeModelessDialogFrame( &fWindow->portRect,
  92.         ((WindowPeek)fWindow)->hilited ? kThemeStateActive : kThemeStateDisabled );
  93.     DrawFakeEditText( ((WindowPeek)fWindow)->hilited ? kThemeStateActive : kThemeStateDisabled );
  94.     DrawFakeListBox( ((WindowPeek)fWindow)->hilited ? kThemeStateActive : kThemeStateDisabled );
  95.     DrawGroups( ((WindowPeek)fWindow)->hilited ? kThemeStateActive : kThemeStateDisabled );
  96.     DrawSeparators( ((WindowPeek)fWindow)->hilited ? kThemeStateActive : kThemeStateDisabled );
  97. }
  98.  
  99. //———————————————————————————————————————————————————————————————————————————————————
  100. //    • DrawFakeEditText
  101. //———————————————————————————————————————————————————————————————————————————————————
  102. //    Draws a mock-up of an edit text box. Note that the edit text frame can actually
  103. //    be drawn outside of the rectangle given. You essentially pass it the content
  104. //    rectangle and it figures out where the frame and bevel should be.
  105. //
  106. void
  107. DialogWindow::DrawFakeEditText( ThemeDrawState drawState )
  108. {
  109.     Rect                editTextRect = { 10, 10, 26, 100 };
  110.     ColorPenState        state;
  111.     
  112.     ::SetPort( fWindow );
  113.     
  114.     ::GetColorAndPenState( &state );
  115.     ::NormalizeColorAndPen();
  116.     
  117.     ::EraseRect( &editTextRect );
  118.     ::DrawThemeEditTextFrame( &editTextRect, drawState );
  119.     
  120.     ::InsetRect( &editTextRect, -1, -1 );
  121.     ::DrawThemeFocusRect( &editTextRect, ((WindowPeek)fWindow)->hilited );
  122.     ::SetColorAndPenState( &state );
  123. }
  124.  
  125. //———————————————————————————————————————————————————————————————————————————————————
  126. //    • DrawFakeListBox
  127. //———————————————————————————————————————————————————————————————————————————————————
  128. //    Draws a mock-up of an list box. Note that the list frame can actually
  129. //    be drawn outside of the rectangle given. You essentially pass it the content
  130. //    rectangle and it figures out where the frame and bevel should be.
  131. //
  132. void
  133. DialogWindow::DrawFakeListBox( ThemeDrawState drawState )
  134. {
  135.     Rect                editTextRect = { 36, 10, 100, 100 };
  136.     ColorPenState        state;
  137.     
  138.     ::SetPort( fWindow );
  139.     
  140.     ::GetColorAndPenState( &state );
  141.     ::NormalizeColorAndPen();
  142.     
  143.     ::EraseRect( &editTextRect );
  144.     ::DrawThemeListBoxFrame( &editTextRect, drawState );
  145.     ::SetColorAndPenState( &state );
  146. }
  147.  
  148. //———————————————————————————————————————————————————————————————————————————————————
  149. //    • DrawGroups
  150. //———————————————————————————————————————————————————————————————————————————————————
  151. //    Draws a primary and secondary group box.
  152. //
  153. void
  154. DialogWindow::DrawGroups( ThemeDrawState drawState )
  155. {
  156.     Rect        primaryRect = { 10, 110, 110, 210 };
  157.     Rect        secondaryRect = { 20, 120, 100, 200 };
  158.     
  159.     ::DrawThemePrimaryGroup( &primaryRect, drawState );
  160.     ::DrawThemeSecondaryGroup( &secondaryRect, drawState );
  161. }
  162.  
  163. //———————————————————————————————————————————————————————————————————————————————————
  164. //    • DrawSeparators
  165. //———————————————————————————————————————————————————————————————————————————————————
  166. //    Simple visual separators
  167. //
  168. void
  169. DialogWindow::DrawSeparators( ThemeDrawState drawState )
  170. {
  171.     Rect        vertRect = { 120, 110, 125, 210 };
  172.     Rect        horizRect = { 10, 220, 110, 225 };
  173.     
  174.     ::DrawThemeSeparator( &vertRect, drawState );
  175.     ::DrawThemeSeparator( &horizRect, drawState );
  176. }
  177.  
  178.