[INTERPRETER]

* NEW: _ready() is new special method that is called when an object construction is completly finished.

[COMPILER]
* NEW: Remove the call to _load() method in form constructors.

[GB.WEB.FORM]
* BUG: WebExpander: Remove a debugging message.
* NEW: WebForm.Debug is a new static property that, if set, dumps all exchanges between the server and the client in the browser console.
* NEW: Use the new _ready special method.
* NEW: WebLabel: Add the Border property.
* NEW: WebLabel: Alignment is a new property that defines the label horizontal alignment.
* NEW: A few changes in default style sheet.


git-svn-id: svn://localhost/gambas/trunk@7541 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2015-12-30 18:11:01 +00:00
parent 7b734661d7
commit a6f458e05c
16 changed files with 174 additions and 73 deletions

View file

@ -769,6 +769,10 @@ _DefaultEvent
C
s
"Open"
Debug
P
b
_InExec
V
i
@ -825,7 +829,7 @@ _AddJavascript
M
(sStr)s
_load
_ready
m
@ -928,7 +932,7 @@ C
_Properties
C
s
"*,Text,Border"
"*,Text,Alignment,Border"
_DrawWith
C
s
@ -941,10 +945,18 @@ Text
p
s
Alignment
p
i
_Render
m
_RenderStyleSheet
m
#WebMenu
WebContainer
C

View file

@ -1,6 +1,6 @@
# Gambas Project File 3.0
# Compiled with Gambas 3.8.90
Startup=Webform3
Startup=Webform2
UseHttpServer=1
Version=3.8.90
VersionFile=1

View file

@ -8,3 +8,18 @@ Public Sub Main()
End
Public Sub DumpSession()
Dim sKey As String
Debug Session.Id
If Session.Id Then
For Each sKey In Session.Keys
Debug sKey; ": "; JSON.Encode(Session[sKey])
Next
Endif
End

View file

@ -12,14 +12,13 @@ Public Sub _new()
Next
'WebTable1.Columns[3].Expand = True
WebTable1.Count = 250
WebTable1.Select(2, 3)
End
Public Sub WebForm_Open()
WebTable1.Count = 250
WebTable1.Select(2, 3)
End

View file

@ -91,7 +91,6 @@ End
Private Sub Border_Write(Value As Boolean)
Debug Value
$bBorder = Value
Me._SetProperty("Border", Value)

View file

@ -10,9 +10,12 @@ Public Const _HiddenControls As String = "WebControl,WebForm,WebWindow,Timer"
Public Const _Properties As String = "*,Title,Resizable"
Public Const _DefaultEvent As String = "Open"
Static Property Debug As Boolean
Static Public _InExec As Integer
Static Public _Current As WebForm
Static Private $bDebug As Boolean
Static Private $aJavascript As New String[]
Event Open
@ -103,6 +106,7 @@ Static Public Sub Main()
Endif
_Current = hForm
If sPath = "x" Then
hForm._Exec(JSON.Decode(Request["c"]))
Else
@ -126,11 +130,11 @@ Static Public Sub _AddJavascript(sStr As String)
End
Public Sub _load()
Public Sub _ready()
Me._InitProperties
_Loaded = True
End
Public Sub _BeforeRender()
@ -442,3 +446,16 @@ End
' If hWindow Then hWindow.Centered = True
'
' End
Static Private Function Debug_Read() As Boolean
Return $bDebug
End
Static Private Sub Debug_Write(Value As Boolean)
$bDebug = Value
_AddJavascript("gw.debug = " & JS(Value))
End

View file

@ -3,13 +3,15 @@
Export
Inherits WebControl
Public Const _Properties As String = "*,Text,Border"
Public Const _Properties As String = "*,Text,Alignment,Border"
Public Const _DrawWith As String = "Label"
Public Const _DefaultSize As String = "24,4"
Property Text As String
Property Alignment As Integer
Private $sText As String
Private $iAlign As Integer
Private Function Text_Read() As String
@ -30,3 +32,45 @@ Public Sub _Render()
Print Replace(Html($sText), "\n", "<br>");
End
Public Sub _RenderStyleSheet()
If $iAlign Then
Me._StartStyleSheet
Super._RenderStyleSheet()
Select Case $iAlign
Case Align.Left
Me._AddStyleSheet("justify-content:flex-start;")
Case Align.Right
Me._AddStyleSheet("justify-content:flex-end;")
Case Align.Center
Me._AddStyleSheet("justify-content:center;")
End Select
Me._EndStyleSheet
Else
Super._RenderStyleSheet
Endif
End
Private Function Alignment_Read() As Integer
Return $iAlign
End
Private Sub Alignment_Write(Value As Integer)
$iAlign = Value
Me._SetProperty("Alignment", Value)
End

View file

@ -1,4 +1,4 @@
Webform3
Webform2
0
0

View file

@ -34,13 +34,13 @@ P:first-child,UL:first-child,OL:first-child {
.gw-button {
padding: 0;
font: inherit;
padding: 0 0.25em;
/*min-height: 1rem;*/
}
.gw-button.gw-noborder {
border: solid 1px transparent;
background: none;
padding: 0;
}
.gw-button.gw-noborder:hover {
@ -476,12 +476,20 @@ P:first-child,UL:first-child,OL:first-child {
vertical-align: top;
}
.gw-table > DIV > TABLE > THEAD > TR > TH:last-child {
border-right: none;
}
.gw-table > DIV > TABLE > TBODY > TR > TD {
border-right: solid 1px #C0C0C0;
padding: 0.25em;
vertical-align: top;
}
.gw-table > DIV > TABLE > TBODY > TR > TD:last-child {
border-right: none;
}
.gw-table > DIV > TABLE > TBODY > TR:last-child > TD {
border-bottom: solid 1px #C0C0C0;
}

View file

@ -8,11 +8,18 @@ gw = {
timers: {},
windows: [],
form: '',
debug: false,
log: function(msg)
{
if (gw.debug)
console.log(msg);
},
send: function(command)
{
var xhr = new XMLHttpRequest();
console.log(command);
gw.log(command);
xhr.open('GET', $root + '/' + encodeURIComponent(gw.form) + '/x?c=' + encodeURIComponent(JSON.stringify(command)), true);
xhr.onreadystatechange = function() {
//console.log('state = ' + xhr.readyState + ' / status = ' + xhr.status);
@ -24,7 +31,9 @@ gw = {
else
gw.selection = undefined;
console.log(xhr.responseText);
if (gw.debug)
console.log(xhr.responseText);
eval(xhr.responseText);
if (gw.active)
@ -128,7 +137,7 @@ gw = {
{
document.addEventListener('mousemove', gw.window.onMove);
document.addEventListener('mouseup', gw.window.onUp);
console.log('document.addEventListener');
gw.log('document.addEventListener');
}
gw.windows.push(id);
@ -179,7 +188,7 @@ gw = {
if (gw.windows.length == 0)
{
console.log('document.removeEventListener');
gw.log('document.removeEventListener');
document.removeEventListener('mousemove', gw.window.onMove);
document.removeEventListener('mouseup', gw.window.onUp);
}

View file

@ -497,3 +497,4 @@ Private Function Size_Read() As Long
Return $iSize
End

View file

@ -502,7 +502,7 @@ void FORM_do(char *source, bool ctrl_public)
if (form_parent_level > 0)
goto _ERROR;
FORM_print("\n Try Me._load()\n");
//FORM_print("\n Try Me._load()\n");
FORM_print("\nEnd\n\n");
// Create or delete the action file if needed

View file

@ -1356,6 +1356,7 @@ void CLASS_search_special(CLASS *class)
class->special[SPEC_PROPERTY] = CLASS_get_symbol_index_kind(class, "_property", CD_METHOD, CD_STATIC_METHOD);
class->special[SPEC_COMPARE] = CLASS_get_symbol_index_kind(class, "_compare", CD_METHOD, 0);
class->special[SPEC_ATTACH] = CLASS_get_symbol_index_kind(class, "_attach", CD_METHOD, 0);
class->special[SPEC_READY] = CLASS_get_symbol_index_kind(class, "_ready", CD_METHOD, 0);
sym = CLASS_get_symbol_index_kind(class, "_@_convert", CD_CONSTANT, 0);
if (sym != NO_SYMBOL)

View file

@ -355,6 +355,7 @@ typedef
SPEC_PROPERTY,
SPEC_COMPARE,
SPEC_ATTACH,
SPEC_READY,
MAX_SPEC = 11
}
CLASS_SPECIAL;

View file

@ -1852,22 +1852,13 @@ void *EXEC_create_object(CLASS *class, int np, char *event)
OBJECT_lock(object, TRUE);
EXEC_special_inheritance(SPEC_NEW, class, object, np, TRUE);
OBJECT_lock(object, FALSE);
// SP--; /* class */
//
// SP->_object.class = class;
// SP->_object.object = object;
// SP++;
EXEC_special(SPEC_READY, class, object, 0, TRUE);
}
CATCH
{
// _free() methods should not be called, but we must
OBJECT_UNREF(object);
PROPAGATE();
// SP--; /* class */
// SP->type = T_NULL;
// SP++;
// PROPAGATE();
}
END_TRY
@ -1953,6 +1944,7 @@ void EXEC_new(void)
EVENT_leave_name(save);
SP--; /* class */
EXEC_special(SPEC_READY, class, object, 0, TRUE);
SP->_object.class = class;
SP->_object.object = object;

View file

@ -47,7 +47,7 @@ static OBJECT *_event_object_list = NULL;
char *OBJECT_where_am_i(const char *file, int line, const char *func)
{
static char buffer[256];
snprintf(buffer, sizeof(buffer), "[%s] %s:%d", file, func, line);
return buffer;
}
@ -56,7 +56,7 @@ char *OBJECT_where_am_i(const char *file, int line, const char *func)
void *OBJECT_new(CLASS *class, const char *name, OBJECT *parent)
{
OBJECT *object;
ALLOC_ZERO(&object, class->size);
object->class = class;
@ -91,11 +91,11 @@ static void dump_attach(char *title)
static void call_attach_special_method(CLASS *class, void *ob, void *parent, const char *name)
{
STACK_check(2);
SP->_object.class = OBJECT_class(parent);
SP->_object.object = parent;
PUSH();
if (name)
{
SP->type = T_CSTRING;
@ -108,7 +108,7 @@ static void call_attach_special_method(CLASS *class, void *ob, void *parent, con
SP->type = T_NULL;
}
SP++;
EXEC_special(SPEC_ATTACH, class, ob, 2, TRUE);
}
@ -153,7 +153,7 @@ void OBJECT_detach(OBJECT *ob)
// return;
// Do not free the observers there
remove_object(ob, ev);
//dump_attach("OBJECT_detach");
@ -164,16 +164,16 @@ void OBJECT_detach(OBJECT *ob)
if (parent)
{
ev->parent = NULL;
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
call_attach_special_method(class, ob, parent, NULL);
#if DEBUG_EVENT || DEBUG_REF
fprintf(stderr, "OBJECT_detach : Detach (%s %p) from (%s %p)\n",
ob->class->name, ob, parent->class->name, parent);
#endif
OBJECT_UNREF(parent);
}
}
}
static void remove_observers(OBJECT *ob)
@ -183,10 +183,10 @@ static void remove_observers(OBJECT *ob)
COBSERVER *obs, *next;
//fprintf(stderr, "Remove observers: %s %p\n", class->name, ob);
if (!class->is_observer && class->n_event == 0)
return;
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
obs = ev->observer;
ev->observer = NULL;
@ -198,9 +198,9 @@ static void remove_observers(OBJECT *ob)
fprintf(stderr, "Remove observer %p %d: %p: %p\n", obs, (int)obs->ob.ref, ob, obs->object);
#endif
OBJECT_UNREF(obs);
obs = next;
obs = next;
}
//ev->observer = NULL;
}
@ -208,13 +208,13 @@ void OBJECT_attach(OBJECT *ob, OBJECT *parent, const char *name)
{
CLASS *class = OBJECT_class(ob);
OBJECT_EVENT *ev;
if (!name)
return;
if (!class->is_observer && class->n_event == 0)
return;
OBJECT_detach(ob);
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
@ -233,7 +233,7 @@ void OBJECT_attach(OBJECT *ob, OBJECT *parent, const char *name)
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
call_attach_special_method(class, ob, parent, name);
//dump_attach("OBJECT_attach");
}
@ -256,9 +256,9 @@ void OBJECT_release_static(CLASS *class, CLASS_VAR *var, int nelt, char *data)
&&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT,
&&__STRING, &&__NEXT, &&__NEXT, &&__VARIANT, &&__ARRAY, &&__STRUCT, &&__NEXT, &&__OBJECT
};
CTYPE type;
while (nelt--)
{
#if TRACE_MEMORY
@ -268,23 +268,23 @@ void OBJECT_release_static(CLASS *class, CLASS_VAR *var, int nelt, char *data)
type = var->type;
goto *jump[type.id];
__STRING:
STRING_unref((char **)&data[var->pos]);
goto __NEXT;
__OBJECT:
OBJECT_UNREF(*((void **)&data[var->pos]));
goto __NEXT;
__VARIANT:
VARIANT_free((VARIANT *)&data[var->pos]);
goto __NEXT;
__ARRAY:
CARRAY_release_static(class, class->load->array[type.value], &data[var->pos]);
goto __NEXT;
__STRUCT:
{
CLASS *sclass = class->load->class_ref[type.value];
@ -307,7 +307,7 @@ static void release(CLASS *class, OBJECT *ob)
if (CLASS_is_native(class))
return;
if (ob == NULL)
{
var = class->load->stat;
@ -331,7 +331,7 @@ static void release(CLASS *class, OBJECT *ob)
var = class->load->dyn;
nelt = class->load->n_dyn;
}
OBJECT_release_static(class, var, nelt, data);
}
@ -349,7 +349,7 @@ void OBJECT_release(CLASS *class, OBJECT *ob)
remove_observers(ob);
ob->ref = 0;
}
release(class, ob);
if (ob)
@ -392,7 +392,7 @@ static void error_OBJECT_create(void)
void *OBJECT_create(CLASS *class, const char *name, void *parent, int nparam)
{
void *ob;
void *object;
void *save;
char *save_name;
@ -402,30 +402,32 @@ void *OBJECT_create(CLASS *class, const char *name, void *parent, int nparam)
save = _object;
save_name = _object_name;
ON_ERROR(error_OBJECT_create)
{
_object_name = EVENT_enter_name(name);
_object = ob = OBJECT_new(class, name, parent);
_object = object = OBJECT_new(class, name, parent);
if (OBJECT_set_pointer)
{
*OBJECT_set_pointer = ob;
OBJECT_ref(ob);
*OBJECT_set_pointer = object;
OBJECT_ref(object);
OBJECT_set_pointer = NULL;
}
OBJECT_lock(ob, TRUE);
EXEC_special_inheritance(SPEC_NEW, class, ob, nparam, TRUE);
OBJECT_lock(ob, FALSE);
OBJECT_lock(object, TRUE);
EXEC_special_inheritance(SPEC_NEW, class, object, nparam, TRUE);
OBJECT_lock(object, FALSE);
EXEC_special(SPEC_READY, class, object, 0, TRUE);
error_OBJECT_create();
}
END_ERROR
_object = save;
_object_name = save_name;
return ob;
return object;
}
@ -452,6 +454,7 @@ void *OBJECT_create_native(CLASS *class, VALUE *param)
break;
}
EXEC_special(SPEC_READY, OBJECT_class(object), object, 0, TRUE);
OBJECT_UNREF_KEEP(object);
return object;
}
@ -465,13 +468,13 @@ void OBJECT_lock(OBJECT *object, bool lock)
return;
class = object->class;
if (class->is_observer)
{
COBSERVER_lock((COBSERVER *)object, lock);
return;
}
if (class->n_event == 0)
return;
@ -492,10 +495,10 @@ bool OBJECT_is_locked(OBJECT *object)
return FALSE;
class = object->class;
if (class->is_observer)
return COBSERVER_is_locked((COBSERVER *)object);
if (class->n_event == 0)
return FALSE;
@ -506,10 +509,10 @@ bool OBJECT_is_locked(OBJECT *object)
OBJECT *OBJECT_parent(void *object)
{
CLASS *class = OBJECT_class(object);
if (!class->is_observer && class->n_event == 0)
return NULL;
//return ((OBJECT *)((intptr_t)OBJECT_event(object)->parent & ~1));
return OBJECT_event(object)->parent;
}
@ -518,7 +521,7 @@ OBJECT *OBJECT_parent(void *object)
OBJECT *OBJECT_active_parent(void *object)
{
OBJECT *parent = OBJECT_parent(object);
if (!parent || OBJECT_is_locked((OBJECT *)object) || OBJECT_is_locked(parent))
return NULL;