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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359 | % | /¯ /¯\ |\ |
%\ W X | \_, \_/ | \| . E R L
%%
%%
%% Copyright Ericsson AB 2008-2013. All Rights Reserved.
%%
%%
%% Whitespace Beautified by ScriptCulture © 2018
%% Sit Back · Feet Up · Learn wxErlang
%% For use as a reference only
%% www.scriptculture.com
%% Not check-summed
%% wx 1.8
%%
%% Licensed under the Apache License,
%% Version 2.0 (the "License"); you may
%% not use this file except in compliance
%% with the License. You may obtain a copy
%% of the License at:
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by
%% applicable law or agreed to in writing, software
%% distributed under the License is distributed
%% on an "AS IS" BASIS, WITHOUT WARRANTIES
%% OR CONDITIONS OF ANY KIND, either
%% express or implied. See the
%% License for the specific
%% language governing
%% permissions and
%% limitations
%% under the
%% License.
%%%%%%%
%%%%
%%%%%
%% @doc See external documentation: <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxicon.html">wxIcon</a>.
%% <p>This class is derived (and can use functions) from:
%% <br />{@link wxBitmap}
%% </p>
%% @type wxIcon().
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% OVERVIEW
%% ––––––––
%% An icon is a small rectangular bitmap usually used for
%% denoting a minimized application. It differs from a wxBitmap
%% in always having a mask associated with it for transparent drawing.
%% On some platforms, icons and bitmaps are implemented identically,
%% since there is no real distinction between a wxBitmap with a
%% mask and an icon; and there is no specific icon format on
%% some platforms (X-based applications usually standardize
%% on XPMs for small bitmaps and icons). However, some
%% platforms (such as Windows) make the distinction,
%% so a separate class is provided.
%%
%% It is usually desirable to associate a pertinent icon with a frame.
%% Icons can also be used for other purposes,
%% for example with wxTreeCtrl and wxListCtrl.
%%
%% Icons have different formats on different platforms.
%% Therefore, separate icons will usually be created
%% for the different environments. Platform-specific
%% methods for creating a wxIcon structure are catered
%% for, and this is an occasion where conditional
%% compilation will probably be required.
%%
%% Note that a new icon must be created for every
%% time the icon is to be used for a new window.
%% In Windows, the icon will not be reloaded if
%% it has already been used. An icon allocated
%% to a frame will be deleted when the frame is deleted.
%%
%% For more information please see Bitmap and icon overview.
%%
%% See Also:
%% —————————
%% wxDC::DrawIcon, wxCursor
%%
%%
-module(wxIcon).
-include("wxe.hrl").
-export([copyFromBitmap/2,destroy/1,new/0,new/1,new/2]).
%% inherited exports
-export([convertToImage/1,copyFromIcon/2,getDepth/1,getHeight/1,getMask/1,getPalette/1,
getSubBitmap/2,getWidth/1,loadFile/2,loadFile/3,ok/1,parent_class/1,
saveFile/3,saveFile/4,setDepth/2,setHeight/2,setMask/2,setPalette/2,
setWidth/2]).
-export_type([wxIcon/0]).
%% @hidden
parent_class(wxBitmap) -> true;
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).
-type wxIcon() :: wx:wx_object().
%·%% NEW / 0 %%·%
%%
%%
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec new() -> wxIcon().
new() ->
wxe_util:construct(?wxIcon_new_0,
<<>>).
%·%% NEW / 1 %%·%
%%
%% Loads an icon from a file or resource.
%%
%% Loads an icon from the specified location.
%%
%% Return Value:
%% See Also:
%%*%%*%%
%% <br /> Also:<br />
%% new(Loc) -> wxIcon() when<br />
%% Loc :: wx:wx_object().<br />
%%
%% Type = ?wxBITMAP_TYPE_INVALID
%% | ?wxBITMAP_TYPE_BMP | ?wxBITMAP_TYPE_BMP_RESOURCE | ?wxBITMAP_TYPE_RESOURCE
%% | ?wxBITMAP_TYPE_ICO | ?wxBITMAP_TYPE_ICO_RESOURCE
%% | ?wxBITMAP_TYPE_CUR | ?wxBITMAP_TYPE_CUR_RESOURCE
%% | ?wxBITMAP_TYPE_XBM | ?wxBITMAP_TYPE_XBM_DATA
%% | ?wxBITMAP_TYPE_XPM | ?wxBITMAP_TYPE_XPM_DATA
%% | ?wxBITMAP_TYPE_TIF | ?wxBITMAP_TYPE_TIF_RESOURCE
%% | ?wxBITMAP_TYPE_GIF | ?wxBITMAP_TYPE_GIF_RESOURCE
%% | ?wxBITMAP_TYPE_PNG | ?wxBITMAP_TYPE_PNG_RESOURCE
%% | ?wxBITMAP_TYPE_JPEG | ?wxBITMAP_TYPE_JPEG_RESOURCE
%% | ?wxBITMAP_TYPE_PNM | ?wxBITMAP_TYPE_PNM_RESOURCE
%% | ?wxBITMAP_TYPE_PCX | ?wxBITMAP_TYPE_PCX_RESOURCE
%% | ?wxBITMAP_TYPE_PICT | ?wxBITMAP_TYPE_PICT_RESOURCE
%% | ?wxBITMAP_TYPE_ICON | ?wxBITMAP_TYPE_ICON_RESOURCE
%% | ?wxBITMAP_TYPE_ANI
%% | ?wxBITMAP_TYPE_IFF
%% | ?wxBITMAP_TYPE_TGA
%% | ?wxBITMAP_TYPE_MACCURSOR | ?wxBITMAP_TYPE_MACCURSOR_RESOURCE
%% | ?wxBITMAP_TYPE_ANY
-spec new(Filename) -> wxIcon()
when
Filename :: unicode:chardata();
(Loc) -> wxIcon()
when
Loc :: wx:wx_object().
new(Filename)
when
is_list(Filename) -> new(Filename, []);
new(#wx_ref{type=LocT,ref=LocRef}) ->
?CLASS(LocT,wx),
wxe_util:construct(?wxIcon_new_1,
<<LocRef:32/?UI>>).
%·%% NEW / 2 %%·%
%%
%% desiredWidth
%%
%% Specifies the desired width of the icon.
%% This parameter only has an effect in Windows
%% (32-bit) where icon resources can contain several
%% icons of different sizes.
%%
%% desiredWidth
%%
%% Specifies the desired height of the icon.
%% This parameter only has an effect in Windows
%% (32-bit) where icon resources can contain several
%% icons of different sizes.
%%
%%
%% REMARKS
%%
%% The first form constructs an icon object with no data;
%% an assignment or another member function such as Create
%% or LoadFile must be called subsequently.
%%
%% The second and third forms provide copy constructors.
%% Note that these do not copy the icon data, but instead
%% a pointer to the data, keeping a reference count.
%% They are therefore very efficient operations.
%%
%% The fourth form constructs an icon from data whose type
%% and value depends on the value of the type argument.
%%
%% The fifth form constructs a (usually monochrome) icon
%% from an array of pixel values, under both X and Windows.
%%
%% The sixth form constructs a new icon.
%%
%% The seventh form constructs an icon from pixmap (XPM) data,
%% if wxWidgets has been configured to incorporate this feature.
%%
%%
%% Return Value:
%% See Also:
%%*%%*%%
%%
%% Type = ?wxBITMAP_TYPE_INVALID | ?wxBITMAP_TYPE_BMP_RESOURCE |
%% ?wxBITMAP_TYPE_BMP | ?wxBITMAP_TYPE_RESOURCE |
%% ?wxBITMAP_TYPE_ICO | ?wxBITMAP_TYPE_ICO_RESOURCE |
%% ?wxBITMAP_TYPE_CUR | ?wxBITMAP_TYPE_CUR_RESOURCE |
%% ?wxBITMAP_TYPE_XBM | ?wxBITMAP_TYPE_XBM_DATA |
%% ?wxBITMAP_TYPE_XPM | ?wxBITMAP_TYPE_XPM_DATA |
%% ?wxBITMAP_TYPE_TIF | ?wxBITMAP_TYPE_TIF_RESOURCE |
%% ?wxBITMAP_TYPE_GIF | ?wxBITMAP_TYPE_GIF_RESOURCE |
%% ?wxBITMAP_TYPE_PNG | ?wxBITMAP_TYPE_PNG_RESOURCE |
%% ?wxBITMAP_TYPE_JPEG | ?wxBITMAP_TYPE_JPEG_RESOURCE |
%% ?wxBITMAP_TYPE_PNM | ?wxBITMAP_TYPE_PNM_RESOURCE |
%% ?wxBITMAP_TYPE_PCX | ?wxBITMAP_TYPE_PCX_RESOURCE |
%% ?wxBITMAP_TYPE_PICT | ?wxBITMAP_TYPE_PICT_RESOURCE |
%% ?wxBITMAP_TYPE_ICON | ?wxBITMAP_TYPE_ICON_RESOURCE |
%% ?wxBITMAP_TYPE_ANI | ?wxBITMAP_TYPE_IFF |
%% ?wxBITMAP_TYPE_TGA | ?wxBITMAP_TYPE_MACCURSOR |
%% ?wxBITMAP_TYPE_ANY | ?wxBITMAP_TYPE_MACCURSOR_RESOURCE
-spec new(Filename, [Option]) -> wxIcon()
when
Filename :: unicode:chardata(),
Option :: {type, wx:wx_enum()}
| {desiredWidth, integer()}
| {desiredHeight, integer()}.
new(Filename, Options)
when
is_list(Filename),
is_list(Options) ->
Filename_UC = unicode:characters_to_binary([Filename,0]),
MOpts = fun({type, Type}, Acc) -> [<<1:32/?UI,Type:32/?UI>>|Acc];
({desiredWidth, DesiredWidth}, Acc) -> [<<2:32/?UI,DesiredWidth:32/?UI>>|Acc];
({desiredHeight, DesiredHeight}, Acc) -> [<<3:32/?UI,DesiredHeight:32/?UI>>|Acc];
(BadOpt, _) -> erlang:error({badoption, BadOpt})
end,
BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
wxe_util:construct(?wxIcon_new_2,
<<(byte_size(Filename_UC)):32/?UI,(Filename_UC)/binary,
0:(((8- ((4+byte_size(Filename_UC)) band 16#7)) band 16#7))/unit:8, BinOpt/binary>>).
%·%% COPY FROM BITMAP %%·%
%%
%% Copies bmp bitmap to this icon.
%%
%% Under MS Windows the bitmap must have mask colour set.
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec copyFromBitmap(This, Bmp) -> ok
when
This :: wxIcon(),
Bmp :: wxBitmap:wxBitmap().
copyFromBitmap(#wx_ref{type=ThisT,ref=ThisRef},
#wx_ref{type=BmpT,ref=BmpRef}) ->
?CLASS(ThisT,wxIcon),
?CLASS(BmpT,wxBitmap),
wxe_util:cast(?wxIcon_CopyFromBitmap,
<<ThisRef:32/?UI,BmpRef:32/?UI>>).
%·%% DESTROY %%·%
%%
%% Destructor. See reference-counted object
%% destruction for more info.
%%
%% If the application omits to delete the icon explicitly,
%% the icon will be destroyed automatically by wxWidgets
%% when the application exits.
%%
%% Do not delete an icon that is selected
%% into a memory device context
%%
%% @doc Destroys this object, do not use object again
-spec destroy(This :: wxIcon()) -> ok.
destroy(Obj=#wx_ref{type=Type}) ->
?CLASS(Type,wxIcon),
wxe_util:destroy(?DESTROY_OBJECT,Obj),
ok.
%% From wxBitmap
%% @hidden
setWidth(This,Width) -> wxBitmap:setWidth(This,Width).
%% @hidden
setPalette(This,Palette) -> wxBitmap:setPalette(This,Palette).
%% @hidden
setMask(This,Mask) -> wxBitmap:setMask(This,Mask).
%% @hidden
setHeight(This,Height) -> wxBitmap:setHeight(This,Height).
%% @hidden
setDepth(This,Depth) -> wxBitmap:setDepth(This,Depth).
%% @hidden
saveFile(This,Name,Type, Options) -> wxBitmap:saveFile(This,Name,Type, Options).
%% @hidden
saveFile(This,Name,Type) -> wxBitmap:saveFile(This,Name,Type).
%% @hidden
ok(This) -> wxBitmap:ok(This).
%% @hidden
loadFile(This,Name, Options) -> wxBitmap:loadFile(This,Name, Options).
%% @hidden
loadFile(This,Name) -> wxBitmap:loadFile(This,Name).
%% @hidden
getSubBitmap(This,Rect) -> wxBitmap:getSubBitmap(This,Rect).
%% @hidden
getWidth(This) -> wxBitmap:getWidth(This).
%% @hidden
getMask(This) -> wxBitmap:getMask(This).
%% @hidden
getPalette(This) -> wxBitmap:getPalette(This).
%% @hidden
getHeight(This) -> wxBitmap:getHeight(This).
%% @hidden
getDepth(This) -> wxBitmap:getDepth(This).
%% @hidden
copyFromIcon(This,Icon) -> wxBitmap:copyFromIcon(This,Icon).
%% @hidden
convertToImage(This) -> wxBitmap:convertToImage(This).
|