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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
|
//===============================================================
// vspinc.cxx - vSpinnerCmd - 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/vspinc.h> // our definitions
#include <v/vcmdprnt.h> // a command parent
#include <v/vapp.h>
#include <v/vutil.h>
int vSpinnerCmd::_textIdPool = (int)M_WindowsReserved5;
//=================>>> vSpinnerCmd::vSpinnerCmd <<<=======================
vSpinnerCmd::vSpinnerCmd(vCmdParent* dp, CommandObject* co) :
vCmd(dp, co)
{
initialize(); // and initialize
}
//=======================>>> vSpinnerCmd::~vSpinnerCmd <<<=====================
vSpinnerCmd::~vSpinnerCmd()
{
SysDebug(Constructor,"vSpinnerCmd::~vSpinnerCmd() Destructor\n")
}
//=====================>>> vSpinnerCmd::initialize <<<=======================
void vSpinnerCmd::initialize(void)
{
char *theText, intval[20];
long style;
SysDebug(Constructor,"vSpinnerCmd::vSpinnerCmd() constructor\n")
CopyToLocal(); // Make local copies of CmdObject
// First, build the Text box
SetupList();
// BEW - v1.20 - If we leave this ES_READONLY, then the spinner
// has a gray background, which is confusing. It can be edited
// now, but that doesn't seem to hurt anything.
style = /* ES_READONLY |*/ WS_BORDER | ES_CENTER; // Bordered readonly text box
if (!(dlgCmd->attrs & CA_Hidden)) // Check for Hidden
style |= WS_VISIBLE;
if (_TextList)
theText = _fullList[_curSelection];
else
{
style |= (ES_MULTILINE | ES_RIGHT);
IntToStr(_curSelection,intval);
theText = intval;
}
_maxWidth = _maxWidth*4 + 2; // change chars to dialog pixels
_maxWidth = (dlgCmd->attrs & CA_Large) ? (_maxWidth * 3)/2
: _maxWidth;
if (dlgCmd->size > 0 && dlgCmd->size < 2048)
_maxWidth = dlgCmd->size;
_w = _maxWidth;
_h = 14;
_textId = _textIdPool++; // get an id for the text control
_parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame, dlgCmd->cRightOf,
dlgCmd->cBelow);
_CtrlOffset = _parentWin->AddDlgControl(_x, _y , _w, _h, _textId,
style, "EDIT", theText, sizeof(vSpinnerCmd*), (LPBYTE)this);
// Now, build the up/down arrows out of a scroll bar
// Cannot make it a WS_TABSTOP or it shows the blinking thumb...
style = WS_GROUP;
int tx = _x + _w;
int ty = _y;
int th = _h;
int tw = 10;
style |= SBS_VERT;
if (!(dlgCmd->attrs & CA_Hidden)) // Check for Hidden
style |= WS_VISIBLE;
// Some kludgy stuff here. We will call SetPosition, but only
// to make the total size and frame stuff come out right.
// We know where the control goes already.
_parentWin->SetPosition(tx, ty, tw, th, dlgCmd->cFrame, _textId,
dlgCmd->cBelow,1);
(void)/*_CtrlOffset = */_parentWin->AddDlgControl(tx, ty, tw, th, _cmdId,
style, "SCROLLBAR", _title, sizeof(vSpinnerCmd*), (LPBYTE)this);
_w += 10; // add in width of scroll arrows
}
//==================>>> vSpinnerCmd::GetCmdValue <<<=========================
int vSpinnerCmd::GetCmdValue(ItemVal id) VCONST
{
if (id != _cmdId)
return -1;
return _curSelection;
}
//=====================>>> vSpinnerCmd::SetCmdVal <<<=========================
void vSpinnerCmd::SetCmdVal(ItemVal val, ItemSetType st)
{
SysDebug2(Misc,"vSpinnerCmd::SetCmdVal(val:%d, type:%d)\n",val,st)
if (st == ChangeList || st == ChangeListPtr)
{
if (st == ChangeListPtr)
_itemList = dlgCmd->itemList;
int oldMax = _maxWidth; // track current max width
SetupList(); // resetup the list
if (oldMax > _maxWidth)
_maxWidth = oldMax; // don't let it get narrower
// redisplay text
_curSelection = val;
SetCmdVal(_curSelection,Value);
return;
}
else if (st == Hidden) // hide or unhide
{
HWND myHwnd = GetMyHwnd(_cmdId);
if (val)
{
::ShowWindow(myHwnd,SW_HIDE);
}
else
{
::ShowWindow(myHwnd,SW_SHOW);
}
}
else if (st == Value)
{
_curSelection = val; // change the current value
// See if the currently selected item is in the list
if (_TextList) // handle like this for text list
{
if (_itemList)
{
if (_curSelection < 0)
_curSelection = 0;
if (_curSelection >= _numItems)
_curSelection = _numItems - 1;
}
// Now show the new current selection
::SetDlgItemText(_parentWin->getParent(),_textId,
_fullList[_curSelection]);
}
else // integer values
{
char intval[32];
if (_curSelection < _minVal)
_curSelection = _minVal;
if (_curSelection >= _maxVal)
_curSelection = _maxVal;
IntToStr(_curSelection, intval);
::SetDlgItemText(_parentWin->getParent(),_textId,intval);
}
}
else if (st == Sensitive)
{
HWND myHwnd = GetMyHwnd(_cmdId);
_Sensitive = val; // set
::EnableWindow(myHwnd, val);
}
}
//===================>>> vSpinnerCmd::vCmdCallback <<<=======================
void vSpinnerCmd::CmdCallback(int id, WORD codeNotify)
{
// id is the SB_ code, and codeNotify is the position
int down = 1;
switch (id)
{
case SB_LINEDOWN: // Down one line
down = 1;
break;
case SB_LINEUP: // Up one line
down = 0;
break;
}
// Change the value, either in the list or the value.
// The increment will depend on various things
if (_TextList)
{
if (down)
{
if (_TextList && _curSelection < (_numItems-1))
_curSelection += _step;
}
else
{
if (_TextList && _curSelection > 0)
_curSelection -= _step;
}
}
else // up/down mean opposite for numbers
{
if (down)
{
if ((_maxVal == 0 && _minVal == 0) || (_curSelection - _step) >= _minVal)
_curSelection -= _step;
}
else
{
if ((_maxVal == 0 && _minVal == 0) || (_curSelection + _step) <= _maxVal)
_curSelection += _step;
}
}
// Now show the new current selection
SetCmdVal(_curSelection,Value);
if (!(dlgCmd->attrs & CA_NoNotify)) // Notify on each selection?
_parentWin->ProcessCmd(_cmdId, _curSelection, dlgCmd->cmdType);
}
//====================>>> vSpinnerCmd::SetupList <<<=======================
void vSpinnerCmd::SetupList(void)
{
// Set up the list for use
int width;
// First, count how many items are in the supplied list
_fullList = (char**)_itemList; // list
_maxWidth = 0; // no items yet
if (dlgCmd->attrs & CA_Text) // A text list of values
{
_TextList = 1; // This is a text list
_step = 1;
for ( _numItems = 0 ; _fullList[_numItems] != 0 ; ++_numItems)
{
width = strlen(_fullList[_numItems]); // strlen
if (width > _maxWidth)
_maxWidth = width; // track largest so far
}
if (_numItems <= 0)
{
SysDebug(BadVals,"Bad list provided for ValueBox\n");
}
// Set to default value
if (_retVal >= 0 && _retVal < _numItems)
_curSelection = _retVal;
else
_curSelection = 0; // item 0 by default
}
else // an integer list
{
_TextList = 0; // This is an integer list
int* minMaxList = (int *) _itemList; // list
_minVal = 0; _maxVal = 0x7fff; _step = 1;
if (minMaxList != 0) // provided a range list
{
_minVal = minMaxList[0];
_maxVal = minMaxList[1];
_step = minMaxList[2];
// Try to make the width pretty
char buff[20];
IntToStr(_minVal,buff);
_maxWidth = strlen(buff) + 1;
IntToStr(_maxVal,buff);
int maxW = strlen(buff) + 1;
if (maxW > _maxWidth)
_maxWidth = maxW;
}
else
_maxWidth = 6;
_curSelection = _retVal;
}
}
|