changeset 19503:912158cf524d

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Wed, 05 Nov 2014 12:45:44 -0500
parents 8e1883060940 (current diff) 735bc47d18af (diff)
children 39a69f54417e
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-gui.cc libinterp/corefcn/sysdep.cc liboctave/util/cmd-edit.cc liboctave/util/cmd-edit.h liboctave/util/oct-rl-edit.c liboctave/util/oct-rl-edit.h
diffstat 6 files changed, 142 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/QTerminal.h
+++ b/libgui/qterminal/libqterminal/QTerminal.h
@@ -110,6 +110,8 @@
 
   void notice_settings (const QSettings *settings);
 
+  virtual void init_terminal_size (void) { }
+
   void terminal_interrupt (void) { emit interrupt_signal (); }
 
 protected:
@@ -148,6 +150,9 @@
     connect (xparent, SIGNAL (settings_changed (const QSettings *)),
              this, SLOT (notice_settings (const QSettings *)));
 
+    connect (xparent, SIGNAL (init_terminal_size_signal ()),
+             this, SLOT (init_terminal_size ()));
+
     connect (xparent, SIGNAL (copyClipboard_signal ()),
              this, SLOT (copyClipboard ()));
 
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp
@@ -1,3 +1,4 @@
+
 /*
 
 Copyright (C) 2011, 2013 Michael Goffioul.
@@ -24,7 +25,7 @@
 #include <QClipboard>
 #include <QColor>
 #include <QFont>
-#include <QHBoxLayout>
+#include <QGridLayout>
 #include <QPaintEvent>
 #include <QPainter>
 #include <QResizeEvent>
@@ -176,11 +177,13 @@
   QConsolePrivate (QWinTerminalImpl* parent, const QString& cmd = QString ());
   ~QConsolePrivate (void);
 
-  void updateConsoleSize (bool sync = false);
+  void updateConsoleSize (bool sync = false, bool allow_smaller_width = false);
   void syncConsoleParameters (void);
   void grabConsoleBuffer (CHAR_INFO* buf = 0);
-  void updateScrollBar (void);
-  void setScrollValue (int value);
+  void updateHorizontalScrollBar (void);
+  void updateVerticalScrollBar (void);
+  void setHorizontalScrollValue (int value);
+  void setVerticalScrollValue (int value);
   void updateConsoleView (bool grab = true);
   void monitorConsole (void);
   void startCommand (void);
@@ -256,7 +259,8 @@
   HANDLE m_process;
 
   QConsoleView* m_consoleView;
-  QScrollBar* m_scrollBar;
+  QScrollBar* m_horizontalScrollBar;
+  QScrollBar* m_verticalScrollBar;
   QTimer* m_consoleWatcher;
   QConsoleThread *m_consoleThread;
 
@@ -369,13 +373,15 @@
   m_buffer = m_tmpBuffer = 0;
 
   m_consoleView = new QConsoleView (parent);
-  m_scrollBar = new QScrollBar (Qt::Vertical, parent);
+  m_horizontalScrollBar = new QScrollBar (Qt::Horizontal, parent);
+  m_verticalScrollBar = new QScrollBar (Qt::Vertical, parent);
 
-  QHBoxLayout* l = new QHBoxLayout (parent);
+  QGridLayout* l = new QGridLayout (parent);
   l->setContentsMargins (0, 0, 0, 0);
   l->setSpacing (0);
-  l->addWidget (m_consoleView, 1);
-  l->addWidget (m_scrollBar, 0);
+  l->addWidget (m_consoleView, 0, 0);
+  l->addWidget (m_horizontalScrollBar, 1, 0);
+  l->addWidget (m_verticalScrollBar, 0, 1);
 
   // Choose 15 (0xF) as index into the Windows console color map for the
   // background and 0 (0x0) as the index for the foreground.  This
@@ -401,7 +407,8 @@
   parent->setFocusPolicy (Qt::StrongFocus);
   parent->winId ();
 
-  updateScrollBar ();
+  updateHorizontalScrollBar ();
+  updateVerticalScrollBar ();
 
   m_consoleWatcher = new QTimer (parent);
   m_consoleWatcher->setInterval (10);
@@ -411,8 +418,12 @@
   QObject::connect (m_blinkCursorTimer, SIGNAL (timeout()),
                     q, SLOT (blinkCursorEvent ()));  
 
-  QObject::connect (m_scrollBar, SIGNAL (valueChanged (int)),
-                    q, SLOT (scrollValueChanged (int)));
+  QObject::connect (m_horizontalScrollBar, SIGNAL (valueChanged (int)),
+                    q, SLOT (horizontalScrollValueChanged (int)));
+
+  QObject::connect (m_verticalScrollBar, SIGNAL (valueChanged (int)),
+                    q, SLOT (verticalScrollValueChanged (int)));
+
   QObject::connect (m_consoleWatcher, SIGNAL (timeout (void)),
                     q, SLOT (monitorConsole (void)));
 
@@ -685,12 +696,17 @@
   QPoint begin = cellpos;
   QPoint end = cellpos;
 
-  int scrollOffset = m_consoleRect.top ();
   int stride = m_consoleRect.width ();
 
+  int verticalScrollOffset = m_consoleRect.top ();
+  int horizontalScrollOffset = m_consoleRect.left ();
+
   // get begin, end in buffer offsets
-  begin.ry () -= scrollOffset;
-  end.ry () -= scrollOffset;
+  begin.ry () -= verticalScrollOffset;
+  end.ry () -= verticalScrollOffset;
+
+  begin.rx () -= horizontalScrollOffset;
+  end.rx () -= horizontalScrollOffset;
 
   // loog at current clicked on char to determinate ig getting space chunk or nonspace chunk
   if (QChar(m_buffer[begin.y ()*stride + begin.x ()].Char.UnicodeChar).isSpace () == false)
@@ -724,8 +740,11 @@
   }
 
   // convert console  offsets to absolute cell positions
-  begin.ry () += scrollOffset;
-  end.ry () += scrollOffset;
+  begin.ry () += verticalScrollOffset;
+  end.ry () += verticalScrollOffset;
+
+  begin.rx () += horizontalScrollOffset;
+  end.rx () += horizontalScrollOffset;
 
   m_beginSelection = begin;
   m_endSelection = end;
@@ -754,10 +773,14 @@
   if (haveSelection)
     maybeSwapPoints (begin, end);
 
-  int scrollOffset = m_consoleRect.top ();
+  int verticalScrollOffset = m_consoleRect.top ();
+  int horizontalScrollOffset = m_consoleRect.left ();
 
-  begin.ry () -= scrollOffset;
-  end.ry () -= scrollOffset;
+  begin.ry () -= verticalScrollOffset;
+  end.ry () -= verticalScrollOffset;
+
+  begin.rx () -= horizontalScrollOffset;
+  end.rx () -= horizontalScrollOffset;
 
   int ascent = p.fontMetrics ().ascent ();
   int stride = m_consoleRect.width ();
@@ -958,7 +981,7 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-void QConsolePrivate::updateConsoleSize (bool sync)
+void QConsolePrivate::updateConsoleSize (bool sync, bool allow_smaller_width)
 {
   QFontMetrics fm (m_font);
   QSize winSize = m_consoleView->size ();
@@ -972,7 +995,7 @@
   // Don't shrink the size of the buffer.  That way wide lines won't be
   // truncated and will reappear if the window is enlarged again later.
 
-  if (m_consoleRect.width () > m_bufferSize.width ())
+  if (allow_smaller_width || m_consoleRect.width () > m_bufferSize.width ())
     m_bufferSize.rwidth () = m_consoleRect.width ();
 
   if (qMax (m_bufferSize.height (), m_consoleRect.height ())
@@ -1010,7 +1033,8 @@
   if (sync)
     syncConsoleParameters ();
 
-  updateScrollBar ();
+  updateHorizontalScrollBar ();
+  updateVerticalScrollBar ();
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -1097,25 +1121,70 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-void QConsolePrivate::updateScrollBar (void)
+void QConsolePrivate::updateHorizontalScrollBar (void)
 {
-  m_scrollBar->setMinimum (0);
-  if (m_bufferSize.height () > m_consoleRect.height ())
-    m_scrollBar->setMaximum (m_bufferSize.height () - m_consoleRect.height ());
+  m_horizontalScrollBar->setMinimum (0);
+  if (m_bufferSize.width () > m_consoleRect.width ())
+    m_horizontalScrollBar->setMaximum (m_bufferSize.width () - m_consoleRect.width ());
   else
-    m_scrollBar->setMaximum (0);
-  m_scrollBar->setSingleStep (1);
-  m_scrollBar->setPageStep (m_consoleRect.height ());
-  m_scrollBar->setValue (m_consoleRect.top ());
+    m_horizontalScrollBar->setMaximum (0);
+  m_horizontalScrollBar->setSingleStep (1);
+  m_horizontalScrollBar->setPageStep (m_consoleRect.width ());
+  m_horizontalScrollBar->setValue (m_consoleRect.left ());
+
+  log ("Horizontal scrollbar parameters updated: %d/%d/%d/%d\n",
+       m_horizontalScrollBar->minimum (),
+       m_horizontalScrollBar->maximum (),
+       m_horizontalScrollBar->singleStep (),
+       m_horizontalScrollBar->pageStep ());
+}
 
-  log ("Scrollbar parameters updated: %d/%d/%d/%d\n",
-       m_scrollBar->minimum (), m_scrollBar->maximum (),
-       m_scrollBar->singleStep (), m_scrollBar->pageStep ());
+void QConsolePrivate::updateVerticalScrollBar (void)
+{
+  m_verticalScrollBar->setMinimum (0);
+  if (m_bufferSize.height () > m_consoleRect.height ())
+    m_verticalScrollBar->setMaximum (m_bufferSize.height () - m_consoleRect.height ());
+  else
+    m_verticalScrollBar->setMaximum (0);
+  m_verticalScrollBar->setSingleStep (1);
+  m_verticalScrollBar->setPageStep (m_consoleRect.height ());
+  m_verticalScrollBar->setValue (m_consoleRect.top ());
+
+  log ("Vertical scrollbar parameters updated: %d/%d/%d/%d\n",
+       m_verticalScrollBar->minimum (), m_verticalScrollBar->maximum (),
+       m_verticalScrollBar->singleStep (), m_verticalScrollBar->pageStep ());
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
-void QConsolePrivate::setScrollValue (int value)
+void QConsolePrivate::setHorizontalScrollValue (int value)
+{
+  if (value == m_consoleRect.left ())
+    return;
+
+  SMALL_RECT r;
+  HANDLE hStdOut = m_stdOut;
+
+  if (value + m_consoleRect.width () > m_bufferSize.width ())
+    value = m_bufferSize.width () - m_consoleRect.width ();
+
+  r.Left = value;
+  r.Top = m_consoleRect.top ();
+  r.Right = value + m_consoleRect.width () - 1;
+  r.Bottom = m_consoleRect.bottom ();
+
+  log ("Scrolling window horizontally: (%d, %d) -> (%d, %d) [%d x %d]\n",
+       r.Left, r.Top, r.Right, r.Bottom, 
+       r.Right - r.Left + 1, r.Bottom - r.Top + 1);
+
+  if (SetConsoleWindowInfo (hStdOut, TRUE, &r))
+    {
+      m_consoleRect.moveLeft (value);
+      updateConsoleView ();
+    }
+}
+
+void QConsolePrivate::setVerticalScrollValue (int value)
 {
   if (value == m_consoleRect.top ())
     return;
@@ -1131,7 +1200,7 @@
   r.Right = m_consoleRect.right ();
   r.Bottom = value + m_consoleRect.height () - 1;
 
-  log ("Scrolling window: (%d, %d) -> (%d, %d) [%d x %d]\n",
+  log ("Scrolling window vertically: (%d, %d) -> (%d, %d) [%d x %d]\n",
        r.Left, r.Top, r.Right, r.Bottom, 
        r.Right - r.Left + 1, r.Bottom - r.Top + 1);
 
@@ -1178,7 +1247,8 @@
           // Buffer size changed
           m_bufferSize.rwidth () = sbi.dwSize.X;
           m_bufferSize.rheight () = sbi.dwSize.Y;
-          updateScrollBar ();
+          updateHorizontalScrollBar ();
+          updateVerticalScrollBar ();
         }
 
       if (m_cursorPos.x () != sbi.dwCursorPosition.X
@@ -1206,7 +1276,8 @@
           m_consoleRect = QRect (sbi.srWindow.Left, sbi.srWindow.Top,
                                  sbi.srWindow.Right - sbi.srWindow.Left + 1,
                                  sbi.srWindow.Bottom - sbi.srWindow.Top + 1);
-          updateScrollBar ();
+          updateHorizontalScrollBar ();
+          updateVerticalScrollBar ();
           updateConsoleView ();
           return;
         }
@@ -1505,6 +1576,13 @@
     }
 }
 
+// Reset width of console buffer and terminal window to be the same.
+
+void QWinTerminalImpl::init_terminal_size (void)
+{
+  d->updateConsoleSize (true, true);
+}
+
 //////////////////////////////////////////////////////////////////////////////
 
 void QWinTerminalImpl::wheelEvent (QWheelEvent* event)
@@ -1513,16 +1591,21 @@
     {
       // Forward to the scrollbar (avoid recursion)
       d->m_inWheelEvent = true;
-      QApplication::sendEvent (d->m_scrollBar, event);
+      QApplication::sendEvent (d->m_verticalScrollBar, event);
       d->m_inWheelEvent = false;
     }
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
-void QWinTerminalImpl::scrollValueChanged (int value)
+void QWinTerminalImpl::horizontalScrollValueChanged (int value)
 {
-  d->setScrollValue (value);
+  d->setHorizontalScrollValue (value);
+}
+
+void QWinTerminalImpl::verticalScrollValueChanged (int value)
+{
+  d->setVerticalScrollValue (value);
 }
 
 //////////////////////////////////////////////////////////////////////////////
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h
@@ -71,6 +71,7 @@
   void pasteClipboard (void);
   void selectAll (void);
   void blinkCursorEvent (void);
+  void init_terminal_size (void);
 
 signals:
   void terminated (void);
@@ -100,7 +101,8 @@
   void dropEvent(QDropEvent *event);
 
 private slots:
-  void scrollValueChanged (int value);
+  void horizontalScrollValueChanged (int value);
+  void verticalScrollValueChanged (int value);
   void monitorConsole (void);
   void updateSelection (void);
   void tripleClickTimeout (void);
--- a/libgui/src/main-window.cc
+++ b/libgui/src/main-window.cc
@@ -941,6 +941,12 @@
 }
 
 void
+main_window::init_terminal_size (void)
+{
+  emit init_terminal_size_signal ();
+}
+
+void
 main_window::set_window_layout (QSettings *settings)
 {
 #if ! defined (Q_OS_WIN32)
--- a/libgui/src/main-window.h
+++ b/libgui/src/main-window.h
@@ -81,6 +81,7 @@
 
 signals:
   void settings_changed (const QSettings *);
+  void init_terminal_size_signal (void);
   void new_file_signal (const QString&);
   void open_file_signal (const QString&);
 
@@ -153,6 +154,7 @@
                                                 const QString& file, int line);
 
   void read_settings (void);
+  void init_terminal_size (void);
   void set_window_layout (QSettings *settings);
   void write_settings (void);
   void connect_visibility_changed (void);
--- a/libgui/src/octave-gui.cc
+++ b/libgui/src/octave-gui.cc
@@ -168,6 +168,8 @@
 
       w.read_settings ();
 
+      w.init_terminal_size ();
+
       // Connect signals for changes in visibility not before w
       // is shown.