OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
gadgetli.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TGadgetList, the base for classes that own gadgets
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/gadget.h>
10#include <owl/gadgetwi.h>
11
12namespace owl {
13
15
17:
18 Gadgets(nullptr),
19 NumGadgets(0)
20{
21}
22
23//
24//
25//
27{
28 TGadget* gadget = Gadgets;
29
30 while (gadget) {
32 gadget = gadget->Next;
33 delete tmp;
34 }
35}
36
37//
38/// Returns the gadget that a given window-relative point is in, or 0 if none is
39/// found.
40//
43{
44 TGadget* gadget = Gadgets;
45 for (; gadget; gadget = gadget->Next)
46 if (gadget->PtIn(point - *reinterpret_cast<TSize*>(&gadget->Bounds.TopLeft())))
47 break;
48
49 return gadget;
50}
51
52//
53/// Returns the gadget with a given ID, or 0 if none is found.
54//
57{
58 for (TGadget* g = Gadgets; g; g = g->NextGadget())
59 if (g->GetId() == id)
60 return g;
61 return nullptr;
62}
63
64//
65/// Returns gadget at a given index.
66//
69{
70 PRECONDITION(index < NumGadgets);
71
72 TGadget* g;
73 for (g = FirstGadget(); index > 0; index--)
74 g = NextGadget(*g);
75 return g;
76}
77
78//
79/// Inserts a Gadget. Caller also needs to call LayoutSession() after inserting
80/// gadgets if this window has already been created.
81///
82/// You can specify a sibling Gadget that the new Gadget
83/// is to be inserted before or after
84///
85/// If "sibling" is 0 then the new Gadget is inserted at the beginning or
86/// the end. The default is to insert the new Gadget at the end
87//
88void
90{
91 PRECONDITION(!gadget.Window); // Would cause problems if still in a window
92
93 TGadget** g = &Gadgets;
94
95 // Locate spot to insert gadget
96 //
97 if (sibling || placement == After) {
98 while (*g && *g != sibling)
99 g = &(*g)->Next;
100
101 CHECK(*g == sibling);
102 }
103 if (placement == After && *g)
104 g = &(*g)->Next;
105
106 // Link supplied gadget into this list
107 //
108 gadget.Next = *g;
109 *g = &gadget;
110
111 // Update count
112 //
113 NumGadgets++;
114
116}
117
118//
119/// Inserts a list of gadgets. Caller also needs to call LayoutSession() after
120/// inserting gadgets if this window has already been created.
121///
122/// Gadgets are removed from the source list
123//
124void
126{
127 if (!list.Gadgets)
128 return;
129
130 TGadget** g = &Gadgets;
131
132 // Locate spot to insert gadgets
133 //
134 if (sibling || placement == After) {
135 while (*g && *g != sibling)
136 g = &(*g)->Next;
137
138 CHECK(*g == sibling);
139 }
140 if (placement == After && *g)
141 g = &(*g)->Next;
142
143 // Find tail of list. Let the source list & this list know about the transfer
144 // as we go.
145 //
146 TGadget* last;
147 for (TGadget* gd = list.Gadgets; gd; gd = gd->Next) {
148 list.Removed(*gd);
149 Inserted(*gd);
150 last = gd;
151 }
152
153 // Link supplied list into this list
154 //
155 last->Next = *g;
156 *g = list.Gadgets;
157
158 // Update counts & source list pointer
159 //
160 NumGadgets += list.NumGadgets;
161 list.Gadgets = nullptr;
162 list.NumGadgets = 0;
163}
164
165//
166/// Remove (unlinks) a gadget from this gadget window. The gadget is returned but
167/// not destroyed. Returns 0 if gadget is not in this window. Caller also needs to
168/// call LayoutSession() after inserting/removing gadgets if this gadget window has
169/// already been created.
170//
171TGadget*
173{
174 if (!Gadgets)
175 return nullptr;
176
177 // Handle head-of-list case
178 //
179 if (&gadget == Gadgets) {
180 Gadgets = Gadgets->Next;
181 }
182 // Scan for gadget, looking one link ahead
183 //
184 else {
185 TGadget* g = Gadgets;
186
187 while (g->Next && g->Next != &gadget)
188 g = g->Next;
189
190 if (!g->Next) // not found
191 return nullptr;
192
193 g->Next = g->Next->Next;
194 }
195
196 NumGadgets--;
197
199
200 return &gadget;
201}
202
203//
204/// A gadget has been inserted. Derived class can override this to update
205/// internals
206//
207void
209{
210}
211
212//
213/// A gadget has been removed. Derived class can override this to update
214/// internals
215//
216void
218{
219}
220
221
222} // OWL namespace
223
#define CHECK(condition)
Definition checks.h:239
#define PRECONDITION(condition)
Definition checks.h:227
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
TGadgetList is a list of gadgets with management functions.
Definition gadgetwi.h:35
TGadget * operator[](uint index)
Returns gadget at a given index.
Definition gadgetli.cpp:68
TGadget * NextGadget(TGadget &gadget) const
Returns the next gadget in the list relative to a given gadget.
Definition gadgetwi.h:407
virtual void Inserted(TGadget &gadget)
A gadget has been inserted.
Definition gadgetli.cpp:208
TPlacement
Enumerates the placement of a gadget.
Definition gadgetwi.h:47
virtual void Removed(TGadget &gadget)
A gadget has been removed.
Definition gadgetli.cpp:217
TGadget * GadgetFromPoint(const TPoint &point) const
Returns the gadget that a given window-relative point is in, or 0 if none is found.
Definition gadgetli.cpp:42
TGadget * GadgetWithId(int id) const
Returns the gadget with a given ID, or 0 if none is found.
Definition gadgetli.cpp:56
virtual ~TGadgetList()
Definition gadgetli.cpp:26
virtual void Insert(TGadget &gadget, TPlacement=After, TGadget *sibling=nullptr)
Inserts a Gadget.
Definition gadgetli.cpp:89
virtual void InsertFrom(TGadgetList &list, TPlacement=After, TGadget *sibling=nullptr)
Inserts a list of gadgets.
Definition gadgetli.cpp:125
virtual TGadget * Remove(TGadget &gadget)
Removes (unlinks) a gadget.
Definition gadgetli.cpp:172
TGadget * FirstGadget() const
Returns the first gadget of the list.
Definition gadgetwi.h:400
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
The tagSIZE struct is defined as.
Definition geometry.h:234
Base class TGadget and simple derived TSeparatorGadget.
Definition of TGadgetList, TGadgetWindow & TGadgetWindowFont A list holding gadgets,...
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned int uint
Definition number.h:25