Grum Report post Posted April 8, 2005 (edited) I've been thinking about this, and your fix is the correct way to do it, Cirion, and should be applied to drag and keypress handlers too. The problem is that the way the code is at the moment, it breaks the scrollbars, and possibly other stuff as well. The problem is that the widget code currently makes no distinction between updating the widget and the ("user defined") effect this has on the window (the callback). I have to think about how to resolve that, suggestions are welcome. Edited April 8, 2005 by Grum Share this post Link to post Share on other sites
Cirion Report post Posted April 8, 2005 Is it possible to use return value of the callbacks in a general way? example: 0 - no handling done in callback, safe to use window/widget structure 1 - callback handled the call, but data didnt change so still safe to do more processing 2 - callback handled this and changed data so stop any processing One thing i also noticed when i was testing notepad was that i couldnt find a way to put the popup window (add category) as topmost window. whatever i tried just made it be 'below' the notepad window. We need a way to specify ordering. or maybe even make a new flag in creation that makes window topmost. And yes i tried add a select_window() call but t didnt help. I didnt dvelve deeper into it though. Share this post Link to post Share on other sites
crusadingknight Report post Posted April 8, 2005 We need a way to specify ordering. or maybe even make a new flag in creation that makes window topmost. And yes i tried add a select_window() call but t didnt help. I didnt dvelve deeper into it though. That's pretty much what select_window() is supposed to do, though I can't figure out why it won't on the popup. Share this post Link to post Share on other sites
Grum Report post Posted April 9, 2005 The crash should be fixed now, thanks Cirion. I'll look into the select_window() Share this post Link to post Share on other sites
crusadingknight Report post Posted April 9, 2005 (edited) Quick Patch to open the NotePad with a key combo (LCTRL n): http://rootshell.be/~bremac/key_note.patch EDIT: Uh, any idea why it loads the same item twice? I end up with two PK Lists, one empty, etc... EDIT2: Yes, I am using most-up-to-date libxml2 Edited April 9, 2005 by crusadingknight Share this post Link to post Share on other sites
Cirion Report post Posted April 9, 2005 I have been trying to figure out why the popup_window not getting topmost and while banging my head against it i rewrote the display_windows() function to use qsort to sort the windows in order to be drawn, instead of the big loops: // qsort function, sorts in ascending order int window_info_compare(const void *p1, const void *p2) { window_info *w1 = *(window_info**)p1; window_info *w2 = *(window_info**)p2; return (w1->order - w2->order); } // new version of display_windows using qsort // NOTE: I have no idea what level is supposed to be doing, it wasnt used // for any noticeable purpose void display_windows(int level) { int i; window_info **wi = NULL; // temp buffer for window info to be sorted wi = calloc(windows_list.num_windows, sizeof(window_info*)); // init temp data for(i=0; i<windows_list.num_windows; i++) wi[i] = &windows_list.window[i]; // qsort them qsort(wi, windows_list.num_windows, sizeof(window_info*), window_info_compare); windows_list.display_level= level; glColor3f(1.0f, 1.0f, 1.0f); // draw everything, already sorted for(i=0; i<windows_list.num_windows; i++) { if (wi[i]->displayed > 0) display_window(wi[i]->window_id); } free(wi); } I have been trying to get the popup window topmost but it seems that the windows are not updated after they are created so it actually is topmost but not redrawn. hmmm strange thing this one, I will throw more random stuff at this and see what happens Share this post Link to post Share on other sites
Grum Report post Posted April 9, 2005 (edited) Quick Patch to open the NotePad with a key combo (LCTRL n):http://rootshell.be/~bremac/key_note.patch EDIT: Uh, any idea why it loads the same item twice? I end up with two PK Lists, one empty, etc... EDIT2: Yes, I am using most-up-to-date libxml2 With or without your last patch? I don't have that problem, but I didn't look at this patch yet. Do they also appear twice in the xml file? EDIT: patch looks good, that's probably not the problem. EDIT 2: applied with minor change (pressing Ctrl-n twice hides the window again) Edited April 9, 2005 by Grum Share this post Link to post Share on other sites
Grum Report post Posted April 9, 2005 Here's the problem: When you click in a window, it executes the window's click handler, then raises the window. In nearly all cases this is what you want, but in this particular case the click handler brings up another window. So the chain of events is: click in notepad -> execute notepad click handler -> open and raise popup window -> raise notepad window. I haven't found a clean solution to solve this yet. Share this post Link to post Share on other sites
Cirion Report post Posted April 9, 2005 OK I thought some more on this and I think this should work and probably also be the right way to do it: The popup window should be a child to notepad window, so I just made this simple change: in notepad.c:display_popup_win() the call to create_window was changed to: popup_win = create_window (win_prompt, notepad_win, 0, popup_x, popup_y, popup_x_len, popup_y_len, ELW_WIN_DEFAULT); Share this post Link to post Share on other sites
Cirion Report post Posted April 9, 2005 About my qsort() version of display_windows(), I noticed the function is sort of timecritical so the question is if the original double loop is faster. There shouldnt be a need to reallocate the space for the array of window_info pointers, but since i dont know if its worth the trouble to change it to become slower I will just let it be at that. It just looked messy when i looked at it earlier, but probably for a good reason Share this post Link to post Share on other sites
crusadingknight Report post Posted April 10, 2005 (edited) The popup window should be a child to notepad window, so I just made this simple change: in notepad.c:display_popup_win() the call to create_window was changed to: popup_win = create_window (win_prompt, notepad_win, 0, popup_x, popup_y, popup_x_len, popup_y_len, ELW_WIN_DEFAULT); I'm afraid I don't think that's good solution, because, with that function call, we need to write new popup windows for every one we may ever need... that really increases code volume, and causes a lot of code duplication, and increase in executable size. Edited April 10, 2005 by crusadingknight Share this post Link to post Share on other sites
Cirion Report post Posted April 10, 2005 (edited) ok that makes sense, but it also should be possible to set the parent of any popup window, normally they belong to some other window. Maybe add a parent window parameter? Today when it is not a child window you can do this: - open notepad - click add category - close the notepad and you have the popup window up but no notepad EDIT: btw you know that int notepadAddCategory() is called like this: widget->OnClick (widget_list *widget, int mx, int my, Uint32 flags)? If we fix the notepadAddCategory params, cant a parent be extracted from first param and used in display_popup_win()? Edited April 10, 2005 by Cirion Share this post Link to post Share on other sites
Wytter Report post Posted April 10, 2005 Well, you'd still be able to use the same handlers so I think that the code duplication problems are minor... It really wouldn't cause too many problems compared to how often we'd be using a popup window... Share this post Link to post Share on other sites
Grum Report post Posted April 10, 2005 Why not just pass the parent window as a parameter to display_popup_win()? Share this post Link to post Share on other sites
Cirion Report post Posted April 10, 2005 Fix: notepad.h, new prototype void display_popup_win (int parent_win, char* label, int maxlen); notepad.c, function params + call to create_window: void display_popup_win (int parent_win, char* label, int maxlen) popup_win = create_window (win_prompt, parent_win, 0, popup_x, popup_y, popup_x_len, popup_y_len, ELW_WIN_DEFAULT); notepad.c, replace function int notepadAddCategory(widget_list *widget, int mx, int my, Uint32 flags) { display_popup_win (notepad_win, label_note_name, 16); return 1; } Share this post Link to post Share on other sites
Cirion Report post Posted April 10, 2005 How would this work for expansion on text buffer: I did it for put_char_in_buffer() only but should be added to the other put_xxxx_in_buffer functions if its usable. int grow_text_message(text_message *buf) { Uint8 *old_data = buf->data; if (buf->size + MAX_TEXT_MESSAGE_LENGTH >= MAX_DISPLAY_TEXT_BUFFER_LENGTH) { // dont grow over max limit return 0; } buf->size += MAX_TEXT_MESSAGE_LENGTH; buf->data = (Uint8*)calloc(buf->size, sizeof(Uint8)); if (buf->len) my_strncp(buf->data, old_data, buf->len); buf->data[buf->len] = '\0'; // just for safety free(old_data); // we were able to grow buffer so tell caller so return 1; } using this changes put_char_in_buffer() to this: int put_char_in_buffer (text_message *buf, Uint8 ch, int pos) { int i, nlen; // if (pos < 0 || pos > buf->len) return 0; if (pos < 0) return 0; if (pos >= buf->size) { // we need make buffer bigger if (grow_text_message(buf) == 0) return 0; } // First shift everything after pos to the right nlen = buf->len + 1; if (nlen >= buf->size) nlen = buf->size - 1; buf->data[nlen] = '\0'; for (i = nlen - 1; i > pos; i--) buf->data[i] = buf->data[i-1]; // insert the new character, and update the length buf->data[pos] = ch; buf->len = nlen; return 1; } Share this post Link to post Share on other sites
Grum Report post Posted April 10, 2005 I made the popup window a child of the main tab. Then it still didn't work because the window selection only went one level deep for raising children, so I rewrote that too. The window ordering should now be fixed. Share this post Link to post Share on other sites
LabRat Report post Posted May 5, 2005 (edited) **moved to bugs forum** Edited May 5, 2005 by ArmageddonQ Share this post Link to post Share on other sites