void ContextMenu::appendItem(ContextMenuItem& item)
{
    if (!m_platformDescription)
        return;
        
    PlatformMenuItemDescription itemDescription = item.releasePlatformDescription();    
    wxItemKind menuKindWx = ( itemDescription.type == CheckableActionType ) ? wxITEM_CHECK : wxITEM_NORMAL;
    wxString titleWx(itemDescription.title);
    int idWx = wxID_ANY;
    wxMenuItem * itemWx;

    ItemActionMap::const_iterator end = s_itemActions.end();
    for (ItemActionMap::const_iterator it = s_itemActions.begin();  it != end; ++it) {
        if (it->second == itemDescription.action)
            idWx = it->first;
    }

    if (itemDescription.subMenu) {
        itemWx = new wxMenuItem(m_platformDescription, idWx, titleWx, wxEmptyString, wxITEM_NORMAL, itemDescription.subMenu);
    } else if (itemDescription.type != SeparatorType) {
        itemWx = new wxMenuItem(m_platformDescription, idWx, titleWx, wxT(""), menuKindWx);
    } else {
        itemWx = new wxMenuItem(m_platformDescription);
    }

    s_itemActions.add(itemWx->GetId(), item.action());
    
    m_platformDescription->Append(itemWx);
    m_platformDescription->Enable(itemWx->GetId(), itemDescription.enabled);
    
    if (menuKindWx == wxITEM_CHECK)
        m_platformDescription->Check(itemWx->GetId(), itemDescription.checked);        
}
Exemplo n.º 2
0
bool ContextMenuUtil::InitMenus(void)
{
	_menuList = new vector<ContextMenuItem*>();

	Json::Value jsonRoot;

	jsonRoot[NATIVITY_COMMAND] = NATIVITY_GET_CONTEXT_MENU_LIST;

	for (vector<wstring>::iterator it = _selectedFiles->begin(); it != _selectedFiles->end(); it++)
	{
		jsonRoot[NATIVITY_VALUE].append(StringUtil::toString(*it));
	}

	Json::FastWriter jsonWriter;

	wstring* getMenuMessage = new wstring();

	getMenuMessage->append(StringUtil::toWstring(jsonWriter.write(jsonRoot)));

	wstring* getMenuReceived = new wstring();

	if (_communicationSocket->SendMessageReceiveResponse(getMenuMessage->c_str(), getMenuReceived))
	{
		Json::Reader jsonReader;
		Json::Value jsonResponse;

		if (!jsonReader.parse(StringUtil::toString(*getMenuReceived), jsonResponse))
		{
			delete getMenuReceived;
			delete getMenuMessage;

			return false;
		}

		Json::Value jsonContextMenuItemsList = jsonResponse.get(NATIVITY_VALUE, "");

		for (unsigned int i = 0; i < jsonContextMenuItemsList.size(); i++)
		{
			Json::Value jsonContextMenuItem = jsonContextMenuItemsList[i];

			ContextMenuItem* contextMenuItem = new ContextMenuItem();
			contextMenuItem->SetId(i);

			if (!_ParseContextMenuItem(jsonContextMenuItem, contextMenuItem))
			{
				delete getMenuReceived;
				delete getMenuMessage;

				return false;
			}

			_menuList->push_back(contextMenuItem);
		}
	}

	delete getMenuReceived;
	delete getMenuMessage;

	return true;;
}
Exemplo n.º 3
0
void ContextMenu::insertItem(unsigned position, ContextMenuItem& item)
{
	checkOrEnableIfNeeded( item );
	
	if( item.releasePlatformDescription() != NULL )
	    m_platformDescription->AddItem( item.releasePlatformDescription(), position );
}
Exemplo n.º 4
0
//! Insert a menu item at specified position.
ContextMenuItem* ContextMenu::insertItem(unsigned int idx, const std::string& text, int commandId, bool enabled,
    bool hasSubMenu, bool checked, bool autoChecking)
{
  ContextMenuItem* newItem = new ContextMenuItem( this, text );
  newItem->setEnabled( enabled );
  newItem->setSubElement( true );
  newItem->setChecked( checked );
  newItem->setAutoChecking( autoChecking );
  newItem->setText( text );
  newItem->setFlag( ContextMenuItem::drawSubmenuSprite );
  newItem->setIsSeparator( text.empty() );
  newItem->setCommandId( commandId );
  sendChildToBack( newItem );

  if (hasSubMenu)
  {
    ContextMenu* subMenu = newItem->addSubMenu( commandId );
    subMenu->setVisible( false );
  }

  if ( idx < _d->items.size() )
  {
    _d->items.insert( _d->items.begin() + idx, newItem );
  }
  else
  {
    _d->items.push_back( newItem );
  }

  return newItem;
}
Exemplo n.º 5
0
bool ContextMenuUtil::PerformAction(int command)
{
	ContextMenuItem*  item;
	
	if(!GetContextMenuItem(command, &item))
	{
		return false;
	}

	wstring* list = new wstring();

	if(!ParserUtil::SerializeList(_selectedFiles, list, true))
	{
		return false;
	}
	
	wchar_t* buffer = new wchar_t(10);

	_itow_s(item->GetId(), buffer, 10, 10);

	wstring* idString = new wstring(buffer);

	map<wstring*, wstring*>* message = new map<wstring*, wstring*>();
	wstring* id = new wstring(ID);
	wstring* files = new wstring(FILES);

	message->insert(make_pair(id, idString));
	message->insert(make_pair(files, list));

	wstring* messageString = new wstring();

	if(!ParserUtil::SerializeMessage(message, messageString, true))
	{
		return false;
	}

	NativityMessage* nativityMessage = new NativityMessage();
	
	wstring* title = new wstring(PERFORM_ACTION);
	nativityMessage->SetCommand(title);
	nativityMessage->SetValue(messageString);

	wstring* nativityMessageString = new wstring();

	if(!ParserUtil::SerializeMessage(nativityMessage, nativityMessageString))
	{
		return false;
	}

	wstring* response = new wstring();

	if(!_communicationSocket->SendMessageReceiveResponse(nativityMessageString->c_str(), response))
	{
		return false;
	}

	return true;
}
Exemplo n.º 6
0
void ContextMenuClientImpl::populateCustomMenuItems(WebCore::ContextMenu* defaultMenu, WebContextMenuData* data)
{
    Vector<WebMenuItemInfo> customItems;
    for (size_t i = 0; i < defaultMenu->itemCount(); ++i) {
        ContextMenuItem* inputItem = defaultMenu->itemAtIndex(i, defaultMenu->platformDescription());
        if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->action() >  ContextMenuItemLastCustomTag)
            continue;

        WebMenuItemInfo outputItem;
        outputItem.label = inputItem->title();
        outputItem.enabled = inputItem->enabled();
        outputItem.checked = inputItem->checked();
        outputItem.action = static_cast<unsigned>(inputItem->action() - ContextMenuItemBaseCustomTag);
        switch (inputItem->type()) {
        case ActionType:
            outputItem.type = WebMenuItemInfo::Option;
            break;
        case CheckableActionType:
            outputItem.type = WebMenuItemInfo::CheckableOption;
            break;
        case SeparatorType:
            outputItem.type = WebMenuItemInfo::Separator;
            break;
        case SubmenuType:
            outputItem.type = WebMenuItemInfo::Group;
            break;
        }
        customItems.append(outputItem);
    }

    WebVector<WebMenuItemInfo> outputItems(customItems.size());
    for (size_t i = 0; i < customItems.size(); ++i)
        outputItems[i] = customItems[i];
    data->customItems.swap(outputItems);
}
void CustomContextMenuProvider::appendSeparator(ContextMenu& contextMenu)
{
    // Avoid separators at the start of any menu and submenu.
    if (!contextMenu.items().size())
        return;

    // Collapse all sequences of two or more adjacent separators in the menu or
    // any submenus to a single separator.
    ContextMenuItem lastItem = contextMenu.items().last();
    if (lastItem.type() == SeparatorType)
        return;

    contextMenu.appendItem(ContextMenuItem(SeparatorType, ContextMenuItemCustomTagNoAction, String(), String()));
}
Exemplo n.º 8
0
ContextMenuItem* MainMenu::addItem(const std::string& text, int commandId, bool enabled, bool hasSubMenu, bool checked, bool autoChecking)
{
    ContextMenuItem* ret = ContextMenu::addItem( text, commandId, enabled, hasSubMenu, checked, autoChecking );
    if( ret && ret->getSubMenu() )
    {
      //ret->getSubMenu()->setStyle( getStyle().getSubStyle( NES_SUBMENU ).getName() );
		  ret->setFlag( ContextMenuItem::drawSubmenuSprite, false );
      ret->setBackgroundMode( Label::bgNone ); 
    }
    //refItem.alignEnabled = true;
    //refItem.horizontal = EGUIA_CENTER;
    //refItem.vertical = EGUIA_CENTER;

    return ret;
}
Exemplo n.º 9
0
static void createAndAppendSpellingAndGrammarSubMenu(const HitTestResult& result, ContextMenuItem& spellingAndGrammarMenuItem)
{
    ContextMenu spellingAndGrammarMenu(result);

    ContextMenuItem showSpellingPanel(ActionType, ContextMenuItemTagShowSpellingPanel, 
        contextMenuItemTagShowSpellingPanel(true));
    ContextMenuItem checkSpelling(ActionType, ContextMenuItemTagCheckSpelling, 
        contextMenuItemTagCheckSpelling());
    ContextMenuItem checkAsYouType(CheckableActionType, ContextMenuItemTagCheckSpellingWhileTyping, 
        contextMenuItemTagCheckSpellingWhileTyping());
    ContextMenuItem grammarWithSpelling(CheckableActionType, ContextMenuItemTagCheckGrammarWithSpelling, 
        contextMenuItemTagCheckGrammarWithSpelling());
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    ContextMenuItem correctSpelling(CheckableActionType, ContextMenuItemTagCorrectSpellingAutomatically, 
        contextMenuItemTagCorrectSpellingAutomatically());
#endif

    spellingAndGrammarMenu.appendItem(showSpellingPanel);
    spellingAndGrammarMenu.appendItem(checkSpelling);
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    spellingAndGrammarMenu.appendItem(*separatorItem());
#endif
    spellingAndGrammarMenu.appendItem(checkAsYouType);
    spellingAndGrammarMenu.appendItem(grammarWithSpelling);
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    spellingAndGrammarMenu.appendItem(correctSpelling);
#endif

    spellingAndGrammarMenuItem.setSubMenu(&spellingAndGrammarMenu);
}
Exemplo n.º 10
0
static void createAndAppendFontSubMenu(const HitTestResult& result, ContextMenuItem& fontMenuItem)
{
    ContextMenu fontMenu(result);

#if PLATFORM(MAC)
    ContextMenuItem showFonts(ActionType, ContextMenuItemTagShowFonts, contextMenuItemTagShowFonts());
#endif
    ContextMenuItem bold(CheckableActionType, ContextMenuItemTagBold, contextMenuItemTagBold());
    ContextMenuItem italic(CheckableActionType, ContextMenuItemTagItalic, contextMenuItemTagItalic());
    ContextMenuItem underline(CheckableActionType, ContextMenuItemTagUnderline, contextMenuItemTagUnderline());
    ContextMenuItem outline(ActionType, ContextMenuItemTagOutline, contextMenuItemTagOutline());
#if PLATFORM(MAC)
    ContextMenuItem styles(ActionType, ContextMenuItemTagStyles, contextMenuItemTagStyles());
    ContextMenuItem showColors(ActionType, ContextMenuItemTagShowColors, contextMenuItemTagShowColors());
#endif

#if PLATFORM(MAC)
    fontMenu.appendItem(showFonts);
#endif
    fontMenu.appendItem(bold);
    fontMenu.appendItem(italic);
    fontMenu.appendItem(underline);
    fontMenu.appendItem(outline);
#if PLATFORM(MAC)
    fontMenu.appendItem(styles);
    fontMenu.appendItem(*separatorItem());
    fontMenu.appendItem(showColors);
#endif

    fontMenuItem.setSubMenu(&fontMenu);
}
v8::Handle<v8::Value> V8InspectorFrontendHost::showContextMenuCallback(const v8::Arguments& args)
{
    if (args.Length() < 2)
        return v8::Undefined();

    v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(args[0]);
    if (!V8MouseEvent::info.equals(V8DOMWrapper::domWrapperType(eventWrapper)))
        return v8::Undefined();

    Event* event = V8Event::toNative(eventWrapper);
    if (!args[1]->IsArray())
        return v8::Undefined();

    v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]);
    Vector<ContextMenuItem*> items;

    for (size_t i = 0; i < array->Length(); ++i) {
        v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(array->Get(v8::Integer::New(i)));
        v8::Local<v8::Value> type = item->Get(v8::String::New("type"));
        v8::Local<v8::Value> id = item->Get(v8::String::New("id"));
        v8::Local<v8::Value> label = item->Get(v8::String::New("label"));
        v8::Local<v8::Value> enabled = item->Get(v8::String::New("enabled"));
        v8::Local<v8::Value> checked = item->Get(v8::String::New("checked"));
        if (!type->IsString())
            continue;
        String typeString = toWebCoreStringWithNullCheck(type);
        if (typeString == "separator") {
            items.append(new ContextMenuItem(SeparatorType,
                                             ContextMenuItemCustomTagNoAction,
                                             String()));
        } else {
            ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id->ToInt32()->Value());
            ContextMenuItem* menuItem = new ContextMenuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, toWebCoreStringWithNullCheck(label));
            if (checked->IsBoolean())
                menuItem->setChecked(checked->ToBoolean()->Value());
            if (enabled->IsBoolean())
                menuItem->setEnabled(enabled->ToBoolean()->Value());
            items.append(menuItem);
        }
    }

    InspectorFrontendHost* frontendHost = V8InspectorFrontendHost::toNative(args.Holder());
    frontendHost->showContextMenu(event, items);

    return v8::Undefined();
}
Exemplo n.º 12
0
void ContextMenu::appendItem(ContextMenuItem& item)
{
    checkOrEnableIfNeeded(item);

    BMenuItem* menuItem = item.releasePlatformDescription();
    if (menuItem)
        m_platformDescription->AddItem(menuItem);
}
Exemplo n.º 13
0
bool ContextMenuUtil::GetContextMenuAction(int action, ContextMenuAction** item)
{
	ContextMenuItem* contextMenuItem;

	if (GetContextMenuItem(action, &contextMenuItem))
	{
		ContextMenuAction* action = new ContextMenuAction();
		action->SetUuid(contextMenuItem->GetUuid());
		action->SetFiles(_selectedFiles);

		item = &action;

		return true;
	}

	return false;
}
Exemplo n.º 14
0
void ContextMenu::insertItem(unsigned int position, ContextMenuItem& item)
{
    if (!m_platformDescription)
        return;

    checkOrEnableIfNeeded(item);
    ::InsertMenuItem(m_platformDescription, position, TRUE, item.releasePlatformDescription());
}
Exemplo n.º 15
0
void ContextMenu::appendItem(ContextMenuItem& item)
{
    ASSERT(m_platformDescription);

    GtkMenuItem* platformItem = item.releasePlatformDescription();
    ASSERT(platformItem);
    gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), GTK_WIDGET(platformItem));
    gtk_widget_show(GTK_WIDGET(platformItem));
}
Exemplo n.º 16
0
void ContextMenu::appendItem(ContextMenuItem& item)
{
    DEBUG("ContextMenu::appendItem\n" );
    
    checkOrEnableIfNeeded( item );
    
    os::MenuItem* pcItem = item.releasePlatformDescription();
    if( pcItem != NULL )
	    m_platformDescription->AddItem( pcItem );
}
Exemplo n.º 17
0
bool ContextMenuUtil::GetContextMenuAction(std::wstring* title, ContextMenuAction** item)
{
	for (vector<ContextMenuItem*>::iterator it = _menuList->begin(); it != _menuList->end(); it++)
	{
		ContextMenuItem* temp = *it;
		wstring* currentTitle = temp->GetTitle();

		if (currentTitle->compare(*title) == 0)
		{
			ContextMenuAction* action = new ContextMenuAction();
			action->SetUuid(temp->GetUuid());
			action->SetFiles(_selectedFiles);

			item = &action;
			return true;
		}
	}

	return false;
}
Exemplo n.º 18
0
static void createAndAppendSpeechSubMenu(const HitTestResult& result, ContextMenuItem& speechMenuItem)
{
    ContextMenu speechMenu(result);

    ContextMenuItem start(ActionType, ContextMenuItemTagStartSpeaking, contextMenuItemTagStartSpeaking());
    ContextMenuItem stop(ActionType, ContextMenuItemTagStopSpeaking, contextMenuItemTagStopSpeaking());

    speechMenu.appendItem(start);
    speechMenu.appendItem(stop);

    speechMenuItem.setSubMenu(&speechMenu);
}
Exemplo n.º 19
0
bool ContextMenuUtil::PerformAction(int command)
{
	ContextMenuItem* contextMenuItem;

	if (!GetContextMenuItem(command, &contextMenuItem))
	{
		return false;
	}

	Json::Value jsonValue;

	jsonValue[NATIVITY_UUID] = StringUtil::toString(contextMenuItem->GetUuid()->c_str());

	for (vector<wstring>::iterator it = _selectedFiles->begin(); it != _selectedFiles->end(); it++)
	{
		wstring selectedFile = *it;

		jsonValue[NATIVITY_FILES].append(StringUtil::toString(selectedFile));
	}

	Json::Value jsonRoot;

	jsonRoot[NATIVITY_COMMAND] = NATIVITY_CONTEXT_MENU_ACTION;
	jsonRoot[NATIVITY_VALUE] = jsonValue;

	Json::FastWriter jsonWriter;

	wstring* jsonMessage = new wstring();

	jsonMessage->append(StringUtil::toWstring(jsonWriter.write(jsonRoot)));

	wstring* response = new wstring();

	if (!_communicationSocket->SendMessageReceiveResponse(jsonMessage->c_str(), response))
	{
		return false;
	}

	return true;
}
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* exec)
{
    if (exec->argumentCount() < 2)
        return jsUndefined();
#if ENABLE(CONTEXT_MENUS)
    Event* event = toEvent(exec->argument(0));

    JSArray* array = asArray(exec->argument(1));
    Vector<ContextMenuItem*> items;

    for (size_t i = 0; i < array->length(); ++i) {
        JSObject* item = asObject(array->getIndex(i));
        JSValue label = item->get(exec, Identifier(exec, "label"));
        JSValue type = item->get(exec, Identifier(exec, "type"));
        JSValue id = item->get(exec, Identifier(exec, "id"));
        JSValue enabled = item->get(exec, Identifier(exec, "enabled"));
        JSValue checked = item->get(exec, Identifier(exec, "checked"));
        if (!type.isString())
            continue;

        String typeString = ustringToString(type.toString(exec)->value(exec));
        if (typeString == "separator") {
            items.append(new ContextMenuItem(SeparatorType,
                                             ContextMenuItemCustomTagNoAction,
                                             String()));
        } else {
            ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
            ContextMenuItem* menuItem = new ContextMenuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, ustringToString(label.toString(exec)->value(exec)));
            if (!enabled.isUndefined())
                menuItem->setEnabled(enabled.toBoolean(exec));
            if (!checked.isUndefined())
                menuItem->setChecked(checked.toBoolean(exec));
            items.append(menuItem);
        }
    }

    impl()->showContextMenu(event, items);
#endif
    return jsUndefined();
}
Exemplo n.º 21
0
bool ContextMenuUtil::_GetContextMenuItem(int index, vector<ContextMenuItem*>* menus, ContextMenuItem** item)
{
	for (vector<ContextMenuItem*>::iterator it = menus->begin(); it != menus->end(); it++)
	{
		ContextMenuItem* temp = *it;
		if (temp->GetIndex() == index)
		{
			*item = temp;
			return true;
		}

		if (temp->GetContextMenuItems() != 0 && temp->GetContextMenuItems()->size() > 0)
		{
			if (_GetContextMenuItem(index, temp->GetContextMenuItems(), item))
			{
				return true;
			}
		}
	}

	return false;
}
IFACEMETHODIMP LiferayNativityContextMenus::GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT* pwReserved, LPSTR pszName, UINT cchMax)
{
	HRESULT hResult = S_OK;
	ContextMenuItem* item;

	switch (uFlags)
	{
		case GCS_HELPTEXTW:
			if (!_contextMenuUtil->GetContextMenuItem((int)idCommand, &item))
			{
				return E_FAIL;
			}

			if (item->GetHelpText() == 0)
			{
				return E_FAIL;
			}

			wcscpy_s((wchar_t*)pszName, cchMax, item->GetHelpText()->c_str());

			break;

		case GCS_VERBW:
			if (!_contextMenuUtil->GetContextMenuItem((int)idCommand, &item))
			{
				return E_FAIL;
			}

			_itow_s(item->GetId(), (wchar_t*)pszName, cchMax, 10);

			break;

		default:
			hResult = S_OK;
	}

	return hResult;
}
Exemplo n.º 23
0
static void createAndAppendTextDirectionSubMenu(const HitTestResult& result, ContextMenuItem& textDirectionMenuItem)
{
    ContextMenu textDirectionMenu(result);

    ContextMenuItem defaultItem(ActionType, ContextMenuItemTagTextDirectionDefault, contextMenuItemTagDefaultDirection());
    ContextMenuItem ltr(CheckableActionType, ContextMenuItemTagTextDirectionLeftToRight, contextMenuItemTagLeftToRight());
    ContextMenuItem rtl(CheckableActionType, ContextMenuItemTagTextDirectionRightToLeft, contextMenuItemTagRightToLeft());

    textDirectionMenu.appendItem(defaultItem);
    textDirectionMenu.appendItem(ltr);
    textDirectionMenu.appendItem(rtl);

    textDirectionMenuItem.setSubMenu(&textDirectionMenu);
}
Exemplo n.º 24
0
static void createAndAppendTransformationsSubMenu(const HitTestResult& result, ContextMenuItem& transformationsMenuItem)
{
    ContextMenu transformationsMenu(result);

    ContextMenuItem makeUpperCase(ActionType, ContextMenuItemTagMakeUpperCase, contextMenuItemTagMakeUpperCase());
    ContextMenuItem makeLowerCase(ActionType, ContextMenuItemTagMakeLowerCase, contextMenuItemTagMakeLowerCase());
    ContextMenuItem capitalize(ActionType, ContextMenuItemTagCapitalize, contextMenuItemTagCapitalize());

    transformationsMenu.appendItem(makeUpperCase);
    transformationsMenu.appendItem(makeLowerCase);
    transformationsMenu.appendItem(capitalize);

    transformationsMenuItem.setSubMenu(&transformationsMenu);
}
Exemplo n.º 25
0
void WebContextMenuProxyGtk::append(ContextMenuItem& menuItem)
{
    unsigned long signalHandlerId;
    GtkAction* action = menuItem.gtkAction();
    if (action) {
        switch (menuItem.type()) {
        case ActionType:
        case CheckableActionType:
            g_object_set_data(G_OBJECT(action), gContextMenuActionId, GINT_TO_POINTER(menuItem.action()));
            signalHandlerId = g_signal_connect(action, "activate", G_CALLBACK(contextMenuItemActivatedCallback), m_page);
            m_signalHandlers.set(signalHandlerId, action);
            // Fall through.
        case SubmenuType:
            signalHandlerId = g_signal_connect(action, "notify::visible", G_CALLBACK(contextMenuItemVisibilityChanged), this);
            m_signalHandlers.set(signalHandlerId, action);
            break;
        case SeparatorType:
            break;
        }
    }

    m_menu.appendItem(menuItem);
}
Exemplo n.º 26
0
static void createAndAppendSpellingSubMenu(const HitTestResult& result, ContextMenuItem& spellingMenuItem)
{
    ContextMenu spellingMenu(result);

    ContextMenuItem showSpellingPanel(ActionType, ContextMenuItemTagShowSpellingPanel, 
        contextMenuItemTagShowSpellingPanel(true));
    ContextMenuItem checkSpelling(ActionType, ContextMenuItemTagCheckSpelling, 
        contextMenuItemTagCheckSpelling());
    ContextMenuItem checkAsYouType(CheckableActionType, ContextMenuItemTagCheckSpellingWhileTyping, 
        contextMenuItemTagCheckSpellingWhileTyping());

    spellingMenu.appendItem(showSpellingPanel);
    spellingMenu.appendItem(checkSpelling);
    spellingMenu.appendItem(checkAsYouType);

    spellingMenuItem.setSubMenu(&spellingMenu);
}
Exemplo n.º 27
0
static void createAndAppendSubstitutionsSubMenu(const HitTestResult& result, ContextMenuItem& substitutionsMenuItem)
{
    ContextMenu substitutionsMenu(result);

    ContextMenuItem showSubstitutions(ActionType, ContextMenuItemTagShowSubstitutions, contextMenuItemTagShowSubstitutions(true));
    ContextMenuItem smartCopyPaste(CheckableActionType, ContextMenuItemTagSmartCopyPaste, contextMenuItemTagSmartCopyPaste());
    ContextMenuItem smartQuotes(CheckableActionType, ContextMenuItemTagSmartQuotes, contextMenuItemTagSmartQuotes());
    ContextMenuItem smartDashes(CheckableActionType, ContextMenuItemTagSmartDashes, contextMenuItemTagSmartDashes());
    ContextMenuItem smartLinks(CheckableActionType, ContextMenuItemTagSmartLinks, contextMenuItemTagSmartLinks());
    ContextMenuItem textReplacement(CheckableActionType, ContextMenuItemTagTextReplacement, contextMenuItemTagTextReplacement());

    substitutionsMenu.appendItem(showSubstitutions);
    substitutionsMenu.appendItem(*separatorItem());
    substitutionsMenu.appendItem(smartCopyPaste);
    substitutionsMenu.appendItem(smartQuotes);
    substitutionsMenu.appendItem(smartDashes);
    substitutionsMenu.appendItem(smartLinks);
    substitutionsMenu.appendItem(textReplacement);

    substitutionsMenuItem.setSubMenu(&substitutionsMenu);
}
Exemplo n.º 28
0
void MainMenu::recalculateSize_()
{
	Rect parentRect = getParent()->getClientRect(); // client rect of parent  

	//AbstractSkin* skin = getEnvironment()->getSkin();
  Font font = Font::create( FONT_2_WHITE );
  
  int height = std::max<int>( DEFAULT_MENU_HEIGHT, getHeight() );
	setGeometry( Rect( parentRect.UpperLeftCorner.getX(), parentRect.UpperLeftCorner.getY(),
                     parentRect.LowerRightCorner.getX(), parentRect.UpperLeftCorner.getY() + height ) );
	Rect rect;

  rect.UpperLeftCorner = parentRect.UpperLeftCorner;
  height = std::max<int>( font.getSize("A").getHeight(), height );
	//if (skin && height < skin->getSize ( EGDS_MENU_HEIGHT ))
	//	height = skin->getSize(EGDS_MENU_HEIGHT);
	int width = rect.UpperLeftCorner.getX();
	int i;

	for( i=0; i<(int)getItemCount(); ++i)
	{
    ContextMenuItem* refItem = getItem( i );
		if ( refItem->isSeparator() )
		{
			refItem->setDim( Size( 16, getHeight() ) );
		}
		else
		{
      Size itemSize = font.getSize( refItem->getText() ) + Size( 20, 0 );
      itemSize.setHeight( getHeight() );
			refItem->setDim( itemSize );
		}

		refItem->setOffset( width );
		width += refItem->getDim().getWidth();
	}

	// recalculate submenus
	for (i=0; i<(int)getItemCount(); ++i)
  {
    ContextMenuItem* refItem = getItem( i );

    Rect rectangle( refItem->getOffset(), 0, refItem->getOffset() + refItem->getDim().getWidth(), height );
    refItem->setGeometry( rectangle );

		if (refItem->getSubMenu())
		{
			// move submenu
      Size itemSize = refItem->getSubMenu()->getAbsoluteRect().getSize();

			refItem->getSubMenu()->setGeometry( Rect( refItem->getOffset(), height,
					                          						refItem->getOffset() + itemSize.getWidth()-5, height+itemSize.getHeight() ));
		}
  }
}
Exemplo n.º 29
0
void ContextMenu::checkOrEnableIfNeeded(ContextMenuItem& item) const
{
    if (item.type() == SeparatorType)
        return;
    
    Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame();
    if (!frame)
        return;

    bool shouldEnable = true;
    bool shouldCheck = false; 

    switch (item.action()) {
        case ContextMenuItemTagCheckSpelling:
            shouldEnable = frame->editor()->canEdit();
            break;
        case ContextMenuItemTagDefaultDirection:
            shouldCheck = false;
            shouldEnable = false;
            break;
        case ContextMenuItemTagLeftToRight:
        case ContextMenuItemTagRightToLeft: {
            ExceptionCode ec = 0;
            RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
            String direction = item.action() == ContextMenuItemTagLeftToRight ? "ltr" : "rtl";
            style->setProperty(CSSPropertyDirection, direction, false, ec);
            shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
            shouldEnable = true;
            break;
        }
        case ContextMenuItemTagTextDirectionDefault: {
            Editor::Command command = frame->editor()->command("MakeTextWritingDirectionNatural");
            shouldCheck = command.state() == TrueTriState;
            shouldEnable = command.isEnabled();
            break;
        }
        case ContextMenuItemTagTextDirectionLeftToRight: {
            Editor::Command command = frame->editor()->command("MakeTextWritingDirectionLeftToRight");
            shouldCheck = command.state() == TrueTriState;
            shouldEnable = command.isEnabled();
            break;
        }
        case ContextMenuItemTagTextDirectionRightToLeft: {
            Editor::Command command = frame->editor()->command("MakeTextWritingDirectionRightToLeft");
            shouldCheck = command.state() == TrueTriState;
            shouldEnable = command.isEnabled();
            break;
        }
        case ContextMenuItemTagCopy:
            shouldEnable = frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
            break;
        case ContextMenuItemTagCut:
            shouldEnable = frame->editor()->canDHTMLCut() || frame->editor()->canCut();
            break;
        case ContextMenuItemTagIgnoreSpelling:
        case ContextMenuItemTagLearnSpelling:
            shouldEnable = frame->selection()->isRange();
            break;
        case ContextMenuItemTagPaste:
            shouldEnable = frame->editor()->canDHTMLPaste() || frame->editor()->canPaste();
            break;
#if PLATFORM(GTK)
        case ContextMenuItemTagDelete:
            shouldEnable = frame->editor()->canDelete();
            break;
        case ContextMenuItemTagSelectAll:
        case ContextMenuItemTagInputMethods:
        case ContextMenuItemTagUnicode:
            shouldEnable = true;
            break;
#endif
        case ContextMenuItemTagUnderline: {
            ExceptionCode ec = 0;
            RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
            style->setProperty(CSSPropertyWebkitTextDecorationsInEffect, "underline", false, ec);
            shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
            shouldEnable = frame->editor()->canEditRichly();
            break;
        }
        case ContextMenuItemTagLookUpInDictionary:
            shouldEnable = frame->selection()->isRange();
            break;
        case ContextMenuItemTagCheckGrammarWithSpelling:
#ifndef BUILDING_ON_TIGER
            if (frame->editor()->isGrammarCheckingEnabled())
                shouldCheck = true;
            shouldEnable = true;
#endif
            break;
        case ContextMenuItemTagItalic: {
            ExceptionCode ec = 0;
            RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
            style->setProperty(CSSPropertyFontStyle, "italic", false, ec);
            shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
            shouldEnable = frame->editor()->canEditRichly();
            break;
        }
        case ContextMenuItemTagBold: {
            ExceptionCode ec = 0;
            RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
            style->setProperty(CSSPropertyFontWeight, "bold", false, ec);
            shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
            shouldEnable = frame->editor()->canEditRichly();
            break;
        }
        case ContextMenuItemTagOutline:
            shouldEnable = false;
            break;
        case ContextMenuItemTagShowSpellingPanel:
#ifndef BUILDING_ON_TIGER
            if (frame->editor()->spellingPanelIsShowing())
                item.setTitle(contextMenuItemTagShowSpellingPanel(false));
            else
                item.setTitle(contextMenuItemTagShowSpellingPanel(true));
#endif
            shouldEnable = frame->editor()->canEdit();
            break;
        case ContextMenuItemTagNoGuessesFound:
            shouldEnable = false;
            break;
        case ContextMenuItemTagCheckSpellingWhileTyping:
            shouldCheck = frame->editor()->isContinuousSpellCheckingEnabled();
            break;
#if PLATFORM(GTK)
        case ContextMenuItemTagGoBack:
            shouldEnable = frame->loader()->canGoBackOrForward(-1);
            break;
        case ContextMenuItemTagGoForward:
            shouldEnable = frame->loader()->canGoBackOrForward(1);
            break;
        case ContextMenuItemTagStop:
            shouldEnable = frame->loader()->documentLoader()->isLoadingInAPISense();
            break;
        case ContextMenuItemTagReload:
            shouldEnable = !frame->loader()->documentLoader()->isLoadingInAPISense();
            break;
        case ContextMenuItemTagFontMenu:
            shouldEnable = frame->editor()->canEditRichly();
            break;
#else
        case ContextMenuItemTagGoBack:
        case ContextMenuItemTagGoForward:
        case ContextMenuItemTagStop:
        case ContextMenuItemTagReload:
        case ContextMenuItemTagFontMenu:
#endif
        case ContextMenuItemTagNoAction:
        case ContextMenuItemTagOpenLinkInNewWindow:
        case ContextMenuItemTagDownloadLinkToDisk:
        case ContextMenuItemTagCopyLinkToClipboard:
        case ContextMenuItemTagOpenImageInNewWindow:
        case ContextMenuItemTagDownloadImageToDisk:
        case ContextMenuItemTagCopyImageToClipboard:
        case ContextMenuItemTagOpenFrameInNewWindow:
        case ContextMenuItemTagSpellingGuess:
        case ContextMenuItemTagOther:
        case ContextMenuItemTagSearchInSpotlight:
        case ContextMenuItemTagSearchWeb:
        case ContextMenuItemTagOpenWithDefaultApplication:
        case ContextMenuItemPDFActualSize:
        case ContextMenuItemPDFZoomIn:
        case ContextMenuItemPDFZoomOut:
        case ContextMenuItemPDFAutoSize:
        case ContextMenuItemPDFSinglePage:
        case ContextMenuItemPDFFacingPages:
        case ContextMenuItemPDFContinuous:
        case ContextMenuItemPDFNextPage:
        case ContextMenuItemPDFPreviousPage:
        case ContextMenuItemTagOpenLink:
        case ContextMenuItemTagIgnoreGrammar:
        case ContextMenuItemTagSpellingMenu:
        case ContextMenuItemTagShowFonts:
        case ContextMenuItemTagStyles:
        case ContextMenuItemTagShowColors:
        case ContextMenuItemTagSpeechMenu:
        case ContextMenuItemTagStartSpeaking:
        case ContextMenuItemTagStopSpeaking:
        case ContextMenuItemTagWritingDirectionMenu:
        case ContextMenuItemTagTextDirectionMenu:
        case ContextMenuItemTagPDFSinglePageScrolling:
        case ContextMenuItemTagPDFFacingPagesScrolling:
        case ContextMenuItemTagInspectElement:
        case ContextMenuItemBaseApplicationTag:
            break;
    }

    item.setChecked(shouldCheck);
    item.setEnabled(shouldEnable);
}
Exemplo n.º 30
0
TopMenu::TopMenu(Widget* parent, const int height , bool useIcon)
: MainMenu( parent, Rect( 0, 0, parent->width(), height ) ),
  _d( new Impl )
{
  setupUI( ":/gui/topmenu.gui" );
  setGeometry( Rect( 0, 0, parent->width(), height ) );

  _d->initBackground( size() );
  _d->useIcon = useIcon;

  GET_DWIDGET_FROM_UI( _d, lbPopulation )
  GET_DWIDGET_FROM_UI( _d, lbFunds )
  GET_DWIDGET_FROM_UI( _d, lbDate )

  if( _d->lbPopulation )
  {
    _d->lbPopulation->setPosition( Point( width() - populationLabelOffset, 0 ) );
    _d->lbPopulation->setIcon( useIcon ? Picture( "population", 1 ) : Picture() );
  }

  if( _d->lbFunds )
  {
    _d->lbFunds->setPosition(  Point( width() - fundLabelOffset, 0) );
    _d->lbFunds->setIcon( useIcon ? Picture( "paneling", 332 ) : Picture() );
  }

  if( _d->lbDate )
    _d->lbDate->setPosition( Point( width() - dateLabelOffset, 0) );

  ContextMenuItem* tmp = addItem( _("##gmenu_file##"), -1, true, true, false, false );
  ContextMenu* file = tmp->addSubMenu();

  ContextMenuItem* restart = file->addItem( _("##gmenu_file_restart##"), -1, true, false, false, false );
  ContextMenuItem* load = file->addItem( _("##mainmenu_loadgame##"), -1, true, false, false, false );
  ContextMenuItem* save = file->addItem( _("##gmenu_file_save##"), -1, true, false, false, false );
  ContextMenuItem* mainMenu = file->addItem( _("##gmenu_file_mainmenu##"), -1, true, false, false, false );
  ContextMenuItem* exit = file->addItem( _("##gmenu_exit_game##"), -1, true, false, false, false );

  CONNECT( restart, onClicked(), &_d->onRestartSignal, Signal0<>::_emit );
  CONNECT( exit, onClicked(), &_d->onExitSignal, Signal0<>::_emit );
  CONNECT( save, onClicked(), &_d->onSaveSignal, Signal0<>::_emit );
  CONNECT( load, onClicked(), &_d->onLoadSignal, Signal0<>::_emit );
  CONNECT( mainMenu, onClicked(), &_d->onEndSignal, Signal0<>::_emit );

  tmp = addItem( _("##gmenu_options##"), -1, true, true, false, false );
  ContextMenu* options = tmp->addSubMenu();
  ContextMenuItem* screen = options->addItem( _("##screen_settings##"), -1, true, false, false, false );
  ContextMenuItem* sound = options->addItem( _("##sound_settings##"), -1, true, false, false, false );
  ContextMenuItem* speed = options->addItem( _("##speed_settings##"), -1, true, false, false, false );
  ContextMenuItem* cityopts = options->addItem( _("##city_settings##"), -1, true, false, false, false );

  CONNECT( screen, onClicked(), &_d->onShowVideoOptionsSignal,     Signal0<>::_emit );
  CONNECT( speed,  onClicked(), &_d->onShowGameSpeedOptionsSignal, Signal0<>::_emit );
  CONNECT( sound,  onClicked(), &_d->onShowSoundOptionsSignal,     Signal0<>::_emit );
  CONNECT( cityopts,  onClicked(), &_d->onShowCityOptionsSignal,   Signal0<>::_emit );

  tmp = addItem( _("##gmenu_help##"), -1, true, true, false, false );
  ContextMenu* helpMenu = tmp->addSubMenu();
  ContextMenuItem* aboutItem = helpMenu->addItem( _("##gmenu_about##"), -1 );
  ContextMenuItem* shortkeysItem = helpMenu->addItem( _("##gmenu_shortkeys##"), -1 );
  CONNECT( aboutItem, onClicked(), _d.data(), Impl::showAboutInfo );
  CONNECT( shortkeysItem, onClicked(), _d.data(), Impl::showShortKeyInfo );

  tmp = addItem( _("##gmenu_advisors##"), -1, true, true, false, false );
  ContextMenu* advisersMenu = tmp->addSubMenu();
  advisersMenu->addItem( _("##visit_labor_advisor##"), advisor::employers );
  advisersMenu->addItem( _("##visit_military_advisor##"   ), advisor::military );
  advisersMenu->addItem( _("##visit_imperial_advisor##"     ), advisor::empire );
  advisersMenu->addItem( _("##visit_rating_advisor##"    ), advisor::ratings );
  advisersMenu->addItem( _("##visit_trade_advisor##"    ), advisor::trading );
  advisersMenu->addItem( _("##visit_population_advisor##" ), advisor::population );
  advisersMenu->addItem( _("##visit_health_advisor##"     ), advisor::health );
  advisersMenu->addItem( _("##visit_education_advisor##"  ), advisor::education );
  advisersMenu->addItem( _("##visit_religion_advisor##"   ), advisor::religion );
  advisersMenu->addItem( _("##visit_entertainment_advisor##"), advisor::entertainment );
  advisersMenu->addItem( _("##visit_financial_advisor##"    ), advisor::finance );
  advisersMenu->addItem( _("##visit_chief_advisor##"       ), advisor::main );

  CONNECT( advisersMenu, onItemAction(), _d.data(), Impl::resolveAdvisorShow );

  _d->updateDate();
}