hotkeys.cpp File Reference

Implementation of hotkey related functions. More...

#include "stdafx.h"
#include "openttd.h"
#include "hotkeys.h"
#include "ini_type.h"
#include "string_func.h"
#include "window_gui.h"

Go to the source code of this file.

Data Structures

struct  KeycodeNames
 String representation of a keycode. More...

Defines

#define SL_HOTKEYS(name, window_name)

Typedefs

typedef EventState GlobalHotkeyHandler (uint16, uint16)

Functions

static uint16 ParseCode (const char *start, const char *end)
 Try to parse a single part of a keycode.
static uint16 ParseKeycode (const char *start, const char *end)
 Parse a string representation of a keycode.
template<class T >
static void ParseHotkeys (Hotkey< T > *hotkey, const char *value)
 Parse a string to the keycodes it represents.
static const char * KeycodeToString (uint16 keycode)
 Convert a hotkey to it's string representation so it can be written to the config file.
template<class T >
const char * SaveKeycodes (const Hotkey< T > *hotkey)
 Convert all keycodes attached to a hotkey to a single string.
template<class T >
void LoadHotkeyGroup (IniGroup *group, T *hotkey_list)
template<class T >
void SaveHotkeyGroup (IniGroup *group, T *hotkey_list)
template<class T >
void SaveLoadHotkeyGroup (IniGroup *group, T *hotkey_list, bool save)
static void SaveLoadHotkeys (bool save)
void LoadHotkeysFromConfig ()
 Load the hotkeys from the config file.
void SaveHotkeysToConfig ()
 Save the hotkeys to the config file.
void HandleGlobalHotkeys (uint16 key, uint16 keycode)

Variables

char * _hotkeys_file
static const KeycodeNames _keycode_to_name []
 Array of non-standard keycodes that can be used in the hotkeys config file.
GlobalHotkeyHandler RailToolbarGlobalHotkeys
GlobalHotkeyHandler DockToolbarGlobalHotkeys
GlobalHotkeyHandler AirportToolbarGlobalHotkeys
GlobalHotkeyHandler TerraformToolbarGlobalHotkeys
GlobalHotkeyHandler TerraformToolbarEditorGlobalHotkeys
GlobalHotkeyHandler RoadToolbarGlobalHotkeys
GlobalHotkeyHandler RoadToolbarEditorGlobalHotkeys
GlobalHotkeyHandler SignListGlobalHotkeys
GlobalHotkeyHandler * _global_hotkey_handlers []
GlobalHotkeyHandler * _global_hotkey_handlers_editor []

Detailed Description

Implementation of hotkey related functions.

Definition in file hotkeys.cpp.


Define Documentation

#define SL_HOTKEYS ( name,
window_name   ) 
Value:
extern Hotkey<window_name> *_##name##_hotkeys;\
  group = ini->GetGroup(#name);\
  SaveLoadHotkeyGroup(group, _##name##_hotkeys, save);

Function Documentation

static const char* KeycodeToString ( uint16  keycode  )  [static]

Convert a hotkey to it's string representation so it can be written to the config file.

Seperate parts of the keycode (like "CTRL" and "F1" are split by a '+'.

Parameters:
keycode The keycode to convert to a string.
Returns:
A string representation of this keycode.
Note:
The return value is a static buffer, strdup the result before calling this function again.

Definition at line 141 of file hotkeys.cpp.

References lastof, lengthof, strecat(), and WKC_GLOBAL_HOTKEY.

Referenced by SaveKeycodes().

static uint16 ParseCode ( const char *  start,
const char *  end 
) [static]

Try to parse a single part of a keycode.

Parameters:
start Start of the string to parse.
end End of the string to parse.
Returns:
A keycode if a match is found or 0.

Definition at line 65 of file hotkeys.cpp.

References KeycodeNames::keycode, and lengthof.

Referenced by ParseKeycode().

template<class T >
static void ParseHotkeys ( Hotkey< T > *  hotkey,
const char *  value 
) [inline, static]

Parse a string to the keycodes it represents.

Parameters:
hotkey The hotkey object to add the keycodes to
value The string to parse

Definition at line 120 of file hotkeys.cpp.

References Hotkey< T >::AddKeycode(), and ParseKeycode().

static uint16 ParseKeycode ( const char *  start,
const char *  end 
) [static]

Parse a string representation of a keycode.

Parameters:
start Start of the input.
end End of the input.
Returns:
A valid keycode or 0.

Definition at line 89 of file hotkeys.cpp.

References ParseCode().

Referenced by ParseHotkeys().

template<class T >
const char* SaveKeycodes ( const Hotkey< T > *  hotkey  )  [inline]

Convert all keycodes attached to a hotkey to a single string.

If multiple keycodes are attached to the hotkey they are split by a comma.

Parameters:
hotkey The keycodes of this hotkey need to be converted to a string.
Returns:
A string representation of all keycodes.
Note:
The return value is a static buffer, strdup the result before calling this function again.

Definition at line 196 of file hotkeys.cpp.

References KeycodeToString(), lastof, SmallVector< T, S >::Length(), and strecat().


Variable Documentation

GlobalHotkeyHandler* _global_hotkey_handlers[]
Initial value:
 {
  RailToolbarGlobalHotkeys,
  DockToolbarGlobalHotkeys,
  AirportToolbarGlobalHotkeys,
  TerraformToolbarGlobalHotkeys,
  RoadToolbarGlobalHotkeys,
  SignListGlobalHotkeys,
}

Definition at line 308 of file hotkeys.cpp.

GlobalHotkeyHandler* _global_hotkey_handlers_editor[]
Initial value:
 {
  TerraformToolbarEditorGlobalHotkeys,
  RoadToolbarEditorGlobalHotkeys,
}

Definition at line 317 of file hotkeys.cpp.

const KeycodeNames _keycode_to_name[] [static]
Initial value:
 {
  {"SHIFT", WKC_SHIFT},
  {"CTRL", WKC_CTRL},
  {"ALT", WKC_ALT},
  {"META", WKC_META},
  {"GLOBAL", WKC_GLOBAL_HOTKEY},
  {"ESC", WKC_ESC},
  {"DEL", WKC_DELETE},
  {"RETURN", WKC_RETURN},
  {"BACKQUOTE", WKC_BACKQUOTE},
  {"F1", WKC_F1},
  {"F2", WKC_F2},
  {"F3", WKC_F3},
  {"F4", WKC_F4},
  {"F5", WKC_F5},
  {"F6", WKC_F6},
  {"F7", WKC_F7},
  {"F8", WKC_F8},
  {"F9", WKC_F9},
  {"F10", WKC_F10},
  {"F11", WKC_F11},
  {"F12", WKC_F12},
  {"PAUSE", WKC_PAUSE},
  {"PLUS", (WindowKeyCodes)'+'},
  {"COMMA", (WindowKeyCodes)','},
  {"NUM_PLUS", WKC_NUM_PLUS},
  {"NUM_MINUS", WKC_NUM_MINUS},
  {"=", WKC_EQUALS},
  {"-", WKC_MINUS},
}

Array of non-standard keycodes that can be used in the hotkeys config file.

Definition at line 28 of file hotkeys.cpp.


Generated on Fri May 27 04:19:55 2011 for OpenTTD by  doxygen 1.6.1