home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lstbx1.zip / LISTBOX.H < prev    next >
Text File  |  1994-01-07  |  13KB  |  291 lines

  1.  
  2. /* Program name: Listbox.C    Title: A List Box    Replacement        */
  3. /*                                    */
  4. /* OS/2    Developer Magazine, Issue:  Jan    '94, page 66                    */
  5. /* Author:  Mark Benge       IBM Corp.                    */
  6. /*        Matt Smith       Prominare Inc.                */
  7. /* Description:     Replacement for OS/2 List Box,    first of a series.    */
  8. /*                                    */
  9. /* Program Requirements:  OS/2 2.x                    */
  10. /*              IBM C    Set/2                    */
  11. /*              WATCOM C 386/9.0                */
  12. /*              Borland C++ for OS/2                */
  13. /*              Zortech C++ for OS/2                */
  14. /*              OS/2 Toolkit                    */
  15.  
  16. /* Copyright ╕ International Business Machines Corp. 1991-1994        */
  17. /* Copyright ╕ 1989-1994  Prominare Inc.  All Rights Reserved.        */
  18.  
  19. /* listbox.h       Created:    1993-10-08  Revised:    1993-12-18    */
  20.  
  21. /* List    Box Control Constant Definition    Header                */
  22.  
  23. /* Functions are defined with strong typing to insure correct usage    */
  24. /* within the final program and    correct    linkage                */
  25.  
  26.  
  27. /* --- Memory Types ---------------------------------------------------    */
  28.  
  29. typedef    ULONG HHEAPMEM;
  30. #define    HALLOC_DEFAULT    0xffffffffUL
  31.  
  32. /* --- Internal    Structures --------------------------------------------    */
  33.  
  34. #define    USER_RESERVED       8       /* Control Reserved Memory Size    */
  35.  
  36. #define    QUCWP_WNDP (QWL_USER + 4)  /* Pointer to Internal Control Data    */
  37.  
  38. typedef    struct _LISTITEM
  39.    {
  40.    PSZ         pszText;           /* Text Pointer            */
  41.    ULONG     cText;           /* Text Length            */
  42.    ULONG     ulHandle;           /* User Defined Handle        */
  43.    ULONG     fl;           /* Flags (Upper 16 bits old Flags)    */
  44.    LONG         cyItem;           /* Item Height            */
  45.    LONG         cxItem;           /* Item Width            */
  46.    ULONG     iIndex;           /* Index Position            */
  47.    } LISTITEM ;
  48.  
  49. typedef    LISTITEM *PLISTITEM;
  50.  
  51. #define    LI_CLEAR       0x00000000UL
  52. #define    LI_SELECTED       0x00000001UL
  53. #define    LI_FOCUS       0x00000002UL
  54. #define    LI_INSERTED       0x00001000UL
  55. #define    LI_SELECTEDPREV       0x00000010UL
  56. #define    LI_SELECTEDOLD       0x00010000UL
  57. #define    LI_FOCUSOLD       0x00020000UL
  58. #define    LI_INSERTEDOLD       0x10000000UL
  59. #define    LI_SELECTEDPREVOLD 0x00100000UL
  60.  
  61. typedef    struct _LISTCOL
  62.    {
  63.    HHEAPMEM  hHeap;           /* Heap Handle            */
  64.    PLISTITEM ali;           /* List Item    Array Pointer        */
  65.    } LISTCOL ;
  66.  
  67. typedef    LISTCOL    *PLISTCOL;
  68.  
  69. typedef    struct _LISTBOXWIN
  70.    {
  71.          /***********************************************************/
  72.          /*    Window Management                    */
  73.          /***********************************************************/
  74.    HHEAPMEM  hHeap;           /* Heap Handle            */
  75.    HAB         hAB;           /* Anchor Block Handle        */
  76.    HWND         hWnd;           /* Control Window Handle        */
  77.    HWND         hwndOwner;           /* Owner Window Handle        */
  78.    HWND         hwndParent;       /* Parent Window Handle        */
  79.    HPOINTER  hptr;           /* Selection    Mouse Pointer        */
  80.          /***********************************************************/
  81.          /*    Styles/ID                        */
  82.          /***********************************************************/
  83.    ULONG     flStyle;           /* Style Flags            */
  84.    ULONG     id;           /* Window ID                */
  85.          /***********************************************************/
  86.          /*    Flags                            */
  87.          /***********************************************************/
  88.    BOOL         fFocus;           /* Focus Flag            */
  89.    BOOL         fDblClk;           /* Mouse Double Click Flag        */
  90.    BOOL         fCapture;           /* Mouse Capture Flag        */
  91.    BOOL         fTimer;           /* Mouse Capture Flag        */
  92.    BOOL         fVisible;           /* List Box Visible Flag        */
  93.    BOOL         fDelaySort;       /* Delay Sort Flag            */
  94.    BOOL         fFocusShown;       /* FocusShown Flag            */
  95.          /***********************************************************/
  96.          /*    Window Display                        */
  97.          /***********************************************************/
  98.    LONG         cx;           /* List Box Width            */
  99.    LONG         cy;           /* List Box Height            */
  100.    LONG         cxWindow;           /* List Box Width  (Actual)        */
  101.    LONG         cyWindow;           /* List Box Height (Actual)        */
  102.    LONG         lClrBackground;       /* Background Colour            */
  103.    LONG         lClrBorder;       /* Border Colour            */
  104.    LONG         lClrHilite;       /* Hilite Colour            */
  105.    LONG         lClrHiliteBackground; /* Hilite Background    Colour        */
  106.    LONG         lClrList;           /* List Colour            */
  107.    LONG         lClrText;           /* Text Colour            */
  108.    RECTL     rcl;           /* Window Rectangle            */
  109.    RECTL     rclCorner;           /* Scroll Corner Rectangle        */
  110.    RECTL     rclAdjusted;       /* Adjusted Top Rectangle        */
  111.    POINTL    aptlOutside[5];       /* Border Points Array        */
  112.    POINTL    aptlInside[5];       /* Border Points Array        */
  113.    LONG         cptl;           /* Border Points Array Count        */
  114.          /***********************************************************/
  115.          /*    Scroll Bars                        */
  116.          /***********************************************************/
  117.    SWP         aswp[4];           /* Scroll Bar Position Array        */
  118.    HWND         hwndScrollBottom;       /* Bottom Scroll Bar    Window Handle    */
  119.    HWND         hwndScrollLeft;       /* Left Scroll Bar Window Handle    */
  120.    HWND         hwndScrollRight;       /* Right Scroll Bar Window Handle    */
  121.    HWND         hwndScrollTop;       /* Top Scroll Bar Window Handle    */
  122.    LONG         cxScroll;           /* Vertical Scroll Bar Width        */
  123.    LONG         cyScroll;           /* Horizontal Scroll    Bar Height    */
  124.          /***********************************************************/
  125.          /*    Scroll Bar Indices                    */
  126.          /***********************************************************/
  127.    LONG         cHorzScroll;       /* Horizontal Scroll    Count        */
  128.    LONG         cVertScroll;       /* Vertical Scroll Count        */
  129.    LONG         iHorzScroll;       /* Horizontal Scroll    Position    */
  130.    LONG         iVertScroll;       /* Vertical Scroll Position        */
  131.          /***********************************************************/
  132.          /*    Indices                            */
  133.          /***********************************************************/
  134.    LONG         iAnchor;           /* Anchor Item Index            */
  135.    LONG         iAnchorLast;       /* Last Anchor Item Index        */
  136.    LONG         iFocus;           /* Focus Item Index            */
  137.    LONG         iFocusLast;       /* Last Focus Item Index        */
  138.    LONG         iSelected;           /* Selected Item Index        */
  139.    LONG         iSelectedLast;       /* Last Selected Item Index        */
  140.          /***********************************************************/
  141.          /*    List Box Limits                        */
  142.          /***********************************************************/
  143.    LONG         cCharsPage;       /* Characters per Page        */
  144.    LONG         cLinesPage;       /* Lines per    Page            */
  145.    LONG         cxItem;           /* Longest Horizontal Item        */
  146.    LONG         cyItem;           /* Item Height            */
  147.    LONG         xChar;           /* Character    Width            */
  148.    LONG         yAscender;           /* Character    Ascender Height        */
  149.          /***********************************************************/
  150.          /*    List Box List                        */
  151.          /***********************************************************/
  152.    PLISTCOL  plc;           /* List Column Array            */
  153.    LONG         cColumns;           /* Columns Count            */
  154.    LONG         cItems;           /* Items Count            */
  155.    BOOL         fDirty;           /* Dirty Update Flag            */
  156.    } LISTBOXWIN    ;
  157.  
  158. typedef    LISTBOXWIN *PLISTBOXWIN;
  159.  
  160. #define    SWP_VERT       0
  161. #define    SWP_HORZ       1
  162.  
  163. #define    IDT_SCROLL  512UL
  164.  
  165. typedef    struct _LISTBOXCDATA
  166.    {
  167.    ULONG    cb;               /* Structure    Size            */
  168.    ULONG    ulVersion;           /* Structure    Version    NUmber        */
  169.    ULONG    cItems;           /* Items Count            */
  170.    BYTE        abList[1];           /* Array List Start            */
  171.    } LISTBOXCDATA ;
  172.  
  173. typedef    LISTBOXCDATA *PLISTBOXCDATA;
  174.  
  175. #define    LBV_100       0x00010000UL       /* Control Data Version Number    */
  176.  
  177. typedef    struct _LISTBOXITEM       /* lbi */
  178.    {
  179.    PSZ        pszText;           /* Item Text    Pointer            */
  180.    ULONG    ulHandle;           /* Item Handle            */
  181.    } LISTBOXITEM ;
  182.  
  183. typedef    LISTBOXITEM *PLISTBOXITEM;
  184.  
  185. /************************************************************************/
  186. /************************************************************************/
  187. /*                                    */
  188. /*     Inline Macros                            */
  189. /*                                    */
  190. /************************************************************************/
  191. /************************************************************************/
  192.  
  193. #define    SaveSelectState(iCol, iSelected)  { if ( plbw->flStyle & LS_OWNERDRAW )\
  194.    if (    (plbw->plc[iCol].ali[iSelected].fl & LI_SELECTED) && fItemVisible(plbw,    iSelected) )\
  195.        plbw->plc[iCol].ali[iSelected].fl |= LI_SELECTEDPREV;\
  196.    else\
  197.        plbw->plc[iCol].ali[iSelected].fl &= ~LI_SELECTEDPREV; }
  198.  
  199. /************************************************************************/
  200. /************************************************************************/
  201. /*                                    */
  202. /*     Extended    Messages                        */
  203. /*                                    */
  204. /************************************************************************/
  205. /************************************************************************/
  206.  
  207. #define    LMX_CALCLINECOUNT      0x0180UL
  208. #define    LMX_CALCSIZE           0x0181UL
  209. #define    LMX_COPY           0x0182UL
  210. #define    LMX_CUT               0x0183UL
  211. #define    LMX_PASTE           0x0184UL
  212. #define    LMX_QUERYITEMCOUNT     0x0185UL
  213. #define    LMX_QUERYITEMRECT      0x0186UL
  214. #define    LMX_QUERYSELECTLIST    0x0187UL
  215. #define    LMX_RESETLIST           0x0188UL
  216. #define    LMX_SELECTALL           0x0189UL
  217. #define    LMX_SELECTITEMBITMAP   0x018aUL
  218. #define    LMX_SETARRAY           0x018bUL
  219. #define    LMX_SETARRAYHANDLES    0x018cUL
  220. #define    LMX_SETITEMBITMAPS     0x018dUL
  221. #define    LMX_SETITEMCOUNT       0x018eUL
  222. #define    LMX_SORT           0x018fUL
  223. #define    LMX_SETARRAYITEMS      0x0190UL
  224. #define    LMX_ADDARRAY           0x0191UL
  225.  
  226. /************************************************************************/
  227. /************************************************************************/
  228. /*                                    */
  229. /*     Prototypes                            */
  230. /*                                    */
  231. /************************************************************************/
  232. /************************************************************************/
  233.  
  234. /* --- EventMgr.C Prototype Definitions    -------------------------------    */
  235.  
  236. MRESULT    mrNotifyOwner(PLISTBOXWIN plbw,    ULONG ulNotification);
  237.  
  238. /* --- HeapMgr.C Prototype Definitions --------------------------------    */
  239.  
  240. HHEAPMEM HeapAlloc(ULONG cbInitial, ULONG cbNewBlks);
  241. VOID     HeapRelease(HHEAPMEM hHeap);
  242. ULONG     HeapSize(HHEAPMEM hHeap);
  243.  
  244. VOID     HeapStatus(HHEAPMEM hHeap, PULONG pcBlocks, PULONG pulSize,
  245.             PULONG pulUsed, PULONG pulFree, PULONG pulUnused, PULONG pulOverhead);
  246. VOID     HeapDisplayStatus(HHEAPMEM hHeap);
  247.  
  248. PVOID     HeapMalloc(HHEAPMEM hHeap, ULONG cbSize);
  249. PVOID     HeapCalloc(HHEAPMEM hHeap, ULONG cItems, ULONG    cbSize);
  250. PVOID     HeapRealloc(HHEAPMEM hHeap, PVOID pv, ULONG cbSize);
  251. VOID     HeapFree(HHEAPMEM hHeap, PVOID    pv);
  252.  
  253. /* --- ListBox.C Prototype Definitions --------------------------------    */
  254.  
  255. BOOL EXPENTRY fRegisterListBox(HAB hAB);
  256. VOID UpdateScrollBars(PLISTBOXWIN plbw);
  257. VOID DrawSelection(PLISTBOXWIN plbw, LONG iItem);
  258. VOID DrawItemSelection(PLISTBOXWIN plbw, LONG iItem);
  259. BOOL fItemVisible(PLISTBOXWIN plbw, LONG iItem);
  260. LONG lItemFromPoint(PLISTBOXWIN    plbw, LONG y);
  261. MRESULT    EXPENTRY ScrollBarWndProc(HWND hWnd, ULONG msg,    MPARAM mp1, MPARAM mp2);
  262. MRESULT    EXPENTRY ListBoxWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  263.  
  264. /* --- ListMgr.C Prototype Definitions --------------------------------    */
  265.  
  266. VOID SaveExtendedState(PLISTBOXWIN plbw);
  267. VOID RestoreExtendedState(PLISTBOXWIN plbw);
  268. BOOL fSelectMultipleItem(PLISTBOXWIN plbw, LONG    iCol, LONG iSelected, BOOL fSelect);
  269. BOOL fSelectItem(PLISTBOXWIN plbw, LONG    iCol, LONG iItem, BOOL fSelect);
  270. VOID SelectExtendedItems(PLISTBOXWIN plbw, LONG    iCol, LONG iSelected);
  271. VOID SetControlDataList(PLISTBOXWIN plbw, ULONG    cItems,    PBYTE pb);
  272. MRESULT    EXPENTRY mrBaseListHandler(HWND    hWnd, ULONG msg, MPARAM    mp1, MPARAM mp2);
  273. MRESULT    EXPENTRY mrExtendedListHandler(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2);
  274.  
  275. /* --- TraffMgr.C Prototype Definitions    -------------------------------    */
  276.  
  277. LONG lGetPresParam(HWND    hWnd, ULONG ulID1, ULONG ulID2,    LONG lDefault);
  278. BOOL fAddHorzScroll(HWND hWnd, PLISTBOXWIN plbw);
  279. VOID MeasureItem(PLISTBOXWIN plbw, LONG    lMaxBaselineExt);
  280. VOID SizeListBox(PLISTBOXWIN plbw);
  281. VOID FocusChange(PLISTBOXWIN plbw, LONG    iFocus,    BOOL fSet);
  282. VOID RemoveFocus(PLISTBOXWIN plbw);
  283. VOID SetFocus(PLISTBOXWIN plbw,    LONG iFocus);
  284. VOID DrawItemSelection(PLISTBOXWIN plbw, LONG iItem);
  285. BOOL fDecodeMouse(PLISTBOXWIN plbw, MPARAM mp1);
  286. BOOL fDecodeExtendedMouse(PLISTBOXWIN plbw, MPARAM mp1,    BOOL fBlock);
  287. VOID LineUp(PLISTBOXWIN    plbw);
  288. VOID LineDown(PLISTBOXWIN plbw);
  289. VOID DragUp(PLISTBOXWIN    plbw);
  290. VOID DragDown(PLISTBOXWIN plbw);
  291.