ソースを参照

Added a module to markdown using the discount lib https://github.com/Orc/discount
More methods added to FLTK module and code fixes.

mingodad 13 年 前
コミット
867cc8867d
5 ファイル変更221 行追加25 行削除
  1. 83 12
      ext/sq_fltk.cpp
  2. 41 0
      ext/sq_markdown.cpp
  3. 18 13
      ourbiz/help-view.nut
  4. 76 0
      ourbiz/help.txt
  5. 3 0
      squilu.cbp

+ 83 - 12
ext/sq_fltk.cpp

@@ -700,6 +700,8 @@ static SQInteger _Fl_Widget_handle(HSQUIRRELVM v)
 	return 1;
 }
 
+FL_WIDGET_VOID_CALL(activate);
+FL_WIDGET_VOID_CALL(deactivate);
 FL_WIDGET_VOID_CALL(redraw);
 FL_WIDGET_VOID_CALL(redraw_label);
 FL_WIDGET_VOID_CALL(hide);
@@ -729,6 +731,8 @@ CHEAP_RTTI_FOR(Fl_Widget);
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Fl_Widget_##name,nparams,pmask,isStatic}
 static SQRegFunction fl_widget_obj_funcs[]={
     CHEAP_RTTI_REG_FUN_FOR(Fl_Widget)
+	_DECL_FUNC(activate,1,_SC("x"), SQFalse),
+	_DECL_FUNC(deactivate,1,_SC("x"), SQFalse),
 	_DECL_FUNC(align,-1,_SC("xi"), SQFalse),
 	_DECL_FUNC(argument,-1,_SC("xi"), SQFalse),
 	_DECL_FUNC(box,-1,_SC("xi"), SQFalse),
@@ -1572,8 +1576,7 @@ static SQRESULT _Flv_Style_List_get(HSQUIRRELVM v){
     SQ_FUNC_VARS_NO_TOP(v);
     SETUP_FLV_STYLE_LIST(v);
     SQ_GET_INTEGER(v, 2, idx);
-    fltk_pushinstance(v, FLTK_TAG(Flv_Style), &self->get(idx));
-    return 1;
+    return fltk_pushinstance(v, FLTK_TAG(Flv_Style), &self->get(idx));
 }
 
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Flv_Style_List_##name,nparams,pmask,isStatic}
@@ -1602,15 +1605,13 @@ FLV_LIST_GETSET_INT(callback_when);
 static SQRESULT _Flv_List_global_style(HSQUIRRELVM v){
     SQ_FUNC_VARS_NO_TOP(v);
     SETUP_FLV_LIST(v);
-    fltk_pushinstance(v, FLTK_TAG(Flv_Style), &self->global_style);
-    return 1;
+    return fltk_pushinstance(v, FLTK_TAG(Flv_Style), &self->global_style);
 }
 
 static SQRESULT _Flv_List_row_style(HSQUIRRELVM v){
     SQ_FUNC_VARS_NO_TOP(v);
     SETUP_FLV_LIST(v);
-    fltk_pushinstance(v, FLTK_TAG(Flv_Style_List), &self->row_style);
-    return 1;
+    return fltk_pushinstance(v, FLTK_TAG(Flv_Style_List), &self->row_style);
 }
 
 static SQRESULT _Flv_List_add_callback_when(HSQUIRRELVM v){
@@ -1661,9 +1662,9 @@ FLV_TABLE_GETSET_INT(col);
 static SQRESULT _Flv_Table_col_style(HSQUIRRELVM v){
     SQ_FUNC_VARS_NO_TOP(v);
     SETUP_FLV_TABLE(v);
-    fltk_pushinstance(v, FLTK_TAG(Flv_Style_List), &self->col_style);
-    return 1;
-}
+    return fltk_pushinstance(v, FLTK_TAG(Flv_Style_List), &self->col_style);
+}
+
 CHEAP_RTTI_FOR(Flv_Table);
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Flv_Table_##name,nparams,pmask,isStatic}
 static SQRegFunction flv_table_obj_funcs[]={
@@ -2264,6 +2265,31 @@ static SQInteger _Fl_Text_Buffer_input_file_was_transcoded(HSQUIRRELVM v)
     sq_pushinteger(v, self->input_file_was_transcoded);
 	return 1;
 }
+
+//int search_forward(int startPos, const char* searchString, int* foundPos, int matchCase = 0) const;
+static SQInteger _Fl_Text_Buffer_search_forward(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS(v);
+    SETUP_FL_TEXT_BUFFER(v);
+    SQ_GET_INTEGER(v, 2, startPos);
+    SQ_GET_STRING(v, 3, searchStr);
+    SQ_OPT_BOOL(v, 4, matchCase, SQFalse);
+    int foundPos = -1;
+    _rc_ = self->search_forward(startPos, searchStr, &foundPos, matchCase);
+    sq_pushinteger(v, _rc_ ? foundPos : -1);
+	return 1;
+}
+
+//void select(int start, int end);
+static SQInteger _Fl_Text_Buffer_select(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS(v);
+    SETUP_FL_TEXT_BUFFER(v);
+    SQ_GET_INTEGER(v, 2, start);
+    SQ_GET_INTEGER(v, 3, end);
+    self->select(start, end);
+    return 0;
+}
 
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Fl_Text_Buffer_##name,nparams,pmask,isStatic}
 static SQRegFunction fl_text_buffer_obj_funcs[]={
@@ -2272,6 +2298,8 @@ static SQRegFunction fl_text_buffer_obj_funcs[]={
 	_DECL_FUNC(length,-1,_SC("xii"),SQFalse),
 	_DECL_FUNC(loadfile,-2,_SC("xsi"),SQFalse),
 	_DECL_FUNC(input_file_was_transcoded,1,_SC("x"),SQFalse),
+	_DECL_FUNC(search_forward,-3,_SC("xisi"),SQFalse),
+	_DECL_FUNC(select, 3,_SC("xii"),SQFalse),
 	{0,0}
 };
 #undef _DECL_FUNC
@@ -2309,6 +2337,27 @@ static SQInteger _Fl_Text_Display_wrap_mode(HSQUIRRELVM v)
     self->wrap_mode(wrap, wrap_margin);
 	return 0;
 }
+
+static SQInteger _Fl_Text_Display_insert_position(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS(v);
+    SETUP_FL_TEXT_DISPLAY(v);
+    if(_top_ > 1){
+        SQ_GET_INTEGER(v, 2, pos);
+        self->insert_position(pos);
+        return 0;
+    }
+    sq_pushinteger(v, self->insert_position());
+    return 1;
+}
+
+static SQInteger _Fl_Text_Display_show_insert_position(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS(v);
+    SETUP_FL_TEXT_DISPLAY(v);
+    self->show_insert_position();
+    return 0;
+}
 
 CHEAP_RTTI_FOR(Fl_Text_Display);
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Fl_Text_Display_##name,nparams,pmask,isStatic}
@@ -2318,6 +2367,8 @@ static SQRegFunction fl_text_display_obj_funcs[]={
 	_DECL_FUNC(buffer,-1,_SC("xx"),SQFalse),
 	_DECL_FUNC(highlight_data, 7,_SC("xxaiic."),SQFalse),
 	_DECL_FUNC(wrap_mode, 3,_SC("xii"),SQFalse),
+	_DECL_FUNC(insert_position,-1,_SC("xi"),SQFalse),
+	_DECL_FUNC(show_insert_position,1,_SC("x"),SQFalse),
 	{0,0}
 };
 #undef _DECL_FUNC
@@ -2360,6 +2411,7 @@ static SQRegFunction fl_text_editor_buffered_obj_funcs[]={
 
 FLTK_CONSTRUCTOR(Fl_Help_View);
 #define SETUP_FL_HELP_VIEW(v) SETUP_FL_KLASS(v, Fl_Help_View)
+#define SETUP_FL_HELP_VIEW_GETSET_INT_CAST(funcNAME, typeNAME) FUNC_GETSET_INT(_Fl_Help_View_, SETUP_FL_HELP_VIEW, self->, funcNAME, typeNAME)
 
 static SQInteger _Fl_Help_View_value(HSQUIRRELVM v)
 {
@@ -2417,10 +2469,11 @@ static const char *help_func_hook(Fl_Widget *sender, const char *uri, const char
     HSQUIRRELVM v = (HSQUIRRELVM) Fl::user_data;
     //sq_reservestack(v, 20);
     SQInteger top = sq_gettop(v);
-    if(fltk_pushinstance(v, FLTK_TAG(Fl_Help_View), sender) == SQ_OK){
+    if(fltk_pushinstance(v, FLTK_TAG(Fl_Help_View), sender)){
         sq_pushstring(v, Fl_Help_View_Links, -1);
         if(sq_getonregistrytable(v) == SQ_OK){
-            sq_push(v, -2); //Fl_Help_View instance
+            //sq_push(v, -2); //Fl_Help_View instance
+            sq_pushuserpointer(v, sender); //Fl_Help_View instance
             if(sq_get(v, -2) == SQ_OK){
                 sq_pushroottable(v);
                 sq_push(v, -4); //Fl_Help_View instance
@@ -2450,11 +2503,17 @@ static SQInteger _Fl_Help_View_link(HSQUIRRELVM v)
         sq_push(v, -2);
         sq_setonregistrytable(v);
     }
-    sq_weakref(v, 1);
+    //sq_weakref(v, 1);
+    //come back here release closure needed ???
+    sq_pushuserpointer(v, self);
     sq_push(v, 2);
     sq_rawset(v, -3);
 	return 0;
 }
+
+SETUP_FL_HELP_VIEW_GETSET_INT_CAST(textcolor, Fl_Color);
+SETUP_FL_HELP_VIEW_GETSET_INT_CAST(textfont, int);
+SETUP_FL_HELP_VIEW_GETSET_INT_CAST(textsize, int);
 
 CHEAP_RTTI_FOR(Fl_Help_View);
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_Fl_Help_View_##name,nparams,pmask,isStatic}
@@ -2466,6 +2525,9 @@ static SQRegFunction fl_help_view_obj_funcs[]={
 	_DECL_FUNC(topline, -1,_SC("x s|i"),SQFalse),
 	_DECL_FUNC(find, -1,_SC("x s|i"),SQFalse),
 	_DECL_FUNC(link, 2,_SC("x c|o"),SQFalse),
+	_DECL_FUNC(textcolor,-1,_SC("xi"),SQFalse),
+	_DECL_FUNC(textfont,-1,_SC("xi"),SQFalse),
+	_DECL_FUNC(textsize,-1,_SC("xi"),SQFalse),
 	{0,0}
 };
 #undef _DECL_FUNC
@@ -3162,6 +3224,14 @@ static SQRegFunction fl_obj_funcs[]={
 #undef _DECL_FUNC
 
 
+static SQInteger _fl_globals_fl_alert(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS_NO_TOP(v);
+    SQ_GET_STRING(v, 2, msg);
+    fl_alert(msg);
+    return 0;
+}
+
 static SQInteger _fl_globals_fl_font(HSQUIRRELVM v)
 {
     SQ_FUNC_VARS(v);
@@ -3450,6 +3520,7 @@ static SQInteger _fl_globals_fl_preferences(HSQUIRRELVM v)
 
 #define _DECL_FUNC(name,nparams,pmask,isStatic) {_SC(#name),_fl_globals_##name,nparams,pmask,isStatic}
 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_draw,-4,_SC(". n|s n|s nnn"),SQTrue),

+ 41 - 0
ext/sq_markdown.cpp

@@ -0,0 +1,41 @@
+
+#include "squirrel.h"
+#include <string.h>
+#include <stdio.h>
+#include "sqstdblobimpl.h"
+extern "C" {
+#include "markdown.h"
+}
+
+static void mywrite(char const *s,int len,void *blob)
+{
+	SQBlob *b= (SQBlob*)blob;
+	b->Write(s,len);
+}
+
+static SQRESULT sq_markdown2html(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS(v);
+    SQ_GET_STRING(v, 2, str);
+    SQ_OPT_INTEGER(v, 3, len, str_size);
+    if(len > str_size || len < 0) return sq_throwerror(v, _SC("invalid parameter value (%d)"), len);
+    SQBlob b(0, 8192);
+    markdown_str(mkd_string(str, len, 0), &b ,mywrite, 0);
+    sq_pushstring(v, (SQChar*)b.GetBuf(), b.Len());
+    return 1;
+}
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SQRESULT sqext_register_markdown(HSQUIRRELVM v)
+{
+    sq_insertfunc(v, _SC("markdown2html"), sq_markdown2html, -2, _SC(".si"), SQTrue);
+    return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif

+ 18 - 13
ourbiz/help-view.nut

@@ -9,6 +9,7 @@ class OurHelpWindow extends HelpWindow
 		base.constructor();
 		_help_file_name = "help.txt";
 		_last_found_pos = 0;
+		_navigation = [];
 		help_text->wrap_mode(1, 0);
 		view_html->textsize(view_html->labelsize());
 		view_html->link(hlp_link);
@@ -34,9 +35,7 @@ class OurHelpWindow extends HelpWindow
 	}
 
 	function refresh_html() {
-		local html;
-		markdown2html(help_text->buffer()->text(),
-			      help_text->buffer()->length(), html);
+		local html = markdown2html(help_text->buffer()->text(), help_text->buffer()->length());
 		view_html->value(html);
 		//printf(html.c_str());
 	}
@@ -68,7 +67,7 @@ class OurHelpWindow extends HelpWindow
 			words_to_search->clear_changed2();
 		}
 
-		local foundPos = 0;
+		local foundPos = -1;
 
 		if(tabs->value() == tabView){
 			foundPos = view_html->find(topic, _last_found_pos);
@@ -77,8 +76,8 @@ class OurHelpWindow extends HelpWindow
 		}
 		else
 		{
-			if(help_text->buffer()->search_forward(_last_found_pos, topic, foundPos)){
-				help_text->buffer()->select(foundPos, foundPos+strlen(topic));
+			if((foundPos = help_text->buffer()->search_forward(_last_found_pos, topic)) >= 0){
+				help_text->buffer()->select(foundPos, foundPos+topic.len());
 				help_text->insert_position(foundPos);
 				help_text->show_insert_position();
 				_last_found_pos = foundPos+1;
@@ -86,13 +85,18 @@ class OurHelpWindow extends HelpWindow
 			}
 		}
 
-		if(!foundPos){
+		if(foundPos < 0){
 			_last_found_pos = 0;
-			fl_alert(_tr("Nothing found for '%s' !"), topic);
+			fl_alert(format(_tr("Nothing found for '%s' !"), topic));
 		}
 	}
 
 	function on_font_size(sender, udata){
+		local pr = sender->window();
+		local view_html = pr->view_html;
+		local btnFontSmaller = pr->btnFontSmaller;
+		local btnFontBigger = pr->btnFontBigger;
+		
 		local fsize = view_html->textsize();
 		if(sender == btnFontSmaller){
 			if (fsize > 10){
@@ -116,14 +120,15 @@ class OurHelpWindow extends HelpWindow
 	}
 
 	function on_navigate(sender, udata){
-		if(sender == btnBackward && !_navigation.empty() )
+		local pr = sender->window();
+		if(sender == pr->btnBackward && !pr->_navigation.empty() )
 		{
-			view_html->topline(_navigation.top());
-			_navigation.pop();
+			pr->view_html->topline(pr->_navigation.top());
+			pr->_navigation.pop();
 		}
-		else if(sender == btnTop)
+		else if(sender == pr->btnTop)
 		{
-			view_html->topline(0);
+			pr->view_html->topline(0);
 		}
 	}
     

+ 76 - 0
ourbiz/help.txt

@@ -0,0 +1,76 @@
+Ourbiz 
+===
+Ourbiz is an excelent application to manage a small business, yet simple and powerfull !
+
+[Help](db:/help)
+---
+Help: using this screen you can consult any existing help topic and edit then to help you make a better use of this application.
+
+Terminology
+---
+Some terminology used on this application that will help you understand and use it better:
+
+- Entity : we call an entity any person/company that we have a commercial relation with.
+
+Tips
+-----
+On any tabular list you can use the keys CTRL+numeric(+) and CTRL+numeric(-) to increse or decrease the font size.
+
+Sales Products List/Search
+---
+On this screen we can navigate through all existing sales products with an easy to use search capability.
+
+Edit Products
+---
+When we need to edit an existing product or add a new one this form is the place to do it.
+
+Sales Entities List/Search
+---
+On this screen we can navigate through all existing sales entities with an easy to use search capability.
+
+Edit Entity
+---
+When we need to edit an existing entity or add a new one this form is the place to do it.
+
+Sales Orders List/Search
+---
+Here is where we register the sales transactions we do with entities and our products/services.
+
+Buys Orders List/Search
+---
+This is the same for the sales transactions but only applied to buy transactions.
+
+Edit Order / Sales Order Edit / Buy Order Edit
+---
+All transactions are registered on this screen.
+
+Delivery Calc
+---
+This is a complement to help calc delivery costs for an order.
+
+Calendar
+---
+To make easy to enter dates we use this screen.
+
+Auxiliar information
+====
+
+V.A.T. Rates List / Edit
+---
+The information about sales tax are here.
+
+Order Types List / Edit
+---
+All transactions availlable are described here with option to add new ones as needed.
+
+Images List / Edit
+---
+Images used though the application are centrally managed here.
+
+Product Groups List/Edit
+---
+To group our products for any purpose we create the groups here.
+
+Entity Groups List/Edit
+---
+Also to group our entities we create the groups here.

+ 3 - 0
squilu.cbp

@@ -143,6 +143,7 @@
 					<Add directory="../zeromq-3.2.2/include" />
 					<Add directory="../dadbiz++/third-party/fltk" />
 					<Add directory="../dadbiz++/third-party/flu" />
+					<Add directory="../dadbiz++/third-party/libharu/include" />
 				</Compiler>
 				<Linker>
 					<Add library="../zeromq-3.2.2/libzmq3.a" />
@@ -160,9 +161,11 @@
 					<Add library="Xft" />
 					<Add library="Xinerama" />
 					<Add library="mpdecimal" />
+					<Add library="hpdfs" />
 					<Add directory="../zeromq-3.2.2" />
 					<Add directory="../dadbiz++/third-party/fltk/lib" />
 					<Add directory="../dadbiz++/third-party/flu" />
+					<Add directory="../dadbiz++/third-party/libharu/src" />
 				</Linker>
 			</Target>
 		</Build>