[haiku-commits] haiku: hrev47939 - src/tests/kits/interface/btextcontrol src/tests/kits/interface headers/os/interface src/kits/interface

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 1 Oct 2014 12:11:43 +0200 (CEST)

hrev47939 adds 2 changesets to branch 'master'
old head: a8f520f2a879ce83582bc6b9d8206bb860ecedb8
new head: 13d147b12ba4c8276daf6ecb858424d358389a16
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=13d147b+%5Ea8f520f

----------------------------------------------------------------------------

48ea56b: Interface Kit tests: add test for BTextControl.
  
  * Only tests very basic functionality, and size of the class, which must
  not change for BeOS compatibility.
  * Also add "manual" test for disabled and invalid controls (just check
  it looks right)

13d147b: Introduce "invalid" text controls.
  
  * MarkAsInvalid is used to enable or disable the mark
  * The B_INVALID BControlLook flag is used
  * invalid BTextControls are drawn with a red border.
  * You ar encouraged to let the user know more precisely what's wrong, by
  showing an helpful error message next to the control or in a tooltip.

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

8 files changed, 82 insertions(+), 3 deletions(-)
headers/os/interface/ControlLook.h               |  3 +-
headers/os/interface/TextControl.h               |  4 +-
src/kits/interface/TextControl.cpp               | 14 ++++++-
.../kits/interface/InterfaceKitTestAddon.cpp     |  2 +
src/tests/kits/interface/Jamfile                 |  2 +
src/tests/kits/interface/TextViewTestManual.cpp  | 11 ++++++
.../interface/btextcontrol/TextControlTest.cpp   | 39 ++++++++++++++++++++
.../interface/btextcontrol/TextControlTest.h     | 10 +++++

############################################################################

Commit:      48ea56bf32984ba755591526b1f2a8ab82bc9eff
URL:         http://cgit.haiku-os.org/haiku/commit/?id=48ea56b
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Wed Oct  1 09:32:18 2014 UTC

Interface Kit tests: add test for BTextControl.

* Only tests very basic functionality, and size of the class, which must
not change for BeOS compatibility.
* Also add "manual" test for disabled and invalid controls (just check
it looks right)

----------------------------------------------------------------------------

diff --git a/src/tests/kits/interface/InterfaceKitTestAddon.cpp 
b/src/tests/kits/interface/InterfaceKitTestAddon.cpp
index da48c61..f5a556f 100644
--- a/src/tests/kits/interface/InterfaceKitTestAddon.cpp
+++ b/src/tests/kits/interface/InterfaceKitTestAddon.cpp
@@ -7,6 +7,7 @@
 #include "bdeskbar/DeskbarTest.h"
 #include "bpolygon/PolygonTest.h"
 #include "bregion/RegionTest.h"
+#include "btextcontrol/TextControlTest.h"
 #include "btextview/TextViewTest.h"
 //#include "bwidthbuffer/WidthBufferTest.h"
 #include "GraphicsDefsTest.h"
@@ -23,6 +24,7 @@ getTestSuite()
        suite->addTest("BDeskbar", DeskbarTestSuite());
        suite->addTest("BPolygon", PolygonTestSuite());
        suite->addTest("BRegion", RegionTestSuite());
+       suite->addTest("BTextControl", TextControlTestSuite());
        suite->addTest("BTextView", TextViewTestSuite());
        //suite->addTest("_BWidthBuffer_", WidthBufferTestSuite());
        suite->addTest("GraphicsDefs", GraphicsDefsTestSuite());
diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile
index 1e41059..f053dee 100644
--- a/src/tests/kits/interface/Jamfile
+++ b/src/tests/kits/interface/Jamfile
@@ -11,6 +11,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) bbitmap ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ;
+SEARCH_SOURCE += [ FDirName $(SUBDIR) btextcontrol ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) btextview ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) bwindowstack ] ;
 
@@ -50,6 +51,7 @@ UnitTestLib libinterfacetest.so
                RegionIntersect.cpp
                RegionOffsetBy.cpp
 
+               TextControlTest.cpp
                TextViewTest.cpp
 
        : be [ TargetLibstdc++ ]
diff --git a/src/tests/kits/interface/TextViewTestManual.cpp 
b/src/tests/kits/interface/TextViewTestManual.cpp
index 0b14625..9bbc040 100644
--- a/src/tests/kits/interface/TextViewTestManual.cpp
+++ b/src/tests/kits/interface/TextViewTestManual.cpp
@@ -6,6 +6,7 @@
 
 #include <Application.h>
 #include <Button.h>
+#include <ControlLook.h>
 #include <GroupLayout.h>
 #include <GroupLayoutBuilder.h>
 #include <ScrollView.h>
@@ -44,6 +45,14 @@ Window::Window()
 {
        fTextControl = new BTextControl("text-contr-O",
                "a single line of text - (c) Conglom-O", NULL);
+
+       BTextControl* disabled = new BTextControl("disabled",
+               "I'm disabled: you can't edit me", NULL);
+       disabled->SetEnabled(false);
+       BTextControl* invalid = new BTextControl("invalid",
+               "I'm invalid: my border is red", NULL);
+       invalid->MarkAsInvalid(true);
+
        fTextView = new BTextView("text-O");
        BScrollView* scrollView = new BScrollView("scroll-O", fTextView, 0, 
true,
                true, B_FANCY_BORDER);
@@ -51,6 +60,8 @@ Window::Window()
        SetLayout(new BGroupLayout(B_HORIZONTAL));
        AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
                .Add(fTextControl)
+               .Add(disabled)
+               .Add(invalid)
                .Add(scrollView)
                .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
                        .Add(new BButton("Align Left", new 
BMessage(kMsgAlignLeft)))
diff --git a/src/tests/kits/interface/btextcontrol/TextControlTest.cpp 
b/src/tests/kits/interface/btextcontrol/TextControlTest.cpp
new file mode 100644
index 0000000..739f13c
--- /dev/null
+++ b/src/tests/kits/interface/btextcontrol/TextControlTest.cpp
@@ -0,0 +1,39 @@
+#include "../common.h"
+
+#include <Application.h>
+#include <String.h>
+#include <TextControl.h>
+
+class TextControlTestcase: public TestCase {
+public:
+       void
+       SizeTest()
+       {
+               CPPUNIT_ASSERT_EQUAL(312, sizeof(BTextControl));
+       }
+
+       void
+       GetTextTest()
+       {
+               BApplication 
app("application/x-vnd.Haiku-interfacekit-textcontroltest");
+               BRect textRect(0, 0, 100, 100);
+               BTextControl* v = new BTextControl(textRect, "test", 0, 0, 0);
+               v->SetText("Initial text");
+               v->TextView()->Insert(8, "(inserted) ", 10);
+               CPPUNIT_ASSERT_EQUAL(BString("Initial (inserted)text"), 
v->Text());
+       }
+};
+
+
+Test*
+TextControlTestSuite()
+{
+       TestSuite *testSuite = new TestSuite();
+
+       testSuite->addTest(new CppUnit::TestCaller<TextControlTestcase>(
+               "BTextControl_Size", &TextControlTestcase::SizeTest));
+       testSuite->addTest(new CppUnit::TestCaller<TextControlTestcase>(
+               "BTextControl_GetText", &TextControlTestcase::GetTextTest));
+
+       return testSuite;
+}
diff --git a/src/tests/kits/interface/btextcontrol/TextControlTest.h 
b/src/tests/kits/interface/btextcontrol/TextControlTest.h
new file mode 100644
index 0000000..2c62902
--- /dev/null
+++ b/src/tests/kits/interface/btextcontrol/TextControlTest.h
@@ -0,0 +1,10 @@
+#ifndef _text_control_test_h_
+#define _text_control_test_h_
+
+class CppUnit::Test;
+
+CppUnit::Test *TextControlTestSuite();
+
+#endif // text_control_test_h_
+
+

############################################################################

Revision:    hrev47939
Commit:      13d147b12ba4c8276daf6ecb858424d358389a16
URL:         http://cgit.haiku-os.org/haiku/commit/?id=13d147b
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Wed Oct  1 10:09:27 2014 UTC

Introduce "invalid" text controls.

* MarkAsInvalid is used to enable or disable the mark
* The B_INVALID BControlLook flag is used
* invalid BTextControls are drawn with a red border.
* You ar encouraged to let the user know more precisely what's wrong, by
showing an helpful error message next to the control or in a tooltip.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/ControlLook.h 
b/headers/os/interface/ControlLook.h
index ec44762..6de91e2 100644
--- a/headers/os/interface/ControlLook.h
+++ b/headers/os/interface/ControlLook.h
@@ -84,8 +84,9 @@ public:
                B_IGNORE_OUTLINE                = 1 << 6,
                B_PARTIALLY_ACTIVATED   = 1 << 7, // like B_ACTIVATED, but for 
tri-state
                B_FLAT                                  = 1 << 8, // flat look 
(e.g. button background)
+               B_INVALID                               = 1 << 9, // invalid 
value, use B_FAILURE_COLOR
 
-               B_BLEND_FRAME           = 1 << 16
+               B_BLEND_FRAME                   = 1 << 16,
        };
 
        virtual BAlignment                      DefaultLabelAlignment() const;
diff --git a/headers/os/interface/TextControl.h 
b/headers/os/interface/TextControl.h
index 05bf6de..95906b3 100644
--- a/headers/os/interface/TextControl.h
+++ b/headers/os/interface/TextControl.h
@@ -40,6 +40,7 @@ public:
 
        virtual void                            SetText(const char* text);
                        const char*                     Text() const;
+                       void                            MarkAsInvalid(bool 
invalid);
 
        virtual void                            SetValue(int32 value);
        virtual status_t                        Invoke(BMessage* message = 
NULL);
@@ -139,8 +140,9 @@ private:
                        float                           fDivider;
 
                        LayoutData*                     fLayoutData;
+                       uint32                          fLook;
 
-                       uint32                          _reserved[9];
+                       uint32                          _reserved[8];
 };
 
 #endif // _TEXT_CONTROL_H
diff --git a/src/kits/interface/TextControl.cpp 
b/src/kits/interface/TextControl.cpp
index f4828d6..caabbbe 100644
--- a/src/kits/interface/TextControl.cpp
+++ b/src/kits/interface/TextControl.cpp
@@ -334,6 +334,16 @@ BTextControl::Text() const
 
 
 void
+BTextControl::MarkAsInvalid(bool invalid)
+{
+       if (invalid)
+               fLook |= BControlLook::B_INVALID;
+       else
+               fLook &= ~BControlLook::B_INVALID;
+}
+
+
+void
 BTextControl::SetValue(int32 value)
 {
        BControl::SetValue(value);
@@ -425,7 +435,7 @@ BTextControl::Draw(BRect updateRect)
 
        if (be_control_look != NULL) {
                rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
-               uint32 flags = 0;
+               uint32 flags = fLook;
                if (!enabled)
                        flags |= BControlLook::B_DISABLED;
                if (active)
@@ -1122,6 +1132,8 @@ BTextControl::_InitData(const char* label, const 
BMessage* archive)
 
        if (label)
                fDivider = floorf(bounds.Width() / 2.0f);
+
+       fLook = 0;
 }
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev47939 - src/tests/kits/interface/btextcontrol src/tests/kits/interface headers/os/interface src/kits/interface - pulkomandy