PageRenderTime 30ms CodeModel.GetById 12ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/win/controls/ostogglefield.d

http://github.com/wilkie/djehuty
D | 152 lines | 112 code | 36 blank | 4 comment | 6 complexity | 09923cf7c688ce5f6df7c5f1100b0734 MD5 | raw file
  1module platform.win.controls.ostogglefield;
  2
  3import gui.togglefield;
  4import core.string;
  5
  6import platform.win.definitions;
  7import platform.win.vars;
  8import platform.win.common;
  9import platform.win.oscontrolinterface;
 10
 11import platform.win.main;
 12import core.view;
 13import gui.widget;
 14import gui.window;
 15
 16class OSToggleField : ToggleField, OSControl
 17{
 18public:
 19	this(int x, int y, int width, int height, String value)
 20	{
 21		super(x,y,width,height,value);
 22	}
 23
 24	this(int x, int y, int width, int height, StringLiteral value)
 25	{
 26		super(x,y,width,height,value);
 27	}
 28
 29	override void OnAdd()
 30	{
 31		int sty = 0;
 32		//sty = WS_EX_TRANSPARENT;
 33		if (_is_grouped)
 34		{
 35			_hWnd = CreateWindowExW(sty, "BUTTON\0", null, WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, _x,_y,_width,_height,WindowGetPlatformVars(_window).hWnd, null,
 36				cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
 37		}
 38		else
 39		{
 40			_hWnd = CreateWindowExW(sty, "BUTTON\0", null, WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, _x,_y,_width,_height,WindowGetPlatformVars(_window).hWnd, null,
 41				cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
 42		}
 43
 44		SendMessageW( _hWnd, WM_SETFONT, cast(WPARAM)win_button_font, 1);
 45
 46		SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
 47		_oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
 48
 49		SetWindowTextW(_hWnd, cast(wchar*)_value.ptr);
 50
 51	}
 52
 53	override void OnRemove()
 54	{
 55		//retrieve the data from the control's window
 56		wchar str[];
 57
 58		int i = SendMessageW(_hWnd, WM_GETTEXTLENGTH, 0, 0);
 59
 60		str = new wchar[i+2];
 61
 62		GetWindowTextW(_hWnd, cast(wchar*)str.ptr, i+2);
 63
 64		_value = new String(cast(StringLiteral)str);
 65
 66		DestroyWindow(_hWnd);
 67	}
 68
 69
 70
 71
 72
 73	// Methods
 74
 75	override void unselect()
 76	{
 77		SendMessageW( _hWnd, BM_SETCHECK, BST_UNCHECKED, 0);
 78	}
 79
 80	override void select()
 81	{
 82		SendMessageW( _hWnd, BM_SETCHECK, BST_CHECKED, 0);
 83	}
 84
 85	override void setText(StringLiteral txt)
 86	{
 87		if (_window !is null)
 88		{
 89			SetWindowTextW(_hWnd, cast(wchar*)txt.ptr);
 90		}
 91		else
 92		{
 93			_value = new String(txt);
 94		}
 95	}
 96
 97	override void setText(String txt)
 98	{
 99		if (_window !is null)
100		{
101			SetWindowTextW(_hWnd, cast(wchar*)txt.ptr);
102		}
103		else
104		{
105			_value = new String(txt);
106		}
107	}
108
109	override String getText()
110	{
111		if (_window !is null)
112		{
113			//retrieve the data from the control's window
114			wchar str[];
115
116			int i = SendMessageW(_hWnd, WM_GETTEXTLENGTH, 0, 0);
117
118			str = new wchar[i+2];
119
120			GetWindowTextW(_hWnd, cast(wchar*)str.ptr, i+2);
121
122			_value = new String(cast(StringLiteral)str);
123		}
124
125		return _value;
126	}
127
128protected:
129
130	LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
131	{
132		if (message == WM_COMMAND)
133		{
134			raiseSignal(Signal.Selected);
135			return 0;
136		}
137
138		return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
139	}
140
141	View _ReturnView(out int x, out int y, out int w, out int h)
142	{
143		x = _x;
144		y = _y;
145		w = _width;
146		h = _height;
147		return _view;
148	}
149
150	HWND _hWnd;
151	WNDPROC _oldproc;
152}