3 * Implements the EndpointInfo object.
5 * Copyright 2013, Haiku, Inc. All rights reserved.
6 * Distributed under the terms of the MIT License.
8 * Revisions by Pete Goodeve
10 * Copyright 1999, Be Incorporated. All Rights Reserved.
11 * This file may be used under the terms of the Be Sample Code License.
13 #include "EndpointInfo.h"
17 #include <IconUtils.h>
19 #include <MidiRoster.h>
20 #include <MidiEndpoint.h>
22 const char* LARGE_ICON_NAME
= "be:large_icon";
23 const char* MINI_ICON_NAME
= "be:mini_icon";
24 const char* VECTOR_ICON_NAME
= "icon";
25 const uint32 LARGE_ICON_TYPE
= 'ICON';
26 const uint32 MINI_ICON_TYPE
= 'MICN';
27 const uint32 VECTOR_ICON_TYPE
= 'VICN';
28 extern const uint8 LARGE_ICON_SIZE
= 32;
29 extern const uint8 MINI_ICON_SIZE
= 16;
30 extern const icon_size DISPLAY_ICON_SIZE
= B_LARGE_ICON
;
31 extern const color_space ICON_COLOR_SPACE
= B_CMAP8
;
33 static BBitmap
* CreateIcon(const BMessage
* msg
, icon_size which
);
36 EndpointInfo::EndpointInfo()
43 EndpointInfo::EndpointInfo(int32 id
)
48 BMidiRoster
* roster
= BMidiRoster::MidiRoster();
50 BMidiEndpoint
* endpoint
= roster
->FindEndpoint(id
);
51 if (endpoint
!= NULL
) {
52 printf("endpoint %" B_PRId32
" = %p\n", id
, endpoint
);
54 if (endpoint
->GetProperties(&msg
) == B_OK
) {
55 fIcon
= CreateIcon(&msg
, DISPLAY_ICON_SIZE
);
63 EndpointInfo::EndpointInfo(const EndpointInfo
& info
)
67 fIcon
= (info
.fIcon
) ? new BBitmap(info
.fIcon
) : NULL
;
72 EndpointInfo::operator=(const EndpointInfo
& info
)
77 fIcon
= (info
.fIcon
) ? new BBitmap(info
.fIcon
) : NULL
;
83 EndpointInfo::~EndpointInfo()
90 EndpointInfo::UpdateProperties(const BMessage
* props
)
93 fIcon
= CreateIcon(props
, DISPLAY_ICON_SIZE
);
98 CreateIcon(const BMessage
* msg
, icon_size which
)
103 BBitmap
* bitmap
= NULL
;
105 // See if a Haiku Vector Icon available
106 if (msg
->FindData(VECTOR_ICON_NAME
, VECTOR_ICON_TYPE
, &data
,
108 BRect
r(0, 0, LARGE_ICON_SIZE
- 1, LARGE_ICON_SIZE
- 1);
109 bitmap
= new BBitmap(r
, B_RGBA32
);
110 if (BIconUtils::GetVectorIcon((const uint8
*)data
, size
,
112 printf("Created vector icon bitmap\n");
120 // If not, look for BeOS style icon
123 const char* iconName
;
125 if (which
== B_LARGE_ICON
) {
126 bmapSize
= LARGE_ICON_SIZE
- 1;
127 iconType
= LARGE_ICON_TYPE
;
128 iconName
= LARGE_ICON_NAME
;
129 } else if (which
== B_MINI_ICON
) {
130 bmapSize
= MINI_ICON_SIZE
- 1;
131 iconType
= MINI_ICON_TYPE
;
132 iconName
= MINI_ICON_NAME
;
136 if (msg
->FindData(iconName
, iconType
, &data
, &size
) == B_OK
) {
137 bitmap
= new BBitmap(BRect(0, 0, bmapSize
, bmapSize
),
139 ASSERT((bitmap
->BitsLength() == size
));
140 memcpy(bitmap
->Bits(), data
, size
);