home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cell06d.zip / samples / status.c < prev    next >
C/C++ Source or Header  |  1999-01-24  |  7KB  |  288 lines

  1. /*
  2. ** Module   :MULTIBAR.C
  3. ** Abstract :Test and sample application for Cell toolkit procedures.
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. ** Log: Sun  08/02/98   Refined
  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.  
  19. /* Local procedures */
  20.  
  21. MRESULT EXPENTRY MainClientProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  22.  
  23. /* Static Variables */
  24.  
  25. CellDef cdLeftPane =
  26. {
  27.     CELL_WINDOW,
  28.     WC_LISTBOX,
  29.     "List",
  30.     LS_NOADJUSTPOS | WS_VISIBLE,
  31.     ID_LIST
  32. };
  33.  
  34. CellDef cdRightPane =
  35. {
  36.     CELL_WINDOW,
  37.     WC_MLE,
  38.     "SampleText",
  39.     MLS_BORDER | WS_VISIBLE,
  40.     ID_MLE
  41. };
  42.  
  43. CellDef rPanel =
  44. {
  45.     CELL_VSPLIT | CELL_SPLITBAR | CELL_SPLIT30x70,
  46.     0,
  47.     "Subwindow",
  48.     WS_VISIBLE,
  49.     ID_TOP,
  50.     &cdLeftPane,
  51.     &cdRightPane,
  52. };
  53.  
  54. CellDef Panel1 =
  55. {
  56.     CELL_WINDOW,
  57.     "StatusLine",
  58.     "",
  59.     WS_VISIBLE,
  60.     ID_STATUS
  61. };
  62.  
  63. CellDef mainClient =
  64. {
  65.     CELL_HSPLIT | CELL_FIXED | CELL_SIZE1,
  66.     0,
  67.     "Status Line Sample",
  68.     FCF_TITLEBAR | FCF_SYSMENU  | FCF_MENU |
  69.     FCF_MINMAX   | FCF_TASKLIST | FCF_SIZEBORDER |
  70.     0,
  71.     MAIN_FRAME,
  72.     &Panel1,
  73.     &rPanel,
  74.     0,                  //Frame subclass proc
  75.     MainClientProc,     //Client subclass proc
  76.     20                  //Status line hight
  77. };
  78.  
  79. ULONG mainItems[]=
  80. {
  81.     IDB_FILENEW ,
  82.     IDB_FILEOPEN,
  83.     IDB_FILESAVE,
  84.     IDB_FILSAVAS,
  85.     TB_SEPARATOR,
  86.     IDB_EXIT    ,
  87.     TB_SEPARATOR,
  88.     IDB_EDITCOPY,
  89.     IDB_EDITCUT ,
  90.     IDB_EDITFIND,
  91.     IDB_EDITFNNX,
  92.     IDB_EDITPAST,
  93.     IDB_EDITREPL,
  94.     IDB_EDITUNDO,
  95.     TB_SEPARATOR,
  96.     IDB_HELP    ,
  97.     IDB_ABOUT   ,
  98.     0
  99. };
  100.  
  101. TbDef mainTb =
  102. {
  103.     TB_VERTICAL | TB_ATTACHED_TP | TB_BUBBLE,
  104.     ID_TOOLBAR,
  105.     mainItems
  106. };
  107.  
  108. ULONG OKMsgBox(PSZ pszText)
  109. {
  110.     return WinMessageBox(HWND_DESKTOP,
  111.                          HWND_DESKTOP,
  112.                          pszText,
  113.                          "Cell Demo",
  114.                          0,
  115.                          MB_OK | MB_INFORMATION | MB_APPLMODAL);
  116. }
  117.  
  118. MRESULT EXPENTRY MainClientProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  119. {
  120.     WindowCellCtlData *pWCtlData = 0;
  121.  
  122.     pWCtlData = (WindowCellCtlData *)WinQueryWindowULong(hwnd, QWL_USER);
  123.  
  124.     switch(msg)
  125.     {
  126.         case WM_COMMAND:
  127.             switch(SHORT1FROMMP(mp1))
  128.             {
  129.                 case IDB_EXIT:
  130.                     WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
  131.                     return ((MRESULT) NULL);
  132.             }
  133.             break;
  134.  
  135.         case WM_CLOSE:
  136.             WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
  137.             return ((MRESULT) NULL);
  138.     }
  139.     if(pWCtlData)
  140.         return pWCtlData->pOldProc(hwnd, msg, mp1, mp2);
  141.  
  142.     return WinDefWindowProc(hwnd, msg, mp1, mp2);
  143. }
  144.  
  145. MRESULT EXPENTRY StatusLineProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  146. {
  147.     switch(msg)
  148.     {
  149.         case WM_PAINT:
  150.             {
  151.                 HPS hpsPaint;
  152.                 RECTL rclPaint;
  153.                 POINTL ptlWork;
  154.  
  155.                 hpsPaint = WinBeginPaint(hwnd, 0, 0);
  156.                 WinQueryWindowRect(hwnd, &rclPaint);
  157.  
  158.                 WinFillRect(hpsPaint, &rclPaint, CLR_PALEGRAY);
  159.  
  160.                 GpiSetColor(hpsPaint, CLR_BLACK);
  161.  
  162.                 ptlWork.x = rclPaint.xLeft      ;
  163.                 ptlWork.y = rclPaint.yBottom    ;
  164.                 GpiMove(hpsPaint, &ptlWork);
  165.                 ptlWork.y = rclPaint.yTop    - 2;
  166.                 GpiLine(hpsPaint, &ptlWork);
  167.                 ptlWork.x = rclPaint.xRight  - 1;
  168.                 GpiLine(hpsPaint, &ptlWork);
  169.  
  170.                 GpiSetColor(hpsPaint,CLR_WHITE);
  171.  
  172.                 ptlWork.y = rclPaint.yBottom    ;
  173.                 GpiLine(hpsPaint, &ptlWork);
  174.                 ptlWork.x = rclPaint.xLeft      ;
  175.                 GpiLine(hpsPaint, &ptlWork);
  176.  
  177.                 rclPaint.yTop    -= 3;
  178.                 rclPaint.yBottom += 1;
  179.                 rclPaint.xRight  -= 2;
  180.                 rclPaint.xLeft   += 1;
  181.  
  182.                 WinDrawText(hpsPaint, -1, "Status message", &rclPaint,
  183.                             CLR_BLACK,
  184.                             0,
  185.                             DT_LEFT | DT_VCENTER);
  186.  
  187.                 WinEndPaint(hpsPaint);
  188.             }
  189.             return MRFROMSHORT(FALSE);
  190.     }
  191.     return WinDefWindowProc(hwnd, msg, mp1, mp2);
  192. }
  193.  
  194. INT main(VOID)
  195. {
  196.     HAB hab;
  197.     HMQ hmq;
  198.     QMSG qmsg;
  199.     HWND hwndFrame;
  200.     HWND hwndTb;
  201.     HWND hwndTmp;
  202.     LONG lColor = CLR_PALEGRAY;
  203.     SWP swp;
  204.     static char cFontMy[]="8.Helv";
  205.  
  206.     hab = WinInitialize(0);
  207.  
  208.     if(!hab)
  209.     {
  210.         return -1;
  211.     }
  212.  
  213.     hmq = WinCreateMsgQueue(hab, 0);
  214.  
  215.     if(!hmq)
  216.     {
  217.         WinTerminate(hab);
  218.         return -2;
  219.     }
  220.  
  221.     ToolkitInit(hab);
  222.  
  223.     WinRegisterClass(hab,
  224.                      "StatusLine",
  225.                      StatusLineProc,
  226.                      CS_SIZEREDRAW,
  227.                      sizeof(ULONG));
  228.  
  229.  
  230.     WinQueryWindowPos(HWND_DESKTOP, &swp);
  231.  
  232.     hwndFrame = CreateCell(&mainClient, HWND_DESKTOP, 0);
  233.  
  234.     if(hwndFrame)
  235.     {
  236.         HWND hwndSubframe = CellWindowFromID(hwndFrame, ID_LPANE);
  237.  
  238.         WinSetWindowPos(hwndFrame, NULLHANDLE,
  239.                         swp.x + swp.cx / 8,
  240.                         swp.y + swp.cy / 8,
  241.                         (swp.cx / 4) * 3,
  242.                         (swp.cy / 4) * 3,
  243.                         SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW);
  244.  
  245.  
  246.         CreateToolbar(hwndFrame, &mainTb);
  247.  
  248.         /* Set status line font */
  249.  
  250.         hwndTmp = CellWindowFromID(hwndFrame, ID_STATUS);
  251.  
  252.         WinSetPresParam(hwndTmp,
  253.                         PP_FONTNAMESIZE,
  254.                         sizeof(cFontMy),
  255.                         cFontMy);
  256.  
  257.         /* Set MLE color */
  258.  
  259.         hwndTmp = CellWindowFromID(hwndFrame, ID_MLE);
  260.  
  261.         WinSendMsg(hwndTmp,
  262.                    MLM_SETBACKCOLOR,
  263.                    MPFROMLONG(CLR_PALEGRAY),
  264.                    MPFROMLONG(MLE_INDEX));
  265.  
  266.         /* Set list color */
  267.  
  268.         hwndTmp = CellWindowFromID(hwndFrame, ID_LIST);
  269.  
  270.         WinSetPresParam(hwndTmp,
  271.                         PP_BACKGROUNDCOLORINDEX,
  272.                         sizeof(lColor),
  273.                         &lColor);
  274.  
  275.         while (WinGetMsg(hab, &qmsg, 0, 0, 0))
  276.             WinDispatchMsg(hab, &qmsg);
  277.  
  278.         WinDestroyWindow(hwndFrame);
  279.     }
  280.  
  281.     WinDestroyMsgQueue(hmq);
  282.     WinTerminate(hab);
  283.  
  284.     return 0;
  285. }
  286.  
  287.  
  288.