xref: /haiku/src/kits/interface/ZombieReplicantView.cpp (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2004, Haiku
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		ZombieReplicantView.cpp
23 //	Author:			Marc Flerackers (mflerackers@androme.be)
24 //	Description:	Class for Zombie replicants
25 //------------------------------------------------------------------------------
26 
27 #include <Alert.h>
28 #include <Message.h>
29 #include <MimeType.h>
30 
31 #include <ZombieReplicantView.h>
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 const static rgb_color kZombieColor = {220, 220, 220, 255};
38 
39 _BZombieReplicantView_::_BZombieReplicantView_(BRect frame, status_t error)
40 	:	BBox(frame, "<Zombie>", B_FOLLOW_NONE, B_WILL_DRAW)
41 {
42 	fError = error;
43 
44 	BFont font(be_bold_font);
45 	font.SetSize(9.0f); // TODO
46 	SetFont(&font);
47 	SetViewColor(kZombieColor);
48 }
49 
50 
51 _BZombieReplicantView_::~_BZombieReplicantView_()
52 {
53 }
54 
55 
56 void
57 _BZombieReplicantView_::MessageReceived(BMessage *msg)
58 {
59 	switch (msg->what) {
60 		case B_ABOUT_REQUESTED:
61 		{
62 			const char *add_on = NULL;
63 			char description[B_MIME_TYPE_LENGTH];
64 
65 			if (fArchive->FindString("add_on", &add_on) == B_OK) {
66 				BMimeType type(add_on);
67 				type.GetShortDescription(description);
68 			}
69 
70 			char error[1024];
71 
72 			sprintf(error, "Can't create the \"%s\" replicant because the library is in the Trash. (%s)",
73 				description, strerror(fError));
74 
75 			(new BAlert("Error", error, "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
76 
77 			break;
78 		}
79 		default:
80 			BView::MessageReceived(msg);
81 	}
82 }
83 
84 
85 void
86 _BZombieReplicantView_::Draw(BRect updateRect)
87 {
88 	BRect bounds(Bounds());
89 	font_height fh;
90 
91 	GetFontHeight(&fh);
92 
93 	DrawChar('?', BPoint(bounds.Width() / 2.0f - StringWidth("?") / 2.0f,
94 		bounds.Height() / 2.0f - fh.ascent / 2.0f));
95 
96 	BBox::Draw(updateRect);
97 }
98 
99 
100 void
101 _BZombieReplicantView_::MouseDown(BPoint)
102 {
103 }
104 
105 
106 void
107 _BZombieReplicantView_::SetArchive(BMessage *archive)
108 {
109 	fArchive = archive;
110 }
111