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

  1. //===============================================================
  2. // vboxlbl.cxx - boxed label for stat bar - 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/vapp.h>
  13. #include <v/vboxlblc.h> // our definitions
  14. #include <v/vcmdprnt.h> // a command parent
  15.  
  16.   // Boxed Labels are subclassed to this procedure
  17.   MRESULT EXPENTRY BoxLblProc(HWND hDlg, ULONG uMsg, MPARAM mp1, MPARAM mp2);
  18.   // this is a pointer to the original entrybox procedure that is subclassed
  19.   PFNWP orgBoxLblProc;
  20.  
  21. //=====================>>> vBoxedLabelCmd::vBoxedLabelCmd <<<================
  22.   vBoxedLabelCmd::vBoxedLabelCmd(vCmdParent* dp, CommandObject* dc) :
  23.     vCmd(dp, dc)
  24.   {
  25.     initialize();
  26.   }
  27. //=================>>> vBoxedLabelCmd::~vBoxedLabelCmd <<<===================
  28.   vBoxedLabelCmd::~vBoxedLabelCmd()
  29.   {
  30.     SysDebug(Destructor,"vBoxedLabelCmd::~vBoxedLabelCmd() destructor\n")
  31.   }
  32. //=====================>>> vBoxedLabelCmd::initialize <<<=====================
  33.   void vBoxedLabelCmd::initialize(void)
  34.   {
  35.     // build a button command for use in a parent window
  36.  
  37.     SysDebug(Constructor,"vBoxedLabelCmd::vBoxedLabelCmd() constructor\n")
  38.  
  39.     long style = WS_GROUP | ES_READONLY | ES_CENTER | ES_AUTOSIZE;
  40.  
  41.     CopyToLocal();                      // Make local copies of CmdObject
  42.  
  43.     if (!(dlgCmd->attrs & CA_Hidden))           // Check for Hidden
  44.     style |= WS_VISIBLE;
  45.  
  46.     if (!(dlgCmd->attrs & CA_NoBorder))
  47.     style |= ES_MARGIN;
  48.  
  49.     _efd.cb = sizeof(ENTRYFDATA);
  50.     _efd.cchEditLimit = 80;
  51.     _efd.ichMinSel = 0;
  52.     _efd.ichMaxSel = 0;
  53.  
  54.     int tl = strlen(_title);
  55.     if ( tl < 80)
  56.     strcpy(_lbl,_title);
  57.     else
  58.     strcpy(_lbl,"text length too long!");
  59.  
  60.     if (dlgCmd->size > 0)               // may reset title!
  61.     {
  62.     _w = dlgCmd->size ;
  63.     }
  64.     else
  65.     {
  66. //      _w = -1;                        // AUTOSIZE confuses SetPosition()
  67. //      _h = -1;                        // AUTOSIZE confuses SetPosition()
  68.  
  69.       // entrybox border extends 1/2 character beyond specified width so
  70.       // need to compensate to keep alignment aesthetic
  71.       _w = LabelWidth(_lbl) + 8;      // set my width
  72.     }
  73.     _h = LabelHeight()+3;  // was 10
  74.  
  75.     // set the entryfield colors so they blend into the dialog background
  76.     _PPColor[0].PPtype = PP_BACKGROUNDCOLORINDEX;
  77.     _PPColor[0].PPval.color = SYSCLR_DIALOGBACKGROUND;
  78.     _PPColor[1].PPtype = PP_DISABLEDBACKGROUNDCOLORINDEX;
  79.     _PPColor[1].PPval.color = SYSCLR_DIALOGBACKGROUND;
  80.     _PPColor[2].PPtype = PP_HILITEBACKGROUNDCOLORINDEX;
  81.     _PPColor[2].PPval.color = SYSCLR_DIALOGBACKGROUND;
  82.     _PPColor[3].PPtype = PP_HILITEFOREGROUNDCOLORINDEX;
  83.     _PPColor[3].PPval.color = SYSCLR_MENUTEXT;
  84.     _PPColor[4].PPtype = 0;    // end of array marker
  85.  
  86.     _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame, dlgCmd->cRightOf,
  87.     dlgCmd->cBelow);
  88.  
  89.     if (_parentWin->paneType() == P_Status)
  90.     {
  91.       _x += 2; _y += 2;   // status panes position fine tuning
  92.       _w -= 4; _h -= 3;
  93.     }
  94.     else
  95.     {
  96.       _x += 2; _y += 2;
  97.       _w -= 4; _h -= 4;
  98.     }
  99.  
  100.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y, _w, _h, _cmdId,
  101.       style, WC_ENTRYFIELD, _lbl, _parentWin->AssyPresParams(_PPColor),
  102.       _efd.cb, &_efd);
  103.  
  104.   }
  105. //================>>> vBoxedLabelCmd::SetCmdVal <<<===========================
  106.   void vBoxedLabelCmd::SetCmdVal(ItemVal val, ItemSetType st)
  107.   {
  108.     SysDebug1(Misc,"vBoxedLabelCmd::SetCmdVal(val:%d)\n",val)
  109.     HWND myHwnd = GetMyHwnd(_cmdId);
  110.  
  111.     switch (st)
  112.     {
  113.       case Sensitive:
  114.     _Sensitive = val;               // set
  115.     WinEnableWindow (myHwnd, val);
  116.     break;
  117.  
  118.       case Hidden:
  119.     if (val)
  120.       WinShowWindow (myHwnd, FALSE);
  121.     else
  122.       WinShowWindow (myHwnd, TRUE);
  123.     break;
  124.     }
  125.   }
  126.  
  127. //================>>> vBoxedLabelCmd::SetCmdStr <<<===========================
  128.   void vBoxedLabelCmd::SetCmdStr(VCONST char* str)
  129.   {
  130.     char trunc[80];
  131.     SysDebug1(Misc,"vBoxedLabelCmd::SetCmdStr(str:%s)\n", strncpy(trunc, str, 60) )
  132.     HWND myHwnd = GetMyHwnd(_cmdId);
  133.     strcpy(_lbl,str);
  134.     _title = _lbl;
  135.  
  136.     WinSetWindowText(myHwnd, _lbl);
  137. // set focus back to client (owner of owner of boxedlabel)
  138. //    HWND client = WinQueryWindow(WinQueryWindow(myHwnd, QW_OWNER), QW_OWNER);
  139. //      WinSetFocus(HWND_DESKTOP,client);
  140.   }
  141.  
  142. //================>>> vBoxedLabelCmd::MEASUREITEM <<<=========================
  143.   int vBoxedLabelCmd::MEASUREITEM(int id, OWNERITEM* ois)
  144.   {
  145.     return 1;
  146.   }
  147.  
  148.  
  149. //================>>> vBoxedLabelCmd::DRAWITEM <<<============================
  150.   int vBoxedLabelCmd::DRAWITEM(int id, OWNERITEM* poi)
  151.   {
  152.     // This really has nothing to do with DRAWITEM, but its
  153.     // an unused procedure that we can hijak and use to subclass
  154.     // boxed labels during the WM_INITDLG setup
  155.  
  156.     if (dlgCmd->cmdType == C_BoxedLabel)
  157.     {
  158.       // This is called during WM_INITDLG for boxed labels
  159.       // so we can subclass the button procedure
  160.       HWND hBtn = GetMyHwnd(id);
  161.       WinSetWindowULong(hBtn, QWL_USER, (LONG) this);
  162.       _orgBoxLblProc = WinSubclassWindow(hBtn, BoxLblProc);
  163.       SysDebug2(OS2Dev,"vBoxedLabelCmd::DRAWITEM this:%x hBtn:%x \n", this, hBtn)
  164.     }
  165.     return (0);
  166.   }
  167.  
  168. //====================>>> BoxLblProc <<<=======================
  169. // we subclass the C_BoxedLabel so we can intercept any attempt
  170. // to activate it with a mouse click
  171.   MRESULT EXPENTRY BoxLblProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  172.   {
  173.     vBoxedLabelCmd* thisCmd = (vBoxedLabelCmd*) WinQueryWindowULong( hwnd, QWL_USER ); // Pointer from window word
  174.     if (!thisCmd)
  175.     {
  176.       return (MRESULT) WinDefDlgProc(hwnd, msg, mp1, mp2);
  177.     }
  178.     else
  179.       return (MRESULT) thisCmd->vBoxLblProc(hwnd, msg, mp1, mp2);
  180.   }
  181.  
  182. //====================>>> vBoxLblProc <<<=======================
  183.   MRESULT vBoxedLabelCmd::vBoxLblProc(HWND hBtn, ULONG uMsg, MPARAM mp1, MPARAM mp2)
  184.   {
  185.     // set the original frame procedure
  186.     orgBoxLblProc = (PFNWP) _orgBoxLblProc;
  187.  
  188.     switch (uMsg)
  189.     {
  190.       case WM_CHORD:
  191.       case WM_BUTTON1DBLCLK:
  192.       case WM_BUTTON2DBLCLK:
  193.       case WM_BUTTON3DBLCLK:
  194.       case WM_BUTTON1DOWN:
  195.       case WM_BUTTON2DOWN:
  196.       case WM_BUTTON3DOWN:
  197.       case WM_SETFOCUS:
  198.       {
  199.         // user has clicked on the label, so trap message and prevent
  200.         // it from reaching the entry field procedure so that control
  201.         // does not get focus
  202.         return 0;
  203.       }
  204.     }
  205.     return orgBoxLblProc(hBtn, uMsg, mp1, mp2);
  206.   }
  207.  
  208. //===================>>> vBoxedLabelCmd::vCmdCallback <<<=======================
  209.   void vBoxedLabelCmd::CmdCallback(UINT uMsg, MPARAM mp1, MPARAM mp2)
  210.   {
  211.    // No Op for a label
  212.   }
  213.  
  214.  
  215.