示例#1
0
文件: combobox.c 项目: amsl/RTGUI
void rtgui_combo_ondraw(rtgui_combo_t *cbo)
{
	rtgui_rect_t rect;
	rtgui_dc_t* dc;

	RT_ASSERT(cbo != RT_NULL);

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

	rtgui_widget_get_rect(cbo, &rect);

	rtgui_rect_inflate(&rect,-RTGUI_WIDGET_BORDER_SIZE(cbo));
	if(RTGUI_WIDGET_IS_ENABLE(cbo))
		RTGUI_DC_BC(dc) = theme.blankspace;
	else
		RTGUI_DC_BC(dc) = theme.background;
	rtgui_dc_fill_rect(dc, &rect);

	rtgui_rect_inflate(&rect,RTGUI_WIDGET_BORDER_SIZE(cbo));
	rtgui_dc_draw_border(dc, &rect,RTGUI_WIDGET_BORDER_STYLE(cbo));

	if(RC_H(rect)<RTGUI_COMBO_HEIGHT)return;

	/* draw downarrow button */
	rect.x1 = rect.x2-RTGUI_COMBO_BUTTON_WIDTH;
	RTGUI_DC_BC(dc) = theme.background;
	rtgui_dc_fill_rect(dc, &rect);

	if(cbo->style & RTGUI_COMBO_STYLE_DOWNARROW_UP)
	{
		rtgui_dc_draw_border(dc, &rect, theme.style);
		rtgui_dc_draw_byte(dc,rect.x1+(rect.x2-rect.x1-7)/2, rect.y1+(rect.y2-rect.y1-4)/2, 4, combo_down_bmp);
	}
	else if(cbo->style & RTGUI_COMBO_STYLE_DOWNARROW_DOWN)
	{
		rtgui_dc_draw_border(dc, &rect, theme.style);
		rtgui_dc_draw_byte(dc,rect.x1+(rect.x2-rect.x1-7)/2+1, rect.y1+(rect.y2-rect.y1-4)/2+1, 4, combo_down_bmp);
	}

	if(cbo->tbox != RT_NULL)
	{
		RTGUI_DC_FC(dc) = theme.foreground;
		rtgui_textbox_ondraw(cbo->tbox);
	}

	rtgui_dc_end_drawing(dc);
}
示例#2
0
rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(object);
	rtgui_textbox_t *box = RTGUI_TEXTBOX(object);

	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_draw != RT_NULL)
			widget->on_draw(RTGUI_OBJECT(widget), event);
		else
#endif
			rtgui_textbox_ondraw(box);
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_mouseclick != RT_NULL)
			widget->on_mouseclick(RTGUI_OBJECT(widget), event);
		else
#endif
			rtgui_textbox_onmouse(box, (struct rtgui_event_mouse *)event);
		return RT_TRUE;

	case RTGUI_EVENT_KBD:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_key != RT_NULL)
			widget->on_key(RTGUI_OBJECT(widget), event);
		else
#endif
			rtgui_textbox_onkey(RTGUI_OBJECT(box), (struct rtgui_event *)event);
		return RT_TRUE;

	default:
		return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
	}

	return RT_FALSE;
}
示例#3
0
文件: fileview.c 项目: amsl/RTGUI
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);
}
示例#4
0
文件: fileview.c 项目: amsl/RTGUI
/* update fileview */
void rtgui_fileview_update_current(rtgui_fileview_t* fview)
{
	rtgui_fileview_item_t *item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t *dc;

	RT_ASSERT(fview != RT_NULL);

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

	/* if directory is null, no dispost */
	if(fview->items==RT_NULL)return;

	rtgui_widget_get_rect(fview, &rect);
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	if((fview->old_item >= fview->first_item) &&
	        (fview->old_item < fview->first_item+fview->item_per_page) &&
	        (fview->old_item != fview->now_item))
	{
		/* these condition dispell blinked when drawed */
		/* get old item rect */
		item_rect = rect;
		item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += ((fview->old_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
		item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

		/* get image rect */
		image_rect.x1 = RTGUI_MARGIN;
		image_rect.y1 = 0;
		image_rect.x2 = RTGUI_MARGIN + file_image->w;
		image_rect.y2 = file_image->h;
		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

		/* draw old item */
		item = &(fview->items[fview->old_item]);
		if(item->type == RTGUI_FITEM_FILE) /* draw item image */
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect,Black);

		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		RTGUI_DC_BC(dc) = theme.blankspace;
		RTGUI_DC_FC(dc) = theme.foreground;
		rtgui_dc_fill_rect(dc,&item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}
	/* draw current item */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += ((fview->now_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_MARGIN + file_image->w;
	image_rect.y2 = file_image->h;
	rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

	item = &(fview->items[fview->now_item]);
	if(item->type == RTGUI_FITEM_FILE) /* draw item image */
		rtgui_image_paste(file_image, dc, &image_rect, Black);
	else
		rtgui_image_paste(folder_image, dc, &image_rect, Black);

	if(fview->dlg != RT_NULL)
	{
		if(fview->dlg->filename != RT_NULL)
		{
			rt_free(fview->dlg->filename);
			fview->dlg->filename = RT_NULL;
		}
		fview->dlg->filename = rt_strdup(item->name);
	}

	item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
	item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);

	{
		if(RTGUI_WIDGET_IS_FOCUSED(fview))
		{
			RTGUI_DC_BC(dc) = DarkBlue;
			RTGUI_DC_FC(dc) = theme.blankspace;
		}
		else
		{
			RTGUI_DC_BC(dc) = Gray;
			RTGUI_DC_FC(dc) = theme.foreground;
		}
		rtgui_dc_fill_rect(dc, &item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}

	if(fview->dlg != RT_NULL)
	{
		if(item->type == RTGUI_FITEM_FILE)
		{
			if(fview->dlg->tbox_filename != RT_NULL)
			{
				rtgui_textbox_set_value(fview->dlg->tbox_filename,fview->dlg->filename);
				RTGUI_DC_FC(dc) = theme.foreground;
				rtgui_textbox_ondraw(fview->dlg->tbox_filename);
			}
		}
	}

	rtgui_dc_end_drawing(dc);
}
示例#5
0
static rt_bool_t rtgui_textbox_onkey(struct rtgui_object *widget, rtgui_event_t *event)
{
	rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);
	struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
	rt_size_t length;
	rt_uint16_t posbak = box->position;

	RT_ASSERT(box != RT_NULL);
	RT_ASSERT(ekbd != RT_NULL);

	/* handle the key at down time and nothing to do with up */
	if (RTGUI_KBD_IS_UP(ekbd))
		return RT_TRUE;

	if (box->dis_length == 0)
	{
		rtgui_rect_t rect;

		rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);

		if (box->font_width == 0)
			return RT_FALSE;

		box->dis_length = (rtgui_rect_width(rect) - 5) / box->font_width;
	}

	length = rt_strlen(box->text);
	if (ekbd->key == RTGUIK_DELETE)
	{
		/* delete latter character */
		if (box->first_pos + box->position == length - 1)
		{
			box->text[box->first_pos + box->position] = '\0';
		}
		else
		{
			char *c;

			/* remove character */
			for (c = &box->text[box->first_pos + box->position]; c[1] != '\0'; c++)
				*c = c[1];
			*c = '\0';
		}
	}
	else if (ekbd->key == RTGUIK_BACKSPACE)
	{
		/* delete front character */
		if (box->position == 0)
		{
			if(box->first_pos > 0)
			{
				if(box->first_pos > box->dis_length)
				{
					box->first_pos -= box->dis_length;
					box->position = box->dis_length;
				}
				else
				{
					box->position = box->first_pos;
					box->first_pos = 0;
				}
			}
		}
		else if (box->position == length-box->first_pos)
		{
			box->text[box->first_pos + box->position - 1] = '\0';
			box->position --;
		}
		else if (box->position != 0)
		{
			/* remove current character */
			if (box->position != 0)
			{
				char *c;

				/* remove character */
				for (c = &box->text[box->position - 1]; c[1] != '\0'; c++)
					*c = c[1];
				*c = '\0';
			}
			box->position --;
		}
	}
	else if (ekbd->key == RTGUIK_LEFT)
	{
		/* move to prev */
		if (box->position > 0)
		{
			box->position --;
		}
		else
		{
			if(box->first_pos > 0)
				box->first_pos -= 1;//DEBUG
		}
	}
	else if (ekbd->key == RTGUIK_RIGHT)
	{
		/* move to next */
		if (box->first_pos + box->position < length)
		{
			if(box->position < box->dis_length)
				box->position ++;
			else 
				box->first_pos += 1;//DEBUG
		}
	}
	else if (ekbd->key == RTGUIK_HOME)
	{
		/* move cursor to start */
		box->position = 0;
		box->first_pos = 0;
	}
	else if (ekbd->key == RTGUIK_END)
	{
		/* move cursor to end */
		if(length > box->dis_length)
		{
			box->position = box->dis_length;
			box->first_pos = length - box->dis_length;
		}
		else
		{
			box->position = length;
			box->first_pos = 0;
		}
	}
	else if (ekbd->key == RTGUIK_RETURN)
	{
		if (box->on_enter != RT_NULL)
		{
			box->on_enter(box, event);
		}
	}
	else if (ekbd->key == RTGUIK_NUMLOCK)
	{
		/* change numlock state */
		/*
		extern void update_number_lock(void);
		update_number_lock();
		*/
	}
	else
	{
		if (isprint(ekbd->key))
		{
			/* it's may print character */
			/* no buffer on this line */
			if (box->flag & RTGUI_TEXTBOX_DIGIT)
			{
				/* only input digit */
				if (!isdigit(ekbd->key))
				{
					/* exception: '.' and '-' */
					if (ekbd->key != '.' && ekbd->key != '-')return RT_FALSE;
					if (ekbd->key == '.' && strchr(box->text, '.'))return RT_FALSE;

					if (ekbd->key == '-')
					{
						if (length + 1 > box->line_length) return RT_FALSE;

						if (strchr(box->text, '-'))
						{
							char *c;
							for (c = &box->text[0]; c != &box->text[length]; c++)
								*c = *(c + 1);
							box->text[length] = '\0';
							box->position --;
							goto _exit;
						}
						else
						{
							char *c;
							for (c = &box->text[length]; c != &box->text[0]; c--)
								*c = *(c - 1);
							box->text[0] = '-';
							box->text[length + 1] = '\0';
							box->position ++;
							goto _exit;
						}
					}
				}
			}
			if (length + 1 > box->line_length) return RT_FALSE;

			if (box->first_pos + box->position <= length - 1)
			{
				char *c;

				for (c = &box->text[length]; c != &box->text[box->first_pos + box->position]; c--)
					*c = *(c - 1);
				box->text[length + 1] = '\0';
			}

			box->text[box->first_pos + box->position] = ekbd->key;
			if(box->position < box->dis_length)
				box->position ++;
			else
				box->first_pos ++;
		}
	}

_exit:
	if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
	{
		if (box->caret_timer != RT_NULL)
			rtgui_timer_stop(box->caret_timer);

		box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
		rtgui_textbox_draw_caret(box, posbak);/* refresh it */
		if (box->caret_timer != RT_NULL)
			rtgui_timer_start(box->caret_timer);
	}

	/* re-draw text box */
	rtgui_textbox_ondraw(box);

	rtgui_textbox_init_caret(box, box->position);
	box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
	rtgui_textbox_draw_caret(box, box->position);

	return RT_TRUE;
}