mirror of
https://github.com/fltk/fltk.git
synced 2025-12-12 22:44:53 +08:00
Improve clipboard example program, fix compilation warnings.
Use show(argc,argv) to enable command line arguments and colors, fix indentation, Windows compilation warnings, and change tab selection color, which was too dark on my Win7 system (low contrast with tab labels). I also added #define TAB_COLOR to make changing the tab selection colors easier, if needed. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10318 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -55,11 +55,13 @@ public:
|
||||
}
|
||||
fl_pop_clip();
|
||||
fl_pop_clip();
|
||||
}
|
||||
}
|
||||
draw_label(); // draw the box image
|
||||
}
|
||||
} *chess_obj;
|
||||
|
||||
#define TAB_COLOR FL_DARK3
|
||||
|
||||
class clipboard_viewer : public Fl_Tabs { // use tabs to display as appropriate the image or textual content of the clipboard
|
||||
public:
|
||||
clipboard_viewer(int x, int y, int w, int h) : Fl_Tabs(x,y,w,h) {};
|
||||
@@ -80,11 +82,11 @@ public:
|
||||
if (format && format < CF_MAX) { sprintf(p, " %d",format); p += strlen(p); }
|
||||
}
|
||||
HANDLE h;
|
||||
if (h = GetClipboardData(CF_DIB)) {
|
||||
if ((h = GetClipboardData(CF_DIB))) {
|
||||
LPBITMAPINFO lpBI = (LPBITMAPINFO)GlobalLock(h);
|
||||
sprintf(p, " biBitCount=%d biCompression=%d biClrUsed=%d",
|
||||
lpBI->bmiHeader.biBitCount, lpBI->bmiHeader.biCompression, lpBI->bmiHeader.biClrUsed);
|
||||
}
|
||||
lpBI->bmiHeader.biBitCount, (int)lpBI->bmiHeader.biCompression, (int)lpBI->bmiHeader.biClrUsed);
|
||||
}
|
||||
CloseClipboard();
|
||||
#endif
|
||||
float scale_x = (float)im->w() / image_box->w(); // rescale the image if larger than the display box
|
||||
@@ -95,21 +97,21 @@ public:
|
||||
Fl_Image *im2 = im->copy(im->w()/scale, im->h()/scale);
|
||||
delete im;
|
||||
im = im2;
|
||||
}
|
||||
}
|
||||
Fl_Image *oldim = image_box->image();
|
||||
if (oldim) delete oldim;
|
||||
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;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
} *tabs;
|
||||
|
||||
|
||||
@@ -118,7 +120,7 @@ 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
|
||||
}
|
||||
|
||||
@@ -126,7 +128,7 @@ void clip_callback(int source, void *data) { // called after clipboard was chang
|
||||
if ( source == 1 ) cb(NULL, (clipboard_viewer *)data);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if !(defined(__APPLE__) || defined(WIN32))
|
||||
extern void fl_register_images();
|
||||
@@ -139,15 +141,15 @@ int main()
|
||||
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(FL_INACTIVE_COLOR);
|
||||
|
||||
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(FL_INACTIVE_COLOR);
|
||||
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);
|
||||
@@ -155,7 +157,7 @@ int main()
|
||||
g2->resizable(NULL);
|
||||
win->end();
|
||||
win->resizable(tabs);
|
||||
win->show();
|
||||
win->show(argc,argv);
|
||||
#if defined(__APPLE__) || defined(WIN32)
|
||||
clip_callback(1, tabs); // use clipboard content at start
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user