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