1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  ITEMLBL.CC                               */
4 /*                                                                           */
5 /* (C) 1995     Ullrich von Bassewitz                                        */
6 /*              Zwehrenbuehlstrasse 33                                       */
7 /*              D-72070 Tuebingen                                            */
8 /* EMail:       uz@ibb.schwaben.com                                          */
9 /*                                                                           */
10 /*****************************************************************************/
11 
12 
13 
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19 
20 
21 
22 // Class ItemLabel is a special window item that acts as a label for another
23 // window item.
24 
25 
26 
27 #include "streamid.h"
28 #include "itemlbl.h"
29 
30 
31 
32 // Register class ItemLabel
33 LINK (ItemLabel, ID_ItemLabel);
34 
35 
36 
37 /*****************************************************************************/
38 /*                              class ItemLabel                              */
39 /*****************************************************************************/
40 
41 
ItemLabel(const String & aItemText,i16 aID,i16 aCtrlID,WindowItem * NextItem)42 ItemLabel::ItemLabel (const String& aItemText, i16 aID, i16 aCtrlID,
43                       WindowItem* NextItem):
44     WindowItem (aItemText, aID, NextItem),
45     CtrlID (aCtrlID)
46 {
47 }
48 
49 
50 
Store(Stream & S) const51 void ItemLabel::Store (Stream& S) const
52 {
53     WindowItem::Store (S);
54     S << CtrlID;
55 }
56 
57 
58 
Load(Stream & S)59 void ItemLabel::Load (Stream& S)
60 {
61     WindowItem::Load (S);
62     S >> CtrlID;
63 }
64 
65 
66 
StreamableID() const67 u16 ItemLabel::StreamableID () const
68 {
69     return ID_ItemLabel;
70 }
71 
72 
73 
Build()74 Streamable* ItemLabel::Build ()
75 {
76     return new ItemLabel (Empty);
77 }
78 
79 
80 
GetCtrlItem()81 WindowItem* ItemLabel::GetCtrlItem ()
82 // Return a pointer to the controlled item or NULL
83 {
84     if (CtrlID != 0) {
85         return GetRootWindow () -> ItemWithID (CtrlID);
86     } else {
87         return NULL;
88     }
89 }
90 
91 
92 
Gray()93 void ItemLabel::Gray ()
94 {
95     // Gray the label
96     WindowItem::Gray ();
97 
98     // If there is a valid controlled item, gray that one, too
99     WindowItem* Item = GetCtrlItem ();
100     if (Item) {
101         Item->Gray ();
102     }
103 }
104 
105 
106 
Select()107 void ItemLabel::Select ()
108 {
109     // Select the label
110     WindowItem::Select ();
111 
112     // If there is a valid controlled item, select that one, too
113     WindowItem* Item = GetCtrlItem ();
114     if (Item) {
115         Item->Select ();
116     }
117 }
118 
119 
120 
Deselect()121 void ItemLabel::Deselect ()
122 {
123     // Deselect the label
124     WindowItem::Deselect ();
125 
126     // If there is a valid controlled item, deselect that one, too
127     WindowItem* Item = GetCtrlItem ();
128     if (Item) {
129         Item->Deselect ();
130     }
131 }
132 
133 
134 
Choose()135 i16 ItemLabel::Choose ()
136 // Choose an entry
137 {
138     // Item must be active
139     PRECONDITION (IsActive ());
140 
141     // Use the controlled item
142     WindowItem* Item = GetCtrlItem ();
143     if (Item) {
144         Item->Activate ();
145         CtrlChoice = Item->Choose ();
146         Item->Deactivate ();
147         return CtrlChoice ? ID : 0;
148     } else {
149         CtrlChoice = 0;
150         return ID;
151     }
152 }
153 
154 
155 
156