dropdown.cpp

Go to the documentation of this file.
00001 // $Id: dropdown.cpp 1412 2006-07-05 19:53:47Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // dropdown.cpp - Drop-down list base class
00100 
00101 // >>>> See O:\camelot\docs\howtouse\DropDowns.doc for details of use <<<<
00102 
00103 /*
00104 */
00105 
00106 
00107 //-----------------------------------------------------------------------------------------
00108 // Include files
00109 
00110 #include "camtypes.h"
00111 
00112 #include "camelot.h"
00113 #include "dropdown.h"
00114 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "palman.h"
00116 
00117 
00118 //-----------------------------------------------------------------------------------------
00119 // Implementation of dynamic classes
00120 
00121 CC_IMPLEMENT_DYNCREATE(DropDown, ListItem)
00122 
00123 
00124 //-----------------------------------------------------------------------------------------
00125 // This must be defined AFTER all CC_IMPLEMENT_DYNCREATE calls
00126 #define new CAM_DEBUG_NEW
00127 
00128 
00129 //-----------------------------------------------------------------------------------------
00130 // Statics
00131 
00132 List DropDown::CurrentDropDowns;
00133 
00134 wxCamVListBoxComboPopup::wxCamVListBoxComboPopup(DropDown * pDropDown) :
00135     wxVListBoxComboPopup(),
00136     m_pDropDown(pDropDown)
00137 {
00138 } 
00139 
00140 wxCamVListBoxComboPopup::~wxCamVListBoxComboPopup()
00141 {
00142 }
00143 
00144 void wxCamVListBoxComboPopup::OnDrawItem(wxDC& dc, const wxRect& rect, int /*TYPENOTE: CORRECT*/ item, int /*TYPENOTE: CORRECT*/ flags) const
00145 {
00146     dc.SetFont( m_useFont );
00147     if (m_pDropDown)
00148         m_pDropDown->HandleDrawItemInternal(dc, rect, item, flags, TRUE);
00149 }
00150 
00151 wxCoord wxCamVListBoxComboPopup::OnMeasureItem(size_t item) const
00152 {
00153     wxScreenDC dc;
00154     dc.SetFont( m_useFont );
00155     if (m_pDropDown)
00156         return m_pDropDown->HandleDrawItemInternal(dc, wxRect(-1, -1, -1, -1), item, 0, FALSE).GetHeight();
00157     else
00158         return 24;
00159 }
00160 
00161 wxCoord wxCamVListBoxComboPopup::OnMeasureItemWidth( size_t item ) const
00162 {
00163     wxScreenDC dc;
00164     dc.SetFont( m_useFont );
00165     if (m_pDropDown)
00166         return m_pDropDown->HandleDrawItemInternal(dc, wxRect(-1, -1, -1, -1), item, 0, FALSE).GetWidth();
00167     else
00168         return -1; // default - will be measured from text width
00169 }
00170 
00171 
00172 
00173 /********************************************************************************************
00174 
00175 >   DropDown::DropDown()
00176 
00177     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00178     Date:       29/8/95
00179 
00180     Purpose:    DropDown constructor
00181 
00182     Notes:      Follow this up with a call to Init()
00183 
00184     SeeAlso:    DropDown::Init; ColourDropDown; FontDropDown
00185 
00186 ********************************************************************************************/
00187 
00188 DropDown::DropDown()
00189 {
00190     ParentDlg = NULL;
00191     m_pPopup = NULL;
00192     ParentGadget = 0;
00193     Initialised = FALSE;
00194 }
00195 
00196 
00197 
00198 /********************************************************************************************
00199 
00200 >   virtual DropDown::~DropDown()
00201 
00202     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00203     Date:       29/8/95
00204 
00205     Purpose:    DropDown destructor
00206 
00207 ********************************************************************************************/
00208 
00209 DropDown::~DropDown()
00210 {
00211     if (Initialised)
00212     {
00213         // Do any deinit here
00214         Init(NULL, 0);
00215     }
00216 }
00217 
00218 /********************************************************************************************
00219 
00220 >   wxOwnerDrawnComboBox * DropDown::GetBox()
00221 
00222     Author:     AlexBligh
00223     Date:       13/05/2005
00224     Returns:    A pointer to the combo box
00225     Purpose:    Return the pointer to the combo box (once class is initialized) or NULL
00226                 on error
00227 
00228 ********************************************************************************************/
00229 
00230 wxOwnerDrawnComboBox * DropDown::GetBox()
00231 {
00232     wxWindow * pGadget = DialogManager::GetGadget(ParentDlg, ParentGadget);
00233     ERROR2IF(!pGadget || !pGadget->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)), NULL, "Bad Dropdown Gadget");
00234     return (wxOwnerDrawnComboBox *)pGadget;
00235 }
00236 
00237 /********************************************************************************************
00238 
00239 >   virtual BOOL DropDown::Init(CWindowID Window, CGadgetID Gadget)
00240 
00241     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00242     Date:       29/8/95
00243 
00244     Inputs:     Window - The Window in which your dropdown list gadget resides or NULL to denitialise
00245                 Gadget - The GadgetID of the deropdown list gadget
00246 
00247     Returns:    TRUE if it succeeded in connecting itself to your gadget
00248                 FALSE if it failed
00249 
00250     Purpose:    DropDown initialiser
00251 
00252 ********************************************************************************************/
00253 
00254 BOOL DropDown::Init(CWindowID Window, CGadgetID Gadget)
00255 {
00256     if (Window)
00257     {
00258         wxWindow * pGadget = DialogManager::GetGadget(Window, Gadget);
00259         if (pGadget && pGadget->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)))
00260         {
00261             if (!Initialised)           // Only ever add myself to the list once
00262             {
00263                 m_pPopup = new wxCamVListBoxComboPopup(this);
00264                 ERROR2IF(!m_pPopup, FALSE, "Could not get new list popup");
00265                 ((wxOwnerDrawnComboBox *)pGadget)->SetPopupControl(m_pPopup);
00266                 CurrentDropDowns.AddHead(this);
00267             }
00268     
00269             ParentDlg = Window;
00270             ParentGadget = Gadget;
00271     
00272             Initialised = TRUE;
00273             return(TRUE);
00274         }
00275         ERROR3("DropDown::Init failed - illegal Gadget");
00276         return(FALSE);
00277     }
00278     else
00279     {
00280         // release all memory
00281         KillList();
00282         ClearList();
00283         ParentDlg=NULL;
00284         ParentGadget=0;
00285         Initialised=FALSE;
00286         CurrentDropDowns.RemoveItem(this);
00287         return TRUE;
00288     }
00289 }
00290 
00291 /********************************************************************************************
00292 
00293 >   static void DropDown::KillDropDownsByWindow(CWindowID Window)
00294 
00295     Author:     Alex Bligh <alex@alex.org.uk>
00296     Date:       15/05/2005
00297 
00298     Purpose:    Kills all the dropdowns associated with a particular window
00299                 This is called when that window is dying. We can't delete the dropdowns
00300                 but we can deinit them so they won't cause anyone eny hassle.
00301 
00302 ********************************************************************************************/
00303 
00304 void DropDown::KillDropDownsByWindow(CWindowID Window)
00305 {
00306     // First kill any associated with this window
00307     DropDown *Ptr = (DropDown *) CurrentDropDowns.GetHead();
00308     while (Ptr != NULL)
00309     {
00310         DropDown * Next = (DropDown *) CurrentDropDowns.GetNext(Ptr); // as we may remove this item from the list
00311         if (Ptr->Initialised && (Ptr->ParentDlg==Window))
00312             Ptr->Init(NULL, 0);
00313         Ptr = Next;
00314     }
00315 
00316     // Now process children if any
00317     wxWindowList::Node * pNode = Window->GetChildren().GetFirst();
00318     while (pNode)
00319     {
00320         KillDropDownsByWindow(pNode->GetData());
00321         pNode = pNode->GetNext();
00322     }
00323     return;
00324 }
00325 
00326 
00327 /********************************************************************************************
00328 
00329 >   void DropDown::ClearList(void)
00330 
00331     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00332     Date:       13/9/95
00333 
00334     Purpose:    Clears all items from the list
00335 
00336 ********************************************************************************************/
00337 
00338 void DropDown::ClearList(void)
00339 {
00340     wxOwnerDrawnComboBox * pGadget = GetBox();
00341     if (!pGadget)
00342         return;
00343     pGadget->Clear();
00344 }
00345 
00346 
00347 
00348 /********************************************************************************************
00349 
00350 >   void DropDown::SetListRedraw(BOOL Enable)
00351 
00352     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00353     Date:       13/9/95
00354 
00355     Inputs:     Enable - TRUE to enable, FALSE to disable redraw
00356 
00357     Purpose:    Enables/Disables redraw of the combobox. Put around a sequence of calls
00358                 to AddItem to stop flickery redraws as you add items.
00359 
00360 ********************************************************************************************/
00361 
00362 void DropDown::SetListRedraw(BOOL Enable)
00363 {
00364     wxOwnerDrawnComboBox * pGadget = GetBox();
00365     if (!pGadget)
00366         return;
00367     if (Enable)
00368         pGadget->Thaw();
00369     else
00370         pGadget->Freeze();
00371 }
00372 
00373 
00374 
00375 /********************************************************************************************
00376 
00377 >   void DropDown::AddItem(void * ItemData)
00378 
00379     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00380     Date:       13/9/95
00381 
00382     Inputs:     ItemData - A data value to associate with this item. This must be unique
00383                 so you can use this ItemData to determine how to redraw the item.
00384                 The value NULL is special: It puts a non-selectable divider line into
00385                 the list.
00386 
00387     Purpose:    Adds another item or divider to the end of the current list
00388 
00389 ********************************************************************************************/
00390 
00391 void DropDown::AddItem(void * ItemData)
00392 {
00393     wxOwnerDrawnComboBox * pGadget = GetBox();
00394     if (!pGadget)
00395         return;
00396     INT32 n=pGadget->Append(wxEmptyString); // put in an empty string first
00397     m_pPopup->SetItemClientData(n, ItemData, wxClientData_Void);
00398     if (ItemData)
00399         pGadget->SetString(n, GetText(ItemData, n));
00400 }
00401 
00402 /********************************************************************************************
00403 
00404 >   void DropDown::DeleteItem(INT32 index)
00405 
00406     Author:     Martin Wuerthner <xara@mw-software.com>
00407     Date:       22/05/06
00408 
00409     Inputs:     index - the index of the item to be removed
00410     Purpose:    Removes an item from the list
00411 
00412 ********************************************************************************************/
00413 
00414 void DropDown::DeleteItem(INT32 index)
00415 {
00416     wxOwnerDrawnComboBox * pGadget = GetBox();
00417     if (!pGadget)
00418         return;
00419     INT32 count = (INT32)pGadget->GetCount();
00420     if (index >= 0 && index < count)
00421     {
00422         pGadget->Delete(index);
00423     }
00424     else
00425     {
00426         ERROR3("DropDown::RemoveItem - attempt to delete non-existing item");
00427     }
00428 }
00429 
00430 /********************************************************************************************
00431 
00432 >   void DropDown::SetSelectedIndex(INT32 SelectedIndex)
00433 
00434     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00435     Date:       13/9/95
00436 
00437     Inputs:     SelectedIndex - the index (0 based) of the item in the drop list
00438 
00439     Purpose:    Sets the index of the selected item in the list.
00440                 Take care never to set a divider as the selected item (it'll work, 
00441                 but it's a silly item to have selected!)
00442 
00443 ********************************************************************************************/
00444 
00445 void DropDown::SetSelectedIndex(INT32 SelectedIndex)
00446 {
00447     wxOwnerDrawnComboBox * pGadget = GetBox();
00448     if (!pGadget)
00449         return;
00450     pGadget->SetSelection(SelectedIndex);       // And set the appropriate selected item
00451 }
00452 
00453 
00454 /********************************************************************************************
00455 
00456 >   void * DropDown::GetItemData(INT32 ItemIndex)
00457 
00458     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00459     Date:       13/9/95
00460 
00461     Inputs:     ItemIndex - the index (0 based) of the item in the drop list (e.g. as
00462                 given to you by GetSelectedValueIndex() on DIM_SELECTION_CHANGED)
00463 
00464     Returns:    NULL, or the data word held in the indexed item
00465 
00466     Purpose:    Retrieves the data for a given item in the list
00467 
00468 ********************************************************************************************/
00469 
00470 void * DropDown::GetItemData(INT32 ItemIndex)
00471 {
00472     wxOwnerDrawnComboBox * pGadget = GetBox();
00473     if (!pGadget)
00474         return NULL;
00475     return m_pPopup->GetItemClientData(ItemIndex);
00476 }
00477 
00478 
00479 
00480 /********************************************************************************************
00481 
00482 >   INT32 DropDown::GetNumberOfItems(void)
00483 
00484     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00485     Date:       13/9/95
00486 
00487     Returns:    A count of how many items are in the list.
00488                 Indexes in the list will go from 0 to GetNumberOfItems()-1
00489 
00490     Purpose:    Determines the number of items in the list
00491 
00492 ********************************************************************************************/
00493 
00494 INT32 DropDown::GetNumberOfItems(void)
00495 {
00496     wxOwnerDrawnComboBox * pGadget = GetBox();
00497     if (!pGadget)
00498         return 0;
00499     return((INT32)pGadget->GetCount());
00500 }
00501 
00502 
00503 
00504 /********************************************************************************************
00505 
00506 >   virtual BOOL DropDown::HandleDrawItemInternal(CWindowID hDlg, UINT32 wParam, INT32 lParam)
00507 
00508     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00509     Date:       29/8/95
00510 
00511     Inputs:     hDlg - The CWindowID of the control which needs redrawing
00512                 wParam, lParam - As for the WM_DRAWITEM message
00513 
00514     Returns:    TRUE if it handled (claimed) the message
00515                 FALSE if it did not handle the message
00516 
00517     Purpose:    Handles redraw of items in a DropDown control
00518 
00519     Notes:      Called by HandleDrawItem when this object has been identified as the owner
00520                 of the control to be redrawn.
00521 
00522                 This method should only be overridden in extreme circumstances
00523 
00524                 If the item data for this item is NULL, then a divider line will be drawn.
00525                 Otherwise, your derived DrawIcon and DrawText methods will be called.
00526 
00527     Scope:      private
00528 
00529     SeeAlso:    DropDown::HasIcon; DropDown::DrawIcon; DropDown::DrawText
00530 
00531 ********************************************************************************************/
00532 
00533 wxSize DropDown::HandleDrawItemInternal(wxDC& dc, const wxRect& Rect, INT32 item, INT32 flags, BOOL Draw)
00534 {
00535     const INT32 border = 2;
00536 
00537     if (CCamApp::IsDisabled())          // Inside an error handler
00538         return(wxDefaultSize);
00539 
00540     wxOwnerDrawnComboBox * pGadget = GetBox();
00541 
00542 //  if ((INT32)pInfo->itemID == -1 || (INT32)pInfo->itemData == -1) // Draw item -1: just exit
00543 //      return(FALSE);
00544 
00545     void * ItemData = GetItemData(item);
00546         // Determine if it is a divider item
00547     if (!ItemData)
00548     {
00549         // It's a divider, so draw it specially - it is a simple black line across the center of the rectangle
00550         wxCoord midpoint = Rect.GetTop()+Rect.GetHeight()/2;
00551         if (Draw)
00552         {
00553             wxPen OldPen=dc.GetPen();
00554             dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
00555             dc.DrawLine(Rect.GetLeft(), midpoint, Rect.GetRight()+1, midpoint);
00556             dc.SetPen(OldPen);
00557         }
00558         return(wxSize(-1,5));
00559     }
00560 
00561     // If we aren't drawing, we should get the size of the text and return that appopriately modified
00562     if (!Draw)
00563     {
00564         // Call the derived class
00565         wxRect def(-1,-1,-1,-1);
00566         wxSize TextSize = DrawText(ItemData, dc, def, item, flags, FALSE); // Rect is unused here as Draw is FALSE
00567         TextSize.x+=2*border;
00568         TextSize.y+=2*border; // This gives us the bounding rect as we leave some space around it
00569         if (HasIcon(ItemData))
00570         {
00571             // There is an icon. It's width is equal to the text height less 2 (deflated in both
00572             // directions. There is also a 6 pixel space
00573             TextSize.x += (TextSize.y-2)+6;
00574         }
00575         return TextSize;
00576     }
00577     
00578     wxRect rect=Rect;
00579     rect.Deflate(border);
00580 
00581     // Calculate where the colour splodge (if any) will go (also used to shift text to the right later)
00582     wxRect IconRect=rect;
00583     IconRect.Deflate(1);
00584     IconRect.SetWidth(IconRect.GetHeight());
00585 
00586     wxRect TextRect=rect;
00587 
00588     wxPalette * OldPal = NULL;
00589 
00590     // If it's a special item with a colour splodge, or a normal colour item, draw the colour splodge
00591     if (HasIcon(ItemData))
00592     {
00593         if (PaletteManager::UsePalette())
00594             OldPal = PaletteManager::StartPaintPalette(&dc);
00595 
00596         // Call the derived class to draw the icon
00597         if (Draw)
00598             DrawIcon(ItemData, dc, IconRect, !pGadget->IsEnabled(), flags);
00599 
00600         // Shift the text to the right of the icon
00601         INT32 shift=IconRect.GetWidth()+6;
00602         TextRect.Offset(shift,0);
00603         INT32 NewWidth=TextRect.GetWidth()-shift;
00604         TextRect.SetWidth(NewWidth<1?1:NewWidth);
00605     }
00606     
00607     if (TextRect.GetWidth()>1)      // if there's room to draw any text, draw it
00608     {
00609         // Call derived class to draw the text
00610         if (Draw)
00611             DrawText(ItemData, dc, TextRect, item, flags, TRUE);
00612     }
00613 
00614     // Restore the DC's previous palette if we selected our one in
00615     if (OldPal)
00616         PaletteManager::StopPaintPalette(&dc, OldPal);
00617 
00618     return(wxDefaultSize);
00619 }
00620 
00621 
00622 
00623 /********************************************************************************************
00624 
00625 >   virtual BOOL DropDown::HasIcon(void * ItemData)
00626 
00627     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00628     Date:       13/9/95
00629 
00630     Inputs:     ItemData - Your item data
00631 
00632     Returns:    TRUE if this item needs an icon to the left of it, FALSE if not
00633 
00634     Purpose:    Determine if an item needs an icon next to it
00635 
00636     Notes:      Called by HandleDrawItemInternal when this object has been identified as the 
00637                 owner of the control to be redrawn.
00638 
00639                 This method MUST be overridden by derived classes to provide redraw of their
00640                 dropdown list items. The base class returns FALSE
00641 
00642                 If you return TRUE, you must also provide the DrawIcon method
00643 
00644     SeeAlso:    DropDown::DrawIcon; DropDown::DrawText
00645 
00646 ********************************************************************************************/
00647 
00648 BOOL DropDown::HasIcon(void * ItemData)
00649 {
00650     return(FALSE);
00651 }
00652 
00653 
00654 
00655 /********************************************************************************************
00656 
00657 >   virtual BOOL DropDown::DrawIcon(void * ItemData, wxDC& dc, wxRect& IconRect, BOOL Disabled)
00658 
00659     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00660     Date:       13/9/95
00661 
00662     Inputs:     ItemData - Your item data
00663                 dc - The DC to render into
00664                 IconRect - points at a rectangle (square in fact) to be drawn within
00665                 Disabled - TRUE if the item is disabled so should be drawn greyed
00666 
00667     Returns:    TRUE if this item needs an icon to the left of it, FALSE if not
00668 
00669     Purpose:    Draws the icon for an item
00670 
00671     Notes:      Called by HandleDrawItemInternal when this object has been identified as the 
00672                 owner of the control to be redrawn - ONLY called if HasIcon returned TRUE
00673 
00674                 This method MUST be overridden by derived classes to provide redraw of their
00675                 dropdown list items. The base class does nothing.
00676 
00677                 On entry, the DC is ready for you to draw into, including having the camelot
00678                 palette selected in etc.
00679 
00680     SeeAlso:    DropDown::HasIcon; DropDown::DrawText; ColourDropDown::DrawIcon
00681 
00682 ********************************************************************************************/
00683 
00684 BOOL DropDown::DrawIcon(void * ItemData, wxDC& dc, wxRect& IconRect, BOOL Disabled, INT32 flags)
00685 {
00686     return(TRUE);
00687 }
00688 
00689 
00690 
00691 /********************************************************************************************
00692 
00693 >   virtual wxSize DropDown::DrawText(void * ItemData, wxDC& dc, wxRect& TextRect, INT32 Item, INT32 flags, BOOL Draw)
00694 
00695     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00696     Date:       13/9/95
00697 
00698     Inputs:     ItemData - Your item data
00699                 wxDC& - the DC to draw into
00700                 TextRect - points at a rectangle in which the text should be rendered
00701                 Item - the index of the item
00702                 flags - the flags sent to OnDrawItem
00703                 Draw - TRUE to Draw, FALSE to just get a size
00704 
00705     Returns:    The size of the text
00706 
00707     Purpose:    Draws the text for an item
00708 
00709     Notes:      Called by HandleDrawItemInternal when this object has been identified as the 
00710                 owner of the control to be redrawn, if HasIcon returned TRUE
00711 
00712                 This method MUST be overridden by derived classes to provide redraw of their
00713                 dropdown list items. The base class draws nothing.
00714 
00715                 Note that on entry, the text FG/BG colours have been set up appropriately
00716                 for the state of the item (shaded, selected, etc)
00717                 Basically, all you have to do is find the text and do a DrawText call.
00718 
00719     SeeAlso:    DropDown::DrawIcon; DropDown::DrawIcon; ColourDropDown::DrawText
00720 
00721 ********************************************************************************************/
00722 
00723 wxSize DropDown::DrawText(void * ItemData, wxDC& dc, wxRect& TextRect, INT32 item, INT32 flags, BOOL Draw)
00724 {
00725     if (Draw)
00726     {
00727         if ( (m_pPopup->wxVListBox::GetSelection() == (INT32)item) && !(flags & wxODCB_PAINTING_CONTROL) )
00728             dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
00729         else
00730             dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
00731     }
00732 
00733     wxString Text = GetText(ItemData, item);
00734     wxCoord w, h;
00735     dc.GetTextExtent(Text, &w, &h);
00736     wxSize size(w,dc.GetCharHeight());
00737     
00738     if (Draw)
00739         dc.DrawText( Text, TextRect.x, TextRect.y );
00740 
00741     return size;
00742 }

Generated on Sat Nov 10 03:48:25 2007 for Camelot by  doxygen 1.4.4