Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / platform / PopupMenu.h
blob2315f02d5f8a287863358f1d5ac6868c2c757954
1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #ifndef PopupMenu_h
22 #define PopupMenu_h
24 #include "IntRect.h"
25 #include "PopupMenuClient.h"
26 #include <wtf/PassRefPtr.h>
27 #include <wtf/RefCounted.h>
29 #if PLATFORM(MAC)
30 #include <wtf/RetainPtr.h>
31 #ifdef __OBJC__
32 @class NSPopUpButtonCell;
33 #else
34 class NSPopUpButtonCell;
35 #endif
36 #elif PLATFORM(WIN)
37 #include "Scrollbar.h"
38 #include "ScrollbarClient.h"
39 #include <wtf/RefPtr.h>
40 typedef struct HWND__* HWND;
41 typedef struct HDC__* HDC;
42 typedef struct HBITMAP__* HBITMAP;
43 #elif PLATFORM(QT)
44 namespace WebCore {
45 class QWebPopup;
47 #elif PLATFORM(GTK)
48 typedef struct _GtkMenu GtkMenu;
49 typedef struct _GtkMenuItem GtkMenuItem;
50 typedef struct _GtkWidget GtkWidget;
51 #include <wtf/HashMap.h>
52 #include <glib.h>
53 #elif PLATFORM(WX)
54 #ifdef __WXMSW__
55 #include <wx/msw/winundef.h>
56 #endif
57 class wxMenu;
58 #include <wx/defs.h>
59 #include <wx/event.h>
60 #elif PLATFORM(CHROMIUM)
61 #include "PopupMenuPrivate.h"
62 #elif PLATFORM(HAIKU)
63 class BMenu;
64 #endif
66 namespace WebCore {
68 class FrameView;
69 class Scrollbar;
71 class PopupMenu : public RefCounted<PopupMenu>
72 #if PLATFORM(WIN)
73 , private ScrollbarClient
74 #endif
75 #if PLATFORM(WX)
76 , public wxEvtHandler
77 #endif
79 public:
80 static PassRefPtr<PopupMenu> create(PopupMenuClient* client) { return adoptRef(new PopupMenu(client)); }
81 ~PopupMenu();
83 void disconnectClient() { m_popupClient = 0; }
85 void show(const IntRect&, FrameView*, int index);
86 void hide();
88 void updateFromElement();
90 PopupMenuClient* client() const { return m_popupClient; }
92 static bool itemWritingDirectionIsNatural();
94 #if PLATFORM(WIN)
95 Scrollbar* scrollbar() const { return m_scrollbar.get(); }
97 static LPCTSTR popupClassName();
99 bool up(unsigned lines = 1);
100 bool down(unsigned lines = 1);
102 int itemHeight() const { return m_itemHeight; }
103 const IntRect& windowRect() const { return m_windowRect; }
104 IntRect clientRect() const;
106 int visibleItems() const;
108 int listIndexAtPoint(const IntPoint&) const;
110 bool setFocusedIndex(int index, bool hotTracking = false);
111 int focusedIndex() const;
112 void focusFirst();
113 void focusLast();
115 void paint(const IntRect& damageRect, HDC = 0);
117 HWND popupHandle() const { return m_popup; }
119 void setWasClicked(bool b = true) { m_wasClicked = b; }
120 bool wasClicked() const { return m_wasClicked; }
122 void setScrollOffset(int offset) { m_scrollOffset = offset; }
123 int scrollOffset() const { return m_scrollOffset; }
125 bool scrollToRevealSelection();
127 void incrementWheelDelta(int delta);
128 void reduceWheelDelta(int delta);
129 int wheelDelta() const { return m_wheelDelta; }
131 bool scrollbarCapturingMouse() const { return m_scrollbarCapturingMouse; }
132 void setScrollbarCapturingMouse(bool b) { m_scrollbarCapturingMouse = b; }
133 #endif
135 protected:
136 PopupMenu(PopupMenuClient*);
138 private:
139 PopupMenuClient* m_popupClient;
141 #if PLATFORM(MAC)
142 void clear();
143 void populate();
145 RetainPtr<NSPopUpButtonCell> m_popup;
146 #elif PLATFORM(QT)
147 void clear();
148 void populate(const IntRect&);
149 QWebPopup* m_popup;
150 #elif PLATFORM(WIN)
151 // ScrollBarClient
152 virtual void valueChanged(Scrollbar*);
153 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
154 virtual bool isActive() const { return true; }
155 virtual bool scrollbarCornerPresent() const { return false; }
157 void calculatePositionAndSize(const IntRect&, FrameView*);
158 void invalidateItem(int index);
160 static LRESULT CALLBACK PopupMenuWndProc(HWND, UINT, WPARAM, LPARAM);
161 LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
162 static void registerClass();
164 RefPtr<Scrollbar> m_scrollbar;
165 HWND m_popup;
166 HDC m_DC;
167 HBITMAP m_bmp;
168 bool m_wasClicked;
169 IntRect m_windowRect;
170 int m_itemHeight;
171 int m_scrollOffset;
172 int m_wheelDelta;
173 int m_focusedIndex;
174 bool m_scrollbarCapturingMouse;
175 bool m_showPopup;
176 #elif PLATFORM(GTK)
177 IntPoint m_menuPosition;
178 GtkMenu* m_popup;
179 HashMap<GtkWidget*, int> m_indexMap;
180 static void menuItemActivated(GtkMenuItem* item, PopupMenu*);
181 static void menuUnmapped(GtkWidget*, PopupMenu*);
182 static void menuPositionFunction(GtkMenu*, gint*, gint*, gboolean*, PopupMenu*);
183 static void menuRemoveItem(GtkWidget*, PopupMenu*);
184 #elif PLATFORM(WX)
185 wxMenu* m_menu;
186 void OnMenuItemSelected(wxCommandEvent&);
187 #elif PLATFORM(CHROMIUM)
188 PopupMenuPrivate p;
189 #elif PLATFORM(HAIKU)
190 BMenu* m_menu;
191 #endif
197 #endif