]> git.saurik.com Git - wxWidgets.git/blame - src/msw/tabctrl.cpp
Removed redundant cursor files
[wxWidgets.git] / src / msw / tabctrl.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: tabctrl.cpp
3// Purpose: wxTabCtrl
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
2bda0e17
KB
13#pragma implementation "tabctrl.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
2432b92d 24#include "wx/wx.h"
2bda0e17
KB
25#endif
26
27#if defined(__WIN95__)
28
4676948b 29#include "wx/msw/private.h"
2bda0e17 30
2cef71bc 31#include <commctrl.h>
2bda0e17 32
186ef90c 33#include "wx/tabctrl.h"
2bda0e17 34#include "wx/app.h"
2bda0e17
KB
35#include "wx/msw/imaglist.h"
36
2bda0e17 37IMPLEMENT_DYNAMIC_CLASS(wxTabCtrl, wxControl)
2b5f62a0 38IMPLEMENT_DYNAMIC_CLASS(wxTabEvent, wxNotifyEvent)
2bda0e17 39
2e4df4bf
VZ
40DEFINE_EVENT_TYPE(wxEVT_COMMAND_TAB_SEL_CHANGED)
41DEFINE_EVENT_TYPE(wxEVT_COMMAND_TAB_SEL_CHANGING)
42
2bda0e17 43BEGIN_EVENT_TABLE(wxTabCtrl, wxControl)
2bda0e17
KB
44 EVT_SYS_COLOUR_CHANGED(wxTabCtrl::OnSysColourChanged)
45END_EVENT_TABLE()
2bda0e17 46
ee4f8c2a 47wxTabCtrl::wxTabCtrl()
2bda0e17
KB
48{
49 m_imageList = NULL;
50}
51
ee4f8c2a
JS
52bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
53 long style, const wxString& name)
2bda0e17
KB
54{
55 m_imageList = NULL;
56
57 m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
42e69d6b 58 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
2bda0e17
KB
59 m_foregroundColour = *wxBLACK ;
60
2bda0e17
KB
61 SetName(name);
62
63 int x = pos.x;
64 int y = pos.y;
65 int width = size.x;
66 int height = size.y;
67
68 m_windowStyle = style;
69
2bda0e17
KB
70 SetParent(parent);
71
2bda0e17
KB
72 if (width <= 0)
73 width = 100;
74 if (height <= 0)
75 height = 30;
76 if (x < 0)
77 x = 0;
78 if (y < 0)
79 y = 0;
80
81 m_windowId = (id < 0 ? NewControlId() : id);
82
96df9ed9 83 long tabStyle = WS_CHILD | WS_VISIBLE;
2bda0e17
KB
84 if (m_windowStyle & wxTC_MULTILINE)
85 tabStyle |= TCS_MULTILINE;
86 if (m_windowStyle & wxTC_RIGHTJUSTIFY)
87 tabStyle |= TCS_RIGHTJUSTIFY;
88 if (m_windowStyle & wxTC_FIXEDWIDTH)
89 tabStyle |= TCS_FIXEDWIDTH;
90 if (m_windowStyle & wxTC_OWNERDRAW)
91 tabStyle |= TCS_OWNERDRAWFIXED;
2b5f62a0
VZ
92 if (m_windowStyle & wxBORDER)
93 tabStyle |= WS_BORDER;
2bda0e17 94
4676948b 95#ifndef __WXWINCE__
2bda0e17 96 tabStyle |= TCS_TOOLTIPS;
4676948b 97#endif
2bda0e17
KB
98
99 // Create the toolbar control.
100 HWND hWndTabCtrl = CreateWindowEx(0L, // No extended styles.
101 WC_TABCONTROL, // Class name for the tab control
fda7962d 102 wxEmptyString, // No default text.
2b5f62a0 103 tabStyle, // Styles and defaults.
2bda0e17
KB
104 x, y, width, height, // Standard size and position.
105 (HWND) parent->GetHWND(), // Parent window
106 (HMENU)m_windowId, // ID.
107 wxGetInstance(), // Current instance.
108 NULL ); // No class data.
109
110 m_hWnd = (WXHWND) hWndTabCtrl;
111 if (parent) parent->AddChild(this);
bfbb0b4c 112
2bda0e17
KB
113 SubclassWin((WXHWND) hWndTabCtrl);
114
2b5f62a0
VZ
115 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
116
bfbb0b4c 117 return true;
2bda0e17
KB
118}
119
ee4f8c2a 120wxTabCtrl::~wxTabCtrl()
2bda0e17
KB
121{
122 UnsubclassWin();
123}
124
a23fd0e1 125bool wxTabCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
2bda0e17 126{
42e69d6b 127 wxTabEvent event(wxEVT_NULL, m_windowId);
5cb598ae 128 wxEventType eventType wxDUMMY_INITIALIZE(wxEVT_NULL);
42e69d6b
VZ
129 NMHDR* hdr1 = (NMHDR*) lParam;
130 switch ( hdr1->code )
131 {
132 case TCN_SELCHANGE:
133 eventType = wxEVT_COMMAND_TAB_SEL_CHANGED;
134 break;
135
136 case TCN_SELCHANGING:
137 eventType = wxEVT_COMMAND_TAB_SEL_CHANGING;
138 break;
fd3f686c 139
4676948b 140#ifndef __WXWINCE__
2bda0e17
KB
141 case TTN_NEEDTEXT:
142 {
143 // TODO
f31a4098 144// if (!tool->m_shortHelpString.empty())
2bda0e17 145// ttText->lpszText = (char *) (const char *)tool->m_shortHelpString;
2bda0e17 146 }
4676948b 147#endif
42e69d6b
VZ
148 default :
149 return wxControl::MSWOnNotify(idCtrl, lParam, result);
150 }
2bda0e17 151
42e69d6b
VZ
152 event.SetEventObject( this );
153 event.SetEventType(eventType);
154 event.SetInt(idCtrl) ;
2b5f62a0 155 event.SetSelection(idCtrl);
2bda0e17 156
42e69d6b 157 return ProcessEvent(event);
2bda0e17
KB
158}
159
160// Responds to colour changes, and passes event on to children.
161void wxTabCtrl::OnSysColourChanged(wxSysColourChangedEvent& event)
162{
163 m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
42e69d6b
VZ
164 GetGValue(GetSysColor(COLOR_BTNFACE)),
165 GetBValue(GetSysColor(COLOR_BTNFACE)));
2bda0e17
KB
166
167 Refresh();
168
169 // Propagate the event to the non-top-level children
170 wxWindow::OnSysColourChanged(event);
171}
172
173// Delete all items
ee4f8c2a 174bool wxTabCtrl::DeleteAllItems()
2bda0e17
KB
175{
176 return ( TabCtrl_DeleteAllItems( (HWND) GetHWND() ) != FALSE );
177}
178
179// Delete an item
ee4f8c2a 180bool wxTabCtrl::DeleteItem(int item)
2bda0e17
KB
181{
182 return ( TabCtrl_DeleteItem( (HWND) GetHWND(), item) != FALSE );
183}
184
185// Get the selection
ee4f8c2a 186int wxTabCtrl::GetSelection() const
2bda0e17
KB
187{
188 return (int) TabCtrl_GetCurSel( (HWND) GetHWND() );
189}
190
da87a1ca
JS
191// Get the tab with the current keyboard focus
192int wxTabCtrl::GetCurFocus() const
193{
194 return (int) TabCtrl_GetCurFocus( (HWND) GetHWND() );
195}
196
2bda0e17 197// Get the associated image list
ee4f8c2a 198wxImageList* wxTabCtrl::GetImageList() const
2bda0e17
KB
199{
200 return m_imageList;
201}
202
203// Get the number of items
ee4f8c2a 204int wxTabCtrl::GetItemCount() const
2bda0e17
KB
205{
206 return (int) TabCtrl_GetItemCount( (HWND) GetHWND() );
207}
208
209// Get the rect corresponding to the tab
ee4f8c2a 210bool wxTabCtrl::GetItemRect(int item, wxRect& wxrect) const
2bda0e17
KB
211{
212 RECT rect;
213 if ( !TabCtrl_GetItemRect( (HWND) GetHWND(), item, & rect) )
bfbb0b4c 214 return false;
2bda0e17
KB
215 else
216 {
217 wxrect.x = rect.left; wxrect.y = rect.top;
218 wxrect.width = rect.right - rect.left;
219 wxrect.height = rect.bottom - rect.top;
bfbb0b4c 220 return true;
2bda0e17
KB
221 }
222}
223
224// Get the number of rows
ee4f8c2a 225int wxTabCtrl::GetRowCount() const
2bda0e17
KB
226{
227 return (int) TabCtrl_GetRowCount( (HWND) GetHWND() );
228}
229
230// Get the item text
ee4f8c2a 231wxString wxTabCtrl::GetItemText(int item) const
2bda0e17 232{
837e5743 233 wxChar buf[256];
fda7962d 234 wxString str(wxEmptyString);
2bda0e17
KB
235 TC_ITEM tcItem;
236 tcItem.mask = TCIF_TEXT;
237 tcItem.pszText = buf;
238 tcItem.cchTextMax = 256;
239
240 if (TabCtrl_GetItem( (HWND) GetHWND(), item, & tcItem) )
241 str = tcItem.pszText;
242
243 return str;
244}
245
246// Get the item image
ee4f8c2a 247int wxTabCtrl::GetItemImage(int item) const
2bda0e17
KB
248{
249 TC_ITEM tcItem;
250 tcItem.mask = TCIF_IMAGE;
251
252 if (TabCtrl_GetItem( (HWND) GetHWND(), item, & tcItem) )
253 return tcItem.iImage;
254 else
255 return -1;
256}
257
258// Get the item data
ee4f8c2a 259void* wxTabCtrl::GetItemData(int item) const
2bda0e17
KB
260{
261 TC_ITEM tcItem;
262 tcItem.mask = TCIF_PARAM;
263
264 if (TabCtrl_GetItem( (HWND) GetHWND(), item, & tcItem) )
265 return (void*) tcItem.lParam;
266 else
267 return 0;
268}
269
270// Hit test
271int wxTabCtrl::HitTest(const wxPoint& pt, long& flags)
272{
273 TC_HITTESTINFO hitTestInfo;
274 hitTestInfo.pt.x = pt.x;
275 hitTestInfo.pt.y = pt.y;
276 int item = TabCtrl_HitTest( (HWND) GetHWND(), & hitTestInfo ) ;
277 flags = 0;
278
279 if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
280 flags |= wxTAB_HITTEST_NOWHERE;
281 if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
282 flags |= wxTAB_HITTEST_ONICON;
283 if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
284 flags |= wxTAB_HITTEST_ONLABEL;
285
286 return item;
287}
288
289// Insert an item
ee4f8c2a 290bool wxTabCtrl::InsertItem(int item, const wxString& text, int imageId, void* data)
2bda0e17 291{
837e5743 292 wxChar buf[256];
2bda0e17
KB
293 TC_ITEM tcItem;
294 tcItem.mask = TCIF_PARAM;
295 tcItem.lParam = (long) data;
489f6cf7 296 if (!text.empty())
2bda0e17
KB
297 {
298 tcItem.mask |= TCIF_TEXT;
837e5743 299 wxStrcpy(buf, (const wxChar*) text);
2bda0e17
KB
300 tcItem.pszText = buf;
301 tcItem.cchTextMax = 256;
302 }
303 if (imageId != -1)
304 {
305 tcItem.mask |= TCIF_IMAGE;
306 tcItem.iImage = imageId;
307 }
308
ee4f8c2a 309 return (TabCtrl_InsertItem( (HWND) GetHWND(), item, & tcItem) != -1);
2bda0e17
KB
310}
311
312// Set the selection
ee4f8c2a 313int wxTabCtrl::SetSelection(int item)
2bda0e17
KB
314{
315 return (int) TabCtrl_SetCurSel( (HWND) GetHWND(), item );
316}
317
318// Set the image list
319void wxTabCtrl::SetImageList(wxImageList* imageList)
320{
321 m_imageList = imageList;
322 TabCtrl_SetImageList( (HWND) GetHWND(), (HIMAGELIST) imageList->GetHIMAGELIST() );
323}
324
325// Set the text for an item
ee4f8c2a 326bool wxTabCtrl::SetItemText(int item, const wxString& text)
2bda0e17 327{
837e5743 328 wxChar buf[256];
2bda0e17
KB
329 TC_ITEM tcItem;
330 tcItem.mask = TCIF_TEXT;
837e5743 331 wxStrcpy(buf, (const wxChar*) text);
2bda0e17
KB
332 tcItem.pszText = buf;
333 tcItem.cchTextMax = 256;
334
335 return ( TabCtrl_SetItem( (HWND) GetHWND(), item, & tcItem) != 0 );
336}
337
338// Set the image for an item
ee4f8c2a 339bool wxTabCtrl::SetItemImage(int item, int image)
2bda0e17
KB
340{
341 TC_ITEM tcItem;
342 tcItem.mask = TCIF_IMAGE;
343 tcItem.iImage = image;
344
345 return ( TabCtrl_SetItem( (HWND) GetHWND(), item, & tcItem) != 0 );
346}
347
348// Set the data for an item
ee4f8c2a 349bool wxTabCtrl::SetItemData(int item, void* data)
2bda0e17
KB
350{
351 TC_ITEM tcItem;
352 tcItem.mask = TCIF_PARAM;
353 tcItem.lParam = (long) data;
354
355 return ( TabCtrl_SetItem( (HWND) GetHWND(), item, & tcItem) != 0 );
356}
357
358// Set the size for a fixed-width tab control
359void wxTabCtrl::SetItemSize(const wxSize& size)
360{
361 TabCtrl_SetItemSize( (HWND) GetHWND(), size.x, size.y );
362}
363
364// Set the padding between tabs
365void wxTabCtrl::SetPadding(const wxSize& padding)
366{
367 TabCtrl_SetPadding( (HWND) GetHWND(), padding.x, padding.y );
368}
369
370#if 0
371// These are the default colors used to map the bitmap colors
372// to the current system colors
373
374#define BGR_BUTTONTEXT (RGB(000,000,000)) // black
375#define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
376#define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
377#define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
378#define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
379#define BGR_BACKGROUND (RGB(255,000,255)) // magenta
380
381void wxMapBitmap(HBITMAP hBitmap, int width, int height)
382{
383 COLORMAP ColorMap[] = {
384 {BGR_BUTTONTEXT, COLOR_BTNTEXT}, // black
385 {BGR_BUTTONSHADOW, COLOR_BTNSHADOW}, // dark grey
386 {BGR_BUTTONFACE, COLOR_BTNFACE}, // bright grey
387 {BGR_BUTTONHILIGHT, COLOR_BTNHIGHLIGHT},// white
388 {BGR_BACKGROUNDSEL, COLOR_HIGHLIGHT}, // blue
389 {BGR_BACKGROUND, COLOR_WINDOW} // magenta
390 };
391
392 int NUM_MAPS = (sizeof(ColorMap)/sizeof(COLORMAP));
393 int n;
394 for ( n = 0; n < NUM_MAPS; n++)
395 {
396 ColorMap[n].to = ::GetSysColor(ColorMap[n].to);
397 }
398
399 HBITMAP hbmOld;
400 HDC hdcMem = CreateCompatibleDC(NULL);
401
402 if (hdcMem)
403 {
404 hbmOld = SelectObject(hdcMem, hBitmap);
405
406 int i, j, k;
407 for ( i = 0; i < width; i++)
408 {
409 for ( j = 0; j < height; j++)
410 {
411 COLORREF pixel = ::GetPixel(hdcMem, i, j);
412/*
413 BYTE red = GetRValue(pixel);
414 BYTE green = GetGValue(pixel);
415 BYTE blue = GetBValue(pixel);
416*/
417
418 for ( k = 0; k < NUM_MAPS; k ++)
419 {
420 if ( ColorMap[k].from == pixel )
421 {
422 /* COLORREF actualPixel = */ ::SetPixel(hdcMem, i, j, ColorMap[k].to);
423 break;
424 }
425 }
426 }
427 }
428
429
430 SelectObject(hdcMem, hbmOld);
431 DeleteObject(hdcMem);
432 }
433
434}
435#endif
436
2bda0e17
KB
437#endif
438 // __WIN95__