1f40fc44eSJérôme Duval// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2f40fc44eSJérôme Duval//
3f40fc44eSJérôme Duval//      Copyright (c) 2004, Haiku
4f40fc44eSJérôme Duval//
5f40fc44eSJérôme Duval//  This software is part of the Haiku distribution and is covered
6f40fc44eSJérôme Duval//  by the Haiku license.
7f40fc44eSJérôme Duval//
8f40fc44eSJérôme Duval//
9f40fc44eSJérôme Duval//  File:                       MethodMenuItem.cpp
10f40fc44eSJérôme Duval//  Authors:            J��r��me Duval,
11f40fc44eSJérôme Duval//
12f40fc44eSJérôme Duval//  Description:        Input Server
13f40fc44eSJérôme Duval//  Created:            October 19, 2004
14f40fc44eSJérôme Duval//
15f40fc44eSJérôme Duval// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
16f40fc44eSJérôme Duval
17f40fc44eSJérôme Duval#include <string.h>
18f40fc44eSJérôme Duval#include "MethodMenuItem.h"
19f40fc44eSJérôme Duval
20c90d3c9dSMurai TakashiMethodMenuItem::MethodMenuItem(int32 cookie, const char* name, const uchar* icon, BMenu* subMenu, BMessenger& messenger)
21f40fc44eSJérôme Duval	: BMenuItem(subMenu),
22f40fc44eSJérôme Duval	fIcon(BRect(0, 0, MENUITEM_ICON_SIZE - 1, MENUITEM_ICON_SIZE - 1), B_CMAP8),
23f40fc44eSJérôme Duval	fCookie(cookie)
24f40fc44eSJérôme Duval{
25f40fc44eSJérôme Duval	SetLabel(name);
26f40fc44eSJérôme Duval	fIcon.SetBits(icon, MENUITEM_ICON_SIZE * MENUITEM_ICON_SIZE, 0, B_CMAP8);
271cafa90eSJérôme Duval	fMessenger = messenger;
28f40fc44eSJérôme Duval}
29f40fc44eSJérôme Duval
30f40fc44eSJérôme Duval
31c90d3c9dSMurai TakashiMethodMenuItem::MethodMenuItem(int32 cookie, const char* name, const uchar* icon)
32f40fc44eSJérôme Duval	: BMenuItem(name, NULL),
33f40fc44eSJérôme Duval	fIcon(BRect(0, 0, MENUITEM_ICON_SIZE - 1, MENUITEM_ICON_SIZE - 1), B_CMAP8),
34f40fc44eSJérôme Duval	fCookie(cookie)
35f40fc44eSJérôme Duval{
36f40fc44eSJérôme Duval	fIcon.SetBits(icon, MENUITEM_ICON_SIZE * MENUITEM_ICON_SIZE, 0, B_CMAP8);
37f40fc44eSJérôme Duval}
38f40fc44eSJérôme Duval
39f40fc44eSJérôme Duval
40f40fc44eSJérôme DuvalMethodMenuItem::~MethodMenuItem()
41f40fc44eSJérôme Duval{
42f40fc44eSJérôme Duval}
43f40fc44eSJérôme Duval
44f40fc44eSJérôme Duval
45f40fc44eSJérôme Duvalvoid
46f40fc44eSJérôme DuvalMethodMenuItem::SetName(const char *name)
47f40fc44eSJérôme Duval{
48f40fc44eSJérôme Duval	SetLabel(name);
49f40fc44eSJérôme Duval}
50f40fc44eSJérôme Duval
51f40fc44eSJérôme Duvalvoid
52f40fc44eSJérôme DuvalMethodMenuItem::SetIcon(const uchar *icon)
53f40fc44eSJérôme Duval{
54f40fc44eSJérôme Duval	fIcon.SetBits(icon, MENUITEM_ICON_SIZE * MENUITEM_ICON_SIZE, 0, B_CMAP8);
55f40fc44eSJérôme Duval}
56f40fc44eSJérôme Duval
57f40fc44eSJérôme Duval
58f40fc44eSJérôme Duvalvoid
59f40fc44eSJérôme DuvalMethodMenuItem::GetContentSize(float *width, float *height)
60f40fc44eSJérôme Duval{
61f40fc44eSJérôme Duval	*width = be_plain_font->StringWidth(Label()) + MENUITEM_ICON_SIZE + 3;
62f40fc44eSJérôme Duval
63f40fc44eSJérôme Duval	font_height fheight;
64f40fc44eSJérôme Duval	be_plain_font->GetHeight(&fheight);
65f40fc44eSJérôme Duval
66f40fc44eSJérôme Duval	*height = fheight.ascent + fheight.descent + fheight.leading - 2;
67f40fc44eSJérôme Duval	if (*height < MENUITEM_ICON_SIZE)
68f40fc44eSJérôme Duval		*height = MENUITEM_ICON_SIZE;
69f40fc44eSJérôme Duval}
70f40fc44eSJérôme Duval
71f40fc44eSJérôme Duval
72f40fc44eSJérôme Duvalvoid
73f40fc44eSJérôme DuvalMethodMenuItem::DrawContent()
74f40fc44eSJérôme Duval{
75f40fc44eSJérôme Duval	BMenu *menu = Menu();
76f40fc44eSJérôme Duval	BPoint contLoc = ContentLocation();
77f40fc44eSJérôme Duval
78f40fc44eSJérôme Duval	menu->SetDrawingMode(B_OP_OVER);
79f40fc44eSJérôme Duval	menu->MovePenTo(contLoc);
80f40fc44eSJérôme Duval	menu->DrawBitmapAsync(&fIcon);
81f40fc44eSJérôme Duval	menu->SetDrawingMode(B_OP_COPY);
82f40fc44eSJérôme Duval	menu->MovePenBy(MENUITEM_ICON_SIZE + 3, 2);
83f40fc44eSJérôme Duval	BMenuItem::DrawContent();
84f40fc44eSJérôme Duval}
85f40fc44eSJérôme Duval
86