Prechádzať zdrojové kódy

More advance to a FLTK minimal working module.

mingodad 13 rokov pred
rodič
commit
1b24f86a34

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 654 - 62
ext/sq_fltk.cpp


+ 4 - 0
ourbiz/list-search-window.nut

@@ -1,4 +1,8 @@
 class Fl_Image_Box extends Fl_Box {
+	image_id = null;
+	image_type = null;
+	thumbIMG = null;
+	
 	constructor(px, py, pw, ph, pl=""){
 		base.constructor(px, py, pw, ph, pl);
 	}

+ 14 - 14
ourbiz/ourbiz-client.nut

@@ -215,7 +215,7 @@ class HTTPConnBin extends HTTPConnAuthBase
         my_result.clear();
         local resp_length = r->getLength();
         if(resp_length > 0) my_result.reserve(resp_length);
-        szContentType = r->getheader("Content-type");
+        my_content_type = r->getheader("Content-type");
     }
 
     function response_data( r, data, data_idx, n )
@@ -349,16 +349,16 @@ class AppServer
 
         if(get_conn_type() == conn_type_e.e_conn_http)
         {
-            local  httpRequest = HTTPConnBin(rec);
-            httpcon_setup(httpRequest);
-
-            httpRequest.send_my_request("GET", get_url);
-            if(httpRequest.my_status != 200)
-            {
-                if(throwNotFound) throw(httpRequest.my_result.tostring());
-                else return;
-            }
-            content_type = httpRequest.my_content_type;
+		local  httpRequest = HTTPConnBin(rec);
+		httpcon_setup(httpRequest);
+
+		httpRequest.send_my_request("GET", get_url);
+		if(httpRequest.my_status != 200)
+		{
+			if(throwNotFound) throw(httpRequest.my_result.tostring());
+			else return;
+		}
+		content_type = httpRequest.my_content_type;
         }
     }
 
@@ -367,7 +367,7 @@ class AppServer
         rec.clear();
         if(get_conn_type() == conn_type_e.e_conn_http)
         {
-            local url = format("/DB/GetBin?%s=%s", table, aid);
+            local url = format("/DB/GetBin?%s=%d", table, aid);
             if(extra_url) url += extra_url;
 
             get_binary_data_from_url(url, rec, binary_type, throwNotFound);
@@ -562,13 +562,13 @@ class AppServer
         get_list_data_search(data, "images", 0, so);
     }
 
-    function images_get_image_record(rec, binary_type, id, thumbnail=true, throwNotFound=true)
+    function images_get_image_record_by_id(rec, binary_type, id, thumbnail=true, throwNotFound=true)
     {
         local extra_url = thumbnail ? "&thumbnail=1" : null;
         get_binary_data(rec, binary_type, "image", id, extra_url, throwNotFound);
     }
 
-    function images_get_image_record(rec, binary_type, img_name, thumbnail=true, throwNotFound=true)
+    function images_get_image_record_by_name(rec, binary_type, img_name, thumbnail=true, throwNotFound=true)
     {
         local extra_url = thumbnail ? "&thumbnail=1" : null;
         get_binary_data(rec, binary_type, "image", 0, extra_url, throwNotFound);

+ 97 - 0
ourbiz/ourbiz-fltk.nut

@@ -23,6 +23,76 @@ function create_popup_menu_for (wgt, yOffset=0, options=null){
 	return o;
 }
 
+function clear_image_box(btn)
+{
+    if (btn->thumbIMG)
+    {
+        btn->hide();
+        btn->image(0);
+        btn->thumbIMG = null;
+    }
+}
+
+function button_show_image(btn, image_id, mime_type, image, image_size, window)
+{
+    btn->image_id = image_id;
+    btn->image_type = mime_type;
+    if (btn->image_id)
+    {
+        if (btn->thumbIMG)
+        {
+            btn->thumbIMG = null;
+            btn->image(null);
+        }
+        if(image_size)
+        {
+            local image_name;
+	    local image_header = image.slice(0, 4);
+            if(image_header == "\x89PNG") btn->image_type = "png";
+            else if(image_header == "\xFF\xD8\xFF\xE0") btn->image_type = "jpg";
+
+            image_name = format("thumbJPG%d", btn->image_id);
+            if(btn->image_type == "jpg") btn->thumbIMG = new Fl_JPEG_Image(image_name, image);
+            else if(btn->image_type == "png") btn->thumbIMG = new Fl_PNG_Image(image_name, image, image_size);
+            else return;
+
+            if( (btn->w() < btn->thumbIMG->w()) || (btn->h() < btn->thumbIMG->h()) )
+            {
+                local imgb = btn->thumbIMG;
+                local new_w = imgb->w();
+                local new_h = imgb->h();
+                best_fit(new_w, new_h, btn->w(), btn->h());
+
+                if(new_w < imgb->w() || new_h < imgb->h())
+                {
+                    btn->thumbIMG = imgb->copy(new_w, new_h);
+                }
+            }
+        }
+
+        btn->hide();
+        btn->image(btn->thumbIMG);
+        btn->show();
+        if(window  && window->shown()) window->show_image(btn->image_id);
+    }
+    else
+    {
+        clear_image_box(btn);
+    }
+}
+
+function button_show_db_image(btn, image_id, window=null, asThumb=true, throwNotFound=true)
+{
+	if(image_id)
+	{
+		local rec = blob(0, 8192), image_type;
+		appServer.images_get_image_record_by_id(rec, image_type, image_id, asThumb, throwNotFound);
+		button_show_image(btn, image_id, image_type, rec.tostring(), rec.len(), window);
+		return;
+	}
+	clear_image_box(btn);
+}
+
 class Fl_Box_ClearLabel extends Fl_Box {
 	constructor(px, py, pw, ph, pl=""){
 		base.constructor(px, py, pw, ph, pl);
@@ -133,6 +203,7 @@ class Fl_Data_Table extends Flv_Data_Table {
 		_forPrint=false;
 		_cols_info = [];
 		_data = [];
+		callback_when(FLVEcb_ROW_CHANGED | FLVEcb_CLICKED | FLVEcb_ROW_HEADER_CLICKED);
 	}
 	function resize(ax, ay, aw, ah){
 		base.resize(ax, ay, aw, ah);
@@ -146,6 +217,9 @@ class Fl_Data_Table extends Flv_Data_Table {
 		rows(_data.size());
 		redraw();
 	}
+	
+	function get_data_value(arow, acol){ return _data[arow][acol];}
+	
 	function get_value(arow, acol){
 		if(acol < 0)
 		{
@@ -185,6 +259,12 @@ class Fl_Data_Table extends Flv_Data_Table {
 		return value;
 	}
 	function handle(event){
+		if(event == FLVE_ROW_CHANGED){
+			local pr = parent_root();
+			if(pr && pr.get("on_row_changed", false)){
+				pr.on_row_changed(this, row());
+			}
+		}
 		local rc = base.handle(event);
 		return rc;
 	}
@@ -452,8 +532,11 @@ class ProductsListSearch extends MyListSearchWindow {
 	_search_by_entities = null;
 	_search_by_id = null;
 	_search_by_active = null;
+	_last_image_id = null;
+	_image_window = null;
 	
 	constructor() {
+		_last_image_id = 0;
 		base.constructor();
 		_search_options = OurBizSearchOptions();
 		label(_tr("Products List Search"));
@@ -498,6 +581,20 @@ class ProductsListSearch extends MyListSearchWindow {
 		local pr = sender.parent_root();
 		local win = pr.showChildWindow("Product Edit", EditProductWindow);
 	}
+	
+	function on_row_changed(sender, row){
+		//print("on_row_changed", sender, row);
+		if(shown()){
+			local img_id = sender->get_data_value(row, sender->cols()-1);
+			if(img_id){
+				img_id = img_id.tointeger();
+				if(img_id != _last_image_id){
+					button_show_db_image(btnThumbImage, img_id, _image_window, true, false);
+					_last_image_id = img_id;
+				}
+			}
+		}
+	}
 }
 
 class OrdersListSearch extends MyListSearchWindow {

+ 103 - 0
ourbiz/search-options.nut

@@ -0,0 +1,103 @@
+class OurBizSearchOptions
+{
+    search_str = null;
+    select_fields = null;
+    group_id = null;
+    product_id = null;
+    entity_id = null;
+    order_id = null;
+    payment_type_id = null;
+    query_limit = null;
+    image_id = null;
+    account_id = null;
+    active = null;
+    cdate = null;
+    contact = null;
+    id = null;
+    inactive = null;
+    mdate = null;
+    date = null;
+    name = null;
+    description = null;
+    notes = null;
+    phone = null;
+    products = null;
+    entities = null;
+    buys = null;
+    sales = null;
+    only_prices_older = null;
+    order_by_creation = null;
+    order_by_modification = null;
+    reference = null;
+    total = null;
+    group_set = null;
+    with_images = null;
+    with_headers = null;
+    with_accounts = null;
+    code = null;
+
+    constructor()
+    {
+        reset();
+    }
+    function reset()
+    {
+        search_str = "";
+        select_fields = "";
+        active =
+            cdate =
+                buys =
+                    contact =
+                        id =
+                            inactive =
+                                mdate = date = total = group_set = false;
+        name = notes = phone =
+                           products = entities = description = sales = false;
+        only_prices_older = order_by_creation = order_by_modification =
+            reference = with_images = false;
+        with_headers = with_accounts = code = false;
+        group_id = 0;
+        product_id = entity_id = order_id = payment_type_id = image_id = account_id = 0;
+        query_limit = 50;
+    }
+
+    function getPostOptions()
+    {
+        local ar = ["search_str="];
+        if(search_str.size()){
+		ar.push(url_encode(search_str));
+        }
+        if(select_fields.size()){
+		ar.push("&select_fields=");
+		ar.push(url_encode(select_fields));
+        }
+	foreach(k,v in OurBizSearchOptions){
+		local ktype = type(v);
+		if(ktype == "integer") {
+			if(v) ar.push(format("&%s=%d", k, v));
+		}
+		else if(ktype == "bool"){
+			if(v) ar.push(format("&%s=1", k));
+		}
+	}
+        return ar.concat();
+    }
+
+    function getOptionsFromMap(map)
+    {
+        search_str = map.get("search_str", "");
+        select_fields = map.get("select_fields", "");
+        search_on = map.get("search_on", "1");
+
+	foreach(k,v in this){
+		local ktype = type(v);
+		if(ktype == "integer") {
+			local value = map.get(k, null);
+			if(value != null) this[k] = value.tointeger();
+		}
+		else if(ktype == "bool"){
+			this[k] = map.get(k, null) != null;
+		}
+	}
+    }
+};

+ 2 - 2
squilu.cbp

@@ -112,11 +112,11 @@
 					<Add library="dl" />
 					<Add library="axtls" />
 					<Add library="fltkutils" />
-					<Add library="fltk" />
 					<Add library="fltk_images" />
 					<Add library="fltk_png" />
 					<Add library="fltk_jpeg" />
 					<Add library="fltk_z" />
+					<Add library="fltk" />
 					<Add library="Xext" />
 					<Add library="Xft" />
 					<Add library="Xinerama" />
@@ -148,11 +148,11 @@
 					<Add library="dl" />
 					<Add library="axtls" />
 					<Add library="fltkutils" />
-					<Add library="fltk" />
 					<Add library="fltk_images" />
 					<Add library="fltk_png" />
 					<Add library="fltk_jpeg" />
 					<Add library="fltk_z" />
+					<Add library="fltk" />
 					<Add library="Xext" />
 					<Add library="Xft" />
 					<Add library="Xinerama" />

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov