summaryrefslogtreecommitdiff
path: root/indra/newview/llsetkeybinddialog.h
blob: 16a2d768e4a797617346eafa3849ae626e9121f6 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
89
90
91
92
93
94
95
96
97
/** 
 * @file llsetkeybinddialog.h
 * @brief LLSetKeyBindDialog class definition
 *
 * $LicenseInfo:firstyear=2019&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2019, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */


#ifndef LL_LLSETKEYBINDDIALOG_H
#define LL_LLSETKEYBINDDIALOG_H

#include "llmodaldialog.h"
#include "lldrawfrustum.h"

class LLCheckBoxCtrl;
class LLTextBase;

// Filters for LLSetKeyBindDialog
static const U32 ALLOW_MOUSE = 1;
static const U32 ALLOW_MASK_MOUSE = 2;
static const U32 ALLOW_KEYS = 4; //keyboard
static const U32 ALLOW_MASK_KEYS = 8;
static const U32 ALLOW_MASKS = 16;
static const U32 CAN_IGNORE_MASKS = 32; // For example W (aka Forward) should work regardless of SHIFT being pressed
static const U32 DEFAULT_KEY_FILTER = ALLOW_MOUSE | ALLOW_MASK_MOUSE | ALLOW_KEYS | ALLOW_MASK_KEYS;


class LLKeyBindResponderInterface
{
public:
    virtual ~LLKeyBindResponderInterface() {};

    virtual void onCancelKeyBind() = 0;
    virtual void onDefaultKeyBind() = 0;
    // returns true if parent failed to set key due to key being in use
    virtual bool onSetKeyBind(EMouseClickType click, KEY key, MASK mask, bool ignore) = 0;
};

class LLSetKeyBindDialog : public LLModalDialog, public LLDrawFrustum
{
public:
    LLSetKeyBindDialog(const LLSD& key);
    ~LLSetKeyBindDialog();

    /*virtual*/ BOOL postBuild();
    /*virtual*/ void onOpen(const LLSD& data);
    /*virtual*/ void onClose(bool app_quiting);
    /*virtual*/ void draw();

    void setParent(LLKeyBindResponderInterface* parent, LLView* frustum_origin, U32 key_mask = DEFAULT_KEY_FILTER);

    // Wrapper around recordAndHandleKey
    // It does not record, it handles, but handleKey function is already in use
    static bool recordKey(KEY key, MASK mask);

    BOOL handleAnyMouseClick(S32 x, S32 y, MASK mask, EMouseClickType clicktype, BOOL down);
    static void onCancel(void* user_data);
    static void onBlank(void* user_data);
    static void onDefault(void* user_data);
    static void onClickTimeout(void* user_data, MASK mask);

    class Updater;

private:
    bool recordAndHandleKey(KEY key, MASK mask);
    void setKeyBind(EMouseClickType click, KEY key, MASK mask, bool ignore);
    LLKeyBindResponderInterface *pParent;
    LLCheckBoxCtrl *pCheckBox;
    LLTextBase *pDesription;

    U32 mKeyFilterMask;
    Updater *pUpdater;

    static bool sRecordKeys; // for convinience and not to check instance each time
};


#endif  // LL_LLSETKEYBINDDIALOG_H