home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pwrgu2.zip / POWERGU2.EXE / LISTCTLS / DRAWLIST / LISTDHDR.CPP < prev    next >
Text File  |  1995-08-23  |  4KB  |  122 lines

  1. //************************************************************
  2. // List Controls - List Box Custom Drawing           
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // All Rights Reserved.
  6. //************************************************************
  7. // os2.h needing for drawing primitives.
  8. #define INCL_GPILOGCOLORTABLE  
  9. #define INCL_WINSYS
  10. #define INCL_WINWINDOWMGR
  11. extern "C" {
  12.   #include <os2.h>
  13. }
  14.  
  15. #include <ilistbox.hpp>
  16. #include <irect.hpp>
  17. #include <ifont.hpp>
  18. #include <icolor.hpp>  
  19. #include <istring.hpp>
  20. #include "listdhdr.hpp"
  21. #include "listitem.hpp"
  22.  
  23. Boolean DrawHandler::highlight ( IListBoxDrawItemEvent& event )
  24.   // Draw selection.
  25.   return this->drawListItem( event, true );
  26. }
  27.  
  28. Boolean DrawHandler::unhighlight ( IListBoxDrawItemEvent& event )
  29.   // Draw without selection.
  30.   return this->drawListItem( event, false );
  31. }
  32.  
  33. Boolean DrawHandler::draw ( IListBoxDrawItemEvent& event, 
  34.                             DrawFlag& flag )
  35. {
  36.   if ( event.isSelected() )
  37.   {
  38.      flag = drewSelected;
  39.      return this->drawListItem( event, true );
  40.   }
  41.   else
  42.      return this->drawListItem( event, false );
  43. }
  44.  
  45. // Handle the drawing of the list box items.
  46. Boolean DrawHandler::drawListItem ( IListBoxDrawItemEvent& event,
  47.                                     Boolean selected )
  48. {
  49.   IListBox* list = (IListBox*)event.controlWindow();
  50.   IRectangle rect = event.itemRect();
  51.   RECTL rectl = rect.asRECTL();
  52.  
  53.   // Fill the background. 
  54.   IColor 
  55.     background         = list->backgroundColor(),
  56.     foreground         = list->foregroundColor(),
  57.     selectedBackground = list->hiliteBackgroundColor(),  
  58.     selectedForeground = list->hiliteForegroundColor();  
  59.   GpiCreateLogColorTable( event.itemPresSpaceHandle(), 
  60.                           0, LCOLF_RGB, 0, 0, 0 );
  61.   WinFillRect( event.itemPresSpaceHandle(), 
  62.                &rectl,
  63.                selected ? selectedBackground.asRGBLong()
  64.                         : background.asRGBLong() );
  65.  
  66.   // Convert the item data from the list box item text.
  67.   ListItem* data = 
  68.      (ListItem*)(list->itemText( event.itemId() ).asUnsigned());
  69.  
  70.   // Determine the indent for the class based on the
  71.   // number of inherited classes.
  72.   if ( data->inheritedClasses() != 0 )
  73.   {
  74.      ISize indentSize( data->inheritedClasses() * (_indent+1), 0 );
  75.      rect.moveBy( indentSize );
  76.   }
  77.  
  78.   // Draw a bitmap based on the collapsed flag
  79.   // if the class is not a leaf.
  80.   if ( data->children() )
  81.   {
  82.      // Make the bitmap a square the size of an item.
  83.      IRectangle rectBitmap( rect.bottomLeft(),
  84.                             ISize( rect.height(),
  85.                                    rect.height() ));
  86.      rectl = rectBitmap.asRECTL();
  87.      WinDrawBitmap( event.itemPresSpaceHandle(),
  88.                     data->collapsed() ? _collapseIcon : _expandIcon,
  89.                     0,
  90.                     (PPOINTL)&rectl,
  91.                     selected ? selectedForeground.asRGBLong()
  92.                              : foreground.asRGBLong(),   
  93.                     selected ? selectedBackground.asRGBLong() 
  94.                              : background.asRGBLong(),   
  95.                     DBM_STRETCH );
  96.   }
  97.  
  98.   // Calculate the rectangle for the text based
  99.   // on the current font of the listbox.
  100.   IFont font( list );
  101.   rect
  102.    .moveBy( ISize( rect.height(), 0 ))
  103.    .sizeTo( ISize( font.textWidth( data->text() ) + 3,
  104.                    rect.size().height() ));
  105.   rectl = rect.asRECTL();
  106.                           
  107.   // Draw the text.
  108.   unsigned long style = DT_VCENTER | DT_LEFT;
  109.   WinDrawText( event.itemPresSpaceHandle(),
  110.                -1,
  111.                data->text(),
  112.                &rectl,
  113.                selected ? selectedForeground.asRGBLong()
  114.                         : foreground.asRGBLong(),
  115.                selected ? selectedBackground.asRGBLong()
  116.                         : background.asRGBLong(),
  117.                style );
  118.   return true;
  119. }
  120.