libyui-rest-api
 
Loading...
Searching...
No Matches
YWidgetActionHandler.h
1/*
2 Copyright (C) 2020 SUSE LLC
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) version 3.0 of the License. This library
8 is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 License for more details. You should have received a copy of the GNU
12 Lesser General Public License along with this library; if not, write
13 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14 Floor, Boston, MA 02110-1301 USA
15*/
16
17#ifndef YWidgetActionHandler_h
18#define YWidgetActionHandler_h
19
20#include <iostream>
21#include <functional>
22#include <microhttpd.h>
23#include <sstream>
24#include <boost/algorithm/string.hpp>
25
26#define TreePathDelimiter "|"
27#define ShortcutChar "&"
28
29#include <yui/YCheckBoxFrame.h>
30#include <yui/YComboBox.h>
31#include <yui/YDateField.h>
32#include <yui/YInputField.h>
33#include <yui/YItem.h>
34#include <yui/YMenuItem.h>
35#include <yui/YMultiSelectionBox.h>
36#include <yui/YRadioButton.h>
37#include <yui/YSelectionBox.h>
38#include <yui/YTimeField.h>
39#include <yui/YWidget.h>
40
41#include "YHttpHandler.h"
42#include "YWidgetFinder.h"
43
44class YWidgetActionHandler
45{
46
47public:
48
49 YWidgetActionHandler() {}
50 virtual ~YWidgetActionHandler() {}
51
57 template<typename T>
58 void activate_widget( T * widget ) {
59 widget->activate();
60 }
61
67 virtual void activate_widget( YCheckBoxFrame * widget ) {};
68 virtual void activate_widget( YComboBox * widget ) {};
69 virtual void activate_widget( YDateField * widget ) {};
70 virtual void activate_widget( YInputField * widget ) {};
71 virtual void activate_widget( YRadioButton * widget ) {};
72 virtual void activate_widget( YTimeField * widget ) {};
73 virtual void activate_widget( YSelectionBox * widget ) {};
74
79 template<typename T, typename I >
80 void activate_widget( T * selector, I *item ) {
81 selector->activateItem( item );
82 }
83
84 virtual void activate_widget( YMultiSelectionBox * widget, YItem * item ) {};
85
86 template<typename T>
87 std::function<void (T*)> get_item_selector_handler( T *widget, const std::string &value, const int state = -1 ) {
88 return [&] (T *selector) {
89 YItem * item = selector->findItem( value );
90 if ( item )
91 {
92 selector->setKeyboardFocus();
93 // Toggle in case state selector undefined
94 bool select = state < 0 ? !item->selected() : (state != 0);
95 if( state < 0 )
96 {
97 select = !item->selected();
98 }
99 else
100 {
101 select = (state != 0);
102 }
103 item->setSelected( select );
104 selector->selectItem( item, select );
105 activate_widget( selector, item );
106 }
107 else
108 {
109 throw YUIException("Item: '" + value + "' cannot be found in the item selector widget");
110 }
111 };
112 }
113
114 // Normalize a label before comparing it for equality:
115 // - remove shortcut characters (&)
116 // - remove BiDi control characters (added to certain table cells to render pathnames correctly)
117 static std::string normalize_label(const std::string & label);
118
119 // Apply normalize_label to both arguments and compare the result with ==.
120 static bool normalized_labels_equal(const std::string & a, const std::string & b)
121 {
122 std::string na = normalize_label(a);
123 std::string nb = normalize_label(b);
124 return na == nb;
125 }
126};
127
128#endif //YWidgetActionHandler_h
void activate_widget(T *widget)
Definition YWidgetActionHandler.h:58
void activate_widget(T *selector, I *item)
Definition YWidgetActionHandler.h:80
virtual void activate_widget(YCheckBoxFrame *widget)
Definition YWidgetActionHandler.h:67