summaryrefslogtreecommitdiffstats
path: root/rfbplayer/ToolBar.cxx
blob: c4808cc14289c0fe8581547666ef795baad8cb2b (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* Copyright (C) 2004 TightVNC Team.  All Rights Reserved.
 *    
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

// -=- ToolBar control class.

#include "ToolBar.h"

ToolBar::ToolBar() : hwndToolBar(0), tbID(-1) {
  INITCOMMONCONTROLSEX icex;

  // Ensure that the common control DLL is loaded
  icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  icex.dwICC  = ICC_BAR_CLASSES;
  InitCommonControlsEx(&icex);
}

ToolBar::~ToolBar() {
  DestroyWindow(getHandle());
}

bool ToolBar::create(int _tbID, HWND parentHwnd, DWORD dwStyle) {
  dwStyle |= WS_CHILD;

  // Create the ToolBar window
  hwndToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, 0, dwStyle, 
    0, 0, 25, 25, parentHwnd, (HMENU)_tbID, GetModuleHandle(0), 0);

  if (hwndToolBar) {
    tbID = _tbID;

    // It's required for backward compatibility
    SendMessage(hwndToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
  }
  return (hwndToolBar ? true : false);
};

int ToolBar::addBitmap(int nButtons, UINT bitmapID) {
  assert(nButtons > 0);
  TBADDBITMAP resBitmap;
  resBitmap.hInst = GetModuleHandle(0);
  resBitmap.nID = bitmapID;
  return SendMessage(getHandle(), TB_ADDBITMAP, nButtons, (LPARAM)&resBitmap);
}

int ToolBar::addSystemBitmap(UINT stdBitmapID) {
  TBADDBITMAP resBitmap;
  resBitmap.hInst = HINST_COMMCTRL;
  resBitmap.nID = stdBitmapID;
  return SendMessage(getHandle(), TB_ADDBITMAP, 0, (LPARAM)&resBitmap);
}

bool ToolBar::setBitmapSize(int width, int height) {
  int result = SendMessage(getHandle(), TB_SETBITMAPSIZE, 
    0, MAKELONG(width, height));
  return (result ? true : false);
}

bool ToolBar::addButton(int iBitmap, int idCommand, BYTE state, BYTE style, UINT dwData, int iString) {
  TBBUTTON tbb;
  tbb.iBitmap = iBitmap;
  tbb.idCommand = idCommand;
  tbb.fsState = state;
  tbb.fsStyle = style;
  tbb.dwData = dwData;
  tbb.iString = iString;

  int result = SendMessage(getHandle(), TB_ADDBUTTONS, 1, (LPARAM)&tbb);
  if (result) {
    SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
  }
  return (result ? true : false);
}

bool ToolBar::addNButton(int nButtons, LPTBBUTTON tbb) {
  assert(nButtons > 0);
  assert(tbb > 0);
  int result = SendMessage(getHandle(), TB_ADDBUTTONS, nButtons, (LPARAM)tbb);
  if (result) {
    SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
  }
  return (result ? true : false);
}

bool ToolBar::deleteButton(int indexButton) {
  assert(indexButton >= 0);
  int result = SendMessage(getHandle(), TB_DELETEBUTTON, indexButton, 0);
  
  if (result) {
    SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
  }
  return (result ? true : false);
}

bool ToolBar::insertButton(int indexButton, LPTBBUTTON tbb) {
  assert(indexButton >= 0);
  assert(tbb > 0);
  int result = SendMessage(getHandle(), TB_INSERTBUTTON, 
    indexButton, (LPARAM)tbb);

  if (result) {
    SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
  }
  return (result ? true : false);
}

int ToolBar::getButtonInfo(int idButton, TBBUTTONINFO *btnInfo) {
  assert(idButton >= 0);
  assert(btnInfo > 0);
  return SendMessage(getHandle(), TB_GETBUTTONINFO, idButton, (LPARAM)btnInfo);
}

bool ToolBar::setButtonInfo(int idButton, TBBUTTONINFO* btnInfo) {
  assert(idButton >= 0);
  assert(btnInfo > 0);
  int result = SendMessage(getHandle(), TB_SETBUTTONINFO, 
    idButton, (LPARAM)(LPTBBUTTONINFO)btnInfo);
  return (result ? true : false);
}

bool ToolBar::checkButton(int idButton, bool check) {
  assert(idButton >= 0);
  int result = SendMessage(getHandle(), TB_CHECKBUTTON, 
    idButton, MAKELONG(check, 0));
  return (result ? true : false);
}

bool ToolBar::enableButton(int idButton, bool enable) {
  assert(idButton >= 0);
  int result = SendMessage(getHandle(), TB_ENABLEBUTTON, 
    idButton, MAKELONG(enable, 0));
  return (result ? true : false);
}

bool ToolBar::pressButton(int idButton, bool press) {
  assert(idButton >= 0);
  int result = SendMessage(getHandle(), TB_PRESSBUTTON, 
    idButton, MAKELONG(press, 0));
  return (result ? true : false);
}

bool ToolBar::getButtonRect(int nIndex, LPRECT buttonRect) {
  int result = SendMessage(getHandle(), TB_GETITEMRECT, 
    nIndex, (LPARAM)buttonRect);
  return (result ? true : false);
}

bool ToolBar::setButtonSize(int width, int height) {
  assert(width > 0);
  assert(height > 0);
  int result = SendMessage(getHandle(), TB_SETBUTTONSIZE, 
    0, MAKELONG(width, height));
  if (result) {
    SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
    return true;
  }
  return false; 
}

void ToolBar::autoSize() {
  SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
}