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
$524.94
Apple Inc.
+5.93
MSFT
$40.01
Microsoft Corpora
-0.39
GOOG
$536.10
Google Inc.
-20.44

MacTech Search:
Community Search:

Software Updates via MacUpdate

VMware Fusion 6.0.3 - Run Windows apps a...
VMware Fusion allows you to create a Virtual Machine on your Mac and run Windows (including Windows 8.1) and Windows software on your Mac. Run your favorite Windows applications alongside Mac... Read more
Tweetbot 1.5.1 - Popular iOS twitter cli...
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Mac DVDRipper Pro 4.1.7 - Copy, backup,...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
PDFpenPro 6.2 - Advanced PDF toolkit for...
PDFpenPro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Create... Read more
PDFpen 6.2 - Edit and annotate PDFs with...
PDFpen allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Features... Read more
Monolingual 1.5.9 - Remove unwanted OS X...
Monolingual is a program for removing unnecesary language resources from OS X, in order to reclaim several hundred megabytes of disk space. It requires a 64-bit capable Intel-based Mac and at least... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - 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

Latest Forum Discussions

See All

Have a Special Dead Trigger 2 Easter Bas...
Have a Special Dead Trigger 2 Easter Basket Full of Goodies, Courtesy of Madfinger Games Posted by Rob Rich on April 18th, 2014 [ permalink ] Dead Trigger 2 | Read more »
Almost All of Playdek’s Library is on Sa...
Almost All of Playdek’s Library is on Sale Right Now, and You Should Check it Out Posted by Rob Rich on April 18th, 2014 [ permalink ] Playdek has released quite a few great iOS ports of board and card games over the years, and now most of them... | Read more »
Zynga Launches Brand New Farmville Exper...
Zynga Launches Brand New Farmville Experience with Farmville 2: Country Escape Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
David. Review
David. Review By Cata Modorcea on April 18th, 2014 Our Rating: :: MINIMALISTIC IN A DIFFERENT WAYUniversal App - Designed for iPhone and iPad David is a minimalistic game wrapped inside of a soothing atmosphere in which the hero... | Read more »
Eyefi Unveils New Eyefi Cloud Service Th...
Eyefi Unveils New Eyefi Cloud Service That Allows Users to Share Media Across Personal Devices Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
Tales from the Dragon Mountain: The Lair...
Tales from the Dragon Mountain: The Lair Review By Jennifer Allen on April 18th, 2014 Our Rating: :: STEADY ADVENTURINGiPad Only App - Designed for the iPad Treading a safe path, Tales from the Dragon Mountain: The Lair is a... | Read more »
Yahoo Updates Flickr App with Advanced E...
Yahoo Updates Flickr App with Advanced Editing Features and More Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
My Incredible Body - A Kid's App to...
My Incredible Body - A Kid's App to Learn about the Human Body 1.1.00 Device: iOS Universal Category: Education Price: $2.99, Version: 1.1.00 (iTunes) Description: Wouldn’t it be cool to look inside yourself and see what was going on... | Read more »
Trials Frontier Review
Trials Frontier Review By Carter Dotson on April 18th, 2014 Our Rating: :: A ROUGH LANDINGUniversal App - Designed for iPhone and iPad Trials Frontier finally brings the famed stunt racing franchise to mobile, but how much does its... | Read more »
Evernote Business Notebook by Moleskin I...
Evernote Business Notebook by Moleskin Introduced – Support Available in Evernote for iOS Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »

Price Scanner via MacPrices.net

Free HopTo 2.2 Helps Enhance Your Productivit...
The HopTo app helps you do more on your iPad by providing more and easier adaccess to files and documents. Version 2.2 adds Egnyte and HopTo’s Mac OSX File Connector. If you already have the hopTo... Read more
National Distracted Driving Awareness Month:...
As the country recognizes National Distracted Driving Awareness Month, Sprint is reminding wireless consumers to focus on driving while behind the wheel, to not text or email while driving, and to... Read more
13-inch 2.4GHz Retina MacBook Pro available f...
Abt has the 13″ 2.4GHz 128GB Retina MacBook Pro available for $1229 including free shipping. Their price is $70 off MSRP. Read more
iMacs on sale for up to $160 off MSRP this we...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
iPad Airs on sale this weekend for up to $100...
Best Buy has WiFi iPad Airs on sale for $50 off MSRP and WiFi + Cellular iPad Airs on sale for $100 off MSRP on their online store for a limited time, with prices now starting at $449. Choose free... Read more
Apple restocks refurbished Mac minis starting...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more
Hyundai Brings Apple CarPlay To The 2015 Sona...
Hyundai Motor America has announced it will bring Apple CarPlay functionality to the 2015 Sonata. CarPlay is pitched as a smarter, safer and easier way to use iPhone in the car and gives iPhone users... Read more
Updated iPads Coming Sooner Than We Had Thoug...
MacRumors, cites KGI securities analyst Ming Chi Kuo, well-respected as an Apple product prognisticator, saying that Apple will introduce an upgraded iPad Air and iPad mini in 2014/Q3, meaning the... Read more
Toshiba Unveils New High And Low End Laptop M...
Toshiba has announced new laptop models covering both the high-end and low-end of the notebook computer spectrum. Toshiba 4K Ultra HD Laptop Toshiba’s new Satellite P55t features one of the world’s... Read more
Save up to $270 with Apple refurbished 13-inc...
The Apple Store has Apple Certified Refurbished October 2013 13″ Retina MacBook Pros available starting at $1099, with models up to $270 off MSRP. Apple’s one-year warranty is standard, and shipping... Read more

Jobs Board

*Apple* Automotive Parts Department position...
Apple Automotive is one of the fastest growing dealer…and it shows. Consider making the switch to the Apple Automotive Group today! At Apple Automotive, we 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
*Apple* Retail - Manager - Holyoke - Apple I...
Job Summary Keeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you’re a master of them all. In the store’s fast-paced, Read more
*Apple* Retail - Manager - Apple (United Sta...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you're a master of them all. In the store's fast-paced, dynamic 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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.