コード例 #1
0
ファイル: Input.cpp プロジェクト: ThaPear/Engine
bool Input::HandleMessage(HWND _HWND, UINT _Message, WPARAM _WParam, LPARAM _LParam)
{
	//printf("Message %i 0x%x.\n", _Message, _Message);

	switch(_Message)
	{
		// Keyboard Input.
		//										If it's not already down.
		case WM_SYSKEYDOWN:		
		case WM_KEYDOWN:	if(!Input::m_KeyStates[GetKeyCode(_LParam)])	Input::OnKeyDown((Key)GetKeyCode(_LParam));	return true;
		case WM_SYSKEYUP:		
		case WM_KEYUP:														Input::OnKeyUp((Key)GetKeyCode(_LParam));	return true;
		case WM_MOUSEMOVE:		Input::OnMouseMove(short2(GetMouseXParam(_LParam), GetMouseYParam(_LParam)));			return true;

		// Mouse Input.
		// Down.
		case WM_LBUTTONDOWN:	Input::OnMouseBtnDown(MouseBtn::Left);													return true;
		case WM_RBUTTONDOWN:	Input::OnMouseBtnDown(MouseBtn::Right);													return true;
		case WM_MBUTTONDOWN:	Input::OnMouseBtnDown(MouseBtn::Middle);												return true;
		case WM_XBUTTONDOWN:	if(GetMouseXButton(_WParam) == 1)	Input::OnMouseBtnDown(MouseBtn::Btn4);
								else								Input::OnMouseBtnDown(MouseBtn::Btn5);				return true;
		// Up.
		case WM_LBUTTONUP:		Input::OnMouseBtnUp(MouseBtn::Left);													return true;
		case WM_RBUTTONUP:		Input::OnMouseBtnUp(MouseBtn::Right);													return true;
		case WM_MBUTTONUP:		Input::OnMouseBtnUp(MouseBtn::Middle);													return true;
		case WM_XBUTTONUP:		if(GetMouseXButton(_WParam) == 1)	Input::OnMouseBtnUp(MouseBtn::Btn4);
								else								Input::OnMouseBtnUp(MouseBtn::Btn5);				return true;
	}

	return false;
}
コード例 #2
0
wxGISAcceleratorTable::wxGISAcceleratorTable(wxGISApplicationBase* pApp) : bHasChanges(true)
{
	m_AccelEntryArray.reserve(20);

	wxGISAppConfig oConfig = GetConfig();
    if(!oConfig.IsOk())
		return;

	wxXmlNode* pAcceleratorsNodeCU = oConfig.GetConfigNode(enumGISHKCU, pApp->GetAppName() + wxString(wxT("/accelerators")));
	wxXmlNode* pAcceleratorsNodeLM = oConfig.GetConfigNode(enumGISHKLM, pApp->GetAppName() + wxString(wxT("/accelerators")));
	//merge two tables
	m_pApp = pApp;
	if(!pApp)
		return;

	//TODO: merge acc tables
	//TODO: if user delete key - it must be mark as deleted to avoid adding it fron LM table

	if(pAcceleratorsNodeCU)
	{
		wxXmlNode *child = pAcceleratorsNodeCU->GetChildren();
		while(child)
		{
			wxString sCmdName = child->GetAttribute(wxT("cmd_name"), NON);
			unsigned char nSubtype = wxAtoi(child->GetAttribute(wxT("subtype"), wxT("0")));
			wxGISCommand* pCmd = m_pApp->GetCommand(sCmdName, nSubtype);
			if(pCmd)
			{
				wxString sFlags = child->GetAttribute(wxT("flags"), wxT("NORMAL"));
                wxDword Flags = GetFlags(sFlags);
				wxString sKey = child->GetAttribute(wxT("keycode"), wxT("A"));
				int nKey = GetKeyCode(sKey);
				Add(wxAcceleratorEntry(Flags, nKey, pCmd->GetId()));
			}
			child = child->GetNext();
		}
	}
	if(pAcceleratorsNodeLM)
	{
		wxXmlNode *child = pAcceleratorsNodeLM->GetChildren();
		while(child)
		{
			wxString sCmdName = child->GetAttribute(wxT("cmd_name"), NON);
			unsigned char nSubtype = wxAtoi(child->GetAttribute(wxT("subtype"), wxT("0")));
			wxGISCommand* pCmd = m_pApp->GetCommand(sCmdName, nSubtype);
			if(pCmd)
			{
				wxString sFlags = child->GetAttribute(wxT("flags"), wxT("NORMAL"));
                wxDword Flags = GetFlags(sFlags);
				wxString sKey = child->GetAttribute(wxT("keycode"), wxT("A"));
				int nKey = GetKeyCode(sKey);
				Add(wxAcceleratorEntry(Flags, nKey, pCmd->GetId()));
			}
			child = child->GetNext();
		}
	}
}
コード例 #3
0
ファイル: accelerator.cpp プロジェクト: jacklibj/r5
wxGISAcceleratorTable::wxGISAcceleratorTable(IApplication* pApp, IGISConfig* pConf) : bHasChanges(true)
{
	m_AccelEntryArray.reserve(20);
	m_pConf = pConf;

	wxXmlNode* pAcceleratorsNodeCU = m_pConf->GetConfigNode(enumGISHKCU, wxString(wxT("accelerators")));
	wxXmlNode* pAcceleratorsNodeLM = m_pConf->GetConfigNode(enumGISHKLM, wxString(wxT("accelerators")));
	//merge two tables
	m_pApp = pApp;
	if(!pApp)
		return;

	//merge acc tables
	//if user delete key - it must be mark as deleted to avoid adding it fron LM table

	if(pAcceleratorsNodeCU)
	{
		wxXmlNode *child = pAcceleratorsNodeCU->GetChildren();
		while(child)
		{
			wxString sCmdName = child->GetPropVal(wxT("cmd_name"), NON);
			unsigned char nSubtype = wxAtoi(child->GetPropVal(wxT("subtype"), wxT("0")));
			ICommand* pCmd = m_pApp->GetCommand(sCmdName, nSubtype);
			if(pCmd)
			{
				wxString sFlags = child->GetPropVal(wxT("flags"), wxT("NORMAL"));
				WXDWORD Flags = GetFlags(sFlags);
				wxString sKey = child->GetPropVal(wxT("keycode"), wxT("A"));
				int nKey = GetKeyCode(sKey);
				Add(wxAcceleratorEntry(Flags, nKey, pCmd->GetID()));
			}
			child = child->GetNext();
		}
	}
	if(pAcceleratorsNodeLM)
	{
		wxXmlNode *child = pAcceleratorsNodeLM->GetChildren();
		while(child)
		{
			wxString sCmdName = child->GetPropVal(wxT("cmd_name"), NON);
			unsigned char nSubtype = wxAtoi(child->GetPropVal(wxT("subtype"), wxT("0")));
			ICommand* pCmd = m_pApp->GetCommand(sCmdName, nSubtype);
			if(pCmd)
			{
				wxString sFlags = child->GetPropVal(wxT("flags"), wxT("NORMAL"));
				WXDWORD Flags = GetFlags(sFlags);
				wxString sKey = child->GetPropVal(wxT("keycode"), wxT("A"));
				int nKey = GetKeyCode(sKey);
				Add(wxAcceleratorEntry(Flags, nKey, pCmd->GetID()));
			}
			child = child->GetNext();
		}
	}
}
コード例 #4
0
	bool Window::getKeyPressed(key::KeyType key) {
		if (key == key::Any) {
			if (anyKeyPressed_) {
				needToBeSetFalse_.push(&anyKeyPressed_);
				return getKeyDown(jngl::key::Any);
			}
		} else if(keyPressed_[GetKeyCode(key)]) {
			needToBeSetFalse_.push(&keyPressed_[GetKeyCode(key)]);
			return true;
		}
		return false;
	}
コード例 #5
0
/* virtual */
nsresult
nsDOMKeyboardEvent::Which(PRUint32* aWhich)
{
  NS_ENSURE_ARG_POINTER(aWhich);

  switch (mEvent->message) {
    case NS_KEY_UP:
    case NS_KEY_DOWN:
      return GetKeyCode(aWhich);
    case NS_KEY_PRESS:
      //Special case for 4xp bug 62878.  Try to make value of which
      //more closely mirror the values that 4.x gave for RETURN and BACKSPACE
      {
        PRUint32 keyCode = ((nsKeyEvent*)mEvent)->keyCode;
        if (keyCode == NS_VK_RETURN || keyCode == NS_VK_BACK) {
          *aWhich = keyCode;
          return NS_OK;
        }
        return GetCharCode(aWhich);
      }
      break;
    default:
      *aWhich = 0;
      break;
  }

  return NS_OK;
}
コード例 #6
0
void DKeyboardNE1_TB::EventDfc()
	{
	__KTRACE_OPT(KHARDWARE,Kern::Printf("DKeyboardNE1_TB::EventDfc"));

	TInt irq=NKern::DisableAllInterrupts();
	while (IsKeyReady())						// while there are keys in the controller's output buffer
		{
		NKern::RestoreInterrupts(irq);
		TRawEvent e;
		TUint keyCode=GetKeyCode();				// Read keycodes from controller
		__KTRACE_OPT(KHARDWARE,Kern::Printf("#%02x",keyCode));

		//
		// TO DO: (mandatory)
		//
		// Convert from hardware scancode to EPOC scancode and send the scancode as an event (key pressed or released)
		// as per below EXAMPLE ONLY:
		//
		TUint bareCode=keyCode&~KFlagKeyPressed;
		TUint8 stdKey=convertCode[bareCode];
		if (keyCode&KFlagKeyPressed)
			e.Set(TRawEvent::EKeyUp,stdKey,0);
		else
			e.Set(TRawEvent::EKeyDown,stdKey,0);
		Kern::AddEvent(e);
		NKern::Sleep(1);						// pause before reading more keycodes
		irq=NKern::DisableAllInterrupts();
		}
	Interrupt::Enable(iIrqHandle);
	NKern::RestoreInterrupts(irq);
	}
コード例 #7
0
ファイル: accelcmn.cpp プロジェクト: Annovae/Dolphin-Core
wxString wxAcceleratorEntry::ToString() const
{
    wxString text;

    int flags = GetFlags();
    if ( flags & wxACCEL_ALT )
        text += _("Alt+");
    if ( flags & wxACCEL_CTRL )
        text += _("Ctrl+");
    if ( flags & wxACCEL_SHIFT )
        text += _("Shift+");
#if defined(__WXMAC__) || defined(__WXCOCOA__)
    if ( flags & wxACCEL_RAW_CTRL )
        text += _("RawCtrl+");
#endif
    
    const int code = GetKeyCode();

    if ( code >= WXK_F1 && code <= WXK_F12 )
        text << _("F") << code - WXK_F1 + 1;
    else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 )
        text << _("KP_") << code - WXK_NUMPAD0;
    else if ( code >= WXK_SPECIAL1 && code <= WXK_SPECIAL20 )
        text << _("SPECIAL") << code - WXK_SPECIAL1 + 1;
    else // check the named keys
    {
        size_t n;
        for ( n = 0; n < WXSIZEOF(wxKeyNames); n++ )
        {
            const wxKeyName& kn = wxKeyNames[n];
            if ( code == kn.code )
            {
                text << wxGetTranslation(kn.name);
                break;
            }
        }

        if ( n == WXSIZEOF(wxKeyNames) )
        {
            // must be a simple key
            if (
#if !wxUSE_UNICODE
                 // we can't call wxIsalnum() for non-ASCII characters in ASCII
                 // build as they're only defined for the ASCII range (or EOF)
                 wxIsascii(code) &&
#endif // ANSI
                    wxIsprint(code) )
            {
                text << (wxChar)code;
            }
            else
            {
                wxFAIL_MSG( wxT("unknown keyboard accelerator code") );
            }
        }
    }

    return text;
}
コード例 #8
0
	bool CheckEvent(SDL_Event * event) {
		if (event->type!=SDL_KEYDOWN && event->type!=SDL_KEYUP) return false;
		Bitu key=GetKeyCode(event->key.keysym);
//		LOG_MSG("key type %i is %x [%x %x]",event->type,key,event->key.keysym.sym,event->key.keysym.scancode);
		assert(Bitu(event->key.keysym.sym)<keys);
		if (event->type==SDL_KEYDOWN) ActivateBindList(&lists[key],0x7fff);
		else DeactivateBindList(&lists[key]);
		return 0;
	}
コード例 #9
0
ファイル: mousekey.cpp プロジェクト: Sly14/upp-mirror
void Keyb_SendKeys(String text, long finalDelay, long delayBetweenKeys)
{
    Array <wchar> virt;
    bool inKey = false;
    String key = "";
    WString wtext(text);
    for (int i = 0; i < wtext.GetCount(); ++i) {
        bool vk = false;
        Sleep(delayBetweenKeys);
        wchar c = wtext[i];
        if (c == '{')
            inKey = true;
        else if (c == '}') {
            if (key == "{")
                c = '{';
            else {
                c = GetKeyCode(key);
                vk = true;
            }
            inKey = false;
            key = "";
        } else if (inKey == 1)
            key.Cat(c);
        else if (c == '\n') {
            c = GetKeyCode("RETURN");
            vk = true;
        }
        if (inKey == false) {
            if (!vk)
                PressKey(c);
#if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64)
            else {
                PressKeyVK(c, true);
                virt.Add(c);
            }
#endif
        }
    }
#if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64)
    for (int i = 0; i < virt.GetCount(); ++i)
        PressKeyVK(virt[i], false, true);
#endif
    Sleep(finalDelay);
}
コード例 #10
0
/* ReadKey(std::string key, std::string toggle)
*	Reads in a key from the key->pair.
*/
unsigned int Config::ReadKey(std::string key, std::string toggle, unsigned int &value) {
	//Check if configuration value exists.
	if (contents.find(key) == contents.end()) {
		contents[key].key = key;
		contents[key].value = toggle;
	}

	contents[key].pointer = &value;
	contents[key].type = CTKey;

	//Grab the proper key code and make s ure it's valid
	KeyCode ret = GetKeyCode(contents[key].value.c_str());
	if (ret.value == 0) {
		value = GetKeyCode(toggle.c_str()).value;
	}
	value = ret.value;

	return ret.value;
}
コード例 #11
0
ファイル: KeyModule.cpp プロジェクト: rhomobile/rhodes
void CKeyModule::setHomeKey(LPCWSTR pkey)
{
    int iTemp = GetKeyCode(pkey);
    if ((iTemp != INVALID_KEY)&&(iTemp != KEY_EMPTYSTRING))
    {
        setHomeKey(iTemp);
        RegisterFromOOPEngine();
    }
    else
        LOG(WARNING) + "Unrecognised Key Value " + pkey;
}
コード例 #12
0
ファイル: accelcmn.cpp プロジェクト: DumaGit/winsparkle
wxString wxAcceleratorEntry::ToString() const
{
    wxString text;

    int flags = GetFlags();
    if ( flags & wxACCEL_ALT )
        text += _("Alt-");
    if ( flags & wxACCEL_CTRL )
        text += _("Ctrl-");
    if ( flags & wxACCEL_SHIFT )
        text += _("Shift-");

    const int code = GetKeyCode();

    if ( code >= WXK_F1 && code <= WXK_F12 )
        text << _("F") << code - WXK_F1 + 1;
    else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 )
        text << _("KP_") << code - WXK_NUMPAD0;
    else if ( code >= WXK_SPECIAL1 && code <= WXK_SPECIAL20 )
        text << _("SPECIAL") << code - WXK_SPECIAL1 + 1;
    else // check the named keys
    {
        size_t n;
        for ( n = 0; n < WXSIZEOF(wxKeyNames); n++ )
        {
            const wxKeyName& kn = wxKeyNames[n];
            if ( code == kn.code )
            {
                text << wxGetTranslation(kn.name);
                break;
            }
        }

        if ( n == WXSIZEOF(wxKeyNames) )
        {
            // must be a simple key
            if (
#if !wxUSE_UNICODE
                 isascii(code) &&
#endif // ANSI
                    wxIsalnum(code) )
            {
                text << (wxChar)code;
            }
            else
            {
                wxFAIL_MSG( wxT("unknown keyboard accelerator code") );
            }
        }
    }

    return text;
}
コード例 #13
0
ファイル: movierecorder.cpp プロジェクト: Tank-D/Shards
void csMovieRecorder::SetupPlugin()
{
  if (initialized) return;

  if (!Engine) Engine = csQueryRegistry<iEngine> (object_reg);

  if (!G2D) G2D = csQueryRegistry<iGraphics2D> (object_reg);
  if (!G2D)
  {
    csPrintf ("No G2D!\n");
    return;
  }

  if (!VFS) VFS = csQueryRegistry<iVFS> (object_reg);
  if (!VFS)
  {
    csPrintf ("No VFS!\n");
    return;
  }

  config.AddConfig (object_reg, "/config/movierecorder.cfg");

  frameRate = config->GetFloat("MovieRecorder.Capture.FPS", 30.0);
  rtjQuality = config->GetFloat("MovieRecorder.Capture.RTJpegQuality", 1.0);
  recordWidth = config->GetInt("MovieRecorder.Capture.Width", 0);
  recordHeight = config->GetInt("MovieRecorder.Capture.Height", 0);
  useLZO = config->GetBool("MovieRecorder.Capture.UseLZO", true);
  useRTJpeg = config->GetBool("MovieRecorder.Capture.UseRTJpeg", false);
  useRGB = config->GetBool("MovieRecorder.Capture.UseRGB", false);
  throttle = config->GetBool("MovieRecorder.Capture.Throttle", true);

  GetKeyCode(config->GetStr("MovieRecorder.Keys.Record", "alt-r"), keyRecord);
  GetKeyCode(config->GetStr("MovieRecorder.Keys.Pause", "alt-p"), keyPause);

  captureFormat.SetMask (filenameFormat != "" ? filenameFormat.GetData () :
			 config->GetStr ("MovieRecorder.Capture.FilenameFormat",
					 "/tmp/crystal000.nuv"));

  initialized = true;
}
コード例 #14
0
	bool Window::getKeyDown(key::KeyType key) {
		if (key == key::Any) {
			for (auto it = keyDown_.begin(); it != keyDown_.end(); ++it) {
				if (it->second) {
					return true;
				}
			}
			for (auto it = characterDown_.begin(); it != characterDown_.end(); ++it) {
				if (it->second) {
					return true;
				}
			}
			return false;
		}
		return keyDown_[GetKeyCode(key)];
	}
コード例 #15
0
/* ReadToggle(std::string key, std::string toggle, bool state)
*	Reads in a toggle from the key->pair
*	Config Example:
*		Key: True, VK_A
*/
Toggle Config::ReadToggle(std::string key, std::string toggle, bool state, Toggle& value) {
	//Check if configuration value exists.
	Toggle ret;
	if (contents.find(key) == contents.end()) {
		contents[key].key = key;
		contents[key].value = ((state) ? "True, " : "False, ") + toggle;
	}

	contents[key].toggle = &value;
	contents[key].type = CTToggle;

	ret.toggle = GetKeyCode(Trim(contents[key].value.substr(contents[key].value.find_first_of(",") + 1)).c_str()).value;
	ret.state = StringToBool(Trim(contents[key].value.substr(0, contents[key].value.find_first_of(","))));

	value = ret;
	return ret;
}
コード例 #16
0
ファイル: KeyModule.cpp プロジェクト: rhomobile/rhodes
int CKeyModule::parseKeyValue(rho::String szKeyValue)
{
    int nKeyValue = INVALID_KEY;
    rho::String comparitor;
    comparitor.assign(szKeyValue);
    std::transform(comparitor.begin(), comparitor.end(), comparitor.begin(), ::tolower);

    if (comparitor.compare("all") == 0)
        nKeyValue = ALL_KEYS;
    else
    {
        nKeyValue = GetKeyCode(rho::common::convertToStringW(szKeyValue).c_str());
        if ((nKeyValue == INVALID_KEY)||(nKeyValue==KEY_EMPTYSTRING))
        {
            LOG(INFO) + "Unrecognised Key Code";
        }
    }
    return nKeyValue;
}
コード例 #17
0
ファイル: menucmn.cpp プロジェクト: czxxjtu/wxPython-1
wxString wxAcceleratorEntry::ToString() const
{
    wxString text;

    int flags = GetFlags();
    if ( flags & wxACCEL_ALT )
        text += _("Alt-");
    if ( flags & wxACCEL_CTRL )
        text += _("Ctrl-");
    if ( flags & wxACCEL_SHIFT )
        text += _("Shift-");

    const int code = GetKeyCode();

    if ( wxIsalnum(code) )
        text << (wxChar)code;
    else if ( code >= WXK_F1 && code <= WXK_F12 )
        text << _("F") << code - WXK_F1 + 1;
    else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 )
        text << _("KP_") << code - WXK_NUMPAD0;
    else if ( code >= WXK_SPECIAL1 && code <= WXK_SPECIAL20 )
        text << _("SPECIAL") << code - WXK_SPECIAL1 + 1;
    else // check the named keys
    {
        size_t n;
        for ( n = 0; n < WXSIZEOF(wxKeyNames); n++ )
        {
            const wxKeyName& kn = wxKeyNames[n];
            if ( code == kn.code )
            {
                text << wxGetTranslation(kn.name);
                break;
            }
        }

        wxASSERT_MSG( n != WXSIZEOF(wxKeyNames),
                      wxT("unknown keyboard accelerator code") );
    }

    return text;
}
コード例 #18
0
	CBind * CreateEventBind(SDL_Event * event) {
		if (event->type!=SDL_KEYDOWN) return 0;
		return CreateKeyBind((SDLKey)GetKeyCode(event->key.keysym));
	};
コード例 #19
0
int CKeyInputCtrl::GetKeyCode()
{
	return GetKeyCode(GetValue());
}
コード例 #20
0
	void Window::setKeyPressed(const key::KeyType key, bool p) {
		keyPressed_[GetKeyCode(key)] = p;
	}
コード例 #21
0
void
uGlobalMenuItem::SyncAccelFromContent()
{
  if (!mKeyContent) {
    dbusmenu_menuitem_property_remove(mDbusMenuItem,
                                      DBUSMENU_MENUITEM_PROP_SHORTCUT);
    return;
  }

  nsAutoString modStr;
  mKeyContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::modifiers, modStr);

  PRUint32 modifier = 0;

  if (!modStr.IsEmpty()) {
    char* str = ToNewUTF8String(modStr);
    char *token = strtok(str, ", \t");
    while(token) {
      if (strcmp(token, "shift") == 0) {
        modifier |= GDK_SHIFT_MASK;
      } else if (strcmp(token, "alt") == 0) {
        modifier |= GDK_MOD1_MASK;
      } else if (strcmp(token, "meta") == 0) {
        modifier |= GDK_META_MASK;
      } else if (strcmp(token, "control") == 0) {
        modifier |= GDK_CONTROL_MASK;
      } else if (strcmp(token, "accel") == 0) {
        nsIPrefBranch *prefs = uGlobalMenuService::GetPrefService();
        PRInt32 accel;
        prefs->GetIntPref("ui.key.accelKey", &accel);
        if (accel == nsIDOMKeyEvent::DOM_VK_META) {
          modifier |= GDK_META_MASK;
        } else if (accel == nsIDOMKeyEvent::DOM_VK_ALT) {
          modifier |= GDK_MOD1_MASK;
        } else {
          modifier |= GDK_CONTROL_MASK;
        }
      }

      token = strtok(nullptr, ", \t");
    }

    nsMemory::Free(str);
  }

  nsAutoString keyStr;
  guint key = 0;
  mKeyContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::key, keyStr);

  nsAutoCString cKeyStr;
  CopyUTF16toUTF8(keyStr, cKeyStr);

  if (!cKeyStr.IsEmpty()) {
    key = gdk_keyval_from_name(cKeyStr.get());
  }

  if (key == 0 && !keyStr.IsEmpty()) {
    key = gdk_unicode_to_keyval(*keyStr.BeginReading());
  }

  if (key == 0) {
    mKeyContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::keycode, keyStr);
    if (!keyStr.IsEmpty())
      key = MozKeyCodeToGdkKeyCode(GetKeyCode(keyStr));
  }

  if (key == 0) {
    key = GDK_VoidSymbol;
  }

  if (key != GDK_VoidSymbol) {
    dbusmenu_menuitem_property_set_shortcut(mDbusMenuItem, key,
                                       static_cast<GdkModifierType>(modifier));
  } else {
    dbusmenu_menuitem_property_remove(mDbusMenuItem,
                                      DBUSMENU_MENUITEM_PROP_SHORTCUT);
  }
}
コード例 #22
0
bool Config::HasChanged(ConfigEntry entry, string& value) {
	if (entry.type != CTToggle && entry.pointer == NULL)
		return false;

	switch (entry.type) {
	case CTBoolean: {
		bool currentBool = *((bool*)entry.pointer);
		bool storedBool = StringToBool(entry.value);

		if (storedBool == currentBool)
			return false;

		value = currentBool ? "True" : "False";
		return true;
	}
	case CTInt: {
		int currentInt = *((int*)entry.pointer);

		int storedInt = 0;
		std::stringstream stream;
		bool hex = false;
		if (entry.value.find("0x") != string::npos) {
			from_string<int>(storedInt, entry.value, std::hex);
			stream << std::hex;
			hex = true;
		}
		else {
			from_string<int>(storedInt, entry.value, std::dec);
		}

		if (currentInt == storedInt)
			return false;

		stream << currentInt;
		value = ((hex) ? "0x" : "") + stream.str();
		return true;
	}
	case CTString: {
		string currentString = *((string*)entry.pointer);

		if (currentString.compare(entry.value) == 0)
			return false;

		value = currentString;
		return true;
	}
	case CTArray: {
		vector<string> valTest = *((vector<string>*)entry.pointer);
		string ind = entry.key.substr(entry.key.find("[") + 1, entry.key.length() - entry.key.find("[") - 2);
		int index = atoi(ind.c_str());

		if (index >= valTest.size()) {
			value = "";
			return true;
		}

		string currentString = valTest.at(index);

		if (currentString.compare(entry.value) == 0)
			return false;

		value = currentString;
		return true;
	}

	case CTAssoc: {
		string assocKey = entry.key.substr(entry.key.find("[") + 1, entry.key.length() - entry.key.find("[") - 2);
		map<string, string> valTest = *((map<string, string>*)entry.pointer);

		string currentString = valTest[assocKey];

		if (currentString.compare(entry.value) == 0)
			return false;

		value = currentString;
		return true;
	}
	case CTAssocBool: {
		string assocKey = entry.key.substr(entry.key.find("[") + 1, entry.key.length() - entry.key.find("[") - 2);
		transform(assocKey.begin(), assocKey.end(), assocKey.begin(), ::tolower);
		map<string, bool> valTest = *((map<string, bool>*)entry.pointer);

		bool currentBool = valTest[assocKey];

		if (currentBool == StringToBool(entry.value))
			return false;

		value = currentBool ? "True" : "False";
		return true;
	}
	case CTAssocInt: {
		string assocKey = entry.key.substr(entry.key.find("[") + 1, entry.key.length() - entry.key.find("[") - 2);
		map<string, unsigned int> valTest = *((map<string, unsigned int>*)entry.pointer);
		int currentInt = valTest[assocKey];

		int storedInt = 0;
		std::stringstream stream;
		bool hex = false;
		if (entry.value.find("0x") != string::npos) {
			from_string<int>(storedInt, entry.value, std::hex);
			stream << std::hex;
			hex = true;
		}
		else {
			from_string<int>(storedInt, entry.value, std::dec);
		}

		if (currentInt == storedInt)
			return false;

		stream << currentInt;
		value = ((hex) ? "0x" : "") + stream.str();
		return true;
	}
	case CTToggle: {
		unsigned int toggle = GetKeyCode(Trim(entry.value.substr(entry.value.find_first_of(",") + 1)).c_str()).value;
		bool state = StringToBool(Trim(entry.value.substr(0, entry.value.find_first_of(","))));

		if (entry.toggle->toggle == toggle && entry.toggle->state == state)
			return false;

		stringstream stream;
		KeyCode newKey = GetKeyCode(entry.toggle->toggle);

		stream << ((entry.toggle->state) ? "True" : "False") << ", " << newKey.name;

		value = stream.str();
		return true;
	}
	case CTKey: {
		unsigned int currentKey = *((unsigned int*)entry.pointer);
		KeyCode code = GetKeyCode(entry.value.c_str());

		if (code.value == currentKey)
			return false;

		KeyCode newCode = GetKeyCode(currentKey);
		value = newCode.name;
		return true;
	}
	}
	return false;
}