Prechádzať zdrojové kódy

Added more classes and methods to FLTK module.

mingodad 13 rokov pred
rodič
commit
1e0d5f1aad

+ 72 - 43
ext/sq_fltk.cpp

@@ -13,6 +13,7 @@
 #include <FL/Fl_Light_Button.H>
 #include <FL/Fl_Check_Button.H>
 #include <FL/Fl_Radio_Button.H>
+#include <FL/Fl_Repeat_Button.H>
 #include <FL/Fl_Return_Button.H>
 #include <FL/Fl_Round_Button.H>
 #include <FL/Fl_Menu_Item.H>
@@ -73,6 +74,7 @@ CREATE_TAG(Fl_Button);
 CREATE_TAG(Fl_Light_Button);
 CREATE_TAG(Fl_Check_Button);
 CREATE_TAG(Fl_Radio_Button);
+CREATE_TAG(Fl_Repeat_Button);
 CREATE_TAG(Fl_Return_Button);
 CREATE_TAG(Fl_Round_Button);
 CREATE_TAG(Fl_Menu_);
@@ -464,6 +466,7 @@ static SQRESULT fltk_pushinstance(HSQUIRRELVM v, const SQChar *klass, SQUserPoin
 	if(sq_getonroottable(v) == SQ_OK){
 	    if(sq_createinstance(v, -1) == SQ_OK){
 	        sq_setinstanceup(v, -1, self);
+	        sq_remove(v, -2); //remove class
 	        return 1;
 	    }
 	}
@@ -877,6 +880,16 @@ static SQRegFunction fl_radio_button_obj_funcs[]={
 };
 #undef _DECL_FUNC
 
+FLTK_CONSTRUCTOR(Fl_Repeat_Button);
+CHEAP_RTTI_FOR(Fl_Repeat_Button);
+#define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Fl_Repeat_Button_##name,nparams,pmask,isStatic}
+static SQRegFunction fl_repeat_button_obj_funcs[]={
+    CHEAP_RTTI_REG_FUN_FOR(Fl_Repeat_Button)
+	_DECL_FUNC(constructor,-5,FLTK_constructor_Mask, SQFalse),
+	{0,0}
+};
+#undef _DECL_FUNC
+
 FLTK_CONSTRUCTOR(Fl_Return_Button);
 CHEAP_RTTI_FOR(Fl_Return_Button);
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Fl_Return_Button_##name,nparams,pmask,isStatic}
@@ -1396,9 +1409,12 @@ static SQRegFunction flu_combo_tree_browser_obj_funcs[]={
 };
 #undef _DECL_FUNC
 
-#define SETUP_FLV_STYLE(v) SETUP_FL_KLASS(v, Flv_Style)
+#define SETUP_FLV_STYLE_AT(v, idx, Var) SETUP_FL_KLASS_AT(v, idx, Var, Flv_Style)
+#define SETUP_FLV_STYLE(v) SETUP_FLV_STYLE_AT(v, 1, self)
 #define FLV_STYLE_GETSET_INT_CAST(funcNAME, typeNAME) FUNC_GETSET_INT(_Flv_Style_, SETUP_FLV_STYLE, self->, funcNAME, typeNAME)
 #define FLV_STYLE_GETSET_INT(funcNAME) FLV_STYLE_GETSET_INT_CAST(funcNAME, int)
+#define FLV_STYLE_GETSET_BOOL(funcNAME) FUNC_GETSET_BOOL(_Flv_Style_, SETUP_FLV_STYLE, self->,funcNAME)
+#define FLV_STYLE_GET_BOOL(funcNAME) FUNC_GET_BOOL(_Flv_Style_, SETUP_FLV_STYLE, funcNAME)
 
 
 //no constructor for Flv_Style
@@ -1564,6 +1580,9 @@ FLV_STYLE_GETSET_INT_CAST(align, Fl_Align);
 FLV_STYLE_GETSET_INT_CAST(border_color, Fl_Color);
 FLV_STYLE_GETSET_INT_CAST(foreground, Fl_Color);
 FLV_STYLE_GETSET_INT_CAST(background, Fl_Color);
+FLV_STYLE_GETSET_BOOL(resizable);
+FLV_STYLE_GET_BOOL(foreground_defined);
+FLV_STYLE_GET_BOOL(background_defined);
 
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Flv_Style_##name,nparams,pmask,isStatic}
 static SQRegFunction flv_style_obj_funcs[]={
@@ -1579,7 +1598,10 @@ static SQRegFunction flv_style_obj_funcs[]={
 	_DECL_FUNC(align,-1,_SC("xi"),SQFalse),
 	_DECL_FUNC(border_color,-1,_SC("xi"),SQFalse),
 	_DECL_FUNC(foreground,-1,_SC("xi"),SQFalse),
+	_DECL_FUNC(foreground_defined,1,_SC("x"),SQFalse),
 	_DECL_FUNC(background,-1,_SC("xi"),SQFalse),
+	_DECL_FUNC(background_defined,1,_SC("x"),SQFalse),
+	_DECL_FUNC(resizable,-1,_SC("xb"),SQFalse),
 	{0,0}
 };
 #undef _DECL_FUNC
@@ -1642,7 +1664,19 @@ static SQRESULT _Flv_List_clear_callback_when(HSQUIRRELVM v){
     SQ_GET_INTEGER(v, 2, when);
     self->clear_callback_when(when);
     return 1;
-}
+}
+
+//void get_style( Flv_Style &s, int R, int C=0 )
+static SQRESULT _Flv_List_get_style(HSQUIRRELVM v){
+    SQ_FUNC_VARS(v);
+    SETUP_FLV_LIST(v);
+    SETUP_FLV_STYLE_AT(v, 2, style);
+    SQ_GET_INTEGER(v, 3, row);
+    SQ_OPT_INTEGER(v, 4, col, 0);
+    self->get_style(*style, row, col);
+    return 0;
+}
+
 CHEAP_RTTI_FOR(Flv_List);
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Flv_List_##name,nparams,pmask,isStatic}
 static SQRegFunction flv_list_obj_funcs[]={
@@ -1661,6 +1695,7 @@ static SQRegFunction flv_list_obj_funcs[]={
 	_DECL_FUNC(callback_when,-1,_SC("xi"),SQFalse),
 	_DECL_FUNC(add_callback_when,2,_SC("xi"),SQFalse),
 	_DECL_FUNC(clear_callback_when,2,_SC("xi"),SQFalse),
+	_DECL_FUNC(get_style,-3,_SC("xxii"),SQFalse),
 	{0,0}
 };
 #undef _DECL_FUNC
@@ -1720,14 +1755,12 @@ class Flv_Data_Table : public Flv_Table
 {
 public:
     int selection_count, _draw_offset;
-    bool _forPrint;
 
     Flv_Data_Table(int X, int Y, int W=340, int H=202, const char *L=0):
         Flv_Table(X, Y, W, H, L)
     {
         _draw_offset = 5;
         selection_count = 0;
-        _forPrint = false;
 
         callback_when( FLVEcb_ROW_CHANGED | FLVEcb_CLICKED);
         selection_color(FL_BLUE);
@@ -1765,35 +1798,20 @@ public:
 
     void get_style(Flv_Style &s, int R, int C )
     {
+        HSQUIRRELVM v = (HSQUIRRELVM) Fl::user_data;
+        SQInteger top = sq_gettop(v);
+        if(sq_get_fl_virtual(v, this, "get_style") == SQ_OK){
+            sq_push(v, -2); //this
+            fltk_pushinstance(v, FLTK_TAG(Flv_Style), &s);
+            sq_pushinteger(v, R);
+            sq_pushinteger(v, C);
+            if(sq_call(v, 4, SQFalse, SQTrue) == SQ_OK){
+                sq_settop(v, top);
+                return;
+            }
+        }
+        sq_settop(v, top);
         Flv_Table::get_style(s, R, C);
-        if(R >= 0 && C >= 0)
-        {
-            Flv_Style &rs = row_style.get(R);
-            Flv_Style &cs = col_style.get(C);
-            Fl_Color have_bg = 0;
-            if(cs.background_defined()) have_bg = cs.background();
-            else if(rs.background_defined()) have_bg = rs.background();
-            if((R % 2) == 0)
-            {
-                if(have_bg)
-                    //s:background(fltk.fl_color_average(207, have_bg, 0.5))
-                    s.background(have_bg);
-                else
-                    s.background(207);
-            }
-            else
-            {
-                if(have_bg)
-                    //s:background(have_bg)
-                    s.background(fl_color_average(FL_WHITE, have_bg, 0.5));
-                else
-                    s.background(FL_WHITE);
-            }
-        }
-        else if(_forPrint)
-        {
-            s.frame(FL_NO_BOX);
-        }
     }
 
     virtual void draw_cell( int Offset, int &X, int &Y, int &W, int &H, int R, int C ){
@@ -1979,17 +1997,15 @@ static SQInteger _Flv_Data_Table_draw_offset(HSQUIRRELVM v)
     return 1;
 }
 
-static SQInteger _Flv_Data_Table_for_print(HSQUIRRELVM v)
-{
-    SQ_FUNC_VARS(v);
+//void get_style( Flv_Style &s, int R, int C=0 )
+static SQRESULT _Flv_Data_Table_get_style(HSQUIRRELVM v){
+    SQ_FUNC_VARS(v);
     SETUP_FLV_DATA_TABLE(v);
-    if(_top_ > 1){
-        SQ_GET_BOOL(v, 2, bval);
-        ((Flv_Data_Table*)self)->_forPrint = bval;
-        return 0;
-    }
-    sq_pushbool(v, ((Flv_Data_Table*)self)->_forPrint);
-    return 1;
+    SETUP_FLV_STYLE_AT(v, 2, style);
+    SQ_GET_INTEGER(v, 3, row);
+    SQ_OPT_INTEGER(v, 4, col, 0);
+    self->Flv_Table::get_style(*style, row, col);
+    return 0;
 }
 
 FLTK_CONSTRUCTOR(Flv_Data_Table);
@@ -1998,9 +2014,9 @@ FLTK_CONSTRUCTOR(Flv_Data_Table);
 static SQRegFunction flv_data_table_obj_funcs[]={
 	_DECL_FUNC(constructor,-5,FLTK_constructor_Mask, SQFalse),
 	_DECL_FUNC(handle,2,_SC("xi"),SQFalse),
-	_DECL_FUNC(for_print,-1,_SC("xb"),SQFalse),
 	_DECL_FUNC(resize,5,_SC("xnnnn"),SQFalse),
 	_DECL_FUNC(draw_offset, -1,_SC("xn"),SQFalse),
+	_DECL_FUNC(get_style,-3,_SC("xxii"),SQFalse),
 	{0,0}
 };
 #undef _DECL_FUNC
@@ -3570,6 +3586,17 @@ static SQInteger _fl_globals_fl_not_clipped(HSQUIRRELVM v)
     return 1;
 }
 
+//Fl_Color fl_color_average(Fl_Color c1, Fl_Color c2, float weight)
+static SQInteger _fl_globals_fl_color_average(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS_NO_TOP(v);
+    SQ_GET_INTEGER(v, 2, c1);
+    SQ_GET_INTEGER(v, 3, c2);
+    SQ_GET_FLOAT(v, 4, weight);
+    sq_pushinteger(v, fl_color_average(c1, c2, weight));
+    return 1;
+}
+
 static SQInteger _fl_globals_fl_preferences(HSQUIRRELVM v)
 {
     SQ_FUNC_VARS(v);
@@ -3586,6 +3613,7 @@ static SQRegFunction fl_globals_funcs[]={
 	_DECL_FUNC(fl_alert, 2,_SC(".s"),SQTrue),
 	_DECL_FUNC(fl_cursor, -2,_SC(".iii"),SQTrue),
 	_DECL_FUNC(fl_color,-1,_SC(".i"),SQTrue),
+	_DECL_FUNC(fl_color_average,4,_SC(".iif"),SQTrue),
 	_DECL_FUNC(fl_draw,-4,_SC(". n|s n|s nnn"),SQTrue),
 	_DECL_FUNC(fl_font,-1,_SC(".ii"),SQTrue),
 	_DECL_FUNC(fl_size,1,_SC("."),SQTrue),
@@ -3990,6 +4018,7 @@ SQRESULT sqext_register_fltklib(HSQUIRRELVM v)
 	PUSH_FL_CLASS(Fl_Check_Button, Fl_Light_Button, fl_check_button_obj_funcs);
 	PUSH_FL_CLASS(Fl_Radio_Button, Fl_Button, fl_radio_button_obj_funcs);
 	PUSH_FL_CLASS(Fl_Return_Button, Fl_Button, fl_return_button_obj_funcs);
+	PUSH_FL_CLASS(Fl_Repeat_Button, Fl_Button, fl_repeat_button_obj_funcs);
 	PUSH_FL_CLASS(Fl_Round_Button, Fl_Light_Button, fl_round_button_obj_funcs);
 
 	PUSH_FL_CLASS(Fl_Menu_, Fl_Widget, fl_menu__obj_funcs);

+ 105 - 0
ourbiz/calendar-gui.fl

@@ -0,0 +1,105 @@
+# data file for the Fltk User Interface Designer (fluid)
+version 1.0302 
+i18n_type 1 
+i18n_include i18n_function.h 
+i18n_function _tr 
+header_name {.h} 
+code_name {.cxx}
+widget_class CalendarWindow {
+  label Calendar open selected
+  xywh {732 184 350 305} type Double labelsize 16
+  class Base_Window visible
+} {
+  Fl_Box label_month {
+    label Calendar
+    xywh {5 5 340 25} box ENGRAVED_BOX color 7 labelsize 16
+  }
+  Fl_Group {} {open
+    xywh {6 35 340 25} labelsize 16
+  } {
+    Fl_Button btnMonth1 {
+      label 1
+      xywh {6 35 25 25}
+    }
+    Fl_Button btnMonth2 {
+      label 2
+      xywh {34 35 25 25}
+    }
+    Fl_Button btnMonth3 {
+      label 3
+      xywh {63 35 25 25}
+    }
+    Fl_Button btnMonth4 {
+      label 4
+      xywh {91 35 25 25}
+    }
+    Fl_Button btnMonth5 {
+      label 5
+      xywh {120 35 25 25}
+    }
+    Fl_Button btnMonth6 {
+      label 6
+      xywh {148 35 25 25}
+    }
+    Fl_Button btnMonth7 {
+      label 7
+      xywh {177 35 25 25}
+    }
+    Fl_Button btnMonth8 {
+      label 8
+      xywh {205 35 25 25}
+    }
+    Fl_Button btnMonth9 {
+      label 9
+      xywh {234 35 25 25}
+    }
+    Fl_Button btnMonth10 {
+      label 10
+      xywh {262 35 25 25}
+    }
+    Fl_Button btnMonth11 {
+      label 11
+      xywh {291 35 25 25}
+    }
+    Fl_Button btnMonth12 {
+      label 12
+      xywh {320 35 25 25}
+    }
+  }
+  Fl_Browser calendar_table {
+    xywh {5 65 340 202} labeltype NO_LABEL labelsize 16
+    class Fl_Virtual_Table
+  }
+  Fl_Group {} {open
+    xywh {5 275 340 25} labelsize 16
+  } {
+    Fl_Button btnPrevYear {
+      label {@<<}
+      tooltip {Go to previous year} xywh {5 275 50 25} labelsize 16
+      class Fl_Repeat_Button
+    }
+    Fl_Button btnPrevMonth {
+      label {@<}
+      tooltip {Go to previous month} xywh {63 275 50 25} labelsize 16
+      class Fl_Repeat_Button
+    }
+    Fl_Button btnToday {
+      label {@<->}
+      tooltip {Go to today date} xywh {121 275 50 25} labelsize 16
+    }
+    Fl_Button btnSelect {
+      label {@circle}
+      tooltip {Select current date} xywh {179 275 50 25} labelsize 16
+    }
+    Fl_Button btnNextMonth {
+      label {@>}
+      tooltip {Go to next month} xywh {237 275 50 25} labelsize 16
+      class Fl_Repeat_Button
+    }
+    Fl_Button btnNextYear {
+      label {@>>}
+      tooltip {Go to next year} xywh {295 275 50 25} labelsize 16
+      class Fl_Repeat_Button
+    }
+  }
+} 

+ 142 - 0
ourbiz/calendar-gui.nut

@@ -0,0 +1,142 @@
+class CalendarWindow extends MyBaseWindow {
+  
+  // Declaration of class members
+  label_month = null;
+  btnMonth1 = null;
+  btnMonth2 = null;
+  btnMonth3 = null;
+  btnMonth4 = null;
+  btnMonth5 = null;
+  btnMonth6 = null;
+  btnMonth7 = null;
+  btnMonth8 = null;
+  btnMonth9 = null;
+  btnMonth10 = null;
+  btnMonth11 = null;
+  btnMonth12 = null;
+  grid = null;
+  btnPrevYear = null;
+  btnPrevMonth = null;
+  btnToday = null;
+  btnSelect = null;
+  btnNextMonth = null;
+  btnNextYear = null;
+  
+  constructor(){
+    base.constructor(732, 184, 350, 305);
+    // Create member functions and widgets
+    {
+      local o = Fl_Box(5, 5, 340, 25, _tr("Calendar"));
+      label_month = o;
+      o.labelsize(16);
+      o.box(FL_ENGRAVED_BOX);
+      o.color(7);
+    }
+    {
+      local o = Fl_Group(6, 35, 340, 25);
+      o.labelsize(16);
+      {
+        {
+          local o = Fl_Button(6, 35, 25, 25, _tr("1"));
+          btnMonth1 = o;
+        }
+        {
+          local o = Fl_Button(34, 35, 25, 25, _tr("2"));
+          btnMonth2 = o;
+        }
+        {
+          local o = Fl_Button(63, 35, 25, 25, _tr("3"));
+          btnMonth3 = o;
+        }
+        {
+          local o = Fl_Button(91, 35, 25, 25, _tr("4"));
+          btnMonth4 = o;
+        }
+        {
+          local o = Fl_Button(120, 35, 25, 25, _tr("5"));
+          btnMonth5 = o;
+        }
+        {
+          local o = Fl_Button(148, 35, 25, 25, _tr("6"));
+          btnMonth6 = o;
+        }
+        {
+          local o = Fl_Button(177, 35, 25, 25, _tr("7"));
+          btnMonth7 = o;
+        }
+        {
+          local o = Fl_Button(205, 35, 25, 25, _tr("8"));
+          btnMonth8 = o;
+        }
+        {
+          local o = Fl_Button(234, 35, 25, 25, _tr("9"));
+          btnMonth9 = o;
+        }
+        {
+          local o = Fl_Button(262, 35, 25, 25, _tr("10"));
+          btnMonth10 = o;
+        }
+        {
+          local o = Fl_Button(291, 35, 25, 25, _tr("11"));
+          btnMonth11 = o;
+        }
+        {
+          local o = Fl_Button(320, 35, 25, 25, _tr("12"));
+          btnMonth12 = o;
+        }
+      }
+      o.end();
+    }
+    {
+      local o = Fl_Data_Table_Calendar(5, 65, 340, 202);
+      grid = o;
+      o.labeltype(FL_NO_LABEL);
+      o.labelsize(16);
+      o.end();
+    }
+    {
+      local o = Fl_Group(5, 275, 340, 25);
+      o.labelsize(16);
+      {
+        {
+          local o = Fl_Repeat_Button(5, 275, 50, 25, _tr("@<<"));
+          btnPrevYear = o;
+          o.labelsize(16);
+          o.tooltip(_tr("Go to previous year"));
+        }
+        {
+          local o = Fl_Repeat_Button(63, 275, 50, 25, _tr("@<"));
+          btnPrevMonth = o;
+          o.labelsize(16);
+          o.tooltip(_tr("Go to previous month"));
+        }
+        {
+          local o = Fl_Button(121, 275, 50, 25, _tr("@<->"));
+          btnToday = o;
+          o.labelsize(16);
+          o.tooltip(_tr("Go to today date"));
+        }
+        {
+          local o = Fl_Button(179, 275, 50, 25, _tr("@circle"));
+          btnSelect = o;
+          o.labelsize(16);
+          o.tooltip(_tr("Select current date"));
+        }
+        {
+          local o = Fl_Repeat_Button(237, 275, 50, 25, _tr("@>"));
+          btnNextMonth = o;
+          o.labelsize(16);
+          o.tooltip(_tr("Go to next month"));
+        }
+        {
+          local o = Fl_Repeat_Button(295, 275, 50, 25, _tr("@>>"));
+          btnNextYear = o;
+          o.labelsize(16);
+          o.tooltip(_tr("Go to next year"));
+        }
+      }
+      o.end();
+    }
+  }
+}
+

+ 85 - 0
ourbiz/delivery-calc-gui.fl

@@ -0,0 +1,85 @@
+# data file for the Fltk User Interface Designer (fluid)
+version 1.0300 
+i18n_type 1 
+i18n_include i18n_function.h 
+i18n_function _tr 
+header_name {.h} 
+code_name {.cxx}
+decl {\#include "My_Base_App.h"} {public global
+} 
+
+widget_class DeliveryCalcWindow {
+  label {Delivery Calc} open
+  xywh {338 167 416 289} type Double labelsize 16
+  class Base_Window visible
+} {
+  Fl_Input gui_destination_zone {
+    label {Destination Zone}
+    dirty_name gui_destination_zone
+    xywh {10 25 395 25} labelsize 16 align 5 textsize 16
+    class Flu_Combo_List
+  }
+  Fl_Input gui_destination_city {
+    label {Destination City}
+    dirty_name gui_destination_city
+    xywh {10 80 395 25} labelsize 16 align 5 textsize 16
+    class Flu_Combo_List
+  }
+  Fl_Input gui_weight {
+    label Weight
+    dirty_name gui_weight selected
+    xywh {10 132 100 25} type Float labelsize 16 align 5 textfont 1 textsize 16
+  }
+  Fl_Output gui_cost {
+    label Cost
+    dirty_name gui_cost
+    xywh {130 133 130 24} labelsize 16 align 5 textsize 16
+    code0 {o->right_to_left(1);}
+    code1 {o->use_numeric_format(1);}
+  }
+  Fl_Output gui_discount {
+    label Discount
+    dirty_name gui_discount
+    xywh {276 131 130 24} labelsize 16 align 5 textsize 16
+    code0 {o->right_to_left(1);}
+    code1 {o->use_numeric_format(1);}
+  }
+  Fl_Output gui_subtotal {
+    label Subtotal
+    dirty_name gui_subtotal
+    xywh {130 185 130 24} labelsize 16 align 5 textsize 16
+    code0 {o->right_to_left(1);}
+    code1 {o->use_numeric_format(1);}
+  }
+  Fl_Output gui_insurance {
+    label Insurance
+    dirty_name gui_insurance
+    xywh {275 181 130 24} labelsize 16 align 5 textsize 16
+    code0 {o->right_to_left(1);}
+    code1 {o->use_numeric_format(1);}
+  }
+  Fl_Output gui_increment {
+    label Increment
+    dirty_name gui_increment
+    xywh {276 219 130 24} labelsize 16 textsize 16
+    code0 {o->right_to_left(1);}
+    code1 {o->use_numeric_format(1);}
+  }
+  Fl_Output gui_total {
+    label Total
+    dirty_name gui_total
+    xywh {276 253 130 24} labelsize 16 textfont 1 textsize 16
+    code0 {o->right_to_left(1);}
+    code1 {o->use_numeric_format(1);}
+  }
+  Fl_Button gui_btnCalc {
+    label Calc
+    dirty_name gui_btnCalc
+    tooltip {Calculate the delivery price} xywh {10 217 100 25} labelsize 16
+  }
+  Fl_Button gui_btnAdd {
+    label Add
+    dirty_name gui_btnAdd
+    tooltip {Add the calculated value on the invoice line} xywh {10 252 100 25} labelsize 16
+  }
+} 

+ 108 - 0
ourbiz/delivery-calc-gui.nut

@@ -0,0 +1,108 @@
+class DeliveryCalcWindow extends MyBaseWindow {
+  
+  // Declaration of class members
+  gui_destination_zone = null;
+  gui_destination_city = null;
+  gui_weight = null;
+  gui_cost = null;
+  gui_discount = null;
+  gui_subtotal = null;
+  gui_insurance = null;
+  gui_increment = null;
+  gui_total = null;
+  gui_btnCalc = null;
+  gui_btnAdd = null;
+  
+  constructor(){
+    base.constructor(338, 167, 416, 289);
+    // Create member functions and widgets
+    {
+      local o = Flu_Combo_List(10, 25, 395, 25, _tr("Destination Zone"));
+      gui_destination_zone = o;
+      o.textsize(16);
+      o.align(5);
+      o.labelsize(16);
+    }
+    {
+      local o = Flu_Combo_List(10, 80, 395, 25, _tr("Destination City"));
+      gui_destination_city = o;
+      o.textsize(16);
+      o.align(5);
+      o.labelsize(16);
+    }
+    {
+      local o = Fl_Float_Input(10, 132, 100, 25, _tr("Weight"));
+      gui_weight = o;
+      o.textsize(16);
+      o.align(5);
+      o.textfont(1);
+      o.labelsize(16);
+    }
+    {
+      local o = Fl_Output(130, 133, 130, 24, _tr("Cost"));
+      gui_cost = o;
+      o.textsize(16);
+      o.align(5);
+      o.labelsize(16);
+      o->right_to_left(1);
+      o->use_numeric_format(1);
+    }
+    {
+      local o = Fl_Output(276, 131, 130, 24, _tr("Discount"));
+      gui_discount = o;
+      o.textsize(16);
+      o.align(5);
+      o.labelsize(16);
+      o->right_to_left(1);
+      o->use_numeric_format(1);
+    }
+    {
+      local o = Fl_Output(130, 185, 130, 24, _tr("Subtotal"));
+      gui_subtotal = o;
+      o.textsize(16);
+      o.align(5);
+      o.labelsize(16);
+      o->right_to_left(1);
+      o->use_numeric_format(1);
+    }
+    {
+      local o = Fl_Output(275, 181, 130, 24, _tr("Insurance"));
+      gui_insurance = o;
+      o.textsize(16);
+      o.align(5);
+      o.labelsize(16);
+      o->right_to_left(1);
+      o->use_numeric_format(1);
+    }
+    {
+      local o = Fl_Output(276, 219, 130, 24, _tr("Increment"));
+      gui_increment = o;
+      o.textsize(16);
+      o.labelsize(16);
+      o->right_to_left(1);
+      o->use_numeric_format(1);
+    }
+    {
+      local o = Fl_Output(276, 253, 130, 24, _tr("Total"));
+      gui_total = o;
+      o.textsize(16);
+      o.textfont(1);
+      o.labelsize(16);
+      o->right_to_left(1);
+      o->use_numeric_format(1);
+    }
+    {
+      local o = Fl_Button(10, 217, 100, 25, _tr("Calc"));
+      gui_btnCalc = o;
+      o.labelsize(16);
+      o.tooltip(_tr("Calculate the delivery price"));
+    }
+    {
+      local o = Fl_Button(10, 252, 100, 25, _tr("Add"));
+      gui_btnAdd = o;
+      o.labelsize(16);
+      o.tooltip(_tr("Add the calculated value on the invoice line"));
+    }
+  }
+}
+

+ 352 - 0
ourbiz/delivery-info.json

@@ -0,0 +1,352 @@
+{
+"provincias" : [
+[1,4,"ALAVA", "Victoria"],
+[2,4,"ALBACETE", "Albacete"],
+[3,3,"ALICANTE", "Alicante", "Crevillente", "Elche", "Elda", "Matola", "San Felipe Neri", "San Juan", "San Vicente de Raspeig", "Torrellano", "Valverde"],
+[4,8,"ALMERIA", "Almeria", "Aguadulce", "Benahadux", "El Ejido", "Huercal de Almería", "La Cañada", "Pechina", "Viator", "Vicar"],
+[33,4,"ASTURIAS", "Oviedo", "Gijón", "Avilés"],
+[5,4,"AVILA", "Ávila"],
+[6,3,"BADAJOZ", "Badajoz"],
+[7,13,"BALEARES, ISLAS", "Palma de Mallorca"],
+[8,1,"BARCELONA", "Barcelona", "Badalona", "Badia", "Cornella de Llobregat", "Hospitalet de Llobregat", "La Florida", "La Llagosta", "Mollet del Valles", "Moncada y Reixach", "Parets del Valles", "San Adrián del Besós", "San Justo Desvern", "Santa Coloma de Gramanet", "Santa Perpetua de Mogoda"],
+[9,1,"BURGOS", "Burgos"],
+[10,3,"CACERES", "Cáceres"],
+[11,9,"CADIZ", "Cadiz", "Jerez", "Puerto Real", "Puerto de Santa María", "San Fernando"],
+[112,8,"CADIZ-Algeciras", "Algeciras", "Estación de San Roque", "La Línea", "Los Barrios", "Palmones", "San Roque"],
+[39,4,"CANTABRIA", "Santander", "Torrelavega"],
+[12,4,"CASTELLON", "Castellón", "Almazora", "El Grao", "Villarreal de los Infantes"],
+[51,-1,"CEUTA", "Ceuta"],
+[13,4,"CIUDAD REAL", "Ciudad Real"],
+[14,8,"CORDOBA", "Córdoba", "Cabra", "Albedín", "Alcolea", "El Higuerón", "Monturque", "Priego de Córdoba", "Santa Cruz", "Villarrubia", "Villaviciosa"],
+[15,4,"CORUÑA, LA", "La Coruña", "Arteixo", "Bergondo", "Betanzos", "Cambre", "Culleredo", "El Ferrol", "Oleiros", "Padrón y Santiago"],
+[16,4,"CUENCA", "Cuenca"],
+[17,4,"GERONA", "Gerona", "Aiguaviva", "El Perelló", "Salt", "Vilablareix"],
+[18,8,"GRANADA", "Granada", "Albolote", "Armilla", "Atarfe", "Cerrillo de Maracena", "Huetor Vega", "Maracena", "Ogijares", "Peligros", "Pinos Puente", "Pulianas", "Santa Fe"],
+[19,4,"GUADALAJARA", "Guadalajara"],
+[20,4,"GUIPUZCOA", "Hernani", "Lasarte", "San Sebastián", "Usurbil"],
+[21,9,"HUELVA", "Huelva", "Aljaraque", "Bea", "Gibrale?n", "Moguer", "Pozo del Camino", "San Juan del Puerto"],
+[22,4,"HUESCA", "Huesca"],
+[23,8,"JAEN", "Jaen", "Andujar", "Bailén", "Linares", "Torredelcampo", "Ubeda"],
+[24,4,"LEON", "Leon"],
+[25,4,"LERIDA", "Lérida"],
+[27,4,"LUGO", "Lugo"],
+[28,3,"MADRID", "Madrid", "Alcobendas", "Alcorcón", "Coslada", "Fuenlabrada", "Getafe", "Leganés", "Pinto", "San Fernando de Henares", "San Sebastián de los Reyes", "Torrejón de Ardoz"],
+[29,10,"MALAGA", "Málaga todas poblaciones"],
+[52,-1,"MELILLA", "Mellilla"],
+[30,6,"MURCIA", "Murcia", "Alcantarilla", "Algezares", "Aljucer", "Beniaján", "Cabezo de Torres", "Cabezo Cortado", "El Palmar", "El Puntal", "Espinardo", "La Albatalia", "La Azacaya", "Molina de Segura", "Nonduermas", "Puente Tocinos", "San Ginés"],
+[31,4,"NAVARRA", "Panplona", "Barrioplano", "Berriozar", "Burlada", "Huarte", "Mutilva Alta", "Mutilva Baja", "Noain", "Villava"],
+[32,4,"OURENSE", "Orense", "San Ciprián das Viñas"],
+[34,1,"PALENCIA", "Palencia", "Dueñas"],
+[35,-1,"PALMAS, LAS", "Las Palmas de Gran Canaria"],
+[36,4,"PONTEVEDRA", "Pontevedra", "Marín", "Mos", "Porriño", "Puixeros", "Redondela y Vigo"],
+[26,4,"RIOJA, LA", "Logroño"],
+[37,1,"SALAMANCA", "Salamanca", "Cabrerizos", "Carbajosa de la Sagrada", "Castellanos de Moriscos", "Villares de la Reina"],
+[38,-1,"SANTA CRUZ DE TENERIFE", "Santa Cruz de Tenerife"],
+[40,4,"SEGOVIA", "Segovia"],
+[41,8,"SEVILLA", "Sevilla", "Alcalá de Guadaira", "Bormujos", "Camas", "Castilleja de la Cuesta", "Dos Hermanas", "Gines", "La Rinconada", "Mairena de Aljarafe", "San Juan de Aznalfarache", "Santiponce", "Tomares", "Valencina de la Concepción"],
+[42,4,"SORIA", "Soria"],
+[43,4,"TARRAGONA", "Tarragona", "Reus"],
+[44,4,"TERUEL", "Teruel"],
+[45,4,"TOLEDO", "Toledo"],
+[46,3,"VALENCIA", "Valencia", "Alacuas", "Aldaya", "Burjasot", "Chirivella", "Mislata", "Nazaret", "Paiporta", "Paterna", "Pica?a", "Tabernes Blanques", "Torrente", "Vinalesa"],
+[47,1,"VALLADOLID", "Valladolid", "Cigales", "Fuensaldaña", "Laguna de Duero", "La Cisternita", "Tudela de Duero", "Villanuela"],
+[48,4,"VIZCAYA", "Arrigorriaga", "Astraduba", "Asua", "Baracaldo", "Basauri", "Bilbao", "Cruces", "Erandio", "Etxeberri", "Galdacano", "Guetxo", "Lejona", "Loiu", "Portugalete", "San Salvador del Valle", "Sondica", "Trápaga", "Zorroza"],
+[49,1,"ZAMORA", "Zamora"],
+[50,1,"ZARAGOZA", "Zaragoza", "Alfajarón", "Cadrete", "Casetas", "Cuarte de Huerva", "Burgo de Ebro", "Figueruelas", "La Cartuja", "La Puebla de Alfinden", "María de Huerva", "Monzalbarba", "Pastriz", "San Juan de Mozarrifar", "Utebo", "Villafranca de Ebro", "Villanueva de Gállego y Zuera"]
+],
+
+"peso_escala" : [
+10,
+20,
+30,
+40,
+50,
+60,
+70,
+80,
+90,
+100,
+120,
+140,
+160,
+180,
+200,
+250,
+300,
+350,
+400,
+450,
+500,
+600,
+700,
+800,
+900,
+1000,
+1001
+],
+
+"precio_baremo_descuento" : [
+0,
+0.2,
+0,
+0.2,
+0.2,
+0,
+0.2,
+0,
+0.2,
+0.2,
+0.2
+],
+
+"precio_baremo" : [
+[],
+[
+	9.92,
+	15.78,
+	20.82,
+	24.96,
+	29.31,
+	34.02,
+	37.35,
+	40.61,
+	44.17,
+	50.02,
+	56.12,
+	62.99,
+	69.76,
+	77.33,
+	85.13,
+	98.84,
+	110.31,
+	126.09,
+	139.18,
+	151.17,
+	162.06,
+	194.13,
+	217.55,
+	238.95,
+	251.33,
+	270.43,
+	249.84
+],
+[],
+[
+	8.66,
+	13.05,
+	16.83,
+	20.59,
+	24.03,
+	28.03,
+	31.35,
+	32.79,
+	37.13,
+	41.30,
+	46.25,
+	52.33,
+	57.95,
+	64.03,
+	69.76,
+	80.35,
+	90.42,
+	102.13,
+	112.26,
+	122.21,
+	127.94,
+	154.62,
+	171.66,
+	185.62,
+	209.25,
+	226.53,
+	205.71
+],
+[
+	10.69,
+	16.99,
+	22.42,
+	26.87,
+	31.57,
+	37.15,
+	42.57,
+	46.62,
+	51.34,
+	53.87,
+	62.68,
+	69.92,
+	75.13,
+	83.28,
+	91.68,
+	103.51,
+	118.80,
+	135.79,
+	150.10,
+	165.42,
+	170.92,
+	203.46,
+	228.00,
+	250.43,
+	262.01,
+	282.59,
+	260.34
+],
+[],
+[
+	8.20,
+	12.65,
+	16.71,
+	19.62,
+	23.39,
+	27.10,
+	29.95,
+	32.37,
+	35.12,
+	36.93,
+	42.34,
+	47.32,
+	52.36,
+	58.19,
+	63.41,
+	77.69,
+	89.77,
+	102.47,
+	110.61,
+	121.86,
+	127.50,
+	149.20,
+	166.13,
+	177.42,
+	189.34,
+	194.80,
+	175.06
+],
+[],
+[
+	7.07,
+	10.93,
+	13.15,
+	15.60,
+	18.06,
+	20.28,
+	22.50,
+	24.72,
+	26.60,
+	28.69,
+	32.38,
+	35.54,
+	38.46,
+	41.73,
+	44.89,
+	52.25,
+	59.34,
+	67.58,
+	74.58,
+	81.30,
+	87.50,
+	102.59,
+	115.85,
+	129.00,
+	142.15,
+	155.01,
+	147.99
+],
+[
+	7.78,
+	11.97,
+	14.76,
+	17.38,
+	19.99,
+	22.54,
+	24.96,
+	27.52,
+	29.58,
+	31.96,
+	35.90,
+	39.43,
+	42.70,
+	46.41,
+	49.94,
+	58.08,
+	65.96,
+	74.95,
+	82.66,
+	90.45,
+	97.37,
+	114.08,
+	128.78,
+	143.24,
+	157.81,
+	172.13,
+	161.95
+],
+[
+	4.45,
+	5.84,
+	6.85,
+	8.01,
+	9.13,
+	9.53,
+	10.64,
+	11.52,
+	12.92,
+	14.20,
+	16.08,
+	18.06,
+	20.41,
+	22.39,
+	24.26,
+	27.31,
+	29.75,
+	33.78,
+	36.82,
+	39.57,
+	42.38,
+	48.98,
+	54.78,
+	61.26,
+	67.58,
+	73.77,
+	66.52
+],
+[],
+[],
+[
+	16.98,
+	22.22,
+	28.43,
+	34.21,
+	40.16,
+	46.36,
+	51.48,
+	56.44,
+	61.15,
+	66.09,
+	74.66,
+	82.84,
+	90.64,
+	98.70,
+	107.74,
+	130.28,
+	151.50,
+	171.22,
+	189.82,
+	208.30,
+	220.92,
+	254.53,
+	283.62,
+	310.32,
+	329.62,
+	352.21,
+	323.77
+],
+[]
+],
+
+"baremoReexpedidion" : 10,
+
+"seguro" : 0.08,
+
+"descuento" : 0.2,
+
+"recargoCombustible" : 0.04
+}
+

+ 128 - 5
ourbiz/ourbiz-fltk.nut

@@ -324,12 +324,17 @@ class Fl_Data_Table extends Flv_Data_Table {
 	_cols_info = null;
 	_data = null;
 	_call_this = null;
+	_forPrint = null;
 
 	constructor(px, py, pw, ph, pl=null){
 		base.constructor(px, py, pw, ph, pl);
 		_cols_info = [];
 		_data = [];
+		_forPrint = false;
 	}
+	
+	function for_print(bval){_forPrint = bval; }
+	
 	function resize(ax, ay, aw, ah){
 		base.resize(ax, ay, aw, ah);
 		calc_cols();
@@ -343,6 +348,11 @@ class Fl_Data_Table extends Flv_Data_Table {
 		redraw();
 	}
 	
+	function set_data(data_array){
+		_data = data_array;
+		recalc_data();
+	}
+	
 	function get_data_value(arow, acol){ return _data[arow][acol];}
 	
 	function get_value(arow, acol){
@@ -378,12 +388,47 @@ class Fl_Data_Table extends Flv_Data_Table {
 			break;
 			case 'B': return (value == "1" ? "@-3+" : "");
 			break;
+			case 'S': return value.tostring();
+			break;
 			case '@': return value.replace("@", "@@"); //escape any @ 	{
 			break;
 		}
 		return value;
 	}
 	
+	function get_style(style, Row, Col){
+		base.get_style(style, Row, Col);
+		if(Row >= 0 && Col >= 0)
+		{
+		    local rs = row_style().get(Row);
+		    local cs = col_style().get(Col);
+		    local have_bg = 0;
+		    if(cs.background_defined()) have_bg = cs.background();
+		    else if(rs.background_defined()) have_bg = rs.background();
+
+		    if((Row % 2) == 0)
+		    {
+			if(have_bg)
+			    //s:background(fltk.fl_color_average(207, have_bg, 0.5))
+			    style.background(have_bg);
+			else
+			    style.background(207);
+		    }
+		    else
+		    {
+			if(have_bg)
+			    //s:background(have_bg)
+			    style.background(fl_color_average(FL_WHITE, have_bg, 0.5));
+			else
+			    style.background(FL_WHITE);
+		    }
+		}
+		else if(_forPrint)
+		{
+		    style.frame(FL_NO_BOX);
+		}
+	}
+	
 	function handle(event){
 		switch(event){
 			case FL_RELEASE:{
@@ -425,7 +470,7 @@ class Fl_Data_Table extends Flv_Data_Table {
 		return rc;
 	}
 	function row_selected(ev){ if(_call_this) _call_this.row_selected(ev);}
-	function set_cols(mycols){
+	function set_cols(mycols, size_absolute=false){
 		_cols_info.clear();
 		for(local i=0, max_cols=mycols.size(); i < max_cols; ++i){
 		    local col_info = {};
@@ -433,7 +478,7 @@ class Fl_Data_Table extends Flv_Data_Table {
 		    _cols_info.push(col_info);
 		}
 		cols(_cols_info.size());
-		calc_cols();
+		calc_cols(size_absolute);
 	}
 	function parse_field_header(str, col_info){
 		local ci = str.split('|');
@@ -447,8 +492,8 @@ class Fl_Data_Table extends Flv_Data_Table {
 		col_info.color <- (ci_size > curr_ci++) ? ci[curr_ci-1].tointeger() : 0;
 		col_info.bgcolor <- (ci_size > curr_ci++) ? ci[curr_ci-1].tointeger() : 0;
 	}
-	function calc_cols(){
-		calc_cols_width();
+	function calc_cols(size_absolute=false){
+		calc_cols_width(size_absolute);
 		for(local k=0, len = cols(); k < len; ++k)
 		{
 		    local v = _cols_info[k];
@@ -471,7 +516,15 @@ class Fl_Data_Table extends Flv_Data_Table {
 		    if(v.bgcolor) cs.background(v.bgcolor);
 		}
 	}
-	function calc_cols_width(){
+	function calc_cols_width(size_absolute=false){
+		if(size_absolute){
+			for(local k=0, len = cols(); k < len; ++k)
+			{
+			    local cs = col_style().get(k);
+			    cs.width(_cols_info[k].width);
+			}
+			return;
+		}
 		local grid_width, total_widths, char_width;
 		grid_width = w();
 		if(has_scrollbar()) grid_width -= scrollbar_width();
@@ -512,11 +565,43 @@ class Fl_Data_Table extends Flv_Data_Table {
 	}
 }
 
+class Fl_Data_Table_Calendar extends Fl_Data_Table {
+
+	constructor(px, py, pw, ph, pl=null){
+		base.constructor(px, py, pw, ph, pl);
+	}
+	function get_style(style, R, C )
+	{
+		base.get_style(style, R, C);
+		if (R >= 0)
+		{
+		    local zebra = false;
+
+		    if ((R % 2) == 0)
+		    {
+			if ((C % 2) == 0) zebra = true;
+		    }
+		    else if((C % 2) != 0) zebra = true;
+
+		    if (zebra) style.background(207);
+		    else style.background(FL_WHITE);
+
+		    if ((R == 0 && _data[0][C] > 7) ||
+			    (R > 3 && _data[R][C] < 20))
+			style.foreground(fl_color_average(FL_BLACK, FL_WHITE, 0.5));
+		    else style.foreground(FL_BLACK);
+		}
+	}
+}
+
+
 dofile("search-options.nut");
 dofile("utils-fltk.nut");
 dofile("help-view-gui.nut");
 dofile("help-view.nut");
 dofile("delivery-calc-gui.nut");
+dofile("calendar-gui.nut");
+dofile("calendar-utils.nut");
 dofile("base-report-A4.nut");
 dofile("invoice-A4.nut");
 dofile("edit-product-window.nut");
@@ -963,17 +1048,55 @@ class MyDeliveryCalcWindow extends DeliveryCalcWindow {
 	}
 }
 
+class MyCalendarWindow extends CalendarWindow {
+	_date = null;
+	_date_source = null;
+	_last_row = null;
+	_last_col = null;
+	static _week_days_abbr = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
+	
+	constructor(){
+		base.constructor();
+		grid->has_scrollbar( FLVS_AUTOMATIC );
+		local gs = grid.global_style();
+		gs->font_size(grid->labelsize());
+		gs->height(28);
+		gs->resizable(false);
+		grid->feature_remove(FLVF_ROW_SELECT);
+		local col_size = grid->w() / _week_days_abbr.len();
+		local cols_info = array(_week_days_abbr.len());
+		foreach(i, v in _week_days_abbr){
+			cols_info[i] = format("%s|%s|%d|R|S", v, v, col_size);
+		}
+		grid->set_cols(cols_info, true);
+		makemonth();
+	}
+	function makemonth(){
+		local tm = CalendarBase.makemonth(2013, 1);
+		grid->set_data(tm);
+	}
+	function cb_gui_destination_zone(sender, udata){
+		this = sender->window();
+	}	
+}
+
 class MyEditOrderWindow extends EditOrderWindow {
 	constructor(){
 		base.constructor();
 		_main_table = "orders";
 		btnCalcDelivery.callback(cb_btnCalcDelivery);
+		btnShowCalendar.callback(cb_btnShowCalendar);
 	}
 	function cb_btnCalcDelivery(sender, udata){
 		this = sender->window();
 		local dc = getChildWindow("Delivery Calc", MyDeliveryCalcWindow);
 		dc.show();
 	}
+	function cb_btnShowCalendar(sender, udata){
+		this = sender->window();
+		local dc = getChildWindow("Calendar", MyCalendarWindow);
+		dc.show();
+	}
 }
 
 class OrdersListSearch extends MyListSearchWindow {