summaryrefslogtreecommitdiff
path: root/plugins/AsSingleWindow/src/Options.cpp
blob: 546c20245a3e309e178bde9abe357b13df2625e9 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "stdafx.h"
#include "AsSingleWindow.h"
#include "Options.h"
#include "resource.h"

int InitOptions(WPARAM wParam, LPARAM)
{
	OPTIONSDIALOGPAGE Opts = { 0 };

    Opts.szTitle.a = LPGEN("AsSingleWindow");
    Opts.szGroup.a = LPGEN("Customize");

    Opts.pfnDlgProc = cbOptionsDialog;
    Opts.pszTemplate = MAKEINTRESOURCEA(IDD_ASW_OPTIONSPAGE);
    Opts.hInstance = pluginVars.hInst;
    Opts.flags = ODPF_BOLDGROUPS;

	Options_AddPage(wParam, &Opts);

    return 0;
}

INT_PTR CALLBACK cbOptionsDialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
        case WM_INITDIALOG:
            dlgProcessInit(hWnd, msg, wParam, lParam);
            break;
        case WM_COMMAND:
            dlgProcessCommand(hWnd, msg, wParam, lParam);
            break;
        case WM_NOTIFY:
            if (((LPNMHDR)lParam)->idFrom == 0) {
                switch (((LPNMHDR)lParam)->code) {
                    case PSN_RESET:
                        optionsLoad();
                        break;
                    case PSN_APPLY:
                        optionsUpdate(hWnd);
                        optionsSave();
                        windowReposition(hWnd); // Èíèöèèðóåì ïåðåðàñ÷åò êîîðäèíàò
                        break;
                }
            }
            break;
        case WM_DESTROY:
            // free up resources
            break;
    }

    return false;
}

void dlgProcessInit(HWND hWnd, UINT, WPARAM, LPARAM)
{
    TranslateDialogDefault(hWnd);

    CheckDlgButton(hWnd, IDC_RADIO_G1_RIGHTCL, (pluginVars.Options.DrivenWindowPos == ASW_CLWINDOWPOS_RIGHT));
    CheckDlgButton(hWnd, IDC_RADIO_G1_LEFTCL, (pluginVars.Options.DrivenWindowPos == ASW_CLWINDOWPOS_LEFT));
    CheckDlgButton(hWnd, IDC_RADIO_G1_DONTMERGEWINDOWS, (pluginVars.Options.DrivenWindowPos == ASW_CLWINDOWPOS_DISABLED));

    CheckDlgButton(hWnd, IDC_RADIO_G2_MERGEALL, (pluginVars.Options.WindowsMerging == ASW_WINDOWS_MERGEALL));
    CheckDlgButton(hWnd, IDC_RADIO_G2_MERGEONE, (pluginVars.Options.WindowsMerging == ASW_WINDOWS_MERGEONE));
    CheckDlgButton(hWnd, IDC_RADIO_G2_DISABLEMERGE, (pluginVars.Options.WindowsMerging == ASW_WINDOWS_MERGEDISABLE));

    dlgUpdateControls(hWnd);
}

void dlgProcessCommand(HWND hWnd, UINT, WPARAM wParam, LPARAM)
{
    WORD idCtrl = LOWORD(wParam);
    WORD idNotifyCode = HIWORD(wParam);

    switch (idCtrl)
    {
        case IDC_RADIO_G1_LEFTCL:
        case IDC_RADIO_G1_RIGHTCL:
        case IDC_RADIO_G1_DONTMERGEWINDOWS:
            if (idNotifyCode == BN_CLICKED)
            {
                dlgUpdateControls(hWnd);
                SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
            }
            break;
        case IDC_RADIO_G2_MERGEALL:
        case IDC_RADIO_G2_MERGEONE:
        case IDC_RADIO_G2_DISABLEMERGE:
            if (idNotifyCode == BN_CLICKED)
                SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
            break;
    }
}

void dlgUpdateControls(HWND hWnd)
{
    UINT idState;

    idState = IsDlgButtonChecked(hWnd, IDC_RADIO_G1_DONTMERGEWINDOWS);
    EnableWindow(GetDlgItem(hWnd, IDC_RADIO_G2_MERGEALL), ! idState);
    EnableWindow(GetDlgItem(hWnd, IDC_RADIO_G2_MERGEONE), ! idState);
    EnableWindow(GetDlgItem(hWnd, IDC_RADIO_G2_DISABLEMERGE), ! idState);
}

void optionsLoad()
{
	pluginVars.Options.DrivenWindowPos = db_get_b(0, SETTINGSNAME, "DrivenWindowPosition", ASW_CLWINDOWPOS_RIGHT);
	pluginVars.Options.WindowsMerging = db_get_b(0, SETTINGSNAME, "WindowsMerging", ASW_WINDOWS_MERGEONE);
}

void optionsUpdate(HWND hWnd)
{
    pluginVars.Options.DrivenWindowPos =
        (IsDlgButtonChecked(hWnd, IDC_RADIO_G1_LEFTCL) * ASW_CLWINDOWPOS_LEFT) +
        (IsDlgButtonChecked(hWnd, IDC_RADIO_G1_RIGHTCL) * ASW_CLWINDOWPOS_RIGHT) +
        (IsDlgButtonChecked(hWnd, IDC_RADIO_G1_DONTMERGEWINDOWS) * ASW_CLWINDOWPOS_DISABLED);

    pluginVars.Options.WindowsMerging =
        (IsDlgButtonChecked(hWnd, IDC_RADIO_G2_MERGEALL) * ASW_WINDOWS_MERGEALL) +
        (IsDlgButtonChecked(hWnd, IDC_RADIO_G2_MERGEONE) * ASW_WINDOWS_MERGEONE) +
        (IsDlgButtonChecked(hWnd, IDC_RADIO_G2_DISABLEMERGE) * ASW_WINDOWS_MERGEDISABLE);
}

void optionsSave()
{
	db_get_b(0, SETTINGSNAME, "DrivenWindowPosition", pluginVars.Options.DrivenWindowPos);
	db_get_b(0, SETTINGSNAME, "WindowsMerging", pluginVars.Options.WindowsMerging);
}

// end of file