1// EndpointInfo.cpp 2// ---------------- 3// Implements the EndpointInfo object. 4// 5// Copyright 1999, Be Incorporated. All Rights Reserved. 6// This file may be used under the terms of the Be Sample Code License. 7 8#include "EndpointInfo.h" 9 10#include <Bitmap.h> 11#include <Debug.h> 12#include <IconUtils.h> 13#include <Message.h> 14#include <MidiRoster.h> 15#include <MidiEndpoint.h> 16 17const char* LARGE_ICON_NAME = "be:large_icon"; 18const char* MINI_ICON_NAME = "be:mini_icon"; 19const char* VECTOR_ICON_NAME = "icon"; 20const uint32 LARGE_ICON_TYPE = 'ICON'; 21const uint32 MINI_ICON_TYPE = 'MICN'; 22const uint32 VECTOR_ICON_TYPE = 'VICN'; 23extern const uint8 LARGE_ICON_SIZE = 32; 24extern const uint8 MINI_ICON_SIZE = 16; 25extern const icon_size DISPLAY_ICON_SIZE = B_LARGE_ICON; 26extern const color_space ICON_COLOR_SPACE = B_CMAP8; 27 28static BBitmap* CreateIcon(const BMessage* msg, icon_size which); 29 30EndpointInfo::EndpointInfo() 31 : m_id(-1), m_icon(NULL) 32{} 33 34EndpointInfo::EndpointInfo(int32 id) 35 : m_id(id), m_icon(NULL) 36{ 37 BMidiRoster* roster = BMidiRoster::MidiRoster(); 38 if (roster) { 39 BMidiEndpoint* endpoint = roster->FindEndpoint(id); 40 if (endpoint) { 41 printf("endpoint %ld = %p\n", id, endpoint); 42 BMessage msg; 43 if (endpoint->GetProperties(&msg) == B_OK) { 44 m_icon = CreateIcon(&msg, DISPLAY_ICON_SIZE); 45 } 46 endpoint->Release(); 47 } 48 } 49} 50 51EndpointInfo::EndpointInfo(const EndpointInfo& info) 52 : m_id(info.m_id) 53{ 54 m_icon = (info.m_icon) ? new BBitmap(info.m_icon) : NULL; 55} 56 57EndpointInfo& EndpointInfo::operator=(const EndpointInfo& info) 58{ 59 if (&info != this) { 60 m_id = info.m_id; 61 delete m_icon; 62 m_icon = (info.m_icon) ? new BBitmap(info.m_icon) : NULL; 63 } 64 return *this; 65} 66 67EndpointInfo::~EndpointInfo() 68{ 69 delete m_icon; 70} 71 72void EndpointInfo::UpdateProperties(const BMessage* props) 73{ 74 delete m_icon; 75 m_icon = CreateIcon(props, DISPLAY_ICON_SIZE); 76} 77 78static BBitmap* CreateIcon(const BMessage* msg, icon_size which) 79{ 80 float iconSize; 81 uint32 iconType; 82 const char* iconName; 83 84 if (which == B_LARGE_ICON) { 85 iconSize = LARGE_ICON_SIZE; 86 iconType = LARGE_ICON_TYPE; 87 iconName = LARGE_ICON_NAME; 88 } else if (which == B_MINI_ICON) { 89 iconSize = MINI_ICON_SIZE; 90 iconType = MINI_ICON_TYPE; 91 iconName = MINI_ICON_NAME; 92 } else { 93 return NULL; 94 } 95 96 const void* data; 97 ssize_t size; 98 BBitmap* bitmap = NULL; 99 100#ifdef __HAIKU__ 101 iconSize = LARGE_ICON_SIZE; 102 103 if (msg->FindData(VECTOR_ICON_NAME, VECTOR_ICON_TYPE, &data, 104 &size) == B_OK) { 105 BRect r(0, 0, iconSize-1, iconSize-1); 106 bitmap = new BBitmap(r, B_RGBA32); 107 if (BIconUtils::GetVectorIcon((const uint8*)data, size, 108 bitmap) == B_OK) { 109 printf("Created vector icon bitmap\n"); 110 return bitmap; 111 } else 112 delete bitmap; 113 } 114#endif 115 116 if (msg->FindData(iconName, iconType, &data, &size) == B_OK) 117 { 118 BRect r(0, 0, iconSize-1, iconSize-1); 119 bitmap = new BBitmap(r, ICON_COLOR_SPACE); 120 ASSERT((bitmap->BitsLength() == size)); 121 memcpy(bitmap->Bits(), data, size); 122 } 123 return bitmap; 124} 125