Esempio n. 1
0
TWindow *new_stringview_window(char *buf, char *title)
{
    TWindow *ret = ttk_new_window();
    ttk_add_widget (ret, ttk_new_textarea_widget (ret->w, ret->h, buf, ttk_textfont, ttk_text_height (ttk_textfont) + 2));
    ttk_window_title (ret, title);
    return ret;
}
Esempio n. 2
0
TWindow *pz_new_textview_window(char *filename)
{
	TWindow *ret;
	char *buf = NULL;
	char tmp[4096];
	FILE *fp;
	long len, cs;

	if ((fp = fopen(filename, "r")) == NULL) {
		pz_perror(filename);
		return TTK_MENU_DONOTHING;
	}
	fseek(fp, 0L, SEEK_END);
	len = ftell(fp);
	rewind(fp);
	if (len == 0) {
		cs = 0;
		while (fgets(tmp, 4096, fp) != NULL) {
			len = buf ? strlen(buf) : 0;
			if (len + (long)strlen(tmp) > cs) {
				cs += 8192;
				if ((buf = realloc(buf, cs)) == NULL) {
					pz_error(_("Memory allocation failed"));
					fclose(fp);
					return TTK_MENU_DONOTHING;
				}
			}
			strncpy(buf + len, tmp, cs - len);
		}
		if (buf == NULL) {
			pz_message(_("Empty file"));
			fclose(fp);
			return TTK_MENU_DONOTHING;
		}
	}
	else {
		cs = len;
		if ((buf = malloc(len + 1)) == NULL) {
			pz_error(_("Memory allocation failed"));
			fclose(fp);
			return TTK_MENU_DONOTHING;
		}
		while (cs > 0) cs -= fread(buf + (len - cs), 1, cs, fp);
		*(buf + len) = '\0'; 
	}
	fclose(fp);

	ret = ttk_new_window();
	ret->data = 0x12345678;
	ttk_add_widget(ret, ttk_new_textarea_widget(ret->w, ret->h, buf,
				ttk_textfont, ttk_text_height(ttk_textfont)+2));
	ttk_window_title(ret, strrchr(filename, '/')?
			strrchr(filename, '/') + 1:filename);
	free(buf); /* strdup'd in textarea */
	return ret;
}
Esempio n. 3
0
TWindow *new_textview_window(char *filename)
{
    struct stat st;
    if (stat (filename, &st) < 0)
	return 0;
    char *buf = malloc (st.st_size);
    if (!buf)
	return 0;
    int fd = open (filename, O_RDONLY);
    if (fd < 0)
	return 0;
    read (fd, buf, st.st_size);
    close (fd);
    
    TWindow *ret = ttk_new_window();
    ttk_add_widget (ret, ttk_new_textarea_widget (ret->w, ret->h, buf, ttk_textfont, ttk_text_height (ttk_textfont) + 2));
    ttk_window_title (ret, strrchr (filename, '/')? strrchr (filename, '/') + 1 : filename);
    free (buf); // strdup'd in textarea
    return ret;
}
Esempio n. 4
0
TWindow *new_font_window (ttk_menu_item *item)
{
    TWindow *ret = ttk_new_window();
    TWidget *this = ttk_new_menu_widget (0, ttk_menufont, ret->w, ret->h);
    ttk_fontinfo *cur = ttk_fonts;
    
    while (cur) {
	ttk_menu_item *item = calloc (1, sizeof(ttk_menu_item));

	item->name = cur->name;
	item->makesub = select_font;
	item->flags = 0;
	item->data = cur;
	ttk_menu_append (this, item);
	
	cur = cur->next;
    }

    ttk_add_widget (ret, this);
    ttk_window_title (ret, _("Select Font"));
    return ret;
}
Esempio n. 5
0
TWindow * iconui_new_menu_window(TWidget * menu_wid)
{
	TWindow * ret;
	int iconsize = 1;//ipod_get_setting((75));
	int iconcache = 1;//ipod_get_setting((76));
	iconsize=1;
	iconcache=1;
	int i = 0;
	while (1) {
		ttk_menu_item * mi = ttk_menu_get_item(menu_wid, i);
		if (!mi) break;
		if (mi->makesub == ttk_mh_sub) mi->makesub = iconui_mh_sub;
		if (iconcache) ttk_free_surface(iconui_get_icon((char *)mi->name));
		i++;
	}
	
	switch (iconsize) {
	case 1: /* small list */
		menu_wid->draw = iconui_menu_draw;
		menu_wid->frame = iconui_menu_frame;
		menu_wid->down = iconui_menu_down;
		menu_wid->button = iconui_menu_button;
		menu_wid->scroll = iconui_menu_scroll;
		menu_wid->destroy = iconui_menu_free;
		//menu_wid->focusable=1;
		((menu_data *)menu_wid->data)->epoch--;
		break;
	case 2: /* large list */
		menu_wid->draw = bigiconui_menu_draw;
		menu_wid->frame = bigiconui_menu_frame;
		menu_wid->down = bigiconui_menu_down;
		menu_wid->button = bigiconui_menu_button;
		menu_wid->scroll = bigiconui_menu_scroll;
		menu_wid->destroy = bigiconui_menu_free;
		((menu_data *)menu_wid->data)->epoch--;
		break;
	case 3: /* small array */
		menu_wid->draw = icon2ui_menu_draw;
		menu_wid->frame = icon2ui_menu_frame;
		menu_wid->down = icon2ui_menu_down;
		menu_wid->button = icon2ui_menu_button;
		menu_wid->scroll = icon2ui_menu_scroll;
		menu_wid->destroy = icon2ui_menu_free;
		((menu_data *)menu_wid->data)->font = iconui_font;
		((menu_data *)menu_wid->data)->epoch--;
		break;
	case 4: /* large array */
		menu_wid->draw = bigicon2ui_menu_draw;
		menu_wid->frame = bigicon2ui_menu_frame;
		menu_wid->down = bigicon2ui_menu_down;
		menu_wid->button = bigicon2ui_menu_button;
		menu_wid->scroll = bigicon2ui_menu_scroll;
		menu_wid->destroy = bigicon2ui_menu_free;
		((menu_data *)menu_wid->data)->font = iconui_font;
		((menu_data *)menu_wid->data)->epoch--;
		break;
	case 5: /* small dock */
		menu_wid->draw = smdockiconui_menu_draw;
		menu_wid->frame = smdockiconui_menu_frame;
		menu_wid->down = smdockiconui_menu_down;
		menu_wid->button = smdockiconui_menu_button;
		menu_wid->scroll = smdockiconui_menu_scroll;
		menu_wid->destroy = smdockiconui_menu_free;
		((menu_data *)menu_wid->data)->font = iconui_font;
		((menu_data *)menu_wid->data)->epoch--;
		break;
	case 6: /* mag dock */
		menu_wid->draw = mdockiconui_menu_draw;
		menu_wid->frame = mdockiconui_menu_frame;
		menu_wid->down = mdockiconui_menu_down;
		menu_wid->button = mdockiconui_menu_button;
		menu_wid->scroll = mdockiconui_menu_scroll;
		menu_wid->destroy = mdockiconui_menu_free;
		((menu_data *)menu_wid->data)->font = iconui_font;
		((menu_data *)menu_wid->data)->epoch--;
		break;
	case 7: /* large dock */
		menu_wid->draw = dockiconui_menu_draw;
		menu_wid->frame = dockiconui_menu_frame;
		menu_wid->down = dockiconui_menu_down;
		menu_wid->button = dockiconui_menu_button;
		menu_wid->scroll = dockiconui_menu_scroll;
		menu_wid->destroy = dockiconui_menu_free;
		((menu_data *)menu_wid->data)->font = iconui_font;
		((menu_data *)menu_wid->data)->epoch--;
		break;
	}
	
	ret = ttk_new_window();
	ttk_add_widget(ret, menu_wid);
	ttk_window_title(ret, "ZacZilla");
	return ret;
}
Esempio n. 6
0
int pz_menuconf_runargs(int argc, char * argv[])
{
	use_str_switch;
	str_switch(argv[0]) {
	str_case("rm")
		if (argc < 2) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (CHKPWR(argv[1])) {
			pz_error("Cannot modify the Power menu from menu.conf.");
		} else {
			pz_menu_remove(argv[1]);
		}
	str_case("hide")
		if (argc < 2) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (CHKPWR(argv[1])) {
			pz_error("Cannot modify the Power menu from menu.conf.");
		} else {
			pz_menu_remove(argv[1]);
		}
	str_case("show")
		if (argc < 2) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (CHKPWR(argv[1])) {
			pz_error("Cannot modify the Power menu from menu.conf.");
		} else {
			ttk_menu_item * item = pz_get_menu_item(argv[1]);
			if (item) item->visible = 0;
		}
	str_case("mv")
		if (argc < 3) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (CHKPWR(argv[1]) || CHKPWR(argv[2])) {
			pz_error("Cannot modify the Power menu from menu.conf.");
		} else {
			ttk_menu_item * item = pz_get_menu_item(argv[1]);
			if (item) {
				ttk_menu_item * nitem;
				pz_menu_add_stub(argv[2]);
				nitem = pz_get_menu_item(argv[2]);
				if (!nitem) {
					pz_error("Could not create menu item %s in menu.conf.", argv[2]);
				} else {
					nitem->makesub = item->makesub;
					nitem->sub = item->sub;
					nitem->flags = item->flags;
					nitem->data = item->data;
					nitem->choices = item->choices;
					nitem->cdata = item->cdata;
					nitem->choicechanged = item->choicechanged;
					nitem->choiceget = item->choiceget;
					nitem->choice = item->choice;
					nitem->visible = item->visible;
					nitem->free_data = item->free_data;
					item->free_data = 0;
				}
				pz_menu_remove(argv[1]);
			}
		}
	str_case("cp")
		if (argc < 3) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (CHKPWR(argv[2])) {
			pz_error("Cannot modify the Power menu from menu.conf.");
		} else {
			ttk_menu_item * item = pz_get_menu_item(argv[1]);
			if (item) {
				ttk_menu_item * nitem;
				pz_menu_add_stub(argv[2]);
				nitem = pz_get_menu_item(argv[2]);
				if (!nitem) {
					pz_error("Could not create menu item %s in menu.conf.", argv[2]);
				} else {
					nitem->makesub = item->makesub;
					nitem->sub = item->sub;
					nitem->flags = item->flags;
					nitem->data = item->data;
					nitem->choices = item->choices;
					nitem->cdata = item->cdata;
					nitem->choicechanged = item->choicechanged;
					nitem->choiceget = item->choiceget;
					nitem->choice = item->choice;
					nitem->visible = item->visible;
					nitem->free_data = 0;
				}
			}
		}
	str_case("ln")
		if (argc < 3) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (CHKPWR(argv[2])) {
			pz_error("Cannot modify the Power menu from menu.conf.");
		} else {
			ttk_menu_item * nitem;
			pz_menu_add_ttkh(argv[2], pz_menuconf_browser_open, 0);
			nitem = pz_get_menu_item(argv[2]);
			if (!nitem) {
				pz_error("Could not create menu item %s in menu.conf.", argv[2]);
			} else {
				nitem->data = strdup(argv[1]);
				nitem->free_data = 1;
			}
		}
	str_case("sort")
		if (argc < 2) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (CHKPWR(argv[1])) {
			pz_error("Cannot modify the Power menu from menu.conf.");
		} else {
			pz_menu_sort(argv[1]);
		}
	str_case("title")
		if (argc < 2) {
			pz_error("Too few arguments to %s in menu.conf.", argv[0]);
		} else if (ttk_windows && ttk_windows->w) {
			ttk_window_title(ttk_windows->w, argv[1]);
		}
	str_case("group")
		if (argc != 3 ) {
			pz_error("Incorrect arguments to %s in menu.conf.", argv[0]);
		} else {
			ttk_menu_item * nitem;
			nitem = pz_get_menu_item(argv[1]);
			if (!nitem) {
				pz_error("Could not regroup  menu item %s in menu.conf.", argv[1]);
			} else {
				if( nitem->group_name ) free( nitem->group_name);
				nitem->group_name = strdup( argv[2] );
			}
		}
	str_default
		pz_error("Invalid command %s in menu.conf.", argv[0]);
	}
	return 0;
}