2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
10 #include "PopUpColumn.h"
12 #include <PopUpMenu.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
),
26 fCycleInit(cycleInit
),
33 PopUpColumn::~PopUpColumn()
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
));
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
);
57 EditWindow
* edit
= new EditWindow(stringField
->String(), 0);
58 msg
->SetString("text", edit
->Go());
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());
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
);