Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
GetDragHilite.c
/* |
File: GetDragHilite.c |
Contains: This shows how to obtain the color that the Drag Manager uses to |
hilite regions when ShowDragHilite is called. Check out GetDragHilite.c |
for the code. |
Please note this is only how it's done presently. Since it is undocumented |
it can and will change in the future. |
Written by: Nitin Ganatra |
Copyright: Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/6/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#include <Windows.h> |
#include <QuickDraw.h> |
#define wTitleBarColor 4 |
#define wTingeLight 11 |
#define wTingeDark 12 |
unsigned short BlendValues(short lightValue, short darkValue); |
void SetupDragHiliteColor(WindowPtr targetWindow); |
/*------------------------------------------------------------------------------------- |
BlendValues |
Blend two color values by 27%. Be careful of overflow when multiplying |
a negative number. Output should be light + 27% of difference between light |
and dark. |
*/ |
unsigned short BlendValues(short lightValue, short darkValue) |
{ |
register short blender; |
blender = darkValue - lightValue; |
if ((unsigned long)lightValue > (unsigned long)darkValue) |
blender = -blender; // flip if subtraction would overflow |
blender = (unsigned short)((unsigned short)blender * .27); |
// 27% percent multiply |
if ((unsigned long)lightValue > (unsigned long)darkValue) |
blender = -blender; // flip it back if it was flipped the |
// first time. |
return ((unsigned short)(lightValue + blender)); |
} |
/*------------------------------------------------------------------------------------- |
SetupDragHiliteColor |
Set the fore color to the color used by the Drag Manager to hilite regions. |
*/ |
void SetupDragHiliteColor(WindowPtr targetWindow) |
{ |
RGBColor windowRGB, lightRGB, darkRGB; |
AuxWinHandle auxHandle; // the default AuxWindow data |
CTabHandle winColorTable; // the window color table |
short i, j; // for our color table search |
windowRGB.red = 0x8000; // Default to 50% gray. |
windowRGB.green = 0x8000; |
windowRGB.blue = 0x8000; |
// If we're using a window which uses System 7's 3D colors |
// then set the hilite color to a tinge for that window. |
GetAuxWin(targetWindow, &auxHandle); |
// do we have an aux window handle ? |
if (auxHandle != nil) { |
winColorTable = (**auxHandle).awCTable; |
// do we have a system 7 sized window color table? |
if ((**winColorTable).ctSize > wTitleBarColor) { |
// yes, now search for the tinge color, start at the end |
// because our tinge colors are usually last in the list. |
for (i = (**winColorTable).ctSize; i > 0; i--) { |
if ((**winColorTable).ctTable[i].value == wTingeLight) { |
// light tinge found, set the window color to it |
// in case we can't find the dark tinge. |
lightRGB = (**winColorTable).ctTable[i].rgb; |
windowRGB.red = lightRGB.red; |
windowRGB.green = lightRGB.green; |
windowRGB.blue = lightRGB.blue; |
// we now need the wTingeDark entry to perform a blend. |
// again, search from the end |
for (j = (**winColorTable).ctSize; j > 0; j--) |
if ((**winColorTable).ctTable[j].value == wTingeDark) { |
// dark tinge found. now do the blend |
darkRGB = (**winColorTable).ctTable[j].rgb; |
windowRGB.red = BlendValues((short)lightRGB.red, (short)darkRGB.red); |
windowRGB.green = BlendValues((short)lightRGB.green, (short)darkRGB.green); |
windowRGB.blue = BlendValues((short)lightRGB.blue, (short)darkRGB.blue); |
// if the Color control panel was set to "Black and White", it makes the |
// tinge colors black and black. Use gray in this case |
if ((windowRGB.red | windowRGB.green | windowRGB.blue) == 0) { |
windowRGB.red = 0x8000; |
windowRGB.green = 0x8000; |
windowRGB.blue = 0x8000; |
} |
j = 0; // bail from inner loop |
} |
i = 0; // bail from outer loop |
} |
} |
} |
} |
RGBForeColor(&windowRGB); // finally, set it |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-30