forked from fastbuild/fastbuild
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOSDropDown.cpp
104 lines (89 loc) · 2.91 KB
/
OSDropDown.cpp
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
// OSDropDown.cpp
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "OSUI/PrecompiledHeader.h"
#include "OSDropDown.h"
// OSUI
#include "OSUI/OSFont.h"
#include "OSUI/OSWindow.h"
// Core
#include "Core/Env/Assert.h"
// system
#if defined( __WINDOWS__ )
#include <CommCtrl.h>
#include <Windows.h>
#endif
// Defines
//------------------------------------------------------------------------------
// CONSTRUCTOR
//------------------------------------------------------------------------------
OSDropDown::OSDropDown( OSWindow * parentWindow )
: OSWidget( parentWindow )
, m_Font( nullptr )
{
}
// SetFont
//------------------------------------------------------------------------------
void OSDropDown::SetFont( OSFont * font )
{
ASSERT( !IsInitialized() ); // Change font after Init not currently supported
m_Font = font;
}
// Init
//------------------------------------------------------------------------------
void OSDropDown::Init( int32_t x, int32_t y, uint32_t w, uint32_t h )
{
#if defined( __WINDOWS__ )
InitCommonControls();
m_Handle = CreateWindowA( WC_COMBOBOX,
"ComboBox",
CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
x, y,
w, h,
(HWND)m_Parent->GetHandle(),
nullptr,
nullptr, // TODO: ??? m_HInstance
nullptr );
// Font
SendMessage( (HWND)m_Handle, WM_SETFONT, (WPARAM)m_Font->GetFont(), (LPARAM)0 );
#else
(void)x;
(void)y;
(void)w;
(void)h;
#endif
OSWidget::Init();
}
// AddItem
//------------------------------------------------------------------------------
void OSDropDown::AddItem( const char * itemText )
{
#if defined( __WINDOWS__ )
SendMessage( (HWND)m_Handle, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)itemText );
#else
(void)itemText;
#endif
}
// SetSelectedItem
//------------------------------------------------------------------------------
void OSDropDown::SetSelectedItem( size_t index )
{
#if defined( __WINDOWS__ )
SendMessage( (HWND)m_Handle, CB_SETCURSEL, (WPARAM)uint32_t( index ), (LPARAM)0 );
#else
(void)index;
#endif
}
// GetSelectedItem
//------------------------------------------------------------------------------
size_t OSDropDown::GetSelectedItem() const
{
#if defined( __WINDOWS__ )
return (size_t)SendMessage((HWND)m_Handle, (UINT)CB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
#else
ASSERT(false);
return 0;
#endif
}
//------------------------------------------------------------------------------