]> git.saurik.com Git - iphone-api.git/blob - WebCore/ContextMenuItem.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / ContextMenuItem.h
1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef ContextMenuItem_h
27 #define ContextMenuItem_h
28
29 #include "PlatformMenuDescription.h"
30 #include "PlatformString.h"
31 #include <wtf/OwnPtr.h>
32
33 #if PLATFORM(MAC)
34 #include <wtf/RetainPtr.h>
35
36 #ifdef __OBJC__
37 @class NSMenuItem;
38 #else
39 class NSMenuItem;
40 #endif
41 #elif PLATFORM(WIN)
42 typedef struct tagMENUITEMINFOW* LPMENUITEMINFO;
43 #elif PLATFORM(GTK)
44 typedef struct _GtkMenuItem GtkMenuItem;
45 #elif PLATFORM(QT)
46 #include <QAction>
47 #elif PLATFORM(WX)
48 class wxMenuItem;
49 #endif
50
51 namespace WebCore {
52
53 class ContextMenu;
54
55 // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
56 // extra values in WebUIDelegatePrivate.h
57 enum ContextMenuAction {
58 ContextMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
59 ContextMenuItemTagOpenLinkInNewWindow=1,
60 ContextMenuItemTagDownloadLinkToDisk,
61 ContextMenuItemTagCopyLinkToClipboard,
62 ContextMenuItemTagOpenImageInNewWindow,
63 ContextMenuItemTagDownloadImageToDisk,
64 ContextMenuItemTagCopyImageToClipboard,
65 ContextMenuItemTagOpenFrameInNewWindow,
66 ContextMenuItemTagCopy,
67 ContextMenuItemTagGoBack,
68 ContextMenuItemTagGoForward,
69 ContextMenuItemTagStop,
70 ContextMenuItemTagReload,
71 ContextMenuItemTagCut,
72 ContextMenuItemTagPaste,
73 #if PLATFORM(GTK)
74 ContextMenuItemTagDelete,
75 ContextMenuItemTagSelectAll,
76 ContextMenuItemTagInputMethods,
77 ContextMenuItemTagUnicode,
78 #endif
79 ContextMenuItemTagSpellingGuess,
80 ContextMenuItemTagNoGuessesFound,
81 ContextMenuItemTagIgnoreSpelling,
82 ContextMenuItemTagLearnSpelling,
83 ContextMenuItemTagOther,
84 ContextMenuItemTagSearchInSpotlight,
85 ContextMenuItemTagSearchWeb,
86 ContextMenuItemTagLookUpInDictionary,
87 ContextMenuItemTagOpenWithDefaultApplication,
88 ContextMenuItemPDFActualSize,
89 ContextMenuItemPDFZoomIn,
90 ContextMenuItemPDFZoomOut,
91 ContextMenuItemPDFAutoSize,
92 ContextMenuItemPDFSinglePage,
93 ContextMenuItemPDFFacingPages,
94 ContextMenuItemPDFContinuous,
95 ContextMenuItemPDFNextPage,
96 ContextMenuItemPDFPreviousPage,
97 // These are new tags! Not a part of API!!!!
98 ContextMenuItemTagOpenLink = 2000,
99 ContextMenuItemTagIgnoreGrammar,
100 ContextMenuItemTagSpellingMenu, // Spelling or Spelling/Grammar sub-menu
101 ContextMenuItemTagShowSpellingPanel,
102 ContextMenuItemTagCheckSpelling,
103 ContextMenuItemTagCheckSpellingWhileTyping,
104 ContextMenuItemTagCheckGrammarWithSpelling,
105 ContextMenuItemTagFontMenu, // Font sub-menu
106 ContextMenuItemTagShowFonts,
107 ContextMenuItemTagBold,
108 ContextMenuItemTagItalic,
109 ContextMenuItemTagUnderline,
110 ContextMenuItemTagOutline,
111 ContextMenuItemTagStyles,
112 ContextMenuItemTagShowColors,
113 ContextMenuItemTagSpeechMenu, // Speech sub-menu
114 ContextMenuItemTagStartSpeaking,
115 ContextMenuItemTagStopSpeaking,
116 ContextMenuItemTagWritingDirectionMenu, // Writing Direction sub-menu
117 ContextMenuItemTagDefaultDirection,
118 ContextMenuItemTagLeftToRight,
119 ContextMenuItemTagRightToLeft,
120 ContextMenuItemTagPDFSinglePageScrolling,
121 ContextMenuItemTagPDFFacingPagesScrolling,
122 ContextMenuItemTagInspectElement,
123 ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu
124 ContextMenuItemTagTextDirectionDefault,
125 ContextMenuItemTagTextDirectionLeftToRight,
126 ContextMenuItemTagTextDirectionRightToLeft,
127 ContextMenuItemBaseApplicationTag = 10000
128 };
129
130 enum ContextMenuItemType {
131 ActionType,
132 CheckableActionType,
133 SeparatorType,
134 SubmenuType
135 };
136
137 #if PLATFORM(MAC)
138 typedef void* PlatformMenuItemDescription;
139 #elif PLATFORM(WIN)
140 typedef LPMENUITEMINFO PlatformMenuItemDescription;
141 #elif PLATFORM(QT)
142 struct PlatformMenuItemDescription {
143 PlatformMenuItemDescription()
144 : type(ActionType),
145 action(ContextMenuItemTagNoAction),
146 checked(false),
147 enabled(true)
148 {}
149
150 ContextMenuItemType type;
151 ContextMenuAction action;
152 String title;
153 QList<ContextMenuItem> subMenuItems;
154 bool checked;
155 bool enabled;
156 };
157 #elif PLATFORM(GTK)
158 struct PlatformMenuItemDescription {
159 PlatformMenuItemDescription()
160 : type(ActionType)
161 , action(ContextMenuItemTagNoAction)
162 , subMenu(0)
163 , checked(false)
164 , enabled(true)
165 {}
166
167 ContextMenuItemType type;
168 ContextMenuAction action;
169 String title;
170 GtkMenu* subMenu;
171 bool checked;
172 bool enabled;
173 };
174 #elif PLATFORM(WX)
175 struct PlatformMenuItemDescription {
176 PlatformMenuItemDescription()
177 : type(ActionType),
178 action(ContextMenuItemTagNoAction),
179 checked(false),
180 enabled(true)
181 {}
182
183 ContextMenuItemType type;
184 ContextMenuAction action;
185 String title;
186 wxMenu * subMenu;
187 bool checked;
188 bool enabled;
189 };
190 #else
191 typedef void* PlatformMenuItemDescription;
192 #endif
193
194 class ContextMenuItem {
195 public:
196 ContextMenuItem(PlatformMenuItemDescription);
197 ContextMenuItem(ContextMenu* subMenu = 0);
198 ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu = 0);
199 #if PLATFORM(GTK)
200 ContextMenuItem(GtkMenuItem*);
201 #endif
202 ~ContextMenuItem();
203
204 PlatformMenuItemDescription releasePlatformDescription();
205
206 ContextMenuItemType type() const;
207 void setType(ContextMenuItemType);
208
209 ContextMenuAction action() const;
210 void setAction(ContextMenuAction);
211
212 String title() const;
213 void setTitle(const String&);
214
215 PlatformMenuDescription platformSubMenu() const;
216 void setSubMenu(ContextMenu*);
217
218 void setChecked(bool = true);
219
220 void setEnabled(bool = true);
221 bool enabled() const;
222
223 // FIXME: Do we need a keyboard accelerator here?
224 #if PLATFORM(GTK)
225 static GtkMenuItem* createNativeMenuItem(const PlatformMenuItemDescription&);
226 #endif
227
228 private:
229 #if PLATFORM(MAC)
230 RetainPtr<NSMenuItem> m_platformDescription;
231 #else
232 PlatformMenuItemDescription m_platformDescription;
233 #endif
234 };
235
236 }
237
238 #endif // ContextMenuItem_h