TweetFollow Us on Twitter

MACINTOSH C CARBON

Demonstration Program Appearance

Goto Contents

// *******************************************************************************************
// Appearance.c                                                            CLASSIC EVENT MODEL
// *******************************************************************************************
// 
// This program opens two kWindowDocumentProc windows containing:
//
// o  In the first window:
//
//    o  On Mac OS 8/9, a theme-compliant list view.
//
//    o  On Mac OS X, some text drawn with Appearance Manager functions.
//
// o  In the second window, various images drawn with Appearance primitives and, on Mac OS 
//    8/9, text drawn in the window header in the correct Appearance colour.
//
// Two of the images in the second window are edit text field frames and one is a list box
// frame.  At any one time, one of these will have a keyboard focus frame drawn around it.
// Clicking in one of the other frames will move the keyboard focus frame to that frame.
//
// The program utilises the following resources:
//
// o  A 'plst' resource.
//
// o  An 'MBAR' resource, and 'MENU' resources for Apple, File, and Edit menus (preload, 
//    non-purgeable).  
//
// o  Two 'WIND' resources (purgeable) (initially not visible).
//
// o  A 'STR#' list resource (purgeable) containing text drawn in the first window.
//
// o  'hrct' and 'hwin' resources (both purgeable), which provide help balloons describing the
//     contents of the windows (Mac OS 8/9).
//
// o  A 'SIZE' resource with the acceptSuspendResumeEvents,  canBackground, 
//    doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
//
// *******************************************************************************************

// .................................................................................. includes

#include <Carbon.h>

// ................................................................................... defines

#define rMenubar          128
#define rNewWindow1       128
#define rNewWindow2       129
#define mAppleApplication 128
#define  iAbout           1
#define mFile             129
#define  iQuit            12
#define sDescription      128
#define MAX_UINT32        0xFFFFFFFF

// .......................................................................... global variables

Boolean   gRunningOnX = false;
Boolean   gDone;
Boolean   gInBackground;
WindowRef gWindowRef1, gWindowRef2;
SInt16    gPixelDepth;
Boolean   gIsColourDevice = false;
Rect      gCurrentRect;
Rect      gEditText1Rect = { 141, 20, 162, 239 };
Rect      gEditText2Rect = { 169, 20, 190, 239 };
Rect      gListBoxRect   = { 203, 90, 300, 239 };

// ....................................................................... function prototypes

void  main                        (void);
void  doPreliminaries             (void);
OSErr quitAppEventHandler         (AppleEvent *,AppleEvent *,SInt32);
void  doEvents                    (EventRecord *);
void  doUpdate                    (EventRecord *);
void  doActivate                  (EventRecord *);
void  doActivateWindow            (WindowRef,Boolean);
void  doOSEvent                   (EventRecord *);
void  doDrawAppearancePrimitives  (ThemeDrawState);
void  doDrawThemeCompliantTextOn9 (WindowRef,ThemeDrawState);
void  doDrawListViewOn9           (WindowRef);
void  doDrawThemeTextOnX          (WindowRef,ThemeDrawState);
void  doChangeKeyBoardFocus       (Point);
void  doGetDepthAndDevice         (void);

// ************************************************************************************** main

void  main(void)
{
  MenuBarHandle menubarHdl;
  SInt32        response;
  MenuRef       menuRef;
  SInt16        fontNum;
  EventRecord   EventStructure;

  // ........................................................................ do preliminaries

  doPreliminaries();

  // ............................................................... set up menu bar and menus

  menubarHdl = GetNewMBar(rMenubar);
  if(menubarHdl == NULL)
    ExitToShell();
  SetMenuBar(menubarHdl);
  DrawMenuBar();

  Gestalt(gestaltMenuMgrAttr,&response);
  if(response & gestaltMenuMgrAquaLayoutMask)
  {
    menuRef = GetMenuRef(mFile);
    if(menuRef != NULL)
    {
      DeleteMenuItem(menuRef,iQuit);
      DeleteMenuItem(menuRef,iQuit - 1);
      DisableMenuItem(menuRef,0);
    }

    gRunningOnX = true;
  }

  // .................................. open first window, set font and font size, show window

  if(!(gWindowRef1 = GetNewCWindow(rNewWindow1,NULL,(WindowRef)-1)))
    ExitToShell();

  SetPortWindowPort(gWindowRef1);
  if(!gRunningOnX)
    UseThemeFont(kThemeSmallSystemFont,smSystemScript);
  else
  {
    GetFNum("\pAmerican Typewriter",&fontNum);
    TextFont(fontNum);
    TextSize(11);
  }

  if(!gRunningOnX)
    SetWTitle(gWindowRef1,"\pList Views");
  else
    SetWTitle(gWindowRef1,"\pTheme Text");

  ShowWindow(gWindowRef1);

  // ................ open second window, set font, set background colour/pattern, show window


  if(!(gWindowRef2 = GetNewCWindow(rNewWindow2,NULL,(WindowRef)-1)))
    ExitToShell();

  SetPortWindowPort(gWindowRef2);
  UseThemeFont(kThemeSmallSystemFont,smSystemScript);

  SetThemeWindowBackground(gWindowRef2,kThemeBrushDialogBackgroundActive,false);

  ShowWindow(gWindowRef2);

  // ...... get pixel depth and whether colour device for certain Appearance Manager functions

  if(!gRunningOnX)
    doGetDepthAndDevice();

// .............. set top edit text field rectangle as target for initial keyboard focus frame

  gCurrentRect = gEditText1Rect;

  // ......................................................................... enter eventLoop

  gDone = false;

  while(!gDone)
  {
    if(WaitNextEvent(everyEvent,&EventStructure,MAX_UINT32,NULL))
      doEvents(&EventStructure);
  }
}

// *************************************************************************** doPreliminaries

void  doPreliminaries(void)
{
  OSErr osError;

  MoreMasterPointers(32);
  InitCursor();
  FlushEvents(everyEvent,0);

  osError = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
                            NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler),
                            0L,false);
  if(osError != noErr)
    ExitToShell();  
}

// **************************************************************************** doQuitAppEvent

OSErr  quitAppEventHandler(AppleEvent *appEvent,AppleEvent *reply,SInt32 handlerRefcon)
{
  OSErr    osError;
  DescType returnedType;
  Size     actualSize;

  osError = AEGetAttributePtr(appEvent,keyMissedKeywordAttr,typeWildCard,&returnedType,NULL,0,
                              &actualSize);

  if(osError == errAEDescNotFound)
  {
    gDone = true;
    osError = noErr;
  } 
  else if(osError == noErr)
    osError = errAEParamMissed;

  return osError;
}

// ********************************************************************************** doEvents

void  doEvents(EventRecord *eventStrucPtr)
{
  SInt32         menuChoice;
  MenuID         menuID;
  MenuItemIndex  menuItem;
  WindowPartCode partCode;
  WindowRef      windowRef;

  switch(eventStrucPtr->what)
  {
    case kHighLevelEvent:
      AEProcessAppleEvent(eventStrucPtr);
      break;

    case keyDown:
      if((eventStrucPtr->modifiers & cmdKey) != 0)
      {
        menuChoice = MenuEvent(eventStrucPtr);
        menuID = HiWord(menuChoice);
        menuItem = LoWord(menuChoice);
        if(menuID == mFile && menuItem  == iQuit)
          gDone = true;
      }
      break;

    case mouseDown:
      if(partCode = FindWindow(eventStrucPtr->where,&windowRef))
      {
        switch(partCode)
        {
          case inMenuBar:
            menuChoice = MenuSelect(eventStrucPtr->where);
            menuID = HiWord(menuChoice);
            menuItem = LoWord(menuChoice);

            if(menuID == 0)
              return;

            switch(menuID)
            {
              case mAppleApplication:
                if(menuItem == iAbout)
                {
                  SysBeep(10);
                  HiliteMenu(0);
                }
                break;

              case mFile:
                if(menuItem == iQuit)
                  gDone = true;
                break;
            }
            break;
        
          case inContent:
            if(windowRef != FrontWindow())
              SelectWindow(windowRef);
            else
            {
              if(FrontWindow() == gWindowRef2)
              {
                SetPortWindowPort(gWindowRef2);
                doChangeKeyBoardFocus(eventStrucPtr->where);
              }
            }
            break;
          
          case inDrag:
            DragWindow(windowRef,eventStrucPtr->where,NULL);
            break;
        }
      }
      break;

    case updateEvt:
      doUpdate(eventStrucPtr);
      break;

    case activateEvt:
      doActivate(eventStrucPtr);
      break;

    case osEvt:
      doOSEvent(eventStrucPtr);
      break;
  }
}

// ********************************************************************************** doUpdate

void  doUpdate(EventRecord *eventStrucPtr)
{
  WindowRef windowRef;

  windowRef = (WindowRef) eventStrucPtr->message;

  BeginUpdate(windowRef);

  SetPortWindowPort(windowRef);

  if(windowRef == gWindowRef2)
  {
    if(gWindowRef2 == FrontWindow() && !gInBackground)
    {
      doDrawAppearancePrimitives(kThemeStateActive);
      DrawThemeFocusRect(&gCurrentRect,true);
      if(!gRunningOnX)
        doDrawThemeCompliantTextOn9(windowRef,kThemeStateActive);
    }
    else
    {
      doDrawAppearancePrimitives(kThemeStateInactive);
      if(!gRunningOnX)
        doDrawThemeCompliantTextOn9(windowRef,kThemeStateInactive);
    }
  }

  if(windowRef == gWindowRef1)
  {
    if(!gRunningOnX)
      doDrawListViewOn9(windowRef);
  }

  EndUpdate(windowRef);
}

// ******************************************************************************** doActivate

void  doActivate(EventRecord *eventStrucPtr)
{
  WindowRef windowRef;
  Boolean   becomingActive;

  windowRef = (WindowRef) eventStrucPtr->message;
  becomingActive = ((eventStrucPtr->modifiers & activeFlag) == activeFlag);
  doActivateWindow(windowRef,becomingActive);
}

// ************************************************************************** doActivateWindow

void  doActivateWindow(WindowRef windowRef,Boolean becomingActive)
{
  if(windowRef == gWindowRef2)
  {
    SetPortWindowPort(gWindowRef2);
    doDrawAppearancePrimitives(becomingActive);
    DrawThemeFocusRect(&gCurrentRect,becomingActive);

    if(!gRunningOnX)
      doDrawThemeCompliantTextOn9(windowRef,becomingActive);

  }
  else if(windowRef == gWindowRef1 && gRunningOnX)
  {
    SetPortWindowPort(gWindowRef1);
    doDrawThemeTextOnX(windowRef,becomingActive);
  }
}

// ********************************************************************************* doOSEvent

void  doOSEvent(EventRecord *eventStrucPtr)
{
  switch((eventStrucPtr->message >> 24) & 0x000000FF)
  {
    case suspendResumeMessage:
      if((eventStrucPtr->message & resumeFlag) == 1)
      {
        SetThemeCursor(kThemeArrowCursor);
        gInBackground = false;
      }
      else
        gInBackground = true;
      break;
  }
}

// **************************************************************** doDrawAppearancePrimitives

void  doDrawAppearancePrimitives(ThemeDrawState inState)
{
  Rect theRect;

  if(gRunningOnX)
  {
    GetWindowPortBounds(gWindowRef2,&theRect);
    EraseRect(&theRect);
  }

  SetRect(&theRect,-1,-1,261,26);
  DrawThemeWindowHeader(&theRect,inState);

  SetRect(&theRect,20,46,119,115);
  DrawThemePrimaryGroup(&theRect,inState);

  SetRect(&theRect,140,46,239,115);
  DrawThemeSecondaryGroup(&theRect,inState);

  SetRect(&theRect,20,127,240,128);
  DrawThemeSeparator(&theRect,inState);

  DrawThemeEditTextFrame(&gEditText1Rect,inState);

  DrawThemeEditTextFrame(&gEditText2Rect,inState);

  SetRect(&theRect,20,203,62,245);
  DrawThemeGenericWell(&theRect,inState,false);

  SetRect(&theRect,20,258,62,300);
  DrawThemeGenericWell(&theRect,inState,true);

  SetRect(&theRect,75,202,76,302);
  DrawThemeSeparator(&theRect,inState);

  DrawThemeListBoxFrame(&gListBoxRect,inState);

  SetRect(&theRect,-1,321,261,337);
  DrawThemePlacard(&theRect,inState);
}

// *************************************************************** doDrawThemeCompliantTextOn9

void  doDrawThemeCompliantTextOn9(WindowRef windowRef,ThemeDrawState inState)
{
  SInt16 windowWidth, stringWidth;
  Rect   portRect;
  Str255 message = "\pBalloon help is available";

  if(inState == kThemeStateActive)
    SetThemeTextColor(kThemeTextColorWindowHeaderActive,gPixelDepth,gIsColourDevice);
  else
    SetThemeTextColor(kThemeTextColorWindowHeaderInactive,gPixelDepth,gIsColourDevice);

  GetWindowPortBounds(windowRef,&portRect);
  windowWidth = portRect.right - portRect.left;
  stringWidth = StringWidth(message);
  MoveTo((windowWidth / 2) - (stringWidth / 2), 17);
  DrawString(message);  
}

// ************************************************************************* doDrawListViewOn9

void  doDrawListViewOn9(WindowRef windowRef)
{
  Rect   theRect;
  SInt16 a;

  GetWindowPortBounds(windowRef,&theRect);

  SetThemeBackground(kThemeBrushListViewBackground,gPixelDepth,gIsColourDevice);
  EraseRect(&theRect);

  theRect.left += 130;

  SetThemeBackground(kThemeBrushListViewSortColumnBackground,gPixelDepth,gIsColourDevice);
  EraseRect(&theRect);

  SetThemePen(kThemeBrushListViewSeparator,gPixelDepth,gIsColourDevice);

  GetWindowPortBounds(windowRef,&theRect);

  for(a=theRect.top;a<=theRect.bottom;a+=18)
  {
    MoveTo(theRect.left,a);
    LineTo(theRect.right - 1,a);
  }

  SetThemeTextColor(kThemeTextColorListView,gPixelDepth,gIsColourDevice);

  for(a=theRect.top;a<=theRect.bottom +18;a+=18)
  {
    MoveTo(theRect.left,a - 5);
    DrawString("\p   List View Background        List View Sort Column");
  }
}

// ************************************************************************ doDrawThemeTextOnX

void  doDrawThemeTextOnX(WindowRef windowRef,ThemeDrawState inState)
{
  Rect        portRect;
  Str255      theString;
  CFStringRef stringRef;

  GetWindowPortBounds(windowRef,&portRect);
  EraseRect(&portRect);

  if(inState == kThemeStateActive)
    TextMode(srcOr);
  else
    TextMode(grayishTextOr);

  SetRect(&portRect,portRect.left,30,portRect.right,50);
  DrawThemeTextBox(CFSTR("System Font"),kThemeSystemFont,inState,true,
                   &portRect,teJustCenter,NULL);
  SetRect(&portRect,portRect.left,60,portRect.right,80);
  DrawThemeTextBox(CFSTR("Emphasized System Font"),kThemeEmphasizedSystemFont,inState,true,
                   &portRect,teJustCenter,NULL);
  SetRect(&portRect,portRect.left,90,portRect.right,105);
  DrawThemeTextBox(CFSTR("Small System Font"),kThemeSmallSystemFont,inState,true,
                   &portRect,teJustCenter,NULL);
  SetRect(&portRect,portRect.left,120,portRect.right,135);
  DrawThemeTextBox(CFSTR("Small Emphasized System Font"),kThemeSmallEmphasizedSystemFont,
                   inState,true,&portRect,teJustCenter,NULL);
  SetRect(&portRect,portRect.left,150,portRect.right,170);
  DrawThemeTextBox(CFSTR("Application Font"),kThemeApplicationFont,inState,true,
                   &portRect,teJustCenter,NULL);
  SetRect(&portRect,portRect.left,180,portRect.right,190);
  DrawThemeTextBox(CFSTR("Label Font"),kThemeLabelFont,inState,true,
                   &portRect,teJustCenter,NULL);
  
  GetIndString(theString,sDescription,1);
  stringRef = CFStringCreateWithPascalString(NULL,theString,CFStringGetSystemEncoding());
  SetRect(&portRect,portRect.left + 20,210,portRect.right - 20,300);
  DrawThemeTextBox(stringRef,kThemeCurrentPortFont,inState,true,&portRect,teJustCenter,NULL);

  if(stringRef != NULL)
    CFRelease(stringRef);
}

// ********************************************************************* doChangeKeyBoardFocus

void  doChangeKeyBoardFocus(Point mouseXY)
{
  Rect portRect;

  DrawThemeFocusRect(&gCurrentRect,false);
  DrawThemeEditTextFrame(&gCurrentRect,kThemeStateActive);
  SetPortWindowPort(gWindowRef2);
  GlobalToLocal(&mouseXY);

  if(PtInRect(mouseXY,&gEditText1Rect))
    gCurrentRect = gEditText1Rect;
  else if(PtInRect(mouseXY,&gEditText2Rect))
    gCurrentRect = gEditText2Rect;
  else if(PtInRect(mouseXY,&gListBoxRect))
    gCurrentRect = gListBoxRect;

  GetWindowPortBounds(gWindowRef2,&portRect);
  InvalWindowRect(gWindowRef2,&portRect);
}

// *********************************************************************** doGetDepthAndDevice

void doGetDepthAndDevice(void)
{
  GDHandle deviceHdl;

  deviceHdl = GetMainDevice();
  gPixelDepth = (*(*deviceHdl)->gdPMap)->pixelSize;
  if(((1 << gdDevType) & (*deviceHdl)->gdFlags) != 0)
    gIsColourDevice = true;
}

// *******************************************************************************************

Demonstration Program Appearance Comments

When this program is run, the user should:

o With the "Drawing With Primitives" window frontmost, click in the edit text frame not
  currently outlined with the keyboard focus frame, or in the list box frame, so as to move the
  keyboard focus frame to that rectangle.

o Click on the desktop to send the application to the background and note the changed
  appearance of the frames and text in the "Drawing With Primitives" window.  On Mac OS 8/9,
  note also that there is no change to the appearance of the content region of the "List Views"
  window.  On Mac OS X, note the changed appearance of the text in the "Theme Text" window. 
  Click on the "Drawing With Primitives" window to bring the application to the foreground with
  that window active, noting the changed appearance of the frames and text.  Click on the
  "Theme Text" window to make it active and note the changed appearance of the text.

o On Mac OS 8/9, Choose Show Balloons from the Help menu and move the cursor over the frames in
  the window titled "Drawing With Primitives" window (when active), and the left and right 
  sides of the window titled "List Views" (when active), noting the descriptions
  in the balloons.

In the following, reference is made to graphics devices and pixel depth.  Graphics devices and
pixel depth are explained at Chapter 11.

Global Variables

gWindowRef1 and gWindowRef2 will be assigned references to window objects.

gPixelDepth will be assigned the pixel depth of the main device (screen).  gIsColourDevice will
be assigned true if the graphics device is a colour device and false if it is a monochrome
device.  The values in these two variables are required by certain Appearance Manager
functions.

gCurrentRect will be assigned the rectangle which is to be the current target for the keyboard
focus frame.  gEditText1Rect, gEditText2Rect, and gListBoxRect are assigned the rectangles for
the two edit text frames and the list box frame.

main

After each window is created, its graphics port is set as the current port before the port's
font is set.  For the first window's graphics port, if the program is running on Mac OS 8/9,
the Appearance Manager function UseThemeFont is called to set the font to the small system
font.  Otherwise the Font Manager function GetFNum is called to get the font number for
American Typewriter, which is then set as the port's font, at 11 points, by the QuickDraw
functions TextFont and TextSize.  For the second window's graphics port, UseThemeFont is called
to set the font to the small system font.

If the program is running on OS 8/9, SetThemeWindowBackground is called to set a
theme-compliant colour/pattern for the "Drawing With Primitives" window's content area.  This
means that the content area will be automatically repainted with that colour/pattern when
required with no further assistance from the application.  When false is passed in the third
parameter, the content region of the window is not invalidated.  (Passing true in this instance
is not appropriate because the window is not yet showing.)

If the program is running on OS 8/9, doGetDepthAndDevice is called to determine the current
pixel depth of the graphics port, and whether the current graphics device is a colour device,
and assign the results to the global variables gPixelDepth and gIsColourDevice.  These values
are required by certain Appearance Manager functions which, in this program, are not called if
the program is running on Mac OS X.

The next line sets the initial target for the keyboard focus frame.  This is the rectangle used
by the first edit text field frame.

doEvents

At the mouseDown case, the inContent case within the partCode switch is of relevance to the
demonstration.

If the mouse-down was within the content region of a window, and if that window is not the
front window, SelectWindow is called to bring that window to the front and activate it.

However, if the window is the front window, and if that window is the "Drawing With Primitives"
window, that window's graphics port is set as the current graphics port for drawing, and
doChangeKeyBoardFocus is called.  That function determines whether the mouse-down was within
one of the edit text field frames or the list box frame, and moves the keyboard focus if
necessary.

doUpdate

Within the doUpdate function, if the window to which the update event relates is the "Drawing
With Primitives" window, if that window is currently the front window, and if the application
is not currently in the background:

o Functions are called to draw the primitives and, on Mac OS 8/9 only, the window header text
  in the active mode.

o DrawThemeFocusRect is called to draw the keyboard focus frame using the rectangle currently
  assigned to the global variable gCurrentRect.

If, however, the "Drawing With Primitives" window is not the front window, the same calls are
made but with the primitives and, on Mac OS 8/9 only, text being drawn in the inactive mode. 
Note that no call is required to erase the keyboard focus frame because this will already have
been erased when the window was deactivated (see below).

If the window to which the update event relates is the "List Views" window, doDrawListViewOn9
is called to draw the window's content area.  Note that, for this window, there is no
differentiation between active and inactive modes.  This is because, for list views, the same
brush type constants are used regardless of whether the window is active or inactive.

doActivateWindow

When an activate event is received for the "Drawing With Primitives" window, functions are
called to draw the primitives and, on Mac OS 8/9 only, the window header text.  In addition, an
Appearance Manager function which draws and erases the keyboard focus rectangle is called.  The
value passed in the becomingActive parameter of these calls ensures ensure that, firstly, the
primitives and text are drawn in the appropriate mode and, secondly, the keyboard focus frame
is either drawn or erased, depending on whether the window is coming to the front or being sent
to the back.

If the activate event is for the first window and the program is running on Mac OS X,
doDrawThemeTextOnX is called to draw some text in the window in either the active or inactive
mode.

doDrawAppearancePrimitives

doDrawAppearancePrimitives uses Appearance Manager functions for drawing Appearance primitives,
and is called to draw the various frames in the "Drawing With Primitives" window.  The mode in
which the primitives are drawn (active or inactive) is determined by the Boolean value passed
in the inState parameter.

doDrawThemeCompliantTextOn9

doDrawThemeCompliantTextOn9, which is called only if the program is running on Mac OS 8/9, draw
some advisory text in the window header of the "Drawing With Primitives" window.  The QuickDraw
drawing function DrawString does the drawing; however, before the drawing begins, the
Appearance Manager function SetThemeTextColor is used to set the foreground colour for drawing
text, in either the active or inactive modes, so as to comply with the Platinum appearance.

At the first two lines, if "Drawing With Primitives" is the active window, SetThemeTextColor is
called with the kThemeTextColorWindowHeaderActive text colour constant passed in the first
parameter.  At the next two lines, if the window is inactive, SetThemeTextColor is called with
kThemeTextColorWindowHeaderInactive passed in the first parameter.  Note that SetThemeTextColor
requires the pixel depth of the graphics port, and whether the graphics device is a colour
device or a monochrome device, passed in the second and third parameters.

The next four lines simply adjust QuickDraw's pen location so that the text is drawn centered
laterally in the window header frame.  The call to DrawString draws the specified text.

doDrawListViewOn9

doDrawListViewOn9, which  is called only if the program is running on Mac OS 8/9, draws a list
view background in the specified window.

The first line copies the window's port rectangle to a local variable of type Rect.

The call to SetThemeBackground sets the background colour/pattern to the colour/pattern
represented by the theme-compliant brush type constant kThemeBrushListViewBackground.  The
QuickDraw function EraseRect fills the whole of the port rectangle with this colour/pattern.

The next line adjusts the Rect variable's left field so that the rectangle now represents the
right half of the port rectangle.  The same drawing process is then repeated, but this time
with kThemeBrushListViewSortColumnBackground passed in the first parameter of the
SetThemeBackground call.

SetThemePen is then called with the colour/pattern represented by the constant
kThemeBrushListViewSeparator passed in the first parameter.  The rectangle for drawing is then
expanded to equate with the port rectangle before the following five lines draw one-pixel-wide
horizontal lines, at 18-pixel intervals, from the top to the bottom of the port rectangle.

Finally, some text is drawn in the list view in the theme-compliant colour for list views. 
SetThemeTextColour is called with the kThemeTextColorListView passed in, following which a for
loop draws some text, at 18-pixel intervals, from the top to the bottom of the port rectangle.

doDrawThemeTextOnX

doDrawThemeTextOnX is called only if the program is running on Mac OS X.  It draws anti-aliased
text in the first window.

GetWindowPortBounds is called to copy the port rectangle to a local variable of type Rect. 
EraseRect is then called to erase the port rectangle, a necessary precursor to drawing over
existing anti-aliased text on Mac OS X using the Appearance Manager function DrawThemeTextBox.

As was done in the function doDrawThemeCompliantTextOn9, SetThemeTextColor could be used here
to set the text colour according to the value received in the inState formal parameter. 
However, in this instance the alternative of calling TextMode is used.  The so-called transfer
modes passed in the calls to TextMode are explained at Chapter 12.  srcOr is the default
transfer mode for text, and causes the colour of the glyph (the visual representation of a
character) to be determined by the graphics port's foreground colour.  The non-standard mode
grayishTextOr is used to draw text in the deactivated state.

Before each call to DrawThemeTextBox, SetRect is called to adjust the top and bottom fields of
the Rect variable portRect.  This controls the vertical positioning of the text in the window,
being passed in DrawThemeTextBox's inBoundingBox parameter.  teJustCenter is passed in
DrawThemeTextBox's inJust parameter to cause the text to be centre-justified within the
rectangle.  The Appearance Manager constants passed in the inFontID parameter determine the
size and style of the drawn text.

At the last block, a string is retrieved from a 'STR#' Resource.  After being converted to a
CFString, that string is drawn by DrawThemeTextBox in the bottom of the window.  Note that
kThemeCurrentPort passed in the inFontID parameter so as to cause the text to be drawn using
the window's graphics port font, which was set in main.

doChangeKeyBoardFocus

doChangeKeyBoardFocus is called when a mouse-down occurs in the content region of the "Drawing
With Primitives" window.

At the first two lines, Appearance Manager functions are used to, firstly, erase the keyboard
focus frame from the rectangle around which it is currently drawn and, secondly, redraw an edit
text field frame around that rectangle.

The call to GlobalToLocal converts the coordinates of the mouse-down to the local coordinates
required by the following calls to PtInRect.  PtInRect returns true if the mouse-down is within
the rectangle passed in the second parameter.  If one of the calls to PtInRect returns true,
that rectangle is made the current rectangle for keyboard focus by assigning it to the global
variable gCurrentRect.

The call to InvalWindowRect ensures that the keyboard focus frame will be drawn by the call to
DrawThemeFocusRect in the function doUpdate.

doGetDepthAndDevice

doGetDepthAndDevice determines the pixel depth of the graphics port, and whether the graphics
device is a colour device or a monochrome device, and assigns the results to two global
variables.  This information is required by the Appearance Manager functions SetThemeTextColor,
SetThemeBackground, and SetThemePen.
 
AAPL
$102.33
Apple Inc.
+1.27
MSFT
$46.67
Microsoft Corpora
-0.39
GOOG
$581.74
Google Inc.
-5.63

MacTech Search:
Community Search:

Software Updates via MacUpdate

GarageSale 6.8 - Create outstanding eBay...
GarageSale is a slick, full-featured client application for the eBay online auction system. Create and manage your auctions with ease. With GarageSale, you can create, edit, track, and manage... Read more
ScreenFlow 4.5.3 - Create screen recordi...
Save 5% with the MacUpdate coupon code: 68031AE15F -- Buy now! ScreenFlow is powerful, easy-to-use screencasting software for the Mac. With ScreenFlow you can record the contents of your entire... Read more
NeoOffice 2014.3 - Mac-tailored, OpenOff...
NeoOffice is a complete office suite for OS X. With NeoOffice, users can view, edit, and save OpenOffice documents, PDF files, and most Microsoft Word, Excel, and PowerPoint documents. NeoOffice 3.x... Read more
Typinator 6.2 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more
PopChar X 6.7 - Floating window shows av...
PopChar X helps you get the most out of your font collection. With its crystal-clear interface, PopChar X provides a frustration-free way to access any font's special characters. Expanded... Read more
Evernote 5.6.0 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
Monosnap 2.2.2 - Versatile screenshot ut...
Monosnap allows you to save screenshots easily, conveniently, and quickly, sharing them with friends and colleagues at once. It's the ideal choice for anyone who is looking for a smart and fast... Read more
Tunnelblick 3.4beta36 - GUI for OpenVPN...
Tunnelblick is a free, open source graphic user interface for OpenVPN on OS X. It provides easy control of OpenVPN client and/or server connections. It comes as a ready-to-use application with all... Read more
SoftRAID 5.0.4 - High-quality RAID manag...
SoftRAID allows you to create and manage disk arrays to increase performance and reliability. SoftRAID's intuitive interface and powerful feature set makes this utility a must have for any Mac OS X... Read more
Audio Hijack Pro 2.11.3 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more

Latest Forum Discussions

See All

Sword King Review
Sword King Review By Jennifer Allen on September 23rd, 2014 Our Rating: :: WEAK, SO WEAKUniversal App - Designed for iPhone and iPad Ever wanted to tap on a screen and assume you’ve killed a monster or two? Probably not, but just... | Read more »
Pangea Software Unveil Bundles and iOS 8...
Pangea Software Unveil Bundles and iOS 8 Updates Posted by Ellis Spice on September 23rd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Race Team Manager Review
Race Team Manager Review By Jennifer Allen on September 23rd, 2014 Our Rating: :: LIGHT RACINGUniversal App - Designed for iPhone and iPad Want to be in charge of a racing team but not be overwhelmed by tactics and options? Race... | Read more »
Kobojo Works with Creative Minds from Fi...
Kobojo has announced details for their newest game, Zodiac – a 2D persistent online RPG. Kobojo has put together a crack team of developers including composer Hitoshi Sakimoto and scenario writer Kazushige Nojima, whose work includes many of the... | Read more »
PlayHaus Review
PlayHaus Review By Amy Solomon on September 23rd, 2014 Our Rating: iPad Only App - Designed for the iPad PlayHaus is a interesting, stylish app for young children, full of cause-and-effect interactions.   | Read more »
Astropolo Review
Astropolo Review By Amy Solomon on September 23rd, 2014 Our Rating: Universal App - Designed for iPhone and iPad Astropolo is a space-themed children’s app with a great sense of style.   | Read more »
New E*TRADE Update Includes Touch ID and...
New E*TRADE Update Includes Touch ID and Home Screen Widget for iOS 8 Posted by Jessica Fisher on September 23rd, 2014 [ permalink ] | Read more »
Cupcake Carnival Review
Cupcake Carnival Review By Jennifer Allen on September 23rd, 2014 Our Rating: :: SAME OLDUniversal App - Designed for iPhone and iPad Cupcake Carnival does all the right match-3 things but it’s a format we’ve seen a little too... | Read more »
This Week at 148Apps: September 15-19, 2...
Expert App Reviewers   So little time and so very many apps. What’s a poor iPhone/iPad lover to do? Fortunately, 148Apps is here to give you the rundown on the latest and greatest releases. And we even have a tremendous back catalog of reviews; just... | Read more »
Kitty Powers’ Matchmaker – Tips, Tricks,...
Hey There, Kittens: | Read more »

Price Scanner via MacPrices.net

Razer DeathAdder Chroma Gaming Mouse Upgraded...
Razer has announced the launch of their new Razer DeathAdder Chroma gaming mouse. Even if you’re not a gamer, the DeathAdder bears considering. I’m a fan of the hard-wired tracking accuracy,... Read more
Check Apple prices on your device with iTracx
MacPrices is proud to offer readers a free iOS app (iPhones, iPads, & iPod touch) and Android app (Google Play and Amazon App Store) called iTracx, which allows you to glance at today’s lowest... Read more
Refurbished 2013 MacBook Pros available for u...
The Apple Store has Apple Certified Refurbished 13″ and 15″ MacBook Pros available starting at $929. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros (4GB RAM/... Read more
New iPhones Score Big in SquareTrade Breakabi...
SquareTrade has announced the iPhone 6 and its larger sibling, iPhone 6 Plus, performed impressively in Breakability testing, and each carries the top Breakability Score in their respective category... Read more
10 Million + First Weekend Sales Set New iPho...
Apple has announced it sold over 10 million new iPhone 6 and iPhone 6 Plus models, a new record, just three days after the launch on September 19. iPhone 6 and iPhone 6 Plus are now available in the... Read more
Betty Crocker Launches New Cookbook for iOS
Betty Crocker, a General Mills brand, an established food industry leader, has announced its free digital cookbook app has been refreshed to make cooking with iPhone, iPad and iPod touch even easier... Read more
Apple restocks some refurbished 2014 MacBook...
The Apple Store has restocked some Apple Certified Refurbished 2014 MacBook Airs, with prices starting at $769. An Apple one-year warranty is included with each MacBook, and shipping is free. These... Read more
13-inch 128GB MacBook Air on sale for $949, s...
B&H Photo has the new 2014 13″ 1.4GHz/128GB MacBook Air on sale for $949.99 including free shipping plus NY tax only. Their price is $50 off MSRP. B&H will also include free copies of... Read more
Apple offering free $25 iTunes Gift Card with...
The Apple Store is offering a free $25 iTunes Gift Card with the purchase of a $99 Apple TV for a limited time. Shipping is free. Read more
Apple refurbished iPod touch available for up...
The Apple Store has Apple Certified Refurbished 5th generation iPod touches available starting at $149. Apple’s one-year warranty is included with each model, and shipping is free. Most colors are... Read more

Jobs Board

Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Position Opening at *Apple* - Apple (United...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.