diff options
| author | Greg Ercolano <erco@seriss.com> | 2017-07-17 01:13:28 +0000 |
|---|---|---|
| committer | Greg Ercolano <erco@seriss.com> | 2017-07-17 01:13:28 +0000 |
| commit | 01733583512f5569f3526855faa69567c4393204 (patch) | |
| tree | 3cc9257275a43b300d8d464b5d3c9f7742208851 | |
| parent | e9741d01f0b1660b61603b840dd3edd3dc7226e4 (diff) | |
Added new example program 'nativefilechooser-simple.cxx'
(Simpler than the application example)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12321 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | examples/Makefile | 1 | ||||
| -rw-r--r-- | examples/nativefilechooser-simple.cxx | 76 |
2 files changed, 77 insertions, 0 deletions
diff --git a/examples/Makefile b/examples/Makefile index 3572f953b..a492f7a9a 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -13,6 +13,7 @@ ALL = clipboard$(EXEEXT) \ howto-parse-args$(EXEEXT) \ howto-text-over-image-button$(EXEEXT) \ menubar-add$(EXEEXT) \ + nativefilechooser-simple$(EXEEXT) \ nativefilechooser-simple-app$(EXEEXT) \ progress-simple$(EXEEXT) \ shapedwindow$(EXEEXT) \ diff --git a/examples/nativefilechooser-simple.cxx b/examples/nativefilechooser-simple.cxx new file mode 100644 index 000000000..1650a920a --- /dev/null +++ b/examples/nativefilechooser-simple.cxx @@ -0,0 +1,76 @@ +// +// "$Id$" +// +// Simple example of using Fl_Native_File_Chooser. +// +// Copyright 1998-2010 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 +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// +#include <FL/Fl.H> +#include <FL/Fl_Window.H> +#include <FL/Fl_Menu_Button.H> +#include <FL/Fl_Native_File_Chooser.H> +#include <FL/fl_message.H> +#include <stdlib.h> /* exit() */ + +Fl_Window *G_win = 0; +Fl_Menu_Button *G_menu = 0; +Fl_Native_File_Chooser *G_chooser = 0; + +static void Menu_CB(Fl_Widget*,void*data) { + // Handle the popup menu item the user picked.. + const char *choice = (const char*)data; + if ( strcmp(choice, "quit") == 0 ) { // Handle "quit" + exit(0); + } else if ( strcmp(choice, "open") == 0 ) { // Handle "open" + if ( G_chooser == 0 ) { + // Create an instance of file chooser we can reuse.. + G_chooser = new Fl_Native_File_Chooser(); + G_chooser->directory("."); // directory to start browsing with + G_chooser->preset_file("nativefilechooser-simple.cxx"); // file to start with + G_chooser->filter("C++\t*.{cxx,cpp,h,H}\n"); + G_chooser->type(Fl_Native_File_Chooser::BROWSE_FILE); // only picks files that exist + G_chooser->title("Pick a file please.."); // custom title for chooser window + } + // Show the chooser + // This blocks while chooser is open. + // + switch ( G_chooser->show() ) { + case -1: break; // Error + case 1: break; // Cancel + default: // Choice + G_chooser->preset_file(G_chooser->filename()); + fl_message("You chose: %s", G_chooser->filename()); + break; + } + } +} + +int main(int argc, char *argv[]) { + Fl::scheme("gtk+"); + G_win = new Fl_Window(640,480,"Test Native File Chooser"); + G_win->tooltip("Use right-click for popup menu.."); + { + // Setup right-click menu for window.. + G_menu = new Fl_Menu_Button(0,20,640,480,"Popup Menu"); + G_menu->type(Fl_Menu_Button::POPUP3); + G_menu->add("Open File Chooser..", 0, Menu_CB, (void*)"open"); + G_menu->add("Quit", 0, Menu_CB, (void*)"quit"); + } + G_win->end(); + G_win->show(argc,argv); + return(Fl::run()); +} + +// +// End of "$Id$". +// |
