#include <newcol.h>
Inheritance diagram for NewColourDlg:
Public Member Functions | |
NewColourDlg () | |
NewColourDlg constructor. | |
virtual | ~NewColourDlg () |
You'll never guess... | |
void | DoWithParam (OpDescriptor *, OpParam *) |
Creates then opens the dialog. | |
BOOL | Create () |
NewColourDlg create method. | |
virtual MsgResult | Message (Msg *Message) |
Handles all the scale dialog's messages. | |
Static Public Member Functions | |
static BOOL | InvokeDialog (ColourList *ParentList, IndexedColour *SourceAndResult, NewColourDlgType Flags=NEWCOLOUR_NAMEDORUNNAMED) |
Opens the new colour dialogue on screen, elicits a response, and returns having set up the new colour according to the users instructions. This is a MODAL dlg. | |
static OpState | GetState (String_256 *, OpDescriptor *) |
NewColourDlg GetState method. | |
static BOOL | Init () |
NewColourDlg Init method. Called by sginit.cpp. | |
Static Public Attributes | |
static const INT32 | IDD = _R(IDD_NEWCOLOURDLG) |
static const CDlgMode | Mode = MODAL |
Protected Member Functions | |
void | ShadeControls (void) |
Shades all controls appropriately to the current selection. | |
void | SetNameText (void) |
Sets the name field appropriately to the current selection If the user has changed the name field, it will not be touched. | |
void | CommitDetails (BOOL Force=FALSE, BOOL ForceMakeShade=FALSE) |
Commits to the current setting for the colour Reads the settings the user has chosen and changes the result colour to suit those settings. Sets the Result to TRUE if it succeeds. Then closes and ends the dialogue. | |
Protected Attributes | |
NewColourParam * | Info |
String_256 | AutoName |
ColourDropDown * | ParentDropDown |
Static Protected Attributes | |
static BOOL | MakeShade = FALSE |
Definition at line 155 of file newcol.h.
|
NewColourDlg constructor.
Definition at line 142 of file newcol.cpp. 00142 : DialogOp(NewColourDlg::IDD, NewColourDlg::Mode) 00143 { 00144 ParentDropDown = NULL; 00145 }
|
|
You'll never guess...
Definition at line 161 of file newcol.cpp. 00162 { 00163 if (ParentDropDown != NULL) 00164 delete ParentDropDown; 00165 }
|
|
Commits to the current setting for the colour Reads the settings the user has chosen and changes the result colour to suit those settings. Sets the Result to TRUE if it succeeds. Then closes and ends the dialogue.
Definition at line 402 of file newcol.cpp. 00403 { 00404 // Set result to 'success' 00405 Info->Result = TRUE; 00406 00407 // Set the colour type etc as appropriate 00408 IndexedColour *ParentColour = Info->TheColour->FindLastLinkedParent(); 00409 00410 // Make sure the parent colour we're setting is legal (not deleted or in another doc) 00411 if (ParentColour != NULL) 00412 { 00413 IndexedColour *Ptr = Info->TheList->GetUndeletedHead(); 00414 while (Ptr != NULL) 00415 { 00416 if (Ptr == ParentColour) 00417 break; 00418 00419 Ptr = Info->TheList->GetUndeletedNext(Ptr); 00420 } 00421 00422 if (Ptr != ParentColour) // ParentColour not found in the intended destination list! 00423 ParentColour = NULL; // Set it to NULL, and we'll find a safe ParentColour below 00424 00425 if (ParentColour != NULL && ParentColour->IsDeleted()) 00426 ParentColour = NULL; 00427 } 00428 00429 if (ParentColour == NULL) 00430 { 00431 // If the parent was illegal, it's a big screwup. Oh bums. 00432 // Luckily, we can fix the problem and continue happily 00433 ERROR3IF(Info->TheColour->FindLastLinkedParent() != NULL, 00434 "NewColourDlg - had to correct colour with illegal parent pointer!"); 00435 00436 // Set the parent to NULL before we do ourselves an injury! 00437 Info->TheColour->SetLinkedParent(NULL, COLOURTYPE_NORMAL); 00438 } 00439 else 00440 { 00441 // Get the parent and child colour definitions in HSV, as this info is useful 00442 ColourContext *cc = ColourContext::GetGlobalDefault(COLOURMODEL_HSVT); 00443 00444 if (Force) 00445 MakeShade = ForceMakeShade; 00446 else 00447 MakeShade = GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE)); 00448 00449 if (MakeShade) 00450 { 00451 /* 00452 Info->TheColour->SetLinkedParent(ParentColour, COLOURTYPE_LINKED); 00453 00454 // Coerce the colour to be an HSV colour 00455 ColourPicker::ForceColourModel(Info->TheColour, cc); 00456 00457 // And set it to inherit Hue only 00458 Info->TheColour->SetInheritsComponent(1, TRUE); 00459 Info->TheColour->SetInheritsComponent(2, FALSE); 00460 Info->TheColour->SetInheritsComponent(3, FALSE); 00461 Info->TheColour->SetInheritsComponent(4, FALSE); 00462 */ 00463 // Calculate the shading values to keep this colour looking correct 00464 FIXED24 NewX(0.0); 00465 FIXED24 NewY(0.0); 00466 00467 // Work out saturation scaling factor 00468 ColourHSVT ParentDef; 00469 ColourHSVT ColourDef; 00470 cc->ConvertColour(ParentColour, (ColourGeneric *)&ParentDef); 00471 cc->ConvertColour(Info->TheColour, (ColourGeneric *)&ColourDef); 00472 00473 double ParentVal = ParentDef.Saturation.MakeDouble(); 00474 double ColourVal = ColourDef.Saturation.MakeDouble(); 00475 00476 if (ParentVal > ColourVal) 00477 { 00478 if (ParentVal > 0.0) 00479 NewX = -((ParentVal - ColourVal) / ParentVal); 00480 } 00481 else 00482 { 00483 if (ParentVal < 1.0) 00484 NewX = (ColourVal - ParentVal) / (1.0 - ParentVal); 00485 } 00486 00487 // Work out Value scaling factor 00488 ParentVal = ParentDef.Value.MakeDouble(); 00489 ColourVal = ColourDef.Value.MakeDouble(); 00490 if (ParentVal > ColourVal) 00491 { 00492 if (ParentVal > 0.0) 00493 NewY = -((ParentVal - ColourVal) / ParentVal); 00494 } 00495 else 00496 { 00497 if (ParentVal < 1.0) 00498 NewY = (ColourVal - ParentVal) / (1.0 - ParentVal); 00499 } 00500 00501 // And make the colour a shade (a special type of tint) 00502 Info->TheColour->SetLinkedParent(ParentColour, COLOURTYPE_TINT); 00503 Info->TheColour->SetShadeValues(NewX, NewY); 00504 } 00505 else 00506 { 00507 // Only change the colour if it is already named - otherwise, we're making 00508 // a local colour into a named colour, and we don't want to alter it. 00509 if (Info->TheColour->IsNamed()) 00510 { 00511 // Copy the colour from the parent - the name will be fixed up below 00512 *Info->TheColour = *ParentColour; 00513 Info->TheColour->SetLinkedParent(ParentColour, Info->TheColour->GetType()); 00514 } 00515 } 00516 } 00517 00518 String_256 NewName(""); 00519 if (!Force) 00520 NewName = GetStringGadgetValue(_R(IDC_NEWCOL_NAME)); 00521 00522 if (NewName.IsEmpty()) // User gave NULL name. Use 'New Colour' instead. 00523 NewName.MakeMsg(_R(IDS_NEWCOLOUR)); 00524 00525 // We must set the new name for the colour - first make sure it's unique 00526 String_64 UniqueName; 00527 if (Info->TheList->GenerateUniqueColourName((const StringBase *) &NewName, &UniqueName) && !Force) 00528 { 00529 // If the name had to be changed, and the force flag is off (the user brought up the dialogue 00530 // and entered a name for themselves) then warn them that the name has been changed to 00531 // protect the innocent. If you can call the CamEPS filter innocent... 00532 00533 TCHAR TempStr[256]; 00534 String_256 jcf(_R(IDS_NEWCOL_RENAMED)); 00535 camSnprintf(TempStr, 256, jcf, (LPCTSTR) UniqueName); 00536 00537 // We still don't have a f***ing way of reporting a f***ing message to the user which uses 00538 // a STRING so we can f***ing include f***ing useful information at runtime! 00539 // Thus, we InformError to do it. This will use the error beep and a scary huge pling icon, 00540 // and the user will brown his pants thinking that an access violation complete death 00541 // scenario is upon him. 00542 Error::SetError(0, TempStr, 0); 00543 InformError(); 00544 } 00545 00546 Info->TheColour->SetName(UniqueName); 00547 00548 if (!Force) 00549 Close(); 00550 00551 End(); 00552 }
|
|
NewColourDlg create method. Authofosr: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Reimplemented from DialogOp. Definition at line 612 of file newcol.cpp. 00613 { 00614 return(DialogOp::Create()); 00615 }
|
|
Creates then opens the dialog.
Reimplemented from Operation. Definition at line 632 of file newcol.cpp. 00633 { 00634 ERROR3IF(pOpParam == NULL, "Come on, play by the rules"); 00635 00636 Info = (NewColourParam *) pOpParam; 00637 00638 if (Info->TheColour == NULL || Info->TheList == NULL) 00639 { 00640 ERROR3("NewColourDlg parameters are unhelpful to say the least"); 00641 End(); 00642 return; 00643 } 00644 00645 // Check that the colour's intended parent is safe (in the destination document) 00646 IndexedColour *Parent = Info->TheColour->FindLastLinkedParent(); 00647 if (Parent != NULL) 00648 { 00649 IndexedColour *Ptr = Info->TheList->GetUndeletedHead(); 00650 while (Ptr != NULL) 00651 { 00652 if (Ptr == Parent) 00653 break; 00654 00655 Ptr = Info->TheList->GetUndeletedNext(Ptr); 00656 } 00657 00658 if (Ptr != Parent) // Parent not found in the intended destination list! 00659 Parent = NULL; // Set it to NULL, and we'll find a safe parent below 00660 } 00661 00662 // --- Make sure the colour defaults to having some sort of safe parent hint 00663 if (Parent == NULL || Parent->IsDeleted()) 00664 { 00665 IndexedColour *Bob = (IndexedColour *) Info->TheList->GetUndeletedHead(); 00666 Info->TheColour->SetLinkedParent(Bob, Info->TheColour->GetType()); 00667 } 00668 00669 // --- Check for key shortcuts 00670 // If various modifier keys are held down when the dlg is invoked, then it will 00671 // shortcut the process by proceeding with certain options set. 00672 if (KeyPress::IsConstrainPressed()) 00673 { 00674 if (KeyPress::IsAdjustPressed()) 00675 CommitDetails(TRUE, MakeShade); // Force previously used setting (ctrl-shift) 00676 else 00677 CommitDetails(TRUE, TRUE); // Force "shade of" (ctrl only) 00678 return; 00679 } 00680 00681 if (KeyPress::IsAdjustPressed()) 00682 { 00683 CommitDetails(TRUE, FALSE); // Force "a copy of" (shift only) 00684 return; 00685 } 00686 00687 // --- Otherwise, create and open the dialogue 00688 if (!Create()) 00689 { 00690 InformError(); 00691 End(); 00692 } 00693 }
|
|
NewColourDlg GetState method.
Definition at line 566 of file newcol.cpp. 00567 { 00568 OpState OpSt; 00569 return(OpSt); 00570 }
|
|
NewColourDlg Init method. Called by sginit.cpp.
Reimplemented from SimpleCCObject. Definition at line 585 of file newcol.cpp. 00586 { 00587 return (RegisterOpDescriptor( 00588 0, 00589 _R(IDS_NEWCOLOURDLG), 00590 CC_RUNTIME_CLASS(NewColourDlg), 00591 OPTOKEN_NEWCOLOURDLG, 00592 NewColourDlg::GetState, 00593 0, // help ID 00594 0 // bubble ID 00595 ) 00596 ); 00597 }
|
|
Opens the new colour dialogue on screen, elicits a response, and returns having set up the new colour according to the users instructions. This is a MODAL dlg.
Definition at line 731 of file newcol.cpp. 00733 { 00734 ERROR3IF(ParentList == NULL || Result == NULL, "Come on, play by the rules"); 00735 00736 NewColourParam Info(ParentList, Result, Flags); 00737 OpDescriptor *TheDlg = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(NewColourDlg)); 00738 00739 ERROR3IF(TheDlg == NULL, "NewColourDlg::InvokeDialog is unable to find the Dlg OpDescriptor"); 00740 00741 if (TheDlg != NULL) 00742 TheDlg->Invoke(&Info); 00743 00744 return(Info.Result); 00745 }
|
|
Handles all the scale dialog's messages.
Reimplemented from DialogOp. Definition at line 184 of file newcol.cpp. 00185 { 00186 if (IS_OUR_DIALOG_MSG(Message)) 00187 { 00188 DialogMsg* Msg = (DialogMsg*)Message; 00189 // BOOL EndDialog = FALSE; 00190 00191 switch (Msg->DlgMsg) 00192 { 00193 case DIM_CREATE: 00194 { 00195 // Tick the "make shade" button if it was on the last time 00196 SetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE), MakeShade); 00197 00198 // Set up the colour drop-down menu 00199 BOOL ok = FALSE; 00200 ParentDropDown = new ColourDropDown; 00201 if (ParentDropDown != NULL && ParentDropDown->Init(WindowID, _R(IDC_NEWCOL_COLLIST))) 00202 { 00203 IndexedColour *ParentColour = Info->TheColour->FindLastLinkedParent(); 00204 00205 // Make sure the parent colour we're setting is legal (not deleted) 00206 if (ParentColour != NULL && ParentColour->IsDeleted()) 00207 ParentColour = NULL; 00208 00209 ok = ParentDropDown->FillInColourList(ParentColour, -1, Info->TheColour); 00210 } 00211 00212 // Shade controls appropriately, and fill in the name text field 00213 ShadeControls(); 00214 SetNameText(); 00215 SetKeyboardFocus(_R(IDC_NEWCOL_NAME)); 00216 HighlightText(_R(IDC_NEWCOL_NAME)); 00217 00218 // If the colour deropdown creation failed, then shade it to be safe 00219 if (!ok) 00220 EnableGadget(_R(IDC_NEWCOL_COLLIST), FALSE); 00221 } 00222 break; 00223 00224 00225 case DIM_COMMIT: 00226 case DIM_SOFT_COMMIT: 00227 CommitDetails(); 00228 break; 00229 00230 00231 case DIM_CANCEL: 00232 Close(); 00233 End(); 00234 break; 00235 00236 00237 case DIM_LFT_BN_CLICKED: 00238 if (Msg->GadgetID == _R(IDC_NEWCOL_SHADE)) 00239 { 00240 SetNameText(); // Ensure name text is updated if necessary 00241 ShadeControls(); // And make sure shading of controls is updated 00242 } 00243 break; 00244 00245 00246 case DIM_SELECTION_CHANGED: 00247 if (Msg->GadgetID == _R(IDC_NEWCOL_COLLIST) && ParentDropDown != NULL) 00248 { 00249 INT32 Index = GetSelectedValueIndex(_R(IDC_NEWCOL_COLLIST)); 00250 00251 IndexedColour *NewParent = ParentDropDown->DecodeSelection(Index); 00252 Info->TheColour->SetLinkedParent(NewParent, Info->TheColour->GetType()); 00253 00254 ShadeControls(); 00255 SetNameText(); 00256 } 00257 break; 00258 /* 00259 case DIM_REDRAW: 00260 if (Msg->GadgetID == _R(IDC_COLNAME_PATCH)) 00261 { 00262 ReDrawInfoType *RedrawInfo = (ReDrawInfoType*) Msg->DlgMsgParam; 00263 DocRect VirtualSize(0, 0, RedrawInfo->dx, RedrawInfo->dy); 00264 RenderRegion *pRender = CreateOSRenderRegion(&VirtualSize, RedrawInfo); 00265 if (pRender) 00266 { 00267 pRender->SaveContext(); 00268 00269 DocColour PatchCol(128L, 128L, 128L); 00270 if (Info->TheColour != NULL) 00271 PatchCol.MakeRefToIndexedColour(Info->TheColour); 00272 00273 pRender->SetLineWidth(0); 00274 pRender->SetLineColour(PatchCol); 00275 pRender->SetFillColour(PatchCol); 00276 pRender->DrawRect(&VirtualSize); 00277 00278 pRender->RestoreContext(); 00279 00280 DestroyOSRenderRegion(pRender); 00281 } 00282 } 00283 break; 00284 */ 00285 default: 00286 break; 00287 } 00288 00289 return (DLG_EAT_IF_HUNGRY(Msg)); 00290 } 00291 00292 return OK; 00293 }
|
|
Sets the name field appropriately to the current selection If the user has changed the name field, it will not be touched.
Definition at line 341 of file newcol.cpp. 00342 { 00343 String_256 CurrentText; 00344 00345 CurrentText = GetStringGadgetValue(_R(IDC_NEWCOL_NAME)); 00346 00347 // Only change the text if it is blank or if the user has not changed it 00348 if (CurrentText.IsEmpty() || CurrentText == AutoName) 00349 { 00350 IndexedColour *ParentColour = Info->TheColour->FindLastLinkedParent(); 00351 00352 // Make sure the parent colour we're setting is legal (not deleted) 00353 if (ParentColour != NULL && ParentColour->IsDeleted()) 00354 ParentColour = NULL; 00355 00356 if (Info->TheColour->IsNamed() && ParentColour != NULL) 00357 { 00358 String_64 *ParentName = ParentColour->GetName(); 00359 00360 if (GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE))) 00361 AutoName.MakeMsg(_R(IDS_SHADEOFCOLOUR), (TCHAR *) *ParentName); // "Shade of red" 00362 else 00363 AutoName.MakeMsg(_R(IDS_COPYOFCOLOUR), (TCHAR *) *ParentName); // "Copy of red" 00364 } 00365 else 00366 { 00367 if (GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE)) && ParentColour != NULL) 00368 AutoName.MakeMsg(_R(IDS_SHADEOFCOLOUR), (TCHAR *) *(ParentColour->GetName())); // "Shade of red" 00369 else 00370 AutoName.MakeMsg(_R(IDS_NEWCOLOUR)); // "New Colour" 00371 } 00372 00373 SetStringGadgetValue(_R(IDC_NEWCOL_NAME), AutoName); 00374 } 00375 }
|
|
Shades all controls appropriately to the current selection.
Definition at line 308 of file newcol.cpp. 00309 { 00310 // If there are no valid parent colours in the document, shade the "make shade" controls 00311 if (Info->TheList->GetUndeletedHead() == NULL) 00312 { 00313 EnableGadget(_R(IDC_NEWCOL_COLLIST), FALSE); 00314 EnableGadget(_R(IDC_NEWCOL_SHADE), FALSE); 00315 } 00316 else 00317 { 00318 // Parent colour for local colours is only available if you turn on "make shade" 00319 // but it is always available (copy-of or shade-of) for named colours 00320 if (Info->TheColour->IsNamed()) 00321 EnableGadget(_R(IDC_NEWCOL_COLLIST), TRUE); 00322 else 00323 EnableGadget(_R(IDC_NEWCOL_COLLIST), GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE))); 00324 } 00325 }
|
|
|
|
|
|
|
|
|
|
|
|
|