libyui-ncurses  2.55.0
NCDialog.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCDialog.h
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #ifndef NCDialog_h
26 #define NCDialog_h
27 
28 #include <iosfwd>
29 
30 #include <yui/YDialog.h>
31 #include "NCWidget.h"
32 #include "NCPushButton.h"
33 
34 
35 class NCDialog;
36 class NCPopupInfo;
37 
38 
39 class NCDialog : public YDialog, public NCWidget
40 {
41 private:
42 
43  friend std::ostream & operator<<( std::ostream & str, const NCDialog & obj );
44  friend std::ostream & operator<<( std::ostream & str, const NCDialog * obj );
45 
46  NCDialog & operator=( const NCDialog & );
47  NCDialog( const NCDialog & );
48 
49  typedef tnode<NCWidget *> * ( tnode<NCWidget *>::* SeekDir )( bool );
50 
51  NCWidget & GetNormal( NCWidget & startwith, SeekDir Direction );
52  void Activate( SeekDir Direction );
53 
54  void _init();
55  void _init_size();
56 
57 protected:
58 
59  virtual const char * location() const { return "NCDialog"; }
60 
61  wint_t getinput(); // get the input (respect terminal encoding)
62 
63 private:
64 
66  NCstyle::StyleSet mystyleset;
67  const NCstyle::Style * dlgstyle;
68 
69  unsigned inMultiDraw_i;
70 
71  bool active;
72  NCWidget *const wActive;
73 
74  NCursesEvent pendingEvent;
75  YEvent::EventReason eventReason;
76 
77  // wrapper for wHandle... calls in processInput()
78  NCursesEvent getInputEvent( wint_t ch );
79  NCursesEvent getHotkeyEvent( wint_t key );
80 
81  void grabActive( NCWidget * nactive );
82  virtual void grabNotify( NCWidget * mgrab );
83  virtual bool wantFocus( NCWidget & ngrab );
84 
85  virtual void wCreate( const wrect & newrect );
86  virtual void wMoveTo( const wpos & newpos );
87  virtual void wDelete();
88  virtual void wRedraw();
89  virtual void wRecoded();
90  virtual void wUpdate( bool forced_br = false );
91  void doUpdate() { wUpdate( true ); }
92 
93  NCWidget & GetNextNormal( NCWidget & startwith );
94  NCWidget & GetPrevNormal( NCWidget & startwith );
95 
96  bool Activate( NCWidget & nactive );
97  void Activate();
98  void Deactivate();
99  void ActivateNext();
100  void ActivatePrev();
101 
102  bool ActivateByKey( int key );
103 
104  void processInput( int timeout_millisec );
105 
106  std::map<int, NCstring> describeFunctionKeys();
107 
108  bool flushTypeahead();
109 
110 protected:
111 
112  virtual wint_t getch( int timeout_millisec = -1 );
113 
114  virtual NCursesEvent wHandleInput( wint_t ch );
115  virtual NCursesEvent wHandleHotkey( wint_t key );
116 
117  virtual void startMultipleChanges();
118  virtual void doneMultipleChanges();
119 
120  /**
121  * Internal open() method: Initialize what is left over to initialize after
122  * all dialog children have been created.
123  * YDialog::setInitialSize() is already called before this in
124  * YDailog::open(), so don't call it here again (very expensive!).
125  *
126  * This function is called (exactly once during the life time of the
127  * dialog) in YDialog::open().
128  *
129  * Implemented from YDialog.
130  **/
131  virtual void openInternal();
132 
133  /**
134  * Wait for a user event.
135  *
136  * Implemented from YDialog.
137  **/
138  virtual YEvent * waitForEventInternal( int timeout_millisec );
139 
140  /**
141  * Check if a user event is pending. If there is one, return it.
142  * If there is none, do not wait for one - return 0.
143  *
144  * Implemented from YDialog.
145  **/
146  virtual YEvent * pollEventInternal();
147 
148 
149 public:
150 
151  NCDialog( YDialogType dialogType,
152  YDialogColorMode colorMode = YDialogNormalColor );
153  virtual ~NCDialog();
154 
155  void showDialog();
156  void closeDialog();
157 
158  void activate( bool newactive );
159  bool isActive() const { return active; }
160 
161  void idleInput();
162 
163  NCursesEvent userInput( int timeout_millisec = -1 );
164  NCursesEvent pollInput();
165 
166  virtual int preferredWidth();
167  virtual int preferredHeight();
168 
169  virtual void setSize( int newWidth, int newHeight );
170 
171  void setStatusLine();
172 
173  /**
174  * Activate this dialog: Make sure that it is shown as the topmost dialog
175  * of this application and that it can receive input.
176  *
177  * Implemented from YDialog.
178  **/
179  virtual void activate();
180 
181  // Get the pending event, only for special cases (REST API)
182  NCursesEvent getPendingEvent() { return pendingEvent;}
183  // Set the pending event, makes sense only when simulating the user actions (REST API)
184  void setPendingEvent(NCursesEvent event) { pendingEvent = event;}
185 
186 protected:
187 
188  enum NCDopts
189  {
190  DEFAULT = 0x00,
191  POPUP = 0x01,
192  NOBOX = 0x10
193  };
194 
195  typedef unsigned NCDoptflag;
196 
197  NCDoptflag ncdopts;
198  wpos popedpos;
199  bool hshaddow;
200  bool vshaddow;
201 
202  NCDialog( YDialogType dialogType, const wpos & at, bool boxed = true );
203 
204  bool isPopup() const { return ( ncdopts & POPUP ); }
205 
206  bool isBoxed() const { return !( ncdopts & NOBOX ); }
207 
208  virtual void initDialog();
209 
210  virtual const NCstyle::Style & wStyle() const
211  {
212  return dlgstyle ? *dlgstyle : NCurses::style()[NCstyle::DefaultStyle];
213  }
214 
215  virtual void setEnabled( bool do_bv ) {}
216 
217 private:
218 
219  friend class NCurses;
220  bool getInvisible();
221  bool getVisible();
222  void resizeEvent();
223  void showHotkeyHelp();
224 };
225 
226 
227 #endif // NCDialog_h
virtual void activate()
Activate this dialog: Make sure that it is shown as the topmost dialog of this application and that i...
Definition: NCDialog.cc:311
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.
Definition: NCDialog.h:215
virtual YEvent * pollEventInternal()
Check if a user event is pending.
Definition: NCDialog.cc:1003
virtual void openInternal()
Internal open() method: Initialize what is left over to initialize after all dialog children have bee...
Definition: NCDialog.cc:228
virtual YEvent * waitForEventInternal(int timeout_millisec)
Wait for a user event.
Definition: NCDialog.cc:987
Definition: position.h:110