ContextMenuItem.h 6.33 KB
Newer Older
aroben's avatar
aroben committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#ifndef ContextMenuItem_h
#define ContextMenuItem_h

bdakin's avatar
bdakin committed
29
#include "PlatformMenuDescription.h"
aroben's avatar
aroben committed
30
#include "PlatformString.h"
bdakin's avatar
bdakin committed
31
#include <wtf/OwnPtr.h>
aroben's avatar
aroben committed
32 33

#if PLATFORM(MAC)
beidson's avatar
beidson committed
34
#include <wtf/RetainPtr.h>
35

aroben's avatar
aroben committed
36 37 38 39 40 41 42
#ifdef __OBJC__
@class NSMenuItem;
#else
class NSMenuItem;
#endif
#elif PLATFORM(WIN)
typedef struct tagMENUITEMINFOW* LPMENUITEMINFO;
zecke's avatar
/:  
zecke committed
43
#elif PLATFORM(GTK)
kjk's avatar
kjk committed
44
typedef struct _GtkMenuItem GtkMenuItem;
45 46
#elif PLATFORM(QT)
#include <QAction>
aroben's avatar
aroben committed
47 48 49 50 51 52
#endif

namespace WebCore {

    class ContextMenu;

sullivan's avatar
sullivan committed
53 54
    // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
    // extra values in WebUIDelegatePrivate.h
aroben's avatar
aroben committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    enum ContextMenuAction {
        ContextMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
        ContextMenuItemTagOpenLinkInNewWindow=1,
        ContextMenuItemTagDownloadLinkToDisk,
        ContextMenuItemTagCopyLinkToClipboard,
        ContextMenuItemTagOpenImageInNewWindow,
        ContextMenuItemTagDownloadImageToDisk,
        ContextMenuItemTagCopyImageToClipboard,
        ContextMenuItemTagOpenFrameInNewWindow,
        ContextMenuItemTagCopy,
        ContextMenuItemTagGoBack,
        ContextMenuItemTagGoForward,
        ContextMenuItemTagStop,
        ContextMenuItemTagReload,
        ContextMenuItemTagCut,
        ContextMenuItemTagPaste,
        ContextMenuItemTagSpellingGuess,
        ContextMenuItemTagNoGuessesFound,
        ContextMenuItemTagIgnoreSpelling,
        ContextMenuItemTagLearnSpelling,
        ContextMenuItemTagOther,
        ContextMenuItemTagSearchInSpotlight,
        ContextMenuItemTagSearchWeb,
        ContextMenuItemTagLookUpInDictionary,
        ContextMenuItemTagOpenWithDefaultApplication,
        ContextMenuItemPDFActualSize,
        ContextMenuItemPDFZoomIn,
        ContextMenuItemPDFZoomOut,
        ContextMenuItemPDFAutoSize,
        ContextMenuItemPDFSinglePage,
        ContextMenuItemPDFFacingPages,
        ContextMenuItemPDFContinuous,
        ContextMenuItemPDFNextPage,
        ContextMenuItemPDFPreviousPage,
bdakin's avatar
bdakin committed
89
        // These are new tags! Not a part of API!!!!
sullivan's avatar
sullivan committed
90
        ContextMenuItemTagOpenLink = 2000,
sullivan's avatar
sullivan committed
91
        ContextMenuItemTagIgnoreGrammar,
bdakin's avatar
bdakin committed
92 93
        ContextMenuItemTagSpellingMenu, // Spelling or Spelling/Grammar sub-menu
        ContextMenuItemTagShowSpellingPanel,
bdakin's avatar
bdakin committed
94 95
        ContextMenuItemTagCheckSpelling,
        ContextMenuItemTagCheckSpellingWhileTyping,
bdakin's avatar
bdakin committed
96
        ContextMenuItemTagCheckGrammarWithSpelling,
bdakin's avatar
bdakin committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
        ContextMenuItemTagFontMenu, // Font sub-menu
        ContextMenuItemTagShowFonts,
        ContextMenuItemTagBold,
        ContextMenuItemTagItalic,
        ContextMenuItemTagUnderline,
        ContextMenuItemTagOutline,
        ContextMenuItemTagStyles,
        ContextMenuItemTagShowColors,
        ContextMenuItemTagSpeechMenu, // Speech sub-menu
        ContextMenuItemTagStartSpeaking,
        ContextMenuItemTagStopSpeaking,
        ContextMenuItemTagWritingDirectionMenu, // Writing Direction sub-menu
        ContextMenuItemTagDefaultDirection,
        ContextMenuItemTagLeftToRight,
        ContextMenuItemTagRightToLeft,
sullivan's avatar
sullivan committed
112 113
        ContextMenuItemTagPDFSinglePageScrolling,
        ContextMenuItemTagPDFFacingPagesScrolling,
aroben's avatar
aroben committed
114
        ContextMenuItemTagInspectElement,
bdakin's avatar
bdakin committed
115
        ContextMenuItemBaseApplicationTag = 10000
aroben's avatar
aroben committed
116 117 118 119 120 121 122 123
    };

    enum ContextMenuItemType {
        ActionType,
        SeparatorType,
        SubmenuType
    };

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
#if PLATFORM(MAC)
    typedef NSMenuItem* PlatformMenuItemDescription;
#elif PLATFORM(WIN)
    typedef LPMENUITEMINFO PlatformMenuItemDescription;
#elif PLATFORM(QT)
    struct PlatformMenuItemDescriptionType {
        PlatformMenuItemDescriptionType() : qaction(0), menu(0), action(ContextMenuItemTagNoAction), type(ActionType), subMenu(0) {}
        QAction *qaction;
        QMenu *menu;
        ContextMenuAction action;
        QString title;
        ContextMenuItemType type;
        PlatformMenuDescription subMenu;
    };
    typedef PlatformMenuItemDescriptionType* PlatformMenuItemDescription;
zecke's avatar
/:  
zecke committed
139
#elif PLATFORM(GTK)
140 141 142
    typedef GtkMenuItem* PlatformMenuItemDescription;
#endif

bdakin's avatar
bdakin committed
143
    class ContextMenuItem {
aroben's avatar
aroben committed
144
    public:
bdakin's avatar
bdakin committed
145 146 147
        ContextMenuItem(PlatformMenuItemDescription);
        ContextMenuItem(ContextMenu* subMenu = 0);
        ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu = 0);
aroben's avatar
aroben committed
148 149
        ~ContextMenuItem();

bdakin's avatar
bdakin committed
150
        PlatformMenuItemDescription releasePlatformDescription();
bdakin's avatar
bdakin committed
151

aroben's avatar
aroben committed
152
        ContextMenuItemType type() const;
bdakin's avatar
bdakin committed
153
        void setType(ContextMenuItemType);
bdakin's avatar
bdakin committed
154 155

        ContextMenuAction action() const;
bdakin's avatar
bdakin committed
156
        void setAction(ContextMenuAction);
bdakin's avatar
bdakin committed
157 158

        String title() const;
aroben's avatar
aroben committed
159
        void setTitle(const String&);
bdakin's avatar
bdakin committed
160 161

        PlatformMenuDescription platformSubMenu() const;
bdakin's avatar
bdakin committed
162 163
        void setSubMenu(ContextMenu*);

aroben's avatar
aroben committed
164
        void setChecked(bool = true);
aroben's avatar
aroben committed
165
        
aroben's avatar
aroben committed
166
        void setEnabled(bool = true);
aroben's avatar
aroben committed
167
        bool enabled() const;
aroben's avatar
aroben committed
168 169 170 171

        // FIXME: Do we need a keyboard accelerator here?

    private:
bdakin's avatar
bdakin committed
172 173 174
#if PLATFORM(MAC)
        RetainPtr<NSMenuItem> m_platformDescription;
#else
aroben's avatar
aroben committed
175
        PlatformMenuItemDescription m_platformDescription;
bdakin's avatar
bdakin committed
176
#endif
aroben's avatar
aroben committed
177 178 179 180 181
    };

}

#endif // ContextMenuItem_h