xref: /haiku/src/apps/processcontroller/AutoIcon.cpp (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
1 /*
2  * Copyright 2000, Georges-Edouard Berenger. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "AutoIcon.h"
7 #include "Utilities.h"
8 
9 #include <Bitmap.h>
10 #include <ControlLook.h>
11 #include <Entry.h>
12 #include <MimeType.h>
13 #include <NodeInfo.h>
14 #include <Roster.h>
15 
16 
17 AutoIcon::~AutoIcon()
18 {
19 	delete fBitmap;
20 }
21 
22 
23 BBitmap*
24 AutoIcon::Bitmap()
25 {
26 	if (fBitmap != NULL)
27 		return fBitmap;
28 
29 	if (fSignature) {
30 		fBitmap = new BBitmap(BRect(BPoint(0, 0),
31 			be_control_look->ComposeIconSize(B_MINI_ICON)), B_RGBA32);
32 
33 		entry_ref ref;
34 		be_roster->FindApp (fSignature, &ref);
35 		if (BNodeInfo::GetTrackerIcon(&ref, fBitmap, (icon_size)-1) != B_OK) {
36 			BMimeType genericAppType(B_APP_MIME_TYPE);
37 			genericAppType.GetIcon(fBitmap, (icon_size)(fBitmap->Bounds().IntegerWidth() + 1));
38 		}
39 	} else if (fbits) {
40 		fBitmap = new BBitmap(BRect(BPoint(0, 0),
41 			BSize(B_MINI_ICON - 1, B_MINI_ICON - 1)), B_RGBA32);
42 
43 		fBitmap->SetBits(fbits, 256, 0, B_CMAP8);
44 	}
45 	return fBitmap;
46 }
47