home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / exedt040.zip / src / status.c < prev    next >
C/C++ Source or Header  |  1999-01-23  |  6KB  |  221 lines

  1. #define INCL_PM
  2. #include <memory.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <os2.h>
  6. #include "exedit.h"
  7.  
  8. void RegisterStatusBar(HAB anHab)
  9. {
  10.  WinRegisterClass(anHab,WC_STATUS,&WinStatusProc,CS_SIZEREDRAW,4);
  11. }
  12.  
  13. void DrawShadowedRect(TStatus* Status,HPS hps,PRECTL rect,BOOL Raised)
  14. {
  15.  POINTL pts[2];
  16.  
  17.  if (!Raised) GpiSetColor(hps,Status->Dark_Shadow);
  18.  else GpiSetColor(hps,Status->Light_Shadow);
  19.  GpiMove(hps,(PPOINTL)rect);
  20.  pts[0].x=rect->xLeft;
  21.  pts[0].y=rect->yTop;
  22.  pts[1].x=rect->xRight;
  23.  pts[1].y=rect->yTop;
  24.  GpiPolyLine(hps,2,pts);
  25.  
  26.  if (Raised) GpiSetColor(hps,Status->Dark_Shadow);
  27.  else GpiSetColor(hps,Status->Light_Shadow);
  28.  GpiMove(hps,(PPOINTL)rect);
  29.  pts[0].x=rect->xRight;
  30.  pts[0].y=rect->yBottom;
  31.  pts[1].x=rect->xRight;
  32.  pts[1].y=rect->yTop;
  33.  GpiPolyLine(hps,2,pts);
  34. }
  35.  
  36. void RclCalc(TStatus* Status)
  37. {
  38.  
  39.  PRECTL rcl=&Status->rcl;
  40.  TPanel *Panel=Status->Panels;
  41.  ULONG Left=rcl->xLeft+Panels_Sep,
  42.        Right,
  43.        FreeL=(rcl->xRight-rcl->xLeft)-(Status->FixPanelsL+(Status->PanelsCount+1)*Panels_Sep);
  44.  
  45.  while (Panel)
  46.  {
  47.   if (Panel->Visible)
  48.   {
  49.    Panel->rcl.xLeft=Left;
  50.    if (Panel->Type==SB_FIX)
  51.    Panel->rcl.xRight=Left+Panel->cx;
  52.    else
  53.    if (Panel->cx)
  54.     Panel->rcl.xRight=Left+(Panel->cx*FreeL/Status->Perc);
  55.  
  56.    Panel->rcl.yTop=rcl->yTop-Panels_Sep;
  57.    Panel->rcl.yBottom=rcl->yBottom+Panels_Sep;
  58.  
  59.    Left=Panel->rcl.xRight+Panels_Sep;
  60.    if (!Panel->Next) Panel->rcl.xRight=rcl->xRight-Panels_Sep;
  61.    WinSetWindowPos(Panel->hwndText,HWND_TOP,Panel->rcl.xLeft+1,Panel->rcl.yBottom+1,
  62.                    Panel->rcl.xRight-Panel->rcl.xLeft-Panels_Sep,
  63.                    Panel->rcl.yTop-Panel->rcl.yBottom-Panels_Sep,SWP_SIZE|SWP_MOVE|SWP_SHOW);
  64.   }
  65.  
  66.   Panel=Panel->Next;
  67.  }
  68. }
  69.  
  70. TPanel* GetPanel(TPanel* First,SHORT Index)
  71. {
  72.  int i;
  73.  for (i=0;i<Index;i++) First=First->Next;
  74.  return First;
  75. }
  76.  
  77. MRESULT EXPENTRY WinStatusProc(HWND hwnd,ULONG msg, MPARAM mp1,MPARAM mp2)
  78. {
  79.  TStatus *Status;
  80.  Status=WinQueryWindowPtr(hwnd,QWL_USER);
  81.  
  82.  switch (msg)
  83.  {
  84.   case WM_CREATE:
  85.    Status=(TStatus*)malloc(sizeof(TStatus));
  86.    WinSetWindowPtr(hwnd,QWL_USER,Status);
  87.  
  88.    Status->usSzStruct=sizeof(TStatus);
  89.    Status->Dark_Shadow=(LONG)WinQuerySysColor(HWND_DESKTOP,SYSCLR_SHADOWHILITEBGND, 0L);
  90.    Status->Light_Shadow=0x00FFFFFF;
  91.    Status->Background=SYSCLR_DIALOGBACKGROUND;
  92.    Status->PanelsCount=0;
  93.    Status->FixPanelsL=0;
  94.    Status->Perc=0;
  95.   break;
  96.  
  97.   case WM_SIZE:
  98.    WinQueryWindowRect(hwnd,&Status->rcl);
  99.    Status->rcl.xRight--;
  100.    Status->rcl.yTop--;
  101.    RclCalc(Status);
  102.   break;
  103.  
  104.   case WM_ERASEBACKGROUND:
  105.   return (MPARAM)FALSE;
  106.  
  107.   case WM_PAINT :
  108.   {
  109.    HPS hps=WinGetPS(hwnd);
  110.    TPanel* Panel=Status->Panels;
  111.  
  112.    GpiCreateLogColorTable(hps,0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  113.    WinFillRect(hps,&Status->rcl,Status->Background);
  114.    DrawShadowedRect(Status,hps,&Status->rcl,TRUE);
  115.    while (Panel)
  116.    {
  117.     if (Panel->Visible)
  118.     {
  119.      DrawShadowedRect(Status,hps,&Panel->rcl,FALSE);
  120.      WinSetWindowPos(Panel->hwndText,HWND_TOP,0,0,0,0,SWP_SHOW);
  121.      WinInvalidateRect(Panel->hwndText,NULL,FALSE);
  122.     }
  123.     else
  124.      WinSetWindowPos(Panel->hwndText,HWND_TOP,0,0,0,0,SWP_HIDE);
  125.  
  126.     Panel=Panel->Next;
  127.    }
  128.  
  129.    WinReleasePS(hps);
  130.   }
  131.   break;
  132.  
  133.  // mp1  1 cx  2 type mp2 1 visible 2 Id
  134.   case SBM_ADDPANEL:
  135.   {
  136.    TPanel *Panel,*NewPanel;
  137.    ULONG Back=WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0L),
  138.          Fore=0;
  139.  
  140.    NewPanel=(TPanel*)malloc(sizeof(TPanel));
  141.    if (!Status->Panels) Status->Panels=NewPanel;
  142.    else
  143.    {
  144.     Panel=Status->Panels;
  145.     while (Panel->Next) Panel=Panel->Next;
  146.     Panel->Next=NewPanel;
  147.    }
  148.  
  149.    NewPanel->cx=SHORT1FROMMP(mp1);
  150.    NewPanel->Type=SHORT2FROMMP(mp1);
  151.    NewPanel->Visible=(BOOL)SHORT1FROMMP(mp2);
  152.    NewPanel->hwndText=WinCreateWindow(hwnd, WC_STATIC,"",
  153.                                       WS_VISIBLE | SS_TEXT | DT_LEFT | DT_VCENTER,
  154.                                       0,0,200,200,hwnd, HWND_TOP, SHORT2FROMMP(mp2),
  155.                                       NULL, NULL);
  156.  
  157.    WinSetPresParam(NewPanel->hwndText, PP_FOREGROUNDCOLOR, 4L, (PVOID)&Fore);
  158.    WinSetPresParam(NewPanel->hwndText, PP_BACKGROUNDCOLOR, 4L, (PVOID)&Back);
  159.    WinSetPresParam(NewPanel->hwndText, PP_FONTNAMESIZE,sizeof("8.Helv.Bold"), (PVOID)"8.Helv.Bold");
  160.  
  161.    if (NewPanel->Type==SB_FIX) Status->FixPanelsL+=NewPanel->cx;
  162.    else Status->Perc+=NewPanel->cx;
  163.    Status->PanelsCount++;
  164.   }
  165.   break;
  166.  
  167.   // mp1  1 index 2 state
  168.   case SBM_HIDEPANEL:
  169.   {
  170.    TPanel *Panel=GetPanel(Status->Panels,SHORT1FROMMP(mp1));
  171.    BOOL Visible=!SHORT2FROMMP(mp1);
  172.  
  173.    if (Visible!=Panel->Visible)
  174.    {
  175.     Panel->Visible=Visible;
  176.     if (Visible)
  177.     {
  178.      if (Panel->Type==SB_FIX) Status->FixPanelsL+=Panel->cx;
  179.      else Status->Perc+=Panel->cx;
  180.      Status->PanelsCount++;
  181.     }
  182.     else
  183.     {
  184.      if (Panel->Type==SB_FIX) Status->FixPanelsL-=Panel->cx;
  185.      else Status->Perc-=Panel->cx;
  186.      Status->PanelsCount--;
  187.     }
  188.    }
  189.   }
  190.   break;
  191.  
  192.   case SBM_SETPANELTEXT:
  193.   {
  194.    TPanel *Panel=GetPanel(Status->Panels,SHORT1FROMMP(mp1));
  195.    WinSetWindowText(Panel->hwndText,(PSZ)mp2);
  196.   }
  197.   break;
  198.  
  199.   case WM_DESTROY:
  200.   {
  201.    TPanel *Panel=Status->Panels;
  202.    TPanel *Temp;
  203.  
  204.    while (Panel)
  205.    {
  206.     WinDestroyWindow(Panel->hwndText);
  207.     Temp=Panel;
  208.     Panel=Panel->Next;
  209.     DosFreeMem(Temp);
  210.    }
  211.    DosFreeMem(Status);
  212.   }
  213.  
  214.   default:
  215.   return WinDefWindowProc(hwnd,msg,mp1,mp2);
  216.  }
  217.  return WinDefWindowProc(hwnd,msg,mp1,mp2);
  218. }
  219.  
  220.  
  221.