#include <coldrop.h>
Inheritance diagram for ColourDropDown:
Public Member Functions | |
ColourDropDown (BOOL AutoUpdateOnColourListChange=TRUE) | |
ColourDropDown constructor. | |
virtual | ~ColourDropDown () |
ColourDropDown destructor. | |
virtual BOOL | Init (CWindowID Window, CGadgetID Gadget) |
DropDown initialiser. | |
void | ClearAllSpecialEntries (void) |
Forgets about any special entries you may have added in the past. | |
BOOL | AddSpecialEntry (StringBase *Text, DocColour *Colour=NULL) |
Adds a "special entry" to the top of the colour list. | |
BOOL | UpdateSpecialEntry (StringBase *Text, DocColour *NewColour) |
Modifies a "special entry" to display a different colour. Cannot be used if the entry has no colour associated with it. | |
BOOL | FillInColourList (IndexedColour *Selected=NULL, INT32 SelectIndex=-1, IndexedColour *NotDescendantOf=NULL) |
"Fills in" the attached control with appropriate entries for the current ColourDropDown settings, and (if neccessary) a separated set of special entries at the top thereof. | |
BOOL | SetSelection (IndexedColour *Selected, INT32 SelectIndex=-1) |
To set the selected item in the list. | |
IndexedColour * | DecodeSelection (INT32 SelectionIndex) |
Decodes an index in the dropdown list back into either a special-item index or an IndexedColour pointer. (See AddSpecialEntry for details). | |
Static Public Member Functions | |
static void | UpdateForNewColourList (void) |
Called by the ColourDropMsgHandler whenever a colour list changes or we swap to a different document, etc. Will automatically clear the list and shade it if there are no documents around. | |
static void | RedrawColourDropDowns (void) |
Called by the ColourDropMsgHandler whenever the selected view's colour context is changed, so we redraw using the new correction/separation options. | |
Protected Member Functions | |
virtual BOOL | HasIcon (void *ItemData) |
Determine if an item needs an icon next to it. | |
virtual BOOL | DrawIcon (void *ItemData, wxDC &dc, wxRect &IconRect, BOOL Disabled, INT32 flags) |
Draws the icon for an item. | |
virtual wxString | GetText (void *ItemData, INT32 Item) |
Draws the text for an item. | |
Protected Attributes | |
List | SpecialEntries |
BOOL | AutoUpdateOnChange |
GBrush | GDrawBrush |
Static Protected Attributes | |
static ColourDropMsgHandler * | MessageHandler = NULL |
static INT32 | MsgHandlerCount = 0 |
Friends | |
class | DialogManager |
Definition at line 125 of file coldrop.h.
|
ColourDropDown constructor.
TRUE (default) if you want the colour list to automatically update when the current colour list (selected document) changes. This includes addition/removal/change of colours, as well as changing document, and auto-shadin/unshading of the list gadget when there are no documents or colours present. FALSE if you want to poke the list yourself. (This should only really be used by the Colour Editor, which already had lots of careful handling code built in- everyone else should just use the default setting) Definition at line 193 of file coldrop.cpp. 00194 { 00195 AutoUpdateOnChange = AutoUpdateOnColourListChange; 00196 }
|
|
ColourDropDown destructor.
Definition at line 211 of file coldrop.cpp. 00212 { 00213 ClearAllSpecialEntries(); 00214 00215 if (MessageHandler != NULL) 00216 { 00217 MsgHandlerCount--; 00218 if (MsgHandlerCount <= 0) 00219 { 00220 delete MessageHandler; // Get rid of msghandler when not needed 00221 MessageHandler = NULL; 00222 } 00223 } 00224 }
|
|
Adds a "special entry" to the top of the colour list.
The colour list can be augmented with a number of "special" entries. Each call to this method adds another entry to the bottom of the special entries list. If there are special entries, they are added to to top of the colour list, with a divider item between them and the colours. There can only be one divider. Special entries are indexed by their order of addition, with the first entry being number 0. When decoding a selection, DecodeSelection will return an IndexedColour pointer (if a colour was selected), or NULL, in which case, use the Index you passed in to determine which Special Entry was selected. Note that the divider will be treated as a special entry (e.g. with 2 special items, you can get an entry 2 selected - this corresponds to the divider, and should be ignored)
Definition at line 331 of file coldrop.cpp. 00332 { 00333 ERROR2IF(ParentDlg == NULL, FALSE, "ColourDropDown not properly initialised"); 00334 00335 SpecialEntry *NewEntry = new SpecialEntry; 00336 if (NewEntry != NULL && NewEntry->Init(Text, Colour)) 00337 { 00338 SpecialEntries.AddTail(NewEntry); 00339 return(TRUE); 00340 } 00341 return(FALSE); 00342 }
|
|
Forgets about any special entries you may have added in the past.
Definition at line 288 of file coldrop.cpp. 00289 { 00290 SpecialEntries.DeleteAll(); 00291 }
|
|
Decodes an index in the dropdown list back into either a special-item index or an IndexedColour pointer. (See AddSpecialEntry for details).
Special entries are indexed by their order of addition, with the first entry being number 0. When decoding a selection, DecodeSelection will return an IndexedColour pointer (if a colour was selected), or NULL, in which case, use the Index you passed in to determine which Special Entry was selected. Note that the divider will be treated as a special entry (e.g. with 2 special items, you can get an entry 2 selected - this corresponds to the divider, and should be ignored)
Definition at line 612 of file coldrop.cpp. 00613 { 00614 // If it's at the top of the list, it could be a "special" (extra) entry 00615 if (!SpecialEntries.IsEmpty() && SelectionIndex <= (INT32)SpecialEntries.GetCount()) 00616 return(NULL); 00617 00618 void * Data = GetItemData(SelectionIndex); 00619 // if (Data == -1) // If the list is empty, we will get a -1 back, so weed it out 00620 // return(NULL); 00621 00622 // Otherwise, it must be a colour, so fetch the colour pointer... 00623 return( (IndexedColour *) Data); 00624 }
|
|
Draws the icon for an item.
Reimplemented from DropDown. Definition at line 756 of file coldrop.cpp. 00757 { 00758 GDrawBrush.Init(&dc); 00759 GDrawBrush.Start(); 00760 00761 wxBrush OldBrush=dc.GetBrush(); 00762 wxPen OldPen=dc.GetPen(); 00763 00764 COLORREF rgb; 00765 00766 BOOL IsSpotColour = FALSE; 00767 00768 if (Disabled) 00769 { 00770 // The item is disabled, so just put a light grey splodge in the place of the colour 00771 rgb = RGB(192, 192, 192); 00772 dc.SetPen(*wxTRANSPARENT_PEN); 00773 } 00774 else 00775 { 00776 ColourContextRGBT *CCrgbt = (ColourContextRGBT *) 00777 ColourManager::GetColourContext(COLOURMODEL_RGBT, DocView::GetSelected()); 00778 00779 ERROR3IF(CCrgbt == NULL, "No available RGB colour context?!"); 00780 00781 CCObject *Item = (CCObject *)ItemData; 00782 if (Item->IsKindOf(CC_RUNTIME_CLASS(IndexedColour))) 00783 { 00784 DocColour Bob; 00785 Bob.MakeRefToIndexedColour((IndexedColour *)ItemData); 00786 rgb = ConvertColourToScreenWord(CCrgbt, &Bob); 00787 00788 if ( ((IndexedColour *) ItemData)->IsSpotOrTintOfSpot() ) 00789 IsSpotColour = TRUE; 00790 } 00791 else 00792 rgb = ConvertColourToScreenWord(CCrgbt, &(((SpecialEntry *)ItemData)->ItemColour)); 00793 00794 dc.SetPen(*wxBLACK_PEN); 00795 } 00796 00797 wxBrush brush; 00798 if (GDrawBrush.Available()) 00799 GDrawBrush.GetLogBrush(rgb, &brush); 00800 else 00801 brush=wxBrush(rgb); 00802 00803 dc.SetBrush(brush); 00804 00805 if (IsSpotColour) 00806 dc.DrawEllipse(IconRect.GetLeft(), IconRect.GetTop(), IconRect.GetWidth(), IconRect.GetHeight()); 00807 else 00808 dc.DrawRectangle(IconRect.GetLeft(), IconRect.GetTop(), IconRect.GetWidth(), IconRect.GetHeight()); 00809 00810 // Finish with GBrush 00811 GDrawBrush.Stop(); 00812 00813 dc.SetBrush(OldBrush); 00814 dc.SetPen(OldPen); 00815 00816 return(TRUE); 00817 }
|
|
"Fills in" the attached control with appropriate entries for the current ColourDropDown settings, and (if neccessary) a separated set of special entries at the top thereof.
NotDescendantOf - NULL, or a pointer to an IndexedColour. If this is non-null then this does not include "NotADescendantOf" or any of its children in the list (this allows a list of all available parent colours for a colour to be compiled by passing that colour in this field)
Call this after initialising the control, and after any subsequent calls to change the contents of the list.
Definition at line 430 of file coldrop.cpp. 00432 { 00433 ERROR2IF(ParentDlg == NULL, FALSE, "ColourDropDown not properly initialised"); 00434 00435 BOOL Result = FALSE; // Assume we've failed until we add an item! 00436 00437 Progress Hourglass; // Start an hourglass running 00438 00439 ColourList *ParentList = ColourManager::GetCurrentColourList(); 00440 00441 SetListRedraw(FALSE); // Disable redraw while updating 00442 ClearList(); // Delete combobox contents 00443 00444 INT32 SelectedIndex = 0; 00445 00446 if (!SpecialEntries.IsEmpty()) 00447 { 00448 // Add an entry for each special entry 00449 ListItem *Ptr = SpecialEntries.GetHead(); 00450 00451 while (Ptr != NULL) 00452 { 00453 AddItem((void *) Ptr); 00454 Ptr = SpecialEntries.GetNext(Ptr); 00455 } 00456 00457 AddItem(NULL); // And add a separator 00458 Result = TRUE; // There are items in the list, so we can return "OK" now 00459 } 00460 00461 // If we have a "NotDescendantOf" colour, then we can only add parent colours to the list 00462 // if the "NotDescendantOf" colour is tint/shade/linked - normal/spot colours cannot have parents 00463 00464 // Of course, we have to rely on the caller to be sensible here, because they might be about 00465 // to change the type of the colour (e.g. New Colour dialogue shows potential parents and 00466 // converts the colour to a shade if a parent is chosen. Thus, we don't want to present a blank 00467 // list of parent colours!) 00468 00469 if (ParentList != NULL) 00470 { 00471 // Determine (precalculate) if NotADescendant (if any) is a tint colour 00472 BOOL NotATint = TRUE; 00473 if (NotDescendantOf != NULL && 00474 NotDescendantOf->GetType() == COLOURTYPE_TINT && 00475 !NotDescendantOf->TintIsShade()) 00476 { 00477 NotATint = FALSE; 00478 } 00479 00480 // Now scan the colour list, adding any legal parent colours to the list 00481 IndexedColour *Ptr = (IndexedColour *) ParentList->GetHead(); 00482 INT32 Index = (SpecialEntries.IsEmpty()) ? 0 : (SpecialEntries.GetCount() + 1); 00483 00484 while (Ptr != NULL) 00485 { 00486 Hourglass.Update(); // Update the houglass 00487 00488 // Is the colour a named, live colour and not descended from NotADescendant? (Note: we 00489 // can safely pass NULL into IsADescendantOf()) 00490 if (!Ptr->IsDeleted() && Ptr->IsNamed() && !Ptr->IsADescendantOf(NotDescendantOf)) 00491 { 00492 AddItem((void *) Ptr); 00493 Result = TRUE; // We've succeeded in adding at least 1 item 00494 if (Ptr == Selected) 00495 SelectedIndex = Index; 00496 00497 Index++; 00498 } 00499 00500 Ptr = (IndexedColour *) ParentList->GetNext(Ptr); 00501 } 00502 } 00503 00504 SetListRedraw(TRUE); // Re-enable redraw 00505 00506 // Override any selection index we have with the caller-provided selection index, if 00507 // it indicates a valid "special item" 00508 if (SelectIndex >= 0 && SelectIndex < (INT32)SpecialEntries.GetCount()) 00509 SelectedIndex = SelectIndex; 00510 00511 if (Result) 00512 SetSelectedIndex(SelectedIndex); // And set the appropriate selected item 00513 00514 // Finally, enable the gadget, and trim its length down if necessary to fit the 00515 // number of displayed items. 00516 // DialogManager::SetComboListLength(ParentDlg, ParentGadget); -- causes nasty redraw of document behind! 00517 DialogManager::EnableGadget(ParentDlg, ParentGadget, TRUE); 00518 00519 return(Result); 00520 }
|
|
Draws the text for an item.
This method MUST be overridden by derived classes to provide redraw of their ColourDropDown list items. The base class draws nothing. Note that on entry, the text FG/BG colours have been set up appropriately for the state of the item (shaded, selected, etc) Basically, all you have to do is find the text and do a DrawText call.
Reimplemented from DropDown. Definition at line 849 of file coldrop.cpp. 00850 { 00851 ERROR3IF(ItemData == NULL, "NULL Itemdata in ColourDropDown::DrawText"); 00852 00853 // Determine if it's a colour or a special item, and find the text to draw 00854 TCHAR * TextToDraw = NULL; 00855 00856 CCObject *pItem = (CCObject *) ItemData; 00857 00858 if (pItem->IsKindOf(CC_RUNTIME_CLASS(IndexedColour))) 00859 TextToDraw = ( (TCHAR *) (*((IndexedColour *)ItemData)->GetName()) ); 00860 else 00861 TextToDraw = ( (TCHAR *) ((SpecialEntry *)ItemData)->ItemText ); 00862 00863 if (TextToDraw) 00864 return wxString(TextToDraw); 00865 else 00866 return wxEmptyString; 00867 }
|
|
Determine if an item needs an icon next to it.
This method MUST be overridden by derived classes to provide redraw of their ColourDropDown list items. The base class returns FALSE If you return TRUE, you must also provide the DrawIcon method
Reimplemented from DropDown. Definition at line 728 of file coldrop.cpp. 00729 { 00730 // All our items have a colour splodge 00731 return(TRUE); 00732 }
|
|
DropDown initialiser.
Reimplemented from DropDown. Definition at line 245 of file coldrop.cpp. 00246 { 00247 BOOL AlreadyInitialised = Initialised; // Remember if this is the first time we've been init'd 00248 00249 if (DropDown::Init(Window, Gadget)) // Call the base class 00250 { 00251 if (AlreadyInitialised) // Only increment handler count on first initialisation 00252 return(TRUE); 00253 00254 if (MessageHandler == NULL) // And ensure we have a message handler 00255 { 00256 MessageHandler = new ColourDropMsgHandler; 00257 MsgHandlerCount = 0; 00258 } 00259 00260 if (MessageHandler != NULL) // And increment its usage count 00261 { 00262 MsgHandlerCount++; 00263 return(TRUE); 00264 } 00265 } 00266 00267 return(FALSE); 00268 }
|
|
Called by the ColourDropMsgHandler whenever the selected view's colour context is changed, so we redraw using the new correction/separation options.
Definition at line 686 of file coldrop.cpp. 00687 { 00688 DropDown *Ptr = (DropDown *) CurrentDropDowns.GetHead(); 00689 while (Ptr != NULL) 00690 { 00691 if (Ptr->IsKindOf(CC_RUNTIME_CLASS(ColourDropDown))) 00692 { 00693 ColourDropDown *CPtr = (ColourDropDown *)Ptr; 00694 DialogManager::InvalidateGadget(CPtr->ParentDlg, CPtr->ParentGadget); 00695 } 00696 00697 Ptr = (DropDown *) CurrentDropDowns.GetNext(Ptr); 00698 } 00699 }
|
|
To set the selected item in the list.
Definition at line 546 of file coldrop.cpp. 00547 { 00548 ERROR2IF(ParentDlg == NULL, FALSE, "ColourDropDown not properly initialised"); 00549 00550 INT32 SelectedIndex = 0; 00551 00552 if (SelectIndex >= 0 && SelectIndex < (INT32)SpecialEntries.GetCount()) // Use special item 00553 SelectedIndex = SelectIndex; 00554 else if (Selected != NULL) // Use colour ptr 00555 { 00556 INT32 Index = (SpecialEntries.IsEmpty()) ? 0 : (SpecialEntries.GetCount() + 1); 00557 INT32 MaxIndex = GetNumberOfItems(); 00558 00559 while (Index < MaxIndex) 00560 { 00561 if (Selected == (IndexedColour *) GetItemData(Index)) 00562 { 00563 SelectedIndex = Index; 00564 break; 00565 } 00566 00567 Index++; 00568 } 00569 } 00570 00571 SetSelectedIndex(SelectedIndex); // And set the appropriate selected item 00572 return(TRUE); 00573 }
|
|
Called by the ColourDropMsgHandler whenever a colour list changes or we swap to a different document, etc. Will automatically clear the list and shade it if there are no documents around.
Scope: sorta private Definition at line 645 of file coldrop.cpp. 00646 { 00647 Document *SelDoc = Document::GetSelected(); 00648 00649 if (SelDoc != NULL) // No need to shade, so return now 00650 return; 00651 00652 DropDown *Ptr = (DropDown *) CurrentDropDowns.GetHead(); 00653 while (Ptr != NULL) 00654 { 00655 if (Ptr->IsKindOf(CC_RUNTIME_CLASS(ColourDropDown))) 00656 { 00657 ColourDropDown *CPtr = (ColourDropDown *)Ptr; 00658 if (CPtr->AutoUpdateOnChange) 00659 { 00660 CPtr->ClearList(); 00661 DialogManager::EnableGadget(CPtr->ParentDlg, CPtr->ParentGadget, FALSE); // Shade 00662 } 00663 } 00664 00665 Ptr = (DropDown *) CurrentDropDowns.GetNext(Ptr); 00666 } 00667 }
|
|
Modifies a "special entry" to display a different colour. Cannot be used if the entry has no colour associated with it.
Definition at line 367 of file coldrop.cpp. 00368 { 00369 ERROR3IF(Text == NULL || NewColour == NULL, "Illegal NULL params"); 00370 00371 SpecialEntry *Ptr = (SpecialEntry *) SpecialEntries.GetHead(); 00372 while (Ptr != NULL) 00373 { 00374 if (Ptr->ItemHasColour && Ptr->ItemText == *Text) 00375 { 00376 // Set the new colour 00377 Ptr->ItemColour = *NewColour; 00378 00379 // And cause the combobox to redraw 00380 DialogManager::InvalidateGadget(ParentDlg, ParentGadget); 00381 00382 return(TRUE); 00383 } 00384 00385 Ptr = (SpecialEntry *) SpecialEntries.GetNext(Ptr); 00386 } 00387 00388 return(FALSE); 00389 }
|
|
Reimplemented from DropDown. |
|
|
|
|
|
|
|
|
|
|