~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Windows/InputBox.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Common/CommonWindows.h"
 
2
#include "Windows/InputBox.h"
 
3
#include "Windows/resource.h"
 
4
#include "util/text/utf8.h"
 
5
 
 
6
static std::wstring textBoxContents;
 
7
static std::wstring out;
 
8
static std::wstring windowTitle;
 
9
static bool defaultSelected;
 
10
 
 
11
static INT_PTR CALLBACK InputBoxFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 
12
{
 
13
        switch (message) {
 
14
        case WM_INITDIALOG:
 
15
                SetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), textBoxContents.c_str());
 
16
                SetWindowText(hDlg, windowTitle.c_str());
 
17
                if (defaultSelected == false) PostMessage(GetDlgItem(hDlg,IDC_INPUTBOX),EM_SETSEL,-1,-1);
 
18
                return TRUE;
 
19
        case WM_COMMAND:
 
20
                switch (wParam)
 
21
                {
 
22
                case IDOK:
 
23
                        {
 
24
                                wchar_t temp[256];
 
25
                                GetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), temp, 255);
 
26
                                out = temp;
 
27
                        }
 
28
                        EndDialog(hDlg, IDOK);
 
29
                        return TRUE;
 
30
                case IDCANCEL:
 
31
                        EndDialog(hDlg, IDCANCEL);
 
32
                        return TRUE;
 
33
                }
 
34
        default:
 
35
                return FALSE;
 
36
        }
 
37
}
 
38
 
 
39
template <bool hex> 
 
40
void InputBoxFunc()
 
41
{
 
42
 
 
43
}
 
44
 
 
45
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::string &defaultValue, std::string &outvalue, bool selected)
 
46
{
 
47
        defaultSelected = selected;
 
48
        if (defaultValue.size() < 255)
 
49
                textBoxContents = ConvertUTF8ToWString(defaultValue);
 
50
        else
 
51
                textBoxContents = L"";
 
52
 
 
53
        if (title != NULL)
 
54
                windowTitle = title;
 
55
        else
 
56
                windowTitle = L"";
 
57
 
 
58
        if (IDOK == DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc)) {
 
59
                outvalue = ConvertWStringToUTF8(out);
 
60
                return true;
 
61
        }
 
62
        else 
 
63
                return false;
 
64
}
 
65
 
 
66
bool InputBox_GetString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::string &defaultValue, std::string &outvalue)
 
67
{
 
68
        const wchar_t *defaultTitle = L"Input value";
 
69
        defaultSelected = true;
 
70
 
 
71
        textBoxContents = ConvertUTF8ToWString(defaultValue);
 
72
 
 
73
        if (title && wcslen(title) <= 0)
 
74
                windowTitle = defaultTitle;
 
75
        else if (title && wcslen(title) < 255)
 
76
                windowTitle = title;
 
77
        else
 
78
                windowTitle = defaultTitle;
 
79
 
 
80
        if (IDOK == DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc)) {
 
81
                outvalue = ConvertWStringToUTF8(out);
 
82
                return true;
 
83
        }
 
84
        else 
 
85
                return false;
 
86
}
 
87
 
 
88
bool InputBox_GetWString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::wstring &defaultValue, std::wstring &outvalue)
 
89
{
 
90
        const wchar_t *defaultTitle = L"Input value";
 
91
        defaultSelected = true;
 
92
 
 
93
        textBoxContents = defaultValue;
 
94
 
 
95
        if (title && wcslen(title) <= 0)
 
96
                windowTitle = defaultTitle;
 
97
        else if (title && wcslen(title) < 255)
 
98
                windowTitle = title;
 
99
        else
 
100
                windowTitle = defaultTitle;
 
101
 
 
102
        if (IDOK == DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc)) {
 
103
                outvalue = out;
 
104
                return true;
 
105
        }
 
106
        else 
 
107
                return false;
 
108
}
 
109
 
 
110
bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, const wchar_t *title, u32 defaultvalue, u32 &outvalue)
 
111
{
 
112
        wchar_t temp[256];
 
113
        wsprintf(temp,L"%08x",defaultvalue);
 
114
        textBoxContents = temp;
 
115
 
 
116
        INT_PTR value = DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc);
 
117
 
 
118
        if (value == IDOK)
 
119
        {
 
120
                if (swscanf(out.c_str(), L"0x%08x", &outvalue) == 1)
 
121
                        return true;
 
122
                if (swscanf(out.c_str(), L"%08x", &outvalue) == 1)
 
123
                        return true;
 
124
                return false;
 
125
        }
 
126
        else 
 
127
        {
 
128
                outvalue = 0;
 
129
                return false;
 
130
        }
 
131
}
 
 
b'\\ No newline at end of file'