From 8cc9b803da70052d6ec3501ed70c12386c6e9d59 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Tue, 9 Aug 2016 20:28:11 +0200 Subject: [PATCH] v101r02 --- core/core.hpp | 1 - gtk/application.cpp | 3 --- gtk/keyboard.cpp | 4 ++-- gtk/settings.cpp | 46 +++++++++++++++++++++++++--------------- gtk/settings.hpp | 29 +++++++++++-------------- gtk/window.cpp | 25 +++++++++++----------- qt/application.cpp | 3 --- qt/keyboard.cpp | 4 ++-- qt/settings.cpp | 46 +++++++++++++++++++++++++--------------- qt/settings.hpp | 25 +++++++++++----------- qt/window.cpp | 30 ++++++++++++-------------- windows/widget/label.cpp | 19 +++++++++++++---- 12 files changed, 128 insertions(+), 107 deletions(-) diff --git a/core/core.hpp b/core/core.hpp index f385df9..7c235d2 100644 --- a/core/core.hpp +++ b/core/core.hpp @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/gtk/application.cpp b/gtk/application.cpp index 9ca4c22..7c09ad9 100644 --- a/gtk/application.cpp +++ b/gtk/application.cpp @@ -42,9 +42,6 @@ auto pApplication::initialize() -> void { display = XOpenDisplay(nullptr); #endif - settings = new Settings; - settings->load(); - //set WM_CLASS to Application::name() if(Application::state.name) gdk_set_program_class(Application::state.name); diff --git a/gtk/keyboard.cpp b/gtk/keyboard.cpp index 90315ab..7a579d4 100644 --- a/gtk/keyboard.cpp +++ b/gtk/keyboard.cpp @@ -8,7 +8,7 @@ auto pKeyboard::poll() -> vector { #if defined(DISPLAY_XORG) XQueryKeymap(pApplication::display, state); #endif - for(auto& code : settings->keycodes) { + for(auto& code : settings.keycodes) { result.append(_pressed(state, code)); } return result; @@ -227,7 +227,7 @@ auto pKeyboard::initialize() -> void { lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0; hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0; #endif - settings->keycodes.append(lo | (hi << 8)); + settings.keycodes.append(lo | (hi << 8)); }; #define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; } diff --git a/gtk/settings.cpp b/gtk/settings.cpp index 594f127..397ef32 100644 --- a/gtk/settings.cpp +++ b/gtk/settings.cpp @@ -1,26 +1,38 @@ namespace hiro { Settings::Settings() { - geometry.append(geometry.frameX = 4, "FrameX"); - geometry.append(geometry.frameY = 24, "FrameY"); - geometry.append(geometry.frameWidth = 8, "FrameWidth"); - geometry.append(geometry.frameHeight = 28, "FrameHeight"); - geometry.append(geometry.menuHeight = 20, "MenuHeight"); - geometry.append(geometry.statusHeight = 20, "StatusHeight"); - append(geometry, "Geometry"); - window.append(window.backgroundColor = 0xedeceb, "BackgroundColor"); - append(window, "Window"); + string path = {Path::local(), "hiro/"}; + auto document = BML::unserialize(file::read({path, "gtk.bml"})); + + auto get = [&](string_view name) { + return document[name]; + }; + + geometry.frameX = get("Geometry/FrameX").integer(); + geometry.frameY = get("Geometry/FrameY").integer(); + geometry.frameWidth = get("Geometry/FrameWidth").integer(); + geometry.frameHeight = get("Geometry/FrameHeight").integer(); + geometry.menuHeight = get("Geometry/MenuHeight").integer(); + geometry.statusHeight = get("Geometry/StatusHeight").integer(); } -auto Settings::load() -> void { - string path = {Path::config(), "hiro/"}; - Configuration::Document::load({path, "gtk.bml"}); -} - -auto Settings::save() -> void { - string path = {Path::config(), "hiro/"}; +Settings::~Settings() { + string path = {Path::local(), "hiro/"}; directory::create(path, 0755); - Configuration::Document::save({path, "gtk.bml"}); + + Markup::Node document; + auto set = [&](string_view name, string_view value) { + document(name).setValue(value); + }; + + set("Geometry/FrameX", geometry.frameX); + set("Geometry/FrameY", geometry.frameY); + set("Geometry/FrameWidth", geometry.frameWidth); + set("Geometry/FrameHeight", geometry.frameHeight); + set("Geometry/MenuHeight", geometry.menuHeight); + set("Geometry/StatusHeight", geometry.statusHeight); + + file::write({path, "gtk.bml"}, BML::serialize(document)); } } diff --git a/gtk/settings.hpp b/gtk/settings.hpp index 8bcd1ed..4223095 100644 --- a/gtk/settings.hpp +++ b/gtk/settings.hpp @@ -1,26 +1,21 @@ namespace hiro { -struct Settings : Configuration::Document { +struct Settings { + Settings(); + ~Settings(); + vector keycodes; - struct Geometry : Configuration::Node { - signed frameX; - signed frameY; - signed frameWidth; - signed frameHeight; - signed menuHeight; - signed statusHeight; + struct Geometry { + int frameX = 4; + int frameY = 24; + int frameWidth = 8; + int frameHeight = 28; + int menuHeight = 20; + int statusHeight = 20; } geometry; - - struct Window : Configuration::Node { - unsigned backgroundColor; - } window; - - Settings(); - auto load() -> void; - auto save() -> void; }; -static Settings* settings = nullptr; +static Settings settings; } diff --git a/gtk/window.cpp b/gtk/window.cpp index 8cd4d28..ef0d43c 100644 --- a/gtk/window.cpp +++ b/gtk/window.cpp @@ -48,11 +48,10 @@ static auto Window_configure(GtkWidget* widget, GdkEvent* event, pWindow* p) -> if(!p->state().fullScreen) { //update geometry settings - settings->geometry.frameX = client.x - border.x; - settings->geometry.frameY = client.y - border.y; - settings->geometry.frameWidth = border.width - client.width; - settings->geometry.frameHeight = border.height - client.height; - settings->save(); + settings.geometry.frameX = client.x - border.x; + settings.geometry.frameY = client.y - border.y; + settings.geometry.frameWidth = border.width - client.width; + settings.geometry.frameHeight = border.height - client.height; } Geometry geometry = { @@ -212,10 +211,10 @@ auto pWindow::frameMargin() const -> Geometry { }; return { - settings->geometry.frameX, - settings->geometry.frameY + _menuHeight(), - settings->geometry.frameWidth, - settings->geometry.frameHeight + _menuHeight() + _statusHeight() + settings.geometry.frameX, + settings.geometry.frameY + _menuHeight(), + settings.geometry.frameWidth, + settings.geometry.frameHeight + _menuHeight() + _statusHeight() }; } @@ -328,13 +327,13 @@ auto pWindow::setVisible(bool visible) -> void { if(gtk_widget_get_visible(gtkMenu)) { GtkAllocation allocation; gtk_widget_get_allocation(gtkMenu, &allocation); - settings->geometry.menuHeight = allocation.height; + settings.geometry.menuHeight = allocation.height; } if(gtk_widget_get_visible(gtkStatus)) { GtkAllocation allocation; gtk_widget_get_allocation(gtkStatus, &allocation); - settings->geometry.statusHeight = allocation.height; + settings.geometry.statusHeight = allocation.height; } } @@ -358,7 +357,7 @@ auto pWindow::_append(mMenu& menu) -> void { } auto pWindow::_menuHeight() const -> signed { - return gtk_widget_get_visible(gtkMenu) ? settings->geometry.menuHeight : 0; + return gtk_widget_get_visible(gtkMenu) ? settings.geometry.menuHeight : 0; } auto pWindow::_setIcon(const string& pathname) -> bool { @@ -414,7 +413,7 @@ auto pWindow::_setStatusVisible(bool visible) -> void { } auto pWindow::_statusHeight() const -> signed { - return gtk_widget_get_visible(gtkStatus) ? settings->geometry.statusHeight : 0; + return gtk_widget_get_visible(gtkStatus) ? settings.geometry.statusHeight : 0; } } diff --git a/qt/application.cpp b/qt/application.cpp index fc09378..064c117 100644 --- a/qt/application.cpp +++ b/qt/application.cpp @@ -41,9 +41,6 @@ auto pApplication::syncX() -> void { auto pApplication::initialize() -> void { display = XOpenDisplay(0); - settings = new Settings; - settings->load(); - static int argc = 1; static char* argv[] = {new char[8], nullptr}; strcpy(argv[0], "hiro"); diff --git a/qt/keyboard.cpp b/qt/keyboard.cpp index 2dad0af..4872be6 100644 --- a/qt/keyboard.cpp +++ b/qt/keyboard.cpp @@ -6,7 +6,7 @@ auto pKeyboard::poll() -> vector { vector result; char state[256]; XQueryKeymap(pApplication::display, state); - for(auto& code : settings->keycodes) { + for(auto& code : settings.keycodes) { result.append(_pressed(state, code)); } return result; @@ -32,7 +32,7 @@ auto pKeyboard::initialize() -> void { auto append = [](unsigned lo, unsigned hi = 0) { lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0; hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0; - settings->keycodes.append(lo << 0 | hi << 8); + settings.keycodes.append(lo << 0 | hi << 8); }; #define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; } diff --git a/qt/settings.cpp b/qt/settings.cpp index 484ccf3..3393a06 100644 --- a/qt/settings.cpp +++ b/qt/settings.cpp @@ -1,26 +1,38 @@ namespace hiro { -static Settings* settings = nullptr; - Settings::Settings() { - geometry.append(geometry.frameX = 4, "FrameX"); - geometry.append(geometry.frameY = 24, "FrameY"); - geometry.append(geometry.frameWidth = 8, "FrameWidth"); - geometry.append(geometry.frameHeight = 28, "FrameHeight"); - geometry.append(geometry.menuHeight = 20, "MenuHeight"); - geometry.append(geometry.statusHeight = 20, "StatusHeight"); - append(geometry, "Geometry"); + string path = {Path::local(), "hiro/"}; + auto document = BML::unserialize(file::read({path, "qt.bml"})); + + auto get = [&](string_view name) { + return document[name]; + }; + + geometry.frameX = get("Geometry/FrameX").integer(); + geometry.frameY = get("Geometry/FrameY").integer(); + geometry.frameWidth = get("Geometry/FrameWidth").integer(); + geometry.frameHeight = get("Geometry/FrameHeight").integer(); + geometry.menuHeight = get("Geometry/MenuHeight").integer(); + geometry.statusHeight = get("Geometry/StatusHeight").integer(); } -auto Settings::load() -> void { - string path{Path::config(), "hiro/"}; - Configuration::Document::load({path, "qt.bml"}); -} - -auto Settings::save() -> void { - string path{Path::config(), "hiro/"}; +Settings::~Settings() { + string path = {Path::local(), "hiro/"}; directory::create(path, 0755); - Configuration::Document::save({path, "qt.bml"}); + + Markup::Node document; + auto set = [&](string_view name, string_view value) { + document(name).setValue(value); + }; + + set("Geometry/FrameX", geometry.frameX); + set("Geometry/FrameY", geometry.frameY); + set("Geometry/FrameWidth", geometry.frameWidth); + set("Geometry/FrameHeight", geometry.frameHeight); + set("Geometry/MenuHeight", geometry.menuHeight); + set("Geometry/StatusHeight", geometry.statusHeight); + + file::write({path, "qt.bml"}, BML::serialize(document)); } } diff --git a/qt/settings.hpp b/qt/settings.hpp index c74657f..4223095 100644 --- a/qt/settings.hpp +++ b/qt/settings.hpp @@ -1,20 +1,21 @@ namespace hiro { -struct Settings : Configuration::Document { +struct Settings { + Settings(); + ~Settings(); + vector keycodes; - struct Geometry : Configuration::Node { - signed frameX; - signed frameY; - signed frameWidth; - signed frameHeight; - signed menuHeight; - signed statusHeight; + struct Geometry { + int frameX = 4; + int frameY = 24; + int frameWidth = 8; + int frameHeight = 28; + int menuHeight = 20; + int statusHeight = 20; } geometry; - - Settings(); - auto load() -> void; - auto save() -> void; }; +static Settings settings; + } diff --git a/qt/window.cpp b/qt/window.cpp index fe5fb79..e28452d 100644 --- a/qt/window.cpp +++ b/qt/window.cpp @@ -70,10 +70,10 @@ auto pWindow::frameMargin() const -> Geometry { 0, _menuHeight() + _statusHeight() }; return { - settings->geometry.frameX, - settings->geometry.frameY + _menuHeight(), - settings->geometry.frameWidth, - settings->geometry.frameHeight + _menuHeight() + _statusHeight() + settings.geometry.frameX, + settings.geometry.frameY + _menuHeight(), + settings.geometry.frameWidth, + settings.geometry.frameHeight + _menuHeight() + _statusHeight() }; } @@ -215,11 +215,11 @@ auto pWindow::_append(mWidget& widget) -> void { } auto pWindow::_menuHeight() const -> signed { - return qtMenuBar->isVisible() ? settings->geometry.menuHeight : 0; + return qtMenuBar->isVisible() ? settings.geometry.menuHeight : 0; } auto pWindow::_statusHeight() const -> signed { - return qtStatusBar->isVisible() ? settings->geometry.statusHeight : 0; + return qtStatusBar->isVisible() ? settings.geometry.statusHeight : 0; } auto pWindow::_updateFrameGeometry() -> void { @@ -227,22 +227,20 @@ auto pWindow::_updateFrameGeometry() -> void { QRect border = qtWindow->frameGeometry(); QRect client = qtWindow->geometry(); - settings->geometry.frameX = client.x() - border.x(); - settings->geometry.frameY = client.y() - border.y(); - settings->geometry.frameWidth = border.width() - client.width(); - settings->geometry.frameHeight = border.height() - client.height(); + settings.geometry.frameX = client.x() - border.x(); + settings.geometry.frameY = client.y() - border.y(); + settings.geometry.frameWidth = border.width() - client.width(); + settings.geometry.frameHeight = border.height() - client.height(); if(qtMenuBar->isVisible()) { pApplication::syncX(); - settings->geometry.menuHeight = qtMenuBar->height(); + settings.geometry.menuHeight = qtMenuBar->height(); } if(qtStatusBar->isVisible()) { pApplication::syncX(); - settings->geometry.statusHeight = qtStatusBar->height(); + settings.geometry.statusHeight = qtStatusBar->height(); } - - settings->save(); } auto QtWindow::closeEvent(QCloseEvent* event) -> void { @@ -305,8 +303,8 @@ auto QtWindow::resizeEvent(QResizeEvent*) -> void { auto QtWindow::sizeHint() const -> QSize { unsigned width = p.state().geometry.width(); unsigned height = p.state().geometry.height(); - if(p.qtMenuBar->isVisible()) height += settings->geometry.menuHeight; - if(p.qtStatusBar->isVisible()) height += settings->geometry.statusHeight; + if(p.qtMenuBar->isVisible()) height += settings.geometry.menuHeight; + if(p.qtStatusBar->isVisible()) height += settings.geometry.statusHeight; return QSize(width, height); } diff --git a/windows/widget/label.cpp b/windows/widget/label.cpp index 3fc883d..0bd242e 100644 --- a/windows/widget/label.cpp +++ b/windows/widget/label.cpp @@ -44,19 +44,30 @@ static auto CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM BeginPaint(hwnd, &ps); RECT rc; GetClientRect(hwnd, &rc); - DrawThemeParentBackground(hwnd, ps.hdc, &rc); + //todo: use DrawThemeParentBackground if Label is inside TabFrame + if(auto brush = window->self()->hbrush) { + FillRect(ps.hdc, &rc, brush); + } else { + DrawThemeParentBackground(hwnd, ps.hdc, &rc); + } SetBkMode(ps.hdc, TRANSPARENT); SelectObject(ps.hdc, label->self()->hfont); - unsigned length = GetWindowTextLength(hwnd); + uint length = GetWindowTextLength(hwnd); wchar_t text[length + 1]; GetWindowText(hwnd, text, length + 1); text[length] = 0; DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS); - unsigned height = rc.bottom; + uint height = rc.bottom; GetClientRect(hwnd, &rc); rc.top = (rc.bottom - height) / 2; rc.bottom = rc.top + height; - DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS); + uint horizontalAlignment = DT_CENTER; + if(label->alignment().horizontal() < 0.333) horizontalAlignment = DT_LEFT; + if(label->alignment().horizontal() > 0.666) horizontalAlignment = DT_RIGHT; + uint verticalAlignment = DT_VCENTER; + if(label->alignment().vertical() < 0.333) verticalAlignment = DT_TOP; + if(label->alignment().vertical() > 0.666) verticalAlignment = DT_BOTTOM; + DrawText(ps.hdc, text, -1, &rc, DT_END_ELLIPSIS | horizontalAlignment | verticalAlignment); EndPaint(hwnd, &ps); return false; }