diff options
-rw-r--r-- | atari/gemtk/gemtk.h | 4 | ||||
-rw-r--r-- | atari/gemtk/objc.c | 133 | ||||
-rwxr-xr-x | atari/res/netsurf.rsc | bin | 38082 -> 37984 bytes | |||
-rwxr-xr-x | atari/res/netsurf.rsh | 10 | ||||
-rwxr-xr-x | atari/res/netsurf.rsm | 15 | ||||
-rw-r--r-- | atari/settings.c | 53 |
6 files changed, 186 insertions, 29 deletions
diff --git a/atari/gemtk/gemtk.h b/atari/gemtk/gemtk.h index 88ad0ccdb..d5b553a1e 100644 --- a/atari/gemtk/gemtk.h +++ b/atari/gemtk/gemtk.h @@ -279,4 +279,8 @@ bool gemtk_obj_is_inside(OBJECT * tree, short obj, GRECT *area); OBJECT *gemtk_obj_get_tree(int idx); void gemtk_obj_mouse_sprite(OBJECT *tree, int index); OBJECT *gemtk_obj_tree_copy(OBJECT *tree); +OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems, + char * selected, bool horizontal, + int max_width); +void gemtk_obj_destroy_popup_tree(OBJECT * popup); #endif // GEMTK_H_INCLUDED diff --git a/atari/gemtk/objc.c b/atari/gemtk/objc.c index 5d47bd64c..3c13f553c 100644 --- a/atari/gemtk/objc.c +++ b/atari/gemtk/objc.c @@ -368,3 +368,136 @@ OBJECT *gemtk_obj_tree_copy(OBJECT *tree) return(new_tree); } + + +OBJECT * gemtk_obj_create_popup_tree(const char **items, int nitems, + char * selected, bool horizontal, + int max_width) +{ + OBJECT * popup = NULL; + int box_width = 0; + int box_height = 0; + int char_width = 10; + int char_height = 16; + int item_height; // height of each item + + assert(items != NULL); + + item_height = char_height; + + /* Allocate room for n items and the root G_BOX: */ + popup = calloc(nitems+1, sizeof(OBJECT)); + assert(popup != null); + + for (int i=0; i<nitems; i++) { + + int len = strlen(items[i]); + + if (horizontal && (max_width<1)) { + box_width += len * char_width; + } + else if (!horizontal){ + /* Detect max width, used for vertical rendering: */ + if(len*char_width > box_width){ + box_width = (len+2) * char_width; + } + box_height += item_height; + } + } + + if (max_width>0){ + box_width = max_width; + } + + if (horizontal) { + box_height = item_height; + } + +/* + printf("popup height: %d, popup width: %d\n", box_height, box_width); +*/ + + popup[0].ob_next = -1; /**< object's next sibling */ + popup[0].ob_head = 1; /**< head of object's children */ + popup[0].ob_tail = nitems; /**< tail of object's children */ + popup[0].ob_type = G_BOX; /**< type of object */ + popup[0].ob_flags = OF_FL3DBAK; /**< flags */ + popup[0].ob_state = OS_NORMAL; /**< state */ + popup[0].ob_spec.index = (long) 16650496L; /**< object-specific data */ + popup[0].ob_x = 0; /**< upper left corner of object */ + popup[0].ob_y = 0; /**< upper left corner of object */ + popup[0].ob_width = box_width; /**< width of obj */ + popup[0].ob_height = box_height; + + + + /* Add items to popup: */ + int xpos = 0, ypos = 0; + + for (int i=0; i<nitems; i++) { + + int state = OS_NORMAL; + int flags = OF_NONE; + int item_width; + char * string = calloc(1, strlen(items[i])+3); + + snprintf(string, strlen(items[i])+3, " %s", items[i]); + + if (selected != NULL) { + if (strcmp(selected, items[i]) == 0) { + state |= OS_CHECKED; + } + } + + if (i == nitems-1) { + flags |= OF_LASTOB; + } + + item_width = (horizontal) ? ((int)strlen(items[i])*char_width) : box_width; + +/* + printf("addin popup item \"%s\" (w: %d, h: %d, flags: %x) at %d/%d\n", items[i], + item_width, item_height, flags, + xpos, ypos); +*/ + + popup[i+1].ob_next = ((flags&OF_LASTOB) != 0) ? 0 : i+2; /**< object's next sibling */ + popup[i+1].ob_head = -1; /**< head of object's children */ + popup[i+1].ob_tail = -1; /**< tail of object's children */ + popup[i+1].ob_type = G_STRING; /**< type of object */ + popup[i+1].ob_flags = flags; /**< flags */ + popup[i+1].ob_state = state; /**< state */ + popup[i+1].ob_spec.free_string = string; /**< object-specific data */ + popup[i+1].ob_x = xpos; /**< upper left corner of object */ + popup[i+1].ob_y = ypos; /**< upper left corner of object */ + popup[i+1].ob_width = item_width; /**< width of obj */ + popup[i+1].ob_height = item_height; + + if (horizontal) { + xpos += item_width; + } + else { + ypos += item_height; + } + + } + + return(popup); +} + +void gemtk_obj_destroy_popup_tree(OBJECT * popup) +{ + int i=0; + + while (1) { + if (popup[i].ob_type == G_STRING) { + free(popup[i+1].ob_spec.free_string); + } + if((popup[i].ob_flags & OF_LASTOB) != OF_LASTOB){ + break; + } + i++; + } + + free(popup); +} diff --git a/atari/res/netsurf.rsc b/atari/res/netsurf.rsc Binary files differindex b47cff0b8..165dd9bf8 100755 --- a/atari/res/netsurf.rsc +++ b/atari/res/netsurf.rsc diff --git a/atari/res/netsurf.rsh b/atari/res/netsurf.rsh index 7255544ed..d37e48768 100755 --- a/atari/res/netsurf.rsh +++ b/atari/res/netsurf.rsh @@ -212,13 +212,9 @@ #define POP_LANGUAGE_SK 14 /* STRING in tree POP_LANGUAGE */
#define POP_LANGUAGE_SV 15 /* STRING in tree POP_LANGUAGE */
-#define POP_FONT_RENDERER 15 /* form/dial */
-#define POP_FONT_RENDERER_INTERNAL 1 /* STRING in tree POP_FONT_RENDERER */
-#define POP_FONT_RENDERER_FREETYPE 2 /* STRING in tree POP_FONT_RENDERER */
+#define TOOLBAR_COOKIES 15 /* form/dial */
-#define TOOLBAR_COOKIES 16 /* form/dial */
+#define TOOLBAR_HISTORY 16 /* form/dial */
-#define TOOLBAR_HISTORY 17 /* form/dial */
-
-#define TOOLBAR_SSL_CERT 18 /* form/dial */
+#define TOOLBAR_SSL_CERT 17 /* form/dial */
#define TOOLBAR_SSL_CERT_TRUSTED 1 /* BUTTON in tree TOOLBAR_SSL_CERT */
diff --git a/atari/res/netsurf.rsm b/atari/res/netsurf.rsm index 37741a937..5074e078b 100755 --- a/atari/res/netsurf.rsm +++ b/atari/res/netsurf.rsm @@ -1,9 +1,9 @@ ResourceMaster v3.65
-#C 19@0@0@0@
+#C 18@0@0@0@
#N 99@32@AZAaza___ _@AZAaza090___ _@@_@
#FoC-Header@rsm2out@C-Header@rsh@@@[C-Header@0@
#R 0@0@1@1@2@1@
-#M 20010100@0@7728@653@
+#M 20010100@0@7728@654@
#T 0@1@MAINMENU@@64@@
#O 4@32@T_FILE@@
#O 5@32@T_EDIT@@
@@ -199,11 +199,8 @@ ResourceMaster v3.65 #O 13@28@RU@@
#O 14@28@SK@@
#O 15@28@SV@@
-#T 15@2@POP_FONT_RENDERER@@3@@
-#O 1@28@INTERNAL@@
-#O 2@28@FREETYPE@@
-#T 16@2@TOOLBAR_COOKIES@@1@@
-#T 17@2@TOOLBAR_HISTORY@@1@@
-#T 18@2@TOOLBAR_SSL_CERT@@2@@
+#T 15@2@TOOLBAR_COOKIES@@1@@
+#T 16@2@TOOLBAR_HISTORY@@1@@
+#T 17@2@TOOLBAR_SSL_CERT@@2@@
#O 1@26@TRUSTED@@
-#c 28824@
+#c 27986@
diff --git a/atari/settings.c b/atari/settings.c index 51db0fa91..d0601cae8 100644 --- a/atari/settings.c +++ b/atari/settings.c @@ -8,6 +8,7 @@ #include <string.h> #include <stdbool.h> #include <cflib.h> +#include <gem.h> #include "utils/nsoption.h" #include "desktop/plot_style.h" @@ -40,6 +41,22 @@ static short any_obj = -1; static GUIWIN * settings_guiwin = NULL; static OBJECT * dlgtree; +/* Available font engines for the font engine selection popup: */ +static const char *font_engines[] = { + +#ifdef WITH_FREETYPE_FONT_DRIVER + "freetype", +#endif + +#ifdef WITH_INTERNAL_FONT_DRIVER + "internal", +#endif + +#ifdef WITH_VDI_FONT_DRIVER + "vdi", +#endif +}; + #define OBJ_SELECTED(idx) ((bool)((dlgtree[idx].ob_state & OS_SELECTED)!=0)) #define OBJ_CHECK(idx) (dlgtree[idx].ob_state |= (OS_SELECTED)); @@ -103,6 +120,7 @@ static void set_text( short idx, char * text, int len ) static void toggle_objects(void) { /* enable / disable (refresh) objects depending on radio button values: */ + /* Simulate GUI events which trigger refresh of bound elements: */ FORMEVENT(SETTINGS_CB_USE_PROXY); FORMEVENT(SETTINGS_CB_PROXY_AUTH); FORMEVENT(SETTINGS_BT_SEL_FONT_RENDERER); @@ -250,7 +268,6 @@ static void display_settings(void) toggle_objects(); } - static void form_event(int index, int external) { char spare[255]; @@ -259,9 +276,6 @@ static void form_event(int index, int external) char * tmp; MENU pop_menu, me_data; - /* For font driver popup: */ - int num_font_drivers = 2; - /* Just a small collection of locales, each country has at least one ATARI-clone user! :) @@ -319,37 +333,50 @@ static void form_event(int index, int external) case SETTINGS_BT_SEL_FONT_RENDERER: if( external ) { objc_offset(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER, &x, &y); - // point mn_tree tree to states popup: - pop_menu.mn_tree = gemtk_obj_get_tree(POP_FONT_RENDERER); + // point mn_tree tree to font renderer popup: + pop_menu.mn_tree = gemtk_obj_create_popup_tree(font_engines, + NOF_ELEMENTS(font_engines), NULL, false,-1); + + assert(pop_menu.mn_tree != NULL); + pop_menu.mn_menu = 0; - pop_menu.mn_item = POP_FONT_RENDERER_INTERNAL; + pop_menu.mn_item = 1; // POP_FONT_RENDERER_INTERNAL; pop_menu.mn_scroll = SCROLL_NO; pop_menu.mn_keystate = 0; + + /* Get font renderer value currently displayed in the dialog: */ + tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER); + // find the selected menu item and uncheck others: - for(i=pop_menu.mn_item; i<=num_font_drivers; i++) { + for(i=pop_menu.mn_item; i<=(short)NOF_ELEMENTS(font_engines); i++) { + /* Get string of menu item: */ get_string(pop_menu.mn_tree, i, spare); - tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER); + + /* Compare menu item text with the text currently displayed in GUI: */ if (strcasecmp(&spare[2], tmp)) { menu_icheck(pop_menu.mn_tree, i, 0); } else { + /* set menu item selected: */ menu_icheck(pop_menu.mn_tree, i, 1); } set_string(pop_menu.mn_tree, i, spare); } + /* Show the popup: */ menu_popup(&pop_menu, x, y, &me_data); choice = me_data.mn_item; - if( choice > 0 && choice <= num_font_drivers ) { + + /* Process selection: */ + if (choice > 0 && choice <= (short)NOF_ELEMENTS(font_engines)) { get_string(pop_menu.mn_tree, choice, spare); - for(i=2; i<(int)strlen(spare); i++) { - spare[i]= (char)tolower(spare[i]); - } set_text(SETTINGS_BT_SEL_FONT_RENDERER, (char*)&spare[2], LABEL_FONT_RENDERER_MAX_LEN); OBJ_REDRAW(SETTINGS_BT_SEL_FONT_RENDERER); } + + gemtk_obj_destroy_popup_tree(pop_menu.mn_tree); } tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER); if (strcasecmp(tmp, "freetype") == 0) { |