/platform/win/controls/oslistbox.d

http://github.com/wilkie/djehuty · D · 91 lines · 70 code · 20 blank · 1 comment · 1 complexity · d1be01b551d92ef6bc8cf0fe3f685d20 MD5 · raw file

  1. module platform.win.controls.oslistbox;
  2. import gui.listbox;
  3. import core.string;
  4. import platform.win.definitions;
  5. import platform.win.vars;
  6. import platform.win.common;
  7. import platform.win.oscontrolinterface;
  8. import platform.win.main;
  9. import core.view;
  10. import gui.widget;
  11. import gui.window;
  12. import interfaces.list;
  13. class OSListBox : ListBox, OSControl
  14. {
  15. public:
  16. this(int x, int y, int width, int height, AbstractList!(String) list = null)
  17. {
  18. super(x,y,width,height,list);
  19. }
  20. override void OnAdd()
  21. {
  22. _hWnd = CreateWindowExW(0, "LISTBOX\0", null, WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT | WS_BORDER | WS_VSCROLL , _x,_y,_width,_height,
  23. WindowGetPlatformVars(_window).hWnd,null, cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
  24. SetWindowPos(_hWnd, cast(HWND)HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  25. SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
  26. _oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
  27. SendMessageW( _hWnd, WM_SETFONT, cast(WPARAM)win_button_font, 1);
  28. // Add all members of the list
  29. Iterator irate = getIterator();
  30. String data;
  31. while(getItem(data, irate))
  32. {
  33. SendMessageW(_hWnd, LB_ADDSTRING, 0, cast(LPARAM)data.ptr);
  34. }
  35. }
  36. override void OnRemove()
  37. {
  38. DestroyWindow(_hWnd);
  39. }
  40. override void addItem(String text)
  41. {
  42. super.addItem(text);
  43. SendMessageW(_hWnd, LB_ADDSTRING, 0, cast(LPARAM)text.ptr);
  44. }
  45. override void addItem(StringLiteral text)
  46. {
  47. super.addItem(text);
  48. SendMessageW(_hWnd, LB_ADDSTRING, 0, cast(LPARAM)text.ptr);
  49. }
  50. protected:
  51. LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
  52. {
  53. switch (message)
  54. {
  55. break;
  56. default:
  57. break;
  58. }
  59. return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
  60. }
  61. View _ReturnView(out int x, out int y, out int w, out int h)
  62. {
  63. x = _x;
  64. y = _y;
  65. w = _width;
  66. h = _height;
  67. return _view;
  68. }
  69. HWND _hWnd;
  70. WNDPROC _oldproc;
  71. }