summaryrefslogtreecommitdiffstats
path: root/win/winvnc/ControlPanel.cxx
blob: 59bb511aef8288a476a25ffea96c718163ce7d6a (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// ControlPanel.cxx: implementation of the ControlPanel class.
//
//////////////////////////////////////////////////////////////////////

#include "ControlPanel.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

using namespace winvnc;

bool ControlPanel::showDialog()
{
  return Dialog::showDialog(MAKEINTRESOURCE(IDD_CONTROL_PANEL), NULL);
}

void ControlPanel::initDialog()
{
  TCHAR *ColumnsStrings[] = {
    (TCHAR *) "IP address",
    (TCHAR *) "Time connected",
    (TCHAR *) "Status"
  };
  InitLVColumns(IDC_LIST_CONNECTIONS, handle, 120, 3, ColumnsStrings,
                LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
                LVS_EX_FULLROWSELECT, LVCFMT_LEFT);
  SendCommand(4, -1);
}

bool ControlPanel::onCommand(int cmd)
{
  switch (cmd) {
  case IDC_PROPERTIES:
    SendMessage(m_hSTIcon, WM_COMMAND, ID_OPTIONS, 0);
    return false;
  case IDC_ADD_CLIENT:
    SendMessage(m_hSTIcon, WM_COMMAND, ID_CONNECT, 0);
    return false;
  case IDC_KILL_ALL:
    {
      SendCommand(2, -1);
      return false;
    }
  case IDC_KILL_SEL_CLIENT:
    {     
      SendCommand(3, 3);
      return false;
    }
  case IDC_VIEW_ONLY:
    {     
      SendCommand(3, 1);
      return false;
    }
  case IDC_FULL_CONTROL:
    {     
      SendCommand(3, 0);
      return false;
    }
  case IDC_STOP_UPDATE:
    {     
      stop_updating = true;
      EndDialog(handle, 0);
      return false;
    }
  case IDC_DISABLE_CLIENTS:
    {   
      ListConnStatus.setDisable(isItemChecked(IDC_DISABLE_CLIENTS));
      SendCommand(3, -1);
      return false;
    }
  }
  return false;
  
}

void ControlPanel::UpdateListView(rfb::ListConnInfo* LCInfo)
{
  getSelConnInfo();
  DeleteAllLVItem(IDC_LIST_CONNECTIONS, handle);
  setItemChecked(IDC_DISABLE_CLIENTS, LCInfo->getDisable());

  if(LCInfo->Empty()) 
    return;

  ListConn.Copy(LCInfo);

  char* ItemString[3];
  int i = 0;

  for (ListConn.iBegin(); !ListConn.iEnd(); ListConn.iNext()) {
    ListConn.iGetCharInfo(ItemString);
    InsertLVItem(IDC_LIST_CONNECTIONS, handle, i, (TCHAR **) ItemString, 3);
    for (ListSelConn.iBegin(); !ListSelConn.iEnd(); ListSelConn.iNext()) {
      if (ListSelConn.iGetConn() == ListConn.iGetConn())
        SelectLVItem(IDC_LIST_CONNECTIONS, handle, i);
    }
    i++;
  } 
}

BOOL ControlPanel::dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch (msg) {
  case WM_INITDIALOG:
    handle = hwnd;
    initDialog();
    return TRUE;
  case WM_DESTROY:
    if (stop_updating) {
      stop_updating = false;
      SendCommand(3, 2);
    }
    return TRUE;
  case WM_COMMAND:
    switch (LOWORD(wParam)) {
    case IDCANCEL:
      handle = NULL;
      EndDialog(hwnd, 0);
      return TRUE;
    default:
      return onCommand(LOWORD(wParam));
    }
  }
  return FALSE;
}

void ControlPanel::getSelConnInfo()
{
  int i = 0;
  ListSelConn.Clear();
  if(ListConn.Empty()) return;
  for (ListConn.iBegin(); !ListConn.iEnd(); ListConn.iNext()) {
    if (IsSelectedLVItem(IDC_LIST_CONNECTIONS, handle, i))
      ListSelConn.iAdd(&ListConn);
    i++;
  }
}

void ControlPanel::SendCommand(DWORD command, int data)
{
  COPYDATASTRUCT copyData;
  copyData.dwData = command;
  copyData.lpData = 0;
  getSelConnInfo();
  if (data != -1) {
    ListConnStatus.Copy(&ListSelConn);
    ListConnStatus.setAllStatus(data);
    ListConnStatus.setDisable(isItemChecked(IDC_DISABLE_CLIENTS));
    copyData.cbData = (DWORD)&ListConnStatus;
  } else {
    ListConnStatus.Clear();
  }
  copyData.cbData = (DWORD)&ListConnStatus;
  SendMessage(m_hSTIcon, WM_COPYDATA, 0, (LPARAM)&copyData);
}

ControlPanel::~ControlPanel()
{
  
}