1 /* 2 * Copyright 2001-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Marc Flerackers (mflerackers@androme.be) 7 */ 8 9 #include <Alert.h> 10 #include <Message.h> 11 #include <MimeType.h> 12 13 #include "ZombieReplicantView.h" 14 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <string.h> 18 #include <new> 19 20 21 22 _BZombieReplicantView_::_BZombieReplicantView_(BRect frame, status_t error) 23 : 24 BBox(frame, "<Zombie>", B_FOLLOW_NONE, B_WILL_DRAW), 25 fError(error) 26 { 27 BFont font(be_bold_font); 28 font.SetSize(9.0f); // TODO 29 SetFont(&font); 30 SetViewColor(kZombieColor); 31 } 32 33 34 _BZombieReplicantView_::~_BZombieReplicantView_() 35 { 36 } 37 38 39 void 40 _BZombieReplicantView_::MessageReceived(BMessage *msg) 41 { 42 switch (msg->what) { 43 case B_ABOUT_REQUESTED: 44 { 45 const char *addOn = NULL; 46 char error[1024]; 47 if (fArchive->FindString("add_on", &addOn) == B_OK) { 48 char description[B_MIME_TYPE_LENGTH] = ""; 49 BMimeType type(addOn); 50 type.GetShortDescription(description); 51 snprintf(error, sizeof(error), 52 "Cannot create the replicant for \"%s\". (%s)", 53 description, strerror(fError)); 54 } else { 55 snprintf(error, sizeof(error), 56 "Cannot locate the application for the replicant. " 57 "No application signature supplied. (%s)", strerror(fError)); 58 } 59 60 61 BAlert *alert = new (std::nothrow) BAlert("Error", error, "OK", NULL, NULL, 62 B_WIDTH_AS_USUAL, B_STOP_ALERT); 63 if (alert != NULL) 64 alert->Go(); 65 66 break; 67 } 68 default: 69 BView::MessageReceived(msg); 70 } 71 } 72 73 74 void 75 _BZombieReplicantView_::Draw(BRect updateRect) 76 { 77 BRect bounds(Bounds()); 78 font_height fh; 79 80 GetFontHeight(&fh); 81 82 DrawChar('?', BPoint(bounds.Width() / 2.0f - StringWidth("?") / 2.0f, 83 bounds.Height() / 2.0f - fh.ascent / 2.0f)); 84 85 BBox::Draw(updateRect); 86 } 87 88 89 void 90 _BZombieReplicantView_::MouseDown(BPoint) 91 { 92 } 93 94 95 void 96 _BZombieReplicantView_::SetArchive(BMessage *archive) 97 { 98 fArchive = archive; 99 } 100