OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
resource.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation classes handling Windows resources
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/resource.h>
10#include <owl/gdiobjec.h>
11#include <owl/gadgetwi.h>
12#include <owl/buttonga.h>
13#include <owl/celarray.h>
14
15
16namespace owl {
17
19
20
21//#if defined(BI_COMP_MSC)
22// const char* szRT_TOOLBAR = RT_TOOLBAR;
23// const char* szRT_NEWDIALOG = RT_NEWDIALOG;
24// const char* szRT_DIALOG = RT_DIALOG;
25//#endif
26
27//
28//
29//
31 : OldResource(nullptr)
32 , NewResource(nullptr)
33{
34 // In 32-bit, favour the new dialog resource over the old one
35 //
37 if (!NewResource->IsOK())
38 // When the new resource cannot be found in 32-bit, try
39 // the old DLGTEMPLATE resource
40 //
42}
43
44//
45//
46//
55
56//
57//
58//
60{
61 delete OldResource;
62 delete NewResource;
63}
64
65
66//
67//
68//
69bool
71{
72 return (NewResource && NewResource->IsOK()) ||
74}
75
76
77//
78//
79//
80bool
82{
84 return (!OldResource || !OldResource->IsOK()) &&
85 ( NewResource && NewResource->IsOK());
86}
87
90{
92 return NewResource->operator DLGTEMPLATEEX*();
93}
94
97{
99 return OldResource->operator DLGTEMPLATE*();
100}
101
102DWORD
104{
106 if (!IsDialogEx())
107 return OldResource->GetSize();
108 else
109 return NewResource->GetSize();
110}
111
112void
114{
115 if (!IsDialogEx()) {
117 rect.left = dlgTemplate->x;
118 rect.right = dlgTemplate->x + dlgTemplate->cx;
119 rect.top = dlgTemplate->y;
120 rect.bottom= dlgTemplate->y + dlgTemplate->cy;
121 } else {
123 rect.left = dlgTemplate->x;
124 rect.right = dlgTemplate->x + dlgTemplate->cx;
125 rect.top = dlgTemplate->y;
126 rect.bottom= dlgTemplate->y + dlgTemplate->cy;
127 }
128}
129
130int
132{
134
135 if (!IsDialogEx()) {
137 p = (LPCWSTR)(dlgTemplate+1);
138 pMenu = p;
139 pClass = pMenu + ((*pMenu == 0xffff) ? 2 : lstrlenW(pMenu)+1);
140 pCaption = pClass + ((*pClass == 0xffff) ? 2 : lstrlenW(pClass)+1);
141 }
142 //else{ Y.B. Finish ??????????????????????????????????????????????????????
143 // DLGTEMPLATEEX* dlgTemplateEx = GetTemplateEx();
144 // !BB Get info about DLGEX!
145 //}
146
147
148 switch (which) {
149 case drtMenuName: p = pMenu; break;
150 case drtClassName: p = pClass; break;
151 case drtCaption: p = pCaption; break;
152 default:
153 return 0;
154 };
155# if defined(UNICODE)
156 int req_size = (*p == 0xffff) ? 2 : lstrlen(p) + 1;
157 if (!buffer || size < req_size) return req_size;
158 if((*p == 0xffff)){
159 memcpy(buffer, p, 2);
160 return 2;
161 }
162 lstrcpy(buffer, p);
163 return lstrlen(buffer);
164# else
165 return WideCharToMultiByte(CP_ACP, 0, p, (*p == 0xffff) ? 2 : lstrlenW(p),
166 buffer, size, nullptr, nullptr);
167# endif
168}
169
170//
171//
172//
174:
176 ToolbarBitmap(nullptr)
177{
179
180 // Following will throw exception in case of failure
181 //
182 ToolbarBitmap = new TBitmap(hInst, id);
183}
184
185//
186//
187//
189{
190 if (ShouldDelete)
191 delete ToolbarBitmap;
192}
193
194//
195//
196//
200 return *(CONST_CAST(TToolbarRes*, this)->operator TOOLBARTEMPLATE*());
201}
202
203//
204//
205//
206TBitmap&
212
213//
214//
215//
216int
219 return TBInfo().count;
220}
221
222//
223//
224//
225ushort*
228 return TBInfo().ids;
229}
230
231//
232//
233//
234int
237 return TBInfo().width;
238}
239
240//
241//
242//
243int
246 return TBInfo().height;
247}
248
249
250//
251//
253:
254 Win(win),
255 TbarRes(nullptr),
256 Id(id),
257 Hinst(hinst)
258{
259}
260
261//
262//
263//
265{
266 delete TbarRes;
267}
268
269//
270// Populate the gadgetwindow with button gadgets and separators using a
271// bitmap and toolbar resource pair. Returns true if the resource was
272// successfully loaded and the gadgets created and false otherwise.
273//
274void
276{
277 // Default to window's module if none was specified
278 //
279 if (!Hinst)
280 Hinst = *(Win.GetModule());
281
282 // NOTE: Don't let the TToolbarRes instance own the bitmap, we'll hand
283 // it to the celarray instead.
284 //
286
287 CHECK(TbarRes->IsOK());
289 TbarRes->GetCount(),
291 TbarRes->GetHeight()));
292 // Hand celarray to gadgetwindow
293 // NOTE: Nice enhancement would be to add/merge toolbar resources using
294 // TCelArray's Add(TCelArray& src, index) method if the window
295 // already has a celarray. Unfortunately, the tbar resource does
296 // provide a method to specify insertion indices to make this
297 // approach usable. So we'll wipe out the previous celarray.
298 //
300
301 // Create gadgets based on resource information
302 //
303 for (int i=0, j=0; i<TbarRes->GetCount(); i++) {
304 if (TbarRes->GetIds()[i] == 0)
306 else {
309 TButtonGadget::Up, true));
310 }
311 }
312}
313
314} // OWL namespace
315/* ========================================================================== */
316
Definition of class TButtonGadget.
Definition of a bitmap Cel array class.
#define CHECK(condition)
Definition checks.h:239
#define PRECONDITION(condition)
Definition checks.h:227
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition gdiobjec.h:510
HBITMAP GetHandle() const
Returns the handle of the bitmap of type BITMAP.
Definition gdiobjec.h:1355
Derived from TGadget, TButtonGadget represent buttons that you can click on or off.
Definition buttonga.h:65
@ Up
Current state of this button.
Definition buttonga.h:81
@ Command
Basic type of this button.
Definition buttonga.h:70
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
DWORD GetSize() const
Definition resource.cpp:103
TResource< DLGTEMPLATEEX, static_cast< int >(RtNewDialog)> * NewResource
Definition resource.h:160
DLGTEMPLATEEX * GetTemplateEx() const
Definition resource.cpp:89
TDialogRes(HINSTANCE hInstance, TResId id)
Definition resource.cpp:30
TResource< DLGTEMPLATE, static_cast< int >(RtDialog)> * OldResource
Definition resource.h:159
bool IsDialogEx() const
Definition resource.cpp:81
void GetRect(TRect &rect) const
Definition resource.cpp:113
TDlgResText
Enumeration of various strings stored with a dialog resource.
Definition resource.h:146
@ drtCaption
Caption of dialog.
Definition resource.h:149
@ drtClassName
Class name of dialog.
Definition resource.h:148
@ drtMenuName
String of menu resource used by dialog.
Definition resource.h:147
bool IsOK() const
Definition resource.cpp:70
int GetText(TCHAR *buffer, int size, TDlgResText which=drtCaption) const
Definition resource.cpp:131
DLGTEMPLATE * GetTemplate() const
Definition resource.cpp:96
Derived from TWindow, TGadgetWindow maintains a list of tiled gadgets for a window and lets you dynam...
Definition gadgetwi.h:122
void Insert(TGadget &, TPlacement=After, TGadget *sibling=nullptr) override
Inserts a gadget before or after a sibling gadget (TPlacement).
virtual void SetCelArray(TCelArray *sharedCels)
Sets a new Shared CelArray for this gadget window.
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TResource simplifies access to a resource by encapsulating the find, load, lock and free steps for ac...
Definition wsyscls.h:498
bool IsOK() const
Confirms whether resource was found.
Definition wsyscls.h:676
DWORD GetSize() const
Returns the size in bytes of the loaded resource.
Definition wsyscls.h:700
TSeparatorGadget is a simple class you can use to create a separator between gadgets.
Definition gadget.h:354
The tagSIZE struct is defined as.
Definition geometry.h:234
TToolbarBldr(TGadgetWindow &win, TResId id, HINSTANCE hinst=0)
Definition resource.cpp:252
HINSTANCE Hinst
Definition resource.h:115
TToolbarRes * TbarRes
Definition resource.h:113
TGadgetWindow & Win
Definition resource.h:112
TToolbarRes(HINSTANCE hInst, TResId id, TAutoDelete del=AutoDelete)
Definition resource.cpp:173
ushort * GetIds() const
Definition resource.cpp:226
TBitmap & GetBitmap()
Definition resource.cpp:207
int GetCount() const
Definition resource.cpp:217
TBitmap * ToolbarBitmap
Definition resource.h:97
int GetWidth() const
Definition resource.cpp:235
TOOLBARTEMPLATE & TBInfo() const
Definition resource.cpp:198
int GetHeight() const
Definition resource.cpp:244
TModule * GetModule() const
Returns a pointer to the module object.
Definition window.h:1841
Definition of TGadgetList, TGadgetWindow & TGadgetWindowFont A list holding gadgets,...
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ AutoDelete
Definition gdibase.h:70
@ NoAutoDelete
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned short ushort
Definition number.h:24
@ RtToolbar
Definition resource.h:39
OWL_DIAGINFO
Definition animctrl.cpp:14
#define CONST_CAST(targetType, object)
Definition defs.h:273
Defines classes handling Windows resources.
Structure describing the binary layout of toolbar resources.
Definition resource.h:70
ushort width
Width of each bitmap glyph.
Definition resource.h:72
ushort ids[1]
Array of ids of glyphs+separators.
Definition resource.h:75
ushort height
Height of each bitmap glyph.
Definition resource.h:73
ushort count
Number of glyphs.
Definition resource.h:74