First commit

This commit is contained in:
2016-11-25 00:27:22 -07:00
commit 5106228da2
41 changed files with 40154 additions and 0 deletions

39
eugtk/GtkAboutDialog.e Normal file
View File

@@ -0,0 +1,39 @@
-------------------
namespace about -- Generic About dialog
-------------------
export constant version = "4.12.0"
--# EXPORTS: about:Dialog -- use run(about:Dialog), not show()
include GtkEngine.e
public include euphoria/info.e
if not equal(version,gtk:version) then
Error(,,"GtkAboutDialog version mismatch","should be version " & gtk:version)
end if
export atom Dialog = create(GtkAboutDialog,{
{"name","about:dialog"},
{"logo","thumbnails/eugtk.png"},
{"program name",prg_name},
{"version","EuGTK version: " & gtk:version},
{"copyright",copyright},
{"comments","For information on the Euphoria\nprogramming language, click below"},
-- must specify custom as the license type if supplying license text;
{"license type",GTK_LICENSE_CUSTOM},
{"license",LGPL}, -- LGPL text is built into EuGTK
{"wrap license",0},
{"website","http://OpenEuphoria.org"},
{"website label","OpenEuphoria"},
{"authors",{"Irv Mullins"}},
--{"artists",0},
--{"documenters",0},
--{"translator credits",0},
--{"add credit section","Special Thanks to",{"\nBob's Burgers\nDuff's Beer"}},
$})

643
eugtk/GtkCairo.e Normal file
View File

@@ -0,0 +1,643 @@
----------------------------
namespace cairo
----------------------------
export constant version = "4.12.0"
include GtkEngine.e
if not equal(version,gtk:version) then
Error(,,"GtkCairo version mismatch","should be version " & gtk:version)
end if
export constant pango_version = gtk_str_func("pango_version_string")
widget[GdkCairo_t] = {"gdk_cairo",
{Cairo_t},
{"new",{P},-routine_id("newGdkCairo")},
{"draw_from_gl",{P,P,I,I,I,I,I,I,I}}, -- 3.16
{"get_clip_rectangle",{P},-routine_id("getClipRect")},
{"set_source_pixbuf",{P,P,D,D}},
{"set_source_window",{P,P,D,D}},
{"region",{P,P}},
{"region_create_from_surface",{P},P},
{"surface_create_from_pixbuf",{P,I,P},P,0,CairoSurface_t},
{"set_source_rgba",{P,I,I,I,D},-routine_id("setCairoRGBA")},
{"set_color",{P,P},-routine_id("setCairoColor")},
"GdkCairo_t"}
function getClipRect(atom cr)
atom fn = define_func("gdk_cairo_get_clip_rectangle",{P,P},B)
atom rect = allocate(8,1)
if c_func(fn,{cr,rect}) then
return rect
else return -1
end if
end function
function newGdkCairo(atom win)
return gtk_func("gdk_cairo_create",{P},{win})
end function
----------------------------------------------------------------
-- to use the Cairo color specs, where colors are 0.0 => 1.0
----------------------------------------------------------------------
function setCairoRGBA(atom cr, atom r, atom g, atom b, atom a=1)
gtk_proc("cairo_set_source_rgba",{P,D,D,D,D},{cr,r,g,b,a})
return 1
end function
--------------------------------------------
-- it's easier to use named colors
--------------------------------------------
function setCairoColor(atom cr, object color)
if atom(color) then color = sprintf("#%06x",color) end if
color = to_rgba(color)
color = from_rgba(color,7)
setCairoRGBA(cr,color[1],color[2],color[3],color[4])
return 1
end function
widget[Cairo_t] = {"cairo",
{GObject},
{"create",{P},P},
{"reference",{P},P},
{"destroy",{P}},
{"status",{P},I},
{"save",{P}},
{"restore",{P}},
{"get_target",{P},P,0,CairoSurface_t},
{"push_group",{P}},
{"push_group_with_content",{P,P}},
{"pop_group",{P},P},
{"pop_group_to_source",{P}},
{"get_group_target",{P},P},
{"set_source_rgb",{P,D,D,D}},
{"set_source",{P,P}},
{"get_source",{P},P},
{"set_source_surface",{P,P,D,D}},
{"set_antialias",{P,I}},
{"get_antialias",{P},I},
{"set_dash",{P,P,I,D}},
{"get_dash_count",{P},I},
{"get_dash",{P,D,D}},
{"set_fill_rule",{P,I}},
{"get_fill_rule",{P},I},
{"set_line_cap",{P,I}},
{"get_line_cap",{P},I},
{"set_line_join",{P,I}},
{"get_line_join",{P},I},
{"set_line_width",{P,D}},
{"get_line_width",{P},D},
{"set_miter_limit",{P,I}},
{"get_miter_limit",{P},I},
{"set_operator",{P,I}},
{"get_operator",{P},I},
{"set_tolerance",{P,D}},
{"get_tolerance",{P},D},
{"clip",{P}},
{"clip_preserve",{P}},
{"clip_extents",{P,D,D,D,D}},
{"in_clip",{P,D,D},B},
{"reset_clip",{P}},
{"rectangle_list_destroy",{P}},
{"fill",{P}},
{"fill_preserve",{P}},
{"fill_extents",{P,D,D,D,D}},
{"in_fill",{P,D,D},B},
{"mask",{P,P}},
{"mask_surface",{P,P,D,D}},
{"paint",{P}},
{"paint_with_alpha",{P,D}},
{"stroke",{P}},
{"stroke_preserve",{P}},
{"stroke_extents",{P,D,D,D,D}},
{"in_stroke",{P,D,D},B},
{"copy_page",{P}},
{"show_page",{P}},
{"copy_path",{P},P},
{"copy_path_flat",{P},P},
{"path_destroy",{P}},
{"append_path",{P,P}},
{"has_current_point",{P},B},
{"get_current_point",{P,D,D}},
{"new_path",{P}},
{"new_sub_path",{P}},
{"close_path",{P}},
{"set_user_data",{P,S,P,P},I},
{"get_user_data",{P,S}},
{"arc",{P,D,D,D,D,D}},
{"arc_negative",{P,D,D,D,D,D}},
{"move_to",{P,D,D}},
{"rel_move_to",{P,D,D}},
{"line_to",{P,D,D}},
{"rel_line_to",{P,D,D}},
{"rectangle",{P,D,D,D,D}},
{"glyph_path",{P,I,I}},
{"text_path",{P,S}},
{"curve_to",{P,D,D,D,D,D,D}},
{"rel_curve_to",{P,D,D,D,D,D,D}},
{"path_extents",{P,D,D,D,D}},
{"set_font_face",{P,S}},
{"device_get_type",{P},I},
{"device_status",{P},I},
{"status_to_string",{I},S},
{"translate",{P,D,D}},
{"scale",{P,D,D}},
{"rotate",{P,D}},
{"transform",{P,P}},
{"translate",{P,D,D}},
{"scale",{P,D,D}},
{"rotate",{P,D}},
{"transform",{P,P}},
{"set_matrix",{P,P}},
{"get_matrix",{P,P}},
{"identity_matrix",{P}},
{"user_to_device",{P,D,D}},
{"user_to_device_distance",{P,D,D}},
{"device_to_user",{P,D,D}},
{"device_to_user_distance",{P,D,D}},
{"version",{},I},
{"version_string",{},S},
{"set_font_size",{P,D}},
{"set_font_matrix",{P,P}},
{"get_font_matrix",{P,P}},
{"set_font_options",{P,P}},
{"get_font_options",{P,P}},
{"select_font_face",{P,S,I,I}},
{"get_font_face",{P},P},
{"set_scaled_font",{P,P}},
{"get_scaled_font",{P},P},
{"show_glyphs",{P,P}},
{"show_text_glyphs",{P,S,I,P,I,P,I,I}},
{"font_extents",{P,P}},
{"text_extents",{P,S,P}},
{"glyph_extents",{P,P,I,P}},
{"toy_font_face_create",{S,I,I},P},
{"toy_font_face_get_slant",{P},I},
{"toy_font_face_get_weight",{P},I},
{"glyph_allocate",{I},P},
{"glyph_free",{P}},
{"text_cluster_allocate",{I},P},
{"text_cluster_free",{P}},
{"show_text",{P,S}},
{"set_source_rgba",{P,D,D,D,D},-routine_id("setCairoRGBA")},
{"set_color",{P,S},-routine_id("setCairoColor")},
{"should_draw_window",{P,P},-routine_id("CairoShouldDrawWin")},
{"transform_to_window",{P,P,P},-routine_id("CairoTransformToWin")},
"Cairo_t"}
function CairoShouldDrawWin(atom cr, atom win)
return gtk_func("gtk_cairo_should_draw_window",{P,P},{cr,win})
end function
function CairoTransformToWin(atom cr, atom win1, atom win2)
gtk_proc("gtk_cairo_transform_to_window",{P,P,P},{cr,win1,win2})
return 1
end function
widget[CairoPattern_t] = {0,
{Cairo_t},
"CairoPattern_t"}
widget[CairoFontOptions] = {"cairo_font_options",
{0},
"CairoFontOptions"}
widget[CairoContent_t] = {0,
{Cairo_t},
"CairoContent_t"}
widget[CairoStatus_t] = {0,
{0},
"CairoStatus_t"}
widget[CairoPattern] = {"cairo_pattern",
{CairoPattern_t},
{"new",{P},-routine_id("newCairoPattern")},
{"add_color_stop_rgb",{P,D,D,D,D}},
{"add_color_stop_rgba",{P,D,D,D,D,D}},
{"get_color_stop_count",{P,I},P,0,CairoStatus_t},
{"get_color_stop_rgba",{P,I,D,D,D,D,D},P,0,CairoStatus_t},
{"create_rgb",{D,D,D},P,0,CairoPattern_t},
{"create_rgba",{D,D,D,D},P,0,CairoPattern_t},
{"get_rgba",{P,D,D,D,D},P,0,CairoPattern_t},
{"create_for_surface",{P},P,0,CairoPattern_t},
{"reference",{P},P,0,CairoPattern_t},
{"destroy",{P}},
{"status",{P},P,0,CairoStatus_t},
{"set_extend",{P,I}},
{"get_extend",{P},I},
{"set_filter",{P,I}},
{"get_filter",{P},I},
{"set_matrix",{P,P}},
{"get_matrix",{P,P}},
{"get_type",{P},I},
{"get_reference_count",{P},I},
"CairoPattern"}
function newCairoPattern(atom surf)
return gtk_func("cairo_pattern_create_for_surface",{P},{surf})
end function
widget[CairoLinearGradient] = {"cairo_pattern",
{CairoPattern},
{"new",{D,D,D,D},-routine_id("newLinearGradient"),0,CairoPattern_t},
{"get_linear_points",{P,D,D,D,D},P,0,CairoStatus_t},
"CairoLinearGradient"}
function newLinearGradient(atom a, atom b, atom c, atom d)
return gtk_func("cairo_pattern_create_linear",{D,D,D,D},{a,b,c,d})
end function
widget[CairoRadialGradient] = {"cairo_pattern",
{CairoPattern},
{"new",{D,D,D,D,D,D},-routine_id("newRadialGradient"),0,CairoPattern_t},
{"get_radial_circles",{P,D,D,D,D,D,D},P,0,CairoStatus_t},
"CairoRadialGradient"}
function newRadialGradient(atom a, atom b, atom c, atom d, atom e, atom f)
return gtk_func("cairo_pattern_create_radial",{D,D,D,D,D,D},{a,b,c,d,e,f})
end function
widget[CairoRegion_t] = {"cairo_region_t", -- FIXME!
{Cairo_t},
"CairoRegion_t"}
widget[CairoSurface_t] = {"cairo_surface_t",
{Cairo_t},
{"get_write_to_png",{P,S},-routine_id("writetoPNG")},
{"create_similar",{P,P,I,I},P,0,CairoSurface_t},
{"create_for_rectangle",{P,D,D,D,D},P,0,CairoSurface_t},
{"reference",{P},P,0,CairoSurface_t},
{"destroy",{P}},
{"finish",{P}},
{"flush",{P}},
{"get_font_options",{P,P}},
{"mark_dirty",{P}},
{"mark_dirty_rectangle",{P,I,I,I,I}},
{"show_page",{P}},
"CairoSurface_t"}
function writetoPNG(atom surf, object name) -- note difference in call name;
return gtk_func("cairo_surface_write_to_png",{P,S},{surf,name})
end function
widget[CairoImageSurface] = {"cairo_image_surface",
{CairoSurface_t},
{"new",{P},-routine_id("newCairoImageSurface")},
{"get_format",{P},I},
{"get_width",{P},P},
{"get_height",{P},P},
{"get_stride",{P},I},
"CairoImageSurface"}
function newCairoImageSurface(object png)
if string(png) then
png = locate_file(png) if file_type(png) = 1 then
png = allocate_string(png)
end if
end if
return gtk_func("cairo_image_surface_create_from_png",{S},{png})
end function
widget[PangoCairoLayout] = {"pango_cairo",
{PangoLayout},
{"new",{P},-routine_id("newPangoCairoLayout")},
{"update_layout",{P,P},-routine_id("updateLayout")},
{"show_glyph_string",{P,P,P}},
{"show_glyph_item",{P,S,P}},
{"show_layout_line",{P,P}},
{"layout_line_path",{P,P}},
{"layout_path",{P,P}},
"PangoCairoLayout"}
function newPangoCairoLayout(atom cr)
atom pcl = gtk_func("pango_cairo_create_layout",{P},{cr})
register(pcl,PangoLayout)
return pcl
end function
function updateLayout(atom pl, atom cr) -- params swapped;
gtk_proc("pango_cairo_update_layout",{P,P},{cr,pl})
return 1
end function
widget[PangoFont] = {"pango_font",
{0},
{"describe",{P},P,0,PangoFontDescription},
{"describe_with_absolute_size",{P},P,0,PangoFontDescription},
{"get_coverage",{P,P},P},
{"get_metrics",{P,P},P},
{"get_font_map",{P},P,0,PangoFontMap},
"PangoFont"}
widget[PangoAttrList] = {"pango_attr_list",
{0},
"PangoAttrList"}
widget[PangoFontDescription] = {"pango_font_description",
{PangoFont},
{"new",{P},-routine_id("newPangoFontDescription")},
{"copy",{P},P,0,PangoFontDescription},
{"copy_static",{P},P,0,PangoFontDescription},
{"hash",{P},I},
{"equal",{P,P},B},
{"free",{P}},
{"set_family",{P,S}},
{"set_family_static",{P,S}},
{"get_family",{P},S},
{"set_style",{P,I}},
{"get_style",{P},I},
{"set_variant",{P,I}},
{"get_variant",{P},P},
{"set_weight",{P,I}},
{"get_weight",{P},I},
{"set_stretch",{P,I}},
{"get_stretch",{P},I},
{"set_size",{P,I}},
{"get_size",{P},I},
{"set_absolute_size",{P,D}},
{"get_size_is_absolute",{P},B},
{"set_gravity",{P,I}},
{"get_gravity",{P},I},
{"get_set_fields",{P},I},
{"unset_fields",{P,I}},
{"merge",{P,P,B}},
{"merge_static",{P,P,B}},
{"better_match",{P,P,P},B},
-- from_string, see new
{"to_string",{P},S},
{"to_filename",{P},S},
"PangoFontDescription"}
function newPangoFontDescription(object name=0)
if atom(name) then
return gtk_func("pango_font_description_new")
else
return gtk_func("pango_font_description_from_string",{P},{allocate_string(name,1)})
end if
end function
widget[PangoContext] = {"pango_context",
{GObject},
{"new",{},P},
{"load_font",{P,P},P},
{"load_fontset",{P,P,P},P},
{"get_metrics",{P,P,P},P},
{"list_families",{P,A,I}},
{"set_font_description",{P,P}},
{"get_font_description",{P},P,0,PangoFontDescription},
{"set_font_map",{P,P}},
{"get_font_map",{P},P},
{"set_base_gravity",{P,I}},
{"get_language",{P},P},
{"set_language",{P,P}},
{"get_layout",{P},P},
{"get_base_dir",{P},I},
{"set_base_dir",{P,I}},
{"get_base_gravity",{P},I},
{"set_base_gravity",{P,I}},
{"get_gravity",{P},I},
{"get_gravity_hint",{P},I},
{"set_gravity_hint",{P,I}},
{"get_matrix",{P},P},
{"set_matrix",{P,P}},
"PangoContext"}
widget[PangoFontsetSimple] = {"pango_fontset_simple",
{GObject},
{"new",{P},P},
{"append",{P,P}},
{"size",{P},I},
"PangoFontsetSimple"}
widget[PangoFontSet] = {"pango_fontset",
{PangoFontsetSimple},
{"get_font",{P,I},P,0,PangoFont},
{"get_metrics",{P},P},
{"foreach",{P,P,P}},
"PangoFontSet"}
widget[PangoFontMap] = {"pango_font_map",
{PangoFontSet},
{"create_context",{P},P},
{"load_font",{P,P,S},P},
{"load_fontset",{P,P,S,P},P},
{"list_families",{P,A,I}},
{"get_shape_engine_type",{P},S},
{"get_serial",{P},I},
{"changed",{P}},
"PangoFontMap"}
widget[PangoFontFace] = {"pango_font_face",
{PangoFontMap},
{"get_face_name",{P},S},
{"list_sizes",{P,P,I}},
{"describe",{P},P,0,PangoFontDescription},
{"is_synthesized",{P},B},
"PangoFontFace"}
widget[PangoFontFamily] = {"pango_font_family",
{PangoFontFace},
{"get_name",{P},S},
{"is_monospace",{P},B},
{"list_faces",{P,P,I}},
"PangoFontFamily"}
widget[PangoLayout] = {"pango_layout",
{GObject},
{"new",{P},-routine_id("newPangoLayout")},
{"set_text",{P,P},-routine_id("pl_set_text")},
{"get_text",{P},S},
{"get_character_count",{P},I},
{"set_markup",{P,S},-routine_id("pl_set_markup")},
{"set_markup_with_accel",{P,S,I,I},-routine_id("pl_set_markup_with_accel")},
{"set_font_description",{P,P}},
{"get_font_description",{P},P},
{"set_attributes",{P,P}},
{"get_attributes",{P},P,0,PangoAttrList},
{"set_width",{P,I}},
{"get_width",{P},I},
{"set_height",{P,I}},
{"get_height",{P},I},
{"get_size",{P,I,I}},
{"get_pixel_size",{P,I,I}},
{"set_wrap",{P,I}},
{"get_wrap",{P},I},
{"is_wrapped",{P},B},
{"set_ellipsize",{P,I}},
{"get_ellipsize",{P},I},
{"is_ellipsized",{P},B},
{"set_indent",{P,I}},
{"get_extents",{P,P,P}},
{"get_indent",{P},I},
{"get_pixel_size",{P,I,I}},
{"get_size",{P,I,I}},
{"set_spacing",{P,I}},
{"get_spacing",{P},I},
{"set_justify",{P,B}},
{"get_justify",{P},B},
{"set_auto_dir",{P,B}},
{"get_auto_dir",{P},B},
{"set_alignment",{P,P}},
{"get_alignment",{P},P},
{"set_tabs",{P,A}},
{"get_tabs",{P},A},
{"set_single_paragraph_mode",{P,B}},
{"get_single_paragraph_mode",{P},B},
{"get_unknown_glyphs_count",{P},I},
{"get_log_attrs",{P,P,I}},
{"get_log_attrs_readonly",{P,I},P},
{"index_to_pos",{P,I,P}},
{"index_to_line_x",{P,I,B,I,I}},
{"xy_to_line",{P,I,I,I,I},B},
{"get_cursor_pos",{P,I,P,P}},
{"move_cursor_visually",{P,B,I,I,I,I,I}},
{"get_pixel_extents",{P,P,P}},
{"get_baseline",{P},I},
{"get_line_count",{P},I},
{"get_line",{P,I},P,0,PangoLayoutLine},
{"get_line_readonly",{P,I},P,0,PangoLayoutLine},
{"get_lines",{P},A,0,GSList},
{"get_lines_readonly",{P},A,0,GSList},
{"get_iter",{P},P,0,PangoLayoutIter},
{"show_layout",{P,P},-routine_id("pl_show_layout")},
{"get_context",{P},P,0,PangoContext},
{"context_changed",{P}},
{"get_serial",{P},I},
{"get_extents",{P,P,P}},
"PangoLayout"}
function newPangoLayout(atom cr=0)
if cr=0 then
Error(,,"requires cairo_t as param!")
end if
return gtk_func("pango_cairo_create_layout",{P},{cr})
end function
function pl_set_text(atom layout, object txt)
if string(txt) then
txt = allocate_string(txt,1)
end if
gtk_proc("pango_layout_set_text",{P,P,I},{layout,txt,-1})
return 1
end function
function pl_set_markup(atom layout, object txt)
if string(txt) then
txt = allocate_string(txt,1)
end if
gtk_proc("pango_layout_set_markup",{P,P,I},{layout,txt,-1})
return 1
end function
function pl_set_markup_with_accel(atom layout, object txt,
integer marker, integer char)
if string(txt) then
txt = allocate_string(txt,1)
end if
gtk_proc("pango_layout_set_markup_with_accel",{P,P,I,I,I},
{layout,txt,-1,marker,char})
return 1
end function
function pl_show_layout(atom pcl, atom cr)
gtk_proc("pango_cairo_show_layout",{P,P},{cr,pcl})
return 1
end function
widget[PangoLayoutLine] = {"pango_layout_line",
{0},
{"ref",{P},P},
{"unref",{P}},
{"get_extents",{P,P,P}},
{"get_pixel_extents",{P,P,P}},
{"index_to_x",{P,I,B,I}},
{"x_to_index",{P,I,I,I},B},
{"get_x_ranges",{P,I,I,P,P}},
"PangoLayoutLine"}
widget[PangoLayoutIter] = {"pango_layout_iter",
{0},
{"copy",{P},P,0,PangoLayoutIter},
{"free",{P}},
{"next_run",{P},B},
{"next_char",{P},B},
{"next_cluster",{P},B},
{"next_line",{P},B},
{"at_last_line",{P},B},
{"get_index",{P},I},
{"get_baseline",{P},I},
{"get_run",{P},P,0,PangoLayoutRun},
{"get_run_readonly",{P},P,0,PangoLayoutRun},
{"get_line",{P},P,0,PangoLayoutLine},
{"get_line_readonly",{P},P,0,PangoLayoutLine},
{"get_layout",{P},P,0,PangoLayout},
{"get_char_extents",{P,P}},
{"get_cluster_extents",{P,P,P}},
{"get_run_extents",{P,P,P}},
{"get_line_yrange",{P,I,I}},
{"get_line_extents",{P,P,P}},
{"get_layout_extents",{P,P,P}},
"PangoLayoutIter"}
widget[PangoLayoutRun] = {"pango_layout_run",
{0},
"PangoLayoutRun"}
widget[PangoTabArray] = {"pango_tab_array",
{0},
{"new",{I,B},P},
{"get_size",{P},I},
{"resize",{P,I}},
{"set_tab",{P,I,I,I}},
{"get_tab",{P,I,P,P}},
{"get_tabs",{P,P,P}},
{"get_position_in_pixels",{P},B},
"PangoTabArray"}
widget[PangoLanguage] = {"pango_language",
{GObject},
{"new",{S},-routine_id("newPangoLanguage")},
{"get_default",{P},-routine_id("getDefaultLanguage")},
{"get_sample_string",{P},-routine_id("getSampleStr")},
{"to_string",{P},S},
{"matches",{P,S},B},
{"includes_script",{P,P},B},
"PangoLanguage"}
function newPangoLanguage(object s)
return gtk_func("pango_language_from_string",{S},{s})
end function
function getDefaultLanguage(object junk)
return gtk_str_func("pango_language_get_default")
end function
function getSampleStr(object x)
return gtk_str_func("pango_language_get_sample_string",{P},{x})
end function
export enum by * 2
PANGO_STRETCH_ULTRA_CONDENSED,
PANGO_STRETCH_EXTRA_CONDENSED,
PANGO_STRETCH_CONDENSED,
PANGO_STRETCH_SEMI_CONDENSED,
PANGO_STRETCH_NORMAL,
PANGO_STRETCH_SEMI_EXPANDED,
PANGO_STRETCH_EXPANDED = 64,
PANGO_STRETCH_EXTRA_EXPANDED,
PANGO_STRETCH_ULTRA_EXPANDED
export enum by * 2
PANGO_FONT_MASK_FAMILY,
PANGO_FONT_MASK_STYLE,
PANGO_FONT_MASK_VARIANT,
PANGO_FONT_MASK_WEIGHT,
PANGO_FONT_MASK_STRETCH,
PANGO_FONT_MASK_SIZE,
PANGO_FONT_MASK_GRAVITY

9648
eugtk/GtkEngine.e Normal file

File diff suppressed because it is too large Load Diff

1514
eugtk/GtkEnums.e Normal file

File diff suppressed because it is too large Load Diff

277
eugtk/GtkEvents.e Normal file
View File

@@ -0,0 +1,277 @@
----------------
namespace events
----------------
export constant version = "4.12.0"
--Thanks to Pete Eberlein for helping with this!
include GtkEngine.e
include std/convert.e
if not equal(version,gtk:version) then
Error(,,"GtkEvents version mismatch","should be version " & gtk:version)
end if
-- Maps keys from keypad to match same keys on keyboard,
-- maps control/arrow keys to negative numbers, so they
-- can be differentiated from the same ascii character
-- values;
constant keyvalues = {
{8,-8}, -- bksp
{9,-9}, -- tab
{20,-20}, -- scroll lock
{27,27}, -- escape
{80,-80}, -- home 'P'
{81,-81}, -- left arrow 'Q'
{82,-82}, -- up arrow 'R'
{83,-83}, -- right arrow 'S'
{84,-84}, -- down arrow 'T'
{85,-85}, -- page up 'U'
{86,-86}, -- page dn 'V'
{87,-87}, -- end 'W'
{99,-99}, -- insert 'c'
{103,-103},
{127,-127}, -- num lock
{141,13}, -- keypad Enter, with or w/o numlock;
-- keypad keys w/o numlock;
{149,-149}, -- keypad home
{150,-150}, -- keypad left
{151,-151}, -- keypad up
{152,-152}, -- keypad right
{153,-153}, -- keypad down
{154,-154}, -- keypad pg up
{155,-155}, -- keypad pg dn
{156,-156}, -- keypad end
{157,-157}, -- keypad 5
{158,-158}, -- keypad ins
{159,-159}, -- keypad del
-- keypad keys with numlock - return ascii 0..9
{170,'*'},{171,'+'},{173,'-'},{175,'/'},
{176,48},{177,49},{178,50},{179,51},{180,52}, -- keypad numbers 0..4
{181,53},{182,54},{183,55},{184,56},{185,57}, -- keypad numbers 5..9
-- F keys;
{190,-190}, -- F1
{191,-191}, -- F2
{192,-192}, -- F3
{193,-193}, -- F4
{194,-194}, -- F5
{195,-195}, -- F6
{196,-196}, -- F7
{197,-197}, -- F8
{198,-198}, -- F9
{199,-199}, -- F10
{200,-200}, -- F11
{201,-201}, -- F12
{227,-227}, -- left ctl
{228,-228}, -- right ctl
{229,-229},
{225,-225}, -- left shift
{226,-226}, -- right shift
{228,-228},
{233,-233}, -- left alt
{234,-234}, -- right alt
{236,-236},
{255,-255}, -- delete
$}
constant shiftkeys = {
{32,-9}, -- shift tab
$}
constant event_names = {
{3,"focus-in"},
{11,"focus-out"}
}
----------------------------------------------------------------------
export function key(atom event) -- get key pressed;
----------------------------------------------------------------------
if event = 0 then return 0 end if
integer k = peek(event+16)
integer z = peek(event+17)
integer s = state(event)
ifdef BITS64 then
k = peek(event+28)
z = peek(event+29)
end ifdef
switch z do
case 0 then return k
case 255 then return vlookup(k,keyvalues,1,2,k)
case 254 then return vlookup(k,shiftkeys,1,2,k)
end switch
return 0
end function
--(32/64)struct GdkEventButton
-- 0 0 GdkEventType type a.k.a. id
-- 4 8 GtkWindow *window
-- 8 16 gint8 send_event
-- 12 20 guint32 time
-- 16 24 gdouble x
-- 24 32 gdouble y
-- 32 40 gdouble *axes
-- 36 48 guint state
-- 40 52 guint button
-- 44 56 GdkDevice *device
-- 48 64 gdouble x_root, y_root
---------------------------------------------------------------------
export function id(atom event)
---------------------------------------------------------------------
if event > 0 then return peek4u(event) else return event end if
end function
---------------------------------------------------------------------
export function name(atom event)
---------------------------------------------------------------------
event = id(event)
for i = 1 to length(event_names) do
if event = event_names[i][1] then
return event_names[i][2]
end if
end for
return -1
end function
---------------------------------------------------------------------
export function window(atom event) -- get event window
---------------------------------------------------------------------
ifdef BITS64 then
return peek8u(event + 8)
end ifdef
return peek4u(event + 4)
end function
---------------------------------------------------------------------
export function time(atom event) -- get event time
---------------------------------------------------------------------
ifdef BITS64 then
return peek4u(event + 20)
end ifdef
return peek4u(event + 12)
end function
---------------------------------------------------------------------
export function xy(atom event) -- get mouse button x y;
---------------------------------------------------------------------
ifdef BITS64 then
return floor({
float64_to_atom(peek({event + 24, 8})),
float64_to_atom(peek({event + 32, 8}))})
end ifdef
return floor({
float64_to_atom(peek({event + 16, 8})),
float64_to_atom(peek({event + 24, 8}))})
end function
---------------------------------------------------------------------
export function axes(atom event)
---------------------------------------------------------------------
ifdef BITS64 then
return float64_to_atom(peek({event + 40, 8}))
end ifdef
return float64_to_atom(peek({event + 32, 8}))
end function
---------------------------------------------------------------------
export function button(atom event) -- get mouse button clicked;
---------------------------------------------------------------------
ifdef BITS64 then
return peek(event+52)
end ifdef
return peek(event+40)
end function
----------------------------------------------------------------------
export function state(atom event)
----------------------------------------------------------------------
ifdef BITS64 then
return peek(event+48)
end ifdef
return peek(event+36)
end function
----------------------------------------------------------------------
export function device(atom event)
----------------------------------------------------------------------
ifdef BITS64 then
return peek(event+56)
end ifdef
return peek(event+44)
end function
---------------------------------------------------------------------
export function clicks(atom event)
---------------------------------------------------------------------
atom ct = allocate(64)
object result
if gtk_func("gdk_event_get_click_count",{P,I},{event,ct}) then
result = peek4u(ct)
else
result = -1
end if
free(ct)
return result
end function
---------------------------------------------------------------------
export function scroll_dir(atom event)
---------------------------------------------------------------------
atom dir = allocate(64)
object result
if gtk_func("gdk_event_get_scroll_direction",{P,I},{event,dir}) then
result = peek4u(dir)
else
result = -1
end if
free(dir)
return result
end function
---------------------------------------------------------------------------------
export function pending() -- used sometimes when using timeout or eu tasks
---------------------------------------------------------------------------------
return gtk_func("gtk_events_pending")
end function
------------------------------------------------------------------------
export procedure main_iteration()
------------------------------------------------------------------------
gtk_proc("gtk_main_iteration")
end procedure
-----------------------------------------------------------------------------------
export procedure main_iteration_do(integer i) -- used sometimes when multi-tasking;
-----------------------------------------------------------------------------------
gtk_proc("gtk_main_iteration_do",{I},i)
end procedure
------------------------------------------------------------------------
-- following routine traps the enter key when Entry is activated,
-- and uses it like the tab key - so it works like people expect.
-- When using Glade, connect each entry's 'activate' signal to
-- trap_enter_key
------------------------------------------------------------------------
constant gsig = define_proc("g_signal_emit_by_name",{P,P,P})
constant fsig = allocate_string("move-focus")
------------------------------------------------------------------------
global function trap_enter_key(atom ctl, atom event)
-----------------------------------------------------------------------
if class_id(ctl) = GtkEntry then
if event = 0 then
c_proc(gsig,{ctl,allocate_string("move-focus"),0})
return 1
end if
end if
return 0
end function

454
eugtk/GtkFileSelector.e Normal file
View File

@@ -0,0 +1,454 @@
-------------------------
namespace fileselector -- Generic file selection dialog;
-------------------------
--# EXPORTS:
/*
-- functions:
fileselector:New()
fileselector:Open()
fileselector:Save()
fileselector:SaveAs()
fileselector:CreateFolder()
fileselector:SelectFolder()
-- returns:
full file path if successful, e.g. "/home/irv/demos/test99.ex"
or an atom:
MB_ABORT when dialog is closed
MB_CANCEL when cancel button is clicked.
*/
include GtkEngine.e
export constant version = "4.12.0"
if not equal(version,gtk:version) then
Error(,,"GtkFileSelector version mismatch","should be version " & gtk:version)
end if
-- default settings, change before calling the dialog if required;
export boolean
create_folders = TRUE,
local_only = TRUE,
select_multiple = FALSE,
show_hidden = FALSE,
do_overwrite_confirmation = TRUE,
show_preview = FALSE,
preview_widget_active = TRUE
export sequence preview_size = {200,200}
export atom preview_max = 150 -- default size
export object selected_filter=0, filters = {"euphoria","text"}
-- may change filters before calling the dialog
-- (or every 5,000 miles, whichever comes first)
-- IOW, to show only .css files, add the line:
-- fileselector:filters = {"css"}
-- before calling:
-- fileselector:Open("~/demos/*")
-- note that the syntax of the parameter to Open() is important:
-- ~/demos or ~/demos/ will only cause the dialog to highlight the ~/demos folder,
-- ~/demos/* will open the demos folder and display the [filtered] file types
-- ~/demos/*.css will show folders and all *.css files
-- combining filters with wildcards:
-- fileselector:filters = {"images"}
-- fileselector:Open("~/demos/glade/*")
-- the above will show all images in the specified directory,
-- whereas:
-- fileselector:Open("~/demos/glade/*.png")
-- will show only .png images in the specified directory,
-- regardless of how the filters are set.
-- below, only .png images will be shown, but drop-down options to show .html and .c files
-- will be available also:
-- fileselector:filters = {"html","c"}
-- fileselector:Open("~/demos/glade/*.png")
--------------------------------------
function generate_filter(object name)
--------------------------------------
object filter = 0
switch name do
case "images",".jpg",".gif",".png",".xpm" then filter = create(GtkFileFilter,{
{"name","Images"},{"add mime type","image/*"}})
case "euphoria",".eu",".e",".exw" then filter = create(GtkFileFilter,{
{"name","Euphoria files"},{"add pattern","*.e"},
{"add pattern","*.ex"},{"add pattern","*.cfg"}})
case "text",".text",".txt" then filter = create(GtkFileFilter,{
{"name","All text"},{"add mime type","text/plain"}})
case "c",".c",".h" then filter = create(GtkFileFilter,{
{"name","C source code"},{"add mime type","text/x-c"},
{"add pattern","*.c"},{"add pattern","*.h"}})
case "c++" then filter = create(GtkFileFilter,{
{"name","C++ source code"},{"add pattern","*.c++"}})
case "css",".css" then filter = create(GtkFileFilter,{
{"name","css markup"},{"add mime type","text/css"},
{"add pattern","*.css"}})
case "python",".python",".py" then filter = create(GtkFileFilter,{
{"name","Python"},{"add mime type","text/x-python"}})
case "html",".htm",".html" then filter = create(GtkFileFilter,{
{"name","html source"},{"add mime type","text/html"},
{"add pattern","*.html"}})
case "ini",".ini" then filter = create(GtkFileFilter,{
{"name","ini"},{"add pattern","*.ini"}})
case "all" then filter = create(GtkFileFilter,{
{"name","All files"},{"add pattern","*"}})
case "dir" then filter = create(GtkFileFilter,{
{"name","Directories"},{"add mime type","inode/directory"}})
end switch
return filter
end function
constant update_preview = call_back(routine_id("UpdatePreview"))
----------------------------------------------------------
export function New(object current=0)
----------------------------------------------------------
object result=0
atom dlg = create(GtkFileChooserDialog)
set(dlg,{
{"name","FileNew"},
{"title","Create a new file"},
{"action",GTK_FILE_CHOOSER_ACTION_SAVE},
{"preview widget active",preview_widget_active},
{"add button","gtk-cancel",MB_CANCEL},
{"add button","gtk-ok",MB_OK},
{"create folders",create_folders},
{"local only",local_only},
{"select multiple",select_multiple},
{"show hidden",show_hidden},
{"do overwrite confirmation",do_overwrite_confirmation}})
for i = 1 to length(filters) do
set(dlg,"add filter",generate_filter(filters[i]))
end for
if show_preview = TRUE then
atom preview = create(GtkImage)
set(dlg,"preview widget",preview)
connect(dlg,"update-preview",update_preview,preview)
end if
if atom(current) and current > 0 then
set(dlg,"current name",unpack(current))
end if
result = get(dlg,"run")
if result = MB_OK then
result = get(dlg,"filename")
end if
destroy(dlg)
return result
end function
export constant new = call_back(routine_id("New"))
----------------------------------------------------
export function Open(object data=0, atom x=0)
----------------------------------------------------
object result=0
object filter=0
if atom(data) and data > 0 then data = unpack(data) end if
if string(data) and equal("*",filename(data)) then filters &= {"all"} end if
atom dlg = create(GtkFileChooserDialog)
set(dlg,{
{"name","FileOpen"},
{"title","Open a file"},
{"action",GTK_FILE_CHOOSER_ACTION_OPEN},
{"preview widget active",preview_widget_active},
{"add button","gtk-cancel",MB_CANCEL},
{"add button","gtk-ok",MB_OK},
{"create folders",create_folders},
{"local only",local_only},
{"select multiple",select_multiple},
{"show hidden",show_hidden},
{"do overwrite confirmation",do_overwrite_confirmation}})
for i = 1 to length(filters) do
set(dlg,"add filter",generate_filter(filters[i]))
end for
if show_preview = TRUE then
atom preview = create(GtkImage)
set(dlg,"preview widget",preview)
connect(dlg,"update-preview",update_preview,preview)
end if
if atom(data) and data > 0 then
data = unpack(data)
end if
if string(data) then
if file_exists(canonical_path(data)) then
set(dlg,"filename",canonical_path(data))
else
if not equal("*",filename(data)) then
filter = create(GtkFileFilter,{ -- build a custom filter;
{"name",filename(data) & " files"},
{"add pattern",filename(data)}})
set(dlg,"add filter",filter)
set(dlg,"filter",filter)
end if
set(dlg,"filename",canonical_path(data)) -- change to desired folder;
end if
end if
result = get(dlg,"run")
if result = MB_OK then
result = get(dlg,"filename")
end if
destroy(dlg)
return result
end function
export constant open = call_back(routine_id("Open"))
----------------------------------------------------
export function Save(object data, object x=0)
----------------------------------------------------
object result=0
atom dlg = create(GtkFileChooserDialog)
atom f
set(dlg,{
{"name","FileSave"},
{"title","Save this file"},
{"action",GTK_FILE_CHOOSER_ACTION_SAVE},
{"add button","gtk-cancel",MB_CANCEL},
{"add button","gtk-ok",MB_OK},
{"create folders",create_folders},
{"local only",local_only},
{"select multiple",select_multiple},
{"show hidden",show_hidden},
{"do overwrite confirmation",do_overwrite_confirmation}})
for i = 1 to length(filters) do
set(dlg,"add filter",generate_filter(filters[i]))
end for
if show_preview = TRUE then
atom preview = create(GtkImage)
set(dlg,"preview widget",preview)
connect(dlg,"update-preview",update_preview,preview)
end if
if atom(data) and data > 0 then
set(dlg,"current name",unpack(data))
end if
if string(data) then
set(dlg,"current name",data)
end if
result = get(dlg,"run")
if result = MB_OK then
result = get(dlg,"filename")
end if
destroy(dlg)
return result
end function
export constant save = call_back(routine_id("Save"))
-----------------------------------------------------------
export function SaveAs(object data=0, object x=0)
-----------------------------------------------------------
object result=0
atom dlg = create(GtkFileChooserDialog)
set(dlg,{
{"name=FileSaveAs"},
{"title","Save this file with a new name"},
{"action",GTK_FILE_CHOOSER_ACTION_SAVE},
{"add button","gtk-cancel",MB_CANCEL},
{"add button","gtk-ok",MB_OK},
{"create folders",create_folders},
{"local only",local_only},
{"select multiple",select_multiple},
{"show hidden",show_hidden},
{"do overwrite confirmation",do_overwrite_confirmation}})
for i = 1 to length(filters) do
set(dlg,"add filter",generate_filter(filters[i]))
end for
if show_preview = TRUE then
atom preview = create(GtkImage)
set(dlg,"preview widget",preview)
connect(dlg,"update-preview",update_preview,preview)
end if
if atom(data) and data > 0 then
set(dlg,"current name",unpack(data))
elsif string(data) then
set(dlg,"current name",data)
end if
result = get(dlg,"run")
if result = MB_OK then
result = get(dlg,"filename")
end if
destroy(dlg)
return result
end function
export constant save_as = call_back(routine_id("SaveAs"))
---------------------------------------------------------------
export function CreateFolder(object data=0, object x=0)
---------------------------------------------------------------
object result=0
atom dlg = create(GtkFileChooserDialog)
set(dlg,{
{"name=NewFolder"},
{"title","Create a new folder"},
{"action",GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER},
{"add button","gtk-cancel",MB_CANCEL},
{"add button","gtk-ok",MB_OK},
{"create folders",create_folders},
{"local only",local_only},
{"select multiple",select_multiple},
{"show hidden",show_hidden},
{"do overwrite confirmation",do_overwrite_confirmation}})
for i = 1 to length(filters) do
set(dlg,"add filter",generate_filter(filters[i]))
end for
if show_preview = TRUE then
atom preview = create(GtkImage)
set(dlg,"preview widget",preview)
connect(dlg,"update-preview",update_preview,preview)
end if
if atom(data) and data > 0 then
set(dlg,"current name",unpack(data))
end if
result = get(dlg,"run")
if result = MB_OK then
result = get(dlg,"filename")
end if
destroy(dlg)
return result
end function
export constant create_folder = call_back(routine_id("CreateFolder"))
---------------------------------------------------------------
export function SelectFolder(object data=0, object x=0)
---------------------------------------------------------------
object result=0
atom dlg = create(GtkFileChooserDialog)
set(dlg,{
{"name","SelectFolder"},
{"title","Select a folder"},
{"action",GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER},
{"add button","gtk-cancel",MB_CANCEL},
{"add button","gtk-ok",MB_OK},
{"create folders",create_folders},
{"local only",local_only},
{"select multiple",select_multiple},
{"show hidden",show_hidden},
{"do overwrite confirmation",do_overwrite_confirmation}})
for i = 1 to length(filters) do
set(dlg,"add filter",generate_filter(filters[i]))
end for
if show_preview = TRUE then
atom preview = create(GtkImage)
set(dlg,"preview widget",preview)
connect(dlg,"update-preview",update_preview,preview)
end if
if atom(data) and data > 0 then
data = unpack(data)
if string(data) then
if file_exists(canonical_path(data)) then
set(dlg,"filename",canonical_path(data))
else
set(dlg,"filename",data)
end if
end if
end if
result = get(dlg,"run")
if result = MB_OK then
result = get(dlg,"filename")
end if
destroy(dlg)
return result
end function
export constant select_folder = call_back(routine_id("SelectFolder"))
------------------------------------------------------------------------------
function UpdatePreview(atom dlg, atom preview) -- local: follow focus changes;
------------------------------------------------------------------------------
object pix
atom ratio
object dimensions
object fn = get(dlg,"filename")
if string(fn) then -- avoid trying to preview a directory!
pix = create(GdkPixbuf,fn)
if pix > 0 then
dimensions = get(pix,"size")
ratio = preview_max / dimensions[1]
dimensions *= {ratio,ratio}
pix = get(pix,"scale simple",dimensions[1],dimensions[2],1)
set(preview,"from pixbuf",pix)
end if
end if
return 0
end function

154
eugtk/GtkFontSelector.e Normal file
View File

@@ -0,0 +1,154 @@
----------------------
namespace fontselector -- Generic font selector dialog
----------------------
--# EXPORTS
/*
-- functions -- callbacks
fontselector:Select() fontselector:select
fontselector:FilterFonts() fontselector:filter
-- fontlist
*/
include GtkEngine.e
include GtkCairo.e
include std/wildcard.e
include std/hash.e
export constant version = "4.12.0"
if not equal(version,gtk:version) then
Error(,,"GtkFontSelector version mismatch","should be version " & gtk:version)
end if
-- Optional parameter is preferred (default) font, the one to be
-- returned if the font dialog ok button is clicked without choosing
-- a different font. You can just specify a size here: "8" and that
-- will set only the dialog's size selector.
--
-- You can specify a full font name and size: e.g. Purisa bold 16,
-- and that font will be the one highlighted for selection.
-- If you specify a font that doesn't exist: e.g. Bogus italic 18,
-- and then use the returned font, GTK will do the best it can,
-- which will be to set the existing font to italic in 18pt.
-- Fairly fail-safe, in other words.
--
-- Setting this does not filter the list of fonts shown by the dialog.
-- to do this, you need to set the pattern. See below.
--
-- To exclude unwanted (and unreadable) fonts, such as symbols and
-- dingbats, add them to the exclude sequence. See below.
--
-- pattern can be set prior to the select() call
-- pattern can be an array of font names, wildcards are ok
-- e.g. {"Courier*","purisa"}
-- if you use, for example, just {"Courier"}, without the wildcard,
-- no fonts will be found.
--
-- {"sans"}, {"*sans"}, or {"*sans*"} will each return a different
-- set of matching font names! trial and error may be required.
--
-- if pattern is left unset, ALL fonts will be shown!
export atom dlg = create(GtkFontChooserDialog,"name=FontSelector")
export object
name = 0, -- font name
title = "Choose a font", -- dialog title
preview_text = "This is an EuGTK font selector",
description = 0, -- a PangoFontDescription
family = 0, -- font family
style = 0, -- normal, oblique, italic
variant = 0,
weight = PANGO_WEIGHT_NORMAL,
mono_filter = 0,
font_list = {}
export atom size = 12*1024
export integer points = 12
export sequence pattern = {"*"}
export sequence exclude = {"*symbol*","*dingbat*","*webdings","*wingdings*"}
-- above list filters out unusable fonts;
------------------------------------------------------------------------
export function Select(object curr_fnt=0)
------------------------------------------------------------------------
set(dlg,"title","Select a font")
set(dlg,"preview text",preview_text)
if string(curr_fnt) then
set(dlg,"font",curr_fnt)
end if
pattern = lower(pattern)
exclude = lower(exclude)
set(dlg,"filter func",filter)
if get(dlg,"run") then
name = get(dlg,"font")
description = create(PangoFontDescription,name)
family = get(description,"family")
size = get(description,"size")
points = math:round(size/PANGO_UNIT)
variant = get(description,"variant")
style = get(description,"style")
weight = get(description,"weight")
end if
hide(dlg) -- we keep it around, since it's likely to be used again :p
return name
end function
export constant select = call_back(routine_id("Select"))
------------------------------------------------------------------------
export function FilterFonts(object family, object face, object data)
------------------------------------------------------------------------
integer result = 0
if mono_filter then
if gtk_func("pango_font_family_is_monospace",{P},{family}) = FALSE then
return 0
end if
end if
object name = lower(gtk_str_func("pango_font_family_get_name",{P},{family}))
for i = 1 to length(pattern) do
result = is_match(pattern[i],name) > 0
if result = 1 then
for x = 1 to length(exclude) do
if is_match(exclude[x],name) then
return 0
end if
end for
end if
return result
end for
return result
end function
export constant filter = call_back(routine_id("FilterFonts"))
sequence weight_names =
{"thin","ultralight","light","book","normal","medium",
"semibold","bold","ultrabold","heavy","ultraheavy"}
/* -- reference;
PANGO_WEIGHT_THIN = 100,
PANGO_WEIGHT_ULTRALIGHT = 200,
PANGO_WEIGHT_LIGHT = 300,
PANGO_WEIGHT_BOOK = 380,
PANGO_WEIGHT_NORMAL = 400,
PANGO_WEIGHT_MEDIUM = 500,
PANGO_WEIGHT_SEMIBOLD = 600,
PANGO_WEIGHT_BOLD = 700,
PANGO_WEIGHT_ULTRABOLD = 800,
PANGO_WEIGHT_HEAVY = 900,
PANGO_WEIGHT_ULTRAHEAVY = 1000,
PANGO_UNIT = 1024
PANGO_STYLE_NORMAL = 0,
PANGO_STYLE_OBLIQUE = 1,
PANGO_STYLE_ITALIC = 2
*/

567
eugtk/GtkPrinter.e Normal file
View File

@@ -0,0 +1,567 @@
--------------------
namespace printer -- Utility to make printing easier
--------------------
export constant version = "4.12.0"
-- EXPORTS:
-- functions callbacks
-- printer:PrintFile() printer:print_file
-- printer:PrintText() printer:print_text
-- This version handles most common printing needs, but it will not yet respect
-- 'marked up' a.k.a. 'rich' text, i.e. text with colors and styles as produced
-- by GTK3's TextView widget. It just prints them as plain text.
--
-- However, it DOES print text marked up with GTK's HTML subset, so you can use
-- <b>, <i>, <u>, <span>, <font> ... etc. in your printouts! This includes various
-- imbedded font styles and colors.
--
-- More documentation is found in ~/documentation/printing.html
include GtkEngine.e
include GtkCairo.e
include std/datetime.e
if not equal(version,gtk:version) then
Error(,,"GtkPrinter version mismatch","should be version " & gtk:version)
end if
-- The following exported variables can be modified before calling the
-- print routine:
public object header = "[1]\n" -- default is just the page title
public object subheader = "[1] page [5]\n\n" -- format for headers on pg.2 ... n
-- default subheader (above) prints page title and pg #;
public object footer = "<small>\n<i>Printed by EuGTK [8] on [9]'s computer</i></small>"
-- default footer (above) prints date and user name;
-- Info ID's for use in header and footer;
-- 1 = page title (for first page)
-- 2 = sub title (for subsequent pages - leave null to use page title (1) on all pgs)
-- 3 = file name
-- 4 = short name (file name w/o path)
-- 5 = current page number
-- 6 = n_pages printed e.g. pg 1 of n
-- 7 = n_copies requested
-- 8 = today's date in date_format
-- 9 = user name
--10 = user's real name
--11 = font name used for this print job
--12 = file length in bytes
--13 = file timestamp
--14 = exported filename, if any
export integer
n_pages = 0, -- number of pages to print (0=all)
n_copies = 1,
collate = FALSE,
duplex = 0,
number_up = 1,
number_up_layout = 1,
units = GTK_UNIT_INCH,
use_line_numbers = TRUE,
use_color = TRUE, -- print eu comments in red if true
lines_per_page = 60,
wrap_at = 0,
track_status = TRUE,
show_progress = TRUE, -- enable the built-in progressbar
embed_page_setup = TRUE,
orientation = 0,
order = 0,
confirm = FALSE,
sourcecode = TRUE,
plaintext = FALSE,
use_full_page = FALSE, -- ignore margins
has_selection = FALSE,
support_selection = FALSE,
quality = GTK_PRINT_QUALITY_DRAFT,
action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
auto_lpp = TRUE
export atom
scale = 100,
top_margin = 0.25, -- in inch units
left_margin = 0.25,
right_margin = 0.25,
bottom_margin = 0.25,
parent = 0,
signal_status_changed = call_back(routine_id("show_status")),
signal_begin_print = call_back(routine_id("begin_print")),
signal_draw_page = call_back(routine_id("draw_page")),
signal_end_print = call_back(routine_id("end_print")),
signal_request_page_setup = 0,
signal_done = 0,
signal_ready = 0,
signal_got_page_size = 0
export object
name = 0,
font = "Ubuntu Mono 8",
jobname = 0,
settings_file = 0,
setup_file = 0,
export_file = 0,
page_ranges = 0,
page_set = GTK_PAGE_SET_ALL,
custom_tab_hook = 0,
custom_tab_label = 0,
custom_tab_func = 0
ifdef WINDOWS then font = "Courier New 16" end ifdef
export object
line_number_format = "[:4] []\n", -- controls line # format AND code line!
paper_name = "na_letter", -- 8.5x11.0"
tabs = " ", -- replace tab chars with 8 spaces
file_name = 0,
short_name = 0,
page_title = 0,
sub_title = 0
export atom
progress = create(GtkProgressBar),
settings = create(GtkPrintSettings)
-- use date and time formats in std/datetime.e;
export sequence date_format = "%A, %B %d %Y %l:%M %p"
sequence user
ifdef WINDOWS then
user = "User"
elsedef
user = proper(getenv("USER"))
end ifdef
-- for local use;
atom fontdesc
integer filesize = 0
object timestamp = 0
sequence text
sequence today = datetime:format(datetime:now(),date_format)
export procedure reset()
n_pages = 0
n_copies = 1
collate = FALSE
duplex = 0
number_up = 1
number_up_layout = 1
units = GTK_UNIT_INCH
use_line_numbers = TRUE
use_color = TRUE
lines_per_page = 60
wrap_at = 0
track_status = TRUE
show_progress = TRUE
embed_page_setup = TRUE
orientation = 0
order = 0
confirm = FALSE
sourcecode = TRUE
plaintext = FALSE
use_full_page = FALSE
has_selection = FALSE
support_selection = FALSE
quality = GTK_PRINT_QUALITY_DRAFT
action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
auto_lpp = TRUE
scale = 100
top_margin = 0.25
left_margin = 0.25
right_margin = 0.25
bottom_margin = 0.25
parent = 0
name = 0
paper_name = "na_letter"
font = "Ubuntu Mono 8"
jobname = 0
settings_file = 0
setup_file = 0
export_file = 0
page_ranges = 0
page_set = GTK_PAGE_SET_ALL
custom_tab_hook = 0
custom_tab_label = 0
custom_tab_func = 0
end procedure
------------------------------------------------------------------------
export function PrintFile(object f=0, object x=0)
------------------------------------------------------------------------
if string(f) and string(x) then
page_title = f
file_name = canonical_path(x)
timestamp = file_timestamp(file_name)
filesize = file_length(file_name)
short_name = filebase(file_name)
text = read_file(file_name)
setup_printer()
return 1
end if
if string(f) and atom(x) and x = 0 then
f = canonical_path(f)
file_name = f
timestamp = file_timestamp(f)
filesize = file_length(f)
short_name = filebase(f)
page_title = filename(f)
text = read_file(f)
setup_printer()
return 1
end if
if string(f) and atom(x) and x < 100 then
page_title = f
short_name = f
file_name = f
text = read_file(x)
setup_printer()
return 1
end if
if atom(f) and atom(x) and x < 101 then
if atom(file_name) then
file_name = ""
end if
if atom(short_name) then
short_name = ""
end if
if atom(page_title) then
page_title = ""
end if
text = read_file(x)
setup_printer()
return 1
end if
if atom(f) and atom(x) then
x = unpack(x)
x = canonical_path(x)
file_name = x
short_name = filebase(x)
page_title = filename(x)
text = read_file(x)
setup_printer()
return 1
end if
return 1
end function
export constant print_file = call_back(routine_id("PrintFile"))
------------------------------------------------------------------------
export function PrintText(object f=0, object x=0)
------------------------------------------------------------------------
if string(f) and string(x) then
page_title = f
text = x
setup_printer()
return 1
end if
if atom(f) and string(x) then
setup_printer()
text = x
return 1
end if
if atom(f) and atom(x) then
if atom(page_title) and page_title = 0 then
page_title = ""
end if
text = unpack(x)
setup_printer()
return 1
end if
return 0
end function
export constant print_text = call_back(routine_id("PrintText"))
integer status_code
sequence status_string
-----------------------------------------------
export function show_status(atom op)
-----------------------------------------------
atom
fn1 = define_func("gtk_print_operation_get_status",{P},I),
fn2 = define_func("gtk_print_operation_get_status_string",{P},S)
status_code = c_func(fn1,{op})
status_string = peek_string(c_func(fn2,{op}))
ifdef PRINT then display("Status [] []",{status_code,status_string}) end ifdef
if show_progress then
set(progress,"text",status_string)
end if
ifdef DELAY then sleep(0.15) end ifdef
return 1
end function
------------------------------------------------------
export function begin_print(atom op, atom context)
------------------------------------------------------
ifdef PRINT then display("Begin printing [] pages ",length(text)) end ifdef
fontdesc = create(PangoFontDescription,font)
if auto_lpp then
atom setup = get(op,"default page setup")
atom pght = get(setup,"page height",GTK_UNIT_POINTS)
--display("Page height [] pt.",pght)
pght -= length(header)
pght -= length(footer)
atom fs = get(fontdesc,"size") / 1024
--display("Font size []",fs)
fs = fs * (96/72)
integer lpp = 1
while ((fs*lpp)) < pght do
lpp += 1
--display("Text height [] lpp []",{(fs*lpp),lpp})
end while
--display("New LPP []",lpp-1)
lines_per_page = lpp
end if
text = process_text(text)
set(op,"n pages",n_pages)
-- important, as a new value for n_pages is computed
-- based on the length of the file being read, unless a set number
-- has been provided from the calling program.
if show_progress then -- turn on the progress dialog in the calling program
show_all(progress)
end if
return 1
end function
----------------------------------------------------------------------------
export function draw_page(atom op, atom context, integer pg, atom data)
----------------------------------------------------------------------------
atom fn6 = define_func("gtk_print_context_get_cairo_context",{P},P)
atom cr = c_func(fn6,{context})
atom pl = create(PangoCairoLayout,cr)
set(pl,"font description",fontdesc)
pg += 1
if pg > length(text) then
set(progress,"text","Printing complete")
return 0
end if
if show_progress then
set(progress,"text",sprintf("Printing page %d",pg))
set(progress,"fraction",pg/n_pages)
end if
ifdef DELAY then sleep(0.25) end ifdef
object details = {
page_title,sub_title,file_name,short_name,
pg,n_pages,n_copies,
today,user,real_name,font,filesize,timestamp,export_file
}
object page
if atom(header) then header = "<b><u>[1]</u> page [5] of [6]</b>\n\n" end if
if pg = 1 or atom(subheader) then
page = text:format(header,details)
& flatten(text[pg])
& text:format(footer,details)
else
page = text:format(subheader,details)
& flatten(text[pg])
& text:format(footer,details)
end if
if plaintext then
set(pl,"text",page,length(page))
else
set(pl,"markup",page,length(page))
end if
set(pl,"update layout",cr)
set(pl,"show layout",cr)
ifdef PRINT then printf(1,"Page %d\n",pg) end ifdef
return 1
end function
------------------------------------------------------------------------
function process_text(object txt)
------------------------------------------------------------------------
txt = split(txt,'\n')
integer comment, n
object a,b
object test
for i = 1 to length(txt) do -- replace chars which will confuse markup
txt[i] = join(split(txt[i],'&'),"&amp;")
txt[i] = join(split(txt[i],"&amp;amp;"),"&amp;")
if sourcecode then
txt[i] = join(split(txt[i],'<'),"&lt;")
txt[i] = join(split(txt[i],'>'),"&gt;")
end if
if use_color then
if match("--",txt[i]) then -- a comment;
txt[i] = split(txt[i],"--")
txt[i] = txt[i][1] & "<span color='red'>-- " & txt[i][2] & "</span>"
end if
end if
if use_line_numbers then
txt[i] = text:format(line_number_format,{i,txt[i]})
else
txt[i] &= '\n'
end if
end for
txt = breakup(txt,lines_per_page)
if n_pages = 0 then -- no selection
n_pages = length(txt)
end if
return txt
end function
------------------------------------------------------------------------
export function end_print()
------------------------------------------------------------------------
status_string = "Printing complete"
ifdef PRINT then display(status_string) end ifdef
return 1
end function
---------------------------------------------------------------
export function setup_printer()
---------------------------------------------------------------
atom _size = create(GtkPaperSize,paper_name)
atom err = allocate(16) err = 0
object results = 0
atom fn7 = define_func("gtk_print_operation_run",{P,I,P,P},I)
atom fn8 = define_func("gtk_print_run_page_setup_dialog",{P,P,P},P)
set(settings,"paper size",_size,units)
set(settings,"n copies",n_copies)
set(settings,"collate",collate)
set(settings,"duplex",duplex)
set(settings,"reverse",order)
set(settings,"scale",scale)
set(settings,"quality",quality)
set(settings,"number up",number_up)
set(settings,"number up layout",number_up_layout)
if string(name) then
set(settings,"printer",name)
end if
atom setup = create(GtkPageSetup)
set(setup,"paper size",_size)
set(setup,"orientation",orientation)
set(setup,"left margin",left_margin,units)
set(setup,"right margin",right_margin,units)
set(setup,"top margin",top_margin,units)
set(setup,"bottom margin",bottom_margin,units)
atom printop = create(GtkPrintOperation)
set(printop,"print settings",settings)
set(printop,"default page setup",setup)
set(printop,"show progress",show_progress)
set(printop,"track print status",track_status)
set(printop,"embed page setup",embed_page_setup)
set(printop,"support selection",support_selection)
set(printop,"has selection",has_selection)
set(printop,"use full page",use_full_page)
if action = GTK_PRINT_OPERATION_ACTION_EXPORT then
export_file = canonical_path(export_file)
set(printop,"export filename",export_file)
end if
if string(jobname) then
set(printop,"job name",jobname)
end if
if custom_tab_hook != 0 then
set(printop,"custom tab label",custom_tab_label)
connect(printop,"create-custom-widget",custom_tab_func,printop)
connect(printop,"custom-widget-apply",custom_tab_hook)
end if
connect(printop,"status-changed",signal_status_changed)
connect(printop,"begin-print",signal_begin_print)
connect(printop,"draw-page",signal_draw_page)
connect(printop,"end-print",signal_end_print)
connect(printop,"request-page-setup",signal_request_page_setup)
connect(printop,"done",signal_done)
connect(printop,"ready",signal_ready)
connect(printop,"got-page-size",signal_got_page_size)
display(get(settings,"printer lpi"))
c_func(fn7,{printop,action,parent,err}) -- start the print process;
if string(setup_file) and file_exists(canonical_path(setup_file)) then
get(setup,"to file",canonical_path(setup_file))
end if
object jobname = get(printop,"job name")
if confirm then
if action = GTK_PRINT_OPERATION_ACTION_EXPORT then
if Question(0,"PDF Written",
sprintf("%s\n<small>Folder: %s</small>",
{filename(export_file),pathname(export_file)}),
sprintf("%s\nStatus: %d\n%s\nClick Yes to view",{jobname,status_code,status_string})
,,,"printer") then
show_uri(export_file)
end if
else
Info(0,"Print Job",jobname,
sprintf("Status: %d %s",{status_code,status_string})
,,"printer")
end if
end if
page_title = 0
n_pages = 0
n_copies = 1
action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
return 1
end function
header = "<b><u>[1]</u></b>\n\n"
-----------------------------
-- copyright 2015 Irv Mullins
-----------------------------

305
eugtk/GtkSettings.e Normal file
View File

@@ -0,0 +1,305 @@
---------------------
namespace settings -- functions to read and write config files (*.ini);
---------------------
export constant version = "4.12.0"
--# EXPORTS
/*
--functions:
settings:Save()
settings:Load()
settings:Add()
-- debug:
-d SETTINGS
*/
include GtkEngine.e
if not equal(version,gtk:version) then
Error(,,"GtkSettings version mismatch","should be version " & gtk:version)
end if
constant fmt = """[].[]=[]"""
------------------------------------------------------------------------
export function Save(sequence inifile, object ctl_list, integer debug=0)
------------------------------------------------------------------------
-- writes an 'ini' type file (file name and extension are up to you)
-- with an entry for each control on ctl_list. The controls MUST have
-- been named, otherwise there's no way to save and retrieve the
-- value/setting for that control.
------------------------------------------------------------------------
object comments = {}
object txt,line
if file_exists(inifile) then
txt = read_lines(inifile)
for i = 1 to length(txt) do -- extract the comments;
line = txt[i]
if match("--",line) = 1
or match("!",line) = 1
or match("+",line) = 1
or equal("\n",line)
or equal({},line) then
comments = append(comments,line)
end if
end for
write_lines(inifile,comments) -- removing everything but the comments;
end if -- file exists
object setting, tmp = 0, pos = {0,0}
object t1, name, prop
atom handle
integer class
atom fn = open(inifile,"a")
for x = 1 to length(ctl_list) do
if string(ctl_list[x]) then
handle = pointer(ctl_list[x])
else
handle = ctl_list[x]
end if
name = get(handle,"name")
class = class_id(handle)
if class=GtkWindow then -- special handling for multiple properties;
printf(fn,"%s\n",{get_setting(handle,"size")})
pos = get(handle,"position")
printf(fn,"%s.position={%d,%d}\n",{name,pos[1],pos[2]})
else
setting = get_setting(handle) -- others have 1 obvious 'saveable' property
if length(setting) < 1 then
continue
end if
if sequence(setting) then
printf(fn,"%s\n",{setting})
end if
end if
end for
flush(fn)
close(fn)
-- if ! exists for this control:property, then ignore the updated setting;
tmp = read_lines(inifile)
for i = 1 to length(tmp) do
if match("--!",tmp[i]) = 1 then
t1 = split(tmp[i],"=")
t1 = t1[1][2..$]
end if
end for
write_lines(inifile,tmp)
return 1
end function
------------------------------------------------------------------------
export function Load(sequence inifile, integer debug=0)
------------------------------------------------------------------------
-- used to restore settings from the specified ini file.
-- this should be called after the controls are 'realized'
object txt, line, obj, prop, val1=0, val2=0, val3=0, val4=0
if not(file_exists(inifile)) then
write_file(inifile,sprintf("--%s\n\n",{inifile}),TEXT_MODE)
display("Creating ini file: []",{inifile})
else
if debug then display("Reading []",{inifile}) end if
end if
txt = read_lines(inifile)
integer err=0
object a,b
for i = 1 to length(txt) do
line = txt[i]
if match("--",line) > 2 then -- strip trailing comments;
line = line[1..match("--",line)-2]
end if
if match("--!",line) = 1 then
line = line[4..$] -- keep it
end if
if match("+",line) = 1 or match("!",line) then
line = line[2..$] -- dito
end if
if match("--",line) or match(";",line)
or match("/*",line) then
continue -- a comment, do nothing with it
end if
if length(line) > 0 then
line = split(line,'=')
a = line[1] b = line[2]
a = split(a,'.')
line = a & {b}
if debug > 1 then display(line) end if
if vlookup(line[1],registry,4,1,-1) = -1 then
err = i
Error(,"Ini Load Error",
sprintf("Invalid object name: %s",{line[1]}),
sprintf("Line #%d of %s",{i,filename(inifile)}))
else
if equal("data",line[2]) then
set(line[1],"data",line[3],line[4])
else
set(line[1],line[2],line[3])
end if
end if
end if
end for
if debug = 1 then
for i = 1 to length(txt) do
if i = err then
display("ERROR:[:3]:[]",{i,txt[i]})
else
display("[:3]:[]",{i,txt[i]})
end if
end for
end if
write_lines(inifile,txt)
return 1
end function
-------------------------------------------------------------------------------------------
export function Add(object ini,object ctl, sequence prop, object v1=0, object v2=0)
-------------------------------------------------------------------------------------------
if atom(ctl) then ctl = get(ctl,"name") end if
Delete(ini,ctl,prop)
if equal("position",prop) or equal("size",prop) then
if string(v1) then v2 = v1[2] v1 = v1[1] end if
end if
if atom(v2) and v2=0 then
writefln("+[].[]=[]",{ctl,prop,v1},{ini,"a"})
else
writefln("+[].[]={[],[]}",{ctl,prop,v1,v2},{ini,"a"})
end if
return 1
end function
--------------------------------------------------------------------
export function Delete(object ini,object ctl, sequence prop)
--------------------------------------------------------------------
if atom(ctl) then ctl = get(ctl,"name") end if
object tmp = read_lines(ini)
object out = {}
object s1 = text:format("[].[]",{ctl,prop})
for i = 1 to length(tmp) do
if match(s1,tmp[i]) then -- skip
else out &= {tmp[i]}
end if
end for
write_lines(ini,out)
return 1
end function
---------------------------------------------------------------------------------
function get_setting(object self, object property = 0)
-- returns the 'important' value from a control
---------------------------------------------------------------------------------
-- returns settings string
-- object must be a named object, e.g. MyButton
-- MyButton.active=1
-- My Calendar.date={YYYY,MM,DD}
object name = 0
object dt
if string(self) then
name = self
self = vlookup(self,registry,4,1)
end if
object val = 0
object txt = {}
integer x = find(self,vslice(registry,1))
ifdef SETTINGS then
display("SELF [] []",{x,self})
display(registry[x])
end ifdef
switch class_id(self) do
-- this decides which value is the important one to save;
-- and stores the control's current value into the registry;
case GtkEntry,GtkEntryBuffer then property = "text"
case GtkCheckButton,GtkRadioButton, GtkToggleButton,
GtkSwitch,GtkComboBox,GtkComboBoxText,
GtkCheckMenuItem,GtkToggleToolButton, GtkSearchEntry
then property = "active"
case GtkPopover then property = "position"
case GtkFontButton then property = "font name"
case GtkAdjustment,GtkSpinButton,GtkScaleButton,GtkVolumeButton,
GtkModelButton,GtkScale
then property = "value"
case GtkEntryCompletion then property = "model"
case GtkLinkButton then property = "uri"
case GtkMenuItem then property = "sensitive"
case GtkPaned then property = "position"
case GtkFileChooser, GtkFileChooserButton, GtkFileChooserWidget, GtkFileChooserDialog
then property = "filename"
case GtkFontChooser, GtkFontChooserWidget, GtkFontChooserDialog then
property = "font"
case GtkCalendar then
dt = get(self,"datetime",0)
registry[x][5] = {"date",dt[1..3]}
txt &= text:format(fmt,{registry[x][4],"date",dt[1..3]})
return txt
case GtkColorButton,GtkColorChooser,GtkColorChooserWidget,
GtkColorChooserDialog then
registry[x][5] = {"rgba",get(self,"rgba",1)}
txt &= text:format(fmt,{registry[x][4],"rgba",get(self,"rgba",1)})
return txt
end switch
if atom(property) then
return txt
end if
val = get(self,property)
registry[x][5] = {property,val}
txt &= text:format(fmt,{registry[x][4],property,val})
return txt
end function