From 5adf0e3edc5cef35ad67ffc8a3533c8fe30c0c58 Mon Sep 17 00:00:00 2001 From: Alexander <0oktonion0@gmail.com> Date: Sun, 4 Aug 2019 17:05:03 +0300 Subject: [PATCH 1/3] BringToFront and SendToBack for Widget --- src/Widget.cpp | 9 +++++++++ src/Widget.h | 27 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Widget.cpp b/src/Widget.cpp index a07c5549..9313b70f 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -491,6 +491,10 @@ void PhWidgets::Widget::OnUnrealized( PtCallbackInfo_t * info) resource.callback[Callback::unrealized].raise(info); } +void Widget::BringToFront() +{ + PtWidgetToFront(widget()); +} void Widget::SetBounds(short x, short y, unsigned short width, unsigned short height) { @@ -537,6 +541,11 @@ Widget Widget::GetNextWidget(Widget widget, bool forward) const return Widget(result); } +void Widget::SendToBack() +{ + PtWidgetToBack(widget()); +} + void Widget::Select() { Focus(); // TODO: check the actual difference diff --git a/src/Widget.h b/src/Widget.h index d5d48751..b3dec7b3 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -1081,6 +1081,17 @@ namespace PhWidgets //! Converts Widget to constant Photon widget pointer operator const PtWidget_t*() const; + //! Brings the widget to the front of the z-order. + /*! + The widget is moved to the front of the z-order. + If the widget is a child of another widget, the child widget is moved to the front of the z-order. + BringToFront() does not make a widget a top-level widget, and it does not raise the Widget::Paint event. + + @see + - SendToBack() + */ + void BringToFront(); + //! Sets input focus to the widget. /*! @return `true` if the input focus request was successful; otherwise, `false`. @@ -1113,7 +1124,7 @@ namespace PhWidgets - ProgressBar - Splitter - Label - - LinkLabel (when there is no link present in the control) + - LinkLabel (when there is no link present in the widget) */ bool Focus(); @@ -1136,6 +1147,20 @@ namespace PhWidgets */ Widget GetNextWidget(Widget widget, bool forward = true) const; + //! Sends the widget to the back of the z-order. + /*! + The widget is moved to the back of the z-order. + If the widget is a child of another widget, the child widget is moved to the back of the z-order. + If the widget is a top-level widget, this method will not work correctly unless the widget is active. + A top-level widget is a widget, such as a Form, that is not a child of another widget. + An active widget is a visible widget that has input focus. + To use the SendToBack() method with an inactive, top-level widget, first call the BringToFront() method on the widget. + + @see + - BringToFront() + */ + void SendToBack(); + //@{ //! Sets the bounds of the widget to the specified location and size. /*! From 60ec919f8f1f0aa0669ec90d744d2d92153967db Mon Sep 17 00:00:00 2001 From: Alexander <0oktonion0@gmail.com> Date: Sun, 4 Aug 2019 17:36:45 +0300 Subject: [PATCH 2/3] Update PhWidgetsFunc.cpp check for nullptr --- src/service/PhWidgetsFunc.cpp | 151 +++++++++++++++++----------------- 1 file changed, 77 insertions(+), 74 deletions(-) diff --git a/src/service/PhWidgetsFunc.cpp b/src/service/PhWidgetsFunc.cpp index 8e4dd007..455d230c 100644 --- a/src/service/PhWidgetsFunc.cpp +++ b/src/service/PhWidgetsFunc.cpp @@ -20,80 +20,83 @@ namespace PhWidgets { const char * WidgetClassName(PtWidget_t *wdg) { - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtArc); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBarGraph); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBasic); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBezier); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBkgd); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtButton); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtCalendar); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtClient); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtClock); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorPanel); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorPatch); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorSel); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorSelGroup); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorWell); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtComboBox); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtCompound); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtContainer); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtDisjoint); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtDivider); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtEllipse); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtFileSel); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtFontSel); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGauge); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGenList); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGenTree); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGraphic); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGrid); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGroup); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtImageArea); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtLabel); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtLine); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtList); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMenu); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMenuBar); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMenuButton); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMeter); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMtrend); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMultitext); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtNumeric); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtNumericFloat); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtNumericInteger); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtOnOffButton); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtOSContainer); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPane); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPanelGroup); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPixel); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPolygon); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPrintSel); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtProgress); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRaw); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRawList); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRawTree); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRect); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRegion); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtScrollArea); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtScrollBar); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtScrollContainer); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtSeparator); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtServer); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtSlider); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTab); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTerminal); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtText); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTimer); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtToggleButton); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtToolbar); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtToolbarGroup); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTree); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTrend); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTty); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtUpDown); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtWebClient); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtWidget); - RETURN_PHWIDGETS_CLASS_NAME(wdg, PtWindow); + if(wdg) + { + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtArc); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBarGraph); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBasic); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBezier); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtBkgd); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtButton); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtCalendar); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtClient); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtClock); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorPanel); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorPatch); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorSel); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorSelGroup); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtColorWell); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtComboBox); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtCompound); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtContainer); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtDisjoint); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtDivider); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtEllipse); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtFileSel); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtFontSel); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGauge); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGenList); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGenTree); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGraphic); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGrid); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtGroup); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtImageArea); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtLabel); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtLine); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtList); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMenu); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMenuBar); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMenuButton); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMeter); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMtrend); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtMultitext); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtNumeric); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtNumericFloat); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtNumericInteger); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtOnOffButton); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtOSContainer); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPane); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPanelGroup); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPixel); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPolygon); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtPrintSel); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtProgress); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRaw); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRawList); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRawTree); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRect); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtRegion); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtScrollArea); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtScrollBar); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtScrollContainer); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtSeparator); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtServer); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtSlider); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTab); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTerminal); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtText); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTimer); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtToggleButton); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtToolbar); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtToolbarGroup); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTree); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTrend); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtTty); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtUpDown); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtWebClient); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtWidget); + RETURN_PHWIDGETS_CLASS_NAME(wdg, PtWindow); + } return "Unknown"; } From f16deca3d185cea65741d6c9869a189fa7d04cb4 Mon Sep 17 00:00:00 2001 From: Alexander <0oktonion0@gmail.com> Date: Sun, 4 Aug 2019 17:37:15 +0300 Subject: [PATCH 3/3] + Widget::Contains() --- src/Widget.cpp | 40 +++++++++++++++++++++++++++++++++++----- src/Widget.h | 32 +++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Widget.cpp b/src/Widget.cpp index 9313b70f..0f1f88bd 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -496,6 +496,29 @@ void Widget::BringToFront() PtWidgetToFront(widget()); } +bool Widget::Contains(const Widget &widget) +{ + PtWidget_t *this_widget = this->widget(); + + if(false == PtIsContainer(this_widget)) + return false; + + PtWidget_t *front = PtWidgetChildFront(this_widget); + + if(NULL == front) + return false; + + PtWidget_t *other_widget = widget.widget(); + + for(PtWidget_t *next = front; next != NULL; next = PtWidgetBrotherBehind(next)) + { + if(next == other_widget) + return true; + } + + return false; +} + void Widget::SetBounds(short x, short y, unsigned short width, unsigned short height) { PhDim_t size; @@ -525,18 +548,25 @@ bool Widget::Focus() return PtGiveFocus(widget(), nullptr) != nullptr; } -Widget Widget::GetNextWidget(Widget widget, bool forward) const +Widget Widget::GetNextWidget(const Widget &widget, bool forward) const { PtWidget_t *this_widget = this->widget(); PtWidget_t *result = forward ? - PtWidgetChildFront(this_widget): - PtWidgetChildBack(this_widget); + PtWidgetBrotherInFront(this_widget): + PtWidgetBrotherBehind(this_widget); if(NULL == result) - throw( - std::out_of_range(std::string("PhWidgets::Widget::GetNextWidget(): \'") + WidgetClassName(this_widget) + "\' widget has no children")); + { + result = + forward ? + PtWidgetBrotherBehind(this_widget): + PtWidgetBrotherInFront(this_widget); + } + + if(NULL == result) + return *this; return Widget(result); } diff --git a/src/Widget.h b/src/Widget.h index b3dec7b3..200fd2f7 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -1092,6 +1092,36 @@ namespace PhWidgets */ void BringToFront(); + //! Retrieves a value indicating whether the specified widget is a child of the widget. + /*! + @param[in] widget The Widget to evaluate. + @returns `true` if the specified widget is a child of the widget; otherwise, `false`. + + ### Examples ### + + The following code example ensures that a Label is visible by calling its BringToFront() method. + This example requires that you have a Window `main_window` with a Label named `label1`. + + @code + void MakeLabelVisible() + { + // If the window contains label1, bring it + // to the front to make sure it is visible. + + if(main_window.Contains(label1)) + { + label1.BringToFront(); + } + } + @endcode + + @see + - BringToFront() + - SendToBack() + - Widgets + */ + bool Contains(const Widget &widget); + //! Sets input focus to the widget. /*! @return `true` if the input focus request was successful; otherwise, `false`. @@ -1145,7 +1175,7 @@ namespace PhWidgets - Container::ActiveWidget - Widgets */ - Widget GetNextWidget(Widget widget, bool forward = true) const; + Widget GetNextWidget(const Widget &widget, bool forward = true) const; //! Sends the widget to the back of the z-order. /*!