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>
|
||||
* 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>
|
||||
* Refactoring FLabel::draw
|
||||
|
|
|
@ -161,13 +161,16 @@ class FFileDialog : public FDialog
|
|||
|
||||
// Method
|
||||
void init();
|
||||
void allocation (int, int);
|
||||
void deallocation();
|
||||
void initCallbacks();
|
||||
inline bool pattern_match (const char* const, char[]);
|
||||
void clear();
|
||||
int numOfDirs();
|
||||
void sortDir();
|
||||
int readDir();
|
||||
void getEntry (struct dirent*);
|
||||
void followSymLink (dir_entry&);
|
||||
void getEntry (const char* const, struct dirent*);
|
||||
void followSymLink (const char* const, dir_entry&);
|
||||
void dirEntriesToList();
|
||||
int changeDir (const FString&);
|
||||
void printPath (const FString&);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* modify it under the terms of the GNU Lesser General Public License *
|
||||
|
@ -148,6 +148,9 @@ class FMessageBox : public FDialog
|
|||
private:
|
||||
// Methods
|
||||
void init (int, int, int);
|
||||
void allocation (int, int, int);
|
||||
void deallocation();
|
||||
void initCallbacks();
|
||||
void calculateDimensions();
|
||||
virtual void draw();
|
||||
void resizeButtons();
|
||||
|
|
|
@ -117,11 +117,7 @@ FFileDialog::FFileDialog ( const FString& dirname
|
|||
//----------------------------------------------------------------------
|
||||
FFileDialog::~FFileDialog() // destructor
|
||||
{
|
||||
delete open;
|
||||
delete cancel;
|
||||
delete hidden;
|
||||
delete filebrowser;
|
||||
delete filename;
|
||||
deallocation();
|
||||
clear();
|
||||
}
|
||||
|
||||
|
@ -410,6 +406,15 @@ void FFileDialog::init()
|
|||
else
|
||||
FDialog::setText("Open file");
|
||||
|
||||
allocation (x, y); // Create widgets
|
||||
initCallbacks();
|
||||
setModal();
|
||||
readDir();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FFileDialog::allocation (int x, int y)
|
||||
{
|
||||
try
|
||||
{
|
||||
filename = new FLineEdit(this);
|
||||
|
@ -441,7 +446,21 @@ void FFileDialog::init()
|
|||
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FFileDialog::deallocation()
|
||||
{
|
||||
delete open;
|
||||
delete cancel;
|
||||
delete hidden;
|
||||
delete filebrowser;
|
||||
delete filename;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FFileDialog::initCallbacks()
|
||||
{
|
||||
filename->addCallback
|
||||
(
|
||||
"activate",
|
||||
|
@ -477,9 +496,6 @@ void FFileDialog::init()
|
|||
"clicked",
|
||||
F_METHOD_CALLBACK (this, &FFileDialog::cb_processOpen)
|
||||
);
|
||||
|
||||
setModal();
|
||||
readDir();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -608,7 +624,7 @@ int FFileDialog::readDir()
|
|||
&& std::strcmp(next->d_name, "..") == 0 )
|
||||
continue;
|
||||
|
||||
getEntry(next);
|
||||
getEntry(dir, next);
|
||||
}
|
||||
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();
|
||||
dir_entry entry;
|
||||
|
@ -663,7 +679,7 @@ void FFileDialog::getEntry (struct dirent* d_entry)
|
|||
entry.socket = S_ISSOCK (s.st_mode);
|
||||
#endif
|
||||
|
||||
followSymLink(entry);
|
||||
followSymLink (dir, entry);
|
||||
|
||||
if ( entry.directory )
|
||||
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 )
|
||||
return; // No symbolic link
|
||||
|
@ -682,7 +698,6 @@ void FFileDialog::followSymLink (dir_entry& entry)
|
|||
char resolved_path[MAXPATHLEN] = {};
|
||||
char symLink[MAXPATHLEN] = {};
|
||||
struct stat sb;
|
||||
const char* const dir = directory.c_str();
|
||||
|
||||
std::strncpy (symLink, dir, sizeof(symLink) - 1);
|
||||
std::strncat ( symLink
|
||||
|
|
|
@ -522,12 +522,11 @@ void FLabel::drawMultiLine()
|
|||
{
|
||||
uInt y = 0;
|
||||
uInt text_lines = uInt(multiline_text.size());
|
||||
|
||||
bool hotkey_printed = false;
|
||||
|
||||
while ( y < text_lines && y < uInt(getHeight()) )
|
||||
{
|
||||
wchar_t* label_text;
|
||||
bool hotkey_printed = false;
|
||||
int align_offset, hotkeypos = -1;
|
||||
uInt length = multiline_text[y].getLength();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* 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 *
|
||||
* modify it under the terms of the GNU Lesser General Public License *
|
||||
|
@ -111,8 +111,7 @@ FMessageBox::FMessageBox ( const FString& caption
|
|||
//----------------------------------------------------------------------
|
||||
FMessageBox::~FMessageBox() // destructor
|
||||
{
|
||||
for (uInt n = 0; n < num_buttons; n++)
|
||||
delete button[n];
|
||||
deallocation();
|
||||
}
|
||||
|
||||
|
||||
|
@ -335,6 +334,16 @@ void FMessageBox::init (int button0, int button1, int button2)
|
|||
button_digit[1] = button1;
|
||||
button_digit[2] = button2;
|
||||
|
||||
allocation (button0, button1, button2);
|
||||
resizeButtons();
|
||||
adjustButtons();
|
||||
initCallbacks();
|
||||
setModal();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMessageBox::allocation (int button0, int button1, int button2)
|
||||
{
|
||||
try
|
||||
{
|
||||
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;
|
||||
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 )
|
||||
{
|
||||
button[0]->addCallback
|
||||
|
@ -400,8 +417,6 @@ void FMessageBox::init (int button0, int button1, int button2)
|
|||
static_cast<FWidget::data_ptr>(&button_digit[2])
|
||||
);
|
||||
}
|
||||
|
||||
setModal();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue