home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vlabelc.cpp < prev    next >
C/C++ Source or Header  |  1999-02-20  |  8KB  |  251 lines

  1. //===============================================================
  2. // vlabelc.cxx  - label Cmd - Windows
  3. //
  4. // Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11. #include <v/vos2.h>     // for OS/2 stuff
  12. #include <v/vlabelc.h>  // our definitions
  13. #include <v/vcmdprnt.h> // a command parent
  14. #include <v/vutil.h>    // utility
  15. #include <v/vicon.h>    // icons
  16. //=====================>>> vLabelCmd::vLabelCmd <<<=======================
  17.   vLabelCmd::vLabelCmd(vCmdParent* dp, CommandObject* dc):
  18.         vCmd(dp, dc)
  19.   {
  20.     initialize();
  21.   }
  22. //=====================>>> vLabelCmd::~vLabelCmd <<<=======================
  23.   vLabelCmd::~vLabelCmd()
  24.   {
  25.     SysDebug(Destructor,"vLabelCmd::~vLabelCmd() destructor\n")
  26.   }
  27. //=====================>>> vLabelCmd::initialize <<<=======================
  28.   void vLabelCmd::initialize(void)
  29.   {
  30.     // build a button command for use in a parent window
  31.     CopyToLocal();                      // Make local copies of CmdObject
  32.     SysDebug(Constructor,"vLabelCmd::vLabelCmd() constructor\n")
  33.  
  34.     if (dlgCmd->cmdType == C_Icon && _itemList != 0)    // icon
  35.     {
  36.       initIcon();
  37.       return;
  38.     }
  39.  
  40.     // set the Pres Params to the system default color
  41.     _PPColor[0].PPtype = PP_BACKGROUNDCOLORINDEX;
  42.     _PPColor[0].PPval.color = SYSCLR_DIALOGBACKGROUND;
  43.     _PPColor[1].PPtype = PP_FOREGROUNDCOLORINDEX;
  44.     _PPColor[1].PPval.color = SYSCLR_MENUTEXT;
  45.     _PPColor[2].PPtype = 0;    // end of array marker
  46.  
  47.     if (dlgCmd->cmdType == C_ColorLabel && _itemList != 0)    // color
  48.     {
  49.       initColorLabel();
  50.     }
  51.  
  52.     ULONG style = SS_TEXT | DT_BOTTOM;
  53.  
  54.     if (!(dlgCmd->attrs & CA_Hidden))   // Check for Hidden
  55.       style |= WS_VISIBLE;
  56.  
  57.     if (dlgCmd->size > 0)               // may reset title!
  58.     {
  59.       _w = dlgCmd->size;
  60.     }
  61.     else if ((dlgCmd->attrs & CA_MainMsg) && (LabelWidth(_title) < 80))
  62.     {
  63.       _w = 88;
  64.     }
  65.     else
  66.       _w = LabelWidth(_title) + 8;            // set my width
  67.  
  68.  
  69.     if (_parentWin->paneType() == P_Status
  70.         || dlgCmd->cmdType == C_Blank)
  71.     {
  72.       _h = LabelHeight()+3;  // was 9
  73.     }
  74.     else
  75.     {
  76.       _h = LabelHeight()+3;  // was 9
  77.     }
  78.  
  79.     _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame,
  80.       dlgCmd->cRightOf, dlgCmd->cBelow);
  81.  
  82. //    _y += 1;   // center better
  83. //    _h -= 1;
  84.  
  85.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y , _w, _h, _cmdId,
  86.       style, WC_STATIC, _title, _parentWin->AssyPresParams(_PPColor), 0, NULL);
  87.   }
  88.  
  89. //=====================>>> vButtonCmd::initColorButton <<<=======================
  90.   void vLabelCmd::initColorLabel(void)
  91.   {
  92.     // wCmd is the widget of this button
  93.     _origColor = 0;
  94.     if (_itemList != 0)          // an RGB provided
  95.     {
  96.       _origColor = (vColor*)_itemList;   // point to the rgb
  97.       _color = *_origColor;
  98.     }
  99.     // set the Pres Params to the specified color
  100.     // we use the RGB version for the background
  101.     _PPColor[0].PPtype = PP_BACKGROUNDCOLORINDEX;
  102.     _PPColor[0].PPval.color = SYSCLR_DIALOGBACKGROUND;
  103.     _PPColor[1].PPtype = PP_FOREGROUNDCOLOR;
  104.     _PPColor[1].PPval.color = (LONG) _color.pixel();
  105.     _PPColor[2].PPtype = 0;    // end of array marker
  106.   }
  107.  
  108. //=====================>>> vLabelCmd::initIcon <<<=======================
  109.   void vLabelCmd::initIcon(void)
  110.   {
  111.     // I don't know how to make an SS_BITMAP control at creation
  112.     // time since there is nothing like a  BTNCDATA structure...
  113.     // So, we start out making a static text control and add the
  114.     // bitmap later in the WM_INITDLG code before its visible
  115.     // (see DRAWITEM for details)
  116.     ULONG style = SS_TEXT;
  117.  
  118.     if (!(dlgCmd->attrs & CA_Hidden))  // Check for Hidden
  119.       style |= WS_VISIBLE;
  120.  
  121.     _ip = (vIcon *) _itemList;  // to access bitmap
  122.     _h = LONG( ((_ip->height*2)/5) + 4 );
  123.     _w = LONG( (_ip->width / 2) + 6 );
  124.  
  125.     _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame,
  126.          dlgCmd->cRightOf, dlgCmd->cBelow);
  127.  
  128. //    _y += 2;   // align it a bit better
  129. //    _h -= 2;
  130.  
  131.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y , _w, _h, _cmdId,
  132.        style, WC_STATIC, "", NULL, 0, NULL);
  133.   }
  134. //================>>> vLabelCmd::SetCmdVal <<<============================
  135.   void vLabelCmd::SetCmdVal(ItemVal val, ItemSetType st)
  136.   {
  137.     SysDebug2(Misc,"vLabelCmd::SetCmdVal(val:%d ItemSetType:%d)\n",val,st)
  138.     HWND myHwnd = GetMyHwnd(_cmdId);
  139.     SysDebug2(OS2Dev,"       myHwnd(_cmdId=%u)=%x\n",_cmdId,myHwnd)
  140.  
  141.     switch (st)
  142.     {
  143.       case Sensitive:
  144.     _Sensitive = val;               // set
  145.     WinEnableWindow (myHwnd, val);
  146.     break;
  147.  
  148.       case Hidden:
  149.     if (val)
  150.     {
  151.       WinShowWindow (myHwnd, FALSE);
  152.     }
  153.     else
  154.     {
  155.       WinShowWindow (myHwnd, TRUE);
  156.     }
  157.     break;
  158.  
  159.       case ChangeColor:               // changed original vColor
  160.       {
  161.     _color = *_origColor;       // recopy color
  162.  
  163.     // set the Pres Params to the specified color
  164.     // we use the RGB version of the PP_
  165.     _PPColor[1].PPtype = PP_FOREGROUNDCOLOR;
  166.     _PPColor[1].PPval.color = (LONG) _color.pixel();
  167.  
  168.     WinSetPresParam(myHwnd, _PPColor[1].PPtype, (ULONG) sizeof(RGB),
  169.       (PVOID) &_PPColor[1].PPval.color);
  170.  
  171.     break;
  172.       }
  173.       case Red:
  174.     _color.SetR(val);
  175.     break;
  176.  
  177.       case Green:
  178.     _color.SetG(val);
  179.     break;
  180.  
  181.       case Blue:
  182.       {
  183.     _color.SetB(val);
  184.     _PPColor[1].PPtype = PP_FOREGROUNDCOLOR;
  185.     _PPColor[1].PPval.color = (LONG) _color.pixel();
  186.     WinSetPresParam(myHwnd, _PPColor[1].PPtype, (ULONG) sizeof(RGB),
  187.       (PVOID) &_PPColor[1].PPval.color);
  188.     break;
  189.       }
  190.     }
  191.   }
  192.  
  193. //================>>> vLabelCmd::SetCmdStr <<<============================
  194.   void vLabelCmd::SetCmdStr(VCONST char* str)
  195.   {
  196.     char trunc[80];
  197.     SysDebug1(Misc,"vLabelCmd::SetCmdStr(str:%s)\n",strncpy(trunc, str, 60) )
  198.     WinSetDlgItemText(_parentWin->getParent(), _cmdId, str);
  199.  
  200.     _title = str;
  201.   }
  202.  
  203. //================>>> vLabelCmd::MEASUREITEM <<<============================
  204.   int vLabelCmd::MEASUREITEM(int id, OWNERITEM* oi)
  205.   {
  206.     return 1;
  207.   }
  208.  
  209. //================>>> vLabelCmd::DRAWITEM <<<============================
  210.   int vLabelCmd::DRAWITEM(int id, OWNERITEM* poi)
  211.   {
  212.     // This really has nothing to do with DRAWITEM, but its
  213.     // an unused procedure that we can hijaak and use to load
  214.     // the bitmap for C_Icons during the WM_INITDLG setup
  215.  
  216.     if (dlgCmd->cmdType == C_Icon)
  217.     {
  218.       // This is called during WM_INITDLG for static Icons
  219.       // so we can load the bitmap
  220.  
  221.       // We force the bitmap to be rebuilt with each call
  222.       // since SS_BITMAP appears to auto destroy the bitmap when the window
  223.       // is destroyed
  224.  
  225.       // Note: For transparent icons we cannot us BM_SRCTRANSPARENT since
  226.       // there is no canvas to bitblt into.  Instead, we pass the dialog
  227.       // background color we need to the icon creation method, and it
  228.       // substitutes the dialog background color for the icon background
  229.       // to fake transparency.
  230.       HBITMAP hImage;
  231.  
  232.       // get icon HBITMAP
  233.       hImage = _ip->GetIconDLG(C_Icon, SYSCLR_DIALOGBACKGROUND);
  234.  
  235.       HWND hIcon = GetMyHwnd(id);
  236.       WinSetWindowBits(hIcon, QWL_STYLE, SS_BITMAP, SS_BITMAP | 0x7f);
  237.       MRESULT NewhImage = WinSendMsg(hIcon, SM_SETHANDLE, MPFROMP(hImage), NULL);
  238.  
  239.       SysDebug2(OS2Dev,"vLabelCmd::DRAWITEM hImage:%x NewhImage:%x\n", hImage, NewhImage)
  240.       SysDebug2(OS2Dev,"vLabelCmd::DRAWITEM this:%x hIcon:%x \n", this, hIcon)
  241.  
  242.     }
  243.     return (0);
  244.   }
  245.  
  246. //===================>>> vLabelCmd::vCmdCallback <<<=======================
  247.   void vLabelCmd::CmdCallback(UINT uMsg, MPARAM mp1, MPARAM mp2)
  248.   {
  249.     // No Op for a label
  250.   }
  251.