Re: Using "editable" tags in non-editable GtkTextView
- From: Jean Bréfort <jean brefort normalesup org>
- To: Juha Nieminen <warp cs tut fi>
- Cc: gtk-list gnome org
- Subject: Re: Using "editable" tags in non-editable GtkTextView
- Date: Thu, 11 Nov 2004 13:50:09 +0100
Le jeu 11/11/2004 à 13:31, Juha Nieminen a écrit :
> In an application I'm making I would like to have a GtkTextView with
> most of its text as non-editable (most of the text is generated
> automatically by other means than the user writing it).
> However, there are certain places here and there where the text should
> be editable by the user.
>
> The GtkTextTag seems perfect for this purpose: I can set the GtkTextView
> as non-editable and add proper GtkTextTags with the "editable" property
> set in the places I want the user to be able to edit.
>
> However, there's one big problem with this: The start tag has right
> gravity and the end tag has left gravity.
> This means that if the user edits the beginning or the end of the
> editable part, his text will end up as non-editable (because if he writes
> a character eg. at the beginning of the editable part, the start tag will
> end up at the right of this character and the written character will thus
> end up outside the tags and thus become non-editable).
> It also means that if the user completely deletes the text in the
> editable part, he will be completely unable to add any text there anymore
> (due to the gravity of the tags, if there's no text between them, it's
> impossible to add any text there).
>
> I can't find any way of defining the gravity of GtkTextTags (as you can
> do with GtkTextMarks).
> Any ideas?
> Perhaps what I want to achieve could be better done in a completely
> different way?
> The text is very dynamic so having fixed-sized field widgets is not
> an option. Also it should be possible for the user to write text which
> extends to several lines (ie. he should be able to type newlines as well)
> in the editable parts. The editable parts are not independent lines in
> the text but parts of existing non-editable lines.
>
> Doing the opposite, that is, marking all non-editable text with
> non-editable tags and leaving the editable parts untagged is not a
> viable solution. Due to how I generate the text it's very difficult
> to join uneditable parts so that they all end up inside the same pair
> of tags (if I wouldn't join them, the user would be able to add text
> between the tags in places I don't want to allow it). Also, doing it
> this way would allow the user to add text at the very beginning and end
> of the text buffer, which is not what I want.
>
> Btw, a second question: How do you set the default text properties
> (eg. font) of a GtkTextView?
> (I would want the non-editable parts to have a certain style, but I can't
> seem to find any way of setting this.)
AFAIK, you should use the GtkTextBuffer events to update the tags after
a user action. I had an analog problem in GChemPaint (I use a
GnomeCanvasRichText instead of a GtkTextView but it should not be very
different). Relevant code is in lib/text-object.cc and lib/text.cc. I
don't use all the available events, just those I needed. There might be
a better solution, but I could not find it.
GChemPaint project page is at
http://savannah.nongnu.org/projects/gchempaint
Regards,
Jean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]