From: Sung-Jin Park Date: Mon, 27 Jul 2020 10:53:29 +0000 (+0900) Subject: DSWindow: add geometric information, apis and integration DSWindow*.cpp into DSWindow.cpp X-Git-Tag: accepted/tizen/unified/20200820.213435~207 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F68%2F241668%2F1;p=platform%2Fcore%2Fuifw%2Flibds.git DSWindow: add geometric information, apis and integration DSWindow*.cpp into DSWindow.cpp Change-Id: Ic9be2b9ec07164efa5ffc7e0eb9ad8da4518e326 Signed-off-by: Sung-Jin Park --- diff --git a/src/DSCore/DSStruct.h b/src/DSCore/DSStruct.h index 92f8e39..fb9aa51 100644 --- a/src/DSCore/DSStruct.h +++ b/src/DSCore/DSStruct.h @@ -8,6 +8,7 @@ namespace display_server using stPosition = struct _stPosition; using stRect = struct _stRect; +using stGeometry = struct _stGeometry; struct _stPosition { @@ -23,6 +24,14 @@ struct _stRect uint32_t h; }; +struct _stGeometry +{ + int x; + int y; + unsigned int w; + unsigned int h; +}; + } // namespace display_server #endif //__DS_STRUCT_H__ diff --git a/src/DSWindow/DSWindow.cpp b/src/DSWindow/DSWindow.cpp index 5c2b797..52d6eba 100644 --- a/src/DSWindow/DSWindow.cpp +++ b/src/DSWindow/DSWindow.cpp @@ -4,20 +4,129 @@ namespace display_server { +DSWindowPrivate::DSWindowPrivate(DSWindow *p_ptr) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr), + __x(0), + __y(0), + __w(1), + __h(1), + __created(false), + __hasFocus(false) +{ +} + +DSWindowPrivate::~DSWindowPrivate() +{ +} + +bool DSWindowPrivate::create(DSWindow *pParent) +{ + // get screen position (x, y) + + // get screen width (w, h) + + __created = __create(__x, __y, __w, __h, pParent); + return __created; +} + +bool DSWindowPrivate::create(int x, int y, unsigned int w, unsigned int h, DSWindow *pParent) +{ + __created = __create(x, y, w, h, pParent); + return __created; +} + +void DSWindowPrivate::destroy(void) +{ +} + +bool DSWindowPrivate::show(void) +{ + return true; +} + +bool DSWindowPrivate::hide(bool autoFocus) +{ + return true; +} + +int DSWindowPrivate::showState(void) +{ + return 0; +} + +bool DSWindowPrivate::setLayer(int layer) +{ + return true; +} + +bool DSWindowPrivate::raise(void) +{ + return true; +} + +bool DSWindowPrivate::lower(void) +{ + return true; +} + +bool DSWindowPrivate::setFocus(void) +{ + return true; +} + +bool DSWindowPrivate::__create(int x, int y, unsigned int w, unsigned int h, DSWindow *pParent) +{ + DS_GET_PUB(DSWindow); + + __x = x; + __y = y; + __w = w; + __h = h; + pub->__parentWindow = pParent; + + // Do something + + return true; +} + +bool DSWindowPrivate::isCreated() +{ + return __created; +} + DSWindow::DSWindow() - : DS_INIT_PRIVATE_PTR(DSWindow) -{} + : DS_INIT_PRIVATE_PTR(DSWindow), + __parentWindow(nullptr) +{ +} + +DSWindow::DSWindow(DSWindow *pParent) + : DS_INIT_PRIVATE_PTR(DSWindow), + __parentWindow(pParent) +{ + create(pParent); +} + +DSWindow::DSWindow(DSWindow *pParent, int x, int y, unsigned int w, unsigned h) + : DS_INIT_PRIVATE_PTR(DSWindow), + __parentWindow(pParent) +{ + create(x, y, w, h, pParent); +} DSWindow::~DSWindow() -{} +{ + +} bool DSWindow::create(DSWindow *pParent) { DS_GET_PRIV(DSWindow); - if (priv->create(this, pParent) == false) + if (!priv->isCreated()) { - return false; + return priv->create(pParent); } return true; @@ -27,9 +136,9 @@ bool DSWindow::create(int x, int y, unsigned int w, unsigned int h, DSWindow *pP { DS_GET_PRIV(DSWindow); - if (priv->create(x, y, w, h, this, pParent) == false) + if (!priv->isCreated()) { - return false; + return priv->create(x, y, w, h, pParent); } return true; @@ -92,5 +201,35 @@ bool DSWindow::setFocus(void) return priv->setFocus(); } +bool DSWindow::hasFocus(void) +{ + DS_GET_PRIV(DSWindow); + + return priv->__hasFocus; +} + +DSWindow *DSWindow::getParent() +{ + return __parentWindow; +} + +void DSWindow::setParent(DSWindow *pParent) +{ + DSLOG_INF("DSWindow", "Parent window has been changed. (%p -> %p)", __parentWindow, pParent); + __parentWindow = pParent; +} + +stGeometry DSWindow::getGeometry() +{ + DS_GET_PRIV(DSWindow); + + stGeometry geom; + geom.x = priv->__x; + geom.y = priv->__y; + geom.w = priv->__w; + geom.h = priv->__h; + + return geom; +} } // namespace display_server \ No newline at end of file diff --git a/src/DSWindow/DSWindow.h b/src/DSWindow/DSWindow.h index cd59a0d..fca506b 100644 --- a/src/DSWindow/DSWindow.h +++ b/src/DSWindow/DSWindow.h @@ -2,6 +2,7 @@ #define _DS_WINDOW_H_ #include "DSCore.h" +#include "DSStruct.h" #include "DSObject.h" namespace display_server @@ -15,6 +16,8 @@ class DSWindow : public DSObject public: explicit DSWindow(); + DSWindow(DSWindow *pParent); + DSWindow(DSWindow *pParent, int x, int y, unsigned int w, unsigned h); virtual ~DSWindow(); bool create(DSWindow *pParent); @@ -31,10 +34,19 @@ public: bool lower(void); bool setFocus(void); + bool hasFocus(void); + + DSWindow *getParent(); + void setParent(DSWindow *pParent); + + stGeometry getGeometry(); protected: //virtual bool _onFocus(void); //virtual bool _onShowStateChange(void); + +private: + DSWindow *__parentWindow; }; } diff --git a/src/DSWindow/DSWindowPrivate.cpp b/src/DSWindow/DSWindowPrivate.cpp deleted file mode 100644 index caa062a..0000000 --- a/src/DSWindow/DSWindowPrivate.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "DSWindow.h" -#include "DSWindowPrivate.h" - -namespace display_server -{ - -DSWindowPrivate::DSWindowPrivate(DSWindow *p_ptr) - : DSObjectPrivate(p_ptr), - __p_ptr(p_ptr) -{ -} - -DSWindowPrivate::~DSWindowPrivate() -{ -} - -bool DSWindowPrivate::create(DSWindow *pWin, DSWindow *pParent) -{ - int x = 0; - int y = 0; - unsigned int w = 1; - unsigned int h = 1; - - // get screen position (x, y) - - // get screen width (w, h) - - return __create(x, y, w, h, pWin, pParent); -} - -bool DSWindowPrivate::create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent) -{ - return __create(x, y, w, h, pWin, pParent); -} - -void DSWindowPrivate::destroy(void) -{ -} - -bool DSWindowPrivate::show(void) -{ - return true; -} - -bool DSWindowPrivate::hide(bool autoFocus) -{ - return true; -} - -int DSWindowPrivate::showState(void) -{ - return 0; -} - -bool DSWindowPrivate::setLayer(int layer) -{ - return true; -} - -bool DSWindowPrivate::raise(void) -{ - return true; -} - -bool DSWindowPrivate::lower(void) -{ - return true; -} - -bool DSWindowPrivate::setFocus(void) -{ - return true; -} - -bool DSWindowPrivate::__create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent) -{ - // Do something - - return true; -} - -} // namespace display_server \ No newline at end of file diff --git a/src/DSWindow/DSWindowPrivate.h b/src/DSWindow/DSWindowPrivate.h index 507cd56..44f284b 100644 --- a/src/DSWindow/DSWindowPrivate.h +++ b/src/DSWindow/DSWindowPrivate.h @@ -1,9 +1,14 @@ #ifndef _DS_WINDOW_PRIVATE_H_ #define _DS_WINDOW_PRIVATE_H_ +#include "DSCore.h" +#include "DSObjectPrivate.h" + namespace display_server { +class DSWindow; + class DSWindowPrivate : public DSObjectPrivate { DS_PIMPL_USE_PUBLIC(DSWindow) @@ -13,8 +18,8 @@ public: DSWindowPrivate(DSWindow *p_ptr); ~DSWindowPrivate(); - bool create(DSWindow *pWin, DSWindow *pParent); - bool create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent); + bool create(DSWindow *pParent); + bool create(int x, int y, unsigned int w, unsigned int h, DSWindow *pParent); void destroy(void); @@ -27,10 +32,17 @@ public: bool lower(void); bool setFocus(void); + bool isCreated(); private: - bool __create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent); - + bool __create(int x, int y, unsigned int w, unsigned int h, DSWindow *pParent); + + int __x; + int __y; + unsigned int __w; + unsigned int __h; + bool __created; + bool __hasFocus; }; } diff --git a/src/meson.build b/src/meson.build index 4b4b283..24bfcf4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -47,8 +47,9 @@ libds_srcs = [ 'DSSignal/DSSignal.h', 'DSCore/DSStruct.h', 'DSCore/DSCore.h', + 'DSWindow/DSWindow.h', + 'DSWindow/DSWindowPrivate.h', 'DSWindow/DSWindow.cpp', - 'DSWindow/DSWindowPrivate.cpp', 'DSWindowShell/DSWindowShell.cpp', 'DSWindowShell/DSWindowShellPrivate.cpp', 'DSZone/DSZone.cpp', diff --git a/tests/DSWindow-test.cpp b/tests/DSWindow-test.cpp index 07b41fe..9838ca8 100644 --- a/tests/DSWindow-test.cpp +++ b/tests/DSWindow-test.cpp @@ -1,6 +1,7 @@ #include "libds-tests.h" #include "DSObject.h" #include "DSWindow.h" +#include "DSStruct.h" using namespace display_server; @@ -15,26 +16,59 @@ public: TEST_F(DSWindowTest, NewDSWindow) { - std::unique_ptr Window = std::make_unique(); - EXPECT_TRUE(Window != nullptr); + DSWindow *win = new DSWindow(); + EXPECT_TRUE(win != nullptr); +} + +TEST_F(DSWindowTest, NewDSWindowWithParent) +{ + DSWindow *wParent = new DSWindow(); + EXPECT_TRUE(wParent != nullptr); + + DSWindow *wChild = new DSWindow(wParent); + EXPECT_TRUE(wChild != nullptr); +} + +TEST_F(DSWindowTest, NewDSWindowWithGeometry) +{ + int x = 100; + int y = 100; + unsigned int w = 500; + unsigned int h = 500; + + DSWindow *win = new DSWindow(nullptr, x, y, w, h); + EXPECT_TRUE(win != nullptr); + + stGeometry geom = win->getGeometry(); + EXPECT_TRUE(geom.x == x); + EXPECT_TRUE(geom.y == y); + EXPECT_TRUE(geom.w == w); + EXPECT_TRUE(geom.h == h); } TEST_F(DSWindowTest, BasicMethods) { - std::unique_ptr Window = std::make_unique(); - EXPECT_TRUE(Window != nullptr); + bool hasFocus = false; + + DSWindow *win = new DSWindow(); + EXPECT_TRUE(win != nullptr); + EXPECT_TRUE(win->create(0, 0, 720, 1280, nullptr) == true); - EXPECT_TRUE(Window->create(nullptr) == true); - EXPECT_TRUE(Window->create(0, 0, 720, 1280, nullptr) == true); + stGeometry geom = win->getGeometry(); + EXPECT_TRUE(geom.x == 0); + EXPECT_TRUE(geom.y == 0); + EXPECT_TRUE(geom.w == 720); + EXPECT_TRUE(geom.h == 1280); - EXPECT_TRUE(Window->show() == true); - EXPECT_TRUE(Window->hide(true) == true); - EXPECT_TRUE(Window->showState() == 0); + EXPECT_TRUE(win->show() == true); + EXPECT_TRUE(win->hide(true) == true); + EXPECT_TRUE(win->showState() == 0); - EXPECT_TRUE(Window->setLayer(100) == true); + EXPECT_TRUE(win->setLayer(100) == true); - EXPECT_TRUE(Window->raise() == true); - EXPECT_TRUE(Window->lower() == true); + EXPECT_TRUE(win->raise() == true); + EXPECT_TRUE(win->lower() == true); - EXPECT_TRUE(Window->setFocus() == true); + hasFocus = win->setFocus(); + EXPECT_TRUE(hasFocus == win->hasFocus()); } \ No newline at end of file