From 0bc06e8f1a73e3df7f4173de90faaf5ecbd05297 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Thu, 18 Nov 2021 13:44:41 +0100 Subject: Reformat and move clipboard demo from examples to test folder The clipboard demo is more a test program than an example and very useful even if the examples are not built. Also update dependencies. --- examples/.gitignore | 1 - examples/CMakeLists.txt | 1 - examples/Makefile | 1 - examples/clipboard.cxx | 160 ------------------------------------------------ 4 files changed, 163 deletions(-) delete mode 100644 examples/clipboard.cxx (limited to 'examples') diff --git a/examples/.gitignore b/examples/.gitignore index a3e97348c..bf8efbd8b 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -4,7 +4,6 @@ # Note: *.exe will be ignored by means of ../.gitignore # browser-simple -clipboard chart-simple draggable-group howto-add_fd-and-popen diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index fc6c13237..351aa5424 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -79,7 +79,6 @@ set (FLUID_SOURCES ############################################################ set (IMAGE_SOURCES - clipboard howto-simple-svg ) diff --git a/examples/Makefile b/examples/Makefile index a4ffc12f5..0ef85508b 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -7,7 +7,6 @@ SHELL = /bin/sh # Executables ALL = browser-simple$(EXEEXT) \ chart-simple$(EXEEXT) \ - clipboard$(EXEEXT) \ draggable-group$(EXEEXT) \ howto-add_fd-and-popen$(EXEEXT) \ howto-browser-with-icons$(EXEEXT) \ diff --git a/examples/clipboard.cxx b/examples/clipboard.cxx deleted file mode 100644 index e3aa322c1..000000000 --- a/examples/clipboard.cxx +++ /dev/null @@ -1,160 +0,0 @@ -// -// Clipboard display test application for the Fast Light Tool Kit (FLTK). -// -// Copyright 1998-2014 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 see the following page on how to report bugs and issues: -// -// https://www.fltk.org/bugs.php -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef _WIN32 -#include -#endif // _WIN32 - -/* Displays and follows the content of the clipboard with either image or text data - */ - -Fl_Box *image_box; -Fl_Box *image_size; -Fl_Text_Display *display; - -inline int fl_min(int a, int b) { return (a < b ? a : b); } - - -class chess : public Fl_Box { // a box with a chess-like pattern below its image -public: - chess(int x, int y, int w, int h) : Fl_Box(FL_FLAT_BOX,x,y,w,h,0) { - align(FL_ALIGN_CENTER | FL_ALIGN_CLIP); - } - void draw() { - draw_box(); - Fl_Image *im = image(); - if (im) { // draw the chess pattern below the box centered image - int X = x() + (w()-im->w())/2, Y = y() + (h()-im->h())/2, W = im->w(), H = im->h(); - fl_push_clip(X,Y,W,H); - fl_push_clip(x(),y(),w(),h()); - fl_color(FL_WHITE); fl_rectf(X,Y,W,H); - fl_color(FL_LIGHT2); - const int side = 4, side2 = 2*side; - for (int j=Y; jw(), im->h()); // display the image original size -#ifdef _WIN32 - OpenClipboard(NULL); // display extra technical info about clipboard content - char *p=title + strlen(title); - int format = EnumClipboardFormats(0); - if (format && format < CF_MAX) { sprintf(p, " %d",format); p += strlen(p); } - while (format) { - format = EnumClipboardFormats(format); - if (format && format < CF_MAX) { sprintf(p, " %d",format); p += strlen(p); } - } - HANDLE h; - if ((h = GetClipboardData(CF_DIB))) { - LPBITMAPINFO lpBI = (LPBITMAPINFO)GlobalLock(h); - sprintf(p, " biBitCount=%d biCompression=%d biClrUsed=%d", - lpBI->bmiHeader.biBitCount, (int)lpBI->bmiHeader.biCompression, (int)lpBI->bmiHeader.biClrUsed); - } - CloseClipboard(); -#endif - Fl_Image *oldimg = image_box->image(); - delete oldimg; - if (im->w() > image_box->w() || im->h() > image_box->h()) im->scale(image_box->w(), image_box->h()); - image_box->image(im); // show the scaled image - image_size->copy_label(title); - value(image_box->parent()); - window()->redraw(); - } - else { // text is being pasted - display->buffer()->text(Fl::event_text()); - value(display); - display->redraw(); - } - return 1; - } -} *tabs; - - -void cb(Fl_Widget *wid, clipboard_viewer *tabs) -{ - if (Fl::clipboard_contains(Fl::clipboard_image)) { - Fl::paste(*tabs, 1, Fl::clipboard_image); // try to find image in the clipboard - return; - } - if (Fl::clipboard_contains(Fl::clipboard_plain_text)) Fl::paste(*tabs, 1, Fl::clipboard_plain_text); // also try to find text -} - -void clip_callback(int source, void *data) { // called after clipboard was changed or at application activation - if ( source == 1 ) cb(NULL, (clipboard_viewer *)data); -} - -int main(int argc, char **argv) -{ - fl_register_images(); // required for the X11 platform to allow pasting of images - Fl_Window* win = new Fl_Window(500, 550, "clipboard viewer"); - tabs = new clipboard_viewer(0, 0, 500, 500); - Fl_Group *g = new Fl_Group( 5, 30, 490, 460, Fl::clipboard_image); // g will display the image form - g->box(FL_FLAT_BOX); - image_box = new chess(5, 30, 490, 450); - image_size = new Fl_Box(FL_NO_BOX, 5, 485, 490, 10, 0); - g->end(); - g->selection_color(TAB_COLOR); - - Fl_Text_Buffer *buffer = new Fl_Text_Buffer(); - display = new Fl_Text_Display(5,30,490, 460, Fl::clipboard_plain_text); // display will display the text form - display->buffer(buffer); - display->selection_color(TAB_COLOR); - tabs->end(); - tabs->resizable(display); - - Fl_Group *g2 = new Fl_Group( 10,510,200,25); - Fl_Button *refresh = new Fl_Button(10,510,200,25, "Refresh from clipboard"); - refresh->callback((Fl_Callback*)cb, tabs); - g2->end(); - g2->resizable(NULL); - win->end(); - win->resizable(tabs); - win->show(argc,argv); - clip_callback(1, tabs); // use clipboard content at start - Fl::add_clipboard_notify(clip_callback, tabs); // will update with new clipboard content immediately or at application activation - - Fl_Image::RGB_scaling(FL_RGB_SCALING_BILINEAR); // set bilinear image scaling method - return Fl::run(); -} -- cgit v1.2.3