Refactoring FMessageBox::init and FFileDialog::init
This commit is contained in:
parent
bce4021f45
commit
7424dd74b4
|
@ -1,5 +1,8 @@
|
||||||
2017-01-31 Markus Gans <guru.mail@muenster.de>
|
2017-01-31 Markus Gans <guru.mail@muenster.de>
|
||||||
* Refactoring FSwitch::drawCheckButton and FWidget::redraw
|
* Refactoring FSwitch::drawCheckButton
|
||||||
|
* Refactoring FWidget::redraw
|
||||||
|
* Refactoring FMessageBox::init
|
||||||
|
* Refactoring FFileDialog::init
|
||||||
|
|
||||||
2017-01-30 Markus Gans <guru.mail@muenster.de>
|
2017-01-30 Markus Gans <guru.mail@muenster.de>
|
||||||
* Refactoring FLabel::draw
|
* Refactoring FLabel::draw
|
||||||
|
|
|
@ -161,13 +161,16 @@ class FFileDialog : public FDialog
|
||||||
|
|
||||||
// Method
|
// Method
|
||||||
void init();
|
void init();
|
||||||
|
void allocation (int, int);
|
||||||
|
void deallocation();
|
||||||
|
void initCallbacks();
|
||||||
inline bool pattern_match (const char* const, char[]);
|
inline bool pattern_match (const char* const, char[]);
|
||||||
void clear();
|
void clear();
|
||||||
int numOfDirs();
|
int numOfDirs();
|
||||||
void sortDir();
|
void sortDir();
|
||||||
int readDir();
|
int readDir();
|
||||||
void getEntry (struct dirent*);
|
void getEntry (const char* const, struct dirent*);
|
||||||
void followSymLink (dir_entry&);
|
void followSymLink (const char* const, dir_entry&);
|
||||||
void dirEntriesToList();
|
void dirEntriesToList();
|
||||||
int changeDir (const FString&);
|
int changeDir (const FString&);
|
||||||
void printPath (const FString&);
|
void printPath (const FString&);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* *
|
* *
|
||||||
* This file is part of the Final Cut widget toolkit *
|
* This file is part of the Final Cut widget toolkit *
|
||||||
* *
|
* *
|
||||||
* Copyright 2014-2017 Markus Gans *
|
* Copyright 2014-2018 Markus Gans *
|
||||||
* *
|
* *
|
||||||
* The Final Cut is free software; you can redistribute it and/or *
|
* The Final Cut is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU Lesser General Public License *
|
* modify it under the terms of the GNU Lesser General Public License *
|
||||||
|
@ -99,7 +99,7 @@ class FMessageBox : public FDialog
|
||||||
, int, int, int
|
, int, int, int
|
||||||
, FWidget* = 0 );
|
, FWidget* = 0 );
|
||||||
// Destructor
|
// Destructor
|
||||||
~FMessageBox();
|
~FMessageBox();
|
||||||
|
|
||||||
// Assignment operator (=)
|
// Assignment operator (=)
|
||||||
FMessageBox& operator = (const FMessageBox&);
|
FMessageBox& operator = (const FMessageBox&);
|
||||||
|
@ -148,6 +148,9 @@ class FMessageBox : public FDialog
|
||||||
private:
|
private:
|
||||||
// Methods
|
// Methods
|
||||||
void init (int, int, int);
|
void init (int, int, int);
|
||||||
|
void allocation (int, int, int);
|
||||||
|
void deallocation();
|
||||||
|
void initCallbacks();
|
||||||
void calculateDimensions();
|
void calculateDimensions();
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
void resizeButtons();
|
void resizeButtons();
|
||||||
|
|
|
@ -117,11 +117,7 @@ FFileDialog::FFileDialog ( const FString& dirname
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FFileDialog::~FFileDialog() // destructor
|
FFileDialog::~FFileDialog() // destructor
|
||||||
{
|
{
|
||||||
delete open;
|
deallocation();
|
||||||
delete cancel;
|
|
||||||
delete hidden;
|
|
||||||
delete filebrowser;
|
|
||||||
delete filename;
|
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,6 +406,15 @@ void FFileDialog::init()
|
||||||
else
|
else
|
||||||
FDialog::setText("Open file");
|
FDialog::setText("Open file");
|
||||||
|
|
||||||
|
allocation (x, y); // Create widgets
|
||||||
|
initCallbacks();
|
||||||
|
setModal();
|
||||||
|
readDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FFileDialog::allocation (int x, int y)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
filename = new FLineEdit(this);
|
filename = new FLineEdit(this);
|
||||||
|
@ -441,7 +446,21 @@ void FFileDialog::init()
|
||||||
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FFileDialog::deallocation()
|
||||||
|
{
|
||||||
|
delete open;
|
||||||
|
delete cancel;
|
||||||
|
delete hidden;
|
||||||
|
delete filebrowser;
|
||||||
|
delete filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FFileDialog::initCallbacks()
|
||||||
|
{
|
||||||
filename->addCallback
|
filename->addCallback
|
||||||
(
|
(
|
||||||
"activate",
|
"activate",
|
||||||
|
@ -477,9 +496,6 @@ void FFileDialog::init()
|
||||||
"clicked",
|
"clicked",
|
||||||
F_METHOD_CALLBACK (this, &FFileDialog::cb_processOpen)
|
F_METHOD_CALLBACK (this, &FFileDialog::cb_processOpen)
|
||||||
);
|
);
|
||||||
|
|
||||||
setModal();
|
|
||||||
readDir();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -608,7 +624,7 @@ int FFileDialog::readDir()
|
||||||
&& std::strcmp(next->d_name, "..") == 0 )
|
&& std::strcmp(next->d_name, "..") == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
getEntry(next);
|
getEntry(dir, next);
|
||||||
}
|
}
|
||||||
else if ( errno != 0 )
|
else if ( errno != 0 )
|
||||||
{
|
{
|
||||||
|
@ -636,7 +652,7 @@ int FFileDialog::readDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FFileDialog::getEntry (struct dirent* d_entry)
|
void FFileDialog::getEntry (const char* const dir, struct dirent* d_entry)
|
||||||
{
|
{
|
||||||
const char* const filter = filter_pattern.c_str();
|
const char* const filter = filter_pattern.c_str();
|
||||||
dir_entry entry;
|
dir_entry entry;
|
||||||
|
@ -663,7 +679,7 @@ void FFileDialog::getEntry (struct dirent* d_entry)
|
||||||
entry.socket = S_ISSOCK (s.st_mode);
|
entry.socket = S_ISSOCK (s.st_mode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
followSymLink(entry);
|
followSymLink (dir, entry);
|
||||||
|
|
||||||
if ( entry.directory )
|
if ( entry.directory )
|
||||||
dir_entries.push_back (entry);
|
dir_entries.push_back (entry);
|
||||||
|
@ -674,7 +690,7 @@ void FFileDialog::getEntry (struct dirent* d_entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FFileDialog::followSymLink (dir_entry& entry)
|
void FFileDialog::followSymLink (const char* const dir, dir_entry& entry)
|
||||||
{
|
{
|
||||||
if ( ! entry.symbolic_link )
|
if ( ! entry.symbolic_link )
|
||||||
return; // No symbolic link
|
return; // No symbolic link
|
||||||
|
@ -682,7 +698,6 @@ void FFileDialog::followSymLink (dir_entry& entry)
|
||||||
char resolved_path[MAXPATHLEN] = {};
|
char resolved_path[MAXPATHLEN] = {};
|
||||||
char symLink[MAXPATHLEN] = {};
|
char symLink[MAXPATHLEN] = {};
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
const char* const dir = directory.c_str();
|
|
||||||
|
|
||||||
std::strncpy (symLink, dir, sizeof(symLink) - 1);
|
std::strncpy (symLink, dir, sizeof(symLink) - 1);
|
||||||
std::strncat ( symLink
|
std::strncat ( symLink
|
||||||
|
|
|
@ -522,12 +522,11 @@ void FLabel::drawMultiLine()
|
||||||
{
|
{
|
||||||
uInt y = 0;
|
uInt y = 0;
|
||||||
uInt text_lines = uInt(multiline_text.size());
|
uInt text_lines = uInt(multiline_text.size());
|
||||||
|
bool hotkey_printed = false;
|
||||||
|
|
||||||
while ( y < text_lines && y < uInt(getHeight()) )
|
while ( y < text_lines && y < uInt(getHeight()) )
|
||||||
{
|
{
|
||||||
wchar_t* label_text;
|
wchar_t* label_text;
|
||||||
bool hotkey_printed = false;
|
|
||||||
int align_offset, hotkeypos = -1;
|
int align_offset, hotkeypos = -1;
|
||||||
uInt length = multiline_text[y].getLength();
|
uInt length = multiline_text[y].getLength();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* *
|
* *
|
||||||
* This file is part of the Final Cut widget toolkit *
|
* This file is part of the Final Cut widget toolkit *
|
||||||
* *
|
* *
|
||||||
* Copyright 2014-2017 Markus Gans *
|
* Copyright 2014-2018 Markus Gans *
|
||||||
* *
|
* *
|
||||||
* The Final Cut is free software; you can redistribute it and/or *
|
* The Final Cut is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU Lesser General Public License *
|
* modify it under the terms of the GNU Lesser General Public License *
|
||||||
|
@ -111,8 +111,7 @@ FMessageBox::FMessageBox ( const FString& caption
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FMessageBox::~FMessageBox() // destructor
|
FMessageBox::~FMessageBox() // destructor
|
||||||
{
|
{
|
||||||
for (uInt n = 0; n < num_buttons; n++)
|
deallocation();
|
||||||
delete button[n];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,6 +334,16 @@ void FMessageBox::init (int button0, int button1, int button2)
|
||||||
button_digit[1] = button1;
|
button_digit[1] = button1;
|
||||||
button_digit[2] = button2;
|
button_digit[2] = button2;
|
||||||
|
|
||||||
|
allocation (button0, button1, button2);
|
||||||
|
resizeButtons();
|
||||||
|
adjustButtons();
|
||||||
|
initCallbacks();
|
||||||
|
setModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FMessageBox::allocation (int button0, int button1, int button2)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
button[0] = new FButton (this);
|
button[0] = new FButton (this);
|
||||||
|
@ -367,10 +376,18 @@ void FMessageBox::init (int button0, int button1, int button2)
|
||||||
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resizeButtons();
|
//----------------------------------------------------------------------
|
||||||
adjustButtons();
|
inline void FMessageBox::deallocation()
|
||||||
|
{
|
||||||
|
for (uInt n = 0; n < num_buttons; n++)
|
||||||
|
delete button[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline void FMessageBox::initCallbacks()
|
||||||
|
{
|
||||||
if ( button_digit[0] != 0 )
|
if ( button_digit[0] != 0 )
|
||||||
{
|
{
|
||||||
button[0]->addCallback
|
button[0]->addCallback
|
||||||
|
@ -400,8 +417,6 @@ void FMessageBox::init (int button0, int button1, int button2)
|
||||||
static_cast<FWidget::data_ptr>(&button_digit[2])
|
static_cast<FWidget::data_ptr>(&button_digit[2])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setModal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue