]> git.saurik.com Git - iphone-api.git/blob - WebCore/PopupMenu.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / PopupMenu.h
1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 *
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.
8 *
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.
13 *
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.
18 *
19 */
20
21 #ifndef PopupMenu_h
22 #define PopupMenu_h
23
24 #include "IntRect.h"
25 #include "PopupMenuClient.h"
26 #include <wtf/PassRefPtr.h>
27 #include <wtf/RefCounted.h>
28
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;
46 }
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 #endif
63
64 namespace WebCore {
65
66 class FrameView;
67 class Scrollbar;
68
69 class PopupMenu : public RefCounted<PopupMenu>
70 #if PLATFORM(WIN)
71 , private ScrollbarClient
72 #endif
73 #if PLATFORM(WX)
74 , public wxEvtHandler
75 #endif
76 {
77 public:
78 static PassRefPtr<PopupMenu> create(PopupMenuClient* client) { return adoptRef(new PopupMenu(client)); }
79 ~PopupMenu();
80
81 void disconnectClient() { m_popupClient = 0; }
82
83 void show(const IntRect&, FrameView*, int index);
84 void hide();
85
86 void updateFromElement();
87
88 PopupMenuClient* client() const { return m_popupClient; }
89
90 static bool itemWritingDirectionIsNatural();
91
92 #if PLATFORM(WIN)
93 Scrollbar* scrollbar() const { return m_scrollbar.get(); }
94
95 bool up(unsigned lines = 1);
96 bool down(unsigned lines = 1);
97
98 int itemHeight() const { return m_itemHeight; }
99 const IntRect& windowRect() const { return m_windowRect; }
100 IntRect clientRect() const;
101
102 int visibleItems() const;
103
104 int listIndexAtPoint(const IntPoint&) const;
105
106 bool setFocusedIndex(int index, bool hotTracking = false);
107 int focusedIndex() const;
108 void focusFirst();
109 void focusLast();
110
111 void paint(const IntRect& damageRect, HDC = 0);
112
113 HWND popupHandle() const { return m_popup; }
114
115 void setWasClicked(bool b = true) { m_wasClicked = b; }
116 bool wasClicked() const { return m_wasClicked; }
117
118 void setScrollOffset(int offset) { m_scrollOffset = offset; }
119 int scrollOffset() const { return m_scrollOffset; }
120
121 bool scrollToRevealSelection();
122
123 void incrementWheelDelta(int delta);
124 void reduceWheelDelta(int delta);
125 int wheelDelta() const { return m_wheelDelta; }
126
127 bool scrollbarCapturingMouse() const { return m_scrollbarCapturingMouse; }
128 void setScrollbarCapturingMouse(bool b) { m_scrollbarCapturingMouse = b; }
129 #endif
130
131 protected:
132 PopupMenu(PopupMenuClient*);
133
134 private:
135 PopupMenuClient* m_popupClient;
136
137 #if PLATFORM(MAC)
138 void clear();
139 void populate();
140
141 #elif PLATFORM(QT)
142 void clear();
143 void populate(const IntRect&);
144 QWebPopup* m_popup;
145 #elif PLATFORM(WIN)
146 // ScrollBarClient
147 virtual void valueChanged(Scrollbar*);
148 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
149 virtual bool isActive() const { return true; }
150 virtual bool scrollbarCornerPresent() const { return false; }
151
152 void calculatePositionAndSize(const IntRect&, FrameView*);
153 void invalidateItem(int index);
154
155 RefPtr<Scrollbar> m_scrollbar;
156 HWND m_popup;
157 HDC m_DC;
158 HBITMAP m_bmp;
159 bool m_wasClicked;
160 IntRect m_windowRect;
161 int m_itemHeight;
162 int m_scrollOffset;
163 int m_wheelDelta;
164 int m_focusedIndex;
165 bool m_scrollbarCapturingMouse;
166 #elif PLATFORM(GTK)
167 IntPoint m_menuPosition;
168 GtkMenu* m_popup;
169 HashMap<GtkWidget*, int> m_indexMap;
170 static void menuItemActivated(GtkMenuItem* item, PopupMenu*);
171 static void menuUnmapped(GtkWidget*, PopupMenu*);
172 static void menuPositionFunction(GtkMenu*, gint*, gint*, gboolean*, PopupMenu*);
173 static void menuRemoveItem(GtkWidget*, PopupMenu*);
174 #elif PLATFORM(WX)
175 wxMenu* m_menu;
176 void OnMenuItemSelected(wxCommandEvent&);
177 #elif PLATFORM(CHROMIUM)
178 PopupMenuPrivate p;
179 #endif
180
181 };
182
183 }
184
185 #endif