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

  1. //===============================================================
  2. // vtextinc.xxx - TextIn 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/vapp.h>
  13. #include <v/vtextinc.h> // our definitions
  14. #include <v/vcmdprnt.h> // a command parent
  15.  
  16. #define TextInFont SysVariableFont        // The font to use
  17. //=====================>>> vTextInCmd::vTextInCmd <<<=======================
  18.   vTextInCmd::vTextInCmd(vCmdParent* dp, CommandObject* co) :
  19.     vCmd(dp, co)
  20.   {
  21.     initialize();
  22.   }
  23. //=====================>>> vTextInCmd::~vTextInCmd <<<=======================
  24.   vTextInCmd::~vTextInCmd()
  25.   {
  26.     SysDebug(Destructor,"vTextInCmd::~vTextInCmd() destructor\n")
  27.   }
  28. //=====================>>> vTextInCmd::initialize <<<=======================
  29.   void vTextInCmd::initialize(void)
  30.   {
  31.     // build a TextIn command for use in a parent window
  32.     SysDebug(Constructor,"vTextInCmd::vTextInCmd() constructor\n")
  33.     _msg[0] = 0;                        // no string yet
  34.  
  35.     CopyToLocal();                      // Make local copies of CmdObject
  36.  
  37.     int defLen = strlen(_title);        // length of supplied string
  38.     if (defLen < 130)
  39.       strcpy(_msg,_title);
  40.  
  41.     int defWidth = (dlgCmd->attrs & CA_Large) ? 35 : 20;
  42.  
  43.     if (dlgCmd->attrs & CA_Small)       // allow small, too.
  44.     defWidth = 10;
  45.  
  46.     if (dlgCmd->size > 0)               // V:1.13
  47.     defWidth = dlgCmd->size;
  48.  
  49.     if (defLen > defWidth)              // Some work space
  50.     defWidth = defLen + 6;
  51.  
  52.     LONG style = ES_LEFT | ES_AUTOSCROLL | WS_GROUP | WS_TABSTOP;
  53.  
  54.     _efd.cb = sizeof(ENTRYFDATA);
  55.     _efd.cchEditLimit = 130;
  56.     _efd.ichMinSel = 0;
  57.     _efd.ichMaxSel = 0;
  58.  
  59.     if (dlgCmd->attrs & CA_Password)
  60.     style |= ES_UNREADABLE;
  61.  
  62.     if (!(dlgCmd->attrs & CA_NoBorder))
  63.     style |= ES_MARGIN;
  64.  
  65.     if (!(dlgCmd->attrs & CA_Hidden))   // Check for Hidden
  66.     style |= WS_VISIBLE;
  67.  
  68.     _w = defWidth * 4 + 6;
  69.     _h = LabelHeight()+6;  // was 12
  70.  
  71.     _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame, dlgCmd->cRightOf,
  72.      dlgCmd->cBelow);
  73.  
  74.     // entrybox border extends 1/2 character beyond specified width so
  75.     // need to compensate to keep alignment aesthetic
  76.     if (!(dlgCmd->attrs & CA_NoBorder))
  77.     {
  78.       _x += 2; _y += 3;
  79.       _w -= 4; _h -= 6;
  80.     }
  81.  
  82.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y , _w, _h, _cmdId,
  83.        style, WC_ENTRYFIELD, _title, 0, _efd.cb, &_efd);
  84.  
  85.   }
  86. //=====================>>> vTextInCmd::GetTextIn <<<=======================
  87.   int vTextInCmd::GetTextIn(ItemVal id, char* str, int maxlen) VCONST
  88.   {
  89.     // recover the data from a TextInCmd - return text + length
  90.     int ix;
  91.     for (ix = 0 ; _msg[ix] != 0 && ix < maxlen-1 ; ++ix)
  92.        str[ix] = _msg[ix];
  93.     str[ix] = 0;
  94.     return strlen(str);
  95.   }
  96. //================>>> vTextInCmd::SetCmdVal <<<============================
  97.   void vTextInCmd::SetCmdVal(ItemVal val, ItemSetType st)
  98.   {
  99.     SysDebug1(Misc,"vTextInCmd::SetCmdVal(val:%d)\n",val)
  100.     HWND myHwnd = GetMyHwnd(_cmdId);
  101.  
  102.     switch (st)
  103.     {
  104.       case Sensitive:
  105.     _Sensitive = val;               // set
  106.     WinEnableWindow (myHwnd, val);
  107.     break;
  108.  
  109.       case Hidden:
  110.     if (val)
  111.       WinShowWindow (myHwnd, FALSE);
  112.     else
  113.       WinShowWindow (myHwnd, TRUE);
  114.     break;
  115.     }
  116.   }
  117. //================>>> vTextInCmd::SetCmdStr <<<============================
  118.   void vTextInCmd::SetCmdStr(VCONST char* str)
  119.   {
  120.     char trunc[80];
  121.     SysDebug1(Misc,"vTextInCmd::SetCmdStr(str:%s)\n", strncpy(trunc, str, 60))
  122.  
  123.     strcpy(_msg, str);
  124.     HWND myHwnd = GetMyHwnd(_cmdId);
  125.     WinSetWindowText(myHwnd, str);
  126.  
  127.   }
  128. //====================>>> vRadioButtonCmd::CmdCallback <<<=======================
  129.   void vTextInCmd::CmdCallback(UINT uMsg, MPARAM mp1, MPARAM mp2)
  130.   {
  131.     // Edit strings are noops except for EN_CHANGE
  132.  
  133.     if (uMsg == WM_CONTROL)
  134.     {
  135.       if (SHORT2FROMMP(mp1) == EN_CHANGE)
  136.       {
  137.     HWND myHwnd = GetMyHwnd(_cmdId);
  138.     WinQueryWindowText(myHwnd, sizeof(_msg), _msg);
  139. //    SysDebug1(OS2Dev,"vTextInCmd::CmdCallBack _msg:%s \n", _msg)
  140.       }
  141.     }
  142.   }
  143.