OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
bitmapga.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TBitmapGadget
7/// Implementation of class TDynamicBitmapGadget
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/bitmapga.h>
11#include <owl/gadgetwi.h>
12#include <owl/celarray.h>
13
14namespace owl {
15
17DIAG_DECLARE_GROUP(OwlGadget); // diagnostic group for gadgets
18
19//
20/// Construct a bitmap gadget
21//
22/// Constructs a TBitmapGadget and sets the current image to the beginning image
23/// (startImage) in the array of images. Then, sets the border style to the current
24/// TGadget border style and numImages to the number of images in the array.
25///
26/// If sharedCels is false, imageResIdOrIndex specifies a single bitmap image that
27/// can be evenly divided into numImages parts. If sharedCels is true,
28/// imageResIdOrIndex specifies the starting image to use in the common
29/// TGadgetWindow bitmap image.
30//
32 int id,
34 int numImages,
35 int startImage,
36 bool sharedCels)
37:
39 ImageArray(nullptr), // Created on first call to GetDesiredSize
40 CurrentImage(startImage),
41 NumImages(numImages),
42 BitmapOrigin(0)
43{
44 if (sharedCels) {
45 ResId = 0;
46 ImageIndex = imageResIdOrIndex.GetInt();
47 }
48 else {
49 ResId = imageResIdOrIndex;
50 ImageIndex = 0;
51 }
52
53 TRACEX(OwlGadget, OWL_CDLEVEL, "TBitmapGadget constructed @" << this);
54}
55
56//
57/// Destruct a bitmap gadget and free its resources
58//
59/// Deletes the array of images.
60//
62{
63 delete ImageArray;
64 TRACEX(OwlGadget, OWL_CDLEVEL, "TBitmapGadget destructed @" << this);
65}
66
67//
68/// When the system colors have been changed, SysColorChange is called by the gadget
69/// window's EvSysColorChange so that bitmap gadgets can be rebuilt and repainted.
70//
71/// Handle a system color change by cleaning up & reloading & processing the
72/// bitmap. Is also called to create the initial bitmap.
73//
74void
76{
77 TCelArray* a = ResId ? CreateCelArray(ResId, NumImages) : nullptr;
78 delete ImageArray;
79 ImageArray = a;
80}
81
82//virtual
91
92//
93/// Set the bounding rect for this button gadget. Also takes care of
94/// re-centering the image
95//
96/// Calls TGadget::SetBounds and passes the dimensions of the bitmap gadget.
97/// SetBounds informs the control gadget of a change in its bounding rectangle.
98//
99void
101{
102 TRACEX(OwlGadget, 1, "TBitmapGadget::SetBounds() called @" << this);
104
107
108 TSize bitmapSize = ImageArray->CelSize();
109
110 BitmapOrigin.x = innerRect.left + (innerRect.Width()-bitmapSize.cx)/2;
111 BitmapOrigin.y = innerRect.top + (innerRect.Height()-bitmapSize.cy)/2;
112}
113
114//
115/// Find out how big this bitmap gadget wants to be. Calculated using the base
116/// size to get the borders, etc. plus the image size.
117//
118/// Calls TGadget::GetDesiredSize, which determines how big the bitmap gadget can
119/// be. The gadget window sends this message to query the gadget's size. If
120/// shrink-wrapping is requested, GetDesiredSize returns the size needed to
121/// accommodate the borders and margins. If shrink-wrapping is not requested, it
122/// returns the gadget's current width and height. TGadgetWindow needs this
123/// information to determine how big the gadget needs to be, but it can adjust these
124/// dimensions if necessary. If WideAsPossible is true, then the width parameter
125/// (size.cx) is ignored.
126//
127void
129{
130 TRACEX(OwlGadget, 1, "TBitmapGadget::GetDesiredSize() called @" << this);
132
133 if (!ImageArray)
134 SysColorChange(); // Get the initial bitmap
135
136 size += (ImageArray ? ImageArray->CelSize() : GetGadgetWindow()->GetCelArray().CelSize());
137}
138
139//
140/// Choose the relative image to display. If immediate is true, this gadget is
141/// repainted immediately
142//
143int
145{
146 PRECONDITION(imageNum >=0 && imageNum < NumImages);
147
148 uint oldImageNum = CurrentImage;
149
150 if (imageNum != CurrentImage) {
151 CurrentImage = imageNum;
152 Invalidate(false);
153 }
154
155 if (immediate)
156 Update();
157 return oldImageNum;
158}
159
160//
161/// Paint this bitmap gadget. Uses normal borders, plus draws the image centered
162//
163void
165{
166 PaintBorder(dc);
167
170
171 TCelArray& imageArray = ImageArray ? *ImageArray : GetGadgetWindow()->GetCelArray();
172
173 imageArray.BitBlt(ImageIndex+CurrentImage, dc, destRect.left, destRect.top);
174}
175
176//
177/// \class TDynamicBitmapGadgetEnabler
178// ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
179//
180# if defined(BI_COMP_BORLANDC)
181# pragma warn -inl
182# endif
183class TDynamicBitmapGadgetEnabler : public TCommandEnabler {
184 public:
185 TDynamicBitmapGadgetEnabler(TWindow::THandle hReceiver,
187 :
189 Gadget(g)
190 {
191 }
192
193 // Override TCommandEnabler virtuals
194 //
195 void Enable(bool enable);
196 void SetText(LPCTSTR){}
197 void SetCheck(int state);
198
199 protected:
200 TDynamicBitmapGadget* Gadget;
201};
202# if defined(BI_COMP_BORLANDC)
203# pragma warn .inl
204# endif
205
206//
207void TDynamicBitmapGadgetEnabler::Enable(bool enable)
208{
210 if(Gadget->GetEnabled() != enable)
211 Gadget->SetEnabled(enable);
212}
213//
214void TDynamicBitmapGadgetEnabler::SetCheck(int state)
215{
216 Gadget->SelectImage(state, false);
217}
218//
219
220//--------------------------------------------------------
221/// TDynamicBitmapGadget Constructor
222//
231
232//
234{
235 PRECONDITION(Window);
236
237 // Must send, not post here, since a ptr to a temp is passed
238 //
239 // This might be called during idle processing before the
240 // HWND has created. Therefore, confirm handle exists.
241 //
242 if (GetGadgetWindow()->GetHandle()){
243 TDynamicBitmapGadgetEnabler ge(*GetGadgetWindow(), this);
245 }
246}
247//
248
249} // OWL namespace
250//==================================================================================
251
252
Definition of class TBitmapGadget Definition of class TDynamicBitmapGadget.
Definition of a bitmap Cel array class.
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
Derived from TGadget, TBitmapGadget is a simple gadget that can display an array of bitmap images one...
Definition bitmapga.h:33
void SetBounds(const TRect &boundRect)
Set the bounding rect for this button gadget.
Definition bitmapga.cpp:100
void SysColorChange()
When the system colors have been changed, SysColorChange is called by the gadget window's EvSysColorC...
Definition bitmapga.cpp:75
TBitmapGadget(TResId imageResIdOrIndex, int id, TBorderStyle borderStyle, int numImages, int startImage=0, bool sharedCels=false)
Construct a bitmap gadget.
Definition bitmapga.cpp:31
void Paint(TDC &dc)
Paint this bitmap gadget. Uses normal borders, plus draws the image centered.
Definition bitmapga.cpp:164
~TBitmapGadget()
Destruct a bitmap gadget and free its resources.
Definition bitmapga.cpp:61
int SelectImage(int imageNum, bool immediate)
Choose the relative image to display.
Definition bitmapga.cpp:144
virtual TCelArray * CreateCelArray(TResId resId, int numImages) const
Definition bitmapga.cpp:84
void GetDesiredSize(TSize &size)
Find out how big this bitmap gadget wants to be.
Definition bitmapga.cpp:128
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
TSize CelSize() const
Return the size of the celarray.
Definition celarray.h:133
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
uint GetId() const
Retrieves the id of the command.
Definition window.h:1695
virtual void Enable(bool enable=true)
Enables or disables the command sender.
Definition window.cpp:301
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
Pseudo-GDI object Device Independent Bitmap (DIB) class.
Definition gdiobjec.h:795
@ MapHighlight
Definition gdiobjec.h:913
Class will send EvEnable message to window, so you can set bitmap, using SetCheck() method of TComman...
Definition bitmapga.h:74
TDynamicBitmapGadget(TResId imageResIdOrIndex, int id, TBorderStyle borderStyle, int numImages, int startImage=0, bool sharedCels=false)
TDynamicBitmapGadget Constructor.
Definition bitmapga.cpp:223
virtual void CommandEnable()
Definition bitmapga.cpp:233
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
void Invalidate(bool erase=true)
Used to invalidate the active (usually nonborder) portion of the gadget, Invalidate calls InvalidateR...
Definition gadget.cpp:408
void GetInnerRect(TRect &rect)
Computes the area of the gadget's rectangle excluding the borders and margins.
Definition gadget.cpp:514
TGadgetWindow * GetGadgetWindow()
Return a pointer to the owning or parent window for the gadget.
Definition gadget.h:536
virtual void SetBounds(const TRect &rect)
Called by the gadget window to inform the gadget of a change in its bounding rectangle.
Definition gadget.cpp:211
bool GetEnabled() const
Determines whether keyboard and mouse input have been enabled for the specified gadget.
Definition gadget.h:458
TBorderStyle
Gadget border styles.
Definition gadget.h:127
virtual void SetEnabled(bool enabled)
Enables or disables keyboard and mouse input for the gadget.
Definition gadget.cpp:194
void Update()
Paint now if possible.
Definition gadget.cpp:417
virtual void GetDesiredSize(TSize &size)
Request by the gadget window to query the gadget's desired size.
Definition gadget.cpp:479
virtual void PaintBorder(TDC &dc)
Self sent by method Paint().
Definition gadget.cpp:432
virtual TCelArray & GetCelArray(int minX=0, int minY=0)
Gets the Shared CelArray for this gadget window.
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
TResult HandleMessage(TMsgId, TParam1=0, TParam2=0)
Dispatches the given message using the response table.
Definition window.cpp:1392
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
#define WM_COMMAND_ENABLE
Definition dispatch.h:4103
Definition of TGadgetList, TGadgetWindow & TGadgetWindowFont A list holding gadgets,...
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
OWL_DIAGINFO
Definition animctrl.cpp:14
#define OWL_CDLEVEL
Definition defs.h:171