btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / shared / IconView.cpp
blob5fdb0edf11495d1de69e3fc1913e1bb43df83036
1 // Author: Michael Wilber
2 // Copyright (C) Haiku, uses the MIT license
5 #include "IconView.h"
7 #include <new>
8 #include <stdio.h>
9 #include <string.h>
11 #include <Entry.h>
12 #include <Node.h>
13 #include <NodeInfo.h>
16 using std::nothrow;
19 IconView::IconView(icon_size iconSize)
21 BView("IconView", B_WILL_DRAW),
22 fIconSize(iconSize),
23 fIconBitmap(new BBitmap(BRect(iconSize), B_RGBA32)),
24 fDrawIcon(false)
26 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
30 IconView::~IconView()
32 delete fIconBitmap;
33 fIconBitmap = NULL;
37 status_t
38 IconView::SetIcon(const BPath& path, icon_size iconSize)
40 fDrawIcon = false;
42 if (iconSize != fIconSize) {
43 BBitmap* bitmap = new BBitmap(BRect(iconSize), B_RGBA32);
44 if (bitmap == NULL)
45 return B_NO_MEMORY;
47 delete fIconBitmap;
48 fIconBitmap = bitmap;
49 fIconSize = iconSize;
52 status_t status = fIconBitmap->InitCheck();
53 if (status != B_OK)
54 return status;
56 BEntry entry(path.Path());
57 BNode node(&entry);
58 BNodeInfo info(&node);
60 status = info.GetTrackerIcon(fIconBitmap, fIconSize);
61 if (status != B_OK)
62 return status;
64 if (!fIconBitmap->IsValid())
65 return fIconBitmap->InitCheck();
67 _SetSize();
69 fDrawIcon = true;
70 Invalidate();
71 return B_OK;
75 void
76 IconView::DrawIcon(bool draw)
78 if (draw == fDrawIcon)
79 return;
81 fDrawIcon = draw;
82 Invalidate();
86 void
87 IconView::Draw(BRect area)
89 if (fDrawIcon && fIconBitmap != NULL) {
90 SetDrawingMode(B_OP_ALPHA);
91 SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
92 DrawBitmap(fIconBitmap);
93 SetDrawingMode(B_OP_COPY);
94 } else
95 BView::Draw(area);
99 status_t
100 IconView::InitCheck() const
102 if (fIconBitmap == NULL)
103 return B_NO_MEMORY;
105 return fIconBitmap->InitCheck();
109 void
110 IconView::_SetSize()
112 SetExplicitMinSize(BSize(fIconSize, fIconSize));
113 SetExplicitMaxSize(BSize(fIconSize, fIconSize));
114 SetExplicitPreferredSize(BSize(fIconSize, fIconSize));