PageRenderTime 53ms CodeModel.GetById 41ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/win/controls/oslistfield.d

http://github.com/wilkie/djehuty
D | 125 lines | 96 code | 27 blank | 2 comment | 1 complexity | ea1ab83c92a7c84cb5f279733fea58c9 MD5 | raw file
  1module platform.win.controls.oslistfield;
  2
  3import gui.listfield;
  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
 16import interfaces.list;
 17
 18import utils.arraylist;
 19
 20class OSListField : ListField, OSControl
 21{
 22public:
 23
 24	this(int x, int y, int width, int height, AbstractList!(String) list = null)
 25	{
 26		super(x,y,width,height,null);
 27	}
 28
 29	override void OnAdd()
 30	{
 31		// CBS_DROPDOWN - editable
 32	   _hWnd = CreateWindowExW(0, "COMBOBOX\0", null, WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | WS_VSCROLL , _x,_y,_width,_height,
 33			WindowGetPlatformVars(_window).hWnd,null, cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
 34
 35		SetWindowPos(_hWnd, cast(HWND)HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
 36
 37		SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
 38		_oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
 39
 40		SendMessageW( _hWnd, WM_SETFONT, cast(WPARAM)win_button_font, 1);
 41
 42		// Add all members of the list
 43		Iterator irate = getIterator();
 44
 45		String data;
 46		while(getItem(data, irate))
 47		{
 48			SendMessageW(_hWnd, CB_ADDSTRING, 0, cast(LPARAM)data.ptr);
 49		}
 50	}
 51
 52	override void OnRemove()
 53	{
 54		DestroyWindow(_hWnd);
 55	}
 56
 57	override void addItem(String text)
 58	{
 59		_list.addItem(text);
 60		SendMessageW(_hWnd, CB_ADDSTRING, 0, cast(LPARAM)text.ptr);
 61	}
 62
 63	override void addItem(StringLiteral text)
 64	{
 65		_list.addItem(new String(text));
 66		SendMessageW(_hWnd, CB_ADDSTRING, 0, cast(LPARAM)text.ptr);
 67	}
 68
 69	override void addList(AbstractList!(String) list)
 70	{
 71		Iterator irate = _list.getIterator();
 72
 73		String data;
 74		while(_list.getItem(data, irate))
 75		{
 76			addItem(data);
 77		}
 78	}
 79
 80	override bool getItem(out String data, uint index)
 81	{
 82		return _list.getItem(data, index);
 83	}
 84
 85	override Iterator getIterator()
 86	{
 87		return _list.getIterator();
 88	}
 89
 90    override bool getItem(out String data, ref Iterator irate)
 91	{
 92		return _list.getItem(data, irate);
 93	}
 94
 95    override uint length()
 96    {
 97		return _list.length();
 98    }
 99
100protected:
101
102	LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
103	{
104		switch (message)
105		{
106			break;
107		default:
108			break;
109		}
110
111		return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
112	}
113
114	View _ReturnView(out int x, out int y, out int w, out int h)
115	{
116		x = _x;
117		y = _y;
118		w = _width;
119		h = _height;
120		return _view;
121	}
122
123	HWND _hWnd;
124	WNDPROC _oldproc;
125}