1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
3 // Copyright (c) 2004, Haiku
5 // This software is part of the Haiku distribution and is covered
6 // by the Haiku license.
9 // File: MethodMenuItem.cpp
10 // Authors: Jérôme Duval,
12 // Description: Input Server
13 // Created: October 19, 2004
15 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
18 #include "MethodMenuItem.h"
20 MethodMenuItem::MethodMenuItem(int32 cookie
, const char* name
, const uchar
* icon
, BMenu
* subMenu
, BMessenger
& messenger
)
22 fIcon(BRect(0, 0, MENUITEM_ICON_SIZE
- 1, MENUITEM_ICON_SIZE
- 1), B_CMAP8
),
26 fIcon
.SetBits(icon
, MENUITEM_ICON_SIZE
* MENUITEM_ICON_SIZE
, 0, B_CMAP8
);
27 fMessenger
= messenger
;
31 MethodMenuItem::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
),
36 fIcon
.SetBits(icon
, MENUITEM_ICON_SIZE
* MENUITEM_ICON_SIZE
, 0, B_CMAP8
);
40 MethodMenuItem::~MethodMenuItem()
46 MethodMenuItem::SetName(const char *name
)
52 MethodMenuItem::SetIcon(const uchar
*icon
)
54 fIcon
.SetBits(icon
, MENUITEM_ICON_SIZE
* MENUITEM_ICON_SIZE
, 0, B_CMAP8
);
59 MethodMenuItem::GetContentSize(float *width
, float *height
)
61 *width
= be_plain_font
->StringWidth(Label()) + MENUITEM_ICON_SIZE
+ 3;
64 be_plain_font
->GetHeight(&fheight
);
66 *height
= fheight
.ascent
+ fheight
.descent
+ fheight
.leading
- 2;
67 if (*height
< MENUITEM_ICON_SIZE
)
68 *height
= MENUITEM_ICON_SIZE
;
73 MethodMenuItem::DrawContent()
76 BPoint contLoc
= ContentLocation();
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();