X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fcursesapp.cc;h=522c57065091234743ee03a52a0f144dcfd44908;hp=5b7ab5c0ab99f655537679b9fecb8ccd140e2783;hb=460005b642d978c6d4b48810803514bd36a6245b;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/c++/cursesapp.cc b/c++/cursesapp.cc index 5b7ab5c0..522c5706 100644 --- a/c++/cursesapp.cc +++ b/c++/cursesapp.cc @@ -1,6 +1,7 @@ // * this is for making emacs happy: -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1998,1999,2001 Free Software Foundation, Inc. * + * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,20 +30,21 @@ /**************************************************************************** * Author: Juergen Pfeifer, 1997 * - * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en * + * and: Thomas E. Dickey * ****************************************************************************/ #include "internal.h" #include "cursesapp.h" -MODULE_ID("$Id: cursesapp.cc,v 1.9 2002/07/06 15:47:52 juergen Exp $") +MODULE_ID("$Id: cursesapp.cc,v 1.17 2020/02/02 23:34:34 tom Exp $") void -NCursesApplication::init(bool bColors) { +NCursesApplication::init(bool bColors) +{ if (bColors) NCursesWindow::useColors(); - - if (Root_Window->colors() > 1) { + + if (Root_Window->colors() > 1) { b_Colors = TRUE; Root_Window->setcolor(1); Root_Window->setpalette(COLOR_YELLOW,COLOR_BLUE); @@ -67,24 +69,32 @@ NCursesApplication* NCursesApplication::theApp = 0; NCursesWindow* NCursesApplication::titleWindow = 0; NCursesApplication::SLK_Link* NCursesApplication::slk_stack = 0; -NCursesApplication::~NCursesApplication() { +NCursesApplication::~NCursesApplication() THROWS(NCursesException) +{ Soft_Label_Key_Set* S; delete titleWindow; + titleWindow = 0; + while( (S=top()) ) { pop(); delete S; } + delete Root_Window; + Root_Window = 0; + ::endwin(); } -int NCursesApplication::rinit(NCursesWindow& w) { +int NCursesApplication::rinit(NCursesWindow& w) +{ titleWindow = &w; return OK; } -void NCursesApplication::push(Soft_Label_Key_Set& S) { +void NCursesApplication::push(Soft_Label_Key_Set& S) +{ SLK_Link* L = new SLK_Link; assert(L != 0); L->prev = slk_stack; @@ -94,33 +104,39 @@ void NCursesApplication::push(Soft_Label_Key_Set& S) { S.show(); } -bool NCursesApplication::pop() { +bool NCursesApplication::pop() +{ if (slk_stack) { SLK_Link* L = slk_stack; slk_stack = slk_stack->prev; delete L; - if (Root_Window && top()) - top()->show(); + if (Root_Window) { + Soft_Label_Key_Set* xx = top(); + if (xx != 0) + xx->show(); + } } return (slk_stack ? FALSE : TRUE); } -Soft_Label_Key_Set* NCursesApplication::top() const { +Soft_Label_Key_Set* NCursesApplication::top() const +{ if (slk_stack) return slk_stack->SLKs; else - return (Soft_Label_Key_Set*)0; + return static_cast(0); } -int NCursesApplication::operator()(void) { +int NCursesApplication::operator()(void) +{ bool bColors = b_Colors; - Soft_Label_Key_Set* S; + Soft_Label_Key_Set* S = 0; int ts = titlesize(); if (ts>0) NCursesWindow::ripoffline(ts,rinit); Soft_Label_Key_Set::Label_Layout fmt = useSLKs(); - if (fmt!=Soft_Label_Key_Set::None) { + if (fmt!=Soft_Label_Key_Set::None) { S = new Soft_Label_Key_Set(fmt); assert(S != 0); init_labels(*S); @@ -138,8 +154,10 @@ int NCursesApplication::operator()(void) { return run(); } -NCursesApplication::NCursesApplication(bool bColors) { - b_Colors = bColors; +NCursesApplication::NCursesApplication(bool bColors) + : b_Colors(bColors), + Root_Window(NULL) +{ if (theApp) THROW(new NCursesException("Application object already created.")); else