Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add form to linux #58

Open
wants to merge 13 commits into
base: tip-of-tree
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ jobs:
# sudo apt update
# sudo apt install g++-9 g++-10 llvm-10 clang-10

- name: Install Qt 5
run: |
sudo apt update
sudo apt install qtbase5-dev

- name: Find Qt
run: |
find /usr/include -name QWidget

- name: Build
#env:
# CXX: g++-10
working-directory: ${{ github.workspace }}/Projects/${{ matrix.compiler }} ${{ matrix.platform }} Make
run: make

- name: Test
run: ${{ github.workspace }}/Projects/${{ matrix.compiler }}\ ${{ matrix.platform }}\ Make/maxGUIAutomatedTests
run: ${{ github.workspace }}/Projects/${{ matrix.compiler }}\ ${{ matrix.platform }}\ Make/maxGUIAutomatedTests
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ int maxGUIEntryPoint(maxGUI::FormContainer form_container) noexcept {
// The message pump will loop until we call maxGUI::PostExitMessage(), which is the default behavior
// when a form is closed.
return maxGUI::MessagePump(form_container);
}
}
10 changes: 8 additions & 2 deletions Code/maxGUI/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ namespace maxGUI
Control::Control(HWND window_handle) noexcept
: window_handle_(std::move(window_handle))
{}
#elif defined(MAX_PLATFORM_LINUX)
Control::Control(QWidget* widget) noexcept
: widget_(std::move(widget))
{}
#endif

void Control::Move(Rectangle rectangle) noexcept {
#if defined(MAX_PLATFORM_WINDOWS)
SetWindowPos(window_handle_, NULL, rectangle.left_, rectangle.top_, rectangle.width_, rectangle.height_, SWP_NOZORDER);
#endif
#if defined(MAX_PLATFORM_LINUX)
(void)rectangle;
if (this) {
widget_->setGeometry(rectangle.left_, rectangle.top_, rectangle.width_, rectangle.height_);
}
#endif
}

Expand All @@ -34,4 +40,4 @@ namespace maxGUI
: rectangle_(std::move(rectangle))
{}

} // namespace maxGUI
} // namespace maxGUI
10 changes: 9 additions & 1 deletion Code/maxGUI/Control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#elif defined(MAX_PLATFORM_LINUX)
#include <QWidget>
#endif

namespace maxGUI
Expand All @@ -25,6 +27,8 @@ namespace maxGUI

#if defined(MAX_PLATFORM_WINDOWS)
explicit Control(HWND window_handle) noexcept;
#elif defined(MAX_PLATFORM_LINUX)
explicit Control(QWidget* widget) noexcept;
#endif

virtual ~Control() noexcept = default;
Expand All @@ -33,6 +37,8 @@ namespace maxGUI

#if defined(MAX_PLATFORM_WINDOWS)
HWND window_handle_;
#elif defined(MAX_PLATFORM_LINUX)
QWidget* widget_;
#endif

//protected:
Expand All @@ -53,6 +59,8 @@ namespace maxGUI

#if defined(MAX_PLATFORM_WINDOWS)
virtual std::unique_ptr<Control> CreateControl(HWND parent_window_handle) const noexcept = 0;
#elif defined(MAX_PLATFORM_LINUX)
virtual std::unique_ptr<Control> CreateControl(QWidget* parent_window) const noexcept = 0;
#endif

Rectangle rectangle_;
Expand All @@ -61,4 +69,4 @@ namespace maxGUI

} // namespace maxGUI

#endif // #ifndef MAXGUI_CONTROL_HPP
#endif // #ifndef MAXGUI_CONTROL_HPP
6 changes: 5 additions & 1 deletion Code/maxGUI/ControlWithText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace maxGUI
ControlWithText::ControlWithText(HWND window_handle) noexcept
: Control(std::move(window_handle))
{}
#elif defined(MAX_PLATFORM_LINUX)
ControlWithText::ControlWithText(QWidget* widget) noexcept
: Control(std::move(widget))
{}
#endif

std::string ControlWithText::GetText() const noexcept {
Expand Down Expand Up @@ -47,4 +51,4 @@ namespace maxGUI
, text_(std::move(text))
{}

} // namespace maxGUI
} // namespace maxGUI
4 changes: 3 additions & 1 deletion Code/maxGUI/ControlWithText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace maxGUI

#if defined(MAX_PLATFORM_WINDOWS)
explicit ControlWithText(HWND window_handle) noexcept;
#elif defined(MAX_PLATFORM_LINUX)
explicit ControlWithText(QWidget* widget) noexcept;
#endif

~ControlWithText() noexcept override = default;
Expand All @@ -47,4 +49,4 @@ namespace maxGUI

} // namespace maxGUI

#endif // #ifndef MAXGUI_CONTROLWITHTEXT_HPP
#endif // #ifndef MAXGUI_CONTROLWITHTEXT_HPP
66 changes: 43 additions & 23 deletions Code/maxGUI/EntryPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,62 @@

#include <maxGUI/EntryPoint.hpp>

int
#if !defined(_MAC)
#if defined(_M_CEE_PURE)
__clrcall
#else
WINAPI
#if defined(MAX_PLATFORM_LINUX)
#include <QApplication>
#endif
#else
CALLBACK

#if defined(MAX_PLATFORM_WINDOWS)
int
#if !defined(_MAC)
#if defined(_M_CEE_PURE)
__clrcall
#else
WINAPI
#endif
#else
CALLBACK
#endif
WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance*/, _In_ LPSTR /*lpCmdLine*/, _In_ int /*nShowCmd*/)
{
return maxGUIEntryPoint(maxGUI::FormContainer(hInstance));
}
#elif defined(MAX_PLATFORM_LINUX)
int main(int argc, char** argv) {
QApplication app(argc, argv);
return maxGUIEntryPoint(maxGUI::FormContainer(&app));
}
#endif
WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance*/, _In_ LPSTR /*lpCmdLine*/, _In_ int /*nShowCmd*/)
{
return maxGUIEntryPoint(maxGUI::FormContainer(hInstance));
}

namespace maxGUI {

void PostExitMessage(const int exit_code) noexcept {
#if defined(MAX_PLATFORM_WINDOWS)
PostQuitMessage(exit_code);
#elif defined(MAX_PLATFORM_LINUX)
// TODO: Can we do this with Qt?
(void)exit_code;
#endif
}

int MessagePump(const FormContainer& form_container) noexcept {
MSG Message = {0};
while (GetMessage(&Message, NULL, 0, 0) > 0)
{
for (const auto& form : form_container.forms_) {
if (IsDialogMessage(form->window_handle_, &Message) == 0)
{
//TranslateAccelerator
TranslateMessage(&Message);
DispatchMessage(&Message);
#if defined(MAX_PLATFORM_WINDOWS)
MSG Message = {0};
while (GetMessage(&Message, NULL, 0, 0) > 0)
{
for (const auto& form : form_container.forms_) {
if (IsDialogMessage(form->window_handle_, &Message) == 0)
{
//TranslateAccelerator
TranslateMessage(&Message);
DispatchMessage(&Message);
}
}
}
}

return static_cast<int>(Message.wParam);
return static_cast<int>(Message.wParam);
#elif defined(MAX_PLATFORM_LINUX)
return form_container.app_->exec();
#endif
}

} // namespace maxGUI
46 changes: 26 additions & 20 deletions Code/maxGUI/EntryPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@
#ifndef MAXGUI_ENTRYPOINT_HPP
#define MAXGUI_ENTRYPOINT_HPP

#include <max/Compiling/Configuration.hpp>
#include <maxGUI/Form.hpp>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>

// This instructs Microsoft Visual C++ 2005 and later to use ComCtl32.dll version 6.
// That gives the modern visual styles.
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#if defined(MAX_PLATFORM_WINDOWS)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>

// This instructs Microsoft Visual C++ 2005 and later to use ComCtl32.dll version 6.
// That gives the modern visual styles.
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

// The user should implement this function.
// maxGUI calls this when the program begins.
int maxGUIEntryPoint(maxGUI::FormContainer form_container) noexcept;

int
#if !defined(_MAC)
#if defined(_M_CEE_PURE)
__clrcall
#else
WINAPI
#endif
#else
CALLBACK
#if defined(MAX_PLATFORM_WINDOWS)
int
#if !defined(_MAC)
#if defined(_M_CEE_PURE)
__clrcall
#else
WINAPI
#endif
#else
CALLBACK
#endif
WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd);
#endif
WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd);

namespace maxGUI {

Expand All @@ -40,4 +46,4 @@ namespace maxGUI {

} // namespace maxGUI

#endif // #ifndef MAXGUI_ENTRYPOINT_HPP
#endif // #ifndef MAXGUI_ENTRYPOINT_HPP
Loading