home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / os2 / programm / 7139 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  5.1 KB

  1. Path: sparky!uunet!usc!news.service.uci.edu!orion.oac.uci.edu!lhoang
  2. From: lhoang@orion.oac.uci.edu (Long Hoang)
  3. Subject: Re: Multicolumn Listboxes
  4. Nntp-Posting-Host: orion.oac.uci.edu
  5. Message-ID: <2B3309CF.4495@news.service.uci.edu>
  6. Newsgroups: comp.os.os2.programmer
  7. Organization: University of California, Irvine
  8. Lines: 117
  9. Date: 19 Dec 92 11:38:55 GMT
  10. References: <BzCttq.569@aplcenmp.apl.jhu.edu>
  11.  
  12. In article <BzCttq.569@aplcenmp.apl.jhu.edu> robbar@aplcenmp.apl.jhu.edu (Robert Baruch) writes:
  13. >Anyone have any code to perform multicolumn listbox insertions?
  14. >This would be a great help to me if someone knew or had the source
  15. >to do this!
  16. >
  17. >Thanks,
  18. >
  19. >Rob Baruch
  20.  
  21.    Here is my clumsy solution:
  22.  
  23.    In resource file, the list box has the style LS_OWNERDRAW
  24.  
  25.    Upon receiving LM_INSERTITEM, either from WinSendMsg() or the macro
  26.        WinInsertLboxItem(), the window procedure for the parent window
  27.        of the list box will receive the 2 message:
  28.  
  29.       WM_MEASUREITEM:
  30.                 // must return a value here for the height of the item
  31.                 // in the list box. This value can be determind correctly
  32.                 // when you have the information passed to you in WM_DRAWITEM
  33.                 // which includes the presentation space handle, you then
  34.                 // can approximate item height.
  35.           return(MRFROM2SHORT((SHORT)item_height, 0));
  36.           break;
  37.  
  38.       WM_DRAWITEM:
  39.           {
  40.               POWNERITEM powneritem;
  41.  
  42.               powneritem = (POWNERITEM)mp2;
  43.  
  44.                         // if un/hightlighting resulting from selection
  45.                         // I let the listbox do it.
  46.               if (powneritem->fsState != pwoneritem->fsStateOld)
  47.                   return((MRESULT)1);
  48.  
  49.               if (!itemheight) {    // set item height, once
  50.                   temprecl.xLeft = 0;       // make it large enough
  51.                   temprecl.xRight = 10000;
  52.                   temprecl.yBottom = 0;
  53.                   temprecl.yTop = 10000;
  54.                   WinDrawText(powneritem->hps,
  55.                               -1,
  56.                               "AAAAA",  // dummy string, should be worst case
  57.                               &temprecl,
  58.                               0L,
  59.                               0L,
  60.                               DT_QUERYEXTENT);
  61.                   itemheight = temprecl.yTop - temprecl.yBottom;
  62.                   WinSendDlgItemMsg(hwndDlg,
  63.                                     VIEWART_LISTBOX,
  64.                                     LM_SETITEMHEIGHT,
  65.                                     (MPARAM)itemheight,
  66.                                     (MPARAM)0);
  67.               }
  68.               WinSendDlgItemMsg(hwndDlg,
  69.                                 SHORT1FROMMP(mp1),
  70.                                 LM_QUERYITEMTEXT,
  71.                                 MPFROM2SHORT(powneritem->idItem, sizeof(str)),
  72.                                 MPFROMP(str));
  73.               p = str;   // str holds the record of fields delimited by blanks
  74.                          // You can design your own format. 
  75.  
  76.                          // gettoken parses the fields for seperate drawings
  77.               p = gettoken(p, firstfield, FIRSTFIELD_LEN);
  78.               p = gettoken(p, secondfield, SECONDFIELD_LEN);
  79.               p = gettoken(p, thirdfield, THIRDFIELD_LEN);
  80.  
  81.               increment = powneritem->rclItem.xRight / 10; 
  82.  
  83.                     // first field occupies 40 percent of the list box witdh
  84.                     // second field occupies 20 percent of the list box witdh
  85.                     // third field occupies the rest
  86.  
  87.               WinDrawText(powneritem->hps,
  88.                           -1,
  89.                           firstfield,
  90.                           &powneritem->rclItem,
  91.                           0L,
  92.                           0L,
  93.                           DT_TEXTATTRS | DT_ERASERECT);
  94.  
  95.               powneritem->rclItem.xLeft += 4 * increment;
  96.               WinDrawText(powneritem->hps,
  97.                           -1,
  98.                           secondfield,
  99.                           &powneritem->rclItem,
  100.                           0L,
  101.                           0L,
  102.                           DT_TEXTATTRS | DT_ERASERECT);
  103.  
  104.               powneritem->rclItem.xLeft += 2 * increment;
  105.               WinDrawText(powneritem->hps,
  106.                           -1,
  107.                           thirdfield,
  108.                           &powneritem->rclItem,
  109.                           0L,
  110.                           0L,
  111.                           DT_TEXTATTRS | DT_ERASERECT);
  112.                   // We achieve proportionality this way going from one
  113.                   // graphic resolution to the other, especially when you have
  114.                   // static text header for each column.
  115.  
  116.               return((MRESULT)1);
  117.           }
  118.           break;
  119.  
  120.      I got the idea from the book 
  121.          Programming Guide, Volume II. OS/2 2.0 Technical Library.
  122.          Chapter 9. List Box Controls.
  123.  
  124.      Your list box might be more complicated than this. However, I'm
  125.      almost sure that the list box must be LS_OWNERDRAW'ed. Please correct
  126.      me if otherwise.
  127.  
  128. ==========================================================================
  129.