r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[View] discuss view related issues

Henrik
15-Nov-2005
[3176]
robert, what happens in the above code is that you replace the original 
feel functions with one ENGAGE function. that's why you loose normal 
field functionality
RobertDumond
15-Nov-2005
[3177]
is there an alternate way i should be doing this?
Henrik
15-Nov-2005
[3178x4]
you need to copy in the original feel from a generic field face into 
your new field along and then add your code to its existing engage 
function
it's a bit of a hassle...
try:

probe get in new-field/feel 'engage

that's the original code
that's the code you need to alter...
RobertDumond
15-Nov-2005
[3182]
thank you, i will try that
Henrik
15-Nov-2005
[3183x2]
you can copy it out into a separate function, which could be called 
ENGAGE-FUNC and make you alterations.


then you can initialize a normal field with a new ENGAGE function 
in your layout:

the-field: field with [feel/engage: :engage-func]
this will leave the remaining feel functions untouched
Geomol
15-Nov-2005
[3185x3]
Henrik, your choice problem. I think, you have to redefine choice. 
The problem is in the multi/text function. You can do it at layout 
time this way:

view layout/size [choice "1" "2" "3" with [multi/text: func [face 
blk] [if pick blk 1 [face/texts: copy blk]] text: "2"]] 400x400
It's better to make your own choice with your own multi/text function.
using styles for example.
Henrik
15-Nov-2005
[3188]
thanks, I'll give it a try...
Volker
15-Nov-2005
[3189]
http://polly.rebol.it/test/test/extend-engage.r
Graham
15-Nov-2005
[3190x3]
I want to save my draw commands to a text database field.
is this the only way

form compress mold data  ?
the question really is, is there a native way to compress blocks 
as a string value ( for saving into a text field )
Volker
15-Nov-2005
[3193]
by molding them
Graham
15-Nov-2005
[3194x2]
does molding save space though?
that's what I am doing above, molding and then using using compress
Volker
15-Nov-2005
[3196]
no, but then you have a string. then you can compress. then you can 
write/binary .
Graham
15-Nov-2005
[3197]
text field .. can't save as binary.
Volker
15-Nov-2005
[3198x2]
i overlooked text-field, only saw saving.
why do you want to do that, compressed in a field?
Graham
15-Nov-2005
[3200x2]
because the field is varchar(8192)
and data is being transmitted over tcp, so good to compress first
Volker
15-Nov-2005
[3202x2]
a sql-field, not a face-field?
you can use 'as-string instead of 'form. but i know no better way 
that "compress mold".
Graham
15-Nov-2005
[3204x2]
sql field
perhaps we native to compress rebol code and return as a string value, 
and not binary
Volker
15-Nov-2005
[3206]
you can convert a binary to a string in place, with 'as-string
Graham
15-Nov-2005
[3207]
I wonder if that will save okay though 


>> t: as-string compress mold [ font bold32 pen yellow red line-pattern 
5 5 line-width 2 ]

== {xœ‹NËÏ+QHÊÏI16R(HÍS¨LÍÉÉ/W(JMQÈÉÌKÕ-H,)I-ÊS0^EB°@yfJI†‚Q,^@\Z^T^T:^@^@^@}
Volker
15-Nov-2005
[3208]
with write/binary yes. dont know what the sql-protocol does.
Graham
15-Nov-2005
[3209x3]
>> t

== {xœ‹NËÏ+QHÊÏI16R(HÍS¨LÍÉÉ/W(JMQÈÉÌKÕ-H,)I-ÊS0^EB°@yfJI†‚Q,^@\Z^T^T:^@^@^@}

>> insert db-port [{update results set draw = (?) where rid = 174} 
t ]
>> insert db-port {select draw from results where rid = 174}
>> r: pick db-port 1

== [{xœ‹NËÏ+QHÊÏI16R(HÍS¨LÍÉÉ/W(JMQÈÉÌKÕ-H,)I-ÊS0^EB°@yfJI†‚Q,^@\Z^T^T:^@^@^@}]
>> decompress to-binary r/1
== {[font bold32 pen yellow red line-pattern 5 5 line-width 2]}
>>
seems to work ...
if you use the 'arrow command in Draw, everything else after that 
has an arrow on it. 
How to turn off arrows after that ?
Anton
15-Nov-2005
[3212x10]
Henrik, your advice is not exactly right: "robert, what happens in 
the above code is that you replace the original feel functions with 
one ENGAGE function. that's why you loose normal field functionality"

Robert has, in fact, only replaced the ENGAGE function in the feel. 
The FEEL keyword in the layout dialect actually MAKEs from the original 
feel, with the spec block you give. eg.

	feel [
		engage: func [...][...]
	]

actually causes something like:

	face/feel: make face/feel [
		engage: func [...][...]
	]


So the other functions which were in the original face/feel are also 
copied in the new feel, unmodified, eg. (DETECT, OVER, REDRAW).

Nevertheless, Robert does need to look at the original ENGAGE function.
Henrik, your second example actually does "damage" to the system.

You are modifying the default FEEL object that is MAKEd from every 
time FIELD styles are created by LAYOUT.
It's basically like the following example. Here we set the ENGAGE
function to NONE to disable user interaction to the field:

	view layout [
		field with [feel/engage: none] 
		field
	]


But the second field also does not respond to user activity, nor 
do fields created in new windows:

	view layout [field] ; <- this field also does not respond

It can be confusing.

You have to remember that the FEEL objects are shared by default, 
to save memory.
These two examples may look the same but they are not:


 layout [field feel [engage: none]] ; this one clones and modifies 
 the FEEL


 layout [field with [feel/engage: none]] ; this one modifies the original 
 FEEL


The LAYOUT dialect has a FEEL keyword, and that causes a MAKE of 
the feel (ie. it is cloned
before being modified by your spec block).

The LAYOUT dialect WITH keyword, however, gets you out of the LAYOUT 
dialect and back into "normal" rebol code, but also binding you inside 
the new face object (the field) that is being created by LAYOUT.

So the "feel" inside the LAYOUT spec block and the "feel" inside 
the WITH block are not the same.
Robert, towards a solution, we need to look in SYSTEM/VIEW/VID/VID-STYLES/FIELD/FEEL, 
eg, by doing this:

	print mold svv/vid-styles/field/feel


So the first attempt should look like this, just copying the code 
from the console:
view/new layout [
	the-field: field feel [

		;;;; 
		engage: func [face act event][
			switch act [
				down [

     either equal? face focal-face [unlight-text] [focus/no-show face]
					caret: offset-to-caret face event/offset
					show face
				]
				over [
					if not-equal? caret offset-to-caret face event/offset [
						if not highlight-start [highlight-start: caret]
						highlight-end: caret: offset-to-caret face event/offset
						show face
					]
				]
				key [
					edit-text face event get in face 'action
				]
			]
		]
		;;;;

	]
	new-field: field
]
focus the-field
do-events
Oh no! We get an error message! "edit-text has no value".
Where is EDIT-TEXT ? It is not defined in the global context.
If you go looking in the system you will eventually find it here:

	CTX-EDIT/EDIT-TEXT


What happened ? The original EDIT-TEXT word, as found in the FIELD/FEEL, 
is bound to CTX-EDIT 

(it's not found in the global context, open a new console and try 
it), but we only bound our new EDIT-TEXT 
word to a new function context (ie. our ENGAGE).


So how do we keep the original bindings of a function, when making 
a copy of it ?
SECOND gives you the body of a function.

	second get in svv/vid-styles/field/feel 'engage


We should COPY that, which keeps the bindings, then modify that copy. 
*Then* we can create the function:

	; copy the engage function body
	body: copy/deep second get in svv/vid-styles/field/feel 'engage

	; <-- modify the body here

	; make the new function
	engage: func [face act event] body

Let's test that to see which keys we want:
view/new layout [
	the-field: field feel [

		use [body at-key-block key-block][

			; copy the engage function body

   body: copy/deep second get in svv/vid-styles/field/feel 'engage


   ; modify the copy to move the block with the EDIT-TEXT word in it
			; to a new IF then-block
			at-key-block: next find select body [switch act] [key]
			key-block: at-key-block/1

   change/only at-key-block compose/only [probe event/key if true (key-block)]

			; make the new function
			engage: func [face act event] body

		]

	]
]
focus the-field
do-events
Now filter for the desired keys:
view/new layout [
	the-field: field feel [

		use [body at-key-block key-block][

			; copy the engage function body

   body: copy/deep second get in svv/vid-styles/field/feel 'engage


   ; modify the copy to move the block with the EDIT-TEXT word in it
			; to a new IF then-block
			at-key-block: next find select body [switch act] [key]
			key-block: at-key-block/1
			change/only at-key-block compose/only [
				if find "-0123456789.^H^-" event/key (key-block)
			]

			; make the new function
			engage: func [face act event] body

		]

	]
	new-field: field
]
focus the-field
do-events
Of course you can add more conditions to the filter, to only allow 
the minus sign at the beginning etc,
but I leave that to you. :)
Graham, if you have trouble, maybe convert to base 64 using ENBASE 
?
Graham
16-Nov-2005
[3222]
arrow 0x0 turns off arrows ..
DideC
16-Nov-2005
[3223x2]
Anton: or you can double bind your code block to ctx-text and system/view
view/new layout [
	the-field: field feel [
		engage: func [face act event] bind bind [
			switch act [
				down [

     either equal? face focal-face [unlight-text] [focus/no-show face]
					caret: offset-to-caret face event/offset
					show face
				]
				over [
					if not-equal? caret offset-to-caret face event/offset [
						if not highlight-start [highlight-start: caret]
						highlight-end: caret: offset-to-caret face event/offset
						show face
					]
				]
				key [
					edit-text face event get in face 'action
				]
			]
		] in ctx-text 'self in system/view 'self 
	]
	new-field: field
]
focus the-field
do-events
Volker
16-Nov-2005
[3225]
first question, is how can i get the first text field to accept mouse 
click events?
Use the original feel
can i update the position of the text curser in the number field

cursor is in system/view/caret. points to the text in your face, 
use series-functions to move cursor


recycling of feel: either dump and patch as shown here, or use traditional 
inheritance/super-call as shown in http://polly.rebol.it/test/test/extend-engage.r