wxErlang

wxIconBundle.erl

  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
%           | /¯  /¯\ |\ |  |¯|  ) ( |\ | |¯\ |   |_¯ 
%\     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_wxiconbundle.html">wxIconBundle</a>.
%% @type wxIconBundle().  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%   
%%   OVERVIEW
%%   ––––––––
%%   This class contains multiple copies of an icon in 
%%   different sizes, see also wxDialog::SetIcons and wxTopLevelWindow::SetIcons.
%%   
%%   
%%   See Also:
%%   —————————
%%   
%%   
%%   
-module(wxIconBundle).
-include("wxe.hrl").
-export([addIcon/2,addIcon/3,destroy/1,getIcon/1,getIcon/2,new/0,new/1,new/2]).

%% inherited exports
-export([parent_class/1]).

-export_type([wxIconBundle/0]).


%% @hidden
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).


-type wxIconBundle()  ::  wx:wx_object().




           %·%% NEW / 0 %%·%

%%   
%%    Default constructor.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new() -> wxIconBundle().
new() ->
  wxe_util:construct(?wxIconBundle_new_0,
               <<>>).





           %·%% NEW / 1 %%·%

%%   
%%   Initializes the bundle with a single icon. 
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new(Ic) -> wxIconBundle()
           when
           Ic ::  wxIconBundle() 
               | wxIcon:wxIcon().
new(#wx_ref{type=IcT,ref=IcRef}) ->
                                   IcOP = 
                                        case 
                                        ?CLASS_T(IcT,wxIconBundle) 
                                        of
                                          true ->
                                                ?wxIconBundle_new_1_1;

                                             _ -> ?CLASS(IcT,wxIcon),
                                                ?wxIconBundle_new_1_0
                                        end,
                                        wxe_util:construct(IcOP,
                                                         <<IcRef:32/?UI>>).





           %·%% NEW / 2 %%·%

%%   
%%   Initializes the bundle with the icon(s) found in the file.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new(File, Type) -> wxIconBundle()
           when
           File :: unicode:chardata(), 
           Type ::          integer().

new(File,Type)
           when 
           is_list(File),
           is_integer(Type) ->
                   File_UC = unicode:characters_to_binary([File,0]),
                            wxe_util:construct(?wxIconBundle_new_2,
                                  <<(byte_size(File_UC)):32/?UI,(File_UC)/binary, 
                         0:(((8- ((4+byte_size(File_UC)) band 16#7)) band 16#7))/unit:8,Type:32/?UI>>).








           %·%% ADD ICON / 2 %%·%

%%   
%%   Adds the icon to the collection; 
%%   if the collection already contains an icon 
%%   with the same width and height, it is replaced by the new one.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec addIcon(This, Icon) -> ok
           when
           This ::  wxIconBundle(), 
           Icon :: wxIcon:wxIcon().

addIcon(#wx_ref{type=ThisT,ref=ThisRef},
        #wx_ref{type=IconT,ref=IconRef}) ->
                                          ?CLASS(ThisT,wxIconBundle),
                                          ?CLASS(IconT,wxIcon),
                            wxe_util:cast(?wxIconBundle_AddIcon_1,
                            <<ThisRef:32/?UI,IconRef:32/?UI>>).





           %·%% ADD ICON / 3 %%·%

%%   
%%   Adds all the icons contained in the file to the bundle; 
%%   if the collection already contains icons with the same 
%%   width and height, they are replaced by the new ones.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec addIcon(This, File, Type) -> ok
           when
           This ::     wxIconBundle(), 
           File :: unicode:chardata(), 
           Type ::          integer().

addIcon(#wx_ref{type=ThisT,ref=ThisRef},
                                        File,  
                                             Type)
           when 
           is_list(File),
           is_integer(Type) ->
                             ?CLASS(ThisT,wxIconBundle),
                   File_UC   = unicode:characters_to_binary([File,0]),
                              wxe_util:cast(?wxIconBundle_AddIcon_2,
                              <<ThisRef:32/?UI,(byte_size(File_UC)):32/?UI,(File_UC)/binary, 
                                    0:(((8- ((0+byte_size(File_UC)) band 16#7)) band 16#7))/unit:8,Type:32/?UI>>).




           %·%% GET ICON %%·%

%%   
%% See below...
%% @equiv getIcon(This, [])
          -spec getIcon(This)      -> wxIcon:wxIcon()
           when
           This :: wxIconBundle().

getIcon(This)
           when 
           is_record(This, wx_ref) ->  getIcon(This, []).

%%    
%%   Returns the icon with the given size; 
%%   if no such icon exists, returns the icon 
%%   with size wxSYS_ICON_X/wxSYS_ICON_Y; 
%%   if no such icon exists, returns the first 
%%   icon in the bundle. If size = wxSize( -1, -1 ), 
%%   returns the icon with size wxSYS_ICON_X/wxSYS_ICON_Y.
%%
%% Return Value:
%% See Also:
%%*%%*%%
%% <br /> Also:<br />
%% getIcon(This, Size) -> wxIcon:wxIcon()           when<br />
%%             This :: wxIconBundle(), Size :: {W :: integer(), H :: integer()}.<br />
%% 
          -spec getIcon(This, [Option]) -> wxIcon:wxIcon()
           when
           This    ::    wxIconBundle(),
           Option  ::  {size, integer()};
     
                       (This, Size)     -> wxIcon:wxIcon()
           when
           This :: wxIconBundle(), 
           Size :: {W :: integer(), 
                    H :: integer()}.

getIcon(#wx_ref{type=ThisT,ref=ThisRef}, Options)
           when 
           is_list(Options) ->
                             ?CLASS(ThisT,wxIconBundle),
                   MOpts = fun({size, Size}, Acc) -> [<<1:32/?UI,Size:32/?UI>>|Acc];
                                      (BadOpt, _) -> erlang:error({badoption, BadOpt})
                           end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:call(?wxIconBundle_GetIcon_1_0,
                                        <<ThisRef:32/?UI, 0:32,BinOpt/binary>>);

getIcon(#wx_ref{type=ThisT,ref=ThisRef},{SizeW,SizeH})
           when 
           is_integer(SizeW),
           is_integer(SizeH) ->
                              ?CLASS(ThisT,wxIconBundle),
                wxe_util:call(?wxIconBundle_GetIcon_1_1,
                <<ThisRef:32/?UI,SizeW:32/?UI,SizeH:32/?UI>>).





           %·%% DESTROY %%·%

%%   Destructor.
%%   
%% @doc Destroys this object, do not use object again
          -spec destroy(This :: wxIconBundle()) -> ok.

destroy(Obj=#wx_ref{type=Type}) ->
                                 ?CLASS(Type,wxIconBundle),
                wxe_util:destroy(?wxIconBundle_destruct,Obj),
                ok.