libyui-ncurses  2.57.2
NCTreePad.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  Copyright (C) 2020 SUSE LLC
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as
6  published by the Free Software Foundation; either version 2.1 of the
7  License, or (at your option) version 3.0 of the License. This library
8  is distributed in the hope that it will be useful, but WITHOUT ANY
9  WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11  License for more details. You should have received a copy of the GNU
12  Lesser General Public License along with this library; if not, write
13  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14  Floor, Boston, MA 02110-1301 USA
15 */
16 
17 
18 /*-/
19 
20  File: NCTreePad.cc
21 
22  Authors: Michael Andres <ma@suse.de>
23  Stefan Hundhammer <shundhammer@suse.de>
24 
25 /-*/
26 
27 #define YUILogComponent "ncurses"
28 #include <yui/YUILog.h>
29 #include "NCTreePad.h"
30 
31 
32 
33 NCTreePad::NCTreePad( int lines, int cols, const NCWidget & p )
34  : NCTablePadBase( lines, cols, p )
35 {
36 }
37 
38 
39 NCTreePad::~NCTreePad()
40 {
41 }
42 
43 
45 {
46  NCPad::Destwin( dwin );
47 
48  if ( destwin )
49  {
50  maxspos.L = visibleLines() > (unsigned) srect.Sze.H ? visibleLines() - srect.Sze.H : 0;
51  }
52 }
53 
54 
55 void NCTreePad::ShowItem( const NCTableLine * item )
56 {
57  if ( !item )
58  return;
59 
60  if ( const_cast<NCTableLine *>( item )->ChangeToVisible() || _dirtyFormat )
61  UpdateFormat();
62 
63  for ( unsigned i = 0; i < visibleLines(); ++i )
64  {
65  if ( _visibleItems[i] == item )
66  {
67  setpos( wpos( i, srect.Pos.C ) );
68  break;
69  }
70  }
71 }
72 
73 
75 {
76  if ( !NCPad::Destwin() )
77  {
78  dirty = true;
79  return OK;
80  }
81 
82  prepareRedraw();
84  drawHeader();
85 
86  dirty = false;
87 
88  return update();
89 }
90 
91 
92 bool NCTreePad::handleInput( wint_t key )
93 {
94  bool handled = false;
95 
96  switch ( key )
97  {
98  // At this time, there are no more special keys to handle on this
99  // level. This method is a stub for future extension if any more keys
100  // need to be handled.
101  //
102  // Add 'case KEY_XXX' branches here if there should be any
103  // and don't forget to set 'handled' to 'true'.
104 #if 0
105  case KEY_SOMETHING: // Sample
106  doSomething();
107  handled = true;
108  break;
109 #endif
110 
111  default: // Call parent class input handler
112 
113  // This also calls currentItemHandleInput() as the first thing it
114  // does to forward key presses to the item at the current cursor
115  // position. Many operations such as opening, closing or selecting
116  // an item are done on that level.
117  handled = NCTablePadBase::handleInput( key );
118  break;
119  }
120 
121  return handled;
122 }
123 
NCPad::destwin
NCursesWindow * destwin
Where to draw us (may be nullptr, not owned)
Definition: NCPad.h:135
NCursesWindow
C++ class for windows.
Definition: ncursesw.h:907
NCTreePad::handleInput
virtual bool handleInput(wint_t key)
Handle a keyboard input event.
Definition: NCTreePad.cc:92
NCTreePad::DoRedraw
virtual int DoRedraw()
Redraw the pad.
Definition: NCTreePad.cc:74
NCTablePadBase::prepareRedraw
virtual void prepareRedraw()
Prepare a redraw: Update the format if needed, set the background, clear the old content.
Definition: NCTablePadBase.cc:261
NCWidget
Definition: NCWidget.h:46
NCTablePadBase::drawHeader
virtual void drawHeader()
Redraw the table header.
Definition: NCTablePadBase.cc:285
NCTablePadBase::_dirtyFormat
bool _dirtyFormat
does table format (size) need recalculating?
Definition: NCTablePadBase.h:293
NCTablePadBase::visibleLines
unsigned visibleLines() const
Return the number of lines that are currently visible.
Definition: NCTablePadBase.h:89
NCTablePadBase::_visibleItems
std::vector< NCTableLine * > _visibleItems
not owned
Definition: NCTablePadBase.h:290
NCTablePadBase::drawContentLines
virtual void drawContentLines()
Redraw the (visible) content lines one by one.
Definition: NCTablePadBase.cc:271
wpos
Screen position pair in the order line, column: (L, C)
Definition: position.h:110
NCTreePad::Destwin
virtual void Destwin(NCursesWindow *dwin)
Definition: NCTreePad.cc:44
NCTablePadBase::handleInput
virtual bool handleInput(wint_t key)
Handle a keyboard input event.
Definition: NCTablePadBase.cc:386
NCTableLine
One line in a NCTable with multiple cells and an optional tree hierarchy.
Definition: NCTableItem.h:68
NCTablePadBase
An NCPad for an NCTable or an NCTree.
Definition: NCTablePadBase.h:59
NCPad::srect
wrect srect
Source rectangle: the visible part of this pad.
Definition: NCPad.h:138