status-bar.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if defined(Hiro_StatusBar)
  2. namespace hiro {
  3. auto pStatusBar::construct() -> void {
  4. if(auto parent = _parent()) {
  5. hwnd = CreateWindow(STATUSCLASSNAME, L"", WS_CHILD, 0, 0, 0, 0, parent->hwnd, nullptr, GetModuleHandle(0), 0);
  6. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
  7. setEnabled(self().enabled());
  8. setFont(self().font());
  9. setText(self().text());
  10. setVisible(self().visible());
  11. }
  12. }
  13. auto pStatusBar::destruct() -> void {
  14. if(hfont) { DeleteObject(hfont); hfont = nullptr; }
  15. if(hwnd) { DestroyWindow(hwnd); hwnd = nullptr; }
  16. if(auto parent = _parent()) {
  17. parent->setGeometry(parent->state().geometry);
  18. }
  19. }
  20. auto pStatusBar::setEnabled(bool) -> void {
  21. //unsupported
  22. }
  23. auto pStatusBar::setFont(const Font&) -> void {
  24. auto font = self().font(true);
  25. if(hfont) DeleteObject(hfont);
  26. hfont = pFont::create(font);
  27. SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0);
  28. auto& text = state().text;
  29. auto height = font.size(text ? text : " ").height();
  30. SendMessage(hwnd, SB_SETMINHEIGHT, (WPARAM)height, 0);
  31. if(auto parent = _parent()) {
  32. parent->setGeometry(parent->state().geometry);
  33. }
  34. }
  35. auto pStatusBar::setText(const string&) -> void {
  36. auto& text = state().text;
  37. SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)(wchar_t*)utf16_t(text));
  38. }
  39. auto pStatusBar::setVisible(bool) -> void {
  40. ShowWindow(hwnd, self().visible() ? SW_SHOWNORMAL : SW_HIDE);
  41. if(auto parent = _parent()) {
  42. parent->setGeometry(parent->state().geometry);
  43. }
  44. }
  45. auto pStatusBar::_parent() -> maybe<pWindow&> {
  46. if(auto parent = self().parentWindow(true)) {
  47. if(auto self = parent->self()) return *self;
  48. }
  49. return {};
  50. }
  51. }
  52. #endif