Fix shared image handling in file chooser (#887)
This commit is contained in:
parent
548fe016d3
commit
89133cf1e1
@ -27,12 +27,13 @@
|
||||
|
||||
#include "../FL/Fl_File_Chooser.H"
|
||||
#include <FL/fl_draw.H>
|
||||
#include <FL/Fl_Shared_Image.H>
|
||||
|
||||
void Fl_File_Chooser::cb_window_i(Fl_Double_Window*, void*) {
|
||||
fileName->value("");
|
||||
fileList->deselect();
|
||||
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
|
||||
window->hide();
|
||||
hide();
|
||||
}
|
||||
void Fl_File_Chooser::cb_window(Fl_Double_Window* o, void* v) {
|
||||
((Fl_File_Chooser*)(o->user_data()))->cb_window_i(o,v);
|
||||
@ -104,7 +105,7 @@ void Fl_File_Chooser::cb_fileName(Fl_File_Input* o, void* v) {
|
||||
}
|
||||
|
||||
void Fl_File_Chooser::cb_okButton_i(Fl_Return_Button*, void*) {
|
||||
window->hide();
|
||||
hide();
|
||||
|
||||
// Do any callback that is registered...
|
||||
if (callback_)
|
||||
@ -118,7 +119,7 @@ void Fl_File_Chooser::cb_cancelButton_i(Fl_Button*, void*) {
|
||||
fileName->value("");
|
||||
fileList->deselect();
|
||||
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
|
||||
window->hide();
|
||||
hide();
|
||||
}
|
||||
void Fl_File_Chooser::cb_cancelButton(Fl_Button* o, void* v) {
|
||||
((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_cancelButton_i(o,v);
|
||||
@ -356,6 +357,9 @@ void Fl_File_Chooser::filter_value(int f) {
|
||||
|
||||
void Fl_File_Chooser::hide() {
|
||||
window->hide();
|
||||
Fl_Shared_Image *oldimage = (Fl_Shared_Image *)previewBox->image();
|
||||
if (oldimage) oldimage->release();
|
||||
previewBox->image(NULL);
|
||||
}
|
||||
|
||||
void Fl_File_Chooser::iconsize(uchar s) {
|
||||
|
@ -32,6 +32,9 @@ comment {//
|
||||
decl {\#include <FL/fl_draw.H>} {private local
|
||||
}
|
||||
|
||||
decl {\#include <FL/Fl_Shared_Image.H>} {selected private local
|
||||
}
|
||||
|
||||
class FL_EXPORT Fl_File_Chooser {open
|
||||
} {
|
||||
decl {enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };} {public local
|
||||
@ -68,7 +71,8 @@ class FL_EXPORT Fl_File_Chooser {open
|
||||
}
|
||||
decl {void update_preview();} {private local
|
||||
}
|
||||
Function {Fl_File_Chooser(const char *d, const char *p, int t, const char *title)} {} {
|
||||
Function {Fl_File_Chooser(const char *d, const char *p, int t, const char *title)} {open
|
||||
} {
|
||||
code {if (!prefs_) {
|
||||
prefs_ = new Fl_Preferences(Fl_Preferences::USER, "fltk.org", "filechooser");
|
||||
}} {}
|
||||
@ -78,12 +82,12 @@ class FL_EXPORT Fl_File_Chooser {open
|
||||
callback {fileName->value("");
|
||||
fileList->deselect();
|
||||
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
|
||||
window->hide();} open
|
||||
private xywh {507 327 490 380} type Double hide resizable
|
||||
hide();} open
|
||||
private xywh {412 246 490 380} type Double resizable
|
||||
code0 {if (title) window->label(title);}
|
||||
code1 {\#include <stdio.h>}
|
||||
code2 {\#include <stdlib.h>}
|
||||
code3 {\#include <string.h>} modal
|
||||
code3 {\#include <string.h>} modal visible
|
||||
} {
|
||||
Fl_Group {} {open
|
||||
private xywh {10 10 470 25}
|
||||
@ -158,7 +162,7 @@ window->hide();} open
|
||||
} {
|
||||
Fl_Return_Button okButton {
|
||||
label OK
|
||||
callback {window->hide();
|
||||
callback {hide();
|
||||
|
||||
// Do any callback that is registered...
|
||||
if (callback_)
|
||||
@ -172,7 +176,7 @@ if (callback_)
|
||||
callback {fileName->value("");
|
||||
fileList->deselect();
|
||||
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
|
||||
window->hide();}
|
||||
hide();}
|
||||
private xywh {408 345 72 25}
|
||||
code0 {o->label(fl_cancel);}
|
||||
}
|
||||
@ -288,9 +292,12 @@ data_ = d;} {}
|
||||
code {showChoice->value(f);
|
||||
showChoiceCB();} {}
|
||||
}
|
||||
Function {hide()} {return_type void
|
||||
Function {hide()} {open return_type void
|
||||
} {
|
||||
code {window->hide();} {}
|
||||
code {window->hide();
|
||||
Fl_Shared_Image *oldimage = (Fl_Shared_Image *)previewBox->image();
|
||||
if (oldimage) oldimage->release();
|
||||
previewBox->image(NULL);} {}
|
||||
}
|
||||
Function {iconsize(uchar s)} {return_type void
|
||||
} {
|
||||
@ -351,7 +358,7 @@ okButton->parent()->init_sizes();} {}
|
||||
} {
|
||||
code {fileList->textfont(f);} {}
|
||||
}
|
||||
Function {textfont()} {selected return_type Fl_Font
|
||||
Function {textfont()} {return_type Fl_Font
|
||||
} {
|
||||
code {return (fileList->textfont());} {}
|
||||
}
|
||||
|
@ -1350,7 +1350,7 @@ Fl_File_Chooser::update_preview()
|
||||
|
||||
oldimage = (Fl_Shared_Image *)previewBox->image();
|
||||
|
||||
if (oldimage) oldimage->release();
|
||||
if (oldimage) ((Fl_Shared_Image *)oldimage)->release();
|
||||
|
||||
previewBox->image(0);
|
||||
|
||||
@ -1444,14 +1444,14 @@ Fl_File_Chooser::update_preview()
|
||||
h = w * image->h() / image->w();
|
||||
|
||||
if (h > pbh) {
|
||||
h = pbh;
|
||||
w = h * image->w() / image->h();
|
||||
h = pbh;
|
||||
w = h * image->w() / image->h();
|
||||
}
|
||||
|
||||
oldimage = (Fl_Shared_Image *)image->copy(w, h);
|
||||
oldimage = Fl_Shared_Image::get(filename, w, h);
|
||||
previewBox->image((Fl_Image *)oldimage);
|
||||
|
||||
image->release();
|
||||
((Fl_Shared_Image *)image)->release();
|
||||
} else {
|
||||
previewBox->image((Fl_Image *)image);
|
||||
}
|
||||
|
@ -239,18 +239,19 @@ void Fl_Shared_Image::release() {
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < num_images_; i ++)
|
||||
for (i = 0; i < num_images_; i ++) {
|
||||
if (images_[i] == this) {
|
||||
num_images_ --;
|
||||
|
||||
if (i < num_images_) {
|
||||
memmove(images_ + i, images_ + i + 1,
|
||||
(num_images_ - i) * sizeof(Fl_Shared_Image *));
|
||||
(num_images_ - i) * sizeof(Fl_Shared_Image *));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
delete this;
|
||||
|
||||
if (num_images_ == 0 && images_) {
|
||||
|
Loading…
Reference in New Issue
Block a user