home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / celltk7b.zip / cell07b.zip / samples / nbsample.cpp < prev    next >
C/C++ Source or Header  |  1999-02-07  |  5KB  |  231 lines

  1. /*
  2. ** Module   :NBSAMPLE.C
  3. ** Abstract :
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. ** Log: Fri  19/02/1998     Created
  7. **
  8. */
  9.  
  10. #define INCL_WIN
  11. #define INCL_NLS
  12. #define INCL_DOS
  13. #define INCL_GPI
  14.  
  15. #include <os2.h>
  16. #include <multibar.h>
  17. #include <cell.h>
  18. #include <string.h>
  19.  
  20. /* Local procedures */
  21.  
  22. MRESULT EXPENTRY MainClientProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  23.  
  24. /* Static Variables */
  25.  
  26. CellDef cdLeftPane =
  27. {
  28.     CELL_WINDOW,
  29.     WC_LISTBOX,
  30.     "List",
  31.     LS_NOADJUSTPOS | WS_VISIBLE,
  32.     ID_LPANE
  33. };
  34.  
  35. CellDef cdRightPane =
  36. {
  37.     CELL_WINDOW,
  38.     WC_MLE,
  39.     "Sample Text",
  40.     MLS_BORDER | WS_VISIBLE,
  41.     ID_RPANE
  42. };
  43.  
  44. CellDef nbClient =
  45. {
  46.     CELL_VSPLIT | CELL_SPLITBAR | CELL_SPLIT40x60,
  47.     0,
  48.     "Notebook page",
  49.     0,
  50.     MAIN_FRAME,
  51.     &cdLeftPane,
  52.     &cdRightPane,
  53.     0,
  54.     0
  55. };
  56.  
  57. CellDef nbPanel   =
  58. {
  59.     CELL_WINDOW,
  60.     WC_NOTEBOOK,
  61.     "",
  62.     WS_VISIBLE        |
  63.     BKS_TABBEDDIALOG  |
  64.     BKS_MAJORTABTOP   |
  65.     0,
  66.     ID_NOTEBOOK
  67. };
  68.  
  69. CellDef mainFrame =
  70. {
  71.     CELL_HSPLIT,
  72.     0,
  73.     "Notebook Sample",
  74.     FCF_TITLEBAR | FCF_SYSMENU  | FCF_MENU |
  75.     FCF_MINMAX   | FCF_TASKLIST | FCF_SIZEBORDER |
  76.     0,
  77.     MAIN_FRAME,
  78.     &nbPanel,
  79.     0,
  80.     0,
  81.     MainClientProc
  82. };
  83.  
  84. ULONG mainItems[]=
  85. {
  86.     IDB_FILENEW , IDB_FILEOPEN, IDB_FILESAVE, IDB_FILSAVAS, TB_SEPARATOR,
  87.     IDB_EXIT    , TB_SEPARATOR, IDB_EDITCOPY, IDB_EDITCUT , IDB_EDITPAST,
  88.     IDB_EDITUNDO, TB_SEPARATOR, IDB_EDITFIND, IDB_EDITFNNX, IDB_EDITREPL,
  89.     TB_SEPARATOR, IDB_HELP    , IDB_ABOUT   , 0
  90. };
  91.  
  92. TbDef mainTb =
  93. {
  94.     TB_ATTACHED_TP | TB_BUBBLE,
  95.     ID_TOOLBAR,
  96.     mainItems
  97. };
  98.  
  99. MRESULT EXPENTRY MainClientProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  100. {
  101.     WindowCellCtlData *pWCtlData = 0;
  102.  
  103.     pWCtlData = (WindowCellCtlData *)WinQueryWindowULong(hwnd, QWL_USER);
  104.  
  105.     switch(msg)
  106.     {
  107.         case WM_COMMAND:
  108.             switch(SHORT1FROMMP(mp1))
  109.             {
  110.                 case IDB_EXIT:
  111.                     WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
  112.                     return ((MRESULT) NULL);
  113.             }
  114.             break;
  115.  
  116.         case WM_CLOSE:
  117.             WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
  118.             return ((MRESULT) NULL);
  119.     }
  120.     if(pWCtlData)
  121.         return pWCtlData->pOldProc(hwnd, msg, mp1, mp2);
  122.  
  123.     return WinDefWindowProc(hwnd, msg, mp1, mp2);
  124. }
  125.  
  126. INT main(VOID)
  127. {
  128.     HAB hab;
  129.     HMQ hmq;
  130.     QMSG qmsg;
  131.     HWND hwndFrame;
  132.     SWP swp;
  133.  
  134.     hab = WinInitialize(0);
  135.  
  136.     if(!hab)
  137.     {
  138.         return -1;
  139.     }
  140.  
  141.     hmq = WinCreateMsgQueue(hab, 0);
  142.  
  143.     if(!hmq)
  144.     {
  145.         WinTerminate(hab);
  146.         return -2;
  147.     }
  148.  
  149.     ToolkitInit(hab);
  150.  
  151.     WinQueryWindowPos(HWND_DESKTOP, &swp);
  152.  
  153.     hwndFrame = CreateCell(&mainFrame, HWND_DESKTOP, 0);
  154.  
  155.     if(hwndFrame)
  156.     {
  157.         ULONG ulPageId;
  158.         HWND hwndList;
  159.         HWND hwndTb;
  160.         HWND hwndNb;
  161.         HWND hwndPage;
  162.         CHAR cText[256];
  163.         static CHAR ppNbFont[] = "9.WarpSans";
  164.         static CHAR cPage[] = "Page ";
  165.         static CHAR cListItem[] = "List Item ";
  166.         int i,j;
  167.  
  168.         hwndNb   = CellWindowFromID(hwndFrame, ID_NOTEBOOK);
  169.         WinSetPresParam(hwndNb,
  170.                         PP_FONTNAMESIZE,
  171.                         sizeof(ppNbFont),
  172.                         ppNbFont);
  173.  
  174.         for(i = 0; i < 15; i++)
  175.         {
  176.             ulPageId = (ULONG) WinSendMsg(hwndNb,
  177.                                           BKM_INSERTPAGE,
  178.                                           0,
  179.                                           MPFROM2SHORT(BKA_MAJOR |
  180.                                                        BKA_AUTOPAGESIZE,
  181.                                                        BKA_LAST));
  182.             strcpy(cText, cPage);
  183.             GenResIDStr(cText + sizeof(cPage) - 1, i + 1);
  184.             WinSendMsg(hwndNb,
  185.                        BKM_SETTABTEXT,
  186.                        MPFROMLONG(ulPageId),
  187.                        MPFROMP(cText));
  188.  
  189.             hwndPage = CreateCell(&nbClient, hwndNb, hwndNb);
  190.             hwndList = CellWindowFromID(hwndPage, ID_LPANE);
  191.  
  192.             for(j = 0; j < 15; j++)
  193.             {
  194.                 strcpy(cText, cListItem);
  195.                 GenResIDStr(cText + sizeof(cListItem) - 1, j + 1);
  196.  
  197.                 WinSendMsg(hwndList,
  198.                            LM_INSERTITEM,
  199.                            MPFROMSHORT(LIT_END),
  200.                            MPFROMP(cText));
  201.             }
  202.  
  203.             WinSendMsg(hwndNb,
  204.                        BKM_SETPAGEWINDOWHWND,
  205.                        MPFROMLONG(ulPageId),
  206.                        MPFROMHWND(hwndPage));
  207.         }
  208.  
  209.         WinSetWindowPos(hwndFrame, NULLHANDLE,
  210.                         swp.x + swp.cx / 8,
  211.                         swp.y + swp.cy / 8,
  212.                         (swp.cx / 4) * 3,
  213.                         (swp.cy / 4) * 3,
  214.                         SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW);
  215.  
  216.         CreateToolbar(hwndFrame, &mainTb);
  217.  
  218.         while (WinGetMsg(hab, &qmsg, 0, 0, 0))
  219.             WinDispatchMsg(hab, &qmsg);
  220.  
  221.         WinDestroyWindow(hwndFrame);
  222.     }
  223.  
  224.     WinDestroyMsgQueue(hmq);
  225.     WinTerminate(hab);
  226.  
  227.     return 0;
  228. }
  229.  
  230.  
  231.