home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dho.zip / DHO / SRC / SOURCE.ZIP / notebk.cc < prev    next >
C/C++ Source or Header  |  1995-08-27  |  10KB  |  404 lines

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: notebk.cc 1.5 1995/08/27 08:13:00 teb Exp $ */
  8.  
  9.  
  10. #define INCL_DOS
  11. #define INCL_WIN
  12. #include<os2.h>
  13. #include"notebk.h"
  14.  
  15. #include<stdlib.h>
  16. #include<string.h>
  17.  
  18.  
  19.  
  20. ULONG TNotebook::setStyleULONG()
  21. {
  22.    ULONG tmp = 0;
  23.  
  24.    if (fNBKattrs.fBindingStyle == spiral)
  25.       tmp = BKS_SPIRALBIND;
  26.    else 
  27.       tmp = BKS_SOLIDBIND;
  28.  
  29.    return tmp;
  30. }   
  31.  
  32.  
  33. //-------------------------------------------------------------------
  34. //  TNotebook
  35. TNotebook::TNotebook(ULONG id, TWinBase *parent):
  36.    TWindow(id, parent)
  37. {
  38.    fId = id;
  39.    fParent = parent;
  40.  
  41.    fNBKattrs.fBindingStyle = spiral;
  42.    fNBKattrs.fBindingSide = bnd_left;
  43.    fNBKattrs.fTabShape = tabSquare;
  44.    
  45.    fNumPages = fX = fY = fWidth = fHeight = 0;
  46.    fPageIDs = NULL;
  47. }
  48.  
  49.  
  50. //-------------------------------------------------------------------
  51. //  TNotebook
  52. TNotebook::TNotebook(ULONG id, TWinBase *parent, binding bnd):
  53.    TWindow(id, parent)
  54. {
  55.    fNBKattrs.fBindingStyle = bnd;
  56.    fNBKattrs.fBindingSide = bnd_left;
  57.    fNBKattrs.fTabShape = tabSquare;
  58.    fNumPages = fX = fY = fWidth = fHeight = 0;
  59.    fPageIDs = NULL;
  60. }
  61.  
  62.  
  63.  
  64. //-------------------------------------------------------------------
  65. //  TNotebook
  66. TNotebook::TNotebook(ULONG id, TWinBase *parent, binding bnd, LONG x, LONG y,
  67.                             LONG width, LONG height):
  68.    TWindow(id, parent)
  69. {
  70.    fNBKattrs.fBindingStyle = bnd;
  71.    fNBKattrs.fBindingSide = bnd_left;
  72.    fNBKattrs.fTabShape = tabSquare;
  73.    fX = x;
  74.    fY = y;
  75.    fHeight = height;
  76.    fWidth = width;
  77.    fNumPages = 0;
  78.    fPageIDs = NULL;
  79. }
  80.  
  81.  
  82. //-------------------------------------------------------------------
  83. //  ~TNotebook
  84. TNotebook::~TNotebook()
  85. {
  86.    if (fPageIDs)
  87.       free(fPageIDs);
  88. }
  89.  
  90.  
  91. //-------------------------------------------------------------------
  92. //  Init
  93. BOOL TNotebook::init()
  94. {
  95.    ULONG side, shape, bindStyle;
  96.  
  97.    if (fNBKattrs.fBindingSide == bnd_right)
  98.       side = BKS_BACKPAGESTL;
  99.    else if (fNBKattrs.fBindingSide == bnd_bottom)
  100.       side = BKS_BACKPAGESTR;
  101.    else if (fNBKattrs.fBindingSide == bnd_top)
  102.       side = BKS_BACKPAGESBL;
  103.    else if (fNBKattrs.fBindingSide == bnd_left)
  104.       side = BKS_BACKPAGESBR;
  105.  
  106.    if (fNBKattrs.fTabShape == tabSquare)
  107.       shape = BKS_SQUARETABS;
  108.    else if (fNBKattrs.fTabShape == tabRound)
  109.       shape = BKS_ROUNDEDTABS;
  110.    else
  111.       shape = BKS_POLYGONTABS;
  112.  
  113.    if (fNBKattrs.fBindingStyle == spiral)
  114.       bindStyle = BKS_SPIRALBIND | side | shape;
  115.    else
  116.       bindStyle =  BKS_SOLIDBIND | side | shape;
  117.  
  118.  
  119.    hwnd = WinCreateWindow(
  120.                fParent->getHWND(),
  121.                WC_NOTEBOOK,
  122.                (PSZ)NULL,
  123.                bindStyle,
  124.                fX, fY, fWidth, fHeight, 
  125.                fParent->getHWND(),
  126.                HWND_BOTTOM,
  127.                fId,
  128.                NULL,
  129.                NULL);
  130.  
  131.    return ( hwnd!= (HWND)NULL);
  132. }
  133.  
  134.  
  135.  
  136. //-------------------------------------------------------------------
  137. //  insertPageFirst
  138. ULONG TNotebook::insertPageFirst(TWindow *page)
  139. {
  140.    return insertPageFirst(page, NULL, tabNone, NULL);
  141. }
  142.  
  143. //-------------------------------------------------------------------
  144. //  insertPageFirst
  145. ULONG TNotebook::insertPageFirst(TWindow *page, char *sline)
  146. {
  147.    return insertPageFirst(page, NULL, tabNone, sline);
  148. }
  149.  
  150.  
  151. //-------------------------------------------------------------------
  152. //  insertPageFirst
  153. ULONG TNotebook::insertPageFirst(TWindow *page, tabStyle tstyle, char *tabText)
  154. {
  155.    return insertPageFirst(page, NULL, tstyle, tabText);
  156. }
  157.  
  158.  
  159. //-------------------------------------------------------------------
  160. //  insertPageFirst
  161. ULONG TNotebook::insertPageFirst(TWindow *page, char *slineText,
  162.                                  tabStyle tstyle, char *tabText)
  163. {
  164.    ULONG style, tab, sline, pageId;
  165.    ULONG *tmpArray;
  166.  
  167.    style = BKA_AUTOPAGESIZE;
  168.  
  169.    if (tstyle == tabMajor)
  170.        style |= BKA_MAJOR;
  171.    else if ( tstyle == tabMinor)
  172.        style |= BKA_MINOR;
  173.   
  174.    if (slineText)
  175.        style |= BKA_STATUSTEXTON;
  176.  
  177.    
  178.    pageId = (ULONG)WinSendMsg(hwnd, BKM_INSERTPAGE,(MPARAM)NULL,
  179.                      MPFROM2SHORT(style, BKA_FIRST));
  180.  
  181.    if (page)
  182.       associateWindow(pageId,page);
  183.  
  184.    if (slineText)
  185.       setStatusLineText(pageId, slineText);
  186.  
  187.    if (tabText)
  188.       setTabText(pageId, tabText);
  189.  
  190.    fNumPages++;
  191.  
  192.    tmpArray = (ULONG*)malloc(sizeof(ULONG)*fNumPages);
  193.    if (tmpArray)
  194.    {
  195.       if (fPageIDs)
  196.          memcpy(&tmpArray[1], fPageIDs, sizeof(ULONG)*(fNumPages-1));
  197.       tmpArray[0] = pageId;
  198.       if (fPageIDs)
  199.          free(fPageIDs);
  200.       fPageIDs = tmpArray;
  201.    }
  202.  
  203.    return pageId;
  204. }
  205.  
  206.  
  207.  
  208. //-------------------------------------------------------------------
  209. //  insertPageLast
  210. ULONG TNotebook::insertPageLast(TWindow *page)
  211. {
  212.    return insertPageLast(page, NULL, tabNone, NULL);
  213. }
  214.  
  215.  
  216.  
  217. //-------------------------------------------------------------------
  218. //  insertPageLast
  219. ULONG TNotebook::insertPageLast(TWindow *page, char *sline)
  220. {
  221.    return insertPageLast(page, sline, tabNone, NULL);
  222. }
  223.  
  224.  
  225. //-------------------------------------------------------------------
  226. // insertPageLast
  227. ULONG TNotebook::insertPageLast(TWindow *page, tabStyle tstyle, char *tabText)
  228. {
  229.    return insertPageLast(page, NULL, tstyle, tabText);
  230. }
  231.  
  232.  
  233. //-------------------------------------------------------------------
  234. //  insertPageLast
  235. ULONG TNotebook::insertPageLast(TWindow *page, char *slineText,
  236.                                 tabStyle tstyle, char *tabText)
  237. {
  238.    ULONG style, tab, sline, pageId;
  239.    ULONG *tmpArray;
  240.  
  241.    if (tstyle == tabMajor)
  242.        tab = BKA_MAJOR;
  243.    else if ( tabMinor == tabMinor)
  244.        tab = BKA_MINOR;
  245.    else 
  246.        tab=0;
  247.  
  248.    if (slineText)
  249.        sline = BKA_STATUSTEXTON;
  250.    else
  251.        sline = 0;
  252.  
  253.    style = tab | sline | BKA_AUTOPAGESIZE;
  254.  
  255.    pageId = (ULONG)WinSendMsg(hwnd, BKM_INSERTPAGE,(MPARAM)NULL,
  256.                  MPFROM2SHORT(style, BKA_LAST));
  257.  
  258.    if (page)
  259.       associateWindow(pageId,page);
  260.  
  261.    if (slineText)
  262.       setStatusLineText(pageId, slineText);
  263.  
  264.    if (tabText)
  265.       setTabText(pageId,tabText);
  266.  
  267.    fNumPages++;
  268.    
  269.    tmpArray = (ULONG*)realloc(fPageIDs, sizeof(ULONG)*fNumPages);
  270.    if (tmpArray)
  271.    {
  272.       fPageIDs = (ULONG*)tmpArray;
  273.       fPageIDs[fNumPages-1] = pageId;
  274.    }
  275.  
  276.    return pageId;
  277.  
  278. }
  279.  
  280.  
  281. //-------------------------------------------------------------------
  282. //  setStatusLineText
  283. void TNotebook::setStatusLineText(ULONG pageId, char *slineText)
  284. {
  285.    WinSendMsg(hwnd, BKM_SETSTATUSLINETEXT, 
  286.              (MPARAM)pageId, MPFROMP((PSZ)slineText));
  287. }
  288.  
  289.  
  290. //-------------------------------------------------------------------
  291. //  setStatusLineText
  292. void TNotebook::setTabText(ULONG pageId, char *slineText)
  293. {
  294.    WinSendMsg(hwnd, BKM_SETTABTEXT,
  295.              (MPARAM)pageId, MPFROMP((PSZ)slineText));
  296. }
  297.  
  298.  
  299.  
  300. //-------------------------------------------------------------------
  301. //  setStatusLineText
  302. void TNotebook::setTabBitmap(ULONG pageId, HBITMAP hbm)
  303. {
  304.    WinSendMsg(hwnd, BKM_SETTABBITMAP, 
  305.              (MPARAM)pageId, MPFROMLONG((ULONG)hbm));
  306. }
  307.  
  308.  
  309. //-------------------------------------------------------------------
  310. //  deletePage
  311. void TNotebook::deletePage(ULONG pageid)
  312. {
  313.    BOOL cont;
  314.    LONG i, j;
  315.    ULONG *tmpArray;
  316.  
  317.    WinSendMsg(hwnd, BKM_DELETEPAGE, 
  318.               MPFROMLONG(pageid), (MPARAM)BKA_SINGLE);
  319.  
  320.    cont = TRUE;
  321.    i = 0;
  322.    while (cont)
  323.    {
  324.       if (fPageIDs[i] == pageid)
  325.       {
  326.          for (j=i; j<fNumPages; j++)
  327.             fPageIDs[j]=fPageIDs[j+1];
  328.             tmpArray = (ULONG*)realloc(fPageIDs, sizeof(ULONG)*(fNumPages-1));
  329.             if (tmpArray)
  330.             {
  331.               fPageIDs = (ULONG*)tmpArray;
  332.             }
  333.       }
  334.  
  335.       i++;
  336.       if (i==fNumPages)
  337.         cont=FALSE;
  338.    }
  339.  
  340.    fNumPages--;
  341. }
  342.  
  343.  
  344.  
  345. //-------------------------------------------------------------------
  346. //  deleteFirstPage
  347. void TNotebook::deleteFirstPage()
  348. {
  349.    deletePage(fPageIDs[0]);
  350. }
  351.  
  352.  
  353.  
  354. //-------------------------------------------------------------------
  355. //  deleteLastPage
  356. void TNotebook::deleteLastPage()
  357. {
  358.    deletePage(fPageIDs[fNumPages-1]);
  359. }
  360.  
  361. //-------------------------------------------------------------------
  362. //
  363. void TNotebook::associateWindow(ULONG pageId, TWindow *win)
  364. {
  365.    WinSendMsg(hwnd, BKM_SETPAGEWINDOWHWND,
  366.               MPFROMLONG(pageId), MPFROMHWND(win->getHWND()));
  367. }
  368.  
  369.  
  370. //-------------------------------------------------------------------
  371. void TNotebook::setMajorTabSize(ULONG x, ULONG y)
  372. {
  373.    WinSendMsg(hwnd, BKM_SETDIMENSIONS,
  374.               MPFROM2SHORT(x, y), MPFROMSHORT(BKA_MAJORTAB));
  375.  
  376. }
  377.  
  378.  
  379. //-------------------------------------------------------------------
  380. void TNotebook::setMinorTabSize(ULONG x, ULONG y)
  381. {
  382.    WinSendMsg(hwnd, BKM_SETDIMENSIONS,
  383.               MPFROM2SHORT(x, y), MPFROMSHORT(BKA_MINORTAB));
  384. }
  385.  
  386. //-------------------------------------------------------------------
  387. //
  388. void TNotebook::associateDlog(ULONG pageId, ULONG dlogRes)
  389. {
  390.    SEL sel = NULL;
  391.    PDLGTEMPLATE pDlgt;
  392.    HWND hwndPage;
  393.  
  394. /*   DosGetResource(NULL, RT_DIALOG, dlogRes, (DLGTEMPLATE*)&sel);
  395.  
  396.    handPage = WinCreateDlg(HWND_DESKTOP, hwnd,    
  397.    pDlgt = MAKEP(sel, 0);
  398.    WinSendMsg(hwnd, BKM_SETPAGEWINDOWHWND,
  399.               MPFROMLONG(pageId), MPFROMHWND(hwndPage));
  400. */
  401. }
  402.  
  403.  
  404.