* Added conditional compilation for
    - Panel.cxx
    - Fl_Text_Buffer.cxx
    - Fl_Text_Display.cxx
    - Fl_Text_Editor.cxx
    - FTextView.cxx
    - FTextRXTX.cxx
  * Added code to support fast wrap
    - Rx text buffer serviced as a non-wrap buffer
    - new lines inserted into text stream when current line
      length exceeds the panel width
    - no attempt to recalculate word wrap if panel is
      resized
    - needed for slow cpu and OS X X implementation
  * Added margin adjuster
  * Removed horizontal scroll when word wrap enabled
  * Set vertical scroll to always visible - prevents
    unnecessary reformating of text when scroll bar
    goes from hidden to visible
  * Corrected faulty logic in handle_dnd for dragging file from
    file manager view to editor widget
    - SHIFT-dnd places object name into target widget
    - dnd places object contents into target widget
    - dnd multiple objects concatenates contents into target widget
  * Test for bottom of text visibility when programmatically
    adding characters to a text view or edit buffer (Rx/Tx)
  * Implemented common FSEL methods for Fltk 1.3.0
    - 1.3.0 used common calls for all supported OS
pull/1/head
David Freese 2012-01-08 06:48:53 -06:00
rodzic faff489972
commit 23b9a177d2
21 zmienionych plików z 4205 dodań i 4121 usunięć

Wyświetl plik

@ -18,6 +18,7 @@ if test "x$target_win32" = "xyes"; then
AC_MSG_WARN([The windres utility could not be found])
fi
AC_DEFINE([__WOE32__], 1, [Define to 1 if we are building on cygwin or mingw])
AC_DEFINE([__MINGW32__], 1, [Define to 1 if we are building on cygwin or mingw])
AC_DEFINE([_WINDOWS], 1, [Define to 1 if we are building on cygwin or mingw])
fi

Wyświetl plik

@ -546,6 +546,8 @@ EXTRA_fldigi_SOURCES += \
fileselector/Fl_Native_File_Chooser_MAC.cxx \
fileselector/Fl_Native_File_Chooser_WIN32.cxx \
fileselector/flnfc_common.cxx \
fileselector/fileselect_1_1.cxx \
fileselector/fileselect_1_3.cxx \
feld/Feld7x7-14.cxx \
feld/Feld7x7n-14.cxx \
feld/FeldDx-14.cxx \

Wyświetl plik

@ -41,7 +41,23 @@
#include <fstream>
#include <algorithm>
#include <map>
#include <dirent.h>
// this tests depends on a modified FL/filename.H in the Fltk-1.3.0
// change
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
// to
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WOE32__)
#ifdef __MINGW32__
# if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3
# undef dirent
# include <dirent.h>
# else
# include <dirent.h>
# endif
#else
# include <dirent.h>
#endif
#ifndef __WOE32__
#include <sys/wait.h>
@ -3430,7 +3446,11 @@ int rightof(Fl_Widget* w)
int leftof(Fl_Widget* w)
{
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
unsigned int a = w->align();
#else
int a = w->align();
#endif
if (a == FL_ALIGN_CENTER || a & FL_ALIGN_INSIDE)
return w->x();
@ -3455,7 +3475,11 @@ int leftof(Fl_Widget* w)
int above(Fl_Widget* w)
{
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
unsigned int a = w->align();
#else
int a = w->align();
#endif
if (a == FL_ALIGN_CENTER || a & FL_ALIGN_INSIDE)
return w->y();
@ -3464,7 +3488,11 @@ int above(Fl_Widget* w)
int below(Fl_Widget* w)
{
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
unsigned int a = w->align();
#else
int a = w->align();
#endif
if (a == FL_ALIGN_CENTER || a & FL_ALIGN_INSIDE)
return w->y() + w->h();
@ -5782,6 +5810,7 @@ int Qidle_time = 0;
static int que_timeout = 0;
bool que_ok = true;
bool que_waiting = true;
void post_queue_execute(void*)
{
@ -5798,6 +5827,7 @@ void post_queue_execute(void*)
void queue_execute_after_rx(void*)
{
que_waiting = false;
if (!que_timeout) {
LOG_ERROR("%s", "timed out");
return;
@ -5813,6 +5843,12 @@ void queue_execute_after_rx(void*)
queue_execute();
}
void do_que_execute(void *)
{
que_waiting = false;
queue_execute();
}
char szTestChar[] = "E|I|S|T|M|O|A|V";
int get_tx_char(void)
{
@ -5911,10 +5947,12 @@ int get_tx_char(void)
if (queue_must_rx()) {
c = 3;
que_timeout = 400; // 20 seconds
Fl::add_timeout(0.0, queue_execute_after_rx);
REQ(queue_execute_after_rx, (void *)0);
while(que_waiting) MilliSleep(1);
} else {
c = -1;
queue_execute();
REQ(do_que_execute, (void*)0);
while(que_waiting) MilliSleep(1);
}
break;
case '^':

Wyświetl plik

@ -19,10 +19,13 @@
// USA.
//
#include <config.h>
#if (FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3) || (FLARQ_FLTK_API_MAJOR == 1 && FLARQ_FLTK_API_MINOR < 3)
// Use Windows' chooser
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(__WIN32__) || defined(__CYGWIN__)
#include "Fl_Native_File_Chooser_WIN32.cxx"
#endif
@ -36,3 +39,4 @@
#include "Fl_Native_File_Chooser_FLTK.cxx"
#endif
#endif

Wyświetl plik

@ -23,167 +23,12 @@
#include <config.h>
#include <string>
#include <cstdlib>
#include <libgen.h>
#if (FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3) || (FLARQ_FLTK_API_MAJOR == 1 && FLARQ_FLTK_API_MINOR < 3)
#include "fileselect.h"
#include "icons.h"
#include "debug.h"
# include "fileselect_1_1.cxx"
#include <FL/fl_ask.H>
#include <FL/Fl_Native_File_Chooser.H>
#if FSEL_THREAD
# include <FL/Fl.H>
# include <semaphore.h>
# include "threads.h"
#endif
using namespace std;
FSEL* FSEL::inst = 0;
static std::string filename;
#if FSEL_THREAD
static pthread_t fsel_thread;
sem_t fsel_sem;
#endif
void FSEL::create(void)
{
if (inst)
return;
#if FSEL_THREAD
if (sem_init(&fsel_sem, 0, 0) == -1) {
LOG_PERROR("sem_init");
return;
}
#endif
inst = new FSEL;
}
void FSEL::destroy(void)
{
#if FSEL_THREAD
sem_destroy(&fsel_sem);
#endif
delete inst;
inst = 0;
}
FSEL::FSEL()
: chooser(new Fl_Native_File_Chooser) { }
FSEL::~FSEL() { delete chooser; }
#if FSEL_THREAD
void* FSEL::thread_func(void* arg)
{
FSEL* fsel = reinterpret_cast<FSEL*>(arg);
fsel->result = fsel->chooser->show();
sem_post(&fsel_sem);
return NULL;
}
#endif
const char* FSEL::get_file(void)
{
// Calling directory() is apparently not enough on Linux
#if !defined(__WOE32__) && !defined(__APPLE__)
const char* preset = chooser->preset_file();
if (preset && *preset != '/' && chooser->directory()) {
filename = chooser->directory();
filename.append("/").append(preset);
chooser->preset_file(filename.c_str());
}
#endif
#if FSEL_THREAD
if (pthread_create(&fsel_thread, NULL, thread_func, this) != 0) {
fl_alert2("could not create file selector thread");
return NULL;
}
for (;;) {
if (sem_trywait(&fsel_sem) == 0)
break;
Fl::wait(0.1);
}
#else
result = chooser->show();
# include "fileselect_1_3.cxx"
#endif
switch (result) {
case -1:
fl_alert2("%s", chooser->errmsg());
// fall through
case 1:
return NULL;
default:
filename = chooser->filename();
string::size_type i = filename.rfind('/');
if (i != string::npos)
chooser->directory(filename.substr(0, i).c_str());
return filename.c_str();
}
}
const char* FSEL::select(const char* title, const char* filter, const char* def, int* fsel)
{
inst->chooser->title(title);
inst->chooser->filter(filter);
if (def) {
char *s = strdup(def), *dir = dirname(s);
if (strcmp(".", dir))
inst->chooser->directory(dir);
free(s);
s = strdup(def);
inst->chooser->preset_file(basename(s));
free(s);
}
inst->chooser->options(Fl_Native_File_Chooser::PREVIEW);
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_FILE);
const char* fn = inst->get_file();
if (fsel)
*fsel = inst->chooser->filter_value();
return fn;
}
const char* FSEL::saveas(const char* title, const char* filter, const char* def, int* fsel)
{
inst->chooser->title(title);
inst->chooser->filter(filter);
if (def) {
char *s = strdup(def), *dir = dirname(s);
if (strcmp(".", dir))
inst->chooser->directory(dir);
free(s);
s = strdup(def);
inst->chooser->preset_file(basename(s));
free(s);
}
inst->chooser->options(Fl_Native_File_Chooser::SAVEAS_CONFIRM |
Fl_Native_File_Chooser::NEW_FOLDER |
Fl_Native_File_Chooser::PREVIEW);
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
const char* fn = inst->get_file();
if (fsel)
*fsel = inst->chooser->filter_value();
return fn;
}
const char* FSEL::dir_select(const char* title, const char* filter, const char* def)
{
inst->chooser->title(title);
inst->chooser->filter(filter);
if (def)
inst->chooser->directory(def);
inst->chooser->options(Fl_Native_File_Chooser::NEW_FOLDER |
Fl_Native_File_Chooser::PREVIEW);
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
return inst->get_file();
}

Wyświetl plik

@ -47,6 +47,23 @@
#include <dirent.h>
#endif
// this tests depends on a modified FL/filename.H in the Fltk-1.3.0
// change
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
// to
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WOE32__)
#ifdef __MINGW32__
# if FLARQ_FLTK_API_MAJOR == 1 && FLARQ_FLTK_API_MINOR < 3
# undef dirent
# include <dirent.h>
# else
# include <dirent.h>
# endif
#else
# include <dirent.h>
#endif
#include "flarq.h"
#include "arq.h"
#include "arqdialogs.h"

Wyświetl plik

@ -44,16 +44,25 @@
#include <FL/Fl_Help_Dialog.H>
#include <FL/Fl_Menu_Item.H>
#ifdef __MINGW32__
# include "compat.h"
#endif
// this tests depends on a modified FL/filename.H in the Fltk-1.3.0
// change
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
// to
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WOE32__)
#include <FL/filename.H>
#ifdef __MINGW32__
# define dirent fl_dirent_no_thanks
#endif
#include <FL/filename.H>
#ifdef __MINGW32__
# undef dirent
# include "compat.h"
# if FLARQ_FLTK_API_MAJOR == 1 && FLARQ_FLTK_API_MINOR < 3
# define dirent fl_dirent_no_thanks
# undef dirent
# include <dirent.h>
# else
# include <dirent.h>
# endif
#else
# include <dirent.h>
#endif
#include "fileselect.h"

Wyświetl plik

@ -1,9 +1,9 @@
//
// "$Id: Fl_Text_Display.H 6902 2009-09-27 11:06:56Z matt $"
// "$Id: Fl_Text_Display_mod.H 8306 2011-01-24 17:04:22Z matt $"
//
// Header file for Fl_Text_Display class.
// Header file for Fl_Text_Display_mod class.
//
// Copyright 2001-2009 by Bill Spitzak and others.
// Copyright 2001-2010 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
// the LGPL for the FLTK library granted by Mark Edel.
//
@ -28,10 +28,12 @@
//
/* \file
Fl_Text_Display widget . */
Fl_Text_Display_mod widget . */
#ifndef FL_TEXT_DISPLAY_H
#define FL_TEXT_DISPLAY_H
#ifndef Fl_Text_Display_mod_H
#define Fl_Text_Display_mod_H
#include <string>
#include <FL/fl_draw.H>
#include <FL/Fl_Group.H>
@ -40,311 +42,451 @@
#include "Fl_Text_Buffer_mod.H"
/**
This is the FLTK text display widget. It allows the user to
view multiple lines of text and supports highlighting and
scrolling. The buffer that is displayed in the widget is managed
by the Fl_Text_Buffer
class.
*/
\brief Rich text display widget.
This is the FLTK text display widget. It allows the user to view multiple lines
of text and supports highlighting and scrolling. The buffer that is displayed
in the widget is managed by the Fl_Text_Buffer_mod class. A single Text Buffer
can be displayed by multiple Text Displays.
*/
class FL_EXPORT Fl_Text_Display_mod: public Fl_Group {
public:
/** text display cursor shapes enumeration */
enum {
NORMAL_CURSOR, CARET_CURSOR, DIM_CURSOR,
BLOCK_CURSOR, HEAVY_CURSOR
};
enum {
CURSOR_POS, CHARACTER_POS
};
/** drag types- they match Fl::event_clicks() so that single clicking to
start a collection selects by character, double clicking selects by
word and triple clicking selects by line.
*/
enum {
DRAG_CHAR = 0, DRAG_WORD = 1, DRAG_LINE = 2
};
friend void fl_text_drag_me(int pos, Fl_Text_Display_mod* d);
typedef void (*Unfinished_Style_Cb)(int, void *);
/** style attributes - currently not implemented! */
enum {
ATTR_NONE = 0,
ATTR_UNDERLINE = 1,
ATTR_HIDDEN = 2
};
/** This structure associates the color,font,size of a string to draw
with an attribute mask matching attr */
struct Style_Table_Entry {
Fl_Color color;
Fl_Font font;
int size;
unsigned attr;
};
Fl_Text_Display_mod(int X, int Y, int W, int H, const char *l = 0);
~Fl_Text_Display_mod();
virtual int handle(int e);
void buffer(Fl_Text_Buffer_mod* buf);
public:
/**
text display cursor shapes enumeration
*/
enum {
NORMAL_CURSOR, /**< I-beam */
CARET_CURSOR, /**< caret under the text */
DIM_CURSOR, /**< dim I-beam */
BLOCK_CURSOR, /**< unfille box under the current character */
HEAVY_CURSOR /**< thick I-beam */
};
/**
Sets or gets the current text buffer associated with the text widget.
Multiple text widgets can be associated with the same text buffer.
*/
void buffer(Fl_Text_Buffer_mod& buf) { buffer(&buf); }
/**
Gets the current text buffer associated with the text widget.
Multiple text widgets can be associated with the same text buffer.
*/
Fl_Text_Buffer_mod* buffer() const { return mBuffer; }
void redisplay_range(int start, int end);
void scroll(int topLineNum, int horizOffset);
void insert(const char* text);
void overstrike(const char* text);
void insert_position(int newPos);
/** Gets the position of the text insertion cursor for text display */
int insert_position() const { return mCursorPos; }
int in_selection(int x, int y) const;
void show_insert_position();
int move_right();
int move_left();
int move_up();
int move_down();
int count_lines(int start, int end, bool start_pos_is_line_start) const;
int line_start(int pos) const;
int line_end(int pos, bool start_pos_is_line_start) const;
int skip_lines(int startPos, int nLines, bool startPosIsLineStart);
int rewind_lines(int startPos, int nLines);
void next_word(void);
void previous_word(void);
void show_cursor(int b = 1);
/** Hides the text cursor */
void hide_cursor() { show_cursor(0); }
void cursor_style(int style);
/** Sets or gets the text cursor color. */
Fl_Color cursor_color() const {return mCursor_color;}
/** Sets or gets the text cursor color. */
void cursor_color(Fl_Color n) {mCursor_color = n;}
/** Sets or gets the width/height of the scrollbars. */
int scrollbar_width() const { return scrollbar_width_; }
/** Sets or gets the width/height of the scrollbars. */
void scrollbar_width(int W) { scrollbar_width_ = W; }
/** Gets the scrollbar alignment type */
Fl_Align scrollbar_align() const { return scrollbar_align_; }
/** Sets the scrollbar alignment type */
void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; }
/** Moves the insert position to the beginning of the current word. */
int word_start(int pos) const { return buffer()->word_start(pos); }
/** Moves the insert position to the end of the current word. */
int word_end(int pos) const { return buffer()->word_end(pos); }
the character position is the left edge of a character, whereas
the cursor is thought to be between the centers of two consecutive
characters.
*/
enum {
CURSOR_POS,
CHARACTER_POS
};
/**
drag types - they match Fl::event_clicks() so that single clicking to
start a collection selects by character, double clicking selects by
word and triple clicking selects by line.
*/
enum {
DRAG_NONE = -2,
DRAG_START_DND = -1,
DRAG_CHAR = 0,
DRAG_WORD = 1,
DRAG_LINE = 2
};
/**
wrap types - used in wrap_mode()
*/
enum {
WRAP_NONE, /**< don't wrap text at all */
WRAP_AT_COLUMN, /**< wrap text at the given text column */
WRAP_AT_PIXEL, /**< wrap text at a pixel position */
WRAP_AT_BOUNDS /**< wrap text so that it fits into the widget width */
};
friend void fl_text_drag_me(int pos, Fl_Text_Display_mod* d);
typedef void (*Unfinished_Style_Cb)(int, void *);
/**
This structure associates the color, font, andsize of a string to draw
with an attribute mask matching attr
*/
struct Style_Table_Entry {
Fl_Color color;
Fl_Font font;
Fl_Fontsize size;
unsigned attr;
};
Fl_Text_Display_mod(int X, int Y, int W, int H, const char *l = 0);
~Fl_Text_Display_mod();
virtual int handle(int e);
void buffer(Fl_Text_Buffer_mod* buf);
/**
Sets the current text buffer associated with the text widget.
Multiple text widgets can be associated with the same text buffer.
\param buf new text buffer
*/
void buffer(Fl_Text_Buffer_mod& buf) { buffer(&buf); }
/**
Gets the current text buffer associated with the text widget.
Multiple text widgets can be associated with the same text buffer.
\return current text buffer
*/
Fl_Text_Buffer_mod* buffer() const { return mBuffer; }
void redisplay_range(int start, int end);
void scroll(int topLineNum, int horizOffset);
void insert(const char* text);
void overstrike(const char* text);
void insert_position(int newPos);
/**
Gets the position of the text insertion cursor for text display.
\return insert position index into text buffer
*/
int insert_position() const { return mCursorPos; }
int position_to_xy(int pos, int* x, int* y) const;
void highlight_data(Fl_Text_Buffer_mod *styleBuffer,
const Style_Table_Entry *styleTable,
int nStyles, char unfinishedStyle,
Unfinished_Style_Cb unfinishedHighlightCB,
void *cbArg);
int in_selection(int x, int y) const;
void show_insert_position();
int move_right();
int move_left();
int move_up();
int move_down();
int count_lines(int start, int end, bool start_pos_is_line_start) const;
int line_start(int pos) const;
int line_end(int startPos, bool startPosIsLineStart) const;
int skip_lines(int startPos, int nLines, bool startPosIsLineStart);
int rewind_lines(int startPos, int nLines);
void next_word(void);
void previous_word(void);
void show_cursor(int b = 1);
/**
Hides the text cursor.
*/
void hide_cursor() { show_cursor(0); }
void cursor_style(int style);
/**
Gets the text cursor color.
\return cursor color
*/
Fl_Color cursor_color() const {return mCursor_color;}
/**
Sets the text cursor color.
\param n new cursor color
*/
void cursor_color(Fl_Color n) {mCursor_color = n;}
/**
Gets the width/height of the scrollbars.
/return width of scrollbars
*/
int scrollbar_width() const { return scrollbar_width_; }
/**
Sets the width/height of the scrollbars.
\param W width of scrollbars
*/
void scrollbar_width(int W) { scrollbar_width_ = W; }
/**
Gets the scrollbar alignment type.
\return scrollbar alignment
*/
Fl_Align scrollbar_align() const { return scrollbar_align_; }
/**
Sets the scrollbar alignment type.
\param a new scrollbar alignment
*/
void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; }
/**
Moves the insert position to the beginning of the current word.
\param pos start calculation at this index
\return beginning of the words
*/
int word_start(int pos) const { return buffer()->word_start(pos); }
/**
Moves the insert position to the end of the current word.
\param pos start calculation at this index
\return index of first character after the end of the word
*/
int word_end(int pos) const { return buffer()->word_end(pos); }
void highlight_data(Fl_Text_Buffer_mod *styleBuffer,
const Style_Table_Entry *styleTable,
int nStyles, char unfinishedStyle,
Unfinished_Style_Cb unfinishedHighlightCB,
void *cbArg);
int position_style(int lineStartPos, int lineLen, int lineIndex) const;
/**
\todo FIXME : get set methods pointing on shortcut_
have no effects as shortcut_ is unused in this class and derived!
\return the current shortcut key
*/
int shortcut() const {return shortcut_;}
/**
\todo FIXME : get set methods pointing on shortcut_
have no effects as shortcut_ is unused in this class and derived!
\param s the new shortcut key
*/
void shortcut(int s) {shortcut_ = s;}
/**
Gets the default font used when drawing text in the widget.
\return current text font face unless overridden by a style
*/
Fl_Font textfont() const {return textfont_;}
/**
Sets the default font used when drawing text in the widget.
\param s default text font face
*/
void textfont(Fl_Font s) {textfont_ = s; mColumnScale = 0;}
/**
Gets the default size of text in the widget.
\return current text height unless overridden by a style
*/
Fl_Fontsize textsize() const {return textsize_;}
/**
Sets the default size of text in the widget.
\param s new text size
*/
void textsize(Fl_Fontsize s) {textsize_ = s; mColumnScale = 0;}
/**
Gets the default color of text in the widget.
\return text color unless overridden by a style
*/
Fl_Color textcolor() const {return textcolor_;}
/**
Sets the default color of text in the widget.
\param n new text color
*/
void textcolor(Fl_Color n) {textcolor_ = n;}
int wrapped_column(int row, int column) const;
int wrapped_row(int row) const;
void wrap_mode(int wrap, int wrap_margin);
virtual void resize(int X, int Y, int W, int H);
int position_style(int lineStartPos, int lineLen, int lineIndex,
int dispIndex) const;
/** \todo FIXME : get set methods pointing on shortcut_
have no effects as shortcut_ is unused in this class and derived! */
int shortcut() const {return shortcut_;}
/** \todo FIXME : get set methods pointing on shortcut_
have no effects as shortcut_ is unused in this class and derived! */
void shortcut(int s) {shortcut_ = s;}
/**
Convert an x pixel position into a column number.
\param x number of pixels from the left margin
\return an approximate column number based on the main font
*/
double x_to_col(double x) const;
/**
Convert a column number into an x pixel position.
\param col an approximate column number based on the main font
\return number of pixels from the left margin to the left of an
average sized character
*/
double col_to_x(double col) const;
protected:
// Most (all?) of this stuff should only be called from resize() or
// draw().
// Anything with "vline" indicates thats it deals with currently
// visible lines.
virtual void draw();
void draw_text(int X, int Y, int W, int H);
void draw_range(int start, int end);
void draw_cursor(int, int);
void draw_string(int style, int x, int y, int toX, const char *string,
int nChars) const;
void draw_vline(int visLineNum, int leftClip, int rightClip,
int leftCharIndex, int rightCharIndex);
int find_x(const char *s, int len, int style, int x) const;
enum {
DRAW_LINE,
FIND_INDEX,
FIND_INDEX_FROM_ZERO,
GET_WIDTH
};
int handle_vline(int mode,
int lineStart, int lineLen, int leftChar, int rightChar,
int topClip, int bottomClip,
int leftClip, int rightClip) const;
void draw_line_numbers(bool clearAll);
void clear_rect(int style, int x, int y, int width, int height) const;
void display_insert();
void offset_line_starts(int newTopLineNum);
void calc_line_starts(int startLine, int endLine);
void update_line_starts(int pos, int charsInserted, int charsDeleted,
int linesInserted, int linesDeleted, int *scrolled);
void calc_last_char();
int position_to_line( int pos, int* lineNum ) const;
double string_width(const char* string, int length, int style) const;
static void scroll_timer_cb(void*);
static void buffer_predelete_cb(int pos, int nDeleted, void* cbArg);
static void buffer_modified_cb(int pos, int nInserted, int nDeleted,
int nRestyled, const char* deletedText,
void* cbArg);
static void h_scrollbar_cb(Fl_Scrollbar* w, Fl_Text_Display_mod* d);
static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display_mod* d);
void update_v_scrollbar();
void update_h_scrollbar();
int measure_vline(int visLineNum) const;
int longest_vline() const;
int empty_vlines() const;
int vline_length(int visLineNum) const;
int xy_to_position(int x, int y, int PosType = CHARACTER_POS) const;
void xy_to_rowcol(int x, int y, int* row, int* column,
int PosType = CHARACTER_POS) const;
void maintain_absolute_top_line_number(int state);
int get_absolute_top_line_number() const;
void absolute_top_line_number(int oldFirstChar);
int maintaining_absolute_top_line_number() const;
void reset_absolute_top_line_number();
int position_to_linecol(int pos, int* lineNum, int* column) const;
int scroll_(int topLineNum, int horizOffset);
void extend_range_for_styles(int* start, int* end);
void find_wrap_range(const char *deletedText, int pos, int nInserted,
int nDeleted, int *modRangeStart, int *modRangeEnd,
int *linesInserted, int *linesDeleted);
void measure_deleted_lines(int pos, int nDeleted);
void wrapped_line_counter(Fl_Text_Buffer_mod *buf, int startPos, int maxPos,
int maxLines, bool startPosIsLineStart,
int styleBufOffset, int *retPos, int *retLines,
int *retLineStart, int *retLineEnd,
bool countLastLineMissingNewLine = true) const;
void find_line_end(int pos, bool start_pos_is_text_start, int *lineEnd,
int *nextLineStart) const;
double measure_proportional_character(const char *s, int colNum, int pos) const;
int wrap_uses_character(int lineEndPos) const;
static const int DEFAULT_TOP_MARGIN;
static const int DEFAULT_BOTTOM_MARGIN;
static const int DEFAULT_LEFT_MARGIN;
static const int DEFAULT_RIGHT_MARGIN;
int TOP_MARGIN, BOTTOM_MARGIN, LEFT_MARGIN, RIGHT_MARGIN;
/** Gets the default font used when drawing text in the widget. */
Fl_Font textfont() const {return textfont_;}
/** Sets the default font used when drawing text in the widget. */
void textfont(Fl_Font s) {textfont_ = s;}
/** Gets the default size of text in the widget. */
Fl_Fontsize textsize() const {return textsize_;}
/** Sets the default size of text in the widget. */
void textsize(Fl_Fontsize s) {textsize_ = s;}
/** Gets the default color of text in the widget. */
Fl_Color textcolor() const {return textcolor_;}
/** Sets the default color of text in the widget. */
void textcolor(Fl_Color n) {textcolor_ = n;}
int wrapped_column(int row, int column) const;
int wrapped_row(int row) const;
void wrap_mode(int wrap, int wrap_margin);
virtual void resize(int X, int Y, int W, int H);
protected:
// Most (all?) of this stuff should only be called from resize() or
// draw().
// Anything with "vline" indicates thats it deals with currently
// visible lines.
virtual void draw();
void draw_text(int X, int Y, int W, int H);
void draw_range(int start, int end);
void draw_cursor(int, int);
void draw_string(int style, int x, int y, int toX, const char *string,
int nChars);
void draw_vline(int visLineNum, int leftClip, int rightClip,
int leftCharIndex, int rightCharIndex);
void draw_line_numbers(bool clearAll);
void clear_rect(int style, int x, int y, int width, int height);
void display_insert();
void offset_line_starts(int newTopLineNum);
void calc_line_starts(int startLine, int endLine);
void update_line_starts(int pos, int charsInserted, int charsDeleted,
int linesInserted, int linesDeleted, int *scrolled);
void calc_last_char();
int position_to_line( size_t pos, int* lineNum ) const;
int string_width(const char* string, int length, int style) const;
static void scroll_timer_cb(void*);
static void buffer_predelete_cb(int pos, int nDeleted, void* cbArg);
static void buffer_modified_cb(int pos, int nInserted, int nDeleted,
int nRestyled, const char* deletedText,
void* cbArg);
static void h_scrollbar_cb(Fl_Scrollbar* w, Fl_Text_Display_mod* d);
static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display_mod* d);
void update_v_scrollbar();
void update_h_scrollbar();
int measure_vline(int visLineNum) const;
int longest_vline() const;
int empty_vlines() const;
int vline_length(int visLineNum) const;
int xy_to_position(int x, int y, int PosType = CHARACTER_POS) const;
void xy_to_rowcol(int x, int y, int* row, int* column,
int PosType = CHARACTER_POS) const;
int position_to_xy(int pos, int* x, int* y) const;
void maintain_absolute_top_line_number(int state);
int get_absolute_top_line_number() const;
void absolute_top_line_number(int oldFirstChar);
int maintaining_absolute_top_line_number() const;
void reset_absolute_top_line_number();
int position_to_linecol(int pos, int* lineNum, int* column) const;
void scroll_(int topLineNum, int horizOffset);
void extend_range_for_styles(int* start, int* end);
void find_wrap_range(const char *deletedText, int pos, int nInserted,
int nDeleted, int *modRangeStart, int *modRangeEnd,
int *linesInserted, int *linesDeleted);
void measure_deleted_lines(int pos, int nDeleted);
void wrapped_line_counter(Fl_Text_Buffer_mod *buf, int startPos, int maxPos,
int maxLines, bool startPosIsLineStart,
int styleBufOffset, int *retPos, int *retLines,
int *retLineStart, int *retLineEnd,
bool countLastLineMissingNewLine = true) const;
void find_line_end(int pos, bool start_pos_is_line_start, int *lineEnd,
int *nextLineStart) const;
int measure_proportional_character(char c, int colNum, int pos) const;
int wrap_uses_character(int lineEndPos) const;
int range_touches_selection(const Fl_Text_Selection *sel, int rangeStart,
int rangeEnd) const;
#ifndef FL_DOXYGEN
static const int DEFAULT_TOP_MARGIN;
static const int DEFAULT_BOTTOM_MARGIN;
static const int DEFAULT_LEFT_MARGIN;
static const int DEFAULT_RIGHT_MARGIN;
int TOP_MARGIN, BOTTOM_MARGIN, LEFT_MARGIN, RIGHT_MARGIN;
int damage_range1_start, damage_range1_end;
int damage_range2_start, damage_range2_end;
int mCursorPos;
int mCursorOn;
int mCursorOldY; /* Y pos. of cursor for blanking */
int mCursorToHint; /* Tells the buffer modified callback
where to move the cursor, to reduce
the number of redraw calls */
int mCursorStyle; /* One of enum cursorStyles above */
int mCursorPreferredCol; /* Column for vert. cursor movement */
int mNVisibleLines; /* # of visible (displayed) lines */
int mNBufferLines; /* # of newlines in the buffer */
Fl_Text_Buffer_mod* mBuffer; /* Contains text to be displayed */
Fl_Text_Buffer_mod* mStyleBuffer; /* Optional parallel buffer containing
color and font information */
int mFirstChar, mLastChar; /* Buffer positions of first and last
displayed character (lastChar points
either to a newline or one character
beyond the end of the buffer) */
int mContinuousWrap; /* Wrap long lines when displaying */
int mWrapMargin; /* Margin in # of char positions for
wrapping in continuousWrap mode */
int* mLineStarts;
int mTopLineNum; /* Line number of top displayed line
of file (first line of file is 1) */
int mAbsTopLineNum; /* In continuous wrap mode, the line
number of the top line if the text
were not wrapped (note that this is
only maintained as needed). */
int mNeedAbsTopLineNum; /* Externally settable flag to continue
maintaining absTopLineNum even if
it isn't needed for line # display */
int mHorizOffset; /* Horizontal scroll pos. in pixels */
int mTopLineNumHint; /* Line number of top displayed line
of file (first line of file is 1) */
int mHorizOffsetHint; /* Horizontal scroll pos. in pixels */
int mNStyles; /* Number of entries in styleTable */
const Style_Table_Entry *mStyleTable; /* Table of fonts and colors for
coloring/syntax-highlighting */
char mUnfinishedStyle; /* Style buffer entry which triggers
on-the-fly reparsing of region */
Unfinished_Style_Cb mUnfinishedHighlightCB; /* Callback to parse "unfinished" */
/* regions */
void* mHighlightCBArg; /* Arg to unfinishedHighlightCB */
int mMaxsize;
int mFixedFontWidth; /* Font width if all current fonts are
fixed and match in width, else -1 */
int mSuppressResync; /* Suppress resynchronization of line
starts during buffer updates */
int mNLinesDeleted; /* Number of lines deleted during
buffer modification (only used
when resynchronization is suppressed) */
int mModifyingTabDistance; /* Whether tab distance is being
modified */
Fl_Color mCursor_color;
Fl_Scrollbar* mHScrollBar;
Fl_Scrollbar* mVScrollBar;
int scrollbar_width_;
Fl_Align scrollbar_align_;
int dragPos, dragType, dragging;
int display_insert_position_hint;
struct { int x, y, w, h; } text_area;
int shortcut_;
Fl_Font textfont_;
Fl_Fontsize textsize_;
Fl_Color textcolor_;
// The following are not presently used from the original NEdit code,
// but are being put here so that future versions of Fl_Text_Display
// can implement line numbers without breaking binary compatibility.
int mLineNumLeft, mLineNumWidth;
/* Line number margin and width */
#endif
int damage_range1_start, damage_range1_end;
int damage_range2_start, damage_range2_end;
int mCursorPos;
int mCursorOn;
int mCursorOldY; /* Y pos. of cursor for blanking */
int mCursorToHint; /* Tells the buffer modified callback
where to move the cursor, to reduce
the number of redraw calls */
int mCursorStyle; /* One of enum cursorStyles above */
int mCursorPreferredXPos; /* Pixel position for vert. cursor movement */
int mNVisibleLines; /* # of visible (displayed) lines */
int mNBufferLines; /* # of newlines in the buffer */
Fl_Text_Buffer_mod* mBuffer; /* Contains text to be displayed */
Fl_Text_Buffer_mod* mStyleBuffer; /* Optional parallel buffer containing
color and font information */
int mFirstChar, mLastChar; /* Buffer positions of first and last
displayed character (lastChar points
either to a newline or one character
beyond the end of the buffer) */
int mContinuousWrap; /* Wrap long lines when displaying */
int mFastDisplay; /* force continuous wrap and insertion of eol characters
used in FTextRX */
std::string s_text; /* current contents of line text buffer */
std::string s_style; /* current contents of line stype buffer */
int mWrapMarginPix; /* Margin in # of pixels for
wrapping in continuousWrap mode */
int* mLineStarts;
int mTopLineNum; /* Line number of top displayed line
of file (first line of file is 1) */
int mAbsTopLineNum; /* In continuous wrap mode, the line
number of the top line if the text
were not wrapped (note that this is
only maintained as needed). */
int mNeedAbsTopLineNum; /* Externally settable flag to continue
maintaining absTopLineNum even if
it isn't needed for line # display */
int mHorizOffset; /* Horizontal scroll pos. in pixels */
int mTopLineNumHint; /* Line number of top displayed line
of file (first line of file is 1) */
int mHorizOffsetHint; /* Horizontal scroll pos. in pixels */
int mNStyles; /* Number of entries in styleTable */
const Style_Table_Entry *mStyleTable; /* Table of fonts and colors for
coloring/syntax-highlighting */
char mUnfinishedStyle; /* Style buffer entry which triggers
on-the-fly reparsing of region */
Unfinished_Style_Cb mUnfinishedHighlightCB; /* Callback to parse "unfinished" */
/* regions */
void* mHighlightCBArg; /* Arg to unfinishedHighlightCB */
int mMaxsize;
int mSuppressResync; /* Suppress resynchronization of line
starts during buffer updates */
int mNLinesDeleted; /* Number of lines deleted during
buffer modification (only used
when resynchronization is suppressed) */
int mModifyingTabDistance; /* Whether tab distance is being
modified */
mutable double mColumnScale; /* Width in pixels of an average character. This
value is calculated as needed (lazy eval); it
needs to be mutable so that it can be calculated
within a method marked as "const" */
Fl_Color mCursor_color;
Fl_Scrollbar* mHScrollBar;
Fl_Scrollbar* mVScrollBar;
int scrollbar_width_;
Fl_Align scrollbar_align_;
int dragPos, dragType, dragging;
int display_insert_position_hint;
struct { int x, y, w, h; } text_area;
int shortcut_;
Fl_Font textfont_;
Fl_Fontsize textsize_;
Fl_Color textcolor_;
// The following are not presently used from the original NEdit code,
// but are being put here so that future versions of Fl_Text_Display_mod
// can implement line numbers without breaking binary compatibility.
/* Line number margin and width */
int mLineNumLeft, mLineNumWidth;
};
#endif
//
// End of "$Id: Fl_Text_Display.H 6902 2009-09-27 11:06:56Z matt $".
// End of "$Id: Fl_Text_Display_mod.H 8306 2011-01-24 17:04:22Z matt $".
//

Wyświetl plik

@ -1,9 +1,9 @@
//
// "$Id: Fl_Text_Editor.H 6893 2009-09-20 19:24:24Z greg.ercolano $"
// "$Id: Fl_Text_Editor_mod.H 7903 2010-11-28 21:06:39Z matt $"
//
// Header file for Fl_Text_Editor class.
// Header file for Fl_Text_Editor_mod class.
//
// Copyright 2001-2009 by Bill Spitzak and others.
// Copyright 2001-2010 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
// the LGPL for the FLTK library granted by Mark Edel.
//
@ -28,22 +28,22 @@
//
/* \file
Fl_Text_Editor widget . */
Fl_Text_Editor_mod widget . */
#ifndef FL_TEXT_EDITOR_H
#define FL_TEXT_EDITOR_H
#ifndef Fl_Text_Editor_mod_H
#define Fl_Text_Editor_mod_H
#include "Fl_Text_Display_mod.H"
// key will match in any state
#define FL_TEXT_EDITOR_ANY_STATE (-1L)
#define Fl_Text_Editor_mod_ANY_STATE (-1L)
/**
This is the FLTK text editor widget. It allows the user to
edit multiple lines of text and supports highlighting and
scrolling. The buffer that is displayed in the widget is managed
by the Fl_Text_Buffer
by the Fl_Text_Buffer_mod
class.
*/
class FL_EXPORT Fl_Text_Editor_mod : public Fl_Text_Display_mod {
@ -136,6 +136,6 @@ class FL_EXPORT Fl_Text_Editor_mod : public Fl_Text_Display_mod {
#endif
//
// End of "$Id: Fl_Text_Editor.H 6893 2009-09-20 19:24:24Z greg.ercolano $".
// End of "$Id: Fl_Text_Editor_mod.H 7903 2010-11-28 21:06:39Z matt $".
//

Wyświetl plik

@ -25,7 +25,24 @@
#include <limits.h>
#include <sys/param.h>
#include <sys/types.h>
#include <dirent.h>
// this tests depends on a modified FL/filename.H in the Fltk-1.3.0
// change
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
// to
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WOE32__)
#ifdef __MINGW32__
# if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3
# undef dirent
# include <dirent.h>
# else
# include <dirent.h>
# endif
#else
# include <dirent.h>
#endif
#include <sys/time.h>
#include <time.h>
#include <signal.h>

Wyświetl plik

@ -1,34 +1,18 @@
// ----------------------------------------------------------------------------
//
// fileselect.h
//
// Copyright (C) 2008-2009
// Stelios Bounanos, M0GLD
//
// This file is part of fldigi.
//
// Fldigi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Fldigi 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with fldigi. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#ifndef FILESELECT_H
#define FILESELECT_H
#ifdef __WOE32__
# define FSEL_THREAD 1
#endif
#include <config.h>
#if (FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3) || (FLARQ_FLTK_API_MAJOR == 1 && FLARQ_FLTK_API_MINOR < 3)
//#ifdef __WIN32__
//# define FSEL_THREAD 1
//#endif
#define FSEL_THREAD 0
class Fl_Native_File_Chooser;
#else
#include <FL/Fl_Native_File_Chooser.H>
#define FSEL_THREAD 0
#endif
class FSEL
{

Wyświetl plik

@ -47,9 +47,7 @@
#endif
#include <unistd.h>
#ifndef __MINGW32__
# include <dirent.h>
#endif
#include <exception>
#include <signal.h>
#include <locale.h>
@ -63,10 +61,17 @@
# define dirent fl_dirent_no_thanks
#endif
#include <FL/filename.H>
#ifdef __MINGW32__
# undef dirent
#ifdef __WOE32__
# if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3
# undef dirent
# include <dirent.h>
# endif
#else
# include <dirent.h>
#endif
#include "gettext.h"
#include "main.h"
#include "waterfall.h"

Wyświetl plik

@ -68,6 +68,23 @@
# include <fcntl.h>
#endif
// this tests depends on a modified FL/filename.H in the Fltk-1.3.0
// change
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
// to
//# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WOE32__)
#ifdef __MINGW32__
# if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3
# undef dirent
# include <dirent.h>
# else
# include <dirent.h>
# endif
#else
# include <dirent.h>
#endif
using namespace std;

Wyświetl plik

@ -70,12 +70,12 @@ struct CMDS { std::string cmd; void (*fp)(std::string); };
static queue<CMDS> cmds;
// following used for debugging and development
//void pushcmd(CMDS cmd)
//{
// LOG_INFO("%s, # = %d", cmd.cmd.c_str(), (int)cmds.size());
// cmds.push(cmd);
//}
#define pushcmd(a) cmds.push((a))
void pushcmd(CMDS cmd)
{
LOG_INFO("%s, # = %d", cmd.cmd.c_str(), (int)cmds.size());
cmds.push(cmd);
}
//#define pushcmd(a) cmds.push((a))
// these variables are referenced outside of this file
MACROTEXT macros;
@ -670,7 +670,7 @@ static void pZD(std::string &s, size_t &i, size_t endbracket)
s.replace( i, 4, szDt);
}
static void pID(std::string &s, size_t &i, size_t endbracket)
static void p_ID(std::string &s, size_t &i, size_t endbracket)
{
if (within_exec) {
s.replace(i, endbracket - i + 1, "");
@ -1833,7 +1833,8 @@ bool queue_must_rx()
static std::string rxcmds = "<!MOD<!WAI<!GOH<!QSY<!GOF";
if (cmds.empty()) return false;
CMDS cmd = cmds.front();
return (rxcmds.find(cmd.cmd.substr(0,5)) != std::string::npos);
bool ret = (rxcmds.find(cmd.cmd.substr(0,5)) != std::string::npos);
return ret;
}
struct MTAGS { const char *mTAG; void (*fp)(std::string &, size_t&, size_t );};
@ -1862,7 +1863,7 @@ static const MTAGS mtags[] = {
{"<ZT>", pZT},
{"<LD>", pLD},
{"<ZD>", pZD},
{"<ID>", pID},
{"<ID>", p_ID},
{"<TEXT>", pTEXT},
{"<CWID>", pCWID},
{"<RX>", pRX},
@ -2016,7 +2017,7 @@ void MACROTEXT::openMacroFile()
{
std::string deffilename = MacrosDir;
deffilename.append(progStatus.LastMacroFile);
const char *p = FSEL::select(_("Open macro file"), _("Fldigi macro definition file\t*.mdf"), deffilename.c_str());
const char *p = FSEL::select(_("Open macro file"), _("Fldigi macro definition file\t*.{mdf}"), deffilename.c_str());
if (p) {
loadMacros(p);
progStatus.LastMacroFile = fl_filename_name(p);
@ -2028,10 +2029,15 @@ void MACROTEXT::saveMacroFile()
{
std::string deffilename = MacrosDir;
deffilename.append(progStatus.LastMacroFile);
const char *p = FSEL::saveas(_("Save macro file"), _("Fldigi macro definition file\t*.mdf"), deffilename.c_str());
const char *p = FSEL::saveas(
_("Save macro file"),
_("Fldigi macro definition file\t*.{mdf}"),
deffilename.c_str());
if (p) {
saveMacros(p);
progStatus.LastMacroFile = fl_filename_name(p);
string sp = p;
if (sp.rfind(".mdf") == string::npos) sp.append(".mdf");
saveMacros(sp.c_str());
progStatus.LastMacroFile = fl_filename_name(sp.c_str());
}
}

Wyświetl plik

@ -143,7 +143,9 @@ FTextRX::FTextRX(int x, int y, int w, int h, const char *l)
init_context_menu();
menu[RX_MENU_QUICK_ENTRY].clear();
menu[RX_MENU_SCROLL_HINTS].clear();
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
menu[RX_MENU_WRAP].hide();
#endif
// Replace the scrollbar widget
MVScrollbar* mvsb = new MVScrollbar(mVScrollBar->x(), mVScrollBar->y(),
mVScrollBar->w(), mVScrollBar->h(), NULL);
@ -152,6 +154,9 @@ FTextRX::FTextRX(int x, int y, int w, int h, const char *l)
remove(mVScrollBar);
delete mVScrollBar;
Fl_Group::add(mVScrollBar = mvsb);
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
mFastDisplay = 1;
#endif
}
FTextRX::~FTextRX()
@ -209,7 +214,11 @@ int FTextRX::handle(int event)
}
case FL_MOVE: {
int p = xy_to_position(Fl::event_x(), Fl::event_y(), Fl_Text_Display_mod::CURSOR_POS);
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
if (sbuf->char_at(p) >= CLICK_START + FTEXT_DEF) {
#else
if (sbuf->character(p) >= CLICK_START + FTEXT_DEF) {
#endif
if (cursor != FL_CURSOR_HAND)
window()->cursor(cursor = FL_CURSOR_HAND);
return 1;
@ -248,6 +257,99 @@ out:
/// @param c The character
/// @param attr The attribute (@see enum text_attr_e); RECV if omitted.
///
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
void FTextRX::add(unsigned char c, int attr)
{
if (c == '\r')
return;
char s[] = { '\0', '\0', FTEXT_DEF + attr, '\0' };
const char *cp = &s[0];
// The user may have moved the cursor by selecting text or
// scrolling. Place it at the end of the buffer.
if (mCursorPos != tbuf->length())
insert_position(tbuf->length());
switch (c) {
case '\b':
// we don't call kf_backspace because it kills selected text
tbuf->remove(tbuf->length() - 1, tbuf->length());
sbuf->remove(sbuf->length() - 1, sbuf->length());
if (s_text.length()) {
s_text.erase(s_text.end() - 1);
s_style.erase(s_style.end() - 1);
}
break;
case '\n':
// maintain the scrollback limit, if we have one
if (max_lines > 0 && tbuf->count_lines(0, tbuf->length()) >= max_lines) {
int le = tbuf->line_end(0) + 1; // plus 1 for the newline
tbuf->remove(0, le);
sbuf->remove(0, le);
}
s_text.clear();
s_style.clear();
insert("\n");
sbuf->append(s + 2);
break;
default:
if ((c < ' ' || c == 127) && attr != CTRL) // look it up
cp = ascii[(unsigned char)c];
else // insert verbatim
s[0] = c;
for (int i = 0; cp[i]; ++i) {
s_text += cp[i];
s_style += s[2];
}
fl_font( textfont(), textsize() );
int lwidth = (int)fl_width( s_text.c_str(), s_text.length());
bool wrapped = false;
if ( lwidth >= (text_area.w - mVScrollBar->w() - LEFT_MARGIN - RIGHT_MARGIN)) {
if (c != ' ') {
size_t p = s_text.rfind(' ');
if (p != string::npos) {
s_text.erase(0, p+1);
s_style.erase(0, p+1);
if (s_text.length() < 10) { // wrap and delete trailing space
tbuf->remove(tbuf->length() - s_text.length(), tbuf->length());
sbuf->remove(sbuf->length() - s_style.length(), sbuf->length());
insert("\n"); // always insert new line
sbuf->append(s + 2);
insert(s_text.c_str());
sbuf->append(s_style.c_str());
wrapped = true;
}
}
}
if (!wrapped) { // add a new line if not wrapped
insert("\n");
sbuf->append(s + 2);
if (c != ' ') { // add character if not a space (no leading spaces)
for (int i = 0; cp[i]; ++i)
sbuf->append(s + 2);
insert(cp);
}
}
s_text.clear();
s_style.clear();
} else {
for (int i = 0; cp[i]; ++i)
sbuf->append(s + 2);
insert(cp);
}
break;
}
// test for bottom of text visibility
if (// !mFastDisplay &&
(mVScrollBar->value() >= mNBufferLines - mNVisibleLines + mVScrollBar->linesize() - 1))
show_insert_position();
}
#else
void FTextRX::add(unsigned char c, int attr)
{
if (c == '\r')
@ -288,7 +390,11 @@ void FTextRX::add(unsigned char c, int attr)
insert(cp);
break;
}
// test for bottom of text visibility
if (mVScrollBar->value() >= mNBufferLines - mNVisibleLines + mVScrollBar->linesize() - 1)
show_insert_position();
}
#endif
void FTextRX::set_quick_entry(bool b)
{
@ -317,6 +423,10 @@ void FTextRX::mark(FTextBase::TEXT_ATTR attr)
void FTextRX::clear(void)
{
FTextBase::clear();
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
s_text.clear();
s_style.clear();
#endif
static_cast<MVScrollbar*>(mVScrollBar)->clear();
}
@ -328,21 +438,38 @@ void FTextRX::setFont(Fl_Font f, int attr)
void FTextRX::handle_clickable(int x, int y)
{
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
int pos;
unsigned int style;
#else
int pos, style;
#endif
pos = xy_to_position(x + this->x(), y + this->y(), CURSOR_POS);
// return unless clickable style
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
if ((style = sbuf->char_at(pos)) < CLICK_START + FTEXT_DEF)
#else
if ((style = sbuf->character(pos)) < CLICK_START + FTEXT_DEF)
#endif
return;
int start, end;
for (start = pos-1; start >= 0; start--)
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
if (sbuf->char_at(start) != style)
#else
if (sbuf->character(start) != style)
#endif
break;
start++;
int len = sbuf->length();
for (end = pos+1; end < len; end++)
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
if (sbuf->char_at(end) != style)
#else
if (sbuf->character(end) != style)
#endif
break;
switch (style - FTEXT_DEF) {
@ -786,7 +913,11 @@ int FTextTX::nextChar(void)
else if (insert_position() <= txpos) // empty buffer or cursor inside transmitted text
c = -1;
else {
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
if ((c = static_cast<unsigned char>(tbuf->char_at(txpos)))) {
#else
if ((c = static_cast<unsigned char>(tbuf->character(txpos)))) {
#endif
++txpos;
REQ(FTextTX::changed_cb, txpos, 0, 0, -1,
static_cast<const char *>(0), this);

Wyświetl plik

@ -49,6 +49,8 @@
#include "FTextView.h"
#include "debug.h"
using namespace std;
@ -192,6 +194,17 @@ void FTextBase::resize(int X, int Y, int W, int H)
if (need_wrap_reset)
reset_wrap_col();
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
TOP_MARGIN = DEFAULT_TOP_MARGIN;
int r = H - Fl::box_dh(box()) - TOP_MARGIN - BOTTOM_MARGIN;
if (mHScrollBar->visible())
r -= scrollbar_width();
int msize = mMaxsize ? mMaxsize : textsize();
if (!msize) msize = 1;
//printf("H %d, textsize %d, lines %d, extra %d\n", r, msize, r / msize, r % msize);
if (r %= msize)
TOP_MARGIN += r;
#else
if (need_margin_reset && textsize() > 0) {
TOP_MARGIN = DEFAULT_TOP_MARGIN;
int r = H - Fl::box_dh(box()) - TOP_MARGIN - BOTTOM_MARGIN;
@ -200,13 +213,13 @@ void FTextBase::resize(int X, int Y, int W, int H)
if (r %= textsize())
TOP_MARGIN += r;
}
if (scroll_hint) {
mTopLineNumHint = mNBufferLines;
mHorizOffsetHint = 0;
#endif
if (scroll_hint) {
mTopLineNumHint = mNBufferLines;
mHorizOffsetHint = 0;
// display_insert_position_hint = 1;
scroll_hint = false;
}
scroll_hint = false;
}
bool hscroll_visible = mHScrollBar->visible();
Fl_Text_Editor_mod::resize(X, Y, W, H);
@ -285,6 +298,8 @@ void FTextBase::set_style(int attr, Fl_Font f, int s, Fl_Color c, int set)
/// @return 0 on success, -1 on error
int FTextBase::readFile(const char* fn)
{
set_word_wrap(restore_wrap);
if ( !(fn || (fn = FSEL::select(_("Insert text"), "Text\t*.txt"))) )
return -1;
@ -393,6 +408,10 @@ char* FTextBase::get_word(int x, int y, const char* nwchars, bool ontext)
return tbuf->selection_text();
}
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
start = tbuf->word_start(p);
end = tbuf->word_end(p);
#else
string nonword = nwchars;
nonword.append(" \t\n");
if (!tbuf->findchars_backward(p, nonword.c_str(), &start))
@ -401,6 +420,7 @@ char* FTextBase::get_word(int x, int y, const char* nwchars, bool ontext)
start++;
if (!tbuf->findchars_forward(p, nonword.c_str(), &end))
end = tbuf->length();
#endif
if (ontext && (p < start || p >= end))
return 0;
@ -775,35 +795,32 @@ int FTextEdit::handle_dnd_drag(int pos)
/// @return 1 or FTextBase::handle(FL_PASTE)
int FTextEdit::handle_dnd_drop(void)
{
restore_wrap = wrap;
set_word_wrap(false);
// paste verbatim if the shift key was held down during dnd
if (Fl::event_shift())
return FTextBase::handle(FL_PASTE);
#if !defined(__APPLE__) && !defined(__WOE32__)
if (strncmp(Fl::event_text(), "file://", 7))
return FTextBase::handle(FL_PASTE);
#endif
string text;
string::size_type p, len;
text = Fl::event_text();
string text = Fl::event_text();
#if defined(__APPLE__) || defined(__WOE32__)
const char sep[] = "\n";
#if defined(__APPLE__) || defined(__WOE32__)
text += sep;
#else
const char sep[] = "\r\n";
#endif
string::size_type p, len = text.length();
len = text.length();
while ((p = text.find(sep)) != string::npos) {
text[p] = '\0';
#if !defined(__APPLE__) && !defined(__WOE32__)
if (text.find("file://") == 0) {
text.erase(0, 7);
p -= 7;
len -= 7;
}
#endif
// paste everything verbatim if we couldn't read the first file
// paste everything verbatim if we cannot read the first file
LOG_INFO("DnD file %s", text.c_str());
if (readFile(text.c_str()) == -1 && len == text.length())
return FTextBase::handle(FL_PASTE);
text.erase(0, p + sizeof(sep) - 1);

Wyświetl plik

@ -1,7 +1,7 @@
//
// "$Id: Fl_Text_Editor.cxx 7462 2010-04-06 23:00:56Z matt $"
// "$Id: Fl_Text_Editor_mod.cxx 8034 2010-12-15 12:21:55Z AlbrechtS $"
//
// Copyright 2001-2009 by Bill Spitzak and others.
// Copyright 2001-2010 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
// the LGPL for the FLTK library granted by Mark Edel.
//
@ -31,8 +31,8 @@
#include <ctype.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include "Fl_Text_Editor_mod.H"
#include <FL/fl_ask.H>
#include "Fl_Text_Editor_mod.H"
/* Keyboard Control Matrix
@ -100,12 +100,12 @@ static struct {
int state;
Fl_Text_Editor_mod::Key_Func func;
} default_key_bindings[] = {
{ FL_Escape, FL_TEXT_EDITOR_ANY_STATE, Fl_Text_Editor_mod::kf_ignore },
{ FL_Enter, FL_TEXT_EDITOR_ANY_STATE, Fl_Text_Editor_mod::kf_enter },
{ FL_KP_Enter, FL_TEXT_EDITOR_ANY_STATE, Fl_Text_Editor_mod::kf_enter },
{ FL_BackSpace, FL_TEXT_EDITOR_ANY_STATE, Fl_Text_Editor_mod::kf_backspace },
{ FL_Insert, FL_TEXT_EDITOR_ANY_STATE, Fl_Text_Editor_mod::kf_insert },
{ FL_Delete, FL_TEXT_EDITOR_ANY_STATE, Fl_Text_Editor_mod::kf_delete },
{ FL_Escape, Fl_Text_Editor_mod_ANY_STATE, Fl_Text_Editor_mod::kf_ignore },
{ FL_Enter, Fl_Text_Editor_mod_ANY_STATE, Fl_Text_Editor_mod::kf_enter },
{ FL_KP_Enter, Fl_Text_Editor_mod_ANY_STATE, Fl_Text_Editor_mod::kf_enter },
{ FL_BackSpace, Fl_Text_Editor_mod_ANY_STATE, Fl_Text_Editor_mod::kf_backspace },
{ FL_Insert, Fl_Text_Editor_mod_ANY_STATE, Fl_Text_Editor_mod::kf_insert },
{ FL_Delete, Fl_Text_Editor_mod_ANY_STATE, Fl_Text_Editor_mod::kf_delete },
{ FL_Home, 0, Fl_Text_Editor_mod::kf_move },
{ FL_End, 0, Fl_Text_Editor_mod::kf_move },
{ FL_Left, 0, Fl_Text_Editor_mod::kf_move },
@ -184,7 +184,7 @@ Fl_Text_Editor_mod::Key_Func Fl_Text_Editor_mod::bound_key_function(int key, int
Key_Binding* cur;
for (cur = list; cur; cur = cur->next)
if (cur->key == key)
if (cur->state == FL_TEXT_EDITOR_ANY_STATE || cur->state == state)
if (cur->state == Fl_Text_Editor_mod_ANY_STATE || cur->state == state)
break;
if (!cur) return 0;
return cur->function;
@ -223,8 +223,6 @@ void Fl_Text_Editor_mod::add_key_binding(int key, int state, Key_Func function,
////////////////////////////////////////////////////////////////
#define NORMAL_INPUT_MOVE 0
static void kill_selection(Fl_Text_Editor_mod* e) {
if (e->buffer()->selected()) {
e->insert_position(e->buffer()->primary_selection()->start());
@ -234,6 +232,7 @@ static void kill_selection(Fl_Text_Editor_mod* e) {
/** Inserts the text associated with the key */
int Fl_Text_Editor_mod::kf_default(int c, Fl_Text_Editor_mod* e) {
// FIXME: this function is a mess! Fix this!
if (!c || (!isprint(c) && c != '\t')) return 0;
char s[2] = "\0";
s[0] = (char)c;
@ -253,13 +252,9 @@ int Fl_Text_Editor_mod::kf_ignore(int, Fl_Text_Editor_mod*) {
/** Does a backspace in the current buffer.*/
int Fl_Text_Editor_mod::kf_backspace(int, Fl_Text_Editor_mod* e) {
if (!e->buffer()->selected() && e->move_left()) {
int l = 1;
// FIXME: character is ucs-4
char c = e->buffer()->character(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
}
e->buffer()->select(e->insert_position(), e->insert_position()+l);
int p1 = e->insert_position();
int p2 = e->buffer()->next_char(p1);
e->buffer()->select(p1, p2);
}
kill_selection(e);
e->show_insert_position();
@ -286,6 +281,7 @@ int Fl_Text_Editor_mod::kf_move(int c, Fl_Text_Editor_mod* e) {
if (!selected)
e->dragPos = e->insert_position();
e->buffer()->unselect();
Fl::copy("", 0, 0);
switch (c) {
case FL_Home:
e->insert_position(e->buffer()->line_start(e->insert_position()));
@ -320,6 +316,11 @@ int Fl_Text_Editor_mod::kf_move(int c, Fl_Text_Editor_mod* e) {
int Fl_Text_Editor_mod::kf_shift_move(int c, Fl_Text_Editor_mod* e) {
kf_move(c, e);
fl_text_drag_me(e->insert_position(), e);
char *copy = e->buffer()->selection_text();
if (copy) {
Fl::copy(copy, strlen(copy), 0);
free(copy);
}
return 1;
}
/** Moves the current text cursor in the direction indicated by control key */
@ -328,6 +329,7 @@ int Fl_Text_Editor_mod::kf_ctrl_move(int c, Fl_Text_Editor_mod* e) {
e->dragPos = e->insert_position();
if (c != FL_Up && c != FL_Down) {
e->buffer()->unselect();
Fl::copy("", 0, 0);
e->show_insert_position();
}
switch (c) {
@ -367,6 +369,7 @@ int Fl_Text_Editor_mod::kf_meta_move(int c, Fl_Text_Editor_mod* e) {
e->dragPos = e->insert_position();
if (c != FL_Up && c != FL_Down) {
e->buffer()->unselect();
Fl::copy("", 0, 0);
e->show_insert_position();
}
switch (c) {
@ -449,13 +452,9 @@ int Fl_Text_Editor_mod::kf_insert(int, Fl_Text_Editor_mod* e) {
/** Does a delete of selected text or the current character in the current buffer.*/
int Fl_Text_Editor_mod::kf_delete(int, Fl_Text_Editor_mod* e) {
if (!e->buffer()->selected()) {
int l = 1;
// FIXME: character is ucs-4
char c = e->buffer()->character(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
}
e->buffer()->select(e->insert_position(), e->insert_position()+l);
int p1 = e->insert_position();
int p2 = e->buffer()->next_char(p1);
e->buffer()->select(p1, p2);
}
kill_selection(e);
@ -497,11 +496,15 @@ int Fl_Text_Editor_mod::kf_paste(int, Fl_Text_Editor_mod* e) {
/** Selects all text in the current buffer.*/
int Fl_Text_Editor_mod::kf_select_all(int, Fl_Text_Editor_mod* e) {
e->buffer()->select(0, e->buffer()->length());
const char *copy = e->buffer()->selection_text();
if (*copy) Fl::copy(copy, strlen(copy), 0);
free((void*)copy);
return 1;
}
/** Undo last edit in the current buffer. Also deselect previous selection. */
int Fl_Text_Editor_mod::kf_undo(int , Fl_Text_Editor_mod* e) {
e->buffer()->unselect();
Fl::copy("", 0, 0);
int crsr;
int ret = e->buffer()->undo(&crsr);
e->insert_position(crsr);
@ -519,7 +522,11 @@ int Fl_Text_Editor_mod::handle_key() {
// bytes to delete and a string to insert:
int del = 0;
if (Fl::compose(del)) {
if (del) buffer()->select(insert_position()-del, insert_position());
if (del) {
int dp = insert_position(), di = del;
while (di--) dp = buffer()->prev_char_clipped(dp);
buffer()->select(dp, insert_position());
}
kill_selection(this);
if (Fl::event_length()) {
if (insert_mode()) insert(Fl::event_text());
@ -549,6 +556,8 @@ void Fl_Text_Editor_mod::maybe_do_callback() {
}
int Fl_Text_Editor_mod::handle(int event) {
static int dndCursorPos;
if (!buffer()) return 0;
switch (event) {
@ -593,7 +602,12 @@ int Fl_Text_Editor_mod::handle(int event) {
if (Fl::event_button() == 2) {
// don't let the text_display see this event
if (Fl_Group::handle(event)) return 1;
dragType = -1;
dragType = DRAG_NONE;
if(buffer()->selected()) {
buffer()->unselect();
}
int pos = xy_to_position(Fl::event_x(), Fl::event_y(), CURSOR_POS);
insert_position(pos);
Fl::paste(*this, 0);
Fl::focus(this);
set_changed();
@ -610,11 +624,29 @@ int Fl_Text_Editor_mod::handle(int event) {
return 1;
}
break;
// Handle drag'n'drop attempt by the user. This is a simplified
// implementation which allows dnd operations onto the scroll bars.
case FL_DND_ENTER: // save the current cursor position
if (Fl::visible_focus() && handle(FL_FOCUS))
Fl::focus(this);
show_cursor(mCursorOn);
dndCursorPos = insert_position();
/* fall through */
case FL_DND_DRAG: // show a temporary insertion cursor
insert_position(xy_to_position(Fl::event_x(), Fl::event_y(), CURSOR_POS));
return 1;
case FL_DND_LEAVE: // restore original cursor
insert_position(dndCursorPos);
return 1;
case FL_DND_RELEASE: // keep insertion cursor and wait for the FL_PASTE event
buffer()->unselect(); // FL_PASTE must not destroy current selection!
return 1;
}
return Fl_Text_Display_mod::handle(event);
}
//
// End of "$Id: Fl_Text_Editor.cxx 7462 2010-04-06 23:00:56Z matt $".
// End of "$Id: Fl_Text_Editor_mod.cxx 8034 2010-12-15 12:21:55Z AlbrechtS $".
//

Wyświetl plik

@ -30,6 +30,12 @@
#include <FL/Fl_Window.H>
#include "Panel.h"
#include <config.h>
#define FLTK13
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3
#undef FLTK13
#endif
// Drag the edges that were initially at oldx,oldy to newx,newy:
// pass -1 as oldx or oldy to disable drag in that direction:
@ -37,7 +43,11 @@
int Panel::orgx()
{
int oldx = w();
#ifdef FLTK13
int *p = sizes() + 8;
#else
short* p = sizes()+8;
#endif
for (int i=children(); i--; p += 4)
if (p[1] < oldx) oldx = p[1];
return oldx;
@ -46,7 +56,11 @@ int Panel::orgx()
int Panel::orgy()
{
int oldy = h();
#ifdef FLTK13
int *p = sizes() + 8;
#else
short* p = sizes()+8;
#endif
for (int i=children(); i--; p += 4)
if (p[3] < oldy) oldy = p[3];
return oldy;
@ -55,7 +69,11 @@ int Panel::orgy()
void Panel::position(int oix, int oiy, int newx, int newy) {
//printf("oix %3d, oiy %3d, nux %3d, nuy %3d\n", oix, oiy, newx, newy);
Fl_Widget* const* a = array();
#ifdef FLTK13
int *p = sizes();
#else
short* p = sizes();
#endif
//printf("p0 %3d, p1 %3d, p2 %3d, p3 %3d\n", p[0], p[1], p[2], p[3]);
//printf("p4 %3d, p5 %3d, p6 %3d, p7 %3d\n", p[0], p[1], p[2], p[3]);
p += 8; // skip group & resizable's saved size
@ -90,7 +108,11 @@ void Panel::position(int oix, int oiy, int newx, int newy) {
// move the lower-right corner (sort of):
void Panel::resize(int X,int Y,int W,int H) {
// remember how much to move the child widgets:
#ifdef FLTK13
int *p = sizes();
#else
short* p = sizes();
#endif
int OX = x();
int OY = y();
int OW = w();
@ -191,8 +213,13 @@ int Panel::handle(int event) {
int oldx = 0;
int oldy = 0;
Fl_Widget*const* a = array();
#ifdef FLTK13
int *q = sizes();
int *p = q + 8;
#else
short* q = sizes();
short* p = q+8;
short* p = q + 8;
#endif
for (int i=children(); i--; p += 4) {
Fl_Widget* o = *a++;
if (o == resizable()) continue;
@ -227,7 +254,9 @@ int Panel::handle(int event) {
case FL_DRAG:
// This is necessary if CONSOLIDATE_MOTION in Fl_x.cxx is turned off:
// if (damage()) return 1; // don't fall behind
#ifdef FLTK13
if (damage()) return 1; // don't fall behind
#endif
case FL_RELEASE: {
if (!sdrag) return 0; // should not happen
Fl_Widget* r = resizable(); if (!r) r = this;