2 * This file is part of the popup menu implementation for <select> elements in WebCore.
4 * Copyright (C) 2008 Apple Computer, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 #include "PopupMenu.h"
27 #include "FrameView.h"
28 #include "NotImplemented.h"
29 #include "PopupMenuClient.h"
30 #include "PlatformString.h"
36 static int s_menuStartId = wxNewId();
42 PopupMenu::PopupMenu(PopupMenuClient* client)
43 : RefCounted<PopupMenu>(0)
44 , m_popupClient(client)
49 PopupMenu::~PopupMenu()
54 void PopupMenu::show(const IntRect& r, FrameView* v, int index)
56 // just delete and recreate
60 wxWindow* nativeWin = v->nativeWindow();
64 m_menu = new wxMenu();
65 int size = client()->listSize();
66 for (int i = 0; i < size; i++) {
67 int id = s_menuStartId + i;
69 if (client()->itemIsSeparator(i)) {
70 m_menu->AppendSeparator();
73 // FIXME: appending a menu item with an empty label asserts in
74 // wx. This needs to be fixed at wx level so that we can have
75 // the concept of "no selection" in choice boxes, etc.
76 if (!client()->itemText(i).isEmpty())
77 m_menu->Append(s_menuStartId + i, client()->itemText(i));
80 nativeWin->Connect(s_menuStartId, s_menuStartId + (size-1), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(PopupMenu::OnMenuItemSelected), NULL, this);
81 nativeWin->PopupMenu(m_menu, r.x() - v->contentsX(), r.y() - v->contentsY());
82 nativeWin->Disconnect(s_menuStartId, s_menuStartId + (size-1), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(PopupMenu::OnMenuItemSelected), NULL, this);
86 void PopupMenu::OnMenuItemSelected(wxCommandEvent& event)
89 client()->valueChanged(event.GetId() - s_menuStartId);
90 client()->hidePopup();
92 // TODO: Do we need to call Disconnect here? Do we have a ref to the native window still?
95 void PopupMenu::hide()
97 // we don't need to do anything here, the native control only exists during the time
101 void PopupMenu::updateFromElement()
103 client()->setTextFromItem(m_popupClient->selectedIndex());
106 bool PopupMenu::itemWritingDirectionIsNatural()