diff options
| author | Bill Spitzak <spitzak@gmail.com> | 1999-02-03 08:43:35 +0000 |
|---|---|---|
| committer | Bill Spitzak <spitzak@gmail.com> | 1999-02-03 08:43:35 +0000 |
| commit | 8009fef12cb88c5d4944bdad9a1e641c282df303 (patch) | |
| tree | 9c3cacadf5121dba5ee5ab42327ba6a9ab79402a /src | |
| parent | 0434a826d57f5de3ef258532cc090717db574d4e (diff) | |
Put Fl::grab() into it's own source file. Rewritten as suggested so that
it takes a window pointer, and grab(0) releases. You can now call grab
repeatedly with the same or different values without it failing. The old
Fl::grab() and Fl::release() are emulated in inline functions in Fl.H
Added Fl_Menu_::copy(Fl_Menu_Item*), which will be useful for fluid, although
that use is nyi.
Fixes and cleanup to the code for Fl_Menu_::add(...).
git-svn-id: file:///fltk/svn/fltk/trunk@268 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Menu_.cxx | 34 | ||||
| -rw-r--r-- | src/Fl_Menu_Window.cxx | 63 | ||||
| -rw-r--r-- | src/Fl_Menu_add.cxx | 120 | ||||
| -rw-r--r-- | src/Fl_grab.cxx | 93 | ||||
| -rw-r--r-- | src/Fl_win32.cxx | 6 | ||||
| -rw-r--r-- | src/Fl_x.cxx | 7 | ||||
| -rw-r--r-- | src/Makefile | 6 |
7 files changed, 197 insertions, 132 deletions
diff --git a/src/Fl_Menu_.cxx b/src/Fl_Menu_.cxx index 8441212a1..fd2f1bcd4 100644 --- a/src/Fl_Menu_.cxx +++ b/src/Fl_Menu_.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Menu_.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $" +// "$Id: Fl_Menu_.cxx,v 1.6 1999/02/03 08:43:32 bill Exp $" // // Common menu code for the Fast Light Tool Kit (FLTK). // @@ -32,9 +32,9 @@ #include <FL/Fl.H> #include <FL/Fl_Menu_.H> +#include <string.h> #include <stdlib.h> - int Fl_Menu_::value(const Fl_Menu_Item* m) { clear_changed(); if (value_ != m) {value_ = m; return 1;} @@ -105,15 +105,37 @@ int Fl_Menu_::size() const { } void Fl_Menu_::menu(const Fl_Menu_Item* m) { - // if (alloc) clear(); - alloc = 0; + clear(); value_ = menu_ = (Fl_Menu_Item*)m; } +void Fl_Menu_::copy(const Fl_Menu_Item* m, void* user_data) { + int n = m->size()+1; + Fl_Menu_Item* newMenu = new Fl_Menu_Item[n]; + memcpy(newMenu, m, n*sizeof(Fl_Menu_Item)); + menu(newMenu); + alloc = 1; // make destructor free it + // for convienence, provide way to change all the user data pointers: + if (user_data) for (; n--;) { + if (newMenu->callback_) newMenu->user_data_ = user_data; + newMenu++; + } +} + Fl_Menu_::~Fl_Menu_() { - // if (alloc) clear(); + clear(); +} + +void Fl_Menu_::clear() { + if (alloc) { + if (alloc>1) for (int i = size(); i--;) + if (menu_[i].text) free((void*)menu_[i].text); + delete[] menu_; + menu_ = 0; + alloc = 0; + } } // -// End of "$Id: Fl_Menu_.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $". +// End of "$Id: Fl_Menu_.cxx,v 1.6 1999/02/03 08:43:32 bill Exp $". // diff --git a/src/Fl_Menu_Window.cxx b/src/Fl_Menu_Window.cxx index ad4cdaf9e..16248115a 100644 --- a/src/Fl_Menu_Window.cxx +++ b/src/Fl_Menu_Window.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Menu_Window.cxx,v 1.7 1999/01/07 19:17:23 mike Exp $" +// "$Id: Fl_Menu_Window.cxx,v 1.8 1999/02/03 08:43:33 bill Exp $" // // Menu window code for the Fast Light Tool Kit (FLTK). // @@ -96,65 +96,6 @@ Fl_Menu_Window::~Fl_Menu_Window() { hide(); } -//////////////////////////////////////////////////////////////// -// "Grab" is done while menu systems are up. This has several effects: -// Events are all sent to the "grab window", which does not even -// have to be displayed (and in the case of Fl_Menu.C it isn't). -// Under X override_redirect and save_under is done to new windows. -// The system is also told to "grab" events and send them to this app. - -extern void fl_fix_focus(); - -#ifdef WIN32 -// We have to keep track of whether we have captured the mouse, since -// MSWindows shows little respect for this... Grep for fl_capture to -// see where and how this is used. -HWND fl_capture; -#endif - -void Fl::grab(Fl_Window& w) { - grab_ = &w; -#ifdef WIN32 - SetActiveWindow(fl_capture = fl_xid(first_window())); - SetCapture(fl_capture); -#else - XGrabPointer(fl_display, - fl_xid(first_window()), - 1, - ButtonPressMask|ButtonReleaseMask| - ButtonMotionMask|PointerMotionMask, - GrabModeAsync, - GrabModeAsync, - None, - 0, - fl_event_time); - XGrabKeyboard(fl_display, - fl_xid(first_window()), - 1, - GrabModeAsync, - GrabModeAsync, - fl_event_time); -#endif -} - -extern void fl_send_extra_move(); // in Fl.cxx - -void Fl::release() { - grab_ = 0; -#ifdef WIN32 - fl_capture = 0; - ReleaseCapture(); -#else - XUngrabKeyboard(fl_display, fl_event_time); - XUngrabPointer(fl_display, fl_event_time); - // this flush is done in case the picked menu item goes into - // an infinite loop, so we don't leave the X server locked up: - XFlush(fl_display); -#endif - fl_send_extra_move(); - return; -} - // -// End of "$Id: Fl_Menu_Window.cxx,v 1.7 1999/01/07 19:17:23 mike Exp $". +// End of "$Id: Fl_Menu_Window.cxx,v 1.8 1999/02/03 08:43:33 bill Exp $". // diff --git a/src/Fl_Menu_add.cxx b/src/Fl_Menu_add.cxx index cb6b91b4d..0b50ec3fd 100644 --- a/src/Fl_Menu_add.cxx +++ b/src/Fl_Menu_add.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Menu_add.cxx,v 1.6 1999/01/29 16:56:48 carl Exp $" +// "$Id: Fl_Menu_add.cxx,v 1.7 1999/02/03 08:43:33 bill Exp $" // // Menu utilities for the Fast Light Tool Kit (FLTK). // @@ -41,20 +41,44 @@ // always allocate this much initially: #define INITIAL_MENU_SIZE 15 -// as menu array size passes through each power of two, the memory -// array allocated is doubled in size: -static Fl_Menu_Item* incr_array(Fl_Menu_Item* array, int size) { - if (size < INITIAL_MENU_SIZE) return array; - if ((size+1) & size) return array; // not a power of 2 - Fl_Menu_Item* newarray = new Fl_Menu_Item[size*2+1]; - for (int i = 0; i <= size; i++) newarray[i] = array[i]; - delete[] array; - return newarray; -} - // if this local pointer is set, array is reallocated and put here: static Fl_Menu_Item** alloc; +// Insert a single Fl_Menu_Item into an array at offset n. If ::alloc +// is not zero, the array may be reallocated. This is done each time +// it's size passes through a power of 2. The new (or old) array is +// returned. +// Notice that size does not count the trailing null item, so one more +// item than you think must be copied. +static Fl_Menu_Item* insert( + Fl_Menu_Item* array, int size, + int n, + const char *text, + int flags) { + // If new size is a power of two, we reallocate to the next power + // of two: + if (alloc && size >= INITIAL_MENU_SIZE && !((size+1)&size)) { + Fl_Menu_Item* newarray = new Fl_Menu_Item[(size+1)*2]; + memcpy(newarray, array, (size+1)*sizeof(Fl_Menu_Item)); + delete[] array; + *alloc = array = newarray; + } + // move all the later items: + memmove(array+n+1, array+n, sizeof(Fl_Menu_Item)*(size-n+1)); + // create the new item: + Fl_Menu_Item* m = array+n; + m->text = text ? strdup(text) : 0; + m->shortcut_ = 0; + m->callback_ = 0; + m->user_data_ = 0; + m->flags = flags; + m->labeltype_ = m->labelfont_ = m->labelsize_ = m->labelcolor_ = 0; + return array; +} + +// Add an item. The text is split at '/' characters to automatically +// produce submenus (actually a totally unnecessary feature as you can +// now add submenu titles directly by setting SUBMENU in the flags): int Fl_Menu_Item::add( const char *text, int shortcut, @@ -85,27 +109,17 @@ int Fl_Menu_Item::add( /* find a matching menu title: */ for (; m->text; m = m->next()) - if (m->flags&FL_SUBMENU && !strcmp(item,m->text)) break; + if (m->flags&FL_SUBMENU && !strcmp(item, m->text)) break; if (!m->text) { /* create a new menu */ - if (alloc) { - int n = m-array; - array = incr_array(array,size); - array = incr_array(array,size+1); - *alloc = array; - m = array+n; - } - memmove(m+2,m,sizeof(Fl_Menu_Item)*(array+size-m)); - m->text = strdup(item); - m->shortcut_ = 0; - m->callback_ = 0; - m->user_data_ = 0; - m->flags = FL_SUBMENU|flags1; - m->labeltype_ = m->labelfont_ = m->labelsize_ = m->labelcolor_ = 0; - (m+1)->text = 0; - size += 2; + int n = m-array; + array = insert(array, size, n, item, FL_SUBMENU|flags1); + size++; + array = insert(array, size, n+1, 0, 0); + size++; + m = array+n; } - m++; /* go into the menu */ + m++; /* go into the submenu */ flags1 = 0; } @@ -114,22 +128,20 @@ int Fl_Menu_Item::add( if (!strcmp(m->text,item)) break; if (!m->text) { /* add a new menu item */ - if (alloc) { - int n = m-array; - *alloc = array = incr_array(array,size); - m = array+n; - } - memmove(m+1,m,sizeof(Fl_Menu_Item)*(array+size-m)); + int n = m-array; + array = insert(array, size, n, item, flags|flags1); size++; - m->text = strdup(item); + if (flags & FL_SUBMENU) { // add submenu delimiter + array = insert(array, size, n+1, 0, 0); + size++; + } + m = array+n; } /* fill it in */ m->shortcut_ = shortcut; m->callback_ = cb; m->user_data_ = data; - m->flags = flags|flags1; - m->labeltype_ = m->labelfont_ = m->labelsize_ = m->labelcolor_ = 0; return m-array; } @@ -137,8 +149,8 @@ int Fl_Menu_Item::add( int Fl_Menu_::add(const char *t, int s, Fl_Callback *c,void *v,int f) { int n = value_ ? value_ - menu_ : 0; if (!menu_) { - alloc = 1; - menu_ = new Fl_Menu_Item[INITIAL_MENU_SIZE]; + alloc = 2; // indicates that the strings can be freed + menu_ = new Fl_Menu_Item[INITIAL_MENU_SIZE+1]; menu_[0].text = 0; } if (alloc) ::alloc = &menu_; @@ -148,6 +160,8 @@ int Fl_Menu_::add(const char *t, int s, Fl_Callback *c,void *v,int f) { return r; } +// This is a Forms (and SGI GL library) compatable add function, it +// adds strings of the form "name\tshortcut|name\tshortcut|..." int Fl_Menu_::add(const char *str) { char buf[128]; int r = 0; @@ -167,30 +181,20 @@ int Fl_Menu_::add(const char *str) { void Fl_Menu_::replace(int i, const char *str) { if (i<0 || i>=size()) return; - if (alloc) free((void *)menu_[i].text); - menu_[i].text = strdup(str); + if (alloc > 1) { + free((void *)menu_[i].text); + str = strdup(str); + } + menu_[i].text = str; } void Fl_Menu_::remove(int i) { int n = size(); if (i<0 || i>=n) return; - if (alloc) free((void *)menu_[i].text); + if (alloc > 1) free((void *)menu_[i].text); memmove(&menu_[i],&menu_[i+1],(n-i)*sizeof(Fl_Menu_Item)); } -void Fl_Menu_::clear() { - for (int i = size(); i--;) - if (menu_[i].text) free((void*)menu_[i].text); - if (alloc) { - delete[] menu_; - menu_ = 0; - alloc = 0; - } else if (menu_) { - menu_[0].text = 0; - value_ = menu_; - } -} - // -// End of "$Id: Fl_Menu_add.cxx,v 1.6 1999/01/29 16:56:48 carl Exp $". +// End of "$Id: Fl_Menu_add.cxx,v 1.7 1999/02/03 08:43:33 bill Exp $". // diff --git a/src/Fl_grab.cxx b/src/Fl_grab.cxx new file mode 100644 index 000000000..8626a7cf6 --- /dev/null +++ b/src/Fl_grab.cxx @@ -0,0 +1,93 @@ +// +// "$Id: Fl_grab.cxx,v 1.1 1999/02/03 08:43:33 bill Exp $" +// +// Grab/release code for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-1999 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems to "fltk-bugs@easysw.com". +// + +#include <config.h> +#include <FL/Fl.H> +#include <FL/x.H> + +//////////////////////////////////////////////////////////////// +// "Grab" is done while menu systems are up. This has several effects: +// Events are all sent to the "grab window", which does not even +// have to be displayed (and in the case of Fl_Menu.C it isn't). +// The system is also told to "grab" events and send them to this app. +// This also modifies how Fl_Window::show() works, on X it turns on +// override_redirect, it does similar things on WIN32. + +extern void fl_send_extra_move(); // in Fl.cxx + +#ifdef WIN32 +// We have to keep track of whether we have captured the mouse, since +// MSWindows shows little respect for this... Grep for fl_capture to +// see where and how this is used. +extern HWND fl_capture; +#endif + +void Fl::grab(Fl_Window* w) { + if (w) { + if (!grab_) { +#ifdef WIN32 + SetActiveWindow(fl_capture = fl_xid(first_window())); + SetCapture(fl_capture); +#else + XGrabPointer(fl_display, + fl_xid(first_window()), + 1, + ButtonPressMask|ButtonReleaseMask| + ButtonMotionMask|PointerMotionMask, + GrabModeAsync, + GrabModeAsync, + None, + 0, + fl_event_time); + XGrabKeyboard(fl_display, + fl_xid(first_window()), + 1, + GrabModeAsync, + GrabModeAsync, + fl_event_time); +#endif + } + grab_ = w; + } else { + if (grab_) { +#ifdef WIN32 + fl_capture = 0; + ReleaseCapture(); +#else + XUngrabKeyboard(fl_display, fl_event_time); + XUngrabPointer(fl_display, fl_event_time); + // this flush is done in case the picked menu item goes into + // an infinite loop, so we don't leave the X server locked up: + XFlush(fl_display); +#endif + grab_ = 0; + fl_send_extra_move(); + } + } +} + +// +// End of "$Id: Fl_grab.cxx,v 1.1 1999/02/03 08:43:33 bill Exp $". +// diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 5bb70fbe5..aa1dee28f 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_win32.cxx,v 1.26 1999/01/29 07:52:21 bill Exp $" +// "$Id: Fl_win32.cxx,v 1.27 1999/02/03 08:43:33 bill Exp $" // // WIN32-specific code for the Fast Light Tool Kit (FLTK). // @@ -176,7 +176,7 @@ void fl_fix_focus(); // in Fl.C //////////////////////////////////////////////////////////////// -extern HWND fl_capture; +HWND fl_capture; static int mouse_event(Fl_Window *window, int what, int button, WPARAM wParam, LPARAM lParam) @@ -862,5 +862,5 @@ void Fl_Window::make_current() { } // -// End of "$Id: Fl_win32.cxx,v 1.26 1999/01/29 07:52:21 bill Exp $". +// End of "$Id: Fl_win32.cxx,v 1.27 1999/02/03 08:43:33 bill Exp $". // diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 412437c6f..36be30df6 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_x.cxx,v 1.22 1999/01/27 17:52:25 mike Exp $" +// "$Id: Fl_x.cxx,v 1.23 1999/02/03 08:43:34 bill Exp $" // // X specific code for the Fast Light Tool Kit (FLTK). // @@ -373,9 +373,12 @@ int fl_handle(const XEvent& xevent) case Expose: Fl_X::i(window)->wait_for_expose = 0; +#if 0 // try to keep windows on top even if WM_TRANSIENT_FOR does not work: + // opaque move/resize window managers do not like this, so I disabled it. if (Fl::first_window()->non_modal() && window != Fl::first_window()) Fl::first_window()->show(); +#endif case GraphicsExpose: window->damage(FL_DAMAGE_EXPOSE, xevent.xexpose.x, xevent.xexpose.y, @@ -818,5 +821,5 @@ void Fl_Window::make_current() { #endif // -// End of "$Id: Fl_x.cxx,v 1.22 1999/01/27 17:52:25 mike Exp $". +// End of "$Id: Fl_x.cxx,v 1.23 1999/02/03 08:43:34 bill Exp $". // diff --git a/src/Makefile b/src/Makefile index 54481d7cb..dfc3431d2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.10 1999/01/31 07:43:15 bill Exp $" +# "$Id: Makefile,v 1.11 1999/02/03 08:43:34 bill Exp $" # # Library makefile for the Fast Light Tool Kit (FLTK). # @@ -87,6 +87,7 @@ CPPFILES = \ Fl_display.cxx \ Fl_get_key.cxx \ Fl_get_system_colors.cxx \ + Fl_grab.cxx \ Fl_own_colormap.cxx \ Fl_visual.cxx \ Fl_x.cxx \ @@ -112,6 +113,7 @@ CPPFILES = \ fl_file_chooser.cxx \ fl_font.cxx \ fl_labeltype.cxx \ + fl_line_style.cxx \ fl_oval_box.cxx \ fl_overlay.cxx \ fl_overlay_visual.cxx \ @@ -182,5 +184,5 @@ install: ../lib/$(LIBNAME) -ln -s FL $(includedir)/Fl # -# End of "$Id: Makefile,v 1.10 1999/01/31 07:43:15 bill Exp $". +# End of "$Id: Makefile,v 1.11 1999/02/03 08:43:34 bill Exp $". # |
