summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-02-20 21:14:47 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-02-20 21:14:47 +0000
commit2f82fd066321cde3e225fc87a9469849215413eb (patch)
tree0fb84acd8268a37ab45c2f2b3c358f6c962e75ea /src
parent7ae0c170ad2f63ac7e27d0496cd9c167e2bd0cbd (diff)
Mixed bag. Please see CHANGES.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7117 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Button.cxx2
-rw-r--r--src/Fl_Group.cxx4
-rw-r--r--src/Fl_Preferences.cxx155
-rw-r--r--src/Fl_Table.cxx2
-rw-r--r--src/Fl_Value_Input.cxx2
-rw-r--r--src/Fl_cocoa.mm43
6 files changed, 148 insertions, 60 deletions
diff --git a/src/Fl_Button.cxx b/src/Fl_Button.cxx
index 147e5cf4d..99e4589b3 100644
--- a/src/Fl_Button.cxx
+++ b/src/Fl_Button.cxx
@@ -60,7 +60,7 @@ int Fl_Button::value(int v) {
*/
void Fl_Button::setonly() { // set this radio button on, turn others off
value(1);
- Fl_Group* g = (Fl_Group*)parent();
+ Fl_Group* g = parent();
Fl_Widget*const* a = g->array();
for (int i = g->children(); i--;) {
Fl_Widget* o = *a++;
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx
index 4deba31ce..329a8723b 100644
--- a/src/Fl_Group.cxx
+++ b/src/Fl_Group.cxx
@@ -77,7 +77,7 @@ void Fl_Group::begin() {current_ = this;}
<I>Exactly the same as</I> current(this->parent()). Any new widgets
added to the widget tree will be added to the parent of the group.
*/
-void Fl_Group::end() {current_ = (Fl_Group*)parent();}
+void Fl_Group::end() {current_ = parent();}
/**
Returns the currently active group.
@@ -429,7 +429,7 @@ Fl_Group::~Fl_Group() {
*/
void Fl_Group::insert(Fl_Widget &o, int index) {
if (o.parent()) {
- Fl_Group* g = (Fl_Group*)(o.parent());
+ Fl_Group* g = o.parent();
int n = g->find(o);
if (g == this) {
if (index > n) index--;
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx
index c3920c692..14b254312 100644
--- a/src/Fl_Preferences.cxx
+++ b/src/Fl_Preferences.cxx
@@ -466,7 +466,7 @@ char Fl_Preferences::deleteAllGroups()
*/
int Fl_Preferences::entries()
{
- return node->nEntry;
+ return node->nEntry();
}
@@ -480,7 +480,7 @@ int Fl_Preferences::entries()
*/
const char *Fl_Preferences::entry( int index )
{
- return node->entry[index].name;
+ return node->entry(index).name;
}
@@ -1350,10 +1350,13 @@ Fl_Preferences::Node::Node( const char *path )
{
if ( path ) path_ = strdup( path ); else path_ = 0;
child_ = 0; next_ = 0; parent_ = 0;
- entry = 0;
- nEntry = NEntry = 0;
+ entry_ = 0;
+ nEntry_ = NEntry_ = 0;
dirty_ = 0;
top_ = 0;
+ indexed_ = 0;
+ index_ = 0;
+ nIndex_ = NIndex_ = 0;
}
void Fl_Preferences::Node::deleteAllChildren()
@@ -1366,27 +1369,28 @@ void Fl_Preferences::Node::deleteAllChildren()
}
child_ = 0L;
dirty_ = 1;
+ updateIndex();
}
void Fl_Preferences::Node::deleteAllEntries()
{
- if ( entry )
+ if ( entry_ )
{
- for ( int i = 0; i < nEntry; i++ )
+ for ( int i = 0; i < nEntry_; i++ )
{
- if ( entry[i].name ) {
- free( entry[i].name );
- entry[i].name = 0L;
+ if ( entry_[i].name ) {
+ free( entry_[i].name );
+ entry_[i].name = 0L;
}
- if ( entry[i].value ) {
- free( entry[i].value );
- entry[i].value = 0L;
+ if ( entry_[i].value ) {
+ free( entry_[i].value );
+ entry_[i].value = 0L;
}
}
- free( entry );
- entry = 0L;
- nEntry = 0;
- NEntry = 0;
+ free( entry_ );
+ entry_ = 0L;
+ nEntry_ = 0;
+ NEntry_ = 0;
}
dirty_ = 1;
}
@@ -1396,6 +1400,7 @@ Fl_Preferences::Node::~Node()
{
deleteAllChildren();
deleteAllEntries();
+ deleteIndex();
if ( path_ ) {
free( path_ );
path_ = 0L;
@@ -1420,12 +1425,12 @@ int Fl_Preferences::Node::write( FILE *f )
{
if ( next_ ) next_->write( f );
fprintf( f, "\n[%s]\n\n", path_ );
- for ( int i = 0; i < nEntry; i++ )
+ for ( int i = 0; i < nEntry_; i++ )
{
- char *src = entry[i].value;
+ char *src = entry_[i].value;
if ( src )
{ // hack it into smaller pieces if needed
- fprintf( f, "%s:", entry[i].name );
+ fprintf( f, "%s:", entry_[i].name );
int cnt;
for ( cnt = 0; cnt < 60; cnt++ )
if ( src[cnt]==0 ) break;
@@ -1443,7 +1448,7 @@ int Fl_Preferences::Node::write( FILE *f )
}
}
else
- fprintf( f, "%s\n", entry[i].name );
+ fprintf( f, "%s\n", entry_[i].name );
}
if ( child_ ) child_->write( f );
dirty_ = 0;
@@ -1482,37 +1487,38 @@ Fl_Preferences::Node *Fl_Preferences::Node::addChild( const char *path )
Node *nd = find( name );
free( name );
dirty_ = 1;
+ updateIndex();
return nd;
}
// create and set, or change an entry within this node
void Fl_Preferences::Node::set( const char *name, const char *value )
{
- for ( int i=0; i<nEntry; i++ )
+ for ( int i=0; i<nEntry_; i++ )
{
- if ( strcmp( name, entry[i].name ) == 0 )
+ if ( strcmp( name, entry_[i].name ) == 0 )
{
if ( !value ) return; // annotation
- if ( strcmp( value, entry[i].value ) != 0 )
+ if ( strcmp( value, entry_[i].value ) != 0 )
{
- if ( entry[i].value )
- free( entry[i].value );
- entry[i].value = strdup( value );
+ if ( entry_[i].value )
+ free( entry_[i].value );
+ entry_[i].value = strdup( value );
dirty_ = 1;
}
lastEntrySet = i;
return;
}
}
- if ( NEntry==nEntry )
+ if ( NEntry_==nEntry_ )
{
- NEntry = NEntry ? NEntry*2 : 10;
- entry = (Entry*)realloc( entry, NEntry * sizeof(Entry) );
+ NEntry_ = NEntry_ ? NEntry_*2 : 10;
+ entry_ = (Entry*)realloc( entry_, NEntry_ * sizeof(Entry) );
}
- entry[ nEntry ].name = strdup( name );
- entry[ nEntry ].value = value?strdup( value ):0;
- lastEntrySet = nEntry;
- nEntry++;
+ entry_[ nEntry_ ].name = strdup( name );
+ entry_[ nEntry_ ].value = value?strdup( value ):0;
+ lastEntrySet = nEntry_;
+ nEntry_++;
dirty_ = 1;
}
@@ -1546,8 +1552,8 @@ void Fl_Preferences::Node::set( const char *line )
// add more data to an existing entry
void Fl_Preferences::Node::add( const char *line )
{
- if ( lastEntrySet<0 || lastEntrySet>=nEntry ) return;
- char *&dst = entry[ lastEntrySet ].value;
+ if ( lastEntrySet<0 || lastEntrySet>=nEntry_ ) return;
+ char *&dst = entry_[ lastEntrySet ].value;
int a = strlen( dst );
int b = strlen( line );
dst = (char*)realloc( dst, a+b+1 );
@@ -1559,15 +1565,15 @@ void Fl_Preferences::Node::add( const char *line )
const char *Fl_Preferences::Node::get( const char *name )
{
int i = getEntry( name );
- return i>=0 ? entry[i].value : 0 ;
+ return i>=0 ? entry_[i].value : 0 ;
}
// find the index of an entry, returns -1 if no such entry
int Fl_Preferences::Node::getEntry( const char *name )
{
- for ( int i=0; i<nEntry; i++ )
+ for ( int i=0; i<nEntry_; i++ )
{
- if ( strcmp( name, entry[i].name ) == 0 )
+ if ( strcmp( name, entry_[i].name ) == 0 )
{
return i;
}
@@ -1580,8 +1586,8 @@ char Fl_Preferences::Node::deleteEntry( const char *name )
{
int ix = getEntry( name );
if ( ix == -1 ) return 0;
- memmove( entry+ix, entry+ix+1, (nEntry-ix-1) * sizeof(Entry) );
- nEntry--;
+ memmove( entry_+ix, entry_+ix+1, (nEntry_-ix-1) * sizeof(Entry) );
+ nEntry_--;
dirty_ = 1;
return 1;
}
@@ -1670,10 +1676,14 @@ Fl_Preferences::Node *Fl_Preferences::Node::search( const char *path, int offset
// return the number of child nodes (groups)
int Fl_Preferences::Node::nChildren()
{
- int cnt = 0;
- for ( Node *nd = child_; nd; nd = nd->next_ )
- cnt++;
- return cnt;
+ if (indexed_) {
+ return nIndex_;
+ } else {
+ int cnt = 0;
+ for ( Node *nd = child_; nd; nd = nd->next_ )
+ cnt++;
+ return cnt;
+ }
}
// return the node name
@@ -1688,7 +1698,7 @@ const char *Fl_Preferences::Node::name()
}
}
-// return the n'th child node
+// return the n'th child node's name
const char *Fl_Preferences::Node::child( int ix )
{
Node *nd = childNode( ix );
@@ -1701,13 +1711,22 @@ const char *Fl_Preferences::Node::child( int ix )
// return the n'th child node
Fl_Preferences::Node *Fl_Preferences::Node::childNode( int ix )
{
- Node *nd;
- for ( nd = child_; nd; nd = nd->next_ )
- {
- if ( !ix-- ) break;
- if ( !nd ) break;
+ createIndex();
+ if (indexed_) {
+ // usually faster access in correct order, but needing more memory
+ return index_[ix];
+ } else {
+ // slow access and reverse order
+ int n = nChildren();
+ ix = n - ix -1;
+ Node *nd;
+ for ( nd = child_; nd; nd = nd->next_ )
+ {
+ if ( !ix-- ) break;
+ if ( !nd ) break;
+ }
+ return nd;
}
- return nd;
}
// remove myself from the list and delete me (and all children)
@@ -1729,11 +1748,39 @@ char Fl_Preferences::Node::remove()
}
}
parent()->dirty_ = 1;
+ parent()->updateIndex();
}
delete this;
return ( nd != 0 );
}
+void Fl_Preferences::Node::createIndex() {
+ if (indexed_) return;
+ int n = nChildren();
+ if (n>NIndex_) {
+ NIndex_ = n + 16;
+ index_ = (Node**)realloc(index_, NIndex_*sizeof(Node**));
+ }
+ Node *nd;
+ int i = 0;
+ for (nd = child_; nd; nd = nd->next_, i++) {
+ index_[n-i-1] = nd;
+ }
+ nIndex_ = n;
+ indexed_ = 1;
+}
+
+void Fl_Preferences::Node::updateIndex() {
+ indexed_ = 0;
+}
+
+void Fl_Preferences::Node::deleteIndex() {
+ if (index_) free(index_);
+ NIndex_ = nIndex_ = 0;
+ index_ = 0;
+ indexed_ = 0;
+}
+
char Fl_Preferences::Node::copyTo(Fl_Tree *tree, Fl_Tree_Item *ti)
{
ti->label(name());
@@ -1744,11 +1791,11 @@ char Fl_Preferences::Node::copyTo(Fl_Tree *tree, Fl_Tree_Item *ti)
nd->copyTo(tree, tic);
tic->close();
}
- int i, n = nEntry;
+ int i, n = nEntry_;
for (i=0; i<n; i++) {
char buf[80];
- const char *name = entry[i].name;
- const char *value = entry[i].value;
+ const char *name = entry_[i].name;
+ const char *value = entry_[i].value;
fl_snprintf(buf, 80, "%s: %s", name, value);
tree->add(ti, buf);
}
diff --git a/src/Fl_Table.cxx b/src/Fl_Table.cxx
index 076718f1a..0eb5a0b80 100644
--- a/src/Fl_Table.cxx
+++ b/src/Fl_Table.cxx
@@ -15,7 +15,7 @@
// 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
diff --git a/src/Fl_Value_Input.cxx b/src/Fl_Value_Input.cxx
index 7b804225d..cabab3102 100644
--- a/src/Fl_Value_Input.cxx
+++ b/src/Fl_Value_Input.cxx
@@ -126,7 +126,7 @@ Fl_Value_Input::Fl_Value_Input(int X, int Y, int W, int H, const char* l)
: Fl_Valuator(X, Y, W, H, l), input(X, Y, W, H, 0) {
soft_ = 0;
if (input.parent()) // defeat automatic-add
- ((Fl_Group*)input.parent())->remove(input);
+ input.parent()->remove(input);
input.parent((Fl_Group *)this); // kludge!
input.callback(input_cb, this);
input.when(FL_WHEN_CHANGED);
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 1749b4b5b..ac139005f 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -38,6 +38,47 @@
// One Compile to copy them all and in the bundle bind them,
// in the Land of MacOS X where the Drop-Shadows lie."
+/*
+ TODO: The following messages point to the last Carbon remainders. We should
+ really remove these as well, so we can stop linking to Carbon alltogether.
+
+ "_GetKeys", referenced from:
+ Fl::get_key(int) in Fl_get_key.o
+
+ "_GetCurrentEventQueue", referenced from:
+ do_queued_events(double)in Fl.o
+
+ "_InstallEventLoopTimer", referenced from:
+ Fl::add_timeout(double, void (*)(void*), void*)in Fl.o
+
+ "_FlushEvents", referenced from:
+ fl_open_display() in Fl.o
+
+ "_GetEventParameter", referenced from:
+ carbonTextHandler(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) in Fl.o
+
+ "_InstallEventHandler", referenced from:
+ fl_open_display() in Fl.o
+
+ "_GetEventDispatcherTarget", referenced from:
+ fl_open_display() in Fl.o
+
+ "_SetEventLoopTimerNextFireTime", referenced from:
+ Fl::add_timeout(double, void (*)(void*), void*)in Fl.o
+
+ "_RemoveEventLoopTimer", referenced from:
+ Fl::add_timeout(double, void (*)(void*), void*)in Fl.o
+ delete_timer(MacTimeout&) in Fl.o
+
+ "_GetMainEventLoop", referenced from:
+ Fl::add_timeout(double, void (*)(void*), void*)in Fl.o
+
+ "_GetCurrentKeyModifiers", referenced from:
+ -[FLView flagsChanged:] in Fl.o
+
+ */
+
+
// we don't need the following definition because we deliver only
// true mouse moves. On very slow systems however, this flag may
// still be useful.
@@ -1918,7 +1959,7 @@ static void q_set_window_title(NSWindow *nsw, const char * name ) {
if ( Fl::e_keysym )
sendEvent = ( prevMods<mods ) ? FL_KEYBOARD : FL_KEYUP;
Fl::e_length = 0;
- Fl::e_text = "";
+ Fl::e_text = (char*)"";
prevMods = mods;
}
mods_to_e_state( mods );