ColourPicker Class Reference

Encapsulates OS-specific colour picker dialogue system, giving a kernel interface for using whatever colour picker(s) are available. More...

#include <colpick.h>

Inheritance diagram for ColourPicker:

CCObject SimpleCCObject List of all members.

Public Member Functions

 ColourPicker ()
 Creates a colourpicker object Scope: private.
 ~ColourPicker ()
 Destructor for a Colour Picker Scope: private.
void EditColour (ColourList *ParentList, IndexedColour *SourceAndResult, BOOL PreferLineColour=FALSE)
 Converts a ColourValue (0.0 to 1.0) into a byte (0..255) with clipping to handle out-of-gamut values.The main colour picker function. Given an IndexedColour, sets up a colour picker showing that colour, allows the user to edit it, and returns the new colour in said IndexedColour. If the colour is changed, an appropriate ColourChangingMsg will be broadcast.

Static Public Member Functions

static BOOL GetStatusLineText (String_256 *Result)
static void UpdateBubbleHelpAndPointer (void)
 Called on Idle (or MouseMove) events to provide bubble help and update the mouse pointer while it is over the colour editor dialogue.
static void SetBubbleHelp (CGadgetID *GadgetList)
 Set all the bubble help up for the colour picker.

Static Protected Member Functions

static BOOL GetStatusLineText (ColourEditDlg *Editor, UINT32 GadgetID, String_256 *Result)
 Bodge to get around the fact that DialogOps don't plug into the status line help system. Returns help for the colour editor. Must go via the winoil, as we have to read the mouse position and find the window it's in.
static TCHARHelpCallbackHandler (CWindowID Window, UINT32 Item, void *UserData)
 Help callback handler to provide bubble help for the colour editor.
static BOOL GetComponentHelp (ColourContext *const pSourceContext, const UINT32 ComponentIndex, StringBase &HelpString)
 Subprocedure for HelpCallbackHandler providing help for each of the colour components.
static BOOL GetComponentAsString (IndexedColour *Source, ColourContext *DestContext, INT32 ComponentIndex, String_8 *Result)
 Retrieves the colour definition of the given colour, converts it to the given colour model, and returns the desired component of the definition in that model as a decimal string appropriate for placing into a colour editor dialogue gadget.
static BOOL GetComponentsAsHexString (IndexedColour *Source, ColourContext *DestContext, INT32 ComponentIndex, String_16 *Result)
 Retrieves the colour definition of the given colour, converts it to the given colour model, and returns the combined value of all components of the definition in that model as a hexadecimal string appropriate for placing into a colour editor dialogue gadget.
static BOOL SetComponentFromString (IndexedColour *Dest, ColourContext *SourceContext, INT32 ComponentIndex, String_8 *NewValue)
 Converts AND COERCES the colour into the destination context. Assumes that the string will be 0..100 (or 0..360 for HSV) Clips the string value into a 0.0 to 1.0 in-gamut range, and then sets the given component of the converted colour to that value. This thus changes the colour model in which the colour is defined as well as the component value.
static BOOL SetComponentsFromHexString (IndexedColour *Dest, ColourContext *SourceContext, String_16 *NewValue)
 Converts AND COERCES the colour into the destination context. Assumes that the string will in hex format (i.e rrggbb or 0xrrggbb) Clips the string value into 0.0 to 1.0 in-gamut ranges, and then sets the components of the converted colour to those values. This thus changes the colour model in which the colour is defined as well as the component value.
static BOOL IsValidHexString (String_16 Hex)
 Internal helper function for ColourPicker::SetComponentsFromHexString () UNLESS YOU KNOW WHAT YOUR DOING - DON'T CALL THIS AS IT ONLY EXISTS TO HELP THE FORE-MENTIONED FUNCTION - AND I CANNOT SEE WHY YOUR CALLING THIS FROM ELSEWHERE ANYWAY !!!!
static BOOL SetComponentFromDouble (IndexedColour *Dest, ColourContext *SourceContext, INT32 ComponentIndex, double NewValue)
 Converts AND COERCES the colour into the destination context. Clips the new value into a 0.0 to 1.0 in-gamut range, and then sets the given component of the converted colour to that value.
static void ForceColourModel (IndexedColour *Dest, ColourContext *SourceContext)
 COERCES the colour into the destination context. This ensures that the colour is defined in the given context's colour model, converting its definition if necessary.
static BOOL GetTintAsString (IndexedColour *Source, StringBase *Result)
 Retrieves the tint of the given colour as a decimal string appropriate for placing into a colour editor dialogue gadget.
static BOOL SetTintFromString (IndexedColour *Dest, StringBase *NewValue)
 Assumes that the string will be 0..100 Clips the string value into a 0.0 to 1.0 in-gamut range, and then sets the tint component of the converted colour to that value.
static BOOL GetShadeValueAsString (IndexedColour *Source, INT32 ValueIndex, StringBase *Result)
 Retrieves the shade of the given colour as a decimal string appropriate for placing into a colour editor dialogue gadget.
static BOOL SetShadeFromStrings (IndexedColour *Dest, StringBase *NewValueX, StringBase *NewValueY)
 Assumes that the string will be -100..100 Clips the string value into a -1.0 to 1.0 in-gamut range, and then sets the shade components of the converted colour to those values.
static void SetWindowExtent (CWindowID WindowID, CGadgetID XGadgetID, CGadgetID YGadgetID)
 Private function used by the kernel ColourEditDlg editor. Given a WindowID and GadgetID (cf DialogOp->DialogMgr interface), this sets the window extent of the window to a short distance outside the right/ bottom edges of the X/Y named gadgets respectively.
static void SetGadgetPositions (CWindowID WindowID, CGadgetID *Gadgets, CGadgetID MoveUnder)
 Private function used by the kernel ColourEditDlg editor. Given a WindowID and GadgetIDs (cf DialogOp->DialogMgr interface), this moves all the gadgets such that (a) All the gadgets in the group remain in the same relative positions, and (b) the Gadgets[0] gadget is moved to lie just underneath the MoveUnder gadget.
static void SetComponentGadgets (CWindowID WindowID, CGadgetID *Gadgets, CGadgetID PickerGadget, ColourModel ModelToDisplay)
 Private function used by the kernel ColourEditDlg editor.
static void SetFixedComponentGadgets (CWindowID WindowID, CGadgetID *Gadgets, CGadgetID PickerGadget, ColourModel ModelToDisplay, INT32 TextWidth[], INT32 EditWidth[])
 Private function used by the kernel ColourEditDlg editor.
static void RelayoutDialog (CWindowID WindowID)
 Ensure the dialog is a sensible size Scope: Protected.
static void OnSize (CWindowID WindowID)
 Respond to size events Scope: Protected.
static void RecursiveBestSize (wxWindow *pwxWindow)
 Initialize platform dependent resources.
static BOOL OnIdleEvent (CWindowID WindowID)
 Respond idle events Scope: Protected.
static void OnCreate (CWindowID WindowID)
 Respond to size events Scope: Protected.
static void ArtificialSizeEvents (CWindowID WindowID)
 Produce artificial size events recursively Scope: Protected.

Static Private Attributes

static wxSize s_LastSize = wxDefaultSize
static wxSize s_UserSize = wxSize(245,245)
static wxSize s_MinSize = wxSize(180,100)
static BOOL s_InColourDialogLayout = FALSE
static BOOL s_JustCreated = FALSE
static INT32 s_IdleCounter = 0

Friends

class ColourEditDlg
class ColourLinkDlg
class NewColourDlg

Detailed Description

Encapsulates OS-specific colour picker dialogue system, giving a kernel interface for using whatever colour picker(s) are available.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/95
Given a (named or unnamed) IndexedColour, a Colour Picker somehow provides a user interface to change it, and returns the colour, cleaner and brighter than you ever thought possible, and for only about the same price as you'd expect to pay for an inferior colour picker. 1 out of 10 home economists prefer our colour picker to all others.

This class also provides secrel-squirrel interfaces for doing rather horrendous direct-pokey Coloue Editor things to IndexedColours. These are only available to our friend editor dialogue classes.

Friends: ColourEditDlg; ColourLinkDlg

See also:
IndexedColour; ColourEditDlg; ColourLinkDlg

Definition at line 138 of file colpick.h.


Constructor & Destructor Documentation

ColourPicker::ColourPicker  ) 
 

Creates a colourpicker object Scope: private.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 166 of file colpick.cpp.

00167 {
00168 }

ColourPicker::~ColourPicker  ) 
 

Destructor for a Colour Picker Scope: private.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 188 of file colpick.cpp.

00189 {
00190 }


Member Function Documentation

void ColourPicker::ArtificialSizeEvents CWindowID  WindowID  )  [static, protected]
 

Produce artificial size events recursively Scope: Protected.

Author:
Alex Bligh
Date:
30/5/2005
Parameters:
- [INPUTS]
On GTK at least, sizing does not occur synchronously. Some of it happens on size events from a gtk_window_size_callback. For various reasons (like the necessity for a wxyield) this is not great). So we produce them ourselves.

Definition at line 3006 of file colpick.cpp.

03007 {
03008     if (!WindowID->IsShown())
03009         return;
03010 
03011     // size children first
03012     wxWindowList::Node * pNode = WindowID->GetChildren().GetFirst();
03013     while (pNode)
03014     {
03015         ArtificialSizeEvents(pNode->GetData());
03016         pNode = pNode->GetNext();
03017     }
03018 
03019     wxSizeEvent event( WindowID->GetSize(), WindowID->GetId() );
03020     event.SetEventObject( WindowID );
03021     WindowID->GetEventHandler()->ProcessEvent( event );
03022 }

void ColourPicker::EditColour ColourList ParentList,
IndexedColour SourceAndResult,
BOOL  PreferLineColour = FALSE
 

Converts a ColourValue (0.0 to 1.0) into a byte (0..255) with clipping to handle out-of-gamut values.The main colour picker function. Given an IndexedColour, sets up a colour picker showing that colour, allows the user to edit it, and returns the new colour in said IndexedColour. If the colour is changed, an appropriate ColourChangingMsg will be broadcast.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/94
Parameters:
ParentList - The list in which the colour resides [INPUTS] May be NULL if you want to just show the picker for whatever local colour is appropriate. SourceAndResult must also be NULL in this case
SourceAndResult - The colour to be edited. If the user changes the colour, this will be set to the new definition. May be NULL if you want to just show the picker for whatever local colour is appropriate. ParentList must also be NULL in this case

PreferLineColour - TRUE if you'd like to edit line colours rather than fill colours in local mode, FALSE to edit fill colours. This flag is ignored unless ParentList == SourceAndResult == NULL. (Implementation note: This calls ColourEditDlg::ForceLineOrFillMode)

Parameters:
- [OUTPUTS]
Returns:
-
Notes: The IndexedColour is actually copied into another for editing. The change, if OK'd is then applied using the ColourManager::ChangeColour function, which provides an undo record of the event.

Scope: private

Returns:
Errors: -
See also:
ColourEditDlg::InvokeDialog

Definition at line 275 of file colpick.cpp.

00277 {
00278 #if FALSE
00279 /*
00280 // **** DEBUG - use Windows Picker if SHIFT NOT held down on entry,
00281 //              else use the Camelot Picker
00282     if (ForceNativePicker)
00283         UseOSPicker = TRUE;
00284     else
00285         UseOSPicker = (::GetAsyncKeyState(CAMKEY(SHIFT)) & 0x8000) ? TRUE : FALSE;
00286 // ****
00287     if (UseOSPicker)
00288     {
00289         IndexedColour *UndoBuffer = new IndexedColour(*SourceAndResult);
00290         if (UndoBuffer == NULL)     // Fail gracefully. Well... Don't crash, anyway
00291             return;
00292 
00293         ColourGeneric *TheColour = UndoBuffer->SourceColourPtr();
00294 
00295         Document *ScopeDoc = Document::GetSelected();
00296         if (ScopeDoc == NULL)
00297             return;
00298 
00299         ColourContext *ccRGB = ScopeDoc->GetDefaultColourContexts()->Context[COLOURMODEL_RGBT];
00300         ENSURE(ccRGB != NULL, "Default RGBT context can't be found!");
00301 
00302         ColourContext *ccSource = ScopeDoc->GetDefaultColourContexts()->Context[UndoBuffer->GetColourModel()];
00303         if (ccSource == NULL)
00304         {
00305             ENSURE(FALSE, "Unsupported source colour context - I can't edit that colour");
00306             return;
00307         }
00308 
00309         // Convert the given colour into RGB, using 'pure' contexts (logical rather than physica
00310         // conversion, i.e. no colour correction en-route)
00311         ColourRGBT TheColourRGB;
00312         ccRGB->ConvertColour(ccSource, TheColour, (ColourGeneric *) &TheColourRGB);
00313 
00314 
00315         // Now set up, and call the Windows colour picker to edit the colour...
00316         CHOOSECOLOR cc;
00317 
00318         // Set initial colour for the colour picker to use
00319         cc.rgbResult = RGB( ColourValueToByte(TheColourRGB.Red),
00320                             ColourValueToByte(TheColourRGB.Green),
00321                             ColourValueToByte(TheColourRGB.Blue) );
00322 
00323 
00324         // Set the default set of available colours (a greyscale for the time being)
00325         // (it is static so that if the user changes any of the colours they will get
00326         // the changed palette back next time around)
00327         static COLORREF acrCustClr[16] =
00328             {
00329                 RGB(255, 255, 255), RGB(239, 239, 239),
00330                 RGB(223, 223, 223), RGB(207, 207, 207),
00331                 RGB(191, 191, 191), RGB(175, 175, 175),
00332                 RGB(159, 159, 159), RGB(143, 143, 143),
00333                 RGB(127, 127, 127), RGB(111, 111, 111),
00334                 RGB(95, 95, 95),    RGB(79, 79, 79),
00335                 RGB(63, 63, 63),    RGB(47, 47, 47),
00336                 RGB(31, 31, 31),    RGB(15, 15, 15)
00337             };
00338 
00339         cc.lStructSize = sizeof(CHOOSECOLOR);
00340         cc.hwndOwner = AfxGetApp()->m_pMainWnd->m_hWnd; // 'owner' window
00341         cc.lpCustColors = (LPDWORD) acrCustClr;         // List of default colours
00342         cc.Flags = CC_RGBINIT | CC_FULLOPEN;            // Use cc.rgbResult to init picker...
00343                                                         // and picker appears fully opened - Geez that
00344                                                         // 'define wossnames' button is a pain in the butt!!!
00345 
00346         if (ChooseColor(&cc))       // Invoke Windows colour picker (if it qualifies as a colour picker!)
00347         {
00348             // User chose a colour and hit OK - read out the return value (always RGB)
00349             UndoBuffer->SetSourceColourModel(COLOURMODEL_RGBT);
00350             ((ColourRGBT *)TheColour)->Red   = ((double) GetRValue(cc.rgbResult)) / 256.0;
00351             ((ColourRGBT *)TheColour)->Green = ((double) GetGValue(cc.rgbResult)) / 256.0;
00352             ((ColourRGBT *)TheColour)->Blue  = ((double) GetBValue(cc.rgbResult)) / 256.0;
00353             ((ColourRGBT *)TheColour)->Transparent = 0;
00354 
00355             Document::GetSelected()->SetCurrent();      // Make this document the current one
00356 
00357             // This swallows UndoBuffer into the undo system - we must NOT delete it
00358             ColourManager::ChangeColour(ParentList, UndoBuffer, SourceAndResult);
00359         }
00360         else
00361             delete UndoBuffer;  // UndoBuffer not used - delete it
00362     }
00363     else
00364 */
00365 #endif
00366     {
00367 #ifndef STANDALONE
00368         // If we are asking to edit an appropriate local colour, state our preference
00369         // for either fill or line colour.
00370         if (SourceAndResult == NULL)
00371             ColourEditDlg::ForceLineOrFillMode(PreferLineColour);
00372 
00373         ColourEditDlg::InvokeDialog(ParentList, SourceAndResult);
00374 #endif
00375     }
00376 }

void ColourPicker::ForceColourModel IndexedColour Dest,
ColourContext SourceContext
[static, protected]
 

COERCES the colour into the destination context. This ensures that the colour is defined in the given context's colour model, converting its definition if necessary.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/94
Parameters:
Dest - the colour to be set [INPUTS] SourceContext - the context in which the new colour value should be defined
Dest is updated appropriately [OUTPUTS]
Returns:
-
Notes: This method always flushes the colour's output cache.

Scope: private

Definition at line 1926 of file colpick.cpp.

01927 {
01928     ERROR3IF(Dest == NULL || SourceContext == NULL,
01929                 "ColourPicker::ForceColourModel - NULL Parameters are illegal");
01930 
01931     // Invalidate the colour's output cache (even if it hasn't really changed - in this
01932     // case we're only causing one weeny little colour conversion, so it's no big deal)
01933     // This is also needed because the above functions expect this call to flush the cache.
01934     Dest->InvalidateCache();
01935 
01936     if (Dest->GetColourModel() != SourceContext->GetColourModel())
01937     {
01938         ColourContext *OldContext = ColourContext::GetGlobalDefault(Dest->GetColourModel());
01939         if (OldContext == NULL)
01940         {
01941             ERROR2RAW("Unable to get colour context for ForceColourModel");
01942             return;
01943         }
01944 
01945         // The colour must be coerced into the new model using secret squirrel private
01946         // methods which we can access only because we are a friend of IndexedColour
01947         ColourGeneric NewDefn;
01948 
01949         Dest->GetSourceColour(&NewDefn);    // Copy into temp space & convert back into the colour
01950         SourceContext->ConvertColour(OldContext, &NewDefn, Dest->SourceColourPtr());
01951 
01952         Dest->SetSourceColourModel(SourceContext->GetColourModel());
01953 
01954         // and once again, flush the cache to make sure the change in model has been noticed
01955         Dest->InvalidateCache();
01956     }
01957 }

BOOL ColourPicker::GetComponentAsString IndexedColour Source,
ColourContext DestContext,
INT32  ComponentIndex,
String_8 Result
[static, protected]
 

Retrieves the colour definition of the given colour, converts it to the given colour model, and returns the desired component of the definition in that model as a decimal string appropriate for placing into a colour editor dialogue gadget.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/94
Parameters:
Source - The colour from which you wish to extract the component [INPUTS] DestContext - The colour context in which you want the resulting component ComponentIndex - The component you wish to extract (1..4)
Result - returns containing a decimal (0.0 .. 100.0) string representing [OUTPUTS] the value of the given component of the colour as it is defined in the given colour model (Note: HSV Hue is done as 0..360).
Returns:
TRUE if the value converted was out of gamut.
Notes: At present, this function clips the value to lie within the legal 0.0 to 1.0 gamut range.

Scope: private

See also:
ColourPicker::SetComponentFromDouble; ColourPicker::SetComponentFromString

Definition at line 1238 of file colpick.cpp.

01241 {
01242     ERROR2IF(Source == NULL || DestContext == NULL || Result == NULL, FALSE,
01243                 "NULL parameters are illegal");
01244 
01245     ERROR2IF(ComponentIndex < 1 || (UINT32)ComponentIndex > DestContext->GetComponentCount(), FALSE,
01246                 "ComponentIndex not in range");
01247 
01248     BOOL OutOfGamut = FALSE;
01249     ColourGeneric Defn;
01250 
01251     DestContext->ConvertColour(Source, &Defn);
01252     
01253     // Sneakily get the component from the ColourGeneric by treating it as an array
01254     // of 4 ColourValue components.
01255     ColourValue *CompPtr = (ColourValue *) &Defn;       
01256     double CompValue = CompPtr[ComponentIndex-1].MakeDouble();
01257 
01258     if (CompValue < 0.0)
01259     {
01260         CompValue = 0.0;        // **** Clip out-of-gamut values.
01261         OutOfGamut = TRUE;      // Remember that this was out of gamut
01262     }
01263 
01264     if (CompValue > 1.0)
01265     {
01266         CompValue = 1.0;        // **** Clip out-of-gamut values.
01267         OutOfGamut = TRUE;      // Remember that this was out of gamut
01268     }
01269 
01270     // Generate a 0..100 value, except for Hue, in which case it's 0..360
01271     UnitGroup* pPossibleUnits = DestContext->GetComponentUnitGroup(ComponentIndex);
01272     if (pPossibleUnits == NULL)
01273     {
01274         ERROR3("ColourPicker::GetComponentAsString - pPossibleUnits NULL");
01275         return FALSE;
01276     }
01277     ERROR3IF(!pPossibleUnits->IS_KIND_OF(UnitGroup), "pPossibleUnits aren't");
01278     ScaleUnit* pUnit = pPossibleUnits->GetDefaultUnit();
01279     if (pUnit == NULL)
01280     {
01281         ERROR3("ColourPicker::GetComponentAsString - Default units NULL");
01282         return FALSE;
01283     }
01284     ERROR3IF(!pUnit->IS_KIND_OF(ScaleUnit), "pUnits isn't");
01285     pUnit->StringFromScale(CompValue, Result, 6);
01286 
01287     // Convert to a 1 d.p. string using the global conversion function
01288 /*  String_32 TempString;
01289     Convert::DoubleToString(CompValue, (StringBase *) &TempString, pUnit->GetDPtoShow());
01290     TempString.Left(Result, 6);
01291 
01292     const Qualifier* pQualifier = pUnit->GetQualifier();
01293     if (pQualifier == NULL || !pQualifier->IS_KIND_OF(Qualifier))
01294     {
01295         ERROR3("ColourPicker::GetComponentAsString - not a Qualifier!");
01296         return FALSE;
01297     }
01298     if (pQualifier->IsShown())
01299         *Result += pQualifier->GetToken();
01300 */
01301     return(OutOfGamut);
01302 }

BOOL ColourPicker::GetComponentHelp ColourContext *const   pSourceContext,
const UINT32  ComponentIndex,
StringBase HelpString
[static, protected]
 

Subprocedure for HelpCallbackHandler providing help for each of the colour components.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/05/96
Parameters:
pSourceContext - the ColourContext in which the component is [INPUTS] ComponentIndex - the index of the component in the colour context (1..GetComponentCount())
HelpString - a string to be displayed as help for the given component [OUTPUTS]
Returns:
TRUE : If help string constructed correctly FALSE : otherwise

Errors: ERROR2IF's if invalid paramters given ERROR3IF's for corrupt data structures

See also:
ColourPicker::HelpCallbackHandler

Definition at line 979 of file colpick.cpp.

00980 {
00981     ERROR2IF(pSourceContext == NULL, FALSE, "NULL parameters not allowed");
00982     ERROR3IF(!pSourceContext->IS_KIND_OF(ColourContext), "ColourPicker::GetComponentHelp() - pSourceContext isn't");
00983     ERROR2IF((ComponentIndex < 1) || (ComponentIndex > pSourceContext->GetComponentCount()), FALSE,
00984                 "Component index out of bounds");
00985 
00986     // Create a string of the form "Red (0..100%)" using the colour component's name and the limits defined for
00987     // the component's unit
00988     UnitGroup* pUnitGroup = pSourceContext->GetComponentUnitGroup(ComponentIndex);
00989     if (pUnitGroup == NULL)
00990     {
00991         ERROR3("ColourPicker::GetComponentHelp - Model has no units");
00992         return FALSE;
00993     }
00994     ERROR3IF(!pUnitGroup->IS_KIND_OF(UnitGroup), "ColourPicker::GetComponentHelp() - pUnitGroup isn't");
00995     ScaleUnit* pUnit = pUnitGroup->GetDefaultUnit();
00996     if (pUnit == NULL)
00997     {
00998         ERROR3("ColourPicker::GetComponentHelp - No default units");
00999         return FALSE;
01000     }
01001     ERROR3IF(!pUnit->IS_KIND_OF(ScaleUnit), "ColourPicker::GetComponentHelp() - pUnit isn't");
01002 
01003     String_64 CompName;
01004     pSourceContext->GetComponentName(ComponentIndex, &CompName, TRUE);
01005 
01006     String_32 LowerLimit;
01007     Convert::DoubleToString(pUnit->GetMin(), (StringBase*)&LowerLimit, pUnit->GetDPtoShow());
01008 
01009     String_32 UpperLimit;
01010     Convert::DoubleToString(pUnit->GetMax(), (StringBase*)&UpperLimit, pUnit->GetDPtoShow());
01011 
01012     String_32 QualifierToken;
01013     const Qualifier* pQualifier = pUnit->GetQualifier();
01014     if (pQualifier == NULL)
01015     {
01016         ERROR3("ColourPicker::GetComponentHelp - No qualifier");
01017         return FALSE;
01018     }
01019     ERROR3IF(!pQualifier->IS_KIND_OF(Qualifier), "ColourPicker::GetComponentHelp - Qualifier isn't");
01020 
01021     if (pQualifier->IsShown())
01022     {
01023         QualifierToken = pQualifier->GetToken();
01024     }
01025 
01026     HelpString.MakeMsg(_R(IDS_EDITBH_COMP234), (TCHAR *)CompName, (TCHAR *)LowerLimit, (TCHAR *)UpperLimit, 
01027                         (TCHAR *)QualifierToken);
01028 
01029     return TRUE;
01030 }

BOOL ColourPicker::GetComponentsAsHexString IndexedColour Source,
ColourContext DestContext,
INT32  ComponentIndex,
String_16 Result
[static, protected]
 

Retrieves the colour definition of the given colour, converts it to the given colour model, and returns the combined value of all components of the definition in that model as a hexadecimal string appropriate for placing into a colour editor dialogue gadget.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/99
Parameters:
Source - The colour from which you wish to extract the component [INPUTS] DestContext - The colour context in which you want the resulting component ComponentIndex - This should be set to -1 at present (cause we are getting all components; and not one in the range 1-4)
Result - returns containing a hexadecimal string representation (rrggbb) [OUTPUTS]
Returns:
TRUE if the value converted was out of gamut.
Notes: At present, this function clips the value to lie within the legal 0.0 to 1.0 gamut range.

Scope: private

See also:
ColourPicker::GetComponentsAsString; ColourPicker::SetComponentsFromHexString

Definition at line 1338 of file colpick.cpp.

01341 {
01342     ERROR2IF(Source == NULL || DestContext == NULL || Result == NULL, FALSE,
01343                 "NULL parameters are illegal");
01344 //  ERROR2IF(!DestContext->IS_KIND_OF(ColourContextWebRGBT), FALSE,
01345 //              "SourceContext parameter is not of type ColourContextWebRGBT");
01346 
01347     if (ComponentIndex == -1)
01348     {
01349         BOOL OutOfGamut = FALSE;
01350         ColourGeneric Defn;
01351 
01352         DestContext->ConvertColour(Source, &Defn);
01353 
01354         // Sneakily get the component from the ColourGeneric by treating it as an array
01355         // of 4 ColourValue components ....
01356 
01357         ColourValue *CompPtr = (ColourValue *) &Defn;       
01358         
01359         String_8 ResultR, ResultG, ResultB;
01360 
01361         for (INT32 i = 1; i < 4; i++)
01362         {
01363             double CompValue = CompPtr[i-1].MakeDouble();
01364 
01365             if (CompValue < 0.0)
01366             {
01367                 CompValue = 0.0;        // **** Clip out-of-gamut values.
01368                 OutOfGamut = TRUE;      // Remember that this was out of gamut
01369             }
01370 
01371             if (CompValue > 1.0)
01372             {
01373                 CompValue = 1.0;        // **** Clip out-of-gamut values.
01374                 OutOfGamut = TRUE;      // Remember that this was out of gamut
01375             }
01376 
01377             // Generate a 0..100 value, except for Hue, in which case it's 0..360
01378             UnitGroup* pPossibleUnits = DestContext->GetComponentUnitGroup(i);
01379             if (pPossibleUnits == NULL)
01380             {
01381                 ERROR3("ColourPicker::GetComponentAsString - pPossibleUnits NULL");
01382                 return FALSE;
01383             }
01384             ERROR3IF(!pPossibleUnits->IS_KIND_OF(UnitGroup), "pPossibleUnits aren't");
01385             ScaleUnit* pUnit = pPossibleUnits->FindUnitFromIndex (1);//GetDefaultUnit();
01386             if (pUnit == NULL)
01387             {
01388                 ERROR3("ColourPicker::GetComponentAsString - Default units NULL");
01389                 return FALSE;
01390             }
01391             ERROR3IF(!pUnit->IS_KIND_OF(ScaleUnit), "pUnits isn't");
01392             
01393             switch (i)
01394             {
01395                 case 1:
01396                     pUnit->StringFromScale(CompValue, &ResultR, 6);
01397                 break;
01398                 case 2:
01399                     pUnit->StringFromScale(CompValue, &ResultG, 6);
01400                 break;
01401                 case 3:
01402                     pUnit->StringFromScale(CompValue, &ResultB, 6);
01403                 break;
01404             }
01405         }
01406 
01407         // convert strings into integers ....
01408         
01409         INT32 rVal = camAtoi ((const TCHAR*) ResultR);
01410         INT32 gVal = camAtoi ((const TCHAR*) ResultG);
01411         INT32 bVal = camAtoi ((const TCHAR*) ResultB);
01412 
01413         // convert integers to base 16 ....
01414         
01415         camSprintf((TCHAR*)ResultR, _T("%X"), rVal);
01416         camSprintf((TCHAR*)ResultG, _T("%X"), gVal);
01417         camSprintf((TCHAR*)ResultB, _T("%X"), bVal);
01418 
01419         String_8 Builder;//FinalResultR, FinalResultG, FinalResultB;
01420 
01421         // I don't want an _itoa one length rr's, gg's or bb's thankyou very much!
01422         // AND glue the results together (== rrggbb) at the same time
01423 
01424         if (ResultR.Length () == 1)
01425         {
01426             Builder += (String_8 (TEXT ("0"))) += ResultR;
01427         }
01428         else
01429         {
01430             Builder += ResultR;
01431         }
01432 
01433         if (ResultG.Length () == 1)
01434         {
01435             Builder += (String_8 (TEXT ("0"))) += ResultG;
01436         }
01437         else
01438         {
01439             Builder += ResultG;
01440         }
01441 
01442         if (ResultB.Length () == 1)
01443         {
01444             Builder += (String_8 (TEXT ("0"))) += ResultB;
01445         }
01446         else
01447         {
01448             Builder += ResultB;
01449         }
01450 
01451         *Result = Builder;      // take that edit box - a correctly built hex string!
01452         
01453         //if ((ResultR.Length () == 1) || (ResultG.Length () == 1) || (ResultB.Length () == 1))
01454         //{
01455         //  *Result += /*(String_8 (TEXT ("0x"))) +=*/ FinalResultR += FinalResultG += FinalResultB;
01456         //}
01457         //else
01458         //{
01459         //  *Result += /*(String_8 (TEXT ("0x"))) +=*/ ResultR += ResultG += ResultB;
01460         //}
01461 
01462         return(OutOfGamut);
01463     }
01464 
01465     return (FALSE);     // stop that annoying warning about not all paths return a value!
01466 }

BOOL ColourPicker::GetShadeValueAsString IndexedColour Source,
INT32  ValueIndex,
StringBase Result
[static, protected]
 

Retrieves the shade of the given colour as a decimal string appropriate for placing into a colour editor dialogue gadget.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/10/95
Parameters:
Source - The colour from which you wish to extract the shade value [INPUTS] ValueIndex - 1 to extract the X component 2 to extract the Y component
Result - returns containing a decimal (-100.0 .. 100.0) string representing [OUTPUTS] the value of the given shade component of the colour
Returns:
TRUE if the value converted was out of gamut.
Notes: At present, this function clips the value to lie within the legal -1.0 to 1.0 gamut range.

If the colour is not a shade, will ENSURE and return "0%"

Scope: private

See also:
ColourPicker::SetShadeFromStrings

Definition at line 2144 of file colpick.cpp.

02145 {
02146     ERROR3IF(Source == NULL || Result == NULL,
02147                 "ColourPicker::GetShadeValueAsString - NULL parameters are illegal");
02148 
02149     ERROR3IF(ValueIndex != 1 && ValueIndex != 2, "ColourPicker::GetShadeValueAsString - Illegal ValueIndex parameter");
02150 
02151     if (Source->GetType() != COLOURTYPE_TINT)
02152     {
02153         ERROR3("ColourPicker::GetShadeValueAsString - Source colour isn't a tint");
02154         *Result = String_8(_R(IDS_CONVERT_ZERO_CHAR)); // TEXT("0");
02155         return(FALSE);
02156     }
02157 
02158     BOOL OutOfGamut = FALSE;
02159     
02160     double CompValue;
02161     if (ValueIndex == 1)
02162         CompValue = -Source->GetShadeValueX().MakeDouble();
02163     else
02164         CompValue = Source->GetShadeValueY().MakeDouble();
02165 
02166     if (CompValue < -1.0)
02167     {
02168         CompValue = -1.0;       // **** Clip out-of-gamut values.
02169         OutOfGamut = TRUE;      // Remember that this was out of gamut
02170     }
02171 
02172     if (CompValue > 1.0)
02173     {
02174         CompValue = 1.0;        // **** Clip out-of-gamut values.
02175         OutOfGamut = TRUE;      // Remember that this was out of gamut
02176     }
02177 
02178     CompValue *= 100.0;
02179 
02180     String_32 TempString;
02181     Convert::DoubleToString(CompValue, (StringBase *) &TempString, 1);
02182 
02183     TempString.Left(Result, 7);
02184 
02185     return(OutOfGamut);
02186 }

BOOL ColourPicker::GetStatusLineText ColourEditDlg Editor,
UINT32  GadgetID,
String_256 Result
[static, protected]
 

Bodge to get around the fact that DialogOps don't plug into the status line help system. Returns help for the colour editor. Must go via the winoil, as we have to read the mouse position and find the window it's in.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/5/95
Parameters:
Editor - points to the current editor [INPUTS] GadgetID - indicates the gadget for which you desire help
If return value is TRUE, Result is updated with an appropriate help string [OUTPUTS]
Returns:
TRUE if it changed Result, FALSE if it can offer no help
See also:
ColourEditDlg::GetStatusLineText

Definition at line 403 of file colpick.cpp.

00404 {
00405 #ifndef STANDALONE
00406 
00407     IndexedColour *Bob = Editor->EditingColour;
00408     if (Bob == NULL)
00409     {
00410         *Result = String_256(_R(IDS_EDITST_NOCOLOUR));
00411         return(TRUE);
00412     }
00413 
00414     ColourContext *cc = ColourContext::GetGlobalDefault(ColourEditDlg::DisplayModel);
00415 
00416     // Set the default help
00417     *Result = String_256(_R(IDS_EDITST_DEFAULT));
00418 
00419     if (FALSE) {}
00420 //  else if (GadgetID == _R(IDCANCEL))
00421 //  {
00422 //      *Result = String_256(_R(IDS_EDITST_CANCEL));
00423 //  }
00424     else if (GadgetID == _R(IDC_EDIT_DROPMENU))
00425     {
00426         *Result = String_256(_R(IDS_EDITST_MENU));
00427     }
00428     else if (GadgetID == _R(IDC_EDIT_COMPONENT1))
00429     {
00430         if (ColourEditDlg::DisplayModel == COLOURMODEL_HSVT)
00431         {
00432             *Result = String_256(_R(IDS_EDITST_COMP1));
00433         }
00434         else
00435         {
00436             if (cc != NULL)
00437             {
00438                 String_64 CompName;
00439                 cc->GetComponentName(1, &CompName, TRUE);
00440                 Result->MakeMsg(_R(IDS_EDITST_COMP234), (TCHAR *)CompName);
00441             }
00442         }
00443     }
00444     else if (GadgetID == _R(IDC_EDIT_COMPONENT2))
00445     {
00446         if (cc != NULL)
00447         {
00448             String_64 CompName;
00449             cc->GetComponentName(2, &CompName, TRUE);
00450             Result->MakeMsg(_R(IDS_EDITST_COMP234), (TCHAR *)CompName);
00451         }
00452     }
00453     else if (GadgetID == _R(IDC_EDIT_COMPONENT3))
00454     {
00455         if (cc != NULL)
00456         {
00457             String_64 CompName;
00458             cc->GetComponentName(3, &CompName, TRUE);
00459             Result->MakeMsg(_R(IDS_EDITST_COMP234), (TCHAR *)CompName);
00460         }
00461     }
00462 // WEBSTER - markn 14/12/96
00463 #ifndef WEBSTER
00464     else if (GadgetID == _R(IDC_EDIT_COMPONENT4))
00465     {
00466         if (cc != NULL)
00467         {
00468             String_64 CompName;
00469             cc->GetComponentName(4, &CompName, TRUE);
00470             Result->MakeMsg(_R(IDS_EDITST_COMP234), (TCHAR *)CompName);
00471         }
00472     }
00473     else if (GadgetID == _R(IDC_EDIT_COLMODEL))
00474     {
00475         *Result = String_256(_R(IDS_EDITST_COLMODEL));
00476     }
00477     else if (GadgetID == _R(IDC_EDIT_NAMEMENU))
00478     {
00479         *Result = String_256(_R(IDS_EDITST_NAME));
00480     }
00481     else if (GadgetID == _R(IDC_EDIT_COLTYPE))
00482     {
00483         *Result = String_256(_R(IDS_EDITST_COLTYPE));
00484     }
00485     else if ((GadgetID == _R(IDC_EDIT_INHERIT1)) ||
00486              (GadgetID == _R(IDC_EDIT_INHERIT2)) ||
00487              (GadgetID == _R(IDC_EDIT_INHERIT3)) ||
00488              (GadgetID == _R(IDC_EDIT_INHERIT4)))
00489     {
00490         *Result = String_256(_R(IDS_EDITST_INHERIT));
00491     }
00492 //  else if ((GadgetID == _R(IDC_EDIT_PATCH)) ||
00493 //           (GadgetID == _R(IDC_EDIT_PARENTPATCH)))
00494 //  {
00495 //      *Result = String_256(_R(IDS_EDITST_PARENTPATCH));
00496 //  }
00497     else if ((GadgetID == _R(IDC_EDIT_PARENTCOL)) ||
00498              (GadgetID == _R(IDC_EDIT_PARENTNAME)))
00499     {
00500         *Result = String_256(_R(IDS_EDITST_PARENTCOL));
00501     }
00502     else if ((GadgetID == _R(IDC_EDIT_TINT)) ||
00503              (GadgetID == _R(IDC_EDIT_TINTSLIDER)))
00504     {
00505         if (Bob->GetType() == COLOURTYPE_TINT && !Bob->TintIsShade())
00506             *Result = String_256(_R(IDS_EDITST_TINT1));     // It's a tint
00507         else
00508             *Result = String_256(_R(IDS_EDITST_TINT2));     // It's a shade
00509     }
00510     else if (GadgetID == _R(IDC_EDIT_SHADE))
00511     {
00512         *Result = String_256(_R(IDS_EDITST_TINT2));         // It's a shade
00513     }
00514     else if (GadgetID == _R(IDC_EDIT_ADVANCED))
00515     {
00516         if (Editor->Folded)
00517             *Result = String_256(_R(IDS_EDITST_ADVANCED1));
00518         else
00519             *Result = String_256(_R(IDS_EDITST_ADVANCED2));
00520     }
00521     else if (GadgetID == _R(IDC_EDIT_3D))
00522     {
00523         *Result = String_256(_R(IDS_EDITST_3D));
00524     }
00525     else if (GadgetID == _R(IDC_EDIT_MAKESTYLE))
00526     {
00527         *Result = String_256(_R(IDS_EDITST_MAKESTYLE));
00528     }
00529 #endif // WEBSTER
00530     else if (GadgetID == _R(IDC_EDIT_PICKER))
00531     {
00532         if (!StatusHelpBuffer.IsEmpty())
00533             *Result = StatusHelpBuffer;
00534         else
00535         {
00536             switch(Bob->GetType())
00537             {
00538             // WEBSTER - markn 14/12/96
00539             #ifndef WEBSTER
00540                 case COLOURTYPE_TINT:
00541                     if (Editor->Folded)
00542                         *Result = String_256(_R(IDS_EDITST_PICKER1));
00543                     else
00544                         *Result = String_256(_R(IDS_EDITST_PICKER2));
00545                     break;
00546 
00547                 case COLOURTYPE_LINKED:
00548                     *Result = String_256(_R(IDS_EDITST_PICKER3));
00549                     break;
00550             #endif // WEBSTER
00551 
00552                 case COLOURTYPE_NORMAL:
00553                 case COLOURTYPE_SPOT:
00554                 default:
00555                     *Result = String_256(_R(IDS_EDITST_PICKER4));
00556                     break;
00557             }
00558         }
00559     }   
00560     else if (GadgetID == _R(IDC_EDIT_216ONLY))
00561     {
00562         *Result = String_256(_R(IDS_EDITST_216ONLY));
00563     }   
00564     else if (GadgetID == _R(IDC_COLOURPICKER))
00565     {
00566         *Result = String_256(_R(IDS_STATICCOLOURPICKERTOOLHELP));
00567     }
00568     else if (GadgetID == _R(IDC_MAKE_LOCAL))
00569     {
00570         *Result = String_256(_R(IDS_EDITST_MAKE_LOCAL));
00571     }
00572     else if (GadgetID == _R(IDC_EDIT_NOCOLOUR))
00573     {
00574         *Result = String_256(_R(IDS_EDITST_SETNOCOLOUR));
00575     }
00576     else if (GadgetID == _R(IDC_EDIT_RENAME))
00577     {
00578         *Result = String_256(_R(IDS_EDITST_RENAME));
00579     }
00580     else if (GadgetID == _R(IDC_EDIT_LINEFILL))
00581     {
00582         *Result = String_256(_R(IDS_EDITST_LINEFILL));
00583     }
00584 #endif
00585     return(TRUE);
00586 }

BOOL ColourPicker::GetStatusLineText String_256 Result  )  [static]
 

Definition at line 655 of file colpick.cpp.

00656 {
00657 #ifndef STANDALONE
00658 
00659     ERROR3IF(Result == NULL, "Illegal NULL param");
00660     
00661     ColourEditDlg *Editor = ColourEditDlg::TheEditor;
00662     if (Editor == NULL)
00663         return(FALSE);
00664 
00665     // Find the main editor window
00666     CWindowID TheWindow = (CWindowID)Editor->WindowID;
00667     if (TheWindow == NULL)
00668         return(FALSE);
00669 
00670     wxPoint mousepos = ::wxGetMousePosition();
00671     wxWindow * window=::wxChildWindowFromPoint(TheWindow, mousepos, FALSE, -1);
00672     if ((!window) || (window!=::wxChildWindowFromPoint(mousepos, FALSE, -1))) // second check to ensure it is not obscured
00673         return FALSE;
00674 
00675     return GetStatusLineText(Editor, window->GetId(), Result);
00676 #else
00677     return(TRUE);
00678 #endif
00679 }

BOOL ColourPicker::GetTintAsString IndexedColour Source,
StringBase Result
[static, protected]
 

Retrieves the tint of the given colour as a decimal string appropriate for placing into a colour editor dialogue gadget.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/8/95
Parameters:
Source - The colour from which you wish to extract the tint [INPUTS]
Result - returns containing a decimal (0.0 .. 100.0) string representing [OUTPUTS] the value of the tint component of the colour
Returns:
TRUE if the value converted was out of gamut.
Notes: At present, this function clips the value to lie within the legal 0.0 to 1.0 gamut range.

If the colour is not a tint, will ENSURE and return "0%"

Scope: private

See also:
ColourPicker::SetTintFromString

Definition at line 1989 of file colpick.cpp.

01990 {
01991     ERROR3IF(Source == NULL || Result == NULL,
01992                 "ColourPicker::GetComponentAsString - NULL parameters are illegal");
01993 
01994     if (Source->GetType() != COLOURTYPE_TINT)
01995     {
01996         ERROR3("ColourPicker::GetTintAsString: Source colour isn't a tint");
01997         *Result = String_8(_R(IDS_CONVERT_ZERO_CHAR)); //TEXT("0");
01998         return(FALSE);
01999     }
02000 
02001     BOOL OutOfGamut = FALSE;
02002     
02003     double CompValue;
02004     if (Source->TintIsShade())
02005         CompValue = Source->GetShadeValueY().MakeDouble();
02006     else
02007         CompValue = Source->GetTintValue().MakeDouble();
02008 
02009     if (CompValue < 0.0)
02010     {
02011         CompValue = 0.0;        // **** Clip out-of-gamut values.
02012         OutOfGamut = TRUE;      // Remember that this was out of gamut
02013     }
02014 
02015     if (CompValue > 1.0)
02016     {
02017         CompValue = 1.0;        // **** Clip out-of-gamut values.
02018         OutOfGamut = TRUE;      // Remember that this was out of gamut
02019     }
02020 
02021     CompValue *= 100.0;
02022 
02023     String_32 TempString;
02024     Convert::DoubleToString(CompValue, (StringBase *) &TempString, 1);
02025 
02026     TempString.Left(Result, 7);
02027 
02028     return(OutOfGamut);
02029 }

TCHAR * ColourPicker::HelpCallbackHandler CWindowID  Window,
UINT32  Item,
void *  UserData
[static, protected]
 

Help callback handler to provide bubble help for the colour editor.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/9/95
Parameters:
Window - identifies the window to get help for [INPUTS] Item - identifies the control to get help for UserData - User-supplied data (not used)
Returns:
The bubble help string to use, or NULL if no help is available
See also:
ColourPicker::UpdateBubbleHelpAndPointer

Definition at line 702 of file colpick.cpp.

00703 {
00704 #ifndef STANDALONE
00705     static String_256 HelpStringStore;
00706     BOOL ReturnVal = FALSE;
00707 
00708     ColourEditDlg *Editor = ColourEditDlg::TheEditor;
00709     if (Editor == NULL)
00710         return(NULL);
00711 
00712     IndexedColour *Bob = Editor->EditingColour;
00713 
00714     ColourContext *cc = NULL;
00715     if (Bob != NULL)
00716         cc = ColourContext::GetGlobalDefault(