void rtgui_workbench_hide_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
{
	RT_ASSERT(workbench != RT_NULL);
	RT_ASSERT(view != RT_NULL);

	/* hide view */
	RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));

	if (view == workbench->current_view)
	{
		rtgui_view_t *next_view;

		workbench->current_view = RT_NULL;

		next_view = RTGUI_VIEW(rtgui_widget_get_next_sibling(RTGUI_WIDGET(view)));
		if (next_view == RT_NULL)
			next_view = RTGUI_VIEW(rtgui_widget_get_prev_sibling(RTGUI_WIDGET(view)));

		if (next_view != RT_NULL)
		{
			rtgui_view_show(next_view, RT_FALSE);
		}
		else
		{
			/* update workbench clip */
			rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
		}
	}
}
Beispiel #2
0
void rtgui_win_hiden(struct rtgui_win* win)
{
    RT_ASSERT(win != RT_NULL);
#ifdef RTGUI_USING_DESKTOP_WINDOW
    RT_ASSERT(win != the_desktop_window);
#endif

    if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) &&
            win->flag & RTGUI_WIN_FLAG_CONNECTED)
    {
        /* send hidden message to server */
        struct rtgui_event_win_hide ehide;
        RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
        ehide.wid = win;

        if (rtgui_server_post_event_sync(RTGUI_EVENT(&ehide),
                                         sizeof(struct rtgui_event_win_hide)) != RT_EOK)
        {
            rt_kprintf("hide win: %s failed\n", win->title);
            return;
        }

        /* set window hide and deactivated */
        RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
        win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
    }
}
void rtgui_workbench_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
{
	RT_ASSERT(workbench != RT_NULL);
	RT_ASSERT(view != RT_NULL);

	/* already shown */
	if (workbench->current_view == view) return;

	if (workbench->current_view != RT_NULL)
	{
		/* hide old view */
		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench->current_view));
	}

	/* show view */
	RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view));
	workbench->current_view = view;

	/* update workbench clip */
	rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));

	if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(workbench)))
	{
		rtgui_widget_update(RTGUI_WIDGET(view));
	}
}
Beispiel #4
0
static void _rtgui_win_constructor(rtgui_win_t *win)
{
    RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
    win->parent_window = RT_NULL;
    /* init window attribute */
    win->on_activate   = RT_NULL;
    win->on_deactivate = RT_NULL;
    win->on_close      = RT_NULL;
    win->on_key        = RT_NULL;
    win->title         = RT_NULL;
    win->modal_code    = RTGUI_MODAL_OK;

    /* initialize last mouse event handled widget */
    win->last_mevent_widget = RT_NULL;
    win->focused_widget	= RT_NULL;

    /* set window hide */
    RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));

    /* set window style */
    win->style = RTGUI_WIN_STYLE_DEFAULT;

    win->flag  = RTGUI_WIN_FLAG_INIT;

    rtgui_object_set_event_handler(RTGUI_OBJECT(win), rtgui_win_event_handler);

    /* init user data */
    win->user_data = 0;
}
Beispiel #5
0
void rtgui_win_move(struct rtgui_win* win, int x, int y)
{
    struct rtgui_event_win_move emove;
    RTGUI_EVENT_WIN_MOVE_INIT(&emove);

    if (win == RT_NULL)
        return;

    /* move window to logic position */
    rtgui_widget_move_to_logic(RTGUI_WIDGET(win),
                               x - RTGUI_WIDGET(win)->extent.x1,
                               y - RTGUI_WIDGET(win)->extent.y1);

    if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
    {
        /* set win hide firstly */
        RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));

        emove.wid	= win;
        emove.x		= x;
        emove.y		= y;
        if (rtgui_server_post_event_sync(RTGUI_EVENT(&emove),
                                         sizeof(struct rtgui_event_win_move)) != RT_EOK)
        {
            return;
        }
    }

    /* set window visible */
    RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
    return;
}
Beispiel #6
0
Datei: edit.c Projekt: amsl/RTGUI
void rtgui_edit_adjust_scroll(rtgui_scrollbar_t *bar)
{
	struct rtgui_edit *edit;
	
	RT_ASSERT(bar != RT_NULL);
	
	if(bar->WIDGET_GROUP != RT_NULL)
	{
		rtgui_rect_t rect;
		rt_uint32_t _left=0,_top=0,_width=RTGUI_DEFAULT_SB_WIDTH,_len=0;

		edit = bar->WIDGET_GROUP;
		rtgui_widget_get_rect(edit, &rect);
		rtgui_widget_rect_to_device(edit,&rect);
		if(bar->orient==RTGUI_HORIZONTAL)
		{
			if(RTGUI_WIDGET_IS_HIDE(edit->hscroll))
			{
				if(edit->max_rows > edit->row_per_page)
				{
					RTGUI_WIDGET_SHOW(edit->hscroll);
					rtgui_scrollbar_set_line_step(edit->hscroll, 1);
					rtgui_scrollbar_set_page_step(edit->hscroll, edit->row_per_page);
					rtgui_scrollbar_set_range(edit->hscroll, edit->max_rows);
				}
				else
					RTGUI_WIDGET_HIDE(edit->vscroll);
				rtgui_widget_update_clip(RTGUI_WIDGET(edit));
			}
			else
			{
				_left = RTGUI_WIDGET_BORDER_SIZE(edit);
				_top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
				_len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
				
				if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll)) 
					_len -= _width;
				rect.x1 += _left;
				rect.y1 += _top;
				rect.x2 = rect.x1+_len;
				rect.y2 = rect.y1+_width;
			}
		}
		else if(bar->orient==RTGUI_VERTICAL)
		{
			_left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_top = RTGUI_WIDGET_BORDER_SIZE(edit);
			_len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			
			if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll))  
				_len -= _width;
			rect.x1 += _left;
			rect.y1 += _top;
			rect.x2 = rect.x1+_width;
			rect.y2 = rect.y1+_len;
		}
		rtgui_widget_set_rect(bar,&rect);
	}
}
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
{
	rtgui_container_add_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
	/* hide view in default */
	RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));

	/* reset view extent */
	rtgui_widget_set_rect(RTGUI_WIDGET(view), &(RTGUI_WIDGET(workbench)->extent));
}
Beispiel #8
0
rtgui_fileview_t* rtgui_fileview_create(pvoid parent, const char* directory, const char* pattern, int left, int top, int w, int h)
{
	rtgui_container_t *container;
	rtgui_fileview_t* fview = RT_NULL;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	/* create a new view */
	fview = rtgui_widget_create(RTGUI_FILEVIEW_TYPE);

	if(fview != RT_NULL)
	{
		rtgui_rect_t rect;

		rtgui_widget_get_rect(container, &rect);
		rtgui_widget_rect_to_device(container,&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+h;

		fview->items = RT_NULL;
		fview->pattern = rt_strdup(pattern);
		fview->item_per_page = RC_H(rect) / (1 + RTGUI_SEL_H);

		rtgui_widget_set_rect(fview,&rect);
		rtgui_container_add_child(container, fview);

		{
			/* create scrollbar */
			rt_uint32_t sLeft,sTop,sw=RTGUI_DEFAULT_SB_WIDTH,sLen;
			sLeft = RC_W(rect)-RTGUI_WIDGET_BORDER_SIZE(fview)-sw;
			sTop = RTGUI_WIDGET_BORDER_SIZE(fview);

			sLen = rect.y2-rect.y1-RTGUI_WIDGET_BORDER_SIZE(fview)*2;
			fview->sbar = rtgui_scrollbar_create(fview,sLeft,sTop,sw,sLen,RTGUI_VERTICAL);
			if(fview->sbar != RT_NULL)
			{
				fview->sbar->widget_link = fview;
				fview->sbar->on_scroll = rtgui_fileview_sbar_handle;
				RTGUI_WIDGET_HIDE(fview->sbar);/* default hid scrollbar */
			}
		}

		rtgui_fileview_set_directory(fview, directory);
	}

	return fview;
}
Beispiel #9
0
void rtgui_combo_add_string(rtgui_combo_t* cbo,const char* string)
{
	if(cbo->lbox != RT_NULL)
	{
		rtgui_listbox_item_t item;
		rtgui_rect_t rect;
		rt_uint32_t h,count;

		item.name = (char*)string;
		item.image = RT_NULL;
		rtgui_listbox_add_item(cbo->lbox, &item, 1);

		rtgui_widget_get_rect(cbo->lbox, &rect);
		count = rtgui_listbox_get_count(cbo->lbox);

		h = RTGUI_WIDGET_BORDER_SIZE(cbo->lbox)*2+(RTGUI_SEL_H + 2)*count;

		if(h>RC_H(rect))
		{
			if(cbo->lbox->item_per_page<5)/* change when less than five */
			{
				rect.y2 = rect.y1+h;
				rtgui_widget_rect_to_device(cbo->lbox,&rect);
				rtgui_widget_set_rect(cbo->lbox,&rect);/* update listbox extent */
				cbo->lbox->item_per_page = RC_H(rect) / (RTGUI_SEL_H+2);

				if(cbo->lbox->scroll != RT_NULL)/* update scrollbar extent */
				{
					rtgui_widget_get_rect(cbo->lbox->scroll, &rect);
					rect.y2 = rect.y1+h-RTGUI_WIDGET_BORDER_SIZE(cbo->lbox)*2;
					rtgui_widget_rect_to_device(cbo->lbox->scroll,&rect);
					rtgui_widget_set_rect(cbo->lbox->scroll,&rect);

					if(cbo->lbox->item_count > cbo->lbox->item_per_page)
					{
						RTGUI_WIDGET_SHOW(cbo->lbox->scroll);
						rtgui_scrollbar_set_line_step(cbo->lbox->scroll, 1);
						rtgui_scrollbar_set_page_step(cbo->lbox->scroll, cbo->lbox->item_per_page);
						rtgui_scrollbar_set_range(cbo->lbox->scroll, cbo->lbox->item_count);
					}
					else
					{
						RTGUI_WIDGET_HIDE(cbo->lbox->scroll);
					}
					rtgui_widget_update_clip(cbo->lbox);
				}
			}
		}
	}
}
Beispiel #10
0
static void _rtgui_win_constructor(rtgui_win_t *win)
{
	/* init window attribute */
	win->on_activate	= RT_NULL;
	win->on_deactivate	= RT_NULL;
	win->on_close		= RT_NULL;
	win->title			= RT_NULL;
	win->modal_code		= RTGUI_MODAL_OK;
	win->modal_widget	= RT_NULL;

	/* set window hide */
	RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));

	/* set window style */
	win->style = RTGUI_WIN_STYLE_DEFAULT;
	rtgui_widget_set_event_handler(RTGUI_WIDGET(win), rtgui_win_event_handler);

	/* init user data */
	win->user_data = 0;
}
Beispiel #11
0
rt_err_t rtgui_workbench_hide(rtgui_workbench_t* workbench)
{
	if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
	{
		struct rtgui_event_panel_hide ehide;
		RTGUI_EVENT_PANEL_HIDE_INIT(&ehide);

		RT_ASSERT(workbench != RT_NULL);
		if (workbench->parent.server == RT_NULL) return -RT_ERROR;

		ehide.panel = workbench->panel;
		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server, RTGUI_EVENT(&ehide),
			sizeof(struct rtgui_event_panel_hide)) != RT_EOK)
			return -RT_ERROR;

		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
		rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
	}

	return RT_EOK;
}
Beispiel #12
0
void rtgui_scrollbar_hide(rtgui_scrollbar_t* bar)
{
	rtgui_rect_t rect;
	struct rtgui_dc* dc;

	RT_ASSERT(bar != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(bar));
	if(dc == RT_NULL)return;

	RTGUI_WIDGET_HIDE(bar);

	/* begin drawing */
	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
	if((RTGUI_WIDGET(bar))->parent != RT_NULL)
		RTGUI_DC_BC(dc) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)->parent);
	else
		RTGUI_DC_BC(dc) = RTGUI_RGB(225, 228, 220);
	rtgui_dc_fill_rect(dc,&rect);

	rtgui_dc_end_drawing(dc);
}
Beispiel #13
0
void rtgui_win_hiden(struct rtgui_win* win)
{
	RT_ASSERT(win != RT_NULL);

	if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) &&
		RTGUI_TOPLEVEL(win)->server != RT_NULL)
	{
		/* send hidden message to server */
		struct rtgui_event_win_hide ehide;
		RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
		ehide.wid = win;

		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&ehide),
			sizeof(struct rtgui_event_win_hide)) != RT_EOK)
		{
			rt_kprintf("hide win: %s failed\n", win->title);
			return;
		}

		/* set window hide and deactivated */
		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
		win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
	}
}
Beispiel #14
0
Datei: edit.c Projekt: amsl/RTGUI
/* set edit text */
void rtgui_edit_set_text(struct rtgui_edit* edit, const char* text)
{
	const char *begin, *ptr;
	int hscroll_flag=0;
	int vscroll_flag=0;

	RT_ASSERT(edit != RT_NULL);

	while(edit->max_rows > 0)
		rtgui_edit_delete_line(edit, edit->head);
	edit->max_rows = 0;

	begin = text;
	for(ptr=begin; *ptr != '\0'; ptr++)
	{
		if(*ptr == 0x0A)
		{	/* unix style */
			rtgui_edit_append_line(edit, begin);
			begin = ptr+1;
		}
		else if(*ptr == 0x0D && *(ptr+1) == 0x0A)
		{	/* windows style */
			rtgui_edit_append_line(edit, begin);
			begin = ptr+2;
		}
	}
	if(*ptr == '\0')
	{
		if(begin < ptr)
			rtgui_edit_append_line(edit, begin);
	}
	
#ifdef RTGUI_EDIT_USING_SCROLL
	if(edit->hscroll != RT_NULL)
	{
		if(edit->max_cols > edit->col_per_page)
		{
			RTGUI_WIDGET_SHOW(edit->hscroll);
			rtgui_scrollbar_set_line_step(edit->hscroll, 1);
			rtgui_scrollbar_set_page_step(edit->hscroll, edit->col_per_page);
			rtgui_scrollbar_set_range(edit->hscroll, edit->max_cols);
			hscroll_flag = 1;
		}
		else
		{
			RTGUI_WIDGET_HIDE(edit->hscroll);
		}
	}
	if(edit->vscroll != RT_NULL)
	{
		if(edit->max_rows > edit->row_per_page)
		{
			RTGUI_WIDGET_SHOW(edit->vscroll);
			rtgui_scrollbar_set_line_step(edit->vscroll, 1);
			rtgui_scrollbar_set_page_step(edit->vscroll, edit->row_per_page);
			rtgui_scrollbar_set_range(edit->vscroll, edit->max_rows);
			vscroll_flag = 1;
		}
		else
		{
			RTGUI_WIDGET_HIDE(edit->vscroll);
		}
	}

	if(edit->hscroll != RT_NULL && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
	{
		rtgui_edit_adjust_scroll(edit->hscroll);
	}
	if(edit->vscroll != RT_NULL && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
	{
		rtgui_edit_adjust_scroll(edit->vscroll);
	}
#endif
	if(hscroll_flag || vscroll_flag)
	{
		rtgui_widget_update_clip(RTGUI_WIDGET(edit));
	}
}
Beispiel #15
0
Datei: edit.c Projekt: amsl/RTGUI
struct rtgui_edit* rtgui_edit_create(pvoid parent, int left, int top, int w, int h)
{
	struct rtgui_container* container;
	struct rtgui_edit* edit;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	edit = (struct rtgui_edit*)rtgui_widget_create(RTGUI_EDIT_TYPE);
	if(edit != RT_NULL)
	{
		rtgui_rect_t rect;
		int effe;
		rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(container),&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+h;
		rtgui_widget_set_rect(RTGUI_WIDGET(edit),&rect);
		rtgui_container_add_child(container, RTGUI_WIDGET(edit));

		/* set character number */
		edit->item_height = edit->font_height; /* the same height */
		effe = h-(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit))*2;
		edit->row_per_page = effe / edit->item_height;
		if(effe % edit->item_height)
			edit->row_per_page += 1;
		
		effe = w-(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit))*2;
		edit->col_per_page = effe / edit->font_width;
		if(effe % edit->font_width)
			edit->col_per_page += 1;
		edit->update_buf = rtgui_malloc(edit->col_per_page + 1);

#ifdef RTGUI_EDIT_USING_SCROLL
		if(edit->hscroll == RT_NULL && edit->flag & RTGUI_EDIT_HSCROLL)
		{
			/* create horizontal scrollbar */
			rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
			_left = RTGUI_WIDGET_BORDER_SIZE(edit);
			_top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			if(edit->max_rows > edit->row_per_page)	_len -= _width;

			edit->hscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_HORIZONTAL);

			if(edit->hscroll != RT_NULL)
			{
				edit->hscroll->WIDGET_GROUP = (pvoid)edit;
				edit->hscroll->on_scroll = rtgui_edit_hscroll_handle;
				RTGUI_WIDGET_HIDE(edit->hscroll);
			}
		}
		if(edit->vscroll == RT_NULL && edit->flag & RTGUI_EDIT_VSCROLL)
		{
			/* create vertical scrollbar */
			rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
			_left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_top = RTGUI_WIDGET_BORDER_SIZE(edit);
			_len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			if(edit->max_cols > edit->col_per_page) _len -= _width;

			edit->vscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_VERTICAL);

			if(edit->vscroll != RT_NULL)
			{
				edit->vscroll->WIDGET_GROUP = (pvoid)edit;
				edit->vscroll->on_scroll = rtgui_edit_vscroll_handle;
				RTGUI_WIDGET_HIDE(edit->vscroll);
			}
		}
#endif
	}

	return edit;
}
Beispiel #16
0
rtgui_combo_t* rtgui_combo_create(pvoid parent,const char* text,int left,int top,int w,int h)
{
	rtgui_container_t *container;
	rtgui_combo_t* cbo;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	cbo = rtgui_widget_create(RTGUI_COMBO_TYPE);
	if(cbo != RT_NULL)
	{
		rtgui_rect_t rect;

		rtgui_widget_get_rect(container, &rect);
		rtgui_widget_rect_to_device(container,&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+RTGUI_COMBO_HEIGHT;
		rtgui_widget_set_rect(cbo,&rect);

		rtgui_container_add_child(container, cbo);

		if(cbo->tbox == RT_NULL)
		{
			int tw,th;
			tw = w-RTGUI_COMBO_BUTTON_WIDTH-RTGUI_WIDGET_BORDER_SIZE(cbo)*2;
			th = h-RTGUI_WIDGET_BORDER_SIZE(cbo)*2;
			cbo->tbox = rtgui_textbox_create(cbo,text,
			                                 RTGUI_WIDGET_BORDER_SIZE(cbo),
			                                 RTGUI_WIDGET_BORDER_SIZE(cbo),
			                                 tw,th,RTGUI_TEXTBOX_NONE);

			if(cbo->tbox == RT_NULL) return RT_NULL;
			rtgui_widget_set_border_style(cbo->tbox,RTGUI_BORDER_NONE);
			cbo->tbox->isedit = RT_FALSE;/* default combo textbox cannot edit */
		}
		if(cbo->lbox == RT_NULL)
		{
			rtgui_point_t point;
			rt_uint32_t mleft,mtop,mwidth;

			rtgui_widget_get_position(cbo, &point);
			mleft = point.x;
			mtop = point.y+RTGUI_COMBO_HEIGHT;
			mwidth = rtgui_widget_get_width(cbo);

			/* create pull down listbox */
			cbo->lbox = rtgui_listbox_create(parent,mleft,mtop,mwidth,4);
			if(cbo->lbox == RT_NULL)return RT_NULL;
			rtgui_widget_set_border_style(cbo->lbox,RTGUI_BORDER_SIMPLE);
			cbo->lbox->ispopup = RT_TRUE;
			cbo->lbox->widget_link = cbo;
			rtgui_listbox_set_onitem(cbo->lbox,rtgui_combo_onitem);

			RTGUI_WIDGET_HIDE(cbo->lbox);
		}
	}

	return cbo;
}
Beispiel #17
0
void rtgui_fileview_set_directory(rtgui_fileview_t* fview, const char* directory)
{
	char fullpath[256];
	rtgui_fileview_item_t *item;

	fview->first_item = 0;
	fview->item_count = 0;

	/* clear file information */
	rtgui_fileview_clear(fview);

	if(directory != RT_NULL)
	{
		DIR* dir;
		struct stat s;
		rt_uint32_t i;
		struct dirent* dirent;

		fview->item_count = 0;
		/* open directory */
		dir = opendir(directory);
		if(dir == RT_NULL) return;

		/* set current directory */
		if(fview->current_dir != RT_NULL)
		{
			rt_free(fview->current_dir);
			fview->current_dir = RT_NULL;
		}
		fview->current_dir = rt_strdup(directory);

		if(fview->dlg != RT_NULL)
		{
			if(fview->dlg->path != RT_NULL)
				rt_free(fview->dlg->path);
			fview->dlg->path = rt_strdup(fview->current_dir);

			if(fview->dlg->tbox_path != RT_NULL)
			{
				rtgui_textbox_set_value(fview->dlg->tbox_path,fview->dlg->path);
				rtgui_textbox_ondraw(fview->dlg->tbox_path);
			}
		}

		do
		{
			dirent = readdir(dir);
			if(dirent == RT_NULL) break;
			fview->item_count ++;
		}
		while(dirent != RT_NULL);
		closedir(dir);

		if((fview->item_count > fview->item_per_page) && fview->sbar!=RT_NULL)
		{
			RTGUI_WIDGET_SHOW(fview->sbar);
			rtgui_scrollbar_set_line_step(fview->sbar,1);
			rtgui_scrollbar_set_page_step(fview->sbar, fview->item_per_page);
			rtgui_scrollbar_set_range(fview->sbar, fview->item_count);
		}
		else
		{
			RTGUI_WIDGET_HIDE(fview->sbar);
		}
		rtgui_widget_update_clip(fview);

		/* apply to memory for store all items. */
		fview->items = (rtgui_fileview_item_t*) rt_malloc(sizeof(rtgui_fileview_item_t) * fview->item_count);

		if(fview->items == RT_NULL) goto __return; /* under the folder has not sub files. */

		/* reopen directory */
		dir = opendir(directory);
		if(dir == RT_NULL)  goto __return;

		for(i=0; i < fview->item_count; i ++)
		{
			dirent = readdir(dir);
			if(dirent == RT_NULL) break;

			item = &(fview->items[i]);
			item->name = rt_strdup(dirent->d_name);

			rt_memset(&s, 0, sizeof(struct stat));

			/* get fullpath of file */
			dfs_get_fullpath(fullpath, directory, dirent->d_name);

			stat(fullpath, &s);
			if(s.st_mode & S_IFDIR)
			{
				item->type = RTGUI_FITEM_DIR;
				item->size = 0;
			}
			else
			{
				item->type = RTGUI_FITEM_FILE;
				item->size = s.st_size;
			}
		}

		closedir(dir);
	}

	fview->now_item = 0;

__return:
	/* update view */
	rtgui_widget_update(fview);
}
Beispiel #18
0
rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
{
	struct rtgui_workbench* workbench = (struct rtgui_workbench*)widget;

	switch (event->type)
	{
	case RTGUI_EVENT_PANEL_DETACH:
		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
		RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
		return RT_TRUE;

	case RTGUI_EVENT_PANEL_SHOW:
		/* show workbench in server */
		rtgui_workbench_show(workbench);
		break;

	case RTGUI_EVENT_PANEL_HIDE:
		/* hide widget */
		RTGUI_WIDGET_HIDE(widget);
		break;

	case RTGUI_EVENT_MOUSE_MOTION:
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				/* let viewer to handle it */
				rtgui_view_t* view = workbench->current_view;
				if (view != RT_NULL &&
					RTGUI_WIDGET(view)->event_handler != RT_NULL)
				{
					RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
				}
			}
		}
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
				{
					/* let modal widget to handle it */
					if (workbench->modal_widget != RT_NULL &&
							workbench->modal_widget->event_handler != RT_NULL)
					{
						workbench->modal_widget->event_handler(workbench->modal_widget, event);
					}
				}
				else
				{
					/* let viewer to handle it */
					rtgui_view_t* view = workbench->current_view;
					if (view != RT_NULL &&
							RTGUI_WIDGET(view)->event_handler != RT_NULL)
					{
						RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
					}
				}
			}
		}
		break;

	case RTGUI_EVENT_KBD:
		{
			struct rtgui_event_kbd* kbd = (struct rtgui_event_kbd*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(kbd->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
				{
					/* let modal widget to handle it */
					if (workbench->modal_widget != RT_NULL &&
							workbench->modal_widget->event_handler != RT_NULL)
					{
						workbench->modal_widget->event_handler(workbench->modal_widget, event);
					}
				}
				else
				{
					if (RTGUI_CONTAINER(widget)->focused == widget)
					{
						/* set focused widget to the current view */
						if (workbench->current_view != RT_NULL)
							rtgui_widget_focus(RTGUI_WIDGET(RTGUI_CONTAINER(workbench->current_view)->focused));
					}

					return rtgui_toplevel_event_handler(widget, event);
				}
			}
		}
		break;

	case RTGUI_EVENT_PAINT:
		{
			struct rtgui_event_paint* epaint = (struct rtgui_event_paint*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(epaint->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				rtgui_view_t* view;

				/* un-hide workbench */
				RTGUI_WIDGET_UNHIDE(widget);

				/* paint a view */
				view = workbench->current_view;
				if (view != RT_NULL)
				{
					/* remake a paint event */
					RTGUI_EVENT_PAINT_INIT(epaint);
					epaint->wid = RT_NULL;

					/* send this event to the view */
					if (RTGUI_WIDGET(view)->event_handler != RT_NULL)
					{
						RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
					}
				}
				else
				{
					struct rtgui_dc* dc;
					struct rtgui_rect rect;

					dc = rtgui_dc_begin_drawing(widget);
					rtgui_widget_get_rect(widget, &rect);
					rtgui_dc_fill_rect(dc, &rect);
					rtgui_dc_end_drawing(dc);
				}
			}
		}
		break;

	case RTGUI_EVENT_CLIP_INFO:
		{
			struct rtgui_event_clip_info* eclip = (struct rtgui_event_clip_info*)event;
			struct rtgui_widget* dest_widget = RTGUI_WIDGET(eclip->wid);

			if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
			{
				dest_widget->event_handler(dest_widget, event);
			}
			else
			{
				return rtgui_toplevel_event_handler(widget, event);
			}
		}
		break;

	case RTGUI_EVENT_WIN_CLOSE:
	case RTGUI_EVENT_WIN_ACTIVATE:
	case RTGUI_EVENT_WIN_DEACTIVATE:
		{
			struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
			struct rtgui_widget* dest_widget = RTGUI_WIDGET(wevent->wid);
			if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
			{
				dest_widget->event_handler(dest_widget, event);
			}
		}
		break;

	case RTGUI_EVENT_WIN_MOVE:
		{
			struct rtgui_event_win_move* wevent = (struct rtgui_event_win_move*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(wevent->wid);
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
		}
		break;

	default:
		return rtgui_toplevel_event_handler(widget, event);
	}

	return RT_TRUE;
}