Remove dialog list item callback from the associated dialog window

This commit is contained in:
Markus Gans 2016-07-30 23:00:37 +02:00
parent 9b7918f2f6
commit d5685aaafc
5 changed files with 30 additions and 14 deletions

View File

@ -1,5 +1,6 @@
2016-07-30 Markus Gans <guru.mail@muenster.de>
* Delete all callbacks from a widget, when it will be destroyed
* Delete all callbacks from a widget with delCallbacks()
* Remove dialog list item callback from the associated window
2016-07-28 Markus Gans <guru.mail@muenster.de>
* Improvements for the window focus

View File

@ -31,7 +31,8 @@ std::deque<FApplication::eventPair>* FApplication::event_queue = 0;
// constructors and destructor
//----------------------------------------------------------------------
FApplication::FApplication (int& _argc, char**& _argv)
: app_argc(_argc)
: FWidget(0)
, app_argc(_argc)
, app_argv(_argv)
, skipped_terminal_update(0)
, key(0)

View File

@ -29,6 +29,7 @@ FMenuItem::FMenuItem (FWidget* parent)
, accel_key(0)
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
@ -48,6 +49,7 @@ FMenuItem::FMenuItem (FString& txt, FWidget* parent)
, accel_key(0)
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
@ -67,6 +69,7 @@ FMenuItem::FMenuItem (const std::string& txt, FWidget* parent)
, accel_key(0)
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
@ -86,6 +89,7 @@ FMenuItem::FMenuItem (const char* txt, FWidget* parent)
, accel_key(0)
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
@ -105,6 +109,7 @@ FMenuItem::FMenuItem (int k, FString& txt, FWidget* parent)
, accel_key(k)
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
@ -124,6 +129,7 @@ FMenuItem::FMenuItem (int k, const std::string& txt, FWidget* parent)
, accel_key(k)
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
@ -143,6 +149,7 @@ FMenuItem::FMenuItem (int k, const char* txt, FWidget* parent)
, accel_key(k)
, menu(0)
, super_menu(0)
, associated_window(0)
{
init (parent);
}
@ -151,6 +158,10 @@ FMenuItem::FMenuItem (int k, const char* txt, FWidget* parent)
FMenuItem::~FMenuItem() // destructor
{
delAccelerator();
// remove dialog list item callback from the dialog
if ( associated_window )
associated_window->delCallback(this);
}
@ -268,8 +279,10 @@ void FMenuItem::createDialogList (FMenu* winmenu)
if ( win )
{
int n = int(std::distance(begin, iter));
FString win_title = win->getText();
FMenuItem* win_item = new FMenuItem (win_title, winmenu);
// get the dialog title
FString name = win->getText();
// create a new dialog list item
FMenuItem* win_item = new FMenuItem (name, winmenu);
if ( n < 9 )
win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9
@ -277,16 +290,17 @@ void FMenuItem::createDialogList (FMenu* winmenu)
win_item->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &FMenuItem::cb_switchToDialog),
_METHOD_CALLBACK (win_item, &FMenuItem::cb_switchToDialog),
dynamic_cast<FWidget::data_ptr>(win)
);
win->addCallback
(
"destroy",
_METHOD_CALLBACK (this, &FMenuItem::cb_destroyDialog),
static_cast<FWidget::data_ptr>(win_item)
_METHOD_CALLBACK (win_item, &FMenuItem::cb_destroyDialog)
);
win_item->associated_window = win;
}
++iter;
@ -310,16 +324,16 @@ void FMenuItem::cb_switchToDialog (FWidget*, void* data_ptr)
}
//----------------------------------------------------------------------
void FMenuItem::cb_destroyDialog (FWidget* widget, void* data_ptr)
void FMenuItem::cb_destroyDialog (FWidget* widget, void*)
{
FDialog* win = static_cast<FDialog*>(widget);
FMenuItem* win_item = static_cast<FMenuItem*>(data_ptr);
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
if ( win_item && win && fapp && ! fapp->isQuit() )
if ( win && fapp )
{
win_item->delAccelerator(win);
win_item->delCallback(this);
delAccelerator(win);
delCallback(win);
associated_window = 0;
}
}

View File

@ -29,7 +29,7 @@
#include "fwidget.h"
class FDialog;
class FMenu;
class FMenuList;
@ -55,6 +55,7 @@ class FMenuItem : public FWidget
int accel_key;
FMenu* menu;
FWidget* super_menu;
FDialog* associated_window;
private:
FMenuItem (const FMenuItem&);

View File

@ -103,7 +103,6 @@ FWidget::FWidget (FWidget* parent)
//----------------------------------------------------------------------
FWidget::~FWidget() // destructor
{
delCallbacks();
processDestroy();
FApplication::removeQueuedEvent(this);