File: vboxlblc.cpp

package info (click to toggle)
libv1.22 1.22-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,380 kB
  • ctags: 9,765
  • sloc: cpp: 58,097; ansic: 6,814; makefile: 1,597; java: 515; sh: 24
file content (192 lines) | stat: -rw-r--r-- 5,647 bytes parent folder | download | duplicates (2)
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
//===============================================================
// vstatlbl.cxx	- boxed label for stat bar - 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/vapp.h>
#include <v/vboxlblc.h>	// our definitions
#include <v/vcmdprnt.h>	// a command parent

//=====================>>> vBoxedLabelCmd::vBoxedLabelCmd <<<================
  vBoxedLabelCmd::vBoxedLabelCmd(vCmdParent* dp, CommandObject* dc) :
    vCmd(dp, dc)
  {
    initialize();
  }

//=================>>> vBoxedLabelCmd::~vBoxedLabelCmd <<<===================
  vBoxedLabelCmd::~vBoxedLabelCmd()
  {

    SysDebug(Destructor,"vBoxedLabelCmd::~vBoxedLabelCmd() destructor\n")

  }

//=====================>>> vBoxedLabelCmd::initialize <<<=====================
  void vBoxedLabelCmd::initialize(void)
  {
    // build a button command for use in a parent window


    SysDebug(Constructor,"vBoxedLabelCmd::vBoxedLabelCmd() constructor\n")

    
    long style = BS_OWNERDRAW | WS_GROUP;	// default for a button

    CopyToLocal();			// Make local copies of CmdObject


    if (!(dlgCmd->attrs & CA_Hidden))		// Check for Hidden
	style |= WS_VISIBLE;

    int tl = strlen(_title);

    if ( tl < 80)
	strcpy(_lbl,_title);
    else
	strcpy(_lbl,"????????");

    if (dlgCmd->size > 0)		// may reset title!
      {
	_w = dlgCmd->size;
      }
     else
	_w = LabelWidth(_lbl) + 4;	// set my width

    _h = 11;			      	// default height

    _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame, dlgCmd->cRightOf,
	dlgCmd->cBelow);


    _CtrlOffset = _parentWin->AddDlgControl(_x, _y, _w, _h, _cmdId,
	  style, "BUTTON", _lbl, sizeof(vBoxedLabelCmd), (LPBYTE)this);
  }

//================>>> vBoxedLabelCmd::SetCmdVal <<<===========================
  void vBoxedLabelCmd::SetCmdVal(ItemVal val, ItemSetType st)
  {

    SysDebug1(Misc,"vBoxedLabelCmd::SetCmdVal(val:%d)\n",val)

    HWND myHwnd = GetMyHwnd(_cmdId);
    if (st == Sensitive)		// used so icons won't get
      {                                 // focus -- icons use ownerdraw,
	_Sensitive = val;	// which behave like buttons, not
	::EnableWindow(myHwnd, val);    // static labels -- this fixes that
      }
    else if (st == Hidden)		// hide or unhide
      {
	if (val)
	  {
	    ::ShowWindow(myHwnd,SW_HIDE);
	  }
	else
	  {
	    ::ShowWindow(myHwnd,SW_SHOW);
	  }
      }
 }

//================>>> vBoxedLabelCmd::SetCmdStr <<<===========================
  void vBoxedLabelCmd::SetCmdStr(VCONST char* str)
  {

    SysDebug1(Misc,"vBoxedLabelCmd::SetCmdStr(str:%s)\n",str)

    HWND myHwnd = GetMyHwnd(_cmdId);
    strcpy(_lbl,str);
    _title = _lbl;
    ::RedrawWindow(myHwnd,NULL,NULL,RDW_INVALIDATE);

  }


//================>>> vBoxedLabelCmd::MEASUREITEM <<<=========================
  int vBoxedLabelCmd::MEASUREITEM(int id, MEASUREITEMSTRUCT* mis)
  {
    mis->CtlType = ODT_BUTTON;
    mis->CtlID = id;
    mis->itemWidth = _w;
    mis->itemHeight = _h;
    
    return 1;
  }

//================>>> vBoxedLabelCmd::DRAWITEM <<<============================
  int vBoxedLabelCmd::DRAWITEM(int /* id */, DRAWITEMSTRUCT* dis)
  {
    switch (dis->itemAction)
      {
	case ODA_DRAWENTIRE:	// redraw entire control
	  {
	    // This gets called after the CTLCOLOR message has been
	    // processed in the dialog/commandpane procs.
	    // We are using LTGRAY_BRUSH for dialogs and command bars.
	    // We need to draw the icon properly on the background.
	    // We will use a null pen, and the same background. We have
	    // to use left-1, top-1, right+1, and bottom+1 to have the
	    // interior of the rectangle in the icon's area. We end up
	    // with a white line otherwise. First, fill gray background

	    
	    HPEN oldpen = (HPEN) ::SelectObject(dis->hDC, GetStockObject(NULL_PEN));

	    HBRUSH oldbrush = static_cast<HBRUSH>(::SelectObject(dis->hDC,
					     theApp->_BarBrush));

	    (void)::Rectangle(dis->hDC,dis->rcItem.left, dis->rcItem.top,
		dis->rcItem.right+1, dis->rcItem.bottom+1);

	    if (!(dlgCmd->attrs & CA_NoBorder))
	      {
	    ::SelectObject(dis->hDC, theApp->_ShadowPen);
	    ::MoveTo(dis->hDC, dis->rcItem.left+1, dis->rcItem.bottom-1);
	    ::LineTo(dis->hDC, dis->rcItem.left+1, dis->rcItem.top);
	    ::LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top);
	   
	    ::SelectObject(dis->hDC,theApp->_LightPen);
	    ::MoveTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top);
	    ::LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.bottom-1);
	    ::LineTo(dis->hDC, dis->rcItem.left+1, dis->rcItem.bottom-1);
              }

	    int oldBkMode = ::GetBkMode(dis->hDC);
	    ::SetBkMode(dis->hDC,TRANSPARENT);
	    ::DrawText(dis->hDC, _lbl, strlen(_lbl),
		      &dis->rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	    ::SetBkMode(dis->hDC,oldBkMode);


	    ::SelectObject(dis->hDC, oldpen);	// restore hdc
	    ::SelectObject(dis->hDC, oldbrush);

	    return 1;
	  }

	case ODA_SELECT:	// indicated selected
	  {
	    return 1;		// no op for icon Frame
	  }

	case ODA_FOCUS:		// gets focus
	  {
	    return 1;		// no op for icon Frame
	  }
      }
    return 0;
  }

//===================>>> vBoxedLabelCmd::vCmdCallback <<<=======================
  void vBoxedLabelCmd::CmdCallback(int /* id */, WORD codeNotify)
  {
   // No Op for a label
  }