Esempio n. 1
0
void print_tree(struct node_t *tree)
{
    struct node_t *it;
    save_depth(tree);
    for (it = object_tree_l_most_node(tree->obj.parent); it;
         it = object_tree_iterator_increment(tree->obj.parent,
                                             OBJECT_POINTER(it))) {
        print_node(it);
    }
}
Esempio n. 2
0
void save_depth(struct node_t *tree)
{
    struct node_t *it;
    for (it = object_tree_l_most_node(tree->obj.parent); it;
         it = object_tree_iterator_increment(tree->obj.parent,
                                             OBJECT_POINTER(it))) {
        struct node_t *par =
            (struct node_t *)object_parent(OBJECT_POINTER(it));
        if (par) {
            it->data.depth = par->data.depth + 1;
        }
        else {
            it->data.depth = 0;
        }
    }
}
Esempio n. 3
0
/**
 * traverse the whole window vector and widget tree increamentally
 *
 * @param do_for_each_widget: function pointer which uses the each widget as parameter
 * @param msg: pointer to message
 * @return: NULL if traversal all, otherwise returns the specific widget that stopped the traversal
 **/
static struct widget* application_widgets_for_each_increament(struct widget*(*do_for_each_widget)(struct widget*, union message*), union message* msg)
{
    int n, i;
    struct object* tree, *node;
    n = vector_size(&(global_application.window_vector));

    for(i = 0; i != n; ++ i)
    {
        tree = vector_at(&(global_application.window_vector), i);
        node = tree->lchild;
        while(node != NULL)
        {
            if(do_for_each_widget(WIDGET_POINTER(node), msg))
                return WIDGET_POINTER(node);
            node = object_tree_iterator_increment(tree, node);
        }
    }
    return NULL;
}
Esempio n. 4
0
/**
 * dispatch msg to all subchild of a widget
 * 
 * @param node: the widget
 * @param type: msg type
 * @return: 0
 **/
static si_t dispatch_msg_to_subchilds(struct object* node, int type)
{
    struct object* n, *t, *parent;

    /**
     * change the structure of the tree just for this
     **/
    n = node;
    t = n->parent;
    parent = t->parent;
    t->parent = n;
    n = object_tree_l_most_node(t);
    while(n != NULL)
    {
        union message msg;

        /**
         * pack the message
         **/
        if(type == MESSAGE_TYPE_WINDOW_DEACTIVATE)
        {
            msg.base.type = MESSAGE_TYPE_WINDOW_DEACTIVATE;
        }
        else if(type == MESSAGE_TYPE_WIDGET_REPAINT)
        {
            struct widget* w = WIDGET_POINTER(n);
            msg.widget_repaint.type = MESSAGE_TYPE_WIDGET_REPAINT;
            msg.widget_repaint.area = w->area;
        }
        else if(type == MESSAGE_TYPE_WINDOW_MINIMIZE 
            || type == MESSAGE_TYPE_WINDOW_RESTORE)
        {
            msg.base.window_descriptor = WINDOW_POINTER(n)->descriptor;
        }

        if(WIDGET_POINTER(n)->callback != NULL)
            WIDGET_POINTER(n)->callback(n, &msg);
        n = object_tree_iterator_increment(t, n);
    }
    t->parent = parent;
    return 0;
}
/* traversal_app {{{ */
si_t traversal_app(struct application_info * app_info_ptr)
{
	si_t i, n;
	struct object * tree, * node;

	n = vector_size(&(app_info_ptr->window_info_vector));

	for(i = 0; i < n; ++ i)
	{
		tree = vector_at(&(app_info_ptr->window_info_vector), i);

		node = tree->lchild;
		while(node != NULL)
		{
			struct window_info * win_info_ptr = (struct window_info *)node;
			EGUI_PRINT_INFO("traversal: app %s, window %s", app_info_ptr->name, win_info_ptr->title);

			node = object_tree_iterator_increment(tree, node);
		}
	}

	return 0;
}
Esempio n. 6
0
/*
   总是将孩子节点加在子节点链的最右边

   如果 parent 在对象树中
   那么完成添加工作后一定要更新 root->parent 的 lchild 成员和 rchild 成员
   这是为了保证遍历的正确
   */
si_t application_add_window(struct window * parent, struct window * window)
{
	struct object node, * tree;

	/* 添加顶层窗口 */
	if(parent == NULL)
	{
		/* node 的父节点是 window */
		node.parent = OBJECT_POINTER(window);
		node.lchild = object_tree_l_most_node(OBJECT_POINTER(window));
		node.rchild = object_tree_r_most_node(OBJECT_POINTER(window));
		node.name = NULL;
		node.id = 0;

		/* 将窗口添加到向量 */
		vector_push_back(&(global_application.window_vector), &node, sizeof(struct object));

		tree = vector_back(&(global_application.window_vector));

		/* window 的父节点是 node */
		window->parent = tree;
	}
	/* 添加非顶层窗口 */
	else
	{
		object_insert_child(OBJECT_POINTER(parent), OBJECT_POINTER(window));
	}
	/**
	 * if already running in app_exec
	 **/
	if(global_application.exec_flag)
	{
		union message msg;
		msg.base.type = MESSAGE_TYPE_WIDGET_REPAINT;
		msg.widget_repaint.area = window->area;

		if(global_application.focus != NULL)
		{
			struct window* w = WINDOW_POINTER(global_application.focus);
			struct object* tree, *node, *tree_real_parent;
			w->is_activated = 0;
			msg.widget_repaint.area = w->area;
			if(w->callback != NULL)
			{
				w->callback(w, &msg);
			}

			node = OBJECT_POINTER(w);
			tree = node->parent;
			tree_real_parent = tree->parent;
			tree->parent = node;
			node = object_tree_l_most_node(tree);
			while(node != NULL)
			{
				union message msg;
				msg.base.type = MESSAGE_TYPE_WIDGET_REPAINT;
				msg.widget_repaint.area = WIDGET_POINTER(node)->area;
				if(WIDGET_POINTER(node)->callback != NULL)
					WIDGET_POINTER(node)->callback(node, &msg);

				node = object_tree_iterator_increment(tree, node);
			}
			tree->parent = tree_real_parent;
		}

		window->descriptor = register_window((parent == NULL ? 0 : parent->descriptor), window->title, 
			window->area.x, window->area.y, window->area.width, window->area.height, 
			window->minimize_enable, window->maximize_enable, window->modal);
		if(window->descriptor == 0)
		{
			EGUI_PRINT_ERROR("failed to register window");
			application_exit();
			return -1;
		}

		/**
		 * find icon for the application
		 **/
		if((window->icon_path = (char*)malloc(256)) == NULL)
		{
			EGUI_PRINT_SYS_ERROR("failed to malloc for icon path. malloc");
			application_exit();
			return -1;
		}
		else
		{
			/**
			 * in C89 standard, snprintf() is NOT included in <stdio.h>
			 * so you have to use sprintf, which may be dangerous. be careful
			 **/
			sprintf(window->icon_path, "%s/icons/%s.bmp", global_application.icon_root_path, global_application.name);
			if(access(window->icon_path, R_OK) == -1)
			{
				sprintf(window->icon_path, "%s/icons/default.bmp", global_application.icon_root_path);
			}
		}

		msg.widget_repaint.area = window->area;
		global_application.focus = window;
		window->is_activated = 1;
		if(window->callback != NULL)
		{
			window->callback(window, &msg);
		}
	}

	return 0;
}
static si_t handle_minimize_button_release(union message* msg)
{
	struct object* tree = NULL;
	struct object* node = NULL;
	int i = 0, j = 0;
	struct window_info_iterator iter;
	/* 不能最小化或不在活动窗口的最小化按钮内释放 */
	if(global_wm.active_win_info_ptr->minimize_enable != 1
		|| !is_point_in_area(&(msg->mouse.cursor_position), &(global_wm.active_win_info_ptr->minimize_button_area)))
	{
		return 0;
	}

	/**
	 * send minmize msg to every client window(including subwindows)
	 **/
	tree = object_get_root(OBJECT_POINTER(global_wm.active_win_info_ptr))->parent;
	node = tree->lchild;
	while(node != NULL)
	{
		EGUI_PRINT_INFO("send minimized msg to %s", ((struct window_info*)node)->title);
		send_window_minimize_message(&global_wm.active_app_info_ptr->uds, msg, (si_t)node);
		node = object_tree_iterator_increment(tree, node);
	}

	/**
	 * send deactive msg to client
	 **/
	send_window_deactivate_message(&global_wm.active_app_info_ptr->uds, msg, (si_t)global_wm.active_win_info_ptr);
	/** 通知桌面 **/
	if(NULL != global_wm.desktop_app_ptr)
	{
		send_window_deactivate_message(&global_wm.desktop_app_ptr->uds, NULL, (si_t)tree->parent);
	}

	window_info_iterator_clear(&iter);
	/* get next active window and application */
	if(all_app_traversal_decrement(&iter, _do_find_next_active_window, tree->parent))
	{
		global_wm.active_win_info_ptr = iter.win_info_ptr;
		global_wm.active_app_info_ptr = iter.app_info_ptr;
	}
	else
	{
		global_wm.active_win_info_ptr = NULL;
		global_wm.active_app_info_ptr = NULL;
		return 0;
	}

	/**
	 * 获得顶层窗口
	 **/
	node = object_get_root(OBJECT_POINTER(global_wm.active_win_info_ptr));
	/**
	 * move next active window back
	 **/
	i = application_info_get_win_index(global_wm.active_app_info_ptr, (struct window_info*)node);
	j = window_manager_get_app_index(global_wm.active_app_info_ptr);
	vector_move_back(&(global_wm.active_app_info_ptr->window_info_vector), i);
	vector_move_back(&(global_wm.application_info_vector), j);

	/**
	 * send active msg
	 **/
	send_window_activate_message(&global_wm.active_app_info_ptr->uds, msg, (si_t)global_wm.active_win_info_ptr);
	if(NULL != global_wm.desktop_app_ptr)
	{
		send_window_activate_message(&global_wm.desktop_app_ptr->uds, NULL, (si_t)node);
	}

	return 0;
}