1
-
2
1
#include <stdio.h>
3
2
#include <LCUI.h>
4
3
#include <LCDesign.h>
4
+ #include <LCUI/input.h>
5
5
#include <LCUI/timer.h>
6
6
#include <LCUI/gui/widget.h>
7
7
#include <LCUI/gui/widget/textedit.h>
@@ -21,7 +21,7 @@ typedef struct FrameViewRec_ {
21
21
LCUI_Widget input ;
22
22
LCUI_Widget content ;
23
23
LCUI_Widget client ;
24
- LCUI_Widget vscrollbar ;
24
+ LCUI_Widget scrollbar ;
25
25
LCUI_Widget hscrollbar ;
26
26
} FrameViewRec , * FrameView ;
27
27
@@ -57,15 +57,27 @@ static void BrowserView_UpdateNavbar(void *arg)
57
57
static void FrameView_OnBtnBackClick (LCUI_Widget w , LCUI_WidgetEvent e ,
58
58
void * arg )
59
59
{
60
+ if (w -> disabled ) {
61
+ return ;
62
+ }
60
63
router_back (((FrameView )e -> data )-> router );
61
64
}
62
65
63
66
static void FrameView_OnBtnForwardClick (LCUI_Widget w , LCUI_WidgetEvent e ,
64
- void * arg )
67
+ void * arg )
65
68
{
69
+ if (w -> disabled ) {
70
+ return ;
71
+ }
66
72
router_forward (((FrameView )e -> data )-> router );
67
73
}
68
74
75
+ static void FrameView_OnBtnRefreshClick (LCUI_Widget w , LCUI_WidgetEvent e ,
76
+ void * arg )
77
+ {
78
+ router_go (((FrameView )e -> data )-> router , 0 );
79
+ }
80
+
69
81
static void FrameView_OnBtnHomeClick (LCUI_Widget w , LCUI_WidgetEvent e ,
70
82
void * arg )
71
83
{
@@ -78,18 +90,45 @@ static void FrameView_OnBtnHomeClick(LCUI_Widget w, LCUI_WidgetEvent e,
78
90
router_location_destroy (location );
79
91
}
80
92
93
+ static void FrameView_OnInputKeydown (LCUI_Widget w , LCUI_WidgetEvent e ,
94
+ void * arg )
95
+ {
96
+ char * path ;
97
+ size_t len ;
98
+ wchar_t raw_path [1024 ];
99
+ router_location_t * location ;
100
+ FrameView self ;
101
+
102
+ if (e -> key .code != LCUI_KEY_ENTER ) {
103
+ return ;
104
+ }
105
+ self = e -> data ;
106
+ len = TextEdit_GetTextW (self -> input , 0 , 1023 , raw_path );
107
+ raw_path [len ] = 0 ;
108
+ len = LCUI_EncodeUTF8String (NULL , raw_path , 1023 );
109
+ path = malloc (len * (sizeof (char ) + 1 ));
110
+ len = LCUI_EncodeUTF8String (path , raw_path , 1023 );
111
+ path [len ] = 0 ;
112
+ location = router_location_create (NULL , path );
113
+ router_push (self -> router , location );
114
+ router_location_destroy (location );
115
+ }
116
+
81
117
static void FrameView_OnRouteUpdate (void * arg , const router_route_t * to ,
82
118
const router_route_t * from )
83
119
{
84
120
const char * path ;
85
121
FrameView self ;
122
+ LCUI_WidgetEventRec e ;
86
123
87
124
self = Widget_GetData (arg , frame_proto );
88
125
if (to ) {
89
126
path = router_route_get_full_path (to );
90
127
TextEdit_SetText (self -> input , path );
91
128
}
92
129
LCUI_SetTimeout (0 , BrowserView_UpdateNavbar , arg );
130
+ LCUI_InitWidgetEvent (& e , "PageLoad" );
131
+ Widget_TriggerEvent (arg , & e , NULL );
93
132
}
94
133
95
134
static void FrameView_OnInit (LCUI_Widget w )
@@ -110,11 +149,8 @@ static void FrameView_OnInit(LCUI_Widget w)
110
149
self -> input = LCUIWidget_New ("textedit" );
111
150
self -> content = LCUIWidget_New ("router-view" );
112
151
self -> client = LCUIWidget_New (NULL );
113
- self -> vscrollbar = LCUIWidget_New ("scrollbar" );
114
- //self->hscrollbar = LCUIWidget_New("scrollbar");
115
- //ScrollBar_BindTarget(self->hscrollbar, self->content);
116
- ScrollBar_BindTarget (self -> vscrollbar , self -> content );
117
- //ScrollBar_SetDirection(self->hscrollbar, SBD_HORIZONTAL);
152
+ self -> scrollbar = LCUIWidget_New ("scrollbar" );
153
+ ScrollBar_BindTarget (self -> scrollbar , self -> content );
118
154
Widget_SetAttribute (w , "router" , router_name );
119
155
Widget_AddClass (w , "v-frame" );
120
156
Widget_AddClass (self -> navbar , "c-navbar v-frame__navbar" );
@@ -131,20 +167,23 @@ static void FrameView_OnInit(LCUI_Widget w)
131
167
Widget_Append (self -> navbar , self -> btn_home );
132
168
Widget_Append (self -> navbar , self -> input );
133
169
Widget_Append (self -> client , self -> content );
134
- Widget_Append (self -> client , self -> vscrollbar );
135
- //Widget_Append(self->client, self->hscrollbar);
170
+ Widget_Append (self -> client , self -> scrollbar );
136
171
Icon_SetName (self -> btn_back , "arrow-left" );
137
172
Icon_SetName (self -> btn_forward , "arrow-right" );
138
173
Icon_SetName (self -> btn_refresh , "refresh" );
139
174
Icon_SetName (self -> btn_home , "home-outline" );
140
175
Widget_BindEvent (self -> btn_back , "click" , FrameView_OnBtnBackClick ,
141
176
self , NULL );
142
- Widget_BindEvent (self -> btn_forward , "click" , FrameView_OnBtnForwardClick ,
143
- self , NULL );
177
+ Widget_BindEvent (self -> btn_forward , "click" ,
178
+ FrameView_OnBtnForwardClick , self , NULL );
144
179
Widget_BindEvent (self -> btn_home , "click" , FrameView_OnBtnHomeClick ,
145
180
self , NULL );
181
+ Widget_BindEvent (self -> btn_refresh , "click" ,
182
+ FrameView_OnBtnRefreshClick , self , NULL );
183
+ Widget_BindEvent (self -> input , "keydown" , FrameView_OnInputKeydown , self , NULL );
146
184
Widget_Append (w , self -> navbar );
147
185
Widget_Append (w , self -> client );
186
+ Widget_SetId (w , router_name );
148
187
FrameView_OnRouteUpdate (w , router_get_current_route (self -> router ),
149
188
NULL );
150
189
}
@@ -161,13 +200,9 @@ static void FrameView_OnDestroy(LCUI_Widget w)
161
200
void FrameView_Load (LCUI_Widget w , const char * path )
162
201
{
163
202
router_location_t * location ;
164
-
165
203
FrameView self ;
166
- LCUI_WidgetEventRec e ;
167
204
168
205
Widget_Update (w );
169
- LCUI_InitWidgetEvent (& e , "PageLoad" );
170
- Widget_TriggerEvent (w , & e , NULL );
171
206
location = router_location_create (NULL , path );
172
207
self = Widget_GetData (w , frame_proto );
173
208
router_push (self -> router , location );
0 commit comments