PageRenderTime 30ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
  1. module platform.win.controls.ostogglefield;
  2. import gui.togglefield;
  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. class OSToggleField : ToggleField, OSControl
  13. {
  14. public:
  15. this(int x, int y, int width, int height, String value)
  16. {
  17. super(x,y,width,height,value);
  18. }
  19. this(int x, int y, int width, int height, StringLiteral value)
  20. {
  21. super(x,y,width,height,value);
  22. }
  23. override void OnAdd()
  24. {
  25. int sty = 0;
  26. //sty = WS_EX_TRANSPARENT;
  27. if (_is_grouped)
  28. {
  29. _hWnd = CreateWindowExW(sty, "BUTTON\0", null, WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, _x,_y,_width,_height,WindowGetPlatformVars(_window).hWnd, null,
  30. cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
  31. }
  32. else
  33. {
  34. _hWnd = CreateWindowExW(sty, "BUTTON\0", null, WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, _x,_y,_width,_height,WindowGetPlatformVars(_window).hWnd, null,
  35. cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
  36. }
  37. SendMessageW( _hWnd, WM_SETFONT, cast(WPARAM)win_button_font, 1);
  38. SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
  39. _oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
  40. SetWindowTextW(_hWnd, cast(wchar*)_value.ptr);
  41. }
  42. override void OnRemove()
  43. {
  44. //retrieve the data from the control's window
  45. wchar str[];
  46. int i = SendMessageW(_hWnd, WM_GETTEXTLENGTH, 0, 0);
  47. str = new wchar[i+2];
  48. GetWindowTextW(_hWnd, cast(wchar*)str.ptr, i+2);
  49. _value = new String(cast(StringLiteral)str);
  50. DestroyWindow(_hWnd);
  51. }
  52. // Methods
  53. override void unselect()
  54. {
  55. SendMessageW( _hWnd, BM_SETCHECK, BST_UNCHECKED, 0);
  56. }
  57. override void select()
  58. {
  59. SendMessageW( _hWnd, BM_SETCHECK, BST_CHECKED, 0);
  60. }
  61. override void setText(StringLiteral txt)
  62. {
  63. if (_window !is null)
  64. {
  65. SetWindowTextW(_hWnd, cast(wchar*)txt.ptr);
  66. }
  67. else
  68. {
  69. _value = new String(txt);
  70. }
  71. }
  72. override void setText(String txt)
  73. {
  74. if (_window !is null)
  75. {
  76. SetWindowTextW(_hWnd, cast(wchar*)txt.ptr);
  77. }
  78. else
  79. {
  80. _value = new String(txt);
  81. }
  82. }
  83. override String getText()
  84. {
  85. if (_window !is null)
  86. {
  87. //retrieve the data from the control's window
  88. wchar str[];
  89. int i = SendMessageW(_hWnd, WM_GETTEXTLENGTH, 0, 0);
  90. str = new wchar[i+2];
  91. GetWindowTextW(_hWnd, cast(wchar*)str.ptr, i+2);
  92. _value = new String(cast(StringLiteral)str);
  93. }
  94. return _value;
  95. }
  96. protected:
  97. LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
  98. {
  99. if (message == WM_COMMAND)
  100. {
  101. raiseSignal(Signal.Selected);
  102. return 0;
  103. }
  104. return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
  105. }
  106. View _ReturnView(out int x, out int y, out int w, out int h)
  107. {
  108. x = _x;
  109. y = _y;
  110. w = _width;
  111. h = _height;
  112. return _view;
  113. }
  114. HWND _hWnd;
  115. WNDPROC _oldproc;
  116. }