vfs: check userland buffers before reading them.
[haiku.git] / src / servers / input / MethodMenuItem.cpp
blob67f0ab91894b31c720a23698a71c680ae271f905
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,
12 // Description: Input Server
13 // Created: October 19, 2004
15 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
17 #include <string.h>
18 #include "MethodMenuItem.h"
20 MethodMenuItem::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)
25 SetLabel(name);
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),
34 fCookie(cookie)
36 fIcon.SetBits(icon, MENUITEM_ICON_SIZE * MENUITEM_ICON_SIZE, 0, B_CMAP8);
40 MethodMenuItem::~MethodMenuItem()
45 void
46 MethodMenuItem::SetName(const char *name)
48 SetLabel(name);
51 void
52 MethodMenuItem::SetIcon(const uchar *icon)
54 fIcon.SetBits(icon, MENUITEM_ICON_SIZE * MENUITEM_ICON_SIZE, 0, B_CMAP8);
58 void
59 MethodMenuItem::GetContentSize(float *width, float *height)
61 *width = be_plain_font->StringWidth(Label()) + MENUITEM_ICON_SIZE + 3;
63 font_height fheight;
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;
72 void
73 MethodMenuItem::DrawContent()
75 BMenu *menu = Menu();
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();