2 * This file is part of the popup menu implementation for <select> elements in WebCore.
4 * Copyright (C) 2008 Apple Computer, Inc.
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 #include "PopupMenuWx.h"
28 #include "FrameView.h"
29 #include "HostWindow.h"
30 #include "PopupMenuClient.h"
31 #include "PlatformString.h"
35 #include <wx/msw/winundef.h>
40 static int s_menuStartId = wxNewId();
44 class PopupMenuEventHandler : public wxEvtHandler
47 PopupMenuEventHandler(PopupMenuClient* client) :
51 void OnMenuItemSelected(wxCommandEvent& event)
54 m_client->valueChanged(event.GetId() - s_menuStartId);
55 m_client->popupDidHide();
57 // TODO: Do we need to call Disconnect here? Do we have a ref to the native window still?
61 PopupMenuClient* m_client;
65 PopupMenuWx::PopupMenuWx(PopupMenuClient* client)
66 : m_popupClient(client)
69 m_popupHandler = new PopupMenuEventHandler(client);
72 PopupMenuWx::~PopupMenuWx()
74 delete m_popupHandler;
78 void PopupMenuWx::disconnectClient()
83 void PopupMenuWx::show(const IntRect& r, FrameView* v, int index)
85 // just delete and recreate
90 wxWindow* nativeWin = v->hostWindow()->platformPageClient();
94 m_menu = new wxMenu();
96 int size = client()->listSize();
97 for (int i = 0; i < size; i++) {
98 int id = s_menuStartId + i;
100 if (client()->itemIsSeparator(i)) {
101 m_menu->AppendSeparator();
104 // FIXME: appending a menu item with an empty label asserts in
105 // wx. This needs to be fixed at wx level so that we can have
106 // the concept of "no selection" in choice boxes, etc.
107 if (!client()->itemText(i).isEmpty())
108 m_menu->Append(s_menuStartId + i, client()->itemText(i));
111 nativeWin->Connect(s_menuStartId, s_menuStartId + (size-1), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(PopupMenuEventHandler::OnMenuItemSelected), 0, m_popupHandler);
112 nativeWin->PopupMenu(m_menu, r.x() - v->scrollX(), r.y() - v->scrollY());
113 nativeWin->Disconnect(s_menuStartId, s_menuStartId + (size-1), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(PopupMenuEventHandler::OnMenuItemSelected), 0, m_popupHandler);
117 void PopupMenuWx::hide()
119 // we don't need to do anything here, the native control only exists during the time
123 void PopupMenuWx::updateFromElement()
125 client()->setTextFromItem(m_popupClient->selectedIndex());