libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCDialog.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019    File:       NCDialog.h
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef NCDialog_h
00026 #define NCDialog_h
00027 
00028 #include <iosfwd>
00029 
00030 #include <yui/YDialog.h>
00031 #include "NCWidget.h"
00032 #include "NCPushButton.h"
00033 
00034 
00035 class NCDialog;
00036 class NCPopupInfo;
00037 
00038 
00039 class NCDialog : public YDialog, public NCWidget
00040 {
00041 private:
00042 
00043     friend std::ostream & operator<<( std::ostream & STREAM, const NCDialog & OBJ );
00044     friend std::ostream & operator<<( std::ostream & STREAM, const NCDialog * OBJ );
00045 
00046     NCDialog & operator=( const NCDialog & );
00047     NCDialog( const NCDialog & );
00048 
00049     typedef tnode<NCWidget *> * ( tnode<NCWidget *>::* SeekDir )( const bool );
00050 
00051     NCWidget & GetNormal( NCWidget & startwith, SeekDir Direction );
00052     void       Activate( SeekDir Direction );
00053 
00054     void _init();
00055     void _init_size();
00056 
00057 protected:
00058 
00059     virtual const char * location() const { return "NCDialog"; }
00060 
00061 private:
00062 
00063     NCursesUserPanel<NCDialog> * pan;
00064     NCstyle::StyleSet            mystyleset;
00065     const NCstyle::Style *       dlgstyle;
00066 
00067     unsigned inMultiDraw_i;
00068 
00069     bool            active;
00070     NCWidget *const wActive;
00071 
00072     NCursesEvent pendingEvent;
00073     YEvent::EventReason eventReason;
00074 
00075     // wrapper for wHandle... calls in processInput()
00076     NCursesEvent getInputEvent( wint_t ch );
00077     NCursesEvent getHotkeyEvent( wint_t key );
00078 
00079     void grabActive( NCWidget * nactive );
00080     virtual void grabNotify( NCWidget * mgrab );
00081     virtual bool wantFocus( NCWidget & ngrab );
00082 
00083     virtual void wCreate( const wrect & newrect );
00084     virtual void wMoveTo( const wpos & newpos );
00085     virtual void wDelete();
00086     virtual void wRedraw();
00087     virtual void wRecoded();
00088     virtual void wUpdate( bool forced_br = false );
00089     void doUpdate() { wUpdate( true ); }
00090 
00091     NCWidget & GetNextNormal( NCWidget & startwith );
00092     NCWidget & GetPrevNormal( NCWidget & startwith );
00093 
00094     bool Activate( NCWidget & nactive );
00095     void Activate();
00096     void Deactivate();
00097     void ActivateNext();
00098     void ActivatePrev();
00099 
00100     bool ActivateByKey( int key );
00101 
00102     void processInput( int timeout_millisec );
00103 
00104     std::map<int, std::string> describeFunctionKeys();
00105 
00106     wint_t getinput();          // get the input (respect terminal encoding)
00107 
00108     bool flushTypeahead();
00109 
00110 protected:
00111 
00112     wint_t getch( int timeout_millisec = -1 );
00113 
00114     virtual NCursesEvent wHandleInput( wint_t ch );
00115     virtual NCursesEvent wHandleHotkey( wint_t key );
00116 
00117     virtual void startMultipleChanges();
00118     virtual void doneMultipleChanges();
00119 
00120     /**
00121      * Internal open() method: Initialize what is left over to initialize after
00122      * all dialog children have been created.
00123      * YDialog::setInitialSize() is already called before this in
00124      * YDailog::open(), so don't call it here again (very expensive!).
00125      *
00126      * This function is called (exactly once during the life time of the
00127      * dialog) in YDialog::open().
00128      *
00129      * Implemented from YDialog.
00130      **/
00131     virtual void openInternal();
00132 
00133     /**
00134      * Wait for a user event.
00135      *
00136      * Implemented from YDialog.
00137      **/
00138     virtual YEvent * waitForEventInternal( int timeout_millisec );
00139 
00140     /**
00141      * Check if a user event is pending. If there is one, return it.
00142      * If there is none, do not wait for one - return 0.
00143      *
00144      * Implemented from YDialog.
00145      **/
00146     virtual YEvent * pollEventInternal();
00147 
00148 
00149 public:
00150 
00151     NCDialog( YDialogType       dialogType,
00152               YDialogColorMode  colorMode = YDialogNormalColor );
00153     virtual ~NCDialog();
00154 
00155     void showDialog();
00156     void closeDialog();
00157 
00158     void activate( const bool newactive );
00159     bool isActive() const { return active; }
00160 
00161     void idleInput();
00162 
00163     NCursesEvent userInput( int timeout_millisec = -1 );
00164     NCursesEvent pollInput();
00165 
00166     virtual int preferredWidth();
00167     virtual int preferredHeight();
00168 
00169     virtual void setSize( int newWidth, int newHeight );
00170 
00171     void setStatusLine();
00172 
00173     /**
00174      * Activate this dialog: Make sure that it is shown as the topmost dialog
00175      * of this application and that it can receive input.
00176      *
00177      * Implemented from YDialog.
00178      **/
00179     virtual void activate();
00180 
00181 protected:
00182 
00183     enum NCDopts
00184     {
00185         DEFAULT = 0x00,
00186         POPUP   = 0x01,
00187         NOBOX   = 0x10
00188     };
00189 
00190     typedef unsigned NCDoptflag;
00191 
00192     NCDoptflag ncdopts;
00193     wpos       popedpos;
00194     bool       hshaddow;
00195     bool       vshaddow;
00196 
00197     NCDialog( YDialogType dialogType, const wpos at, const bool boxed = true );
00198 
00199     bool isPopup() const { return ( ncdopts & POPUP ); }
00200 
00201     bool isBoxed() const { return !( ncdopts & NOBOX ); }
00202 
00203     virtual void initDialog();
00204 
00205     virtual const NCstyle::Style & wStyle() const
00206     {
00207         return dlgstyle ? *dlgstyle : NCurses::style()[NCstyle::DefaultStyle];
00208     }
00209 
00210     virtual void setEnabled( bool do_bv ) {}
00211 
00212 private:
00213 
00214     friend class NCurses;
00215     bool getInvisible();
00216     bool getVisible();
00217     void resizeEvent();
00218 };
00219 
00220 
00221 #endif // NCDialog_h
 All Classes Functions Variables