1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
//===============================================================
// vradiocc.cxx - RadioButtons - Windows
//
// Copyright (C) 1995,1996, 1997, 1998 Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================
#include <v/vwin32.h> // for Win 32 stuff
#include <v/vradioc.h> // our definitions
#include <v/vcmdprnt.h> // a command parent
#include <v/vapp.h>
#include <v/vutil.h>
vRadioButtonCmd* vRadioButtonCmd::_RBList = 0; // empty list to start
//================>>> vRadioButtonCmd::vRadioButtonCmd <<<=====================
vRadioButtonCmd::vRadioButtonCmd(vCmdParent* dp, CommandObject* dc) :
vCmd(dp, dc)
{
// Create bitmaps if need to
SysDebug(Constructor,"vRadioButtonCmd::vRadioButtonCmd() constructor\n")
initialize(); // and initialize
}
//================>>> vRadioButtonCmd::vRadioButtonCmd <<<=====================
vRadioButtonCmd::vRadioButtonCmd(const vRadioButtonCmd& r) :
vCmd(r)
{
vSysError("vRadioButtonCmd - V semantics do not support copy constructors!");
}
//===========>>> vRadioButtonCmd::~vRadioButtonCmd <<<======================
vRadioButtonCmd::~vRadioButtonCmd()
{
// We have to remove ourself from the list of all RBs
SysDebug(Destructor,"vRadioButtonCmd::~vRadioButtonCmd() destructor\n")
if (_RBList == this) // first one special
{
_RBList = _nextRB;
}
else
{
for (vRadioButtonCmd* rbl = _RBList ; rbl != 0 ; rbl = rbl->_nextRB)
{
if (rbl->_nextRB == this) // we found ourself!
{
rbl->_nextRB = _nextRB; // unlink us
break;
}
}
}
}
//=====================>>> vRadioButtonCmd::initialize <<<=======================
void vRadioButtonCmd::initialize(void)
{
// build a button command for use in a parent window
_nextRB = _RBList; // add us in to front of list
_RBList = this;
long style = WS_TABSTOP | WS_GROUP | BS_RADIOBUTTON; // default for a button
CopyToLocal(); // Make local copies of CmdObject
if (!(dlgCmd->attrs & CA_Hidden)) // Check for Hidden
style |= WS_VISIBLE;
_w = vLblLen(_title)*4+14; // set my width
_h = 11;
_parentWin->SetPosition(_x, _y, _w, _h+3, dlgCmd->cFrame, dlgCmd->cRightOf,
dlgCmd->cBelow);
_y += 2; // Center better
_CtrlOffset = _parentWin->AddDlgControl(_x, _y, _w, _h, _cmdId,
style, "BUTTON", _title, sizeof(vCmd*), (LPBYTE)this);
}
//================>>> vRadioButtonCmd::ResetItemValue <<<======================
void vRadioButtonCmd::ResetItemValue(void)
{
// We have to toggle things
if (_retVal == _origVal) // No op if no change
return;
_retVal = _origVal; // restore
::CheckDlgButton(_parentWin->getParent(), _cmdId, _retVal);
// let parent window handle now
_parentWin->ProcessCmd(_cmdId, _retVal, dlgCmd->cmdType);
}
//==================>>> vRadioButtonCmd::GetCmdValue <<<=========================
int vRadioButtonCmd::GetCmdValue(ItemVal id) VCONST
{
if (id != _cmdId)
return -1;
return _retVal;
}
//================>>> vRadioButtonCmd::SetCmdVal <<<========================
void vRadioButtonCmd::SetCmdVal(ItemVal val, ItemSetType st)
{
SysDebug1(Misc,"vRadioButtonCmd::SetCmdVal(val:%d)\n",val)
HWND myHwnd = GetMyHwnd(_cmdId);
if (st == Sensitive)
{
_Sensitive = val; // set
EnableWindow(myHwnd, val);
}
else if (st == Hidden) // hide or unhide
{
if (val)
{
::ShowWindow(myHwnd,SW_HIDE);
}
else
{
::ShowWindow(myHwnd,SW_SHOW);
}
}
else if (st == Value || st == Checked)
{
_retVal = val; // set
if (_retVal) // Need to turn off other
{
// We have to toggle things, so scan the list of all radio buttons,
// searching for other buttons in the same frame
ItemVal ourFrame = dlgCmd->cFrame; // remember our frame
for (vRadioButtonCmd* rbl = _RBList ; rbl != 0 ; rbl = rbl->_nextRB)
{
CommandObject* dc = rbl->dlgCmd; // shorthand
if (dc->cFrame == ourFrame) // Radio Button in same frame
{
if (rbl->_retVal && rbl->_cmdId != _cmdId) // This one was ON, turn off
{
rbl->_retVal = 0; // toggle
::CheckDlgButton(_parentWin->getParent(),rbl->_cmdId, 0);
break;
}
}
}
}
::CheckDlgButton(_parentWin->getParent(), _cmdId, val);
}
}
//================>>> vRadioButtonCmd::SetCmdStr <<<=========================
void vRadioButtonCmd::SetCmdStr(VCONST char *str)
{
SysDebug1(Misc,"vRadioButtonCmd::SetCmdStr(str:%s)\n",str)
SetDlgItemText(_parentWin->getParent(), _cmdId, str);
_title = str;
}
//====================>>> vRadioButtonCmd::CmdCallback <<<=======================
void vRadioButtonCmd::CmdCallback(int /* id */, WORD /*codeNotify*/)
{
// We have to toggle things, so scan the list of all radio buttons,
// searching for other buttons in the same frame
ItemVal ourFrame = dlgCmd->cFrame; // remember our frame
for (vRadioButtonCmd* rbl = _RBList ; rbl != 0 ; rbl = rbl->_nextRB)
{
CommandObject* dc = rbl->dlgCmd; // shorthand
if (dc->cFrame == ourFrame) // Radio Button in same frame
{
if (rbl->_retVal && rbl->_cmdId != _cmdId) // This one was ON, turn off
{
rbl->_retVal = 0; // toggle
::CheckDlgButton(_parentWin->getParent(),rbl->_cmdId, 0);
// inform parent of change
_parentWin->ProcessCmd(rbl->_cmdId, rbl->_retVal, dc->cmdType);
break;
}
}
}
// Now, we need to turn this RadioButton ON
if (!_retVal)
{
_retVal = 1; // toggle
SetCmdVal(1,Checked);
// and let the parent window know about the change
_parentWin->ProcessCmd(_cmdId, _retVal, dlgCmd->cmdType);
}
}
|