GNOME Bugzilla – Bug 500358
display doesn't update after calling gtk_hex_set_data
Last modified: 2007-12-20 04:21:13 UTC
I'm trying to use the GtkHex widget with data from memory. When i call gtk_hex_set_data() to set some new data, I would expect the widget to update its display, however it doesn't seem to do so. I have to actually minimize and unminimize (force an expose event, I suppose) in order for the new data to show up. Also, after forcing the expose update, when you attempt to edit the hex data, the values don't always update until I update the entire the lower nibble (e.g. if I just change the upper nibble, it doesn't update its display). I'll attach a test program which displays the issue for me.
Created attachment 99829 [details] test program
I should note that the 'no update when only editing the upper nibble' problem doesn't seem to show up in ghex-the-application, only when I use the widget in my application.
Created attachment 99949 [details] [review] [PATCH] Redraw GtkHex widget when the HexDocument changes Connect to the HexDocument's document_changed signal and redraw the widget so that the display gets updated when modifying the data with hex_document_set_data(). Fix for bug #500358 --- ChangeLog | 7 +++++++ src/gtkhex.c | 19 ++++++++++++++++++- src/gtkhex.h | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-)
OK, after investigating this a little bit more, I think I know why the GHex application doesn't exhibit this problem but my example program does. I believe it is because the GHex application uses the function hex_document_add_view(), which creates a GtkHex widget and adds it to doc->views. By default, the HexDocument's 'document_changed' signal handler emits the 'data_changed' signal for all views in doc->views, and this then causes the view to redraw itself. However, if you create the GtkHex widget without using hex_document_add_view() (e.g. simply using gtk_hex_new(HexDocument*)), the GtkHex widget does not get added to doc->views. Because of this, it never noticies that the underlying document has changed, because it relies on the HexDocument object to emit the 'data_changed' signal for the view. It seems that if the view simply always connected to the document's 'document_changed' signal in the constructor (as I've done in the patch above), we wouldn't even need the list of views in HexDocument...
Based on your last comment it sounds like we might also want to remove the list of views in HexDocument. Can you test that and rework the patch to do that as well? Thanks.
Created attachment 100729 [details] [review] [PATCH] Redraw GtkHex widget when the HexDocument changes (Fix for bug #500358) Connect to the HexDocument's document_changed signal and redraw the widget so that the display gets updated when modifying the data with hex_document_set_data(). Since the GtkHex view is connecting to the 'document_changed' signal, we no longer have to rely on the HexDocument object to emit the 'data_changed' signal for each view in the gh->views list. --- ChangeLog | 7 +++++++ src/gtkhex.c | 19 ++++++++++++++++++- src/gtkhex.h | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-)
Here's an updated patch. It probably requires a little explanation -- In looking more closely at the code, it turns out that the list of views in HexDocument is still useful for the following situation: - There are multiple views of the same document open - the document has been changed - we only want to pop up a "close without saving?" dialog when they close the last view So I left the list of views in, but they no longer have anything to do with the data_changed/document_changed signal. That is now done exclusively by connecting to the signal in the GtkHex constructor.
Created attachment 100730 [details] [review] [PATCH] Redraw GtkHex widget when the HexDocument changes (Fix for bug #500358) Connect to the HexDocument's document_changed signal and redraw the widget so that the display gets updated when modifying the data with hex_document_set_data(). Since the GtkHex view is connecting to the 'document_changed' signal, we no longer have to rely on the HexDocument object to emit the 'data_changed' signal for each view in the gh->views list. --- ChangeLog | 7 +++++++ src/gtkhex.c | 19 ++++++++++++++++++- src/gtkhex.h | 2 +- src/hex-document.c | 8 -------- 4 files changed, 26 insertions(+), 10 deletions(-)
sorry for the noise, the first updated patch was incorrect -- marking obsolete
just fyi, I'm waiting for these changes to get into ghex svn so I can start committing the experimental memory editing stuff for nemiver.
Looks good. Please commit.
Thanks, committed in r1177