Exemplo n.º 1
0
int jx_resize_pad(jx_window *w, int pw, int ph)
{
	/* validate window */
	if (check_window(w))
		return JX_ERR_INVALID_WINDOW;
	/* validate is pad */
	if (w->flags & JX_WF_PAD)
		return JX_ERR_INVALID_PAD;
	/* check size is valid */
	if (pw <= 0 || ph <= 0)
		return JX_ERR_INVALID_PAD_SIZE;
	/* check if its in range */
	if (pw < w->w || ph < w->h)
		return JX_ERR_OUT_OF_PAD;
	/* move the scroll into range */
	if (w->px + w->w > pw)
		w->px = pw - w->w;
	if (w->py + w->h > ph)
		w->py = ph - w->h;
	
	wchar_t *buffer_text = malloc(pw * ph * sizeof(wchar_t));
	memcpy(buffer_text, w->buffer_text, pw * ph * sizeof(wchar_t));
	uint16_t *buffer_fg = malloc(pw * ph * sizeof(uint16_t));
	memcpy(buffer_fg, w->buffer_fg, pw * ph * sizeof(uint16_t));
	uint16_t *buffer_bg = malloc(pw * ph * sizeof(uint16_t));
	memcpy(buffer_bg, w->buffer_bg, pw * ph * sizeof(uint16_t));
	w->buffer_text = buffer_text;
	w->buffer_fg = buffer_fg;
	w->buffer_bg = buffer_bg;
	w->flags |= JX_WF_DIRTY;
	w->pw = pw;
	w->ph = ph;

	return JX_SUCCESS;
}
Exemplo n.º 2
0
/*
  window.autoscroll -> true/false
  the window can scroll?

  Stack:
  1: the instance table
  2: the accessed key
*/
int		lui_window_get_autoscroll(lua_State *L)
{
    PANEL		*p = check_window(L, 1);

    lua_pushboolean(L, (is_scrollok(panel_window(p)) == TRUE));
    return 1;
}
Exemplo n.º 3
0
/*
  window.hidden -> true/false
  the window is visible?

  Stack:
  1: the instance table
  2: the accessed key
*/
int		lui_window_get_hidden(lua_State *L)
{
    PANEL		*p = check_window(L, 1);

    lua_pushboolean(L, (panel_hidden(p) == TRUE));
    return 1;
}
Exemplo n.º 4
0
/* move a window */
int jx_move(jx_window *w, int x, int y)
{
	/* validate window */
	if (check_window(w))
		return JX_ERR_INVALID_WINDOW;
	/* check if any work needs to be done */
	if (w->x == x && w->y == y)
		return JX_SUCCESS;

	/* the parent window is dirty */
	w->parent->flags |= JX_WF_DIRTY;
	/* the siblings are dirty if this window overlaps them */
	for (jx_window *a = window_head; a != window_tail; a = a->next) {
		/* only process windows that are under this window */
		if (a == w) break;
		/* if overlap, mark as dirty */
		if (a->parent == w->parent &&
		    a->x < w->x + w->w && a->x + a->w > w->x &&
		    a->y < w->y + w->h && a->y + a->h > w->y)
			a->flags |= JX_WF_DIRTY;
	}
	/* this window is dirty */
	w->flags |= JX_WF_DIRTY;
	w->x = x;
	w->y = y;

	return JX_SUCCESS;
}
Exemplo n.º 5
0
/* destroy a window */
int jx_destroy_window(jx_window *w)
{
	/* validate window */
	if (check_window(w))
		return JX_ERR_INVALID_WINDOW;

	/* destroy children */
	for (jx_window *a = window_head; a != window_tail; a = a->next)
		if (a->parent == w)
			jx_destroy_window(a);

	/* finally destroy window */
	for (jx_window *a = window_head; a != window_tail; a = a->next) {
		if (a == w) {
			if (w->flags & JX_WF_PAD) {
				free(w->buffer_text);
				free(w->buffer_fg);
				free(w->buffer_bg);
			}
			a->prev->next = w->next;
			a->next->prev = w->prev;
			free(w);

			return JX_SUCCESS;
		}
	}

	return JX_ERR_INVALID_WINDOW;
}
Exemplo n.º 6
0
static void update_slider_value(GuiObject * slid)
{
	GuiObject *text;
	GuiWindow *win;
	
	check_object(slid, "slid", "update_slider_value");
	text = slid->next;
	check_object(text, "text", "update_slider_value");
	win = slid->win;
	check_window(win, "update_slider_value");

	if (slid->max_value <= 2)
		sprintf(text->label, "%0.2f", slid->position / (float) (slid->slider_length - 1) *
			slid->max_value);
	else if (slid->max_value <= 10)
		sprintf(text->label, "%0.1f", slid->position / (float) (slid->slider_length - 1) *
			slid->max_value);
	else
		sprintf(text->label, "%0.0f", slid->position / (float) (slid->slider_length - 1) *
			slid->max_value);

	win_fillbox(win, text->x, text->y, text->width, text->height, text->bg_col1);
	text->x = slid->x_min - string_length(text->label) / 2 + slid_width / 2 - 1;
	create_text(text);
	update_text(text);
}
Exemplo n.º 7
0
/*
  window.cursor.y
  return the row number of the cursor

  Stack:
  1: the instance table
  2: the accessed key
*/
int		lui_window_get_cursor_y(lua_State *L)
{
    PANEL		*p = check_window(L, 1);

    lua_pushinteger(L, getcury(panel_window(p)));
    return 1;
}
Exemplo n.º 8
0
/*
  window["autoscroll"] = true/false
  enable/disable autoscrolling

  Stack:
  1: the instance table
  2: the accessed key
  3: the value to set
*/
int		lui_window_set_autoscroll(lua_State *L)
{
    WINDOW	*w = panel_window(check_window(L, 1));

    scrollok(w, lua_toboolean(L, 3) == 1 ? TRUE : FALSE);
    wrefresh(w);
    return 0;			/* TODO: send something ? */
}
Exemplo n.º 9
0
void show_number(GuiObject * obj)
{
	check_object(obj, "obj", "show_number");
	check_window(obj->win, "show_number");

	update_number(obj);
	show_window(obj->win);
}
Exemplo n.º 10
0
void show_slider(GuiObject * slid)
{
	check_object(slid, "slid", "show_slider");
	check_window(slid->win, "show_slider");

	update_slider(slid);
	show_window(slid->win);
}
Exemplo n.º 11
0
/*
  window:addch(c)
  put a char in the virtual window
*/
int		lui_addch_window(lua_State *L)
{
    WINDOW	*w = panel_window(check_window(L, 1));
    const char	*str = luaL_checkstring(L, 2);

    if (*str)
        waddch(w, *str);
    return 0;
}
Exemplo n.º 12
0
/*
  window:move(x, y)
  move the window
*/
int		lui_move_window(lua_State *L)
{
    PANEL		*p = check_window(L, 1);
    const int	x = luaL_checkint(L, 2);
    const int	y = luaL_checkint(L, 3);

    move_panel(p, y, x);
    return 0;
}
Exemplo n.º 13
0
int		lui_window_set_style(lua_State *L)
{
    WINDOW	*w = panel_window(check_window(L, 1));
    t_style	s;

    get_style(L, 3, s);
    wbkgd(w, s.on & ~s.off);
    return 0;
}
Exemplo n.º 14
0
/*
  window.["hidden"] = true/false
  hide or unhide the window.

  Stack:
  1: the instance table
  2: the accessed key
  3: the value to set
*/
int		lui_window_set_hidden(lua_State *L)
{
    PANEL		*p = check_window(L, 1);

    if (lua_toboolean(L, 3))	/* hidden = true -> hide the window */
        hide_panel(p);
    else			       /* hidden = false -> show the window */
        show_panel(p);
    update_panels();
    return 0;			/* TODO: send something ? */
}
Exemplo n.º 15
0
/*
  window:clear()
  clearing the window
*/
int		lui_clear_window(lua_State *L)
{
    PANEL		*p;

    p = check_window(L, 1);

    wclear(panel_window(p));
    update_panels();
    doupdate();
    return 0;
}
Exemplo n.º 16
0
/*
  window.__gc
  destroy the window

  Stack:
  1: the instance table
  2: the accessed key
*/
int		lui_destroy_window(lua_State *L)
{
    PANEL		*p;
    WINDOW	*w;

    p = check_window(L, 1);
    w = panel_window(p);
    del_panel(p);
    delwin(w);
    return 0;
}
Exemplo n.º 17
0
/*
 * call-seq:
 *   insert_sub_page(pos, window, text, [select], [bitmap]) -> true/false
 *   insert_sub_page(pos, WindowClass, text, [select], [bitmap],**options) [{|window| }] -> true/false
 *
 * inserts a new page to the BookCtrl widget into the given position.
 *
 * ===Arguments
 * * pos is a Integer
 * * window is a WX::Window instance
 * * text is the Label of the page. String
 * * select is true/false and says if the new page should be selected
 * * bitmap is a Integer and says the position of the bitmap in the image_list
 * ===Return value
 * true/false
 * === Exceptions
 * [IndexError]
 * * bitmap is greater than the list of bitmaps in the image_list
 * [ArgumentError]
 * * window does not have this BookCtrl as parent
 *
*/
DLL_LOCAL VALUE _insertSubPage(int argc,VALUE *argv,VALUE self)
{
	VALUE n,window,text,select,imageid,hash;
	wxWindow *w = NULL;
	bool sel = false;
	int iid = -1;
	rb_scan_args(argc, argv, "32:",&n,&window,&text,&select,&imageid,&hash);

	check_imagelist(_self,imageid,iid);
	check_window(self,hash,window,w);

	return wrap(_self->InsertSubPage(NUM2INT(n),w,unwrap<wxString>(text),sel,iid));
}
Exemplo n.º 18
0
/*
  window:addstr(s)
  put a string in the virtual window
*/
int		lui_addstr_window(lua_State *L)
{
    PANEL		*p;
    char		*str;
    WINDOW	*w;

    p = check_window(L, 1);
    str = luasoul_strdup(luaL_checkstring(L, 2));
    w = panel_window(p);

    waddstr(w, str);
    return 0;
}
Exemplo n.º 19
0
/*
  window:scroll(nlines)
  if nlines > 0 scroll up nlines
  otherwise scroll down nlines
*/
int		lui_scroll_window(lua_State *L)
{
    PANEL		*p;
    WINDOW	*w;
    int		nlines;

    p = check_window(L, 1);
    nlines = luaL_checkinteger(L, 2);
    w = panel_window(p);

    wscrl(w, nlines);
    wrefresh(w);
    return 0;
}
Exemplo n.º 20
0
/*
  window:refresh()
  refresh the window (update physical window to match virtual window).
*/
int		lui_refresh_window(lua_State *L)
{
    WINDOW	*w = panel_window(check_window(L, 1));

    /*
      FIXME:
      set the bkgd each time we refresh is absolutely not necessary,
      but when we clear the screen it's useful...
    */
    wbkgd(w, getbkgd(w));

    update_panels();
    doupdate();
    return 0;
}
Exemplo n.º 21
0
/*
 * call-seq:
 *   prepend_sub_page(window, text, [select], [bitmap]) -> true/false
 *   prepend_sub_page(WindowClass, text, [select], [bitmap],**options) [{|window| }] -> true/false
 *
 * prepends a new page to the BookCtrl widget.
 *
 * ===Arguments
 * * window is a WX::Window instance
 * * text is the Label of the page. String
 * * select is true/false and says if the new page should be selected
 * * bitmap is a Integer and says the position of the bitmap in the image_list
 * ===Return value
 * true/false
 * === Exceptions
 * [IndexError]
 * * bitmap is greater than the list of bitmaps in the image_list
 * [ArgumentError]
 * * window does not have this BookCtrl as parent
 *
*/
DLL_LOCAL VALUE _prependSubPage(int argc,VALUE *argv,VALUE self)
{
	VALUE window,text,select,imageid,hash;
	wxWindow *w = NULL;
	bool sel = false;
	int iid = -1;
	rb_scan_args(argc, argv, "22:",&window,&text,&select,&imageid,&hash);

	if(!NIL_P(select))
		sel = RTEST(select);

	check_imagelist(_self,imageid,iid);
	check_window(self,hash,window,w);

	return wrap(_self->InsertSubPage(0,w,unwrap<wxString>(text),sel,iid));
}
Exemplo n.º 22
0
static void move_slider(GuiObject * slid, int pos_neg)
{
	GuiWinThread *win_thread;
	
	check_object(slid, "slid", "move_slider");
	check_window(slid->win, "move_slider");
	win_thread = (slid->win)->win_thread;
	
	do {
		usleep(sleep_time);
		do_window_functions(win_thread);
		new_position(slid, pos_neg);
		if (GuiGetMessage() == GuiMouseEvent)
			move_mouse();
	}
	while (GuiMouseGetButton() == GuiMouseLeftButton);
}
Exemplo n.º 23
0
GuiObject *add_number(GuiWindow * win, int type, int x, int y, int seg_length, char *mask)
{
	GuiObject *number;
	int i;

	check_window(win, "add_number");

	number = (GuiObject *) malloc(sizeof(GuiObject));
	if (number == NULL)
		error("Cannot allocate memory for number.");

	number->win = win;
	number->x = number->x_min = x;
	number->y = number->y_min = y;
	number->objclass = NUMBER;
	number->active = TRUE;
	number->pressed = FALSE;
	number->hide = FALSE;
	number->type = type;
	number->fg_col = NUMBER_FORE;
	number->bg_col1 = BLACK;

	number->width = 0;
	for (i = 0;i < strlen(mask);i++)
		if (mask[i] == ' ')
			number->width += 13;
		else
			number->width += bigfont_width[mask[i] - ' '];
	number->height = bigfont_height;

	number->x_max = x + number->width - 1;
	number->y_max = y + number->height - 1;
	number->align = ALIGN_LEFT;
	sprintf(number->label, "%s", mask);
	number->info[0] = '\0';	/* make string length zero */

	number->data[0] = (char *) malloc(number->width * number->height);
	if (number->data[0] == NULL)
		error("Cannot allocate memory for number.");
	number->data[1] = NULL;	/* don't use second data-block */

	create_number(number);
	add_object(number);

	return number;
}
Exemplo n.º 24
0
/*
  window:resize(width, height)
  resize the window
*/
int		lui_resize_window(lua_State *L)
{
    PANEL		*p;
    WINDOW	*w;
    const int	width = luaL_checkint(L, 2);
    const int	height = luaL_checkint(L, 3);

    p = check_window(L, 1);
    w = panel_window(p);

    if (width <= 0 && height <= 0)
    {
        luaL_error(L, "can't resize window: invalid dimension");
        return 0;
    }
    wresize(w, height, width);
    return 0;
}
Exemplo n.º 25
0
int jx_resize(jx_window *win, int w, int h)
{
	/* validate window */
	if (check_window(win))
		return JX_ERR_INVALID_WINDOW;
	/* check size is valid */
	if (w <= 0 || h <= 0)
		return JX_ERR_INVALID_WINDOW_SIZE;
	/* check if any work needs to be done */
	if (win->w == w && win->h == h)
		return JX_SUCCESS;

	win->parent->flags |= JX_WF_DIRTY;
	/* the siblings are dirty if this window overlaps them */
	for (jx_window *a = window_head; a != window_tail; a = a->next) {
		/* only process windows that are under this window */
		if (a == win) break;
		/* if overlap, mark as dirty */
		if (a->parent == win->parent &&
		    (a->x < win->x + win->w && a->x + a->w > win->x &&
		    a->y < win->y + win->h && a->y + a->h > win->y) ||
		    (a->x < win->x + w && a->x + a->w > win->x &&
		    a->y < win->y + h && a->y + a->h > win->y))
			a->flags |= JX_WF_DIRTY;
	}
	if (win->flags & JX_WF_PAD) {
		if (win->pw < w || win->ph < h)
			jx_resize_pad(win, MAX(w, win->pw), MAX(h, win->ph));
	} else {
		wchar_t *buffer_text = malloc(w * h * sizeof(wchar_t));
		memcpy(buffer_text, win->buffer_text, w * h * sizeof(wchar_t));
		uint16_t *buffer_fg = malloc(w * h * sizeof(uint16_t));
		memcpy(buffer_fg, win->buffer_fg, w * h * sizeof(uint16_t));
		uint16_t *buffer_bg = malloc(w * h * sizeof(uint16_t));
		memcpy(buffer_bg, win->buffer_bg, w * h * sizeof(uint16_t));
		win->buffer_text = buffer_text;
		win->buffer_fg = buffer_fg;
		win->buffer_bg = buffer_bg;
	}
	win->w = w;
	win->h = h;

	return JX_SUCCESS;
}
Exemplo n.º 26
0
/*
 * call-seq:
 *   prepend(window, [options])
 *   prepend(sizer, [options])
 *   prepend(size, [options])
 *
 * prepends a new WX::Sizer::Item
 * ===Arguments
 * * window is a WX::Window
 * * sizer is a WX::Sizer
 * * size is a WX::Size
 *
 * *options: Hash with possible options to set:
 *   * expand true/false says if the element should expand to the whole size
 *   * proportion Integer
 * ===Return value
 * WX::Sizer::Item
 */
DLL_LOCAL VALUE _prepend(int argc,VALUE *argv,VALUE self)
{
	VALUE obj,hash;
	rb_scan_args(argc, argv, "1:",&obj,&hash);

	wxSizerFlags flags(unwrap<wxSizerFlags>(hash));

	if(rb_obj_is_kind_of(obj, rb_cWXWindow)) {
		wxWindow *win = unwrap<wxWindow*>(obj);
		if(check_window(_self, win, hash))
			return wrap(_self->Prepend(win, flags));
	} else if(rb_obj_is_kind_of(obj, rb_cWXSizer))
		return wrap(_self->Prepend(unwrap<wxSizer*>(obj),flags));
	else {
		const wxSize &size = unwrap<wxSize>(obj);
		return wrap(_self->Prepend(size.GetWidth(),size.GetHeight(),flags));
	}
	return Qnil;
}
Exemplo n.º 27
0
/*
 * call-seq:
 *   insert(pos, window, [options])
 *   insert(pos, sizer, [options])
 *   insert(pos, size, [options])
 *
 * inserts a new WX::Sizer::Item into the given position.
 * ===Arguments
 * * pos is Integer
 * * window is a WX::Window
 * * sizer is a WX::Sizer
 * * size is a WX::Size
 *
 * *options: Hash with possible options to set:
 *   * expand true/false says if the element should expand to the whole size
 *   * proportion Integer
 * ===Return value
 * WX::Sizer::Item
 */
DLL_LOCAL VALUE _insert(int argc,VALUE *argv,VALUE self)
{
	VALUE index,obj,hash;
	rb_scan_args(argc, argv, "2:",&index,&obj,&hash);

	wxSizerFlags flags(unwrap<wxSizerFlags>(hash));

	if(rb_obj_is_kind_of(obj, rb_cWXWindow)) {
		wxWindow *win = unwrap<wxWindow*>(obj);
		if(check_window(_self, win, hash))
			return wrap(_self->Insert(RB_NUM2INT(index), win, flags));
	} else if(rb_obj_is_kind_of(obj, rb_cWXSizer))
		return wrap(_self->Insert(RB_NUM2INT(index),unwrap<wxSizer*>(obj),flags));
	else {
		const wxSize &size = unwrap<wxSize>(obj);
		return wrap(_self->Insert(RB_NUM2INT(index),size.GetWidth(),size.GetHeight(),flags));
	}
	return Qnil;
}
Exemplo n.º 28
0
/* create a window to edit */
jx_window *jx_create_window(jx_window *parent, int x, int y, int w, int h,
		int flags)
{
	/* validate parent window */
	if (check_window(parent))
		return NULL;
	jx_window *win = calloc(sizeof(jx_window), 1);
	win->x = x;
	win->y = y;
	win->w = w;
	win->h = h;
	win->buffer_text = malloc(w * h * sizeof(wchar_t));
	win->buffer_fg = malloc(w * h * sizeof(uint16_t));
	win->buffer_bg = malloc(w * h * sizeof(uint16_t));
	win->flags = flags | JX_WF_DIRTY;
	win->parent = parent;
	win->prev = window_tail;
	window_tail->next = win;
	return win;
}
Exemplo n.º 29
0
/* change a window into a pad */
int jx_make_pad(jx_window *w, int pw, int ph)
{
	/* validate window */
	if (check_window(w))
		return JX_ERR_INVALID_WINDOW;

	if (pw < w->w || ph < w->h)
		return JX_ERR_INVALID_PAD_SIZE;

	w->flags |= JX_WF_PAD | JX_WF_DIRTY;
	if (w->buffer_text)
		free(w->buffer_text);
	w->buffer_text = malloc(pw * ph * sizeof(wchar_t));
	if (w->buffer_fg)
		free(w->buffer_fg);
	w->buffer_fg = malloc(pw * ph * sizeof(uint16_t));
	if (w->buffer_bg)
		free(w->buffer_bg);
	w->buffer_bg = malloc(pw * ph * sizeof(uint16_t));

	return JX_SUCCESS;
}
Exemplo n.º 30
0
int jx_scroll_pad(jx_window *w, int px, int py)
{
	/* validate window */
	if (check_window(w))
		return JX_ERR_INVALID_WINDOW;
	/* validate is pad */
	if (w->flags & JX_WF_PAD)
		return JX_ERR_INVALID_PAD;
	/* check if its in range */
	if (w->px < 0 || w->py < 0 ||
	    w->px + w->w > w->pw || w->py + w->h > w->ph)
		return JX_ERR_OUT_OF_PAD;
	/* check if any work needs to be done */
	if (w->px == px && w->py && py)
		return JX_SUCCESS;

	w->flags |= JX_WF_DIRTY;
	w->px = px;
	w->py = py;

	return JX_SUCCESS;
}