Page 1 of 1

GET Class

Posted: Thu Mar 27, 2008 10:27 am
by xProgrammer
Hi Antonio

I want to try to fix a few aspects of the way GETs operate. Basically where the cursor goes and how selections are handled. I looked at the source code in get.prg and noticed the following

Code: Select all

METHOD GotFocus() CLASS TGet

   ::SetPos( 0 )
   ::SetSel( 0, 0 )

return nil
but I can't see ::SetPos() or ::SetSel() declared in TGet or TControl or TWindow. Have I just missed it or what?

Currently the cursor goes to the end of the text (including the blanks) and selections are ignored.

By the way do you call

Code: Select all

void                gtk_entry_set_max_length            (GtkEntry *entry,
                                                         gint max);
anywhere in your code? Do you set it based on the length of the variable in the associated GET? Do we in reality need an associated GET?

Thanks
Doug
(xProgrammer)

Posted: Fri Mar 28, 2008 10:28 am
by Antonio Linares
Doug,

Those methods are defined in the Class header as INLINE methods.

The reason to use a GET variable is to be able to use the Clipper (Harbour) formats of the GET when using PICTUREs.

Posted: Fri Mar 28, 2008 11:44 am
by xProgrammer
Hi Antonio

Thanks for your reply. I have been studying get.prg and I think I understand why blocked text is not being treated as such.

Look at the KeyDown( nKey ) method of class TGet.

Take a back space event as an example. The code calls the BackSpace() method of the associated GET object. This "moves the cursor to the left and deletes a character". But if the user has blocked a section of the text the whole section should be deleted.

A similar argument applies, I think, to your otherwise clause.

I think you need to add a HB_FUNC( GETGETSEL ) to gets.c based on gboolean gtk_editable_get_selection_bounds (GtkEditable *editable,
gint *start,
gint *end);
with a corresponding GetSel() method in your TGet class which could be called as part of the BackSpace and Otherwise clauses of the DO CASE in KeyDown( nKey ).

If I am right (and I quite possibly am totally wrong) that would fix one of my two problems with GETs as they currently operate.

Posted: Sat Mar 29, 2008 2:22 am
by xProgrammer
Hi Antonio

Another suggestion for a change that might improve the operation of the TGet Class.

The line:

Code: Select all

::SetText( If( ! ::lPassword, ::oGet:buffer, Replicate( "*", Len( AllTrim( ::oGet:buffer ) ) ) ) )
that occurs for both Back Space and Otherwise cases in the KeyDown( nKey ) method of class TGet might be better

Code: Select all

::SetText( If( ! ::lPassword, RTRIM(::oGet:buffer), Replicate( "*", Len( AllTrim( ::oGet:buffer ) ) ) ) )
Hopefully this might stop us from tabbing to the end of a GET past where the meaningful text is.

Regards
Doug
(xProgrammer)

Posted: Sat Mar 29, 2008 2:28 am
by xProgrammer
Hi Antonio

Is it possible for me to rebuild the ?library? from a modified c source (eg if I change gets.c) ? If so and you tell me how to do it, I can experiment with some of my suggestions and report back to you.

Regards
Doug
(xProgrammer)

Posted: Sat Mar 29, 2008 8:59 am
by Antonio Linares
Doug,

You can compile a C file this way:
gcc `pkg-config --cflags gtk+-2.0` -I./../harbour/include -I./include -Wall -c -o file.o file.c

And replace it in the library this way:
ar rc ./lib/libfivec.a file.o

Some Progress

Posted: Sun Mar 30, 2008 12:10 am
by xProgrammer
Hi Antonio

1. I modified the TGet class so that it applied RTrim to oGet:buffer in four places:

the new() method

the K_BS case of the KeyDown() method

the K_DEL case of the KeyDown() method

the otherwise case of the KeyDown() method

This significantly improves behaviour when tabbing into a GET. Now the cursor position on entering a GET via a tab is at the end of the non-blank text (which is OK).

2. Whilst the GotFocus() method of the TGet class is clearly called when the event fires, neither ::SetPos( 0 ) nor ::SetSel( 0, 0 ) are working because the cursor stays at the end of the (now non-blank) text and the selection is the whole of the (now non blank) text. Note that the selection is not effective because the TGet class doesn't take it into account at this stage.

We need to fix SetPos() and SetSel() before we fix the operation of selection which will require a GetSel() function.

Regards
Doug
(xProgrammer)