File: icon.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (307 lines) | stat: -rw-r--r-- 9,676 bytes parent folder | download | duplicates (2)
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
/////////////////////////////////////////////////////////////////////////////
// Name:        icon.h
// Purpose:     interface of wxIcon
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////



/**
    In wxIcon context this value means: "use the screen depth".
*/
#define wxICON_SCREEN_DEPTH       (-1)


/**
    @class wxIcon

    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.

    @remarks
    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 @ref overview_bitmap.

    @library{wxcore}
    @category{gdi}

    @stdobjects
    ::wxNullIcon

    @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
         wxDC::DrawIcon, wxCursor
*/
class wxIcon : public wxGDIObject
{
public:
    /**
        Default ctor.

        Constructs an icon object with no data; an assignment or another member
        function such as LoadFile() must be called subsequently.
    */
    wxIcon();

    /**
        Copy ctor.
    */
    wxIcon(const wxIcon& icon);

    /*
        Creates an icon from the given data, which can be of arbitrary type.

    wxIcon(void* data, int type, int width, int height, int depth = -1);

        NOTE: this ctor is not implemented by all ports, is somewhat useless
              without further description of the "data" supported formats and
              uses 'int type' instead of wxBitmapType, so don't document it.
    */

    /**
        Creates an icon from an array of bits.
        You should only use this function for monochrome bitmaps (depth 1) in
        portable programs: in this case the bits parameter should contain an XBM image.

        For other bit depths, the behaviour is platform dependent: under Windows,
        the data is passed without any changes to the underlying CreateBitmap() API.
        Under other platforms, only monochrome bitmaps may be created using this
        constructor and wxImage should be used for creating colour bitmaps from
        static data.

        @param bits
            Specifies an array of pixel values.
        @param width
            The width of the image.
        @param height
            The height of the image.

        @beginWxPerlOnly
        In wxPerl use Wx::Icon->newBits(bits, width, height, depth = -1);
        @endWxPerlOnly

        @onlyfor{wxmsw,wxosx}
    */
    wxIcon(const char bits[], int width, int height);

    /**
        Creates a bitmap from XPM data.
        To use this constructor, you must first include an XPM file.
        For example, assuming that the file mybitmap.xpm contains an XPM array
        of character pointers called @e mybitmap:

        @code
        #include "mybitmap.xpm"
        ...
        wxIcon *icon = new wxIcon(mybitmap);
        @endcode

        A macro, wxICON, is available which creates an icon using an XPM on
        the appropriate platform, or an icon resource on Windows.

        @code
        wxIcon icon(wxICON(sample));

        // Equivalent to:
        #if defined(__WXGTK__) || defined(__WXMOTIF__)
        wxIcon icon(sample_xpm);
        #endif

        #if defined(__WXMSW__)
        wxIcon icon("sample");
        #endif
        @endcode

        @beginWxPerlOnly
        In wxPerl use Wx::Icon->newFromXPM(data).
        @endWxPerlOnly
    */
    wxIcon(const char* const* bits);

    /**
        Loads an icon from a file or resource.

        @param name
            This can refer to a resource name or a filename under MS Windows and X.
            Its meaning is determined by the @a type parameter.
        @param type
            May be one of the ::wxBitmapType values and indicates which type of
            bitmap should be loaded. See the note in the class detailed description.
            Note that the wxICON_DEFAULT_TYPE constant has different value under
            different wxWidgets ports. See the icon.h header for the value it takes
            for a specific port.
        @param desiredWidth
            Specifies the desired width of the icon. This parameter only has
            an effect in Windows where icon resources can contain several icons
            of different sizes.
        @param desiredHeight
            Specifies the desired height of the icon. This parameter only has
            an effect in Windows where icon resources can contain several icons
            of different sizes.

        @see LoadFile()
    */
    wxIcon(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE,
           int desiredWidth = -1, int desiredHeight = -1);

    /**
        Loads an icon from the specified location.
    */
    wxIcon(const wxIconLocation& loc);

    /**
        Destructor.
        See @ref overview_refcount_destruct for more info.

        If the application omits to delete the icon explicitly, the icon will be
        destroyed automatically by wxWidgets when the application exits.

        @warning
        Do not delete an icon that is selected into a memory device context.
    */
    virtual ~wxIcon();

    /**
        Attach a Windows icon handle.

        This wxMSW-specific method allows assigning a native Windows @c HICON
        (which must be castes to @c WXHICON opaque handle type) to wxIcon.
        Notice that this means that the @c HICON will be destroyed by wxIcon
        when it is destroyed.

        @return @true if successful.

        @onlyfor{wxmsw}

        @since 2.9.5
    */
    bool CreateFromHICON(WXHICON icon);

    /**
        Returns disabled (dimmed) version of the icon.

        This method is available in wxIcon only under wxMSW, other ports only
        have it in wxBitmap. You can always use wxImage::ConvertToDisabled()
        and create the icon from wxImage manually however.

        @onlyfor{wxmsw}

        @since 2.9.0
    */
    wxIcon ConvertToDisabled(unsigned char brightness = 255) const;

    /**
        Copies @a bmp bitmap to this icon.
        Under MS Windows the bitmap must have mask colour set.

        @see LoadFile()
    */
    void CopyFromBitmap(const wxBitmap& bmp);

    /**
        Gets the colour depth of the icon.
        A value of 1 indicates a monochrome icon.
    */
    int GetDepth() const;

    /**
        Gets the height of the icon in pixels.

        @see GetWidth()
    */
    int GetHeight() const;

    /**
        Gets the width of the icon in pixels.

        @see GetHeight()
    */
    int GetWidth() const;

    /**
        Returns @true if icon data is present.
    */
    virtual bool IsOk() const;

    /**
        Loads an icon from a file or resource.

        @param name
            Either a filename or a Windows resource name.
            The meaning of name is determined by the @a type parameter.
        @param type
            One of the ::wxBitmapType values; see the note in the class
            detailed description.
            Note that the wxICON_DEFAULT_TYPE constant has different value under
            different wxWidgets ports. See the icon.h header for the value it takes
            for a specific port.
        @param desiredWidth
            Specifies the desired width of the icon. This parameter only has
            an effect in Windows where icon resources can contain several icons
            of different sizes.
        @param desiredHeight
            Specifies the desired height of the icon. This parameter only has
            an effect in Windows where icon resources can contain several icons
            of different sizes.

        @return @true if the operation succeeded, @false otherwise.
    */
    bool LoadFile(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE,
                  int desiredWidth = -1, int desiredHeight = -1);

    /**
        Sets the depth member (does not affect the icon data).

        @param depth
            Icon depth.
    */
    void SetDepth(int depth);

    /**
        Sets the height member (does not affect the icon data).

        @param height
            Icon height in pixels.
    */
    void SetHeight(int height);

    /**
        Sets the width member (does not affect the icon data).

        @param width
            Icon width in pixels.
    */
    void SetWidth(int width);

    /**
        Assignment operator, using @ref overview_refcount.

        @param icon
            Icon to assign.
    */
    wxIcon& operator=(const wxIcon& icon);
};

/**
    An empty wxIcon.
*/
wxIcon wxNullIcon;