libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / preferences / shortcuts / PopUpColumn.cpp
blobe7f5b1e0f43d664daec25d65822e9019841bf5b2
1 /*
2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Josef Gajdusek
7 */
10 #include "PopUpColumn.h"
12 #include <PopUpMenu.h>
13 #include <MenuItem.h>
14 #include <Window.h>
16 #include "EditWindow.h"
17 #include "ShortcutsWindow.h"
19 PopUpColumn::PopUpColumn(BPopUpMenu* menu, const char* name, float width,
20 float minWidth, float maxWidth, uint32 truncate, bool editable,
21 bool cycle, int cycleInit, alignment align)
23 BStringColumn(name, width, minWidth, maxWidth, truncate, align),
24 fEditable(editable),
25 fCycle(cycle),
26 fCycleInit(cycleInit),
27 fMenu(menu)
29 SetWantsEvents(true);
33 PopUpColumn::~PopUpColumn()
35 delete fMenu;
38 void
39 PopUpColumn::MouseDown(BColumnListView* parent, BRow* row, BField* field,
40 BRect fieldRect, BPoint point, uint32 buttons)
42 if ((buttons & B_SECONDARY_MOUSE_BUTTON)
43 || (buttons & B_PRIMARY_MOUSE_BUTTON && (fEditable || fCycle))) {
44 BMessage* msg = new BMessage(ShortcutsWindow::HOTKEY_ITEM_MODIFIED);
45 msg->SetInt32("row", parent->IndexOf(row));
46 msg->SetInt32("column", LogicalFieldNum());
47 if (buttons & B_SECONDARY_MOUSE_BUTTON) {
48 BMenuItem* selected = fMenu->Go(parent->ConvertToScreen(point));
49 if (selected) {
50 msg->SetString("text", selected->Label());
51 parent->Window()->PostMessage(msg);
54 if (buttons & B_PRIMARY_MOUSE_BUTTON && row->IsSelected()) {
55 BStringField* stringField = static_cast<BStringField*>(field);
56 if (fEditable) {
57 EditWindow* edit = new EditWindow(stringField->String(), 0);
58 msg->SetString("text", edit->Go());
59 } else if (fCycle) {
60 BMenuItem* item;
61 for (int i = 0; (item = fMenu->ItemAt(i)) != NULL; i++)
62 if (strcmp(stringField->String(), item->Label()) == 0) {
63 item = fMenu->ItemAt((i + 1) % fMenu->CountItems());
64 break;
66 if (item == NULL)
67 item = fMenu->ItemAt(fCycleInit);
68 msg->SetString("text", item->Label());
70 parent->Window()->PostMessage(msg);
73 BStringColumn::MouseDown(parent, row, field, fieldRect, point, buttons);