1 /********************************************************************************
2 *                                                                               *
3 *                        B M P   I c o n   O b j e c t                          *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2005 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXBMPIcon.cpp,v 1.31 2005/01/16 16:06:06 fox Exp $                       *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "FXHash.h"
28 #include "FXThread.h"
29 #include "FXStream.h"
30 #include "FXMemoryStream.h"
31 #include "FXString.h"
32 #include "FXSize.h"
33 #include "FXPoint.h"
34 #include "FXRectangle.h"
35 #include "FXObject.h"
36 #include "FXSettings.h"
37 #include "FXRegistry.h"
38 #include "FXApp.h"
39 #include "FXId.h"
40 #include "FXDrawable.h"
41 #include "FXImage.h"
42 #include "FXIcon.h"
43 #include "FXBMPIcon.h"
44 
45 
46 /*
47   Notes:
48   - BMP does not support alpha in the file format.
49   - You can also let the system guess a transparancy color based on the corners.
50   - If that doesn't work, you can force a specific transparency color.
51 */
52 
53 using namespace FX;
54 
55 /*******************************************************************************/
56 
57 namespace FX {
58 
59 
60 // Suggested file extension
61 const FXchar FXBMPIcon::fileExt[]="bmp";
62 
63 
64 // Object implementation
65 FXIMPLEMENT(FXBMPIcon,FXIcon,NULL,0)
66 
67 
68 // Initialize nicely
FXBMPIcon(FXApp * a,const void * pix,FXColor clr,FXuint opts,FXint w,FXint h)69 FXBMPIcon::FXBMPIcon(FXApp* a,const void *pix,FXColor clr,FXuint opts,FXint w,FXint h):FXIcon(a,NULL,clr,opts,w,h){
70   if(pix){
71     FXMemoryStream ms;
72     ms.open(FXStreamLoad,(FXuchar*)pix);
73     loadPixels(ms);
74     ms.close();
75     }
76   }
77 
78 
79 // Save object to stream
savePixels(FXStream & store) const80 FXbool FXBMPIcon::savePixels(FXStream& store) const {
81   if(fxsaveBMP(store,data,width,height)){
82     return TRUE;
83     }
84   return FALSE;
85   }
86 
87 
88 // Load object from stream
loadPixels(FXStream & store)89 FXbool FXBMPIcon::loadPixels(FXStream& store){
90   FXColor *pixels; FXint w,h;
91   if(fxloadBMP(store,pixels,w,h)){
92     setData(pixels,IMAGE_OWNED,w,h);
93     if(options&IMAGE_ALPHAGUESS) transp=guesstransp();
94     return TRUE;
95     }
96   return FALSE;
97   }
98 
99 
100 // Clean up
~FXBMPIcon()101 FXBMPIcon::~FXBMPIcon(){
102   }
103 
104 }
105