summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <git@matthiasm.com>2020-01-14 19:22:03 +0100
committerMatthias Melcher <git@matthiasm.com>2020-01-14 19:22:03 +0100
commitafcc79c3f7d5ffd9f9bd2185494688a5d5927aab (patch)
tree667156480c4b8c5eef936b47ed5103e3c137565f
parented80d9cef0c321012c65c31104be66dc64bf2fad (diff)
parentd598f9ea06f610053cd16b51cbe1aa477c8501ef (diff)
Merge remote-tracking branch 'refs/remotes/origin/master'
-rw-r--r--FL/Fl_BMP_Image.H10
-rw-r--r--FL/Fl_GIF_Image.H4
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Fl_BMP_Image.cxx164
-rw-r--r--src/Fl_GIF_Image.cxx129
-rw-r--r--src/Fl_Image_Reader.cxx131
-rw-r--r--src/Fl_Image_Reader.h90
-rw-r--r--src/Fl_Preferences.cxx55
-rw-r--r--src/Fl_cocoa.mm64
-rw-r--r--src/Makefile3
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H7
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx1
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H6
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx12
-rw-r--r--src/makedepend4
-rw-r--r--test/device.cxx4
16 files changed, 379 insertions, 306 deletions
diff --git a/FL/Fl_BMP_Image.H b/FL/Fl_BMP_Image.H
index aca8d1e2b..0d60d7114 100644
--- a/FL/Fl_BMP_Image.H
+++ b/FL/Fl_BMP_Image.H
@@ -3,17 +3,17 @@
//
// BMP image header file for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
-// http://www.fltk.org/COPYING.php
+// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
-// http://www.fltk.org/str.php
+// https://www.fltk.org/str.php
//
/* \file
@@ -25,7 +25,7 @@
/**
The Fl_BMP_Image class supports loading, caching,
- and drawing of Windows Bitmap (BMP) image files.
+ and drawing of Windows Bitmap (BMP) image files.
*/
class FL_EXPORT Fl_BMP_Image : public Fl_RGB_Image {
@@ -36,7 +36,7 @@ class FL_EXPORT Fl_BMP_Image : public Fl_RGB_Image {
protected:
- void load_bmp_(class BMPReader &rdr);
+ void load_bmp_(class Fl_Image_Reader &rdr);
};
diff --git a/FL/Fl_GIF_Image.H b/FL/Fl_GIF_Image.H
index 0f316eca9..ff781acd8 100644
--- a/FL/Fl_GIF_Image.H
+++ b/FL/Fl_GIF_Image.H
@@ -3,7 +3,7 @@
//
// GIF image header file for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -37,7 +37,7 @@ public:
protected:
- void load_gif_(class GIFReader &rdr);
+ void load_gif_(class Fl_Image_Reader &rdr);
};
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 08eb9194f..9db3dc421 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -46,6 +46,7 @@ set (CPPFILES
Fl_Group.cxx
Fl_Help_View.cxx
Fl_Image.cxx
+ Fl_Image_Reader.cxx
Fl_Image_Surface.cxx
Fl_Input.cxx
Fl_Input_.cxx
diff --git a/src/Fl_BMP_Image.cxx b/src/Fl_BMP_Image.cxx
index b2faf2de9..da869f5a6 100644
--- a/src/Fl_BMP_Image.cxx
+++ b/src/Fl_BMP_Image.cxx
@@ -1,8 +1,9 @@
//
// "$Id$"
//
-// Fl_BMP_Image routines.
+// Fl_BMP_Image class for the Fast Light Tool Kit (FLTK).
//
+// Copyright 2011-2020 by Bill Spitzak and others.
// Copyright 1997-2010 by Easy Software Products.
// Image support by Matthias Melcher, Copyright 2000-2009.
//
@@ -10,15 +11,11 @@
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
-// http://www.fltk.org/COPYING.php
+// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
-// http://www.fltk.org/str.php
-//
-// Contents:
-//
-// Fl_BMP_Image::Fl_BMP_Image() - Load a BMP image file.
+// https://www.fltk.org/str.php
//
//
@@ -26,12 +23,12 @@
//
#include <FL/Fl_BMP_Image.H>
+#include "Fl_Image_Reader.h"
#include <FL/fl_utf8.h>
#include <FL/Fl.H>
#include <stdio.h>
#include <stdlib.h>
-
//
// BMP definitions...
//
@@ -44,135 +41,8 @@
#endif // !BI_RGB
-//
-// Local reader class...
-//
-
-/*
- This class reads data chunks from a file or from memory in LSB-first
- byte order.
-
- TODO: GIFReader and BMPReader are very similar and should be combined to avoid
- code duplication.
- */
-class BMPReader
-{
-public:
- // Create the reader.
- BMPReader() :
- pIsFile(0), pIsData(0),
- pFile(0L), pData(0L), pStart(0L),
- pName(0L)
- { }
- // Initialize the reader to access the file system, filename is copied
- // and stored.
- int open(const char *filename) {
- if (!filename)
- return -1;
- pName = strdup(filename);
- if ( (pFile = fl_fopen(filename, "rb")) == NULL ) {
- return -1;
- }
- pIsFile = 1;
- return 0;
- }
- // Initialize the reader for memory access, name is copied and stored
- int open(const char *imagename, const unsigned char *data) {
- if (imagename)
- pName = strdup(imagename);
- if (data) {
- pStart = pData = data;
- pIsData = 1;
- return 0;
- } else {
- return -1;
- }
- }
- // Close and destroy the reader
- ~BMPReader() {
- if (pIsFile && pFile) {
- fclose(pFile);
- }
- if (pName)
- ::free(pName);
- }
- // Read a single byte form memory or a file
- uchar read_byte() {
- if (pIsFile) {
- return getc(pFile);
- } else if (pIsData) {
- return *pData++;
- } else {
- return 0;
- }
- }
- // Read a 16-bit unsigned integer, LSB-first
- unsigned short read_word() {
- unsigned char b0, b1; // Bytes from file
- if (pIsFile) {
- b0 = (uchar)getc(pFile);
- b1 = (uchar)getc(pFile);
- return ((b1 << 8) | b0);
- } else if (pIsData) {
- b0 = *pData++;
- b1 = *pData++;
- return ((b1 << 8) | b0);
- } else {
- return 0;
- }
- }
- // Read a 32-bit unsigned integer, LSB-first
- unsigned int read_dword() {
- unsigned char b0, b1, b2, b3; // Bytes from file
- if (pIsFile) {
- b0 = (uchar)getc(pFile);
- b1 = (uchar)getc(pFile);
- b2 = (uchar)getc(pFile);
- b3 = (uchar)getc(pFile);
- return ((((((b3 << 8) | b2) << 8) | b1) << 8) | b0);
- } else if (pIsData) {
- b0 = *pData++;
- b1 = *pData++;
- b2 = *pData++;
- b3 = *pData++;
- return ((((((b3 << 8) | b2) << 8) | b1) << 8) | b0);
- } else {
- return 0;
- }
- }
- // Read a 32-bit signed integer, LSB-first
- int read_long() {
- return (int)read_dword();
- };
- // Move the current read position to a byte offset fro the beginning of the
- // file or the original start address in memory
- void seek(unsigned int n) {
- if (pIsFile) {
- fseek(pFile, n , SEEK_SET);
- } else if (pIsData) {
- pData = pStart + n;
- }
- }
- // return the name or filename for this reader
- const char *name() { return pName; }
-private:
- // open() sets this if we read form a file
- char pIsFile;
- // open() sets this if we read form memory
- char pIsData;
- // a pointer to the opened file
- FILE *pFile;
- // a pointer to the current byte in memory
- const unsigned char *pData;
- // a pointer to the start of the image data
- const unsigned char *pStart;
- // a copy of the name associated with this reader
- char *pName;
-};
-
-
/**
- \brief The constructor loads the named BMP image from the given bmp filename.
+ \brief This constructor loads the named BMP image from the given BMP filename.
The destructor frees all memory and server resources that are used by
the image.
@@ -189,11 +59,11 @@ private:
Fl_BMP_Image::Fl_BMP_Image(const char *filename) // I - File to read
: Fl_RGB_Image(0,0,0)
{
- BMPReader f;
- if (f.open(filename)==-1) {
+ Fl_Image_Reader rdr;
+ if (rdr.open(filename) == -1) {
ld(ERR_FILE_ACCESS);
} else {
- load_bmp_(f);
+ load_bmp_(rdr);
}
}
@@ -201,12 +71,12 @@ Fl_BMP_Image::Fl_BMP_Image(const char *filename) // I - File to read
\brief Read a BMP image from memory.
Construct an image from a block of memory inside the application. Fluid offers
- "binary Data" chunks as a great way to add image data into the C++ source code.
+ "binary data" chunks as a great way to add image data into the C++ source code.
imagename can be NULL. If a name is given, the image is added to the list of
shared images and will be available by that name.
Use Fl_Image::fail() to check if Fl_BMP_Image failed to load. fail() returns
- ERR_FILE_ACCESS if the file could not be opened or read, ERR_FORMAT if the
+ ERR_FILE_ACCESS if the image could not be read from memory, ERR_FORMAT if the
BMP format could not be decoded, and ERR_NO_IMAGE if the image could not
be loaded for another reason.
@@ -219,20 +89,20 @@ Fl_BMP_Image::Fl_BMP_Image(const char *filename) // I - File to read
Fl_BMP_Image::Fl_BMP_Image(const char *imagename, const unsigned char *data)
: Fl_RGB_Image(0,0,0)
{
- BMPReader d;
- if (d.open(imagename, data)==-1) {
+ Fl_Image_Reader rdr;
+ if (rdr.open(imagename, data) == -1) {
ld(ERR_FILE_ACCESS);
} else {
- load_bmp_(d);
+ load_bmp_(rdr);
}
}
/*
This method reads BMP image data and creates an RGB or RGBA image. The BMP
format supports only 1 bit for alpha. To avoid code duplication, we use
- a BMPReader that reads data from either a file or from memory.
+ an Fl_Image_Reader that reads data from either a file or from memory.
*/
-void Fl_BMP_Image::load_bmp_(class BMPReader &rdr)
+void Fl_BMP_Image::load_bmp_(Fl_Image_Reader &rdr)
{
int info_size, // Size of info header
depth, // Depth of image (bits)
@@ -584,7 +454,7 @@ void Fl_BMP_Image::load_bmp_(class BMPReader &rdr)
break;
}
}
-
+
if (havemask) {
for (y = h() - 1; y >= 0; y --) {
ptr = (uchar *)array + y * w() * d() + 3;
diff --git a/src/Fl_GIF_Image.cxx b/src/Fl_GIF_Image.cxx
index 4054eac77..9036b6f6f 100644
--- a/src/Fl_GIF_Image.cxx
+++ b/src/Fl_GIF_Image.cxx
@@ -3,7 +3,7 @@
//
// Fl_GIF_Image routines.
//
-// Copyright 1997-2019 by Bill Spitzak and others.
+// Copyright 1997-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -15,9 +15,6 @@
//
// http://www.fltk.org/str.php
//
-// Contents:
-//
-//
//
// Reference: GIF89a Specification (links valid as of Jan 05, 2019):
@@ -35,11 +32,13 @@
#include <FL/Fl.H>
#include <FL/Fl_GIF_Image.H>
-#include <stdio.h>
-#include <stdlib.h>
+#include "Fl_Image_Reader.h"
#include <FL/fl_utf8.h>
#include "flstring.h"
+#include <stdio.h>
+#include <stdlib.h>
+
// Read a .gif file and convert it to a "xpm" format (actually my
// modified one with compressed colormaps).
@@ -75,100 +74,6 @@
* (415) 336-1080
*/
-typedef unsigned char uchar;
-
-//
-// Local reader class...
-//
-
-/*
- This class reads data chunks from a file or from memory in LSB-first
- byte order.
-
- TODO: GIFReader and BMPReader are very similar and should be combined to avoid
- code duplication.
- */
-class GIFReader
-{
-public:
- // Create the reader.
- GIFReader() :
- pIsFile(0), pIsData(0),
- pFile(0L), pData(0L),
- pName(0L)
- { }
- // Initialize the reader to access the file system, filename is copied
- // and stored.
- int open(const char *filename) {
- if (!filename)
- return -1;
- pName = strdup(filename);
- if ( (pFile = fl_fopen(filename, "rb")) == NULL ) {
- return -1;
- }
- pIsFile = 1;
- return 0;
- }
- // Initialize the reader for memory access, name is copied and stored
- int open(const char *imagename, const unsigned char *data) {
- if (imagename)
- pName = strdup(imagename);
- if (data) {
- pData = data;
- pIsData = 1;
- return 0;
- } else {
- return -1;
- }
- }
- // Close and destroy the reader
- ~GIFReader() {
- if (pIsFile && pFile) {
- fclose(pFile);
- }
- if (pName)
- ::free(pName);
- }
- // Read a single byte form memory or a file
- uchar read_byte() {
- if (pIsFile) {
- return getc(pFile);
- } else if (pIsData) {
- return *pData++;
- } else {
- return 0;
- }
- }
- // Read a 16-bit unsigned integer, LSB-first
- unsigned short read_word() {
- unsigned char b0, b1; // Bytes from file
- if (pIsFile) {
- b0 = (uchar)getc(pFile);
- b1 = (uchar)getc(pFile);
- return ((b1 << 8) | b0);
- } else if (pIsData) {
- b0 = *pData++;
- b1 = *pData++;
- return ((b1 << 8) | b0);
- } else {
- return 0;
- }
- }
- // return the name or filename for this reader
- const char *name() { return pName; }
-private:
- // open() sets this if we read form a file
- char pIsFile;
- // open() sets this if we read form memory
- char pIsData;
- // a pointer to the opened file
- FILE *pFile;
- // a pointer to the current byte in memory
- const unsigned char *pData;
- // a copy of the name associated with this reader
- char *pName;
-};
-
/**
\brief The constructor loads the named GIF image.
@@ -191,12 +96,12 @@ private:
Fl_GIF_Image::Fl_GIF_Image(const char *filename) :
Fl_Pixmap((char *const*)0)
{
- GIFReader f;
- if (f.open(filename)==-1) {
+ Fl_Image_Reader rdr;
+ if (rdr.open(filename) == -1) {
Fl::error("Fl_GIF_Image: Unable to open %s!", filename);
ld(ERR_FILE_ACCESS);
} else {
- load_gif_(f);
+ load_gif_(rdr);
}
}
@@ -222,24 +127,24 @@ Fl_GIF_Image::Fl_GIF_Image(const char *filename) :
\see Fl_GIF_Image::Fl_GIF_Image(const char *filename)
\see Fl_Shared_Image
- */
+*/
Fl_GIF_Image::Fl_GIF_Image(const char *imagename, const unsigned char *data) :
Fl_Pixmap((char *const*)0)
{
- GIFReader d;
- if (d.open(imagename, data)==-1) {
+ Fl_Image_Reader rdr;
+ if (rdr.open(imagename, data)==-1) {
ld(ERR_FILE_ACCESS);
} else {
- load_gif_(d);
+ load_gif_(rdr);
}
}
/*
This method reads GIF image data and creates an RGB or RGBA image. The GIF
format supports only 1 bit for alpha. To avoid code duplication, we use
- a GIFReader that reads data from either a file or from memory.
- */
-void Fl_GIF_Image::load_gif_(GIFReader &rdr)
+ an Fl_Image_Reader that reads data from either a file or from memory.
+*/
+void Fl_GIF_Image::load_gif_(Fl_Image_Reader &rdr)
{
char **new_data; // Data array
@@ -343,7 +248,7 @@ void Fl_GIF_Image::load_gif_(GIFReader &rdr)
}
// skip the data:
- while (blocklen>0) {while (blocklen--) {ch = rdr.read_byte();} blocklen=rdr.read_byte();}
+ while (blocklen>0) {while (blocklen--) {ch = rdr.read_byte();} blocklen = rdr.read_byte();}
}
if (BitsPerPixel >= CodeSize)
@@ -402,7 +307,7 @@ void Fl_GIF_Image::load_gif_(GIFReader &rdr)
/* Fetch the next code from the raster data stream. The codes can be
* any length from 3 to 12 bits, packed into 8-bit bytes, so we have to
* maintain our location as a pointer and a bit offset.
- * In addition, gif adds totally useless and annoying block counts
+ * In addition, GIF adds totally useless and annoying block counts
* that must be correctly skipped over. */
int CurCode = thisbyte;
if (frombit+CodeSize > 7) {
diff --git a/src/Fl_Image_Reader.cxx b/src/Fl_Image_Reader.cxx
new file mode 100644
index 000000000..083efb471
--- /dev/null
+++ b/src/Fl_Image_Reader.cxx
@@ -0,0 +1,131 @@
+//
+// Internal (Image) Reader class for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2020 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// https://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// https://www.fltk.org/str.php
+//
+
+
+//
+// Include necessary header files...
+//
+
+#include "Fl_Image_Reader.h"
+
+#include <FL/fl_utf8.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ This internal (undocumented) class reads data chunks from a file or from
+ memory in LSB-first byte order.
+
+ This class is used in Fl_GIF_Image and Fl_BMP_Image to avoid code
+ duplication and may be extended to be used in similar cases. Future
+ options might be to read data in MSB-first byte order or to add more
+ methods.
+*/
+
+// Initialize the reader to access the file system, filename is copied
+// and stored.
+int Fl_Image_Reader::open(const char *filename) {
+ if (!filename)
+ return -1;
+ pName = strdup(filename);
+ if ( (pFile = fl_fopen(filename, "rb")) == NULL ) {
+ return -1;
+ }
+ pIsFile = 1;
+ return 0;
+}
+
+// Initialize the reader for memory access, name is copied and stored
+int Fl_Image_Reader::open(const char *imagename, const unsigned char *data) {
+ if (imagename)
+ pName = strdup(imagename);
+ if (data) {
+ pStart = pData = data;
+ pIsData = 1;
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
+// Close and destroy the reader
+Fl_Image_Reader::~Fl_Image_Reader() {
+ if (pIsFile && pFile) {
+ fclose(pFile);
+ }
+ if (pName)
+ ::free(pName);
+}
+
+// Read a single byte from memory or a file
+uchar Fl_Image_Reader::read_byte() {
+ if (pIsFile) {
+ return getc(pFile);
+ } else if (pIsData) {
+ return *pData++;
+ } else {
+ return 0;
+ }
+}
+
+// Read a 16-bit unsigned integer, LSB-first
+unsigned short Fl_Image_Reader::read_word() {
+ unsigned char b0, b1; // Bytes from file
+ if (pIsFile) {
+ b0 = (uchar)getc(pFile);
+ b1 = (uchar)getc(pFile);
+ return ((b1 << 8) | b0);
+ } else if (pIsData) {
+ b0 = *pData++;
+ b1 = *pData++;
+ return ((b1 << 8) | b0);
+ } else {
+ return 0;
+ }
+}
+
+// Read a 32-bit unsigned integer, LSB-first
+unsigned int Fl_Image_Reader::read_dword() {
+ unsigned char b0, b1, b2, b3; // Bytes from file
+ if (pIsFile) {
+ b0 = (uchar)getc(pFile);
+ b1 = (uchar)getc(pFile);
+ b2 = (uchar)getc(pFile);
+ b3 = (uchar)getc(pFile);
+ return ((((((b3 << 8) | b2) << 8) | b1) << 8) | b0);
+ } else if (pIsData) {
+ b0 = *pData++;
+ b1 = *pData++;
+ b2 = *pData++;
+ b3 = *pData++;
+ return ((((((b3 << 8) | b2) << 8) | b1) << 8) | b0);
+ } else {
+ return 0;
+ }
+}
+
+// Read a 32-bit signed integer, LSB-first
+// int Fl_Image_Reader::read_long() -- implementation in header file
+
+// Move the current read position to a byte offset from the beginning
+// of the file or the original start address in memory
+void Fl_Image_Reader::seek(unsigned int n) {
+ if (pIsFile) {
+ fseek(pFile, n , SEEK_SET);
+ } else if (pIsData) {
+ pData = pStart + n;
+ }
+}
diff --git a/src/Fl_Image_Reader.h b/src/Fl_Image_Reader.h
new file mode 100644
index 000000000..83d9c366e
--- /dev/null
+++ b/src/Fl_Image_Reader.h
@@ -0,0 +1,90 @@
+//
+// Internal (Image) Reader class for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2020 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// https://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// https://www.fltk.org/str.php
+//
+
+/*
+ This internal (undocumented) class reads data chunks from a file or from
+ memory in LSB-first byte order.
+
+ This class is used in Fl_GIF_Image and Fl_BMP_Image to avoid code
+ duplication and may be extended to be used in similar cases. Future
+ options might be to read data in MSB-first byte order or to add more
+ methods.
+*/
+
+#ifndef FL_IMAGE_READER_H
+#define FL_IMAGE_READER_H
+
+#include <stdio.h>
+
+class Fl_Image_Reader
+{
+public:
+ // Create the reader.
+ Fl_Image_Reader() :
+ pIsFile(0), pIsData(0),
+ pFile(0L), pData(0L),
+ pStart(0L),
+ pName(0L)
+ {}
+
+ // Initialize the reader to access the file system, filename is copied
+ // and stored.
+ int open(const char *filename);
+
+ // Initialize the reader for memory access, name is copied and stored
+ int open(const char *imagename, const unsigned char *data);
+
+ // Close and destroy the reader
+ ~Fl_Image_Reader();
+
+ // Read a single byte from memory or a file
+ unsigned char read_byte();
+
+ // Read a 16-bit unsigned integer, LSB-first
+ unsigned short read_word();
+
+ // Read a 32-bit unsigned integer, LSB-first
+ unsigned int read_dword();
+
+ // Read a 32-bit signed integer, LSB-first
+ int read_long() {
+ return (int)read_dword();
+ };
+
+ // Move the current read position to a byte offset from the beginning
+ // of the file or the original start address in memory
+ void seek(unsigned int n);
+
+ // return the name or filename for this reader
+ const char *name() { return pName; }
+
+private:
+
+ // open() sets this if we read from a file
+ char pIsFile;
+ // open() sets this if we read from memory
+ char pIsData;
+ // a pointer to the opened file
+ FILE *pFile;
+ // a pointer to the current byte in memory
+ const unsigned char *pData;
+ // a pointer to the start of the image data
+ const unsigned char *pStart;
+ // a copy of the name associated with this reader
+ char *pName;
+};
+
+#endif // FL_IMAGE_READER_H
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx
index 3c4bb8feb..a9b4464bf 100644
--- a/src/Fl_Preferences.cxx
+++ b/src/Fl_Preferences.cxx
@@ -3,17 +3,18 @@
//
// Preferences methods for the Fast Light Tool Kit (FLTK).
//
+// Copyright 2011-2020 by Bill Spitzak and others.
// Copyright 2002-2010 by Matthias Melcher.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
-// http://www.fltk.org/COPYING.php
+// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
-// http://www.fltk.org/str.php
+// https://www.fltk.org/str.php
//
#include <FL/Fl.H>
@@ -118,48 +119,48 @@ unsigned int Fl_Preferences::file_access()
only as long as the application runs. It can be used as a database for
volatile information. FLTK uses it to register plugins at run-time.
- \note On \b MSWindows, the directory is constructed by querying the <i>Common AppData</i>
- or <i>AppData</i> key of the <tt>Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders</tt>
- registry entry. The filename and path is then constructed as <tt>$(query)/$(vendor)/$(application).prefs</tt> .
+ \note On \b Windows, the directory is constructed by querying the <i>Common AppData</i>
+ or <i>AppData</i> key of the <tt>Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders</tt>
+ registry entry. The filename and path is then constructed as <tt>\$(query)/\$(vendor)/\$(application).prefs</tt> .
If the query call fails, data will be stored in RAM only and be lost when the app exits.
\par In FLTK versions before 1.4.0, if querying the registry failed, preferences would be written to
- <tt>C:\FLTK\$(vendor)\$(application).prefs</tt> .
+ <tt>C:\\FLTK\\\$(vendor)\\\$(application).prefs</tt> .
\note On \b Linux, the \c USER directory is constructed by reading \c $HOME . If \c $HOME is not set
or not pointing to an existing directory, we are checking the path member of the passwd struct returned by
\c getpwuid(getuid()) . If all attempts fail, data will be stored in RAM only and be lost when the app exits.
- The filename and path is then constructed as <tt>$(directory)/.fltk/$(vendor)/$(application).prefs</tt> .
- The \c SYSTEM directory is hardcoded as <tt>/etc/fltk/$(vendor)/$(application).prefs</tt> .
+ The filename and path is then constructed as <tt>\$(directory)/.fltk/\$(vendor)/\$(application).prefs</tt> .
+ The \c SYSTEM directory is hardcoded as <tt>/etc/fltk/\$(vendor)/\$(application).prefs</tt> .
\par In FLTK versions before 1.4.0, if \c $HOME was not set, the \c USER path would be empty,
- generating <tt>$(vendor)/$(application).prefs</tt>, which was used relative the the current working directory.
+ generating <tt>\$(vendor)/\$(application).prefs</tt>, which was used relative to the current working directory.
- \note On \b MacOS, the \c USER directory is constructed by reading \c $HOME . If \c $HOME is not set
+ \note On \b macOS, the \c USER directory is constructed by reading \c $HOME . If \c $HOME is not set
or not pointing to an existing directory, we check the path returned by \c NSHomeDirectory() , and
finally checking the path member of the passwd struct returned by \c getpwuid(getuid()) .
If all attempts fail, data will be stored in RAM only and be lost when the app exits.
- The filename and path is then constructed as <tt>$(directory)/Library/Preferences/$(vendor)/$(application).prefs</tt> .
- The \c SYSTEM directory is hardcoded as <tt>/Library/Preferences/$(vendor)/$(application).prefs</tt> .
+ The filename and path is then constructed as <tt>\$(directory)/Library/Preferences/\$(vendor)/\$(application).prefs</tt> .
+ The \c SYSTEM directory is hardcoded as <tt>/Library/Preferences/\$(vendor)/\$(application).prefs</tt> .
\par In FLTK versions before 1.4.0, if \c $HOME was not set, the \c USER path would be \c NULL ,
- generating <tt>\<null\>/Library/Preferences/$(vendor)/$(application).prefs</tt>, which would silently fail to
- create a prefrences file.
+ generating <tt>\<null\>/Library/Preferences/\$(vendor)/\$(application).prefs</tt>, which would silently fail to
+ create a preferences file.
\param[in] root can be \c USER or \c SYSTEM for user specific or system wide preferences
\param[in] vendor unique text describing the company or author of this file, must be a valid filepath segment
\param[in] application unique text describing the application, must be a valid filepath segment
- \todo Before the release of 1.4.0, I want to make a failed attempt to write a preferences file smarter. I
- plan to use a subgroup of the "runtime" preferences to store data and stay accessable until the application
- exits. Data would be stored under <tt>./$(vendor)/$(application).prefs</tt> in RAM, but not on disk.
+ \todo (Matt) Before the release of 1.4.0, I want to make a further attempt to write a preferences file smarter. I
+ plan to use a subgroup of the "runtime" preferences to store data and stay accessible until the application
+ exits. Data would be stored under <tt>./\$(vendor)/\$(application).prefs</tt> in RAM, but not on disk.
- \todo I want a way to access the type of the root preferences (SYSTEM, USER, MEMORY), and the state of
+ \todo (Matt) I want a way to access the type of the root preferences (SYSTEM, USER, MEMORY), and the state of
the file access (OK, FILE_SYSTEM_FAIL, PERMISSION_FAIL, etc.), and probably the dirty() flag as well.
- \todo Also, I need to explain runtime preferences.
+ \todo (Matt) Also, I need to explain runtime preferences.
- \todo Lastly, I think I have to put short sample code in the Doxygen docs. The test app ist just not enough.
+ \todo (Matt) Lastly, I think I have to put short sample code in the Doxygen docs. The test app ist just not enough.
*/
Fl_Preferences::Fl_Preferences( Root root, const char *vendor, const char *application ) {
node = new Node( "." );
@@ -564,8 +565,8 @@ static char *decodeText( const char *src ) {
for ( ; *s; s++, len++ ) {
if ( *s == '\\' ) {
if ( isdigit( s[1] ) ) {
- s+=3;
- } else {
+ s+=3;
+ } else {
s+=1;
}
}
@@ -911,7 +912,7 @@ Fl_Preferences::RootNode::RootNode( Fl_Preferences *prefs, Root root, const char
char *filename = Fl::system_driver()->preference_rootnode(prefs, root, vendor, application);
filename_ = filename ? strdup(filename) : 0L;
vendor_ = strdup(vendor);
- application_ = strdup(application);
+ application_ = strdup(application);
read();
}
@@ -936,7 +937,7 @@ Fl_Preferences::RootNode::RootNode( Fl_Preferences *prefs, const char *path, con
filename_ = strdup(filename);
}
vendor_ = strdup(vendor);
- application_ = strdup(application);
+ application_ = strdup(application);
read();
}
@@ -990,7 +991,7 @@ int Fl_Preferences::RootNode::read() {
char buf[1024];
FILE *f = fl_fopen( filename_, "rb" );
if ( !f )
- return -1;
+ return -1;
if (fgets( buf, 1024, f )==0) { /* ignore */ }
if (fgets( buf, 1024, f )==0) { /* ignore */ }
if (fgets( buf, 1024, f )==0) { /* ignore */ }
@@ -1067,7 +1068,7 @@ char Fl_Preferences::RootNode::getPath( char *path, int pathlen ) {
return 1;
// copy the root filepath into the provided buffer
- strlcpy( path, filename_, pathlen);
+ strlcpy( path, filename_, pathlen);
char *name = 0L, *ext = 0L;
@@ -1366,7 +1367,7 @@ Fl_Preferences::Node *Fl_Preferences::Node::find( const char *path ) {
// - if the pathname is "." (current node) return this node
// - if the pathname is "./" (root node) return the topmost node
// - if the pathname starts with "./", start the search at the root node instead
-Fl_Preferences::Node *Fl_Preferences::Node::search( const char *path, int offset ) {
+Fl_Preferences::Node *Fl_Preferences::Node::search( const char *path, int offset ) {
if ( offset == 0 ) {
if ( path[0] == '.' ) {
if ( path[1] == 0 ) {
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index cb634a43c..8b392cdba 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -582,6 +582,7 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
if (views_use_CA) [(FLView*)[self contentView] reset_aux_bitmap];
#endif
+ [[self standardWindowButton:NSWindowDocumentIconButton] setImage:nil];
[super close];
// when a fullscreen window is closed, windowDidResize may be sent after the close message was sent
// and before the FLWindow receives the final dealloc message
@@ -1133,6 +1134,7 @@ static FLTextView *fltextview_instance = nil;
- (BOOL)windowShouldClose:(id)fl;
- (void)anyWindowWillClose:(NSNotification *)notif;
- (void)doNothing:(id)unused;
+- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu;
@end
@@ -1304,6 +1306,7 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
FLWindow *nsw = (FLWindow*)[notif object];
Fl_Window *window = [nsw getFl_Window];
Fl::first_window(window);
+ if (!window->parent()) [nsw orderFront:nil];
update_e_xy_and_e_xy_root(nsw);
if (fl_sys_menu_bar && Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style()) {
// select the corresponding Window menu item
@@ -1390,6 +1393,9 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
{
return;
}
+- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu {
+ return NO;
+}
@end
@interface FLAppDelegate : NSObject
@@ -3075,6 +3081,16 @@ Fl_X* Fl_Cocoa_Window_Driver::makeWindow()
[cw setLevel:winlevel];
q_set_window_title(cw, w->label(), w->iconlabel());
+ NSImage *icon = icon_image; // is a window or default icon present?
+ if (!icon) icon = ((Fl_Cocoa_Screen_Driver*)Fl::screen_driver())->default_icon;
+ if (icon && (winstyle & NSTitledWindowMask) && w->label() && strlen(w->label())>0) {
+ [cw setRepresentedFilename:[NSString stringWithFormat:@"/%@", [cw title]]];
+ NSButton *icon_button = [cw standardWindowButton:NSWindowDocumentIconButton];
+ if (icon_button) {
+ [icon setSize:[icon_button frame].size];
+ [icon_button setImage:icon];
+ }
+ }
if (!force_position()) {
if (w->modal()) {
[cw center];
@@ -4428,13 +4444,59 @@ char *Fl_Darwin_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Pre
// Our C path names for preferences will be:
// SYSTEM: "/Library/Preferences/$vendor/$application.prefs"
- // SYSTEM: "/Users/$user/Preferences/$vendor/$application.prefs"
+ // USER: "/Users/$user/Library/Preferences/$vendor/$application.prefs"
snprintf(filename + strlen(filename), FL_PATH_MAX - strlen(filename),
"/%s/%s.prefs", vendor, application);
return filename;
}
+Fl_Cocoa_Window_Driver::~Fl_Cocoa_Window_Driver()
+{
+ if (shape_data_) {
+ if (shape_data_->mask) {
+ CGImageRelease(shape_data_->mask);
+ }
+ delete shape_data_;
+ }
+ [icon_image release];
+}
+
+static NSImage* rgb_to_nsimage(const Fl_RGB_Image *rgb) {
+ if (!rgb) return nil;
+ int ld = rgb->ld();
+ if (!ld) ld = rgb->w() * rgb->d();
+ NSImage *win_icon = nil;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ if (fl_mac_os_version >= 101000) {
+ NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:rgb->w() pixelsHigh:rgb->h()
+ bitsPerSample:8 samplesPerPixel:rgb->d() hasAlpha:!(rgb->d() & 1) isPlanar:NO
+ colorSpaceName:(rgb->d()<=2) ? NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace
+ bitmapFormat:NSAlphaNonpremultipliedBitmapFormat bytesPerRow:ld bitsPerPixel:rgb->d()*8]; // 10.4
+ memcpy([bitmap bitmapData], rgb->array, rgb->h() * ld);
+ win_icon = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)];
+ [win_icon addRepresentation:bitmap];
+ [bitmap release];
+ }
+#endif
+ return win_icon;
+}
+
+void Fl_Cocoa_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) {
+ [icon_image release];
+ icon_image = nil;
+ if (count >= 1 && pWindow->border() && pWindow->label() && strlen(pWindow->label())) {
+ icon_image = rgb_to_nsimage(icons[0]);
+ }
+}
+
+void Fl_Cocoa_Screen_Driver::default_icons(const Fl_RGB_Image *icons[], int count) {
+ [default_icon release];
+ default_icon = nil;
+ if (count >= 1) {
+ default_icon = rgb_to_nsimage(icons[0]);
+ }
+}
//
// End of "$Id$".
diff --git a/src/Makefile b/src/Makefile
index 57891d332..597ff03fb 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,7 +3,7 @@
#
# Library Makefile for the Fast Light Tool Kit (FLTK).
#
-# Copyright 1998-2018 by Bill Spitzak and others.
+# Copyright 1998-2020 by Bill Spitzak and others.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this
@@ -48,6 +48,7 @@ CPPFILES = \
Fl_Group.cxx \
Fl_Help_View.cxx \
Fl_Image.cxx \
+ Fl_Image_Reader.cxx \
Fl_Image_Surface.cxx \
Fl_Input.cxx \
Fl_Input_.cxx \
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
index faf5b8520..97dd28a77 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
@@ -41,6 +41,11 @@
class Fl_Window;
class Fl_Input;
class Fl_RGB_Image;
+#ifdef __OBJC__
+@class NSImage;
+#else
+class NSImage;
+#endif
class FL_EXPORT Fl_Cocoa_Screen_Driver : public Fl_Screen_Driver
{
@@ -54,6 +59,7 @@ protected:
static int insertion_point_height;
static bool insertion_point_location_is_valid;
public:
+ NSImage *default_icon;
Fl_Cocoa_Screen_Driver();
static int next_marked_length; // next length of marked text after current marked text will have been replaced
static void breakMacEventLoop();
@@ -100,6 +106,7 @@ public:
virtual float scale(int n) {return scale_;}
virtual void scale(int n, float f) { scale_ = f;}
virtual Fl_RGB_Image *read_win_rectangle(int X, int Y, int w, int h, Fl_Window *win, bool may_capture_subwins, bool *did_capture_subwins);
+ virtual void default_icons(const Fl_RGB_Image *icons[], int count);
private:
float scale_;
};
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
index 34e1c80fd..835169e3e 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
@@ -79,6 +79,7 @@ static Fl_Text_Editor::Key_Binding extra_bindings[] = {
Fl_Cocoa_Screen_Driver::Fl_Cocoa_Screen_Driver() {
text_editor_extra_key_bindings = extra_bindings;
scale_ = 1.;
+ default_icon = nil;
}
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
index 6de52e5db..9ef5d46c9 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
@@ -33,12 +33,14 @@ class Fl_Window;
#ifdef __OBJC__
@class CALayer;
@class NSCursor;
+@class NSImage;
@class FLWindow;
@class NSOpenGLContext;
@class NSOpenGLPixelFormat;
#else
class CALayer;
class NSCursor;
+class NSImage;
class FLWindow;
class NSOpenGLContext;
class NSOpenGLPixelFormat;
@@ -153,6 +155,10 @@ public:
static void GLcontext_makecurrent(NSOpenGLContext*); // uses Objective-c
static void GL_cleardrawable(void); // uses Objective-c
static void gl_start(NSOpenGLContext*); // uses Objective-c
+
+ //icons
+ virtual void icons(const Fl_RGB_Image *icons[], int count);
+ NSImage *icon_image;
};
#endif // FL_COCOA_WINDOW_DRIVER_H
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
index 43ae44664..35daffd22 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
@@ -52,17 +52,7 @@ Fl_Cocoa_Window_Driver::Fl_Cocoa_Window_Driver(Fl_Window *win)
{
cursor = nil;
window_flags_ = 0;
-}
-
-
-Fl_Cocoa_Window_Driver::~Fl_Cocoa_Window_Driver()
-{
- if (shape_data_) {
- if (shape_data_->mask) {
- CGImageRelease(shape_data_->mask);
- }
- delete shape_data_;
- }
+ icon_image = NULL;
}
diff --git a/src/makedepend b/src/makedepend
index 8198618cc..7a01c834e 100644
--- a/src/makedepend
+++ b/src/makedepend
@@ -61,6 +61,7 @@ Fl_BMP_Image.o: ../FL/abi-version.h
Fl_BMP_Image.o: ../FL/fl_types.h
Fl_BMP_Image.o: ../FL/fl_utf8.h
Fl_BMP_Image.o: ../FL/platform_types.h
+Fl_BMP_Image.o: Fl_Image_Reader.h
Fl_Bitmap.o: ../FL/Enumerations.H
Fl_Bitmap.o: ../FL/Fl.H
Fl_Bitmap.o: ../FL/Fl_Bitmap.H
@@ -466,6 +467,7 @@ Fl_GIF_Image.o: ../FL/fl_types.h
Fl_GIF_Image.o: ../FL/fl_utf8.h
Fl_GIF_Image.o: ../FL/platform_types.h
Fl_GIF_Image.o: ../config.h
+Fl_GIF_Image.o: Fl_Image_Reader.h
Fl_GIF_Image.o: flstring.h
Fl_Gl_Choice.o: ../FL/Enumerations.H
Fl_Gl_Choice.o: ../FL/Fl.H
@@ -672,6 +674,8 @@ Fl_Image.o: ../FL/platform_types.h
Fl_Image.o: ../config.h
Fl_Image.o: config_lib.h
Fl_Image.o: flstring.h
+Fl_Image_Reader.o: ../FL/fl_utf8.h
+Fl_Image_Reader.o: Fl_Image_Reader.h
Fl_Image_Surface.o: ../FL/Enumerations.H
Fl_Image_Surface.o: ../FL/Fl.H
Fl_Image_Surface.o: ../FL/Fl_Bitmap.H
diff --git a/test/device.cxx b/test/device.cxx
index 94b7a7f25..964e4da84 100644
--- a/test/device.cxx
+++ b/test/device.cxx
@@ -754,6 +754,10 @@ int main(int argc, char ** argv) {
w3->end();
w2->end();
+ Fl_RGB_Image *rgba_icon = new Fl_RGB_Image(pixmap);
+ Fl_Window::default_icon(rgba_icon);
+ //w2->icon(rgba_icon);
+ delete rgba_icon;
w2->show(argc, argv);
Fl::run();