Small indent / whitespace fixups, Manolo's doc modification for

Fl_Native_File_Chooser::options.



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7015 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Greg Ercolano 2010-01-17 17:09:00 +00:00
parent 7221382917
commit 97ac940d91
3 changed files with 106 additions and 105 deletions

View File

@ -62,7 +62,7 @@ Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
_directory = NULL;
_errmsg = NULL;
_file_chooser = new Fl_File_Chooser(NULL, NULL, 0, NULL);
type(val); // do this after _file_chooser created
type(val); // do this after _file_chooser created
_nfilters = 0;
// Added by MG
@ -142,7 +142,7 @@ int Fl_Native_File_Chooser::type() const {
-------------- ----------------------------------------------- ------- ------- -------
NEW_FOLDER Shows the 'New Folder' button. Ignored Used Used
PREVIEW Enables the 'Preview' mode by default. Ignored Ignored Used
SAVEAS_CONFIRM Confirm dialog if BROWSE_SAVE_FILE file exists. Ignored Used Ignored
SAVEAS_CONFIRM Confirm dialog if BROWSE_SAVE_FILE file exists. Ignored Used Used
\endcode
*/
void Fl_Native_File_Chooser::options(int val) {
@ -258,10 +258,10 @@ const char* Fl_Native_File_Chooser::filename() const {
\b Example:
\code
if ( fnfc->show() == 0 ) {
// Print all filenames user selected
for (int n=0; n<fnfc->count(); n++ ) {
printf("%d) '%s'\n", n, fnfc->filename(n));
}
// Print all filenames user selected
for (int n=0; n<fnfc->count(); n++ ) {
printf("%d) '%s'\n", n, fnfc->filename(n));
}
}
\endcode
*/
@ -352,10 +352,10 @@ int Fl_Native_File_Chooser::filter_value() const {
\b Example:
\code
if ( fnfc->show() == 0 ) {
// Print all filenames user selected
for (int n=0; n<fnfc->count(); n++ ) {
printf("%d) '%s'\n", n, fnfc->filename(n));
}
// Print all filenames user selected
for (int n=0; n<fnfc->count(); n++ ) {
printf("%d) '%s'\n", n, fnfc->filename(n));
}
}
\endcode
*/
@ -412,33 +412,33 @@ void Fl_Native_File_Chooser::parse_filter() {
switch (*in) {
// FINISHED PARSING NAME?
case '\t':
if ( mode != 'n' ) goto regchar;
mode = 'w';
break;
if ( mode != 'n' ) goto regchar;
mode = 'w';
break;
// ESCAPE NEXT CHAR
case '\\':
++in;
goto regchar;
++in;
goto regchar;
// FINISHED PARSING ONE OF POSSIBLY SEVERAL FILTERS?
case '\r':
case '\n':
case '\0':
// APPEND NEW FILTER TO LIST
if ( wildcard[0] ) {
// OUT: "name(wild)\tname(wild)"
char comp[2048];
sprintf(comp, "%s%.511s(%.511s)", ((_parsedfilt)?"\t":""),
name, wildcard);
_parsedfilt = strapp(_parsedfilt, comp);
_nfilters++;
//DEBUG printf("DEBUG: PARSED FILT NOW <%s>\n", _parsedfilt);
}
// RESET
wildcard[0] = name[0] = '\0';
mode = strchr(in, '\t') ? 'n' : 'w';
// DONE?
if ( *in == '\0' ) return; // done
else continue; // not done yet, more filters
// APPEND NEW FILTER TO LIST
if ( wildcard[0] ) {
// OUT: "name(wild)\tname(wild)"
char comp[2048];
sprintf(comp, "%s%.511s(%.511s)", ((_parsedfilt)?"\t":""),
name, wildcard);
_parsedfilt = strapp(_parsedfilt, comp);
_nfilters++;
//DEBUG printf("DEBUG: PARSED FILT NOW <%s>\n", _parsedfilt);
}
// RESET
wildcard[0] = name[0] = '\0';
mode = strchr(in, '\t') ? 'n' : 'w';
// DONE?
if ( *in == '\0' ) return; // done
else continue; // not done yet, more filters
// Parse all other chars
default: // handle all non-special chars

View File

@ -292,9 +292,9 @@ void Fl_Native_File_Chooser::event_handler(NavEventCallbackMessage callBackSelec
}
if ( nfb->_btype == BROWSE_SAVE_FILE && nfb->preset_file() ) {
const char *p, *q;
p = nfb->preset_file();//don't use the path part of preset_file
p = nfb->preset_file(); // don't use the path part of preset_file
q = strrchr(p, '/');
if(q == NULL) q = p; else q++;
if (q == NULL) q = p; else q++;
CFStringRef namestr = CFStringCreateWithCString(NULL,
q,
kCFStringEncodingUTF8);
@ -314,7 +314,7 @@ void Fl_Native_File_Chooser::event_handler(NavEventCallbackMessage callBackSelec
nfb->_tempitem.version = kNavMenuItemSpecVersion;
nfb->_tempitem.menuCreator = 'extn';
nfb->_tempitem.menuType = nfb->_filt_value;
*nfb->_tempitem.menuItemName = '\0'; // needed on 10.3+
*nfb->_tempitem.menuItemName = '\0'; // needed on 10.3+
NavCustomControl(cbparm->context,
kNavCtlSelectCustomType,
&(nfb->_tempitem));
@ -408,11 +408,11 @@ Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
// DESTRUCTOR
Fl_Native_File_Chooser::~Fl_Native_File_Chooser() {
// _opts // nothing to manage
// _opts // nothing to manage
#ifndef __APPLE_COCOA__
if (_ref) { NavDialogDispose(_ref); _ref = NULL; }
#endif
// _options // nothing to manage
// _options // nothing to manage
// _keepstate // nothing to manage
// _tempitem // nothing to manage
clear_pathnames();
@ -421,7 +421,7 @@ Fl_Native_File_Chooser::~Fl_Native_File_Chooser() {
_preset_file = strfree(_preset_file);
_filter = strfree(_filter);
//_filt_names // managed by clear_filters()
//_filt_patt[i] // managed by clear_filters()
//_filt_patt[i] // managed by clear_filters()
//_filt_total // managed by clear_filters()
clear_filters();
//_filt_value // nothing to manage
@ -566,7 +566,7 @@ int Fl_Native_File_Chooser::post() {
// Prompt user for filename to 'save as'
if ((err = NavCreatePutFileDialog(&_opts, // options
0, // file types
kNavGenericSignature, //file creator
kNavGenericSignature, // file creator
event_handler, // event handler
(void*)this, // callback data
&_ref)) != noErr ) { // dialog ref
@ -800,13 +800,13 @@ void Fl_Native_File_Chooser::parse_filter(const char *in) {
#ifndef __APPLE_COCOA__
// STATIC: FILTER CALLBACK
Boolean Fl_Native_File_Chooser::filter_proc_cb(AEDesc *theItem,
void *info,
void *callBackUD,
NavFilterModes filterMode) {
void *info,
void *callBackUD,
NavFilterModes filterMode) {
return((Fl_Native_File_Chooser*)callBackUD)->filter_proc_cb2(theItem,
info,
callBackUD,
filterMode);
info,
callBackUD,
filterMode);
}
// FILTER CALLBACK
@ -814,9 +814,9 @@ Boolean Fl_Native_File_Chooser::filter_proc_cb(AEDesc *theItem,
// false if no match.
//
Boolean Fl_Native_File_Chooser::filter_proc_cb2(AEDesc *theItem,
void *info,
void *callBackUD,
NavFilterModes filterMode) {
void *info,
void *callBackUD,
NavFilterModes filterMode) {
// All files chosen or no filters
if ( _filt_value == _filt_total ) return(true);
@ -860,11 +860,11 @@ const char* Fl_Native_File_Chooser::preset_file() {
int Fl_Native_File_Chooser::get_saveas_basename(void) {
char *q = strdup( [[(NSSavePanel*)_panel filename] fileSystemRepresentation] );
id delegate = [(NSSavePanel*)_panel delegate];
if(delegate != nil) {
if (delegate != nil) {
const char *d = [[(NSSavePanel*)_panel directory] fileSystemRepresentation];
int l = strlen(d) + 1;
int lu = strlen(UNLIKELYPREFIX);
//remove UNLIKELYPREFIX between directory and filename parts
// Remove UNLIKELYPREFIX between directory and filename parts
memmove(q + l, q + l + lu, strlen(q + l + lu) + 1);
}
set_single_pathname( q );
@ -909,7 +909,7 @@ void Fl_Native_File_Chooser::type(int val) {
}
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
{
if( [nspopup indexOfSelectedItem] == [nspopup numberOfItems] - 1) return YES;
if ( [nspopup indexOfSelectedItem] == [nspopup numberOfItems] - 1) return YES;
const char *pathname = [filename fileSystemRepresentation];
if ( fl_filename_isdir(pathname) ) return YES;
if ( fl_filename_match(pathname, filter_pattern[ [nspopup indexOfSelectedItem] ]) ) return YES;
@ -928,7 +928,7 @@ void Fl_Native_File_Chooser::type(int val) {
@implementation FLsaveDelegate
- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag
{
if(! okFlag) return filename;
if (! okFlag) return filename;
// User has clicked save, and no overwrite confirmation should occur.
// To get the latter, we need to change the name we return (hence the prefix):
return [@ UNLIKELYPREFIX stringByAppendingString:filename];
@ -961,7 +961,7 @@ static NSPopUpButton *createPopupAccessory(NSSavePanel *panel, const char *filte
CFRelease(tab);
[popup addItemsWithTitles:(NSArray*)array];
NSMenuItem *item = [popup itemWithTitle:@""];
if(item) [popup removeItemWithTitle:@""];
if (item) [popup removeItemWithTitle:@""];
CFRelease(array);
[popup selectItemAtIndex:rank];
[panel setAccessoryView:view];
@ -1002,18 +1002,18 @@ int Fl_Native_File_Chooser::post() {
}
// SHOW THE DIALOG
if( [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]] ) {
if ( [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]] ) {
NSPopUpButton *popup = nil;
if(_filt_total) {
if (_filt_total) {
char *p; p = _filter;
char *q; q = new char[strlen(p) + 1];
char *r, *s, *t;
t = q;
do { //copy to t what is in _filter removing what is between \t and \n, if any
do { // copy to t what is in _filter removing what is between \t and \n, if any
r = strchr(p, '\n');
if(!r) r = p + strlen(p) - 1;
if (!r) r = p + strlen(p) - 1;
s = strchr(p, '\t');
if(s && s < r) { memcpy(q, p, s - p); q += s - p; *(q++) = '\n'; }
if (s && s < r) { memcpy(q, p, s - p); q += s - p; *(q++) = '\n'; }
else { memcpy(q, p, r - p + 1); q += r - p + 1; }
*q = 0;
p = r + 1;
@ -1025,7 +1025,7 @@ int Fl_Native_File_Chooser::post() {
[popup setAction:@selector(validateVisibleColumns)];
[popup setTarget:(NSObject*)_panel];
static FLopenDelegate *openDelegate = nil;
if(openDelegate == nil) {
if (openDelegate == nil) {
// not to be ever freed
openDelegate = [[FLopenDelegate alloc] init];
}
@ -1035,17 +1035,17 @@ int Fl_Native_File_Chooser::post() {
NSString *dir = nil;
NSString *fname = nil;
NSString *preset = nil;
if(_preset_file) {
if (_preset_file) {
preset = [[NSString alloc] initWithUTF8String:_preset_file];
if(strchr(_preset_file, '/') != NULL)
if (strchr(_preset_file, '/') != NULL)
dir = [[NSString alloc] initWithString:[preset stringByDeletingLastPathComponent]];
fname = [preset lastPathComponent];
}
if(_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
retval = [(NSOpenPanel*)_panel runModalForDirectory:dir file:fname types:nil];
[dir release];
[preset release];
if(_filt_total) {
if (_filt_total) {
_filt_value = [popup indexOfSelectedItem];
}
if ( retval == NSOKButton ) {
@ -1063,24 +1063,24 @@ int Fl_Native_File_Chooser::post() {
NSString *fname = nil;
NSString *preset = nil;
NSPopUpButton *popup = nil;
if( !(_options & SAVEAS_CONFIRM) ) {
if ( !(_options & SAVEAS_CONFIRM) ) {
static FLsaveDelegate *saveDelegate = nil;
if(saveDelegate == nil)saveDelegate = [[FLsaveDelegate alloc] init];//not to be ever freed
if (saveDelegate == nil)saveDelegate = [[FLsaveDelegate alloc] init]; // not to be ever freed
[(NSSavePanel*)_panel setDelegate:saveDelegate];
}
if(_preset_file) {
if (_preset_file) {
preset = [[NSString alloc] initWithUTF8String:_preset_file];
if(strchr(_preset_file, '/') != NULL) {
if (strchr(_preset_file, '/') != NULL) {
dir = [[NSString alloc] initWithString:[preset stringByDeletingLastPathComponent]];
}
fname = [preset lastPathComponent];
}
if(_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
if(_filt_total) {
if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
if (_filt_total) {
popup = createPopupAccessory((NSSavePanel*)_panel, _filter, "Format:", _filt_value);
}
retval = [(NSSavePanel*)_panel runModalForDirectory:dir file:fname];
if(_filt_total) {
if (_filt_total) {
_filt_value = [popup indexOfSelectedItem];
}
[dir release];

View File

@ -108,11 +108,12 @@ static void dnullcat(char*&wp, const char *string, int n = -1 ) {
//
char *wp2 = wp;
if ( *(wp2+0) != '\0' && *(wp2+1) != '\0' ) {
for ( ; 1; wp2++ )
for ( ; 1; wp2++ ) {
if ( *(wp2+0) == '\0' && *(wp2+1) == '\0' ) {
wp2++;
break;
}
}
}
if ( n == -1 ) n = strlen(string);
@ -278,7 +279,7 @@ int Fl_Native_File_Chooser::showfile() {
ClearOFN();
clear_pathnames();
size_t fsize = MAX_PATH;
_ofn.Flags |= OFN_NOVALIDATE; // prevent disabling of front slashes
_ofn.Flags |= OFN_NOVALIDATE; // prevent disabling of front slashes
_ofn.Flags |= OFN_HIDEREADONLY; // hide goofy readonly flag
// USE NEW BROWSER
_ofn.Flags |= OFN_EXPLORER; // use newer explorer windows
@ -394,41 +395,41 @@ int Fl_Native_File_Chooser::showfile() {
switch ( _btype ) {
case BROWSE_FILE:
case BROWSE_SAVE_FILE:
set_single_pathname(wchartoutf8(_ofn.lpstrFile));
// Win2Unix(_pathnames[_tpathnames-1]);
break;
case BROWSE_MULTI_FILE: {
// EXTRACT MULTIPLE FILENAMES
const WCHAR *dirname = _ofn.lpstrFile;
int dirlen = wcslen(dirname);
if ( dirlen > 0 ) {
// WALK STRING SEARCHING FOR 'DOUBLE-NULL'
// eg. "/dir/name\0foo1\0foo2\0foo3\0\0"
//
char pathname[MAX_PATH];
for ( const WCHAR *s = dirname + dirlen + 1;
*s; s+= (wcslen(s)+1)) {
strcpy(pathname, wchartoutf8(dirname));
strcat(pathname, "\\");
strcat(pathname, wchartoutf8(s));
add_pathname(pathname);
}
}
// XXX
// Work around problem where pasted forward-slash pathname
// into the file browser causes new "Explorer" interface
// not to grok forward slashes, passing back as a 'filename'..!
set_single_pathname(wchartoutf8(_ofn.lpstrFile));
// Win2Unix(_pathnames[_tpathnames-1]);
break;
case BROWSE_MULTI_FILE: {
// EXTRACT MULTIPLE FILENAMES
const WCHAR *dirname = _ofn.lpstrFile;
int dirlen = wcslen(dirname);
if ( dirlen > 0 ) {
// WALK STRING SEARCHING FOR 'DOUBLE-NULL'
// eg. "/dir/name\0foo1\0foo2\0foo3\0\0"
//
if ( _tpathnames == 0 ) {
add_pathname(wchartoutf8(dirname));
// Win2Unix(_pathnames[_tpathnames-1]);
char pathname[MAX_PATH];
for ( const WCHAR *s = dirname + dirlen + 1;
*s; s+= (wcslen(s)+1)) {
strcpy(pathname, wchartoutf8(dirname));
strcat(pathname, "\\");
strcat(pathname, wchartoutf8(s));
add_pathname(pathname);
}
break;
}
case BROWSE_DIRECTORY:
case BROWSE_MULTI_DIRECTORY:
case BROWSE_SAVE_DIRECTORY:
abort(); // never happens: handled by showdir()
// XXX
// Work around problem where pasted forward-slash pathname
// into the file browser causes new "Explorer" interface
// not to grok forward slashes, passing back as a 'filename'..!
//
if ( _tpathnames == 0 ) {
add_pathname(wchartoutf8(dirname));
// Win2Unix(_pathnames[_tpathnames-1]);
}
break;
}
case BROWSE_DIRECTORY:
case BROWSE_MULTI_DIRECTORY:
case BROWSE_SAVE_DIRECTORY:
abort(); // never happens: handled by showdir()
}
return(0);
}
@ -447,7 +448,7 @@ int CALLBACK Fl_Native_File_Chooser::Dir_CB(HWND win, UINT msg, LPARAM param, LP
if ( SHGetPathFromIDList((ITEMIDLIST*)param, path) ) {
::SendMessage(win, BFFM_ENABLEOK, 0, 1);
} else {
//disable ok button if not a path
// disable ok button if not a path
::SendMessage(win, BFFM_ENABLEOK, 0, 0);
}
break;
@ -625,7 +626,7 @@ void Fl_Native_File_Chooser::clear_filters() {
// ADD A FILTER
void Fl_Native_File_Chooser::add_filter(const char *name_in, // name of filter (optional: can be null)
const char *winfilter) { // windows style filter (eg. "*.cxx;*.h")
const char *winfilter) { // windows style filter (eg. "*.cxx;*.h")
// No name? Make one..
char name[1024];
if ( !name_in || name_in[0] == '\0' ) {