Fixed a few pedantic warnings. Added Fl::option as discussed in STR #2368, but I am not too happy with it yet. Please see discussion in that STR.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7789 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
1e26ada2c5
commit
5560a4f0f1
32
FL/Fl.H
32
FL/Fl.H
@ -106,13 +106,14 @@ typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
|
||||
|
||||
/** @} */ /* group callback_functions */
|
||||
|
||||
|
||||
/**
|
||||
The Fl is the FLTK global (static) containing
|
||||
state information and global methods for the current application.
|
||||
*/
|
||||
class FL_EXPORT Fl {
|
||||
Fl() {}; // no constructor!
|
||||
|
||||
|
||||
public: // should be private!
|
||||
#ifndef FL_DOXYGEN
|
||||
static int e_number;
|
||||
@ -143,7 +144,34 @@ public: // should be private!
|
||||
If true then flush() will do something.
|
||||
*/
|
||||
static void damage(int d) {damage_ = d;}
|
||||
|
||||
|
||||
public:
|
||||
typedef enum {
|
||||
/// If set, the arrow keys can change focus from a text widget to another
|
||||
/// widget. If clear, only Tab and BackTab can.
|
||||
OPTION_ARROW_FOCUS = 0,
|
||||
/// If set, calls to fl_file_chooser will open the native file chooser.
|
||||
/// If clear, the FLTK file chooser will open instead.
|
||||
/// \todo Fl::OPTION_NATIVE_FILECHOOSER not yet supported
|
||||
OPTION_NATIVE_FILECHOOSER,
|
||||
// don't change this, leave it always as the last element
|
||||
OPTION_LAST
|
||||
} Fl_Option;
|
||||
|
||||
private:
|
||||
static unsigned char options_[OPTION_LAST];
|
||||
static unsigned char options_read_;
|
||||
|
||||
public:
|
||||
/**
|
||||
Return a global setting for all FLTK applications, possibly overridden
|
||||
by a setting specifically for this application.
|
||||
|
||||
\param opt
|
||||
\returns true or false
|
||||
*/
|
||||
static bool option(Fl_Option opt);
|
||||
|
||||
/**
|
||||
The currently executing idle callback function: DO NOT USE THIS DIRECTLY!
|
||||
|
||||
|
@ -39,8 +39,8 @@
|
||||
inset box and a white background. The text may contain any
|
||||
characters (even 0), and will correctly display any UTF text, using
|
||||
^X notation for unprintable control characters. It assumes the
|
||||
font can draw any characters of the used scripts, which is true
|
||||
for standard fonts under MSWindows and Mac OS X.</P>
|
||||
font can draw any characters of the used scripts, which is true
|
||||
for standard fonts under MSWindows and Mac OS X.</P>
|
||||
|
||||
<CENTER><TABLE border=1 WIDTH=90% summary="Fl_Input keyboard and mouse bindings.">
|
||||
|
||||
@ -114,10 +114,10 @@
|
||||
also be able to type "dead key" prefix characters. On X you will
|
||||
actually be able to see what dead key you typed, and if you then move
|
||||
the cursor without completing the sequence the accent will remain
|
||||
inserted.
|
||||
inserted.
|
||||
|
||||
<p>Under Mac OS X, character composition is done as for any Mac application
|
||||
using Mac OS-defined keystroke series.</TD></TR>
|
||||
<p>Under Mac OS X, character composition is done as for any Mac application
|
||||
using Mac OS-defined keystroke series.</TD></TR>
|
||||
</TABLE></CENTER>
|
||||
|
||||
<!-- NEW PAGE -->
|
||||
|
@ -38,15 +38,14 @@
|
||||
This input field displays '\n' characters as new lines rather than ^J,
|
||||
and accepts the Return, Tab, and up and down arrow keys. This is for
|
||||
editing multiline text.
|
||||
<P>
|
||||
|
||||
This is far from the nirvana of text editors, and is probably only
|
||||
good for small bits of text, 10 lines at most. Note that this widget
|
||||
does not support scrollbars or per-character color control.
|
||||
<P>
|
||||
|
||||
If you are presenting large amounts of text and need scrollbars
|
||||
or full color control of characters, you probably want Fl_Text_Editor
|
||||
instead.
|
||||
<P>
|
||||
*/
|
||||
class Fl_Multiline_Input : public Fl_Input {
|
||||
public:
|
||||
|
@ -37,10 +37,10 @@
|
||||
This widget is a subclass of Fl_Output that displays multiple
|
||||
lines of text. It also displays tab characters as whitespace to the
|
||||
next column.
|
||||
<P>
|
||||
|
||||
Note that this widget does not support scrollbars, or per-character
|
||||
color control.
|
||||
<P>
|
||||
|
||||
If you are presenting large amounts of read-only text
|
||||
and need scrollbars, or full color control of characters,
|
||||
then use Fl_Text_Display. If you want to display HTML text,
|
||||
|
32
src/Fl.cxx
32
src/Fl.cxx
@ -85,6 +85,10 @@ int Fl::e_length;
|
||||
int Fl::visible_focus_ = 1,
|
||||
Fl::dnd_text_ops_ = 1;
|
||||
|
||||
unsigned char Fl::options_[] = { 0, 0 };
|
||||
unsigned char Fl::options_read_ = 0;
|
||||
|
||||
|
||||
Fl_Window *fl_xfocus; // which window X thinks has focus
|
||||
Fl_Window *fl_xmousewin;// which window X thinks has FL_ENTER
|
||||
Fl_Window *Fl::grab_; // most recent Fl::grab()
|
||||
@ -1734,6 +1738,33 @@ void Fl::clear_widget_pointer(Fl_Widget const *w)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Fl::option(Fl_Option o)
|
||||
{
|
||||
if (!options_read_) {
|
||||
int tmp;
|
||||
{ // first, read the system wide preferences
|
||||
Fl_Preferences prefs(Fl_Preferences::SYSTEM, "fltk.org", "fltk");
|
||||
Fl_Preferences opt(prefs, "options");
|
||||
prefs.get("ArrowFocus", tmp, 0); options_[OPTION_ARROW_FOCUS] = tmp;
|
||||
prefs.get("NativeFilechooser", tmp, 0); options_[OPTION_NATIVE_FILECHOOSER] = tmp;
|
||||
}
|
||||
{ // next, check the user preferences
|
||||
Fl_Preferences prefs(Fl_Preferences::USER, "fltk.org", "fltk");
|
||||
Fl_Preferences opt(prefs, "options");
|
||||
prefs.get("ArrowFocus", tmp, 0); options_[OPTION_ARROW_FOCUS] = tmp;
|
||||
prefs.get("NativeFilechooser", tmp, 0); options_[OPTION_NATIVE_FILECHOOSER] = tmp;
|
||||
}
|
||||
{ // now, if the developer has registered this app, we could as for per-application preferences
|
||||
}
|
||||
options_read_ = 1;
|
||||
}
|
||||
if (o<0 || o>=OPTION_LAST)
|
||||
return false;
|
||||
return (bool)options_[o];
|
||||
}
|
||||
|
||||
|
||||
// Helper class Fl_Widget_Tracker
|
||||
|
||||
/**
|
||||
@ -1753,6 +1784,7 @@ Fl_Widget_Tracker::~Fl_Widget_Tracker() {
|
||||
Fl::release_widget_pointer(wp_); // remove pointer from watch list
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
|
@ -382,7 +382,8 @@ int Fl_Input::handle_key() {
|
||||
case ctrl('A'): // go to the beginning of the current line
|
||||
return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
|
||||
case ctrl('B'): // go one character backward
|
||||
return shift_position(position()-1) + NORMAL_INPUT_MOVE;
|
||||
i = shift_position(position()-1) + NORMAL_INPUT_MOVE;
|
||||
return Fl::option(Fl::OPTION_ARROW_FOCUS) ? i : 1;
|
||||
case ctrl('C'): // copy
|
||||
return copy(1);
|
||||
case ctrl('D'): // cut the next character
|
||||
@ -396,7 +397,8 @@ int Fl_Input::handle_key() {
|
||||
case ctrl('E'): // go to the end of the line
|
||||
return shift_position(line_end(position())) + NORMAL_INPUT_MOVE;
|
||||
case ctrl('F'): // go to the next character
|
||||
return shift_position(position()+1) + NORMAL_INPUT_MOVE;
|
||||
i = shift_position(position()+1) + NORMAL_INPUT_MOVE;
|
||||
return Fl::option(Fl::OPTION_ARROW_FOCUS) ? i : 1;
|
||||
case ctrl('H'): // cut the previous character
|
||||
if (readonly()) {
|
||||
fl_beep();
|
||||
@ -417,7 +419,10 @@ int Fl_Input::handle_key() {
|
||||
return copy_cuts();
|
||||
case ctrl('N'): // go down one line
|
||||
i = position();
|
||||
if (line_end(i) >= size()) return NORMAL_INPUT_MOVE;
|
||||
if (line_end(i) >= size()) {
|
||||
if (input_type()==FL_MULTILINE_INPUT && !Fl::option(Fl::OPTION_ARROW_FOCUS)) return 1;
|
||||
return NORMAL_INPUT_MOVE;
|
||||
}
|
||||
while (repeat_num--) {
|
||||
i = line_end(i);
|
||||
if (i >= size()) break;
|
||||
@ -427,7 +432,10 @@ int Fl_Input::handle_key() {
|
||||
return 1;
|
||||
case ctrl('P'): // go up one line
|
||||
i = position();
|
||||
if (!line_start(i)) return NORMAL_INPUT_MOVE;
|
||||
if (!line_start(i)) {
|
||||
if (input_type()==FL_MULTILINE_INPUT && !Fl::option(Fl::OPTION_ARROW_FOCUS)) return 1;
|
||||
return NORMAL_INPUT_MOVE;
|
||||
}
|
||||
while(repeat_num--) {
|
||||
i = line_start(i);
|
||||
if (!i) break;
|
||||
|
@ -51,6 +51,8 @@ extern Fl_Menu_* fl_menu_array_owner; // in Fl_Menu_.cxx
|
||||
// above pointers to detect if the array belongs to an Fl_Menu_
|
||||
// widget, and if so it reallocates as necessary.
|
||||
|
||||
|
||||
|
||||
// Insert a single Fl_Menu_Item into an array of size at offset n,
|
||||
// if this is local_array it will be reallocated if needed.
|
||||
static Fl_Menu_Item* array_insert(
|
||||
@ -81,6 +83,8 @@ static Fl_Menu_Item* array_insert(
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Comparison that does not care about deleted '&' signs:
|
||||
static int compare(const char* a, const char* b) {
|
||||
for (;;) {
|
||||
@ -97,6 +101,8 @@ static int compare(const char* a, const char* b) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Adds 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):
|
||||
@ -111,15 +117,26 @@ int Fl_Menu_Item::add(
|
||||
return(insert(-1,mytext,sc,cb,data,myflags)); // -1: append
|
||||
}
|
||||
|
||||
/** Inserts an item at position \p index.
|
||||
|
||||
|
||||
/**
|
||||
Inserts an item at position \p index.
|
||||
|
||||
If \p index is -1, the item is added the same way as Fl_Menu_Item::add().
|
||||
If \p index is -1, the item is added the same way as Fl_Menu_Item::add().
|
||||
|
||||
If 'mytext' contains any un-escaped front slashes (/), it's assumed
|
||||
a menu pathname is being specified, and the value of \p index
|
||||
will be ignored.
|
||||
If 'mytext' contains any un-escaped front slashes (/), it's assumed
|
||||
a menu pathname is being specified, and the value of \p index
|
||||
will be ignored.
|
||||
|
||||
In all other aspects, the behavior of insert() is the same as add().
|
||||
In all other aspects, the behavior of insert() is the same as add().
|
||||
|
||||
\param index insert new items here
|
||||
\param mytext new label string, details see above
|
||||
\param sc keyboard shortcut for new item
|
||||
\param cb callback function for new item
|
||||
\param data user data for new item
|
||||
\param myflags menu flags as described in FL_Menu_Item
|
||||
\returns the index into the menu() array, where the entry was added
|
||||
*/
|
||||
int Fl_Menu_Item::insert(
|
||||
int index,
|
||||
@ -199,6 +216,8 @@ int Fl_Menu_Item::insert(
|
||||
return m-array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Adds a new menu item.
|
||||
|
||||
@ -307,6 +326,8 @@ int Fl_Menu_::add(const char *label,int shortcut,Fl_Callback *callback,void *use
|
||||
return(insert(-1,label,shortcut,callback,userdata,flags)); // -1: append
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Inserts a new menu item at the specified \p index position.
|
||||
|
||||
@ -387,6 +408,8 @@ int Fl_Menu_::insert(
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
This is a Forms (and SGI GL library) compatible add function, it
|
||||
adds many menu items, with '|' separating the menu items, and tab
|
||||
@ -399,6 +422,9 @@ int Fl_Menu_::insert(
|
||||
same special characters as described for the long version of add().
|
||||
|
||||
No items must be added to a menu during a callback to the same menu.
|
||||
|
||||
\param str string containing multiple menu labels as described above
|
||||
\returns the index into the menu() array, where the entry was added
|
||||
*/
|
||||
int Fl_Menu_::add(const char *str) {
|
||||
char buf[1024];
|
||||
@ -417,10 +443,15 @@ int Fl_Menu_::add(const char *str) {
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Changes the text of item \p i. This is the only way to get
|
||||
slash into an add()'ed menu item. If the menu array was directly set
|
||||
with menu(x) then copy() is done to make a private array.
|
||||
|
||||
\param i index into menu array
|
||||
\param str new label for menu item at index i
|
||||
*/
|
||||
void Fl_Menu_::replace(int i, const char *str) {
|
||||
if (i<0 || i>=size()) return;
|
||||
@ -431,11 +462,16 @@ void Fl_Menu_::replace(int i, const char *str) {
|
||||
}
|
||||
menu_[i].text = str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Deletes item \p i from the menu. If the menu array was directly
|
||||
set with menu(x) then copy() is done to make a private array.
|
||||
|
||||
No items must be removed from a menu during a callback to the same menu.
|
||||
|
||||
\param i index into menu array
|
||||
*/
|
||||
void Fl_Menu_::remove(int i) {
|
||||
int n = size();
|
||||
|
@ -993,7 +993,7 @@ OSStatus cocoaKeyboardHandler(NSEvent *theEvent)
|
||||
UniChar one;
|
||||
CFStringGetCharacters((CFStringRef)sim, CFRangeMake(0, 1), &one);
|
||||
sym = one;
|
||||
// charactersIgnoringModifiers does'nt ignore shift, remove it when it's on
|
||||
// charactersIgnoringModifiers doesn't ignore shift, remove it when it's on
|
||||
if(sym >= 'A' && sym <= 'Z') sym += 32;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user