From 7ec5a57fc3f04526f36477e22066199372beb0ee Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Tue, 8 Dec 2020 12:30:30 +0900
Subject: Renaming of files in preparation for code style tools.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 ark/ChangeLog                       |    9 +-
 kcharselect/CMakeLists.txt          |    2 +-
 kcharselect/Makefile.am             |    4 +-
 kcharselect/kcharselectdia.cc       |  289 --
 kcharselect/kcharselectdia.cpp      |  289 ++
 kcharselect/main.cc                 |   49 -
 kcharselect/main.cpp                |   49 +
 kgpg/Makefile.am                    |    2 +-
 khexedit/CMakeLists.txt             |   20 +-
 khexedit/Makefile.am                |   16 +-
 khexedit/bitswapwidget.cc           |  323 ---
 khexedit/bitswapwidget.cpp          |  323 +++
 khexedit/chartabledialog.cc         |  212 --
 khexedit/chartabledialog.cpp        |  212 ++
 khexedit/conversion.cc              |  395 ---
 khexedit/conversion.cpp             |  395 +++
 khexedit/converterdialog.cc         |  163 --
 khexedit/converterdialog.cpp        |  163 ++
 khexedit/dialog.cc                  | 1433 ----------
 khexedit/dialog.cpp                 | 1433 ++++++++++
 khexedit/draglabel.cc               |  149 -
 khexedit/draglabel.cpp              |  149 +
 khexedit/exportdialog.cc            |  696 -----
 khexedit/exportdialog.cpp           |  696 +++++
 khexedit/fileinfodialog.cc          |  330 ---
 khexedit/fileinfodialog.cpp         |  330 +++
 khexedit/hexbuffer.cc               | 5099 -----------------------------------
 khexedit/hexbuffer.cpp              | 5099 +++++++++++++++++++++++++++++++++++
 khexedit/hexclipboard.cc            |  254 --
 khexedit/hexclipboard.cpp           |  254 ++
 khexedit/hexdrag.cc                 |  130 -
 khexedit/hexdrag.cpp                |  130 +
 khexedit/hexeditorwidget.cc         | 2443 -----------------
 khexedit/hexeditorwidget.cpp        | 2443 +++++++++++++++++
 khexedit/hexerror.cc                |   69 -
 khexedit/hexerror.cpp               |   69 +
 khexedit/hexmanagerwidget.cc        |  370 ---
 khexedit/hexmanagerwidget.cpp       |  370 +++
 khexedit/hexprinter.cc              |  168 --
 khexedit/hexprinter.cpp             |  168 ++
 khexedit/hextoolwidget.cc           |  416 ---
 khexedit/hextoolwidget.cpp          |  416 +++
 khexedit/hexvalidator.cc            |  329 ---
 khexedit/hexvalidator.cpp           |  329 +++
 khexedit/hexviewwidget.cc           | 2286 ----------------
 khexedit/hexviewwidget.cpp          | 2286 ++++++++++++++++
 khexedit/listview.cc                |   54 -
 khexedit/listview.cpp               |   54 +
 khexedit/main.cc                    |  130 -
 khexedit/main.cpp                   |  130 +
 khexedit/optiondialog.cc            | 1224 ---------
 khexedit/optiondialog.cpp           | 1224 +++++++++
 khexedit/printdialogpage.cc         |  386 ---
 khexedit/printdialogpage.cpp        |  386 +++
 khexedit/searchbar.cc               |  188 --
 khexedit/searchbar.cpp              |  188 ++
 khexedit/statusbarprogress.cc       |  374 ---
 khexedit/statusbarprogress.cpp      |  374 +++
 khexedit/stringdialog.cc            |  412 ---
 khexedit/stringdialog.cpp           |  412 +++
 khexedit/toplevel.cc                | 1363 ----------
 khexedit/toplevel.cpp               | 1363 ++++++++++
 klaptopdaemon/CMakeLists.txt        |    2 +-
 klaptopdaemon/Makefile.am           |    2 +-
 klaptopdaemon/xautolock.cc          |  277 --
 klaptopdaemon/xautolock.cpp         |  277 ++
 kregexpeditor/CMakeLists.txt        |    2 +-
 kregexpeditor/Makefile.am           |    4 +-
 kregexpeditor/gen_qregexplexer.cpp  |    2 +-
 kregexpeditor/gen_qregexpparser.cc  | 1447 ----------
 kregexpeditor/gen_qregexpparser.cpp | 1447 ++++++++++
 kregexpeditor/gen_qregexpparser.h   |   93 +
 kregexpeditor/gen_qregexpparser.hh  |   93 -
 kregexpeditor/qregexpparser.l       |    2 +-
 kregexpeditor/qt-only/compile       |    4 +-
 kregexpeditor/qt-only/qt-only.pro   |    2 +-
 76 files changed, 21586 insertions(+), 21589 deletions(-)
 delete mode 100644 kcharselect/kcharselectdia.cc
 create mode 100644 kcharselect/kcharselectdia.cpp
 delete mode 100644 kcharselect/main.cc
 create mode 100644 kcharselect/main.cpp
 delete mode 100644 khexedit/bitswapwidget.cc
 create mode 100644 khexedit/bitswapwidget.cpp
 delete mode 100644 khexedit/chartabledialog.cc
 create mode 100644 khexedit/chartabledialog.cpp
 delete mode 100644 khexedit/conversion.cc
 create mode 100644 khexedit/conversion.cpp
 delete mode 100644 khexedit/converterdialog.cc
 create mode 100644 khexedit/converterdialog.cpp
 delete mode 100644 khexedit/dialog.cc
 create mode 100644 khexedit/dialog.cpp
 delete mode 100644 khexedit/draglabel.cc
 create mode 100644 khexedit/draglabel.cpp
 delete mode 100644 khexedit/exportdialog.cc
 create mode 100644 khexedit/exportdialog.cpp
 delete mode 100644 khexedit/fileinfodialog.cc
 create mode 100644 khexedit/fileinfodialog.cpp
 delete mode 100644 khexedit/hexbuffer.cc
 create mode 100644 khexedit/hexbuffer.cpp
 delete mode 100644 khexedit/hexclipboard.cc
 create mode 100644 khexedit/hexclipboard.cpp
 delete mode 100644 khexedit/hexdrag.cc
 create mode 100644 khexedit/hexdrag.cpp
 delete mode 100644 khexedit/hexeditorwidget.cc
 create mode 100644 khexedit/hexeditorwidget.cpp
 delete mode 100644 khexedit/hexerror.cc
 create mode 100644 khexedit/hexerror.cpp
 delete mode 100644 khexedit/hexmanagerwidget.cc
 create mode 100644 khexedit/hexmanagerwidget.cpp
 delete mode 100644 khexedit/hexprinter.cc
 create mode 100644 khexedit/hexprinter.cpp
 delete mode 100644 khexedit/hextoolwidget.cc
 create mode 100644 khexedit/hextoolwidget.cpp
 delete mode 100644 khexedit/hexvalidator.cc
 create mode 100644 khexedit/hexvalidator.cpp
 delete mode 100644 khexedit/hexviewwidget.cc
 create mode 100644 khexedit/hexviewwidget.cpp
 delete mode 100644 khexedit/listview.cc
 create mode 100644 khexedit/listview.cpp
 delete mode 100644 khexedit/main.cc
 create mode 100644 khexedit/main.cpp
 delete mode 100644 khexedit/optiondialog.cc
 create mode 100644 khexedit/optiondialog.cpp
 delete mode 100644 khexedit/printdialogpage.cc
 create mode 100644 khexedit/printdialogpage.cpp
 delete mode 100644 khexedit/searchbar.cc
 create mode 100644 khexedit/searchbar.cpp
 delete mode 100644 khexedit/statusbarprogress.cc
 create mode 100644 khexedit/statusbarprogress.cpp
 delete mode 100644 khexedit/stringdialog.cc
 create mode 100644 khexedit/stringdialog.cpp
 delete mode 100644 khexedit/toplevel.cc
 create mode 100644 khexedit/toplevel.cpp
 delete mode 100644 klaptopdaemon/xautolock.cc
 create mode 100644 klaptopdaemon/xautolock.cpp
 delete mode 100644 kregexpeditor/gen_qregexpparser.cc
 create mode 100644 kregexpeditor/gen_qregexpparser.cpp
 create mode 100644 kregexpeditor/gen_qregexpparser.h
 delete mode 100644 kregexpeditor/gen_qregexpparser.hh

diff --git a/ark/ChangeLog b/ark/ChangeLog
index aa440bd7..e9f3e96d 100644
--- a/ark/ChangeLog
+++ b/ark/ChangeLog
@@ -1,8 +1,5 @@
           $Id$
 
-2001-10-24: Roberto Selbach Teixeira <maragato@kde.org>
-	* Renamed all .cc files to .cpp to make things more logic.
-
 2001-06-23: Roberto Selbach Teixeira <maragato@kde.org>
 	* Fixed a bug in tar addition with non-compressed tar archives
 	
@@ -20,12 +17,12 @@
 	  
 2001-05-29  Roberto Selbach Teixeira  <maragato@conectiva.com>
 
-	* compressedfile.cc (unarchFile): move to fromLocal8Bit() to allow
+	* compressedfile.cpp (unarchFile): move to fromLocal8Bit() to allow
 	non-Latin1 characters in filenames.
 
-	* ar.cc (unarchFile): .latin1() to .local8Bit()
+	* ar.cpp (unarchFile): .latin1() to .local8Bit()
 
-	* zip.cc (unarchFile): .latin1() to .local8Bit()
+	* zip.cpp (unarchFile): .latin1() to .local8Bit()
 
 2000-07-10:  Emily Ezust <emilye@corel.com>
 	* Added checks for available disk space
diff --git a/kcharselect/CMakeLists.txt b/kcharselect/CMakeLists.txt
index cc3d6cf5..1ccd7507 100644
--- a/kcharselect/CMakeLists.txt
+++ b/kcharselect/CMakeLists.txt
@@ -25,7 +25,7 @@ link_directories(
 ##### kcharselect (executable) ##################
 
 tde_add_executable( kcharselect AUTOMOC
-  SOURCES kcharselectdia.cc main.cc
+  SOURCES kcharselectdia.cpp main.cpp
   LINK tdeui-shared
   DESTINATION ${BIN_INSTALL_DIR} 
 )
diff --git a/kcharselect/Makefile.am b/kcharselect/Makefile.am
index 2cce07f6..740200c3 100644
--- a/kcharselect/Makefile.am
+++ b/kcharselect/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = $(all_includes)
 LDADD	= $(LIB_TDEFILE)
 bin_PROGRAMS = kcharselect
 
-kcharselect_SOURCES = kcharselectdia.cc main.cc
+kcharselect_SOURCES = kcharselectdia.cpp main.cpp
 kcharselect_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor
 kcharselect_METASOURCES = kcharselectdia.moc
 
@@ -17,5 +17,5 @@ rcdir = $(kde_datadir)/kcharselect
 rc_DATA = kcharselectui.rc
 
 messages: rc.cpp
-	$(XGETTEXT) *.cc *.cpp -o $(podir)/kcharselect.pot 
+	$(XGETTEXT) *.cpp -o $(podir)/kcharselect.pot 
 
diff --git a/kcharselect/kcharselectdia.cc b/kcharselect/kcharselectdia.cc
deleted file mode 100644
index 8750b68e..00000000
--- a/kcharselect/kcharselectdia.cc
+++ /dev/null
@@ -1,289 +0,0 @@
-/******************************************************************/
-/* KCharSelectDia - (c) by Reginald Stadlbauer 1999               */
-/* Author: Reginald Stadlbauer                                    */
-/* E-Mail: reggie@kde.org                                         */
-/*         RTL support by Bryce Nesbitt                           */
-/******************************************************************/
-
-#include "kcharselectdia.moc"
-
-#include <stdlib.h>
-
-#include <kdialog.h>
-#include <tdeapplication.h>
-#include <tdeaccel.h>
-#include <tdeconfig.h>
-#include <tdelocale.h>
-#include <tdeaction.h>
-
-/******************************************************************/
-/* class KCharSelectDia                                           */
-/******************************************************************/
-
-//==================================================================
-KCharSelectDia::KCharSelectDia(TQWidget *parent,const char *name,
-			       const TQChar &_chr,const TQString &_font,
-			       int _tableNum, bool direction)
-  : TDEMainWindow(parent,name), vChr(_chr), vFont(_font)
-{
-  setCaption(TQString()); // Standard caption
-
-  TQWidget *mainWidget = new TQWidget(this);
-  setCentralWidget(mainWidget);
-
-  grid = new TQGridLayout( mainWidget, 3, 4, KDialog::marginHint(), KDialog::spacingHint() );
-
-  // Add character selection widget from library tdeui
-  charSelect = new KCharSelect(mainWidget,"",vFont,vChr,_tableNum);
-  charSelect->resize(charSelect->sizeHint());
-  connect(charSelect,TQT_SIGNAL(highlighted(const TQChar &)),
-	  TQT_SLOT(charChanged(const TQChar &)));
-  connect(charSelect,TQT_SIGNAL(activated(const TQChar &)),
-	  TQT_SLOT(add(const TQChar &)));
-  connect(charSelect,TQT_SIGNAL(fontChanged(const TQString &)),
-	  TQT_SLOT(fontSelected(const TQString &)));
-  grid->addMultiCellWidget(charSelect, 0, 0, 0, 3);
-
-  // Build line editor
-  lined = new TQLineEdit(mainWidget);
-  lined->resize(lined->sizeHint());
-
-  TQFont font = lined->font();
-  font.setFamily( vFont );
-  lined->setFont( font );
-
-  connect(lined,TQT_SIGNAL(textChanged(const TQString &)),
-	  TQT_SLOT(lineEditChanged()));
-  grid->addMultiCellWidget(lined, 1, 1, 0, 3);
-
-  // Build some buttons
-  bHelp = new KPushButton( KStdGuiItem::help(), mainWidget );
-  connect(bHelp,TQT_SIGNAL(clicked()),this,TQT_SLOT(help()));
-  bHelp->setFixedSize( bHelp->sizeHint() );
-  grid->addWidget( bHelp, 2, 0 );
-
-  TQSpacerItem *space = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding );
-  grid->addItem( space, 2, 1 );
-
-  bClear = new KPushButton( KStdGuiItem::clear(), mainWidget );
-  connect(bClear,TQT_SIGNAL(clicked()),this,TQT_SLOT(clear()));
-  bClear->setFixedSize( bClear->sizeHint() );
-  grid->addWidget( bClear, 2, 2 );
-
-  bClip = new KPushButton( KGuiItem( i18n( "&To Clipboard" ),
-            "edit-copy" ), mainWidget );
-  bClip->setFixedSize( bClip->sizeHint() );
-  connect(bClip,TQT_SIGNAL(clicked()),this,TQT_SLOT(toClip()));
-  grid->addWidget( bClip, 2, 3 );
-
-  // Build menu
-  KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(_exit()), actionCollection() );
-  
-  new TDEAction(i18n("&To Clipboard"), "edit-copy",
-         TDEStdAccel::shortcut(TDEStdAccel::Copy), TQT_TQOBJECT(this), TQT_SLOT(toClip()), actionCollection(), "copy_clip" );
-
-  (void)new TDEAction(i18n("To Clipboard &UTF-8"), 0, TQT_TQOBJECT(this),
-    TQT_SLOT(toClipUTF8()), actionCollection(), "copy_utf_8" );
-  (void)new TDEAction(i18n("To Clipboard &HTML"), 0, TQT_TQOBJECT(this),
-      TQT_SLOT(toClipHTML()), actionCollection(), "copy_html" );
- 
-  new TDEAction(i18n("&From Clipboard"), "edit-paste",
-         TDEStdAccel::shortcut(TDEStdAccel::Paste), TQT_TQOBJECT(this), TQT_SLOT(fromClip()), actionCollection(), "from_clip" );
-  (void)new TDEAction(i18n("From Clipboard UTF-8"), 0, TQT_TQOBJECT(this),
-      TQT_SLOT(fromClipUTF8()), actionCollection(), "from_clip_utf8" );
-  
-  i18n("From Clipboard HTML");      // Intended for future use
-  
-  KStdAction::clear(TQT_TQOBJECT(this), TQT_SLOT(clear()), actionCollection(), "clear");
-  (void)new TDEAction(i18n("&Flip"), 0, TQT_TQOBJECT(this),
-      TQT_SLOT(flipText()), actionCollection(), "flip" );
-  (void)new TDEAction(i18n("&Alignment"), 0, TQT_TQOBJECT(this),
-      TQT_SLOT(toggleEntryDirection()), actionCollection(), "alignment" );
-  
-  charSelect->setFocus();
-
-  entryDirection = direction;
-  if( entryDirection )
-    lined->setAlignment( TQt::AlignRight );
-  else
-    lined->setAlignment( TQt::AlignLeft );
-
-  setupGUI(Keys|StatusBar|Save|Create);
-}
-
-//==================================================================
-void KCharSelectDia::charChanged(const TQChar &_chr)
-{
-  vChr = _chr;
-}
-
-//==================================================================
-void KCharSelectDia::fontSelected(const TQString &_font)
-{
-  charSelect->setFont(_font);
-
-  TQFont font = lined->font();
-  font.setFamily( _font );
-  lined->setFont( font );
-
-  vFont = _font;
-}
-
-//==================================================================
-void KCharSelectDia::add(const TQChar &_chr)
-{
-  TQString str;
-  int cursorPos;
-
-  charChanged(_chr);
-
-  str       = lined->text();
-  cursorPos = lined->cursorPosition();
-  str.insert( cursorPos, vChr );
-  lined->setText(str);
-  cursorPos++;
-  lined->setCursorPosition( cursorPos );
-}
-
-//==================================================================
-void KCharSelectDia::toClip()
-{
-  TQClipboard *cb = TQApplication::clipboard();
-  cb->setSelectionMode( true );
-  cb->setText(lined->text());
-  cb->setSelectionMode( false );
-  cb->setText(lined->text());
-}
-
-//==================================================================
-// UTF-8 is rapidly becoming the favored 8-bit encoding for
-// Unicode (iso10646-1).
-//
-void KCharSelectDia::toClipUTF8()
-{
-  TQClipboard *cb = TQApplication::clipboard();
-  TQString str = lined->text();
-  cb->setText(str.utf8());
-}
-
-//==================================================================
-//  Put valid HTML 4.0 into the clipboard.  Valid ISO-8859-1 Latin 1
-//  characters are left undisturbed.  Everything else, including the
-//  "c0 control characters" often used by Windows, are clipped
-//  as a HTML entity.
-//
-void KCharSelectDia::toClipHTML()
-{
-  TQClipboard *cb = TQApplication::clipboard();
-  TQString input;
-  TQString html;
-  TQString tempstring;
-  TQChar   tempchar;
-  uint i;
-
-  input = lined->text();
-  for(i=0; i< input.length(); i++ )
-    {
-      tempchar = input.at(i);
-      if(  tempchar.latin1() && ((tempchar.unicode() < 128) || (tempchar.unicode() >= 128+32)) )
-        {
-          html.append(input.at(i));
-        }
-      else
-        {
-          html.append(tempstring.sprintf("&#x%x;", tempchar.unicode()));
-        }
-    }
-  cb->setText(html);
-}
-
-//==================================================================
-//
-void KCharSelectDia::fromClip()
-{
-  TQClipboard *cb = TQApplication::clipboard();
-  lined->setText( cb->text() );
-}
-
-//==================================================================
-// UTF-8 is rapidly becoming the favored 8-bit encoding for
-// Unicode (iso10646-1).  This function is handy for decoding
-// UTF-8 found in legacy applications, consoles, filenames, webpages,
-// etc.
-//
-void KCharSelectDia::fromClipUTF8()
-{
-  TQClipboard *cb = TQApplication::clipboard();
-  TQString str = cb->text();
-
-  lined->setText( str.fromUtf8( str.latin1() ) );
-}
-
-//==================================================================
-//  Reverse the text held in the line edit buffer.  This is crucial
-//  for dealing with visual vs. logical representations of
-//  right to left languages, and handy for working around all
-//  manner of legacy character order issues.
-//
-void KCharSelectDia::flipText()
-{
-  TQString input;
-  TQString output;
-  uint i;
-
-  input = lined->text();
-  for(i=0; i< input.length(); i++ )
-    {
-      output.prepend( input.at(i) );
-    }
-  lined->setText(output);
-}
-
-//==================================================================
-void KCharSelectDia::toggleEntryDirection()
-{
-    entryDirection ^= 1;
-    if( entryDirection )
-        lined->setAlignment( TQt::AlignRight );
-    else
-        lined->setAlignment( TQt::AlignLeft );
-}
-
-//==================================================================
-void KCharSelectDia::lineEditChanged()
-{
-    if( entryDirection )
-      {
-        if(lined->cursorPosition())
-            lined->setCursorPosition( lined->cursorPosition() - 1 );
-      }
-}
-
-//==================================================================
-void KCharSelectDia::_exit()
-{
-  TDEConfig *config = kapp->config();
-
-  config->setGroup("General");
-  config->writeEntry("selectedFont",vFont);
-  config->writeEntry("char",static_cast<int>(vChr.unicode()));
-  config->writeEntry("table",charSelect->tableNum());
-  config->writeEntry("entryDirection",entryDirection);
-  config->sync();
-
-  delete this;
-  exit(0);
-}
-
-//==================================================================
-void KCharSelectDia::clear()
-{
-  lined->clear();
-}
-
-//==================================================================
-void KCharSelectDia::help()
-{
-  kapp->invokeHelp();
-}
-
diff --git a/kcharselect/kcharselectdia.cpp b/kcharselect/kcharselectdia.cpp
new file mode 100644
index 00000000..8750b68e
--- /dev/null
+++ b/kcharselect/kcharselectdia.cpp
@@ -0,0 +1,289 @@
+/******************************************************************/
+/* KCharSelectDia - (c) by Reginald Stadlbauer 1999               */
+/* Author: Reginald Stadlbauer                                    */
+/* E-Mail: reggie@kde.org                                         */
+/*         RTL support by Bryce Nesbitt                           */
+/******************************************************************/
+
+#include "kcharselectdia.moc"
+
+#include <stdlib.h>
+
+#include <kdialog.h>
+#include <tdeapplication.h>
+#include <tdeaccel.h>
+#include <tdeconfig.h>
+#include <tdelocale.h>
+#include <tdeaction.h>
+
+/******************************************************************/
+/* class KCharSelectDia                                           */
+/******************************************************************/
+
+//==================================================================
+KCharSelectDia::KCharSelectDia(TQWidget *parent,const char *name,
+			       const TQChar &_chr,const TQString &_font,
+			       int _tableNum, bool direction)
+  : TDEMainWindow(parent,name), vChr(_chr), vFont(_font)
+{
+  setCaption(TQString()); // Standard caption
+
+  TQWidget *mainWidget = new TQWidget(this);
+  setCentralWidget(mainWidget);
+
+  grid = new TQGridLayout( mainWidget, 3, 4, KDialog::marginHint(), KDialog::spacingHint() );
+
+  // Add character selection widget from library tdeui
+  charSelect = new KCharSelect(mainWidget,"",vFont,vChr,_tableNum);
+  charSelect->resize(charSelect->sizeHint());
+  connect(charSelect,TQT_SIGNAL(highlighted(const TQChar &)),
+	  TQT_SLOT(charChanged(const TQChar &)));
+  connect(charSelect,TQT_SIGNAL(activated(const TQChar &)),
+	  TQT_SLOT(add(const TQChar &)));
+  connect(charSelect,TQT_SIGNAL(fontChanged(const TQString &)),
+	  TQT_SLOT(fontSelected(const TQString &)));
+  grid->addMultiCellWidget(charSelect, 0, 0, 0, 3);
+
+  // Build line editor
+  lined = new TQLineEdit(mainWidget);
+  lined->resize(lined->sizeHint());
+
+  TQFont font = lined->font();
+  font.setFamily( vFont );
+  lined->setFont( font );
+
+  connect(lined,TQT_SIGNAL(textChanged(const TQString &)),
+	  TQT_SLOT(lineEditChanged()));
+  grid->addMultiCellWidget(lined, 1, 1, 0, 3);
+
+  // Build some buttons
+  bHelp = new KPushButton( KStdGuiItem::help(), mainWidget );
+  connect(bHelp,TQT_SIGNAL(clicked()),this,TQT_SLOT(help()));
+  bHelp->setFixedSize( bHelp->sizeHint() );
+  grid->addWidget( bHelp, 2, 0 );
+
+  TQSpacerItem *space = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding );
+  grid->addItem( space, 2, 1 );
+
+  bClear = new KPushButton( KStdGuiItem::clear(), mainWidget );
+  connect(bClear,TQT_SIGNAL(clicked()),this,TQT_SLOT(clear()));
+  bClear->setFixedSize( bClear->sizeHint() );
+  grid->addWidget( bClear, 2, 2 );
+
+  bClip = new KPushButton( KGuiItem( i18n( "&To Clipboard" ),
+            "edit-copy" ), mainWidget );
+  bClip->setFixedSize( bClip->sizeHint() );
+  connect(bClip,TQT_SIGNAL(clicked()),this,TQT_SLOT(toClip()));
+  grid->addWidget( bClip, 2, 3 );
+
+  // Build menu
+  KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(_exit()), actionCollection() );
+  
+  new TDEAction(i18n("&To Clipboard"), "edit-copy",
+         TDEStdAccel::shortcut(TDEStdAccel::Copy), TQT_TQOBJECT(this), TQT_SLOT(toClip()), actionCollection(), "copy_clip" );
+
+  (void)new TDEAction(i18n("To Clipboard &UTF-8"), 0, TQT_TQOBJECT(this),
+    TQT_SLOT(toClipUTF8()), actionCollection(), "copy_utf_8" );
+  (void)new TDEAction(i18n("To Clipboard &HTML"), 0, TQT_TQOBJECT(this),
+      TQT_SLOT(toClipHTML()), actionCollection(), "copy_html" );
+ 
+  new TDEAction(i18n("&From Clipboard"), "edit-paste",
+         TDEStdAccel::shortcut(TDEStdAccel::Paste), TQT_TQOBJECT(this), TQT_SLOT(fromClip()), actionCollection(), "from_clip" );
+  (void)new TDEAction(i18n("From Clipboard UTF-8"), 0, TQT_TQOBJECT(this),
+      TQT_SLOT(fromClipUTF8()), actionCollection(), "from_clip_utf8" );
+  
+  i18n("From Clipboard HTML");      // Intended for future use
+  
+  KStdAction::clear(TQT_TQOBJECT(this), TQT_SLOT(clear()), actionCollection(), "clear");
+  (void)new TDEAction(i18n("&Flip"), 0, TQT_TQOBJECT(this),
+      TQT_SLOT(flipText()), actionCollection(), "flip" );
+  (void)new TDEAction(i18n("&Alignment"), 0, TQT_TQOBJECT(this),
+      TQT_SLOT(toggleEntryDirection()), actionCollection(), "alignment" );
+  
+  charSelect->setFocus();
+
+  entryDirection = direction;
+  if( entryDirection )
+    lined->setAlignment( TQt::AlignRight );
+  else
+    lined->setAlignment( TQt::AlignLeft );
+
+  setupGUI(Keys|StatusBar|Save|Create);
+}
+
+//==================================================================
+void KCharSelectDia::charChanged(const TQChar &_chr)
+{
+  vChr = _chr;
+}
+
+//==================================================================
+void KCharSelectDia::fontSelected(const TQString &_font)
+{
+  charSelect->setFont(_font);
+
+  TQFont font = lined->font();
+  font.setFamily( _font );
+  lined->setFont( font );
+
+  vFont = _font;
+}
+
+//==================================================================
+void KCharSelectDia::add(const TQChar &_chr)
+{
+  TQString str;
+  int cursorPos;
+
+  charChanged(_chr);
+
+  str       = lined->text();
+  cursorPos = lined->cursorPosition();
+  str.insert( cursorPos, vChr );
+  lined->setText(str);
+  cursorPos++;
+  lined->setCursorPosition( cursorPos );
+}
+
+//==================================================================
+void KCharSelectDia::toClip()
+{
+  TQClipboard *cb = TQApplication::clipboard();
+  cb->setSelectionMode( true );
+  cb->setText(lined->text());
+  cb->setSelectionMode( false );
+  cb->setText(lined->text());
+}
+
+//==================================================================
+// UTF-8 is rapidly becoming the favored 8-bit encoding for
+// Unicode (iso10646-1).
+//
+void KCharSelectDia::toClipUTF8()
+{
+  TQClipboard *cb = TQApplication::clipboard();
+  TQString str = lined->text();
+  cb->setText(str.utf8());
+}
+
+//==================================================================
+//  Put valid HTML 4.0 into the clipboard.  Valid ISO-8859-1 Latin 1
+//  characters are left undisturbed.  Everything else, including the
+//  "c0 control characters" often used by Windows, are clipped
+//  as a HTML entity.
+//
+void KCharSelectDia::toClipHTML()
+{
+  TQClipboard *cb = TQApplication::clipboard();
+  TQString input;
+  TQString html;
+  TQString tempstring;
+  TQChar   tempchar;
+  uint i;
+
+  input = lined->text();
+  for(i=0; i< input.length(); i++ )
+    {
+      tempchar = input.at(i);
+      if(  tempchar.latin1() && ((tempchar.unicode() < 128) || (tempchar.unicode() >= 128+32)) )
+        {
+          html.append(input.at(i));
+        }
+      else
+        {
+          html.append(tempstring.sprintf("&#x%x;", tempchar.unicode()));
+        }
+    }
+  cb->setText(html);
+}
+
+//==================================================================
+//
+void KCharSelectDia::fromClip()
+{
+  TQClipboard *cb = TQApplication::clipboard();
+  lined->setText( cb->text() );
+}
+
+//==================================================================
+// UTF-8 is rapidly becoming the favored 8-bit encoding for
+// Unicode (iso10646-1).  This function is handy for decoding
+// UTF-8 found in legacy applications, consoles, filenames, webpages,
+// etc.
+//
+void KCharSelectDia::fromClipUTF8()
+{
+  TQClipboard *cb = TQApplication::clipboard();
+  TQString str = cb->text();
+
+  lined->setText( str.fromUtf8( str.latin1() ) );
+}
+
+//==================================================================
+//  Reverse the text held in the line edit buffer.  This is crucial
+//  for dealing with visual vs. logical representations of
+//  right to left languages, and handy for working around all
+//  manner of legacy character order issues.
+//
+void KCharSelectDia::flipText()
+{
+  TQString input;
+  TQString output;
+  uint i;
+
+  input = lined->text();
+  for(i=0; i< input.length(); i++ )
+    {
+      output.prepend( input.at(i) );
+    }
+  lined->setText(output);
+}
+
+//==================================================================
+void KCharSelectDia::toggleEntryDirection()
+{
+    entryDirection ^= 1;
+    if( entryDirection )
+        lined->setAlignment( TQt::AlignRight );
+    else
+        lined->setAlignment( TQt::AlignLeft );
+}
+
+//==================================================================
+void KCharSelectDia::lineEditChanged()
+{
+    if( entryDirection )
+      {
+        if(lined->cursorPosition())
+            lined->setCursorPosition( lined->cursorPosition() - 1 );
+      }
+}
+
+//==================================================================
+void KCharSelectDia::_exit()
+{
+  TDEConfig *config = kapp->config();
+
+  config->setGroup("General");
+  config->writeEntry("selectedFont",vFont);
+  config->writeEntry("char",static_cast<int>(vChr.unicode()));
+  config->writeEntry("table",charSelect->tableNum());
+  config->writeEntry("entryDirection",entryDirection);
+  config->sync();
+
+  delete this;
+  exit(0);
+}
+
+//==================================================================
+void KCharSelectDia::clear()
+{
+  lined->clear();
+}
+
+//==================================================================
+void KCharSelectDia::help()
+{
+  kapp->invokeHelp();
+}
+
diff --git a/kcharselect/main.cc b/kcharselect/main.cc
deleted file mode 100644
index cb74af5f..00000000
--- a/kcharselect/main.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-/******************************************************************/
-/* KCharSelectDia - (c) by Reginald Stadlbauer 1999               */
-/* Author: Reginald Stadlbauer                                    */
-/* E-Mail: reggie@kde.org                                         */
-/******************************************************************/
-
-#include "kcharselectdia.h"
-
-#include <tdeapplication.h>
-#include <tdeconfig.h>
-#include <tdecmdlineargs.h>
-#include <tdeaboutdata.h>
-#include <tdeglobalsettings.h>
-
-static const char description[] = 
-	I18N_NOOP("TDE character selection utility");
-
-/*================================================================*/
-int main(int argc, char **argv)
-{
-  TDEAboutData aboutData( "kcharselect", I18N_NOOP("KCharSelect"),
-    version, description, TDEAboutData::License_GPL,
-    "(c) 1999, Reginald Stadlbauer");
-  aboutData.addAuthor("Reginald Stadlbauer",0, "reggie@kde.org");
-  aboutData.addCredit( "Nadeem Hasan", I18N_NOOP( "GUI cleanup and fixes" ),
-        "nhasan@kde.org" );
-  aboutData.addCredit( "Ryan Cumming", I18N_NOOP( "GUI cleanup and fixes" ),
-        "bodnar42@phalynx.dhs.org" );
-  aboutData.addCredit("Benjamin C. Meyer",I18N_NOOP("XMLUI conversion"),"ben+kcharselect@meyerhome.net");
-	TDECmdLineArgs::init( argc, argv, &aboutData );
-
-  TDEApplication app;
-
-  TDEConfig *config = kapp->config();
-
-  config->setGroup("General");
-  TQString font(config->readEntry("selectedFont", TDEGlobalSettings::generalFont().family()));
-  TQChar c = TQChar(static_cast<unsigned short>(config->readNumEntry("char",33)));
-  int tn = config->readNumEntry("table",0);
-  bool direction = config->readNumEntry("entryDirection",0);
-  
-  KCharSelectDia *dia = new KCharSelectDia(0L,"",c,font,tn,direction);
-
-  app.setMainWidget(dia);
-  dia->show();
-
-  return app.exec();
-}
-
diff --git a/kcharselect/main.cpp b/kcharselect/main.cpp
new file mode 100644
index 00000000..cb74af5f
--- /dev/null
+++ b/kcharselect/main.cpp
@@ -0,0 +1,49 @@
+/******************************************************************/
+/* KCharSelectDia - (c) by Reginald Stadlbauer 1999               */
+/* Author: Reginald Stadlbauer                                    */
+/* E-Mail: reggie@kde.org                                         */
+/******************************************************************/
+
+#include "kcharselectdia.h"
+
+#include <tdeapplication.h>
+#include <tdeconfig.h>
+#include <tdecmdlineargs.h>
+#include <tdeaboutdata.h>
+#include <tdeglobalsettings.h>
+
+static const char description[] = 
+	I18N_NOOP("TDE character selection utility");
+
+/*================================================================*/
+int main(int argc, char **argv)
+{
+  TDEAboutData aboutData( "kcharselect", I18N_NOOP("KCharSelect"),
+    version, description, TDEAboutData::License_GPL,
+    "(c) 1999, Reginald Stadlbauer");
+  aboutData.addAuthor("Reginald Stadlbauer",0, "reggie@kde.org");
+  aboutData.addCredit( "Nadeem Hasan", I18N_NOOP( "GUI cleanup and fixes" ),
+        "nhasan@kde.org" );
+  aboutData.addCredit( "Ryan Cumming", I18N_NOOP( "GUI cleanup and fixes" ),
+        "bodnar42@phalynx.dhs.org" );
+  aboutData.addCredit("Benjamin C. Meyer",I18N_NOOP("XMLUI conversion"),"ben+kcharselect@meyerhome.net");
+	TDECmdLineArgs::init( argc, argv, &aboutData );
+
+  TDEApplication app;
+
+  TDEConfig *config = kapp->config();
+
+  config->setGroup("General");
+  TQString font(config->readEntry("selectedFont", TDEGlobalSettings::generalFont().family()));
+  TQChar c = TQChar(static_cast<unsigned short>(config->readNumEntry("char",33)));
+  int tn = config->readNumEntry("table",0);
+  bool direction = config->readNumEntry("entryDirection",0);
+  
+  KCharSelectDia *dia = new KCharSelectDia(0L,"",c,font,tn,direction);
+
+  app.setMainWidget(dia);
+  dia->show();
+
+  return app.exec();
+}
+
diff --git a/kgpg/Makefile.am b/kgpg/Makefile.am
index e4b78eb5..9191bb28 100644
--- a/kgpg/Makefile.am
+++ b/kgpg/Makefile.am
@@ -37,7 +37,7 @@ KDE_ICON = kgpg
 
 messages: rc.cpp
 	$(PREPARETIPS) > tips.txt
-	LIST=`find . -name \*.h -o -name \*.txt -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
+	LIST=`find . -name \*.h -o -name \*.txt -o -name \*.cpp; \
 	if test -n "$$LIST"; then \
 	 $(XGETTEXT) $$LIST -o $(podir)/kgpg.pot; \
 	fi
diff --git a/khexedit/CMakeLists.txt b/khexedit/CMakeLists.txt
index 12d3b466..003fdf60 100644
--- a/khexedit/CMakeLists.txt
+++ b/khexedit/CMakeLists.txt
@@ -29,16 +29,16 @@ link_directories(
 ##### khexedit (executable) #####################
 
 tde_add_executable( khexedit AUTOMOC
-  SOURCES main.cc toplevel.cc hexmanagerwidget.cc
-    hexeditorwidget.cc hextoolwidget.cc
-    hexviewwidget.cc hexbuffer.cc conversion.cc
-    dialog.cc hexvalidator.cc hexclipboard.cc
-    optiondialog.cc printdialogpage.cc
-    statusbarprogress.cc hexprinter.cc
-    hexerror.cc draglabel.cc stringdialog.cc
-    bitswapwidget.cc chartabledialog.cc
-    hexdrag.cc exportdialog.cc fileinfodialog.cc
-    converterdialog.cc listview.cc searchbar.cc
+  SOURCES main.cpp toplevel.cpp hexmanagerwidget.cpp
+    hexeditorwidget.cpp hextoolwidget.cpp
+    hexviewwidget.cpp hexbuffer.cpp conversion.cpp
+    dialog.cpp hexvalidator.cpp hexclipboard.cpp
+    optiondialog.cpp printdialogpage.cpp
+    statusbarprogress.cpp hexprinter.cpp
+    hexerror.cpp draglabel.cpp stringdialog.cpp
+    bitswapwidget.cpp chartabledialog.cpp
+    hexdrag.cpp exportdialog.cpp fileinfodialog.cpp
+    converterdialog.cpp listview.cpp searchbar.cpp
   LINK tdeio-shared tdeprint-shared
   DESTINATION ${BIN_INSTALL_DIR}
 )
diff --git a/khexedit/Makefile.am b/khexedit/Makefile.am
index 45c34f71..e261c551 100644
--- a/khexedit/Makefile.am
+++ b/khexedit/Makefile.am
@@ -4,13 +4,13 @@ SUBDIRS = pics lib parts
 
 bin_PROGRAMS = khexedit
 
-khexedit_SOURCES = main.cc toplevel.cc hexmanagerwidget.cc \
-hexeditorwidget.cc hextoolwidget.cc hexviewwidget.cc hexbuffer.cc \
-conversion.cc dialog.cc hexvalidator.cc hexclipboard.cc \
-optiondialog.cc printdialogpage.cc statusbarprogress.cc \
-hexprinter.cc hexerror.cc draglabel.cc stringdialog.cc \
-bitswapwidget.cc chartabledialog.cc hexdrag.cc exportdialog.cc \
-fileinfodialog.cc converterdialog.cc listview.cc searchbar.cc
+khexedit_SOURCES = main.cpp toplevel.cpp hexmanagerwidget.cpp \
+hexeditorwidget.cpp hextoolwidget.cpp hexviewwidget.cpp hexbuffer.cpp \
+conversion.cpp dialog.cpp hexvalidator.cpp hexclipboard.cpp \
+optiondialog.cpp printdialogpage.cpp statusbarprogress.cpp \
+hexprinter.cpp hexerror.cpp draglabel.cpp stringdialog.cpp \
+bitswapwidget.cpp chartabledialog.cpp hexdrag.cpp exportdialog.cpp \
+fileinfodialog.cpp converterdialog.cpp listview.cpp searchbar.cpp
 
 noinst_HEADERS = toplevel.h hexmanagerwidget.h hexeditorwidget.h \
 hextoolwidget.h hexviewwidget.h hexbuffer.h conversion.h dialog.h \
@@ -32,4 +32,4 @@ rc_DATA = khexeditui.rc
 
 messages: rc.cpp
 	$(EXTRACTRC) parts/kpart/*rc >> rc.cpp
-	$(XGETTEXT) rc.cpp `find . -name \*.cc -o -name \*.cpp` -o $(podir)/khexedit.pot
+	$(XGETTEXT) rc.cpp `find . -name \*.cpp` -o $(podir)/khexedit.pot
diff --git a/khexedit/bitswapwidget.cc b/khexedit/bitswapwidget.cc
deleted file mode 100644
index e281d2bd..00000000
--- a/khexedit/bitswapwidget.cc
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <tqpainter.h>
- 
-#include <tdeglobalsettings.h>
-
-#include "bitswapwidget.h"
-
-CDigitLabel::CDigitLabel( TQWidget *parent, uint digit, const char *name )
-  :TQLabel(parent, name), mDigit( digit ), mDotPosition( 0 )
-{
-  setFocusPolicy( TQ_StrongFocus );
-  initialize();
-}
-
-CDigitLabel::~CDigitLabel( void )
-{
-
-}
-
-void CDigitLabel::initialize( void )
-{
-  TQFont font( TDEGlobalSettings::generalFont() );
-  font.setBold( true );
-  setFont( font );
-}
-
-
-void CDigitLabel::paletteChange( const TQPalette & )
-{
-  update();
-}
-
-
-void CDigitLabel::setValue( uint digit, bool notify )
-{
-  if( mDigit != digit )
-  {
-    if( notify == true )
-    {
-      emit valueChanged( TQT_TQOBJECT(this), digit, false );
-    }
-
-    mDigit = digit;
-    update();
-
-    if( notify == true )
-    {
-      emit valueChanged( TQT_TQOBJECT(this), mDigit, true );
-    }
-  }
-}
-
-
-void CDigitLabel::setDotPosition( uint dotPosition )
-{
-  if( mDotPosition != dotPosition )
-  {
-    mDotPosition = dotPosition;
-    update();
-  }
-}
-
-
-
-TQSize CDigitLabel::sizeHint( void ) const
-{
-  int h = fontMetrics().height();
-  TQSize s( h, h ); // Retangular
-  return( s );
-}
- 
-
-#include <stdio.h>
-
-
-void CDigitLabel::drawContents( TQPainter *p )
-{
-  TQRect cr = contentsRect();
-
-  if( hasFocus() == true )
-  {
-    p->fillRect( cr, palette().active().highlight() );
-    p->setPen( palette().active().highlightedText() );
-  }
-  else
-  {
-    p->fillRect( cr, palette().active().base() );
-    p->setPen( palette().active().text() );
-  }
-
-  if( mDotPosition != 0 )
-  {
-    p->fillRect( cr.x()+2, cr.y()+2, 5, 5, TQt::red ); // UL    
-    /*
-    if( mDotPosition == 1 )
-    {
-      p->fillRect( cr.x()+2, cr.y()+2, 5, 5, red ); // UL
-    }
-    else if( mDotPosition == 2 )
-    {
-      p->fillRect( cr.width()-7, cr.y()+2, 5, 5, red ); // UR
-    }
-    else if( mDotPosition == 3 ) 
-    {
-      p->fillRect( cr.x()+2, cr.height()-7, 5, 5, red ); // LL
-    }
-    else if( mDotPosition == 4 )
-    {
-      p->fillRect( cr.width()-7, cr.height()-7, 5, 5, red ); // LR
-    } 
-    */
-  }
-
-  TQString text;
-  text.setNum( mDigit );
-  p->drawText( 0, 0, cr.width(), cr.height(), alignment(), text );
-
-  
-
-}
-
-
-void CDigitLabel::keyPressEvent( TQKeyEvent *e )  
-{
-  switch ( e->key() ) 
-  {
-    case Key_Left:
-    case Key_Up: 
-      emit stepCell( TQT_TQOBJECT(this), false );
-    break;
-
-    case Key_Right:
-    case Key_Down:  
-      emit stepCell( TQT_TQOBJECT(this), true );
-    break;
-    
-    case Key_Escape:
-      e->ignore(); // Allow dialog or whatever use this one
-      return;
-    break;
-
-    default:
-    {
-      int val =  e->text()[0].digitValue();
-      if( val >= 0 && val <= 7 )
-      {
-	setValue( val, true );
-      }
-    }
-    break;
-  }
-  
-  e->accept();
-}
-
-
-
-CByteWidget::CByteWidget( TQWidget *parent, const char *name )
-  :TQWidget(parent, name)
-{
-  mHBox = new TQHBoxLayout( this, 0 );
-  
-  for( uint i=0; i<8; i++ )
-  {
-    mDigit[i] = new CDigitLabel( this, 7-i );
-    mDigit[i]->setLineWidth( 1 );
-    mDigit[i]->setFixedSize( mDigit[i]->sizeHint()*2 );
-    mDigit[i]->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
-    mDigit[i]->setAlignment( AlignCenter );
-    connect( mDigit[i], TQT_SIGNAL(stepCell(const TQObject *, bool )),
-	     this, TQT_SLOT(stepCell(const TQObject *, bool )));
-    connect( mDigit[i], TQT_SIGNAL(valueChanged(const TQObject *, uint, bool )),
-	     this, TQT_SLOT(valueChanged(const TQObject *, uint, bool )));
-    mHBox->addWidget( mDigit[i] );
-  }
-
-  mHBox->addStretch();  
-}
-
-CByteWidget::~CByteWidget( void )
-{
-  for( uint i=0; i<8; i++ ) { delete mDigit[i]; }
-  delete mHBox;
-}
-
-void CByteWidget::stepCell( const TQObject *obj, bool next )
-{
-  for( uint i=0; i<8; i++ )
-  {
-    if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
-    {
-      if( next == true )
-      {
-	mDigit[(i+1)%8]->setFocus();
-      }
-      else
-      {
-	mDigit[(i+7)%8]->setFocus();
-      }
-    }
-  }
-}
-
-
-
-void CByteWidget::valueChanged( const TQObject *obj, uint val, bool after )
-{
-  if( after == false )
-  {
-    for( uint i=0; i<8; i++ )
-    {
-      if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
-      {
-	uint tmp = 7-mDigit[i]->value();
-	mDigit[tmp]->setValue( mDigit[i]->value(), false );
-	break;
-      }
-    }
-
-
-    if( mDigit[7-val]->value() != val )
-    {
-      uint tmp = mDigit[7-val]->value();
-      mDigit[7-tmp]->setValue( tmp, false );
-      mDigit[7-val]->setValue( val, false );
-    }
-
-  }
-  else
-  {
-    setBuddy( obj );
-
-    uint pos = 1;
-    for( uint i=0; i<8; i++ )
-    {
-      if( mDigit[i]->value() < (7-i) )
-      {
-	mDigit[i]->setDotPosition( pos );
-	mDigit[7-mDigit[i]->value()]->setDotPosition( pos );
-	pos++;
-      }
-      else if( mDigit[i]->value() == (7-i) )
-      {
-	mDigit[i]->setDotPosition( 0 );
-      }
-    }
-
-  }
-}
-
-
-void CByteWidget::reset( void )
-{
-  for( uint i=0; i<8; i++ )
-  {
-    mDigit[i]->setValue( 7-i, false );
-    mDigit[i]->setDotPosition( 0 );
-  }
-}
-
-
-void CByteWidget::setBuddy( const TQObject *obj )
-{
-  for( uint i=0; i<8; i++ )
-  {
-    if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
-    {
-      uint val = mDigit[i]->value();
-      if( val < 8 )
-      {
-	mDigit[7-val]->setValue( 7-i, false );
-      }
-      break;
-    }
-  }
-}
-
-
-
-
-
-bool CByteWidget::flag( TQByteArray &buf )
-{
-  bool swapPresent = false;
-  uint i, j;
-  
-  buf.resize( 8 );
-  for( i=0; i<8; buf[i++] = 0 );
-
-  for( i=j=0; i<8; i++ )
-  {
-    if( mDigit[i]->value() < (7-i) )
-    {
-      buf[j] = 7 - i; j++;
-      buf[j] = mDigit[i]->value(); j++;
-      swapPresent = true;
-    }
-  }
-
-  return( swapPresent );
-}
-
-
-#include "bitswapwidget.moc"
diff --git a/khexedit/bitswapwidget.cpp b/khexedit/bitswapwidget.cpp
new file mode 100644
index 00000000..e281d2bd
--- /dev/null
+++ b/khexedit/bitswapwidget.cpp
@@ -0,0 +1,323 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <tqpainter.h>
+ 
+#include <tdeglobalsettings.h>
+
+#include "bitswapwidget.h"
+
+CDigitLabel::CDigitLabel( TQWidget *parent, uint digit, const char *name )
+  :TQLabel(parent, name), mDigit( digit ), mDotPosition( 0 )
+{
+  setFocusPolicy( TQ_StrongFocus );
+  initialize();
+}
+
+CDigitLabel::~CDigitLabel( void )
+{
+
+}
+
+void CDigitLabel::initialize( void )
+{
+  TQFont font( TDEGlobalSettings::generalFont() );
+  font.setBold( true );
+  setFont( font );
+}
+
+
+void CDigitLabel::paletteChange( const TQPalette & )
+{
+  update();
+}
+
+
+void CDigitLabel::setValue( uint digit, bool notify )
+{
+  if( mDigit != digit )
+  {
+    if( notify == true )
+    {
+      emit valueChanged( TQT_TQOBJECT(this), digit, false );
+    }
+
+    mDigit = digit;
+    update();
+
+    if( notify == true )
+    {
+      emit valueChanged( TQT_TQOBJECT(this), mDigit, true );
+    }
+  }
+}
+
+
+void CDigitLabel::setDotPosition( uint dotPosition )
+{
+  if( mDotPosition != dotPosition )
+  {
+    mDotPosition = dotPosition;
+    update();
+  }
+}
+
+
+
+TQSize CDigitLabel::sizeHint( void ) const
+{
+  int h = fontMetrics().height();
+  TQSize s( h, h ); // Retangular
+  return( s );
+}
+ 
+
+#include <stdio.h>
+
+
+void CDigitLabel::drawContents( TQPainter *p )
+{
+  TQRect cr = contentsRect();
+
+  if( hasFocus() == true )
+  {
+    p->fillRect( cr, palette().active().highlight() );
+    p->setPen( palette().active().highlightedText() );
+  }
+  else
+  {
+    p->fillRect( cr, palette().active().base() );
+    p->setPen( palette().active().text() );
+  }
+
+  if( mDotPosition != 0 )
+  {
+    p->fillRect( cr.x()+2, cr.y()+2, 5, 5, TQt::red ); // UL    
+    /*
+    if( mDotPosition == 1 )
+    {
+      p->fillRect( cr.x()+2, cr.y()+2, 5, 5, red ); // UL
+    }
+    else if( mDotPosition == 2 )
+    {
+      p->fillRect( cr.width()-7, cr.y()+2, 5, 5, red ); // UR
+    }
+    else if( mDotPosition == 3 ) 
+    {
+      p->fillRect( cr.x()+2, cr.height()-7, 5, 5, red ); // LL
+    }
+    else if( mDotPosition == 4 )
+    {
+      p->fillRect( cr.width()-7, cr.height()-7, 5, 5, red ); // LR
+    } 
+    */
+  }
+
+  TQString text;
+  text.setNum( mDigit );
+  p->drawText( 0, 0, cr.width(), cr.height(), alignment(), text );
+
+  
+
+}
+
+
+void CDigitLabel::keyPressEvent( TQKeyEvent *e )  
+{
+  switch ( e->key() ) 
+  {
+    case Key_Left:
+    case Key_Up: 
+      emit stepCell( TQT_TQOBJECT(this), false );
+    break;
+
+    case Key_Right:
+    case Key_Down:  
+      emit stepCell( TQT_TQOBJECT(this), true );
+    break;
+    
+    case Key_Escape:
+      e->ignore(); // Allow dialog or whatever use this one
+      return;
+    break;
+
+    default:
+    {
+      int val =  e->text()[0].digitValue();
+      if( val >= 0 && val <= 7 )
+      {
+	setValue( val, true );
+      }
+    }
+    break;
+  }
+  
+  e->accept();
+}
+
+
+
+CByteWidget::CByteWidget( TQWidget *parent, const char *name )
+  :TQWidget(parent, name)
+{
+  mHBox = new TQHBoxLayout( this, 0 );
+  
+  for( uint i=0; i<8; i++ )
+  {
+    mDigit[i] = new CDigitLabel( this, 7-i );
+    mDigit[i]->setLineWidth( 1 );
+    mDigit[i]->setFixedSize( mDigit[i]->sizeHint()*2 );
+    mDigit[i]->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
+    mDigit[i]->setAlignment( AlignCenter );
+    connect( mDigit[i], TQT_SIGNAL(stepCell(const TQObject *, bool )),
+	     this, TQT_SLOT(stepCell(const TQObject *, bool )));
+    connect( mDigit[i], TQT_SIGNAL(valueChanged(const TQObject *, uint, bool )),
+	     this, TQT_SLOT(valueChanged(const TQObject *, uint, bool )));
+    mHBox->addWidget( mDigit[i] );
+  }
+
+  mHBox->addStretch();  
+}
+
+CByteWidget::~CByteWidget( void )
+{
+  for( uint i=0; i<8; i++ ) { delete mDigit[i]; }
+  delete mHBox;
+}
+
+void CByteWidget::stepCell( const TQObject *obj, bool next )
+{
+  for( uint i=0; i<8; i++ )
+  {
+    if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
+    {
+      if( next == true )
+      {
+	mDigit[(i+1)%8]->setFocus();
+      }
+      else
+      {
+	mDigit[(i+7)%8]->setFocus();
+      }
+    }
+  }
+}
+
+
+
+void CByteWidget::valueChanged( const TQObject *obj, uint val, bool after )
+{
+  if( after == false )
+  {
+    for( uint i=0; i<8; i++ )
+    {
+      if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
+      {
+	uint tmp = 7-mDigit[i]->value();
+	mDigit[tmp]->setValue( mDigit[i]->value(), false );
+	break;
+      }
+    }
+
+
+    if( mDigit[7-val]->value() != val )
+    {
+      uint tmp = mDigit[7-val]->value();
+      mDigit[7-tmp]->setValue( tmp, false );
+      mDigit[7-val]->setValue( val, false );
+    }
+
+  }
+  else
+  {
+    setBuddy( obj );
+
+    uint pos = 1;
+    for( uint i=0; i<8; i++ )
+    {
+      if( mDigit[i]->value() < (7-i) )
+      {
+	mDigit[i]->setDotPosition( pos );
+	mDigit[7-mDigit[i]->value()]->setDotPosition( pos );
+	pos++;
+      }
+      else if( mDigit[i]->value() == (7-i) )
+      {
+	mDigit[i]->setDotPosition( 0 );
+      }
+    }
+
+  }
+}
+
+
+void CByteWidget::reset( void )
+{
+  for( uint i=0; i<8; i++ )
+  {
+    mDigit[i]->setValue( 7-i, false );
+    mDigit[i]->setDotPosition( 0 );
+  }
+}
+
+
+void CByteWidget::setBuddy( const TQObject *obj )
+{
+  for( uint i=0; i<8; i++ )
+  {
+    if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
+    {
+      uint val = mDigit[i]->value();
+      if( val < 8 )
+      {
+	mDigit[7-val]->setValue( 7-i, false );
+      }
+      break;
+    }
+  }
+}
+
+
+
+
+
+bool CByteWidget::flag( TQByteArray &buf )
+{
+  bool swapPresent = false;
+  uint i, j;
+  
+  buf.resize( 8 );
+  for( i=0; i<8; buf[i++] = 0 );
+
+  for( i=j=0; i<8; i++ )
+  {
+    if( mDigit[i]->value() < (7-i) )
+    {
+      buf[j] = 7 - i; j++;
+      buf[j] = mDigit[i]->value(); j++;
+      swapPresent = true;
+    }
+  }
+
+  return( swapPresent );
+}
+
+
+#include "bitswapwidget.moc"
diff --git a/khexedit/chartabledialog.cc b/khexedit/chartabledialog.cc
deleted file mode 100644
index a46bee0f..00000000
--- a/khexedit/chartabledialog.cc
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <limits.h>
-
-#include <tqlabel.h>
-#include <tqheader.h>
-#include <tqlayout.h>
-#include <tqspinbox.h>
-
-#include <tdeglobalsettings.h>
-#include <tdelocale.h>
-#include <kstdguiitem.h>
-
-#include "chartabledialog.h"
-
-
-CCharTableDialog::CCharTableDialog( TQWidget *parent, const char *name,
-				    bool modal )
-  :KDialogBase( Plain, i18n("Character Table"), Help|User1|Cancel, User1,
-		parent, name, modal, true, KStdGuiItem::insert())
-{
-  updateGeometry();
-  setHelp( "khexedit/khexedit.html", TQString() );
-
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  mCharacterList = new CListView( plainPage(), "characterList" );
-  mCharacterList->setFont( TDEGlobalSettings::fixedFont() );
-  mCharacterList->addColumn( i18n("Decimal") );
-  mCharacterList->addColumn( i18n("Hexadecimal") );
-  mCharacterList->addColumn( i18n("Octal") );
-  mCharacterList->addColumn( i18n("Binary") );
-  mCharacterList->addColumn( i18n("Text") );
-  mCharacterList->setAllColumnsShowFocus( true );
-  mCharacterList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
-  mCharacterList->setSorting( -1 );
-
-  //
-  // I am setting the min. size below
-  //
-  //connect( mCharacterList, TQT_SIGNAL(doubleClicked(TQListViewItem *) ),
-  //TQT_SLOT(startAssign(TQListViewItem *)));
-
-  topLayout->addWidget( mCharacterList, 10 );
-
-  TQHBoxLayout *hbox = new TQHBoxLayout();
-  if( hbox == 0 ) { return; }
-  topLayout->addLayout( hbox );
-
-  text = i18n("Insert this number of characters:");
-  TQLabel *label = new TQLabel( text, plainPage() );
-  label->setFixedWidth( label->sizeHint().width() );
-  hbox->addWidget( label );
-
-  mInputCountSpin = new TQSpinBox( plainPage(), "spin" );
-  mInputCountSpin->setMinimumWidth( fontMetrics().maxWidth()*7 );
-  mInputCountSpin->setRange( 1, INT_MAX );
-  mInputCountSpin->setValue( 1 );
-  hbox->addWidget( mInputCountSpin );
-
-  hbox->addStretch ( 10 );
-
-  createListData();
-  setColumnWidth();
-  mCharacterList->setVisibleItem( 15 );
-}
-
-
-
-CCharTableDialog::~CCharTableDialog( void )
-{
-}
-
-
-const char *printBinary( uint val )
-{
-  static char buf[9];
-  for( int i = 0; i < 8; i++ )
-  {
-    buf[7-i] = (val&(1<<i)) ? '1' : '0';
-  }
-  buf[8] = 0;
-  return( buf );
-}
-
-
-void CCharTableDialog::createListData( void )
-{
-  TQString d, h, o, b, c;
-  TQListViewItem *item = 0;
-
-  char buf[10];
-  memset( buf, 0, sizeof( buf ) );
-
-  for( uint i=0; i<256; i++ )
-  {
-    d.sprintf("%03d", i );
-    h.sprintf("0x%02x", i );
-    o.sprintf("%03o", i );
-    b.sprintf("%s", printBinary(i) );
-
-    if( TQChar((char)i).isPrint() == true )
-    {
-      c = TQChar((char)i);
-    }
-    else
-    {
-      c = TQChar('.');
-    }
-
-    item = new TQListViewItem( mCharacterList, item, d, h, o, b, c );
-    if( i == 0 )
-    {
-      mCharacterList->setSelected( item, true );
-    }
-
-  }
-}
-
-
-void CCharTableDialog::slotUser1( void ) // Insert
-{
- TQListViewItem *item = mCharacterList->selectedItem();
- if( item != 0 )
- {
-   startAssign( item );
- }
-
-}
-
-void CCharTableDialog::startAssign( TQListViewItem *item )
-{
-  TQByteArray buf;
-  if( buf.fill( item->text(0).toInt(), mInputCountSpin->value() ) == false )
-  {
-    return;
-  }
-  emit assign( buf );
-}
-
-
-void CCharTableDialog::setColumnWidth( void )
-{
-  const TQFontMetrics &fm = mCharacterList->fontMetrics();
-  int w0, w1, w2, w3, w4;
-
-  w0 = -fm.minLeftBearing() - fm.minRightBearing() + 8 + fm.maxWidth();
-  w3 = 0;
-
-  w1  = fm.width( mCharacterList->header()->label(0) ) + w0;
-  w2  = fm.width('0')*5;
-  w3 += w1 > w2 ? w1 : w2;
-  mCharacterList->setColumnWidth( 0, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mCharacterList->header()->label(1) ).width() + w0;
-  w2  = fm.width('0')*6;
-  w3 += w1 > w2 ? w1 : w2;
-  mCharacterList->setColumnWidth( 1, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mCharacterList->header()->label(2) ).width() + w0;
-  w2  = fm.width('0')*5;
-  w3 += w1 > w2 ? w1 : w2;
-  mCharacterList->setColumnWidth( 2, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mCharacterList->header()->label(3) ).width() + w0;
-  w2  = fm.width('0')*10;
-  w3 += w1 > w2 ? w1 : w2;
-  mCharacterList->setColumnWidth( 3, w1 > w2 ? w1 : w2 );
-
-  w4 = mCharacterList->viewport()->width() - w3;
-  w1 = fm.boundingRect( mCharacterList->header()->label(4) ).width() + w0;
-  w2 = fm.width('0')*3;
-  w1 = w1 > w2 ? w1 : w2;
-  mCharacterList->setColumnWidth( 4, w1 > w4 ? w1 : w4 );
-}
-
-
-void CCharTableDialog::resizeEvent( TQResizeEvent * )
-{
-  setColumnWidth();
-}
-
-
-void CCharTableDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  setColumnWidth();
-  mCharacterList->setFocus();
-}
-
-
-#include "chartabledialog.moc"
diff --git a/khexedit/chartabledialog.cpp b/khexedit/chartabledialog.cpp
new file mode 100644
index 00000000..a46bee0f
--- /dev/null
+++ b/khexedit/chartabledialog.cpp
@@ -0,0 +1,212 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <limits.h>
+
+#include <tqlabel.h>
+#include <tqheader.h>
+#include <tqlayout.h>
+#include <tqspinbox.h>
+
+#include <tdeglobalsettings.h>
+#include <tdelocale.h>
+#include <kstdguiitem.h>
+
+#include "chartabledialog.h"
+
+
+CCharTableDialog::CCharTableDialog( TQWidget *parent, const char *name,
+				    bool modal )
+  :KDialogBase( Plain, i18n("Character Table"), Help|User1|Cancel, User1,
+		parent, name, modal, true, KStdGuiItem::insert())
+{
+  updateGeometry();
+  setHelp( "khexedit/khexedit.html", TQString() );
+
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  mCharacterList = new CListView( plainPage(), "characterList" );
+  mCharacterList->setFont( TDEGlobalSettings::fixedFont() );
+  mCharacterList->addColumn( i18n("Decimal") );
+  mCharacterList->addColumn( i18n("Hexadecimal") );
+  mCharacterList->addColumn( i18n("Octal") );
+  mCharacterList->addColumn( i18n("Binary") );
+  mCharacterList->addColumn( i18n("Text") );
+  mCharacterList->setAllColumnsShowFocus( true );
+  mCharacterList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
+  mCharacterList->setSorting( -1 );
+
+  //
+  // I am setting the min. size below
+  //
+  //connect( mCharacterList, TQT_SIGNAL(doubleClicked(TQListViewItem *) ),
+  //TQT_SLOT(startAssign(TQListViewItem *)));
+
+  topLayout->addWidget( mCharacterList, 10 );
+
+  TQHBoxLayout *hbox = new TQHBoxLayout();
+  if( hbox == 0 ) { return; }
+  topLayout->addLayout( hbox );
+
+  text = i18n("Insert this number of characters:");
+  TQLabel *label = new TQLabel( text, plainPage() );
+  label->setFixedWidth( label->sizeHint().width() );
+  hbox->addWidget( label );
+
+  mInputCountSpin = new TQSpinBox( plainPage(), "spin" );
+  mInputCountSpin->setMinimumWidth( fontMetrics().maxWidth()*7 );
+  mInputCountSpin->setRange( 1, INT_MAX );
+  mInputCountSpin->setValue( 1 );
+  hbox->addWidget( mInputCountSpin );
+
+  hbox->addStretch ( 10 );
+
+  createListData();
+  setColumnWidth();
+  mCharacterList->setVisibleItem( 15 );
+}
+
+
+
+CCharTableDialog::~CCharTableDialog( void )
+{
+}
+
+
+const char *printBinary( uint val )
+{
+  static char buf[9];
+  for( int i = 0; i < 8; i++ )
+  {
+    buf[7-i] = (val&(1<<i)) ? '1' : '0';
+  }
+  buf[8] = 0;
+  return( buf );
+}
+
+
+void CCharTableDialog::createListData( void )
+{
+  TQString d, h, o, b, c;
+  TQListViewItem *item = 0;
+
+  char buf[10];
+  memset( buf, 0, sizeof( buf ) );
+
+  for( uint i=0; i<256; i++ )
+  {
+    d.sprintf("%03d", i );
+    h.sprintf("0x%02x", i );
+    o.sprintf("%03o", i );
+    b.sprintf("%s", printBinary(i) );
+
+    if( TQChar((char)i).isPrint() == true )
+    {
+      c = TQChar((char)i);
+    }
+    else
+    {
+      c = TQChar('.');
+    }
+
+    item = new TQListViewItem( mCharacterList, item, d, h, o, b, c );
+    if( i == 0 )
+    {
+      mCharacterList->setSelected( item, true );
+    }
+
+  }
+}
+
+
+void CCharTableDialog::slotUser1( void ) // Insert
+{
+ TQListViewItem *item = mCharacterList->selectedItem();
+ if( item != 0 )
+ {
+   startAssign( item );
+ }
+
+}
+
+void CCharTableDialog::startAssign( TQListViewItem *item )
+{
+  TQByteArray buf;
+  if( buf.fill( item->text(0).toInt(), mInputCountSpin->value() ) == false )
+  {
+    return;
+  }
+  emit assign( buf );
+}
+
+
+void CCharTableDialog::setColumnWidth( void )
+{
+  const TQFontMetrics &fm = mCharacterList->fontMetrics();
+  int w0, w1, w2, w3, w4;
+
+  w0 = -fm.minLeftBearing() - fm.minRightBearing() + 8 + fm.maxWidth();
+  w3 = 0;
+
+  w1  = fm.width( mCharacterList->header()->label(0) ) + w0;
+  w2  = fm.width('0')*5;
+  w3 += w1 > w2 ? w1 : w2;
+  mCharacterList->setColumnWidth( 0, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mCharacterList->header()->label(1) ).width() + w0;
+  w2  = fm.width('0')*6;
+  w3 += w1 > w2 ? w1 : w2;
+  mCharacterList->setColumnWidth( 1, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mCharacterList->header()->label(2) ).width() + w0;
+  w2  = fm.width('0')*5;
+  w3 += w1 > w2 ? w1 : w2;
+  mCharacterList->setColumnWidth( 2, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mCharacterList->header()->label(3) ).width() + w0;
+  w2  = fm.width('0')*10;
+  w3 += w1 > w2 ? w1 : w2;
+  mCharacterList->setColumnWidth( 3, w1 > w2 ? w1 : w2 );
+
+  w4 = mCharacterList->viewport()->width() - w3;
+  w1 = fm.boundingRect( mCharacterList->header()->label(4) ).width() + w0;
+  w2 = fm.width('0')*3;
+  w1 = w1 > w2 ? w1 : w2;
+  mCharacterList->setColumnWidth( 4, w1 > w4 ? w1 : w4 );
+}
+
+
+void CCharTableDialog::resizeEvent( TQResizeEvent * )
+{
+  setColumnWidth();
+}
+
+
+void CCharTableDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  setColumnWidth();
+  mCharacterList->setFocus();
+}
+
+
+#include "chartabledialog.moc"
diff --git a/khexedit/conversion.cc b/khexedit/conversion.cc
deleted file mode 100644
index a0b6195b..00000000
--- a/khexedit/conversion.cc
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <string.h>
-
-#include <tdelocale.h>
-
-#include "conversion.h"
-
-
-CConversion::CConversion( void )
-{
-  setMode( cnvDefault );
-}
-
-
-CConversion::EMode CConversion::mode( void )
-{
-  return( (EMode)mState.mode );
-}
-
-const SEncodeState &CConversion::state( void )
-{
-  return( mState );
-}
-
-TQString CConversion::names( unsigned int index )
-{
-  static const TQString strings[4] = 
-  {
-    i18n("Default encoding", "Default"),
-    i18n("EBCDIC"),
-    i18n("US-ASCII (7 bit)"),
-    i18n("Unknown"),
-  };
- 
-  return( strings[ index > cnvUsAscii ? 3 : index ] );
-}
-
-
-const unsigned char *CConversion::tables( EMode cnvMode )
-{
-  /*
-  static unsigned char ebcdicToLatin1[256] = 
-  {
-    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
-    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
-    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
-    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F,
-    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
-    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07,
-    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
-    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A,
-    0x20, 0xA0, 0xE2, 0xE4, 0xE0, 0xE1, 0xE3, 0xE5, 
-    0xE7, 0xF1, 0xA2, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
-    0x26, 0xE9, 0xEA, 0xEB, 0xE8, 0xED, 0xEE, 0xEF, 
-    0xEC, 0xDF, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
-    0x2D, 0x2F, 0xC2, 0xC4, 0xC0, 0xC1, 0xC3, 0xC5, 
-    0xC7, 0xD1, 0xA6, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
-    0xF8, 0xC9, 0xCA, 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 
-    0xCC, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
-    0xD8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
-    0x68, 0x69, 0xAB, 0xBB, 0xF0, 0xFD, 0xFE, 0xB1,
-    0xB0, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
-    0x71, 0x72, 0xAA, 0xBA, 0xE6, 0xB8, 0xC6, 0xA4,
-    0xB5, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
-    0x79, 0x7A, 0xA1, 0xBF, 0xD0, 0x5B, 0xDE, 0xAE,
-    0xAC, 0xA3, 0xA5, 0xB7, 0xA9, 0xA7, 0xB6, 0xBC, 
-    0xBD, 0xBE, 0xDD, 0xA8, 0xAF, 0x5D, 0xB4, 0xD7,
-    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
-    0x48, 0x49, 0xAD, 0xF4, 0xF6, 0xF2, 0xF3, 0xF5,
-    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
-    0x51, 0x52, 0xB9, 0xFB, 0xFC, 0xF9, 0xFA, 0xFF,
-    0x5C, 0xF7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
-    0x59, 0x5A, 0xB2, 0xD4, 0xD6, 0xD2, 0xD3, 0xD5,
-    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
-    0x38, 0x39, 0xB3, 0xDB, 0xDC, 0xD9, 0xDA, 0x9F
-  };
-  */
-
-  static unsigned char ebcdicToLatin1[256] = 
-  {
-    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
-    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 
-    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
-    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F, 
-    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
-    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07, 
-    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
-    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A, 
-    0x20, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 
-    0xA7, 0xA8, 0x5B, 0x2E, 0x3C, 0x28, 0x2B, 0x21, 
-    0x26, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 
-    0xB0, 0xB1, 0x5D, 0x24, 0x2A, 0x29, 0x3B, 0x5E, 
-    0x2D, 0x2F, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 
-    0xB8, 0xB9, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, 
-    0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 
-    0xC2, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, 
-    0xC3, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
-    0x68, 0x69, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 
-    0xCA, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
-    0x71, 0x72, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 
-    0xD1, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
-    0x79, 0x7A, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 
-    0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 
-    0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 
-    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
-    0x48, 0x49, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 
-    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
-    0x51, 0x52, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 
-    0x5C, 0x9F, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
-    0x59, 0x5A, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 
-    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
-    0x38, 0x39, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 
-  }; 
-
-  static unsigned char buf[256]; 
-
-
-  if( cnvMode == cnvEbcdic )
-  {
-    return( ebcdicToLatin1 );
-  }
-  else if( cnvMode == cnvUsAscii )
-  {
-    memset( buf, 0, 256 );
-    for( unsigned int i=0; i<127; i++ ) { buf[i] = i; }
-    return( buf );
-  }
-  else if( cnvMode == cnvDefault )
-  {
-    for( unsigned int i=0; i<256; i++ ) { buf[i] = i; }
-    return( buf );
-  }
-  else
-  {
-    return( 0 );
-  }
-}
-
-
-void CConversion::setMode( EMode cnvMode )
-{
-  const unsigned char *table = tables( cnvMode );
-  if( table == 0 )
-  {
-    cnvMode = cnvDefault;
-    table = tables( cnvMode );
-  }  
-
-  mState.mode = cnvMode;
-  mState.name = names( mState.mode );
-  memcpy( mData, table, 256 );
-}
-
-
-bool CConversion::lossless( EMode cnvMode )
-{
-  const unsigned char *table = tables( cnvMode );
-  if( table == 0 )
-  {
-    return( false );
-  }
-
-  unsigned char flag[256];
-  memset( flag, 0, sizeof( flag ) );
-
-  for( uint i=0; i<256; i++ )
-  {
-    int index = table[i];
-    if( flag[index] != 0 )
-    {
-      return( false );
-    }
-    flag[index] += 1;
-  }
-  
-  return( true );
-}
-
-
-
-#if 0
-void CConversion::setMode( EMode cnvMode )
-{
-  /*
-  static unsigned char ebcdicToLatin1[256] = 
-  {
-    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
-    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
-    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
-    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F,
-    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
-    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07,
-    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
-    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A,
-    0x20, 0xA0, 0xE2, 0xE4, 0xE0, 0xE1, 0xE3, 0xE5, 
-    0xE7, 0xF1, 0xA2, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
-    0x26, 0xE9, 0xEA, 0xEB, 0xE8, 0xED, 0xEE, 0xEF, 
-    0xEC, 0xDF, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
-    0x2D, 0x2F, 0xC2, 0xC4, 0xC0, 0xC1, 0xC3, 0xC5, 
-    0xC7, 0xD1, 0xA6, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
-    0xF8, 0xC9, 0xCA, 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 
-    0xCC, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
-    0xD8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
-    0x68, 0x69, 0xAB, 0xBB, 0xF0, 0xFD, 0xFE, 0xB1,
-    0xB0, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
-    0x71, 0x72, 0xAA, 0xBA, 0xE6, 0xB8, 0xC6, 0xA4,
-    0xB5, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
-    0x79, 0x7A, 0xA1, 0xBF, 0xD0, 0x5B, 0xDE, 0xAE,
-    0xAC, 0xA3, 0xA5, 0xB7, 0xA9, 0xA7, 0xB6, 0xBC, 
-    0xBD, 0xBE, 0xDD, 0xA8, 0xAF, 0x5D, 0xB4, 0xD7,
-    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
-    0x48, 0x49, 0xAD, 0xF4, 0xF6, 0xF2, 0xF3, 0xF5,
-    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
-    0x51, 0x52, 0xB9, 0xFB, 0xFC, 0xF9, 0xFA, 0xFF,
-    0x5C, 0xF7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
-    0x59, 0x5A, 0xB2, 0xD4, 0xD6, 0xD2, 0xD3, 0xD5,
-    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
-    0x38, 0x39, 0xB3, 0xDB, 0xDC, 0xD9, 0xDA, 0x9F
-  };
-  */
-
-  static unsigned char ebcdicToLatin1[256] = 
-  {
-    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
-    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 
-    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
-    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F, 
-    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
-    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07, 
-    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
-    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A, 
-    0x20, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 
-    0xA7, 0xA8, 0x5B, 0x2E, 0x3C, 0x28, 0x2B, 0x21, 
-    0x26, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 
-    0xB0, 0xB1, 0x5D, 0x24, 0x2A, 0x29, 0x3B, 0x5E, 
-    0x2D, 0x2F, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 
-    0xB8, 0xB9, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, 
-    0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 
-    0xC2, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, 
-    0xC3, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
-    0x68, 0x69, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 
-    0xCA, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
-    0x71, 0x72, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 
-    0xD1, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
-    0x79, 0x7A, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 
-    0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 
-    0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 
-    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
-    0x48, 0x49, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 
-    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
-    0x51, 0x52, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 
-    0x5C, 0x9F, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
-    0x59, 0x5A, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 
-    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
-    0x38, 0x39, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 
-  }; 
-
-
-  if( cnvMode == cnvEbcdic )
-  {
-    memcpy( mData, ebcdicToLatin1, 256 );
-  }
-  else if( cnvMode == cnvUsAscii )
-  {
-    memset( mData, 0, 256 );
-    for( unsigned int i=0; i<127; i++ ) { mData[i] = i; }
-  }
-  else
-  {
-    for( unsigned int i=0; i<256; i++ ) { mData[i] = i; }
-    cnvMode = cnvDefault;
-  }
-
-  mState.mode = cnvMode;
-  mState.name = names( mState.mode );
-}
-#endif
-
-
-
-
-int CConversion::convert( TQByteArray &buf, EMode newMode, CProgress &p )
-{
-  if( newMode == mode() )
-  {
-    p.finish();
-    return( Err_Success );
-  }
-
-  if( buf.isEmpty() )
-  {
-    p.finish();
-    setMode( newMode );
-    return( Err_Success );
-  }
-
-  //
-  // Make backup
-  //
-  const TQByteArray tmp( buf.copy() );
-  if( tmp.isEmpty() )
-  {
-    p.finish();
-    return( Err_NoMemory );
-  }
-
-  unsigned char rev[256];
-  uint i, sum;
-
-  sum = 0;
-
-  const float total = buf.size() * 2.0;
-
-  //
-  // Prepare reverse buffer.
-  //
-  for( i=0; i < 256; i++ ) 
-  { 
-    rev[(unsigned char)mData[i]] = i; 
-  }
-
-  //
-  // Normalize
-  //
-  for( i=0; i<buf.size(); i++, sum++ ) 
-  {
-    buf[i] = rev[ (unsigned char)buf[i] ];
-
-    //
-    // The expired() function introduces too much overhead in this case
-    // so it is only executed every 100'th character
-    //
-    if( i % 100 == 0 && p.expired() == true )
-    {
-      const int errCode = p.step( (float)sum/ total );
-      if( errCode == Err_Stop )
-      {
-        buf = tmp;
-	p.finish();
-	return( Err_OperationAborted );
-      }
-    }
-  }
-
-  EMode origMode = mode();
-  setMode( newMode );
-
-  //
-  // Apply new encoding.
-  //
-  for( uint i=0; i<buf.size(); i++, sum++ )
-  {
-    buf[i] = mData[ (unsigned char)buf[i] ];
-
-    //
-    // The expired() function introduces too much overhead in this case
-    // so it is only executed every 100'th character
-    //
-    if( i % 100 == 0 && p.expired() == true )
-    {
-      const int errCode = p.step( (float)sum/ total );
-      if( errCode == Err_Stop )
-      {
-        buf = tmp;
-	setMode( origMode );
-	p.finish();
-	return( Err_OperationAborted );
-      }
-    }
-  }
-
-  p.finish();
-  return( Err_Success );
-}
-
-
diff --git a/khexedit/conversion.cpp b/khexedit/conversion.cpp
new file mode 100644
index 00000000..a0b6195b
--- /dev/null
+++ b/khexedit/conversion.cpp
@@ -0,0 +1,395 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <string.h>
+
+#include <tdelocale.h>
+
+#include "conversion.h"
+
+
+CConversion::CConversion( void )
+{
+  setMode( cnvDefault );
+}
+
+
+CConversion::EMode CConversion::mode( void )
+{
+  return( (EMode)mState.mode );
+}
+
+const SEncodeState &CConversion::state( void )
+{
+  return( mState );
+}
+
+TQString CConversion::names( unsigned int index )
+{
+  static const TQString strings[4] = 
+  {
+    i18n("Default encoding", "Default"),
+    i18n("EBCDIC"),
+    i18n("US-ASCII (7 bit)"),
+    i18n("Unknown"),
+  };
+ 
+  return( strings[ index > cnvUsAscii ? 3 : index ] );
+}
+
+
+const unsigned char *CConversion::tables( EMode cnvMode )
+{
+  /*
+  static unsigned char ebcdicToLatin1[256] = 
+  {
+    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
+    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
+    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F,
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
+    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07,
+    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
+    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A,
+    0x20, 0xA0, 0xE2, 0xE4, 0xE0, 0xE1, 0xE3, 0xE5, 
+    0xE7, 0xF1, 0xA2, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
+    0x26, 0xE9, 0xEA, 0xEB, 0xE8, 0xED, 0xEE, 0xEF, 
+    0xEC, 0xDF, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
+    0x2D, 0x2F, 0xC2, 0xC4, 0xC0, 0xC1, 0xC3, 0xC5, 
+    0xC7, 0xD1, 0xA6, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
+    0xF8, 0xC9, 0xCA, 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 
+    0xCC, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
+    0xD8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
+    0x68, 0x69, 0xAB, 0xBB, 0xF0, 0xFD, 0xFE, 0xB1,
+    0xB0, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
+    0x71, 0x72, 0xAA, 0xBA, 0xE6, 0xB8, 0xC6, 0xA4,
+    0xB5, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
+    0x79, 0x7A, 0xA1, 0xBF, 0xD0, 0x5B, 0xDE, 0xAE,
+    0xAC, 0xA3, 0xA5, 0xB7, 0xA9, 0xA7, 0xB6, 0xBC, 
+    0xBD, 0xBE, 0xDD, 0xA8, 0xAF, 0x5D, 0xB4, 0xD7,
+    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
+    0x48, 0x49, 0xAD, 0xF4, 0xF6, 0xF2, 0xF3, 0xF5,
+    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
+    0x51, 0x52, 0xB9, 0xFB, 0xFC, 0xF9, 0xFA, 0xFF,
+    0x5C, 0xF7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
+    0x59, 0x5A, 0xB2, 0xD4, 0xD6, 0xD2, 0xD3, 0xD5,
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
+    0x38, 0x39, 0xB3, 0xDB, 0xDC, 0xD9, 0xDA, 0x9F
+  };
+  */
+
+  static unsigned char ebcdicToLatin1[256] = 
+  {
+    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
+    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 
+    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
+    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F, 
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
+    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07, 
+    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
+    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A, 
+    0x20, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 
+    0xA7, 0xA8, 0x5B, 0x2E, 0x3C, 0x28, 0x2B, 0x21, 
+    0x26, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 
+    0xB0, 0xB1, 0x5D, 0x24, 0x2A, 0x29, 0x3B, 0x5E, 
+    0x2D, 0x2F, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 
+    0xB8, 0xB9, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, 
+    0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 
+    0xC2, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, 
+    0xC3, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
+    0x68, 0x69, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 
+    0xCA, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
+    0x71, 0x72, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 
+    0xD1, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
+    0x79, 0x7A, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 
+    0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 
+    0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 
+    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
+    0x48, 0x49, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 
+    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
+    0x51, 0x52, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 
+    0x5C, 0x9F, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
+    0x59, 0x5A, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
+    0x38, 0x39, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 
+  }; 
+
+  static unsigned char buf[256]; 
+
+
+  if( cnvMode == cnvEbcdic )
+  {
+    return( ebcdicToLatin1 );
+  }
+  else if( cnvMode == cnvUsAscii )
+  {
+    memset( buf, 0, 256 );
+    for( unsigned int i=0; i<127; i++ ) { buf[i] = i; }
+    return( buf );
+  }
+  else if( cnvMode == cnvDefault )
+  {
+    for( unsigned int i=0; i<256; i++ ) { buf[i] = i; }
+    return( buf );
+  }
+  else
+  {
+    return( 0 );
+  }
+}
+
+
+void CConversion::setMode( EMode cnvMode )
+{
+  const unsigned char *table = tables( cnvMode );
+  if( table == 0 )
+  {
+    cnvMode = cnvDefault;
+    table = tables( cnvMode );
+  }  
+
+  mState.mode = cnvMode;
+  mState.name = names( mState.mode );
+  memcpy( mData, table, 256 );
+}
+
+
+bool CConversion::lossless( EMode cnvMode )
+{
+  const unsigned char *table = tables( cnvMode );
+  if( table == 0 )
+  {
+    return( false );
+  }
+
+  unsigned char flag[256];
+  memset( flag, 0, sizeof( flag ) );
+
+  for( uint i=0; i<256; i++ )
+  {
+    int index = table[i];
+    if( flag[index] != 0 )
+    {
+      return( false );
+    }
+    flag[index] += 1;
+  }
+  
+  return( true );
+}
+
+
+
+#if 0
+void CConversion::setMode( EMode cnvMode )
+{
+  /*
+  static unsigned char ebcdicToLatin1[256] = 
+  {
+    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
+    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
+    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F,
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
+    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07,
+    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
+    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A,
+    0x20, 0xA0, 0xE2, 0xE4, 0xE0, 0xE1, 0xE3, 0xE5, 
+    0xE7, 0xF1, 0xA2, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
+    0x26, 0xE9, 0xEA, 0xEB, 0xE8, 0xED, 0xEE, 0xEF, 
+    0xEC, 0xDF, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
+    0x2D, 0x2F, 0xC2, 0xC4, 0xC0, 0xC1, 0xC3, 0xC5, 
+    0xC7, 0xD1, 0xA6, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
+    0xF8, 0xC9, 0xCA, 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 
+    0xCC, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
+    0xD8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
+    0x68, 0x69, 0xAB, 0xBB, 0xF0, 0xFD, 0xFE, 0xB1,
+    0xB0, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
+    0x71, 0x72, 0xAA, 0xBA, 0xE6, 0xB8, 0xC6, 0xA4,
+    0xB5, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
+    0x79, 0x7A, 0xA1, 0xBF, 0xD0, 0x5B, 0xDE, 0xAE,
+    0xAC, 0xA3, 0xA5, 0xB7, 0xA9, 0xA7, 0xB6, 0xBC, 
+    0xBD, 0xBE, 0xDD, 0xA8, 0xAF, 0x5D, 0xB4, 0xD7,
+    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
+    0x48, 0x49, 0xAD, 0xF4, 0xF6, 0xF2, 0xF3, 0xF5,
+    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
+    0x51, 0x52, 0xB9, 0xFB, 0xFC, 0xF9, 0xFA, 0xFF,
+    0x5C, 0xF7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
+    0x59, 0x5A, 0xB2, 0xD4, 0xD6, 0xD2, 0xD3, 0xD5,
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
+    0x38, 0x39, 0xB3, 0xDB, 0xDC, 0xD9, 0xDA, 0x9F
+  };
+  */
+
+  static unsigned char ebcdicToLatin1[256] = 
+  {
+    0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 
+    0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 
+    0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, 
+    0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F, 
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, 
+    0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07, 
+    0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 
+    0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A, 
+    0x20, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 
+    0xA7, 0xA8, 0x5B, 0x2E, 0x3C, 0x28, 0x2B, 0x21, 
+    0x26, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 
+    0xB0, 0xB1, 0x5D, 0x24, 0x2A, 0x29, 0x3B, 0x5E, 
+    0x2D, 0x2F, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 
+    0xB8, 0xB9, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, 
+    0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 
+    0xC2, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, 
+    0xC3, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
+    0x68, 0x69, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 
+    0xCA, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 
+    0x71, 0x72, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 
+    0xD1, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
+    0x79, 0x7A, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 
+    0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 
+    0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 
+    0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
+    0x48, 0x49, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 
+    0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 
+    0x51, 0x52, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 
+    0x5C, 0x9F, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
+    0x59, 0x5A, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
+    0x38, 0x39, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 
+  }; 
+
+
+  if( cnvMode == cnvEbcdic )
+  {
+    memcpy( mData, ebcdicToLatin1, 256 );
+  }
+  else if( cnvMode == cnvUsAscii )
+  {
+    memset( mData, 0, 256 );
+    for( unsigned int i=0; i<127; i++ ) { mData[i] = i; }
+  }
+  else
+  {
+    for( unsigned int i=0; i<256; i++ ) { mData[i] = i; }
+    cnvMode = cnvDefault;
+  }
+
+  mState.mode = cnvMode;
+  mState.name = names( mState.mode );
+}
+#endif
+
+
+
+
+int CConversion::convert( TQByteArray &buf, EMode newMode, CProgress &p )
+{
+  if( newMode == mode() )
+  {
+    p.finish();
+    return( Err_Success );
+  }
+
+  if( buf.isEmpty() )
+  {
+    p.finish();
+    setMode( newMode );
+    return( Err_Success );
+  }
+
+  //
+  // Make backup
+  //
+  const TQByteArray tmp( buf.copy() );
+  if( tmp.isEmpty() )
+  {
+    p.finish();
+    return( Err_NoMemory );
+  }
+
+  unsigned char rev[256];
+  uint i, sum;
+
+  sum = 0;
+
+  const float total = buf.size() * 2.0;
+
+  //
+  // Prepare reverse buffer.
+  //
+  for( i=0; i < 256; i++ ) 
+  { 
+    rev[(unsigned char)mData[i]] = i; 
+  }
+
+  //
+  // Normalize
+  //
+  for( i=0; i<buf.size(); i++, sum++ ) 
+  {
+    buf[i] = rev[ (unsigned char)buf[i] ];
+
+    //
+    // The expired() function introduces too much overhead in this case
+    // so it is only executed every 100'th character
+    //
+    if( i % 100 == 0 && p.expired() == true )
+    {
+      const int errCode = p.step( (float)sum/ total );
+      if( errCode == Err_Stop )
+      {
+        buf = tmp;
+	p.finish();
+	return( Err_OperationAborted );
+      }
+    }
+  }
+
+  EMode origMode = mode();
+  setMode( newMode );
+
+  //
+  // Apply new encoding.
+  //
+  for( uint i=0; i<buf.size(); i++, sum++ )
+  {
+    buf[i] = mData[ (unsigned char)buf[i] ];
+
+    //
+    // The expired() function introduces too much overhead in this case
+    // so it is only executed every 100'th character
+    //
+    if( i % 100 == 0 && p.expired() == true )
+    {
+      const int errCode = p.step( (float)sum/ total );
+      if( errCode == Err_Stop )
+      {
+        buf = tmp;
+	setMode( origMode );
+	p.finish();
+	return( Err_OperationAborted );
+      }
+    }
+  }
+
+  p.finish();
+  return( Err_Success );
+}
+
+
diff --git a/khexedit/converterdialog.cc b/khexedit/converterdialog.cc
deleted file mode 100644
index e742e73c..00000000
--- a/khexedit/converterdialog.cc
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-
-#include <tqlabel.h>
-#include <tqlayout.h>
-
-#include <tdelocale.h>
-
-#include "converterdialog.h"
-#include "hexvalidator.h"
-
-
-CValidateLineEdit::CValidateLineEdit( TQWidget *parent, int validateType,
-				      const char *name )
-  :TQLineEdit( parent, name ), mBusy(false)
-{
-  mValidator = new CHexValidator( this, (CHexValidator::EState)validateType );
-  setValidator( mValidator );
-  connect( this, TQT_SIGNAL(textChanged(const TQString &)),
-	   this, TQT_SLOT(convertText(const TQString &)) );
-}
-
-
-CValidateLineEdit::~CValidateLineEdit( void )
-{
-}
-
-
-void CValidateLineEdit::setData( const TQByteArray &buf )
-{
-  if( mBusy == false )
-  {
-    TQString text;
-    mValidator->format( text, buf );
-    setText( text );
-  }
-}
-
-
-void CValidateLineEdit::convertText( const TQString &text )
-{
-  TQByteArray buf;
-  mValidator->convert( buf, text );
-  mBusy = true; // Don't update while editing
-  emit dataChanged( buf );
-  mBusy = false;
-}
-
-
-
-CConverterDialog::CConverterDialog( TQWidget *parent, const char *name, 
-				    bool modal )
-  :KDialogBase( parent, name, modal, i18n("Converter"), Cancel|User2|User1, 
-		Cancel, true, KStdGuiItem::clear(), i18n("&On Cursor") )
-{
-  TQWidget *page = new TQWidget( this );
-  setMainWidget( page );
-
-  TQGridLayout *topLayout = new TQGridLayout( page, 6, 2, 0, spacingHint() );
-  topLayout->setRowStretch( 5, 10 );
-  topLayout->setColStretch( 1, 10 );
-
-  TQLabel *label = new TQLabel( i18n("Hexadecimal:"), page );
-  topLayout->addWidget( label, 0, 0 );
-  label = new TQLabel( i18n("Decimal:"), page );
-  topLayout->addWidget( label, 1, 0 );
-  label = new TQLabel( i18n("Octal:"), page );
-  topLayout->addWidget( label, 2, 0 );
-  label = new TQLabel( i18n("Binary:"), page );
-  topLayout->addWidget( label, 3, 0 );
-  label = new TQLabel( i18n("Text:"), page );
-  topLayout->addWidget( label, 4, 0 );
-
-  mHexInput = new CValidateLineEdit( page, CHexValidator::hexadecimal );
-  mHexInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  topLayout->addWidget( mHexInput, 0, 1 );
-  mDecInput = new CValidateLineEdit( page, CHexValidator::decimal );
-  topLayout->addWidget( mDecInput, 1, 1 );
-  mOctInput = new CValidateLineEdit( page, CHexValidator::octal );
-  topLayout->addWidget( mOctInput, 2, 1 );
-  mBinInput = new CValidateLineEdit( page, CHexValidator::binary );
-  topLayout->addWidget( mBinInput, 3, 1 );
-  mTxtInput = new CValidateLineEdit( page, CHexValidator::regularText );
-  topLayout->addWidget( mTxtInput, 4, 1 );
-
-  connect( mHexInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
-	   this, TQT_SLOT(setData(const TQByteArray &)) );
-  connect( mDecInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
-	   this, TQT_SLOT(setData(const TQByteArray &)) );
-  connect( mOctInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
-	   this, TQT_SLOT(setData(const TQByteArray &)) );
-  connect( mBinInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
-	   this, TQT_SLOT(setData(const TQByteArray &)) );
-  connect( mTxtInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
-	   this, TQT_SLOT(setData(const TQByteArray &)) );
-
-}
-
-
-CConverterDialog::~CConverterDialog( void )
-{
-}
-
-
-void CConverterDialog::showEvent( TQShowEvent *e )  
-{
-  KDialogBase::showEvent(e);
-  mHexInput->setFocus();
-}
-
-
-void CConverterDialog::setData( const TQByteArray &data )
-{
-  mHexInput->blockSignals(true);
-  mDecInput->blockSignals(true);
-  mOctInput->blockSignals(true);
-  mBinInput->blockSignals(true);
-  mTxtInput->blockSignals(true);
-  mHexInput->setData(data);
-  mDecInput->setData(data);
-  mOctInput->setData(data);
-  mBinInput->setData(data);
-  mTxtInput->setData(data);
-  mHexInput->blockSignals(false);
-  mDecInput->blockSignals(false);
-  mOctInput->blockSignals(false);
-  mBinInput->blockSignals(false);
-  mTxtInput->blockSignals(false);
-}
-
-void CConverterDialog::slotUser1( void ) // Clear
-{
-  TQByteArray buf;
-  setData( buf );
-}
-
-void CConverterDialog::slotUser2( void ) // On Cursor
-{
-  TQByteArray buf;
-  emit probeCursorValue( buf, 1 );
-  setData( buf );
-}
-
-
-#include "converterdialog.moc"
diff --git a/khexedit/converterdialog.cpp b/khexedit/converterdialog.cpp
new file mode 100644
index 00000000..e742e73c
--- /dev/null
+++ b/khexedit/converterdialog.cpp
@@ -0,0 +1,163 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+
+#include <tqlabel.h>
+#include <tqlayout.h>
+
+#include <tdelocale.h>
+
+#include "converterdialog.h"
+#include "hexvalidator.h"
+
+
+CValidateLineEdit::CValidateLineEdit( TQWidget *parent, int validateType,
+				      const char *name )
+  :TQLineEdit( parent, name ), mBusy(false)
+{
+  mValidator = new CHexValidator( this, (CHexValidator::EState)validateType );
+  setValidator( mValidator );
+  connect( this, TQT_SIGNAL(textChanged(const TQString &)),
+	   this, TQT_SLOT(convertText(const TQString &)) );
+}
+
+
+CValidateLineEdit::~CValidateLineEdit( void )
+{
+}
+
+
+void CValidateLineEdit::setData( const TQByteArray &buf )
+{
+  if( mBusy == false )
+  {
+    TQString text;
+    mValidator->format( text, buf );
+    setText( text );
+  }
+}
+
+
+void CValidateLineEdit::convertText( const TQString &text )
+{
+  TQByteArray buf;
+  mValidator->convert( buf, text );
+  mBusy = true; // Don't update while editing
+  emit dataChanged( buf );
+  mBusy = false;
+}
+
+
+
+CConverterDialog::CConverterDialog( TQWidget *parent, const char *name, 
+				    bool modal )
+  :KDialogBase( parent, name, modal, i18n("Converter"), Cancel|User2|User1, 
+		Cancel, true, KStdGuiItem::clear(), i18n("&On Cursor") )
+{
+  TQWidget *page = new TQWidget( this );
+  setMainWidget( page );
+
+  TQGridLayout *topLayout = new TQGridLayout( page, 6, 2, 0, spacingHint() );
+  topLayout->setRowStretch( 5, 10 );
+  topLayout->setColStretch( 1, 10 );
+
+  TQLabel *label = new TQLabel( i18n("Hexadecimal:"), page );
+  topLayout->addWidget( label, 0, 0 );
+  label = new TQLabel( i18n("Decimal:"), page );
+  topLayout->addWidget( label, 1, 0 );
+  label = new TQLabel( i18n("Octal:"), page );
+  topLayout->addWidget( label, 2, 0 );
+  label = new TQLabel( i18n("Binary:"), page );
+  topLayout->addWidget( label, 3, 0 );
+  label = new TQLabel( i18n("Text:"), page );
+  topLayout->addWidget( label, 4, 0 );
+
+  mHexInput = new CValidateLineEdit( page, CHexValidator::hexadecimal );
+  mHexInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  topLayout->addWidget( mHexInput, 0, 1 );
+  mDecInput = new CValidateLineEdit( page, CHexValidator::decimal );
+  topLayout->addWidget( mDecInput, 1, 1 );
+  mOctInput = new CValidateLineEdit( page, CHexValidator::octal );
+  topLayout->addWidget( mOctInput, 2, 1 );
+  mBinInput = new CValidateLineEdit( page, CHexValidator::binary );
+  topLayout->addWidget( mBinInput, 3, 1 );
+  mTxtInput = new CValidateLineEdit( page, CHexValidator::regularText );
+  topLayout->addWidget( mTxtInput, 4, 1 );
+
+  connect( mHexInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
+	   this, TQT_SLOT(setData(const TQByteArray &)) );
+  connect( mDecInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
+	   this, TQT_SLOT(setData(const TQByteArray &)) );
+  connect( mOctInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
+	   this, TQT_SLOT(setData(const TQByteArray &)) );
+  connect( mBinInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
+	   this, TQT_SLOT(setData(const TQByteArray &)) );
+  connect( mTxtInput, TQT_SIGNAL(dataChanged(const TQByteArray &)),
+	   this, TQT_SLOT(setData(const TQByteArray &)) );
+
+}
+
+
+CConverterDialog::~CConverterDialog( void )
+{
+}
+
+
+void CConverterDialog::showEvent( TQShowEvent *e )  
+{
+  KDialogBase::showEvent(e);
+  mHexInput->setFocus();
+}
+
+
+void CConverterDialog::setData( const TQByteArray &data )
+{
+  mHexInput->blockSignals(true);
+  mDecInput->blockSignals(true);
+  mOctInput->blockSignals(true);
+  mBinInput->blockSignals(true);
+  mTxtInput->blockSignals(true);
+  mHexInput->setData(data);
+  mDecInput->setData(data);
+  mOctInput->setData(data);
+  mBinInput->setData(data);
+  mTxtInput->setData(data);
+  mHexInput->blockSignals(false);
+  mDecInput->blockSignals(false);
+  mOctInput->blockSignals(false);
+  mBinInput->blockSignals(false);
+  mTxtInput->blockSignals(false);
+}
+
+void CConverterDialog::slotUser1( void ) // Clear
+{
+  TQByteArray buf;
+  setData( buf );
+}
+
+void CConverterDialog::slotUser2( void ) // On Cursor
+{
+  TQByteArray buf;
+  emit probeCursorValue( buf, 1 );
+  setData( buf );
+}
+
+
+#include "converterdialog.moc"
diff --git a/khexedit/dialog.cc b/khexedit/dialog.cc
deleted file mode 100644
index c2f2d80b..00000000
--- a/khexedit/dialog.cc
+++ /dev/null
@@ -1,1433 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <ctype.h>
-#include <iostream>
-#include <limits.h>
-
-#include <tqbuttongroup.h>
-#include <tqfileinfo.h>
-#include <tqlayout.h>
-#include <tqvalidator.h>
-
-#include <tdefiledialog.h>
-#include <tdelocale.h>
-#include <tdemessagebox.h>
-#include <kseparator.h>
-#include <kstdguiitem.h>
-
-#include "dialog.h"
-#include <tqpushbutton.h>
-
-static const TQStringList &formatStrings( void );
-static const TQStringList &operationStrings( void );
-
-
-CGotoDialog::CGotoDialog( TQWidget *parent, const char *name, bool modal )
-  :KDialogBase( Plain, i18n("Goto Offset"), Ok|Cancel, Ok, parent, name,
-		modal )
-{
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  TQVBoxLayout *vbox = new TQVBoxLayout();
-  if( vbox == 0 ) { return; }
-  topLayout->addLayout( vbox );
-
-  mComboBox = new TQComboBox( true, plainPage() );
-  if( mComboBox == 0 ) { return; }
-  mComboBox->setMaxCount( 10 );
-  mComboBox->setInsertionPolicy( TQComboBox::AtTop );
-  mComboBox->setMinimumWidth( fontMetrics().maxWidth()*17 );
-
-  TQLabel *label = new TQLabel( mComboBox, i18n("O&ffset:"), plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mComboBox );
-
-  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
-  if( group == 0 ) { return; }
-  topLayout->addWidget( group, 10 );
-
-  TQGridLayout *gbox = new TQGridLayout( group, 4, 2, spacingHint() );
-  if( gbox == 0 ) { return; }
-  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
-  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
-  gbox->addWidget( mCheckFromCursor, 1, 0 );
-  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
-  gbox->addWidget( mCheckBackward, 1, 1 );
-  mCheckVisible = new TQCheckBox( i18n("&Stay visible"), group );
-  gbox->addWidget( mCheckVisible, 2, 0 );
-  gbox->setRowStretch( 3, 10 );
-
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Goto Dialog");
-  mCheckFromCursor->setChecked( config.readBoolEntry( "FromCursor", false ) );
-  mCheckVisible->setChecked( config.readBoolEntry( "StayVisible", true ) );
-  mCheckBackward->setChecked( config.readBoolEntry( "Backwards", false ) );
-}
-
-
-
-CGotoDialog::~CGotoDialog( void )
-{
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Goto Dialog");
-  config.writeEntry( "FromCursor", mCheckFromCursor->isChecked() );
-  config.writeEntry( "StayVisible", mCheckVisible->isChecked() );
-  config.writeEntry( "Backwards", mCheckBackward->isChecked() );
-  config.sync();
-}
-
-
-
-void CGotoDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  mComboBox->setFocus();
-}
-
-
-
-//
-// Format of input string:
-// 0x<HexNumber>|<DecimalNumber>s<Bit>
-// s = :,. or space
-//
-void CGotoDialog::slotOk( void )
-{
-  uint offset;
-  bool success = stringToOffset( mComboBox->currentText(), offset );
-  if( success == false )
-  {
-    showEntryFailure( this, TQString("") );
-    return;
-  }
-
-  if( mCheckVisible->isChecked() == false )
-  {
-    hide();
-  }
-  emit gotoOffset( offset, 7, mCheckFromCursor->isChecked(),
-		   mCheckBackward->isChecked() == true ? false : true );
-
-  #if 0
-  const char *p = mComboBox->currentText();
-  if( strlen( p ) == 0 )
-  {
-    return;
-  }
-
-  //
-  // Skip any whitespaces in front of string
-  //
-  for( ; *p != 0 && isspace( *p ) ; p++ );
-
-  uint offset, bit;
-  int match;
-  if( strncmp( p, "0x", 2 ) == 0 || strncmp( p, "0X", 2 ) == 0 )
-  {
-    match = sscanf( p+2, "%x", &offset );
-  }
-  else
-  {
-    match = sscanf( p, "%u", &offset );
-  }
-
-  if( match == 0 )
-  {
-    return;
-  }
-
-  bit = 7;
-
-  p = strpbrk( p, ":,. " );
-  if( p != 0 )
-  {
-    match = sscanf( p+1, "%u", &bit );
-    if( match == 0 )
-    {
-      return;
-    }
-    if( bit > 7 ) { bit = 7; }
-  }
-  #endif
-}
-
-
-
-CFindDialog::CFindDialog( TQWidget *parent, const char *name, bool modal )
-  :KDialogBase( Plain, i18n("Find"), Ok|Cancel, Ok, parent, name, modal )
-{
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  TQVBoxLayout *vbox = new TQVBoxLayout();
-  if( vbox == 0 ) { return; }
-  topLayout->addLayout( vbox );
-
-  mSelector = new TQComboBox( false, plainPage() );
-  if( mSelector == 0 ) { return; }
-  mSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mSelector->insertStringList( formatStrings() );
-  connect( mSelector, TQT_SIGNAL(activated(int)), TQT_SLOT(selectorChanged(int)) );
-
-  TQLabel *label = new TQLabel( mSelector, i18n("Fo&rmat:"), plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mSelector );
-
-  mInput = new TQLineEdit( plainPage() );
-  if( mInput == 0 ) { return; }
-  mInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  connect( mInput, TQT_SIGNAL(textChanged(const TQString&)),
-	   TQT_SLOT(inputChanged(const TQString&)) );
-  mFindValidator = new CHexValidator( this, CHexValidator::regularText );
-  if( mFindValidator == 0 ) { return; }
-  mInput->setValidator( mFindValidator );
-
-  label = new TQLabel( mInput, i18n("F&ind:"), plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mInput );
-
-  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
-  if( group == 0 ) { return; }
-  topLayout->addWidget( group, 10 );
-
-  TQGridLayout *gbox = new TQGridLayout( group, 5, 2, spacingHint() );
-  if( gbox == 0 ) { return; }
-  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
-
-  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
-  gbox->addWidget( mCheckFromCursor, 1, 0 );
-  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
-  gbox->addWidget( mCheckBackward, 1, 1 );
-  mCheckInSelection = new TQCheckBox( i18n("&In selection"), group );
-  gbox->addWidget( mCheckInSelection, 2, 0 );
-  mCheckUseNavigator = new TQCheckBox( i18n("&Use navigator"),group);
-  gbox->addWidget( mCheckUseNavigator, 2, 1 );
-  mCheckIgnoreCase = new TQCheckBox( i18n("Ignore c&ase"),group);
-  gbox->addWidget( mCheckIgnoreCase, 3, 0 );
-  gbox->setRowStretch( 4, 10 );
-
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Find Dialog");
-  mCheckFromCursor->setChecked( config.readBoolEntry( "FromCursor", true ) );
-  mCheckInSelection->setChecked( config.readBoolEntry( "InSelection", false) );
-  mCheckIgnoreCase->setChecked( config.readBoolEntry( "IgnoreCase", false ) );
-  mCheckBackward->setChecked( config.readBoolEntry( "Backwards", false ) );
-  mCheckUseNavigator->setChecked( config.readBoolEntry( "UseNavigator", true));
-  uint val = config.readUnsignedNumEntry( "Format", 0 );
-  mSelector->setCurrentItem(TQMIN(4,val) );
-  selectorChanged( mSelector->currentItem() );
-  enableButtonOK(!mInput->text().isEmpty());
-}
-
-
-CFindDialog::~CFindDialog( void )
-{
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Find Dialog");
-  config.writeEntry( "FromCursor", mCheckFromCursor->isChecked() );
-  config.writeEntry( "InSelection", mCheckInSelection->isChecked() );
-  config.writeEntry( "IgnoreCase", mCheckIgnoreCase->isChecked() );
-  config.writeEntry( "Backwards", mCheckBackward->isChecked() );
-  config.writeEntry( "UseNavigator", mCheckUseNavigator->isChecked() );
-  config.writeEntry( "Format", mSelector->currentItem() );
-  config.sync();
-}
-
-
-void CFindDialog::selectorChanged( int index )
-{
-  mFindValidator->setState( (CHexValidator::EState)index );
-  mInput->setText( mFindString[ index ] );
-  mCheckIgnoreCase->setEnabled( index == 4 );
-}
-
-
-void CFindDialog::inputChanged( const TQString &text )
-{
-  mFindString[ mSelector->currentItem() ] = text;
-  mFindValidator->convert( mFindData,
-    mFindString[ mSelector->currentItem() ] );
-  enableButtonOK(!text.isEmpty());
-}
-
-
-void CFindDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  mInput->setFocus();
-}
-
-
-bool CFindDialog::isEmpty( void )
-{
-  return( mFindData.isEmpty() );
-}
-
-
-void CFindDialog::slotOk( void )
-{
-  if( isEmpty() == true )
-  {
-    showEntryFailure( this, TQString("") );
-    return;
-  }
-
-  SSearchControl sc;
-  sc.key = mFindData;
-  sc.keyType = mSelector->currentItem();
-  sc.fromCursor = mCheckFromCursor->isChecked();
-  sc.inSelection = mCheckInSelection->isChecked();
-  sc.forward = mCheckBackward->isChecked() == true ? false : true;
-  sc.ignoreCase = mCheckIgnoreCase->isEnabled() && mCheckIgnoreCase->isChecked();
-
-  hide();
-  emit findData( sc, Find_First, mCheckUseNavigator->isChecked() );
-}
-
-
-void CFindDialog::findAgain( EOperation operation )
-{
-  if( isEmpty() == true )
-  {
-    showEntryFailure( this, TQString("") );
-    return;
-  }
-
-  SSearchControl sc;
-  sc.key = mFindData;
-  sc.fromCursor = true;
-  sc.inSelection = mCheckInSelection->isChecked();
-  sc.ignoreCase = mCheckIgnoreCase->isEnabled() && mCheckIgnoreCase->isChecked();
-  if( operation == find_Next )
-  {
-    sc.forward = true;
-  }
-  else if( operation == find_Previous )
-  {
-    sc.forward = false;
-  }
-  else
-  {
-    sc.forward = mCheckBackward->isChecked() == true ? false : true;
-  }
-
-  hide();
-  emit findData( sc, Find_Next, false );
-}
-
-
-
-CFindNavigatorDialog::CFindNavigatorDialog( TQWidget *parent, const char *name,
-					     bool modal )
-  :KDialogBase( Plain, i18n("Find (Navigator)"), User3|User2|User1|Close,
-		User2, parent, name, modal, true, i18n("New &Key"),
-		i18n("&Next"), i18n("&Previous") )
-{
-  TQString text;
-  TQBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  topLayout->addSpacing( spacingHint() ); // A little bit extra space
-
-  TQHBoxLayout *hbox = new TQHBoxLayout();
-  if( hbox == 0 ) { return; }
-  topLayout->addLayout( hbox );
-
-  text = i18n("Searching for:");
-  TQLabel *label = new TQLabel( text, plainPage() );
-  hbox->addWidget( label );
-
-  mKey = new TQLineEdit( plainPage() );
-  mKey->setMinimumWidth( fontMetrics().width("M") * 20 );
-  mKey->setFocusPolicy( TQ_NoFocus );
-  hbox->addWidget( mKey );
-
-  topLayout->addSpacing( spacingHint() ); // A little bit extra space
-  topLayout->addStretch(10);
-}
-
-
-CFindNavigatorDialog::~CFindNavigatorDialog( void )
-{
-}
-
-
-void CFindNavigatorDialog::defineData( SSearchControl &sc )
-{
-  mSearchControl = sc;
-  mSearchControl.key.duplicate( sc.key );
-
-  if( mSearchControl.key.isEmpty() == true )
-  {
-    mKey->setText("");
-    return;
-  }
-
-  if( mSearchControl.keyType == 0 )
-  {
-    TQString str;
-    for( uint i=0; i<mSearchControl.key.size(); i++ )
-    {
-      str += mSearchControl.key[i];
-    }
-    mKey->setText( str );
-
-  }
-  else if( mSearchControl.keyType == 1 )
-  {
-    TQString str("0x ");
-    for( uint i=0; i<mSearchControl.key.size(); i++ )
-    {
-      str += TQString().sprintf("%02X ", (unsigned char)mSearchControl.key[i]);
-    }
-    mKey->setText( str );
-  }
-  else if( mSearchControl.keyType == 2 )
-  {
-    TQString str;
-    for( uint i=0; i<mSearchControl.key.size(); i++ )
-    {
-      str += TQString().sprintf("%03o ", (unsigned char)mSearchControl.key[i]);
-    }
-    mKey->setText( str );
-  }
-  else
-  {
-    char buf[10];
-    memset( buf, 0, sizeof( buf ) ); buf[8] = ' ';
-
-    TQString str;
-    for( uint i=0; i<mSearchControl.key.size(); i++ )
-    {
-      unsigned char data = (unsigned char)mSearchControl.key[i];
-      for( int j = 0; j < 8; j++ )
-      {
-	buf[7-j] = (data&(1<<j)) ? '1' : '0';
-      }
-      str += buf;
-    }
-    mKey->setText( str );
-  }
-}
-
-
-void CFindNavigatorDialog::slotUser3( void ) // Previous
-{
-  done( repPrevious );
-}
-
-
-void CFindNavigatorDialog::slotUser2( void ) // Next
-{
-  done( repNext );
-}
-
-
-void CFindNavigatorDialog::slotUser1( void ) // New key
-{
-  done( repNewKey );
-}
-
-
-void CFindNavigatorDialog::slotClose( void )
-{
-  done( repClose );
-}
-
-
-void CFindNavigatorDialog::done( int resultCode )
-{
-  setResult( resultCode );
-  if( resultCode == repClose || resultCode == repNewKey )
-  {
-    if( resultCode == repNewKey )
-    {
-      emit makeKey();
-    }
-    hide();
-    return;
-  }
-
-  mSearchControl.forward = resultCode == repNext ? true : false;
-  emit findData( mSearchControl, Find_Next, true );
-}
-
-
-
-
-CReplaceDialog::CReplaceDialog( TQWidget *parent, const char *name, bool modal )
-  :KDialogBase( Plain, i18n("Find & Replace"), Ok|Cancel, Ok,
-		parent, name, modal )
-{
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  TQVBoxLayout *vbox = new TQVBoxLayout();
-  if( vbox == 0 ) { return; }
-  topLayout->addLayout( vbox );
-
-
-  mFindSelector = new TQComboBox( false, plainPage() );
-  if( mFindSelector == 0 ) { return; }
-  mFindSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mFindSelector->insertStringList( formatStrings() );
-  connect( mFindSelector, TQT_SIGNAL(activated(int)),
-	   TQT_SLOT(findSelectorChanged(int)) );
-
-  text = i18n("Fo&rmat (find):");
-  TQLabel *label = new TQLabel( mFindSelector, text, plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mFindSelector );
-
-  mFindInput = new TQLineEdit( plainPage() );
-  if( mFindInput == 0 ) { return; }
-  mFindInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mFindValidator = new CHexValidator( this, CHexValidator::regularText );
-  if( mFindValidator == 0 ) { return; }
-  mFindInput->setValidator( mFindValidator );
-  connect( mFindInput, TQT_SIGNAL(textChanged(const TQString&)),
-	   TQT_SLOT(findInputChanged(const TQString&)) );
-
-  label = new TQLabel( mFindInput, i18n("F&ind:"), plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mFindInput  );
-
-  mReplaceSelector = new TQComboBox( false, plainPage() );
-  if( mReplaceSelector == 0 ) { return; }
-  mReplaceSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mReplaceSelector->insertStringList( formatStrings() );
-  connect( mReplaceSelector, TQT_SIGNAL(activated(int)),
-	   TQT_SLOT(replaceSelectorChanged(int)) );
-
-  text = i18n("For&mat (replace):");
-  label = new TQLabel( mReplaceSelector, text, plainPage() );
-  if( label == 0 ) { return; }
-  label->setFixedHeight( label->sizeHint().height() );
-
-  vbox->addWidget( label );
-  vbox->addWidget( mReplaceSelector );
-
-  mReplaceInput = new TQLineEdit( plainPage() );
-  if( mReplaceInput == 0 ) { return; }
-  mReplaceInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mReplaceValidator = new CHexValidator( this, CHexValidator::regularText );
-  if( mReplaceValidator == 0 ) { return; }
-  mReplaceInput->setValidator( mReplaceValidator );
-  connect( mReplaceInput, TQT_SIGNAL(textChanged(const TQString&)),
-	   TQT_SLOT(replaceInputChanged(const TQString&)) );
-
-  label = new TQLabel( mReplaceInput, i18n("Rep&lace:"), plainPage() );
-  if( label == 0 ) { return; }
-  label->setFixedHeight( label->sizeHint().height() );
-
-  vbox->addWidget( label );
-  vbox->addWidget( mReplaceInput );
-
-  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
-  if( group == 0 ) { return; }
-  topLayout->addWidget( group, 10 );
-
-  TQGridLayout *gbox = new TQGridLayout( group, 5, 2, spacingHint() );
-  if( gbox == 0 ) { return; }
-  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
-  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
-  gbox->addWidget( mCheckFromCursor, 1, 0 );
-  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
-  gbox->addWidget( mCheckBackward, 1, 1 );
-  mCheckInSelection = new TQCheckBox( i18n("&In selection"), group );
-  gbox->addWidget( mCheckInSelection, 2, 0 );
-  mCheckPrompt = new TQCheckBox( i18n("&Prompt"), group );
-  gbox->addWidget( mCheckPrompt, 2, 1 );
-  mCheckIgnoreCase = new TQCheckBox( i18n("Ignore c&ase"), group );
-  gbox->addWidget( mCheckIgnoreCase, 3, 0 );
-  gbox->setRowStretch( 4, 10 );
-
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Replace Dialog");
-  mCheckFromCursor->setChecked( config.readBoolEntry( "FromCursor", true ) );
-  mCheckInSelection->setChecked( config.readBoolEntry( "InSelection", false) );
-  mCheckIgnoreCase->setChecked( config.readBoolEntry( "IgnoreCase", false ) );
-  mCheckBackward->setChecked( config.readBoolEntry( "Backwards", false ) );
-  mCheckPrompt->setChecked( config.readBoolEntry( "Prompt", true));
-  uint val = config.readUnsignedNumEntry( "FindFormat", 0 );
-  mFindSelector->setCurrentItem(TQMIN(4,val) );
-  findSelectorChanged( mFindSelector->currentItem() );
-  val = config.readUnsignedNumEntry( "ReplaceFormat", 0 );
-  mReplaceSelector->setCurrentItem(TQMIN(4,val) );
-  replaceSelectorChanged( mReplaceSelector->currentItem() );
-  enableButtonOK(!mFindInput->text().isEmpty());
-}
-
-
-CReplaceDialog::~CReplaceDialog( void )
-{
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Replace Dialog");
-  config.writeEntry( "FromCursor", mCheckFromCursor->isChecked() );
-  config.writeEntry( "InSelection", mCheckInSelection->isChecked() );
-  config.writeEntry( "IgnoreCase", mCheckIgnoreCase->isChecked() );
-  config.writeEntry( "Backwards", mCheckBackward->isChecked() );
-  config.writeEntry( "Prompt", mCheckPrompt->isChecked() );
-  config.writeEntry( "FindFormat", mFindSelector->currentItem() );
-  config.writeEntry( "ReplaceFormat", mReplaceSelector->currentItem() );
-  config.sync();
-}
-
-
-void CReplaceDialog::findSelectorChanged( int index )
-{
-  mFindValidator->setState( (CHexValidator::EState)index );
-  mFindInput->setText( mFindString[ index ] );
-  mCheckIgnoreCase->setEnabled( index == 4 );
-}
-
-
-void CReplaceDialog::findInputChanged( const TQString &text )
-{
-  mFindString[ mFindSelector->currentItem() ] = text;
-  mFindValidator->convert( mFindData,
-    mFindString[ mFindSelector->currentItem() ] );
-  enableButtonOK(!text.isEmpty());
-}
-
-
-void CReplaceDialog::replaceSelectorChanged( int index )
-{
-  mReplaceValidator->setState( (CHexValidator::EState)index );
-  mReplaceInput->setText( mReplaceString[ index ] );
-}
-
-
-void CReplaceDialog::replaceInputChanged( const TQString &text )
-{
-  mReplaceString[ mReplaceSelector->currentItem() ] = text;
-  mReplaceValidator->convert( mReplaceData,
-    mReplaceString[ mReplaceSelector->currentItem() ] );
-}
-
-
-void CReplaceDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  mFindInput->setFocus();
-}
-
-
-void CReplaceDialog::slotOk( void )
-{
-  if( mFindData.isEmpty() == true )
-  {
-    showEntryFailure( this, TQString("") );
-    return;
-  }
-
-  if( mFindData == mReplaceData )
-  {
-    showEntryFailure( this,i18n("Source and target values can not be equal."));
-    return;
-  }
-
-  hide();
-
-  SSearchControl sc;
-  sc.key = mFindData;
-  sc.val = mReplaceData;
-  sc.fromCursor = mCheckFromCursor->isChecked();
-  sc.inSelection = mCheckInSelection->isChecked();
-  sc.forward = mCheckBackward->isChecked() == true ? false : true;
-
-  sc.ignoreCase = mCheckIgnoreCase->isEnabled() && mCheckIgnoreCase->isChecked();
-
-  emit replaceData( sc, mCheckPrompt->isChecked() ? Replace_First: Replace_AllInit );
-}
-
-
-
-
-
-CReplacePromptDialog::CReplacePromptDialog( TQWidget *parent, const char *name,
-					     bool modal )
-  :KDialogBase( Plain, i18n("Find & Replace"), User3|User2|User1|Close,
-		User2, parent, name, modal, true, i18n("Replace &All"),
-		i18n("Do Not Replace"), i18n("Replace"))
-{
-  TQString text;
-  TQBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  topLayout->addSpacing( spacingHint() ); // A little bit extra space
-
-  text = i18n("Replace marked data at cursor position?");
-  TQLabel* label = new TQLabel( text, plainPage() );
-  topLayout->addWidget( label );
-
-  topLayout->addSpacing( spacingHint() ); // A little bit extra space
-  topLayout->addStretch(10);
-}
-
-
-CReplacePromptDialog::~CReplacePromptDialog( void )
-{
-}
-
-
-void CReplacePromptDialog::defineData( SSearchControl &sc )
-{
-  mSearchControl = sc;
-  mSearchControl.key.duplicate( sc.key );
-  mSearchControl.val.duplicate( sc.val );
-}
-
-
-void CReplacePromptDialog::slotUser3( void )
-{
-  done( repYes );
-}
-
-
-void CReplacePromptDialog::slotUser2( void )
-{
-  done( repNo );
-}
-
-
-void CReplacePromptDialog::slotUser1( void )
-{
-  done( repAll );
-}
-
-
-void CReplacePromptDialog::slotClose( void )
-{
-  done( repClose );
-}
-
-
-void CReplacePromptDialog::done( int returnCode )
-{
-  if( returnCode == repClose )
-  {
-    hide();
-  }
-  else if( returnCode == repYes )
-  {
-    emit replaceData( mSearchControl, Replace_Next );
-  }
-  else if( returnCode == repNo )
-  {
-    emit replaceData( mSearchControl, Replace_Ignore );
-  }
-  else
-  {
-    emit replaceData( mSearchControl, Replace_All );
-  }
-}
-
-
-
-
-CFilterDialog::CFilterDialog( TQWidget *parent, const char *name, bool modal )
-  :KDialogBase( Plain, i18n("Binary Filter"), Ok|Cancel, Ok,
-		parent, name, modal )
-{
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  TQVBoxLayout *vbox = new TQVBoxLayout();
-  if( vbox == 0 ) { return; }
-  topLayout->addLayout( vbox );
-
-
-  mOperationSelector = new TQComboBox( false, plainPage() );
-  if( mOperationSelector == 0 ) { return; }
-  mOperationSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mOperationSelector->insertStringList( operationStrings() );
-  connect( mOperationSelector, TQT_SIGNAL(activated(int)),
-	   TQT_SLOT(operationSelectorChanged(int)) );
-
-  text = i18n("O&peration:");
-  TQLabel *label = new TQLabel( mOperationSelector, text, plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mOperationSelector );
-
-  KSeparator *separator = new KSeparator( plainPage() );
-  separator->setOrientation( TQFrame::HLine );
-  vbox->addWidget( separator );
-
-
-  mWidgetStack = new TQWidgetStack( plainPage(), "pagestack" );
-  if( mWidgetStack == 0 ) { return; }
-  vbox->addWidget( mWidgetStack );
-
-  makeEmptyLayout();
-  makeOperandLayout();
-  makeBitSwapLayout();
-  makeRotateLayout();
-  mWidgetStack->raiseWidget( (int)OperandPage );
-
-
-  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
-  if( group == 0 ) { return; }
-  topLayout->addWidget( group, 10 );
-
-  TQGridLayout *gbox = new TQGridLayout( group, 4, 2, spacingHint() );
-  if( gbox == 0 ) { return; }
-  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
-  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
-  gbox->addWidget( mCheckFromCursor, 1, 0 );
-  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
-  gbox->addWidget( mCheckBackward, 1, 1 );
-  mCheckInSelection = new TQCheckBox( i18n("&In selection"), group );
-  gbox->addWidget( mCheckInSelection, 2, 0 );
-  mCheckVisible = new TQCheckBox( i18n("&Stay visible"), group );
-  gbox->addWidget( mCheckVisible, 2, 1 );
-  gbox->setRowStretch( 3, 10 );
-}
-
-
-CFilterDialog::~CFilterDialog( void )
-{
-  delete mOperandValidator;
-}
-
-
-void CFilterDialog::makeEmptyLayout( void )
-{
-  TQFrame *page = new TQFrame( plainPage() );
-  if( page == 0 ) { return; }
-  mWidgetStack->addWidget( page, EmptyPage );
-}
-
-
-void CFilterDialog::makeOperandLayout( void )
-{
-  TQString text;
-
-  TQFrame *page = new TQFrame( plainPage() );
-  if( page == 0 ) { return; }
-  mWidgetStack->addWidget( page, OperandPage );
-
-  TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, spacingHint() );
-  if( vbox == 0 ) { return; }
-
-  mOperandSelector = new TQComboBox( false, page );
-  if( mOperandSelector == 0 ) { return; }
-  mOperandSelector->setFixedHeight( mOperandSelector->sizeHint().height());
-  mOperandSelector->setMinimumWidth( fontMetrics().width("M")*20 );
-  mOperandSelector->insertStringList( formatStrings() );
-  connect( mOperandSelector, TQT_SIGNAL(activated(int)),
-	   TQT_SLOT(operandSelectorChanged(int)) );
-
-  text = i18n("Fo&rmat (operand):");
-  mOperandFormatLabel = new TQLabel( mOperandSelector, text, page );
-  if( mOperandFormatLabel == 0 ) { return; }
-
-  vbox->addWidget( mOperandFormatLabel );
-  vbox->addWidget( mOperandSelector );
-
-  mOperandInput = new TQLineEdit( page );
-  if( mOperandInput == 0 ) { return; }
-  mOperandInput->setMinimumWidth( fontMetrics().width("M") * 20 );
-  mOperandValidator = new CHexValidator( this, CHexValidator::regularText );
-  if( mOperandValidator == 0 ) { return; }
-  mOperandInput->setValidator( mOperandValidator );
-  connect( mOperandInput, TQT_SIGNAL(textChanged(const TQString&)),
-	   TQT_SLOT(operandInputChanged(const TQString&)) );
-
-  mOperandInputLabel = new TQLabel( mOperandInput, i18n("O&perand:"), page );
-  if( mOperandInputLabel == 0 ) { return; }
-
-  vbox->addWidget( mOperandInputLabel );
-  vbox->addWidget( mOperandInput  );
-  vbox->addSpacing( 1 );
-}
-
-
-void CFilterDialog::makeBitSwapLayout( void )
-{
-  TQString text;
-
-  TQFrame *page = new TQFrame( plainPage() );
-  if( page == 0 ) { return; }
-  mWidgetStack->addWidget( page, BitSwapPage );
-
-  TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, spacingHint() );
-  if( vbox == 0 ) { return; }
-
-  text = i18n("Swap rule");
-  TQLabel *label = new TQLabel( text, page );
-  if( label == 0 ) { return; }
-  label->setFixedHeight( label->sizeHint().height() );
-  vbox->addWidget( label );
-
-  mByteWidget = new CByteWidget( page );
-  vbox->addWidget( mByteWidget );
-
-  TQHBoxLayout *hbox = new TQHBoxLayout( 0 );
-  vbox->addLayout( hbox );
-
-  text = i18n("&Reset");
-  TQPushButton *resetButton = new TQPushButton( text, page );
-  resetButton->setFixedHeight( resetButton->sizeHint().height() );
-  connect( resetButton, TQT_SIGNAL(clicked()), mByteWidget, TQT_SLOT(reset()) );
-
-  hbox->addWidget( resetButton );
-  hbox->addStretch( 10 );
-}
-
-
-void CFilterDialog::makeRotateLayout( void )
-{
-  TQString text;
-
-  TQFrame *page = new TQFrame( plainPage() );
-  if( page == 0 ) { return; }
-  mWidgetStack->addWidget( page, RotatePage );
-
-  TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, spacingHint() );
-  if( vbox == 0 ) { return; }
-
-  mGroupSpin = new TQSpinBox( page );
-  if( mGroupSpin == 0 ) { return; }
-  mGroupSpin->setMinimumWidth( fontMetrics().width("M")*20 );
-  mGroupSpin->setRange(1, INT_MAX );
-
-  text = i18n("&Group size [bytes]");
-  TQLabel *label = new TQLabel( mGroupSpin, text, page );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mGroupSpin );
-
-  mBitSpin = new TQSpinBox( page );
-  if( mBitSpin == 0 ) { return; }
-  mBitSpin->setMinimumWidth( fontMetrics().width("M")*20 );
-  mBitSpin->setRange(INT_MIN, INT_MAX);
-
-  text = i18n("S&hift size [bits]");
-  label = new TQLabel( mBitSpin, text, page );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mBitSpin );
-}
-
-
-
-void CFilterDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  mOperandInput->setFocus();
-}
-
-
-
-void CFilterDialog::slotOk( void )
-{
-  SFilterControl fc;
-  switch( mOperationSelector->currentItem() )
-  {
-    case SFilterControl::OperandAndData:
-    case SFilterControl::OperandOrData:
-    case SFilterControl::OperandXorData:
-      if( mOperandData.isEmpty() == true )
-      {
-	showEntryFailure( this, TQString("") );
-	return;
-      }
-      fc.operand = mOperandData;
-    break;
-
-    case SFilterControl::InvertData:
-    case SFilterControl::ReverseData:
-    break;
-
-    case SFilterControl::RotateData:
-    case SFilterControl::ShiftData:
-      fc.rotate[0] = mGroupSpin->value();
-      fc.rotate[1] = mBitSpin->value();
-      if( fc.rotate[1] == 0 )
-      {
-	TQString msg = i18n("Shift size is zero.");
-	showEntryFailure( this, msg );
-	return;
-      }
-    break;
-
-    case SFilterControl::SwapBits:
-      if( mByteWidget->flag( fc.operand ) == false )
-      {
-	TQString msg = i18n("Swap rule does not define any swapping.");
-	showEntryFailure( this, msg );
-	return;
-      }
-    break;
-
-    default:
-      return;
-    break;
-
-  }
-
-  if( mCheckVisible->isChecked() == false )
-  {
-    hide();
-  }
-
-  fc.operation = (SFilterControl::Operation)mOperationSelector->currentItem();
-  fc.fromCursor = mCheckFromCursor->isChecked();
-  fc.inSelection = mCheckInSelection->isChecked();
-  if( mCheckBackward->isEnabled() == true )
-  {
-    fc.forward = mCheckBackward->isChecked() == true ? false : true;
-  }
-  else
-  {
-    fc.forward = true;
-  }
-
-  emit filterData( fc );
-}
-
-
-void CFilterDialog::operandSelectorChanged( int index )
-{
-  mOperandValidator->setState( (CHexValidator::EState)index );
-  mOperandInput->setText( mOperandString[ index ] );
-}
-
-
-void CFilterDialog::operandInputChanged( const TQString &text )
-{
-  mOperandString[ mOperandSelector->currentItem() ] = text;
-  mOperandValidator->convert( mOperandData,
-    mOperandString[ mOperandSelector->currentItem() ] );
-}
-
-
-void CFilterDialog::operationSelectorChanged( int index )
-{
-  if( index <= 2 )
-  {
-    mWidgetStack->raiseWidget( OperandPage );
-    mCheckBackward->setEnabled( true );
-  }
-  else if( index <= 4 )
-  {
-    mWidgetStack->raiseWidget( EmptyPage );
-    mCheckBackward->setEnabled( true );
-  }
-  else if( index <= 6 )
-  {
-    mWidgetStack->raiseWidget( RotatePage );
-    mCheckBackward->setEnabled( false );
-  }
-  else
-  {
-    mWidgetStack->raiseWidget( BitSwapPage );
-    mCheckBackward->setEnabled( true );
-  }
-}
-
-
-
-
-CInsertDialog::CInsertDialog( TQWidget *parent, const char *name, bool modal )
-  :KDialogBase( Plain, i18n("Insert Pattern"), Ok|Cancel, Ok,
-		parent, name, modal )
-{
-  setButtonOKText(i18n("&Insert"));
-
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-  TQVBoxLayout *vbox = new TQVBoxLayout();
-  if( vbox == 0 ) { return; }
-  topLayout->addLayout( vbox );
-
-  mSizeBox = new TQSpinBox( plainPage() );
-  if( mSizeBox == 0 ) { return; }
-  mSizeBox->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mSizeBox->setRange( 1, INT_MAX );
-  mSizeBox->setValue( 1 );
-
-  TQLabel *label = new TQLabel( mSizeBox, i18n("&Size:"), plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mSizeBox );
-
-  mPatternSelector = new TQComboBox( false, plainPage() );
-  if( mPatternSelector == 0 ) { return; }
-  mPatternSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mPatternSelector->insertStringList( formatStrings() );
-  connect( mPatternSelector, TQT_SIGNAL(activated(int)),
-	   TQT_SLOT(patternSelectorChanged(int)) );
-
-  text = i18n("Fo&rmat (pattern):");
-  label = new TQLabel( mPatternSelector, text, plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mPatternSelector );
-
-  mPatternInput = new TQLineEdit( plainPage() );
-  if( mPatternInput == 0 ) { return; }
-  mPatternInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mPatternValidator = new CHexValidator( this, CHexValidator::regularText );
-  if( mPatternValidator == 0 ) { return; }
-  mPatternInput->setValidator( mPatternValidator );
-  connect( mPatternInput, TQT_SIGNAL(textChanged(const TQString&)),
-	   TQT_SLOT(patternInputChanged(const TQString&)) );
-
-  label = new TQLabel( mPatternInput, i18n("&Pattern:"), plainPage() );
-  if( label == 0 ) { return; }
-
-  vbox->addWidget( label );
-  vbox->addWidget( mPatternInput );
-
-  mOffsetInput = new TQLineEdit( plainPage() );
-  mOffsetInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
-
-  mOffsetLabel = new TQLabel( mOffsetInput, i18n("&Offset:"), plainPage() );
-  if( mOffsetLabel == 0 ) { return; }
-
-  vbox->addWidget( mOffsetLabel );
-  vbox->addWidget( mOffsetInput );
-
-  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
-  if( group == 0 ) { return; }
-  topLayout->addWidget( group, 10 );
-
-
-  TQGridLayout *gbox = new TQGridLayout( group, 4, 2, spacingHint() );
-  if( gbox == 0 ) { return; }
-  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
-
-  mCheckPattern = new TQCheckBox( i18n("R&epeat pattern"), group );
-  gbox->addWidget( mCheckPattern, 1, 0 );
-  mCheckOnCursor = new TQCheckBox( i18n("&Insert on cursor position"), group );
-  gbox->addWidget( mCheckOnCursor, 2, 0 );
-  connect( mCheckOnCursor, TQT_SIGNAL(clicked()), TQT_SLOT(cursorCheck()) );
-  gbox->setRowStretch( 3, 10 );
-
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Insert Pattern Dialog");
-  mCheckPattern->setChecked( config.readBoolEntry( "RepeatPattern", false ) );
-  mCheckOnCursor->setChecked( config.readBoolEntry( "InsertOnCursor", false) );
-  cursorCheck();
-  uint val = config.readUnsignedNumEntry( "Format", 0 );
-  mPatternSelector->setCurrentItem( TQMIN(4,val) );
-  patternSelectorChanged( mPatternSelector->currentItem() );
-}
-
-
-CInsertDialog::~CInsertDialog( void )
-{
-  TDEConfig &config = *kapp->config();
-  config.setGroup("Insert Pattern Dialog");
-  config.writeEntry( "RepeatPattern", mCheckPattern->isChecked() );
-  config.writeEntry( "InsertOnCursor", mCheckOnCursor->isChecked() );
-  config.writeEntry( "Format", mPatternSelector->currentItem() );
-  config.sync();
-}
-
-
-void CInsertDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  mPatternInput->setFocus();
-}
-
-
-void CInsertDialog::patternSelectorChanged( int index )
-{
-  mPatternValidator->setState( (CHexValidator::EState)index );
-  mPatternInput->setText( mPatternString[ index ] );
-}
-
-
-void CInsertDialog::patternInputChanged( const TQString &text )
-{
-  mPatternString[ mPatternSelector->currentItem() ] = text;
-  mPatternValidator->convert( mPatternData,
-    mPatternString[ mPatternSelector->currentItem() ] );
-}
-
-
-void CInsertDialog::slotOk( void )
-{
-  if( mPatternData.isEmpty() == true )
-  {
-    showEntryFailure( this, TQString("") );
-    return;
-  }
-
-  SInsertData id;
-  id.size = mSizeBox->value();
-  id.repeatPattern = mCheckPattern->isChecked();
-  id.onCursor = mCheckOnCursor->isChecked();
-  id.pattern = mPatternData;
-
-  if( id.onCursor == false )
-  {
-    bool success = stringToOffset( mOffsetInput->text(), id.offset );
-    if( success == false )
-    {
-      showEntryFailure( this, TQString("") );
-      return;
-    }
-  }
-
-  hide();
-  execute( id );
-}
-
-
-void CInsertDialog::cursorCheck( void )
-{
-  bool state = mCheckOnCursor->isChecked() == true ? false : true;
-  mOffsetLabel->setEnabled( state );
-  mOffsetInput->setEnabled( state );
-}
-
-
-
-
-void centerDialog( TQWidget *widget, TQWidget *centerParent )
-{
-  if( centerParent == 0 || widget == 0 )
-  {
-    return;
-  }
-
-  TQPoint point = centerParent->mapToGlobal( TQPoint(0,0) );
-  TQRect pos    = centerParent->geometry();
-
-  widget->setGeometry( point.x() + pos.width()/2  - widget->width()/2,
-		       point.y() + pos.height()/2 - widget->height()/2,
-		       widget->width(), widget->height() );
-}
-
-
-void centerDialogBottom( TQWidget *widget, TQWidget *centerParent )
-{
-  if( centerParent == 0 || widget == 0 )
-  {
-    return;
-  }
-
-  TQPoint point = centerParent->mapToGlobal( TQPoint(0,0) );
-  TQRect pos    = centerParent->geometry();
-
-  widget->setGeometry( point.x() + pos.width()/2  - widget->width()/2,
-		       point.y() + pos.height() - widget->height(),
-		       widget->width(), widget->height() );
-}
-
-
-void comboMatchText( TQComboBox *combo, const TQString &text )
-{
-  for( int i=0; i < combo->count(); i++ )
-  {
-    if( combo->text(i) == text )
-    {
-      combo->setCurrentItem(i);
-      return;
-    }
-  }
-  combo->setCurrentItem(0);
-}
-
-
-
-
-
-void showEntryFailure( TQWidget *parent, const TQString &msg )
-{
-  TQString message;
-  message += i18n("Your request can not be processed.");
-  message += "\n";
-  if( msg.isNull() == true || msg.isEmpty() == true )
-  {
-    message += i18n("Examine argument(s) and try again.");
-  }
-  else
-  {
-    message += msg;
-  }
-  KMessageBox::sorry( parent, message, i18n("Invalid argument(s)") );
-}
-
-
-bool verifyFileDestnation( TQWidget *parent, const TQString &title,
-			   const TQString &path )
-{
-  if( path.isEmpty() == true )
-  {
-    TQString msg = i18n("You must specify a destination file.");
-    KMessageBox::sorry( parent, msg, title );
-    return( false );
-  }
-
-  TQFileInfo info( path );
-  if( info.exists() == true )
-  {
-    if( info.isDir() == true )
-    {
-      TQString msg = i18n("You have specified an existing folder.");
-      KMessageBox::sorry( parent, msg, title );
-      return( false );
-    }
-
-    if( info.isWritable() == false )
-    {
-      TQString msg = i18n("You do not have write permission to this file.");
-      KMessageBox::sorry( parent, msg, title );
-      return( false );
-    }
-
-    TQString msg = i18n( ""
-      "You have specified an existing file.\n"
-      "Overwrite current file?" );
-    int reply = KMessageBox::warningContinueCancel( parent, msg, title, i18n("Overwrite") );
-    if( reply != KMessageBox::Continue )
-    {
-      return( false );
-    }
-  }
-
-  return( true );
-}
-
-
-
-bool stringToOffset( const TQString & text, uint &offset )
-{
-  if( text.isEmpty() )
-  {
-    return( false );
-  }
-
-  const char * p = text.ascii(); // ####: Is this correct?
-
-  //
-  // Skip any whitespaces in front of string
-  //
-  for( ; *p != 0 && isspace( *p ) ; p++ );
-
-  int match = 0;
-  bool space = false;
-  if( strncmp( p, "0x", 2 ) == 0 || strncmp( p, "0X", 2 ) == 0 )
-  {
-    for( const char *q = p+2; *q != 0; q++ )
-    {
-      if( isxdigit( *q ) == 0 || space == true )
-      {
-	if( isspace( *q ) == 0 )
-	{
-	  return( false );
-	}
-	space = true;
-      }
-    }
-    match = sscanf( p+2, "%x", &offset );
-  }
-  else
-  {
-    for( const char *q = p; *q != 0; q++ )
-    {
-      if( isdigit( *q ) == 0 || space == true )
-      {
-	if( isspace( *q ) == 0 )
-	{
-	  return( false );
-	}
-	space = true;
-      }
-    }
-    match = sscanf( p, "%u", &offset );
-  }
-
-  if( match == 0 )
-  {
-    return( false );
-  }
-
-  return( true );
-}
-
-
-static const TQStringList &formatStrings( void )
-{
-  static TQStringList list;
-  if( list.isEmpty() == true )
-  {
-    list.append( i18n( "Hexadecimal" ) );
-    list.append( i18n( "Decimal" ) );
-    list.append( i18n( "Octal" ) );
-    list.append( i18n( "Binary" ) );
-    list.append( i18n( "Regular Text" ) );
-  }
-  return( list );
-}
-
-
-static const TQStringList &operationStrings( void )
-{
-  static TQStringList list;
-  if( list.isEmpty() == true )
-  {
-    list.append( i18n( "operand AND data" ) );
-    list.append( i18n( "operand OR data" ) );
-    list.append( i18n( "operand XOR data" ) );
-    list.append( i18n( "INVERT data" ) );
-    list.append( i18n( "REVERSE data" ) );
-    list.append( i18n( "ROTATE data" ) );
-    list.append( i18n( "SHIFT data" ) );
-    list.append( i18n( "Swap Individual Bits" ) );
-  }
-
-  return( list );
-}
-
-
-
-
-
-#include "dialog.moc"
diff --git a/khexedit/dialog.cpp b/khexedit/dialog.cpp
new file mode 100644
index 00000000..c2f2d80b
--- /dev/null
+++ b/khexedit/dialog.cpp
@@ -0,0 +1,1433 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <ctype.h>
+#include <iostream>
+#include <limits.h>
+
+#include <tqbuttongroup.h>
+#include <tqfileinfo.h>
+#include <tqlayout.h>
+#include <tqvalidator.h>
+
+#include <tdefiledialog.h>
+#include <tdelocale.h>
+#include <tdemessagebox.h>
+#include <kseparator.h>
+#include <kstdguiitem.h>
+
+#include "dialog.h"
+#include <tqpushbutton.h>
+
+static const TQStringList &formatStrings( void );
+static const TQStringList &operationStrings( void );
+
+
+CGotoDialog::CGotoDialog( TQWidget *parent, const char *name, bool modal )
+  :KDialogBase( Plain, i18n("Goto Offset"), Ok|Cancel, Ok, parent, name,
+		modal )
+{
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  TQVBoxLayout *vbox = new TQVBoxLayout();
+  if( vbox == 0 ) { return; }
+  topLayout->addLayout( vbox );
+
+  mComboBox = new TQComboBox( true, plainPage() );
+  if( mComboBox == 0 ) { return; }
+  mComboBox->setMaxCount( 10 );
+  mComboBox->setInsertionPolicy( TQComboBox::AtTop );
+  mComboBox->setMinimumWidth( fontMetrics().maxWidth()*17 );
+
+  TQLabel *label = new TQLabel( mComboBox, i18n("O&ffset:"), plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mComboBox );
+
+  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
+  if( group == 0 ) { return; }
+  topLayout->addWidget( group, 10 );
+
+  TQGridLayout *gbox = new TQGridLayout( group, 4, 2, spacingHint() );
+  if( gbox == 0 ) { return; }
+  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
+  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
+  gbox->addWidget( mCheckFromCursor, 1, 0 );
+  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
+  gbox->addWidget( mCheckBackward, 1, 1 );
+  mCheckVisible = new TQCheckBox( i18n("&Stay visible"), group );
+  gbox->addWidget( mCheckVisible, 2, 0 );
+  gbox->setRowStretch( 3, 10 );
+
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Goto Dialog");
+  mCheckFromCursor->setChecked( config.readBoolEntry( "FromCursor", false ) );
+  mCheckVisible->setChecked( config.readBoolEntry( "StayVisible", true ) );
+  mCheckBackward->setChecked( config.readBoolEntry( "Backwards", false ) );
+}
+
+
+
+CGotoDialog::~CGotoDialog( void )
+{
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Goto Dialog");
+  config.writeEntry( "FromCursor", mCheckFromCursor->isChecked() );
+  config.writeEntry( "StayVisible", mCheckVisible->isChecked() );
+  config.writeEntry( "Backwards", mCheckBackward->isChecked() );
+  config.sync();
+}
+
+
+
+void CGotoDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  mComboBox->setFocus();
+}
+
+
+
+//
+// Format of input string:
+// 0x<HexNumber>|<DecimalNumber>s<Bit>
+// s = :,. or space
+//
+void CGotoDialog::slotOk( void )
+{
+  uint offset;
+  bool success = stringToOffset( mComboBox->currentText(), offset );
+  if( success == false )
+  {
+    showEntryFailure( this, TQString("") );
+    return;
+  }
+
+  if( mCheckVisible->isChecked() == false )
+  {
+    hide();
+  }
+  emit gotoOffset( offset, 7, mCheckFromCursor->isChecked(),
+		   mCheckBackward->isChecked() == true ? false : true );
+
+  #if 0
+  const char *p = mComboBox->currentText();
+  if( strlen( p ) == 0 )
+  {
+    return;
+  }
+
+  //
+  // Skip any whitespaces in front of string
+  //
+  for( ; *p != 0 && isspace( *p ) ; p++ );
+
+  uint offset, bit;
+  int match;
+  if( strncmp( p, "0x", 2 ) == 0 || strncmp( p, "0X", 2 ) == 0 )
+  {
+    match = sscanf( p+2, "%x", &offset );
+  }
+  else
+  {
+    match = sscanf( p, "%u", &offset );
+  }
+
+  if( match == 0 )
+  {
+    return;
+  }
+
+  bit = 7;
+
+  p = strpbrk( p, ":,. " );
+  if( p != 0 )
+  {
+    match = sscanf( p+1, "%u", &bit );
+    if( match == 0 )
+    {
+      return;
+    }
+    if( bit > 7 ) { bit = 7; }
+  }
+  #endif
+}
+
+
+
+CFindDialog::CFindDialog( TQWidget *parent, const char *name, bool modal )
+  :KDialogBase( Plain, i18n("Find"), Ok|Cancel, Ok, parent, name, modal )
+{
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  TQVBoxLayout *vbox = new TQVBoxLayout();
+  if( vbox == 0 ) { return; }
+  topLayout->addLayout( vbox );
+
+  mSelector = new TQComboBox( false, plainPage() );
+  if( mSelector == 0 ) { return; }
+  mSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mSelector->insertStringList( formatStrings() );
+  connect( mSelector, TQT_SIGNAL(activated(int)), TQT_SLOT(selectorChanged(int)) );
+
+  TQLabel *label = new TQLabel( mSelector, i18n("Fo&rmat:"), plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mSelector );
+
+  mInput = new TQLineEdit( plainPage() );
+  if( mInput == 0 ) { return; }
+  mInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  connect( mInput, TQT_SIGNAL(textChanged(const TQString&)),
+	   TQT_SLOT(inputChanged(const TQString&)) );
+  mFindValidator = new CHexValidator( this, CHexValidator::regularText );
+  if( mFindValidator == 0 ) { return; }
+  mInput->setValidator( mFindValidator );
+
+  label = new TQLabel( mInput, i18n("F&ind:"), plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mInput );
+
+  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
+  if( group == 0 ) { return; }
+  topLayout->addWidget( group, 10 );
+
+  TQGridLayout *gbox = new TQGridLayout( group, 5, 2, spacingHint() );
+  if( gbox == 0 ) { return; }
+  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
+
+  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
+  gbox->addWidget( mCheckFromCursor, 1, 0 );
+  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
+  gbox->addWidget( mCheckBackward, 1, 1 );
+  mCheckInSelection = new TQCheckBox( i18n("&In selection"), group );
+  gbox->addWidget( mCheckInSelection, 2, 0 );
+  mCheckUseNavigator = new TQCheckBox( i18n("&Use navigator"),group);
+  gbox->addWidget( mCheckUseNavigator, 2, 1 );
+  mCheckIgnoreCase = new TQCheckBox( i18n("Ignore c&ase"),group);
+  gbox->addWidget( mCheckIgnoreCase, 3, 0 );
+  gbox->setRowStretch( 4, 10 );
+
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Find Dialog");
+  mCheckFromCursor->setChecked( config.readBoolEntry( "FromCursor", true ) );
+  mCheckInSelection->setChecked( config.readBoolEntry( "InSelection", false) );
+  mCheckIgnoreCase->setChecked( config.readBoolEntry( "IgnoreCase", false ) );
+  mCheckBackward->setChecked( config.readBoolEntry( "Backwards", false ) );
+  mCheckUseNavigator->setChecked( config.readBoolEntry( "UseNavigator", true));
+  uint val = config.readUnsignedNumEntry( "Format", 0 );
+  mSelector->setCurrentItem(TQMIN(4,val) );
+  selectorChanged( mSelector->currentItem() );
+  enableButtonOK(!mInput->text().isEmpty());
+}
+
+
+CFindDialog::~CFindDialog( void )
+{
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Find Dialog");
+  config.writeEntry( "FromCursor", mCheckFromCursor->isChecked() );
+  config.writeEntry( "InSelection", mCheckInSelection->isChecked() );
+  config.writeEntry( "IgnoreCase", mCheckIgnoreCase->isChecked() );
+  config.writeEntry( "Backwards", mCheckBackward->isChecked() );
+  config.writeEntry( "UseNavigator", mCheckUseNavigator->isChecked() );
+  config.writeEntry( "Format", mSelector->currentItem() );
+  config.sync();
+}
+
+
+void CFindDialog::selectorChanged( int index )
+{
+  mFindValidator->setState( (CHexValidator::EState)index );
+  mInput->setText( mFindString[ index ] );
+  mCheckIgnoreCase->setEnabled( index == 4 );
+}
+
+
+void CFindDialog::inputChanged( const TQString &text )
+{
+  mFindString[ mSelector->currentItem() ] = text;
+  mFindValidator->convert( mFindData,
+    mFindString[ mSelector->currentItem() ] );
+  enableButtonOK(!text.isEmpty());
+}
+
+
+void CFindDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  mInput->setFocus();
+}
+
+
+bool CFindDialog::isEmpty( void )
+{
+  return( mFindData.isEmpty() );
+}
+
+
+void CFindDialog::slotOk( void )
+{
+  if( isEmpty() == true )
+  {
+    showEntryFailure( this, TQString("") );
+    return;
+  }
+
+  SSearchControl sc;
+  sc.key = mFindData;
+  sc.keyType = mSelector->currentItem();
+  sc.fromCursor = mCheckFromCursor->isChecked();
+  sc.inSelection = mCheckInSelection->isChecked();
+  sc.forward = mCheckBackward->isChecked() == true ? false : true;
+  sc.ignoreCase = mCheckIgnoreCase->isEnabled() && mCheckIgnoreCase->isChecked();
+
+  hide();
+  emit findData( sc, Find_First, mCheckUseNavigator->isChecked() );
+}
+
+
+void CFindDialog::findAgain( EOperation operation )
+{
+  if( isEmpty() == true )
+  {
+    showEntryFailure( this, TQString("") );
+    return;
+  }
+
+  SSearchControl sc;
+  sc.key = mFindData;
+  sc.fromCursor = true;
+  sc.inSelection = mCheckInSelection->isChecked();
+  sc.ignoreCase = mCheckIgnoreCase->isEnabled() && mCheckIgnoreCase->isChecked();
+  if( operation == find_Next )
+  {
+    sc.forward = true;
+  }
+  else if( operation == find_Previous )
+  {
+    sc.forward = false;
+  }
+  else
+  {
+    sc.forward = mCheckBackward->isChecked() == true ? false : true;
+  }
+
+  hide();
+  emit findData( sc, Find_Next, false );
+}
+
+
+
+CFindNavigatorDialog::CFindNavigatorDialog( TQWidget *parent, const char *name,
+					     bool modal )
+  :KDialogBase( Plain, i18n("Find (Navigator)"), User3|User2|User1|Close,
+		User2, parent, name, modal, true, i18n("New &Key"),
+		i18n("&Next"), i18n("&Previous") )
+{
+  TQString text;
+  TQBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  topLayout->addSpacing( spacingHint() ); // A little bit extra space
+
+  TQHBoxLayout *hbox = new TQHBoxLayout();
+  if( hbox == 0 ) { return; }
+  topLayout->addLayout( hbox );
+
+  text = i18n("Searching for:");
+  TQLabel *label = new TQLabel( text, plainPage() );
+  hbox->addWidget( label );
+
+  mKey = new TQLineEdit( plainPage() );
+  mKey->setMinimumWidth( fontMetrics().width("M") * 20 );
+  mKey->setFocusPolicy( TQ_NoFocus );
+  hbox->addWidget( mKey );
+
+  topLayout->addSpacing( spacingHint() ); // A little bit extra space
+  topLayout->addStretch(10);
+}
+
+
+CFindNavigatorDialog::~CFindNavigatorDialog( void )
+{
+}
+
+
+void CFindNavigatorDialog::defineData( SSearchControl &sc )
+{
+  mSearchControl = sc;
+  mSearchControl.key.duplicate( sc.key );
+
+  if( mSearchControl.key.isEmpty() == true )
+  {
+    mKey->setText("");
+    return;
+  }
+
+  if( mSearchControl.keyType == 0 )
+  {
+    TQString str;
+    for( uint i=0; i<mSearchControl.key.size(); i++ )
+    {
+      str += mSearchControl.key[i];
+    }
+    mKey->setText( str );
+
+  }
+  else if( mSearchControl.keyType == 1 )
+  {
+    TQString str("0x ");
+    for( uint i=0; i<mSearchControl.key.size(); i++ )
+    {
+      str += TQString().sprintf("%02X ", (unsigned char)mSearchControl.key[i]);
+    }
+    mKey->setText( str );
+  }
+  else if( mSearchControl.keyType == 2 )
+  {
+    TQString str;
+    for( uint i=0; i<mSearchControl.key.size(); i++ )
+    {
+      str += TQString().sprintf("%03o ", (unsigned char)mSearchControl.key[i]);
+    }
+    mKey->setText( str );
+  }
+  else
+  {
+    char buf[10];
+    memset( buf, 0, sizeof( buf ) ); buf[8] = ' ';
+
+    TQString str;
+    for( uint i=0; i<mSearchControl.key.size(); i++ )
+    {
+      unsigned char data = (unsigned char)mSearchControl.key[i];
+      for( int j = 0; j < 8; j++ )
+      {
+	buf[7-j] = (data&(1<<j)) ? '1' : '0';
+      }
+      str += buf;
+    }
+    mKey->setText( str );
+  }
+}
+
+
+void CFindNavigatorDialog::slotUser3( void ) // Previous
+{
+  done( repPrevious );
+}
+
+
+void CFindNavigatorDialog::slotUser2( void ) // Next
+{
+  done( repNext );
+}
+
+
+void CFindNavigatorDialog::slotUser1( void ) // New key
+{
+  done( repNewKey );
+}
+
+
+void CFindNavigatorDialog::slotClose( void )
+{
+  done( repClose );
+}
+
+
+void CFindNavigatorDialog::done( int resultCode )
+{
+  setResult( resultCode );
+  if( resultCode == repClose || resultCode == repNewKey )
+  {
+    if( resultCode == repNewKey )
+    {
+      emit makeKey();
+    }
+    hide();
+    return;
+  }
+
+  mSearchControl.forward = resultCode == repNext ? true : false;
+  emit findData( mSearchControl, Find_Next, true );
+}
+
+
+
+
+CReplaceDialog::CReplaceDialog( TQWidget *parent, const char *name, bool modal )
+  :KDialogBase( Plain, i18n("Find & Replace"), Ok|Cancel, Ok,
+		parent, name, modal )
+{
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  TQVBoxLayout *vbox = new TQVBoxLayout();
+  if( vbox == 0 ) { return; }
+  topLayout->addLayout( vbox );
+
+
+  mFindSelector = new TQComboBox( false, plainPage() );
+  if( mFindSelector == 0 ) { return; }
+  mFindSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mFindSelector->insertStringList( formatStrings() );
+  connect( mFindSelector, TQT_SIGNAL(activated(int)),
+	   TQT_SLOT(findSelectorChanged(int)) );
+
+  text = i18n("Fo&rmat (find):");
+  TQLabel *label = new TQLabel( mFindSelector, text, plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mFindSelector );
+
+  mFindInput = new TQLineEdit( plainPage() );
+  if( mFindInput == 0 ) { return; }
+  mFindInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mFindValidator = new CHexValidator( this, CHexValidator::regularText );
+  if( mFindValidator == 0 ) { return; }
+  mFindInput->setValidator( mFindValidator );
+  connect( mFindInput, TQT_SIGNAL(textChanged(const TQString&)),
+	   TQT_SLOT(findInputChanged(const TQString&)) );
+
+  label = new TQLabel( mFindInput, i18n("F&ind:"), plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mFindInput  );
+
+  mReplaceSelector = new TQComboBox( false, plainPage() );
+  if( mReplaceSelector == 0 ) { return; }
+  mReplaceSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mReplaceSelector->insertStringList( formatStrings() );
+  connect( mReplaceSelector, TQT_SIGNAL(activated(int)),
+	   TQT_SLOT(replaceSelectorChanged(int)) );
+
+  text = i18n("For&mat (replace):");
+  label = new TQLabel( mReplaceSelector, text, plainPage() );
+  if( label == 0 ) { return; }
+  label->setFixedHeight( label->sizeHint().height() );
+
+  vbox->addWidget( label );
+  vbox->addWidget( mReplaceSelector );
+
+  mReplaceInput = new TQLineEdit( plainPage() );
+  if( mReplaceInput == 0 ) { return; }
+  mReplaceInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mReplaceValidator = new CHexValidator( this, CHexValidator::regularText );
+  if( mReplaceValidator == 0 ) { return; }
+  mReplaceInput->setValidator( mReplaceValidator );
+  connect( mReplaceInput, TQT_SIGNAL(textChanged(const TQString&)),
+	   TQT_SLOT(replaceInputChanged(const TQString&)) );
+
+  label = new TQLabel( mReplaceInput, i18n("Rep&lace:"), plainPage() );
+  if( label == 0 ) { return; }
+  label->setFixedHeight( label->sizeHint().height() );
+
+  vbox->addWidget( label );
+  vbox->addWidget( mReplaceInput );
+
+  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
+  if( group == 0 ) { return; }
+  topLayout->addWidget( group, 10 );
+
+  TQGridLayout *gbox = new TQGridLayout( group, 5, 2, spacingHint() );
+  if( gbox == 0 ) { return; }
+  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
+  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
+  gbox->addWidget( mCheckFromCursor, 1, 0 );
+  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
+  gbox->addWidget( mCheckBackward, 1, 1 );
+  mCheckInSelection = new TQCheckBox( i18n("&In selection"), group );
+  gbox->addWidget( mCheckInSelection, 2, 0 );
+  mCheckPrompt = new TQCheckBox( i18n("&Prompt"), group );
+  gbox->addWidget( mCheckPrompt, 2, 1 );
+  mCheckIgnoreCase = new TQCheckBox( i18n("Ignore c&ase"), group );
+  gbox->addWidget( mCheckIgnoreCase, 3, 0 );
+  gbox->setRowStretch( 4, 10 );
+
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Replace Dialog");
+  mCheckFromCursor->setChecked( config.readBoolEntry( "FromCursor", true ) );
+  mCheckInSelection->setChecked( config.readBoolEntry( "InSelection", false) );
+  mCheckIgnoreCase->setChecked( config.readBoolEntry( "IgnoreCase", false ) );
+  mCheckBackward->setChecked( config.readBoolEntry( "Backwards", false ) );
+  mCheckPrompt->setChecked( config.readBoolEntry( "Prompt", true));
+  uint val = config.readUnsignedNumEntry( "FindFormat", 0 );
+  mFindSelector->setCurrentItem(TQMIN(4,val) );
+  findSelectorChanged( mFindSelector->currentItem() );
+  val = config.readUnsignedNumEntry( "ReplaceFormat", 0 );
+  mReplaceSelector->setCurrentItem(TQMIN(4,val) );
+  replaceSelectorChanged( mReplaceSelector->currentItem() );
+  enableButtonOK(!mFindInput->text().isEmpty());
+}
+
+
+CReplaceDialog::~CReplaceDialog( void )
+{
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Replace Dialog");
+  config.writeEntry( "FromCursor", mCheckFromCursor->isChecked() );
+  config.writeEntry( "InSelection", mCheckInSelection->isChecked() );
+  config.writeEntry( "IgnoreCase", mCheckIgnoreCase->isChecked() );
+  config.writeEntry( "Backwards", mCheckBackward->isChecked() );
+  config.writeEntry( "Prompt", mCheckPrompt->isChecked() );
+  config.writeEntry( "FindFormat", mFindSelector->currentItem() );
+  config.writeEntry( "ReplaceFormat", mReplaceSelector->currentItem() );
+  config.sync();
+}
+
+
+void CReplaceDialog::findSelectorChanged( int index )
+{
+  mFindValidator->setState( (CHexValidator::EState)index );
+  mFindInput->setText( mFindString[ index ] );
+  mCheckIgnoreCase->setEnabled( index == 4 );
+}
+
+
+void CReplaceDialog::findInputChanged( const TQString &text )
+{
+  mFindString[ mFindSelector->currentItem() ] = text;
+  mFindValidator->convert( mFindData,
+    mFindString[ mFindSelector->currentItem() ] );
+  enableButtonOK(!text.isEmpty());
+}
+
+
+void CReplaceDialog::replaceSelectorChanged( int index )
+{
+  mReplaceValidator->setState( (CHexValidator::EState)index );
+  mReplaceInput->setText( mReplaceString[ index ] );
+}
+
+
+void CReplaceDialog::replaceInputChanged( const TQString &text )
+{
+  mReplaceString[ mReplaceSelector->currentItem() ] = text;
+  mReplaceValidator->convert( mReplaceData,
+    mReplaceString[ mReplaceSelector->currentItem() ] );
+}
+
+
+void CReplaceDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  mFindInput->setFocus();
+}
+
+
+void CReplaceDialog::slotOk( void )
+{
+  if( mFindData.isEmpty() == true )
+  {
+    showEntryFailure( this, TQString("") );
+    return;
+  }
+
+  if( mFindData == mReplaceData )
+  {
+    showEntryFailure( this,i18n("Source and target values can not be equal."));
+    return;
+  }
+
+  hide();
+
+  SSearchControl sc;
+  sc.key = mFindData;
+  sc.val = mReplaceData;
+  sc.fromCursor = mCheckFromCursor->isChecked();
+  sc.inSelection = mCheckInSelection->isChecked();
+  sc.forward = mCheckBackward->isChecked() == true ? false : true;
+
+  sc.ignoreCase = mCheckIgnoreCase->isEnabled() && mCheckIgnoreCase->isChecked();
+
+  emit replaceData( sc, mCheckPrompt->isChecked() ? Replace_First: Replace_AllInit );
+}
+
+
+
+
+
+CReplacePromptDialog::CReplacePromptDialog( TQWidget *parent, const char *name,
+					     bool modal )
+  :KDialogBase( Plain, i18n("Find & Replace"), User3|User2|User1|Close,
+		User2, parent, name, modal, true, i18n("Replace &All"),
+		i18n("Do Not Replace"), i18n("Replace"))
+{
+  TQString text;
+  TQBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  topLayout->addSpacing( spacingHint() ); // A little bit extra space
+
+  text = i18n("Replace marked data at cursor position?");
+  TQLabel* label = new TQLabel( text, plainPage() );
+  topLayout->addWidget( label );
+
+  topLayout->addSpacing( spacingHint() ); // A little bit extra space
+  topLayout->addStretch(10);
+}
+
+
+CReplacePromptDialog::~CReplacePromptDialog( void )
+{
+}
+
+
+void CReplacePromptDialog::defineData( SSearchControl &sc )
+{
+  mSearchControl = sc;
+  mSearchControl.key.duplicate( sc.key );
+  mSearchControl.val.duplicate( sc.val );
+}
+
+
+void CReplacePromptDialog::slotUser3( void )
+{
+  done( repYes );
+}
+
+
+void CReplacePromptDialog::slotUser2( void )
+{
+  done( repNo );
+}
+
+
+void CReplacePromptDialog::slotUser1( void )
+{
+  done( repAll );
+}
+
+
+void CReplacePromptDialog::slotClose( void )
+{
+  done( repClose );
+}
+
+
+void CReplacePromptDialog::done( int returnCode )
+{
+  if( returnCode == repClose )
+  {
+    hide();
+  }
+  else if( returnCode == repYes )
+  {
+    emit replaceData( mSearchControl, Replace_Next );
+  }
+  else if( returnCode == repNo )
+  {
+    emit replaceData( mSearchControl, Replace_Ignore );
+  }
+  else
+  {
+    emit replaceData( mSearchControl, Replace_All );
+  }
+}
+
+
+
+
+CFilterDialog::CFilterDialog( TQWidget *parent, const char *name, bool modal )
+  :KDialogBase( Plain, i18n("Binary Filter"), Ok|Cancel, Ok,
+		parent, name, modal )
+{
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  TQVBoxLayout *vbox = new TQVBoxLayout();
+  if( vbox == 0 ) { return; }
+  topLayout->addLayout( vbox );
+
+
+  mOperationSelector = new TQComboBox( false, plainPage() );
+  if( mOperationSelector == 0 ) { return; }
+  mOperationSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mOperationSelector->insertStringList( operationStrings() );
+  connect( mOperationSelector, TQT_SIGNAL(activated(int)),
+	   TQT_SLOT(operationSelectorChanged(int)) );
+
+  text = i18n("O&peration:");
+  TQLabel *label = new TQLabel( mOperationSelector, text, plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mOperationSelector );
+
+  KSeparator *separator = new KSeparator( plainPage() );
+  separator->setOrientation( TQFrame::HLine );
+  vbox->addWidget( separator );
+
+
+  mWidgetStack = new TQWidgetStack( plainPage(), "pagestack" );
+  if( mWidgetStack == 0 ) { return; }
+  vbox->addWidget( mWidgetStack );
+
+  makeEmptyLayout();
+  makeOperandLayout();
+  makeBitSwapLayout();
+  makeRotateLayout();
+  mWidgetStack->raiseWidget( (int)OperandPage );
+
+
+  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
+  if( group == 0 ) { return; }
+  topLayout->addWidget( group, 10 );
+
+  TQGridLayout *gbox = new TQGridLayout( group, 4, 2, spacingHint() );
+  if( gbox == 0 ) { return; }
+  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
+  mCheckFromCursor = new TQCheckBox( i18n("&From cursor"), group );
+  gbox->addWidget( mCheckFromCursor, 1, 0 );
+  mCheckBackward = new TQCheckBox( i18n("&Backwards"), group );
+  gbox->addWidget( mCheckBackward, 1, 1 );
+  mCheckInSelection = new TQCheckBox( i18n("&In selection"), group );
+  gbox->addWidget( mCheckInSelection, 2, 0 );
+  mCheckVisible = new TQCheckBox( i18n("&Stay visible"), group );
+  gbox->addWidget( mCheckVisible, 2, 1 );
+  gbox->setRowStretch( 3, 10 );
+}
+
+
+CFilterDialog::~CFilterDialog( void )
+{
+  delete mOperandValidator;
+}
+
+
+void CFilterDialog::makeEmptyLayout( void )
+{
+  TQFrame *page = new TQFrame( plainPage() );
+  if( page == 0 ) { return; }
+  mWidgetStack->addWidget( page, EmptyPage );
+}
+
+
+void CFilterDialog::makeOperandLayout( void )
+{
+  TQString text;
+
+  TQFrame *page = new TQFrame( plainPage() );
+  if( page == 0 ) { return; }
+  mWidgetStack->addWidget( page, OperandPage );
+
+  TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, spacingHint() );
+  if( vbox == 0 ) { return; }
+
+  mOperandSelector = new TQComboBox( false, page );
+  if( mOperandSelector == 0 ) { return; }
+  mOperandSelector->setFixedHeight( mOperandSelector->sizeHint().height());
+  mOperandSelector->setMinimumWidth( fontMetrics().width("M")*20 );
+  mOperandSelector->insertStringList( formatStrings() );
+  connect( mOperandSelector, TQT_SIGNAL(activated(int)),
+	   TQT_SLOT(operandSelectorChanged(int)) );
+
+  text = i18n("Fo&rmat (operand):");
+  mOperandFormatLabel = new TQLabel( mOperandSelector, text, page );
+  if( mOperandFormatLabel == 0 ) { return; }
+
+  vbox->addWidget( mOperandFormatLabel );
+  vbox->addWidget( mOperandSelector );
+
+  mOperandInput = new TQLineEdit( page );
+  if( mOperandInput == 0 ) { return; }
+  mOperandInput->setMinimumWidth( fontMetrics().width("M") * 20 );
+  mOperandValidator = new CHexValidator( this, CHexValidator::regularText );
+  if( mOperandValidator == 0 ) { return; }
+  mOperandInput->setValidator( mOperandValidator );
+  connect( mOperandInput, TQT_SIGNAL(textChanged(const TQString&)),
+	   TQT_SLOT(operandInputChanged(const TQString&)) );
+
+  mOperandInputLabel = new TQLabel( mOperandInput, i18n("O&perand:"), page );
+  if( mOperandInputLabel == 0 ) { return; }
+
+  vbox->addWidget( mOperandInputLabel );
+  vbox->addWidget( mOperandInput  );
+  vbox->addSpacing( 1 );
+}
+
+
+void CFilterDialog::makeBitSwapLayout( void )
+{
+  TQString text;
+
+  TQFrame *page = new TQFrame( plainPage() );
+  if( page == 0 ) { return; }
+  mWidgetStack->addWidget( page, BitSwapPage );
+
+  TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, spacingHint() );
+  if( vbox == 0 ) { return; }
+
+  text = i18n("Swap rule");
+  TQLabel *label = new TQLabel( text, page );
+  if( label == 0 ) { return; }
+  label->setFixedHeight( label->sizeHint().height() );
+  vbox->addWidget( label );
+
+  mByteWidget = new CByteWidget( page );
+  vbox->addWidget( mByteWidget );
+
+  TQHBoxLayout *hbox = new TQHBoxLayout( 0 );
+  vbox->addLayout( hbox );
+
+  text = i18n("&Reset");
+  TQPushButton *resetButton = new TQPushButton( text, page );
+  resetButton->setFixedHeight( resetButton->sizeHint().height() );
+  connect( resetButton, TQT_SIGNAL(clicked()), mByteWidget, TQT_SLOT(reset()) );
+
+  hbox->addWidget( resetButton );
+  hbox->addStretch( 10 );
+}
+
+
+void CFilterDialog::makeRotateLayout( void )
+{
+  TQString text;
+
+  TQFrame *page = new TQFrame( plainPage() );
+  if( page == 0 ) { return; }
+  mWidgetStack->addWidget( page, RotatePage );
+
+  TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, spacingHint() );
+  if( vbox == 0 ) { return; }
+
+  mGroupSpin = new TQSpinBox( page );
+  if( mGroupSpin == 0 ) { return; }
+  mGroupSpin->setMinimumWidth( fontMetrics().width("M")*20 );
+  mGroupSpin->setRange(1, INT_MAX );
+
+  text = i18n("&Group size [bytes]");
+  TQLabel *label = new TQLabel( mGroupSpin, text, page );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mGroupSpin );
+
+  mBitSpin = new TQSpinBox( page );
+  if( mBitSpin == 0 ) { return; }
+  mBitSpin->setMinimumWidth( fontMetrics().width("M")*20 );
+  mBitSpin->setRange(INT_MIN, INT_MAX);
+
+  text = i18n("S&hift size [bits]");
+  label = new TQLabel( mBitSpin, text, page );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mBitSpin );
+}
+
+
+
+void CFilterDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  mOperandInput->setFocus();
+}
+
+
+
+void CFilterDialog::slotOk( void )
+{
+  SFilterControl fc;
+  switch( mOperationSelector->currentItem() )
+  {
+    case SFilterControl::OperandAndData:
+    case SFilterControl::OperandOrData:
+    case SFilterControl::OperandXorData:
+      if( mOperandData.isEmpty() == true )
+      {
+	showEntryFailure( this, TQString("") );
+	return;
+      }
+      fc.operand = mOperandData;
+    break;
+
+    case SFilterControl::InvertData:
+    case SFilterControl::ReverseData:
+    break;
+
+    case SFilterControl::RotateData:
+    case SFilterControl::ShiftData:
+      fc.rotate[0] = mGroupSpin->value();
+      fc.rotate[1] = mBitSpin->value();
+      if( fc.rotate[1] == 0 )
+      {
+	TQString msg = i18n("Shift size is zero.");
+	showEntryFailure( this, msg );
+	return;
+      }
+    break;
+
+    case SFilterControl::SwapBits:
+      if( mByteWidget->flag( fc.operand ) == false )
+      {
+	TQString msg = i18n("Swap rule does not define any swapping.");
+	showEntryFailure( this, msg );
+	return;
+      }
+    break;
+
+    default:
+      return;
+    break;
+
+  }
+
+  if( mCheckVisible->isChecked() == false )
+  {
+    hide();
+  }
+
+  fc.operation = (SFilterControl::Operation)mOperationSelector->currentItem();
+  fc.fromCursor = mCheckFromCursor->isChecked();
+  fc.inSelection = mCheckInSelection->isChecked();
+  if( mCheckBackward->isEnabled() == true )
+  {
+    fc.forward = mCheckBackward->isChecked() == true ? false : true;
+  }
+  else
+  {
+    fc.forward = true;
+  }
+
+  emit filterData( fc );
+}
+
+
+void CFilterDialog::operandSelectorChanged( int index )
+{
+  mOperandValidator->setState( (CHexValidator::EState)index );
+  mOperandInput->setText( mOperandString[ index ] );
+}
+
+
+void CFilterDialog::operandInputChanged( const TQString &text )
+{
+  mOperandString[ mOperandSelector->currentItem() ] = text;
+  mOperandValidator->convert( mOperandData,
+    mOperandString[ mOperandSelector->currentItem() ] );
+}
+
+
+void CFilterDialog::operationSelectorChanged( int index )
+{
+  if( index <= 2 )
+  {
+    mWidgetStack->raiseWidget( OperandPage );
+    mCheckBackward->setEnabled( true );
+  }
+  else if( index <= 4 )
+  {
+    mWidgetStack->raiseWidget( EmptyPage );
+    mCheckBackward->setEnabled( true );
+  }
+  else if( index <= 6 )
+  {
+    mWidgetStack->raiseWidget( RotatePage );
+    mCheckBackward->setEnabled( false );
+  }
+  else
+  {
+    mWidgetStack->raiseWidget( BitSwapPage );
+    mCheckBackward->setEnabled( true );
+  }
+}
+
+
+
+
+CInsertDialog::CInsertDialog( TQWidget *parent, const char *name, bool modal )
+  :KDialogBase( Plain, i18n("Insert Pattern"), Ok|Cancel, Ok,
+		parent, name, modal )
+{
+  setButtonOKText(i18n("&Insert"));
+
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+  TQVBoxLayout *vbox = new TQVBoxLayout();
+  if( vbox == 0 ) { return; }
+  topLayout->addLayout( vbox );
+
+  mSizeBox = new TQSpinBox( plainPage() );
+  if( mSizeBox == 0 ) { return; }
+  mSizeBox->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mSizeBox->setRange( 1, INT_MAX );
+  mSizeBox->setValue( 1 );
+
+  TQLabel *label = new TQLabel( mSizeBox, i18n("&Size:"), plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mSizeBox );
+
+  mPatternSelector = new TQComboBox( false, plainPage() );
+  if( mPatternSelector == 0 ) { return; }
+  mPatternSelector->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mPatternSelector->insertStringList( formatStrings() );
+  connect( mPatternSelector, TQT_SIGNAL(activated(int)),
+	   TQT_SLOT(patternSelectorChanged(int)) );
+
+  text = i18n("Fo&rmat (pattern):");
+  label = new TQLabel( mPatternSelector, text, plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mPatternSelector );
+
+  mPatternInput = new TQLineEdit( plainPage() );
+  if( mPatternInput == 0 ) { return; }
+  mPatternInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mPatternValidator = new CHexValidator( this, CHexValidator::regularText );
+  if( mPatternValidator == 0 ) { return; }
+  mPatternInput->setValidator( mPatternValidator );
+  connect( mPatternInput, TQT_SIGNAL(textChanged(const TQString&)),
+	   TQT_SLOT(patternInputChanged(const TQString&)) );
+
+  label = new TQLabel( mPatternInput, i18n("&Pattern:"), plainPage() );
+  if( label == 0 ) { return; }
+
+  vbox->addWidget( label );
+  vbox->addWidget( mPatternInput );
+
+  mOffsetInput = new TQLineEdit( plainPage() );
+  mOffsetInput->setMinimumWidth( fontMetrics().maxWidth()*17 );
+
+  mOffsetLabel = new TQLabel( mOffsetInput, i18n("&Offset:"), plainPage() );
+  if( mOffsetLabel == 0 ) { return; }
+
+  vbox->addWidget( mOffsetLabel );
+  vbox->addWidget( mOffsetInput );
+
+  TQButtonGroup *group = new TQButtonGroup( i18n("Options"), plainPage() );
+  if( group == 0 ) { return; }
+  topLayout->addWidget( group, 10 );
+
+
+  TQGridLayout *gbox = new TQGridLayout( group, 4, 2, spacingHint() );
+  if( gbox == 0 ) { return; }
+  gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
+
+  mCheckPattern = new TQCheckBox( i18n("R&epeat pattern"), group );
+  gbox->addWidget( mCheckPattern, 1, 0 );
+  mCheckOnCursor = new TQCheckBox( i18n("&Insert on cursor position"), group );
+  gbox->addWidget( mCheckOnCursor, 2, 0 );
+  connect( mCheckOnCursor, TQT_SIGNAL(clicked()), TQT_SLOT(cursorCheck()) );
+  gbox->setRowStretch( 3, 10 );
+
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Insert Pattern Dialog");
+  mCheckPattern->setChecked( config.readBoolEntry( "RepeatPattern", false ) );
+  mCheckOnCursor->setChecked( config.readBoolEntry( "InsertOnCursor", false) );
+  cursorCheck();
+  uint val = config.readUnsignedNumEntry( "Format", 0 );
+  mPatternSelector->setCurrentItem( TQMIN(4,val) );
+  patternSelectorChanged( mPatternSelector->currentItem() );
+}
+
+
+CInsertDialog::~CInsertDialog( void )
+{
+  TDEConfig &config = *kapp->config();
+  config.setGroup("Insert Pattern Dialog");
+  config.writeEntry( "RepeatPattern", mCheckPattern->isChecked() );
+  config.writeEntry( "InsertOnCursor", mCheckOnCursor->isChecked() );
+  config.writeEntry( "Format", mPatternSelector->currentItem() );
+  config.sync();
+}
+
+
+void CInsertDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  mPatternInput->setFocus();
+}
+
+
+void CInsertDialog::patternSelectorChanged( int index )
+{
+  mPatternValidator->setState( (CHexValidator::EState)index );
+  mPatternInput->setText( mPatternString[ index ] );
+}
+
+
+void CInsertDialog::patternInputChanged( const TQString &text )
+{
+  mPatternString[ mPatternSelector->currentItem() ] = text;
+  mPatternValidator->convert( mPatternData,
+    mPatternString[ mPatternSelector->currentItem() ] );
+}
+
+
+void CInsertDialog::slotOk( void )
+{
+  if( mPatternData.isEmpty() == true )
+  {
+    showEntryFailure( this, TQString("") );
+    return;
+  }
+
+  SInsertData id;
+  id.size = mSizeBox->value();
+  id.repeatPattern = mCheckPattern->isChecked();
+  id.onCursor = mCheckOnCursor->isChecked();
+  id.pattern = mPatternData;
+
+  if( id.onCursor == false )
+  {
+    bool success = stringToOffset( mOffsetInput->text(), id.offset );
+    if( success == false )
+    {
+      showEntryFailure( this, TQString("") );
+      return;
+    }
+  }
+
+  hide();
+  execute( id );
+}
+
+
+void CInsertDialog::cursorCheck( void )
+{
+  bool state = mCheckOnCursor->isChecked() == true ? false : true;
+  mOffsetLabel->setEnabled( state );
+  mOffsetInput->setEnabled( state );
+}
+
+
+
+
+void centerDialog( TQWidget *widget, TQWidget *centerParent )
+{
+  if( centerParent == 0 || widget == 0 )
+  {
+    return;
+  }
+
+  TQPoint point = centerParent->mapToGlobal( TQPoint(0,0) );
+  TQRect pos    = centerParent->geometry();
+
+  widget->setGeometry( point.x() + pos.width()/2  - widget->width()/2,
+		       point.y() + pos.height()/2 - widget->height()/2,
+		       widget->width(), widget->height() );
+}
+
+
+void centerDialogBottom( TQWidget *widget, TQWidget *centerParent )
+{
+  if( centerParent == 0 || widget == 0 )
+  {
+    return;
+  }
+
+  TQPoint point = centerParent->mapToGlobal( TQPoint(0,0) );
+  TQRect pos    = centerParent->geometry();
+
+  widget->setGeometry( point.x() + pos.width()/2  - widget->width()/2,
+		       point.y() + pos.height() - widget->height(),
+		       widget->width(), widget->height() );
+}
+
+
+void comboMatchText( TQComboBox *combo, const TQString &text )
+{
+  for( int i=0; i < combo->count(); i++ )
+  {
+    if( combo->text(i) == text )
+    {
+      combo->setCurrentItem(i);
+      return;
+    }
+  }
+  combo->setCurrentItem(0);
+}
+
+
+
+
+
+void showEntryFailure( TQWidget *parent, const TQString &msg )
+{
+  TQString message;
+  message += i18n("Your request can not be processed.");
+  message += "\n";
+  if( msg.isNull() == true || msg.isEmpty() == true )
+  {
+    message += i18n("Examine argument(s) and try again.");
+  }
+  else
+  {
+    message += msg;
+  }
+  KMessageBox::sorry( parent, message, i18n("Invalid argument(s)") );
+}
+
+
+bool verifyFileDestnation( TQWidget *parent, const TQString &title,
+			   const TQString &path )
+{
+  if( path.isEmpty() == true )
+  {
+    TQString msg = i18n("You must specify a destination file.");
+    KMessageBox::sorry( parent, msg, title );
+    return( false );
+  }
+
+  TQFileInfo info( path );
+  if( info.exists() == true )
+  {
+    if( info.isDir() == true )
+    {
+      TQString msg = i18n("You have specified an existing folder.");
+      KMessageBox::sorry( parent, msg, title );
+      return( false );
+    }
+
+    if( info.isWritable() == false )
+    {
+      TQString msg = i18n("You do not have write permission to this file.");
+      KMessageBox::sorry( parent, msg, title );
+      return( false );
+    }
+
+    TQString msg = i18n( ""
+      "You have specified an existing file.\n"
+      "Overwrite current file?" );
+    int reply = KMessageBox::warningContinueCancel( parent, msg, title, i18n("Overwrite") );
+    if( reply != KMessageBox::Continue )
+    {
+      return( false );
+    }
+  }
+
+  return( true );
+}
+
+
+
+bool stringToOffset( const TQString & text, uint &offset )
+{
+  if( text.isEmpty() )
+  {
+    return( false );
+  }
+
+  const char * p = text.ascii(); // ####: Is this correct?
+
+  //
+  // Skip any whitespaces in front of string
+  //
+  for( ; *p != 0 && isspace( *p ) ; p++ );
+
+  int match = 0;
+  bool space = false;
+  if( strncmp( p, "0x", 2 ) == 0 || strncmp( p, "0X", 2 ) == 0 )
+  {
+    for( const char *q = p+2; *q != 0; q++ )
+    {
+      if( isxdigit( *q ) == 0 || space == true )
+      {
+	if( isspace( *q ) == 0 )
+	{
+	  return( false );
+	}
+	space = true;
+      }
+    }
+    match = sscanf( p+2, "%x", &offset );
+  }
+  else
+  {
+    for( const char *q = p; *q != 0; q++ )
+    {
+      if( isdigit( *q ) == 0 || space == true )
+      {
+	if( isspace( *q ) == 0 )
+	{
+	  return( false );
+	}
+	space = true;
+      }
+    }
+    match = sscanf( p, "%u", &offset );
+  }
+
+  if( match == 0 )
+  {
+    return( false );
+  }
+
+  return( true );
+}
+
+
+static const TQStringList &formatStrings( void )
+{
+  static TQStringList list;
+  if( list.isEmpty() == true )
+  {
+    list.append( i18n( "Hexadecimal" ) );
+    list.append( i18n( "Decimal" ) );
+    list.append( i18n( "Octal" ) );
+    list.append( i18n( "Binary" ) );
+    list.append( i18n( "Regular Text" ) );
+  }
+  return( list );
+}
+
+
+static const TQStringList &operationStrings( void )
+{
+  static TQStringList list;
+  if( list.isEmpty() == true )
+  {
+    list.append( i18n( "operand AND data" ) );
+    list.append( i18n( "operand OR data" ) );
+    list.append( i18n( "operand XOR data" ) );
+    list.append( i18n( "INVERT data" ) );
+    list.append( i18n( "REVERSE data" ) );
+    list.append( i18n( "ROTATE data" ) );
+    list.append( i18n( "SHIFT data" ) );
+    list.append( i18n( "Swap Individual Bits" ) );
+  }
+
+  return( list );
+}
+
+
+
+
+
+#include "dialog.moc"
diff --git a/khexedit/draglabel.cc b/khexedit/draglabel.cc
deleted file mode 100644
index dfca9a63..00000000
--- a/khexedit/draglabel.cc
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <stdlib.h>
-
-#include <tqbitmap.h>
-#include <tqpainter.h>
-
-#include <kurldrag.h>
-
-#include "draglabel.h"
-
-
-CDragLabel::CDragLabel( TQWidget *parent )
-  : TQLabel( "draglabel", parent, "tde toolbar widget" )
-{
-  mValid = true;
-  mDragPending = false;
-  setBackgroundMode( TQt::PaletteButton );
-}
-
-
-CDragLabel::~CDragLabel( void )
-{
-}
-
-
-void CDragLabel::mousePressEvent( TQMouseEvent *e )
-{
-  if( mValid == false || e->button() != Qt::LeftButton || mUrl.isEmpty() == true )
-  {
-    return;
-  }
-
-  mDragOrigin = e->pos();
-  mDragPending = true;
-}
-
-
-void CDragLabel::mouseMoveEvent( TQMouseEvent *e )
-{
-  if( mDragPending == true )
-  {
-    if( abs(e->x() - mDragOrigin.x()) + abs(e->y() - mDragOrigin.y()) > 5 )
-    {
-      mDragPending = false;
-
-      //
-      // Make drag object, assign pixmap and grab keyboard. The grabbing
-      // will allow ESC to abort the drag
-      //
-      KURL::List uris;
-      uris.append(KURL(mUrl));
-      KURLDrag *uriDrag = new KURLDrag( uris, this );
-      if( uriDrag == 0 ) { return; }
-      prepPixmap( *uriDrag );
-      grabKeyboard();
-      uriDrag->drag();
-      releaseKeyboard();
-    }
-  }
-}
-
-void CDragLabel::mouseReleaseEvent( TQMouseEvent * )
-{
-  mDragPending = false;
-}
-
-
-void CDragLabel::setUrl( const TQString &url )
-{
-  mUrl = url;
-}
-
-
-void CDragLabel::setDragMask( const TQPixmap pix )
-{
-  mDragMask = pix;
-}
-
-
-void CDragLabel::prepPixmap( KURLDrag &uriDrag )
-{
-  if( pixmap() == 0 )
-  {
-    return;
-  }
-
-  TQString text;
-  int index = mUrl.findRev( '/', mUrl.length() );
-  if( index < 0 )
-  {
-    text = mUrl;
-  }
-  else
-  {
-    text = mUrl.right( mUrl.length() - index - 1 );
-  }
-
-  int sep = 2;
-  TQRect rect = fontMetrics().boundingRect(text);
-  int w = pixmap()->width() + rect.width() + sep + 2;
-  int h = fontMetrics().lineSpacing();
-  if( pixmap()->height() > h ) { h = pixmap()->height(); }
-
-  TQBitmap mask( w, h, TRUE );
-  TQPixmap dragPixmap( w, h );
-  dragPixmap.fill( black );
-
-  TQPainter p;
-  p.begin( &mask );
-  p.setPen( white );
-  p.drawPixmap( 0, 0, mDragMask );
-  p.drawText( pixmap()->width()+sep, 0, w-pixmap()->width()+sep,
-	      h, AlignVCenter|AlignLeft, text );
-  p.end();
-
-  p.begin( &dragPixmap );
-  p.drawPixmap( 0, 0, *pixmap() );
-  p.end();
-
-  dragPixmap.setMask( mask );
-
-  TQPoint hotspot( pixmap()->width(), pixmap()->height()/2 );
-  uriDrag.setPixmap( dragPixmap, hotspot );
-}
-
-
-
-
-
-#include "draglabel.moc"
diff --git a/khexedit/draglabel.cpp b/khexedit/draglabel.cpp
new file mode 100644
index 00000000..dfca9a63
--- /dev/null
+++ b/khexedit/draglabel.cpp
@@ -0,0 +1,149 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <stdlib.h>
+
+#include <tqbitmap.h>
+#include <tqpainter.h>
+
+#include <kurldrag.h>
+
+#include "draglabel.h"
+
+
+CDragLabel::CDragLabel( TQWidget *parent )
+  : TQLabel( "draglabel", parent, "tde toolbar widget" )
+{
+  mValid = true;
+  mDragPending = false;
+  setBackgroundMode( TQt::PaletteButton );
+}
+
+
+CDragLabel::~CDragLabel( void )
+{
+}
+
+
+void CDragLabel::mousePressEvent( TQMouseEvent *e )
+{
+  if( mValid == false || e->button() != Qt::LeftButton || mUrl.isEmpty() == true )
+  {
+    return;
+  }
+
+  mDragOrigin = e->pos();
+  mDragPending = true;
+}
+
+
+void CDragLabel::mouseMoveEvent( TQMouseEvent *e )
+{
+  if( mDragPending == true )
+  {
+    if( abs(e->x() - mDragOrigin.x()) + abs(e->y() - mDragOrigin.y()) > 5 )
+    {
+      mDragPending = false;
+
+      //
+      // Make drag object, assign pixmap and grab keyboard. The grabbing
+      // will allow ESC to abort the drag
+      //
+      KURL::List uris;
+      uris.append(KURL(mUrl));
+      KURLDrag *uriDrag = new KURLDrag( uris, this );
+      if( uriDrag == 0 ) { return; }
+      prepPixmap( *uriDrag );
+      grabKeyboard();
+      uriDrag->drag();
+      releaseKeyboard();
+    }
+  }
+}
+
+void CDragLabel::mouseReleaseEvent( TQMouseEvent * )
+{
+  mDragPending = false;
+}
+
+
+void CDragLabel::setUrl( const TQString &url )
+{
+  mUrl = url;
+}
+
+
+void CDragLabel::setDragMask( const TQPixmap pix )
+{
+  mDragMask = pix;
+}
+
+
+void CDragLabel::prepPixmap( KURLDrag &uriDrag )
+{
+  if( pixmap() == 0 )
+  {
+    return;
+  }
+
+  TQString text;
+  int index = mUrl.findRev( '/', mUrl.length() );
+  if( index < 0 )
+  {
+    text = mUrl;
+  }
+  else
+  {
+    text = mUrl.right( mUrl.length() - index - 1 );
+  }
+
+  int sep = 2;
+  TQRect rect = fontMetrics().boundingRect(text);
+  int w = pixmap()->width() + rect.width() + sep + 2;
+  int h = fontMetrics().lineSpacing();
+  if( pixmap()->height() > h ) { h = pixmap()->height(); }
+
+  TQBitmap mask( w, h, TRUE );
+  TQPixmap dragPixmap( w, h );
+  dragPixmap.fill( black );
+
+  TQPainter p;
+  p.begin( &mask );
+  p.setPen( white );
+  p.drawPixmap( 0, 0, mDragMask );
+  p.drawText( pixmap()->width()+sep, 0, w-pixmap()->width()+sep,
+	      h, AlignVCenter|AlignLeft, text );
+  p.end();
+
+  p.begin( &dragPixmap );
+  p.drawPixmap( 0, 0, *pixmap() );
+  p.end();
+
+  dragPixmap.setMask( mask );
+
+  TQPoint hotspot( pixmap()->width(), pixmap()->height()/2 );
+  uriDrag.setPixmap( dragPixmap, hotspot );
+}
+
+
+
+
+
+#include "draglabel.moc"
diff --git a/khexedit/exportdialog.cc b/khexedit/exportdialog.cc
deleted file mode 100644
index 2cdfae7c..00000000
--- a/khexedit/exportdialog.cc
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <limits.h>
-#include <tqbuttongroup.h>
-#include <tqlineedit.h> 
-
-#include <tdefiledialog.h>
-#include <tdelocale.h>
-#include <tdemessagebox.h>
-
-#include "dialog.h"
-#include "exportdialog.h"
-#include <tqpushbutton.h>
-
-
-CExportDialog::CExportDialog( TQWidget *parent, char *name, bool modal )
-  :KDialogBase( Tabbed, i18n("Export Document"), Help|Ok|Cancel, Ok,
-		parent, name,  modal )
-{
-  setHelp( "khexedit/khexedit.html", TQString() );
-
-  mFrame[ page_destination ] = addPage( i18n("Destination") );
-  mFrame[ page_option ] = addPage( i18n("Options") );
-
-  setupDestinationPage();
-  setupOptionPage();
- 
-  mConfig = 0;
-  readConfiguration();
-
-  TQString path = mDestination.fileInput->text();
-  int index = path.findRev( '/' );
-  if( index != -1 ) { mWorkDir = path.left( index+1 ); }
-}
-
-
-CExportDialog::~CExportDialog( void )
-{
-  writeConfiguration();
-  delete mConfig; mConfig = 0;
-}
-
-
-void CExportDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  showPage(0);
-  mDestination.fileInput->setFocus();
-}
-
-
-void CExportDialog::readConfiguration( void )
-{
-  if( mConfig != 0 ) { return; }
-
-  mConfig = new KSimpleConfig( TQString("hexexport") );
-  if( mConfig == 0 ) { return; }
-
-  mConfig->setGroup( "Destination" );
-
-  int val = mConfig->readNumEntry( "Format", 0 );
-  mDestination.formatCombo->setCurrentItem( val );
-  formatChanged( val < 0 || val > option_html ? 0 : val );
-
-  mConfig->setGroup( "Option" );
-  val = mConfig->readNumEntry( "HtmlLine", 80 );
-  mHtml.lineSpin->setValue( val );
-  TQString text = mConfig->readEntry( "HtmlPrefix", "table" );
-  mHtml.prefixInput->setText( text );
-  val = mConfig->readNumEntry( "HtmlHeader", 1 );
-  mHtml.topCombo->setCurrentItem( val < 0 || val >= 4 ? 0 : val );
-  val = mConfig->readNumEntry( "HtmlFooter", 3 );
-  mHtml.bottomCombo->setCurrentItem( val < 0 || val >= 4 ? 0 : val );
-
-  bool state = mConfig->readBoolEntry( "HtmlSymlink", true );
-  mHtml.symlinkCheck->setChecked( state );  
-  state = mConfig->readBoolEntry( "HtmlNavigatorBar", true );
-  mHtml.navigatorCheck->setChecked( state );
-  state = mConfig->readBoolEntry( "HtmlBlackWhite", false );
-  mHtml.bwCheck->setChecked( state );
-
-  text = mConfig->readEntry( "ArrayName", "buffer" );
-  mArray.nameInput->setText( text );
-  text = mConfig->readEntry( "ArrayElementType", "char" );
-  for( int i=0; i < mArray.typeCombo->count(); i++ )
-  { 
-    if( mArray.typeCombo->text(i) == text )
-    {
-      mArray.typeCombo->setCurrentItem(i);
-      break;
-    }
-  }
-  val = mConfig->readNumEntry( "ArrayElementPerLine", 20 );
-  val = TQMAX( val, mArray.lineSizeSpin->minValue() );  
-  val = TQMIN( val, mArray.lineSizeSpin->maxValue() );
-  mArray.lineSizeSpin->setValue( val );
-  state = mConfig->readBoolEntry( "ArrayUnsignedAsHex", true );
-  mArray.hexadecimalCheck->setChecked( state );
-}
-
-
-void CExportDialog::writeConfiguration( void )
-{
-  if( mConfig == 0 )
-  {
-    return;
-  }
-
-  mConfig->setGroup( "Destination" );
-  mConfig->writeEntry( "Format", mDestination.formatCombo->currentItem() );
-
-  mConfig->setGroup( "Option" );
-  mConfig->writeEntry( "HtmlLine", mHtml.lineSpin->value() );
-  mConfig->writeEntry( "HtmlPrefix", mHtml.prefixInput->text() );
-  mConfig->writeEntry( "HtmlHeader", mHtml.topCombo->currentItem() );
-  mConfig->writeEntry( "HtmlFooter", mHtml.bottomCombo->currentItem() );
-  mConfig->writeEntry( "HtmlSymlink", mHtml.symlinkCheck->isChecked());
-  mConfig->writeEntry( "HtmlNavigatorBar",mHtml.navigatorCheck->isChecked());
-  mConfig->writeEntry( "HtmlBlackWhite", mHtml.bwCheck->isChecked() );
-
-
-  mConfig->writeEntry( "ArrayName", mArray.nameInput->text() );
-  mConfig->writeEntry( "ArrayElementType", mArray.typeCombo->currentText() );
-  mConfig->writeEntry( "ArrayElementPerLine", mArray.lineSizeSpin->value() );
-  mConfig->writeEntry( "ArrayUnsignedAsHex", 
-		       mArray.hexadecimalCheck->isChecked() );
-  mConfig->sync();
-}
-
-
-void CExportDialog::setupDestinationPage( void )
-{
-  TQString text;
-  TQFrame *page = mFrame[ page_destination ];
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
-  if( topLayout == 0 ) { return; }
-
-  TQStringList formatList;
-  formatList.append( i18n("Plain Text") );
-  formatList.append( i18n("HTML Tables") );
-  formatList.append( i18n("Rich Text (RTF)") );
-  formatList.append( i18n("C Array") );
-
-  mDestination.formatCombo = new TQComboBox( false, page );
-  mDestination.formatCombo->insertStringList( formatList );
-  mDestination.formatCombo->setMinimumWidth( fontMetrics().maxWidth()*10 );
-  connect( mDestination.formatCombo, TQT_SIGNAL(activated(int)),
-	   TQT_SLOT(formatChanged(int)) );
-
-  text = i18n("&Format:");
-  TQLabel *label = new TQLabel( mDestination.formatCombo, text, page );
-  topLayout->addWidget( label );
-  topLayout->addWidget( mDestination.formatCombo );
-
-  TQHBoxLayout *hbox = new TQHBoxLayout();
-  topLayout->addLayout( hbox );
-
-  text = i18n("&Destination:");
-  label = new TQLabel( text, page );
-  hbox->addWidget( label );
- 
-  text = i18n("(Package folder)"); 
-  mDestination.fileExtraLabel = new TQLabel( text, page );
-  hbox->addWidget( mDestination.fileExtraLabel, 10, AlignLeft|AlignVCenter );
-
-  hbox = new TQHBoxLayout();
-  topLayout->addLayout( hbox );
-
-  mDestination.fileInput = new TQLineEdit( page );
-  hbox->addWidget( mDestination.fileInput );
-  connect(mDestination.fileInput, TQT_SIGNAL(textChanged ( const TQString & )),this,TQT_SLOT(destinationChanged(const TQString &)));
-  text = i18n("Choose...");
-  TQPushButton *browseButton = new TQPushButton( text, page, "browse" );
-  hbox->addWidget( browseButton );
-  connect( browseButton, TQT_SIGNAL(clicked()), TQT_SLOT(browserClicked()) );
-  mDestination.fileInput->setMinimumWidth( fontMetrics().maxWidth()*15 );
-
-  label->setBuddy(mDestination.fileInput);
-
-  hbox = new TQHBoxLayout();
-  topLayout->addLayout( hbox, 10 );
-
-  mDestination.rangeBox = new TQButtonGroup( i18n("Export Range"), page );
-  hbox->addWidget( mDestination.rangeBox );
-
-  TQButtonGroup *group = mDestination.rangeBox; // convenience
-
-  TQVBoxLayout *vbox = new TQVBoxLayout( group, spacingHint() );  
-  vbox->addSpacing( fontMetrics().lineSpacing() );
-  
-  TQRadioButton *radio1 = new TQRadioButton( i18n("&Everything"), group );
-  radio1->setFixedSize( radio1->sizeHint() );
-  mDestination.rangeBox->insert( radio1, 0 );
-  vbox->addWidget( radio1, 0, AlignLeft );
-
-  TQRadioButton *radio2 = new TQRadioButton( i18n("&Selection"), group );
-  radio2->setFixedSize( radio2->sizeHint() );
-  mDestination.rangeBox->insert( radio2, 1 );
-  vbox->addWidget( radio2, 0, AlignLeft );
-
-  TQRadioButton *radio3 = new TQRadioButton( i18n("&Range"), group );
-  radio3->setFixedSize( radio3->sizeHint() );
-  mDestination.rangeBox->insert( radio3, 2 );
-  vbox->addWidget( radio3, 0, AlignLeft );
-
-  TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
-  vbox->addLayout( gbox );
-
-  mDestination.fromInput = new TQLineEdit( group );
-  text = i18n("&From offset:");
-  mDestination.fromLabel = new TQLabel( mDestination.fromInput, text, group );
-  gbox->addWidget( mDestination.fromLabel, 0, 0 );
-  gbox->addWidget( mDestination.fromInput, 0, 1 );
-
-  mDestination.toInput = new TQLineEdit( group );
-  text = i18n("&To offset:");
-  mDestination.toLabel = new TQLabel( mDestination.toInput, text, group );
-  gbox->addWidget( mDestination.toLabel, 1, 0 );
-  gbox->addWidget( mDestination.toInput, 1, 1 );
-
-  connect( group, TQT_SIGNAL(clicked(int)), TQT_SLOT(rangeChanged(int)) );
-  group->setButton(0);
-  rangeChanged(0);
-  enableButtonOK( !mDestination.fileInput->text().isEmpty() );
-}
-
-void CExportDialog::destinationChanged(const TQString &_text)
-{
-  enableButtonOK( !_text.isEmpty() );
-}
-
-void CExportDialog::setupOptionPage( void )
-{
-  TQFrame *page = mFrame[ page_option ];
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
-  if( topLayout == 0 ) { return; }
-
-  mOptionStack = new TQWidgetStack( page, "stack" );
-  if( mOptionStack == 0 ) { return; }
-  topLayout->addWidget( mOptionStack );
-
-  makeTextOption();
-  makeHtmlOption();
-  makeRtfOption();
-  makeCArrayOption();
-  mOptionStack->raiseWidget( (int)option_text );
-
-  TQSize size = mOptionStack->sizeHint();
-  size += TQSize(spacingHint()*2, spacingHint()*2);
-  page->setMinimumSize( size ); 
-}
-
-
-void CExportDialog::makeTextOption( void )
-{
-  TQFrame *page = new TQFrame( mFrame[ page_option ] );
-  if( page == 0 ) { return; }
-  mOptionStack->addWidget( page, option_text );
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
-  TQString text = i18n("No options for this format.");
-  TQLabel *label = new TQLabel( text, page );
-  topLayout->addWidget( label, 0, AlignCenter );
-}
-
-
-void CExportDialog::makeHtmlOption( void )
-{
-  TQFrame *page = new TQFrame( mFrame[ page_option ] );
-  if( page == 0 ) { return; }
-  mOptionStack->addWidget( page, option_html );
-
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
-  if( topLayout == 0 ) { return; }
-
-  text = i18n("HTML Options (one table per page)");
-  TQLabel *label = new TQLabel( text, page );
-  topLayout->addWidget( label );
-
-  TQFrame *hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  topLayout->addWidget( hline );
-
-  TQFrame *frame = new TQFrame( page );
-  if( frame == 0 ) { return; }  
-  topLayout->addWidget( frame );
-
-  TQGridLayout *gbox = new TQGridLayout( frame, 4, 2, 0, spacingHint() );
-  if( gbox == 0 ) { return; }
-  gbox->setColStretch( 1, 10 );  
-
-  mHtml.lineSpin = new TQSpinBox( frame );
-  mHtml.lineSpin->setMinimumWidth( fontMetrics().maxWidth()*10 );
-  mHtml.lineSpin->setRange( 5, INT_MAX );
-  gbox->addWidget( mHtml.lineSpin, 0, 1 );
-  
-  text = i18n("&Lines per table:");
-  label = new TQLabel( mHtml.lineSpin, text, frame );
-  gbox->addWidget( label, 0, 0 );
-
-  mHtml.prefixInput = new TQLineEdit( frame, "prefix" );
-  mHtml.prefixInput->setMinimumWidth( fontMetrics().maxWidth()*10 );
-  gbox->addWidget( mHtml.prefixInput, 1, 1 );
-
-  text = i18n("Filename &prefix (in package):");
-  label = new TQLabel( mHtml.prefixInput, text, frame );
-  gbox->addWidget( label, 1, 0 );
-
-  TQStringList headerList;
-  headerList.append( i18n("None") );
-  headerList.append( i18n("Filename with Path") );
-  headerList.append( i18n("Filename") );
-  headerList.append( i18n("Page Number") );
-
-  mHtml.topCombo = new TQComboBox( false, frame );
-  mHtml.topCombo->insertStringList( headerList );
-  gbox->addWidget( mHtml.topCombo, 2, 1 );
-
-  text = i18n("Header &above text:");
-  label = new TQLabel( mHtml.topCombo, text, frame );
-  gbox->addWidget( label, 2, 0 );
-
-  mHtml.bottomCombo = new TQComboBox( false, frame );
-  mHtml.bottomCombo->insertStringList( headerList );
-  gbox->addWidget( mHtml.bottomCombo, 3, 1 );
-
-  text = i18n("&Footer below text:");
-  label = new TQLabel( mHtml.bottomCombo, text, frame );
-  gbox->addWidget( label, 3, 0 );
-
-  text = i18n("Link \"index.html\" to &table of contents file");
-  mHtml.symlinkCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mHtml.symlinkCheck );
-
-  text = i18n("&Include navigator bar");
-  mHtml.navigatorCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mHtml.navigatorCheck );
-
-  text = i18n("&Use black and white only");
-  mHtml.bwCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mHtml.bwCheck );
-
-  topLayout->addStretch(10);
-}
-
-
-void CExportDialog::makeRtfOption( void )
-{
-  TQFrame *page = new TQFrame( mFrame[ page_option ] );
-  if( page == 0 ) { return; }
-  mOptionStack->addWidget( page, option_rtf );
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
-  TQString text = i18n("No options for this format.");
-  TQLabel *label = new TQLabel( text, page );
-  topLayout->addWidget( label, 0, AlignCenter );
-}
-
-
-void CExportDialog::makeCArrayOption( void )
-{
-  TQFrame *page = new TQFrame( mFrame[ page_option ] );
-  mOptionStack->addWidget( page, option_carray );
-
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
-
-  text = i18n("C Array Options");
-  TQLabel *label = new TQLabel( text, page );
-  topLayout->addWidget( label, 0, AlignLeft );
-
-  TQFrame *hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  topLayout->addWidget( hline );
-
-  TQGridLayout *gbox = new TQGridLayout( 3, 2, spacingHint() );
-  topLayout->addLayout( gbox );
-  gbox->setColStretch( 1, 10 );
-
-  mArray.nameInput = new TQLineEdit( page );
-  gbox->addWidget( mArray.nameInput, 0, 1 );
-  text = i18n("Array name:"); 
-  label = new TQLabel( mArray.nameInput, text, page );
-  gbox->addWidget( label, 0, 0 );
-
-  TQStringList typeList;
-  typeList.append( i18n("char") );
-  typeList.append( i18n("unsigned char") );
-  typeList.append( i18n("short") );
-  typeList.append( i18n("unsigned short") );
-  typeList.append( i18n("int") );
-  typeList.append( i18n("unsigned int") );
-  typeList.append( i18n("float") );
-  typeList.append( i18n("double") );
-  mArray.typeCombo = new TQComboBox( false, page );
-  mArray.typeCombo->insertStringList( typeList );
-  mArray.typeCombo->setMinimumWidth( fontMetrics().maxWidth()*10 );
-  gbox->addWidget( mArray.typeCombo, 1, 1 );
-  text = i18n("Element type:"); 
-  label = new TQLabel( mArray.typeCombo, text, page );
-  gbox->addWidget( label, 1, 0 );
-  
-  mArray.lineSizeSpin = new TQSpinBox( page );
-  mArray.lineSizeSpin->setMinimumWidth( fontMetrics().maxWidth()*10 );
-  mArray.lineSizeSpin->setRange( 1, INT_MAX );
-  gbox->addWidget( mArray.lineSizeSpin, 2, 1 );
-  text = i18n("Elements per line:"); 
-  label = new TQLabel( mArray.lineSizeSpin, text, page );
-  gbox->addWidget( label, 2, 0 );
-
-  text = i18n("Print unsigned values as hexadecimal");
-  mArray.hexadecimalCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mArray.hexadecimalCheck );
-
-  topLayout->addStretch(10);
-}
-
-
-
-
-
-void CExportDialog::formatChanged( int index )
-{
-  mDestination.formatCombo->setCurrentItem(index);
-  mDestination.fileExtraLabel->setEnabled( index == option_html );
-  mOptionStack->raiseWidget( index );
-}
-
-
-void CExportDialog::rangeChanged( int id )
-{
-  bool state = id == 2 ? true : false;
-  mDestination.toLabel->setEnabled( state );
-  mDestination.fromLabel->setEnabled( state );
-  mDestination.toInput->setEnabled( state );
-  mDestination.fromInput->setEnabled( state );
-}
-
-
-void CExportDialog::browserClicked( void )
-{
-  TQString url;
-  if( mDestination.formatCombo->currentItem() == option_html )
-  {
-    url = KFileDialog::getExistingDirectory( mWorkDir, topLevelWidget() );
-  }
-  else
-  {
-    url = KFileDialog::getSaveFileName( mWorkDir, "*", topLevelWidget() );
-  }
-
-  if( url.isEmpty() )
-  {
-    return;
-  }
-  
-  int index = url.findRev( '/' );
-  if( index != -1 ) 
-  { 
-    mWorkDir = url.left( index+1 ); 
-  }
-  mDestination.fileInput->setText( url );
-}
-
-
-void CExportDialog::slotOk( void )
-{
-  TQString path( mDestination.fileInput->text() );
-
-  int format = mDestination.formatCombo->currentItem();
-  if( format == option_text )
-  {
-    if( verifyFileDestnation( this, i18n("Export Document"), path ) == false )
-    {
-      return;
-    }
-
-    SExportText e;
-    uint mode;
-    if( collectRange( mode, e.range.start, e.range.stop ) == false )
-    {
-      showEntryFailure( this, TQString("") );
-      return;
-    }
-    e.range.mode = (SExportRange::EMode)mode; // FIXME
-    e.destFile   = path;
-
-    hide();
-    emit exportText(e);
-  }
-  else if( format == option_html )
-  {
-    SExportHtml e;
-    uint mode;
-    if( collectRange( mode, e.range.start, e.range.stop ) == false )
-    {
-      showEntryFailure( this, TQString("") );
-      return;
-    }
-    e.range.mode = (SExportRange::EMode)mode; // FIXME
-
-    const TQString str = mHtml.prefixInput->text().stripWhiteSpace();
-    mHtml.prefixInput->setText( str );
-    if( mHtml.prefixInput->text().isEmpty() == true )
-    {
-      mHtml.prefixInput->setText( "table" );
-    }
-
-    const TQString prefix = mHtml.prefixInput->text();
-    for( uint i=0; i<prefix.length(); i++ )
-    {
-      TQChar c = prefix[i];
-      if( c.isSpace() == true || c.isPunct() == true )
-      {
-	TQString msg = i18n("The filename prefix can not contain empty letters "
-	  "or punctuation marks.");
-	KMessageBox::sorry( this, msg, i18n("Export Document") );
-	return;
-      }
-    }
-
-    if( verifyPackage( path ) == false )
-    {
-      return;
-    }
-
-    e.package       = path;
-    e.prefix        = prefix;
-    e.linePerPage   = mHtml.lineSpin->value();
-    e.topCaption    = mHtml.topCombo->currentItem();
-    e.bottomCaption = mHtml.bottomCombo->currentItem();
-    e.symLink       = mHtml.symlinkCheck->isChecked();
-    e.navigator     = mHtml.navigatorCheck->isChecked();
-    e.blackWhite    = mHtml.bwCheck->isChecked();
-
-    hide();
-    emit exportHtml(e);
-  }
-  else if( format == option_rtf )
-  {
-    TQString msg = i18n("This format is not yet supported.");
-    KMessageBox::sorry( this, msg );
-  }
-  else if( format == option_carray )
-  {
-    if( verifyFileDestnation( this, i18n("Export Document"), path ) == false )
-    {
-      return;
-    }
-
-    SExportCArray e;
-    uint mode;
-    if( collectRange( mode, e.range.start, e.range.stop ) == false )
-    {
-      showEntryFailure( this, TQString("") );
-      return;
-    }
-    e.range.mode = (SExportRange::EMode)mode; // FIXME
-    e.destFile   = path;
-    e.arrayName = mArray.nameInput->text();
-    e.elementType = mArray.typeCombo->currentItem();
-    e.elementPerLine = mArray.lineSizeSpin->value(); 
-    e.unsignedAsHexadecimal = mArray.hexadecimalCheck->isChecked();
-
-    emit exportCArray( e );
-  }
-}
-
-
-
-
-bool CExportDialog::collectRange( uint &mode, uint &start, uint &stop )
-{
-  TQButton *b = mDestination.rangeBox->selected();
-  if( b == 0 )
-  {
-    return( false );
-  }
-  
-  int id =  mDestination.rangeBox->id( b );
-  if( id == 0 )
-  {
-    mode = SExportRange::All;
-  }
-  else if( id == 1 )
-  {
-    mode = SExportRange::Selection;
-  }
-  else if( id == 2 )
-  {
-    mode = SExportRange::Range;
-    bool ok1 = stringToOffset( mDestination.fromInput->text(), start );
-    bool ok2 = stringToOffset( mDestination.toInput->text(), stop );
-    if( ok1 == false || ok2 == false || start >= stop )
-    {
-      return( false );
-    }
-  }
-  else
-  {
-    return( false );
-  }
-
-  return( true );
-}
-
-
-//
-// This one will attempt to create a directory if 'path'
-// specifies a nonexistent name.
-//
-bool CExportDialog::verifyPackage( const TQString &path )
-{
-  const TQString title = i18n("Export Document");
-
-  if( path.isEmpty() == true )
-  {
-    TQString msg = i18n("You must specify a destination.");
-    KMessageBox::sorry( this, msg, title );
-    return( false );
-  }
-
-  TQFileInfo info( path );
-  if( info.exists() == false )
-  {
-    TQDir directory;
-    if( directory.mkdir( path ) == false )
-    {
-      TQString msg;
-      msg += i18n("Unable to create a new folder");
-      msg += "\n";
-      msg += path;
-      KMessageBox::sorry( this, msg, title );
-      return( false );
-    }
-  }
-  else
-  {
-    if( info.isDir() == false ) 
-    {
-      TQString msg = i18n("You have specified an existing file");
-      KMessageBox::sorry( this, msg, title );
-      return( false );
-    }
-    else
-    {
-      if( info.isWritable() == false ) 
-      {
-	TQString msg = i18n( ""
-          "You do not have write permission to this folder.");
-	KMessageBox::sorry( this, msg, title );
-	return( false );
-      }
-
-      const TQString prefix = mHtml.prefixInput->text();
-      TQString f1 = TQString("%1%2.html").arg(prefix).arg("00000000");
-      TQString f2 = TQString("%1%2.html").arg(prefix).arg("99999999");
-
-      TQString msg = i18n( ""
-        "You have specified an existing folder.\n"
-	"If you continue, any existing file in the range "
-	"\"%1\" to \"%2\" can be lost.\n"
-	"Continue?").arg(f1).arg(f2);
-      int reply = KMessageBox::warningContinueCancel( this, msg, title );
-      if( reply != KMessageBox::Continue )
-      {
-	return( false );
-      }
-
-    }
-  }
-
-  return( true );
-}
-
-#include "exportdialog.moc"
diff --git a/khexedit/exportdialog.cpp b/khexedit/exportdialog.cpp
new file mode 100644
index 00000000..2cdfae7c
--- /dev/null
+++ b/khexedit/exportdialog.cpp
@@ -0,0 +1,696 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <limits.h>
+#include <tqbuttongroup.h>
+#include <tqlineedit.h> 
+
+#include <tdefiledialog.h>
+#include <tdelocale.h>
+#include <tdemessagebox.h>
+
+#include "dialog.h"
+#include "exportdialog.h"
+#include <tqpushbutton.h>
+
+
+CExportDialog::CExportDialog( TQWidget *parent, char *name, bool modal )
+  :KDialogBase( Tabbed, i18n("Export Document"), Help|Ok|Cancel, Ok,
+		parent, name,  modal )
+{
+  setHelp( "khexedit/khexedit.html", TQString() );
+
+  mFrame[ page_destination ] = addPage( i18n("Destination") );
+  mFrame[ page_option ] = addPage( i18n("Options") );
+
+  setupDestinationPage();
+  setupOptionPage();
+ 
+  mConfig = 0;
+  readConfiguration();
+
+  TQString path = mDestination.fileInput->text();
+  int index = path.findRev( '/' );
+  if( index != -1 ) { mWorkDir = path.left( index+1 ); }
+}
+
+
+CExportDialog::~CExportDialog( void )
+{
+  writeConfiguration();
+  delete mConfig; mConfig = 0;
+}
+
+
+void CExportDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  showPage(0);
+  mDestination.fileInput->setFocus();
+}
+
+
+void CExportDialog::readConfiguration( void )
+{
+  if( mConfig != 0 ) { return; }
+
+  mConfig = new KSimpleConfig( TQString("hexexport") );
+  if( mConfig == 0 ) { return; }
+
+  mConfig->setGroup( "Destination" );
+
+  int val = mConfig->readNumEntry( "Format", 0 );
+  mDestination.formatCombo->setCurrentItem( val );
+  formatChanged( val < 0 || val > option_html ? 0 : val );
+
+  mConfig->setGroup( "Option" );
+  val = mConfig->readNumEntry( "HtmlLine", 80 );
+  mHtml.lineSpin->setValue( val );
+  TQString text = mConfig->readEntry( "HtmlPrefix", "table" );
+  mHtml.prefixInput->setText( text );
+  val = mConfig->readNumEntry( "HtmlHeader", 1 );
+  mHtml.topCombo->setCurrentItem( val < 0 || val >= 4 ? 0 : val );
+  val = mConfig->readNumEntry( "HtmlFooter", 3 );
+  mHtml.bottomCombo->setCurrentItem( val < 0 || val >= 4 ? 0 : val );
+
+  bool state = mConfig->readBoolEntry( "HtmlSymlink", true );
+  mHtml.symlinkCheck->setChecked( state );  
+  state = mConfig->readBoolEntry( "HtmlNavigatorBar", true );
+  mHtml.navigatorCheck->setChecked( state );
+  state = mConfig->readBoolEntry( "HtmlBlackWhite", false );
+  mHtml.bwCheck->setChecked( state );
+
+  text = mConfig->readEntry( "ArrayName", "buffer" );
+  mArray.nameInput->setText( text );
+  text = mConfig->readEntry( "ArrayElementType", "char" );
+  for( int i=0; i < mArray.typeCombo->count(); i++ )
+  { 
+    if( mArray.typeCombo->text(i) == text )
+    {
+      mArray.typeCombo->setCurrentItem(i);
+      break;
+    }
+  }
+  val = mConfig->readNumEntry( "ArrayElementPerLine", 20 );
+  val = TQMAX( val, mArray.lineSizeSpin->minValue() );  
+  val = TQMIN( val, mArray.lineSizeSpin->maxValue() );
+  mArray.lineSizeSpin->setValue( val );
+  state = mConfig->readBoolEntry( "ArrayUnsignedAsHex", true );
+  mArray.hexadecimalCheck->setChecked( state );
+}
+
+
+void CExportDialog::writeConfiguration( void )
+{
+  if( mConfig == 0 )
+  {
+    return;
+  }
+
+  mConfig->setGroup( "Destination" );
+  mConfig->writeEntry( "Format", mDestination.formatCombo->currentItem() );
+
+  mConfig->setGroup( "Option" );
+  mConfig->writeEntry( "HtmlLine", mHtml.lineSpin->value() );
+  mConfig->writeEntry( "HtmlPrefix", mHtml.prefixInput->text() );
+  mConfig->writeEntry( "HtmlHeader", mHtml.topCombo->currentItem() );
+  mConfig->writeEntry( "HtmlFooter", mHtml.bottomCombo->currentItem() );
+  mConfig->writeEntry( "HtmlSymlink", mHtml.symlinkCheck->isChecked());
+  mConfig->writeEntry( "HtmlNavigatorBar",mHtml.navigatorCheck->isChecked());
+  mConfig->writeEntry( "HtmlBlackWhite", mHtml.bwCheck->isChecked() );
+
+
+  mConfig->writeEntry( "ArrayName", mArray.nameInput->text() );
+  mConfig->writeEntry( "ArrayElementType", mArray.typeCombo->currentText() );
+  mConfig->writeEntry( "ArrayElementPerLine", mArray.lineSizeSpin->value() );
+  mConfig->writeEntry( "ArrayUnsignedAsHex", 
+		       mArray.hexadecimalCheck->isChecked() );
+  mConfig->sync();
+}
+
+
+void CExportDialog::setupDestinationPage( void )
+{
+  TQString text;
+  TQFrame *page = mFrame[ page_destination ];
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
+  if( topLayout == 0 ) { return; }
+
+  TQStringList formatList;
+  formatList.append( i18n("Plain Text") );
+  formatList.append( i18n("HTML Tables") );
+  formatList.append( i18n("Rich Text (RTF)") );
+  formatList.append( i18n("C Array") );
+
+  mDestination.formatCombo = new TQComboBox( false, page );
+  mDestination.formatCombo->insertStringList( formatList );
+  mDestination.formatCombo->setMinimumWidth( fontMetrics().maxWidth()*10 );
+  connect( mDestination.formatCombo, TQT_SIGNAL(activated(int)),
+	   TQT_SLOT(formatChanged(int)) );
+
+  text = i18n("&Format:");
+  TQLabel *label = new TQLabel( mDestination.formatCombo, text, page );
+  topLayout->addWidget( label );
+  topLayout->addWidget( mDestination.formatCombo );
+
+  TQHBoxLayout *hbox = new TQHBoxLayout();
+  topLayout->addLayout( hbox );
+
+  text = i18n("&Destination:");
+  label = new TQLabel( text, page );
+  hbox->addWidget( label );
+ 
+  text = i18n("(Package folder)"); 
+  mDestination.fileExtraLabel = new TQLabel( text, page );
+  hbox->addWidget( mDestination.fileExtraLabel, 10, AlignLeft|AlignVCenter );
+
+  hbox = new TQHBoxLayout();
+  topLayout->addLayout( hbox );
+
+  mDestination.fileInput = new TQLineEdit( page );
+  hbox->addWidget( mDestination.fileInput );
+  connect(mDestination.fileInput, TQT_SIGNAL(textChanged ( const TQString & )),this,TQT_SLOT(destinationChanged(const TQString &)));
+  text = i18n("Choose...");
+  TQPushButton *browseButton = new TQPushButton( text, page, "browse" );
+  hbox->addWidget( browseButton );
+  connect( browseButton, TQT_SIGNAL(clicked()), TQT_SLOT(browserClicked()) );
+  mDestination.fileInput->setMinimumWidth( fontMetrics().maxWidth()*15 );
+
+  label->setBuddy(mDestination.fileInput);
+
+  hbox = new TQHBoxLayout();
+  topLayout->addLayout( hbox, 10 );
+
+  mDestination.rangeBox = new TQButtonGroup( i18n("Export Range"), page );
+  hbox->addWidget( mDestination.rangeBox );
+
+  TQButtonGroup *group = mDestination.rangeBox; // convenience
+
+  TQVBoxLayout *vbox = new TQVBoxLayout( group, spacingHint() );  
+  vbox->addSpacing( fontMetrics().lineSpacing() );
+  
+  TQRadioButton *radio1 = new TQRadioButton( i18n("&Everything"), group );
+  radio1->setFixedSize( radio1->sizeHint() );
+  mDestination.rangeBox->insert( radio1, 0 );
+  vbox->addWidget( radio1, 0, AlignLeft );
+
+  TQRadioButton *radio2 = new TQRadioButton( i18n("&Selection"), group );
+  radio2->setFixedSize( radio2->sizeHint() );
+  mDestination.rangeBox->insert( radio2, 1 );
+  vbox->addWidget( radio2, 0, AlignLeft );
+
+  TQRadioButton *radio3 = new TQRadioButton( i18n("&Range"), group );
+  radio3->setFixedSize( radio3->sizeHint() );
+  mDestination.rangeBox->insert( radio3, 2 );
+  vbox->addWidget( radio3, 0, AlignLeft );
+
+  TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
+  vbox->addLayout( gbox );
+
+  mDestination.fromInput = new TQLineEdit( group );
+  text = i18n("&From offset:");
+  mDestination.fromLabel = new TQLabel( mDestination.fromInput, text, group );
+  gbox->addWidget( mDestination.fromLabel, 0, 0 );
+  gbox->addWidget( mDestination.fromInput, 0, 1 );
+
+  mDestination.toInput = new TQLineEdit( group );
+  text = i18n("&To offset:");
+  mDestination.toLabel = new TQLabel( mDestination.toInput, text, group );
+  gbox->addWidget( mDestination.toLabel, 1, 0 );
+  gbox->addWidget( mDestination.toInput, 1, 1 );
+
+  connect( group, TQT_SIGNAL(clicked(int)), TQT_SLOT(rangeChanged(int)) );
+  group->setButton(0);
+  rangeChanged(0);
+  enableButtonOK( !mDestination.fileInput->text().isEmpty() );
+}
+
+void CExportDialog::destinationChanged(const TQString &_text)
+{
+  enableButtonOK( !_text.isEmpty() );
+}
+
+void CExportDialog::setupOptionPage( void )
+{
+  TQFrame *page = mFrame[ page_option ];
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
+  if( topLayout == 0 ) { return; }
+
+  mOptionStack = new TQWidgetStack( page, "stack" );
+  if( mOptionStack == 0 ) { return; }
+  topLayout->addWidget( mOptionStack );
+
+  makeTextOption();
+  makeHtmlOption();
+  makeRtfOption();
+  makeCArrayOption();
+  mOptionStack->raiseWidget( (int)option_text );
+
+  TQSize size = mOptionStack->sizeHint();
+  size += TQSize(spacingHint()*2, spacingHint()*2);
+  page->setMinimumSize( size ); 
+}
+
+
+void CExportDialog::makeTextOption( void )
+{
+  TQFrame *page = new TQFrame( mFrame[ page_option ] );
+  if( page == 0 ) { return; }
+  mOptionStack->addWidget( page, option_text );
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
+  TQString text = i18n("No options for this format.");
+  TQLabel *label = new TQLabel( text, page );
+  topLayout->addWidget( label, 0, AlignCenter );
+}
+
+
+void CExportDialog::makeHtmlOption( void )
+{
+  TQFrame *page = new TQFrame( mFrame[ page_option ] );
+  if( page == 0 ) { return; }
+  mOptionStack->addWidget( page, option_html );
+
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
+  if( topLayout == 0 ) { return; }
+
+  text = i18n("HTML Options (one table per page)");
+  TQLabel *label = new TQLabel( text, page );
+  topLayout->addWidget( label );
+
+  TQFrame *hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  topLayout->addWidget( hline );
+
+  TQFrame *frame = new TQFrame( page );
+  if( frame == 0 ) { return; }  
+  topLayout->addWidget( frame );
+
+  TQGridLayout *gbox = new TQGridLayout( frame, 4, 2, 0, spacingHint() );
+  if( gbox == 0 ) { return; }
+  gbox->setColStretch( 1, 10 );  
+
+  mHtml.lineSpin = new TQSpinBox( frame );
+  mHtml.lineSpin->setMinimumWidth( fontMetrics().maxWidth()*10 );
+  mHtml.lineSpin->setRange( 5, INT_MAX );
+  gbox->addWidget( mHtml.lineSpin, 0, 1 );
+  
+  text = i18n("&Lines per table:");
+  label = new TQLabel( mHtml.lineSpin, text, frame );
+  gbox->addWidget( label, 0, 0 );
+
+  mHtml.prefixInput = new TQLineEdit( frame, "prefix" );
+  mHtml.prefixInput->setMinimumWidth( fontMetrics().maxWidth()*10 );
+  gbox->addWidget( mHtml.prefixInput, 1, 1 );
+
+  text = i18n("Filename &prefix (in package):");
+  label = new TQLabel( mHtml.prefixInput, text, frame );
+  gbox->addWidget( label, 1, 0 );
+
+  TQStringList headerList;
+  headerList.append( i18n("None") );
+  headerList.append( i18n("Filename with Path") );
+  headerList.append( i18n("Filename") );
+  headerList.append( i18n("Page Number") );
+
+  mHtml.topCombo = new TQComboBox( false, frame );
+  mHtml.topCombo->insertStringList( headerList );
+  gbox->addWidget( mHtml.topCombo, 2, 1 );
+
+  text = i18n("Header &above text:");
+  label = new TQLabel( mHtml.topCombo, text, frame );
+  gbox->addWidget( label, 2, 0 );
+
+  mHtml.bottomCombo = new TQComboBox( false, frame );
+  mHtml.bottomCombo->insertStringList( headerList );
+  gbox->addWidget( mHtml.bottomCombo, 3, 1 );
+
+  text = i18n("&Footer below text:");
+  label = new TQLabel( mHtml.bottomCombo, text, frame );
+  gbox->addWidget( label, 3, 0 );
+
+  text = i18n("Link \"index.html\" to &table of contents file");
+  mHtml.symlinkCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mHtml.symlinkCheck );
+
+  text = i18n("&Include navigator bar");
+  mHtml.navigatorCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mHtml.navigatorCheck );
+
+  text = i18n("&Use black and white only");
+  mHtml.bwCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mHtml.bwCheck );
+
+  topLayout->addStretch(10);
+}
+
+
+void CExportDialog::makeRtfOption( void )
+{
+  TQFrame *page = new TQFrame( mFrame[ page_option ] );
+  if( page == 0 ) { return; }
+  mOptionStack->addWidget( page, option_rtf );
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
+  TQString text = i18n("No options for this format.");
+  TQLabel *label = new TQLabel( text, page );
+  topLayout->addWidget( label, 0, AlignCenter );
+}
+
+
+void CExportDialog::makeCArrayOption( void )
+{
+  TQFrame *page = new TQFrame( mFrame[ page_option ] );
+  mOptionStack->addWidget( page, option_carray );
+
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );  
+
+  text = i18n("C Array Options");
+  TQLabel *label = new TQLabel( text, page );
+  topLayout->addWidget( label, 0, AlignLeft );
+
+  TQFrame *hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  topLayout->addWidget( hline );
+
+  TQGridLayout *gbox = new TQGridLayout( 3, 2, spacingHint() );
+  topLayout->addLayout( gbox );
+  gbox->setColStretch( 1, 10 );
+
+  mArray.nameInput = new TQLineEdit( page );
+  gbox->addWidget( mArray.nameInput, 0, 1 );
+  text = i18n("Array name:"); 
+  label = new TQLabel( mArray.nameInput, text, page );
+  gbox->addWidget( label, 0, 0 );
+
+  TQStringList typeList;
+  typeList.append( i18n("char") );
+  typeList.append( i18n("unsigned char") );
+  typeList.append( i18n("short") );
+  typeList.append( i18n("unsigned short") );
+  typeList.append( i18n("int") );
+  typeList.append( i18n("unsigned int") );
+  typeList.append( i18n("float") );
+  typeList.append( i18n("double") );
+  mArray.typeCombo = new TQComboBox( false, page );
+  mArray.typeCombo->insertStringList( typeList );
+  mArray.typeCombo->setMinimumWidth( fontMetrics().maxWidth()*10 );
+  gbox->addWidget( mArray.typeCombo, 1, 1 );
+  text = i18n("Element type:"); 
+  label = new TQLabel( mArray.typeCombo, text, page );
+  gbox->addWidget( label, 1, 0 );
+  
+  mArray.lineSizeSpin = new TQSpinBox( page );
+  mArray.lineSizeSpin->setMinimumWidth( fontMetrics().maxWidth()*10 );
+  mArray.lineSizeSpin->setRange( 1, INT_MAX );
+  gbox->addWidget( mArray.lineSizeSpin, 2, 1 );
+  text = i18n("Elements per line:"); 
+  label = new TQLabel( mArray.lineSizeSpin, text, page );
+  gbox->addWidget( label, 2, 0 );
+
+  text = i18n("Print unsigned values as hexadecimal");
+  mArray.hexadecimalCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mArray.hexadecimalCheck );
+
+  topLayout->addStretch(10);
+}
+
+
+
+
+
+void CExportDialog::formatChanged( int index )
+{
+  mDestination.formatCombo->setCurrentItem(index);
+  mDestination.fileExtraLabel->setEnabled( index == option_html );
+  mOptionStack->raiseWidget( index );
+}
+
+
+void CExportDialog::rangeChanged( int id )
+{
+  bool state = id == 2 ? true : false;
+  mDestination.toLabel->setEnabled( state );
+  mDestination.fromLabel->setEnabled( state );
+  mDestination.toInput->setEnabled( state );
+  mDestination.fromInput->setEnabled( state );
+}
+
+
+void CExportDialog::browserClicked( void )
+{
+  TQString url;
+  if( mDestination.formatCombo->currentItem() == option_html )
+  {
+    url = KFileDialog::getExistingDirectory( mWorkDir, topLevelWidget() );
+  }
+  else
+  {
+    url = KFileDialog::getSaveFileName( mWorkDir, "*", topLevelWidget() );
+  }
+
+  if( url.isEmpty() )
+  {
+    return;
+  }
+  
+  int index = url.findRev( '/' );
+  if( index != -1 ) 
+  { 
+    mWorkDir = url.left( index+1 ); 
+  }
+  mDestination.fileInput->setText( url );
+}
+
+
+void CExportDialog::slotOk( void )
+{
+  TQString path( mDestination.fileInput->text() );
+
+  int format = mDestination.formatCombo->currentItem();
+  if( format == option_text )
+  {
+    if( verifyFileDestnation( this, i18n("Export Document"), path ) == false )
+    {
+      return;
+    }
+
+    SExportText e;
+    uint mode;
+    if( collectRange( mode, e.range.start, e.range.stop ) == false )
+    {
+      showEntryFailure( this, TQString("") );
+      return;
+    }
+    e.range.mode = (SExportRange::EMode)mode; // FIXME
+    e.destFile   = path;
+
+    hide();
+    emit exportText(e);
+  }
+  else if( format == option_html )
+  {
+    SExportHtml e;
+    uint mode;
+    if( collectRange( mode, e.range.start, e.range.stop ) == false )
+    {
+      showEntryFailure( this, TQString("") );
+      return;
+    }
+    e.range.mode = (SExportRange::EMode)mode; // FIXME
+
+    const TQString str = mHtml.prefixInput->text().stripWhiteSpace();
+    mHtml.prefixInput->setText( str );
+    if( mHtml.prefixInput->text().isEmpty() == true )
+    {
+      mHtml.prefixInput->setText( "table" );
+    }
+
+    const TQString prefix = mHtml.prefixInput->text();
+    for( uint i=0; i<prefix.length(); i++ )
+    {
+      TQChar c = prefix[i];
+      if( c.isSpace() == true || c.isPunct() == true )
+      {
+	TQString msg = i18n("The filename prefix can not contain empty letters "
+	  "or punctuation marks.");
+	KMessageBox::sorry( this, msg, i18n("Export Document") );
+	return;
+      }
+    }
+
+    if( verifyPackage( path ) == false )
+    {
+      return;
+    }
+
+    e.package       = path;
+    e.prefix        = prefix;
+    e.linePerPage   = mHtml.lineSpin->value();
+    e.topCaption    = mHtml.topCombo->currentItem();
+    e.bottomCaption = mHtml.bottomCombo->currentItem();
+    e.symLink       = mHtml.symlinkCheck->isChecked();
+    e.navigator     = mHtml.navigatorCheck->isChecked();
+    e.blackWhite    = mHtml.bwCheck->isChecked();
+
+    hide();
+    emit exportHtml(e);
+  }
+  else if( format == option_rtf )
+  {
+    TQString msg = i18n("This format is not yet supported.");
+    KMessageBox::sorry( this, msg );
+  }
+  else if( format == option_carray )
+  {
+    if( verifyFileDestnation( this, i18n("Export Document"), path ) == false )
+    {
+      return;
+    }
+
+    SExportCArray e;
+    uint mode;
+    if( collectRange( mode, e.range.start, e.range.stop ) == false )
+    {
+      showEntryFailure( this, TQString("") );
+      return;
+    }
+    e.range.mode = (SExportRange::EMode)mode; // FIXME
+    e.destFile   = path;
+    e.arrayName = mArray.nameInput->text();
+    e.elementType = mArray.typeCombo->currentItem();
+    e.elementPerLine = mArray.lineSizeSpin->value(); 
+    e.unsignedAsHexadecimal = mArray.hexadecimalCheck->isChecked();
+
+    emit exportCArray( e );
+  }
+}
+
+
+
+
+bool CExportDialog::collectRange( uint &mode, uint &start, uint &stop )
+{
+  TQButton *b = mDestination.rangeBox->selected();
+  if( b == 0 )
+  {
+    return( false );
+  }
+  
+  int id =  mDestination.rangeBox->id( b );
+  if( id == 0 )
+  {
+    mode = SExportRange::All;
+  }
+  else if( id == 1 )
+  {
+    mode = SExportRange::Selection;
+  }
+  else if( id == 2 )
+  {
+    mode = SExportRange::Range;
+    bool ok1 = stringToOffset( mDestination.fromInput->text(), start );
+    bool ok2 = stringToOffset( mDestination.toInput->text(), stop );
+    if( ok1 == false || ok2 == false || start >= stop )
+    {
+      return( false );
+    }
+  }
+  else
+  {
+    return( false );
+  }
+
+  return( true );
+}
+
+
+//
+// This one will attempt to create a directory if 'path'
+// specifies a nonexistent name.
+//
+bool CExportDialog::verifyPackage( const TQString &path )
+{
+  const TQString title = i18n("Export Document");
+
+  if( path.isEmpty() == true )
+  {
+    TQString msg = i18n("You must specify a destination.");
+    KMessageBox::sorry( this, msg, title );
+    return( false );
+  }
+
+  TQFileInfo info( path );
+  if( info.exists() == false )
+  {
+    TQDir directory;
+    if( directory.mkdir( path ) == false )
+    {
+      TQString msg;
+      msg += i18n("Unable to create a new folder");
+      msg += "\n";
+      msg += path;
+      KMessageBox::sorry( this, msg, title );
+      return( false );
+    }
+  }
+  else
+  {
+    if( info.isDir() == false ) 
+    {
+      TQString msg = i18n("You have specified an existing file");
+      KMessageBox::sorry( this, msg, title );
+      return( false );
+    }
+    else
+    {
+      if( info.isWritable() == false ) 
+      {
+	TQString msg = i18n( ""
+          "You do not have write permission to this folder.");
+	KMessageBox::sorry( this, msg, title );
+	return( false );
+      }
+
+      const TQString prefix = mHtml.prefixInput->text();
+      TQString f1 = TQString("%1%2.html").arg(prefix).arg("00000000");
+      TQString f2 = TQString("%1%2.html").arg(prefix).arg("99999999");
+
+      TQString msg = i18n( ""
+        "You have specified an existing folder.\n"
+	"If you continue, any existing file in the range "
+	"\"%1\" to \"%2\" can be lost.\n"
+	"Continue?").arg(f1).arg(f2);
+      int reply = KMessageBox::warningContinueCancel( this, msg, title );
+      if( reply != KMessageBox::Continue )
+      {
+	return( false );
+      }
+
+    }
+  }
+
+  return( true );
+}
+
+#include "exportdialog.moc"
diff --git a/khexedit/fileinfodialog.cc b/khexedit/fileinfodialog.cc
deleted file mode 100644
index 96fb0607..00000000
--- a/khexedit/fileinfodialog.cc
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <tqheader.h>
-#include <tqlabel.h>
-#include <tqlayout.h>
-
-#include <tdeglobalsettings.h>
-#include <tdeglobal.h>
-#include <tdelocale.h>
-
-#include "fileinfodialog.h"
-#include "listview.h"
-
-// quick'n'dirty hack to have the occurrence column sorted correctly
-class CStatisticListViewItem : public TQListViewItem
-{
-  public:
-    CStatisticListViewItem( TQListView * parent, TQListViewItem * after,
-                            TQString label1, TQString label2, TQString label3, TQString label4,
-                            TQString label5, TQString label6, TQString label7, int i, int o)
-    : TQListViewItem( parent, after, label1, label2, label3, label4, label5, label6, label7),
-      item( i ),
-      occurrence( o )
-    {}
-
-    virtual int compare( TQListViewItem *i, int col, bool ascending/*TQt doc says: ignore this one*/ ) const
-    {
-      // occurrence column (or the percent one)?
-      if( col == 5 || col == 6 )
-      {
-        const int otherOccurrence = ((CStatisticListViewItem*)i)->occurrence;
-        return occurrence < otherOccurrence ? -1 : occurrence == otherOccurrence ? 0 : 1;
-      }
-      // char column?
-      else if( col == 4 )
-      {
-        const int otherItem = ((CStatisticListViewItem*)i)->item;
-        return item < otherItem ? -1 : item == otherItem ? 0 : 1;
-      }
-      // default
-      else
-        return TQListViewItem::compare(i,col,ascending);
-    }
-
-  protected:
-    // no of byte
-    int item;
-    // number of the byte's occurrence
-    int occurrence;
-};
-
-
-
-CFileInfoDialog::CFileInfoDialog( TQWidget *parent,const char *name,bool modal)
-  :KDialogBase( Plain, i18n("Statistics"), Help|User1|Cancel, User1,
-		parent, name, modal, true, i18n("&Update") ),
-   mBusy(false), mDirty(false)
-{
-  setHelp( "khexedit/khexedit.html", TQString() );
-
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-  if( topLayout == 0 ) { return; }
-
-
-  TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
-  if( gbox == 0 ) { return; }
-  topLayout->addLayout( gbox );
-  gbox->setColStretch( 1, 10 );
-
-  text = i18n("File name: ");
-  TQLabel *label = new TQLabel( text, plainPage() );
-  gbox->addWidget( label, 0, 0 );
-
-  text = i18n("Size [bytes]: ");
-  label = new TQLabel( text, plainPage() );
-  gbox->addWidget( label, 1, 0 );
-
-  mFileNameLabel = new TQLabel( plainPage() );
-  mFileSizeLabel = new TQLabel( plainPage() );
-  gbox->addWidget( mFileNameLabel, 0, 1 );
-  gbox->addWidget( mFileSizeLabel, 1, 1 );
-
-  mFrequencyList = new CListView( plainPage(), "stringList" );
-  mFrequencyList->setFont( TDEGlobalSettings::fixedFont() );
-
-  mFrequencyList->addColumn( i18n("Hexadecimal") );
-  mFrequencyList->addColumn( i18n("Decimal") );
-  mFrequencyList->addColumn( i18n("Octal") );
-  mFrequencyList->addColumn( i18n("Binary") );
-  mFrequencyList->addColumn( i18n("Text") );
-  mFrequencyList->addColumn( i18n("Occurrence") );
-  mFrequencyList->addColumn( i18n("Percent") );
-  mFrequencyList->setAllColumnsShowFocus( true );
-  mFrequencyList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
-  topLayout->addWidget( mFrequencyList, 10 );
-
-  mDirtyLabel = new TQLabel( plainPage() );
-  mDirtyLabel->setFixedHeight( fontMetrics().height() );
-  topLayout->addWidget( mDirtyLabel );
-
-  setStatistics();
-  setColumnWidth();
-  mFrequencyList->setVisibleItem( 15 );
-
-  //
-  // Load the first set of data when this timer expires. I do it this
-  // way so that the dialog will be visible when the load operation starts.
-  //
-  startTimer( 0 );
-}
-
-
-CFileInfoDialog::~CFileInfoDialog( void )
-{
-}
-
-
-void CFileInfoDialog::slotUser1( void ) // Update
-{
-  if( mBusy )
-    return;
-
-  SStatisticControl *sc = new SStatisticControl;
-  if( sc == 0 ) { return; }
-
-  mBusy = true;
-  emit collectStatistic( *sc );
-  mBusy = false;
-
-  delete sc;
-
-}
-
-
-void CFileInfoDialog::setDirty( void )
-{
-  if( mDirty )
-    return;
-
-  mDirtyLabel->setText(
-    i18n("Warning: Document has been modified since last update"));
-  mDirty = true;
-}
-
-
-void CFileInfoDialog::setClean( void )
-{
-  if( !mDirty )
-    return;
-
-  mDirtyLabel->setText("");
-  mDirty = false;
-}
-
-
-const char *printBin( uint val )
-{
-  static char buf[9];
-  for( int i = 0; i < 8; i++ )
-    buf[7-i] = (val&(1<<i)) ? '1' : '0';
-  buf[8] = 0;
-  return( buf );
-}
-
-
-void CFileInfoDialog::setStatistics() // Default
-{
-  setClean();
-  mFrequencyList->clear();
-  mFileNameLabel->clear();
-  mFileSizeLabel->clear();
-
-  static const TQString u("?");
-  TQString d, h, o, b, c;
-  TQListViewItem *item = 0;
-
-  char buf[10];
-  memset( buf, 0, sizeof( buf ) );
-
-  for( uint i=0; i<256; i++ )
-  {
-    h.sprintf("0x%02x", i );
-    d.sprintf("%03d", i );
-    o.sprintf("%03o", i );
-    b.sprintf("%s", printBin(i) );
-
-    const TQChar _i((char)i);
-    c = _i.isPrint() ? _i : TQChar('.'); 
-
-    item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, u, u, i, -1 );
-    if( i == 0 )
-      mFrequencyList->setSelected( item, true );
-  }
-}
-
-
-
-void CFileInfoDialog::setStatistics( SStatisticControl &sc )
-{
-  setClean();
-  mFrequencyList->clear();
-  mFileNameLabel->setText( sc.documentName );
-  mFileSizeLabel->setText( TDEGlobal::locale()->formatNumber(sc.documentSize, 0) );
-
-  TQString d, h, o, b, c, n, p;
-  TQListViewItem *item = 0;
-
-  uint size, pre, i;
-  // find width of occurrence
-  for( i=size=0; i<256; i++ )
-    if( sc.occurrence[i] > size ) 
-      size = sc.occurrence[i];
-  for( pre = 1; size > 0 ; pre++ )
-    size /= 10;
-
-  for( i=0; i<256; i++ )
-  {
-    h.sprintf("0x%02x", i );
-    d.sprintf("%03d", i );
-    o.sprintf("%03o", i );
-    b.sprintf("%s", printBin(i) );
-
-    n = TQString("%1").arg( sc.occurrence[i], pre );
-    if( sc.documentSize == 0 )
-      p = "0.00";
-    else
-    {
-      double val = 100.0*((double)sc.occurrence[i]/(double)sc.documentSize);
-      p = TQString("%1").arg( val, 6, 'f', 2 );
-    }
-
-    const TQChar _i((char)i);
-    c = _i.isPrint() ? _i : TQChar('.'); 
-
-    item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, n, p, i, sc.occurrence[i] );
-    if( i == 0 )
-      mFrequencyList->setSelected( item, true );
-  }
-}
-
-
-
-void CFileInfoDialog::setColumnWidth( void )
-{
-  const TQFontMetrics &fm = mFrequencyList->fontMetrics();
-  int w0, w1, w2, w3, w4;
-
-  w0 = -fm.minLeftBearing() - fm.minRightBearing() + 8 + fm.maxWidth();
-  w3 = 0;
-
-  w1  = fm.width( mFrequencyList->header()->label(0) ) + w0;
-  w2  = fm.width('0')*6;
-  w3 += w1 > w2 ? w1 : w2;
-  mFrequencyList->setColumnWidth( 0, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mFrequencyList->header()->label(1) ).width() + w0;
-  w2  = fm.width('0')*5;
-  w3 += w1 > w2 ? w1 : w2;
-  mFrequencyList->setColumnWidth( 1, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mFrequencyList->header()->label(2) ).width() + w0;
-  w2  = fm.width('0')*5;
-  w3 += w1 > w2 ? w1 : w2;
-  mFrequencyList->setColumnWidth( 2, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mFrequencyList->header()->label(3) ).width() + w0;
-  w2  = fm.width('0')*10;
-  w3 += w1 > w2 ? w1 : w2;
-  mFrequencyList->setColumnWidth( 3, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mFrequencyList->header()->label(4) ).width() + w0;
-  w2  = fm.width('0')*3;
-  w3 += w1 > w2 ? w1 : w2;
-  mFrequencyList->setColumnWidth( 4, w1 > w2 ? w1 : w2 );
-
-  w1  = fm.boundingRect( mFrequencyList->header()->label(5) ).width() + w0;
-  w2  = fm.width('0')*10;
-  w3 += w1 > w2 ? w1 : w2;
-  mFrequencyList->setColumnWidth( 5, w1 > w2 ? w1 : w2 );
-
-  w4 = mFrequencyList->viewport()->width() - w3;
-  w1 = fm.boundingRect( mFrequencyList->header()->label(6) ).width() + w0;
-  w2 = fm.width('0')*3;
-  w1 = w1 > w2 ? w1 : w2;
-  mFrequencyList->setColumnWidth( 6, w1 > w4 ? w1 : w4 );
-}
-
-
-void CFileInfoDialog::resizeEvent( TQResizeEvent * )
-{
-  setColumnWidth();
-}
-
-
-void CFileInfoDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  setColumnWidth();
-  mFrequencyList->setFocus();
-}
-
-
-void CFileInfoDialog::timerEvent( TQTimerEvent * )
-{
-  TQT_TQOBJECT(this)->killTimers();
-  slotUser1();
-}
-
-
-
-#include "fileinfodialog.moc"
diff --git a/khexedit/fileinfodialog.cpp b/khexedit/fileinfodialog.cpp
new file mode 100644
index 00000000..96fb0607
--- /dev/null
+++ b/khexedit/fileinfodialog.cpp
@@ -0,0 +1,330 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <tqheader.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+
+#include <tdeglobalsettings.h>
+#include <tdeglobal.h>
+#include <tdelocale.h>
+
+#include "fileinfodialog.h"
+#include "listview.h"
+
+// quick'n'dirty hack to have the occurrence column sorted correctly
+class CStatisticListViewItem : public TQListViewItem
+{
+  public:
+    CStatisticListViewItem( TQListView * parent, TQListViewItem * after,
+                            TQString label1, TQString label2, TQString label3, TQString label4,
+                            TQString label5, TQString label6, TQString label7, int i, int o)
+    : TQListViewItem( parent, after, label1, label2, label3, label4, label5, label6, label7),
+      item( i ),
+      occurrence( o )
+    {}
+
+    virtual int compare( TQListViewItem *i, int col, bool ascending/*TQt doc says: ignore this one*/ ) const
+    {
+      // occurrence column (or the percent one)?
+      if( col == 5 || col == 6 )
+      {
+        const int otherOccurrence = ((CStatisticListViewItem*)i)->occurrence;
+        return occurrence < otherOccurrence ? -1 : occurrence == otherOccurrence ? 0 : 1;
+      }
+      // char column?
+      else if( col == 4 )
+      {
+        const int otherItem = ((CStatisticListViewItem*)i)->item;
+        return item < otherItem ? -1 : item == otherItem ? 0 : 1;
+      }
+      // default
+      else
+        return TQListViewItem::compare(i,col,ascending);
+    }
+
+  protected:
+    // no of byte
+    int item;
+    // number of the byte's occurrence
+    int occurrence;
+};
+
+
+
+CFileInfoDialog::CFileInfoDialog( TQWidget *parent,const char *name,bool modal)
+  :KDialogBase( Plain, i18n("Statistics"), Help|User1|Cancel, User1,
+		parent, name, modal, true, i18n("&Update") ),
+   mBusy(false), mDirty(false)
+{
+  setHelp( "khexedit/khexedit.html", TQString() );
+
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+  if( topLayout == 0 ) { return; }
+
+
+  TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
+  if( gbox == 0 ) { return; }
+  topLayout->addLayout( gbox );
+  gbox->setColStretch( 1, 10 );
+
+  text = i18n("File name: ");
+  TQLabel *label = new TQLabel( text, plainPage() );
+  gbox->addWidget( label, 0, 0 );
+
+  text = i18n("Size [bytes]: ");
+  label = new TQLabel( text, plainPage() );
+  gbox->addWidget( label, 1, 0 );
+
+  mFileNameLabel = new TQLabel( plainPage() );
+  mFileSizeLabel = new TQLabel( plainPage() );
+  gbox->addWidget( mFileNameLabel, 0, 1 );
+  gbox->addWidget( mFileSizeLabel, 1, 1 );
+
+  mFrequencyList = new CListView( plainPage(), "stringList" );
+  mFrequencyList->setFont( TDEGlobalSettings::fixedFont() );
+
+  mFrequencyList->addColumn( i18n("Hexadecimal") );
+  mFrequencyList->addColumn( i18n("Decimal") );
+  mFrequencyList->addColumn( i18n("Octal") );
+  mFrequencyList->addColumn( i18n("Binary") );
+  mFrequencyList->addColumn( i18n("Text") );
+  mFrequencyList->addColumn( i18n("Occurrence") );
+  mFrequencyList->addColumn( i18n("Percent") );
+  mFrequencyList->setAllColumnsShowFocus( true );
+  mFrequencyList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
+  topLayout->addWidget( mFrequencyList, 10 );
+
+  mDirtyLabel = new TQLabel( plainPage() );
+  mDirtyLabel->setFixedHeight( fontMetrics().height() );
+  topLayout->addWidget( mDirtyLabel );
+
+  setStatistics();
+  setColumnWidth();
+  mFrequencyList->setVisibleItem( 15 );
+
+  //
+  // Load the first set of data when this timer expires. I do it this
+  // way so that the dialog will be visible when the load operation starts.
+  //
+  startTimer( 0 );
+}
+
+
+CFileInfoDialog::~CFileInfoDialog( void )
+{
+}
+
+
+void CFileInfoDialog::slotUser1( void ) // Update
+{
+  if( mBusy )
+    return;
+
+  SStatisticControl *sc = new SStatisticControl;
+  if( sc == 0 ) { return; }
+
+  mBusy = true;
+  emit collectStatistic( *sc );
+  mBusy = false;
+
+  delete sc;
+
+}
+
+
+void CFileInfoDialog::setDirty( void )
+{
+  if( mDirty )
+    return;
+
+  mDirtyLabel->setText(
+    i18n("Warning: Document has been modified since last update"));
+  mDirty = true;
+}
+
+
+void CFileInfoDialog::setClean( void )
+{
+  if( !mDirty )
+    return;
+
+  mDirtyLabel->setText("");
+  mDirty = false;
+}
+
+
+const char *printBin( uint val )
+{
+  static char buf[9];
+  for( int i = 0; i < 8; i++ )
+    buf[7-i] = (val&(1<<i)) ? '1' : '0';
+  buf[8] = 0;
+  return( buf );
+}
+
+
+void CFileInfoDialog::setStatistics() // Default
+{
+  setClean();
+  mFrequencyList->clear();
+  mFileNameLabel->clear();
+  mFileSizeLabel->clear();
+
+  static const TQString u("?");
+  TQString d, h, o, b, c;
+  TQListViewItem *item = 0;
+
+  char buf[10];
+  memset( buf, 0, sizeof( buf ) );
+
+  for( uint i=0; i<256; i++ )
+  {
+    h.sprintf("0x%02x", i );
+    d.sprintf("%03d", i );
+    o.sprintf("%03o", i );
+    b.sprintf("%s", printBin(i) );
+
+    const TQChar _i((char)i);
+    c = _i.isPrint() ? _i : TQChar('.'); 
+
+    item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, u, u, i, -1 );
+    if( i == 0 )
+      mFrequencyList->setSelected( item, true );
+  }
+}
+
+
+
+void CFileInfoDialog::setStatistics( SStatisticControl &sc )
+{
+  setClean();
+  mFrequencyList->clear();
+  mFileNameLabel->setText( sc.documentName );
+  mFileSizeLabel->setText( TDEGlobal::locale()->formatNumber(sc.documentSize, 0) );
+
+  TQString d, h, o, b, c, n, p;
+  TQListViewItem *item = 0;
+
+  uint size, pre, i;
+  // find width of occurrence
+  for( i=size=0; i<256; i++ )
+    if( sc.occurrence[i] > size ) 
+      size = sc.occurrence[i];
+  for( pre = 1; size > 0 ; pre++ )
+    size /= 10;
+
+  for( i=0; i<256; i++ )
+  {
+    h.sprintf("0x%02x", i );
+    d.sprintf("%03d", i );
+    o.sprintf("%03o", i );
+    b.sprintf("%s", printBin(i) );
+
+    n = TQString("%1").arg( sc.occurrence[i], pre );
+    if( sc.documentSize == 0 )
+      p = "0.00";
+    else
+    {
+      double val = 100.0*((double)sc.occurrence[i]/(double)sc.documentSize);
+      p = TQString("%1").arg( val, 6, 'f', 2 );
+    }
+
+    const TQChar _i((char)i);
+    c = _i.isPrint() ? _i : TQChar('.'); 
+
+    item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, n, p, i, sc.occurrence[i] );
+    if( i == 0 )
+      mFrequencyList->setSelected( item, true );
+  }
+}
+
+
+
+void CFileInfoDialog::setColumnWidth( void )
+{
+  const TQFontMetrics &fm = mFrequencyList->fontMetrics();
+  int w0, w1, w2, w3, w4;
+
+  w0 = -fm.minLeftBearing() - fm.minRightBearing() + 8 + fm.maxWidth();
+  w3 = 0;
+
+  w1  = fm.width( mFrequencyList->header()->label(0) ) + w0;
+  w2  = fm.width('0')*6;
+  w3 += w1 > w2 ? w1 : w2;
+  mFrequencyList->setColumnWidth( 0, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mFrequencyList->header()->label(1) ).width() + w0;
+  w2  = fm.width('0')*5;
+  w3 += w1 > w2 ? w1 : w2;
+  mFrequencyList->setColumnWidth( 1, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mFrequencyList->header()->label(2) ).width() + w0;
+  w2  = fm.width('0')*5;
+  w3 += w1 > w2 ? w1 : w2;
+  mFrequencyList->setColumnWidth( 2, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mFrequencyList->header()->label(3) ).width() + w0;
+  w2  = fm.width('0')*10;
+  w3 += w1 > w2 ? w1 : w2;
+  mFrequencyList->setColumnWidth( 3, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mFrequencyList->header()->label(4) ).width() + w0;
+  w2  = fm.width('0')*3;
+  w3 += w1 > w2 ? w1 : w2;
+  mFrequencyList->setColumnWidth( 4, w1 > w2 ? w1 : w2 );
+
+  w1  = fm.boundingRect( mFrequencyList->header()->label(5) ).width() + w0;
+  w2  = fm.width('0')*10;
+  w3 += w1 > w2 ? w1 : w2;
+  mFrequencyList->setColumnWidth( 5, w1 > w2 ? w1 : w2 );
+
+  w4 = mFrequencyList->viewport()->width() - w3;
+  w1 = fm.boundingRect( mFrequencyList->header()->label(6) ).width() + w0;
+  w2 = fm.width('0')*3;
+  w1 = w1 > w2 ? w1 : w2;
+  mFrequencyList->setColumnWidth( 6, w1 > w4 ? w1 : w4 );
+}
+
+
+void CFileInfoDialog::resizeEvent( TQResizeEvent * )
+{
+  setColumnWidth();
+}
+
+
+void CFileInfoDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  setColumnWidth();
+  mFrequencyList->setFocus();
+}
+
+
+void CFileInfoDialog::timerEvent( TQTimerEvent * )
+{
+  TQT_TQOBJECT(this)->killTimers();
+  slotUser1();
+}
+
+
+
+#include "fileinfodialog.moc"
diff --git a/khexedit/hexbuffer.cc b/khexedit/hexbuffer.cc
deleted file mode 100644
index 83cfa84c..00000000
--- a/khexedit/hexbuffer.cc
+++ /dev/null
@@ -1,5099 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <tqfileinfo.h>
-
-#include <tdelocale.h>
-#include <tdeglobal.h>
-#include <tdeglobalsettings.h>
-#include <knotifyclient.h>
-
-#include "hexbuffer.h"
-#include "hexerror.h"
-
-//
-// There are some comments marked with a "// ##" at various places.
-// These indicate a patch from Sergey A. Sukiyazov which I have applied
-// "as is" for now. The number of TQString::fromLocal8Bit in this modification
-// indicates that I should perhaps modify code elsewhere as well 
-// (espen 2000-11-26)
-//
-
-// #define DEBUG_FIXED_SIZE 1024
-// #define PRINTER_TEST
-
-
-CHexAction::CHexAction( HexAction action, uint offset )
-{
-  mAction   = action;
-  mOffset   = offset;
-  mSize     = 0;
-  mData     = 0;
-  mDataSize = 0;
-  mNext     = 0;
-}
-
-CHexAction::~CHexAction( void )
-{
-  delete [] mData;
-}
-
-void CHexAction::setData( uint size, char *data, uint dataSize )
-{
-
-  if( data != 0 && dataSize > 0 )
-  {
-    mData = new char[ dataSize ];
-    if( mData == 0 )
-    {
-      return;
-    }
-    memcpy( mData, data, dataSize );
-    mDataSize = dataSize;
-  }
-  else
-  {
-    mDataSize = 0;
-    mData = 0;
-  }
-  mSize = size;
-}
-
-
-CHexActionGroup::CHexActionGroup( uint startOffset, uint startBit )
-{
-  mStartOffset = startOffset;
-  mStartBit    = startBit;
-  mHexAction   = 0;
-}
-
-CHexActionGroup::~CHexActionGroup( void )
-{
-  CHexAction *ptr = mHexAction;
-  while( ptr != 0 )
-  {
-    CHexAction *next = ptr->mNext;
-    delete ptr;
-    ptr = next;
-  }
-}
-
-void CHexActionGroup::insertAction( CHexAction *hexAction )
-{
-  hexAction->mNext = mHexAction;
-  mHexAction = hexAction;
-}
-
-
-
-int SFilterControl::execute( uchar *dest, uchar *src, uint size )
-{
-  if( size == 0 )
-  {
-    return( Err_IllegalArgument );
-  }
-
-  uint numElement = operand.size();
-  if( operation == OperandAndData )
-  {
-    if( numElement == 0 ) { return( Err_IllegalArgument ); }
-    if( forward == true )
-    {
-      for( uint i = 0; i < size; )
-      {
-	for( uint j = 0; i < size && j < numElement; j++, i++ )
-	{
-	  dest[i] = src[i] & operand[j];
-	}
-      }
-    }
-    else
-    {
-      for( uint i = size; i > 0; )
-      {
-	for( uint j = numElement; i > 0 && j > 0; j--, i-- )
-	{
-	  dest[i-1] = src[i-1] & operand[j-1];
-	}
-      }
-    }
-  }
-  else if( operation == OperandOrData )
-  {
-    if( numElement == 0 ) { return( Err_IllegalArgument ); }
-    if( forward == true )
-    {
-      for( uint i = 0; i < size; )
-      {
-	for( uint j = 0; i < size && j < numElement; j++, i++ )
-	{
-	  dest[i] = src[i] | operand[j];
-	}
-      }
-    }
-    else
-    {
-      for( uint i = size; i > 0; )
-      {
-	for( uint j = numElement; i > 0 && j > 0; j--, i-- )
-	{
-	  dest[i-1] = src[i-1] | operand[j-1];
-	}
-      }
-    }
-  }
-  else if( operation == OperandXorData )
-  {
-    if( numElement == 0 ) { return( Err_IllegalArgument ); }
-    if( forward == true )
-    {
-      for( uint i = 0; i < size; )
-      {
-	for( uint j = 0; i < size && j < numElement; j++, i++ )
-	{
-	  dest[i] = src[i] ^ operand[j];
-	}
-      }
-    }
-    else
-    {
-      for( uint i = size; i > 0; )
-      {
-	for( uint j = numElement; i > 0 && j > 0; j--, i-- )
-	{
-	  dest[i-1] = src[i-1] ^ operand[j-1];
-	}
-      }
-    }
-  }
-  else if( operation == InvertData )
-  {
-    for( uint i = 0; i < size; i++ )
-    {
-      dest[i] = ~src[i];
-    }
-  }
-  else if( operation == ReverseData )
-  {
-    for( uint i = 0; i < size; i++ )
-    {
-      uchar flag = src[i];
-      uchar rev  = 0;
-      for( uint j = 0; j < 8; j++ )
-      {
-	rev |= (((flag & 0x80) >> (7-j)));
-	flag <<= 1;
-      }
-      dest[i] = rev;
-    }
-  }
-  else if( operation == RotateData || operation == ShiftData )
-  {
-    //
-    // Only forward here
-    //
-    bool up   = rotate[1] > 0 ? true : false;
-    int range = rotate[0];
-    int shift = abs(rotate[1]);
-    if( range == 0 || shift == 0 ) { return( Err_IllegalArgument ); }
-    shift = shift % (range*8);
-
-    int b = shift / 8;
-    int s = shift - b * 8;
-
-    for( uint i = 0; i < size; )
-    {
-      if( up == true )
-      {
-	int j;
-	if( operation == RotateData )
-	{
-	  for( j=0; j < b && i+range < size ; i++, j++ )
-	  {
-	    dest[i] = src[i+range-b];
-	  }
-	}
-	else
-	{
-	  for( j=0; j < b && i < size ; dest[i] = 0, i++, j++ );
-	}
-	for( ; j < range && i < size ; i++, j++ )
-	{
-	  dest[i] = src[i-b];
-	}
-
-	uchar last = dest[i-1];
-	for( int k=1; k <= j; k++ )
-	{
-	  dest[i-k] >>= s;
-	  if( k < j )
-	  {
-	    dest[i-k] |= dest[i-k-1]<<(8-s);
-	  }
-	  else if( j == range && operation == RotateData )
-	  {
-	    dest[i-k] |= last<<(8-s);
-	  }
-	}
-      }
-      else
-      {
-	int j;
-	for( j=0; j+b < range && i+b < size ; i++, j++ )
-	{
-	  dest[i] = src[i+b];
-	}
-	for( ; j < range && i < size ; i++, j++ )
-	{
-	  dest[i] = operation == RotateData ? src[i+b-range] : 0;
-	}
-	
-	uchar first = dest[i-j];
-	for( int k=j; k>0; k-- )
-	{
-	  dest[i-k] <<= s;
-	  if( k>1 )
-	  {
-	    dest[i-k] |= dest[i-k+1]>>(8-s);
-	  }
-	  else if( j == range && operation == RotateData )
-	  {
-	    dest[i-k] |= first>>(8-s);
-	  }
-	}
-      }
-    }
-  }
-  else if( operation == SwapBits )
-  {
-    //
-    // Swap bits. Based on Leon Lessing's work.
-    //
-
-    //
-    // Make non swapped version first.
-    //
-    for( uint i = 0; i < size; i++ )
-    {
-      dest[i] = src[i];
-    }
-
-    //
-    // Swap the pairs the have been defined
-    // Format of operand (example):
-    // 7 2 5 0 0 0 0 0
-    // Swap bit 7 with bit 2 and swap bit 5 with bit 0
-    //
-    for( uint j=0; j<4; j++ )
-    {
-      uchar b1 = 1 << (uchar)operand[j*2];
-      uchar b2 = 1 << (uchar)operand[j*2+1];
-      if( b1 == b2 ) { continue; } // Equal, no need to swap.
-
-      for( uint i = 0; i < size; i++ )
-      {
-	uchar b = 0;
-	if( dest[i] & b1 ) { b |= b2; }
-	if( dest[i] & b2 ) { b |= b1; }
-
-	//
-	// A short description so that I will understand what the
-	// h... is going on five minutes from now.
-	//
-	// Destination byte is masked (AND'ed) with the inverse bitmap
-	// (the noninversed bitmap contains position of the
-	// two swap bits, eg 7-2 gives 10000100). Then the destination
-	// is OR'ed with the swapped bitmap.
-	//
-	dest[i] = (dest[i] & ~(b1 | b2)) | b;
-      }
-    }
-  }
-  else
-  {
-    return( Err_IllegalArgument );
-  }
-
-  return( Err_Success );
-}
-
-
-const char *SExportCArray::printFormatted( const char *b, uint maxSize ) const
-{
-  static char buf[12];
-  if( elementType == Char )
-  {
-    char e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    sprintf( buf, "%d", e );
-    return( buf );
-  }
-  else if( elementType == Uchar )
-  {
-    unsigned char e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    if( unsignedAsHexadecimal == true )
-    {
-      sprintf( buf, "0x%02x", e );
-    }
-    else
-    {
-      sprintf( buf, "%u", e );
-    }
-    return( buf );
-  }
-  else if( elementType == Short )
-  {
-    short e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    sprintf( buf, "%d", e );
-    return( buf );
-
-  }
-  else if( elementType == Ushort )
-  {
-    unsigned short e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    if( unsignedAsHexadecimal == true )
-    {
-      sprintf( buf, "0x%04x", e );
-    }
-    else
-    {
-      sprintf( buf, "%u", e );
-    }
-    return( buf );
-  }
-  else if( elementType == Int )
-  {
-    int e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    sprintf( buf, "%u", e );
-    return( buf );
-  }
-  else if( elementType == Uint )
-  {
-    unsigned int e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    if( unsignedAsHexadecimal == true )
-    {
-      sprintf( buf, "0x%08x", e );
-    }
-    else
-    {
-      sprintf( buf, "%u", e );
-    }
-    return( buf );
-  }
-  else if( elementType == Float )
-  {
-    float e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    sprintf( buf, "%f", e );
-    return( buf );
-  }
-  else if( elementType == Double )
-  {
-    double e = 0;
-    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
-    sprintf( buf, "%f", e );
-    return( buf );
-  }
-
-  else
-  {
-    return("");
-  }
-}
-
-
-TQString SExportCArray::variableName( uint range ) const
-{
-  const char *typeString[] =
-  {
-    "char",
-    "unsigned char",
-    "short",
-    "unsigned short",
-    "int",
-    "unsigned int",
-    "float",
-    "double"
-  };
-
-  uint es = elementSize();
-  uint numElement = range / es + ((range % es) ? 1 : 0);
-
-  return( TQString("%1 %2[%2]").arg(typeString[elementType]).
-	  arg(arrayName).arg(numElement) );
-}
-
-
-
-int SExportCArray::elementSize( void ) const
-{
-  if( elementType == Char || elementType == Uchar )
-  {
-    return( sizeof(char) );
-  }
-  else if( elementType == Short || elementType == Ushort )
-  {
-    return( sizeof(short) );
-  }
-  else if( elementType == Int || elementType == Uint )
-  {
-    return( sizeof(int) );
-  }
-  else if( elementType == Float )
-  {
-    return( sizeof(float) );
-  }
-  else if( elementType == Double )
-  {
-    return( sizeof(double) );
-  }
-  else
-  {
-    return(1);
-  }
-}
-
-
-char CHexBuffer::mHexBigBuffer[16]=
-{
-  '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
-};
-
-char CHexBuffer::mHexSmallBuffer[16]=
-{
-  '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
-};
-
-char CHexBuffer::mDecBuffer[10]=
-{
-  '0','1','2','3','4','5','6','7','8','9'
-};
-
-char CHexBuffer::mOctBuffer[8]=
-{
-  '0','1','2','3','4','5','6','7'
-};
-
-
-SCursorState CHexBuffer::mCursorState;
-SFileState CHexBuffer::mFileState;
-
-
-
-
-CHexBuffer::CHexBuffer( void )
-  :TQByteArray()
-{
-  mColorIndex   = 0;
-  mPrintBuf     = 0;
-  mLoadingData  = false;
-  mEditMode     = EditReplace;
-  mActiveEditor = edit_primary;
-
-  mDocumentModified = false;
-
-  #ifdef DEBUG_FIXED_SIZE
-  setMaximumSize( DEBUG_FIXED_SIZE );
-  #else
-  setMaximumSize( ~0 );
-  #endif
-
-  setDocumentSize(0);
-
-  #ifdef PRINTER_TEST
-  puts("<CHexBuffer> Printer test is activated");
-  #endif
-
-
-  setInputMode( mInputMode );
-
-  int errCode = setLayout( mLayout );
-  if( errCode != 0 )
-  {
-    return;
-  }
-  setColor( mColor );
-  setFont( mFontInfo.init() );
-  setShowCursor( true );
-  setDisableCursor( false );
-  setEditMode( EditReplace, false, false );
-  setSoundState( false, false );
-
-  mUndoLimit = 10;
-  mUndoIndex = 0;
-  mUndoList.setAutoDelete( TRUE );
-  mBookmarkList.setAutoDelete( TRUE );
-}
-
-
-CHexBuffer::~CHexBuffer( void )
-{
-  //debug("CHexBuffer::~CHexBuffer");
-  delete [] mColorIndex;
-  delete [] mPrintBuf;
-}
-
-
-
-bool CHexBuffer::hasFileName( void )
-{
-  //
-  // FIXME: Files can be called "Untitled" so this must be corrected.
-  //
-  if( mUrl.isEmpty() || mUrl.contains( i18n( "Untitled" ), false ) )
-  {
-    return( false );
-  }
-  else
-  {
-    return( true );
-  }
-}
-
-
-
-int CHexBuffer::setLayout( SDisplayLayout &layout )
-{
-  mLayout = layout;
-  mLayout.verify();
-
-  if( mLayout.primaryMode == SDisplayLayout::textOnly )
-  {
-    mActiveEditor = edit_primary;
-    setEditMode( mEditMode );
-  }
-
-  mCursor.setLineSize( mLayout.lineSize );
-  mCursor.addOffset( 0 ); // This will only reset the cell position
-
-  computeLineWidth();
-  cursorCompute();
-
-  delete [] mColorIndex; mColorIndex = 0;
-  delete [] mPrintBuf; mPrintBuf = 0;
-
-  mColorIndex = new unsigned char[ mLayout.lineSize ];
-  if( mColorIndex == 0 )
-  {
-    return( Err_NoMemory );
-  }
-  setColor( mColor );
-
-  //
-  // The 'mPrintBuf' is used to store formatted text. It is used for all
-  // print operations and must have the size of the 'mDpyState.lineSize' which
-  // is the number of bytes in one single display line.
-  //
-  mPrintBuf = new char[ mLayout.lineSize < 12 ? 12 : mLayout.lineSize ];
-  if( mPrintBuf == 0 )
-  {
-    delete [] mColorIndex; mColorIndex = 0;
-    return( Err_NoMemory );
-  }
-
-  return( Err_Success );
-}
-
-
-void CHexBuffer::setColor( SDisplayColor &color )
-{
-  mColor = color;
-
-  //
-  // Test...
-  //
-  //mColor.secondTextBg = TQt::yellow;
-  //mColor.offsetBg = TQt::lightGray;
-  //mColor.gridFg = TQt::darkCyan;
-
-  /*
-  mColor.secondTextBg = mColor.textBg;
-  mColor.offsetBg = mColor.textBg;
-  mColor.gridFg = mColor.textBg;
-  */
-
-  if( mColorIndex != 0 )
-  {
-    uint columnSize = mLayout.columnSize == 0 ? 1 : mLayout.columnSize;
-    for( uint i = 0, entry = 0;  i < mLayout.lineSize; i++ )
-    {
-      if( i > 0 && i % columnSize == 0 ) { entry = entry == 0 ? 1 : 0; }
-      mColorIndex[i] = entry;
-    }
-  }
-}
-
-void CHexBuffer::setInputMode( SDisplayInputMode &mode )
-{
-  mInputMode = mode;
-  if( mInputMode.allowResize == false && mEditMode != EditReplace )
-  {
-    setEditMode( EditReplace );
-  }
-}
-
-
-bool CHexBuffer::toggleEditor( void )
-{
-  bool changed;
-  if( mLayout.secondaryMode == SDisplayLayout::hide )
-  {
-    changed = mActiveEditor == edit_secondary ? true : false;
-    mActiveEditor = edit_primary;
-  }
-  else
-  {
-    changed = true;
-    mActiveEditor = mActiveEditor == edit_primary ?
-      edit_secondary : edit_primary;
-  }
-
-  setEditMode( mEditMode ); // Sets the cursor shapes as well
-
-  if( changed == true )
-  {
-    mCursor.resetCell();
-    cursorCompute();
-  }
-
-  return( changed );
-}
-
-
-
-
-
-
-
-bool CHexBuffer::matchWidth( uint width )
-{
-  if( documentPresent() == false || (uint)mFixedWidth >= width )
-  {
-    return( false );
-  }
-
-  width -= mFixedWidth;
-
-  uint  g = mLayout.columnSpacing == 0 ? 1 : mLayout.columnSize;
-  uint  n = g * mNumCell;
-  uint  u = mUnitWidth;
-  uint  s = mLayout.secondaryMode == SDisplayLayout::hide ? 0 : g;
-  uint  o = mLayout.columnSpacing == 0 ? 0 : mSplitWidth;
-  float x = (float)(width+o)/(float)(u*(n+s)+o);
-
-  uint lineSize = (uint)x * g;
-
-  if( mLayout.lockColumn == false )
-  {
-    //
-    // Examine if we can add one or more entries from the next column. This
-    // will make the rightmost column smaller than the rest but we will
-    // utilize as much of the available space (ie., width) as possible.
-    // (Note that the entry itself (which represents one byte of filedata)
-    // can not be splitted, eg., in binary mode the entry is eight byte
-    // wide and will not be splitted).
-    //
-    int w = (int)((float)((int)x)* (float)(u*(n+s)+o) - (float)o);
-    if( w > 0 && (uint)w < width )
-    {
-      width -= w;
-      if( width > o )
-      {
-	x = (float)(width-o) / (float)(u*(mNumCell+1));
-	lineSize += (uint)x;
-      }
-    }
-  }
-
-  if( lineSize == 0 || lineSize == mLayout.lineSize )
-  {
-    //
-    // We have to redraw all text if a change occurs so we avoid it if
-    // possible.
-    //
-    return( false );
-  }
-
-  mLayout.lineSize  = lineSize;
-  setLayout( mLayout );
-  return( true );
-}
-
-
-void CHexBuffer::setNonPrintChar( TQChar nonPrintChar )
-{
-  mFontInfo.nonPrintChar = nonPrintChar;
-}
-
-
-void CHexBuffer::setShowCursor( bool showCursor )
-{
-  mShowCursor = showCursor;
-}
-
-
-void CHexBuffer::setDisableCursor( bool disableCursor )
-{
-  mDisableCursor = disableCursor;
-}
-
-
-void CHexBuffer::setCursorShapeModifier( bool alwaysBlock, bool thickInsert )
-{
-  mCursor.setShapeModifier( alwaysBlock, thickInsert );
-  setEditMode( mEditMode );
-}
-
-void CHexBuffer::setEditMode( EEditMode editMode, bool alwaysBlock,
-			      bool thickInsert )
-{
-  mCursor.setShapeModifier( alwaysBlock, thickInsert );
-  setEditMode( editMode );
-}
-
-void CHexBuffer::setEditMode( EEditMode editMode )
-{
-  mEditMode = editMode;
-  if( mEditMode == EditInsert )
-  {
-    if( mActiveEditor == edit_primary )
-    {
-      mCursor.setShape( SCursorSpec::thin, SCursorSpec::frame, mUnitWidth,
-			mNumCell );
-    }
-    else
-    {
-      mCursor.setShape( SCursorSpec::frame, SCursorSpec::thin, mUnitWidth,
-			mNumCell );
-    }
-
-  }
-  else
-  {
-    if( mActiveEditor == edit_primary )
-    {
-      mCursor.setShape( SCursorSpec::solid, SCursorSpec::frame, mUnitWidth,
-			mNumCell );
-    }
-    else
-    {
-      mCursor.setShape( SCursorSpec::frame, SCursorSpec::solid, mUnitWidth,
-			mNumCell );
-    }
-  }
-}
-
-
-
-void CHexBuffer::setMaximumSize( uint maximumSize )
-{
-  if( maximumSize == 0 ) { maximumSize = ~0; }
-
-  mMaximumSize   = maximumSize;
-  mFixedSizeMode = maximumSize == (uint)~0 ? false : true;
-  mCursor.setFixedSizeMode( mFixedSizeMode );
-
-  if( mLayout.offsetVisible == false )
-  {
-    mOffsetSize  = 0;
-    mOffsetIndex = 0;
-    printOffset = &CHexBuffer::printDummyOffset;
-  }
-  else
-  {
-    if( mLayout.offsetMode ==  SDisplayLayout::decimal )
-    {
-      printOffset = &CHexBuffer::printDecimalOffset;
-      for( mOffsetSize=0; maximumSize > 0; mOffsetSize += 1 )
-      {
-	maximumSize = maximumSize / 10;
-      }
-      mOffsetIndex = 10 - mOffsetSize;
-    }
-    else if( mLayout.offsetMode == SDisplayLayout::hexadecimal )
-    {
-      if( mLayout.offsetUpperCase == true )
-      {
-	printOffset = &CHexBuffer::printHexadecimalBigOffset;
-      }
-      else
-      {
-	printOffset = &CHexBuffer::printHexadecimalSmallOffset;
-      }
-      for( mOffsetSize=0; maximumSize > 0; mOffsetSize += 1 )
-      {
-	maximumSize = maximumSize / 16;
-      }
-      if( mOffsetSize > 4 ) { mOffsetSize += 1; } // Space for the ':' sign
-      mOffsetIndex = 9 - mOffsetSize;
-    }
-    else
-    {
-      mLayout.offsetVisible = false;
-      mOffsetSize  = 0;
-      mOffsetIndex = 0;
-      printOffset = &CHexBuffer::printDummyOffset;
-    }
-  }
-}
-
-
-void CHexBuffer::setDocumentSize( uint size )
-{
-  if( size > mMaximumSize ) { size = mMaximumSize; }
-  mDocumentSize = size;
-  mCursor.setDocumentSize( size );
-  updateBookmarkMap(true);
-}
-
-
-void CHexBuffer::setUndoLevel( uint level )
-{
-  if( level < 10 ) { level = 10; }
-
-  if( level >= mUndoLimit )
-  {
-    mUndoLimit = level;
-    return;
-  }
-  else
-  {
-    //
-    // The maximum size decreases. If the list is larger than the the new
-    // limit, then reduce the list size starting with the oldest elements.
-    //
-    mUndoLimit = level;
-    while( mUndoList.count() >= mUndoLimit )
-    {
-      mUndoList.removeFirst();
-      mUndoIndex -= (mUndoIndex > 0 ? 1 : 0);
-    }
-  }
-}
-
-
-void CHexBuffer::setSoundState( bool inputSound, bool fatalSound )
-{
-  mInputErrorSound = inputSound;
-  mFatalErrorSound = fatalSound;
-}
-
-
-void CHexBuffer::setBookmarkVisibility( bool showInColumn, bool showInEditor )
-{
-  mShowBookmarkInOffsetColumn = showInColumn;
-  mShowBookmarkInEditor = showInEditor;
-}
-
-int CHexBuffer::writeFile( TQFile &file, CProgress &p )
-{
-  uint offset = 0;
-  uint remaining = documentSize();
-
-  do
-  {
-    const uint blockSize = TQMIN( 131072 /* == 1024 * 128 */  , remaining );
-    const int writeSize = file.writeBlock( data() + offset, blockSize );
-    if( writeSize == -1 )
-    {
-      p.finish();
-      return( Err_ReadFailed );
-    }
-    offset    += blockSize;
-    remaining -= blockSize;
-
-    if( p.expired() == true )
-    {
-      int errCode = p.step( (float)offset/(float)documentSize() );
-      if( errCode == Err_Stop && remaining > 0 )
-      {
-	p.finish();
-	return( Err_Success );
-      }
-    }
-  }
-  while( remaining > 0 );
-
-  p.finish();
-  mDocumentModified = false;
-  registerDiskModifyTime( file );
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::readFile( TQFile &file, const TQString &url, CProgress &p )
-{
-  if( resize( file.size() + 100 ) == false )
-  {
-    p.finish();
-    return( Err_NoMemory );
-  }
-
-  if( file.size() > 0 )
-  {
-    mLoadingData = true;
-    uint offset = 0;
-    uint remaining = file.size();
-    while( remaining > 0 )
-    {
-      const uint blockSize = TQMIN( 131072 /* == 1024 * 128 */  , remaining );
-      const int readSize = file.readBlock( data() + offset, blockSize );
-      if( readSize == -1 )
-      {
-        p.finish();
-	mLoadingData = false;
-	return( Err_ReadFailed );
-      }
-      for( uint i=0; i<blockSize; i++)
-      {
-	data()[offset+i] = mEncode[ (unsigned char) data()[offset+i] ];
-      }
-
-      offset    += blockSize;
-      remaining -= blockSize;
-
-      if( p.expired() == true )
-      {
-	int errCode = p.step( (float)offset/(float)file.size() );
-	if( errCode == Err_Stop && remaining > 0 )
-	{
-	  p.finish();
-	  return( Err_OperationAborted );
-	}
-      }
-    }
-    mLoadingData = false;
-  }
-
-  p.finish();
-
-  mDocumentModified = false;
-  setDocumentSize( file.size() );
-  registerDiskModifyTime( file );
-  setUrl( url );
-  computeNumLines();
-  mSelect.reset();
-  mMark.reset();
-  mUndoList.clear();
-  mUndoIndex = 0;
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::insertFile( TQFile &file, CProgress &p )
-{
-  if( file.size() == 0 )
-  {
-    p.finish();
-    return( Err_Success );
-  }
-
-  TQByteArray array( file.size() );
-  if( array.isNull() == true )
-  {
-    p.finish();
-    return( Err_NoMemory );
-  }
-
-  uint offset = 0;
-  uint remaining = file.size();
-  while( remaining > 0 )
-  {
-    const uint blockSize = TQMIN( 131072 /* == 1024 * 128 */  , remaining );
-    const int readSize = file.readBlock( array.data() + offset, blockSize );
-    if( readSize == -1 )
-    {
-      p.finish();
-      return( Err_ReadFailed );
-    }
-    for( uint i=0; i<blockSize; i++)
-    {
-      array[offset+i] = mEncode[ (unsigned char) array[offset+i] ];
-    }
-
-    offset    += blockSize;
-    remaining -= blockSize;
-
-    if( p.expired() == true )
-    {
-      int errCode = p.step( (float)offset/(float)file.size() );
-      if( errCode == Err_Stop && remaining > 0 )
-      {
-	p.finish();
-	return( Err_OperationAborted );
-      }
-    }
-  }
-
-  p.finish();
-
-  int errCode = inputAtCursor( array, 0 );
-  return( errCode );
-}
-
-
-int CHexBuffer::newFile( const TQString &url )
-{
-  if( resize( 100 ) == 0 )
-  {
-    return( Err_NoMemory );
-  }
-
-  mDocumentModified = false;
-  setDocumentSize( 0 );
-  setUrl( url );
-  computeNumLines();
-  mSelect.reset();
-
-  return( Err_Success );
-}
-
-
-void CHexBuffer::closeFile( void )
-{
-  resize(0);
-  computeNumLines();
-
-  mUndoList.clear();
-  mUndoIndex = 0;
-
-  setDocumentSize(0);
-  mDocumentModified = false;
-
-  TQString emptyUrl;
-  setUrl( emptyUrl );
-
-  mSelect.reset();
-  mMark.reset();
-
-  removeBookmark(-1); // Negative index - All bookmarks
-}
-
-
-void CHexBuffer::registerDiskModifyTime( const TQFile &file )
-{
-  TQFileInfo fileInfo( file );
-  mDiskModifyTime = fileInfo.lastModified();
-}
-
-
-
-void CHexBuffer::setFont( const SDisplayFontInfo &fontInfo )
-{
-  mFontInfo = fontInfo;
-  TQFontMetrics fm( mFontInfo.font );
-  mFontHeight = fm.height();
-  mFontAscent = fm.ascent();
-  computeLineWidth();
-
-  for( int i=0; i < 256; i++ )
-  {
-    mCharValid[i] = TQChar(i).isPrint();
-  }
-
-  /*
-  TQFontInfo info( mFontInfo.font );
-  puts("CHexBuffer mCharValid broken");
-
-  KCharset charset( info.charSet() );
-  for( int i=0; i < 256; i++ )
-  {
-    mCharValid[i] = charset.printable(i);
-  }
-  */
-}
-
-
-int CHexBuffer::setEncoding( CConversion::EMode mode, CProgress &p )
-{
-  int errCode = mEncode.convert( *this, mode, p );
-  if( errCode == Err_Success )
-  {
-    //
-    // The cursor stores the byte it is "covering", so this information
-    // must be updated.
-    //
-    cursorCompute();
-  }
-
-  return( errCode );
-}
-
-
-
-
-void CHexBuffer::computeLineWidth( void )
-{
-  TQFontMetrics fm( mFontInfo.font );
-  mUnitWidth  = fm.width( "M" );
-
-  if( mLayout.primaryMode == SDisplayLayout::textOnly )
-  {
-    mSplitWidth = 0;
-  }
-  else if( mLayout.columnCharSpace == true )
-  {
-    mSplitWidth = mUnitWidth;
-  }
-  else
-  {
-    mSplitWidth = mLayout.columnSpacing;
-  }
-
-  setMaximumSize( mMaximumSize );
-
-  if( mLayout.primaryMode == SDisplayLayout::hexadecimal )
-  {
-    mNumCell = 2;
-    mCursor.setCellWeight( 4 );
-    if( mLayout.primaryUpperCase == true )
-    {
-      printCell = &CHexBuffer::printHexadecimalBigCell;
-      inputCell = &CHexBuffer::inputHexadecimal;
-    }
-    else
-    {
-      printCell = &CHexBuffer::printHexadecimalSmallCell;
-      inputCell = &CHexBuffer::inputHexadecimal;
-    }
-  }
-  else if( mLayout.primaryMode == SDisplayLayout::decimal )
-  {
-    mNumCell  = 3;
-    printCell = &CHexBuffer::printDecimalCell;
-    inputCell = &CHexBuffer::inputDecimal;
-    mCursor.setCellWeight( 3 );
-  }
-  else if( mLayout.primaryMode == SDisplayLayout::octal )
-  {
-    mNumCell  = 3;
-    printCell = &CHexBuffer::printOctalCell;
-    inputCell = &CHexBuffer::inputOctal;
-    mCursor.setCellWeight( 3 );
-  }
-  else if( mLayout.primaryMode == SDisplayLayout::binary )
-  {
-    mNumCell  = 8;
-    printCell = &CHexBuffer::printBinaryCell;
-    inputCell = &CHexBuffer::inputBinary;
-    mCursor.setCellWeight( 1 );
-  }
-  else if( mLayout.primaryMode == SDisplayLayout::textOnly )
-  {
-    mNumCell  = 1;
-    printCell = &CHexBuffer::printAsciiCell;
-    inputCell = &CHexBuffer::inputAscii;
-    mCursor.setCellWeight( 8 );
-  }
-  else
-  {
-    mNumCell  = 2;
-    mLayout.primaryMode = SDisplayLayout::hexadecimal;
-    mLayout.primaryUpperCase = false;
-    printCell = &CHexBuffer::printHexadecimalSmallCell;
-    inputCell = &CHexBuffer::inputHexadecimal;
-    mCursor.setCellWeight( 4 );
-  }
-
-  //
-  // 'mPrimaryWidth' is the number of pixels that are needed to display a
-  // line in the primary field.
-  //
-  mPrimaryWidth = mLayout.lineSize * mNumCell * mUnitWidth;
-
-  if( mLayout.columnSpacing != 0 )
-  {
-    int numSplit = mLayout.lineSize / mLayout.columnSize;
-    numSplit -= mLayout.lineSize % mLayout.columnSize == 0 ? 1 : 0;
-    mPrimaryWidth += numSplit * mSplitWidth;
-  }
-
-  //
-  // 'mSecondaryWidth' is the number of pixels that are needed to display a
-  // line in the secondary field (there are no spaces).
-  //
-  if( mLayout.secondaryMode == SDisplayLayout::hide )
-  {
-    mSecondaryWidth = 0;
-  }
-  else
-  {
-    mSecondaryWidth = mLayout.lineSize * mUnitWidth;
-  }
-
-  //
-  // 'mLineWidth' is the total number of pixels required to display
-  // offset data, separators, primary and secondary data on a line.
-  //
-  mLineWidth = mPrimaryWidth + mSecondaryWidth + mOffsetSize * mUnitWidth;
-
-  //
-  // The 'mFixedWidth' is the number of pixels of the width that stays the
-  // same regardless of how many characters that are displayed.
-  // This entity consists of the edge margins, the inner margins and the
-  // separators.
-  //
-  mFixedWidth = mOffsetSize * mUnitWidth;
-
-  //
-  // The edge margin is always present in both ends.
-  //
-  mLineWidth  += mLayout.edgeMarginWidth * 2;
-  mFixedWidth += mLayout.edgeMarginWidth * 2;
-
-  //
-  // 'mTextStart1' is the number of pixels from the left edge where the
-  // primary field starts.
-  //
-  mTextStart1 = mLayout.edgeMarginWidth;
-  if( mLayout.offsetVisible == true )
-  {
-    int width;
-    if( mLayout.leftSeparatorWidth > 0 )
-    {
-      width = mLayout.separatorMarginWidth * 2 + mLayout.leftSeparatorWidth;
-    }
-    else
-    {
-      width = (mLayout.separatorMarginWidth * 3) / 2;
-    }
-
-    mLineWidth  += width;
-    mFixedWidth += width;
-    mTextStart1 += width + mOffsetSize * mUnitWidth;
-  }
-
-  //
-  // 'mTextStart2' is the number of pixels from the left edge where the
-  // secondary fields start.
-  //
-  mTextStart2 = mTextStart1;
-  if( mLayout.secondaryMode != SDisplayLayout::hide )
-  {
-    int width;
-    if( mLayout.rightSeparatorWidth > 0 )
-    {
-      width = mLayout.separatorMarginWidth * 2 + mLayout.rightSeparatorWidth;
-    }
-    else
-    {
-      width = (mLayout.separatorMarginWidth * 3) / 2;
-    }
-
-    mLineWidth  += width;
-    mFixedWidth += width;
-    mTextStart2 += width + mPrimaryWidth;
-  }
-
-  setEditMode( mEditMode );
-  computeNumLines();
-}
-
-
-void CHexBuffer::computeNumLines( void )
-{
-  if( mLayout.lineSize == 0 )
-  {
-    mNumLines = 1;
-  }
-  else
-  {
-    uint s = mFixedSizeMode == true ? mMaximumSize : documentSize() + 1;
-    mNumLines = s / mLayout.lineSize + (s % mLayout.lineSize ? 1 : 0);
-  }
-}
-
-
-
-void CHexBuffer::drawSelection( TQPainter &paint, TQColor &color, uint start,
-				uint stop, int sx )
-{
-  if( start >= stop ) { return; }
-  uint width = stop - start;
-
-  uint addStart, addWidth;
-  addStart = (start / mLayout.columnSize) * mSplitWidth;
-  if( width == 0 )
-  {
-    addWidth = 0;
-  }
-  else
-  {
-    uint g = mLayout.columnSize;
-    addWidth = (((start % g) + width - 1) / g) * mSplitWidth;
-  }
-
-  int offset = mTextStart1 - sx;
-  paint.fillRect( offset + start * mNumCell * mUnitWidth + addStart,
-		  0, width * mNumCell * mUnitWidth + addWidth,
-		  mFontHeight, color );
-
-  if( mLayout.secondaryMode != SDisplayLayout::hide )
-  {
-    offset = mTextStart2 - sx;
-    paint.fillRect( offset + start * mUnitWidth,
-		    0, width * mUnitWidth,
-		    mFontHeight, color );
-  }
-}
-
-
-
-
-
-void CHexBuffer::drawText( TQPainter &paint, uint line, int sx, int x1, int x2 )
-{
-  uint fileOffset = line * mLayout.lineSize;
-  if( documentPresent() == false || mLoadingData == true )
-  {
-    paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.inactiveBg );
-    return;
-  }
-
-  bool outsideText;
-  if( size() == 0 || fileOffset > documentSize() || fileOffset >= mMaximumSize)
-  {
-    outsideText = true;
-  }
-  else
-  {
-    outsideText = false;
-  }
-
-  if( (line+1) % 2 || outsideText == true )
-  {
-    paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.textBg );
-  }
-  else
-  {
-    paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.secondTextBg );
-  }
-  if( mLayout.horzGridWidth > 0 && outsideText == false )
-  {
-    paint.setPen( mColor.gridFg );
-    paint.drawLine( x1, mFontHeight, x2, mFontHeight );
-  }
-
-  if( mSelect.inside( fileOffset, mLayout.lineSize ) == true )
-  {
-    uint start = mSelect.start( fileOffset );
-    uint stop  = mSelect.stop( fileOffset, mLayout.lineSize );
-    drawSelection( paint, mColor.selectBg, start, stop, sx );
-  }
-
-  //
-  // A marked area will be displayed "above" a selcted area (given
-  // the mark background color is different)
-  //
-  if( mMark.inside( fileOffset, mLayout.lineSize ) == true )
-  {
-    uint start = mMark.start( fileOffset );
-    uint stop  = mMark.stop( fileOffset, mLayout.lineSize );
-    drawSelection( paint, mColor.markBg, start, stop, sx );
-  }
-
-  uint dataSize;
-  unsigned char *fileData;
-  if( outsideText == true )
-  {
-    if( size() == 0 )
-    {
-      return;
-    }
-    dataSize = 0;
-    fileData = 0;
-  }
-  else
-  {
-    dataSize = documentSize() - fileOffset;
-    if( dataSize > mLayout.lineSize ) { dataSize = mLayout.lineSize; }
-    fileData = (unsigned char*)&(data()[ fileOffset ]);
-  }
-
-  //
-  // Compute the offset area size. We postpose the actual drawing
-  // until we have drawn any bookmark indicators in the editor areas.
-  // because we may want to draw an indicator in the offset area as well.
-  //
-  int offset = mLayout.edgeMarginWidth - sx;
-  if( mLayout.offsetVisible == true )
-  {
-    offset += mOffsetSize * mUnitWidth;
-    if( mLayout.leftSeparatorWidth > 0 )
-    {
-      offset += mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth*2;
-    }
-    else
-    {
-      offset += (mLayout.separatorMarginWidth * 3) / 2;
-    }
-  }
-
-
-  #if 0
-  int offset = mLayout.edgeMarginWidth - sx;
-  if( mLayout.offsetVisible == true )
-  {
-    int s0 = mOffsetSize * mUnitWidth;
-    int s1 = s0 + mLayout.separatorMarginWidth + mLayout.edgeMarginWidth - sx;
-    if( x1 < s1 && x2 > 0 )
-    {
-      if( outsideText == true )
-      {
-	paint.fillRect( 0, 0, s1, lineHeight(), mColor.offsetBg );
-      }
-      else
-      {
-	//
-	// I want to display the grid here so I cant use lineHeight()
-	//
-	paint.fillRect( 0, 0, s1, mFontHeight, mColor.offsetBg );
-      }
-    }
-
-    if( x1 < offset + s0 && x2 >= offset && fileData != 0 )
-    {
-      paint.setPen( mColor.offsetFg );
-      THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
-      // ## paint.drawText(offset,mFontAscent,&mPrintBuf[mOffsetIndex],
-      // mOffsetSize);
-      paint.drawText( offset, mFontAscent, 
-		      TQString::fromLocal8Bit(&mPrintBuf[mOffsetIndex]),
-		      mOffsetSize );
-    }
-    offset += s0;
-
-    if( mLayout.leftSeparatorWidth > 0 )
-    {
-      offset += mLayout.separatorMarginWidth;
-
-      int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
-      if( x1 < offset + s2 && x2 >= offset )
-      {
-	TQPen pen( mColor.leftSeparatorFg, mLayout.leftSeparatorWidth );
-	paint.setPen( pen );
-	int center = offset + mLayout.leftSeparatorWidth/2;
-	paint.drawLine( center, 0, center, lineHeight() );
-      }
-      offset += s2;
-    }
-    else
-    {
-      offset += (mLayout.separatorMarginWidth * 3) / 2;
-    }
-  }
-  #endif
-
-
-  //
-  // Draw the primary area
-  //
-  int localOffset = offset;
-  for( uint i = 0; i < dataSize; i++ )
-  {
-    int s = mNumCell * mUnitWidth +
-      ((i+1) % mLayout.columnSize == 0) * mSplitWidth;
-    if( x1 < localOffset + s && x2 >= localOffset )
-    {
-      int flag = THIS_FPTR(printCell)( mPrintBuf, fileData[i] );
-      if( mSelect.inside( fileOffset+i ) )
-      {
-	paint.setPen( mColor.selectFg );
-      }
-      else if( mMark.inside( fileOffset+i ) )
-      {
-	paint.setPen( mColor.markFg );
-      }
-      else
-      {
-	paint.setPen( flag == 0 ? foregroundColor( i ) : mColor.nonPrintFg );
-      }
-
-      // ## paint.drawText( localOffset, mFontAscent, mPrintBuf, mNumCell );
-      paint.drawText( localOffset, mFontAscent, 
-		      TQString::fromLocal8Bit(mPrintBuf), mNumCell );
-    }
-    localOffset += s;
-
-    if( mLayout.vertGridWidth > 0 && i+1 < dataSize )
-    {
-      if( (i+1) % mLayout.columnSize == 0 )
-      {
-	paint.setPen( mColor.gridFg );
-	int x = localOffset - (mSplitWidth+1) / 2;
-	paint.drawLine( x, 0, x, mFontHeight );
-      }
-    }
-  }
-
-  //
-  // Draw the secondary area
-  //
-  offset += mPrimaryWidth;
-  if( mLayout.secondaryMode != SDisplayLayout::hide )
-  {
-    if( mLayout.rightSeparatorWidth > 0 )
-    {
-      offset += mLayout.separatorMarginWidth;
-      int s = mLayout.separatorMarginWidth + mLayout.rightSeparatorWidth;
-      if( x1 < offset + s && x2 >= offset )
-      {
-	TQPen pen( mColor.rightSeparatorFg, mLayout.rightSeparatorWidth );
-	paint.setPen( pen );
-	int center = offset + mLayout.rightSeparatorWidth/2;
-	paint.drawLine( center, 0, center, lineHeight() );
-      }
-      offset += s;
-    }
-    else
-    {
-      offset += (mLayout.separatorMarginWidth * 3) / 2;
-    }
-
-    int s = mUnitWidth;
-    for( uint i = 0; i < dataSize; i++ )
-    {
-      if( x1 < offset + s && x2 >= offset )
-      {
-	int flag = printAsciiCell( mPrintBuf, fileData[i] );
-	if( mSelect.inside( fileOffset+i ) )
-	{
-	  paint.setPen( mColor.selectFg );
-	}
-	else if( mMark.inside( fileOffset+i ) )
-	{
-	  paint.setPen( mColor.markFg );
-	}
-	else
-	{
-	  paint.setPen( flag == 0 ? mColor.secondaryFg : mColor.nonPrintFg );
-	}
-
-	// ## paint.drawText( offset, mFontAscent, mPrintBuf, 1 );
-	paint.drawText( offset, mFontAscent, 
-			TQString::fromLocal8Bit(mPrintBuf), 1 );
-      }
-      offset += s;
-    }
-  }
-
-  //
-  // Draw the bookmark identifiers on this line (if any).  We use the
-  // bitmask to minimize the number of times we try to draw the bookmarks.
-  //
-  int bookmarkPosition = 0;
-  if( mBookmarkMap.testBit(fileOffset/200) ||
-      mBookmarkMap.testBit((fileOffset+mLayout.lineSize-1)/200 ) )
-  {
-    // Returns a bookmark postion state
-    bookmarkPosition = drawBookmarks( paint, line, sx );
-  }
-
-  //
-  // Draw the offset area. We have delayed the drawing until now because
-  // it is possible to draw a bookmark indicator in this area.
-  //
-  offset = mLayout.edgeMarginWidth - sx;
-  if( mLayout.offsetVisible == true )
-  {
-    int s0 = mOffsetSize * mUnitWidth;
-    int s1 = s0 + mLayout.separatorMarginWidth + mLayout.edgeMarginWidth - sx;
-    if( x1 < s1 && x2 > 0 )
-    {
-      TQColor bg = mShowBookmarkInOffsetColumn &&
-	(bookmarkPosition & BookmarkOnLine) ?
-	mColor.bookmarkBg : mColor.offsetBg;
-      if( outsideText == true )
-      {
-	paint.fillRect( 0, 0, s1, lineHeight(), bg );
-      }
-      else
-      {
-	//
-	// I want to display the grid here so I cant use lineHeight()
-	//
-	paint.fillRect( 0, 0, s1, mFontHeight, bg );
-      }
-    }
-
-    if( x1 < offset + s0 && x2 >= offset && fileData != 0 )
-    {
-      paint.setPen( mShowBookmarkInOffsetColumn &&
-		    bookmarkPosition & BookmarkOnLine ?
-		    mColor.bookmarkFg : mColor.offsetFg );
-      THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
-      // ## paint.drawText(offset,mFontAscent,&mPrintBuf[mOffsetIndex],
-      // mOffsetSize);
-      paint.drawText( offset, mFontAscent, 
-		      TQString::fromLocal8Bit(&mPrintBuf[mOffsetIndex]),
-		      mOffsetSize );
-    }
-
-    offset += s0;
-
-    if( mLayout.leftSeparatorWidth > 0 )
-    {
-      offset += mLayout.separatorMarginWidth;
-
-      int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
-      if( x1 < offset + s2 && x2 >= offset )
-      {
-	TQPen pen( mColor.leftSeparatorFg, mLayout.leftSeparatorWidth );
-	paint.setPen( pen );
-	int center = offset + mLayout.leftSeparatorWidth/2;
-	paint.drawLine( center, 0, center, lineHeight() );
-      }
-    }
-  }
-
-
-  //
-  // If the cursors are located on the line we have drawn we redraw
-  // them unless they have been disabled.
-  //
-  if( mDisableCursor == false )
-  {
-    if( mCursor.curr.inside( fileOffset, fileOffset + mLayout.lineSize ) )
-    {
-      drawCursor( paint, line, sx, bookmarkPosition & BookmarkOnCursor );
-    }
-  }
-
-}
-
-
-
-
-void CHexBuffer::drawText( TQPainter &paint, uint line, int x1, int x2, int y,
-			   bool useBlackWhite )
-{
-  uint fileOffset = line * mLayout.lineSize;
-
-  bool outsideText;
-  if( size() == 0 || fileOffset > documentSize() || fileOffset >= mMaximumSize)
-  {
-    outsideText = true;
-  }
-  else
-  {
-    outsideText = false;
-  }
-
-  if( (line+1) % 2 || outsideText == true )
-  {
-    paint.fillRect( x1, y, x2, lineHeight(),
-		    useBlackWhite == true ? TQt::white : mColor.textBg );
-  }
-  else
-  {
-    paint.fillRect( x1, y, x2, lineHeight(),
-		    useBlackWhite == true ? TQt::white : mColor.secondTextBg );
-  }
-
-  if( mLayout.horzGridWidth > 0 && outsideText == false )
-  {
-    TQPen pen( useBlackWhite == true ? TQt::black : mColor.gridFg,
-	      mLayout.horzGridWidth );
-    paint.setPen( pen );
-    paint.drawLine( x1, y+mFontHeight, x2+x1, y+mFontHeight );
-  }
-
-  uint dataSize;
-  unsigned char *fileData;
-  if( outsideText == true )
-  {
-    if( size() == 0 )
-    {
-      return;
-    }
-    dataSize = 0;
-    fileData = 0;
-  }
-  else
-  {
-    dataSize = documentSize() - fileOffset;
-    if( dataSize > mLayout.lineSize ) { dataSize = mLayout.lineSize; }
-    fileData = (unsigned char*)&(data()[ fileOffset ]);
-  }
-
-  int offset = mLayout.edgeMarginWidth + x1;
-
-  if( mLayout.offsetVisible == true )
-  {
-    int s1 = mOffsetSize * mUnitWidth;
-    if( fileData != 0 )
-    {
-      paint.setPen( useBlackWhite == true ? TQt::black : mColor.offsetFg );
-      THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
-      // ## paint.drawText( offset, mFontAscent+y, &mPrintBuf[mOffsetIndex],
-      // mOffsetSize );
-      paint.drawText( offset, mFontAscent+y, 
-		      TQString::fromLocal8Bit(&mPrintBuf[mOffsetIndex]), 
- 		      mOffsetSize );
-    }
-    offset += s1;
-
-    if( mLayout.leftSeparatorWidth > 0 )
-    {
-      offset += mLayout.separatorMarginWidth;
-
-      int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
-      TQPen pen( useBlackWhite == true ? TQt::black : mColor.leftSeparatorFg,
-		mLayout.leftSeparatorWidth );
-      paint.setPen( pen );
-      int center = offset + mLayout.leftSeparatorWidth/2;
-      paint.drawLine( center, y, center, mFontHeight+y );
-      offset += s2;
-    }
-    else
-    {
-      offset += (mLayout.separatorMarginWidth * 3) / 2;
-    }
-  }
-
-  int localOffset = offset;
-  for( uint i = 0; i < dataSize; i++ )
-  {
-    int s = mNumCell * mUnitWidth +
-      ((i+1) % mLayout.columnSize == 0) * mSplitWidth;
-    int flag = THIS_FPTR(printCell)( mPrintBuf, fileData[i] );
-    if( useBlackWhite == true )
-    {
-      paint.setPen( TQt::black );
-    }
-    else
-    {
-      paint.setPen( flag == 0 ? foregroundColor( i ) : mColor.nonPrintFg );
-    }
-    // ## paint.drawText( localOffset, mFontAscent+y, mPrintBuf, mNumCell );
-    paint.drawText( localOffset, mFontAscent+y, 
-		    TQString::fromLocal8Bit(mPrintBuf), mNumCell );
-    localOffset += s;
-
-    if( mLayout.vertGridWidth > 0 && i+1 < dataSize )
-    {
-      if( (i+1) % mLayout.columnSize == 0 )
-      {
-	TQPen pen( useBlackWhite == true ? TQt::black : mColor.gridFg,
-		  mLayout.vertGridWidth );
-	paint.setPen( pen );
-	int x = localOffset - (mSplitWidth+1) / 2;
-	paint.drawLine( x, y, x, y+mFontHeight );
-      }
-    }
-
-  }
-
-  offset += mPrimaryWidth;
-
-  if( mLayout.secondaryMode != SDisplayLayout::hide )
-  {
-    if( mLayout.rightSeparatorWidth > 0 )
-    {
-      offset += mLayout.separatorMarginWidth;
-      int s = mLayout.separatorMarginWidth + mLayout.rightSeparatorWidth;
-      TQPen pen( useBlackWhite == true ? TQt::black : mColor.rightSeparatorFg,
-		mLayout.rightSeparatorWidth );
-      paint.setPen( pen );
-      int center = offset + mLayout.rightSeparatorWidth/2;
-      paint.drawLine( center, y, center, mFontHeight+y );
-      offset += s;
-    }
-    else
-    {
-      offset += (mLayout.separatorMarginWidth * 3) / 2;
-    }
-
-
-    int s = mUnitWidth;
-    for( uint i = 0; i < dataSize; i++ )
-    {
-      int flag = printAsciiCell( mPrintBuf, fileData[i] );
-      if( useBlackWhite == true )
-      {
-	paint.setPen( TQt::black );
-      }
-      else
-      {
-	paint.setPen( flag == 0 ? mColor.secondaryFg : mColor.nonPrintFg );
-      }
-      // ## paint.drawText( offset, mFontAscent+y, mPrintBuf, 1 );
-      paint.drawText( offset, mFontAscent+y, 
-		      TQString::fromLocal8Bit(mPrintBuf), 1 );
-      offset += s;
-    }
-  }
-
-}
-
-
-int CHexBuffer::headerHeight( TQPainter &paint )
-{
-  TQFont font( paint.font() );
-  paint.setFont( TDEGlobalSettings::generalFont() );
-  const TQFontMetrics &fm = paint.fontMetrics();
-
-  int height = fm.height();
-  paint.setFont( font );
-  return( height );
-}
-
-int CHexBuffer::headerMargin( TQPainter &paint )
-{
-  TQFont font( paint.font() );
-  paint.setFont( TDEGlobalSettings::generalFont() );
-  const TQFontMetrics &fm = paint.fontMetrics();
-
-  int margin = fm.height() / 2;
-  paint.setFont( font );
-  return( margin );
-}
-
-
-void CHexBuffer::drawHeader( TQPainter &paint, int sx, int width, int y,
-			     bool isFooter, const SPageHeader &header,
-			     const SPagePosition &position )
-{
-  TQFont font( paint.font() );
-  paint.setFont( TDEGlobalSettings::generalFont() );
-  const TQFontMetrics &fm = paint.fontMetrics();
-
-  paint.fillRect( sx, y, width, fm.height(), TQt::white );
-  paint.setPen( TQt::black );
-  if( header.line == SPageHeader::SingleLine )
-  {
-    if( isFooter == false )
-    {
-      paint.drawLine( sx, y+fm.height(), sx+width, y+fm.height() );
-    }
-    else
-    {
-      paint.drawLine( sx, y, sx+width, y );
-    }
-  }
-  else if( header.line == SPageHeader::Rectangle )
-  {
-    paint.drawRect( sx, y, width, fm.height() );
-  }
-
-  int pos[3] =
-  {
-    TQPainter::AlignLeft, TQPainter::AlignHCenter, TQPainter::AlignRight
-  };
-
-  TQString msg;
-  for( int i=0; i<3; i++ )
-  {
-    if( header.pos[i] == SPageHeader::DateTime )
-    {
-      TQDateTime datetime;
-      datetime.setTime_t( position.now );
-      msg = TDEGlobal::locale()->formatDateTime(datetime);
-    }
-    else if( header.pos[i] == SPageHeader::PageNumber )
-    {
-      msg = i18n("Page %1 of %2")
-        .arg(TDEGlobal::locale()->formatNumber(position.curPage, 0))
-        .arg(TDEGlobal::locale()->formatNumber(position.maxPage, 0));
-    }
-    else if( header.pos[i] == SPageHeader::FileName )
-    {
-      msg = mUrl;
-    }
-    else
-    {
-      continue;
-    }
-
-    if( 0 && pos[i] == TQPainter::AlignRight )
-    {
-      //const TQFontMetrics &f = TQFontMetrics( TDEGlobalSettings::generalFont() );
-      //TQRect r = paint.boundingRect(sx, y, width, fm.height(), pos[i], msg );
-      //printf("R: %d, %d, %d, %d\n", r.x(), r.y(), r.width(), r.height() );
-
-      int x = sx + width - /*r.width();*/ fm.width(msg);
-      paint.drawText( x, y+fm.height(), msg );
-      //printf("paint at %d\n", x );
-    }
-    else
-    {
-      paint.drawText( sx, y, width, fm.height(), pos[i], msg );
-    }
-  }
-
-  //
-  // restore original font.
-  //
-  paint.setFont( font );
-}
-
-
-
-
-int CHexBuffer::drawBookmarks( TQPainter &paint, uint line, int startx )
-{
-  if( documentPresent() == false || mLoadingData == true )
-  {
-    return( 0 );
-  }
-
-  uint start = line*mLayout.lineSize;
-  uint stop  = start+mLayout.lineSize;
-  TQColor bg  = mColor.bookmarkBg;
-  TQColor fg  = mColor.bookmarkFg;
-
-  int bookmarkPosition = 0;
-
-  for( SCursorOffset *c=mBookmarkList.first(); c!=0; c=mBookmarkList.next() )
-  {
-    if( c->offset >= start && c->offset < stop )
-    {
-      int x = c->offset - start;
-      int x1 = mTextStart1 + x * mUnitWidth * mNumCell;
-      x1 += (x / mLayout.columnSize) * mSplitWidth;
-      int x2 = mTextStart2 + x * mUnitWidth;
-
-      bookmarkPosition |= BookmarkOnLine;
-
-      if( mShowBookmarkInEditor == false )
-      {
-	continue;
-      }
-
-      uint offset = line*mLayout.lineSize+x;
-      if( offset == mCursor.curr.offset )
-      {
-	bookmarkPosition |= BookmarkOnCursor;
-      }
-
-      if( mSelect.inside( offset ) || mMark.inside( offset ) )
-      {
-	paint.fillRect( x1-startx, 2, mUnitWidth*mNumCell, mFontHeight-4, bg );
-	if( mLayout.secondaryMode != SDisplayLayout::hide )
-	{
-	  paint.fillRect( x2-startx, 2, mUnitWidth, mFontHeight-4, bg );
-	}
-      }
-      else
-      {
-	paint.fillRect( x1-startx, 1, mUnitWidth*mNumCell, mFontHeight-2, bg );
-	if( mLayout.secondaryMode != SDisplayLayout::hide )
-	{
-	  paint.fillRect( x2-startx, 1, mUnitWidth, mFontHeight-2, bg );
-	}
-      }
-
-      unsigned char c = (data()[ line*mLayout.lineSize+x]);
-
-      int flag = THIS_FPTR(printCell)( mPrintBuf, c );
-      paint.setPen( flag == 0 ? fg : mColor.nonPrintFg );
-      // ## paint.drawText( x1-startx, mFontAscent, mPrintBuf, mNumCell );
-      paint.drawText( x1-startx, mFontAscent, 
-		      TQString::fromLocal8Bit(mPrintBuf), mNumCell );
-      if( mLayout.secondaryMode != SDisplayLayout::hide )
-      {
-	flag = printAsciiCell( mPrintBuf, c );
-	paint.setPen( flag == 0 ? fg : mColor.nonPrintFg );
-	// ## paint.drawText( x2-startx, mFontAscent, mPrintBuf, 1 );	
-	paint.drawText( x2-startx, mFontAscent, 
-			TQString::fromLocal8Bit(mPrintBuf), 1 );
-      }
-    }
-  }
-
-  return bookmarkPosition;
-}
-
-
-
-void CHexBuffer::drawCursor( TQPainter &paint, uint line, int startx,
-			     bool onBookmark )
-{
-  if( documentPresent() == false || mLoadingData == true )
-  {
-    return;
-  }
-
-  SCursorSpec &c = mCursor.curr;
-
-  //
-  // Draw the cursor in primary edit area.
-  //
-  TQColor bg, fg;
-  bool useFg;
-  if( mMark.inside( c.offset ) == true )
-  {
-    bg = mColor.markBg;
-    fg = mSelect.inside( c.offset ) ? mColor.selectFg : mColor.markFg;
-    useFg = true;
-  }
-  else if( mSelect.inside( c.offset ) == true )
-  {
-    bg = mColor.selectBg;
-    fg = mColor.selectFg;
-    useFg = true;
-  }
-  else
-  {
-    bg = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
-    fg = foregroundColor( c.offset % mLayout.lineSize );
-    useFg = false; // Can be true later.
-  }
-
-  TQColor cbg = mColor.cursorBg;
-  TQColor cfg = mColor.cursorFg;
-
-  //
-  // Fill in the general backround color
-  //
-  paint.fillRect( c.x1 - startx, 0, mUnitWidth, mFontHeight, bg );
-  if( onBookmark == true )
-  {
-    int w = mUnitWidth * (mNumCell-c.cell); // Rest of cell
-    if( useFg == true )
-    {
-      paint.fillRect( c.x1-startx, 2, w, mFontHeight-4, mColor.bookmarkBg );
-    }
-    else
-    {
-      paint.fillRect( c.x1-startx, 1, w, mFontHeight-2, mColor.bookmarkBg );
-    }
-  }
-
-  //
-  // Draw the cursor shape
-  //
-  bool transparent = false;
-  if( mActiveEditor == edit_primary )
-  {
-    if( mShowCursor == true ) // Cursor blink on
-    {
-      if( c.mPrimaryShape == SCursorSpec::thin )
-      {
-	paint.setPen( cbg );
-	int center = c.x1 - startx - 1;
-	transparent = true;
-	
-	if( c.thickState == true )
-	{
-	  paint.drawLine( center, 0, center, mFontHeight - 1 );
-	  paint.drawLine( center+1, 0, center+1, mFontHeight - 1 );
-	}
-	else
-	{
-	  paint.drawLine( center, 0, center, mFontHeight - 1 );
-	  paint.drawLine( center-2, 0, center+2, 0 );
-	  paint.drawLine( center-2, mFontHeight-1, center+2, mFontHeight-1 );
-	}
-      }
-      else // Solid block shape
-      {
-	paint.fillRect( c.x1 - startx, 0, mUnitWidth, mFontHeight, cbg );
-	useFg = true;
-	fg = cfg;
-      }
-    }
-  }
-  else
-  {
-    transparent = true;
-    paint.setPen( cbg );
-    paint.drawRect( c.x1 - startx, 0, mUnitWidth*mNumCell, mFontHeight );
-  }
-
-  //
-  // Draw the text on the cursor position and to the end of the cell.
-  //
-  if( c.offset < documentSize() )
-  {
-    int flag = THIS_FPTR(printCell)( mPrintBuf, (unsigned char)c.data );
-    if( onBookmark == true )
-    {
-      // Inside bookmark. Draw text with bookmark foreground.
-      paint.setPen( mColor.bookmarkFg );
-      // ## paint.drawText( c.x1-startx, mFontAscent, &mPrintBuf[c.cell],
-      // mNumCell-c.cell );
-      paint.drawText( c.x1-startx, mFontAscent, 
-		      TQString::fromLocal8Bit(&mPrintBuf[c.cell]), 
- 		      mNumCell-c.cell );
-    }
-
-    if( transparent == false || onBookmark == false )
-    {
-      paint.setPen( flag == 0 || useFg == true ? fg : mColor.nonPrintFg );
-      // ## paint.drawText( c.x1 - startx, mFontAscent, &mPrintBuf[c.cell], 1);
-      paint.drawText( c.x1 - startx, mFontAscent, 
-		      TQString::fromLocal8Bit(&mPrintBuf[c.cell]), 1 );
-    }
-  }
-
-  //
-  // Draw the cursor in secodary edit area.
-  //
-  if( mLayout.secondaryMode == SDisplayLayout::hide )
-  {
-    return;
-  }
-
-
-  if( mMark.inside( c.offset ) == true )
-  {
-    bg = mColor.markBg;
-    fg = mSelect.inside( c.offset ) ? mColor.selectFg : mColor.markFg;
-    useFg = true;
-  }
-  else if( mSelect.inside( c.offset ) == true )
-  {
-    bg = mColor.selectBg;
-    fg = mColor.selectFg;
-    useFg = true;
-  }
-  else
-  {
-    bg = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
-    fg = mColor.secondaryFg;
-    useFg = false; // Can be true later.
-  }
-
-
-
-  //
-  // Fill in the general backround color
-  //
-  if( onBookmark == true )
-  {
-    if( useFg == true )
-    {
-      paint.fillRect( c.x2-startx, 2, mUnitWidth, mFontHeight-4,
-		      mColor.bookmarkBg );
-    }
-    else
-    {
-      paint.fillRect( c.x2-startx, 1, mUnitWidth, mFontHeight-2,
-		      mColor.bookmarkBg );
-    }
-  }
-  else
-  {
-    paint.fillRect( c.x2 - startx, 0, mUnitWidth, mFontHeight, bg );
-  }
-
-  //
-  // Draw the cursor shape
-  //
-  transparent = false;
-  if( mActiveEditor == edit_secondary )
-  {
-    if( mShowCursor == true ) // Cursor blink on
-    {
-      if( c.mSecondaryShape == SCursorSpec::thin )
-      {
-	paint.setPen( cbg );
-	int center = c.x2 - startx - 1;
-	transparent = true;
-
-	if( c.thickState == true )
-	{
-	  paint.drawLine( center, 0, center, mFontHeight - 1 );
-	  paint.drawLine( center+1, 0, center+1, mFontHeight - 1 );
-	}
-	else
-	{
-	  paint.drawLine( center, 0, center, mFontHeight - 1 );
-	  paint.drawLine( center-2, 0, center+2, 0 );
-	  paint.drawLine( center-2, mFontHeight-1, center+2, mFontHeight-1 );
-	}
-      }
-      else
-      {
-	paint.fillRect( c.x2 - startx, 0, mUnitWidth, mFontHeight, cbg );
-	useFg = true;
-	fg = cfg;
-      }
-    }
-  }
-  else
-  {
-    transparent = true;
-    paint.setPen( cbg );
-    paint.drawRect( c.x2 - startx, 0, mUnitWidth, mFontHeight );
-  }
-
-  //
-  // Draw the text on the cursor position and to the end of the cell.
-  //
-  if( c.offset < documentSize() )
-  {
-    int flag = printAsciiCell( mPrintBuf, (unsigned char)c.data );
-    if( onBookmark == true )
-    {
-      // Inside bookmark. Draw text with bookmark foreground.
-      paint.setPen( flag == 0 ? mColor.bookmarkFg : mColor.nonPrintFg );
-      // ## paint.drawText( c.x2-startx, mFontAscent, mPrintBuf, 1 );
-      paint.drawText( c.x2-startx, mFontAscent, 
-		      TQString::fromLocal8Bit(mPrintBuf), 1 );
-    }
-    if( transparent == false || onBookmark == false )
-    {
-      paint.setPen( flag == 0 || useFg == true ? fg : mColor.nonPrintFg );
-      // ## paint.drawText( c.x2 - startx, mFontAscent, mPrintBuf, 1 );
-      paint.drawText( c.x2 - startx, mFontAscent, 
-		      TQString::fromLocal8Bit(mPrintBuf), 1 );
-    }
-  }
-
-}
-
-
-
-
-void CHexBuffer::cursorReset( void )
-{
-  mCursor.reset();
-  cursorCompute();
-}
-
-void CHexBuffer::cursorCompute( void )
-{
-  mCursor.prev = mCursor.curr;
-
-  if( mCursor.next.offset >= documentSize() )
-  {
-    if( documentSize() == 0 )
-    {
-      mCursor.curr.offset  = 0;
-      mCursor.curr.data    = 0;
-      mCursor.curr.cell    = 0;
-      mCursor.curr.maxCell = mNumCell;
-
-      int x = mCursor.curr.offset % mLayout.lineSize;
-      mCursor.curr.x1 = mTextStart1;
-      mCursor.curr.x1 += (x * mNumCell + mCursor.curr.cell) * mUnitWidth;
-      mCursor.curr.x1 += (x / mLayout.columnSize) * mSplitWidth;
-      mCursor.curr.x2 = mTextStart2 + x * mUnitWidth;
-      mCursor.curr.y  = (mCursor.curr.offset/mLayout.lineSize) *
-	(mFontHeight+mLayout.horzGridWidth);
-      return;
-
-    }
-    if( mFixedSizeMode == true )
-    {
-      uint max = mMaximumSize - 1;
-      uint off = mCursor.curr.offset % mLayout.lineSize;
-      uint end = max % mLayout.lineSize;
-      if( off > end )
-      {
-	uint diff = off - end;
-	if( max + diff > mLayout.lineSize )
-	{
-	  mCursor.next.offset = max + diff - mLayout.lineSize;
-	}
-	else
-	{
-	  mCursor.next.offset = 0;
-	}
-      }
-      else
-      {
-	uint diff = end - off;
-	mCursor.next.offset = diff > max ? max : max - diff;
-      }
-    }
-    else
-    {
-      mCursor.next.offset = documentSize();
-    }
-  }
-
-  mCursor.curr.offset  = mCursor.next.offset;
-  mCursor.curr.data    = data()[ mCursor.curr.offset ];
-  mCursor.curr.cell    = mCursor.next.cell;
-  mCursor.curr.maxCell = mNumCell;
-
-  int x = mCursor.curr.offset % mLayout.lineSize;
-
-  mCursor.curr.x1 = mTextStart1;
-  mCursor.curr.x1 += (x * mNumCell + mCursor.curr.cell) * mUnitWidth;
-  mCursor.curr.x1 += (x / mLayout.columnSize) * mSplitWidth;
-  mCursor.curr.x2 = mTextStart2 + x * mUnitWidth;
-  mCursor.curr.y  = (mCursor.curr.offset/mLayout.lineSize) *
-    (mFontHeight + mLayout.horzGridWidth);
-}
-
-
-bool CHexBuffer::setCursorPosition( int x, int y, bool init, bool cellLevel )
-{
-  if( documentPresent() == false )
-  {
-    return( false );
-  }
-
-  uint line  = y < 0 ? 0 : y / lineHeight();
-  uint entry = 0;
-  int  bit   = 7;
-
-  if( init == false )
-  {
-    if( mCursor.area() == edit_primary )
-    {
-      int start = mTextStart1;
-      if( x < start - (int)mLayout.separatorMarginWidth )
-      {
-	return( false );
-      }
-      else
-      {
-	int stop  = mTextStart1 + mPrimaryWidth + mLayout.separatorMarginWidth;
-	int width = mNumCell * mUnitWidth;
-	int space = mSplitWidth;
-
-	for( int position = start, i=0; position < stop; i++ )
-	{
-	  if( x <= position + width )
-	  {
-	    if( cellLevel == true )
-	    {
-	      while( bit > 0 )
-	      {
-		if( x <= position + mUnitWidth )
-		{
-		  break;
-		}
-		bit -= mCursor.cellWeight();
-		position += mUnitWidth;
-	      }
-	    }
-	    break;
-	  }
-	  position += width + (((i+1) % mLayout.columnSize) ? 0 : space);
-	  entry    += 1;
-	}
-      }
-    }
-    else
-    {
-      int start = mTextStart2;
-      if( x < start - (int)mLayout.separatorMarginWidth ||
-	  mLayout.secondaryMode == SDisplayLayout::hide )
-      {
-	return( false );
-      }
-      int stop  = mTextStart2 + mLayout.lineSize * mUnitWidth;
-      int width = mUnitWidth * 1;
-      int space = 0;
-
-      for( int position = start; position < stop; )
-      {
-	if( x <= position + width )
-	{
-	  break;
-	}
-	position += width + space;
-	entry    += 1;
-      }
-    }
-  }
-  else
-  {
-    int start = mTextStart1;
-    int stop  = start + mPrimaryWidth + mLayout.separatorMarginWidth;
-    if( x >= start - (int)mLayout.separatorMarginWidth && x <= stop )
-    {
-      int width = mUnitWidth * mNumCell;
-      int space = mSplitWidth;
-
-      for( int position = start, i=0; position < stop; i++ )
-      {
-	if( x <= position + width )
-	{
-	  if( cellLevel == true )
-	  {
-	    while( bit > 0 )
-	    {
-	      if( x <= position + mUnitWidth )
-	      {
-		break;
-	      }
-	      bit -= mCursor.cellWeight();
-	      position += mUnitWidth;
-	    }
-	  }
-	  break;
-	}
-	position += width + (((i+1) % mLayout.columnSize) ? 0 : space);
-	entry    += 1;
-      }
-
-      mActiveEditor = edit_primary;
-    }
-    else if( mLayout.secondaryMode != SDisplayLayout::hide )
-    {
-      start = mTextStart2;
-      stop  = mTextStart2 + mLayout.lineSize * mUnitWidth +
-	mLayout.edgeMarginWidth;
-      if( x >= start - (int)mLayout.separatorMarginWidth && x <= stop )
-      {
-	int width = mUnitWidth * 1;
-	int space = 0;
-
-	for( int position = start; position < stop; )
-	{
-	  if( x <= position + width )
-	  {
-	    break;
-	  }
-	  position += width + space;
-	  entry    += 1;
-	}
-
-	mActiveEditor = edit_secondary;
-      }
-    }
-    else
-    {
-      return( false );
-    }
-  }
-
-  uint offset = line * mLayout.lineSize + entry;
-  if( offset > documentSize() )
-  {
-    offset = documentSize();
-  }
-
-  mCursor.setOffset( offset );
-  mCursor.setBit( bit < 0 ? 0 : bit );
-
-  cursorCompute();
-  if( mActiveEditor != mCursor.area() )
-  {
-    mCursor.setArea( mActiveEditor );
-    setEditMode( mEditMode );
-  }
-
-  return( true );
-}
-
-
-
-
-bool CHexBuffer::inputAtCursor( TQChar c )
-{
-  if( documentPresent() == false || mInputMode.noInput() == true )
-  {
-    if( mInputMode.noInput() == true ) { inputSound(); }
-    return( false );
-  }
-
-  if( c.isPrint() == false )
-  {
-    inputSound();
-    return( false );
-  }
-
-  unsigned char dest;
-  bool insert;
-  if( mEditMode == EditReplace || mCursor.curr.cell > 0 )
-  {
-    if( mCursor.curr.offset >= documentSize() )
-    {
-      dest   = 0;
-      insert = true;
-    }
-    else
-    {
-      dest   = (unsigned char)data()[ mCursor.curr.offset ];
-      insert = false;
-    }
-  }
-  else
-  {
-    dest   = 0;
-    insert = true;
-  }
-
-  if( insert == true && mInputMode.allowResize == false )
-  {
-    inputSound();
-    return( false );
-  }
-
-  if( mActiveEditor == edit_primary )
-  {
-    // ## if( THIS_FPTR(inputCell)( &dest, c.latin1(), mCursor.curr.cell ) 
-    //== false )
-    if( THIS_FPTR(inputCell)( &dest, TQString(c).local8Bit()[0], 
-			      mCursor.curr.cell ) == false )
-    {
-      inputSound();
-      return( false );
-    }
-  }
-  else if( mActiveEditor == edit_secondary )
-  {
-    // ## if( inputAscii( &dest, c.latin1(), mCursor.curr.cell ) == false )
-    if( !inputAscii( &dest, TQString(c).local8Bit()[0], mCursor.curr.cell ) )
-    {
-      inputSound();
-      return( false );
-    }
-  }
-  else
-  {
-    return( false );
-  }
-
-  recordStart( mCursor );
-  recordReplace( mCursor, insert == true ? 0 : 1, (char*)&dest, 1 );
-  cursorRight( cursorPrimaryEdit() );
-  recordEnd( mCursor );
-
-  computeNumLines();
-  return( true );
-}
-
-
-
-int CHexBuffer::inputAtCursor( const TQByteArray &buf, uint oldSize )
-{
-  if( documentPresent() == false )
-  {
-    return( Err_NoActiveDocument );
-  }
-  if( buf.isNull() == true )
-  {
-    return( Err_EmptyArgument );
-  }
-
-  if( mInputMode.noInput() == true )
-  {
-    inputSound();
-    return( Err_WriteProtect );
-  }
-
-  if( mInputMode.allowResize == false )
-  {
-    inputSound();
-    return( Err_NoResize );
-  }
-
-  recordStart( mCursor );
-  recordReplace( mCursor, oldSize, (char*)&buf[0], buf.size() );
-  cursorStep( buf.size(), true, false );
-  recordEnd( mCursor );
-
-  computeNumLines();
-  return( Err_Success );
-}
-
-
-bool CHexBuffer::removeAtCursor( bool beforeCursor )
-{
-  if( documentPresent() == false )
-  {
-    return( false );
-  }
-
-  if( mInputMode.noInput() == true || mInputMode.allowResize == false )
-  {
-    inputSound();
-    return( false );
-  }
-
-
-  if( mSelect.valid() == true )
-  {
-    cutSelection();
-    return( true );
-  }
-
-
-  if( beforeCursor == true )
-  {
-    if( mCursor.curr.offset == 0 )
-    {
-      return( false );
-    }
-
-    recordStart( mCursor );
-    cursorLeft( false );
-    recordReplace( mCursor, 1, 0, 0 );
-    recordEnd( mCursor );
-
-    computeNumLines();
-    return( true );
-  }
-  else
-  {
-    if( mCursor.curr.offset + 1 > documentSize() )
-    {
-      return( false );
-    }
-
-    recordStart( mCursor );
-    recordReplace( mCursor, 1, 0, 0 );
-    recordEnd( mCursor );
-
-    computeNumLines();
-    return( true );
-  }
-}
-
-
-
-int CHexBuffer::locateRange(const SExportRange &range, uint &start, uint &stop)
-{
-  if( range.mode == SExportRange::All )
-  {
-    start = 0;
-    stop  = documentSize();
-  }
-  else if( range.mode == SExportRange::Selection )
-  {
-    if( mSelect.valid() == false )
-    {
-      return( Err_NoSelection );
-    }
-    start = mSelect.curr.start;
-    stop  = mSelect.curr.stop;
-  }
-  else if( range.mode == SExportRange::Range )
-  {
-    start = range.start;
-    stop  = range.stop;
-  }
-  else
-  {
-    return( Err_IllegalMode );
-  }
-
-  if( start >= stop )
-  {
-    return( Err_IllegalRange );
-  }
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::exportText( const SExportText &ex, CProgress &p )
-{
-  uint start, stop;
-  int errCode = locateRange( ex.range, start, stop );
-  if( errCode != Err_Success )
-  {
-    p.finish();
-    return( errCode );
-  }
-
-  TQFile file( ex.destFile );
-  if( file.open( IO_WriteOnly ) == false )
-  {
-    p.finish();
-    return( Err_OpenWriteFailed );
-  }
-
-  uint startLine = calculateLine( start );
-  if( startLine >= (uint)numLines() )
-  {
-    startLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-
-  uint stopLine  = calculateLine( stop );
-  if( stopLine >= (uint)numLines() )
-  {
-    stopLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-
-  uint totalSize   = stopLine - startLine + 1;
-  uint remaining   = stopLine - startLine + 1;
-  uint bytePerLine = mOffsetSize + 1 + (mNumCell + 2)*mLayout.lineSize + 1;
-  uint linePerStep = 20;
-
-  TQByteArray array( bytePerLine * linePerStep + 1 ); // Line is 0 terminated
-  if( array.isEmpty() == true )
-  {
-    p.finish();
-    return( Err_NoMemory );
-  }
-
-  while( remaining > 0 )
-  {
-    uint blockSize = remaining > linePerStep ? linePerStep : remaining;
-    uint printSize = 0;
-
-    for( uint i = 0; i < blockSize; i++, startLine++ )
-    {
-      printSize += printLine( &array[printSize], startLine );
-    }
-
-    int writeSize = file.writeBlock( &array[0], printSize );
-    if( writeSize == -1 )
-    {
-      p.finish();
-      return( Err_WriteFailed );
-    }
-
-    remaining -= blockSize;
-    if( p.expired() == true )
-    {
-      int errCode = p.step( (float)(totalSize-remaining)/(float)totalSize );
-      if( errCode == Err_Stop && remaining > 0 )
-      {
-	p.finish();
-	return( Err_OperationAborted );
-      }
-    }
-  }
-
-  p.finish();
-  return( Err_Success );
-}
-
-
-
-int CHexBuffer::exportHtml( const SExportHtml &ex, CProgress &p )
-{
-  uint start, stop;
-  int errCode = locateRange( ex.range, start, stop );
-  if( errCode != Err_Success )
-  {
-    p.finish();
-    return( errCode );
-  }
-
-  uint startLine = calculateLine( start );
-  if( startLine >= (uint)numLines() )
-  {
-    startLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-
-  uint stopLine  = calculateLine( stop );
-  if( stopLine >= (uint)numLines() )
-  {
-    stopLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-
-  uint totalSize = stopLine - startLine + 1;
-  uint remaining = stopLine - startLine + 1;
-
-  if( ex.linePerPage == 0 )
-  {
-    p.finish();
-    return( Err_IllegalArgument );
-  }
-
-  uint linePerPage = ex.linePerPage;
-  uint numFiles    = remaining/linePerPage + (remaining%linePerPage ? 1 : 0);
-  uint fileCount   = 0;
-
-  TQStringList fileNames, offsets;
-  TQString name, offset;
-  for( uint i=0; i < numFiles; i++ )
-  {
-    name.sprintf( "%08d.html", i+1 );
-    fileNames.append( TQString("%1/%2%3").arg(ex.package).arg(ex.prefix).
-		      arg(name));
-  }
-  name.sprintf( "%08d.html", 0 );
-  TQString tocName =TQString("%1/%2%3").arg(ex.package).arg(ex.prefix).arg(name);
-
-  TQString linkName;
-  if( ex.symLink == true )
-  {
-    linkName = TQString("%1/%2").arg(ex.package).arg("index.html");
-  }
-
-  while( remaining  > 0 )
-  {
-    THIS_FPTR(printOffset)( mPrintBuf, startLine*mLayout.lineSize );
-    mPrintBuf[mOffsetSize]=0;
-    offset.sprintf("[%s]", mPrintBuf );
-
-    uint pageSize = remaining > linePerPage ? linePerPage : remaining;
-    printHtmlDataPage( tocName, fileNames, fileCount, ex, startLine, pageSize);
-
-    remaining -= pageSize;
-    startLine += pageSize;
-    fileCount += 1;
-
-    THIS_FPTR(printOffset)( mPrintBuf, (startLine-1)*mLayout.lineSize );
-    mPrintBuf[mOffsetSize]=0;
-    offset += TQString(" %1 [%2]").arg(i18n("to")).arg(mPrintBuf);
-    offsets.append(offset);
-
-    if( p.expired() == true )
-    {
-      int errCode = p.step( (float)(totalSize-remaining)/(float)totalSize );
-      if( errCode == Err_Stop && remaining > 0 )
-      {
-	printHtmlTocPage( tocName, linkName, fileNames, offsets, fileCount );
-	p.finish();
-	return( Err_OperationAborted );
-      }
-    }
-  }
-
-  printHtmlTocPage( tocName, linkName, fileNames, offsets, fileCount );
-
-  p.finish();
-  return( Err_Success );
-}
-
-
-int CHexBuffer::exportCArray( const SExportCArray &ex, CProgress &p )
-{
-  uint start, stop;
-  int errCode = locateRange( ex.range, start, stop );
-  if( errCode != Err_Success )
-  {
-    p.finish();
-    return( errCode );
-  }
-
-  TQFile file( ex.destFile );
-  if( file.open( IO_WriteOnly ) == false )
-  {
-    p.finish();
-    return( Err_OpenWriteFailed );
-  }
-
-  uint startLine = calculateLine( start );
-  if( startLine >= (uint)numLines() )
-  {
-    startLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-
-  uint stopLine  = calculateLine( stop );
-  if( stopLine >= (uint)numLines() )
-  {
-    stopLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-
-  uint elementSize = ex.elementSize();
-  uint elementOnThisLine = 0;
-
-  TQTextStream dest( &file );
-
-  dest << ex.variableName(stop-start).latin1() << "={" << endl;
-  for( unsigned int i=start; i<stop; i+=elementSize )
-  {
-    dest << ex.printFormatted( (const char*)&data()[i], stop-i );
-    if( i + elementSize < stop )
-    {
-      dest << ",";
-    }
-
-    if( ++elementOnThisLine >= ex.elementPerLine )
-    {
-      dest << endl;
-      elementOnThisLine = 0;
-    }
-
-    if( p.expired() == true )
-    {
-      int errCode = p.step( (float)(i-start)/(float)(stop-start) );
-      if( errCode == Err_Stop && (i+elementSize) < stop)
-      {
-	p.finish();
-	return( Err_OperationAborted );
-      }
-    }
-  }
-  dest << "};" << endl;
-
-  p.finish();
-  return( Err_Success );
-}
-
-
-
-
-
-
-
-int CHexBuffer::copySelectedText( TQByteArray &array, int columnSegment )
-{
-  SExportRange range;
-  range.mode = SExportRange::Selection;
-  return( copyText( array, range, columnSegment ) );
-}
-
-
-int CHexBuffer::copyAllText( TQByteArray &array )
-{
-  SExportRange range;
-  range.mode = SExportRange::All;
-  return( copyText( array, range, VisibleColumn ) );
-}
-
-
-int CHexBuffer::copyText( TQByteArray &array, const SExportRange &range,
-			  int columnSegment )
-{
-  uint start, stop;
-  int errCode = locateRange( range, start, stop );
-  if( errCode != Err_Success )
-  {
-    return( errCode );
-  }
-
-  uint startLine = calculateLine( start );
-  uint stopLine  = calculateLine( stop );
-  if( startLine >= (uint)numLines() )
-  {
-    startLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-  if( stopLine >= (uint)numLines() )
-  {
-    stopLine = numLines() == 0 ? 0 : numLines() - 1;
-  }
-
-  uint bytePerLine = mOffsetSize + 1 + (mNumCell + 2)*mLayout.lineSize + 1;
-  uint size = (stopLine - startLine + 1)*bytePerLine;
-  if( array.resize( size+1 ) == false )
-  {
-    return( Err_NoMemory );
-  }
-
-  if( columnSegment == VisibleColumn )
-  {
-    columnSegment = PrimaryColumn; // Always visible
-    if( mLayout.offsetVisible == true )
-    {
-      columnSegment |= OffsetColumn;
-    }
-    if( mLayout.secondaryMode != SDisplayLayout::hide )
-    {
-      columnSegment |= SecondaryColumn;
-    }
-  }
-
-  uint offset = 0;
-  for( uint i = startLine; i <= stopLine; i++ )
-  {
-    offset += printLine( &array[offset], i, columnSegment );
-  }
-  array[size] = 0;
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::copySelectedData( TQByteArray &array )
-{
-  uint start = mSelect.start();
-  uint stop  = mSelect.stop();
-
-  if( mSelect.valid() == false || start >= stop )
-  {
-    return( Err_IllegalRange );
-  }
-
-  uint size = stop - start;
-  if( array.resize( size ) == false )
-  {
-    return( Err_NoMemory );
-  }
-
-  //unsigned char *src = (unsigned char*)data();
-  //char *dst = (char*)array.data();
-
-  memcpy( &array[0], &data()[start], size );
-  return( Err_Success );
-}
-
-
-uint CHexBuffer::numPage( CHexPrinter &printer )
-{
-  TQPainter paint( &printer );
-  paint.setFont( font() );
-
-  SPageMargin margin = printer.pageMargin();
-  SPageSize size = printer.pageUsableSize();
-  int headHeight, footHeight, headMargin, footMargin, freeHeight;
-
-  headHeight = footHeight = headMargin = footMargin = 0;
-  if( printer.pageHeader().enable == true )
-  {
-    headHeight = headerHeight( paint );
-    headMargin = headerMargin( paint );
-  }
-  if( printer.pageFooter().enable == true )
-  {
-    footHeight = headerHeight( paint );
-    footMargin = headerMargin( paint );
-  }
-  freeHeight = size.height - headHeight - footHeight - headMargin - footMargin;
-
-  float scale = 1.0;
-  if( (uint)mLineWidth > size.width )
-  {
-    scale = (float)size.width / (float)mLineWidth;
-  }
-  uint linePerPage = (uint) ((float)freeHeight/((float)lineHeight()*scale));
-
-  uint remaining = numLines();
-
-  return( remaining / linePerPage + (remaining % linePerPage ? 1 : 0) );
-}
-
-
-
-int CHexBuffer::print( CHexPrinter &printer, CProgress &p )
-{
-  printer.setDocName( mUrl );
-
-  TQPainter paint( &printer );
-  paint.setFont( font() );
-
-  SPageMargin margin = printer.pageMargin();
-  SPageSize size = printer.pageUsableSize();
-  paint.setClipRect( margin.left, margin.top, size.width, size.height );
-
-  //printf("%d,%d,%d,%d\n", margin.left, margin.top, size.width, size.height );
-
-  int headHeight, footHeight, headMargin, footMargin, freeHeight;
-
-  headHeight = footHeight = headMargin = footMargin = 0;
-  if( printer.pageHeader().enable == true )
-  {
-    headHeight = headerHeight( paint );
-    headMargin = headerMargin( paint );
-  }
-  if( printer.pageFooter().enable == true )
-  {
-    footHeight = headerHeight( paint );
-    footMargin = headerMargin( paint );
-  }
-  freeHeight = size.height - headHeight - footHeight - headMargin - footMargin;
-
-  float scale = 1.0;
-  if( (uint)mLineWidth > size.width )
-  {
-    scale = (float)size.width / (float)mLineWidth;
-    paint.scale( scale, scale );
-  }
-
-  uint linePerPage = (uint) ((float)freeHeight/((float)lineHeight()*scale));
-  uint sx = (uint) ((float)margin.left/scale);
-  uint sy = (uint) ((float)(margin.top+headHeight+headMargin)/scale);
-
-  uint remaining = numLines();
-  uint line = 0;
-
-  #ifdef PRINTER_TEST
-  remaining = remaining > linePerPage * 10 ? linePerPage * 10 : remaining;
-  #endif
-
-
-  SPagePosition pageData( time(0), remaining, linePerPage );
-  while( remaining > 0 )
-  {
-    uint lineInPage = remaining > linePerPage ? linePerPage : remaining;
-    uint y = sy;
-
-    //
-    // Draw header and footer. Reset scaling during that operation.
-    //
-    paint.scale( 1.0/scale, 1.0/scale );
-    if( printer.pageHeader().enable == true )
-    {
-      drawHeader( paint, margin.left, size.width, margin.top, false,
-		  printer.pageHeader(), pageData );
-    }
-    if( printer.pageFooter().enable == true )
-    {
-      drawHeader( paint, margin.left, size.width,
-		  margin.top+size.height-footHeight, true,
-		  printer.pageFooter(), pageData );
-    }
-    paint.scale( scale, scale );
-
-    //
-    // Draw actual data
-    //
-    for( uint i=0; i < lineInPage; i++, line++ )
-    {
-      drawText( paint, line, sx, mLineWidth, y, false/*printer.printBlackWhite()*/ );
-      y += lineHeight();// - mLayout.horzGridWidth; // FIXME not really nice :)
-
-      if( p.expired() == true )
-      {
-	int errCode = p.step( pageData.current(), pageData.max() );
-	if( errCode == Err_Stop )
-	{
-	  p.finish();
-	  return( Err_Success ); // Success here, even if we cancel
-	}
-      }
-    }
-
-    if( p.expired() == true )
-    {
-      int errCode = p.step( pageData.current(), pageData.max() );
-      if( errCode == Err_Stop )
-      {
-	p.finish();
-	return( Err_Success );// Success here, even if we cancel
-      }
-    }
-
-    remaining -= lineInPage;
-    if( remaining > 0 )
-    {
-      printer.newPage();
-    }
-
-    pageData.step();
-  }
-
-  p.finish();
-  return( Err_Success );
-}
-
-
-
-
-
-uint CHexBuffer::printLine( char *dst, uint line )
-{
-  uint offset = line * mLayout.lineSize;
-  unsigned char *src;
-  char *start = dst;
-
-  uint dataSize;
-  if( offset >= documentSize() )
-  {
-    src = 0;
-    dataSize = 0;
-  }
-  else
-  {
-    src = (unsigned char*)&data()[ offset ];
-    dataSize = documentSize() - offset;
-  }
-
-  if( mLayout.offsetVisible == true )
-  {
-    THIS_FPTR(printOffset)( dst, offset ); dst += mOffsetSize;
-    sprintf( dst, " " ); dst += 1;
-  }
-  for( uint i=0; i < mLayout.lineSize; i++ )
-  {
-    if( i<dataSize )
-    {
-      THIS_FPTR(printCell)( dst, src[i] ); dst += mNumCell;
-    }
-    else
-    {
-      memset( dst, ' ', mNumCell ); dst += mNumCell;
-    }
-    if( mSplitWidth != 0 )
-    {
-      sprintf( dst, " " ); dst += 1;
-    }
-  }
-  if( mLayout.secondaryMode != SDisplayLayout::hide )
-  {
-    for( uint i=0; i < mLayout.lineSize; i++ )
-    {
-      if( i < dataSize )
-      {
-	printAsciiCell( dst, src[i] ); dst += 1;
-      }
-      else
-      {
-	memset( dst, ' ', 1 ); dst += 1;
-      }
-    }
-  }
-  sprintf( dst, "\n" ); dst += 1;
-  return( (uint)(dst-start) );
-}
-
-
-uint CHexBuffer::printLine( char *dst, uint line, int columnSegment )
-{
-  uint offset = line * mLayout.lineSize;
-  unsigned char *src;
-  char *start = dst;
-
-  uint dataSize;
-  if( offset >= documentSize() )
-  {
-    src = 0;
-    dataSize = 0;
-  }
-  else
-  {
-    src = (unsigned char*)&data()[ offset ];
-    dataSize = documentSize() - offset;
-  }
-
-  if( columnSegment & OffsetColumn )
-  {
-    THIS_FPTR(printOffset)( dst, offset ); dst += mOffsetSize;
-    sprintf( dst, " " ); dst += 1;
-  }
-
-  if( columnSegment & PrimaryColumn )
-  {
-    for( uint i=0; i < mLayout.lineSize; i++ )
-    {
-      if( i<dataSize )
-      {
-	THIS_FPTR(printCell)( dst, src[i] ); dst += mNumCell;
-      }
-      else
-      {
-	memset( dst, ' ', mNumCell ); dst += mNumCell;
-      }
-      if( mSplitWidth != 0 )
-      {
-	sprintf( dst, " " ); dst += 1;
-      }
-    }
-  }
-
-  if( columnSegment & SecondaryColumn )
-  {
-    for( uint i=0; i < mLayout.lineSize; i++ )
-    {
-      if( i < dataSize )
-      {
-	printAsciiCell( dst, src[i] ); dst += 1;
-      }
-      else
-      {
-	memset( dst, ' ', 1 ); dst += 1;
-      }
-    }
-  }
-
-  sprintf( dst, "\n" ); dst += 1;
-  return( (uint)(dst-start) );
-}
-
-
-
-
-
-
-
-
-
-
-
-bool CHexBuffer::cutSelection( void )
-{
-  if( documentPresent() == false || mSelect.size() == 0 )
-  {
-    return( false );
-  }
-
-  if( mInputMode.noInput() == true || mInputMode.allowResize == false )
-  {
-    inputSound();
-    return( false );
-  }
-
-  recordStart( mCursor );
-  cursorGoto( mSelect.start(), 0 );
-  recordReplace( mCursor, mSelect.size(), 0, 0 );
-  recordEnd( mCursor );
-
-  mSelect.reset();
-
-  computeNumLines();
-  return( true );
-}
-
-
-
-bool CHexBuffer::undo( void )
-{
-  if( documentPresent() == false || mUndoIndex == 0 ||
-      mInputMode.noInput() == true )
-  {
-    if( mInputMode.noInput() == true ) { inputSound(); }
-    return( false );
-  }
-
-  CHexActionGroup *group = mUndoList.at( mUndoIndex-1 );
-  if( group == 0 )
-  {
-    return( false );
-  }
-
-  mUndoIndex -= 1;
-  doActionGroup( group );
-
-  cursorGoto( group->mStartOffset, group->mStartBit );
-
-  return( true );
-}
-
-
-bool CHexBuffer::redo( void )
-{
-  if( documentPresent() == false || mUndoIndex >= mUndoList.count() ||
-      mInputMode.noInput() == true )
-  {
-    if( mInputMode.noInput() == true ) { inputSound(); }
-    return( false );
-  }
-
-  CHexActionGroup *group = mUndoList.at( mUndoIndex );
-  if( group == 0 )
-  {
-    return( false );
-  }
-
-  mUndoIndex += 1;
-  doActionGroup( group );
-
-  cursorGoto( group->mStopOffset, group->mStopBit );
-
-  return( true );
-}
-
-
-int CHexBuffer::addBookmark( int position )
-{
-  if( documentPresent() == false )
-  {
-    return( Err_NoData );
-  }
-
-  if( mBookmarkList.count() >= 9 && position == -1 )
-  {
-    return( Err_ListFull );
-  }
-
-  SCursorOffset *co = new SCursorOffset;
-  if( co == 0 )
-  {
-    fatalSound();
-    return( Err_NoMemory );
-  }
-
-  co->offset = mCursor.curr.offset;
-  co->bit    = mCursor.bit();
-
-  if( position == -1 || position > (int)mBookmarkList.count() )
-  {
-    mBookmarkList.append( co );
-  }
-  else
-  {
-    mBookmarkList.remove( (uint)position );
-    mBookmarkList.insert( (uint)position, co );
-  }
-
-  updateBookmarkMap(false);
-  return( Err_Success );
-}
-
-
-bool CHexBuffer::removeBookmark( int position )
-{
-  if( position < 0 )
-  {
-    if( mBookmarkList.count() == 0 )
-    {
-      return( false );
-    }
-    mBookmarkList.clear();
-  }
-  else
-  {
-    if( (uint)position >= mBookmarkList.count() )
-    {
-      return( false );
-    }
-    mBookmarkList.remove( position );
-  }
-
-  updateBookmarkMap(false);
-  return( true );
-}
-
-
-void CHexBuffer::updateBookmarkMap( bool resize )
-{
-  if( resize == true )
-  {
-    mBookmarkMap.resize( documentSize()/200 + 3 );
-  }
-  mBookmarkMap.fill(0);
-
-  int bookmarkMapSize = mBookmarkMap.size();
-  for( SCursorOffset *c=mBookmarkList.first(); c!=0; c=mBookmarkList.next() )
-  {
-    int bookmarkOffset = c->offset / 200;
-    if( bookmarkOffset < bookmarkMapSize )
-    {
-      //
-      // Espen 2000-05-16:
-      // I do this test to avoid some TQt warnings when I have closed
-      // or reduced the size of the documnet while the (now invalid)
-      // bookmarks still exist.
-      //
-      mBookmarkMap.setBit(bookmarkOffset);
-    }
-  }
-}
-
-
-int CHexBuffer::findFirst( SSearchControl &sc )
-{
-  mMark.reset();
-  int errCode = scanData( sc, true );
-  return( errCode );
-}
-
-int CHexBuffer::findNext( SSearchControl &sc )
-{
-  sc.fromCursor = true;
-  int errCode = scanData( sc, false );
-  return( errCode );
-}
-
-int CHexBuffer::findWrap( SSearchControl &sc )
-{
-  if( sc.wrapValid == false )
-  {
-    return( Err_NoMatch );
-  }
-  sc.wrapValid = false;
-
-  sc.fromCursor = false;
-  sc.wrapActive = true;
-  int errCode = scanData( sc, false );
-  sc.fromCursor = true;
-  return( errCode );
-}
-
-
-
-
-int CHexBuffer::replaceAll( SSearchControl &sc, bool init )
-{
-  if( init == true )
-  {
-    initScanData( sc );
-  }
-
-  if( sc.key.isEmpty() == true )
-  {
-    return( Err_EmptyArgument );
-  }
-
-  if( documentSize() == 0 )
-  {
-    return( Err_EmptyDocument );
-  }
-
-  uint head, tail;
-  if( sc.inSelection == true )
-  {
-    if( mSelect.valid() == false )
-    {
-      return( Err_NoSelection );
-    }
-
-    head = mSelect.start();
-    tail = mSelect.stop();
-  }
-  else
-  {
-    head = 0;
-    tail = documentSize();
-  }
-
-  uint start, stop;
-  if( sc.fromCursor == false )
-  {
-    if( sc.wrapActive == true )
-    {
-      start = sc.forward == true ? head : sc.wrapMark;
-      stop  = sc.forward == true ? sc.wrapMark+sc.key.size() : tail;
-    }
-    else
-    {
-      start = head;
-      stop  = tail;
-    }
-  }
-  else if( sc.forward == true )
-  {
-    start = cursorOffset() < head ? head : cursorOffset();
-    stop  = sc.wrapActive == true ? sc.wrapMark+sc.key.size() : tail;
-  }
-  else
-  {
-    start = sc.wrapActive == true ? sc.wrapMark : head;
-    stop  = cursorOffset() > tail ? tail : cursorOffset();
-  }
-
-  if( sc.forward == true && start + sc.key.size() > stop )
-  {
-    //
-    // When searching backwards "stop" is the last offset from where
-    // we do a memcmp() upward in memory. An overflow for that
-    // situation is taken care of below.
-    //
-    return( Err_NoMatch );
-  }
-
-  if( stop + sc.key.size() > tail )
-  {
-    uint diff = stop + sc.key.size() - tail;
-    stop = stop > diff ? stop - diff : 0;
-  }
-
-  if( mInputMode.noInput() == true )
-  {
-    inputSound();
-    return( Err_WriteProtect );
-  }
-
-  recordStart( mCursor );
-  uint numReplaced = 0;
-
-  if( sc.forward == true )
-  {
-    for( uint i = start; i <= stop ; )
-    {
-      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) != 0 )
-      {
-	i++;
-      }
-      else
-      {
-	cursorGoto( i, 7 );
-	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
-	numReplaced += 1;
-
-	if( sc.inSelection == true )
-	{
-	  if( sc.key.size() > sc.val.size() )
-	  {
-	    mSelect.shrink( sc.key.size() - sc.val.size() );
-	  }
-	  else
-	  {
-	    mSelect.expand( sc.val.size() - sc.key.size() );
-	  }
-	}
-	
-	if( sc.key.size() > sc.val.size() )
-	{
-	  uint diff = sc.key.size() - sc.val.size();
-	  stop -= TQMIN( stop, diff );
-	}
-	else if( sc.key.size() < sc.val.size() )
-	{
-	  stop += sc.val.size() - sc.key.size();
-	}
-
-	i += sc.val.size();
-	cursorStep( sc.val.size(), true, false );
-      }
-    }
-  }
-  else
-  {
-    for( uint i = stop; i >= start; )
-    {
-      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) != 0 )
-      {
-	if( i == 0 ) { break; }
-	i--;
-      }
-      else
-      {
-	cursorGoto( i, 7 );
-	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
-	numReplaced += 1;
-
-	if( sc.inSelection == true )
-	{
-	  if( sc.key.size() > sc.val.size() )
-	  {
-	    mSelect.shrink( sc.key.size() - sc.val.size() );
-	  }
-	  else
-	  {
-	    mSelect.expand( sc.val.size() - sc.key.size() );
-	  }
-	}
-
-	i -= TQMIN( i, sc.key.size() );
-	if( i == 0 ) { break; }
-      }
-    }
-  }
-
-  recordEnd( mCursor );
-  computeNumLines();
-
-  if( numReplaced == 0 )
-  {
-    return( Err_NoMatch );
-  }
-
-  sc.numReplace += numReplaced;
-  sc.match = true;
-  mMark.reset();
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::replaceMarked( SSearchControl &sc )
-{
-  if( documentSize() == 0 )
-  {
-    return( Err_EmptyDocument );
-  }
-
-  if( mMark.valid() == false )
-  {
-    return( Err_NoMark );
-  }
-
-  bool inSelection;
-  if( mSelect.valid() == true )
-  {
-    if( mMark.start() >= mSelect.start() && mMark.stop() <= mSelect.stop() )
-    {
-      inSelection = true;
-    }
-    else
-    {
-      inSelection = false;
-    }
-  }
-  else
-  {
-    inSelection = false;
-  }
-
-  if( mInputMode.noInput() == true )
-  {
-    inputSound();
-    return( Err_WriteProtect );
-  }
-
-  recordStart( mCursor );
-  cursorGoto( mMark.start(), 7 );
-  recordReplace( mCursor, mMark.size(), sc.val.data(), sc.val.size() );
-  sc.numReplace += 1;
-
-  if( inSelection == true )
-  {
-    if( mMark.size() > sc.val.size() )
-    {
-      mSelect.shrink( mMark.size() - sc.val.size() );
-    }
-    else
-    {
-      sc.wrapMark += sc.val.size() - mMark.size();
-      mSelect.expand( sc.val.size() - mMark.size() );
-    }
-  }
-
-
-  if( sc.wrapActive == false )
-  {
-    if( sc.forward == false )
-    {
-      sc.wrapMark += mMark.size() > sc.val.size() ?
-	mMark.size() - sc.val.size() : sc.val.size() - mMark.size();
-    }
-  }
-
-
-  recordEnd( mCursor );
-  computeNumLines();
-
-  if( sc.forward == true )
-  {
-    //
-    // We must step over the area we have just altered. This is
-    // vital if the search key contains a pattern that exists in
-    // the replace data buffer.
-    //
-    cursorStep( sc.val.size(), true, false );
-  }
-  mMark.reset();
-  return( Err_Success );
-}
-
-
-#if 0
-
-int CHexBuffer::replaceAll( SSearchControl &sc, bool init )
-{
-  if( init == true )
-  {
-    initScanData( sc );
-  }
-
-  if( sc.key.isEmpty() == true )
-  {
-    return( Err_EmptyArgument );
-  }
-
-  if( documentSize() == 0 )
-  {
-    return( Err_EmptyDocument );
-  }
-
-  uint head, tail;
-  if( sc.inSelection == true )
-  {
-    if( mSelect.valid() == false )
-    {
-      return( Err_NoSelection );
-    }
-
-    head = mSelect.start();
-    tail = mSelect.stop();
-  }
-  else
-  {
-    head = 0;
-    tail = documentSize();
-  }
-
-  uint start, stop;
-  if( sc.fromCursor == false )
-  {
-    if( sc.wrapActive == true )
-    {
-      start = sc.forward == true ? head : sc.wrapMark;
-      stop  = sc.forward == true ? sc.wrapMark : tail;
-    }
-    else
-    {
-      start = head;
-      stop  = tail;
-    }
-  }
-  else if( sc.forward == true )
-  {
-    start = cursorOffset() < head ? head : cursorOffset();
-    stop  = sc.wrapActive == true ? sc.wrapMark : tail;
-  }
-  else
-  {
-    start = sc.wrapActive == true ? sc.wrapMark : head;
-    stop  = cursorOffset() > tail ? tail : cursorOffset();
-  }
-
-
-  if( start + sc.key.size() > stop )
-  {
-    return( Err_NoMatch );
-  }
-
-  if( stop + sc.key.size() > tail )
-  {
-    uint diff = stop + sc.key.size() - tail;
-    stop = stop > diff ? stop - diff : 0;
-  }
-
-  if( mInputMode.noInput() == true )
-  {
-    inputSound();
-    return( Err_WriteProtect );
-  }
-
-  recordStart( mCursor );
-  uint numReplaced = 0;
-
-  if( sc.forward == true )
-  {
-    for( uint i = start; i <= stop; i++ )
-    {
-      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) == 0 )
-      {
-	cursorGoto( i, 7 );
-	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
-	numReplaced += 1;
-
-	if( sc.inSelection == true )
-	{
-	  if( sc.key.size() > sc.val.size() )
-	  {
-	    mSelect.shrink( sc.key.size() - sc.val.size() );
-	  }
-	  else
-	  {
-	    mSelect.expand( sc.val.size() - sc.key.size() );
-	  }
-	}
-
-	if( sc.key.size() > sc.key.size() )
-	{
-	  uint diff = sc.key.size() - sc.val.size();
-	  i += diff - 1;
-	}
-	else if( sc.key.size() < sc.val.size() )
-	{
-	  uint diff = sc.val.size() - sc.key.size();
-	  stop += diff;
-	}
-	else
-	{
-	  i += sc.val.size() - 1;
-	}
-	cursorStep( sc.val.size(), true, false );
-      }
-    }
-  }
-  else
-  {
-    for( uint i = stop; i >= start; i-- )
-    {
-      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) == 0 )
-      {
-	cursorGoto( i, 7 );
-	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
-	numReplaced += 1;
-
-	if( sc.inSelection == true )
-	{
-	  if( sc.key.size() > sc.val.size() )
-	  {
-	    mSelect.shrink( sc.key.size() - sc.val.size() );
-	  }
-	  else
-	  {
-	    mSelect.expand( sc.val.size() - sc.key.size() );
-	  }
-	}
-
-      }
-      if( i == 0 ) { break; }
-    }
-  }
-
-  recordEnd( mCursor );
-  computeNumLines();
-
-  if( numReplaced == 0 )
-  {
-    return( Err_NoMatch );
-  }
-
-  sc.numReplace += numReplaced;
-  sc.match = true;
-  mMark.reset();
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::replaceMarked( SSearchControl &sc )
-{
-  if( documentSize() == 0 )
-  {
-    return( Err_EmptyDocument );
-  }
-
-  if( mMark.valid() == false )
-  {
-    return( Err_NoMark );
-  }
-
-  bool inSelection;
-  if( mSelect.valid() == false )
-  {
-    if( mMark.start() >= mSelect.start() && mMark.stop() <= mSelect.stop() )
-    {
-      inSelection = true;
-    }
-    else
-    {
-      inSelection = false;
-    }
-  }
-  else
-  {
-    inSelection = false;
-  }
-
-  if( mInputMode.noInput() == true )
-  {
-    inputSound();
-    return( Err_WriteProtect );
-  }
-
-  recordStart( mCursor );
-  cursorGoto( mMark.start(), 7 );
-  recordReplace( mCursor, mMark.size(), sc.val.data(), sc.val.size() );
-  sc.numReplace += 1;
-
-  if( inSelection == true )
-  {
-    if( mMark.size() > sc.val.size() )
-    {
-      mSelect.shrink( mMark.size() - sc.val.size() );
-    }
-    else
-    {
-      mSelect.expand( sc.val.size() - mMark.size() );
-    }
-  }
-
-  recordEnd( mCursor );
-  computeNumLines();
-  mMark.reset();
-
-  return( Err_Success );
-}
-
-#endif
-
-
-int CHexBuffer::initScanData( SSearchControl &sc )
-{
-  sc.wrapValid  = false;
-  sc.wrapActive = false;
-  sc.wrapMark   = 0;
-  sc.match      = false;
-  sc.numReplace = 0;
-
-  uint head, tail;
-  if( sc.inSelection == true )
-  {
-    if( mSelect.valid() == false )
-    {
-      return( Err_NoSelection );
-    }
-
-    head = mSelect.start();
-    tail = mSelect.stop();
-  }
-  else
-  {
-    head = 0;
-    tail = documentSize();
-  }
-
-  if( sc.fromCursor == false )
-  {
-    sc.wrapValid  = false;
-    sc.wrapActive = false;
-    sc.wrapMark   = 0;
-  }
-  else if( sc.forward == true )
-  {
-    if( cursorOffset() > tail )
-    {	
-      sc.wrapValid  = true;
-      sc.wrapActive = false;
-      sc.wrapMark   = tail;
-    }
-    else if( cursorOffset() <= head )
-    {
-      sc.wrapValid  = false;
-      sc.wrapActive = false;
-      sc.wrapMark   = 0;
-    }
-    else
-    {
-      sc.wrapValid  = true;
-      sc.wrapActive = false;
-      sc.wrapMark   = cursorOffset();
-    }
-  }
-  else
-  {
-    if( cursorOffset() >= tail )
-    {
-      sc.wrapValid  = false;
-      sc.wrapActive = false;
-      sc.wrapMark   = 0;
-    }
-    else if( cursorOffset() < head )
-    {
-      sc.wrapValid  = true;
-      sc.wrapActive = false;
-      sc.wrapMark   = head;
-    }
-    else
-    {
-      sc.wrapValid  = true;
-      sc.wrapActive = false;
-      sc.wrapMark   = cursorOffset();
-    }
-  }
-
-  return( Err_Success );
-}
-
-
-
-int CHexBuffer::scanData( SSearchControl &sc, bool init )
-{
-  if( init == true )
-  {
-    int errCode = initScanData( sc );
-    if( errCode != Err_Success )
-    {
-      return( errCode );
-    }
-  }
-
-  if( sc.key.isEmpty() == true )
-  {
-    return( Err_EmptyArgument );
-  }
-
-  if( documentSize() == 0 )
-  {
-    return( Err_EmptyDocument );
-  }
-
-  uint head, tail;
-  if( sc.inSelection == true )
-  {
-    if( mSelect.valid() == false )
-    {
-      return( Err_NoSelection );
-    }
-
-    head = mSelect.start();
-    tail = mSelect.stop();
-  }
-  else
-  {
-    head = 0;
-    tail = documentSize();
-  }
-
-  uint start, stop;
-  if( sc.fromCursor == false )
-  {
-    if( sc.wrapActive == true )
-    {
-      start = sc.forward == true ? head : sc.wrapMark;
-      stop  = sc.forward == true ? sc.wrapMark+sc.key.size() : tail;
-    }
-    else
-    {
-      start = head;
-      stop  = tail;
-    }
-  }
-  else if( sc.forward == true )
-  {
-    start = cursorOffset() < head ? head : cursorOffset();
-    stop  = sc.wrapActive == true ? sc.wrapMark : tail;
-  }
-  else
-  {
-    start = sc.wrapActive == true ? sc.wrapMark : head;
-    stop  = cursorOffset() > tail ? tail : cursorOffset();
-  }
-
-  if( sc.forward == true && start + sc.key.size() > stop )
-  {
-    //
-    // When searching backwards "stop" is the last offset from where
-    // we do a memcmp() upward in memory. An overflow for that
-    // situation is taken care of below.
-    //
-    return( stop + sc.key.size() < tail ? Err_WrapBuffer : Err_NoData );
-  }
-
-  if( stop + sc.key.size() > tail )
-  {
-    uint diff = stop + sc.key.size() - tail;
-    stop = stop > diff ? stop - diff : 0;
-  }
-
-  if( sc.forward == true )
-  {
-    for( uint i = start; i <= stop; i++ )
-    {
-      int result;
-      if( sc.ignoreCase == true )
-      {
-	result = strncasecmp( &data()[i], sc.key.data(), sc.key.size() );
-      }
-      else
-      {
-	result = memcmp( &data()[i], sc.key.data(), sc.key.size() );
-      }
-      if( result == 0 )
-      {
-	if( i != cursorOffset() || mMark.size() != sc.key.size() )
-	{
-	  sc.match = true;
-	  cursorGoto( i, 7 );
-	  markSet( i, (uint)sc.key.size() );
-	  return( Err_Success );
-	}
-      }
-    }
-    return( start > head ? Err_WrapBuffer : Err_NoData );
-  }
-  else
-  {
-    for( uint i = stop; i >= start; i-- )
-    {
-      int result;
-      if( sc.ignoreCase == true )
-      {
-	result = strncasecmp( &data()[i], sc.key.data(), sc.key.size() );
-      }
-      else
-      {
-	result = memcmp( &data()[i], sc.key.data(), sc.key.size() );
-      }
-      if( result == 0 )
-      {	
-	if( i != cursorOffset() || mMark.size() != sc.key.size() )
-	{
-	  sc.match = true;
-	  cursorGoto( i, 7 );
-	  markSet( i, (uint)sc.key.size() );
-	  return( Err_Success );
-	}
-      }
-      if( i == 0 ) { break; }
-    }
-
-    return( stop + sc.key.size() <= tail ? Err_WrapBuffer : Err_NoData );
-  }
-}
-
-
-
-
-
-int CHexBuffer::filter( SFilterControl &fc )
-{
-  uint head, tail;
-  if( fc.inSelection == true )
-  {
-    if( mSelect.valid() == false )
-    {
-      return( Err_NoSelection );
-    }
-
-    head = mSelect.start();
-    tail = mSelect.stop();
-  }
-  else
-  {
-    head = 0;
-    tail = documentSize();
-  }
-
-  uint start, stop;
-  if( fc.fromCursor == false )
-  {
-    start = head;
-    stop  = tail;
-  }
-  else if( fc.forward == true )
-  {
-    start = cursorOffset() < head ? head : cursorOffset();
-    stop  = tail;
-  }
-  else
-  {
-    start = head;
-    stop  = cursorOffset() > tail ? tail : cursorOffset();
-  }
-
-  if( mInputMode.noInput() == true )
-  {
-    inputSound();
-    return( Err_WriteProtect );
-  }
-
-  if( start >= stop ) { return( Err_IllegalRange ); }
-  TQByteArray buf( stop - start );
-  if( buf.isEmpty() == true ) { return( Err_NoMemory ); }
-
-  int errCode = fc.execute((uchar*)&buf[0],(uchar*)&data()[start],buf.size());
-  if( errCode == Err_Success )
-  {
-    recordStart( mCursor );
-    cursorGoto( start, 7 );
-    recordReplace( mCursor, buf.size(), buf.data(), buf.size() );
-    recordEnd( mCursor );
-  }
-
-  return( errCode );
-}
-
-
-
-int CHexBuffer::collectStrings( CStringCollectControl &sc )
-{
-  uint startOffset = 0;
-  uint start, i;
-  bool on = false;
-
-  if( sc.minLength < 1 ) { sc.minLength = 1; }
-
-  start = startOffset;
-  for( i = startOffset; i<documentSize(); i++ )
-  {
-    unsigned char item = data()[i];
-    if( isprint( item ) == 0 || item >= 128 )
-    {
-      if( on == true && i-start >= sc.minLength )
-      {
-	TQByteArray a( i-start );
-	for( uint j=0; j<(i-start); a[j]=data()[start+j], j++ );
-	sc.add( start, a );
-      }
-      on = false;
-    }
-    else
-    {
-      if( on == false ) { start = i; }
-      on = true;
-    }
-  }
-
-  if( on == true && i-start >= sc.minLength )
-  {
-    TQByteArray a( i-start );
-    for( uint j=0; j<(i-start); a[j]=data()[start+j], j++ );
-    sc.add( start, a );
-  }
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::collectStatistic( SStatisticControl &sc, CProgress &p )
-{
-  sc.documentSize = documentSize();
-  sc.documentName = mUrl;
-
-  for( uint i = 0; i<documentSize(); i++ )
-  {
-    sc.occurrence[ (unsigned char)data()[i] ] += 1;
-
-    //
-    // The expired() function introduces too much overhead in this case
-    // so it is only executed every 100'th character
-    //
-    if( i % 100 == 0 && p.expired() == true )
-    {
-      int errCode = p.step( (float)i/(float)documentSize() );
-      if( errCode == Err_Stop && i+1 < documentSize() )
-      {
-	p.finish();
-	return( Err_OperationAborted );
-      }
-    }
-  }
-  p.finish();
-  return( Err_NoErr );
-}
-
-
-void CHexBuffer::doActionGroup( CHexActionGroup *group )
-{
-  if( group == 0 )
-  {
-    return;
-  }
-
-  CHexAction *action = group->mHexAction;
-  group->mHexAction = 0;
-
-  while( action != 0 )
-  {
-    doAction( action );
-    CHexAction *next = action->mNext;
-    group->insertAction( action );
-    action = next;
-  }
-
-  computeNumLines();
-}
-
-
-void CHexBuffer::doAction( CHexAction *action )
-{
-  if( action->mAction == CHexAction::replace )
-  {
-    doReplace( action, true );
-  }
-}
-
-
-
-
-
-void CHexBuffer::recordStart( SCursor &cursor )
-{
-  //
-  // Step 1: Remove any undo element that is more recent than the
-  // current undo index
-  //
-  while( mUndoList.count() > mUndoIndex )
-  {
-    mUndoList.removeLast();
-  }
-
-  //
-  // Step 2: Make sure the undo list is no larger than the undo limit.
-  // We remove the oldest elements in the list.
-  //
-  while( mUndoList.count() >= mUndoLimit )
-  {
-    mUndoList.removeFirst();
-    mUndoIndex -= 1;
-  }
-
-  CHexActionGroup *group = new CHexActionGroup( cursor.curr.offset,
-						cursor.bit() );
-  if( group == 0 )
-  {
-    return;
-  }
-
-  mUndoList.append( group );
-  mUndoIndex += 1;
-}
-
-
-void CHexBuffer::recordReplace( SCursor &cursor, uint size, char *data1,
-				uint data1Size )
-{
-  CHexAction *hexAction = new CHexAction( CHexAction::replace,
-					  cursor.curr.offset );
-  if( hexAction == 0 )
-  {
-    return;
-  }
-
-  hexAction->mSize = size;
-  hexAction->mData = data1;
-  hexAction->mDataSize = data1Size;
-
-  doReplace( hexAction, false );
-  mUndoList.getLast()->insertAction( hexAction );
-
-  if( mCursor.curr.offset < documentSize() )
-  {
-    mCursor.curr.data = data()[ mCursor.curr.offset ];
-  }
-
-}
-
-void CHexBuffer::recordEnd( SCursor &cursor )
-{
-  mUndoList.getLast()->mStopOffset = cursor.curr.offset;
-  mUndoList.getLast()->mStopBit = cursor.bit();
-}
-
-
-//
-// This method is the only place where the doucument data can be changed.
-//
-void CHexBuffer::doReplace( CHexAction *hexAction, bool removeData )
-{
-  uint offset   = hexAction->mOffset;
-  uint oldSize  = hexAction->mSize;
-  char *newData = hexAction->mData;
-  uint newSize  = hexAction->mDataSize;
-
-  hexAction->setData( newSize, &data()[offset], oldSize );
-
-  //
-  // Input new data. Resize buffer first if necessary. We always mark the
-  // data as changed (dirty) when the buffer is resized, otherwise only
-  // when the new data differ from the current. Nice feature :-)
-  //
-  int errCode;
-  if( newSize > oldSize )
-  {
-    errCode = moveBuffer( offset + newSize - oldSize, offset );
-    mDocumentModified = true;
-  }
-  else if( newSize < oldSize )
-  {
-    errCode = moveBuffer( offset, offset + oldSize - newSize );
-    mDocumentModified = true;
-  }
-  else
-  {
-    errCode = Err_Success;
-    if( memcmp( &data()[offset], newData, newSize ) != 0 )
-    {
-      mDocumentModified = true;
-    }
-  }
-
-  if( errCode == Err_Success )
-  {
-    memcpy( &data()[offset], newData, newSize );
-  }
-
-  //
-  // Data is removed regardless of success or not. Otherwise we will
-  // have a mmeory leak. The single reason why the operation above could
-  // fail is because there was that no more memory that could be
-  // allocated.
-  //
-  if( removeData == true )
-  {
-    delete [] newData;
-  }
-
-}
-
-
-bool CHexBuffer::inputDummy( unsigned char *dest, int value, uint cell )
-{
-  (void)dest;
-  (void)value;
-  (void)cell;
-  return( false );
-}
-
-
-bool CHexBuffer::inputHexadecimal( unsigned char *dest, int value, uint cell )
-{
-  if( value >= '0' && value <= '9' )
-  {
-    value = value - '0';
-  }
-  else if( value >= 'A' && value <= 'F' )
-  {
-    value = value - 'A' + 10;
-  }
-  else if( value >= 'a' && value <= 'f' )
-  {
-    value = value - 'a' + 10;
-  }
-  else
-  {
-    return( false );
-  }
-
-  if( cell > 1 )
-  {
-    return( false );
-  }
-
-  uint shift = 1 - cell;
-  *dest = (*dest & ~(0xF<<(shift*4)) ) | (value<<(shift*4));
-  return( true );
-}
-
-
-bool CHexBuffer::inputDecimal( unsigned char *dest, int value, uint cell )
-{
-  //
-  // 2000-01-22 Espen Sand
-  // I do the insertion a bit different here since decimal is special
-  // with respect to bitwidths.
-  //
-  if( value < '0' || value > '9' || cell > 2 )
-  {
-    return( false );
-  }
-
-  char buf[4];
-  printDecimalCell( buf, *dest );
-  buf[cell]=value;
-  buf[3]=0;
-
-  int tmp = atoi(buf);
-  if( tmp > 255 )
-  {
-    return( false );
-  }
-
-  *dest = tmp;
-  return( true );
-}
-
-
-bool CHexBuffer::inputOctal( unsigned char *dest, int value, uint cell )
-{
-  if( value >= '0' && value <= '7' )
-  {
-    value = value - '0';
-    if( cell == 0 && value > 3 )
-    {
-      return( false );
-    }
-  }
-  else
-  {
-    return( false );
-  }
-
-  if( cell >= 3 )
-  {
-    return( false );
-  }
-
-  uint shift = 2 - cell;
-  *dest = (*dest & ~(0x7<<(shift*3)) ) | (value<<(shift*3));
-  return( true );
-}
-
-
-bool CHexBuffer::inputBinary( unsigned char *dest, int value, uint cell )
-{
-  if( value >= '0' && value <= '1' )
-  {
-    value = value - '0';
-  }
-  else
-  {
-    return( false );
-  }
-
-  if( cell > 7 )
-  {
-    return( false );
-  }
-
-  uint shift = 7 - cell;
-  *dest = (*dest & ~(1<<shift)) | (value<<shift);
-  return( true );
-}
-
-
-
-bool CHexBuffer::inputAscii( unsigned char *dest, int value, uint )
-{
-  *dest = value;
-  return( true );
-}
-
-
-
-int CHexBuffer::moveBuffer( uint destOffset, uint srcOffset )
-{
-  if( srcOffset > documentSize() || destOffset == srcOffset )
-  {
-    return( Err_Success );
-  }
-
-  if( destOffset < srcOffset )
-  {
-    char *dest = &data()[ destOffset ];
-    char *src  = &data()[ srcOffset ];
-
-    memmove( dest, src, documentSize() - srcOffset );
-    setDocumentSize( documentSize() - (srcOffset - destOffset) );
-    return( Err_Success );
-  }
-  else
-  {
-    uint s = documentSize() - srcOffset;
-    if( destOffset + s >= size() )
-    {
-      int errCode = resizeBuffer( destOffset + s );
-      if( errCode != Err_Success )
-      {
-	fatalSound();
-	return( errCode );
-      }
-    }
-    else
-    {
-      setDocumentSize( documentSize() + (destOffset - srcOffset) );
-    }
-
-    char *dest = &data()[ destOffset ];
-    char *src  = &data()[ srcOffset ];
-
-    memmove( dest, src, s );
-    memset( src, 0, destOffset - srcOffset );
-    return( Err_Success );
-  }
-}
-
-
-
-
-int CHexBuffer::resizeBuffer( uint newSize )
-{
-  if( newSize < documentSize() )
-  {
-    return( Err_Success );
-  }
-
-  if( newSize >= size() )
-  {
-    TQByteArray tmp;
-    tmp.duplicate( data(), size() );
-    if( tmp.isNull() == true )
-    {
-      return( Err_NoMemory );
-    }
-
-    if( fill( '\0', newSize + 100 ) == false )
-    {
-      return( Err_NoMemory );
-    }
-
-    memcpy( data(), &tmp[0], tmp.size() );
-  }
-
-  setDocumentSize( newSize );
-  return( Err_Success );
-}
-
-
-void CHexBuffer::inputSound( void )
-{
-  if( mInputErrorSound == true )
-  {
-    KNotifyClient::beep( TQObject::tr("Edit operation failed") );
-  }
-}
-
-
-void CHexBuffer::fatalSound( void )
-{
-  if( mFatalErrorSound == true )
-  {
-    KNotifyClient::beep( TQObject::tr("Could not allocate memory") );
-  }
-}
-
-
-int CHexBuffer::printHtmlDataPage( const TQString &tocName,
-				   const TQStringList &fileNames, uint index,
-				   const SExportHtml &ex,
-				   uint line, uint numLine )
-{
-  if( fileNames.count() == 0 )
-  {
-    return( Err_NullArgument );
-  }
-
-  if( index >= fileNames.count() )
-  {
-    index = fileNames.count()-1;
-  }
-
-  TQFile file( fileNames[index] );
-  if( file.open( IO_WriteOnly ) == false )
-  {
-    return( Err_OperationAborted );
-  }
-
-  TQTextStream os( &file );
-  const TQString *next = index+1 >= fileNames.count() ? 0 : &fileNames[index+1];
-  const TQString *prev = index == 0 ? 0 : &fileNames[index-1];
-  const TQString *toc  = tocName.length() == 0 ? 0 : &tocName;
-
-  printHtmlHeader( os, true );
-  if( ex.navigator == true )
-  {
-    printHtmlNavigator( os, next, prev, toc );
-  }
-
-  printHtmlCaption( os, ex.topCaption, index+1, fileNames.count() );
-  printHtmlTable( os, line, numLine, ex.blackWhite );
-  printHtmlCaption( os, ex.bottomCaption, index+1, fileNames.count() );
-
-  if( ex.navigator == true )
-  {
-    printHtmlNavigator( os, next, prev, toc );
-  }
-  printHtmlHeader( os, false );
-
-  return( Err_Success );
-}
-
-
-void CHexBuffer::printHtmlTocPage( const TQString &tocName,
-				   const TQString &linkName,
-				   const TQStringList &fileNames,
-				   const TQStringList &offsets,
-				   uint numPage )
-{
-  if( numPage == 0 || fileNames.count() == 0 )
-  {
-    return;
-  }
-  if( numPage >= fileNames.count() )
-  {
-    numPage = fileNames.count() - 1;
-  }
-
-  TQFile file( tocName );
-  if( file.open( IO_WriteOnly ) == false )
-  {
-    return;
-  }
-
-  TQTextStream os( &file );
-  printHtmlHeader( os, true );
-
-  os << "<P ALIGN=\"CENTER\">" << endl;
-  os << "<B><FONT COLOR=BLACK>" << endl;
-  os << mUrl << endl;
-  os << "</FONT></B></CAPTION>" << endl;
-  os << "</P>" << endl;
-
-  os << "<P ALIGN=\"CENTER\"><TT>" << endl;
-  for( uint i=0; i<=numPage; i++ )
-  {
-    TQString n( fileNames[i].right( fileNames[i].length() -
-				   fileNames[i].findRev('/') - 1) );
-    os << "<A HREF=\"" << n << "\">" << i18n("Page") << i+1;
-    os << "</A>";
-    os << " " << offsets[i];
-    os << "<br>" << endl;
-  }
-  os << "</P>" << endl;
-
-  printHtmlHeader( os, false );
-
-  if( linkName.isEmpty() == false )
-  {
-    //
-    // Make a symlink. We ignore any error here. I don't consider
-    // it to be fatal.
-    //
-    TQString n( tocName.right( tocName.length() - tocName.findRev('/') - 1) );
-    symlink( n.latin1(), linkName.latin1() );
-  }
-
-}
-
-
-
-void CHexBuffer::printHtmlCaption( TQTextStream &os, uint captionType,
-				   uint curPage, uint numPage )
-{
-  TQString caption;
-  switch( captionType )
-  {
-    case 0:
-      return;
-    break;
-
-    case 1:
-      caption = mUrl;
-    break;
-
-    case 2:
-      caption = mUrl.right( mUrl.length() - mUrl.findRev('/') - 1);
-    break;
-
-    case 3:
-      caption = i18n("Page %1 of %2").arg(curPage).arg(numPage);
-    break;
-  }
-
-  os << "<P ALIGN=\"CENTER\">" << endl;
-  os << "<B><FONT COLOR=BLACK>" << endl;
-  os << caption << endl;
-  os << "</FONT></B></CAPTION>" << endl;
-  os << "</P>" << endl;
-}
-
-
-
-void CHexBuffer::printHtmlNavigator( TQTextStream &os, const TQString *next,
-				     const TQString *prev, const TQString *toc )
-{
-  os << "<TABLE BORDER=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">" << endl;
-  os << "<TR>" << endl;
-  os << "<TD>" << endl;
-  if( next == 0 )
-  {
-    os << i18n("Next") << " ";
-  }
-  else
-  {
-    TQString n( next->right( next->length() - next->findRev('/') - 1) );
-    os << "<A HREF=\"" << n << "\">" << i18n("Next") << "</A>" << " ";
-  }
-
-  if( prev == 0 )
-  {
-    os << i18n("Previous") << " ";
-  }
-  else
-  {
-    TQString p( prev->right( prev->length() - prev->findRev('/') - 1) );
-    os << "<A HREF=\"" << p << "\">" << i18n("Previous") << "</A>" << " ";
-  }
-
-  if( toc == 0 )
-  {
-    os << i18n("Contents") << " ";
-  }
-  else
-  {
-    TQString t( toc->right( toc->length() - toc->findRev('/') - 1) );
-    os << "<A HREF=\"" << t << "\">" << i18n("Contents");
-    os << "</A>" << " ";
-  }
-
-  os << "</TD>" << endl;
-
-  os << "<TD ALIGN=\"RIGHT\">" << endl;
-  os << "<A HREF=\"" << "http://home.sol.no/~espensa/khexedit" << "\">";
-  os << i18n("Generated by khexedit");
-  os << "</A>" << " ";
-
-  os << "</TD>" << endl;
-  os << "</TR>" << endl << "</TABLE>" << endl;
-}
-
-
-int CHexBuffer::printHtmlHeader( TQTextStream &os, bool isFront )
-{
-  if( isFront == true )
-  {
-    os << "<HTML>" << endl << "<HEAD>" << endl;
-    os << "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; ";
-    os << "charset=iso-8859-1\">" << endl;
-    os << "<META NAME=\"hexdata\" CONTENT=\"khexedit dump\">" << endl;
-    os << "</HEAD>" << endl << "<BODY>" << endl;
-  }
-  else
-  {
-    os << "</BODY>" << endl << "</HTML>" << endl;
-  }
-
-  return( Err_Success );
-}
-
-
-int CHexBuffer::printHtmlTable( TQTextStream &os, uint line, uint numLine,
-				bool bw )
-{
-  uint i;
-  TQColor color;
-
-
-  int numCol = 1;
-  if( mLayout.offsetVisible == true ) { numCol += 1; }
-  if( mLayout.secondaryMode != SDisplayLayout::hide ) { numCol += 1; }
-
-  os << "<TABLE BORDER=1 COLS=" << numCol << " WIDTH=\"100%\" ";
-  os << "CELLSPACING=0 CELLPADDING=2>" << endl;
-  if( mLayout.offsetVisible == true )
-  {
-    color = bw == true ? TQt::white : mColor.offsetBg;
-    os << "<TD BGCOLOR=" << TQString(color.name()).latin1() << ">" << endl;
-    os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
-    os << "CELLSPACING=0 CELLPADDING=2>" << endl;
-
-    color = bw == true ? TQt::black : mColor.offsetFg;
-    for( i=0; i<numLine; i++ )
-    {
-      os << "<TR><TD><TT><b><FONT COLOR=" << TQString(color.name()).latin1() << ">";
-      THIS_FPTR(printOffset)( mPrintBuf, (line+i)*mLayout.lineSize );
-      mPrintBuf[mOffsetSize]=0;
-      os << mPrintBuf << "</TD></TR>" << endl;
-    }
-    os << "</TABLE>" << endl << "</TD>" << endl;
-  }
-
-  color = bw == true ? TQt::white : mColor.textBg;
-  os << "<TD BGCOLOR=" << TQString(color.name()).latin1()  << ">" << endl;
-  os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
-  os << "CELLSPACING=0 CELLPADDING=2>" << endl;
-  for( i=0; i<numLine; i++ )
-  {
-    printHtmlLine( os, line+i, true, bw );
-  }
-  os << "</TABLE>" << endl << "</TD>" << endl;
-
-  if( mLayout.secondaryMode != SDisplayLayout::hide )
-  {
-    color = bw == true ? TQt::white : mColor.textBg;
-    os << "<TD BGCOLOR=" << TQString(color.name()).latin1() << ">" << endl;
-    os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
-    os << "CELLSPACING=0 CELLPADDING=2>" << endl;
-    for( i=0; i<numLine; i++ )
-    {
-      printHtmlLine( os, line+i, false, bw );
-    }
-    os << "</TABLE>" << endl << "</TD>" << endl;
-  }
-
-  os << "</TR>" << endl << "</TABLE>" << endl;
-  return( Err_Success );
-}
-
-
-int CHexBuffer::printHtmlLine( TQTextStream &os, uint line, bool isPrimary,
-			       bool bw )
-{
-  uint offset  = line * mLayout.lineSize;
-  TQColor prevColor;
-
-  TQColor color;
-  if( bw == true )
-  {
-    color = TQt::white;
-  }
-  else
-  {
-    color = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
-  }
-
-  os << "<TR><TD NOWRAP BGCOLOR=" << TQString(color.name()).latin1() << "><TT><B>"
-     << endl;
-  if( offset >= documentSize() )
-  {
-    os << "<BR></TD></TR>" << endl;
-    return( Err_Success );
-  }
-
-  for( uint i=0; i < mLayout.lineSize; i++ )
-  {
-    if( isPrimary == true )
-    {
-      if( offset+i >= documentSize() )
-      {
-	memset(mPrintBuf, ' ', mNumCell );	
-	mPrintBuf[mNumCell] = 0;
-	if( i == 0 )
-	{
-	  color = bw == true ? TQt::black : foregroundColor(i);
-	}
-	else
-	{
-	  color = prevColor;
-	}
-      }
-      else
-      {
-	unsigned char val = (unsigned char)data()[offset+i];
-	if( THIS_FPTR(printCell)( mPrintBuf, val ) == 0 )
-	{
-	  color = bw == true ? TQt::black : foregroundColor(i);
-	}
-	else
-	{
-	  color = bw == true ? TQt::black : mColor.nonPrintFg;
-	}
-      }
-      mPrintBuf[mNumCell] = 0;
-      if( i == 0 )
-      {
-	os << "<FONT COLOR=" << TQString(color.name()).latin1() << ">";
-      }
-      else if( color != prevColor )
-      {
-	os << "</FONT><FONT COLOR=" << TQString(color.name()).latin1() << ">";
-      }
-      prevColor = color;
-
-      if( mPrintBuf[0] == '<' )
-      {
-	os << "&lt;";
-      }
-      else
-      {
-	os << mPrintBuf;
-	if( (i+1) % mLayout.columnSize == 0 && (i+1) != mLayout.lineSize )
-	{
-	  os << " ";
-	}
-      }
-    }
-    else
-    {
-      if( offset+i >= documentSize() )
-      {
-	memset(mPrintBuf, ' ', 1 );
-	if( i == 0 )
-	{
-	  color = bw == true ? TQt::black : mColor.secondaryFg;
-	}
-	else
-	{
-	  color = prevColor;
-	}
-      }
-      else
-      {
-	unsigned char val = (unsigned char)data()[offset+i];
-	if( printAsciiCell( mPrintBuf, val ) == 0 )
-	{
-	  color = bw == true ? TQt::black : mColor.secondaryFg;
-	}
-	else
-	{
-	  color = bw == true ? TQt::black : mColor.nonPrintFg;
-	}
-	mPrintBuf[1] = 0;
-
-	if( i == 0 )
-	{
-	  os << "<FONT COLOR=" << TQString(color.name()).latin1() << ">";
-	}
-	else if( color != prevColor )
-	{
-	  os << "</FONT><FONT COLOR=" << TQString(color.name()).latin1()  << ">";
-	}
-	prevColor = color;
-	
-	mPrintBuf[1] = 0;
-	os << (mPrintBuf[0] == '<' ? "&lt;" : mPrintBuf);
-      }
-
-    }
-  }
-  os << "</TD></TR>" << endl;
-  return( Err_Success );
-}
-
-
-
-
-
diff --git a/khexedit/hexbuffer.cpp b/khexedit/hexbuffer.cpp
new file mode 100644
index 00000000..83cfa84c
--- /dev/null
+++ b/khexedit/hexbuffer.cpp
@@ -0,0 +1,5099 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <tqfileinfo.h>
+
+#include <tdelocale.h>
+#include <tdeglobal.h>
+#include <tdeglobalsettings.h>
+#include <knotifyclient.h>
+
+#include "hexbuffer.h"
+#include "hexerror.h"
+
+//
+// There are some comments marked with a "// ##" at various places.
+// These indicate a patch from Sergey A. Sukiyazov which I have applied
+// "as is" for now. The number of TQString::fromLocal8Bit in this modification
+// indicates that I should perhaps modify code elsewhere as well 
+// (espen 2000-11-26)
+//
+
+// #define DEBUG_FIXED_SIZE 1024
+// #define PRINTER_TEST
+
+
+CHexAction::CHexAction( HexAction action, uint offset )
+{
+  mAction   = action;
+  mOffset   = offset;
+  mSize     = 0;
+  mData     = 0;
+  mDataSize = 0;
+  mNext     = 0;
+}
+
+CHexAction::~CHexAction( void )
+{
+  delete [] mData;
+}
+
+void CHexAction::setData( uint size, char *data, uint dataSize )
+{
+
+  if( data != 0 && dataSize > 0 )
+  {
+    mData = new char[ dataSize ];
+    if( mData == 0 )
+    {
+      return;
+    }
+    memcpy( mData, data, dataSize );
+    mDataSize = dataSize;
+  }
+  else
+  {
+    mDataSize = 0;
+    mData = 0;
+  }
+  mSize = size;
+}
+
+
+CHexActionGroup::CHexActionGroup( uint startOffset, uint startBit )
+{
+  mStartOffset = startOffset;
+  mStartBit    = startBit;
+  mHexAction   = 0;
+}
+
+CHexActionGroup::~CHexActionGroup( void )
+{
+  CHexAction *ptr = mHexAction;
+  while( ptr != 0 )
+  {
+    CHexAction *next = ptr->mNext;
+    delete ptr;
+    ptr = next;
+  }
+}
+
+void CHexActionGroup::insertAction( CHexAction *hexAction )
+{
+  hexAction->mNext = mHexAction;
+  mHexAction = hexAction;
+}
+
+
+
+int SFilterControl::execute( uchar *dest, uchar *src, uint size )
+{
+  if( size == 0 )
+  {
+    return( Err_IllegalArgument );
+  }
+
+  uint numElement = operand.size();
+  if( operation == OperandAndData )
+  {
+    if( numElement == 0 ) { return( Err_IllegalArgument ); }
+    if( forward == true )
+    {
+      for( uint i = 0; i < size; )
+      {
+	for( uint j = 0; i < size && j < numElement; j++, i++ )
+	{
+	  dest[i] = src[i] & operand[j];
+	}
+      }
+    }
+    else
+    {
+      for( uint i = size; i > 0; )
+      {
+	for( uint j = numElement; i > 0 && j > 0; j--, i-- )
+	{
+	  dest[i-1] = src[i-1] & operand[j-1];
+	}
+      }
+    }
+  }
+  else if( operation == OperandOrData )
+  {
+    if( numElement == 0 ) { return( Err_IllegalArgument ); }
+    if( forward == true )
+    {
+      for( uint i = 0; i < size; )
+      {
+	for( uint j = 0; i < size && j < numElement; j++, i++ )
+	{
+	  dest[i] = src[i] | operand[j];
+	}
+      }
+    }
+    else
+    {
+      for( uint i = size; i > 0; )
+      {
+	for( uint j = numElement; i > 0 && j > 0; j--, i-- )
+	{
+	  dest[i-1] = src[i-1] | operand[j-1];
+	}
+      }
+    }
+  }
+  else if( operation == OperandXorData )
+  {
+    if( numElement == 0 ) { return( Err_IllegalArgument ); }
+    if( forward == true )
+    {
+      for( uint i = 0; i < size; )
+      {
+	for( uint j = 0; i < size && j < numElement; j++, i++ )
+	{
+	  dest[i] = src[i] ^ operand[j];
+	}
+      }
+    }
+    else
+    {
+      for( uint i = size; i > 0; )
+      {
+	for( uint j = numElement; i > 0 && j > 0; j--, i-- )
+	{
+	  dest[i-1] = src[i-1] ^ operand[j-1];
+	}
+      }
+    }
+  }
+  else if( operation == InvertData )
+  {
+    for( uint i = 0; i < size; i++ )
+    {
+      dest[i] = ~src[i];
+    }
+  }
+  else if( operation == ReverseData )
+  {
+    for( uint i = 0; i < size; i++ )
+    {
+      uchar flag = src[i];
+      uchar rev  = 0;
+      for( uint j = 0; j < 8; j++ )
+      {
+	rev |= (((flag & 0x80) >> (7-j)));
+	flag <<= 1;
+      }
+      dest[i] = rev;
+    }
+  }
+  else if( operation == RotateData || operation == ShiftData )
+  {
+    //
+    // Only forward here
+    //
+    bool up   = rotate[1] > 0 ? true : false;
+    int range = rotate[0];
+    int shift = abs(rotate[1]);
+    if( range == 0 || shift == 0 ) { return( Err_IllegalArgument ); }
+    shift = shift % (range*8);
+
+    int b = shift / 8;
+    int s = shift - b * 8;
+
+    for( uint i = 0; i < size; )
+    {
+      if( up == true )
+      {
+	int j;
+	if( operation == RotateData )
+	{
+	  for( j=0; j < b && i+range < size ; i++, j++ )
+	  {
+	    dest[i] = src[i+range-b];
+	  }
+	}
+	else
+	{
+	  for( j=0; j < b && i < size ; dest[i] = 0, i++, j++ );
+	}
+	for( ; j < range && i < size ; i++, j++ )
+	{
+	  dest[i] = src[i-b];
+	}
+
+	uchar last = dest[i-1];
+	for( int k=1; k <= j; k++ )
+	{
+	  dest[i-k] >>= s;
+	  if( k < j )
+	  {
+	    dest[i-k] |= dest[i-k-1]<<(8-s);
+	  }
+	  else if( j == range && operation == RotateData )
+	  {
+	    dest[i-k] |= last<<(8-s);
+	  }
+	}
+      }
+      else
+      {
+	int j;
+	for( j=0; j+b < range && i+b < size ; i++, j++ )
+	{
+	  dest[i] = src[i+b];
+	}
+	for( ; j < range && i < size ; i++, j++ )
+	{
+	  dest[i] = operation == RotateData ? src[i+b-range] : 0;
+	}
+	
+	uchar first = dest[i-j];
+	for( int k=j; k>0; k-- )
+	{
+	  dest[i-k] <<= s;
+	  if( k>1 )
+	  {
+	    dest[i-k] |= dest[i-k+1]>>(8-s);
+	  }
+	  else if( j == range && operation == RotateData )
+	  {
+	    dest[i-k] |= first>>(8-s);
+	  }
+	}
+      }
+    }
+  }
+  else if( operation == SwapBits )
+  {
+    //
+    // Swap bits. Based on Leon Lessing's work.
+    //
+
+    //
+    // Make non swapped version first.
+    //
+    for( uint i = 0; i < size; i++ )
+    {
+      dest[i] = src[i];
+    }
+
+    //
+    // Swap the pairs the have been defined
+    // Format of operand (example):
+    // 7 2 5 0 0 0 0 0
+    // Swap bit 7 with bit 2 and swap bit 5 with bit 0
+    //
+    for( uint j=0; j<4; j++ )
+    {
+      uchar b1 = 1 << (uchar)operand[j*2];
+      uchar b2 = 1 << (uchar)operand[j*2+1];
+      if( b1 == b2 ) { continue; } // Equal, no need to swap.
+
+      for( uint i = 0; i < size; i++ )
+      {
+	uchar b = 0;
+	if( dest[i] & b1 ) { b |= b2; }
+	if( dest[i] & b2 ) { b |= b1; }
+
+	//
+	// A short description so that I will understand what the
+	// h... is going on five minutes from now.
+	//
+	// Destination byte is masked (AND'ed) with the inverse bitmap
+	// (the noninversed bitmap contains position of the
+	// two swap bits, eg 7-2 gives 10000100). Then the destination
+	// is OR'ed with the swapped bitmap.
+	//
+	dest[i] = (dest[i] & ~(b1 | b2)) | b;
+      }
+    }
+  }
+  else
+  {
+    return( Err_IllegalArgument );
+  }
+
+  return( Err_Success );
+}
+
+
+const char *SExportCArray::printFormatted( const char *b, uint maxSize ) const
+{
+  static char buf[12];
+  if( elementType == Char )
+  {
+    char e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    sprintf( buf, "%d", e );
+    return( buf );
+  }
+  else if( elementType == Uchar )
+  {
+    unsigned char e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    if( unsignedAsHexadecimal == true )
+    {
+      sprintf( buf, "0x%02x", e );
+    }
+    else
+    {
+      sprintf( buf, "%u", e );
+    }
+    return( buf );
+  }
+  else if( elementType == Short )
+  {
+    short e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    sprintf( buf, "%d", e );
+    return( buf );
+
+  }
+  else if( elementType == Ushort )
+  {
+    unsigned short e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    if( unsignedAsHexadecimal == true )
+    {
+      sprintf( buf, "0x%04x", e );
+    }
+    else
+    {
+      sprintf( buf, "%u", e );
+    }
+    return( buf );
+  }
+  else if( elementType == Int )
+  {
+    int e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    sprintf( buf, "%u", e );
+    return( buf );
+  }
+  else if( elementType == Uint )
+  {
+    unsigned int e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    if( unsignedAsHexadecimal == true )
+    {
+      sprintf( buf, "0x%08x", e );
+    }
+    else
+    {
+      sprintf( buf, "%u", e );
+    }
+    return( buf );
+  }
+  else if( elementType == Float )
+  {
+    float e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    sprintf( buf, "%f", e );
+    return( buf );
+  }
+  else if( elementType == Double )
+  {
+    double e = 0;
+    memcpy( &e, b, TQMIN(sizeof(e),maxSize) );
+    sprintf( buf, "%f", e );
+    return( buf );
+  }
+
+  else
+  {
+    return("");
+  }
+}
+
+
+TQString SExportCArray::variableName( uint range ) const
+{
+  const char *typeString[] =
+  {
+    "char",
+    "unsigned char",
+    "short",
+    "unsigned short",
+    "int",
+    "unsigned int",
+    "float",
+    "double"
+  };
+
+  uint es = elementSize();
+  uint numElement = range / es + ((range % es) ? 1 : 0);
+
+  return( TQString("%1 %2[%2]").arg(typeString[elementType]).
+	  arg(arrayName).arg(numElement) );
+}
+
+
+
+int SExportCArray::elementSize( void ) const
+{
+  if( elementType == Char || elementType == Uchar )
+  {
+    return( sizeof(char) );
+  }
+  else if( elementType == Short || elementType == Ushort )
+  {
+    return( sizeof(short) );
+  }
+  else if( elementType == Int || elementType == Uint )
+  {
+    return( sizeof(int) );
+  }
+  else if( elementType == Float )
+  {
+    return( sizeof(float) );
+  }
+  else if( elementType == Double )
+  {
+    return( sizeof(double) );
+  }
+  else
+  {
+    return(1);
+  }
+}
+
+
+char CHexBuffer::mHexBigBuffer[16]=
+{
+  '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
+};
+
+char CHexBuffer::mHexSmallBuffer[16]=
+{
+  '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
+};
+
+char CHexBuffer::mDecBuffer[10]=
+{
+  '0','1','2','3','4','5','6','7','8','9'
+};
+
+char CHexBuffer::mOctBuffer[8]=
+{
+  '0','1','2','3','4','5','6','7'
+};
+
+
+SCursorState CHexBuffer::mCursorState;
+SFileState CHexBuffer::mFileState;
+
+
+
+
+CHexBuffer::CHexBuffer( void )
+  :TQByteArray()
+{
+  mColorIndex   = 0;
+  mPrintBuf     = 0;
+  mLoadingData  = false;
+  mEditMode     = EditReplace;
+  mActiveEditor = edit_primary;
+
+  mDocumentModified = false;
+
+  #ifdef DEBUG_FIXED_SIZE
+  setMaximumSize( DEBUG_FIXED_SIZE );
+  #else
+  setMaximumSize( ~0 );
+  #endif
+
+  setDocumentSize(0);
+
+  #ifdef PRINTER_TEST
+  puts("<CHexBuffer> Printer test is activated");
+  #endif
+
+
+  setInputMode( mInputMode );
+
+  int errCode = setLayout( mLayout );
+  if( errCode != 0 )
+  {
+    return;
+  }
+  setColor( mColor );
+  setFont( mFontInfo.init() );
+  setShowCursor( true );
+  setDisableCursor( false );
+  setEditMode( EditReplace, false, false );
+  setSoundState( false, false );
+
+  mUndoLimit = 10;
+  mUndoIndex = 0;
+  mUndoList.setAutoDelete( TRUE );
+  mBookmarkList.setAutoDelete( TRUE );
+}
+
+
+CHexBuffer::~CHexBuffer( void )
+{
+  //debug("CHexBuffer::~CHexBuffer");
+  delete [] mColorIndex;
+  delete [] mPrintBuf;
+}
+
+
+
+bool CHexBuffer::hasFileName( void )
+{
+  //
+  // FIXME: Files can be called "Untitled" so this must be corrected.
+  //
+  if( mUrl.isEmpty() || mUrl.contains( i18n( "Untitled" ), false ) )
+  {
+    return( false );
+  }
+  else
+  {
+    return( true );
+  }
+}
+
+
+
+int CHexBuffer::setLayout( SDisplayLayout &layout )
+{
+  mLayout = layout;
+  mLayout.verify();
+
+  if( mLayout.primaryMode == SDisplayLayout::textOnly )
+  {
+    mActiveEditor = edit_primary;
+    setEditMode( mEditMode );
+  }
+
+  mCursor.setLineSize( mLayout.lineSize );
+  mCursor.addOffset( 0 ); // This will only reset the cell position
+
+  computeLineWidth();
+  cursorCompute();
+
+  delete [] mColorIndex; mColorIndex = 0;
+  delete [] mPrintBuf; mPrintBuf = 0;
+
+  mColorIndex = new unsigned char[ mLayout.lineSize ];
+  if( mColorIndex == 0 )
+  {
+    return( Err_NoMemory );
+  }
+  setColor( mColor );
+
+  //
+  // The 'mPrintBuf' is used to store formatted text. It is used for all
+  // print operations and must have the size of the 'mDpyState.lineSize' which
+  // is the number of bytes in one single display line.
+  //
+  mPrintBuf = new char[ mLayout.lineSize < 12 ? 12 : mLayout.lineSize ];
+  if( mPrintBuf == 0 )
+  {
+    delete [] mColorIndex; mColorIndex = 0;
+    return( Err_NoMemory );
+  }
+
+  return( Err_Success );
+}
+
+
+void CHexBuffer::setColor( SDisplayColor &color )
+{
+  mColor = color;
+
+  //
+  // Test...
+  //
+  //mColor.secondTextBg = TQt::yellow;
+  //mColor.offsetBg = TQt::lightGray;
+  //mColor.gridFg = TQt::darkCyan;
+
+  /*
+  mColor.secondTextBg = mColor.textBg;
+  mColor.offsetBg = mColor.textBg;
+  mColor.gridFg = mColor.textBg;
+  */
+
+  if( mColorIndex != 0 )
+  {
+    uint columnSize = mLayout.columnSize == 0 ? 1 : mLayout.columnSize;
+    for( uint i = 0, entry = 0;  i < mLayout.lineSize; i++ )
+    {
+      if( i > 0 && i % columnSize == 0 ) { entry = entry == 0 ? 1 : 0; }
+      mColorIndex[i] = entry;
+    }
+  }
+}
+
+void CHexBuffer::setInputMode( SDisplayInputMode &mode )
+{
+  mInputMode = mode;
+  if( mInputMode.allowResize == false && mEditMode != EditReplace )
+  {
+    setEditMode( EditReplace );
+  }
+}
+
+
+bool CHexBuffer::toggleEditor( void )
+{
+  bool changed;
+  if( mLayout.secondaryMode == SDisplayLayout::hide )
+  {
+    changed = mActiveEditor == edit_secondary ? true : false;
+    mActiveEditor = edit_primary;
+  }
+  else
+  {
+    changed = true;
+    mActiveEditor = mActiveEditor == edit_primary ?
+      edit_secondary : edit_primary;
+  }
+
+  setEditMode( mEditMode ); // Sets the cursor shapes as well
+
+  if( changed == true )
+  {
+    mCursor.resetCell();
+    cursorCompute();
+  }
+
+  return( changed );
+}
+
+
+
+
+
+
+
+bool CHexBuffer::matchWidth( uint width )
+{
+  if( documentPresent() == false || (uint)mFixedWidth >= width )
+  {
+    return( false );
+  }
+
+  width -= mFixedWidth;
+
+  uint  g = mLayout.columnSpacing == 0 ? 1 : mLayout.columnSize;
+  uint  n = g * mNumCell;
+  uint  u = mUnitWidth;
+  uint  s = mLayout.secondaryMode == SDisplayLayout::hide ? 0 : g;
+  uint  o = mLayout.columnSpacing == 0 ? 0 : mSplitWidth;
+  float x = (float)(width+o)/(float)(u*(n+s)+o);
+
+  uint lineSize = (uint)x * g;
+
+  if( mLayout.lockColumn == false )
+  {
+    //
+    // Examine if we can add one or more entries from the next column. This
+    // will make the rightmost column smaller than the rest but we will
+    // utilize as much of the available space (ie., width) as possible.
+    // (Note that the entry itself (which represents one byte of filedata)
+    // can not be splitted, eg., in binary mode the entry is eight byte
+    // wide and will not be splitted).
+    //
+    int w = (int)((float)((int)x)* (float)(u*(n+s)+o) - (float)o);
+    if( w > 0 && (uint)w < width )
+    {
+      width -= w;
+      if( width > o )
+      {
+	x = (float)(width-o) / (float)(u*(mNumCell+1));
+	lineSize += (uint)x;
+      }
+    }
+  }
+
+  if( lineSize == 0 || lineSize == mLayout.lineSize )
+  {
+    //
+    // We have to redraw all text if a change occurs so we avoid it if
+    // possible.
+    //
+    return( false );
+  }
+
+  mLayout.lineSize  = lineSize;
+  setLayout( mLayout );
+  return( true );
+}
+
+
+void CHexBuffer::setNonPrintChar( TQChar nonPrintChar )
+{
+  mFontInfo.nonPrintChar = nonPrintChar;
+}
+
+
+void CHexBuffer::setShowCursor( bool showCursor )
+{
+  mShowCursor = showCursor;
+}
+
+
+void CHexBuffer::setDisableCursor( bool disableCursor )
+{
+  mDisableCursor = disableCursor;
+}
+
+
+void CHexBuffer::setCursorShapeModifier( bool alwaysBlock, bool thickInsert )
+{
+  mCursor.setShapeModifier( alwaysBlock, thickInsert );
+  setEditMode( mEditMode );
+}
+
+void CHexBuffer::setEditMode( EEditMode editMode, bool alwaysBlock,
+			      bool thickInsert )
+{
+  mCursor.setShapeModifier( alwaysBlock, thickInsert );
+  setEditMode( editMode );
+}
+
+void CHexBuffer::setEditMode( EEditMode editMode )
+{
+  mEditMode = editMode;
+  if( mEditMode == EditInsert )
+  {
+    if( mActiveEditor == edit_primary )
+    {
+      mCursor.setShape( SCursorSpec::thin, SCursorSpec::frame, mUnitWidth,
+			mNumCell );
+    }
+    else
+    {
+      mCursor.setShape( SCursorSpec::frame, SCursorSpec::thin, mUnitWidth,
+			mNumCell );
+    }
+
+  }
+  else
+  {
+    if( mActiveEditor == edit_primary )
+    {
+      mCursor.setShape( SCursorSpec::solid, SCursorSpec::frame, mUnitWidth,
+			mNumCell );
+    }
+    else
+    {
+      mCursor.setShape( SCursorSpec::frame, SCursorSpec::solid, mUnitWidth,
+			mNumCell );
+    }
+  }
+}
+
+
+
+void CHexBuffer::setMaximumSize( uint maximumSize )
+{
+  if( maximumSize == 0 ) { maximumSize = ~0; }
+
+  mMaximumSize   = maximumSize;
+  mFixedSizeMode = maximumSize == (uint)~0 ? false : true;
+  mCursor.setFixedSizeMode( mFixedSizeMode );
+
+  if( mLayout.offsetVisible == false )
+  {
+    mOffsetSize  = 0;
+    mOffsetIndex = 0;
+    printOffset = &CHexBuffer::printDummyOffset;
+  }
+  else
+  {
+    if( mLayout.offsetMode ==  SDisplayLayout::decimal )
+    {
+      printOffset = &CHexBuffer::printDecimalOffset;
+      for( mOffsetSize=0; maximumSize > 0; mOffsetSize += 1 )
+      {
+	maximumSize = maximumSize / 10;
+      }
+      mOffsetIndex = 10 - mOffsetSize;
+    }
+    else if( mLayout.offsetMode == SDisplayLayout::hexadecimal )
+    {
+      if( mLayout.offsetUpperCase == true )
+      {
+	printOffset = &CHexBuffer::printHexadecimalBigOffset;
+      }
+      else
+      {
+	printOffset = &CHexBuffer::printHexadecimalSmallOffset;
+      }
+      for( mOffsetSize=0; maximumSize > 0; mOffsetSize += 1 )
+      {
+	maximumSize = maximumSize / 16;
+      }
+      if( mOffsetSize > 4 ) { mOffsetSize += 1; } // Space for the ':' sign
+      mOffsetIndex = 9 - mOffsetSize;
+    }
+    else
+    {
+      mLayout.offsetVisible = false;
+      mOffsetSize  = 0;
+      mOffsetIndex = 0;
+      printOffset = &CHexBuffer::printDummyOffset;
+    }
+  }
+}
+
+
+void CHexBuffer::setDocumentSize( uint size )
+{
+  if( size > mMaximumSize ) { size = mMaximumSize; }
+  mDocumentSize = size;
+  mCursor.setDocumentSize( size );
+  updateBookmarkMap(true);
+}
+
+
+void CHexBuffer::setUndoLevel( uint level )
+{
+  if( level < 10 ) { level = 10; }
+
+  if( level >= mUndoLimit )
+  {
+    mUndoLimit = level;
+    return;
+  }
+  else
+  {
+    //
+    // The maximum size decreases. If the list is larger than the the new
+    // limit, then reduce the list size starting with the oldest elements.
+    //
+    mUndoLimit = level;
+    while( mUndoList.count() >= mUndoLimit )
+    {
+      mUndoList.removeFirst();
+      mUndoIndex -= (mUndoIndex > 0 ? 1 : 0);
+    }
+  }
+}
+
+
+void CHexBuffer::setSoundState( bool inputSound, bool fatalSound )
+{
+  mInputErrorSound = inputSound;
+  mFatalErrorSound = fatalSound;
+}
+
+
+void CHexBuffer::setBookmarkVisibility( bool showInColumn, bool showInEditor )
+{
+  mShowBookmarkInOffsetColumn = showInColumn;
+  mShowBookmarkInEditor = showInEditor;
+}
+
+int CHexBuffer::writeFile( TQFile &file, CProgress &p )
+{
+  uint offset = 0;
+  uint remaining = documentSize();
+
+  do
+  {
+    const uint blockSize = TQMIN( 131072 /* == 1024 * 128 */  , remaining );
+    const int writeSize = file.writeBlock( data() + offset, blockSize );
+    if( writeSize == -1 )
+    {
+      p.finish();
+      return( Err_ReadFailed );
+    }
+    offset    += blockSize;
+    remaining -= blockSize;
+
+    if( p.expired() == true )
+    {
+      int errCode = p.step( (float)offset/(float)documentSize() );
+      if( errCode == Err_Stop && remaining > 0 )
+      {
+	p.finish();
+	return( Err_Success );
+      }
+    }
+  }
+  while( remaining > 0 );
+
+  p.finish();
+  mDocumentModified = false;
+  registerDiskModifyTime( file );
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::readFile( TQFile &file, const TQString &url, CProgress &p )
+{
+  if( resize( file.size() + 100 ) == false )
+  {
+    p.finish();
+    return( Err_NoMemory );
+  }
+
+  if( file.size() > 0 )
+  {
+    mLoadingData = true;
+    uint offset = 0;
+    uint remaining = file.size();
+    while( remaining > 0 )
+    {
+      const uint blockSize = TQMIN( 131072 /* == 1024 * 128 */  , remaining );
+      const int readSize = file.readBlock( data() + offset, blockSize );
+      if( readSize == -1 )
+      {
+        p.finish();
+	mLoadingData = false;
+	return( Err_ReadFailed );
+      }
+      for( uint i=0; i<blockSize; i++)
+      {
+	data()[offset+i] = mEncode[ (unsigned char) data()[offset+i] ];
+      }
+
+      offset    += blockSize;
+      remaining -= blockSize;
+
+      if( p.expired() == true )
+      {
+	int errCode = p.step( (float)offset/(float)file.size() );
+	if( errCode == Err_Stop && remaining > 0 )
+	{
+	  p.finish();
+	  return( Err_OperationAborted );
+	}
+      }
+    }
+    mLoadingData = false;
+  }
+
+  p.finish();
+
+  mDocumentModified = false;
+  setDocumentSize( file.size() );
+  registerDiskModifyTime( file );
+  setUrl( url );
+  computeNumLines();
+  mSelect.reset();
+  mMark.reset();
+  mUndoList.clear();
+  mUndoIndex = 0;
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::insertFile( TQFile &file, CProgress &p )
+{
+  if( file.size() == 0 )
+  {
+    p.finish();
+    return( Err_Success );
+  }
+
+  TQByteArray array( file.size() );
+  if( array.isNull() == true )
+  {
+    p.finish();
+    return( Err_NoMemory );
+  }
+
+  uint offset = 0;
+  uint remaining = file.size();
+  while( remaining > 0 )
+  {
+    const uint blockSize = TQMIN( 131072 /* == 1024 * 128 */  , remaining );
+    const int readSize = file.readBlock( array.data() + offset, blockSize );
+    if( readSize == -1 )
+    {
+      p.finish();
+      return( Err_ReadFailed );
+    }
+    for( uint i=0; i<blockSize; i++)
+    {
+      array[offset+i] = mEncode[ (unsigned char) array[offset+i] ];
+    }
+
+    offset    += blockSize;
+    remaining -= blockSize;
+
+    if( p.expired() == true )
+    {
+      int errCode = p.step( (float)offset/(float)file.size() );
+      if( errCode == Err_Stop && remaining > 0 )
+      {
+	p.finish();
+	return( Err_OperationAborted );
+      }
+    }
+  }
+
+  p.finish();
+
+  int errCode = inputAtCursor( array, 0 );
+  return( errCode );
+}
+
+
+int CHexBuffer::newFile( const TQString &url )
+{
+  if( resize( 100 ) == 0 )
+  {
+    return( Err_NoMemory );
+  }
+
+  mDocumentModified = false;
+  setDocumentSize( 0 );
+  setUrl( url );
+  computeNumLines();
+  mSelect.reset();
+
+  return( Err_Success );
+}
+
+
+void CHexBuffer::closeFile( void )
+{
+  resize(0);
+  computeNumLines();
+
+  mUndoList.clear();
+  mUndoIndex = 0;
+
+  setDocumentSize(0);
+  mDocumentModified = false;
+
+  TQString emptyUrl;
+  setUrl( emptyUrl );
+
+  mSelect.reset();
+  mMark.reset();
+
+  removeBookmark(-1); // Negative index - All bookmarks
+}
+
+
+void CHexBuffer::registerDiskModifyTime( const TQFile &file )
+{
+  TQFileInfo fileInfo( file );
+  mDiskModifyTime = fileInfo.lastModified();
+}
+
+
+
+void CHexBuffer::setFont( const SDisplayFontInfo &fontInfo )
+{
+  mFontInfo = fontInfo;
+  TQFontMetrics fm( mFontInfo.font );
+  mFontHeight = fm.height();
+  mFontAscent = fm.ascent();
+  computeLineWidth();
+
+  for( int i=0; i < 256; i++ )
+  {
+    mCharValid[i] = TQChar(i).isPrint();
+  }
+
+  /*
+  TQFontInfo info( mFontInfo.font );
+  puts("CHexBuffer mCharValid broken");
+
+  KCharset charset( info.charSet() );
+  for( int i=0; i < 256; i++ )
+  {
+    mCharValid[i] = charset.printable(i);
+  }
+  */
+}
+
+
+int CHexBuffer::setEncoding( CConversion::EMode mode, CProgress &p )
+{
+  int errCode = mEncode.convert( *this, mode, p );
+  if( errCode == Err_Success )
+  {
+    //
+    // The cursor stores the byte it is "covering", so this information
+    // must be updated.
+    //
+    cursorCompute();
+  }
+
+  return( errCode );
+}
+
+
+
+
+void CHexBuffer::computeLineWidth( void )
+{
+  TQFontMetrics fm( mFontInfo.font );
+  mUnitWidth  = fm.width( "M" );
+
+  if( mLayout.primaryMode == SDisplayLayout::textOnly )
+  {
+    mSplitWidth = 0;
+  }
+  else if( mLayout.columnCharSpace == true )
+  {
+    mSplitWidth = mUnitWidth;
+  }
+  else
+  {
+    mSplitWidth = mLayout.columnSpacing;
+  }
+
+  setMaximumSize( mMaximumSize );
+
+  if( mLayout.primaryMode == SDisplayLayout::hexadecimal )
+  {
+    mNumCell = 2;
+    mCursor.setCellWeight( 4 );
+    if( mLayout.primaryUpperCase == true )
+    {
+      printCell = &CHexBuffer::printHexadecimalBigCell;
+      inputCell = &CHexBuffer::inputHexadecimal;
+    }
+    else
+    {
+      printCell = &CHexBuffer::printHexadecimalSmallCell;
+      inputCell = &CHexBuffer::inputHexadecimal;
+    }
+  }
+  else if( mLayout.primaryMode == SDisplayLayout::decimal )
+  {
+    mNumCell  = 3;
+    printCell = &CHexBuffer::printDecimalCell;
+    inputCell = &CHexBuffer::inputDecimal;
+    mCursor.setCellWeight( 3 );
+  }
+  else if( mLayout.primaryMode == SDisplayLayout::octal )
+  {
+    mNumCell  = 3;
+    printCell = &CHexBuffer::printOctalCell;
+    inputCell = &CHexBuffer::inputOctal;
+    mCursor.setCellWeight( 3 );
+  }
+  else if( mLayout.primaryMode == SDisplayLayout::binary )
+  {
+    mNumCell  = 8;
+    printCell = &CHexBuffer::printBinaryCell;
+    inputCell = &CHexBuffer::inputBinary;
+    mCursor.setCellWeight( 1 );
+  }
+  else if( mLayout.primaryMode == SDisplayLayout::textOnly )
+  {
+    mNumCell  = 1;
+    printCell = &CHexBuffer::printAsciiCell;
+    inputCell = &CHexBuffer::inputAscii;
+    mCursor.setCellWeight( 8 );
+  }
+  else
+  {
+    mNumCell  = 2;
+    mLayout.primaryMode = SDisplayLayout::hexadecimal;
+    mLayout.primaryUpperCase = false;
+    printCell = &CHexBuffer::printHexadecimalSmallCell;
+    inputCell = &CHexBuffer::inputHexadecimal;
+    mCursor.setCellWeight( 4 );
+  }
+
+  //
+  // 'mPrimaryWidth' is the number of pixels that are needed to display a
+  // line in the primary field.
+  //
+  mPrimaryWidth = mLayout.lineSize * mNumCell * mUnitWidth;
+
+  if( mLayout.columnSpacing != 0 )
+  {
+    int numSplit = mLayout.lineSize / mLayout.columnSize;
+    numSplit -= mLayout.lineSize % mLayout.columnSize == 0 ? 1 : 0;
+    mPrimaryWidth += numSplit * mSplitWidth;
+  }
+
+  //
+  // 'mSecondaryWidth' is the number of pixels that are needed to display a
+  // line in the secondary field (there are no spaces).
+  //
+  if( mLayout.secondaryMode == SDisplayLayout::hide )
+  {
+    mSecondaryWidth = 0;
+  }
+  else
+  {
+    mSecondaryWidth = mLayout.lineSize * mUnitWidth;
+  }
+
+  //
+  // 'mLineWidth' is the total number of pixels required to display
+  // offset data, separators, primary and secondary data on a line.
+  //
+  mLineWidth = mPrimaryWidth + mSecondaryWidth + mOffsetSize * mUnitWidth;
+
+  //
+  // The 'mFixedWidth' is the number of pixels of the width that stays the
+  // same regardless of how many characters that are displayed.
+  // This entity consists of the edge margins, the inner margins and the
+  // separators.
+  //
+  mFixedWidth = mOffsetSize * mUnitWidth;
+
+  //
+  // The edge margin is always present in both ends.
+  //
+  mLineWidth  += mLayout.edgeMarginWidth * 2;
+  mFixedWidth += mLayout.edgeMarginWidth * 2;
+
+  //
+  // 'mTextStart1' is the number of pixels from the left edge where the
+  // primary field starts.
+  //
+  mTextStart1 = mLayout.edgeMarginWidth;
+  if( mLayout.offsetVisible == true )
+  {
+    int width;
+    if( mLayout.leftSeparatorWidth > 0 )
+    {
+      width = mLayout.separatorMarginWidth * 2 + mLayout.leftSeparatorWidth;
+    }
+    else
+    {
+      width = (mLayout.separatorMarginWidth * 3) / 2;
+    }
+
+    mLineWidth  += width;
+    mFixedWidth += width;
+    mTextStart1 += width + mOffsetSize * mUnitWidth;
+  }
+
+  //
+  // 'mTextStart2' is the number of pixels from the left edge where the
+  // secondary fields start.
+  //
+  mTextStart2 = mTextStart1;
+  if( mLayout.secondaryMode != SDisplayLayout::hide )
+  {
+    int width;
+    if( mLayout.rightSeparatorWidth > 0 )
+    {
+      width = mLayout.separatorMarginWidth * 2 + mLayout.rightSeparatorWidth;
+    }
+    else
+    {
+      width = (mLayout.separatorMarginWidth * 3) / 2;
+    }
+
+    mLineWidth  += width;
+    mFixedWidth += width;
+    mTextStart2 += width + mPrimaryWidth;
+  }
+
+  setEditMode( mEditMode );
+  computeNumLines();
+}
+
+
+void CHexBuffer::computeNumLines( void )
+{
+  if( mLayout.lineSize == 0 )
+  {
+    mNumLines = 1;
+  }
+  else
+  {
+    uint s = mFixedSizeMode == true ? mMaximumSize : documentSize() + 1;
+    mNumLines = s / mLayout.lineSize + (s % mLayout.lineSize ? 1 : 0);
+  }
+}
+
+
+
+void CHexBuffer::drawSelection( TQPainter &paint, TQColor &color, uint start,
+				uint stop, int sx )
+{
+  if( start >= stop ) { return; }
+  uint width = stop - start;
+
+  uint addStart, addWidth;
+  addStart = (start / mLayout.columnSize) * mSplitWidth;
+  if( width == 0 )
+  {
+    addWidth = 0;
+  }
+  else
+  {
+    uint g = mLayout.columnSize;
+    addWidth = (((start % g) + width - 1) / g) * mSplitWidth;
+  }
+
+  int offset = mTextStart1 - sx;
+  paint.fillRect( offset + start * mNumCell * mUnitWidth + addStart,
+		  0, width * mNumCell * mUnitWidth + addWidth,
+		  mFontHeight, color );
+
+  if( mLayout.secondaryMode != SDisplayLayout::hide )
+  {
+    offset = mTextStart2 - sx;
+    paint.fillRect( offset + start * mUnitWidth,
+		    0, width * mUnitWidth,
+		    mFontHeight, color );
+  }
+}
+
+
+
+
+
+void CHexBuffer::drawText( TQPainter &paint, uint line, int sx, int x1, int x2 )
+{
+  uint fileOffset = line * mLayout.lineSize;
+  if( documentPresent() == false || mLoadingData == true )
+  {
+    paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.inactiveBg );
+    return;
+  }
+
+  bool outsideText;
+  if( size() == 0 || fileOffset > documentSize() || fileOffset >= mMaximumSize)
+  {
+    outsideText = true;
+  }
+  else
+  {
+    outsideText = false;
+  }
+
+  if( (line+1) % 2 || outsideText == true )
+  {
+    paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.textBg );
+  }
+  else
+  {
+    paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.secondTextBg );
+  }
+  if( mLayout.horzGridWidth > 0 && outsideText == false )
+  {
+    paint.setPen( mColor.gridFg );
+    paint.drawLine( x1, mFontHeight, x2, mFontHeight );
+  }
+
+  if( mSelect.inside( fileOffset, mLayout.lineSize ) == true )
+  {
+    uint start = mSelect.start( fileOffset );
+    uint stop  = mSelect.stop( fileOffset, mLayout.lineSize );
+    drawSelection( paint, mColor.selectBg, start, stop, sx );
+  }
+
+  //
+  // A marked area will be displayed "above" a selcted area (given
+  // the mark background color is different)
+  //
+  if( mMark.inside( fileOffset, mLayout.lineSize ) == true )
+  {
+    uint start = mMark.start( fileOffset );
+    uint stop  = mMark.stop( fileOffset, mLayout.lineSize );
+    drawSelection( paint, mColor.markBg, start, stop, sx );
+  }
+
+  uint dataSize;
+  unsigned char *fileData;
+  if( outsideText == true )
+  {
+    if( size() == 0 )
+    {
+      return;
+    }
+    dataSize = 0;
+    fileData = 0;
+  }
+  else
+  {
+    dataSize = documentSize() - fileOffset;
+    if( dataSize > mLayout.lineSize ) { dataSize = mLayout.lineSize; }
+    fileData = (unsigned char*)&(data()[ fileOffset ]);
+  }
+
+  //
+  // Compute the offset area size. We postpose the actual drawing
+  // until we have drawn any bookmark indicators in the editor areas.
+  // because we may want to draw an indicator in the offset area as well.
+  //
+  int offset = mLayout.edgeMarginWidth - sx;
+  if( mLayout.offsetVisible == true )
+  {
+    offset += mOffsetSize * mUnitWidth;
+    if( mLayout.leftSeparatorWidth > 0 )
+    {
+      offset += mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth*2;
+    }
+    else
+    {
+      offset += (mLayout.separatorMarginWidth * 3) / 2;
+    }
+  }
+
+
+  #if 0
+  int offset = mLayout.edgeMarginWidth - sx;
+  if( mLayout.offsetVisible == true )
+  {
+    int s0 = mOffsetSize * mUnitWidth;
+    int s1 = s0 + mLayout.separatorMarginWidth + mLayout.edgeMarginWidth - sx;
+    if( x1 < s1 && x2 > 0 )
+    {
+      if( outsideText == true )
+      {
+	paint.fillRect( 0, 0, s1, lineHeight(), mColor.offsetBg );
+      }
+      else
+      {
+	//
+	// I want to display the grid here so I cant use lineHeight()
+	//
+	paint.fillRect( 0, 0, s1, mFontHeight, mColor.offsetBg );
+      }
+    }
+
+    if( x1 < offset + s0 && x2 >= offset && fileData != 0 )
+    {
+      paint.setPen( mColor.offsetFg );
+      THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
+      // ## paint.drawText(offset,mFontAscent,&mPrintBuf[mOffsetIndex],
+      // mOffsetSize);
+      paint.drawText( offset, mFontAscent, 
+		      TQString::fromLocal8Bit(&mPrintBuf[mOffsetIndex]),
+		      mOffsetSize );
+    }
+    offset += s0;
+
+    if( mLayout.leftSeparatorWidth > 0 )
+    {
+      offset += mLayout.separatorMarginWidth;
+
+      int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
+      if( x1 < offset + s2 && x2 >= offset )
+      {
+	TQPen pen( mColor.leftSeparatorFg, mLayout.leftSeparatorWidth );
+	paint.setPen( pen );
+	int center = offset + mLayout.leftSeparatorWidth/2;
+	paint.drawLine( center, 0, center, lineHeight() );
+      }
+      offset += s2;
+    }
+    else
+    {
+      offset += (mLayout.separatorMarginWidth * 3) / 2;
+    }
+  }
+  #endif
+
+
+  //
+  // Draw the primary area
+  //
+  int localOffset = offset;
+  for( uint i = 0; i < dataSize; i++ )
+  {
+    int s = mNumCell * mUnitWidth +
+      ((i+1) % mLayout.columnSize == 0) * mSplitWidth;
+    if( x1 < localOffset + s && x2 >= localOffset )
+    {
+      int flag = THIS_FPTR(printCell)( mPrintBuf, fileData[i] );
+      if( mSelect.inside( fileOffset+i ) )
+      {
+	paint.setPen( mColor.selectFg );
+      }
+      else if( mMark.inside( fileOffset+i ) )
+      {
+	paint.setPen( mColor.markFg );
+      }
+      else
+      {
+	paint.setPen( flag == 0 ? foregroundColor( i ) : mColor.nonPrintFg );
+      }
+
+      // ## paint.drawText( localOffset, mFontAscent, mPrintBuf, mNumCell );
+      paint.drawText( localOffset, mFontAscent, 
+		      TQString::fromLocal8Bit(mPrintBuf), mNumCell );
+    }
+    localOffset += s;
+
+    if( mLayout.vertGridWidth > 0 && i+1 < dataSize )
+    {
+      if( (i+1) % mLayout.columnSize == 0 )
+      {
+	paint.setPen( mColor.gridFg );
+	int x = localOffset - (mSplitWidth+1) / 2;
+	paint.drawLine( x, 0, x, mFontHeight );
+      }
+    }
+  }
+
+  //
+  // Draw the secondary area
+  //
+  offset += mPrimaryWidth;
+  if( mLayout.secondaryMode != SDisplayLayout::hide )
+  {
+    if( mLayout.rightSeparatorWidth > 0 )
+    {
+      offset += mLayout.separatorMarginWidth;
+      int s = mLayout.separatorMarginWidth + mLayout.rightSeparatorWidth;
+      if( x1 < offset + s && x2 >= offset )
+      {
+	TQPen pen( mColor.rightSeparatorFg, mLayout.rightSeparatorWidth );
+	paint.setPen( pen );
+	int center = offset + mLayout.rightSeparatorWidth/2;
+	paint.drawLine( center, 0, center, lineHeight() );
+      }
+      offset += s;
+    }
+    else
+    {
+      offset += (mLayout.separatorMarginWidth * 3) / 2;
+    }
+
+    int s = mUnitWidth;
+    for( uint i = 0; i < dataSize; i++ )
+    {
+      if( x1 < offset + s && x2 >= offset )
+      {
+	int flag = printAsciiCell( mPrintBuf, fileData[i] );
+	if( mSelect.inside( fileOffset+i ) )
+	{
+	  paint.setPen( mColor.selectFg );
+	}
+	else if( mMark.inside( fileOffset+i ) )
+	{
+	  paint.setPen( mColor.markFg );
+	}
+	else
+	{
+	  paint.setPen( flag == 0 ? mColor.secondaryFg : mColor.nonPrintFg );
+	}
+
+	// ## paint.drawText( offset, mFontAscent, mPrintBuf, 1 );
+	paint.drawText( offset, mFontAscent, 
+			TQString::fromLocal8Bit(mPrintBuf), 1 );
+      }
+      offset += s;
+    }
+  }
+
+  //
+  // Draw the bookmark identifiers on this line (if any).  We use the
+  // bitmask to minimize the number of times we try to draw the bookmarks.
+  //
+  int bookmarkPosition = 0;
+  if( mBookmarkMap.testBit(fileOffset/200) ||
+      mBookmarkMap.testBit((fileOffset+mLayout.lineSize-1)/200 ) )
+  {
+    // Returns a bookmark postion state
+    bookmarkPosition = drawBookmarks( paint, line, sx );
+  }
+
+  //
+  // Draw the offset area. We have delayed the drawing until now because
+  // it is possible to draw a bookmark indicator in this area.
+  //
+  offset = mLayout.edgeMarginWidth - sx;
+  if( mLayout.offsetVisible == true )
+  {
+    int s0 = mOffsetSize * mUnitWidth;
+    int s1 = s0 + mLayout.separatorMarginWidth + mLayout.edgeMarginWidth - sx;
+    if( x1 < s1 && x2 > 0 )
+    {
+      TQColor bg = mShowBookmarkInOffsetColumn &&
+	(bookmarkPosition & BookmarkOnLine) ?
+	mColor.bookmarkBg : mColor.offsetBg;
+      if( outsideText == true )
+      {
+	paint.fillRect( 0, 0, s1, lineHeight(), bg );
+      }
+      else
+      {
+	//
+	// I want to display the grid here so I cant use lineHeight()
+	//
+	paint.fillRect( 0, 0, s1, mFontHeight, bg );
+      }
+    }
+
+    if( x1 < offset + s0 && x2 >= offset && fileData != 0 )
+    {
+      paint.setPen( mShowBookmarkInOffsetColumn &&
+		    bookmarkPosition & BookmarkOnLine ?
+		    mColor.bookmarkFg : mColor.offsetFg );
+      THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
+      // ## paint.drawText(offset,mFontAscent,&mPrintBuf[mOffsetIndex],
+      // mOffsetSize);
+      paint.drawText( offset, mFontAscent, 
+		      TQString::fromLocal8Bit(&mPrintBuf[mOffsetIndex]),
+		      mOffsetSize );
+    }
+
+    offset += s0;
+
+    if( mLayout.leftSeparatorWidth > 0 )
+    {
+      offset += mLayout.separatorMarginWidth;
+
+      int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
+      if( x1 < offset + s2 && x2 >= offset )
+      {
+	TQPen pen( mColor.leftSeparatorFg, mLayout.leftSeparatorWidth );
+	paint.setPen( pen );
+	int center = offset + mLayout.leftSeparatorWidth/2;
+	paint.drawLine( center, 0, center, lineHeight() );
+      }
+    }
+  }
+
+
+  //
+  // If the cursors are located on the line we have drawn we redraw
+  // them unless they have been disabled.
+  //
+  if( mDisableCursor == false )
+  {
+    if( mCursor.curr.inside( fileOffset, fileOffset + mLayout.lineSize ) )
+    {
+      drawCursor( paint, line, sx, bookmarkPosition & BookmarkOnCursor );
+    }
+  }
+
+}
+
+
+
+
+void CHexBuffer::drawText( TQPainter &paint, uint line, int x1, int x2, int y,
+			   bool useBlackWhite )
+{
+  uint fileOffset = line * mLayout.lineSize;
+
+  bool outsideText;
+  if( size() == 0 || fileOffset > documentSize() || fileOffset >= mMaximumSize)
+  {
+    outsideText = true;
+  }
+  else
+  {
+    outsideText = false;
+  }
+
+  if( (line+1) % 2 || outsideText == true )
+  {
+    paint.fillRect( x1, y, x2, lineHeight(),
+		    useBlackWhite == true ? TQt::white : mColor.textBg );
+  }
+  else
+  {
+    paint.fillRect( x1, y, x2, lineHeight(),
+		    useBlackWhite == true ? TQt::white : mColor.secondTextBg );
+  }
+
+  if( mLayout.horzGridWidth > 0 && outsideText == false )
+  {
+    TQPen pen( useBlackWhite == true ? TQt::black : mColor.gridFg,
+	      mLayout.horzGridWidth );
+    paint.setPen( pen );
+    paint.drawLine( x1, y+mFontHeight, x2+x1, y+mFontHeight );
+  }
+
+  uint dataSize;
+  unsigned char *fileData;
+  if( outsideText == true )
+  {
+    if( size() == 0 )
+    {
+      return;
+    }
+    dataSize = 0;
+    fileData = 0;
+  }
+  else
+  {
+    dataSize = documentSize() - fileOffset;
+    if( dataSize > mLayout.lineSize ) { dataSize = mLayout.lineSize; }
+    fileData = (unsigned char*)&(data()[ fileOffset ]);
+  }
+
+  int offset = mLayout.edgeMarginWidth + x1;
+
+  if( mLayout.offsetVisible == true )
+  {
+    int s1 = mOffsetSize * mUnitWidth;
+    if( fileData != 0 )
+    {
+      paint.setPen( useBlackWhite == true ? TQt::black : mColor.offsetFg );
+      THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
+      // ## paint.drawText( offset, mFontAscent+y, &mPrintBuf[mOffsetIndex],
+      // mOffsetSize );
+      paint.drawText( offset, mFontAscent+y, 
+		      TQString::fromLocal8Bit(&mPrintBuf[mOffsetIndex]), 
+ 		      mOffsetSize );
+    }
+    offset += s1;
+
+    if( mLayout.leftSeparatorWidth > 0 )
+    {
+      offset += mLayout.separatorMarginWidth;
+
+      int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
+      TQPen pen( useBlackWhite == true ? TQt::black : mColor.leftSeparatorFg,
+		mLayout.leftSeparatorWidth );
+      paint.setPen( pen );
+      int center = offset + mLayout.leftSeparatorWidth/2;
+      paint.drawLine( center, y, center, mFontHeight+y );
+      offset += s2;
+    }
+    else
+    {
+      offset += (mLayout.separatorMarginWidth * 3) / 2;
+    }
+  }
+
+  int localOffset = offset;
+  for( uint i = 0; i < dataSize; i++ )
+  {
+    int s = mNumCell * mUnitWidth +
+      ((i+1) % mLayout.columnSize == 0) * mSplitWidth;
+    int flag = THIS_FPTR(printCell)( mPrintBuf, fileData[i] );
+    if( useBlackWhite == true )
+    {
+      paint.setPen( TQt::black );
+    }
+    else
+    {
+      paint.setPen( flag == 0 ? foregroundColor( i ) : mColor.nonPrintFg );
+    }
+    // ## paint.drawText( localOffset, mFontAscent+y, mPrintBuf, mNumCell );
+    paint.drawText( localOffset, mFontAscent+y, 
+		    TQString::fromLocal8Bit(mPrintBuf), mNumCell );
+    localOffset += s;
+
+    if( mLayout.vertGridWidth > 0 && i+1 < dataSize )
+    {
+      if( (i+1) % mLayout.columnSize == 0 )
+      {
+	TQPen pen( useBlackWhite == true ? TQt::black : mColor.gridFg,
+		  mLayout.vertGridWidth );
+	paint.setPen( pen );
+	int x = localOffset - (mSplitWidth+1) / 2;
+	paint.drawLine( x, y, x, y+mFontHeight );
+      }
+    }
+
+  }
+
+  offset += mPrimaryWidth;
+
+  if( mLayout.secondaryMode != SDisplayLayout::hide )
+  {
+    if( mLayout.rightSeparatorWidth > 0 )
+    {
+      offset += mLayout.separatorMarginWidth;
+      int s = mLayout.separatorMarginWidth + mLayout.rightSeparatorWidth;
+      TQPen pen( useBlackWhite == true ? TQt::black : mColor.rightSeparatorFg,
+		mLayout.rightSeparatorWidth );
+      paint.setPen( pen );
+      int center = offset + mLayout.rightSeparatorWidth/2;
+      paint.drawLine( center, y, center, mFontHeight+y );
+      offset += s;
+    }
+    else
+    {
+      offset += (mLayout.separatorMarginWidth * 3) / 2;
+    }
+
+
+    int s = mUnitWidth;
+    for( uint i = 0; i < dataSize; i++ )
+    {
+      int flag = printAsciiCell( mPrintBuf, fileData[i] );
+      if( useBlackWhite == true )
+      {
+	paint.setPen( TQt::black );
+      }
+      else
+      {
+	paint.setPen( flag == 0 ? mColor.secondaryFg : mColor.nonPrintFg );
+      }
+      // ## paint.drawText( offset, mFontAscent+y, mPrintBuf, 1 );
+      paint.drawText( offset, mFontAscent+y, 
+		      TQString::fromLocal8Bit(mPrintBuf), 1 );
+      offset += s;
+    }
+  }
+
+}
+
+
+int CHexBuffer::headerHeight( TQPainter &paint )
+{
+  TQFont font( paint.font() );
+  paint.setFont( TDEGlobalSettings::generalFont() );
+  const TQFontMetrics &fm = paint.fontMetrics();
+
+  int height = fm.height();
+  paint.setFont( font );
+  return( height );
+}
+
+int CHexBuffer::headerMargin( TQPainter &paint )
+{
+  TQFont font( paint.font() );
+  paint.setFont( TDEGlobalSettings::generalFont() );
+  const TQFontMetrics &fm = paint.fontMetrics();
+
+  int margin = fm.height() / 2;
+  paint.setFont( font );
+  return( margin );
+}
+
+
+void CHexBuffer::drawHeader( TQPainter &paint, int sx, int width, int y,
+			     bool isFooter, const SPageHeader &header,
+			     const SPagePosition &position )
+{
+  TQFont font( paint.font() );
+  paint.setFont( TDEGlobalSettings::generalFont() );
+  const TQFontMetrics &fm = paint.fontMetrics();
+
+  paint.fillRect( sx, y, width, fm.height(), TQt::white );
+  paint.setPen( TQt::black );
+  if( header.line == SPageHeader::SingleLine )
+  {
+    if( isFooter == false )
+    {
+      paint.drawLine( sx, y+fm.height(), sx+width, y+fm.height() );
+    }
+    else
+    {
+      paint.drawLine( sx, y, sx+width, y );
+    }
+  }
+  else if( header.line == SPageHeader::Rectangle )
+  {
+    paint.drawRect( sx, y, width, fm.height() );
+  }
+
+  int pos[3] =
+  {
+    TQPainter::AlignLeft, TQPainter::AlignHCenter, TQPainter::AlignRight
+  };
+
+  TQString msg;
+  for( int i=0; i<3; i++ )
+  {
+    if( header.pos[i] == SPageHeader::DateTime )
+    {
+      TQDateTime datetime;
+      datetime.setTime_t( position.now );
+      msg = TDEGlobal::locale()->formatDateTime(datetime);
+    }
+    else if( header.pos[i] == SPageHeader::PageNumber )
+    {
+      msg = i18n("Page %1 of %2")
+        .arg(TDEGlobal::locale()->formatNumber(position.curPage, 0))
+        .arg(TDEGlobal::locale()->formatNumber(position.maxPage, 0));
+    }
+    else if( header.pos[i] == SPageHeader::FileName )
+    {
+      msg = mUrl;
+    }
+    else
+    {
+      continue;
+    }
+
+    if( 0 && pos[i] == TQPainter::AlignRight )
+    {
+      //const TQFontMetrics &f = TQFontMetrics( TDEGlobalSettings::generalFont() );
+      //TQRect r = paint.boundingRect(sx, y, width, fm.height(), pos[i], msg );
+      //printf("R: %d, %d, %d, %d\n", r.x(), r.y(), r.width(), r.height() );
+
+      int x = sx + width - /*r.width();*/ fm.width(msg);
+      paint.drawText( x, y+fm.height(), msg );
+      //printf("paint at %d\n", x );
+    }
+    else
+    {
+      paint.drawText( sx, y, width, fm.height(), pos[i], msg );
+    }
+  }
+
+  //
+  // restore original font.
+  //
+  paint.setFont( font );
+}
+
+
+
+
+int CHexBuffer::drawBookmarks( TQPainter &paint, uint line, int startx )
+{
+  if( documentPresent() == false || mLoadingData == true )
+  {
+    return( 0 );
+  }
+
+  uint start = line*mLayout.lineSize;
+  uint stop  = start+mLayout.lineSize;
+  TQColor bg  = mColor.bookmarkBg;
+  TQColor fg  = mColor.bookmarkFg;
+
+  int bookmarkPosition = 0;
+
+  for( SCursorOffset *c=mBookmarkList.first(); c!=0; c=mBookmarkList.next() )
+  {
+    if( c->offset >= start && c->offset < stop )
+    {
+      int x = c->offset - start;
+      int x1 = mTextStart1 + x * mUnitWidth * mNumCell;
+      x1 += (x / mLayout.columnSize) * mSplitWidth;
+      int x2 = mTextStart2 + x * mUnitWidth;
+
+      bookmarkPosition |= BookmarkOnLine;
+
+      if( mShowBookmarkInEditor == false )
+      {
+	continue;
+      }
+
+      uint offset = line*mLayout.lineSize+x;
+      if( offset == mCursor.curr.offset )
+      {
+	bookmarkPosition |= BookmarkOnCursor;
+      }
+
+      if( mSelect.inside( offset ) || mMark.inside( offset ) )
+      {
+	paint.fillRect( x1-startx, 2, mUnitWidth*mNumCell, mFontHeight-4, bg );
+	if( mLayout.secondaryMode != SDisplayLayout::hide )
+	{
+	  paint.fillRect( x2-startx, 2, mUnitWidth, mFontHeight-4, bg );
+	}
+      }
+      else
+      {
+	paint.fillRect( x1-startx, 1, mUnitWidth*mNumCell, mFontHeight-2, bg );
+	if( mLayout.secondaryMode != SDisplayLayout::hide )
+	{
+	  paint.fillRect( x2-startx, 1, mUnitWidth, mFontHeight-2, bg );
+	}
+      }
+
+      unsigned char c = (data()[ line*mLayout.lineSize+x]);
+
+      int flag = THIS_FPTR(printCell)( mPrintBuf, c );
+      paint.setPen( flag == 0 ? fg : mColor.nonPrintFg );
+      // ## paint.drawText( x1-startx, mFontAscent, mPrintBuf, mNumCell );
+      paint.drawText( x1-startx, mFontAscent, 
+		      TQString::fromLocal8Bit(mPrintBuf), mNumCell );
+      if( mLayout.secondaryMode != SDisplayLayout::hide )
+      {
+	flag = printAsciiCell( mPrintBuf, c );
+	paint.setPen( flag == 0 ? fg : mColor.nonPrintFg );
+	// ## paint.drawText( x2-startx, mFontAscent, mPrintBuf, 1 );	
+	paint.drawText( x2-startx, mFontAscent, 
+			TQString::fromLocal8Bit(mPrintBuf), 1 );
+      }
+    }
+  }
+
+  return bookmarkPosition;
+}
+
+
+
+void CHexBuffer::drawCursor( TQPainter &paint, uint line, int startx,
+			     bool onBookmark )
+{
+  if( documentPresent() == false || mLoadingData == true )
+  {
+    return;
+  }
+
+  SCursorSpec &c = mCursor.curr;
+
+  //
+  // Draw the cursor in primary edit area.
+  //
+  TQColor bg, fg;
+  bool useFg;
+  if( mMark.inside( c.offset ) == true )
+  {
+    bg = mColor.markBg;
+    fg = mSelect.inside( c.offset ) ? mColor.selectFg : mColor.markFg;
+    useFg = true;
+  }
+  else if( mSelect.inside( c.offset ) == true )
+  {
+    bg = mColor.selectBg;
+    fg = mColor.selectFg;
+    useFg = true;
+  }
+  else
+  {
+    bg = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
+    fg = foregroundColor( c.offset % mLayout.lineSize );
+    useFg = false; // Can be true later.
+  }
+
+  TQColor cbg = mColor.cursorBg;
+  TQColor cfg = mColor.cursorFg;
+
+  //
+  // Fill in the general backround color
+  //
+  paint.fillRect( c.x1 - startx, 0, mUnitWidth, mFontHeight, bg );
+  if( onBookmark == true )
+  {
+    int w = mUnitWidth * (mNumCell-c.cell); // Rest of cell
+    if( useFg == true )
+    {
+      paint.fillRect( c.x1-startx, 2, w, mFontHeight-4, mColor.bookmarkBg );
+    }
+    else
+    {
+      paint.fillRect( c.x1-startx, 1, w, mFontHeight-2, mColor.bookmarkBg );
+    }
+  }
+
+  //
+  // Draw the cursor shape
+  //
+  bool transparent = false;
+  if( mActiveEditor == edit_primary )
+  {
+    if( mShowCursor == true ) // Cursor blink on
+    {
+      if( c.mPrimaryShape == SCursorSpec::thin )
+      {
+	paint.setPen( cbg );
+	int center = c.x1 - startx - 1;
+	transparent = true;
+	
+	if( c.thickState == true )
+	{
+	  paint.drawLine( center, 0, center, mFontHeight - 1 );
+	  paint.drawLine( center+1, 0, center+1, mFontHeight - 1 );
+	}
+	else
+	{
+	  paint.drawLine( center, 0, center, mFontHeight - 1 );
+	  paint.drawLine( center-2, 0, center+2, 0 );
+	  paint.drawLine( center-2, mFontHeight-1, center+2, mFontHeight-1 );
+	}
+      }
+      else // Solid block shape
+      {
+	paint.fillRect( c.x1 - startx, 0, mUnitWidth, mFontHeight, cbg );
+	useFg = true;
+	fg = cfg;
+      }
+    }
+  }
+  else
+  {
+    transparent = true;
+    paint.setPen( cbg );
+    paint.drawRect( c.x1 - startx, 0, mUnitWidth*mNumCell, mFontHeight );
+  }
+
+  //
+  // Draw the text on the cursor position and to the end of the cell.
+  //
+  if( c.offset < documentSize() )
+  {
+    int flag = THIS_FPTR(printCell)( mPrintBuf, (unsigned char)c.data );
+    if( onBookmark == true )
+    {
+      // Inside bookmark. Draw text with bookmark foreground.
+      paint.setPen( mColor.bookmarkFg );
+      // ## paint.drawText( c.x1-startx, mFontAscent, &mPrintBuf[c.cell],
+      // mNumCell-c.cell );
+      paint.drawText( c.x1-startx, mFontAscent, 
+		      TQString::fromLocal8Bit(&mPrintBuf[c.cell]), 
+ 		      mNumCell-c.cell );
+    }
+
+    if( transparent == false || onBookmark == false )
+    {
+      paint.setPen( flag == 0 || useFg == true ? fg : mColor.nonPrintFg );
+      // ## paint.drawText( c.x1 - startx, mFontAscent, &mPrintBuf[c.cell], 1);
+      paint.drawText( c.x1 - startx, mFontAscent, 
+		      TQString::fromLocal8Bit(&mPrintBuf[c.cell]), 1 );
+    }
+  }
+
+  //
+  // Draw the cursor in secodary edit area.
+  //
+  if( mLayout.secondaryMode == SDisplayLayout::hide )
+  {
+    return;
+  }
+
+
+  if( mMark.inside( c.offset ) == true )
+  {
+    bg = mColor.markBg;
+    fg = mSelect.inside( c.offset ) ? mColor.selectFg : mColor.markFg;
+    useFg = true;
+  }
+  else if( mSelect.inside( c.offset ) == true )
+  {
+    bg = mColor.selectBg;
+    fg = mColor.selectFg;
+    useFg = true;
+  }
+  else
+  {
+    bg = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
+    fg = mColor.secondaryFg;
+    useFg = false; // Can be true later.
+  }
+
+
+
+  //
+  // Fill in the general backround color
+  //
+  if( onBookmark == true )
+  {
+    if( useFg == true )
+    {
+      paint.fillRect( c.x2-startx, 2, mUnitWidth, mFontHeight-4,
+		      mColor.bookmarkBg );
+    }
+    else
+    {
+      paint.fillRect( c.x2-startx, 1, mUnitWidth, mFontHeight-2,
+		      mColor.bookmarkBg );
+    }
+  }
+  else
+  {
+    paint.fillRect( c.x2 - startx, 0, mUnitWidth, mFontHeight, bg );
+  }
+
+  //
+  // Draw the cursor shape
+  //
+  transparent = false;
+  if( mActiveEditor == edit_secondary )
+  {
+    if( mShowCursor == true ) // Cursor blink on
+    {
+      if( c.mSecondaryShape == SCursorSpec::thin )
+      {
+	paint.setPen( cbg );
+	int center = c.x2 - startx - 1;
+	transparent = true;
+
+	if( c.thickState == true )
+	{
+	  paint.drawLine( center, 0, center, mFontHeight - 1 );
+	  paint.drawLine( center+1, 0, center+1, mFontHeight - 1 );
+	}
+	else
+	{
+	  paint.drawLine( center, 0, center, mFontHeight - 1 );
+	  paint.drawLine( center-2, 0, center+2, 0 );
+	  paint.drawLine( center-2, mFontHeight-1, center+2, mFontHeight-1 );
+	}
+      }
+      else
+      {
+	paint.fillRect( c.x2 - startx, 0, mUnitWidth, mFontHeight, cbg );
+	useFg = true;
+	fg = cfg;
+      }
+    }
+  }
+  else
+  {
+    transparent = true;
+    paint.setPen( cbg );
+    paint.drawRect( c.x2 - startx, 0, mUnitWidth, mFontHeight );
+  }
+
+  //
+  // Draw the text on the cursor position and to the end of the cell.
+  //
+  if( c.offset < documentSize() )
+  {
+    int flag = printAsciiCell( mPrintBuf, (unsigned char)c.data );
+    if( onBookmark == true )
+    {
+      // Inside bookmark. Draw text with bookmark foreground.
+      paint.setPen( flag == 0 ? mColor.bookmarkFg : mColor.nonPrintFg );
+      // ## paint.drawText( c.x2-startx, mFontAscent, mPrintBuf, 1 );
+      paint.drawText( c.x2-startx, mFontAscent, 
+		      TQString::fromLocal8Bit(mPrintBuf), 1 );
+    }
+    if( transparent == false || onBookmark == false )
+    {
+      paint.setPen( flag == 0 || useFg == true ? fg : mColor.nonPrintFg );
+      // ## paint.drawText( c.x2 - startx, mFontAscent, mPrintBuf, 1 );
+      paint.drawText( c.x2 - startx, mFontAscent, 
+		      TQString::fromLocal8Bit(mPrintBuf), 1 );
+    }
+  }
+
+}
+
+
+
+
+void CHexBuffer::cursorReset( void )
+{
+  mCursor.reset();
+  cursorCompute();
+}
+
+void CHexBuffer::cursorCompute( void )
+{
+  mCursor.prev = mCursor.curr;
+
+  if( mCursor.next.offset >= documentSize() )
+  {
+    if( documentSize() == 0 )
+    {
+      mCursor.curr.offset  = 0;
+      mCursor.curr.data    = 0;
+      mCursor.curr.cell    = 0;
+      mCursor.curr.maxCell = mNumCell;
+
+      int x = mCursor.curr.offset % mLayout.lineSize;
+      mCursor.curr.x1 = mTextStart1;
+      mCursor.curr.x1 += (x * mNumCell + mCursor.curr.cell) * mUnitWidth;
+      mCursor.curr.x1 += (x / mLayout.columnSize) * mSplitWidth;
+      mCursor.curr.x2 = mTextStart2 + x * mUnitWidth;
+      mCursor.curr.y  = (mCursor.curr.offset/mLayout.lineSize) *
+	(mFontHeight+mLayout.horzGridWidth);
+      return;
+
+    }
+    if( mFixedSizeMode == true )
+    {
+      uint max = mMaximumSize - 1;
+      uint off = mCursor.curr.offset % mLayout.lineSize;
+      uint end = max % mLayout.lineSize;
+      if( off > end )
+      {
+	uint diff = off - end;
+	if( max + diff > mLayout.lineSize )
+	{
+	  mCursor.next.offset = max + diff - mLayout.lineSize;
+	}
+	else
+	{
+	  mCursor.next.offset = 0;
+	}
+      }
+      else
+      {
+	uint diff = end - off;
+	mCursor.next.offset = diff > max ? max : max - diff;
+      }
+    }
+    else
+    {
+      mCursor.next.offset = documentSize();
+    }
+  }
+
+  mCursor.curr.offset  = mCursor.next.offset;
+  mCursor.curr.data    = data()[ mCursor.curr.offset ];
+  mCursor.curr.cell    = mCursor.next.cell;
+  mCursor.curr.maxCell = mNumCell;
+
+  int x = mCursor.curr.offset % mLayout.lineSize;
+
+  mCursor.curr.x1 = mTextStart1;
+  mCursor.curr.x1 += (x * mNumCell + mCursor.curr.cell) * mUnitWidth;
+  mCursor.curr.x1 += (x / mLayout.columnSize) * mSplitWidth;
+  mCursor.curr.x2 = mTextStart2 + x * mUnitWidth;
+  mCursor.curr.y  = (mCursor.curr.offset/mLayout.lineSize) *
+    (mFontHeight + mLayout.horzGridWidth);
+}
+
+
+bool CHexBuffer::setCursorPosition( int x, int y, bool init, bool cellLevel )
+{
+  if( documentPresent() == false )
+  {
+    return( false );
+  }
+
+  uint line  = y < 0 ? 0 : y / lineHeight();
+  uint entry = 0;
+  int  bit   = 7;
+
+  if( init == false )
+  {
+    if( mCursor.area() == edit_primary )
+    {
+      int start = mTextStart1;
+      if( x < start - (int)mLayout.separatorMarginWidth )
+      {
+	return( false );
+      }
+      else
+      {
+	int stop  = mTextStart1 + mPrimaryWidth + mLayout.separatorMarginWidth;
+	int width = mNumCell * mUnitWidth;
+	int space = mSplitWidth;
+
+	for( int position = start, i=0; position < stop; i++ )
+	{
+	  if( x <= position + width )
+	  {
+	    if( cellLevel == true )
+	    {
+	      while( bit > 0 )
+	      {
+		if( x <= position + mUnitWidth )
+		{
+		  break;
+		}
+		bit -= mCursor.cellWeight();
+		position += mUnitWidth;
+	      }
+	    }
+	    break;
+	  }
+	  position += width + (((i+1) % mLayout.columnSize) ? 0 : space);
+	  entry    += 1;
+	}
+      }
+    }
+    else
+    {
+      int start = mTextStart2;
+      if( x < start - (int)mLayout.separatorMarginWidth ||
+	  mLayout.secondaryMode == SDisplayLayout::hide )
+      {
+	return( false );
+      }
+      int stop  = mTextStart2 + mLayout.lineSize * mUnitWidth;
+      int width = mUnitWidth * 1;
+      int space = 0;
+
+      for( int position = start; position < stop; )
+      {
+	if( x <= position + width )
+	{
+	  break;
+	}
+	position += width + space;
+	entry    += 1;
+      }
+    }
+  }
+  else
+  {
+    int start = mTextStart1;
+    int stop  = start + mPrimaryWidth + mLayout.separatorMarginWidth;
+    if( x >= start - (int)mLayout.separatorMarginWidth && x <= stop )
+    {
+      int width = mUnitWidth * mNumCell;
+      int space = mSplitWidth;
+
+      for( int position = start, i=0; position < stop; i++ )
+      {
+	if( x <= position + width )
+	{
+	  if( cellLevel == true )
+	  {
+	    while( bit > 0 )
+	    {
+	      if( x <= position + mUnitWidth )
+	      {
+		break;
+	      }
+	      bit -= mCursor.cellWeight();
+	      position += mUnitWidth;
+	    }
+	  }
+	  break;
+	}
+	position += width + (((i+1) % mLayout.columnSize) ? 0 : space);
+	entry    += 1;
+      }
+
+      mActiveEditor = edit_primary;
+    }
+    else if( mLayout.secondaryMode != SDisplayLayout::hide )
+    {
+      start = mTextStart2;
+      stop  = mTextStart2 + mLayout.lineSize * mUnitWidth +
+	mLayout.edgeMarginWidth;
+      if( x >= start - (int)mLayout.separatorMarginWidth && x <= stop )
+      {
+	int width = mUnitWidth * 1;
+	int space = 0;
+
+	for( int position = start; position < stop; )
+	{
+	  if( x <= position + width )
+	  {
+	    break;
+	  }
+	  position += width + space;
+	  entry    += 1;
+	}
+
+	mActiveEditor = edit_secondary;
+      }
+    }
+    else
+    {
+      return( false );
+    }
+  }
+
+  uint offset = line * mLayout.lineSize + entry;
+  if( offset > documentSize() )
+  {
+    offset = documentSize();
+  }
+
+  mCursor.setOffset( offset );
+  mCursor.setBit( bit < 0 ? 0 : bit );
+
+  cursorCompute();
+  if( mActiveEditor != mCursor.area() )
+  {
+    mCursor.setArea( mActiveEditor );
+    setEditMode( mEditMode );
+  }
+
+  return( true );
+}
+
+
+
+
+bool CHexBuffer::inputAtCursor( TQChar c )
+{
+  if( documentPresent() == false || mInputMode.noInput() == true )
+  {
+    if( mInputMode.noInput() == true ) { inputSound(); }
+    return( false );
+  }
+
+  if( c.isPrint() == false )
+  {
+    inputSound();
+    return( false );
+  }
+
+  unsigned char dest;
+  bool insert;
+  if( mEditMode == EditReplace || mCursor.curr.cell > 0 )
+  {
+    if( mCursor.curr.offset >= documentSize() )
+    {
+      dest   = 0;
+      insert = true;
+    }
+    else
+    {
+      dest   = (unsigned char)data()[ mCursor.curr.offset ];
+      insert = false;
+    }
+  }
+  else
+  {
+    dest   = 0;
+    insert = true;
+  }
+
+  if( insert == true && mInputMode.allowResize == false )
+  {
+    inputSound();
+    return( false );
+  }
+
+  if( mActiveEditor == edit_primary )
+  {
+    // ## if( THIS_FPTR(inputCell)( &dest, c.latin1(), mCursor.curr.cell ) 
+    //== false )
+    if( THIS_FPTR(inputCell)( &dest, TQString(c).local8Bit()[0], 
+			      mCursor.curr.cell ) == false )
+    {
+      inputSound();
+      return( false );
+    }
+  }
+  else if( mActiveEditor == edit_secondary )
+  {
+    // ## if( inputAscii( &dest, c.latin1(), mCursor.curr.cell ) == false )
+    if( !inputAscii( &dest, TQString(c).local8Bit()[0], mCursor.curr.cell ) )
+    {
+      inputSound();
+      return( false );
+    }
+  }
+  else
+  {
+    return( false );
+  }
+
+  recordStart( mCursor );
+  recordReplace( mCursor, insert == true ? 0 : 1, (char*)&dest, 1 );
+  cursorRight( cursorPrimaryEdit() );
+  recordEnd( mCursor );
+
+  computeNumLines();
+  return( true );
+}
+
+
+
+int CHexBuffer::inputAtCursor( const TQByteArray &buf, uint oldSize )
+{
+  if( documentPresent() == false )
+  {
+    return( Err_NoActiveDocument );
+  }
+  if( buf.isNull() == true )
+  {
+    return( Err_EmptyArgument );
+  }
+
+  if( mInputMode.noInput() == true )
+  {
+    inputSound();
+    return( Err_WriteProtect );
+  }
+
+  if( mInputMode.allowResize == false )
+  {
+    inputSound();
+    return( Err_NoResize );
+  }
+
+  recordStart( mCursor );
+  recordReplace( mCursor, oldSize, (char*)&buf[0], buf.size() );
+  cursorStep( buf.size(), true, false );
+  recordEnd( mCursor );
+
+  computeNumLines();
+  return( Err_Success );
+}
+
+
+bool CHexBuffer::removeAtCursor( bool beforeCursor )
+{
+  if( documentPresent() == false )
+  {
+    return( false );
+  }
+
+  if( mInputMode.noInput() == true || mInputMode.allowResize == false )
+  {
+    inputSound();
+    return( false );
+  }
+
+
+  if( mSelect.valid() == true )
+  {
+    cutSelection();
+    return( true );
+  }
+
+
+  if( beforeCursor == true )
+  {
+    if( mCursor.curr.offset == 0 )
+    {
+      return( false );
+    }
+
+    recordStart( mCursor );
+    cursorLeft( false );
+    recordReplace( mCursor, 1, 0, 0 );
+    recordEnd( mCursor );
+
+    computeNumLines();
+    return( true );
+  }
+  else
+  {
+    if( mCursor.curr.offset + 1 > documentSize() )
+    {
+      return( false );
+    }
+
+    recordStart( mCursor );
+    recordReplace( mCursor, 1, 0, 0 );
+    recordEnd( mCursor );
+
+    computeNumLines();
+    return( true );
+  }
+}
+
+
+
+int CHexBuffer::locateRange(const SExportRange &range, uint &start, uint &stop)
+{
+  if( range.mode == SExportRange::All )
+  {
+    start = 0;
+    stop  = documentSize();
+  }
+  else if( range.mode == SExportRange::Selection )
+  {
+    if( mSelect.valid() == false )
+    {
+      return( Err_NoSelection );
+    }
+    start = mSelect.curr.start;
+    stop  = mSelect.curr.stop;
+  }
+  else if( range.mode == SExportRange::Range )
+  {
+    start = range.start;
+    stop  = range.stop;
+  }
+  else
+  {
+    return( Err_IllegalMode );
+  }
+
+  if( start >= stop )
+  {
+    return( Err_IllegalRange );
+  }
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::exportText( const SExportText &ex, CProgress &p )
+{
+  uint start, stop;
+  int errCode = locateRange( ex.range, start, stop );
+  if( errCode != Err_Success )
+  {
+    p.finish();
+    return( errCode );
+  }
+
+  TQFile file( ex.destFile );
+  if( file.open( IO_WriteOnly ) == false )
+  {
+    p.finish();
+    return( Err_OpenWriteFailed );
+  }
+
+  uint startLine = calculateLine( start );
+  if( startLine >= (uint)numLines() )
+  {
+    startLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+
+  uint stopLine  = calculateLine( stop );
+  if( stopLine >= (uint)numLines() )
+  {
+    stopLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+
+  uint totalSize   = stopLine - startLine + 1;
+  uint remaining   = stopLine - startLine + 1;
+  uint bytePerLine = mOffsetSize + 1 + (mNumCell + 2)*mLayout.lineSize + 1;
+  uint linePerStep = 20;
+
+  TQByteArray array( bytePerLine * linePerStep + 1 ); // Line is 0 terminated
+  if( array.isEmpty() == true )
+  {
+    p.finish();
+    return( Err_NoMemory );
+  }
+
+  while( remaining > 0 )
+  {
+    uint blockSize = remaining > linePerStep ? linePerStep : remaining;
+    uint printSize = 0;
+
+    for( uint i = 0; i < blockSize; i++, startLine++ )
+    {
+      printSize += printLine( &array[printSize], startLine );
+    }
+
+    int writeSize = file.writeBlock( &array[0], printSize );
+    if( writeSize == -1 )
+    {
+      p.finish();
+      return( Err_WriteFailed );
+    }
+
+    remaining -= blockSize;
+    if( p.expired() == true )
+    {
+      int errCode = p.step( (float)(totalSize-remaining)/(float)totalSize );
+      if( errCode == Err_Stop && remaining > 0 )
+      {
+	p.finish();
+	return( Err_OperationAborted );
+      }
+    }
+  }
+
+  p.finish();
+  return( Err_Success );
+}
+
+
+
+int CHexBuffer::exportHtml( const SExportHtml &ex, CProgress &p )
+{
+  uint start, stop;
+  int errCode = locateRange( ex.range, start, stop );
+  if( errCode != Err_Success )
+  {
+    p.finish();
+    return( errCode );
+  }
+
+  uint startLine = calculateLine( start );
+  if( startLine >= (uint)numLines() )
+  {
+    startLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+
+  uint stopLine  = calculateLine( stop );
+  if( stopLine >= (uint)numLines() )
+  {
+    stopLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+
+  uint totalSize = stopLine - startLine + 1;
+  uint remaining = stopLine - startLine + 1;
+
+  if( ex.linePerPage == 0 )
+  {
+    p.finish();
+    return( Err_IllegalArgument );
+  }
+
+  uint linePerPage = ex.linePerPage;
+  uint numFiles    = remaining/linePerPage + (remaining%linePerPage ? 1 : 0);
+  uint fileCount   = 0;
+
+  TQStringList fileNames, offsets;
+  TQString name, offset;
+  for( uint i=0; i < numFiles; i++ )
+  {
+    name.sprintf( "%08d.html", i+1 );
+    fileNames.append( TQString("%1/%2%3").arg(ex.package).arg(ex.prefix).
+		      arg(name));
+  }
+  name.sprintf( "%08d.html", 0 );
+  TQString tocName =TQString("%1/%2%3").arg(ex.package).arg(ex.prefix).arg(name);
+
+  TQString linkName;
+  if( ex.symLink == true )
+  {
+    linkName = TQString("%1/%2").arg(ex.package).arg("index.html");
+  }
+
+  while( remaining  > 0 )
+  {
+    THIS_FPTR(printOffset)( mPrintBuf, startLine*mLayout.lineSize );
+    mPrintBuf[mOffsetSize]=0;
+    offset.sprintf("[%s]", mPrintBuf );
+
+    uint pageSize = remaining > linePerPage ? linePerPage : remaining;
+    printHtmlDataPage( tocName, fileNames, fileCount, ex, startLine, pageSize);
+
+    remaining -= pageSize;
+    startLine += pageSize;
+    fileCount += 1;
+
+    THIS_FPTR(printOffset)( mPrintBuf, (startLine-1)*mLayout.lineSize );
+    mPrintBuf[mOffsetSize]=0;
+    offset += TQString(" %1 [%2]").arg(i18n("to")).arg(mPrintBuf);
+    offsets.append(offset);
+
+    if( p.expired() == true )
+    {
+      int errCode = p.step( (float)(totalSize-remaining)/(float)totalSize );
+      if( errCode == Err_Stop && remaining > 0 )
+      {
+	printHtmlTocPage( tocName, linkName, fileNames, offsets, fileCount );
+	p.finish();
+	return( Err_OperationAborted );
+      }
+    }
+  }
+
+  printHtmlTocPage( tocName, linkName, fileNames, offsets, fileCount );
+
+  p.finish();
+  return( Err_Success );
+}
+
+
+int CHexBuffer::exportCArray( const SExportCArray &ex, CProgress &p )
+{
+  uint start, stop;
+  int errCode = locateRange( ex.range, start, stop );
+  if( errCode != Err_Success )
+  {
+    p.finish();
+    return( errCode );
+  }
+
+  TQFile file( ex.destFile );
+  if( file.open( IO_WriteOnly ) == false )
+  {
+    p.finish();
+    return( Err_OpenWriteFailed );
+  }
+
+  uint startLine = calculateLine( start );
+  if( startLine >= (uint)numLines() )
+  {
+    startLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+
+  uint stopLine  = calculateLine( stop );
+  if( stopLine >= (uint)numLines() )
+  {
+    stopLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+
+  uint elementSize = ex.elementSize();
+  uint elementOnThisLine = 0;
+
+  TQTextStream dest( &file );
+
+  dest << ex.variableName(stop-start).latin1() << "={" << endl;
+  for( unsigned int i=start; i<stop; i+=elementSize )
+  {
+    dest << ex.printFormatted( (const char*)&data()[i], stop-i );
+    if( i + elementSize < stop )
+    {
+      dest << ",";
+    }
+
+    if( ++elementOnThisLine >= ex.elementPerLine )
+    {
+      dest << endl;
+      elementOnThisLine = 0;
+    }
+
+    if( p.expired() == true )
+    {
+      int errCode = p.step( (float)(i-start)/(float)(stop-start) );
+      if( errCode == Err_Stop && (i+elementSize) < stop)
+      {
+	p.finish();
+	return( Err_OperationAborted );
+      }
+    }
+  }
+  dest << "};" << endl;
+
+  p.finish();
+  return( Err_Success );
+}
+
+
+
+
+
+
+
+int CHexBuffer::copySelectedText( TQByteArray &array, int columnSegment )
+{
+  SExportRange range;
+  range.mode = SExportRange::Selection;
+  return( copyText( array, range, columnSegment ) );
+}
+
+
+int CHexBuffer::copyAllText( TQByteArray &array )
+{
+  SExportRange range;
+  range.mode = SExportRange::All;
+  return( copyText( array, range, VisibleColumn ) );
+}
+
+
+int CHexBuffer::copyText( TQByteArray &array, const SExportRange &range,
+			  int columnSegment )
+{
+  uint start, stop;
+  int errCode = locateRange( range, start, stop );
+  if( errCode != Err_Success )
+  {
+    return( errCode );
+  }
+
+  uint startLine = calculateLine( start );
+  uint stopLine  = calculateLine( stop );
+  if( startLine >= (uint)numLines() )
+  {
+    startLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+  if( stopLine >= (uint)numLines() )
+  {
+    stopLine = numLines() == 0 ? 0 : numLines() - 1;
+  }
+
+  uint bytePerLine = mOffsetSize + 1 + (mNumCell + 2)*mLayout.lineSize + 1;
+  uint size = (stopLine - startLine + 1)*bytePerLine;
+  if( array.resize( size+1 ) == false )
+  {
+    return( Err_NoMemory );
+  }
+
+  if( columnSegment == VisibleColumn )
+  {
+    columnSegment = PrimaryColumn; // Always visible
+    if( mLayout.offsetVisible == true )
+    {
+      columnSegment |= OffsetColumn;
+    }
+    if( mLayout.secondaryMode != SDisplayLayout::hide )
+    {
+      columnSegment |= SecondaryColumn;
+    }
+  }
+
+  uint offset = 0;
+  for( uint i = startLine; i <= stopLine; i++ )
+  {
+    offset += printLine( &array[offset], i, columnSegment );
+  }
+  array[size] = 0;
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::copySelectedData( TQByteArray &array )
+{
+  uint start = mSelect.start();
+  uint stop  = mSelect.stop();
+
+  if( mSelect.valid() == false || start >= stop )
+  {
+    return( Err_IllegalRange );
+  }
+
+  uint size = stop - start;
+  if( array.resize( size ) == false )
+  {
+    return( Err_NoMemory );
+  }
+
+  //unsigned char *src = (unsigned char*)data();
+  //char *dst = (char*)array.data();
+
+  memcpy( &array[0], &data()[start], size );
+  return( Err_Success );
+}
+
+
+uint CHexBuffer::numPage( CHexPrinter &printer )
+{
+  TQPainter paint( &printer );
+  paint.setFont( font() );
+
+  SPageMargin margin = printer.pageMargin();
+  SPageSize size = printer.pageUsableSize();
+  int headHeight, footHeight, headMargin, footMargin, freeHeight;
+
+  headHeight = footHeight = headMargin = footMargin = 0;
+  if( printer.pageHeader().enable == true )
+  {
+    headHeight = headerHeight( paint );
+    headMargin = headerMargin( paint );
+  }
+  if( printer.pageFooter().enable == true )
+  {
+    footHeight = headerHeight( paint );
+    footMargin = headerMargin( paint );
+  }
+  freeHeight = size.height - headHeight - footHeight - headMargin - footMargin;
+
+  float scale = 1.0;
+  if( (uint)mLineWidth > size.width )
+  {
+    scale = (float)size.width / (float)mLineWidth;
+  }
+  uint linePerPage = (uint) ((float)freeHeight/((float)lineHeight()*scale));
+
+  uint remaining = numLines();
+
+  return( remaining / linePerPage + (remaining % linePerPage ? 1 : 0) );
+}
+
+
+
+int CHexBuffer::print( CHexPrinter &printer, CProgress &p )
+{
+  printer.setDocName( mUrl );
+
+  TQPainter paint( &printer );
+  paint.setFont( font() );
+
+  SPageMargin margin = printer.pageMargin();
+  SPageSize size = printer.pageUsableSize();
+  paint.setClipRect( margin.left, margin.top, size.width, size.height );
+
+  //printf("%d,%d,%d,%d\n", margin.left, margin.top, size.width, size.height );
+
+  int headHeight, footHeight, headMargin, footMargin, freeHeight;
+
+  headHeight = footHeight = headMargin = footMargin = 0;
+  if( printer.pageHeader().enable == true )
+  {
+    headHeight = headerHeight( paint );
+    headMargin = headerMargin( paint );
+  }
+  if( printer.pageFooter().enable == true )
+  {
+    footHeight = headerHeight( paint );
+    footMargin = headerMargin( paint );
+  }
+  freeHeight = size.height - headHeight - footHeight - headMargin - footMargin;
+
+  float scale = 1.0;
+  if( (uint)mLineWidth > size.width )
+  {
+    scale = (float)size.width / (float)mLineWidth;
+    paint.scale( scale, scale );
+  }
+
+  uint linePerPage = (uint) ((float)freeHeight/((float)lineHeight()*scale));
+  uint sx = (uint) ((float)margin.left/scale);
+  uint sy = (uint) ((float)(margin.top+headHeight+headMargin)/scale);
+
+  uint remaining = numLines();
+  uint line = 0;
+
+  #ifdef PRINTER_TEST
+  remaining = remaining > linePerPage * 10 ? linePerPage * 10 : remaining;
+  #endif
+
+
+  SPagePosition pageData( time(0), remaining, linePerPage );
+  while( remaining > 0 )
+  {
+    uint lineInPage = remaining > linePerPage ? linePerPage : remaining;
+    uint y = sy;
+
+    //
+    // Draw header and footer. Reset scaling during that operation.
+    //
+    paint.scale( 1.0/scale, 1.0/scale );
+    if( printer.pageHeader().enable == true )
+    {
+      drawHeader( paint, margin.left, size.width, margin.top, false,
+		  printer.pageHeader(), pageData );
+    }
+    if( printer.pageFooter().enable == true )
+    {
+      drawHeader( paint, margin.left, size.width,
+		  margin.top+size.height-footHeight, true,
+		  printer.pageFooter(), pageData );
+    }
+    paint.scale( scale, scale );
+
+    //
+    // Draw actual data
+    //
+    for( uint i=0; i < lineInPage; i++, line++ )
+    {
+      drawText( paint, line, sx, mLineWidth, y, false/*printer.printBlackWhite()*/ );
+      y += lineHeight();// - mLayout.horzGridWidth; // FIXME not really nice :)
+
+      if( p.expired() == true )
+      {
+	int errCode = p.step( pageData.current(), pageData.max() );
+	if( errCode == Err_Stop )
+	{
+	  p.finish();
+	  return( Err_Success ); // Success here, even if we cancel
+	}
+      }
+    }
+
+    if( p.expired() == true )
+    {
+      int errCode = p.step( pageData.current(), pageData.max() );
+      if( errCode == Err_Stop )
+      {
+	p.finish();
+	return( Err_Success );// Success here, even if we cancel
+      }
+    }
+
+    remaining -= lineInPage;
+    if( remaining > 0 )
+    {
+      printer.newPage();
+    }
+
+    pageData.step();
+  }
+
+  p.finish();
+  return( Err_Success );
+}
+
+
+
+
+
+uint CHexBuffer::printLine( char *dst, uint line )
+{
+  uint offset = line * mLayout.lineSize;
+  unsigned char *src;
+  char *start = dst;
+
+  uint dataSize;
+  if( offset >= documentSize() )
+  {
+    src = 0;
+    dataSize = 0;
+  }
+  else
+  {
+    src = (unsigned char*)&data()[ offset ];
+    dataSize = documentSize() - offset;
+  }
+
+  if( mLayout.offsetVisible == true )
+  {
+    THIS_FPTR(printOffset)( dst, offset ); dst += mOffsetSize;
+    sprintf( dst, " " ); dst += 1;
+  }
+  for( uint i=0; i < mLayout.lineSize; i++ )
+  {
+    if( i<dataSize )
+    {
+      THIS_FPTR(printCell)( dst, src[i] ); dst += mNumCell;
+    }
+    else
+    {
+      memset( dst, ' ', mNumCell ); dst += mNumCell;
+    }
+    if( mSplitWidth != 0 )
+    {
+      sprintf( dst, " " ); dst += 1;
+    }
+  }
+  if( mLayout.secondaryMode != SDisplayLayout::hide )
+  {
+    for( uint i=0; i < mLayout.lineSize; i++ )
+    {
+      if( i < dataSize )
+      {
+	printAsciiCell( dst, src[i] ); dst += 1;
+      }
+      else
+      {
+	memset( dst, ' ', 1 ); dst += 1;
+      }
+    }
+  }
+  sprintf( dst, "\n" ); dst += 1;
+  return( (uint)(dst-start) );
+}
+
+
+uint CHexBuffer::printLine( char *dst, uint line, int columnSegment )
+{
+  uint offset = line * mLayout.lineSize;
+  unsigned char *src;
+  char *start = dst;
+
+  uint dataSize;
+  if( offset >= documentSize() )
+  {
+    src = 0;
+    dataSize = 0;
+  }
+  else
+  {
+    src = (unsigned char*)&data()[ offset ];
+    dataSize = documentSize() - offset;
+  }
+
+  if( columnSegment & OffsetColumn )
+  {
+    THIS_FPTR(printOffset)( dst, offset ); dst += mOffsetSize;
+    sprintf( dst, " " ); dst += 1;
+  }
+
+  if( columnSegment & PrimaryColumn )
+  {
+    for( uint i=0; i < mLayout.lineSize; i++ )
+    {
+      if( i<dataSize )
+      {
+	THIS_FPTR(printCell)( dst, src[i] ); dst += mNumCell;
+      }
+      else
+      {
+	memset( dst, ' ', mNumCell ); dst += mNumCell;
+      }
+      if( mSplitWidth != 0 )
+      {
+	sprintf( dst, " " ); dst += 1;
+      }
+    }
+  }
+
+  if( columnSegment & SecondaryColumn )
+  {
+    for( uint i=0; i < mLayout.lineSize; i++ )
+    {
+      if( i < dataSize )
+      {
+	printAsciiCell( dst, src[i] ); dst += 1;
+      }
+      else
+      {
+	memset( dst, ' ', 1 ); dst += 1;
+      }
+    }
+  }
+
+  sprintf( dst, "\n" ); dst += 1;
+  return( (uint)(dst-start) );
+}
+
+
+
+
+
+
+
+
+
+
+
+bool CHexBuffer::cutSelection( void )
+{
+  if( documentPresent() == false || mSelect.size() == 0 )
+  {
+    return( false );
+  }
+
+  if( mInputMode.noInput() == true || mInputMode.allowResize == false )
+  {
+    inputSound();
+    return( false );
+  }
+
+  recordStart( mCursor );
+  cursorGoto( mSelect.start(), 0 );
+  recordReplace( mCursor, mSelect.size(), 0, 0 );
+  recordEnd( mCursor );
+
+  mSelect.reset();
+
+  computeNumLines();
+  return( true );
+}
+
+
+
+bool CHexBuffer::undo( void )
+{
+  if( documentPresent() == false || mUndoIndex == 0 ||
+      mInputMode.noInput() == true )
+  {
+    if( mInputMode.noInput() == true ) { inputSound(); }
+    return( false );
+  }
+
+  CHexActionGroup *group = mUndoList.at( mUndoIndex-1 );
+  if( group == 0 )
+  {
+    return( false );
+  }
+
+  mUndoIndex -= 1;
+  doActionGroup( group );
+
+  cursorGoto( group->mStartOffset, group->mStartBit );
+
+  return( true );
+}
+
+
+bool CHexBuffer::redo( void )
+{
+  if( documentPresent() == false || mUndoIndex >= mUndoList.count() ||
+      mInputMode.noInput() == true )
+  {
+    if( mInputMode.noInput() == true ) { inputSound(); }
+    return( false );
+  }
+
+  CHexActionGroup *group = mUndoList.at( mUndoIndex );
+  if( group == 0 )
+  {
+    return( false );
+  }
+
+  mUndoIndex += 1;
+  doActionGroup( group );
+
+  cursorGoto( group->mStopOffset, group->mStopBit );
+
+  return( true );
+}
+
+
+int CHexBuffer::addBookmark( int position )
+{
+  if( documentPresent() == false )
+  {
+    return( Err_NoData );
+  }
+
+  if( mBookmarkList.count() >= 9 && position == -1 )
+  {
+    return( Err_ListFull );
+  }
+
+  SCursorOffset *co = new SCursorOffset;
+  if( co == 0 )
+  {
+    fatalSound();
+    return( Err_NoMemory );
+  }
+
+  co->offset = mCursor.curr.offset;
+  co->bit    = mCursor.bit();
+
+  if( position == -1 || position > (int)mBookmarkList.count() )
+  {
+    mBookmarkList.append( co );
+  }
+  else
+  {
+    mBookmarkList.remove( (uint)position );
+    mBookmarkList.insert( (uint)position, co );
+  }
+
+  updateBookmarkMap(false);
+  return( Err_Success );
+}
+
+
+bool CHexBuffer::removeBookmark( int position )
+{
+  if( position < 0 )
+  {
+    if( mBookmarkList.count() == 0 )
+    {
+      return( false );
+    }
+    mBookmarkList.clear();
+  }
+  else
+  {
+    if( (uint)position >= mBookmarkList.count() )
+    {
+      return( false );
+    }
+    mBookmarkList.remove( position );
+  }
+
+  updateBookmarkMap(false);
+  return( true );
+}
+
+
+void CHexBuffer::updateBookmarkMap( bool resize )
+{
+  if( resize == true )
+  {
+    mBookmarkMap.resize( documentSize()/200 + 3 );
+  }
+  mBookmarkMap.fill(0);
+
+  int bookmarkMapSize = mBookmarkMap.size();
+  for( SCursorOffset *c=mBookmarkList.first(); c!=0; c=mBookmarkList.next() )
+  {
+    int bookmarkOffset = c->offset / 200;
+    if( bookmarkOffset < bookmarkMapSize )
+    {
+      //
+      // Espen 2000-05-16:
+      // I do this test to avoid some TQt warnings when I have closed
+      // or reduced the size of the documnet while the (now invalid)
+      // bookmarks still exist.
+      //
+      mBookmarkMap.setBit(bookmarkOffset);
+    }
+  }
+}
+
+
+int CHexBuffer::findFirst( SSearchControl &sc )
+{
+  mMark.reset();
+  int errCode = scanData( sc, true );
+  return( errCode );
+}
+
+int CHexBuffer::findNext( SSearchControl &sc )
+{
+  sc.fromCursor = true;
+  int errCode = scanData( sc, false );
+  return( errCode );
+}
+
+int CHexBuffer::findWrap( SSearchControl &sc )
+{
+  if( sc.wrapValid == false )
+  {
+    return( Err_NoMatch );
+  }
+  sc.wrapValid = false;
+
+  sc.fromCursor = false;
+  sc.wrapActive = true;
+  int errCode = scanData( sc, false );
+  sc.fromCursor = true;
+  return( errCode );
+}
+
+
+
+
+int CHexBuffer::replaceAll( SSearchControl &sc, bool init )
+{
+  if( init == true )
+  {
+    initScanData( sc );
+  }
+
+  if( sc.key.isEmpty() == true )
+  {
+    return( Err_EmptyArgument );
+  }
+
+  if( documentSize() == 0 )
+  {
+    return( Err_EmptyDocument );
+  }
+
+  uint head, tail;
+  if( sc.inSelection == true )
+  {
+    if( mSelect.valid() == false )
+    {
+      return( Err_NoSelection );
+    }
+
+    head = mSelect.start();
+    tail = mSelect.stop();
+  }
+  else
+  {
+    head = 0;
+    tail = documentSize();
+  }
+
+  uint start, stop;
+  if( sc.fromCursor == false )
+  {
+    if( sc.wrapActive == true )
+    {
+      start = sc.forward == true ? head : sc.wrapMark;
+      stop  = sc.forward == true ? sc.wrapMark+sc.key.size() : tail;
+    }
+    else
+    {
+      start = head;
+      stop  = tail;
+    }
+  }
+  else if( sc.forward == true )
+  {
+    start = cursorOffset() < head ? head : cursorOffset();
+    stop  = sc.wrapActive == true ? sc.wrapMark+sc.key.size() : tail;
+  }
+  else
+  {
+    start = sc.wrapActive == true ? sc.wrapMark : head;
+    stop  = cursorOffset() > tail ? tail : cursorOffset();
+  }
+
+  if( sc.forward == true && start + sc.key.size() > stop )
+  {
+    //
+    // When searching backwards "stop" is the last offset from where
+    // we do a memcmp() upward in memory. An overflow for that
+    // situation is taken care of below.
+    //
+    return( Err_NoMatch );
+  }
+
+  if( stop + sc.key.size() > tail )
+  {
+    uint diff = stop + sc.key.size() - tail;
+    stop = stop > diff ? stop - diff : 0;
+  }
+
+  if( mInputMode.noInput() == true )
+  {
+    inputSound();
+    return( Err_WriteProtect );
+  }
+
+  recordStart( mCursor );
+  uint numReplaced = 0;
+
+  if( sc.forward == true )
+  {
+    for( uint i = start; i <= stop ; )
+    {
+      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) != 0 )
+      {
+	i++;
+      }
+      else
+      {
+	cursorGoto( i, 7 );
+	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
+	numReplaced += 1;
+
+	if( sc.inSelection == true )
+	{
+	  if( sc.key.size() > sc.val.size() )
+	  {
+	    mSelect.shrink( sc.key.size() - sc.val.size() );
+	  }
+	  else
+	  {
+	    mSelect.expand( sc.val.size() - sc.key.size() );
+	  }
+	}
+	
+	if( sc.key.size() > sc.val.size() )
+	{
+	  uint diff = sc.key.size() - sc.val.size();
+	  stop -= TQMIN( stop, diff );
+	}
+	else if( sc.key.size() < sc.val.size() )
+	{
+	  stop += sc.val.size() - sc.key.size();
+	}
+
+	i += sc.val.size();
+	cursorStep( sc.val.size(), true, false );
+      }
+    }
+  }
+  else
+  {
+    for( uint i = stop; i >= start; )
+    {
+      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) != 0 )
+      {
+	if( i == 0 ) { break; }
+	i--;
+      }
+      else
+      {
+	cursorGoto( i, 7 );
+	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
+	numReplaced += 1;
+
+	if( sc.inSelection == true )
+	{
+	  if( sc.key.size() > sc.val.size() )
+	  {
+	    mSelect.shrink( sc.key.size() - sc.val.size() );
+	  }
+	  else
+	  {
+	    mSelect.expand( sc.val.size() - sc.key.size() );
+	  }
+	}
+
+	i -= TQMIN( i, sc.key.size() );
+	if( i == 0 ) { break; }
+      }
+    }
+  }
+
+  recordEnd( mCursor );
+  computeNumLines();
+
+  if( numReplaced == 0 )
+  {
+    return( Err_NoMatch );
+  }
+
+  sc.numReplace += numReplaced;
+  sc.match = true;
+  mMark.reset();
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::replaceMarked( SSearchControl &sc )
+{
+  if( documentSize() == 0 )
+  {
+    return( Err_EmptyDocument );
+  }
+
+  if( mMark.valid() == false )
+  {
+    return( Err_NoMark );
+  }
+
+  bool inSelection;
+  if( mSelect.valid() == true )
+  {
+    if( mMark.start() >= mSelect.start() && mMark.stop() <= mSelect.stop() )
+    {
+      inSelection = true;
+    }
+    else
+    {
+      inSelection = false;
+    }
+  }
+  else
+  {
+    inSelection = false;
+  }
+
+  if( mInputMode.noInput() == true )
+  {
+    inputSound();
+    return( Err_WriteProtect );
+  }
+
+  recordStart( mCursor );
+  cursorGoto( mMark.start(), 7 );
+  recordReplace( mCursor, mMark.size(), sc.val.data(), sc.val.size() );
+  sc.numReplace += 1;
+
+  if( inSelection == true )
+  {
+    if( mMark.size() > sc.val.size() )
+    {
+      mSelect.shrink( mMark.size() - sc.val.size() );
+    }
+    else
+    {
+      sc.wrapMark += sc.val.size() - mMark.size();
+      mSelect.expand( sc.val.size() - mMark.size() );
+    }
+  }
+
+
+  if( sc.wrapActive == false )
+  {
+    if( sc.forward == false )
+    {
+      sc.wrapMark += mMark.size() > sc.val.size() ?
+	mMark.size() - sc.val.size() : sc.val.size() - mMark.size();
+    }
+  }
+
+
+  recordEnd( mCursor );
+  computeNumLines();
+
+  if( sc.forward == true )
+  {
+    //
+    // We must step over the area we have just altered. This is
+    // vital if the search key contains a pattern that exists in
+    // the replace data buffer.
+    //
+    cursorStep( sc.val.size(), true, false );
+  }
+  mMark.reset();
+  return( Err_Success );
+}
+
+
+#if 0
+
+int CHexBuffer::replaceAll( SSearchControl &sc, bool init )
+{
+  if( init == true )
+  {
+    initScanData( sc );
+  }
+
+  if( sc.key.isEmpty() == true )
+  {
+    return( Err_EmptyArgument );
+  }
+
+  if( documentSize() == 0 )
+  {
+    return( Err_EmptyDocument );
+  }
+
+  uint head, tail;
+  if( sc.inSelection == true )
+  {
+    if( mSelect.valid() == false )
+    {
+      return( Err_NoSelection );
+    }
+
+    head = mSelect.start();
+    tail = mSelect.stop();
+  }
+  else
+  {
+    head = 0;
+    tail = documentSize();
+  }
+
+  uint start, stop;
+  if( sc.fromCursor == false )
+  {
+    if( sc.wrapActive == true )
+    {
+      start = sc.forward == true ? head : sc.wrapMark;
+      stop  = sc.forward == true ? sc.wrapMark : tail;
+    }
+    else
+    {
+      start = head;
+      stop  = tail;
+    }
+  }
+  else if( sc.forward == true )
+  {
+    start = cursorOffset() < head ? head : cursorOffset();
+    stop  = sc.wrapActive == true ? sc.wrapMark : tail;
+  }
+  else
+  {
+    start = sc.wrapActive == true ? sc.wrapMark : head;
+    stop  = cursorOffset() > tail ? tail : cursorOffset();
+  }
+
+
+  if( start + sc.key.size() > stop )
+  {
+    return( Err_NoMatch );
+  }
+
+  if( stop + sc.key.size() > tail )
+  {
+    uint diff = stop + sc.key.size() - tail;
+    stop = stop > diff ? stop - diff : 0;
+  }
+
+  if( mInputMode.noInput() == true )
+  {
+    inputSound();
+    return( Err_WriteProtect );
+  }
+
+  recordStart( mCursor );
+  uint numReplaced = 0;
+
+  if( sc.forward == true )
+  {
+    for( uint i = start; i <= stop; i++ )
+    {
+      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) == 0 )
+      {
+	cursorGoto( i, 7 );
+	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
+	numReplaced += 1;
+
+	if( sc.inSelection == true )
+	{
+	  if( sc.key.size() > sc.val.size() )
+	  {
+	    mSelect.shrink( sc.key.size() - sc.val.size() );
+	  }
+	  else
+	  {
+	    mSelect.expand( sc.val.size() - sc.key.size() );
+	  }
+	}
+
+	if( sc.key.size() > sc.key.size() )
+	{
+	  uint diff = sc.key.size() - sc.val.size();
+	  i += diff - 1;
+	}
+	else if( sc.key.size() < sc.val.size() )
+	{
+	  uint diff = sc.val.size() - sc.key.size();
+	  stop += diff;
+	}
+	else
+	{
+	  i += sc.val.size() - 1;
+	}
+	cursorStep( sc.val.size(), true, false );
+      }
+    }
+  }
+  else
+  {
+    for( uint i = stop; i >= start; i-- )
+    {
+      if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) == 0 )
+      {
+	cursorGoto( i, 7 );
+	recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
+	numReplaced += 1;
+
+	if( sc.inSelection == true )
+	{
+	  if( sc.key.size() > sc.val.size() )
+	  {
+	    mSelect.shrink( sc.key.size() - sc.val.size() );
+	  }
+	  else
+	  {
+	    mSelect.expand( sc.val.size() - sc.key.size() );
+	  }
+	}
+
+      }
+      if( i == 0 ) { break; }
+    }
+  }
+
+  recordEnd( mCursor );
+  computeNumLines();
+
+  if( numReplaced == 0 )
+  {
+    return( Err_NoMatch );
+  }
+
+  sc.numReplace += numReplaced;
+  sc.match = true;
+  mMark.reset();
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::replaceMarked( SSearchControl &sc )
+{
+  if( documentSize() == 0 )
+  {
+    return( Err_EmptyDocument );
+  }
+
+  if( mMark.valid() == false )
+  {
+    return( Err_NoMark );
+  }
+
+  bool inSelection;
+  if( mSelect.valid() == false )
+  {
+    if( mMark.start() >= mSelect.start() && mMark.stop() <= mSelect.stop() )
+    {
+      inSelection = true;
+    }
+    else
+    {
+      inSelection = false;
+    }
+  }
+  else
+  {
+    inSelection = false;
+  }
+
+  if( mInputMode.noInput() == true )
+  {
+    inputSound();
+    return( Err_WriteProtect );
+  }
+
+  recordStart( mCursor );
+  cursorGoto( mMark.start(), 7 );
+  recordReplace( mCursor, mMark.size(), sc.val.data(), sc.val.size() );
+  sc.numReplace += 1;
+
+  if( inSelection == true )
+  {
+    if( mMark.size() > sc.val.size() )
+    {
+      mSelect.shrink( mMark.size() - sc.val.size() );
+    }
+    else
+    {
+      mSelect.expand( sc.val.size() - mMark.size() );
+    }
+  }
+
+  recordEnd( mCursor );
+  computeNumLines();
+  mMark.reset();
+
+  return( Err_Success );
+}
+
+#endif
+
+
+int CHexBuffer::initScanData( SSearchControl &sc )
+{
+  sc.wrapValid  = false;
+  sc.wrapActive = false;
+  sc.wrapMark   = 0;
+  sc.match      = false;
+  sc.numReplace = 0;
+
+  uint head, tail;
+  if( sc.inSelection == true )
+  {
+    if( mSelect.valid() == false )
+    {
+      return( Err_NoSelection );
+    }
+
+    head = mSelect.start();
+    tail = mSelect.stop();
+  }
+  else
+  {
+    head = 0;
+    tail = documentSize();
+  }
+
+  if( sc.fromCursor == false )
+  {
+    sc.wrapValid  = false;
+    sc.wrapActive = false;
+    sc.wrapMark   = 0;
+  }
+  else if( sc.forward == true )
+  {
+    if( cursorOffset() > tail )
+    {	
+      sc.wrapValid  = true;
+      sc.wrapActive = false;
+      sc.wrapMark   = tail;
+    }
+    else if( cursorOffset() <= head )
+    {
+      sc.wrapValid  = false;
+      sc.wrapActive = false;
+      sc.wrapMark   = 0;
+    }
+    else
+    {
+      sc.wrapValid  = true;
+      sc.wrapActive = false;
+      sc.wrapMark   = cursorOffset();
+    }
+  }
+  else
+  {
+    if( cursorOffset() >= tail )
+    {
+      sc.wrapValid  = false;
+      sc.wrapActive = false;
+      sc.wrapMark   = 0;
+    }
+    else if( cursorOffset() < head )
+    {
+      sc.wrapValid  = true;
+      sc.wrapActive = false;
+      sc.wrapMark   = head;
+    }
+    else
+    {
+      sc.wrapValid  = true;
+      sc.wrapActive = false;
+      sc.wrapMark   = cursorOffset();
+    }
+  }
+
+  return( Err_Success );
+}
+
+
+
+int CHexBuffer::scanData( SSearchControl &sc, bool init )
+{
+  if( init == true )
+  {
+    int errCode = initScanData( sc );
+    if( errCode != Err_Success )
+    {
+      return( errCode );
+    }
+  }
+
+  if( sc.key.isEmpty() == true )
+  {
+    return( Err_EmptyArgument );
+  }
+
+  if( documentSize() == 0 )
+  {
+    return( Err_EmptyDocument );
+  }
+
+  uint head, tail;
+  if( sc.inSelection == true )
+  {
+    if( mSelect.valid() == false )
+    {
+      return( Err_NoSelection );
+    }
+
+    head = mSelect.start();
+    tail = mSelect.stop();
+  }
+  else
+  {
+    head = 0;
+    tail = documentSize();
+  }
+
+  uint start, stop;
+  if( sc.fromCursor == false )
+  {
+    if( sc.wrapActive == true )
+    {
+      start = sc.forward == true ? head : sc.wrapMark;
+      stop  = sc.forward == true ? sc.wrapMark+sc.key.size() : tail;
+    }
+    else
+    {
+      start = head;
+      stop  = tail;
+    }
+  }
+  else if( sc.forward == true )
+  {
+    start = cursorOffset() < head ? head : cursorOffset();
+    stop  = sc.wrapActive == true ? sc.wrapMark : tail;
+  }
+  else
+  {
+    start = sc.wrapActive == true ? sc.wrapMark : head;
+    stop  = cursorOffset() > tail ? tail : cursorOffset();
+  }
+
+  if( sc.forward == true && start + sc.key.size() > stop )
+  {
+    //
+    // When searching backwards "stop" is the last offset from where
+    // we do a memcmp() upward in memory. An overflow for that
+    // situation is taken care of below.
+    //
+    return( stop + sc.key.size() < tail ? Err_WrapBuffer : Err_NoData );
+  }
+
+  if( stop + sc.key.size() > tail )
+  {
+    uint diff = stop + sc.key.size() - tail;
+    stop = stop > diff ? stop - diff : 0;
+  }
+
+  if( sc.forward == true )
+  {
+    for( uint i = start; i <= stop; i++ )
+    {
+      int result;
+      if( sc.ignoreCase == true )
+      {
+	result = strncasecmp( &data()[i], sc.key.data(), sc.key.size() );
+      }
+      else
+      {
+	result = memcmp( &data()[i], sc.key.data(), sc.key.size() );
+      }
+      if( result == 0 )
+      {
+	if( i != cursorOffset() || mMark.size() != sc.key.size() )
+	{
+	  sc.match = true;
+	  cursorGoto( i, 7 );
+	  markSet( i, (uint)sc.key.size() );
+	  return( Err_Success );
+	}
+      }
+    }
+    return( start > head ? Err_WrapBuffer : Err_NoData );
+  }
+  else
+  {
+    for( uint i = stop; i >= start; i-- )
+    {
+      int result;
+      if( sc.ignoreCase == true )
+      {
+	result = strncasecmp( &data()[i], sc.key.data(), sc.key.size() );
+      }
+      else
+      {
+	result = memcmp( &data()[i], sc.key.data(), sc.key.size() );
+      }
+      if( result == 0 )
+      {	
+	if( i != cursorOffset() || mMark.size() != sc.key.size() )
+	{
+	  sc.match = true;
+	  cursorGoto( i, 7 );
+	  markSet( i, (uint)sc.key.size() );
+	  return( Err_Success );
+	}
+      }
+      if( i == 0 ) { break; }
+    }
+
+    return( stop + sc.key.size() <= tail ? Err_WrapBuffer : Err_NoData );
+  }
+}
+
+
+
+
+
+int CHexBuffer::filter( SFilterControl &fc )
+{
+  uint head, tail;
+  if( fc.inSelection == true )
+  {
+    if( mSelect.valid() == false )
+    {
+      return( Err_NoSelection );
+    }
+
+    head = mSelect.start();
+    tail = mSelect.stop();
+  }
+  else
+  {
+    head = 0;
+    tail = documentSize();
+  }
+
+  uint start, stop;
+  if( fc.fromCursor == false )
+  {
+    start = head;
+    stop  = tail;
+  }
+  else if( fc.forward == true )
+  {
+    start = cursorOffset() < head ? head : cursorOffset();
+    stop  = tail;
+  }
+  else
+  {
+    start = head;
+    stop  = cursorOffset() > tail ? tail : cursorOffset();
+  }
+
+  if( mInputMode.noInput() == true )
+  {
+    inputSound();
+    return( Err_WriteProtect );
+  }
+
+  if( start >= stop ) { return( Err_IllegalRange ); }
+  TQByteArray buf( stop - start );
+  if( buf.isEmpty() == true ) { return( Err_NoMemory ); }
+
+  int errCode = fc.execute((uchar*)&buf[0],(uchar*)&data()[start],buf.size());
+  if( errCode == Err_Success )
+  {
+    recordStart( mCursor );
+    cursorGoto( start, 7 );
+    recordReplace( mCursor, buf.size(), buf.data(), buf.size() );
+    recordEnd( mCursor );
+  }
+
+  return( errCode );
+}
+
+
+
+int CHexBuffer::collectStrings( CStringCollectControl &sc )
+{
+  uint startOffset = 0;
+  uint start, i;
+  bool on = false;
+
+  if( sc.minLength < 1 ) { sc.minLength = 1; }
+
+  start = startOffset;
+  for( i = startOffset; i<documentSize(); i++ )
+  {
+    unsigned char item = data()[i];
+    if( isprint( item ) == 0 || item >= 128 )
+    {
+      if( on == true && i-start >= sc.minLength )
+      {
+	TQByteArray a( i-start );
+	for( uint j=0; j<(i-start); a[j]=data()[start+j], j++ );
+	sc.add( start, a );
+      }
+      on = false;
+    }
+    else
+    {
+      if( on == false ) { start = i; }
+      on = true;
+    }
+  }
+
+  if( on == true && i-start >= sc.minLength )
+  {
+    TQByteArray a( i-start );
+    for( uint j=0; j<(i-start); a[j]=data()[start+j], j++ );
+    sc.add( start, a );
+  }
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::collectStatistic( SStatisticControl &sc, CProgress &p )
+{
+  sc.documentSize = documentSize();
+  sc.documentName = mUrl;
+
+  for( uint i = 0; i<documentSize(); i++ )
+  {
+    sc.occurrence[ (unsigned char)data()[i] ] += 1;
+
+    //
+    // The expired() function introduces too much overhead in this case
+    // so it is only executed every 100'th character
+    //
+    if( i % 100 == 0 && p.expired() == true )
+    {
+      int errCode = p.step( (float)i/(float)documentSize() );
+      if( errCode == Err_Stop && i+1 < documentSize() )
+      {
+	p.finish();
+	return( Err_OperationAborted );
+      }
+    }
+  }
+  p.finish();
+  return( Err_NoErr );
+}
+
+
+void CHexBuffer::doActionGroup( CHexActionGroup *group )
+{
+  if( group == 0 )
+  {
+    return;
+  }
+
+  CHexAction *action = group->mHexAction;
+  group->mHexAction = 0;
+
+  while( action != 0 )
+  {
+    doAction( action );
+    CHexAction *next = action->mNext;
+    group->insertAction( action );
+    action = next;
+  }
+
+  computeNumLines();
+}
+
+
+void CHexBuffer::doAction( CHexAction *action )
+{
+  if( action->mAction == CHexAction::replace )
+  {
+    doReplace( action, true );
+  }
+}
+
+
+
+
+
+void CHexBuffer::recordStart( SCursor &cursor )
+{
+  //
+  // Step 1: Remove any undo element that is more recent than the
+  // current undo index
+  //
+  while( mUndoList.count() > mUndoIndex )
+  {
+    mUndoList.removeLast();
+  }
+
+  //
+  // Step 2: Make sure the undo list is no larger than the undo limit.
+  // We remove the oldest elements in the list.
+  //
+  while( mUndoList.count() >= mUndoLimit )
+  {
+    mUndoList.removeFirst();
+    mUndoIndex -= 1;
+  }
+
+  CHexActionGroup *group = new CHexActionGroup( cursor.curr.offset,
+						cursor.bit() );
+  if( group == 0 )
+  {
+    return;
+  }
+
+  mUndoList.append( group );
+  mUndoIndex += 1;
+}
+
+
+void CHexBuffer::recordReplace( SCursor &cursor, uint size, char *data1,
+				uint data1Size )
+{
+  CHexAction *hexAction = new CHexAction( CHexAction::replace,
+					  cursor.curr.offset );
+  if( hexAction == 0 )
+  {
+    return;
+  }
+
+  hexAction->mSize = size;
+  hexAction->mData = data1;
+  hexAction->mDataSize = data1Size;
+
+  doReplace( hexAction, false );
+  mUndoList.getLast()->insertAction( hexAction );
+
+  if( mCursor.curr.offset < documentSize() )
+  {
+    mCursor.curr.data = data()[ mCursor.curr.offset ];
+  }
+
+}
+
+void CHexBuffer::recordEnd( SCursor &cursor )
+{
+  mUndoList.getLast()->mStopOffset = cursor.curr.offset;
+  mUndoList.getLast()->mStopBit = cursor.bit();
+}
+
+
+//
+// This method is the only place where the doucument data can be changed.
+//
+void CHexBuffer::doReplace( CHexAction *hexAction, bool removeData )
+{
+  uint offset   = hexAction->mOffset;
+  uint oldSize  = hexAction->mSize;
+  char *newData = hexAction->mData;
+  uint newSize  = hexAction->mDataSize;
+
+  hexAction->setData( newSize, &data()[offset], oldSize );
+
+  //
+  // Input new data. Resize buffer first if necessary. We always mark the
+  // data as changed (dirty) when the buffer is resized, otherwise only
+  // when the new data differ from the current. Nice feature :-)
+  //
+  int errCode;
+  if( newSize > oldSize )
+  {
+    errCode = moveBuffer( offset + newSize - oldSize, offset );
+    mDocumentModified = true;
+  }
+  else if( newSize < oldSize )
+  {
+    errCode = moveBuffer( offset, offset + oldSize - newSize );
+    mDocumentModified = true;
+  }
+  else
+  {
+    errCode = Err_Success;
+    if( memcmp( &data()[offset], newData, newSize ) != 0 )
+    {
+      mDocumentModified = true;
+    }
+  }
+
+  if( errCode == Err_Success )
+  {
+    memcpy( &data()[offset], newData, newSize );
+  }
+
+  //
+  // Data is removed regardless of success or not. Otherwise we will
+  // have a mmeory leak. The single reason why the operation above could
+  // fail is because there was that no more memory that could be
+  // allocated.
+  //
+  if( removeData == true )
+  {
+    delete [] newData;
+  }
+
+}
+
+
+bool CHexBuffer::inputDummy( unsigned char *dest, int value, uint cell )
+{
+  (void)dest;
+  (void)value;
+  (void)cell;
+  return( false );
+}
+
+
+bool CHexBuffer::inputHexadecimal( unsigned char *dest, int value, uint cell )
+{
+  if( value >= '0' && value <= '9' )
+  {
+    value = value - '0';
+  }
+  else if( value >= 'A' && value <= 'F' )
+  {
+    value = value - 'A' + 10;
+  }
+  else if( value >= 'a' && value <= 'f' )
+  {
+    value = value - 'a' + 10;
+  }
+  else
+  {
+    return( false );
+  }
+
+  if( cell > 1 )
+  {
+    return( false );
+  }
+
+  uint shift = 1 - cell;
+  *dest = (*dest & ~(0xF<<(shift*4)) ) | (value<<(shift*4));
+  return( true );
+}
+
+
+bool CHexBuffer::inputDecimal( unsigned char *dest, int value, uint cell )
+{
+  //
+  // 2000-01-22 Espen Sand
+  // I do the insertion a bit different here since decimal is special
+  // with respect to bitwidths.
+  //
+  if( value < '0' || value > '9' || cell > 2 )
+  {
+    return( false );
+  }
+
+  char buf[4];
+  printDecimalCell( buf, *dest );
+  buf[cell]=value;
+  buf[3]=0;
+
+  int tmp = atoi(buf);
+  if( tmp > 255 )
+  {
+    return( false );
+  }
+
+  *dest = tmp;
+  return( true );
+}
+
+
+bool CHexBuffer::inputOctal( unsigned char *dest, int value, uint cell )
+{
+  if( value >= '0' && value <= '7' )
+  {
+    value = value - '0';
+    if( cell == 0 && value > 3 )
+    {
+      return( false );
+    }
+  }
+  else
+  {
+    return( false );
+  }
+
+  if( cell >= 3 )
+  {
+    return( false );
+  }
+
+  uint shift = 2 - cell;
+  *dest = (*dest & ~(0x7<<(shift*3)) ) | (value<<(shift*3));
+  return( true );
+}
+
+
+bool CHexBuffer::inputBinary( unsigned char *dest, int value, uint cell )
+{
+  if( value >= '0' && value <= '1' )
+  {
+    value = value - '0';
+  }
+  else
+  {
+    return( false );
+  }
+
+  if( cell > 7 )
+  {
+    return( false );
+  }
+
+  uint shift = 7 - cell;
+  *dest = (*dest & ~(1<<shift)) | (value<<shift);
+  return( true );
+}
+
+
+
+bool CHexBuffer::inputAscii( unsigned char *dest, int value, uint )
+{
+  *dest = value;
+  return( true );
+}
+
+
+
+int CHexBuffer::moveBuffer( uint destOffset, uint srcOffset )
+{
+  if( srcOffset > documentSize() || destOffset == srcOffset )
+  {
+    return( Err_Success );
+  }
+
+  if( destOffset < srcOffset )
+  {
+    char *dest = &data()[ destOffset ];
+    char *src  = &data()[ srcOffset ];
+
+    memmove( dest, src, documentSize() - srcOffset );
+    setDocumentSize( documentSize() - (srcOffset - destOffset) );
+    return( Err_Success );
+  }
+  else
+  {
+    uint s = documentSize() - srcOffset;
+    if( destOffset + s >= size() )
+    {
+      int errCode = resizeBuffer( destOffset + s );
+      if( errCode != Err_Success )
+      {
+	fatalSound();
+	return( errCode );
+      }
+    }
+    else
+    {
+      setDocumentSize( documentSize() + (destOffset - srcOffset) );
+    }
+
+    char *dest = &data()[ destOffset ];
+    char *src  = &data()[ srcOffset ];
+
+    memmove( dest, src, s );
+    memset( src, 0, destOffset - srcOffset );
+    return( Err_Success );
+  }
+}
+
+
+
+
+int CHexBuffer::resizeBuffer( uint newSize )
+{
+  if( newSize < documentSize() )
+  {
+    return( Err_Success );
+  }
+
+  if( newSize >= size() )
+  {
+    TQByteArray tmp;
+    tmp.duplicate( data(), size() );
+    if( tmp.isNull() == true )
+    {
+      return( Err_NoMemory );
+    }
+
+    if( fill( '\0', newSize + 100 ) == false )
+    {
+      return( Err_NoMemory );
+    }
+
+    memcpy( data(), &tmp[0], tmp.size() );
+  }
+
+  setDocumentSize( newSize );
+  return( Err_Success );
+}
+
+
+void CHexBuffer::inputSound( void )
+{
+  if( mInputErrorSound == true )
+  {
+    KNotifyClient::beep( TQObject::tr("Edit operation failed") );
+  }
+}
+
+
+void CHexBuffer::fatalSound( void )
+{
+  if( mFatalErrorSound == true )
+  {
+    KNotifyClient::beep( TQObject::tr("Could not allocate memory") );
+  }
+}
+
+
+int CHexBuffer::printHtmlDataPage( const TQString &tocName,
+				   const TQStringList &fileNames, uint index,
+				   const SExportHtml &ex,
+				   uint line, uint numLine )
+{
+  if( fileNames.count() == 0 )
+  {
+    return( Err_NullArgument );
+  }
+
+  if( index >= fileNames.count() )
+  {
+    index = fileNames.count()-1;
+  }
+
+  TQFile file( fileNames[index] );
+  if( file.open( IO_WriteOnly ) == false )
+  {
+    return( Err_OperationAborted );
+  }
+
+  TQTextStream os( &file );
+  const TQString *next = index+1 >= fileNames.count() ? 0 : &fileNames[index+1];
+  const TQString *prev = index == 0 ? 0 : &fileNames[index-1];
+  const TQString *toc  = tocName.length() == 0 ? 0 : &tocName;
+
+  printHtmlHeader( os, true );
+  if( ex.navigator == true )
+  {
+    printHtmlNavigator( os, next, prev, toc );
+  }
+
+  printHtmlCaption( os, ex.topCaption, index+1, fileNames.count() );
+  printHtmlTable( os, line, numLine, ex.blackWhite );
+  printHtmlCaption( os, ex.bottomCaption, index+1, fileNames.count() );
+
+  if( ex.navigator == true )
+  {
+    printHtmlNavigator( os, next, prev, toc );
+  }
+  printHtmlHeader( os, false );
+
+  return( Err_Success );
+}
+
+
+void CHexBuffer::printHtmlTocPage( const TQString &tocName,
+				   const TQString &linkName,
+				   const TQStringList &fileNames,
+				   const TQStringList &offsets,
+				   uint numPage )
+{
+  if( numPage == 0 || fileNames.count() == 0 )
+  {
+    return;
+  }
+  if( numPage >= fileNames.count() )
+  {
+    numPage = fileNames.count() - 1;
+  }
+
+  TQFile file( tocName );
+  if( file.open( IO_WriteOnly ) == false )
+  {
+    return;
+  }
+
+  TQTextStream os( &file );
+  printHtmlHeader( os, true );
+
+  os << "<P ALIGN=\"CENTER\">" << endl;
+  os << "<B><FONT COLOR=BLACK>" << endl;
+  os << mUrl << endl;
+  os << "</FONT></B></CAPTION>" << endl;
+  os << "</P>" << endl;
+
+  os << "<P ALIGN=\"CENTER\"><TT>" << endl;
+  for( uint i=0; i<=numPage; i++ )
+  {
+    TQString n( fileNames[i].right( fileNames[i].length() -
+				   fileNames[i].findRev('/') - 1) );
+    os << "<A HREF=\"" << n << "\">" << i18n("Page") << i+1;
+    os << "</A>";
+    os << " " << offsets[i];
+    os << "<br>" << endl;
+  }
+  os << "</P>" << endl;
+
+  printHtmlHeader( os, false );
+
+  if( linkName.isEmpty() == false )
+  {
+    //
+    // Make a symlink. We ignore any error here. I don't consider
+    // it to be fatal.
+    //
+    TQString n( tocName.right( tocName.length() - tocName.findRev('/') - 1) );
+    symlink( n.latin1(), linkName.latin1() );
+  }
+
+}
+
+
+
+void CHexBuffer::printHtmlCaption( TQTextStream &os, uint captionType,
+				   uint curPage, uint numPage )
+{
+  TQString caption;
+  switch( captionType )
+  {
+    case 0:
+      return;
+    break;
+
+    case 1:
+      caption = mUrl;
+    break;
+
+    case 2:
+      caption = mUrl.right( mUrl.length() - mUrl.findRev('/') - 1);
+    break;
+
+    case 3:
+      caption = i18n("Page %1 of %2").arg(curPage).arg(numPage);
+    break;
+  }
+
+  os << "<P ALIGN=\"CENTER\">" << endl;
+  os << "<B><FONT COLOR=BLACK>" << endl;
+  os << caption << endl;
+  os << "</FONT></B></CAPTION>" << endl;
+  os << "</P>" << endl;
+}
+
+
+
+void CHexBuffer::printHtmlNavigator( TQTextStream &os, const TQString *next,
+				     const TQString *prev, const TQString *toc )
+{
+  os << "<TABLE BORDER=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">" << endl;
+  os << "<TR>" << endl;
+  os << "<TD>" << endl;
+  if( next == 0 )
+  {
+    os << i18n("Next") << " ";
+  }
+  else
+  {
+    TQString n( next->right( next->length() - next->findRev('/') - 1) );
+    os << "<A HREF=\"" << n << "\">" << i18n("Next") << "</A>" << " ";
+  }
+
+  if( prev == 0 )
+  {
+    os << i18n("Previous") << " ";
+  }
+  else
+  {
+    TQString p( prev->right( prev->length() - prev->findRev('/') - 1) );
+    os << "<A HREF=\"" << p << "\">" << i18n("Previous") << "</A>" << " ";
+  }
+
+  if( toc == 0 )
+  {
+    os << i18n("Contents") << " ";
+  }
+  else
+  {
+    TQString t( toc->right( toc->length() - toc->findRev('/') - 1) );
+    os << "<A HREF=\"" << t << "\">" << i18n("Contents");
+    os << "</A>" << " ";
+  }
+
+  os << "</TD>" << endl;
+
+  os << "<TD ALIGN=\"RIGHT\">" << endl;
+  os << "<A HREF=\"" << "http://home.sol.no/~espensa/khexedit" << "\">";
+  os << i18n("Generated by khexedit");
+  os << "</A>" << " ";
+
+  os << "</TD>" << endl;
+  os << "</TR>" << endl << "</TABLE>" << endl;
+}
+
+
+int CHexBuffer::printHtmlHeader( TQTextStream &os, bool isFront )
+{
+  if( isFront == true )
+  {
+    os << "<HTML>" << endl << "<HEAD>" << endl;
+    os << "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; ";
+    os << "charset=iso-8859-1\">" << endl;
+    os << "<META NAME=\"hexdata\" CONTENT=\"khexedit dump\">" << endl;
+    os << "</HEAD>" << endl << "<BODY>" << endl;
+  }
+  else
+  {
+    os << "</BODY>" << endl << "</HTML>" << endl;
+  }
+
+  return( Err_Success );
+}
+
+
+int CHexBuffer::printHtmlTable( TQTextStream &os, uint line, uint numLine,
+				bool bw )
+{
+  uint i;
+  TQColor color;
+
+
+  int numCol = 1;
+  if( mLayout.offsetVisible == true ) { numCol += 1; }
+  if( mLayout.secondaryMode != SDisplayLayout::hide ) { numCol += 1; }
+
+  os << "<TABLE BORDER=1 COLS=" << numCol << " WIDTH=\"100%\" ";
+  os << "CELLSPACING=0 CELLPADDING=2>" << endl;
+  if( mLayout.offsetVisible == true )
+  {
+    color = bw == true ? TQt::white : mColor.offsetBg;
+    os << "<TD BGCOLOR=" << TQString(color.name()).latin1() << ">" << endl;
+    os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
+    os << "CELLSPACING=0 CELLPADDING=2>" << endl;
+
+    color = bw == true ? TQt::black : mColor.offsetFg;
+    for( i=0; i<numLine; i++ )
+    {
+      os << "<TR><TD><TT><b><FONT COLOR=" << TQString(color.name()).latin1() << ">";
+      THIS_FPTR(printOffset)( mPrintBuf, (line+i)*mLayout.lineSize );
+      mPrintBuf[mOffsetSize]=0;
+      os << mPrintBuf << "</TD></TR>" << endl;
+    }
+    os << "</TABLE>" << endl << "</TD>" << endl;
+  }
+
+  color = bw == true ? TQt::white : mColor.textBg;
+  os << "<TD BGCOLOR=" << TQString(color.name()).latin1()  << ">" << endl;
+  os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
+  os << "CELLSPACING=0 CELLPADDING=2>" << endl;
+  for( i=0; i<numLine; i++ )
+  {
+    printHtmlLine( os, line+i, true, bw );
+  }
+  os << "</TABLE>" << endl << "</TD>" << endl;
+
+  if( mLayout.secondaryMode != SDisplayLayout::hide )
+  {
+    color = bw == true ? TQt::white : mColor.textBg;
+    os << "<TD BGCOLOR=" << TQString(color.name()).latin1() << ">" << endl;
+    os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
+    os << "CELLSPACING=0 CELLPADDING=2>" << endl;
+    for( i=0; i<numLine; i++ )
+    {
+      printHtmlLine( os, line+i, false, bw );
+    }
+    os << "</TABLE>" << endl << "</TD>" << endl;
+  }
+
+  os << "</TR>" << endl << "</TABLE>" << endl;
+  return( Err_Success );
+}
+
+
+int CHexBuffer::printHtmlLine( TQTextStream &os, uint line, bool isPrimary,
+			       bool bw )
+{
+  uint offset  = line * mLayout.lineSize;
+  TQColor prevColor;
+
+  TQColor color;
+  if( bw == true )
+  {
+    color = TQt::white;
+  }
+  else
+  {
+    color = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
+  }
+
+  os << "<TR><TD NOWRAP BGCOLOR=" << TQString(color.name()).latin1() << "><TT><B>"
+     << endl;
+  if( offset >= documentSize() )
+  {
+    os << "<BR></TD></TR>" << endl;
+    return( Err_Success );
+  }
+
+  for( uint i=0; i < mLayout.lineSize; i++ )
+  {
+    if( isPrimary == true )
+    {
+      if( offset+i >= documentSize() )
+      {
+	memset(mPrintBuf, ' ', mNumCell );	
+	mPrintBuf[mNumCell] = 0;
+	if( i == 0 )
+	{
+	  color = bw == true ? TQt::black : foregroundColor(i);
+	}
+	else
+	{
+	  color = prevColor;
+	}
+      }
+      else
+      {
+	unsigned char val = (unsigned char)data()[offset+i];
+	if( THIS_FPTR(printCell)( mPrintBuf, val ) == 0 )
+	{
+	  color = bw == true ? TQt::black : foregroundColor(i);
+	}
+	else
+	{
+	  color = bw == true ? TQt::black : mColor.nonPrintFg;
+	}
+      }
+      mPrintBuf[mNumCell] = 0;
+      if( i == 0 )
+      {
+	os << "<FONT COLOR=" << TQString(color.name()).latin1() << ">";
+      }
+      else if( color != prevColor )
+      {
+	os << "</FONT><FONT COLOR=" << TQString(color.name()).latin1() << ">";
+      }
+      prevColor = color;
+
+      if( mPrintBuf[0] == '<' )
+      {
+	os << "&lt;";
+      }
+      else
+      {
+	os << mPrintBuf;
+	if( (i+1) % mLayout.columnSize == 0 && (i+1) != mLayout.lineSize )
+	{
+	  os << " ";
+	}
+      }
+    }
+    else
+    {
+      if( offset+i >= documentSize() )
+      {
+	memset(mPrintBuf, ' ', 1 );
+	if( i == 0 )
+	{
+	  color = bw == true ? TQt::black : mColor.secondaryFg;
+	}
+	else
+	{
+	  color = prevColor;
+	}
+      }
+      else
+      {
+	unsigned char val = (unsigned char)data()[offset+i];
+	if( printAsciiCell( mPrintBuf, val ) == 0 )
+	{
+	  color = bw == true ? TQt::black : mColor.secondaryFg;
+	}
+	else
+	{
+	  color = bw == true ? TQt::black : mColor.nonPrintFg;
+	}
+	mPrintBuf[1] = 0;
+
+	if( i == 0 )
+	{
+	  os << "<FONT COLOR=" << TQString(color.name()).latin1() << ">";
+	}
+	else if( color != prevColor )
+	{
+	  os << "</FONT><FONT COLOR=" << TQString(color.name()).latin1()  << ">";
+	}
+	prevColor = color;
+	
+	mPrintBuf[1] = 0;
+	os << (mPrintBuf[0] == '<' ? "&lt;" : mPrintBuf);
+      }
+
+    }
+  }
+  os << "</TD></TR>" << endl;
+  return( Err_Success );
+}
+
+
+
+
+
diff --git a/khexedit/hexclipboard.cc b/khexedit/hexclipboard.cc
deleted file mode 100644
index 47326477..00000000
--- a/khexedit/hexclipboard.cc
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-//
-// This is a VERY crude implementation, which serves my requirements and 
-// nothing more.
-//
-
-
-#include <string.h>
-#include "hexclipboard.h"
-
-
-static const uchar *base64EncodeTable( void )
-{
-  static uchar table[64] =
-  {
-    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
-    'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
-    'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
-    'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',
-  };
-
-  return( table );
-}
-
-static const uchar *base64DecodeTable( void )
-{
-  static uchar table[255];
-  static bool init = false;
-  if( init == false )
-  {
-    uint i;
-    for( i = 0; i < 255; i++ )    { table[i] = 0x80; }
-    for( i = 'A'; i <= 'Z'; i++ ) { table[i] = 0 + (i - 'A'); }
-    for( i = 'a'; i <= 'z'; i++ ) { table[i] = 26 + (i - 'a'); }
-    for( i = '0'; i <= '9'; i++ ) { table[i] = 52 + (i - '0'); }
-    table[(uchar)'+'] = 62;
-    table[(uchar)'/'] = 63;
-    table[(uchar)'='] = 0;
-    init  = true;
-  }
-  return( table );
-}
-
-
-static const char *mimeHeader( void )
-{
-  static const char *data = 
-    "Content-Type: application/octet-stream; " \
-    "name=\"khexedit_copy\"\r\n" \
-    "Content-Transfer-Encoding: base64\r\n\r\n";
-  return( data );
-}
-
-
-
-
-
-
-
-
-CHexClipboard::CHexClipboard( void )
-{
-}
-
-
-CHexClipboard::~CHexClipboard( void )
-{
-}
-
-
-bool CHexClipboard::encode( TQByteArray &dst, TQByteArray &src )
-{
-  if( src.size() == 0 )
-  {
-    return( false );
-  }
-
-  uint srcSize  = src.size();
-  uint mimeSize = strlen( mimeHeader() );
-  uint lineSize = 72;
-  uint dstSize  = (srcSize / 3 + (srcSize % 3 ? 1 : 0)) * 4;
-  dstSize += ((dstSize/lineSize) + 1)*2 + 1;
-
-  dst.resize( dstSize + mimeSize + 1 );
-  if( dst.isNull() == true )
-  {
-    return( false );
-  }
-
-  unsigned char inBuf[3], outBuf[4];
-  uint lineLen = 0;
-  
-  memcpy( dst.data(), mimeHeader(), mimeSize );
-  uint j = mimeSize;
-
-
-  const uchar *table = base64EncodeTable();
-  for( uint i=0; i < srcSize; i += 3 )
-  {
-    memset( inBuf, 0, sizeof(inBuf) );
-    uint n;
-    for( n=0; n < 3; n++ )
-    {
-      if( i+n >= srcSize )
-      {
-	break;
-      }
-      inBuf[n] = src[i+n];
-    }
-
-    if( n > 0 ) 
-    {
-      outBuf[0] = table[ inBuf[0] >> 2 ];
-      outBuf[1] = table[ ((inBuf[0] & 0x3) << 4) | (inBuf[1] >> 4) ];
-      outBuf[2] = table[ ((inBuf[1] & 0xF) << 2) | (inBuf[2] >> 6) ];
-      outBuf[3] = table[ inBuf[2] & 0x3F ];
-
-      if( n < 3 )
-      {
-	outBuf[3] = '=';
-	if( n < 2 )
-	{
-	  outBuf[2] = '=';
-	}
-      }
-      
-      for( uint m=0; m<4; m++ )
-      {
-	if( lineLen >= lineSize )
-	{
-	  dst[j++] = '\r';
-	  dst[j++] = '\n';
-	  lineLen = 0;
-	}
-	dst[j++] = outBuf[m];
-	lineLen += 1;
-      }
-    }
-  }
-  dst[j++] = '\r';
-  dst[j++] = '\n';
-  dst[j++] = '\0';
-  return( true );
-} 
-
-
-
-
-bool CHexClipboard::decode( TQByteArray &dst, TQString &src )
-{
-  uint mimeSize = strlen( mimeHeader() );
-  if( src.length() <= mimeSize )
-  {
-    return( plainDecode( dst, src ) );
-  }
-
-  if( memcmp( src.ascii(), mimeHeader(), mimeSize ) != 0 )
-  {
-    return( plainDecode( dst, src ) );
-  }
-
-  uint srcSize = src.length();
-  uint dstSize = (srcSize * 3) / 4;
-  uchar srcBuf[4], valBuf[4], dstBuf[3];
-  uint sumElement = 0;
-
-  dst.resize( dstSize );
-  if( dst.isNull() == true )
-  {
-    return( plainDecode( dst, src ) );
-  }
-
-  uint i,j;
-  uint n = 0;
-
-  const uchar *table = base64DecodeTable();
-  for( i=mimeSize; i<srcSize; )
-  {
-    for( j=0; j<4; )
-    {
-      if( i >= srcSize )
-      {
-	dst.truncate( sumElement );
-	return( j > 0 ? false : true );
-      }
-
-      int c = src[i++].latin1();
-      if( c <= ' ' )
-      {
-	continue;
-      }
-      if( table[c] & 0x80 )
-      {
-	return( plainDecode( dst, src ) );
-      }
-
-      srcBuf[j] = c;
-      valBuf[j] = table[c];
-      j++;
-    }
-  
-    dstBuf[0] = (valBuf[0] << 2) | (valBuf[1] >> 4);
-    dstBuf[1] = (valBuf[1] << 4) | (valBuf[2] >> 2);
-    dstBuf[2] = (valBuf[2] << 6) | (valBuf[3]);
-
-    uint numElement = srcBuf[2] == '=' ? 1 : (srcBuf[3] == '=' ? 2 : 3);    
-    for( uint m=0; m < numElement; m++ )
-    {
-      dst[n++] = dstBuf[m];
-    }
-    sumElement += numElement;
-
-    if( numElement < 3 )
-    {
-      break;
-    }
-  }
-
-  dst.truncate( sumElement );
-  return( true );
-} 
-
-
-bool CHexClipboard::plainDecode( TQByteArray &dst, TQString &src )
-{
-  dst.resize( src.length() );
-  if( dst.isNull() == true )
-  {
-    return( false );
-  }
-
-  for( uint i=0; i < src.length(); dst[i] = src[i].latin1(), i++ );
-  return( true );
-}
-
diff --git a/khexedit/hexclipboard.cpp b/khexedit/hexclipboard.cpp
new file mode 100644
index 00000000..47326477
--- /dev/null
+++ b/khexedit/hexclipboard.cpp
@@ -0,0 +1,254 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+//
+// This is a VERY crude implementation, which serves my requirements and 
+// nothing more.
+//
+
+
+#include <string.h>
+#include "hexclipboard.h"
+
+
+static const uchar *base64EncodeTable( void )
+{
+  static uchar table[64] =
+  {
+    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+    'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+    'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+    'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',
+  };
+
+  return( table );
+}
+
+static const uchar *base64DecodeTable( void )
+{
+  static uchar table[255];
+  static bool init = false;
+  if( init == false )
+  {
+    uint i;
+    for( i = 0; i < 255; i++ )    { table[i] = 0x80; }
+    for( i = 'A'; i <= 'Z'; i++ ) { table[i] = 0 + (i - 'A'); }
+    for( i = 'a'; i <= 'z'; i++ ) { table[i] = 26 + (i - 'a'); }
+    for( i = '0'; i <= '9'; i++ ) { table[i] = 52 + (i - '0'); }
+    table[(uchar)'+'] = 62;
+    table[(uchar)'/'] = 63;
+    table[(uchar)'='] = 0;
+    init  = true;
+  }
+  return( table );
+}
+
+
+static const char *mimeHeader( void )
+{
+  static const char *data = 
+    "Content-Type: application/octet-stream; " \
+    "name=\"khexedit_copy\"\r\n" \
+    "Content-Transfer-Encoding: base64\r\n\r\n";
+  return( data );
+}
+
+
+
+
+
+
+
+
+CHexClipboard::CHexClipboard( void )
+{
+}
+
+
+CHexClipboard::~CHexClipboard( void )
+{
+}
+
+
+bool CHexClipboard::encode( TQByteArray &dst, TQByteArray &src )
+{
+  if( src.size() == 0 )
+  {
+    return( false );
+  }
+
+  uint srcSize  = src.size();
+  uint mimeSize = strlen( mimeHeader() );
+  uint lineSize = 72;
+  uint dstSize  = (srcSize / 3 + (srcSize % 3 ? 1 : 0)) * 4;
+  dstSize += ((dstSize/lineSize) + 1)*2 + 1;
+
+  dst.resize( dstSize + mimeSize + 1 );
+  if( dst.isNull() == true )
+  {
+    return( false );
+  }
+
+  unsigned char inBuf[3], outBuf[4];
+  uint lineLen = 0;
+  
+  memcpy( dst.data(), mimeHeader(), mimeSize );
+  uint j = mimeSize;
+
+
+  const uchar *table = base64EncodeTable();
+  for( uint i=0; i < srcSize; i += 3 )
+  {
+    memset( inBuf, 0, sizeof(inBuf) );
+    uint n;
+    for( n=0; n < 3; n++ )
+    {
+      if( i+n >= srcSize )
+      {
+	break;
+      }
+      inBuf[n] = src[i+n];
+    }
+
+    if( n > 0 ) 
+    {
+      outBuf[0] = table[ inBuf[0] >> 2 ];
+      outBuf[1] = table[ ((inBuf[0] & 0x3) << 4) | (inBuf[1] >> 4) ];
+      outBuf[2] = table[ ((inBuf[1] & 0xF) << 2) | (inBuf[2] >> 6) ];
+      outBuf[3] = table[ inBuf[2] & 0x3F ];
+
+      if( n < 3 )
+      {
+	outBuf[3] = '=';
+	if( n < 2 )
+	{
+	  outBuf[2] = '=';
+	}
+      }
+      
+      for( uint m=0; m<4; m++ )
+      {
+	if( lineLen >= lineSize )
+	{
+	  dst[j++] = '\r';
+	  dst[j++] = '\n';
+	  lineLen = 0;
+	}
+	dst[j++] = outBuf[m];
+	lineLen += 1;
+      }
+    }
+  }
+  dst[j++] = '\r';
+  dst[j++] = '\n';
+  dst[j++] = '\0';
+  return( true );
+} 
+
+
+
+
+bool CHexClipboard::decode( TQByteArray &dst, TQString &src )
+{
+  uint mimeSize = strlen( mimeHeader() );
+  if( src.length() <= mimeSize )
+  {
+    return( plainDecode( dst, src ) );
+  }
+
+  if( memcmp( src.ascii(), mimeHeader(), mimeSize ) != 0 )
+  {
+    return( plainDecode( dst, src ) );
+  }
+
+  uint srcSize = src.length();
+  uint dstSize = (srcSize * 3) / 4;
+  uchar srcBuf[4], valBuf[4], dstBuf[3];
+  uint sumElement = 0;
+
+  dst.resize( dstSize );
+  if( dst.isNull() == true )
+  {
+    return( plainDecode( dst, src ) );
+  }
+
+  uint i,j;
+  uint n = 0;
+
+  const uchar *table = base64DecodeTable();
+  for( i=mimeSize; i<srcSize; )
+  {
+    for( j=0; j<4; )
+    {
+      if( i >= srcSize )
+      {
+	dst.truncate( sumElement );
+	return( j > 0 ? false : true );
+      }
+
+      int c = src[i++].latin1();
+      if( c <= ' ' )
+      {
+	continue;
+      }
+      if( table[c] & 0x80 )
+      {
+	return( plainDecode( dst, src ) );
+      }
+
+      srcBuf[j] = c;
+      valBuf[j] = table[c];
+      j++;
+    }
+  
+    dstBuf[0] = (valBuf[0] << 2) | (valBuf[1] >> 4);
+    dstBuf[1] = (valBuf[1] << 4) | (valBuf[2] >> 2);
+    dstBuf[2] = (valBuf[2] << 6) | (valBuf[3]);
+
+    uint numElement = srcBuf[2] == '=' ? 1 : (srcBuf[3] == '=' ? 2 : 3);    
+    for( uint m=0; m < numElement; m++ )
+    {
+      dst[n++] = dstBuf[m];
+    }
+    sumElement += numElement;
+
+    if( numElement < 3 )
+    {
+      break;
+    }
+  }
+
+  dst.truncate( sumElement );
+  return( true );
+} 
+
+
+bool CHexClipboard::plainDecode( TQByteArray &dst, TQString &src )
+{
+  dst.resize( src.length() );
+  if( dst.isNull() == true )
+  {
+    return( false );
+  }
+
+  for( uint i=0; i < src.length(); dst[i] = src[i].latin1(), i++ );
+  return( true );
+}
+
diff --git a/khexedit/hexdrag.cc b/khexedit/hexdrag.cc
deleted file mode 100644
index eff7c937..00000000
--- a/khexedit/hexdrag.cc
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-
-#include "hexdrag.h"
-static const char *mediaString = "application/octet-stream";
-
-
-CHexDrag::CHexDrag( const TQByteArray &data, TQWidget *dragSource,
-		    const char *name )
-  :TQDragObject(dragSource,name)
-{
-  setData( data );
-  prepPixmap();
-}
-
-
-CHexDrag::CHexDrag( TQWidget *dragSource, const char *name )
-  :TQDragObject(dragSource,name)
-{
-  prepPixmap();
-}
-
-
-void CHexDrag::setData( const TQByteArray &data )
-{
-  mData = data;
-}
-
-
-
-void CHexDrag::prepPixmap(void)
-{
-  //
-  // Wont use it yet,
-  //
-  /*
-  TDEIconLoader &loader = *TDEGlobal::iconLoader();
-  TQPixmap pix = loader.loadIcon( "binary.xpm" );
-
-  TQPoint hotspot( pix.width()-20,pix.height()/2 );
-  setPixmap( pix, hotspot ); 
-  */
-}
-
-
-const char *CHexDrag::format( int i ) const
-{
-  if( i == 0 )
-  {
-    return( mediaString );
-  }
-  else
-  {
-    return( 0 );
-  }
-  return( i == 0 ? mediaString : 0 );
-}
-
-
-TQByteArray CHexDrag::encodedData( const char *fmt ) const
-{
-  if( fmt != 0 )
-  {
-    if( strcmp( fmt, mediaString) == 0 )
-    {
-      return( mData );
-    }
-  }
-
-  TQByteArray buf;
-  return( buf );
-}
-
-
-bool CHexDrag::canDecode( const TQMimeSource *e )
-{
-  return( e->provides(mediaString) );
-}
-
-
-bool CHexDrag::decode( const TQMimeSource *e, TQByteArray &dest )
-{
-  dest = e->encodedData(mediaString);
-  return( dest.size() == 0 ? false : true );
-
-  //
-  // I get an 
-  // "X Error: BadAtom (invalid Atom parameter) 5
-  //   Major opcode:  17"
-  //
-  // if I try to use the code below on a source that has been 
-  // collected from TQClipboard. It is the e->provides(mediaString)
-  // that fail (TQt-2.0). Sometimes it works :(
-  //
-  // printf("0: %s\n", e->format(0) ); No problem. 
-  // printf("1: %s\n", e->format(1) ); Crash. 
-  //
-  #if 0
-  if( e->provides(mediaString) == true )
-  {
-    dest = e->encodedData(mediaString);
-    return( true );
-  }
-  else
-  {
-    return( false );
-  }
-  #endif
-}
-
-
-#include "hexdrag.moc"
diff --git a/khexedit/hexdrag.cpp b/khexedit/hexdrag.cpp
new file mode 100644
index 00000000..eff7c937
--- /dev/null
+++ b/khexedit/hexdrag.cpp
@@ -0,0 +1,130 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+
+#include "hexdrag.h"
+static const char *mediaString = "application/octet-stream";
+
+
+CHexDrag::CHexDrag( const TQByteArray &data, TQWidget *dragSource,
+		    const char *name )
+  :TQDragObject(dragSource,name)
+{
+  setData( data );
+  prepPixmap();
+}
+
+
+CHexDrag::CHexDrag( TQWidget *dragSource, const char *name )
+  :TQDragObject(dragSource,name)
+{
+  prepPixmap();
+}
+
+
+void CHexDrag::setData( const TQByteArray &data )
+{
+  mData = data;
+}
+
+
+
+void CHexDrag::prepPixmap(void)
+{
+  //
+  // Wont use it yet,
+  //
+  /*
+  TDEIconLoader &loader = *TDEGlobal::iconLoader();
+  TQPixmap pix = loader.loadIcon( "binary.xpm" );
+
+  TQPoint hotspot( pix.width()-20,pix.height()/2 );
+  setPixmap( pix, hotspot ); 
+  */
+}
+
+
+const char *CHexDrag::format( int i ) const
+{
+  if( i == 0 )
+  {
+    return( mediaString );
+  }
+  else
+  {
+    return( 0 );
+  }
+  return( i == 0 ? mediaString : 0 );
+}
+
+
+TQByteArray CHexDrag::encodedData( const char *fmt ) const
+{
+  if( fmt != 0 )
+  {
+    if( strcmp( fmt, mediaString) == 0 )
+    {
+      return( mData );
+    }
+  }
+
+  TQByteArray buf;
+  return( buf );
+}
+
+
+bool CHexDrag::canDecode( const TQMimeSource *e )
+{
+  return( e->provides(mediaString) );
+}
+
+
+bool CHexDrag::decode( const TQMimeSource *e, TQByteArray &dest )
+{
+  dest = e->encodedData(mediaString);
+  return( dest.size() == 0 ? false : true );
+
+  //
+  // I get an 
+  // "X Error: BadAtom (invalid Atom parameter) 5
+  //   Major opcode:  17"
+  //
+  // if I try to use the code below on a source that has been 
+  // collected from TQClipboard. It is the e->provides(mediaString)
+  // that fail (TQt-2.0). Sometimes it works :(
+  //
+  // printf("0: %s\n", e->format(0) ); No problem. 
+  // printf("1: %s\n", e->format(1) ); Crash. 
+  //
+  #if 0
+  if( e->provides(mediaString) == true )
+  {
+    dest = e->encodedData(mediaString);
+    return( true );
+  }
+  else
+  {
+    return( false );
+  }
+  #endif
+}
+
+
+#include "hexdrag.moc"
diff --git a/khexedit/hexeditorwidget.cc b/khexedit/hexeditorwidget.cc
deleted file mode 100644
index 09a9407b..00000000
--- a/khexedit/hexeditorwidget.cc
+++ /dev/null
@@ -1,2443 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-
-#include <iostream>
-#include <unistd.h>
-
-#undef Unsorted
-
-#include <tdefiledialog.h>
-#include <tdeglobalsettings.h>
-#include <tdeio/netaccess.h>
-#include <tdelocale.h>
-#include <tdemessagebox.h>
-#include <tdetempfile.h>
-#include <kpushbutton.h>
-#include <kstdguiitem.h>
-
-#include "chartabledialog.h"
-#include "converterdialog.h"
-#include "dialog.h"
-#include "exportdialog.h"
-#include "fileinfodialog.h"
-#include "hexeditorwidget.h"
-#include "hexerror.h"
-#include "optiondialog.h"
-#include "printdialogpage.h"
-#include "stringdialog.h"
-
-
-
-
-CHexEditorWidget::CHexEditorWidget( TQWidget *parent, const char *name )
-  : TQWidget( parent, name )
-{
-  CHexBuffer *hexBuffer = new CHexBuffer;
-  if( hexBuffer == 0 ) { return; }
-
-  mDocumentList.setAutoDelete( true );
-  mDocumentList.append( hexBuffer );
-  mUntitledCount = 1;
-
-  mHexView = new CHexViewWidget( this, "hexview", hexBuffer );
-  if( mHexView == 0 || mHexView->widgetValid() == false ) { return; }
-
-  connect( mHexView, TQT_SIGNAL(pleaseOpenNewFile()), TQT_SLOT( newFile()) );
-  connect( mHexView, TQT_SIGNAL(pleaseOpenFile( const TQString&, bool, uint )),
-	   TQT_SLOT( open(const TQString&, bool, uint)) );
-  connect( mHexView, TQT_SIGNAL(pleaseStepFile(bool)), TQT_SLOT( stepFile(bool)) );
-  connect( kapp, TQT_SIGNAL( tdedisplayFontChanged() ), TQT_SLOT( fontChanged() ) );
-  connect( kapp, TQT_SIGNAL( tdedisplayPaletteChanged() ),TQT_SLOT( paletteChanged()) );
-  connect( mHexView, TQT_SIGNAL( layoutChanged( const SDisplayLayout & ) ),
-	   TQT_SLOT( layoutChanged( const SDisplayLayout & ) ) );
-  connect( mHexView, TQT_SIGNAL( inputModeChanged( const SDisplayInputMode & ) ),
-	   this, TQT_SLOT( inputModeChanged( const SDisplayInputMode & ) ) );
-
-  mHexView->setFocus();
-  setBackgroundColor( palette().active().base() );
-
-  mProgressBusy    = false;
-  mGotoDialog      = 0;
-  mFindDialog      = 0;
-  mReplaceDialog   = 0;
-  mInsertDialog    = 0;
-  mFilterDialog    = 0;
-  mOptionDialog    = 0;
-  mStringDialog    = 0;
-  mCharTableDialog = 0;
-  mFileInfoDialog  = 0;
-  mExportDialog    = 0;
-  mConverterDialog = 0;
-  mFindNavigatorDialog   = 0;
-  mReplacePromptDialog   = 0;
-}
-
-CHexEditorWidget::~CHexEditorWidget( void )
-{
-  delete mHexView;
-  delete mGotoDialog;
-  delete mFindDialog;
-  delete mReplaceDialog;
-  delete mInsertDialog;
-  delete mFilterDialog;
-  delete mOptionDialog;
-  delete mStringDialog;
-  delete mCharTableDialog;
-  delete mFileInfoDialog;
-  delete mExportDialog;
-  delete mConverterDialog;
-  delete mFindNavigatorDialog;
-  delete mReplacePromptDialog;
-}
-
-
-void CHexEditorWidget::initialize( void )
-{
-  setColor( mDisplayState.color );
-  setFont( mDisplayState.font );
-  mHexView->setMisc( mDisplayState.misc );
-  mHexView->setCursor( mDisplayState.cursor, false );
-  mHexView->setLayout( mDisplayState.layout );
-  mHexView->setInputMode( mDisplayState.input );
-  mHexView->setInsertMode( mDisplayState.misc.insertMode );
-}
-
-
-void CHexEditorWidget::writeConfiguration( TDEConfig &config )
-{
-  SDisplayLayout &layout = mDisplayState.layout;
-  config.setGroup( "Display Options" );
-  config.writeEntry( "PrimaryMode",          layout.primaryModeString() );
-  config.writeEntry( "SecondaryMode",        layout.secondaryModeString() );
-  config.writeEntry( "OffsetMode",           layout.offsetModeString() );
-  config.writeEntry( "OffsetVisible",        layout.offsetVisible );
-  config.writeEntry( "PrimaryUpperCase",     layout.primaryUpperCase );
-  config.writeEntry( "OffsetUpperCase",      layout.offsetUpperCase );
-  config.writeEntry( "LineSize",             layout.lineSize );
-  config.writeEntry( "ColumnSize",           layout.columnSize );
-  config.writeEntry( "LockLine",             layout.lockLine );
-  config.writeEntry( "LockColumn",           layout.lockColumn );
-  config.writeEntry( "ColumnCharSpace",      layout.columnCharSpace );
-  config.writeEntry( "ColumnSpacing",        layout.columnSpacing );
-  config.writeEntry( "SeparatorMarginWidth", layout.separatorMarginWidth );
-  config.writeEntry( "EdgeMarginWidth",      layout.edgeMarginWidth );
-  config.writeEntry( "LeftSeparatorWidth",   layout.leftSeparatorWidth );
-  config.writeEntry( "RightSeparatorWidth",  layout.rightSeparatorWidth );
-  config.writeEntry( "GridMode",             layout.gridModeString() );
-
-  SDisplayLine &line = mDisplayState.line;
-  config.setGroup( "Line Size" );
-  config.writeEntry( "Hexadecimal",line.lineSize[SDisplayLine::hexadecimal] );
-  config.writeEntry( "Decimal",    line.lineSize[SDisplayLine::decimal] );
-  config.writeEntry( "Octal",      line.lineSize[SDisplayLine::octal] );
-  config.writeEntry( "Binary",     line.lineSize[SDisplayLine::binary] );
-  config.writeEntry( "TextOnly",   line.lineSize[SDisplayLine::textOnly] );
-  config.setGroup( "Column Size" );
-  config.writeEntry( "Hexadecimal",line.columnSize[SDisplayLine::hexadecimal]);
-  config.writeEntry( "Decimal",    line.columnSize[SDisplayLine::decimal] );
-  config.writeEntry( "Octal",      line.columnSize[SDisplayLine::octal] );
-  config.writeEntry( "Binary",     line.columnSize[SDisplayLine::binary] );
-  config.writeEntry( "TextOnly",   line.columnSize[SDisplayLine::textOnly] );
-
-  SDisplayColor &color = mDisplayState.color;
-  config.setGroup( "Display Colors" );
-  config.writeEntry( "UseSystemColor",       color.useSystemColor );
-  config.writeEntry( "TextBg",               color.textBg );
-  config.writeEntry( "SecondTextBg",         color.secondTextBg );
-  config.writeEntry( "OffsetBg",             color.offsetBg );
-  config.writeEntry( "InactiveBg",           color.inactiveBg );
-  config.writeEntry( "PrimaryFg1",           color.primaryFg[0] );
-  config.writeEntry( "PrimaryFg2",           color.primaryFg[1] );
-  config.writeEntry( "OffsetFg",             color.offsetFg );
-  config.writeEntry( "SecondaryFg",          color.secondaryFg );
-  config.writeEntry( "MarkBg",               color.markBg );
-  config.writeEntry( "MarkFg",               color.markFg );
-  config.writeEntry( "LeftSeparatorFg",      color.leftSeparatorFg );
-  config.writeEntry( "RightSeparatorFg",     color.leftSeparatorFg );
-  config.writeEntry( "NonPrintFg",           color.nonPrintFg );
-  config.writeEntry( "CursorBg",             color.cursorBg );
-  config.writeEntry( "CursorFg",             color.cursorFg );
-  config.writeEntry( "GridFg",               color.gridFg );
-  config.writeEntry( "BookmarkBg",           color.bookmarkBg );
-  config.writeEntry( "BookmarkFg",           color.bookmarkFg );
-
-  SDisplayFont &font = mDisplayState.font;
-  config.setGroup( "Display Font" );
-  config.writeEntry( "UseSystemFont",        font.useSystemFont );
-  config.writeEntry( "LocalFont",            font.localFont );
-  config.writeEntry( "NonPrintChar",         font.nonPrintChar.unicode() );
-
-  SDisplayCursor &cursor = mDisplayState.cursor;
-  config.setGroup( "Display Cursor" );
-  config.writeEntry( "NeverBlink",           cursor.alwaysVisible );
-  config.writeEntry( "AlwaysBlockShape",     cursor.alwaysBlockShape );
-  config.writeEntry( "ThickInsertShape",     cursor.thickInsertShape );
-  config.writeEntry( "FocusMode",            cursor.focusModeString() );
-  config.writeEntry( "Interval",             cursor.interval );
-
-  SDisplayMisc &misc = mDisplayState.misc;
-  config.setGroup( "Display Misc" );
-  config.writeEntry( "UndoLevel",            misc.undoLevel );
-  config.writeEntry( "OpenFile",             misc.openFileString() );
-  config.writeEntry( "InputSound",           misc.inputSound );
-  config.writeEntry( "FatalSound",           misc.fatalSound );
-  config.writeEntry( "AutoCopyToClipboard",  misc.autoCopyToClipboard );
-  config.writeEntry( "InsertMode",           misc.insertMode );
-  config.writeEntry( "WriteProtect",         misc.writeProtect );
-  config.writeEntry( "ConfirmWrap",          misc.confirmWrap );
-  config.writeEntry( "CursorJump",           misc.cursorJump );
-  config.writeEntry( "MakeBackup",           misc.makeBackup );
-  config.writeEntry( "ConfirmThreshold",     misc.confirmThreshold );
-  config.writeEntry( "ThresholdValue",       misc.thresholdValue );
-  config.writeEntry( "DiscardRecent",        misc.discardRecent );
-  config.writeEntry( "GotoOnStartup",        misc.gotoOnStartup );
-  config.writeEntry( "GotoOnReload",         misc.gotoOnReload );
-  config.writeEntry( "ShowBookmarkInOffsetColumn", misc.bookmarkOffsetColumn );
-  config.writeEntry( "ShowBookmarkInEditor", misc.bookmarkEditor );
-
-  if( mExportDialog != 0 )
-  {
-    mExportDialog->writeConfiguration();
-  }
-}
-
-void CHexEditorWidget::readConfiguration( TDEConfig &config )
-{
-  SDisplayLayout &layout = mDisplayState.layout;
-  config.setGroup( "Display Options" );
-  layout.setPrimaryMode( config.readEntry("PrimaryMode") );
-  layout.setSecondaryMode( config.readEntry("SecondaryMode") );
-  layout.setOffsetMode( config.readEntry("OffsetMode") );
-  layout.offsetVisible = config.readBoolEntry(
-    "OffsetVisible", layout.offsetVisible );
-  layout.primaryUpperCase = config.readBoolEntry(
-    "PrimaryUpperCase", layout.primaryUpperCase );
-  layout.offsetUpperCase = config.readBoolEntry(
-    "OffsetUpperCase", layout.offsetUpperCase );
-  layout.lineSize = config.readNumEntry(
-    "LineSize", layout.lineSize );
-  layout.columnSize = config.readNumEntry(
-    "ColumnSize", layout.columnSize );
-  layout.lockLine = config.readBoolEntry(
-    "LockLine", layout.lockLine );
-  layout.lockColumn = config.readBoolEntry(
-    "LockColumn", layout.lockColumn );
-  layout.columnCharSpace = config.readBoolEntry(
-    "ColumnCharSpace", layout.columnCharSpace );
-  layout.columnSpacing = config.readNumEntry(
-    "ColumnSpacing", layout.columnSpacing );
-  layout.separatorMarginWidth = config.readNumEntry(
-    "SeparatorMarginWidth", layout.separatorMarginWidth );
-  layout.edgeMarginWidth = config.readNumEntry(
-    "EdgeMarginWidth", layout.edgeMarginWidth );
-  layout.leftSeparatorWidth = config.readNumEntry(
-    "LeftSeparatorWidth", layout.leftSeparatorWidth );
-  layout.rightSeparatorWidth = config.readNumEntry(
-    "RightSeparatorWidth", layout.rightSeparatorWidth );
-  layout.setGridMode( config.readEntry("GridMode") );
-
-  SDisplayLine &line = mDisplayState.line;
-  config.setGroup( "Line Size" );
-  line.lineSize[SDisplayLine::hexadecimal] = config.readUnsignedNumEntry(
-    "Hexadecimal", line.lineSize[SDisplayLine::hexadecimal] );
-  line.lineSize[SDisplayLine::decimal] = config.readUnsignedNumEntry(
-    "Decimal", line.lineSize[SDisplayLine::decimal] );
-  line.lineSize[SDisplayLine::octal] = config.readUnsignedNumEntry(
-    "Octal", line.lineSize[SDisplayLine::octal] );
-  line.lineSize[SDisplayLine::binary] = config.readUnsignedNumEntry(
-    "Binary", line.lineSize[SDisplayLine::binary] );
-  line.lineSize[SDisplayLine::textOnly] = config.readUnsignedNumEntry(
-    "TextOnly", line.lineSize[SDisplayLine::textOnly] );
-  config.setGroup( "Column Size" );
-  line.columnSize[SDisplayLine::hexadecimal] = config.readUnsignedNumEntry(
-    "Hexadecimal", line.columnSize[SDisplayLine::hexadecimal] );
-  line.columnSize[SDisplayLine::decimal] = config.readUnsignedNumEntry(
-    "Decimal", line.columnSize[SDisplayLine::decimal] );
-  line.columnSize[SDisplayLine::octal] = config.readUnsignedNumEntry(
-    "Octal", line.columnSize[SDisplayLine::octal] );
-  line.columnSize[SDisplayLine::binary] = config.readUnsignedNumEntry(
-    "Binary", line.columnSize[SDisplayLine::binary] );
-  line.columnSize[SDisplayLine::textOnly] = config.readUnsignedNumEntry(
-    "TextOnly", line.columnSize[SDisplayLine::textOnly] );
-
-  SDisplayFont &font = mDisplayState.font;
-  config.setGroup( "Display Font" );
-  font.useSystemFont = config.readBoolEntry(
-    "UseSystemFont", true );
-  font.localFont = config.readFontEntry(
-    "LocalFont", &font.localFont );
-  font.nonPrintChar = config.readNumEntry(
-    "NonPrintChar", font.nonPrintChar );
-
-  SDisplayColor &color = mDisplayState.color;
-  config.setGroup( "Display Colors" );
-  color.useSystemColor = config.readBoolEntry(
-    "UseSystemColor", color.useSystemColor );
-  color.textBg = config.readColorEntry(
-    "TextBg", &color.textBg );
-  color.secondTextBg = config.readColorEntry(
-    "SecondTextBg", &color.secondTextBg );
-  color.offsetBg = config.readColorEntry(
-    "OffsetBg", &color.offsetBg );
-  color.inactiveBg = config.readColorEntry(
-    "InactiveBg", &color.inactiveBg );
-  color.primaryFg[0] = config.readColorEntry(
-    "PrimaryFg1", &color.primaryFg[0] );
-  color.primaryFg[1] = config.readColorEntry(
-    "PrimaryFg2", &color.primaryFg[1] );
-  color.offsetFg = config.readColorEntry(
-    "OffsetFg", &color.offsetFg );
-  color.secondaryFg = config.readColorEntry(
-    "SecondaryFg", &color.secondaryFg );
-  color.markBg = config.readColorEntry(
-    "MarkBg", &color.markBg );
-  color.markFg = config.readColorEntry(
-    "MarkFg", &color.markFg );
-  color.cursorBg = config.readColorEntry(
-    "CursorBg", &color.cursorBg );
-  color.cursorFg = config.readColorEntry(
-    "CursorFg", &color.cursorFg );
-  color.leftSeparatorFg = config.readColorEntry(
-    "LeftSeparatorFg", &color.leftSeparatorFg );
-  color.rightSeparatorFg = config.readColorEntry(
-    "RightSeparatorFg", &color.rightSeparatorFg );
-  color.nonPrintFg = config.readColorEntry(
-    "NonPrintFg", &color.nonPrintFg );
-  color.gridFg = config.readColorEntry(
-    "GridFg", &color.gridFg );
-  color.bookmarkBg = config.readColorEntry(
-    "BookmarkBg", &color.bookmarkBg );
-  color.bookmarkFg = config.readColorEntry(
-    "BookmarkFg", &color.bookmarkFg );
-
-  SDisplayCursor &cursor = mDisplayState.cursor;
-  config.setGroup( "Display Cursor" );
-  cursor.alwaysVisible = config.readBoolEntry(
-    "NeverBlink", cursor.alwaysVisible );
-  cursor.alwaysBlockShape = config.readBoolEntry(
-    "AlwaysBlockShape", cursor.alwaysBlockShape );
-  cursor.thickInsertShape = config.readBoolEntry(
-    "ThickInsertShape", cursor.thickInsertShape );
-  cursor.setFocusMode( config.readEntry("FocusMode") );
-  cursor.interval = config.readNumEntry(
-    "Interval", cursor.interval );
-
-  SDisplayMisc &misc = mDisplayState.misc;
-  config.setGroup( "Display Misc" );
-  misc.undoLevel = config.readNumEntry(
-    "UndoLevel", misc.undoLevel );
-  misc.setOpenFile( config.readEntry("OpenFile") );
-  misc.inputSound = config.readBoolEntry(
-    "InputSound", misc.inputSound );
-  misc.fatalSound = config.readBoolEntry(
-    "FatalSound", misc.fatalSound );
-  misc.autoCopyToClipboard = config.readBoolEntry(
-    "AutoCopyToClipboard", misc.autoCopyToClipboard );
-  misc.insertMode = config.readBoolEntry(
-    "InsertMode", misc.insertMode );
-  misc.writeProtect = config.readBoolEntry(
-    "WriteProtect", misc.writeProtect );
-  misc.confirmWrap = config.readBoolEntry(
-    "ConfirmWrap", misc.confirmWrap );
-  misc.cursorJump = config.readBoolEntry(
-    "CursorJump", misc.cursorJump );
-  misc.makeBackup = config.readBoolEntry(
-    "MakeBackup", misc.makeBackup );
-  misc.confirmThreshold = config.readBoolEntry(
-    "ConfirmThreshold", misc.confirmThreshold );
-  misc.thresholdValue = config.readNumEntry(
-    "ThresholdValue", misc.thresholdValue );
-  misc.discardRecent = config.readBoolEntry(
-    "DiscardRecent", misc.discardRecent );
-  misc.gotoOnStartup = config.readBoolEntry(
-    "GotoOnStartup", misc.gotoOnStartup );
-  misc.gotoOnReload = config.readBoolEntry(
-    "GotoOnReload", misc.gotoOnReload );
-  misc.bookmarkOffsetColumn = config.readBoolEntry(
-    "ShowBookmarkInOffsetColumn", misc.bookmarkOffsetColumn );
-  misc.bookmarkEditor = config.readBoolEntry(
-    "ShowBookmarkInEditor", misc.bookmarkEditor );
-}
-
-
-
-void CHexEditorWidget::resizeEvent( TQResizeEvent *e )
-{
-  mHexView->resize( e->size().width(), e->size().height() );
-}
-
-
-void CHexEditorWidget::fontChanged( void )
-{
-  if( mDisplayState.font.useSystemFont == true )
-  {
-    setFont( mDisplayState.font );
-  }
-}
-
-void CHexEditorWidget::paletteChanged( void )
-{
-  setColor( mDisplayState.color );
-}
-
-void CHexEditorWidget::layoutChanged( const SDisplayLayout &/*layout*/ )
-{
-  //mDisplayState.layout = layout;
-}
-
-void CHexEditorWidget::inputModeChanged( const SDisplayInputMode &input )
-{
-  mDisplayState.input = input;
-}
-
-
-void CHexEditorWidget::setLineSize(const SDisplayLine &line )
-{
-  mDisplayState.line = line;
-}
-
-void CHexEditorWidget::setLayout( const SDisplayLayout &layout )
-{
-  //
-  // We only set the values that can be modified by the dialog
-  //
-  mDisplayState.layout.lockLine = layout.lockLine;
-  mDisplayState.layout.lockColumn = layout.lockColumn;
-  mDisplayState.layout.leftSeparatorWidth = layout.leftSeparatorWidth;
-  mDisplayState.layout.rightSeparatorWidth = layout.rightSeparatorWidth;
-  mDisplayState.layout.separatorMarginWidth = layout.separatorMarginWidth;
-  mDisplayState.layout.edgeMarginWidth = layout.edgeMarginWidth;
-  mDisplayState.layout.columnCharSpace = layout.columnCharSpace;
-  mDisplayState.layout.columnSpacing = layout.columnSpacing;
-  mDisplayState.layout.horzGridWidth = layout.horzGridWidth;
-  mDisplayState.layout.vertGridWidth = layout.vertGridWidth;
-
-  //
-  // Select the line and column sizes we shall use now.
-  //
-  SDisplayLayout &l = mDisplayState.layout;
-  l.lineSize   = mDisplayState.line.lineSize[ l.primaryMode ];
-  l.columnSize = mDisplayState.line.columnSize[ l.primaryMode ];
-
-  mHexView->setLayout( mDisplayState.layout );
-}
-
-void CHexEditorWidget::setCursor( const SDisplayCursor &cursor )
-{
-  mDisplayState.cursor = cursor;
-  mHexView->setCursor( mDisplayState.cursor, true );
-}
-
-void CHexEditorWidget::setColor( const SDisplayColor &color )
-{
-  mDisplayState.color = color;
-
-  //
-  // The selection colors can not be chosen.
-  //
-  mDisplayState.color.selectBg = kapp->palette().active().highlight();
-  mDisplayState.color.selectFg = kapp->palette().active().highlightedText();
-
-  if( mDisplayState.color.useSystemColor == true )
-  {
-    SDisplayColor c = mDisplayState.color;
-    c.textBg           = kapp->palette().active().base();
-    c.secondTextBg     = kapp->palette().active().base();
-    c.offsetBg         = kapp->palette().active().base();
-    c.inactiveBg       = kapp->palette().active().base();
-    c.primaryFg[0]     = kapp->palette().active().text();
-    c.primaryFg[1]     = kapp->palette().active().text();
-    c.nonPrintFg       = kapp->palette().active().text();
-    c.offsetFg         = kapp->palette().active().text();
-    c.secondaryFg      = kapp->palette().active().text();
-    c.leftSeparatorFg  = kapp->palette().active().text();
-    c.rightSeparatorFg = kapp->palette().active().text();
-    c.cursorBg         = kapp->palette().active().text();
-    c.cursorFg         = kapp->palette().active().base();
-    c.gridFg           = kapp->palette().active().text();
-    SDisplayColor defaultColor;
-    c.bookmarkBg       = defaultColor.bookmarkBg;
-    c.bookmarkFg       = defaultColor.bookmarkFg;
-
-    mHexView->setColor( c, true );
-  }
-  else
-  {
-    mHexView->setColor( mDisplayState.color, true );
-  }
-}
-
-
-void CHexEditorWidget::setFont( const SDisplayFont &font )
-{
-  mDisplayState.font = font;
-
-  SDisplayFontInfo fontInfo;
-  if( mDisplayState.font.useSystemFont == true )
-  {
-    fontInfo.font = TDEGlobalSettings::fixedFont();
-  }
-  else
-  {
-    fontInfo.font = mDisplayState.font.localFont;
-  }
-  fontInfo.nonPrintChar = mDisplayState.font.nonPrintChar;
-  mHexView->setFont( fontInfo, true );
-}
-
-void CHexEditorWidget::setMisc( const SDisplayMisc &misc )
-{
-  mDisplayState.misc = misc;
-  mHexView->setMisc( mDisplayState.misc );
-}
-
-
-
-void CHexEditorWidget::setHexadecimalMode( void )
-{
-  layout().primaryMode   = SDisplayLayout::hexadecimal;
-  layout().lineSize      = line().lineSize[ SDisplayLine::hexadecimal ];
-  layout().columnSize    = line().columnSize[ SDisplayLine::hexadecimal ];
-  mHexView->setLayout( layout() );
-}
-
-
-void CHexEditorWidget::setDecimalMode( void )
-{
-  layout().primaryMode   = SDisplayLayout::decimal;
-  layout().lineSize      = line().lineSize[ SDisplayLine::decimal ];
-  layout().columnSize    = line().columnSize[ SDisplayLine::decimal ];
-  mHexView->setLayout( layout() );
-}
-
-
-void CHexEditorWidget::setOctalMode( void )
-{
-  layout().primaryMode   = SDisplayLayout::octal;
-  layout().lineSize      = line().lineSize[ SDisplayLine::octal ];
-  layout().columnSize    = line().columnSize[ SDisplayLine::octal ];
-  mHexView->setLayout( layout() );
-}
-
-
-void CHexEditorWidget::setBinaryMode( void )
-{
-  layout().primaryMode   = SDisplayLayout::binary;
-  layout().lineSize      = line().lineSize[ SDisplayLine::binary ];
-  layout().columnSize    = line().columnSize[ SDisplayLine::binary ];
-  mHexView->setLayout( layout() );
-}
-
-
-void CHexEditorWidget::setTextMode( void )
-{
-  layout().primaryMode   = SDisplayLayout::textOnly;
-  layout().lineSize      = line().lineSize[ SDisplayLine::textOnly ];
-  layout().columnSize    = line().columnSize[ SDisplayLine::textOnly ];
-  mHexView->setLayout( layout() );
-}
-
-
-
-void CHexEditorWidget::saveWorkingDirectory( const TQString &url )
-{
-  if( url.isEmpty() == true )
-  {
-    return;
-  }
-
-  int index = url.findRev( '/' );
-  if( index != -1 )
-  {
-    mWorkDir = url.left( index+1 );
-  }
-}
-
-
-
-void CHexEditorWidget::newFile( void )
-{
-  if( busy( true ) == true )
-  {
-    return;
-  }
-
-  TQString url = i18n("Untitled %1").arg( mUntitledCount );
-
-  //
-  // If the url is already present in the document list (should not happen),
-  // then this document is "raised".
-  //
-  bool success = selectDocument( url, false );
-  if( success == true )
-  {
-    return;
-  }
-
-  //
-  // Prepare a new buffer we can load the document into
-  //
-  success = createBuffer();
-  if( success == false )
-  {
-    return;
-  }
-
-  int errCode = mHexView->newFile( url );
-  if( errCode != Err_Success )
-  {
-    TQString msg = i18n("Unable to create new document.");
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Operation Failed") );
-    return;
-  }
-
-  mUntitledCount += 1;
-}
-
-
-
-
-void CHexEditorWidget::newFile( const TQByteArray &data )
-{
-  newFile();
-  mHexView->append( data );
-}
-
-
-
-
-void CHexEditorWidget::open()
-{
-  KURL file = KFileDialog::getOpenURL( mWorkDir, "*" ,topLevelWidget() );
-
-  if( file.isEmpty() )
-    return;
-
-  TQString url = file.url();
-
-  saveWorkingDirectory( url );
-
-  if( busy( true ) )
-    return;
-
-  //
-  // If the url is already present in the document list, then this
-  // document is "raised".
-  //
-  if( selectDocument( url, true ) )
-    return;
-
-  //
-  // Prepare a new buffer we can load the document into
-  //
-  if( !createBuffer() )
-    return;
-
-  int errCode = readURL( file, false );
-  if( errCode != Err_Success )
-  {
-    emit errorLoadFile( url );
-    removeBuffer();
-  }
-  else if( errCode == Err_Success )
-  {
-    defaultWriteProtection();
-  }
-}
-
-
-
-void CHexEditorWidget::open( const TQString &url, bool reloadWhenChanged,
-			     uint offset )
-{
-  if( busy( true ) == true )
-  {
-    return;
-  }
-
-  //
-  // If the url is already present in the document list, then this
-  // document is "raised".
-  //
-  bool success = selectDocument( url, reloadWhenChanged );
-  if( success == true )
-  {
-    return;
-  }
-
-  //
-  // Prepare a new buffer we can load the document into
-  //
-  success = createBuffer();
-  if( success == false )
-  {
-    return;
-  }
-
-  int errCode = readURL( url, false );
-  if( errCode != Err_Success )
-  {
-    emit errorLoadFile( url );
-    removeBuffer();
-  }
-  else if( errCode == Err_Success )
-  {
-    mHexView->gotoOffset( offset );
-    defaultWriteProtection();
-  }
-}
-
-
-void CHexEditorWidget::stepFile( bool next )
-{
-  //
-  // The buffer list is is reverse when compared with the visible
-  // document list in the menu so I toggle the flag.
-  //
-  next = next == true ? false : true;
-
-  CHexBuffer *hexBuffer = documentItem( mHexView->url(), next );
-  if( hexBuffer == 0 )
-  {
-    return;
-  }
-
-  mHexView->setBuffer( hexBuffer );
-}
-
-
-
-
-
-bool CHexEditorWidget::isOpen( const TQString &url, uint &offset )
-{
-  CHexBuffer *hexBuffer = documentItem( url );
-  if( hexBuffer == 0 )
-  {
-    return( false );
-  }
-  offset = hexBuffer->cursorOffset();
-  return( true );
-}
-
-
-bool CHexEditorWidget::selectDocument( const TQString &url,
-				       bool reloadWhenChanged )
-{
-  CHexBuffer *hexBuffer = documentItem( url );
-  if( hexBuffer == 0 )
-  {
-    return( false );
-  }
-
-  mHexView->setBuffer( hexBuffer );
-
-  if( reloadWhenChanged == true && mHexView->urlValid() == true )
-  {
-    if( modifiedByAlien( mHexView->url() ) == true )
-    {
-      reload();
-    }
-  }
-
-  return( true );
-}
-
-
-void CHexEditorWidget::insertFile( void )
-{
-  KFileDialog fdlg(mWorkDir, TQString(), topLevelWidget(), 0, TRUE);
-  fdlg.setOperationMode( KFileDialog::Opening );
-  fdlg.okButton()->setGuiItem( KStdGuiItem::insert() );
-  fdlg.setCaption(i18n("Insert File"));
-
-  if (!fdlg.exec()) return;
-  KURL file = fdlg.selectedURL();
-
-  if( file.isEmpty() )
-    return;
-
-  if( !file.isLocalFile() )
-  {
-    KMessageBox::sorry( this, i18n( "Only local files are currently supported." ) );
-    return;
-  }
-
-  TQString url = file.path();
-
-  saveWorkingDirectory( url );
-
-  if( busy( true ) )
-    return;
-
-  readURL( url, true );
-}
-
-
-
-void CHexEditorWidget::stop( void )
-{
-  mProgressStop = mProgressBusy;
-}
-
-
-bool CHexEditorWidget::close( void )
-{
-  if( busy( true ) == true )
-  {
-    return( false );
-  }
-
-  if( querySave() == false )
-  {
-    return( false );
-  }
-
-  removeBuffer();
-  return( true );
-}
-
-
-
-
-bool CHexEditorWidget::closeAll( void )
-{
-  if( busy( true ) == true )
-  {
-    return( false );
-  }
-
-  while( mDocumentList.count() > 0 )
-  {
-    CHexBuffer *buf;
-    for( buf = mDocumentList.first(); buf != 0; buf = mDocumentList.next() )
-    {
-      //
-      // We select the buffer we are about to close because it will
-      // the become visible, and because 'close()' works on the current
-      // buffer.
-      //
-      mHexView->setBuffer( buf );
-      if( close() == false )
-      {
-	return( false );
-      }
-    }
-
-    //
-    // The document list will always contain at least one element because
-    // the hexview widget needs a hexbuffer to work. If this hexbuffer is
-    // not valid, then all files have been closed.
-    //
-    if( mDocumentList.count() == 1 && mHexView->documentPresent() == false )
-    {
-      break;
-    }
-  }
-
-  return( true );
-}
-
-
-
-bool CHexEditorWidget::querySave( void )
-{
-  if( mHexView->modified() == false )
-  {
-    return( true );
-  }
-
-  TQString msg = i18n(""
-    "The current document has been modified.\n"
-    "Do you want to save it?" );
-  int reply = KMessageBox::warningYesNoCancel( topLevelWidget(), msg, TQString(), KStdGuiItem::save(), KStdGuiItem::discard() );
-  if( reply == KMessageBox::Yes )
-  {
-    return( save() );
-  }
-  else if( reply == KMessageBox::No )
-  {
-    return( true );
-  }
-  else
-  {
-    return( false );
-  }
-}
-
-
-bool CHexEditorWidget::backup( void )
-{
-  if( mHexView->documentPresent() == false || mHexView->urlValid() == false )
-  {
-    return( false );
-  }
-
-  KURL kurl( mHexView->url() );
-  if( kurl.isLocalFile() == false )
-  {
-    return( false );
-  }
-
-  const TQString currentName = kurl.path();
-  TQString backupName = currentName + '~';
-
-  int errCode = rename( currentName.latin1(), backupName.latin1() );
-  if( errCode != 0 )
-  {
-    return( false );
-  }
-
-
-  return( true );
-}
-
-
-
-//
-// Returns false if operation was canceled
-//
-bool CHexEditorWidget::save( void )
-{
-  if( mHexView->documentPresent() == false )
-  {
-    return( true );
-  }
-
-  if( mHexView->urlValid() == false )
-  {
-    return( saveAs() );
-  }
-  else
-  {
-    if( modifiedByAlien( mHexView->url() ) == true )
-    {
-      TQString msg = i18n(""
-       "Current document has been changed on disk.\n"
-       "If you save now, those changes will be lost.\n"
-       "Proceed?" );
-      int reply = KMessageBox::warningYesNoCancel( topLevelWidget(), msg,
-						   i18n("Save"), KStdGuiItem::save(), KStdGuiItem::discard() );
-      if( reply == KMessageBox::No || reply == KMessageBox::Cancel )
-      {
-	return( reply == KMessageBox::No ? true : false );
-      }
-    }
-
-    if( mDisplayState.misc.makeBackup == true )
-    {
-      backup();
-    }
-    writeURL( mHexView->url() );
-  }
-
-  return( true );
-}
-
-
-//
-// Returns false if operation was canceled
-//
-bool CHexEditorWidget::saveAs( void )
-{
-  if( mHexView->documentPresent() == false )
-  {
-    return( true );
-  }
-
-  KURL url;
-  while( 1 )
-  {
-    url = KFileDialog::getSaveURL( mHexView->url(), "*", this );
-    if( url.isEmpty() == true )
-    {
-      return( false );
-    }
-    else
-    {
-      saveWorkingDirectory( url.url() );
-    }
-
-    if( url.isLocalFile() )
-    {
-      TQString name( url.path() );
-      TQFileInfo info( name );
-
-      if( info.exists() )
-      {
-	TQString msg = i18n(""
-          "A document with this name already exists.\n"
-          "Do you want to overwrite it?" );
-	int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg,
-					       i18n("Save As"), i18n("Overwrite") );
-	if( reply == KMessageBox::Continue )
-	  break;
-      }
-      else
-	break;
-    }
-  }
-
-  TQString symbolicName( url.url() );
-//  KURL::decode( symbolicName );
-
-  mHexView->setUrl( symbolicName );
-  writeURL( mHexView->url() );
-  return( true );
-}
-
-
-
-void CHexEditorWidget::reload( void )
-{
-  if( mHexView->documentPresent() == false )
-  {
-    return;
-  }
-
-  if( busy( true ) == true )
-  {
-    return;
-  }
-
-  if( mHexView->urlValid() == false )
-  {
-    TQString msg = i18n( "The current document does not exist on the disk." );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Reload") );
-    return;
-  }
-
-  if( mHexView->modified() == true )
-  {
-    TQString msg;
-    if( modifiedByAlien( mHexView->url() ) == true )
-    {
-      msg = i18n( "The current document has changed on the disk and "
-                  "also contains unsaved modifications.\n"
-                  "If you reload now, the modifications will be lost." );
-    }
-    else
-    {
-      msg = i18n( "The current document contains unsaved modifications.\n"
-                   "If you reload now, the modifications will be lost." );
-    }
-
-    int reply = KMessageBox::warningContinueCancel(topLevelWidget(),msg,i18n("Reload"), i18n("&Reload"));
-    if( reply != KMessageBox::Continue )
-    {
-      return;
-    }
-  }
-
-  TQString url( mHexView->url() );
-  uint offset = mHexView->offset();
-
-  //mHexView->closeFile();
-  int errCode = readURL( url, false );
-  if( errCode == Err_Success && gotoReloadOffset() == true )
-  {
-    mHexView->gotoOffset( offset );
-  }
-
-}
-
-
-void CHexEditorWidget::print( void )
-{
-  CHexPrinter prt;
-
-  prt.addDialogPage( new LayoutDialogPage() );
-
-  prt.setPageSelection( KPrinter::SystemSide );
-  prt.setFullPage( true ); // I use my own marings
-
-  // FIXME: Make a better header for the printingdialog
-  if (prt.setup(topLevelWidget(), i18n("Print Hex-Document")))
-  {
-     prt.setTopMarginMM( prt.option("kde-khexedit-topmarginmm").toInt() );
-     prt.setBottomMarginMM( prt.option("kde-khexedit-bottommarginmm").toInt() );
-     prt.setLeftMarginMM( prt.option("kde-khexedit-leftmarginmm").toInt() );
-     prt.setRightMarginMM( prt.option("kde-khexedit-rightmarginmm").toInt() );
-
-     prt.setPageHeader( (prt.option("kde-khexedit-headercheck") == "true"),
-			  prt.option("kde-khexedit-headercombo0").toInt(),
-			  prt.option("kde-khexedit-headercombo1").toInt(),
-			  prt.option("kde-khexedit-headercombo2").toInt(),
-			  prt.option("kde-khexedit-headercombo3").toInt() );
-
-     prt.setPageFooter( (prt.option("kde-khexedit-footercheck") == "true"),
-			  prt.option("kde-khexedit-footercombo0").toInt(),
-			  prt.option("kde-khexedit-footercombo1").toInt(),
-			  prt.option("kde-khexedit-footercombo2").toInt(),
-			  prt.option("kde-khexedit-footercombo3").toInt() );
-
-     printPostscript(prt);
-  }
-
-}
-
-
-
-
-void CHexEditorWidget::printPostscript( CHexPrinter &printer )
-{
-  if( confirmPrintPageNumber( printer ) == false )
-  {
-    return;
-  }
-
-  //
-  // No i18n() on this one!
-  // Constants come from config.h
-  //
-  TQString creator( PACKAGE );
-  creator += " ";
-  creator += VERSION;
-
-  printer.setCreator( creator );
-
-  int errCode = prepareProgressData( pg_print );
-  if( errCode == Err_Success )
-  {
-    errCode = mHexView->print( printer, mProgressData );
-  }
-
-  TQString msg = i18n("Could not print data.\n");
-  msg += hexError( errCode );
-
-  if( errCode != Err_Success )
-  {
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Print") );
-  }
-}
-
-
-bool CHexEditorWidget::confirmPrintPageNumber( CHexPrinter &printer )
-{
-  if( mDisplayState.misc.confirmThreshold == true )
-  {
-    uint numPage = mHexView->numPage( printer );
-    printer.setMinMax( 1, numPage );
-    uint numPageSelected = printer.pageList().count();
-
-    if( numPageSelected > mDisplayState.misc.thresholdValue )
-    {
-      TQString msg = i18n(
-        "<qt>Print threshold exceeded.<br>"
-        "You are about to print one page.<br>"
-	"Proceed?</qt>",
-        "<qt>Print threshold exceeded.<br>"
-        "You are about to print %n pages.<br>"
-	"Proceed?</qt>",
-	numPageSelected );
-      int reply = KMessageBox::warningYesNo( topLevelWidget(), msg,
-					     i18n("Print"), KStdGuiItem::print(), KStdGuiItem::cancel() );
-      if( reply != KMessageBox::Continue )
-      {
-	return( false );
-      }
-    }
-  }
-
-  return( true );
-}
-
-
-void CHexEditorWidget::exportDialog( void )
-{
-  if( mExportDialog == 0 )
-  {
-    mExportDialog = new CExportDialog( topLevelWidget(), 0, false );
-    if( mExportDialog == 0 ) { return; }
-    connect( mExportDialog, TQT_SIGNAL( exportText(const SExportText &)),
-	     this, TQT_SLOT( exportText( const SExportText &)) );
-    connect( mExportDialog, TQT_SIGNAL( exportHtml(const SExportHtml &)),
-	     this, TQT_SLOT( exportHtml( const SExportHtml &)) );
-    connect( mExportDialog, TQT_SIGNAL( exportCArray(const SExportCArray &)),
-	     this, TQT_SLOT( exportCArray( const SExportCArray &)) );
-  }
-  mExportDialog->show();
-}
-
-
-
-void CHexEditorWidget::exportText( const SExportText &ex )
-{
-  int errCode = prepareProgressData( pg_export );
-  if( errCode == Err_Success )
-  {
-    errCode = mHexView->exportText( ex, mProgressData );
-  }
-
-  if( errCode != Err_Success )
-  {
-    TQString msg = i18n("Unable to export data.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Export") );
-  }
-}
-
-
-void CHexEditorWidget::exportHtml( const SExportHtml &ex )
-{
-  int errCode = prepareProgressData( pg_export );
-  if( errCode == Err_Success )
-  {
-    errCode = mHexView->exportHtml( ex, mProgressData );
-  }
-
-  if( errCode != Err_Success )
-  {
-    TQString msg = i18n("Unable to export data.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Export") );
-  }
-}
-
-
-void CHexEditorWidget::exportCArray( const SExportCArray &ex )
-{
-  int errCode = prepareProgressData( pg_export );
-  if( errCode == Err_Success )
-  {
-    errCode = mHexView->exportCArray( ex, mProgressData );
-  }
-
-  if( errCode != Err_Success )
-  {
-    TQString msg = i18n("Unable to export data.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Export") );
-  }
-}
-
-
-void CHexEditorWidget::encode( CConversion::EMode mode )
-{
-  if( mHexView->losslessEncoding( mode ) == false )
-  {
-    TQString msg = i18n(""
-      "The encoding you have selected is not reversible.\n"
-      "If you revert to the original encoding later, there is no "
-      "guarantee that the data can be restored to the original state.");
-    int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg,
-					   i18n("Encode"), i18n("&Encode"));
-    if( reply != KMessageBox::Continue )
-    {
-      // Restore correct menu setting
-      mHexView->reportEncoding();
-      return;
-    }
-  }
-
-  int errCode = prepareProgressData( pg_encode );
-  if( errCode == Err_Success )
-  {
-    errCode = mHexView->setEncoding( mode, mProgressData );
-  }
-
-  if( errCode != Err_Success )
-  {
-    TQString msg = i18n("Could not encode data.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Encode") );
-  }
-}
-
-void CHexEditorWidget::undo( void )
-{
-  mHexView->undo();
-}
-
-void CHexEditorWidget::redo( void )
-{
-  mHexView->redo();
-}
-
-void CHexEditorWidget::toggleWriteProtection( void )
-{
-  mDisplayState.input.readOnly = mDisplayState.input.readOnly == true ?
-    false : true;
-  mHexView->setInputMode( mDisplayState.input );
-}
-
-void CHexEditorWidget::defaultWriteProtection( void )
-{
-  mDisplayState.input.readOnly = mDisplayState.misc.writeProtect;
-  mHexView->setInputMode( mDisplayState.input );
-}
-
-void CHexEditorWidget::toggleResizeLock( void )
-{
-  mDisplayState.input.allowResize = mDisplayState.input.allowResize == true ?
-    false : true;
-  mHexView->setInputMode( mDisplayState.input );
-}
-
-void CHexEditorWidget::setResizeLock( bool state )
-{
-  mDisplayState.input.allowResize = state;
-  mHexView->setInputMode( mDisplayState.input );
-}
-
-void CHexEditorWidget::enableInputLock( bool inputLock )
-{
-  mDisplayState.input.inputLock = inputLock;
-  mHexView->setInputMode( mDisplayState.input );
-}
-
-void CHexEditorWidget::toggleOffsetColumnVisibility( void )
-{
-  layout().offsetVisible = layout().offsetVisible == true ? false : true;
-  mHexView->setLayout( layout() );
-}
-
-void CHexEditorWidget::toggleTextColumnVisibility( void )
-{
-  layout().secondaryMode = layout().secondaryMode == SDisplayLayout::hide ?
-    SDisplayLayout::textOnly : SDisplayLayout::hide;
-  mHexView->setLayout( layout() );
-}
-
-void CHexEditorWidget::toggleOffsetAsDecimal( void )
-{
-  layout().offsetMode = layout().offsetMode == SDisplayLayout::hexadecimal ?
-    SDisplayLayout::decimal : SDisplayLayout::hexadecimal;
-  mHexView->setLayout( layout() );
-}
-
-void CHexEditorWidget::toggleDataUppercase( void )
-{
-  layout().primaryUpperCase = layout().primaryUpperCase == true ? false : true;
-  mHexView->setLayout( layout() );
-}
-
-void CHexEditorWidget::toggleOffsetUppercase( void )
-{
-  layout().offsetUpperCase = layout().offsetUpperCase == true ? false : true;
-  mHexView->setLayout( layout() );
-}
-
-void CHexEditorWidget::toggleInsertMode( void )
-{
-  mHexView->setInsertMode( !mHexView->insertMode() );
-}
-
-void CHexEditorWidget::benchmark( void )
-{
-  mHexView->benchmark();
-}
-
-void CHexEditorWidget::copy( void )
-{
-  mHexView->copy();
-}
-
-void CHexEditorWidget::copyText( void )
-{
-  mHexView->copyText();
-}
-
-void CHexEditorWidget::paste( void )
-{
-  if( mHexView->documentPresent() == false )
-  {
-    pasteNewFile();
-  }
-  else
-  {
-    mHexView->paste();
-  }
-}
-
-void CHexEditorWidget::pasteNewFile( void )
-{
-  newFile();
-  mHexView->paste();
-}
-
-void CHexEditorWidget::cut( void )
-{
-  mHexView->cut();
-}
-
-void CHexEditorWidget::selectAll( void )
-{
-  mHexView->selectAll();
-}
-
-void CHexEditorWidget::unselect( void )
-{
-  mHexView->unselect();
-}
-
-
-void CHexEditorWidget::addBookmark( void )
-{
-  mHexView->addBookmark( -1 );
-}
-
-
-void CHexEditorWidget::removeBookmark( void )
-{
-  if( mHexView->bookmarkCount() > 0 )
-  {
-    mHexView->removeBookmark( false );
-  }
-}
-
-
-void CHexEditorWidget::removeAllBookmark( void )
-{
-  if( mHexView->bookmarkCount() > 0 )
-  {
-    TQString msg = i18n(""
-      "Deleted bookmarks can not be restored.\n"
-      "Proceed?" );
-    int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg );
-    if( reply != KMessageBox::Continue )
-    {
-      return;
-    }
-    mHexView->removeBookmark( true );
-  }
-}
-
-
-void CHexEditorWidget::replaceBookmark( void )
-{
-  mHexView->replaceBookmark();
-}
-
-
-void CHexEditorWidget::gotoBookmark( int position )
-{
-  mHexView->gotoBookmark( (uint)position );
-}
-
-void CHexEditorWidget::gotoNextBookmark( void )
-{
-  mHexView->gotoNextBookmark(true);
-}
-
-void CHexEditorWidget::gotoPrevBookmark( void )
-{
-  mHexView->gotoNextBookmark(false);
-}
-
-void CHexEditorWidget::gotoOffset( void )
-{
-  if( mGotoDialog == 0 )
-  {
-    mGotoDialog = new CGotoDialog( topLevelWidget(), 0, false );
-    if( mGotoDialog == 0 ) { return; }
-    connect( mGotoDialog, TQT_SIGNAL(gotoOffset( uint, uint, bool, bool )),
-	     mHexView, TQT_SLOT(gotoOffset( uint, uint, bool, bool )) );
-  }
-  mGotoDialog->show();
-}
-
-
-void CHexEditorWidget::find( void )
-{
-  if( mFindNavigatorDialog != 0 )
-  {
-    mFindNavigatorDialog->hide();
-  }
-
-  if( mFindDialog == 0 )
-  {
-    mFindDialog = new CFindDialog( topLevelWidget(), 0, false );
-    if( mFindDialog == 0 ) { return; }
-    connect( mFindDialog,
-	     TQT_SIGNAL(findData(SSearchControl &, uint, bool)),
-	     TQT_SLOT(findData(SSearchControl &, uint, bool)) );
-  }
-  mFindDialog->show();
-}
-
-
-
-void CHexEditorWidget::findData( SSearchControl &sc, uint mode, bool navigator)
-{
-  for( uint i=0; i < 2; i++ )
-  {
-    int errCode;
-    if( mode == Find_First )
-    {
-      errCode = mHexView->findFirst( sc );
-      if( errCode == Err_Success )
-      {
-	if( navigator == true )
-	{
-	  findNavigator( sc );
-	}
-	return;
-      }
-    }
-    else if( mode == Find_Next )
-    {
-      errCode = mHexView->findNext( sc );
-      if( errCode == Err_Success )
-      {
-	if( navigator == true )
-	{
-	  findNavigator( sc );
-	}
-	return;
-      }
-    }
-    else
-    {
-      return;
-    }
-
-    if( errCode == Err_WrapBuffer && i == 0 )
-    {
-      bool reply = askWrap( sc.forward, i18n("Find") );
-      if( reply == false )
-      {
-	return;
-      }
-
-      sc.fromCursor = false;
-      mode = Find_First;
-    }
-  }
-
-  if( mode == Find_First )
-  {
-    TQString msg = i18n( "Search key not found in document." );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Find") );
-  }
-}
-
-
-
-void CHexEditorWidget::findAgain( void )
-{
-  if( canFind( true ) == true )
-  {
-    mFindDialog->findAgain( CFindDialog::find_Again );
-  }
-}
-
-
-void CHexEditorWidget::findNext( void )
-{
-  if( canFind( true ) == true )
-  {
-    mFindDialog->findAgain( CFindDialog::find_Next );
-  }
-}
-
-
-void CHexEditorWidget::findPrevious( void )
-{
-  if( canFind( true ) == true )
-  {
-    mFindDialog->findAgain( CFindDialog::find_Previous );
-  }
-}
-
-
-bool CHexEditorWidget::askWrap( bool fwd, const TQString &header )
-{
-  if( mDisplayState.misc.confirmWrap == false )
-  {
-    return( true ); // Never ask the user
-  }
-
-  TQString msg;
-  if( fwd == true )
-  {
-    msg += i18n(""
-      "End of document reached.\n"
-      "Continue from the beginning?" );
-  }
-  else
-  {
-    msg += i18n(""
-      "Beginning of document reached.\n"
-      "Continue from the end?" );
-  }
-
-  int reply = KMessageBox::questionYesNo( topLevelWidget(), msg, header, KStdGuiItem::cont(), KStdGuiItem::cancel() );
-  return( reply == KMessageBox::Yes ? true : false );
-}
-
-
-bool CHexEditorWidget::canFind( bool showError )
-{
-  if( mFindDialog == 0 || mFindDialog->isEmpty() == true )
-  {
-    if( showError == true )
-    {
-      TQString msg = i18n(""
-        "Your request can not be processed.\n"
-        "No search pattern defined." );
-      KMessageBox::sorry( topLevelWidget(), msg, i18n("Find") );
-    }
-    return( false );
-  }
-
-  return( true );
-}
-
-
-
-void CHexEditorWidget::findNavigator( SSearchControl &sc )
-{
-  if( canFind( false ) == false )
-  {
-    return;
-  }
-
-  if( mFindNavigatorDialog == 0 )
-  {
-    mFindNavigatorDialog = new CFindNavigatorDialog(topLevelWidget(),0,false);
-    if( mFindNavigatorDialog == 0 ) { return; }
-    connect( mFindNavigatorDialog,
-	     TQT_SIGNAL(findData(SSearchControl &, uint, bool)),
-	     TQT_SLOT(findData(SSearchControl &, uint, bool)) );
-    connect( mFindNavigatorDialog, TQT_SIGNAL(makeKey(void)),
-	     TQT_SLOT(find()) );
-  }
-  if( mFindNavigatorDialog->isVisible() == false )
-  {
-    mFindNavigatorDialog->defineData( sc );
-  }
-  mFindNavigatorDialog->show();
-}
-
-
-
-void CHexEditorWidget::replace( void )
-{
-  hideReplacePrompt();
-
-  if( mReplaceDialog == 0 )
-  {
-    mReplaceDialog = new CReplaceDialog( topLevelWidget(), 0, false );
-    if( mReplaceDialog == 0 ) { return; }
-    connect( mReplaceDialog,
-	     TQT_SIGNAL( replaceData( SSearchControl &, uint)),
-	     TQT_SLOT( replaceData( SSearchControl &, uint)));
-  }
-  mReplaceDialog->show();
-}
-
-
-
-void CHexEditorWidget::replaceData( SSearchControl &sc, uint mode )
-{
-  while( 1 )
-  {
-    if( mode == Replace_All || mode == Replace_AllInit )
-    {
-      mHexView->replaceAll( sc, mode == Replace_AllInit ? true : false );
-    }
-    else if( mode == Replace_First )
-    {
-      int errCode = mHexView->findFirst( sc );
-      if( errCode == Err_Success )
-      {
-	replacePrompt( sc );
-	return;
-      }
-    }
-    else if( mode == Replace_Next )
-    {
-      int errCode = mHexView->replaceMarked( sc );
-      if( errCode != Err_Success )
-      {
-	// Perhaps a notification here ?
-      }
-      errCode = mHexView->findNext( sc );
-      if( errCode == Err_Success )
-      {
-	replacePrompt( sc );
-	return;
-      }
-    }
-    else if( mode == Replace_Ignore )
-    {
-      int errCode = mHexView->findNext( sc );
-      if( errCode == Err_Success )
-      {
-	replacePrompt( sc );
-	return;
-      }
-    }
-    else
-    {
-      break;
-    }
-
-    if( sc.wrapValid == false )
-    {
-      break;
-    }
-
-    bool reply = askWrap( sc.forward, i18n("Find and Replace") );
-    if( reply == false )
-    {
-      break;
-    }
-
-    int errCode = mHexView->findWrap( sc );
-    if( errCode != Err_Success )
-    {
-      break;
-    }
-
-    if( mode == Replace_All || mode == Replace_AllInit )
-    {
-      mode = Replace_All;
-      continue;
-    }
-
-    replacePrompt( sc );
-    return;
-  }
-
-  replaceResult( sc );
-}
-
-void CHexEditorWidget::replacePrompt( SSearchControl &sc )
-{
-  if( mReplacePromptDialog == 0 )
-  {
-    mReplacePromptDialog = new CReplacePromptDialog(topLevelWidget(), 0,false);
-    if( mReplacePromptDialog == 0 ) { return; }
-    connect( mReplacePromptDialog,
-	     TQT_SIGNAL( replaceData( SSearchControl &, uint)),
-	     TQT_SLOT( replaceData( SSearchControl &, uint)));
-  }
-  if( mReplacePromptDialog->isVisible() == false )
-  {
-    mReplacePromptDialog->defineData( sc );
-  }
-  mReplacePromptDialog->show();
-}
-
-
-void CHexEditorWidget::hideReplacePrompt( void )
-{
-  if( mReplacePromptDialog != 0 )
-  {
-    mReplacePromptDialog->hide();
-  }
-}
-
-
-
-void CHexEditorWidget::replaceResult( SSearchControl &sc )
-{
-  hideReplacePrompt();
-
-  if( sc.match == false )
-  {
-    TQString msg;
-    if( sc.inSelection == true )
-    {
-      msg += i18n( "Search key not found in selected area." );
-    }
-    else
-    {
-      msg += i18n( "Search key not found in document." );
-    }
-    KMessageBox::information( topLevelWidget(), msg, i18n("Find & Replace"));
-  }
-  else
-  {
-    const TQString msg = i18n(
-      "<qt>Operation complete.<br><br>One replacement was made.</qt>",
-      "<qt>Operation complete.<br><br>%n replacements were made.</qt>", sc.numReplace );
-    KMessageBox::information( topLevelWidget(), msg, i18n("Find & Replace"));
-  }
-}
-
-
-void CHexEditorWidget::insertPattern( void )
-{
-  if( mInsertDialog == 0 )
-  {
-    mInsertDialog = new CInsertDialog( topLevelWidget(), 0, false );
-    if( mInsertDialog == 0 ) { return; }
-    connect( mInsertDialog, TQT_SIGNAL(execute( SInsertData & )),
-	     mHexView, TQT_SLOT(insert( SInsertData & )) );
-  }
-  mInsertDialog->show();
-}
-
-
-void CHexEditorWidget::encoding( void )
-{
-  TQString msg = i18n(""
-    "Not available yet!\n"
-    "Define your own encoding" );
-  KMessageBox::sorry( topLevelWidget(), msg, i18n("Encoding") );
-}
-
-
-void CHexEditorWidget::strings( void )
-{
-  if( mStringDialog == 0 )
-  {
-    mStringDialog = new CStringDialog( topLevelWidget(), 0, false );
-    if( mStringDialog == 0 ) { return; }
-    connect( mStringDialog, TQT_SIGNAL(markText( uint, uint, bool )),
-	     mHexView, TQT_SLOT(setMark( uint, uint, bool )) );
-    connect( mStringDialog, TQT_SIGNAL(collect()), TQT_SLOT(collectStrings()) );
-    connect( mHexView, TQT_SIGNAL(fileName( const TQString &, bool ) ),
-	     mStringDialog, TQT_SLOT( removeList() ) );
-    connect( mHexView, TQT_SIGNAL(dataChanged()),
-	     mStringDialog, TQT_SLOT(setDirty()) );
-  }
-  mStringDialog->show();
-}
-
-
-void CHexEditorWidget::collectStrings( void )
-{
-  int errCode = prepareProgressData( pg_strings );
-  if( errCode == Err_Success )
-  {
-    mHexView->collectStrings( mStringDialog->stringData() );
-    errCode = mStringDialog->updateList( mProgressData );
-  }
-
-  if( errCode != Err_Success && errCode != Err_Stop )
-  {
-    TQString msg = i18n("Could not collect strings.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Collect Strings") );
-  }
-
-}
-
-
-
-void CHexEditorWidget::recordView( void )
-{
-  TQString msg = i18n(""
-   "Not available yet!\n"
-   "Define a record (structure) and fill it with data from the document." );
-  KMessageBox::sorry( topLevelWidget(), msg, i18n("Record Viewer") );
-}
-
-void CHexEditorWidget::filter( void )
-{
-  if( mFilterDialog == 0 )
-  {
-    mFilterDialog = new CFilterDialog( topLevelWidget(), 0, false );
-    if( mFilterDialog == 0 ) { return; }
-    connect( mFilterDialog, TQT_SIGNAL(filterData( SFilterControl & )),
-	     mHexView, TQT_SLOT(filter( SFilterControl & )) );
-  }
-  mFilterDialog->show();
-}
-
-
-void CHexEditorWidget::chart( void )
-{
-  if( mCharTableDialog == 0 )
-  {
-    mCharTableDialog = new CCharTableDialog( topLevelWidget(), 0, false );
-    if( mCharTableDialog == 0 ) { return; }
-    connect( mCharTableDialog, TQT_SIGNAL(assign( const TQByteArray & )),
-	     mHexView, TQT_SLOT(insert( const TQByteArray & )) );
-  }
-  mCharTableDialog->show();
-}
-
-
-void CHexEditorWidget::converter( void )
-{
-  if( mConverterDialog == 0 )
-  {
-    mConverterDialog = new CConverterDialog( this, "converter", false );
-    connect( mConverterDialog, TQT_SIGNAL(probeCursorValue(TQByteArray &, uint)),
-	     mHexView, TQT_SLOT(valueOnCursor(TQByteArray &, uint)) );
-  }
-  mConverterDialog->show();
-}
-
-
-void CHexEditorWidget::statistics( void )
-{
-  if( mFileInfoDialog == 0 )
-  {
-    mFileInfoDialog = new CFileInfoDialog( topLevelWidget(), 0, false );
-    if( mFileInfoDialog == 0 ) { return; }
-    connect( mFileInfoDialog, TQT_SIGNAL(collectStatistic(SStatisticControl &)),
-	     TQT_SLOT(collectStatistics(SStatisticControl &)));
-    connect( mHexView, TQT_SIGNAL(dataChanged()),
-	     mFileInfoDialog, TQT_SLOT(setDirty()) );
-  }
-  mFileInfoDialog->show();
-}
-
-
-void CHexEditorWidget::collectStatistics( SStatisticControl &sc )
-{
-  int errCode = prepareProgressData( pg_statistic );
-  if( errCode == Err_Success )
-  {
-    errCode = mHexView->collectStatistic( sc, mProgressData );
-    if( errCode == Err_Success )
-    {
-      mFileInfoDialog->setStatistics( sc );
-    }
-  }
-
-  if( errCode != Err_Success && errCode != Err_Stop )
-  {
-    mFileInfoDialog->setStatistics(); // Default values
-
-    TQString msg = i18n("Could not collect document statistics.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg,
-			i18n("Collect Document Statistics") );
-  }
-
-}
-
-
-void CHexEditorWidget::options( void )
-{
-  if( mOptionDialog == 0 )
-  {
-    mOptionDialog = new COptionDialog( topLevelWidget(), 0, false );
-    if( mOptionDialog == 0 ) { return; }
-
-    connect( mOptionDialog, TQT_SIGNAL(lineSizeChoice(const SDisplayLine &)),
-	     TQT_SLOT(setLineSize(const SDisplayLine &)) );
-    connect( mOptionDialog, TQT_SIGNAL(layoutChoice(const SDisplayLayout &)),
-	     TQT_SLOT(setLayout(const SDisplayLayout &)) );
-    connect( mOptionDialog, TQT_SIGNAL(fontChoice(const SDisplayFont &)),
-	     TQT_SLOT(setFont(const SDisplayFont &)) );
-    connect( mOptionDialog, TQT_SIGNAL(colorChoice(const SDisplayColor &)),
-	     TQT_SLOT(setColor(const SDisplayColor &)) );
-    connect( mOptionDialog, TQT_SIGNAL(cursorChoice(const SDisplayCursor &)),
-	     TQT_SLOT(setCursor(const SDisplayCursor &)) );
-    connect( mOptionDialog, TQT_SIGNAL(miscChoice(const SDisplayMisc &)),
-	     TQT_SLOT(setMisc(const SDisplayMisc &)) );
-    connect( mOptionDialog, TQT_SIGNAL(removeRecentFiles()),
-	     TQT_SIGNAL(removeRecentFiles()) );
-  }
-  if( mOptionDialog->isVisible() == false )
-  {
-    mOptionDialog->setState( mDisplayState );
-  }
-  mOptionDialog->show();
-}
-
-
-
-void CHexEditorWidget::favorites( void )
-{
-  TQString msg = i18n(""
-    "Not available yet!\n"
-    "Save or retrive your favorite layout" );
-  KMessageBox::sorry( topLevelWidget(), msg, i18n("Profiles") );
-}
-
-
-int CHexEditorWidget::readURL( const KURL &url, bool insert )
-{
-  //
-  // 1) Make sure there is data in the url
-  //
-  if( url.isEmpty() )
-    return( Err_EmptyArgument );
-
-  //
-  // 2) Verify that the url is valid URL string. If not, try to repair it.
-  // This will work if the url contains a name of a file in the
-  // current directory.
-  //
-  if( !url.isValid() )
-  {
-    TQString msg = i18n("Malformed URL\n%1").arg( url.url() );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read URL") );
-    return( Err_IllegalArgument );
-  }
-
-  //
-  // 3) Load the file.
-  //
-  TQString tmpfile;
-  if ( !TDEIO::NetAccess::download( url, tmpfile, this ) )
-    return Err_ReadFailed;
-
-  bool success = readFile( tmpfile, url.url(), insert );
-
-  TDEIO::NetAccess::removeTempFile( tmpfile );
-
-  return( success == true ? Err_Success : Err_ReadFailed );
-}
-
-
-void CHexEditorWidget::writeURL( TQString &url )
-{
-  KURL kurl( url );
-  if( kurl.isLocalFile() )
-    writeFile( kurl.path() );
-  else
-  {
-    bool modified = mHexView->modified();
-    KTempFile tf;
-    tf.setAutoDelete( true );
-    writeFile( tf.name() );
-    if( !TDEIO::NetAccess::upload(tf.name(),url,this) )
-    {
-      mHexView->setModified( modified );
-      TQString msg = i18n("Could not save remote file.");
-      KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
-    }
-  }
-}
-
-bool CHexEditorWidget::modifiedByAlien( const TQString &url )
-{
-  KURL kurl( url );
-  if( kurl.isLocalFile() == false )
-  {
-    return( false );
-  }
-
-  TQFileInfo fileInfo( kurl.path() );
-  if( fileInfo.exists() == false )
-  {
-    return( false );
-  }
-
-  if( fileInfo.lastModified() == mHexView->diskModifyTime() )
-  {
-    return( false );
-  }
-
-  return( true );
-}
-
-
-
-bool CHexEditorWidget::readFile( const TQString &diskPath, const TQString &url,
-				 bool insert )
-{
-
-  TQFileInfo info( diskPath );
-  if( info.exists() == false )
-  {
-    const TQString msg = i18n("The specified file does not exist.\n%1").arg( diskPath );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
-    return( false );
-  }
-
-  if( info.isDir() == true )
-  {
-    const TQString msg = i18n("You have specified a folder.\n%1").arg( diskPath );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
-    return( false );
-  }
-
-  if( info.isReadable() == false )
-  {
-    const TQString msg = i18n("You do not have read permission to this file.\n%1").arg( diskPath );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
-    return( false );
-  }
-
-  TQFile file( diskPath );
-  if( file.open( IO_ReadOnly | IO_Raw ) == false )
-  {
-    const TQString msg = i18n("An error occurred while trying to open the file.\n%1").arg( diskPath );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
-    return( false );
-  }
-
-  if( mHexView->documentPresent() == false )
-  {
-    //
-    // Can not insert if there is no document present.
-    //
-    insert = false;
-  }
-
-  int errCode = prepareProgressData( insert == true ? pg_insert: pg_read );
-  if( errCode == Err_Success )
-  {
-    if( insert == true )
-    {
-      errCode = mHexView->insertFile( file, mProgressData );
-    }
-    else
-    {
-      errCode = mHexView->readFile( file, url, mProgressData );
-    }
-  }
-
-  if( errCode != Err_Success )
-  {
-    TQString header = insert == true ? i18n("Insert") : i18n("Read");
-    TQString msg = i18n("Could not read file.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg, header );
-  }
-
-  file.close();
-  return( errCode == Err_Success || errCode == Err_Busy ? true : false );
-}
-
-
-
-
-bool CHexEditorWidget::writeFile( const TQString &diskPath )
-{
-  TQFileInfo info( diskPath );
-  if( info.exists() == true )
-  {
-    if( info.isDir() == true )
-    {
-      TQString msg = i18n("You have specified a folder.");
-      KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
-      return( false );
-    }
-
-    if( info.isWritable() == false )
-    {
-      TQString msg = i18n("You do not have write permission.");
-      KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
-      return( false );
-    }
-  }
-
-  TQFile file( diskPath );
-  if( file.open( IO_WriteOnly | IO_Raw | IO_Truncate ) == false )
-  {
-    TQString msg = i18n("An error occurred while trying to open the file.");
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
-    return( false );
-  }
-
-  int errCode = prepareProgressData( pg_write );
-  if( errCode == Err_Success )
-  {
-    errCode = mHexView->writeFile( file, mProgressData );
-  }
-  if( errCode != Err_Success )
-  {
-    TQString msg = i18n("Could not write data to disk.\n");
-    msg += hexError( errCode );
-    KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
-  }
-
-  file.close();
-  return( true );
-}
-
-
-CHexBuffer *CHexEditorWidget::documentItem( const TQString &url )
-{
-  TQString symbolicName( url );
-//  KURL::decode( symbolicName );
-
-  for( CHexBuffer *hexBuffer = mDocumentList.first(); hexBuffer != 0;
-       hexBuffer = mDocumentList.next() )
-  {
-    if( hexBuffer->url() == symbolicName )
-    {
-      return( hexBuffer );
-    }
-  }
-
-  return( 0 );
-}
-
-
-CHexBuffer *CHexEditorWidget::documentItem( const TQString &url, bool next )
-{
-  if( mDocumentList.count() <= 1 )
-  {
-    return( 0 );
-  }
-
-  TQString symbolicName( url );
-//  KURL::decode( symbolicName );
-
-  if( next == true )
-  {
-    CHexBuffer *hexBuffer = mDocumentList.first();
-    for( ; hexBuffer != 0; hexBuffer = mDocumentList.next() )
-    {
-      if( hexBuffer->url() == symbolicName )
-      {
-	hexBuffer = mDocumentList.next();
-	return( hexBuffer == 0 ? mDocumentList.first() : hexBuffer );
-      }
-    }
-  }
-  else
-  {
-    CHexBuffer *hexBuffer = mDocumentList.last();
-    for( ; hexBuffer != 0; hexBuffer = mDocumentList.prev() )
-    {
-      if( hexBuffer->url() == symbolicName )
-      {
-	hexBuffer = mDocumentList.prev();
-	return( hexBuffer == 0 ? mDocumentList.last() : hexBuffer );
-      }
-    }
-  }
-
-  return( 0 );
-}
-
-
-
-bool CHexEditorWidget::createBuffer( void )
-{
-  if( mHexView->documentPresent() == false )
-  {
-    //
-    // The document is not valid, i.e. the buffer contains no data
-    // so we can use this one without destroying anything.
-    //
-    return( true );
-  }
-
-  CHexBuffer *hexBuffer = new CHexBuffer;
-  if( hexBuffer == 0 )
-  {
-    TQString msg = i18n( "Can not create text buffer.\n" );
-    msg += hexError( Err_NoMemory );
-    KMessageBox::error( topLevelWidget(), msg, i18n("Loading Failed" ) );
-    return( false );
-  }
-
-  mDocumentList.append( hexBuffer );
-  mHexView->setBuffer( hexBuffer );
-
-  return( true );
-}
-
-
-void CHexEditorWidget::removeBuffer( void )
-{
-  mHexView->closeFile();
-
-  if( mDocumentList.count() > 1 )
-  {
-    CHexBuffer *prev = 0;
-    CHexBuffer *curr = mDocumentList.first();
-    for( ; curr != 0; curr = mDocumentList.next() )
-    {
-      if( curr == mHexView->hexBuffer() )
-      {
-	CHexBuffer *ptr = prev != 0 ? prev : mDocumentList.next();
-	if( ptr != 0 )
-	{
-	  mHexView->setBuffer( ptr );
-	  mDocumentList.remove( curr );
-	  break;
-	}
-      }
-      prev = curr;
-    }
-  }
-
-}
-
-
-bool CHexEditorWidget::modified( void )
-{
-  for( CHexBuffer *hexBuffer = mDocumentList.first(); hexBuffer != 0;
-       hexBuffer = mDocumentList.next() )
-  {
-    if( hexBuffer->modified() == true )
-    {
-      return( true );
-    }
-  }
-
-  return( false );
-}
-
-
-
-
-int CHexEditorWidget::prepareProgressData( EProgressMode mode )
-{
-  if( mode >= pg_MAX )
-  {
-    return( Err_IllegalMode );
-  }
-
-  if( mProgressBusy == true )
-  {
-    return( Err_Busy );
-  }
-
-
-  mProgressMode = mode;
-  mProgressBusy = true;
-  mProgressStop = false;
-  enableInputLock( true );
-
-  static TQString names[] =
-  {
-    i18n("Reading"),
-    i18n("Writing"),
-    i18n("Inserting"),
-    i18n("Printing"),
-    i18n("Encoding"),
-    i18n("Collect strings"),
-    i18n("Exporting"),
-    i18n("Scanning"),
-  };
-
-  mProgressData.define( progressReceiver, this );
-  emit setProgressText( TQString(names[mode]) );
-  emit operationChanged( true );
-
-  return( Err_Success );
-}
-
-
-int CHexEditorWidget::progressReceiver( void *clientData, SProgressData &pd )
-{
-  if( clientData != 0 )
-  {
-    int errCode = ((CHexEditorWidget*)clientData)->progressParse( pd );
-    return( errCode );
-  }
-  else
-  {
-    return( Err_Success );
-  }
-}
-
-
-int CHexEditorWidget::progressParse( const SProgressData &pd )
-{
-  if( pd.valid() == 0 )
-  {
-    emit enableProgressText( false );
-    emit setProgress( 0 );
-    emit operationChanged( false );
-    mProgressBusy = false;
-    enableInputLock( false );
-    kapp->processEvents();
-    return( Err_Success );
-  }
-  else if( pd.useFraction == 1 )
-  {
-    emit enableProgressText( true );
-    emit setProgress( (int)(100.0 * pd.fraction ) );
-    kapp->processEvents();
-  }
-  else
-  {
-    emit enableProgressText( true );
-    emit setProgress( pd.curPage, pd.maxPage );
-    kapp->processEvents();
-  }
-
-  if( mProgressStop == false )
-  {
-    return( Err_Success );
-  }
-
-  TQString msg, header;
-  switch( mProgressMode )
-  {
-    case pg_read:
-      header = i18n("Read");
-      msg = i18n("Do you really want to cancel reading?");
-    break;
-
-    case pg_write:
-      header = i18n("Write");
-      msg  = i18n("Do you really want to cancel writing?\n"
-                  "WARNING: Canceling can corrupt your data on disk");
-    break;
-
-    case pg_insert:
-      header = i18n("Insert");
-      msg = i18n("Do you really want to cancel inserting?");
-    break;
-
-    case pg_print:
-      header = i18n("Print");
-      msg = i18n("Do you really want to cancel printing?");
-    break;
-
-    case pg_encode:
-      header = i18n("Encode");
-      msg = i18n("Do you really want to cancel encoding?");
-    break;
-
-    case pg_strings:
-      header = i18n("Collect strings");
-      msg = i18n("Do you really want to cancel string scanning?");
-    break;
-
-    case pg_export:
-      header = i18n("Export");
-      msg = i18n("Do you really want to cancel exporting?");
-    break;
-
-    case pg_statistic:
-      header = i18n("Collect document statistics");
-      msg = i18n("Do you really want to cancel document scanning?");
-    break;
-
-    default:
-      return( Err_Success );
-    break;
-
-  }
-
-  int reply = KMessageBox::warningYesNo( topLevelWidget(), msg, header, KStdGuiItem::cancel(), KStdGuiItem::cont() );
-  mProgressStop = false;
-  return( reply == KMessageBox::Yes ? Err_Stop : Err_Success );
-}
-
-
-
-bool CHexEditorWidget::busy( bool showWarning )
-{
-  if( mProgressBusy == true && showWarning == true )
-  {
-    TQString msg = i18n("Could not finish operation.\n");
-    msg += hexError( Err_Busy );
-    KMessageBox::sorry( topLevelWidget(), msg );
-  }
-
-  return( mProgressBusy );
-}
-
-
-
-
-#include "hexeditorwidget.moc"
diff --git a/khexedit/hexeditorwidget.cpp b/khexedit/hexeditorwidget.cpp
new file mode 100644
index 00000000..09a9407b
--- /dev/null
+++ b/khexedit/hexeditorwidget.cpp
@@ -0,0 +1,2443 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+
+#include <iostream>
+#include <unistd.h>
+
+#undef Unsorted
+
+#include <tdefiledialog.h>
+#include <tdeglobalsettings.h>
+#include <tdeio/netaccess.h>
+#include <tdelocale.h>
+#include <tdemessagebox.h>
+#include <tdetempfile.h>
+#include <kpushbutton.h>
+#include <kstdguiitem.h>
+
+#include "chartabledialog.h"
+#include "converterdialog.h"
+#include "dialog.h"
+#include "exportdialog.h"
+#include "fileinfodialog.h"
+#include "hexeditorwidget.h"
+#include "hexerror.h"
+#include "optiondialog.h"
+#include "printdialogpage.h"
+#include "stringdialog.h"
+
+
+
+
+CHexEditorWidget::CHexEditorWidget( TQWidget *parent, const char *name )
+  : TQWidget( parent, name )
+{
+  CHexBuffer *hexBuffer = new CHexBuffer;
+  if( hexBuffer == 0 ) { return; }
+
+  mDocumentList.setAutoDelete( true );
+  mDocumentList.append( hexBuffer );
+  mUntitledCount = 1;
+
+  mHexView = new CHexViewWidget( this, "hexview", hexBuffer );
+  if( mHexView == 0 || mHexView->widgetValid() == false ) { return; }
+
+  connect( mHexView, TQT_SIGNAL(pleaseOpenNewFile()), TQT_SLOT( newFile()) );
+  connect( mHexView, TQT_SIGNAL(pleaseOpenFile( const TQString&, bool, uint )),
+	   TQT_SLOT( open(const TQString&, bool, uint)) );
+  connect( mHexView, TQT_SIGNAL(pleaseStepFile(bool)), TQT_SLOT( stepFile(bool)) );
+  connect( kapp, TQT_SIGNAL( tdedisplayFontChanged() ), TQT_SLOT( fontChanged() ) );
+  connect( kapp, TQT_SIGNAL( tdedisplayPaletteChanged() ),TQT_SLOT( paletteChanged()) );
+  connect( mHexView, TQT_SIGNAL( layoutChanged( const SDisplayLayout & ) ),
+	   TQT_SLOT( layoutChanged( const SDisplayLayout & ) ) );
+  connect( mHexView, TQT_SIGNAL( inputModeChanged( const SDisplayInputMode & ) ),
+	   this, TQT_SLOT( inputModeChanged( const SDisplayInputMode & ) ) );
+
+  mHexView->setFocus();
+  setBackgroundColor( palette().active().base() );
+
+  mProgressBusy    = false;
+  mGotoDialog      = 0;
+  mFindDialog      = 0;
+  mReplaceDialog   = 0;
+  mInsertDialog    = 0;
+  mFilterDialog    = 0;
+  mOptionDialog    = 0;
+  mStringDialog    = 0;
+  mCharTableDialog = 0;
+  mFileInfoDialog  = 0;
+  mExportDialog    = 0;
+  mConverterDialog = 0;
+  mFindNavigatorDialog   = 0;
+  mReplacePromptDialog   = 0;
+}
+
+CHexEditorWidget::~CHexEditorWidget( void )
+{
+  delete mHexView;
+  delete mGotoDialog;
+  delete mFindDialog;
+  delete mReplaceDialog;
+  delete mInsertDialog;
+  delete mFilterDialog;
+  delete mOptionDialog;
+  delete mStringDialog;
+  delete mCharTableDialog;
+  delete mFileInfoDialog;
+  delete mExportDialog;
+  delete mConverterDialog;
+  delete mFindNavigatorDialog;
+  delete mReplacePromptDialog;
+}
+
+
+void CHexEditorWidget::initialize( void )
+{
+  setColor( mDisplayState.color );
+  setFont( mDisplayState.font );
+  mHexView->setMisc( mDisplayState.misc );
+  mHexView->setCursor( mDisplayState.cursor, false );
+  mHexView->setLayout( mDisplayState.layout );
+  mHexView->setInputMode( mDisplayState.input );
+  mHexView->setInsertMode( mDisplayState.misc.insertMode );
+}
+
+
+void CHexEditorWidget::writeConfiguration( TDEConfig &config )
+{
+  SDisplayLayout &layout = mDisplayState.layout;
+  config.setGroup( "Display Options" );
+  config.writeEntry( "PrimaryMode",          layout.primaryModeString() );
+  config.writeEntry( "SecondaryMode",        layout.secondaryModeString() );
+  config.writeEntry( "OffsetMode",           layout.offsetModeString() );
+  config.writeEntry( "OffsetVisible",        layout.offsetVisible );
+  config.writeEntry( "PrimaryUpperCase",     layout.primaryUpperCase );
+  config.writeEntry( "OffsetUpperCase",      layout.offsetUpperCase );
+  config.writeEntry( "LineSize",             layout.lineSize );
+  config.writeEntry( "ColumnSize",           layout.columnSize );
+  config.writeEntry( "LockLine",             layout.lockLine );
+  config.writeEntry( "LockColumn",           layout.lockColumn );
+  config.writeEntry( "ColumnCharSpace",      layout.columnCharSpace );
+  config.writeEntry( "ColumnSpacing",        layout.columnSpacing );
+  config.writeEntry( "SeparatorMarginWidth", layout.separatorMarginWidth );
+  config.writeEntry( "EdgeMarginWidth",      layout.edgeMarginWidth );
+  config.writeEntry( "LeftSeparatorWidth",   layout.leftSeparatorWidth );
+  config.writeEntry( "RightSeparatorWidth",  layout.rightSeparatorWidth );
+  config.writeEntry( "GridMode",             layout.gridModeString() );
+
+  SDisplayLine &line = mDisplayState.line;
+  config.setGroup( "Line Size" );
+  config.writeEntry( "Hexadecimal",line.lineSize[SDisplayLine::hexadecimal] );
+  config.writeEntry( "Decimal",    line.lineSize[SDisplayLine::decimal] );
+  config.writeEntry( "Octal",      line.lineSize[SDisplayLine::octal] );
+  config.writeEntry( "Binary",     line.lineSize[SDisplayLine::binary] );
+  config.writeEntry( "TextOnly",   line.lineSize[SDisplayLine::textOnly] );
+  config.setGroup( "Column Size" );
+  config.writeEntry( "Hexadecimal",line.columnSize[SDisplayLine::hexadecimal]);
+  config.writeEntry( "Decimal",    line.columnSize[SDisplayLine::decimal] );
+  config.writeEntry( "Octal",      line.columnSize[SDisplayLine::octal] );
+  config.writeEntry( "Binary",     line.columnSize[SDisplayLine::binary] );
+  config.writeEntry( "TextOnly",   line.columnSize[SDisplayLine::textOnly] );
+
+  SDisplayColor &color = mDisplayState.color;
+  config.setGroup( "Display Colors" );
+  config.writeEntry( "UseSystemColor",       color.useSystemColor );
+  config.writeEntry( "TextBg",               color.textBg );
+  config.writeEntry( "SecondTextBg",         color.secondTextBg );
+  config.writeEntry( "OffsetBg",             color.offsetBg );
+  config.writeEntry( "InactiveBg",           color.inactiveBg );
+  config.writeEntry( "PrimaryFg1",           color.primaryFg[0] );
+  config.writeEntry( "PrimaryFg2",           color.primaryFg[1] );
+  config.writeEntry( "OffsetFg",             color.offsetFg );
+  config.writeEntry( "SecondaryFg",          color.secondaryFg );
+  config.writeEntry( "MarkBg",               color.markBg );
+  config.writeEntry( "MarkFg",               color.markFg );
+  config.writeEntry( "LeftSeparatorFg",      color.leftSeparatorFg );
+  config.writeEntry( "RightSeparatorFg",     color.leftSeparatorFg );
+  config.writeEntry( "NonPrintFg",           color.nonPrintFg );
+  config.writeEntry( "CursorBg",             color.cursorBg );
+  config.writeEntry( "CursorFg",             color.cursorFg );
+  config.writeEntry( "GridFg",               color.gridFg );
+  config.writeEntry( "BookmarkBg",           color.bookmarkBg );
+  config.writeEntry( "BookmarkFg",           color.bookmarkFg );
+
+  SDisplayFont &font = mDisplayState.font;
+  config.setGroup( "Display Font" );
+  config.writeEntry( "UseSystemFont",        font.useSystemFont );
+  config.writeEntry( "LocalFont",            font.localFont );
+  config.writeEntry( "NonPrintChar",         font.nonPrintChar.unicode() );
+
+  SDisplayCursor &cursor = mDisplayState.cursor;
+  config.setGroup( "Display Cursor" );
+  config.writeEntry( "NeverBlink",           cursor.alwaysVisible );
+  config.writeEntry( "AlwaysBlockShape",     cursor.alwaysBlockShape );
+  config.writeEntry( "ThickInsertShape",     cursor.thickInsertShape );
+  config.writeEntry( "FocusMode",            cursor.focusModeString() );
+  config.writeEntry( "Interval",             cursor.interval );
+
+  SDisplayMisc &misc = mDisplayState.misc;
+  config.setGroup( "Display Misc" );
+  config.writeEntry( "UndoLevel",            misc.undoLevel );
+  config.writeEntry( "OpenFile",             misc.openFileString() );
+  config.writeEntry( "InputSound",           misc.inputSound );
+  config.writeEntry( "FatalSound",           misc.fatalSound );
+  config.writeEntry( "AutoCopyToClipboard",  misc.autoCopyToClipboard );
+  config.writeEntry( "InsertMode",           misc.insertMode );
+  config.writeEntry( "WriteProtect",         misc.writeProtect );
+  config.writeEntry( "ConfirmWrap",          misc.confirmWrap );
+  config.writeEntry( "CursorJump",           misc.cursorJump );
+  config.writeEntry( "MakeBackup",           misc.makeBackup );
+  config.writeEntry( "ConfirmThreshold",     misc.confirmThreshold );
+  config.writeEntry( "ThresholdValue",       misc.thresholdValue );
+  config.writeEntry( "DiscardRecent",        misc.discardRecent );
+  config.writeEntry( "GotoOnStartup",        misc.gotoOnStartup );
+  config.writeEntry( "GotoOnReload",         misc.gotoOnReload );
+  config.writeEntry( "ShowBookmarkInOffsetColumn", misc.bookmarkOffsetColumn );
+  config.writeEntry( "ShowBookmarkInEditor", misc.bookmarkEditor );
+
+  if( mExportDialog != 0 )
+  {
+    mExportDialog->writeConfiguration();
+  }
+}
+
+void CHexEditorWidget::readConfiguration( TDEConfig &config )
+{
+  SDisplayLayout &layout = mDisplayState.layout;
+  config.setGroup( "Display Options" );
+  layout.setPrimaryMode( config.readEntry("PrimaryMode") );
+  layout.setSecondaryMode( config.readEntry("SecondaryMode") );
+  layout.setOffsetMode( config.readEntry("OffsetMode") );
+  layout.offsetVisible = config.readBoolEntry(
+    "OffsetVisible", layout.offsetVisible );
+  layout.primaryUpperCase = config.readBoolEntry(
+    "PrimaryUpperCase", layout.primaryUpperCase );
+  layout.offsetUpperCase = config.readBoolEntry(
+    "OffsetUpperCase", layout.offsetUpperCase );
+  layout.lineSize = config.readNumEntry(
+    "LineSize", layout.lineSize );
+  layout.columnSize = config.readNumEntry(
+    "ColumnSize", layout.columnSize );
+  layout.lockLine = config.readBoolEntry(
+    "LockLine", layout.lockLine );
+  layout.lockColumn = config.readBoolEntry(
+    "LockColumn", layout.lockColumn );
+  layout.columnCharSpace = config.readBoolEntry(
+    "ColumnCharSpace", layout.columnCharSpace );
+  layout.columnSpacing = config.readNumEntry(
+    "ColumnSpacing", layout.columnSpacing );
+  layout.separatorMarginWidth = config.readNumEntry(
+    "SeparatorMarginWidth", layout.separatorMarginWidth );
+  layout.edgeMarginWidth = config.readNumEntry(
+    "EdgeMarginWidth", layout.edgeMarginWidth );
+  layout.leftSeparatorWidth = config.readNumEntry(
+    "LeftSeparatorWidth", layout.leftSeparatorWidth );
+  layout.rightSeparatorWidth = config.readNumEntry(
+    "RightSeparatorWidth", layout.rightSeparatorWidth );
+  layout.setGridMode( config.readEntry("GridMode") );
+
+  SDisplayLine &line = mDisplayState.line;
+  config.setGroup( "Line Size" );
+  line.lineSize[SDisplayLine::hexadecimal] = config.readUnsignedNumEntry(
+    "Hexadecimal", line.lineSize[SDisplayLine::hexadecimal] );
+  line.lineSize[SDisplayLine::decimal] = config.readUnsignedNumEntry(
+    "Decimal", line.lineSize[SDisplayLine::decimal] );
+  line.lineSize[SDisplayLine::octal] = config.readUnsignedNumEntry(
+    "Octal", line.lineSize[SDisplayLine::octal] );
+  line.lineSize[SDisplayLine::binary] = config.readUnsignedNumEntry(
+    "Binary", line.lineSize[SDisplayLine::binary] );
+  line.lineSize[SDisplayLine::textOnly] = config.readUnsignedNumEntry(
+    "TextOnly", line.lineSize[SDisplayLine::textOnly] );
+  config.setGroup( "Column Size" );
+  line.columnSize[SDisplayLine::hexadecimal] = config.readUnsignedNumEntry(
+    "Hexadecimal", line.columnSize[SDisplayLine::hexadecimal] );
+  line.columnSize[SDisplayLine::decimal] = config.readUnsignedNumEntry(
+    "Decimal", line.columnSize[SDisplayLine::decimal] );
+  line.columnSize[SDisplayLine::octal] = config.readUnsignedNumEntry(
+    "Octal", line.columnSize[SDisplayLine::octal] );
+  line.columnSize[SDisplayLine::binary] = config.readUnsignedNumEntry(
+    "Binary", line.columnSize[SDisplayLine::binary] );
+  line.columnSize[SDisplayLine::textOnly] = config.readUnsignedNumEntry(
+    "TextOnly", line.columnSize[SDisplayLine::textOnly] );
+
+  SDisplayFont &font = mDisplayState.font;
+  config.setGroup( "Display Font" );
+  font.useSystemFont = config.readBoolEntry(
+    "UseSystemFont", true );
+  font.localFont = config.readFontEntry(
+    "LocalFont", &font.localFont );
+  font.nonPrintChar = config.readNumEntry(
+    "NonPrintChar", font.nonPrintChar );
+
+  SDisplayColor &color = mDisplayState.color;
+  config.setGroup( "Display Colors" );
+  color.useSystemColor = config.readBoolEntry(
+    "UseSystemColor", color.useSystemColor );
+  color.textBg = config.readColorEntry(
+    "TextBg", &color.textBg );
+  color.secondTextBg = config.readColorEntry(
+    "SecondTextBg", &color.secondTextBg );
+  color.offsetBg = config.readColorEntry(
+    "OffsetBg", &color.offsetBg );
+  color.inactiveBg = config.readColorEntry(
+    "InactiveBg", &color.inactiveBg );
+  color.primaryFg[0] = config.readColorEntry(
+    "PrimaryFg1", &color.primaryFg[0] );
+  color.primaryFg[1] = config.readColorEntry(
+    "PrimaryFg2", &color.primaryFg[1] );
+  color.offsetFg = config.readColorEntry(
+    "OffsetFg", &color.offsetFg );
+  color.secondaryFg = config.readColorEntry(
+    "SecondaryFg", &color.secondaryFg );
+  color.markBg = config.readColorEntry(
+    "MarkBg", &color.markBg );
+  color.markFg = config.readColorEntry(
+    "MarkFg", &color.markFg );
+  color.cursorBg = config.readColorEntry(
+    "CursorBg", &color.cursorBg );
+  color.cursorFg = config.readColorEntry(
+    "CursorFg", &color.cursorFg );
+  color.leftSeparatorFg = config.readColorEntry(
+    "LeftSeparatorFg", &color.leftSeparatorFg );
+  color.rightSeparatorFg = config.readColorEntry(
+    "RightSeparatorFg", &color.rightSeparatorFg );
+  color.nonPrintFg = config.readColorEntry(
+    "NonPrintFg", &color.nonPrintFg );
+  color.gridFg = config.readColorEntry(
+    "GridFg", &color.gridFg );
+  color.bookmarkBg = config.readColorEntry(
+    "BookmarkBg", &color.bookmarkBg );
+  color.bookmarkFg = config.readColorEntry(
+    "BookmarkFg", &color.bookmarkFg );
+
+  SDisplayCursor &cursor = mDisplayState.cursor;
+  config.setGroup( "Display Cursor" );
+  cursor.alwaysVisible = config.readBoolEntry(
+    "NeverBlink", cursor.alwaysVisible );
+  cursor.alwaysBlockShape = config.readBoolEntry(
+    "AlwaysBlockShape", cursor.alwaysBlockShape );
+  cursor.thickInsertShape = config.readBoolEntry(
+    "ThickInsertShape", cursor.thickInsertShape );
+  cursor.setFocusMode( config.readEntry("FocusMode") );
+  cursor.interval = config.readNumEntry(
+    "Interval", cursor.interval );
+
+  SDisplayMisc &misc = mDisplayState.misc;
+  config.setGroup( "Display Misc" );
+  misc.undoLevel = config.readNumEntry(
+    "UndoLevel", misc.undoLevel );
+  misc.setOpenFile( config.readEntry("OpenFile") );
+  misc.inputSound = config.readBoolEntry(
+    "InputSound", misc.inputSound );
+  misc.fatalSound = config.readBoolEntry(
+    "FatalSound", misc.fatalSound );
+  misc.autoCopyToClipboard = config.readBoolEntry(
+    "AutoCopyToClipboard", misc.autoCopyToClipboard );
+  misc.insertMode = config.readBoolEntry(
+    "InsertMode", misc.insertMode );
+  misc.writeProtect = config.readBoolEntry(
+    "WriteProtect", misc.writeProtect );
+  misc.confirmWrap = config.readBoolEntry(
+    "ConfirmWrap", misc.confirmWrap );
+  misc.cursorJump = config.readBoolEntry(
+    "CursorJump", misc.cursorJump );
+  misc.makeBackup = config.readBoolEntry(
+    "MakeBackup", misc.makeBackup );
+  misc.confirmThreshold = config.readBoolEntry(
+    "ConfirmThreshold", misc.confirmThreshold );
+  misc.thresholdValue = config.readNumEntry(
+    "ThresholdValue", misc.thresholdValue );
+  misc.discardRecent = config.readBoolEntry(
+    "DiscardRecent", misc.discardRecent );
+  misc.gotoOnStartup = config.readBoolEntry(
+    "GotoOnStartup", misc.gotoOnStartup );
+  misc.gotoOnReload = config.readBoolEntry(
+    "GotoOnReload", misc.gotoOnReload );
+  misc.bookmarkOffsetColumn = config.readBoolEntry(
+    "ShowBookmarkInOffsetColumn", misc.bookmarkOffsetColumn );
+  misc.bookmarkEditor = config.readBoolEntry(
+    "ShowBookmarkInEditor", misc.bookmarkEditor );
+}
+
+
+
+void CHexEditorWidget::resizeEvent( TQResizeEvent *e )
+{
+  mHexView->resize( e->size().width(), e->size().height() );
+}
+
+
+void CHexEditorWidget::fontChanged( void )
+{
+  if( mDisplayState.font.useSystemFont == true )
+  {
+    setFont( mDisplayState.font );
+  }
+}
+
+void CHexEditorWidget::paletteChanged( void )
+{
+  setColor( mDisplayState.color );
+}
+
+void CHexEditorWidget::layoutChanged( const SDisplayLayout &/*layout*/ )
+{
+  //mDisplayState.layout = layout;
+}
+
+void CHexEditorWidget::inputModeChanged( const SDisplayInputMode &input )
+{
+  mDisplayState.input = input;
+}
+
+
+void CHexEditorWidget::setLineSize(const SDisplayLine &line )
+{
+  mDisplayState.line = line;
+}
+
+void CHexEditorWidget::setLayout( const SDisplayLayout &layout )
+{
+  //
+  // We only set the values that can be modified by the dialog
+  //
+  mDisplayState.layout.lockLine = layout.lockLine;
+  mDisplayState.layout.lockColumn = layout.lockColumn;
+  mDisplayState.layout.leftSeparatorWidth = layout.leftSeparatorWidth;
+  mDisplayState.layout.rightSeparatorWidth = layout.rightSeparatorWidth;
+  mDisplayState.layout.separatorMarginWidth = layout.separatorMarginWidth;
+  mDisplayState.layout.edgeMarginWidth = layout.edgeMarginWidth;
+  mDisplayState.layout.columnCharSpace = layout.columnCharSpace;
+  mDisplayState.layout.columnSpacing = layout.columnSpacing;
+  mDisplayState.layout.horzGridWidth = layout.horzGridWidth;
+  mDisplayState.layout.vertGridWidth = layout.vertGridWidth;
+
+  //
+  // Select the line and column sizes we shall use now.
+  //
+  SDisplayLayout &l = mDisplayState.layout;
+  l.lineSize   = mDisplayState.line.lineSize[ l.primaryMode ];
+  l.columnSize = mDisplayState.line.columnSize[ l.primaryMode ];
+
+  mHexView->setLayout( mDisplayState.layout );
+}
+
+void CHexEditorWidget::setCursor( const SDisplayCursor &cursor )
+{
+  mDisplayState.cursor = cursor;
+  mHexView->setCursor( mDisplayState.cursor, true );
+}
+
+void CHexEditorWidget::setColor( const SDisplayColor &color )
+{
+  mDisplayState.color = color;
+
+  //
+  // The selection colors can not be chosen.
+  //
+  mDisplayState.color.selectBg = kapp->palette().active().highlight();
+  mDisplayState.color.selectFg = kapp->palette().active().highlightedText();
+
+  if( mDisplayState.color.useSystemColor == true )
+  {
+    SDisplayColor c = mDisplayState.color;
+    c.textBg           = kapp->palette().active().base();
+    c.secondTextBg     = kapp->palette().active().base();
+    c.offsetBg         = kapp->palette().active().base();
+    c.inactiveBg       = kapp->palette().active().base();
+    c.primaryFg[0]     = kapp->palette().active().text();
+    c.primaryFg[1]     = kapp->palette().active().text();
+    c.nonPrintFg       = kapp->palette().active().text();
+    c.offsetFg         = kapp->palette().active().text();
+    c.secondaryFg      = kapp->palette().active().text();
+    c.leftSeparatorFg  = kapp->palette().active().text();
+    c.rightSeparatorFg = kapp->palette().active().text();
+    c.cursorBg         = kapp->palette().active().text();
+    c.cursorFg         = kapp->palette().active().base();
+    c.gridFg           = kapp->palette().active().text();
+    SDisplayColor defaultColor;
+    c.bookmarkBg       = defaultColor.bookmarkBg;
+    c.bookmarkFg       = defaultColor.bookmarkFg;
+
+    mHexView->setColor( c, true );
+  }
+  else
+  {
+    mHexView->setColor( mDisplayState.color, true );
+  }
+}
+
+
+void CHexEditorWidget::setFont( const SDisplayFont &font )
+{
+  mDisplayState.font = font;
+
+  SDisplayFontInfo fontInfo;
+  if( mDisplayState.font.useSystemFont == true )
+  {
+    fontInfo.font = TDEGlobalSettings::fixedFont();
+  }
+  else
+  {
+    fontInfo.font = mDisplayState.font.localFont;
+  }
+  fontInfo.nonPrintChar = mDisplayState.font.nonPrintChar;
+  mHexView->setFont( fontInfo, true );
+}
+
+void CHexEditorWidget::setMisc( const SDisplayMisc &misc )
+{
+  mDisplayState.misc = misc;
+  mHexView->setMisc( mDisplayState.misc );
+}
+
+
+
+void CHexEditorWidget::setHexadecimalMode( void )
+{
+  layout().primaryMode   = SDisplayLayout::hexadecimal;
+  layout().lineSize      = line().lineSize[ SDisplayLine::hexadecimal ];
+  layout().columnSize    = line().columnSize[ SDisplayLine::hexadecimal ];
+  mHexView->setLayout( layout() );
+}
+
+
+void CHexEditorWidget::setDecimalMode( void )
+{
+  layout().primaryMode   = SDisplayLayout::decimal;
+  layout().lineSize      = line().lineSize[ SDisplayLine::decimal ];
+  layout().columnSize    = line().columnSize[ SDisplayLine::decimal ];
+  mHexView->setLayout( layout() );
+}
+
+
+void CHexEditorWidget::setOctalMode( void )
+{
+  layout().primaryMode   = SDisplayLayout::octal;
+  layout().lineSize      = line().lineSize[ SDisplayLine::octal ];
+  layout().columnSize    = line().columnSize[ SDisplayLine::octal ];
+  mHexView->setLayout( layout() );
+}
+
+
+void CHexEditorWidget::setBinaryMode( void )
+{
+  layout().primaryMode   = SDisplayLayout::binary;
+  layout().lineSize      = line().lineSize[ SDisplayLine::binary ];
+  layout().columnSize    = line().columnSize[ SDisplayLine::binary ];
+  mHexView->setLayout( layout() );
+}
+
+
+void CHexEditorWidget::setTextMode( void )
+{
+  layout().primaryMode   = SDisplayLayout::textOnly;
+  layout().lineSize      = line().lineSize[ SDisplayLine::textOnly ];
+  layout().columnSize    = line().columnSize[ SDisplayLine::textOnly ];
+  mHexView->setLayout( layout() );
+}
+
+
+
+void CHexEditorWidget::saveWorkingDirectory( const TQString &url )
+{
+  if( url.isEmpty() == true )
+  {
+    return;
+  }
+
+  int index = url.findRev( '/' );
+  if( index != -1 )
+  {
+    mWorkDir = url.left( index+1 );
+  }
+}
+
+
+
+void CHexEditorWidget::newFile( void )
+{
+  if( busy( true ) == true )
+  {
+    return;
+  }
+
+  TQString url = i18n("Untitled %1").arg( mUntitledCount );
+
+  //
+  // If the url is already present in the document list (should not happen),
+  // then this document is "raised".
+  //
+  bool success = selectDocument( url, false );
+  if( success == true )
+  {
+    return;
+  }
+
+  //
+  // Prepare a new buffer we can load the document into
+  //
+  success = createBuffer();
+  if( success == false )
+  {
+    return;
+  }
+
+  int errCode = mHexView->newFile( url );
+  if( errCode != Err_Success )
+  {
+    TQString msg = i18n("Unable to create new document.");
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Operation Failed") );
+    return;
+  }
+
+  mUntitledCount += 1;
+}
+
+
+
+
+void CHexEditorWidget::newFile( const TQByteArray &data )
+{
+  newFile();
+  mHexView->append( data );
+}
+
+
+
+
+void CHexEditorWidget::open()
+{
+  KURL file = KFileDialog::getOpenURL( mWorkDir, "*" ,topLevelWidget() );
+
+  if( file.isEmpty() )
+    return;
+
+  TQString url = file.url();
+
+  saveWorkingDirectory( url );
+
+  if( busy( true ) )
+    return;
+
+  //
+  // If the url is already present in the document list, then this
+  // document is "raised".
+  //
+  if( selectDocument( url, true ) )
+    return;
+
+  //
+  // Prepare a new buffer we can load the document into
+  //
+  if( !createBuffer() )
+    return;
+
+  int errCode = readURL( file, false );
+  if( errCode != Err_Success )
+  {
+    emit errorLoadFile( url );
+    removeBuffer();
+  }
+  else if( errCode == Err_Success )
+  {
+    defaultWriteProtection();
+  }
+}
+
+
+
+void CHexEditorWidget::open( const TQString &url, bool reloadWhenChanged,
+			     uint offset )
+{
+  if( busy( true ) == true )
+  {
+    return;
+  }
+
+  //
+  // If the url is already present in the document list, then this
+  // document is "raised".
+  //
+  bool success = selectDocument( url, reloadWhenChanged );
+  if( success == true )
+  {
+    return;
+  }
+
+  //
+  // Prepare a new buffer we can load the document into
+  //
+  success = createBuffer();
+  if( success == false )
+  {
+    return;
+  }
+
+  int errCode = readURL( url, false );
+  if( errCode != Err_Success )
+  {
+    emit errorLoadFile( url );
+    removeBuffer();
+  }
+  else if( errCode == Err_Success )
+  {
+    mHexView->gotoOffset( offset );
+    defaultWriteProtection();
+  }
+}
+
+
+void CHexEditorWidget::stepFile( bool next )
+{
+  //
+  // The buffer list is is reverse when compared with the visible
+  // document list in the menu so I toggle the flag.
+  //
+  next = next == true ? false : true;
+
+  CHexBuffer *hexBuffer = documentItem( mHexView->url(), next );
+  if( hexBuffer == 0 )
+  {
+    return;
+  }
+
+  mHexView->setBuffer( hexBuffer );
+}
+
+
+
+
+
+bool CHexEditorWidget::isOpen( const TQString &url, uint &offset )
+{
+  CHexBuffer *hexBuffer = documentItem( url );
+  if( hexBuffer == 0 )
+  {
+    return( false );
+  }
+  offset = hexBuffer->cursorOffset();
+  return( true );
+}
+
+
+bool CHexEditorWidget::selectDocument( const TQString &url,
+				       bool reloadWhenChanged )
+{
+  CHexBuffer *hexBuffer = documentItem( url );
+  if( hexBuffer == 0 )
+  {
+    return( false );
+  }
+
+  mHexView->setBuffer( hexBuffer );
+
+  if( reloadWhenChanged == true && mHexView->urlValid() == true )
+  {
+    if( modifiedByAlien( mHexView->url() ) == true )
+    {
+      reload();
+    }
+  }
+
+  return( true );
+}
+
+
+void CHexEditorWidget::insertFile( void )
+{
+  KFileDialog fdlg(mWorkDir, TQString(), topLevelWidget(), 0, TRUE);
+  fdlg.setOperationMode( KFileDialog::Opening );
+  fdlg.okButton()->setGuiItem( KStdGuiItem::insert() );
+  fdlg.setCaption(i18n("Insert File"));
+
+  if (!fdlg.exec()) return;
+  KURL file = fdlg.selectedURL();
+
+  if( file.isEmpty() )
+    return;
+
+  if( !file.isLocalFile() )
+  {
+    KMessageBox::sorry( this, i18n( "Only local files are currently supported." ) );
+    return;
+  }
+
+  TQString url = file.path();
+
+  saveWorkingDirectory( url );
+
+  if( busy( true ) )
+    return;
+
+  readURL( url, true );
+}
+
+
+
+void CHexEditorWidget::stop( void )
+{
+  mProgressStop = mProgressBusy;
+}
+
+
+bool CHexEditorWidget::close( void )
+{
+  if( busy( true ) == true )
+  {
+    return( false );
+  }
+
+  if( querySave() == false )
+  {
+    return( false );
+  }
+
+  removeBuffer();
+  return( true );
+}
+
+
+
+
+bool CHexEditorWidget::closeAll( void )
+{
+  if( busy( true ) == true )
+  {
+    return( false );
+  }
+
+  while( mDocumentList.count() > 0 )
+  {
+    CHexBuffer *buf;
+    for( buf = mDocumentList.first(); buf != 0; buf = mDocumentList.next() )
+    {
+      //
+      // We select the buffer we are about to close because it will
+      // the become visible, and because 'close()' works on the current
+      // buffer.
+      //
+      mHexView->setBuffer( buf );
+      if( close() == false )
+      {
+	return( false );
+      }
+    }
+
+    //
+    // The document list will always contain at least one element because
+    // the hexview widget needs a hexbuffer to work. If this hexbuffer is
+    // not valid, then all files have been closed.
+    //
+    if( mDocumentList.count() == 1 && mHexView->documentPresent() == false )
+    {
+      break;
+    }
+  }
+
+  return( true );
+}
+
+
+
+bool CHexEditorWidget::querySave( void )
+{
+  if( mHexView->modified() == false )
+  {
+    return( true );
+  }
+
+  TQString msg = i18n(""
+    "The current document has been modified.\n"
+    "Do you want to save it?" );
+  int reply = KMessageBox::warningYesNoCancel( topLevelWidget(), msg, TQString(), KStdGuiItem::save(), KStdGuiItem::discard() );
+  if( reply == KMessageBox::Yes )
+  {
+    return( save() );
+  }
+  else if( reply == KMessageBox::No )
+  {
+    return( true );
+  }
+  else
+  {
+    return( false );
+  }
+}
+
+
+bool CHexEditorWidget::backup( void )
+{
+  if( mHexView->documentPresent() == false || mHexView->urlValid() == false )
+  {
+    return( false );
+  }
+
+  KURL kurl( mHexView->url() );
+  if( kurl.isLocalFile() == false )
+  {
+    return( false );
+  }
+
+  const TQString currentName = kurl.path();
+  TQString backupName = currentName + '~';
+
+  int errCode = rename( currentName.latin1(), backupName.latin1() );
+  if( errCode != 0 )
+  {
+    return( false );
+  }
+
+
+  return( true );
+}
+
+
+
+//
+// Returns false if operation was canceled
+//
+bool CHexEditorWidget::save( void )
+{
+  if( mHexView->documentPresent() == false )
+  {
+    return( true );
+  }
+
+  if( mHexView->urlValid() == false )
+  {
+    return( saveAs() );
+  }
+  else
+  {
+    if( modifiedByAlien( mHexView->url() ) == true )
+    {
+      TQString msg = i18n(""
+       "Current document has been changed on disk.\n"
+       "If you save now, those changes will be lost.\n"
+       "Proceed?" );
+      int reply = KMessageBox::warningYesNoCancel( topLevelWidget(), msg,
+						   i18n("Save"), KStdGuiItem::save(), KStdGuiItem::discard() );
+      if( reply == KMessageBox::No || reply == KMessageBox::Cancel )
+      {
+	return( reply == KMessageBox::No ? true : false );
+      }
+    }
+
+    if( mDisplayState.misc.makeBackup == true )
+    {
+      backup();
+    }
+    writeURL( mHexView->url() );
+  }
+
+  return( true );
+}
+
+
+//
+// Returns false if operation was canceled
+//
+bool CHexEditorWidget::saveAs( void )
+{
+  if( mHexView->documentPresent() == false )
+  {
+    return( true );
+  }
+
+  KURL url;
+  while( 1 )
+  {
+    url = KFileDialog::getSaveURL( mHexView->url(), "*", this );
+    if( url.isEmpty() == true )
+    {
+      return( false );
+    }
+    else
+    {
+      saveWorkingDirectory( url.url() );
+    }
+
+    if( url.isLocalFile() )
+    {
+      TQString name( url.path() );
+      TQFileInfo info( name );
+
+      if( info.exists() )
+      {
+	TQString msg = i18n(""
+          "A document with this name already exists.\n"
+          "Do you want to overwrite it?" );
+	int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg,
+					       i18n("Save As"), i18n("Overwrite") );
+	if( reply == KMessageBox::Continue )
+	  break;
+      }
+      else
+	break;
+    }
+  }
+
+  TQString symbolicName( url.url() );
+//  KURL::decode( symbolicName );
+
+  mHexView->setUrl( symbolicName );
+  writeURL( mHexView->url() );
+  return( true );
+}
+
+
+
+void CHexEditorWidget::reload( void )
+{
+  if( mHexView->documentPresent() == false )
+  {
+    return;
+  }
+
+  if( busy( true ) == true )
+  {
+    return;
+  }
+
+  if( mHexView->urlValid() == false )
+  {
+    TQString msg = i18n( "The current document does not exist on the disk." );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Reload") );
+    return;
+  }
+
+  if( mHexView->modified() == true )
+  {
+    TQString msg;
+    if( modifiedByAlien( mHexView->url() ) == true )
+    {
+      msg = i18n( "The current document has changed on the disk and "
+                  "also contains unsaved modifications.\n"
+                  "If you reload now, the modifications will be lost." );
+    }
+    else
+    {
+      msg = i18n( "The current document contains unsaved modifications.\n"
+                   "If you reload now, the modifications will be lost." );
+    }
+
+    int reply = KMessageBox::warningContinueCancel(topLevelWidget(),msg,i18n("Reload"), i18n("&Reload"));
+    if( reply != KMessageBox::Continue )
+    {
+      return;
+    }
+  }
+
+  TQString url( mHexView->url() );
+  uint offset = mHexView->offset();
+
+  //mHexView->closeFile();
+  int errCode = readURL( url, false );
+  if( errCode == Err_Success && gotoReloadOffset() == true )
+  {
+    mHexView->gotoOffset( offset );
+  }
+
+}
+
+
+void CHexEditorWidget::print( void )
+{
+  CHexPrinter prt;
+
+  prt.addDialogPage( new LayoutDialogPage() );
+
+  prt.setPageSelection( KPrinter::SystemSide );
+  prt.setFullPage( true ); // I use my own marings
+
+  // FIXME: Make a better header for the printingdialog
+  if (prt.setup(topLevelWidget(), i18n("Print Hex-Document")))
+  {
+     prt.setTopMarginMM( prt.option("kde-khexedit-topmarginmm").toInt() );
+     prt.setBottomMarginMM( prt.option("kde-khexedit-bottommarginmm").toInt() );
+     prt.setLeftMarginMM( prt.option("kde-khexedit-leftmarginmm").toInt() );
+     prt.setRightMarginMM( prt.option("kde-khexedit-rightmarginmm").toInt() );
+
+     prt.setPageHeader( (prt.option("kde-khexedit-headercheck") == "true"),
+			  prt.option("kde-khexedit-headercombo0").toInt(),
+			  prt.option("kde-khexedit-headercombo1").toInt(),
+			  prt.option("kde-khexedit-headercombo2").toInt(),
+			  prt.option("kde-khexedit-headercombo3").toInt() );
+
+     prt.setPageFooter( (prt.option("kde-khexedit-footercheck") == "true"),
+			  prt.option("kde-khexedit-footercombo0").toInt(),
+			  prt.option("kde-khexedit-footercombo1").toInt(),
+			  prt.option("kde-khexedit-footercombo2").toInt(),
+			  prt.option("kde-khexedit-footercombo3").toInt() );
+
+     printPostscript(prt);
+  }
+
+}
+
+
+
+
+void CHexEditorWidget::printPostscript( CHexPrinter &printer )
+{
+  if( confirmPrintPageNumber( printer ) == false )
+  {
+    return;
+  }
+
+  //
+  // No i18n() on this one!
+  // Constants come from config.h
+  //
+  TQString creator( PACKAGE );
+  creator += " ";
+  creator += VERSION;
+
+  printer.setCreator( creator );
+
+  int errCode = prepareProgressData( pg_print );
+  if( errCode == Err_Success )
+  {
+    errCode = mHexView->print( printer, mProgressData );
+  }
+
+  TQString msg = i18n("Could not print data.\n");
+  msg += hexError( errCode );
+
+  if( errCode != Err_Success )
+  {
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Print") );
+  }
+}
+
+
+bool CHexEditorWidget::confirmPrintPageNumber( CHexPrinter &printer )
+{
+  if( mDisplayState.misc.confirmThreshold == true )
+  {
+    uint numPage = mHexView->numPage( printer );
+    printer.setMinMax( 1, numPage );
+    uint numPageSelected = printer.pageList().count();
+
+    if( numPageSelected > mDisplayState.misc.thresholdValue )
+    {
+      TQString msg = i18n(
+        "<qt>Print threshold exceeded.<br>"
+        "You are about to print one page.<br>"
+	"Proceed?</qt>",
+        "<qt>Print threshold exceeded.<br>"
+        "You are about to print %n pages.<br>"
+	"Proceed?</qt>",
+	numPageSelected );
+      int reply = KMessageBox::warningYesNo( topLevelWidget(), msg,
+					     i18n("Print"), KStdGuiItem::print(), KStdGuiItem::cancel() );
+      if( reply != KMessageBox::Continue )
+      {
+	return( false );
+      }
+    }
+  }
+
+  return( true );
+}
+
+
+void CHexEditorWidget::exportDialog( void )
+{
+  if( mExportDialog == 0 )
+  {
+    mExportDialog = new CExportDialog( topLevelWidget(), 0, false );
+    if( mExportDialog == 0 ) { return; }
+    connect( mExportDialog, TQT_SIGNAL( exportText(const SExportText &)),
+	     this, TQT_SLOT( exportText( const SExportText &)) );
+    connect( mExportDialog, TQT_SIGNAL( exportHtml(const SExportHtml &)),
+	     this, TQT_SLOT( exportHtml( const SExportHtml &)) );
+    connect( mExportDialog, TQT_SIGNAL( exportCArray(const SExportCArray &)),
+	     this, TQT_SLOT( exportCArray( const SExportCArray &)) );
+  }
+  mExportDialog->show();
+}
+
+
+
+void CHexEditorWidget::exportText( const SExportText &ex )
+{
+  int errCode = prepareProgressData( pg_export );
+  if( errCode == Err_Success )
+  {
+    errCode = mHexView->exportText( ex, mProgressData );
+  }
+
+  if( errCode != Err_Success )
+  {
+    TQString msg = i18n("Unable to export data.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Export") );
+  }
+}
+
+
+void CHexEditorWidget::exportHtml( const SExportHtml &ex )
+{
+  int errCode = prepareProgressData( pg_export );
+  if( errCode == Err_Success )
+  {
+    errCode = mHexView->exportHtml( ex, mProgressData );
+  }
+
+  if( errCode != Err_Success )
+  {
+    TQString msg = i18n("Unable to export data.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Export") );
+  }
+}
+
+
+void CHexEditorWidget::exportCArray( const SExportCArray &ex )
+{
+  int errCode = prepareProgressData( pg_export );
+  if( errCode == Err_Success )
+  {
+    errCode = mHexView->exportCArray( ex, mProgressData );
+  }
+
+  if( errCode != Err_Success )
+  {
+    TQString msg = i18n("Unable to export data.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Export") );
+  }
+}
+
+
+void CHexEditorWidget::encode( CConversion::EMode mode )
+{
+  if( mHexView->losslessEncoding( mode ) == false )
+  {
+    TQString msg = i18n(""
+      "The encoding you have selected is not reversible.\n"
+      "If you revert to the original encoding later, there is no "
+      "guarantee that the data can be restored to the original state.");
+    int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg,
+					   i18n("Encode"), i18n("&Encode"));
+    if( reply != KMessageBox::Continue )
+    {
+      // Restore correct menu setting
+      mHexView->reportEncoding();
+      return;
+    }
+  }
+
+  int errCode = prepareProgressData( pg_encode );
+  if( errCode == Err_Success )
+  {
+    errCode = mHexView->setEncoding( mode, mProgressData );
+  }
+
+  if( errCode != Err_Success )
+  {
+    TQString msg = i18n("Could not encode data.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Encode") );
+  }
+}
+
+void CHexEditorWidget::undo( void )
+{
+  mHexView->undo();
+}
+
+void CHexEditorWidget::redo( void )
+{
+  mHexView->redo();
+}
+
+void CHexEditorWidget::toggleWriteProtection( void )
+{
+  mDisplayState.input.readOnly = mDisplayState.input.readOnly == true ?
+    false : true;
+  mHexView->setInputMode( mDisplayState.input );
+}
+
+void CHexEditorWidget::defaultWriteProtection( void )
+{
+  mDisplayState.input.readOnly = mDisplayState.misc.writeProtect;
+  mHexView->setInputMode( mDisplayState.input );
+}
+
+void CHexEditorWidget::toggleResizeLock( void )
+{
+  mDisplayState.input.allowResize = mDisplayState.input.allowResize == true ?
+    false : true;
+  mHexView->setInputMode( mDisplayState.input );
+}
+
+void CHexEditorWidget::setResizeLock( bool state )
+{
+  mDisplayState.input.allowResize = state;
+  mHexView->setInputMode( mDisplayState.input );
+}
+
+void CHexEditorWidget::enableInputLock( bool inputLock )
+{
+  mDisplayState.input.inputLock = inputLock;
+  mHexView->setInputMode( mDisplayState.input );
+}
+
+void CHexEditorWidget::toggleOffsetColumnVisibility( void )
+{
+  layout().offsetVisible = layout().offsetVisible == true ? false : true;
+  mHexView->setLayout( layout() );
+}
+
+void CHexEditorWidget::toggleTextColumnVisibility( void )
+{
+  layout().secondaryMode = layout().secondaryMode == SDisplayLayout::hide ?
+    SDisplayLayout::textOnly : SDisplayLayout::hide;
+  mHexView->setLayout( layout() );
+}
+
+void CHexEditorWidget::toggleOffsetAsDecimal( void )
+{
+  layout().offsetMode = layout().offsetMode == SDisplayLayout::hexadecimal ?
+    SDisplayLayout::decimal : SDisplayLayout::hexadecimal;
+  mHexView->setLayout( layout() );
+}
+
+void CHexEditorWidget::toggleDataUppercase( void )
+{
+  layout().primaryUpperCase = layout().primaryUpperCase == true ? false : true;
+  mHexView->setLayout( layout() );
+}
+
+void CHexEditorWidget::toggleOffsetUppercase( void )
+{
+  layout().offsetUpperCase = layout().offsetUpperCase == true ? false : true;
+  mHexView->setLayout( layout() );
+}
+
+void CHexEditorWidget::toggleInsertMode( void )
+{
+  mHexView->setInsertMode( !mHexView->insertMode() );
+}
+
+void CHexEditorWidget::benchmark( void )
+{
+  mHexView->benchmark();
+}
+
+void CHexEditorWidget::copy( void )
+{
+  mHexView->copy();
+}
+
+void CHexEditorWidget::copyText( void )
+{
+  mHexView->copyText();
+}
+
+void CHexEditorWidget::paste( void )
+{
+  if( mHexView->documentPresent() == false )
+  {
+    pasteNewFile();
+  }
+  else
+  {
+    mHexView->paste();
+  }
+}
+
+void CHexEditorWidget::pasteNewFile( void )
+{
+  newFile();
+  mHexView->paste();
+}
+
+void CHexEditorWidget::cut( void )
+{
+  mHexView->cut();
+}
+
+void CHexEditorWidget::selectAll( void )
+{
+  mHexView->selectAll();
+}
+
+void CHexEditorWidget::unselect( void )
+{
+  mHexView->unselect();
+}
+
+
+void CHexEditorWidget::addBookmark( void )
+{
+  mHexView->addBookmark( -1 );
+}
+
+
+void CHexEditorWidget::removeBookmark( void )
+{
+  if( mHexView->bookmarkCount() > 0 )
+  {
+    mHexView->removeBookmark( false );
+  }
+}
+
+
+void CHexEditorWidget::removeAllBookmark( void )
+{
+  if( mHexView->bookmarkCount() > 0 )
+  {
+    TQString msg = i18n(""
+      "Deleted bookmarks can not be restored.\n"
+      "Proceed?" );
+    int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg );
+    if( reply != KMessageBox::Continue )
+    {
+      return;
+    }
+    mHexView->removeBookmark( true );
+  }
+}
+
+
+void CHexEditorWidget::replaceBookmark( void )
+{
+  mHexView->replaceBookmark();
+}
+
+
+void CHexEditorWidget::gotoBookmark( int position )
+{
+  mHexView->gotoBookmark( (uint)position );
+}
+
+void CHexEditorWidget::gotoNextBookmark( void )
+{
+  mHexView->gotoNextBookmark(true);
+}
+
+void CHexEditorWidget::gotoPrevBookmark( void )
+{
+  mHexView->gotoNextBookmark(false);
+}
+
+void CHexEditorWidget::gotoOffset( void )
+{
+  if( mGotoDialog == 0 )
+  {
+    mGotoDialog = new CGotoDialog( topLevelWidget(), 0, false );
+    if( mGotoDialog == 0 ) { return; }
+    connect( mGotoDialog, TQT_SIGNAL(gotoOffset( uint, uint, bool, bool )),
+	     mHexView, TQT_SLOT(gotoOffset( uint, uint, bool, bool )) );
+  }
+  mGotoDialog->show();
+}
+
+
+void CHexEditorWidget::find( void )
+{
+  if( mFindNavigatorDialog != 0 )
+  {
+    mFindNavigatorDialog->hide();
+  }
+
+  if( mFindDialog == 0 )
+  {
+    mFindDialog = new CFindDialog( topLevelWidget(), 0, false );
+    if( mFindDialog == 0 ) { return; }
+    connect( mFindDialog,
+	     TQT_SIGNAL(findData(SSearchControl &, uint, bool)),
+	     TQT_SLOT(findData(SSearchControl &, uint, bool)) );
+  }
+  mFindDialog->show();
+}
+
+
+
+void CHexEditorWidget::findData( SSearchControl &sc, uint mode, bool navigator)
+{
+  for( uint i=0; i < 2; i++ )
+  {
+    int errCode;
+    if( mode == Find_First )
+    {
+      errCode = mHexView->findFirst( sc );
+      if( errCode == Err_Success )
+      {
+	if( navigator == true )
+	{
+	  findNavigator( sc );
+	}
+	return;
+      }
+    }
+    else if( mode == Find_Next )
+    {
+      errCode = mHexView->findNext( sc );
+      if( errCode == Err_Success )
+      {
+	if( navigator == true )
+	{
+	  findNavigator( sc );
+	}
+	return;
+      }
+    }
+    else
+    {
+      return;
+    }
+
+    if( errCode == Err_WrapBuffer && i == 0 )
+    {
+      bool reply = askWrap( sc.forward, i18n("Find") );
+      if( reply == false )
+      {
+	return;
+      }
+
+      sc.fromCursor = false;
+      mode = Find_First;
+    }
+  }
+
+  if( mode == Find_First )
+  {
+    TQString msg = i18n( "Search key not found in document." );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Find") );
+  }
+}
+
+
+
+void CHexEditorWidget::findAgain( void )
+{
+  if( canFind( true ) == true )
+  {
+    mFindDialog->findAgain( CFindDialog::find_Again );
+  }
+}
+
+
+void CHexEditorWidget::findNext( void )
+{
+  if( canFind( true ) == true )
+  {
+    mFindDialog->findAgain( CFindDialog::find_Next );
+  }
+}
+
+
+void CHexEditorWidget::findPrevious( void )
+{
+  if( canFind( true ) == true )
+  {
+    mFindDialog->findAgain( CFindDialog::find_Previous );
+  }
+}
+
+
+bool CHexEditorWidget::askWrap( bool fwd, const TQString &header )
+{
+  if( mDisplayState.misc.confirmWrap == false )
+  {
+    return( true ); // Never ask the user
+  }
+
+  TQString msg;
+  if( fwd == true )
+  {
+    msg += i18n(""
+      "End of document reached.\n"
+      "Continue from the beginning?" );
+  }
+  else
+  {
+    msg += i18n(""
+      "Beginning of document reached.\n"
+      "Continue from the end?" );
+  }
+
+  int reply = KMessageBox::questionYesNo( topLevelWidget(), msg, header, KStdGuiItem::cont(), KStdGuiItem::cancel() );
+  return( reply == KMessageBox::Yes ? true : false );
+}
+
+
+bool CHexEditorWidget::canFind( bool showError )
+{
+  if( mFindDialog == 0 || mFindDialog->isEmpty() == true )
+  {
+    if( showError == true )
+    {
+      TQString msg = i18n(""
+        "Your request can not be processed.\n"
+        "No search pattern defined." );
+      KMessageBox::sorry( topLevelWidget(), msg, i18n("Find") );
+    }
+    return( false );
+  }
+
+  return( true );
+}
+
+
+
+void CHexEditorWidget::findNavigator( SSearchControl &sc )
+{
+  if( canFind( false ) == false )
+  {
+    return;
+  }
+
+  if( mFindNavigatorDialog == 0 )
+  {
+    mFindNavigatorDialog = new CFindNavigatorDialog(topLevelWidget(),0,false);
+    if( mFindNavigatorDialog == 0 ) { return; }
+    connect( mFindNavigatorDialog,
+	     TQT_SIGNAL(findData(SSearchControl &, uint, bool)),
+	     TQT_SLOT(findData(SSearchControl &, uint, bool)) );
+    connect( mFindNavigatorDialog, TQT_SIGNAL(makeKey(void)),
+	     TQT_SLOT(find()) );
+  }
+  if( mFindNavigatorDialog->isVisible() == false )
+  {
+    mFindNavigatorDialog->defineData( sc );
+  }
+  mFindNavigatorDialog->show();
+}
+
+
+
+void CHexEditorWidget::replace( void )
+{
+  hideReplacePrompt();
+
+  if( mReplaceDialog == 0 )
+  {
+    mReplaceDialog = new CReplaceDialog( topLevelWidget(), 0, false );
+    if( mReplaceDialog == 0 ) { return; }
+    connect( mReplaceDialog,
+	     TQT_SIGNAL( replaceData( SSearchControl &, uint)),
+	     TQT_SLOT( replaceData( SSearchControl &, uint)));
+  }
+  mReplaceDialog->show();
+}
+
+
+
+void CHexEditorWidget::replaceData( SSearchControl &sc, uint mode )
+{
+  while( 1 )
+  {
+    if( mode == Replace_All || mode == Replace_AllInit )
+    {
+      mHexView->replaceAll( sc, mode == Replace_AllInit ? true : false );
+    }
+    else if( mode == Replace_First )
+    {
+      int errCode = mHexView->findFirst( sc );
+      if( errCode == Err_Success )
+      {
+	replacePrompt( sc );
+	return;
+      }
+    }
+    else if( mode == Replace_Next )
+    {
+      int errCode = mHexView->replaceMarked( sc );
+      if( errCode != Err_Success )
+      {
+	// Perhaps a notification here ?
+      }
+      errCode = mHexView->findNext( sc );
+      if( errCode == Err_Success )
+      {
+	replacePrompt( sc );
+	return;
+      }
+    }
+    else if( mode == Replace_Ignore )
+    {
+      int errCode = mHexView->findNext( sc );
+      if( errCode == Err_Success )
+      {
+	replacePrompt( sc );
+	return;
+      }
+    }
+    else
+    {
+      break;
+    }
+
+    if( sc.wrapValid == false )
+    {
+      break;
+    }
+
+    bool reply = askWrap( sc.forward, i18n("Find and Replace") );
+    if( reply == false )
+    {
+      break;
+    }
+
+    int errCode = mHexView->findWrap( sc );
+    if( errCode != Err_Success )
+    {
+      break;
+    }
+
+    if( mode == Replace_All || mode == Replace_AllInit )
+    {
+      mode = Replace_All;
+      continue;
+    }
+
+    replacePrompt( sc );
+    return;
+  }
+
+  replaceResult( sc );
+}
+
+void CHexEditorWidget::replacePrompt( SSearchControl &sc )
+{
+  if( mReplacePromptDialog == 0 )
+  {
+    mReplacePromptDialog = new CReplacePromptDialog(topLevelWidget(), 0,false);
+    if( mReplacePromptDialog == 0 ) { return; }
+    connect( mReplacePromptDialog,
+	     TQT_SIGNAL( replaceData( SSearchControl &, uint)),
+	     TQT_SLOT( replaceData( SSearchControl &, uint)));
+  }
+  if( mReplacePromptDialog->isVisible() == false )
+  {
+    mReplacePromptDialog->defineData( sc );
+  }
+  mReplacePromptDialog->show();
+}
+
+
+void CHexEditorWidget::hideReplacePrompt( void )
+{
+  if( mReplacePromptDialog != 0 )
+  {
+    mReplacePromptDialog->hide();
+  }
+}
+
+
+
+void CHexEditorWidget::replaceResult( SSearchControl &sc )
+{
+  hideReplacePrompt();
+
+  if( sc.match == false )
+  {
+    TQString msg;
+    if( sc.inSelection == true )
+    {
+      msg += i18n( "Search key not found in selected area." );
+    }
+    else
+    {
+      msg += i18n( "Search key not found in document." );
+    }
+    KMessageBox::information( topLevelWidget(), msg, i18n("Find & Replace"));
+  }
+  else
+  {
+    const TQString msg = i18n(
+      "<qt>Operation complete.<br><br>One replacement was made.</qt>",
+      "<qt>Operation complete.<br><br>%n replacements were made.</qt>", sc.numReplace );
+    KMessageBox::information( topLevelWidget(), msg, i18n("Find & Replace"));
+  }
+}
+
+
+void CHexEditorWidget::insertPattern( void )
+{
+  if( mInsertDialog == 0 )
+  {
+    mInsertDialog = new CInsertDialog( topLevelWidget(), 0, false );
+    if( mInsertDialog == 0 ) { return; }
+    connect( mInsertDialog, TQT_SIGNAL(execute( SInsertData & )),
+	     mHexView, TQT_SLOT(insert( SInsertData & )) );
+  }
+  mInsertDialog->show();
+}
+
+
+void CHexEditorWidget::encoding( void )
+{
+  TQString msg = i18n(""
+    "Not available yet!\n"
+    "Define your own encoding" );
+  KMessageBox::sorry( topLevelWidget(), msg, i18n("Encoding") );
+}
+
+
+void CHexEditorWidget::strings( void )
+{
+  if( mStringDialog == 0 )
+  {
+    mStringDialog = new CStringDialog( topLevelWidget(), 0, false );
+    if( mStringDialog == 0 ) { return; }
+    connect( mStringDialog, TQT_SIGNAL(markText( uint, uint, bool )),
+	     mHexView, TQT_SLOT(setMark( uint, uint, bool )) );
+    connect( mStringDialog, TQT_SIGNAL(collect()), TQT_SLOT(collectStrings()) );
+    connect( mHexView, TQT_SIGNAL(fileName( const TQString &, bool ) ),
+	     mStringDialog, TQT_SLOT( removeList() ) );
+    connect( mHexView, TQT_SIGNAL(dataChanged()),
+	     mStringDialog, TQT_SLOT(setDirty()) );
+  }
+  mStringDialog->show();
+}
+
+
+void CHexEditorWidget::collectStrings( void )
+{
+  int errCode = prepareProgressData( pg_strings );
+  if( errCode == Err_Success )
+  {
+    mHexView->collectStrings( mStringDialog->stringData() );
+    errCode = mStringDialog->updateList( mProgressData );
+  }
+
+  if( errCode != Err_Success && errCode != Err_Stop )
+  {
+    TQString msg = i18n("Could not collect strings.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Collect Strings") );
+  }
+
+}
+
+
+
+void CHexEditorWidget::recordView( void )
+{
+  TQString msg = i18n(""
+   "Not available yet!\n"
+   "Define a record (structure) and fill it with data from the document." );
+  KMessageBox::sorry( topLevelWidget(), msg, i18n("Record Viewer") );
+}
+
+void CHexEditorWidget::filter( void )
+{
+  if( mFilterDialog == 0 )
+  {
+    mFilterDialog = new CFilterDialog( topLevelWidget(), 0, false );
+    if( mFilterDialog == 0 ) { return; }
+    connect( mFilterDialog, TQT_SIGNAL(filterData( SFilterControl & )),
+	     mHexView, TQT_SLOT(filter( SFilterControl & )) );
+  }
+  mFilterDialog->show();
+}
+
+
+void CHexEditorWidget::chart( void )
+{
+  if( mCharTableDialog == 0 )
+  {
+    mCharTableDialog = new CCharTableDialog( topLevelWidget(), 0, false );
+    if( mCharTableDialog == 0 ) { return; }
+    connect( mCharTableDialog, TQT_SIGNAL(assign( const TQByteArray & )),
+	     mHexView, TQT_SLOT(insert( const TQByteArray & )) );
+  }
+  mCharTableDialog->show();
+}
+
+
+void CHexEditorWidget::converter( void )
+{
+  if( mConverterDialog == 0 )
+  {
+    mConverterDialog = new CConverterDialog( this, "converter", false );
+    connect( mConverterDialog, TQT_SIGNAL(probeCursorValue(TQByteArray &, uint)),
+	     mHexView, TQT_SLOT(valueOnCursor(TQByteArray &, uint)) );
+  }
+  mConverterDialog->show();
+}
+
+
+void CHexEditorWidget::statistics( void )
+{
+  if( mFileInfoDialog == 0 )
+  {
+    mFileInfoDialog = new CFileInfoDialog( topLevelWidget(), 0, false );
+    if( mFileInfoDialog == 0 ) { return; }
+    connect( mFileInfoDialog, TQT_SIGNAL(collectStatistic(SStatisticControl &)),
+	     TQT_SLOT(collectStatistics(SStatisticControl &)));
+    connect( mHexView, TQT_SIGNAL(dataChanged()),
+	     mFileInfoDialog, TQT_SLOT(setDirty()) );
+  }
+  mFileInfoDialog->show();
+}
+
+
+void CHexEditorWidget::collectStatistics( SStatisticControl &sc )
+{
+  int errCode = prepareProgressData( pg_statistic );
+  if( errCode == Err_Success )
+  {
+    errCode = mHexView->collectStatistic( sc, mProgressData );
+    if( errCode == Err_Success )
+    {
+      mFileInfoDialog->setStatistics( sc );
+    }
+  }
+
+  if( errCode != Err_Success && errCode != Err_Stop )
+  {
+    mFileInfoDialog->setStatistics(); // Default values
+
+    TQString msg = i18n("Could not collect document statistics.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg,
+			i18n("Collect Document Statistics") );
+  }
+
+}
+
+
+void CHexEditorWidget::options( void )
+{
+  if( mOptionDialog == 0 )
+  {
+    mOptionDialog = new COptionDialog( topLevelWidget(), 0, false );
+    if( mOptionDialog == 0 ) { return; }
+
+    connect( mOptionDialog, TQT_SIGNAL(lineSizeChoice(const SDisplayLine &)),
+	     TQT_SLOT(setLineSize(const SDisplayLine &)) );
+    connect( mOptionDialog, TQT_SIGNAL(layoutChoice(const SDisplayLayout &)),
+	     TQT_SLOT(setLayout(const SDisplayLayout &)) );
+    connect( mOptionDialog, TQT_SIGNAL(fontChoice(const SDisplayFont &)),
+	     TQT_SLOT(setFont(const SDisplayFont &)) );
+    connect( mOptionDialog, TQT_SIGNAL(colorChoice(const SDisplayColor &)),
+	     TQT_SLOT(setColor(const SDisplayColor &)) );
+    connect( mOptionDialog, TQT_SIGNAL(cursorChoice(const SDisplayCursor &)),
+	     TQT_SLOT(setCursor(const SDisplayCursor &)) );
+    connect( mOptionDialog, TQT_SIGNAL(miscChoice(const SDisplayMisc &)),
+	     TQT_SLOT(setMisc(const SDisplayMisc &)) );
+    connect( mOptionDialog, TQT_SIGNAL(removeRecentFiles()),
+	     TQT_SIGNAL(removeRecentFiles()) );
+  }
+  if( mOptionDialog->isVisible() == false )
+  {
+    mOptionDialog->setState( mDisplayState );
+  }
+  mOptionDialog->show();
+}
+
+
+
+void CHexEditorWidget::favorites( void )
+{
+  TQString msg = i18n(""
+    "Not available yet!\n"
+    "Save or retrive your favorite layout" );
+  KMessageBox::sorry( topLevelWidget(), msg, i18n("Profiles") );
+}
+
+
+int CHexEditorWidget::readURL( const KURL &url, bool insert )
+{
+  //
+  // 1) Make sure there is data in the url
+  //
+  if( url.isEmpty() )
+    return( Err_EmptyArgument );
+
+  //
+  // 2) Verify that the url is valid URL string. If not, try to repair it.
+  // This will work if the url contains a name of a file in the
+  // current directory.
+  //
+  if( !url.isValid() )
+  {
+    TQString msg = i18n("Malformed URL\n%1").arg( url.url() );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read URL") );
+    return( Err_IllegalArgument );
+  }
+
+  //
+  // 3) Load the file.
+  //
+  TQString tmpfile;
+  if ( !TDEIO::NetAccess::download( url, tmpfile, this ) )
+    return Err_ReadFailed;
+
+  bool success = readFile( tmpfile, url.url(), insert );
+
+  TDEIO::NetAccess::removeTempFile( tmpfile );
+
+  return( success == true ? Err_Success : Err_ReadFailed );
+}
+
+
+void CHexEditorWidget::writeURL( TQString &url )
+{
+  KURL kurl( url );
+  if( kurl.isLocalFile() )
+    writeFile( kurl.path() );
+  else
+  {
+    bool modified = mHexView->modified();
+    KTempFile tf;
+    tf.setAutoDelete( true );
+    writeFile( tf.name() );
+    if( !TDEIO::NetAccess::upload(tf.name(),url,this) )
+    {
+      mHexView->setModified( modified );
+      TQString msg = i18n("Could not save remote file.");
+      KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
+    }
+  }
+}
+
+bool CHexEditorWidget::modifiedByAlien( const TQString &url )
+{
+  KURL kurl( url );
+  if( kurl.isLocalFile() == false )
+  {
+    return( false );
+  }
+
+  TQFileInfo fileInfo( kurl.path() );
+  if( fileInfo.exists() == false )
+  {
+    return( false );
+  }
+
+  if( fileInfo.lastModified() == mHexView->diskModifyTime() )
+  {
+    return( false );
+  }
+
+  return( true );
+}
+
+
+
+bool CHexEditorWidget::readFile( const TQString &diskPath, const TQString &url,
+				 bool insert )
+{
+
+  TQFileInfo info( diskPath );
+  if( info.exists() == false )
+  {
+    const TQString msg = i18n("The specified file does not exist.\n%1").arg( diskPath );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
+    return( false );
+  }
+
+  if( info.isDir() == true )
+  {
+    const TQString msg = i18n("You have specified a folder.\n%1").arg( diskPath );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
+    return( false );
+  }
+
+  if( info.isReadable() == false )
+  {
+    const TQString msg = i18n("You do not have read permission to this file.\n%1").arg( diskPath );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
+    return( false );
+  }
+
+  TQFile file( diskPath );
+  if( file.open( IO_ReadOnly | IO_Raw ) == false )
+  {
+    const TQString msg = i18n("An error occurred while trying to open the file.\n%1").arg( diskPath );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Read") );
+    return( false );
+  }
+
+  if( mHexView->documentPresent() == false )
+  {
+    //
+    // Can not insert if there is no document present.
+    //
+    insert = false;
+  }
+
+  int errCode = prepareProgressData( insert == true ? pg_insert: pg_read );
+  if( errCode == Err_Success )
+  {
+    if( insert == true )
+    {
+      errCode = mHexView->insertFile( file, mProgressData );
+    }
+    else
+    {
+      errCode = mHexView->readFile( file, url, mProgressData );
+    }
+  }
+
+  if( errCode != Err_Success )
+  {
+    TQString header = insert == true ? i18n("Insert") : i18n("Read");
+    TQString msg = i18n("Could not read file.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg, header );
+  }
+
+  file.close();
+  return( errCode == Err_Success || errCode == Err_Busy ? true : false );
+}
+
+
+
+
+bool CHexEditorWidget::writeFile( const TQString &diskPath )
+{
+  TQFileInfo info( diskPath );
+  if( info.exists() == true )
+  {
+    if( info.isDir() == true )
+    {
+      TQString msg = i18n("You have specified a folder.");
+      KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
+      return( false );
+    }
+
+    if( info.isWritable() == false )
+    {
+      TQString msg = i18n("You do not have write permission.");
+      KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
+      return( false );
+    }
+  }
+
+  TQFile file( diskPath );
+  if( file.open( IO_WriteOnly | IO_Raw | IO_Truncate ) == false )
+  {
+    TQString msg = i18n("An error occurred while trying to open the file.");
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
+    return( false );
+  }
+
+  int errCode = prepareProgressData( pg_write );
+  if( errCode == Err_Success )
+  {
+    errCode = mHexView->writeFile( file, mProgressData );
+  }
+  if( errCode != Err_Success )
+  {
+    TQString msg = i18n("Could not write data to disk.\n");
+    msg += hexError( errCode );
+    KMessageBox::sorry( topLevelWidget(), msg, i18n("Write Failure") );
+  }
+
+  file.close();
+  return( true );
+}
+
+
+CHexBuffer *CHexEditorWidget::documentItem( const TQString &url )
+{
+  TQString symbolicName( url );
+//  KURL::decode( symbolicName );
+
+  for( CHexBuffer *hexBuffer = mDocumentList.first(); hexBuffer != 0;
+       hexBuffer = mDocumentList.next() )
+  {
+    if( hexBuffer->url() == symbolicName )
+    {
+      return( hexBuffer );
+    }
+  }
+
+  return( 0 );
+}
+
+
+CHexBuffer *CHexEditorWidget::documentItem( const TQString &url, bool next )
+{
+  if( mDocumentList.count() <= 1 )
+  {
+    return( 0 );
+  }
+
+  TQString symbolicName( url );
+//  KURL::decode( symbolicName );
+
+  if( next == true )
+  {
+    CHexBuffer *hexBuffer = mDocumentList.first();
+    for( ; hexBuffer != 0; hexBuffer = mDocumentList.next() )
+    {
+      if( hexBuffer->url() == symbolicName )
+      {
+	hexBuffer = mDocumentList.next();
+	return( hexBuffer == 0 ? mDocumentList.first() : hexBuffer );
+      }
+    }
+  }
+  else
+  {
+    CHexBuffer *hexBuffer = mDocumentList.last();
+    for( ; hexBuffer != 0; hexBuffer = mDocumentList.prev() )
+    {
+      if( hexBuffer->url() == symbolicName )
+      {
+	hexBuffer = mDocumentList.prev();
+	return( hexBuffer == 0 ? mDocumentList.last() : hexBuffer );
+      }
+    }
+  }
+
+  return( 0 );
+}
+
+
+
+bool CHexEditorWidget::createBuffer( void )
+{
+  if( mHexView->documentPresent() == false )
+  {
+    //
+    // The document is not valid, i.e. the buffer contains no data
+    // so we can use this one without destroying anything.
+    //
+    return( true );
+  }
+
+  CHexBuffer *hexBuffer = new CHexBuffer;
+  if( hexBuffer == 0 )
+  {
+    TQString msg = i18n( "Can not create text buffer.\n" );
+    msg += hexError( Err_NoMemory );
+    KMessageBox::error( topLevelWidget(), msg, i18n("Loading Failed" ) );
+    return( false );
+  }
+
+  mDocumentList.append( hexBuffer );
+  mHexView->setBuffer( hexBuffer );
+
+  return( true );
+}
+
+
+void CHexEditorWidget::removeBuffer( void )
+{
+  mHexView->closeFile();
+
+  if( mDocumentList.count() > 1 )
+  {
+    CHexBuffer *prev = 0;
+    CHexBuffer *curr = mDocumentList.first();
+    for( ; curr != 0; curr = mDocumentList.next() )
+    {
+      if( curr == mHexView->hexBuffer() )
+      {
+	CHexBuffer *ptr = prev != 0 ? prev : mDocumentList.next();
+	if( ptr != 0 )
+	{
+	  mHexView->setBuffer( ptr );
+	  mDocumentList.remove( curr );
+	  break;
+	}
+      }
+      prev = curr;
+    }
+  }
+
+}
+
+
+bool CHexEditorWidget::modified( void )
+{
+  for( CHexBuffer *hexBuffer = mDocumentList.first(); hexBuffer != 0;
+       hexBuffer = mDocumentList.next() )
+  {
+    if( hexBuffer->modified() == true )
+    {
+      return( true );
+    }
+  }
+
+  return( false );
+}
+
+
+
+
+int CHexEditorWidget::prepareProgressData( EProgressMode mode )
+{
+  if( mode >= pg_MAX )
+  {
+    return( Err_IllegalMode );
+  }
+
+  if( mProgressBusy == true )
+  {
+    return( Err_Busy );
+  }
+
+
+  mProgressMode = mode;
+  mProgressBusy = true;
+  mProgressStop = false;
+  enableInputLock( true );
+
+  static TQString names[] =
+  {
+    i18n("Reading"),
+    i18n("Writing"),
+    i18n("Inserting"),
+    i18n("Printing"),
+    i18n("Encoding"),
+    i18n("Collect strings"),
+    i18n("Exporting"),
+    i18n("Scanning"),
+  };
+
+  mProgressData.define( progressReceiver, this );
+  emit setProgressText( TQString(names[mode]) );
+  emit operationChanged( true );
+
+  return( Err_Success );
+}
+
+
+int CHexEditorWidget::progressReceiver( void *clientData, SProgressData &pd )
+{
+  if( clientData != 0 )
+  {
+    int errCode = ((CHexEditorWidget*)clientData)->progressParse( pd );
+    return( errCode );
+  }
+  else
+  {
+    return( Err_Success );
+  }
+}
+
+
+int CHexEditorWidget::progressParse( const SProgressData &pd )
+{
+  if( pd.valid() == 0 )
+  {
+    emit enableProgressText( false );
+    emit setProgress( 0 );
+    emit operationChanged( false );
+    mProgressBusy = false;
+    enableInputLock( false );
+    kapp->processEvents();
+    return( Err_Success );
+  }
+  else if( pd.useFraction == 1 )
+  {
+    emit enableProgressText( true );
+    emit setProgress( (int)(100.0 * pd.fraction ) );
+    kapp->processEvents();
+  }
+  else
+  {
+    emit enableProgressText( true );
+    emit setProgress( pd.curPage, pd.maxPage );
+    kapp->processEvents();
+  }
+
+  if( mProgressStop == false )
+  {
+    return( Err_Success );
+  }
+
+  TQString msg, header;
+  switch( mProgressMode )
+  {
+    case pg_read:
+      header = i18n("Read");
+      msg = i18n("Do you really want to cancel reading?");
+    break;
+
+    case pg_write:
+      header = i18n("Write");
+      msg  = i18n("Do you really want to cancel writing?\n"
+                  "WARNING: Canceling can corrupt your data on disk");
+    break;
+
+    case pg_insert:
+      header = i18n("Insert");
+      msg = i18n("Do you really want to cancel inserting?");
+    break;
+
+    case pg_print:
+      header = i18n("Print");
+      msg = i18n("Do you really want to cancel printing?");
+    break;
+
+    case pg_encode:
+      header = i18n("Encode");
+      msg = i18n("Do you really want to cancel encoding?");
+    break;
+
+    case pg_strings:
+      header = i18n("Collect strings");
+      msg = i18n("Do you really want to cancel string scanning?");
+    break;
+
+    case pg_export:
+      header = i18n("Export");
+      msg = i18n("Do you really want to cancel exporting?");
+    break;
+
+    case pg_statistic:
+      header = i18n("Collect document statistics");
+      msg = i18n("Do you really want to cancel document scanning?");
+    break;
+
+    default:
+      return( Err_Success );
+    break;
+
+  }
+
+  int reply = KMessageBox::warningYesNo( topLevelWidget(), msg, header, KStdGuiItem::cancel(), KStdGuiItem::cont() );
+  mProgressStop = false;
+  return( reply == KMessageBox::Yes ? Err_Stop : Err_Success );
+}
+
+
+
+bool CHexEditorWidget::busy( bool showWarning )
+{
+  if( mProgressBusy == true && showWarning == true )
+  {
+    TQString msg = i18n("Could not finish operation.\n");
+    msg += hexError( Err_Busy );
+    KMessageBox::sorry( topLevelWidget(), msg );
+  }
+
+  return( mProgressBusy );
+}
+
+
+
+
+#include "hexeditorwidget.moc"
diff --git a/khexedit/hexerror.cc b/khexedit/hexerror.cc
deleted file mode 100644
index 6549f1da..00000000
--- a/khexedit/hexerror.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <tdelocale.h>
-
-#include "hexerror.h"
-
-static TQString message;
-
-
-const TQString &hexError( int index )
-{
-  static TQString messages[ Err_MAXERROR - Err_NoData ] = 
-  {
-    i18n("No data"),                                    // Err_NoData
-    i18n("Insufficient memory"),                        // Err_NoMemory
-    i18n("List is full"),                               // Err_ListFull
-    i18n("Read operation failed"),                      // Err_ReadFailed
-    i18n("Write operation failed"),                     // Err_WriteFailed
-    i18n("Empty argument"),                             // Err_EmptyArgument
-    i18n("Illegal argument"),                           // Err_IllegalArgument
-    i18n("Null pointer argument"),                      // Err_NullArgument
-    i18n("Wrap buffer"),                                // Err_WrapBuffer
-    i18n("No match"),                                   // Err_NoMatch
-    i18n("No data is selected"),                        // Err_NoSelection
-    i18n("Empty document"),                             // Err_EmptyDocument
-    i18n("No active document"),                         // Err_NoActiveDocument
-    i18n("No data is marked"),                          // Err_NoMark
-    i18n("Document is write protected"),                // Err_WriteProtect
-    i18n("Document is resize protected"),               // Err_NoResize
-    i18n("Operation was stopped"),                      // Err_Stop
-    i18n("Illegal mode"),                               // Err_IllegalMode
-    i18n("Program is busy, try again later"),           // Err_Busy
-    i18n("Value is not within valid range"),            // Err_IllegalRange
-    i18n("Operation was aborted"),                      // Err_OperationAborted
-    i18n("File could not be opened for writing"),       // Err_OpenWriteFailed
-    i18n("File could not be opened for reading"),       // Err_OpenReadFailed
-  }; 
-
-
-  if( index < Err_NoData || index >= Err_MAXERROR )
-  {
-    message = i18n("Unknown error");
-  }
-  else
-  {
-    message = messages[ index - Err_NoData ];
-  }
-
-  return( message );
-}
-
diff --git a/khexedit/hexerror.cpp b/khexedit/hexerror.cpp
new file mode 100644
index 00000000..6549f1da
--- /dev/null
+++ b/khexedit/hexerror.cpp
@@ -0,0 +1,69 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <tdelocale.h>
+
+#include "hexerror.h"
+
+static TQString message;
+
+
+const TQString &hexError( int index )
+{
+  static TQString messages[ Err_MAXERROR - Err_NoData ] = 
+  {
+    i18n("No data"),                                    // Err_NoData
+    i18n("Insufficient memory"),                        // Err_NoMemory
+    i18n("List is full"),                               // Err_ListFull
+    i18n("Read operation failed"),                      // Err_ReadFailed
+    i18n("Write operation failed"),                     // Err_WriteFailed
+    i18n("Empty argument"),                             // Err_EmptyArgument
+    i18n("Illegal argument"),                           // Err_IllegalArgument
+    i18n("Null pointer argument"),                      // Err_NullArgument
+    i18n("Wrap buffer"),                                // Err_WrapBuffer
+    i18n("No match"),                                   // Err_NoMatch
+    i18n("No data is selected"),                        // Err_NoSelection
+    i18n("Empty document"),                             // Err_EmptyDocument
+    i18n("No active document"),                         // Err_NoActiveDocument
+    i18n("No data is marked"),                          // Err_NoMark
+    i18n("Document is write protected"),                // Err_WriteProtect
+    i18n("Document is resize protected"),               // Err_NoResize
+    i18n("Operation was stopped"),                      // Err_Stop
+    i18n("Illegal mode"),                               // Err_IllegalMode
+    i18n("Program is busy, try again later"),           // Err_Busy
+    i18n("Value is not within valid range"),            // Err_IllegalRange
+    i18n("Operation was aborted"),                      // Err_OperationAborted
+    i18n("File could not be opened for writing"),       // Err_OpenWriteFailed
+    i18n("File could not be opened for reading"),       // Err_OpenReadFailed
+  }; 
+
+
+  if( index < Err_NoData || index >= Err_MAXERROR )
+  {
+    message = i18n("Unknown error");
+  }
+  else
+  {
+    message = messages[ index - Err_NoData ];
+  }
+
+  return( message );
+}
+
diff --git a/khexedit/hexmanagerwidget.cc b/khexedit/hexmanagerwidget.cc
deleted file mode 100644
index a8d4bedc..00000000
--- a/khexedit/hexmanagerwidget.cc
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <tdelocale.h>
-#include <tqlayout.h>
-#include "hexmanagerwidget.h"
-#include "searchbar.h"
-
-CHexManagerWidget::CHexManagerWidget( TQWidget *parent, const char *name,
-				      EConversionPosition conversionPosition,
-				      EPosition tabBarPosition,
-				      EPosition searchBarPosition )
-  : TQWidget( parent, name )
-{
-  mValid = false;
-
-  mEditor    = new CHexEditorWidget( this );
-  mTabBar    = new CTabBar( this );
-  mTabBar->hide();
-  mSearchBar = 0;
-
-  mConverter = new CHexToolWidget( this );
-
-  connect( mEditor->view(), TQT_SIGNAL(fileName(const TQString &, bool)),
-	   this, TQT_SLOT( addName(const TQString &)));
-  connect( mEditor->view(), TQT_SIGNAL( fileClosed(const TQString &)),
-	   this, TQT_SLOT( removeName(const TQString &)));
-  connect( mEditor->view(),TQT_SIGNAL(fileRename(const TQString &,const TQString &)),
-	   this, TQT_SLOT(changeName(const TQString &,const TQString &)));
-  connect( mEditor->view(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
-	   mConverter, TQT_SLOT( cursorChanged( SCursorState & ) ) );
-  connect( mConverter, TQT_SIGNAL( closed(void) ),
-	   this, TQT_SIGNAL( conversionClosed(void) ) );
-  connect( mTabBar, TQT_SIGNAL(selected(const TQString &)),
-	   this, TQT_SLOT(open(const TQString &)));
-
-  mValid = true;
-  setConversionVisibility( conversionPosition );
-  setTabBarPosition( tabBarPosition );
-  setSearchBarPosition( searchBarPosition );
-}
-
-
-CHexManagerWidget::~CHexManagerWidget( void )
-{
-  delete mEditor;
-  delete mTabBar;
-  delete mConverter;
-}
-
-
-void CHexManagerWidget::updateLayout( void )
-{
-  if( mValid == false ) { return; }
-
-  delete layout();
-  TQVBoxLayout *vlay = new TQVBoxLayout( this, 0, 0 );
-
-  if( mSearchBar && mSearchBarPosition == AboveEditor )
-  {
-    vlay->addWidget( mSearchBar );
-  }
-
-  if( mTabPosition == AboveEditor )
-  {
-    vlay->addWidget( mTabBar );
-    vlay->addWidget( mEditor, 1 );
-  }
-  else
-  {
-    vlay->addWidget( mEditor, 1 );
-    vlay->addWidget( mTabBar );
-  }
-
-  if( mSearchBar && mSearchBarPosition == BelowEditor )
-  {
-    vlay->addWidget( mSearchBar );
-  }
-
-  if( mConversionPosition == Embed )
-  {
-    vlay->addWidget( mConverter );
-  }
-  vlay->activate(); // Required in this case
-}
-
-
-void CHexManagerWidget::setConversionVisibility( EConversionPosition position )
-{
-  if( mValid == false )
-  {
-    return;
-  }
-
-  if( mConversionPosition == position )
-  {
-    if( mConversionPosition == Float )
-    {
-      mConverter->raise();
-    }
-    return;
-  }
-
-  mConversionPosition = position;
-  if( mConversionPosition == Hide )
-  {
-    mConverter->hide();
-  }
-  else if( mConversionPosition == Float )
-  {
-    TQPoint point = mapToGlobal( TQPoint(0,0) );
-    TQRect  rect  = geometry();
-    TQPoint p;
-
-    p.setX(point.x() + rect.width()/2 - mConverter->minimumSize().width()/2);
-    p.setY(point.y() + rect.height()/2 - mConverter->minimumSize().height()/2);
-    mConverter->resize( mConverter->minimumSize() );
-    mConverter->reparent( 0, WStyle_Customize | WStyle_DialogBorder, p, true );
-    mConverter->setCaption(kapp->makeStdCaption(i18n("Conversion")));
-  }
-  else
-  {
-    mConversionPosition = Embed;
-    uint utilHeight = mConverter->minimumSize().height();
-    TQPoint p( 0, height() - utilHeight );
-    mConverter->reparent( this, 0, p, true );
-  }
-
-  updateLayout();
-}
-
-
-void CHexManagerWidget::setTabBarPosition( EPosition position )
-{
-  mTabPosition = position;
-  if( mTabPosition != HideItem && mTabBar->count() > 0 )
-  {
-    if( mTabPosition == AboveEditor )
-    {
-      mTabBar->setShape( TQTabBar::RoundedAbove );
-    }
-    else
-    {
-      mTabBar->setShape( TQTabBar::RoundedBelow );
-    }
-    mTabBar->show();
-  }
-  else
-  {
-    mTabBar->hide();
-  }
-
-  updateLayout();
-}
-
-
-void CHexManagerWidget::setSearchBarPosition( EPosition position )
-{
-  mSearchBarPosition = position;
-  if( position != HideItem )
-  {
-    if( mSearchBar == 0 )
-    {
-      mSearchBar = new CSearchBar( this );
-      connect( mSearchBar, TQT_SIGNAL(hidden()), this, TQT_SLOT(searchBarHidden()) );
-      connect( mSearchBar, TQT_SIGNAL(findData(SSearchControl &, uint, bool)),
-	       mEditor, TQT_SLOT(findData(SSearchControl &, uint, bool)) );
-      connect( editor()->view(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
-	       mSearchBar, TQT_SLOT( cursorMoved() ) );
-    }
-    mSearchBar->show();
-  }
-  else
-  {
-    if( mSearchBar != 0 )
-    {
-      mSearchBar->hide();
-    }
-  }
-
-  updateLayout();
-}
-
-
-void CHexManagerWidget::searchBarHidden( void )
-{
-  updateLayout();
-  mSearchBarPosition = HideItem;
-  emit searchBarClosed();
-}
-
-
-void CHexManagerWidget::addName( const TQString &name )
-{
-  if( name.isEmpty() == true )
-  {
-    return;
-  }
-
-  mTabBar->addName( name );
-  if( mTabBar->isVisible() == false && mTabPosition != HideItem )
-  {
-    setTabBarPosition( mTabPosition );
-  }
-}
-
-
-void CHexManagerWidget::removeName( const TQString &name )
-{
-  mTabBar->removeName( name );
-  if( mTabBar->isVisible() == true && mTabBar->count() == 0 )
-  {
-    setTabBarPosition( mTabPosition );
-  }
-}
-
-
-void CHexManagerWidget::changeName( const TQString &curName,
-				    const TQString &newName )
-{
-  mTabBar->changeName( curName, newName );
-}
-
-
-void CHexManagerWidget::open( const TQString &name )
-{
-  mEditor->open( name, false, 0 );
-}
-
-
-int CHexManagerWidget::preferredWidth( void )
-{
-  int w = mEditor->defaultTextWidth();
-  if( mConversionPosition == Embed )
-  {
-    int converterWidth = mConverter->sizeHint().width();
-    w = TQMAX( w, converterWidth );
-  }
-  return( w );
-}
-
-
-
-CTabBar::CTabBar( TQWidget *parent, char *name )
-  :TQTabBar( parent, name )
-{
-  connect( this, TQT_SIGNAL(selected(int)), this, TQT_SLOT(slotSelected(int)) );
-}
-
-
-void CTabBar::addName( const TQString &name )
-{
-  TQString n( name.right(name.length()-name.findRev('/')-1) );
-
-  TQTab *t = find( n );
-  if( t == 0 )
-  {
-    t = new TQTab();
-    t->setText( n);
-    int id = addTab( t );
-    mFileList.append( CFileKey(name,id) );
-  }
-  setCurrentTab(t);
-}
-
-
-void CTabBar::removeName( const TQString &name )
-{
-  TQString n( name.right(name.length()-name.findRev('/')-1) );
-  TQTab *t = find(n);
-  if( t == 0 )
-  {
-    return;
-  }
-
-  TQValueList<CFileKey>::Iterator it;
-  for( it = mFileList.begin(); it != mFileList.end(); ++it )
-  {
-    if( (*it).id() == t->identifier() )
-    {
-      mFileList.remove(it);
-      removeTab(t);
-      layoutTabs();
-      break;
-    }
-  }
-}
-
-
-void CTabBar::changeName( const TQString &curName, const TQString &newName )
-{
-  TQString n( curName.right(curName.length()-curName.findRev('/')-1) );
-  TQTab *t = find(n);
-  if( t == 0 )
-  {
-    return;
-  }
-
-  TQValueList<CFileKey>::Iterator it;
-  for( it = mFileList.begin(); it != mFileList.end(); ++it )
-  {
-    if( (*it).id() == t->identifier() )
-    {
-      TQString m( newName.right(newName.length()-newName.findRev('/')-1) );
-      t->setText(m);
-
-      mFileList.remove(it);
-      mFileList.append( CFileKey(newName,t->identifier()) );
-      layoutTabs();
-      update(); // Seems to be necessary
-      break;
-    }
-  }
-}
-
-
-TQTab *CTabBar::find( const TQString &name )
-{
-  TQPtrList<TQTab> &list = *tabList();
-  for( TQTab *t = list.first(); t != 0; t = list.next() )
-  {
-    if( t->text() == name )
-    {
-      return( t );
-    }
-  }
-
-  return( 0 );
-}
-
-
-int CTabBar::count( void )
-{
-  return( tabList()->count() );
-}
-
-
-void CTabBar::slotSelected( int id )
-{
-  TQValueList<CFileKey>::Iterator it;
-  for( it = mFileList.begin(); it != mFileList.end(); ++it )
-  {
-    if( (*it).id() == id )
-    {
-      emit selected( (*it).filename() );
-    }
-  }
-}
-
-
-
-
-#include "hexmanagerwidget.moc"
diff --git a/khexedit/hexmanagerwidget.cpp b/khexedit/hexmanagerwidget.cpp
new file mode 100644
index 00000000..a8d4bedc
--- /dev/null
+++ b/khexedit/hexmanagerwidget.cpp
@@ -0,0 +1,370 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <tdelocale.h>
+#include <tqlayout.h>
+#include "hexmanagerwidget.h"
+#include "searchbar.h"
+
+CHexManagerWidget::CHexManagerWidget( TQWidget *parent, const char *name,
+				      EConversionPosition conversionPosition,
+				      EPosition tabBarPosition,
+				      EPosition searchBarPosition )
+  : TQWidget( parent, name )
+{
+  mValid = false;
+
+  mEditor    = new CHexEditorWidget( this );
+  mTabBar    = new CTabBar( this );
+  mTabBar->hide();
+  mSearchBar = 0;
+
+  mConverter = new CHexToolWidget( this );
+
+  connect( mEditor->view(), TQT_SIGNAL(fileName(const TQString &, bool)),
+	   this, TQT_SLOT( addName(const TQString &)));
+  connect( mEditor->view(), TQT_SIGNAL( fileClosed(const TQString &)),
+	   this, TQT_SLOT( removeName(const TQString &)));
+  connect( mEditor->view(),TQT_SIGNAL(fileRename(const TQString &,const TQString &)),
+	   this, TQT_SLOT(changeName(const TQString &,const TQString &)));
+  connect( mEditor->view(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
+	   mConverter, TQT_SLOT( cursorChanged( SCursorState & ) ) );
+  connect( mConverter, TQT_SIGNAL( closed(void) ),
+	   this, TQT_SIGNAL( conversionClosed(void) ) );
+  connect( mTabBar, TQT_SIGNAL(selected(const TQString &)),
+	   this, TQT_SLOT(open(const TQString &)));
+
+  mValid = true;
+  setConversionVisibility( conversionPosition );
+  setTabBarPosition( tabBarPosition );
+  setSearchBarPosition( searchBarPosition );
+}
+
+
+CHexManagerWidget::~CHexManagerWidget( void )
+{
+  delete mEditor;
+  delete mTabBar;
+  delete mConverter;
+}
+
+
+void CHexManagerWidget::updateLayout( void )
+{
+  if( mValid == false ) { return; }
+
+  delete layout();
+  TQVBoxLayout *vlay = new TQVBoxLayout( this, 0, 0 );
+
+  if( mSearchBar && mSearchBarPosition == AboveEditor )
+  {
+    vlay->addWidget( mSearchBar );
+  }
+
+  if( mTabPosition == AboveEditor )
+  {
+    vlay->addWidget( mTabBar );
+    vlay->addWidget( mEditor, 1 );
+  }
+  else
+  {
+    vlay->addWidget( mEditor, 1 );
+    vlay->addWidget( mTabBar );
+  }
+
+  if( mSearchBar && mSearchBarPosition == BelowEditor )
+  {
+    vlay->addWidget( mSearchBar );
+  }
+
+  if( mConversionPosition == Embed )
+  {
+    vlay->addWidget( mConverter );
+  }
+  vlay->activate(); // Required in this case
+}
+
+
+void CHexManagerWidget::setConversionVisibility( EConversionPosition position )
+{
+  if( mValid == false )
+  {
+    return;
+  }
+
+  if( mConversionPosition == position )
+  {
+    if( mConversionPosition == Float )
+    {
+      mConverter->raise();
+    }
+    return;
+  }
+
+  mConversionPosition = position;
+  if( mConversionPosition == Hide )
+  {
+    mConverter->hide();
+  }
+  else if( mConversionPosition == Float )
+  {
+    TQPoint point = mapToGlobal( TQPoint(0,0) );
+    TQRect  rect  = geometry();
+    TQPoint p;
+
+    p.setX(point.x() + rect.width()/2 - mConverter->minimumSize().width()/2);
+    p.setY(point.y() + rect.height()/2 - mConverter->minimumSize().height()/2);
+    mConverter->resize( mConverter->minimumSize() );
+    mConverter->reparent( 0, WStyle_Customize | WStyle_DialogBorder, p, true );
+    mConverter->setCaption(kapp->makeStdCaption(i18n("Conversion")));
+  }
+  else
+  {
+    mConversionPosition = Embed;
+    uint utilHeight = mConverter->minimumSize().height();
+    TQPoint p( 0, height() - utilHeight );
+    mConverter->reparent( this, 0, p, true );
+  }
+
+  updateLayout();
+}
+
+
+void CHexManagerWidget::setTabBarPosition( EPosition position )
+{
+  mTabPosition = position;
+  if( mTabPosition != HideItem && mTabBar->count() > 0 )
+  {
+    if( mTabPosition == AboveEditor )
+    {
+      mTabBar->setShape( TQTabBar::RoundedAbove );
+    }
+    else
+    {
+      mTabBar->setShape( TQTabBar::RoundedBelow );
+    }
+    mTabBar->show();
+  }
+  else
+  {
+    mTabBar->hide();
+  }
+
+  updateLayout();
+}
+
+
+void CHexManagerWidget::setSearchBarPosition( EPosition position )
+{
+  mSearchBarPosition = position;
+  if( position != HideItem )
+  {
+    if( mSearchBar == 0 )
+    {
+      mSearchBar = new CSearchBar( this );
+      connect( mSearchBar, TQT_SIGNAL(hidden()), this, TQT_SLOT(searchBarHidden()) );
+      connect( mSearchBar, TQT_SIGNAL(findData(SSearchControl &, uint, bool)),
+	       mEditor, TQT_SLOT(findData(SSearchControl &, uint, bool)) );
+      connect( editor()->view(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
+	       mSearchBar, TQT_SLOT( cursorMoved() ) );
+    }
+    mSearchBar->show();
+  }
+  else
+  {
+    if( mSearchBar != 0 )
+    {
+      mSearchBar->hide();
+    }
+  }
+
+  updateLayout();
+}
+
+
+void CHexManagerWidget::searchBarHidden( void )
+{
+  updateLayout();
+  mSearchBarPosition = HideItem;
+  emit searchBarClosed();
+}
+
+
+void CHexManagerWidget::addName( const TQString &name )
+{
+  if( name.isEmpty() == true )
+  {
+    return;
+  }
+
+  mTabBar->addName( name );
+  if( mTabBar->isVisible() == false && mTabPosition != HideItem )
+  {
+    setTabBarPosition( mTabPosition );
+  }
+}
+
+
+void CHexManagerWidget::removeName( const TQString &name )
+{
+  mTabBar->removeName( name );
+  if( mTabBar->isVisible() == true && mTabBar->count() == 0 )
+  {
+    setTabBarPosition( mTabPosition );
+  }
+}
+
+
+void CHexManagerWidget::changeName( const TQString &curName,
+				    const TQString &newName )
+{
+  mTabBar->changeName( curName, newName );
+}
+
+
+void CHexManagerWidget::open( const TQString &name )
+{
+  mEditor->open( name, false, 0 );
+}
+
+
+int CHexManagerWidget::preferredWidth( void )
+{
+  int w = mEditor->defaultTextWidth();
+  if( mConversionPosition == Embed )
+  {
+    int converterWidth = mConverter->sizeHint().width();
+    w = TQMAX( w, converterWidth );
+  }
+  return( w );
+}
+
+
+
+CTabBar::CTabBar( TQWidget *parent, char *name )
+  :TQTabBar( parent, name )
+{
+  connect( this, TQT_SIGNAL(selected(int)), this, TQT_SLOT(slotSelected(int)) );
+}
+
+
+void CTabBar::addName( const TQString &name )
+{
+  TQString n( name.right(name.length()-name.findRev('/')-1) );
+
+  TQTab *t = find( n );
+  if( t == 0 )
+  {
+    t = new TQTab();
+    t->setText( n);
+    int id = addTab( t );
+    mFileList.append( CFileKey(name,id) );
+  }
+  setCurrentTab(t);
+}
+
+
+void CTabBar::removeName( const TQString &name )
+{
+  TQString n( name.right(name.length()-name.findRev('/')-1) );
+  TQTab *t = find(n);
+  if( t == 0 )
+  {
+    return;
+  }
+
+  TQValueList<CFileKey>::Iterator it;
+  for( it = mFileList.begin(); it != mFileList.end(); ++it )
+  {
+    if( (*it).id() == t->identifier() )
+    {
+      mFileList.remove(it);
+      removeTab(t);
+      layoutTabs();
+      break;
+    }
+  }
+}
+
+
+void CTabBar::changeName( const TQString &curName, const TQString &newName )
+{
+  TQString n( curName.right(curName.length()-curName.findRev('/')-1) );
+  TQTab *t = find(n);
+  if( t == 0 )
+  {
+    return;
+  }
+
+  TQValueList<CFileKey>::Iterator it;
+  for( it = mFileList.begin(); it != mFileList.end(); ++it )
+  {
+    if( (*it).id() == t->identifier() )
+    {
+      TQString m( newName.right(newName.length()-newName.findRev('/')-1) );
+      t->setText(m);
+
+      mFileList.remove(it);
+      mFileList.append( CFileKey(newName,t->identifier()) );
+      layoutTabs();
+      update(); // Seems to be necessary
+      break;
+    }
+  }
+}
+
+
+TQTab *CTabBar::find( const TQString &name )
+{
+  TQPtrList<TQTab> &list = *tabList();
+  for( TQTab *t = list.first(); t != 0; t = list.next() )
+  {
+    if( t->text() == name )
+    {
+      return( t );
+    }
+  }
+
+  return( 0 );
+}
+
+
+int CTabBar::count( void )
+{
+  return( tabList()->count() );
+}
+
+
+void CTabBar::slotSelected( int id )
+{
+  TQValueList<CFileKey>::Iterator it;
+  for( it = mFileList.begin(); it != mFileList.end(); ++it )
+  {
+    if( (*it).id() == id )
+    {
+      emit selected( (*it).filename() );
+    }
+  }
+}
+
+
+
+
+#include "hexmanagerwidget.moc"
diff --git a/khexedit/hexprinter.cc b/khexedit/hexprinter.cc
deleted file mode 100644
index 2d55a6af..00000000
--- a/khexedit/hexprinter.cc
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-
-#include "hexprinter.h"
-
-
-CHexPrinter::CHexPrinter( void )
-  : KPrinter()
-{
-}
-
-
-void CHexPrinter::setPageMarginMM( uint top, uint bottom, int right, int left )
-{
-  mPageMargin.top = top;
-  mPageMargin.left = left;
-  mPageMargin.bottom = bottom;
-  mPageMargin.right = right;
-}
-
-void CHexPrinter::setTopMarginMM( uint value )
-{
-  mPageMargin.top = value;
-}
-
-void CHexPrinter::setLeftMarginMM( uint value )
-{
-  mPageMargin.left = value;
-}
-
-void CHexPrinter::setBottomMarginMM( uint value )
-{
-  mPageMargin.bottom = value;
-}
-
-void CHexPrinter::setRightMarginMM( uint value )
-{
-  mPageMargin.right = value;
-}
-
-
-
-void CHexPrinter::setPageHeader( bool enable, uint left, uint center, 
-				 uint right, uint line )
-{
-  if( left > SPageHeader::FileName ) { left = SPageHeader::NoString; }
-  if( center > SPageHeader::FileName ) { center = SPageHeader::NoString; }
-  if( right > SPageHeader::FileName ) { right = SPageHeader::NoString; }
-  if( line > SPageHeader::Rectangle ) { line = SPageHeader::NoLine; }
-
-  mHeader.enable = enable;
-  mHeader.pos[0] = (SPageHeader::EHeaderString)left; 
-  mHeader.pos[1] = (SPageHeader::EHeaderString)center;
-  mHeader.pos[2] = (SPageHeader::EHeaderString)right;
-  mHeader.line = (SPageHeader::EHeaderLine)line;
-
-  if( mHeader.pos[0] == SPageHeader::NoString && 
-      mHeader.pos[1] == SPageHeader::NoString &&
-      mHeader.pos[2] == SPageHeader::NoString &&
-      mHeader.line == SPageHeader::NoLine )
-  {
-    mHeader.enable = false;
-  }
-}
-
-void CHexPrinter::setPageFooter( bool enable, uint left, uint center, 
-				 uint right, uint line )
-{
-  if( left > SPageHeader::FileName ) { left = SPageHeader::NoString; }
-  if( center > SPageHeader::FileName ) { center = SPageHeader::NoString; }
-  if( right > SPageHeader::FileName ) { right = SPageHeader::NoString; }
-  if( line > SPageHeader::Rectangle ) { line = SPageHeader::NoLine; }
-
-  mFooter.enable = enable;
-  mFooter.pos[0] = (SPageHeader::EHeaderString)left;
-  mFooter.pos[1] = (SPageHeader::EHeaderString)center;
-  mFooter.pos[2] = (SPageHeader::EHeaderString)right;
-  mFooter.line = (SPageHeader::EHeaderLine)line;
-
-  if( mFooter.pos[0] == SPageHeader::NoString && 
-      mFooter.pos[1] == SPageHeader::NoString &&
-      mFooter.pos[2] == SPageHeader::NoString &&
-      mFooter.line == SPageHeader::NoLine )
-  {
-    mFooter.enable = false;
-  }
-}
-
-
-SPageMargin CHexPrinter::pageMargin( void )
-{
-  TQPaintDeviceMetrics metric( this );
-  float f = (float)metric.width()/(float)metric.widthMM();
-    
-  SPageMargin margin;
-  margin.top = (uint) (f*(float)mPageMargin.top);
-  margin.right = (uint) (f*(float)mPageMargin.right);
-  margin.bottom = (uint) (f*(float)mPageMargin.bottom);
-  margin.left = (uint) (f*(float)mPageMargin.left);
-
-  return( margin );
-}
-
-
-SPageMargin CHexPrinter::pageMarginMM( void )
-{
-  return( mPageMargin );
-}
-
-
-SPageSize CHexPrinter::pageFullSize( void )
-{
-  TQPaintDeviceMetrics metric( this );
-  SPageSize size;
-  size.width = metric.width();
-  size.height = metric.height();
-  
-  return( size );
-}
-
-
-SPageSize CHexPrinter::pageUsableSize( void )
-{
-  TQPaintDeviceMetrics metric( this );
-  SPageMargin margin = pageMargin();
-  SPageSize size;
-
-  uint mw = margin.left + margin.right;
-  if( metric.width() <= (int)mw )
-  {
-    size.width = 1;
-  }
-  else
-  {
-    size.width = metric.width() - mw;
-  }
-
-  uint mh = margin.top + margin.bottom;
-  if( metric.height() <= (int)mh )
-  {
-    size.height = 1;
-  }
-  else
-  {
-    size.height = metric.height() - mh;
-  }
-
-  return( size );
-}
-
diff --git a/khexedit/hexprinter.cpp b/khexedit/hexprinter.cpp
new file mode 100644
index 00000000..2d55a6af
--- /dev/null
+++ b/khexedit/hexprinter.cpp
@@ -0,0 +1,168 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+
+#include "hexprinter.h"
+
+
+CHexPrinter::CHexPrinter( void )
+  : KPrinter()
+{
+}
+
+
+void CHexPrinter::setPageMarginMM( uint top, uint bottom, int right, int left )
+{
+  mPageMargin.top = top;
+  mPageMargin.left = left;
+  mPageMargin.bottom = bottom;
+  mPageMargin.right = right;
+}
+
+void CHexPrinter::setTopMarginMM( uint value )
+{
+  mPageMargin.top = value;
+}
+
+void CHexPrinter::setLeftMarginMM( uint value )
+{
+  mPageMargin.left = value;
+}
+
+void CHexPrinter::setBottomMarginMM( uint value )
+{
+  mPageMargin.bottom = value;
+}
+
+void CHexPrinter::setRightMarginMM( uint value )
+{
+  mPageMargin.right = value;
+}
+
+
+
+void CHexPrinter::setPageHeader( bool enable, uint left, uint center, 
+				 uint right, uint line )
+{
+  if( left > SPageHeader::FileName ) { left = SPageHeader::NoString; }
+  if( center > SPageHeader::FileName ) { center = SPageHeader::NoString; }
+  if( right > SPageHeader::FileName ) { right = SPageHeader::NoString; }
+  if( line > SPageHeader::Rectangle ) { line = SPageHeader::NoLine; }
+
+  mHeader.enable = enable;
+  mHeader.pos[0] = (SPageHeader::EHeaderString)left; 
+  mHeader.pos[1] = (SPageHeader::EHeaderString)center;
+  mHeader.pos[2] = (SPageHeader::EHeaderString)right;
+  mHeader.line = (SPageHeader::EHeaderLine)line;
+
+  if( mHeader.pos[0] == SPageHeader::NoString && 
+      mHeader.pos[1] == SPageHeader::NoString &&
+      mHeader.pos[2] == SPageHeader::NoString &&
+      mHeader.line == SPageHeader::NoLine )
+  {
+    mHeader.enable = false;
+  }
+}
+
+void CHexPrinter::setPageFooter( bool enable, uint left, uint center, 
+				 uint right, uint line )
+{
+  if( left > SPageHeader::FileName ) { left = SPageHeader::NoString; }
+  if( center > SPageHeader::FileName ) { center = SPageHeader::NoString; }
+  if( right > SPageHeader::FileName ) { right = SPageHeader::NoString; }
+  if( line > SPageHeader::Rectangle ) { line = SPageHeader::NoLine; }
+
+  mFooter.enable = enable;
+  mFooter.pos[0] = (SPageHeader::EHeaderString)left;
+  mFooter.pos[1] = (SPageHeader::EHeaderString)center;
+  mFooter.pos[2] = (SPageHeader::EHeaderString)right;
+  mFooter.line = (SPageHeader::EHeaderLine)line;
+
+  if( mFooter.pos[0] == SPageHeader::NoString && 
+      mFooter.pos[1] == SPageHeader::NoString &&
+      mFooter.pos[2] == SPageHeader::NoString &&
+      mFooter.line == SPageHeader::NoLine )
+  {
+    mFooter.enable = false;
+  }
+}
+
+
+SPageMargin CHexPrinter::pageMargin( void )
+{
+  TQPaintDeviceMetrics metric( this );
+  float f = (float)metric.width()/(float)metric.widthMM();
+    
+  SPageMargin margin;
+  margin.top = (uint) (f*(float)mPageMargin.top);
+  margin.right = (uint) (f*(float)mPageMargin.right);
+  margin.bottom = (uint) (f*(float)mPageMargin.bottom);
+  margin.left = (uint) (f*(float)mPageMargin.left);
+
+  return( margin );
+}
+
+
+SPageMargin CHexPrinter::pageMarginMM( void )
+{
+  return( mPageMargin );
+}
+
+
+SPageSize CHexPrinter::pageFullSize( void )
+{
+  TQPaintDeviceMetrics metric( this );
+  SPageSize size;
+  size.width = metric.width();
+  size.height = metric.height();
+  
+  return( size );
+}
+
+
+SPageSize CHexPrinter::pageUsableSize( void )
+{
+  TQPaintDeviceMetrics metric( this );
+  SPageMargin margin = pageMargin();
+  SPageSize size;
+
+  uint mw = margin.left + margin.right;
+  if( metric.width() <= (int)mw )
+  {
+    size.width = 1;
+  }
+  else
+  {
+    size.width = metric.width() - mw;
+  }
+
+  uint mh = margin.top + margin.bottom;
+  if( metric.height() <= (int)mh )
+  {
+    size.height = 1;
+  }
+  else
+  {
+    size.height = metric.height() - mh;
+  }
+
+  return( size );
+}
+
diff --git a/khexedit/hextoolwidget.cc b/khexedit/hextoolwidget.cc
deleted file mode 100644
index ef66db26..00000000
--- a/khexedit/hextoolwidget.cc
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <kdialog.h>
-#include <tdelocale.h>
-
-#include "hextoolwidget.h"
-#include <tqlabel.h>
-#include <tqlayout.h>
-#include <tqlineedit.h>
-#include <tqcheckbox.h>
-#include <tqcombobox.h>
-
-
-CHexToolWidget::CHexToolWidget( TQWidget *parent, const char *name )
-  : TQFrame( parent, name )
-{
-  setFrameStyle( TQFrame::Panel | TQFrame::Raised );
-  setLineWidth( 1 );
-
-  TQString text;
-  mUtilBox = new TQGridLayout( this, 5, 4, KDialog::marginHint(), KDialog::spacingHint() );
-  mUtilBox->setColStretch( 3, 10 );
-
-  TQString msg1[4] =
-  {
-    i18n("Signed 8 bit:"), i18n("Unsigned 8 bit:"),
-    i18n("Signed 16 bit:"), i18n("Unsigned 16 bit:")
-  };
-
-  TQString msg2[4] =
-  {
-    i18n("Signed 32 bit:"), i18n("Unsigned 32 bit:"),
-    i18n("32 bit float:"), i18n("64 bit float:")
-  };
-
-  TQString msg3[4] =
-  {
-    i18n("Hexadecimal:"), i18n("Octal:"),
-    i18n("Binary:"), i18n("Text:")
-  };
-
-  TQGridLayout *ValuesBox = new TQGridLayout( NULL, 4, 6, 0, KDialog::spacingHint() );
-  ValuesBox->setColStretch( 2, 10 );
-  ValuesBox->setColStretch( 5, 10 );
-
-  for( int i=0; i<4; i++ )
-  {
-    TQLabel *Label = new TQLabel( msg1[i], this );
-    Label->setAlignment( AlignRight|AlignVCenter );
-    ValuesBox->addWidget( Label, i, 0 );
-
-    mText1[i] = new TQLineEdit( this );
-    mText1[i]->setReadOnly( true );
-    mText1[i]->setAlignment( AlignRight );
-    ValuesBox->addWidget( mText1[i], i, 1 );
-
-    Label = new TQLabel( msg2[i], this );
-    Label->setAlignment( AlignRight|AlignVCenter );
-    ValuesBox->addWidget( Label, i, 3 );
-
-    mText2[i] = new TQLineEdit( this );
-    mText2[i]->setReadOnly( true );
-    mText2[i]->setAlignment( AlignRight );
-    ValuesBox->addWidget( mText2[i], i, 4 );
-
-    Label = new TQLabel( msg3[i], this );
-    Label->setAlignment( AlignRight|AlignVCenter );
-    mUtilBox->addWidget( Label, i, 1 );
-
-    mText3[i] = new TQLineEdit( this );
-    mText3[i]->setReadOnly( true );
-    mText3[i]->setAlignment( AlignRight );
-    mUtilBox->addWidget( mText3[i], i, 2 );
-  }
-
-  TQBoxLayout * SettingsBox = new TQHBoxLayout( NULL, 0, KDialog::spacingHint() );
-
-  text = i18n("Show little endian decoding");
-  mCheckIntelFormat = new TQCheckBox( text, this );
-  mCheckIntelFormat->setMinimumSize( mCheckIntelFormat->sizeHint() );
-  connect( mCheckIntelFormat, TQT_SIGNAL(clicked()), this, TQT_SLOT(intelFormat()) );
-  SettingsBox->addWidget( mCheckIntelFormat, 0, AlignVCenter );
-  mCheckIntelFormat->setChecked( // default value to please endian system users
-#ifdef WORDS_BIGENDIAN
-    false   // Big Endian: SUN, Motorola machines (amongst others)
-#else
-    true    // Little Endian: Intel, Alpha
-#endif
-  );
-  // TODO: make this a pulldown box, adding PDP endianess
-
-  text = i18n("Show unsigned as hexadecimal");
-  mCheckHexadecimal = new TQCheckBox( text, this );
-  mCheckHexadecimal->setMinimumSize( mCheckHexadecimal->sizeHint() );
-  connect( mCheckHexadecimal, TQT_SIGNAL(clicked()), this, TQT_SLOT(unsignedFormat()) );
-  SettingsBox->addWidget( mCheckHexadecimal, 0, AlignVCenter );
-
-  mUtilBox->addMultiCellLayout( ValuesBox,   0, 3, 0, 0, AlignLeft|AlignVCenter );
-  mUtilBox->addMultiCellLayout( SettingsBox, 4, 4, 0, 0, AlignLeft|AlignVCenter );
-
-  //
-  // Variable bitwidth. Based on Craig Graham's work.
-  //
-  TQLabel *bitLabel = new TQLabel( i18n("Stream length:"), this );
-  bitLabel->setAlignment( AlignRight|AlignVCenter );
-  mUtilBox->addWidget( bitLabel, 4, 1 );
-
-  mBitCombo = new TQComboBox( false, this );
-  text = i18n("Fixed 8 Bit" );
-  mBitCombo->insertItem( text );
-  for( int i=0; i<16; i++ )
-  {
-    text.sprintf("%u ", i+1 );
-    text += i==0 ? i18n("Bit Window") : i18n("Bits Window");
-    mBitCombo->insertItem( text );
-  }
-  mBitCombo->setMinimumSize( mBitCombo->sizeHint() );
-  connect( mBitCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(bitWidthChanged(int)));
-  mUtilBox->addWidget( mBitCombo, 4, 2 );
-
-	/* load font metrics */
-	fontChanged();
-
-  mUtilBox->activate();
-
-  connect( kapp, TQT_SIGNAL( tdedisplayFontChanged() ),
-	   TQT_SLOT( fontChanged() ) );
-
-  mCursorState.valid = false;
-  mViewHexCaps = true;
-
-  setMinimumSize( sizeHint() );
-  show();
-}
-
-
-CHexToolWidget::~CHexToolWidget( void )
-{
-}
-
-
-void CHexToolWidget::writeConfiguration( TDEConfig &config )
-{
-  config.setGroup("Conversion" );
-  config.writeEntry("LittleEndian",  mCheckIntelFormat->isChecked() );
-  config.writeEntry("UnsignedAsHex", mCheckHexadecimal->isChecked() );
-  config.writeEntry("StreamWindow", mBitCombo->currentItem() );
-}
-
-void CHexToolWidget::readConfiguration( TDEConfig &config )
-{
-  config.setGroup("Conversion" );
-  bool s1  = config.readBoolEntry( "LittleEndian", true );
-  bool s2  = config.readBoolEntry( "UnsignedAsHex", false );
-  int  val = config.readNumEntry( "StreamWindow", 0 );
-
-  mCheckIntelFormat->setChecked( s1 );
-  mCheckHexadecimal->setChecked( s2 );
-  mBitCombo->setCurrentItem( val );
-}
-
-//++cg[6/7/1999]: handler for change signal from bit width combo
-void CHexToolWidget::bitWidthChanged( int /*i*/ )
-{
-  cursorChanged( mCursorState );
-}
-
-
-//
-// Variable bitwidth. Based on Craig Graham's work.
-//
-// ++cg[6/7/1999]: Read n bit's from a bitstream (allows N length bit
-// values to cross byte boundarys).
-//
-unsigned long CHexToolWidget::bitValue( SCursorState &state, int n )
-{
-  static const unsigned char bitmask[9] =
-  {
-    0, 1<<7, 3<<6, 7<<5, 15<<4, 31<<3, 63<<2, 127<<1, 255
-  };
-
-  unsigned long rtn = 0;
-  unsigned char *byte = state.data;
-  int bit = 7 - state.cell;
-
-  while( n )
-  {
-    //
-    // c hold's current byte, shifted to put remaining bits in
-    // high bits of byte
-    //
-    unsigned char c = *byte << bit;
-
-    //
-    // if there are n bits or more remaining in this byte, we
-    // swallow n bits, otherwise we swallow as many
-    // bits as we can (8-bit)
-    //
-    int this_time = ((8-bit)>=n)?n:(8-bit);
-
-    //
-    // mask to get only the bit's we're swallowing
-    //
-    c &= bitmask[this_time];
-
-    //
-    // shift down to get bit's in low part of byte
-    //
-    c >>= 8-this_time;
-
-    //
-    // shift up previous results to make room and OR in the extracted bits.
-    //
-    rtn = (rtn<<this_time)|c;
-
-    n   -= this_time;  // update the count of remaining bits
-    bit += this_time;  // tell the stream we swallowed some swallowed bits
-
-    //
-    // if we've swallowed 8 bits, we zero the bit count and move on to
-    // the next byte
-    //
-    if( bit==8 )
-    {
-      bit=0;
-      byte++;
-    }
-  }
-
-  return( rtn );
-}
-
-
-void CHexToolWidget::cursorChanged( SCursorState &state )
-{
-  if( state.valid == true )
-  {
-    TQString buf;
-    // change by Kossebau[03.11.2003]:
-    // checking for system endianess, using the compiler for the byte interpretation and cutting bloaded code
-    // TODO: add PDP endianess
-    void *P8Bit, *P16Bit, *P32Bit, *P64Bit;
-    // ensure strict alignment for double as needed on some architectures (e.g. PA-RISC)
-    typedef union { unsigned char b[8]; double d; } aligned_t;
-    aligned_t Data;
-    if(
-#ifdef WORDS_BIGENDIAN
-        !  // Assume Big Endian. This is the case for SUN machines (amongst others)
-#else
-           // Assume Little Endian. This is the case for the Intel architecture.
-#endif
-         mCheckIntelFormat->isChecked() )
-    {
-      // take it as it is
-      memcpy( Data.b, state.data, 8 );
-      P8Bit = P16Bit = P32Bit = P64Bit = Data.b;
-    }
-    else
-    {
-      // reverse order
-      for( int i=0,j=7; i<8; ++i,--j )
-        Data.b[i] = state.data[j];
-
-      P8Bit =  &Data.b[7];
-      P16Bit = &Data.b[6];
-      P32Bit = &Data.b[4];
-      P64Bit = Data.b;
-    }
-
-    bool NoHex = !mCheckHexadecimal->isChecked();
-
-    // unsigned 8 bit
-    buf.sprintf( NoHex?"%u":mViewHexCaps?"0x%02X":"0x%02x", *(unsigned char*)P8Bit );
-    mText1[1]->setText( buf );
-    // signed int 8 bit
-    buf.sprintf( "%d", *(signed char*)P8Bit );
-    mText1[0]->setText( buf );
-
-    // unsigned int 16 bit
-    buf.sprintf( NoHex?"%u":mViewHexCaps?"0x%04X":"0x%04x", *(unsigned short*)P16Bit );
-    mText1[3]->setText( buf );
-    // signed int 16 bit
-    buf.sprintf( "%d", *(short*)P16Bit );
-    mText1[2]->setText( buf );
-
-    // unsigned int 32 bit
-    buf.sprintf( NoHex?"%u":mViewHexCaps?"0x%08X":"0x%08x", *(unsigned int*)P32Bit );
-    mText2[1]->setText( buf );
-    // signed int 32 bit
-    buf.sprintf( "%d", *(int*)P32Bit );
-    mText2[0]->setText( buf );
-
-    // float 32 bit
-    buf.sprintf( "%E", *(float*)P32Bit );
-    mText2[2]->setText( buf );
-    // float 64 bit
-    buf.sprintf( "%E", *(double*)P64Bit );
-    mText2[3]->setText( buf );
-
-    int numBits = mBitCombo->currentItem();
-    if( numBits == 0 )
-    {
-      //
-      // This is the original stuff
-      //
-      unsigned char data = (unsigned char)state.data[0];
-      buf.sprintf( mViewHexCaps?"%02X":"%02x", data );
-      mText3[0]->setText( buf );
-      buf.sprintf( "%03o", data );
-      mText3[1]->setText( buf );
-
-      char bitBuf[32];
-      for( int i = 0; i < 8; i++ )
-        bitBuf[7-i] = (data&(1<<i)) ? '1' : '0';
-
-      bitBuf[8] = 0;
-      mText3[2]->setText( TQString(bitBuf) );
-    }
-    else
-    {
-      //
-      // Variable bitwidth. Based on Craig Graham's work.
-      //
-      unsigned long data = bitValue( state, numBits );
-      buf.sprintf( mViewHexCaps?"%02lX %02lX":"%02lx %02lx", (data>>8)&0xFF, data&0xFF );
-      mText3[0]->setText( buf );
-      buf.sprintf( "%03lo %03lo", (data>>8)&0xFF, data&0xFF );
-      mText3[1]->setText( buf );
-      char bitBuf[32];
-      for( int i = 0; i<numBits; i++ )
-        bitBuf[numBits-i-1] = (data&(1L<<i)) ? '1' : '0';
-      bitBuf[numBits] = 0;
-      mText3[2]->setText( TQString(bitBuf) );
-    }
-
-    // Fix by Sergey A. Sukiyazov
-    unsigned char data[2] = { 0, 0 };
-    data[0] = state.charValid == false ? '.' :
-      (char)((unsigned char)state.data[0]&0xff );
-    buf = TQString::fromLocal8Bit( (const char *)data );
-
-    mText3[3]->setText( buf );
-  }
-  else
-  {
-    TQString str;
-    for( int i=0; i<4; i++)
-    {
-      mText1[i]->setText( str );
-      mText2[i]->setText( str );
-      mText3[i]->setText( str );
-    }
-  }
-
-  mCursorState = state;
-}
-
-
-void CHexToolWidget::fontChanged( void )
-{
-  TQFontMetrics fm( mText1[0]->font() );
-  int W1 = fm.width( "XXXXXXXX" );
-  int W2 = fm.width( "XXXXXXXXXXXX" );
-  int W3 = fm.width( "888888888888888888" );
-	for( int i=0; i<4; i++ )
-  {
-		mText1[i]->setFixedWidth( W1 );
-		mText2[i]->setFixedWidth( W2 );
-		mText3[i]->setFixedWidth( W3 );
-  }
-}
-
-
-void CHexToolWidget::intelFormat( void )
-{
-  cursorChanged( mCursorState );
-}
-
-
-void CHexToolWidget::unsignedFormat( void )
-{
-  cursorChanged( mCursorState );
-}
-
-
-void CHexToolWidget::resizeEvent( TQResizeEvent */*e*/ )
-{
-}
-
-
-
-void CHexToolWidget::closeEvent( TQCloseEvent *e )
-{
-  e->accept();
-  emit closed();
-}
-
-#include "hextoolwidget.moc"
diff --git a/khexedit/hextoolwidget.cpp b/khexedit/hextoolwidget.cpp
new file mode 100644
index 00000000..ef66db26
--- /dev/null
+++ b/khexedit/hextoolwidget.cpp
@@ -0,0 +1,416 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <kdialog.h>
+#include <tdelocale.h>
+
+#include "hextoolwidget.h"
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqlineedit.h>
+#include <tqcheckbox.h>
+#include <tqcombobox.h>
+
+
+CHexToolWidget::CHexToolWidget( TQWidget *parent, const char *name )
+  : TQFrame( parent, name )
+{
+  setFrameStyle( TQFrame::Panel | TQFrame::Raised );
+  setLineWidth( 1 );
+
+  TQString text;
+  mUtilBox = new TQGridLayout( this, 5, 4, KDialog::marginHint(), KDialog::spacingHint() );
+  mUtilBox->setColStretch( 3, 10 );
+
+  TQString msg1[4] =
+  {
+    i18n("Signed 8 bit:"), i18n("Unsigned 8 bit:"),
+    i18n("Signed 16 bit:"), i18n("Unsigned 16 bit:")
+  };
+
+  TQString msg2[4] =
+  {
+    i18n("Signed 32 bit:"), i18n("Unsigned 32 bit:"),
+    i18n("32 bit float:"), i18n("64 bit float:")
+  };
+
+  TQString msg3[4] =
+  {
+    i18n("Hexadecimal:"), i18n("Octal:"),
+    i18n("Binary:"), i18n("Text:")
+  };
+
+  TQGridLayout *ValuesBox = new TQGridLayout( NULL, 4, 6, 0, KDialog::spacingHint() );
+  ValuesBox->setColStretch( 2, 10 );
+  ValuesBox->setColStretch( 5, 10 );
+
+  for( int i=0; i<4; i++ )
+  {
+    TQLabel *Label = new TQLabel( msg1[i], this );
+    Label->setAlignment( AlignRight|AlignVCenter );
+    ValuesBox->addWidget( Label, i, 0 );
+
+    mText1[i] = new TQLineEdit( this );
+    mText1[i]->setReadOnly( true );
+    mText1[i]->setAlignment( AlignRight );
+    ValuesBox->addWidget( mText1[i], i, 1 );
+
+    Label = new TQLabel( msg2[i], this );
+    Label->setAlignment( AlignRight|AlignVCenter );
+    ValuesBox->addWidget( Label, i, 3 );
+
+    mText2[i] = new TQLineEdit( this );
+    mText2[i]->setReadOnly( true );
+    mText2[i]->setAlignment( AlignRight );
+    ValuesBox->addWidget( mText2[i], i, 4 );
+
+    Label = new TQLabel( msg3[i], this );
+    Label->setAlignment( AlignRight|AlignVCenter );
+    mUtilBox->addWidget( Label, i, 1 );
+
+    mText3[i] = new TQLineEdit( this );
+    mText3[i]->setReadOnly( true );
+    mText3[i]->setAlignment( AlignRight );
+    mUtilBox->addWidget( mText3[i], i, 2 );
+  }
+
+  TQBoxLayout * SettingsBox = new TQHBoxLayout( NULL, 0, KDialog::spacingHint() );
+
+  text = i18n("Show little endian decoding");
+  mCheckIntelFormat = new TQCheckBox( text, this );
+  mCheckIntelFormat->setMinimumSize( mCheckIntelFormat->sizeHint() );
+  connect( mCheckIntelFormat, TQT_SIGNAL(clicked()), this, TQT_SLOT(intelFormat()) );
+  SettingsBox->addWidget( mCheckIntelFormat, 0, AlignVCenter );
+  mCheckIntelFormat->setChecked( // default value to please endian system users
+#ifdef WORDS_BIGENDIAN
+    false   // Big Endian: SUN, Motorola machines (amongst others)
+#else
+    true    // Little Endian: Intel, Alpha
+#endif
+  );
+  // TODO: make this a pulldown box, adding PDP endianess
+
+  text = i18n("Show unsigned as hexadecimal");
+  mCheckHexadecimal = new TQCheckBox( text, this );
+  mCheckHexadecimal->setMinimumSize( mCheckHexadecimal->sizeHint() );
+  connect( mCheckHexadecimal, TQT_SIGNAL(clicked()), this, TQT_SLOT(unsignedFormat()) );
+  SettingsBox->addWidget( mCheckHexadecimal, 0, AlignVCenter );
+
+  mUtilBox->addMultiCellLayout( ValuesBox,   0, 3, 0, 0, AlignLeft|AlignVCenter );
+  mUtilBox->addMultiCellLayout( SettingsBox, 4, 4, 0, 0, AlignLeft|AlignVCenter );
+
+  //
+  // Variable bitwidth. Based on Craig Graham's work.
+  //
+  TQLabel *bitLabel = new TQLabel( i18n("Stream length:"), this );
+  bitLabel->setAlignment( AlignRight|AlignVCenter );
+  mUtilBox->addWidget( bitLabel, 4, 1 );
+
+  mBitCombo = new TQComboBox( false, this );
+  text = i18n("Fixed 8 Bit" );
+  mBitCombo->insertItem( text );
+  for( int i=0; i<16; i++ )
+  {
+    text.sprintf("%u ", i+1 );
+    text += i==0 ? i18n("Bit Window") : i18n("Bits Window");
+    mBitCombo->insertItem( text );
+  }
+  mBitCombo->setMinimumSize( mBitCombo->sizeHint() );
+  connect( mBitCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(bitWidthChanged(int)));
+  mUtilBox->addWidget( mBitCombo, 4, 2 );
+
+	/* load font metrics */
+	fontChanged();
+
+  mUtilBox->activate();
+
+  connect( kapp, TQT_SIGNAL( tdedisplayFontChanged() ),
+	   TQT_SLOT( fontChanged() ) );
+
+  mCursorState.valid = false;
+  mViewHexCaps = true;
+
+  setMinimumSize( sizeHint() );
+  show();
+}
+
+
+CHexToolWidget::~CHexToolWidget( void )
+{
+}
+
+
+void CHexToolWidget::writeConfiguration( TDEConfig &config )
+{
+  config.setGroup("Conversion" );
+  config.writeEntry("LittleEndian",  mCheckIntelFormat->isChecked() );
+  config.writeEntry("UnsignedAsHex", mCheckHexadecimal->isChecked() );
+  config.writeEntry("StreamWindow", mBitCombo->currentItem() );
+}
+
+void CHexToolWidget::readConfiguration( TDEConfig &config )
+{
+  config.setGroup("Conversion" );
+  bool s1  = config.readBoolEntry( "LittleEndian", true );
+  bool s2  = config.readBoolEntry( "UnsignedAsHex", false );
+  int  val = config.readNumEntry( "StreamWindow", 0 );
+
+  mCheckIntelFormat->setChecked( s1 );
+  mCheckHexadecimal->setChecked( s2 );
+  mBitCombo->setCurrentItem( val );
+}
+
+//++cg[6/7/1999]: handler for change signal from bit width combo
+void CHexToolWidget::bitWidthChanged( int /*i*/ )
+{
+  cursorChanged( mCursorState );
+}
+
+
+//
+// Variable bitwidth. Based on Craig Graham's work.
+//
+// ++cg[6/7/1999]: Read n bit's from a bitstream (allows N length bit
+// values to cross byte boundarys).
+//
+unsigned long CHexToolWidget::bitValue( SCursorState &state, int n )
+{
+  static const unsigned char bitmask[9] =
+  {
+    0, 1<<7, 3<<6, 7<<5, 15<<4, 31<<3, 63<<2, 127<<1, 255
+  };
+
+  unsigned long rtn = 0;
+  unsigned char *byte = state.data;
+  int bit = 7 - state.cell;
+
+  while( n )
+  {
+    //
+    // c hold's current byte, shifted to put remaining bits in
+    // high bits of byte
+    //
+    unsigned char c = *byte << bit;
+
+    //
+    // if there are n bits or more remaining in this byte, we
+    // swallow n bits, otherwise we swallow as many
+    // bits as we can (8-bit)
+    //
+    int this_time = ((8-bit)>=n)?n:(8-bit);
+
+    //
+    // mask to get only the bit's we're swallowing
+    //
+    c &= bitmask[this_time];
+
+    //
+    // shift down to get bit's in low part of byte
+    //
+    c >>= 8-this_time;
+
+    //
+    // shift up previous results to make room and OR in the extracted bits.
+    //
+    rtn = (rtn<<this_time)|c;
+
+    n   -= this_time;  // update the count of remaining bits
+    bit += this_time;  // tell the stream we swallowed some swallowed bits
+
+    //
+    // if we've swallowed 8 bits, we zero the bit count and move on to
+    // the next byte
+    //
+    if( bit==8 )
+    {
+      bit=0;
+      byte++;
+    }
+  }
+
+  return( rtn );
+}
+
+
+void CHexToolWidget::cursorChanged( SCursorState &state )
+{
+  if( state.valid == true )
+  {
+    TQString buf;
+    // change by Kossebau[03.11.2003]:
+    // checking for system endianess, using the compiler for the byte interpretation and cutting bloaded code
+    // TODO: add PDP endianess
+    void *P8Bit, *P16Bit, *P32Bit, *P64Bit;
+    // ensure strict alignment for double as needed on some architectures (e.g. PA-RISC)
+    typedef union { unsigned char b[8]; double d; } aligned_t;
+    aligned_t Data;
+    if(
+#ifdef WORDS_BIGENDIAN
+        !  // Assume Big Endian. This is the case for SUN machines (amongst others)
+#else
+           // Assume Little Endian. This is the case for the Intel architecture.
+#endif
+         mCheckIntelFormat->isChecked() )
+    {
+      // take it as it is
+      memcpy( Data.b, state.data, 8 );
+      P8Bit = P16Bit = P32Bit = P64Bit = Data.b;
+    }
+    else
+    {
+      // reverse order
+      for( int i=0,j=7; i<8; ++i,--j )
+        Data.b[i] = state.data[j];
+
+      P8Bit =  &Data.b[7];
+      P16Bit = &Data.b[6];
+      P32Bit = &Data.b[4];
+      P64Bit = Data.b;
+    }
+
+    bool NoHex = !mCheckHexadecimal->isChecked();
+
+    // unsigned 8 bit
+    buf.sprintf( NoHex?"%u":mViewHexCaps?"0x%02X":"0x%02x", *(unsigned char*)P8Bit );
+    mText1[1]->setText( buf );
+    // signed int 8 bit
+    buf.sprintf( "%d", *(signed char*)P8Bit );
+    mText1[0]->setText( buf );
+
+    // unsigned int 16 bit
+    buf.sprintf( NoHex?"%u":mViewHexCaps?"0x%04X":"0x%04x", *(unsigned short*)P16Bit );
+    mText1[3]->setText( buf );
+    // signed int 16 bit
+    buf.sprintf( "%d", *(short*)P16Bit );
+    mText1[2]->setText( buf );
+
+    // unsigned int 32 bit
+    buf.sprintf( NoHex?"%u":mViewHexCaps?"0x%08X":"0x%08x", *(unsigned int*)P32Bit );
+    mText2[1]->setText( buf );
+    // signed int 32 bit
+    buf.sprintf( "%d", *(int*)P32Bit );
+    mText2[0]->setText( buf );
+
+    // float 32 bit
+    buf.sprintf( "%E", *(float*)P32Bit );
+    mText2[2]->setText( buf );
+    // float 64 bit
+    buf.sprintf( "%E", *(double*)P64Bit );
+    mText2[3]->setText( buf );
+
+    int numBits = mBitCombo->currentItem();
+    if( numBits == 0 )
+    {
+      //
+      // This is the original stuff
+      //
+      unsigned char data = (unsigned char)state.data[0];
+      buf.sprintf( mViewHexCaps?"%02X":"%02x", data );
+      mText3[0]->setText( buf );
+      buf.sprintf( "%03o", data );
+      mText3[1]->setText( buf );
+
+      char bitBuf[32];
+      for( int i = 0; i < 8; i++ )
+        bitBuf[7-i] = (data&(1<<i)) ? '1' : '0';
+
+      bitBuf[8] = 0;
+      mText3[2]->setText( TQString(bitBuf) );
+    }
+    else
+    {
+      //
+      // Variable bitwidth. Based on Craig Graham's work.
+      //
+      unsigned long data = bitValue( state, numBits );
+      buf.sprintf( mViewHexCaps?"%02lX %02lX":"%02lx %02lx", (data>>8)&0xFF, data&0xFF );
+      mText3[0]->setText( buf );
+      buf.sprintf( "%03lo %03lo", (data>>8)&0xFF, data&0xFF );
+      mText3[1]->setText( buf );
+      char bitBuf[32];
+      for( int i = 0; i<numBits; i++ )
+        bitBuf[numBits-i-1] = (data&(1L<<i)) ? '1' : '0';
+      bitBuf[numBits] = 0;
+      mText3[2]->setText( TQString(bitBuf) );
+    }
+
+    // Fix by Sergey A. Sukiyazov
+    unsigned char data[2] = { 0, 0 };
+    data[0] = state.charValid == false ? '.' :
+      (char)((unsigned char)state.data[0]&0xff );
+    buf = TQString::fromLocal8Bit( (const char *)data );
+
+    mText3[3]->setText( buf );
+  }
+  else
+  {
+    TQString str;
+    for( int i=0; i<4; i++)
+    {
+      mText1[i]->setText( str );
+      mText2[i]->setText( str );
+      mText3[i]->setText( str );
+    }
+  }
+
+  mCursorState = state;
+}
+
+
+void CHexToolWidget::fontChanged( void )
+{
+  TQFontMetrics fm( mText1[0]->font() );
+  int W1 = fm.width( "XXXXXXXX" );
+  int W2 = fm.width( "XXXXXXXXXXXX" );
+  int W3 = fm.width( "888888888888888888" );
+	for( int i=0; i<4; i++ )
+  {
+		mText1[i]->setFixedWidth( W1 );
+		mText2[i]->setFixedWidth( W2 );
+		mText3[i]->setFixedWidth( W3 );
+  }
+}
+
+
+void CHexToolWidget::intelFormat( void )
+{
+  cursorChanged( mCursorState );
+}
+
+
+void CHexToolWidget::unsignedFormat( void )
+{
+  cursorChanged( mCursorState );
+}
+
+
+void CHexToolWidget::resizeEvent( TQResizeEvent */*e*/ )
+{
+}
+
+
+
+void CHexToolWidget::closeEvent( TQCloseEvent *e )
+{
+  e->accept();
+  emit closed();
+}
+
+#include "hextoolwidget.moc"
diff --git a/khexedit/hexvalidator.cc b/khexedit/hexvalidator.cc
deleted file mode 100644
index 74126e7d..00000000
--- a/khexedit/hexvalidator.cc
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <tqwidget.h>
-#include "hexvalidator.h"
-
-CHexValidator::CHexValidator( TQWidget *parent, EState state,
-			      const char *name )
-  :TQValidator( TQT_TQOBJECT(parent), name )
-{
-  setState( state );
-}
-
-CHexValidator::~CHexValidator( void )
-{
-}
-
-TQValidator::State CHexValidator::validate( TQString &string, int &/*pos*/ ) const
-{
-  if( mState == hexadecimal )
-  {
-    for( uint i=0; i < string.length(); i++ )
-    {
-      int val = string[i].latin1();
-      if( isxdigit( val ) == 0 && isspace( val ) == 0 )
-      {
-	return( TQValidator::Invalid );
-      }
-    }
-    return( TQValidator::Valid );
-  }
-  if( mState == decimal )
-  {
-    for( uint i=0; i < string.length(); i++ )
-    {
-      int val = string[i].latin1();
-      if( isdigit( val ) == 0 && isspace( val ) == 0 )
-      {
-	return( TQValidator::Invalid );
-      }
-    }
-    return( TQValidator::Valid );
-  }
-  else if( mState == octal )
-  {
-    for( uint i=0; i < string.length(); i++ )
-    {
-      int val = string[i].latin1();
-      if( (isdigit( val ) == 0 || val == '8' || val == '9') &&
-	  isspace( val ) == 0 )
-      {
-	return( TQValidator::Invalid );
-      }
-    }
-    return( TQValidator::Valid );
-  }
-  else if( mState == binary )
-  {
-    for( uint i=0; i < string.length(); i++ )
-    {
-      int val = string[i].latin1();
-      if( val != '0' && val != '1' && isspace( val ) == 0 )
-      {
-	return( TQValidator::Invalid );
-      }
-    }
-    return( TQValidator::Valid );
-  }
-  else if( mState == regularText )
-  {
-    return( TQValidator::Valid );
-  }
-  else
-  {
-    return( TQValidator::Invalid );
-  }
-
-}
-
-
-void CHexValidator::setState( EState state )
-{
-  mState = state;
-}
-
-
-void CHexValidator::convert( TQByteArray &dest, const TQString &src )
-{
-  uint value;
-  uint k=0;
-
-  if( mState == hexadecimal )
-  {
-    dest.resize(0);
-
-    char buf[3];
-    for( uint i=0; i < src.length(); i++ )
-    {
-      int val = src[i].latin1();
-      if( isxdigit(val) )
-      {
-	buf[k++] = val;
-	if( k == 2 )
-	{
-	  buf[k] = 0;
-	  sscanf( buf, "%X", &value );
-
-	  dest.resize( dest.size()+1 );
-	  dest[ dest.size()-1 ] = value;
-	  k = 0;
-	}
-      }
-    }
-
-    if( k == 1 )
-    {
-      buf[1] = buf[0];
-      buf[0] = '0';
-      buf[2] = 0;
-      sscanf( buf, "%X", &value );
-
-      dest.resize( dest.size()+1 );
-      dest[ dest.size()-1 ] = value;
-    }
-
-  }
-  else if( mState == decimal )
-  {
-    dest.resize(0);
-
-    char buf[4];
-    for( uint i=0; i < src.length(); i++ )
-    {
-      int val = src[i].latin1();
-      if( isdigit(val) )
-      {
-	buf[k++] = val;
-	if( k == 3 )
-	{
-	  buf[k] = 0;
-	  sscanf( buf, "%u", &value );
-
-	  dest.resize( dest.size()+1 );
-	  dest[ dest.size()-1 ] = value;
-	  k = 0;
-	}
-      }
-    }
-
-    if( k == 1 || k == 2 )
-    {
-      if( k == 1 )
-      {
-	buf[2] = buf[0];
-	buf[0] = buf[1] = '0';
-      }
-      else
-      {
-	buf[2] = buf[1];
-	buf[1] = buf[0];
-	buf[0] = '0';
-      }
-      buf[3] = 0;
-      sscanf( buf, "%u", &value );
-
-      dest.resize( dest.size()+1 );
-      dest[ dest.size()-1 ] = value;
-    }
-  }
-
-  else if( mState == octal )
-  {
-    dest.resize(0);
-
-    char buf[4];
-    for( uint i=0; i < src.length(); i++ )
-    {
-      int val = src[i].latin1();
-      if( isdigit(val) )
-      {
-	buf[k++] = val;
-	if( k == 3 )
-	{
-	  if( buf[0] > '3' ) { buf[0] = '3'; }
-	  buf[k] = 0;
-	  sscanf( buf, "%o", &value );
-
-	  dest.resize( dest.size()+1 );
-	  dest[ dest.size()-1 ] = value;
-	  k = 0;
-	}
-      }
-    }
-
-    if( k == 1 || k == 2 )
-    {
-      if( k == 1 )
-      {
-	buf[2] = buf[0];
-	buf[0] = buf[1] = '0';
-      }
-      else
-      {
-	buf[2] = buf[1];
-	buf[1] = buf[0];
-	buf[0] = '0';
-      }
-      buf[3] = 0;
-      sscanf( buf, "%o", &value );
-
-      dest.resize( dest.size()+1 );
-      dest[ dest.size()-1 ] = value;
-    }
-  }
-  else if( mState == binary )
-  {
-    dest.resize(0);
-
-    char buf[9];
-    for( uint i=0; i < src.length(); i++ )
-    {
-      int val = src[i].latin1();
-      if( isdigit(val) )
-      {
-	buf[k++] = val;
-	if( k == 8 )
-	{
-	  value = 0;
-	  for( uint j=0; j < 8; j++ )
-	  {
-	    value |= (buf[8-j-1] == '1') ? 1<<j : 0;
-	  }
-
-	  dest.resize( dest.size()+1 );
-	  dest[ dest.size()-1 ] = value;
-	  k = 0;
-	}
-      }
-    }
-
-    if( k > 0 )
-    {
-      value = 0;
-      for( uint j=0; j < k; j++ )
-      {
-	value |= (buf[k-j-1] == '1') ? 1<<j : 0;
-      }
-
-      dest.resize( dest.size()+1 );
-      dest[ dest.size()-1 ] = value;
-    }
-  }
-  else if( mState == regularText )
-  {
-    dest.resize(src.length());
-    for( uint i=0; i < src.length(); i++ )
-    {
-      dest[i] = src[i].latin1();
-    }
-
-  }
-  else
-  {
-    dest.resize(0);
-  }
-}
-
-
-
-void CHexValidator::format( TQString &dest, const TQByteArray &src )
-{
-  for( uint i=0; i<src.size(); ++i )
-  {
-    unsigned char srcCh = (unsigned char)src[i];
-    TQString formattedCh;
-
-    switch( mState )
-    {
-      case hexadecimal:
-        formattedCh = zeroExtend( TQString::number( srcCh, 16 ), 2 );
-        break;
-      case decimal:
-        formattedCh = zeroExtend( TQString::number( srcCh, 10), 3 );
-        break;
-      case octal:
-        formattedCh = zeroExtend( TQString::number( srcCh, 8), 3 );
-        break;
-      case binary:
-        formattedCh = zeroExtend( TQString::number( srcCh, 2), 8 );
-        break;
-      case regularText:
-        formattedCh = TQString( TQChar( srcCh ) );
-        break;
-    }
-
-    dest += formattedCh + " ";
-  }
-}
-
-
-TQString CHexValidator::zeroExtend( const TQString &src, unsigned destLen) const
-{
-  if( src.length() >= destLen )
-    return src;
-
-  TQString zeroes;
-  zeroes.fill( '0', destLen - src.length() );
-  return zeroes + src;
-}
-#include "hexvalidator.moc"
diff --git a/khexedit/hexvalidator.cpp b/khexedit/hexvalidator.cpp
new file mode 100644
index 00000000..74126e7d
--- /dev/null
+++ b/khexedit/hexvalidator.cpp
@@ -0,0 +1,329 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <tqwidget.h>
+#include "hexvalidator.h"
+
+CHexValidator::CHexValidator( TQWidget *parent, EState state,
+			      const char *name )
+  :TQValidator( TQT_TQOBJECT(parent), name )
+{
+  setState( state );
+}
+
+CHexValidator::~CHexValidator( void )
+{
+}
+
+TQValidator::State CHexValidator::validate( TQString &string, int &/*pos*/ ) const
+{
+  if( mState == hexadecimal )
+  {
+    for( uint i=0; i < string.length(); i++ )
+    {
+      int val = string[i].latin1();
+      if( isxdigit( val ) == 0 && isspace( val ) == 0 )
+      {
+	return( TQValidator::Invalid );
+      }
+    }
+    return( TQValidator::Valid );
+  }
+  if( mState == decimal )
+  {
+    for( uint i=0; i < string.length(); i++ )
+    {
+      int val = string[i].latin1();
+      if( isdigit( val ) == 0 && isspace( val ) == 0 )
+      {
+	return( TQValidator::Invalid );
+      }
+    }
+    return( TQValidator::Valid );
+  }
+  else if( mState == octal )
+  {
+    for( uint i=0; i < string.length(); i++ )
+    {
+      int val = string[i].latin1();
+      if( (isdigit( val ) == 0 || val == '8' || val == '9') &&
+	  isspace( val ) == 0 )
+      {
+	return( TQValidator::Invalid );
+      }
+    }
+    return( TQValidator::Valid );
+  }
+  else if( mState == binary )
+  {
+    for( uint i=0; i < string.length(); i++ )
+    {
+      int val = string[i].latin1();
+      if( val != '0' && val != '1' && isspace( val ) == 0 )
+      {
+	return( TQValidator::Invalid );
+      }
+    }
+    return( TQValidator::Valid );
+  }
+  else if( mState == regularText )
+  {
+    return( TQValidator::Valid );
+  }
+  else
+  {
+    return( TQValidator::Invalid );
+  }
+
+}
+
+
+void CHexValidator::setState( EState state )
+{
+  mState = state;
+}
+
+
+void CHexValidator::convert( TQByteArray &dest, const TQString &src )
+{
+  uint value;
+  uint k=0;
+
+  if( mState == hexadecimal )
+  {
+    dest.resize(0);
+
+    char buf[3];
+    for( uint i=0; i < src.length(); i++ )
+    {
+      int val = src[i].latin1();
+      if( isxdigit(val) )
+      {
+	buf[k++] = val;
+	if( k == 2 )
+	{
+	  buf[k] = 0;
+	  sscanf( buf, "%X", &value );
+
+	  dest.resize( dest.size()+1 );
+	  dest[ dest.size()-1 ] = value;
+	  k = 0;
+	}
+      }
+    }
+
+    if( k == 1 )
+    {
+      buf[1] = buf[0];
+      buf[0] = '0';
+      buf[2] = 0;
+      sscanf( buf, "%X", &value );
+
+      dest.resize( dest.size()+1 );
+      dest[ dest.size()-1 ] = value;
+    }
+
+  }
+  else if( mState == decimal )
+  {
+    dest.resize(0);
+
+    char buf[4];
+    for( uint i=0; i < src.length(); i++ )
+    {
+      int val = src[i].latin1();
+      if( isdigit(val) )
+      {
+	buf[k++] = val;
+	if( k == 3 )
+	{
+	  buf[k] = 0;
+	  sscanf( buf, "%u", &value );
+
+	  dest.resize( dest.size()+1 );
+	  dest[ dest.size()-1 ] = value;
+	  k = 0;
+	}
+      }
+    }
+
+    if( k == 1 || k == 2 )
+    {
+      if( k == 1 )
+      {
+	buf[2] = buf[0];
+	buf[0] = buf[1] = '0';
+      }
+      else
+      {
+	buf[2] = buf[1];
+	buf[1] = buf[0];
+	buf[0] = '0';
+      }
+      buf[3] = 0;
+      sscanf( buf, "%u", &value );
+
+      dest.resize( dest.size()+1 );
+      dest[ dest.size()-1 ] = value;
+    }
+  }
+
+  else if( mState == octal )
+  {
+    dest.resize(0);
+
+    char buf[4];
+    for( uint i=0; i < src.length(); i++ )
+    {
+      int val = src[i].latin1();
+      if( isdigit(val) )
+      {
+	buf[k++] = val;
+	if( k == 3 )
+	{
+	  if( buf[0] > '3' ) { buf[0] = '3'; }
+	  buf[k] = 0;
+	  sscanf( buf, "%o", &value );
+
+	  dest.resize( dest.size()+1 );
+	  dest[ dest.size()-1 ] = value;
+	  k = 0;
+	}
+      }
+    }
+
+    if( k == 1 || k == 2 )
+    {
+      if( k == 1 )
+      {
+	buf[2] = buf[0];
+	buf[0] = buf[1] = '0';
+      }
+      else
+      {
+	buf[2] = buf[1];
+	buf[1] = buf[0];
+	buf[0] = '0';
+      }
+      buf[3] = 0;
+      sscanf( buf, "%o", &value );
+
+      dest.resize( dest.size()+1 );
+      dest[ dest.size()-1 ] = value;
+    }
+  }
+  else if( mState == binary )
+  {
+    dest.resize(0);
+
+    char buf[9];
+    for( uint i=0; i < src.length(); i++ )
+    {
+      int val = src[i].latin1();
+      if( isdigit(val) )
+      {
+	buf[k++] = val;
+	if( k == 8 )
+	{
+	  value = 0;
+	  for( uint j=0; j < 8; j++ )
+	  {
+	    value |= (buf[8-j-1] == '1') ? 1<<j : 0;
+	  }
+
+	  dest.resize( dest.size()+1 );
+	  dest[ dest.size()-1 ] = value;
+	  k = 0;
+	}
+      }
+    }
+
+    if( k > 0 )
+    {
+      value = 0;
+      for( uint j=0; j < k; j++ )
+      {
+	value |= (buf[k-j-1] == '1') ? 1<<j : 0;
+      }
+
+      dest.resize( dest.size()+1 );
+      dest[ dest.size()-1 ] = value;
+    }
+  }
+  else if( mState == regularText )
+  {
+    dest.resize(src.length());
+    for( uint i=0; i < src.length(); i++ )
+    {
+      dest[i] = src[i].latin1();
+    }
+
+  }
+  else
+  {
+    dest.resize(0);
+  }
+}
+
+
+
+void CHexValidator::format( TQString &dest, const TQByteArray &src )
+{
+  for( uint i=0; i<src.size(); ++i )
+  {
+    unsigned char srcCh = (unsigned char)src[i];
+    TQString formattedCh;
+
+    switch( mState )
+    {
+      case hexadecimal:
+        formattedCh = zeroExtend( TQString::number( srcCh, 16 ), 2 );
+        break;
+      case decimal:
+        formattedCh = zeroExtend( TQString::number( srcCh, 10), 3 );
+        break;
+      case octal:
+        formattedCh = zeroExtend( TQString::number( srcCh, 8), 3 );
+        break;
+      case binary:
+        formattedCh = zeroExtend( TQString::number( srcCh, 2), 8 );
+        break;
+      case regularText:
+        formattedCh = TQString( TQChar( srcCh ) );
+        break;
+    }
+
+    dest += formattedCh + " ";
+  }
+}
+
+
+TQString CHexValidator::zeroExtend( const TQString &src, unsigned destLen) const
+{
+  if( src.length() >= destLen )
+    return src;
+
+  TQString zeroes;
+  zeroes.fill( '0', destLen - src.length() );
+  return zeroes + src;
+}
+#include "hexvalidator.moc"
diff --git a/khexedit/hexviewwidget.cc b/khexedit/hexviewwidget.cc
deleted file mode 100644
index 6c15ae3b..00000000
--- a/khexedit/hexviewwidget.cc
+++ /dev/null
@@ -1,2286 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <iostream>
-
-#include <tqclipboard.h>
-#include <tqdrawutil.h>
-
-
-#include <tdeglobalsettings.h>
-#include <tdelocale.h>
-#include <tdepopupmenu.h>
-#include <kdebug.h>
-#include <kurldrag.h>
-
-#include "hexdrag.h"
-#include "hexerror.h"
-#include "hexviewwidget.h"
-
-//
-// The usage of the WNorthWestGravity flag should make screen update
-// faster (less paintEvents). I have had to add update() some places
-// to ensure proper redrawing. Undefine if something goes wrong
-// (i.e. not updated )
-//
-#define USE_NORTHWEST_GRAVITY 1
-
-//
-// I don't want to decide what is best: Drag starts when mouse is moved or
-// after a timeout.
-//
-#define USE_DRAG_MOVEMENT 1
-
-
-
-
-
-
-CDragManager::CDragManager( void )
-{
-  mActivateMode = Movement;
-  mPending = false;
-  mTimerId = 0;
-}
-
-void CDragManager::setActivateMode( EDragActivateMode mode )
-{
-  clear();
-  mActivateMode = mode; // Movement or Timer
-}
-
-void CDragManager::setup( int x, int y )
-{
-  if( mActivateMode == Movement )
-  {
-    mOrigin.setX(x);
-    mOrigin.setY(y);
-  }
-  else
-  {
-    setupTimer();
-  }
-  mPending = true;
-}
-
-bool CDragManager::start( TQMouseEvent *e )
-{
-  if( mPending == false )
-  {
-    return( false );
-  }
-
-  if( mActivateMode == Movement )
-  {
-    if( (mOrigin - e->pos()).manhattanLength() > TDEGlobalSettings::dndEventDelay() )
-    {
-      mPending = false;
-      emit startDrag( e->state() & ShiftButton ? true : false );
-    }
-    return( true );
-  }
-  else // Timer
-  {
-    if( mTimerId != 0 )
-    {
-      removeTimer();
-      mPending = false;
-      emit startDrag( e->state() & ShiftButton ? true : false );
-      return( true );
-    }
-    else
-    {
-      // Should never happen!
-      mPending = false;
-      return( false );
-    }
-  }
-
-}
-
-bool CDragManager::clear( void )
-{
-  if( mPending == false )
-  {
-    return( false );
-  }
-
-  if( mActivateMode == Timer )
-  {
-    removeTimer();
-  }
-
-  mPending = false;
-  return( true );
-}
-
-void CDragManager::timerEvent( TQTimerEvent *e )
-{
-  if( e->timerId() == mTimerId )
-  {
-    removeTimer();
-    if( mPending == true )
-    {
-      mPending = false;
-      emit startDrag( ( kapp->keyboardModifiers() & TDEApplication::ShiftModifier ) );
-    }
-  }
-}
-
-void CDragManager::removeTimer( void )
-{
-  if( mTimerId != 0 )
-  {
-    killTimer( mTimerId );
-    mTimerId = 0;
-  }
-}
-
-void CDragManager::setupTimer( void )
-{
-  if( mTimerId != 0 )
-  {
-    killTimer( mTimerId );
-    mTimerId = 0;
-  }
-  mTimerId = startTimer( 500 );
-}
-
-
-//
-// This widget will use the entire space of the parent widget
-//
-CHexViewWidget::CHexViewWidget( TQWidget *parent, const char *name,
-				CHexBuffer *hexBuffer )
-  : TQFrame( parent, name,
-	    #ifdef USE_NORTHWEST_GRAVITY
-	    TQt::WStaticContents
-	    #else
-	    0
-	    #endif
-	    ), mScrollBarSize( 16 )
-{
-  if( parent == 0 || hexBuffer == 0 ) { return; }
-
-  //
-  // TQt 2.0:
-  // -------
-  // I use the "CScrollBar" because sometimes (very seldom) when I
-  // do a mHorzScroll->hide() the mHorzScroll->isVisible() remains true
-  // in updateView() for a short while. I need the correct visibility
-  // because I have to redraw the area - due to the "WNorthWestGravity" usage.
-  //
-  // I tried to do a
-  // "while( mHorzScroll->isVisible() ) { mHorzScroll->hide(); }"
-  // but then the loop never ended. The "CScrollBar" emits a "hidden()"
-  // signal whenever is receives a TQHideEvent.
-  //
-
-  mVertScroll = new CScrollBar( Qt::Vertical, this );
-  if( mVertScroll == 0 ) { return; }
-  mHorzScroll = new CScrollBar( Qt::Horizontal, this );
-  if( mHorzScroll == 0 ) { return; }
-  mCorner = new TQWidget( this );
-  if( mCorner == 0 ) { return; }
-  connect( mHorzScroll, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(changeXPos(int)) );
-  connect( mVertScroll, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(changeYPos(int)) );
-  connect( mHorzScroll, TQT_SIGNAL(hidden()), TQT_SLOT(update()) );
-  connect( mVertScroll, TQT_SIGNAL(hidden()), TQT_SLOT(update()) );
-  mHorzScroll->hide();
-  mVertScroll->hide();
-
-  mDragManager = new CDragManager();
-  if( mDragManager == 0 ) { return; }
-  #ifdef USE_DRAG_MOVEMENT
-  mDragManager->setActivateMode( CDragManager::Movement );
-  #else
-  mDragManager->setActivateMode( CDragManager::Timer );
-  #endif
-  connect( mDragManager, TQT_SIGNAL(startDrag(bool)), TQT_SLOT(startDrag(bool)) );
-
-  setFrameStyle( TQFrame::WinPanel|TQFrame::Sunken );
-  setWFlags( WResizeNoErase );
-  setFocusPolicy( TQ_StrongFocus );
-
-  mHexBuffer = hexBuffer;
-  mHexBuffer->cursorReset();
-
-  mEditMode      = mHexBuffer->editMode();
-  mShowCursor    = false;
-  mCursorTimerId = 0;
-
-  mDocumentMenu  = 0;
-
-  setTextBufferSize(); // Make sure there is a pixmap buffer
-  setStartX(0);
-  setStartY(0);
-
-  setAcceptDrops(true);
-  setDropHighlight(false); // Init state + frame shape
-  setBackgroundColor( mHexBuffer->backgroundColor() );
-}
-
-
-CHexViewWidget::~CHexViewWidget( void )
-{
-  delete mVertScroll;
-  delete mHorzScroll;
-  delete mCorner;
-  delete mDragManager;
-}
-
-
-int CHexViewWidget::readFile( TQFile &file, const TQString &url, CProgress &p )
-{
-  int errCode = mHexBuffer->readFile( file, url, p );
-  if( errCode != Err_Success )
-  {
-    return( errCode );
-  }
-
-  initFile();
-  return( Err_Success );
-}
-
-
-int CHexViewWidget::insertFile( TQFile &file, CProgress &p )
-{
-  int errCode = mHexBuffer->insertFile( file, p );
-  if( errCode != Err_Success )
-  {
-    return( errCode );
-  }
-
-  updateWindow( true, true );
-
-  emit dataChanged();
-  emit cursorChanged( mHexBuffer->cursorState() );
-  emit layoutChanged( mLayout );
-  return( Err_Success );
-}
-
-
-int CHexViewWidget::newFile( const TQString &url )
-{
-  int errCode = mHexBuffer->newFile( url );
-  if( errCode != Err_Success )
-  {
-    return( errCode );
-  }
-
-  initFile();
-  return( Err_Success );
-}
-
-
-int CHexViewWidget::writeFile( TQFile &file, CProgress &p )
-{
-  int errCode = mHexBuffer->writeFile( file, p );
-  if( errCode == Err_Success )
-  {
-    emit fileState( mHexBuffer->fileState() );
-  }
-  return( errCode );
-}
-
-
-void CHexViewWidget::closeFile( void )
-{
-  emit fileClosed( mHexBuffer->url() );
-  mHexBuffer->closeFile();
-  initFile();
-}
-
-
-
-void CHexViewWidget::initFile( void )
-{
-  setStartX(0);
-  setStartY(0);
-
-  mHexBuffer->cursorReset();
-  mHexBuffer->setLayout( mLayout );
-  mHexBuffer->setFont( mFontInfo );
-  setEditMode( mEditMode );
-  setColor( mColor, false );
-  setCursor( mCursor, false );
-  setMisc( mMisc );
-
-  setBackgroundColor( mHexBuffer->backgroundColor() );
-  setBackgroundMode( NoBackground );
-
-  updateView( true, false );
-  resizeEvent( 0 );
-
-  emit dataChanged();
-  emit cursorChanged( mHexBuffer->cursorState() );
-  emit fileState( mHexBuffer->fileState() );
-  emit encodingChanged( mHexBuffer->encoding() );
-  emit fileName( mHexBuffer->url(), mHexBuffer->hasFileName() );
-  emit bookmarkChanged( mHexBuffer->bookmarkList() );
-}
-
-
-void CHexViewWidget::setBuffer( CHexBuffer *hexBuffer )
-{
-  if( hexBuffer == 0 || mHexBuffer == hexBuffer )
-  {
-    return;
-  }
-
-  unselect();
-  unmark();
-
-  mHexBuffer = hexBuffer;
-  mHexBuffer->setLayout( mLayout );
-  mHexBuffer->setFont( mFontInfo );
-  setEditMode( mEditMode );
-  setColor( mColor, false );
-  setCursor( mCursor, false );
-  setMisc( mMisc );
-
-  if( mLayout.lockLine == false )
-  {
-    mHexBuffer->matchWidth( width() );
-  }
-
-  setBackgroundColor( hexBuffer->backgroundColor() );
-  setBackgroundMode( NoBackground );
-
-  setEditMode( mEditMode );
-  updateWindow();
-
-  emit dataChanged();
-  emit cursorChanged( mHexBuffer->cursorState() );
-  emit fileState( mHexBuffer->fileState() );
-  emit encodingChanged( mHexBuffer->encoding() );
-  emit layoutChanged( mLayout );
-  emit inputModeChanged( mHexBuffer->inputMode() );
-  emit fileName( mHexBuffer->url(), mHexBuffer->hasFileName() );
-  emit bookmarkChanged( mHexBuffer->bookmarkList() );
-}
-
-
-
-
-void CHexViewWidget::changeXPos( int p )
-{
-  int dx = startX() - p;
-  setStartX(p);
-
-
-  if( TQABS(dx) < width() )
-  {
-    scroll( dx, 0, contentsRect() );
-  }
-  else
-  {
-    TQWidget::update();
-  }
-
-  //
-  // If the start position has become 0, then update the view. This
-  // will remove the scrollbar (if it is visible) if the textarea width
-  // is wider than the text. The scrollbar will then disappear under the
-  // mouse pointer.
-  //
-  if( startX() == 0 )
-  {
-    updateView( false, false );
-  }
-
-}
-
-
-void CHexViewWidget::changeYPos( int p )
-{
-  int dy  = startY() - p;
-  setStartY(p);
-
-  if( TQABS( dy ) < height() )
-  {
-    scroll( 0, dy, contentsRect() );
-  }
-  else
-  {
-    TQWidget::update();
-  }
-
-  //
-  // If the start position has become 0, then update the view. This
-  // will remove the scrollbar (if it is visible) if the textarea height
-  // is taller than the text. The scrollbar will then disappear under the
-  // mouse pointer.
-  //
-  if( startY() == 0 )
-  {
-    updateView( false, false );
-  }
-}
-
-
-void CHexViewWidget::clipboardChanged( void )
-{
-  disconnect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
-	     this,TQT_SLOT(clipboardChanged()));
-  unselect();
-}
-
-void CHexViewWidget::paletteChanged( void )
-{
-  setColor( mColor, true );
-}
-
-
-void CHexViewWidget::fontChanged( void )
-{
-  //setFont( kapp->fixedFont, true );
-}
-
-void CHexViewWidget::filter( SFilterControl &fc )
-{
-  int errCode = mHexBuffer->filter( fc );
-  if( errCode == Err_Success )
-  {
-    repaint();
-    emit dataChanged();
-    emit cursorChanged( mHexBuffer->cursorState() );
-  }
-}
-
-
-
-void CHexViewWidget::insert( SInsertData &id )
-{
-  if( id.onCursor == false )
-  {
-    mHexBuffer->cursorGoto( id.offset, 7 );
-  }
-  SCursorConfig cc;
-  updateCursor( cc, true );
-
-  if( id.size == 0 )
-  {
-    return;
-  }
-
-  TQByteArray buf( id.size );
-  if( buf.isNull() == true )
-  {
-    return;
-  }
-  buf.fill( 0 );
-
-  if( id.pattern.size() > 0 )
-  {
-    uint size = id.pattern.size()>buf.size() ? buf.size() : id.pattern.size();
-    if( id.repeatPattern == false )
-    {
-      memcpy( &buf[0], &id.pattern[0], size );
-      if( size < buf.size() )
-      {
-	memset( &buf[size], id.pattern[id.pattern.size()-1], buf.size()-size );
-      }
-    }
-    else
-    {
-      for( uint i=0; i < buf.size(); i+= size )
-      {
-	uint s = i+size > buf.size() ? buf.size()-i : size;
-	memcpy( &buf[i], &id.pattern[0], s );
-      }
-    }
-  }
-
-  insert( buf );
-}
-
-
-void CHexViewWidget::insert( const TQByteArray &buf )
-{
-  if( mHexBuffer->documentPresent() == false )
-  {
-    emit pleaseOpenNewFile();
-    if( mHexBuffer->documentPresent() == false )
-    {
-      return;
-    }
-  }
-
-  uint offset = mHexBuffer->cursorOffset();
-  int errCode = mHexBuffer->inputAtCursor( buf, 0 );
-  if( errCode == Err_Success  )
-  {
-    updateWindow( offset, true );
-    emit dataChanged();
-  }
-}
-
-
-void CHexViewWidget::append( const TQByteArray &buf )
-{
-  if( mHexBuffer->documentPresent() == false )
-  {
-    insert( buf );
-  }
-  else
-  {
-    SCursorConfig cc;
-    cc.emulateControlButton( true );
-    cursorEnd( cc );
-
-    int errCode = mHexBuffer->inputAtCursor( buf, 0 );
-    if( errCode == Err_Success  )
-    {
-      updateWindow( true, true );
-      emit dataChanged();
-    }
-  }
-}
-
-
-void CHexViewWidget::valueOnCursor( TQByteArray &buf, uint size )
-{
-  mHexBuffer->valueOnCursor( buf, size );
-}
-
-
-
-void CHexViewWidget::updateView( bool redraw, bool fixCursor )
-{
-  int f2 = frameWidth() * 2;
-  int scrollBarCount = 0; // Number of visible scrollbars
-  int editWidth = 0;
-  int editHeight = 0;
-
-  for( uint i=0; i < 2; i++ )
-  {
-    editWidth  = width()  - f2; // Total available width
-    editHeight = height() - f2; // Total available height
-    int textWidth  = dataWidth();
-    int textHeight = mHexBuffer->totalHeight();
-
-    //
-    // This will move the start position of the horizontal scrollbar
-    // to the left (if possible) if the text width is smaller than the
-    // edit width.
-    //
-    if( startX() > 0 )
-    {
-      int size = mVertScroll->isVisible() == true ? mScrollBarSize : 0;
-      if( startX() + editWidth - size > textWidth )
-      {
-	int position = textWidth - editWidth + size;
-	setStartX( position > 0 ? position : 0 );
-	#ifdef USE_NORTHWEST_GRAVITY
-	redraw = true;
-	#endif
-      }
-    }
-
-    int tooMuchX = textWidth - editWidth;
-    bool horzScrollbarVisible = startX() > 0 || tooMuchX > 0 ? true : false;
-    if( horzScrollbarVisible == true )
-    {
-      editHeight -= mScrollBarSize;
-    }
-
-
-    //
-    // This will move the start position of the vertical scrollbar
-    // to the top (if possible) if the text height is smaller than the
-    // edit height.
-    //
-    if( startY() > 0 )
-    {
-      if( startY() + editHeight > textHeight )
-      {
-	int position = textHeight - editHeight;
-	setStartY( position > 0 ? position : 0 );
-	#ifdef USE_NORTHWEST_GRAVITY
-	redraw = true;
-	#endif
-      }
-    }
-
-    int tooMuchY  = textHeight - editHeight;
-    int startLine = startY() / textHeight;
-
-    if( startLine > 0 || tooMuchY > 0 )
-    {
-      editWidth -= mScrollBarSize;
-      tooMuchX += mScrollBarSize;
-      if( horzScrollbarVisible == false && tooMuchX > 0 )
-      {
-	// Horizontal scrollbar will be visible after all.
-	editHeight -= mScrollBarSize;
-	tooMuchY += mScrollBarSize;
-      }
-    }
-
-    if( tooMuchX < startX() ) { tooMuchX = startX(); }
-    if( tooMuchY < startY() ) { tooMuchY = startY(); }
-
-    scrollBarCount = 0;
-    if( tooMuchX > 0 && documentPresent() == true )
-    {
-      mHorzScroll->blockSignals( true );
-      mHorzScroll->setGeometry( 0, editHeight+f2, editWidth+f2,mScrollBarSize);
-      mHorzScroll->setRange( 0, tooMuchX );
-      mHorzScroll->setValue( startX() );
-      mHorzScroll->setSteps(mHexBuffer->lineHeight(),editWidth-mScrollBarSize);
-      mHorzScroll->blockSignals( false );
-      if( mHorzScroll->isVisible() == false ) { mHorzScroll->show(); }
-      scrollBarCount ++;
-    }
-    else
-    {
-      if( mHorzScroll->isVisible() == true ) { mHorzScroll->hide(); }
-    }
-
-    if( tooMuchY > 0 && documentPresent() == true )
-    {
-      mVertScroll->blockSignals( true );
-      mVertScroll->setGeometry( editWidth+f2, 0, mScrollBarSize,editHeight+f2);
-      mVertScroll->setRange( 0, tooMuchY );
-      mVertScroll->setValue( startY() );
-      mVertScroll->setSteps(mHexBuffer->lineHeight(),
-			    editHeight-mScrollBarSize );
-      mVertScroll->blockSignals( false );
-      if( mVertScroll->isVisible() == false ) { mVertScroll->show(); }
-      scrollBarCount ++;
-    }
-    else
-    {
-      if( mVertScroll->isVisible() == true ) { mVertScroll->hide(); }
-    }
-
-    if( fixCursor == true )
-    {
-      int position = mHexBuffer->cursorFixedPosition( startY(), height() );
-      if( position != startY() )
-      {
-	setStartY( position );
-	fixCursor = false;
-	continue;
-      }
-    }
-    break;
-  }
-
-
-  if( scrollBarCount == 2 )
-  {
-    mCorner->setGeometry( editWidth+f2, editHeight+f2, mScrollBarSize,
-			  mScrollBarSize );
-    mCorner->show();
-  }
-  else
-  {
-    mCorner->hide();
-  }
-
-
-  updateFrameSize();
-
-  if( redraw == true )
-  {
-    TQWidget::update();
-  }
-}
-
-
-void CHexViewWidget::setPalette( const TQPalette &p )
-{
-  TQWidget::setPalette( p );
-  mCorner->setPalette( p );
-  mVertScroll->setPalette( p );
-  mHorzScroll->setPalette( p );
-}
-
-
-void CHexViewWidget::setLayout( SDisplayLayout &layout )
-{
-  mLayout = layout;
-  mHexBuffer->setLayout( mLayout );
-  updateWindow();
-
-  emit layoutChanged( mLayout );
-  emit cursorChanged( mHexBuffer->cursorState() );
-  emit textWidth( defaultWidth() );
-}
-
-
-void CHexViewWidget::setInputMode( SDisplayInputMode &input )
-{
-  mHexBuffer->setInputMode( input );
-  emit inputModeChanged( mHexBuffer->inputMode() );
-}
-
-
-void CHexViewWidget::setCursor( const SDisplayCursor &cursor,
-                                bool /*updateDisplay*/ )
-{
-  mCursor = cursor;
-  mHexBuffer->setCursorShapeModifier( cursor.alwaysBlockShape,
-				      cursor.thickInsertShape );
-  setupCursorTimer();
-  redrawFromOffset( mHexBuffer->cursorOffset(), false );
-}
-
-void CHexViewWidget::setColor( const SDisplayColor &color,
-			       bool updateDisplay )
-{
-  mColor = color;
-  mHexBuffer->setColor( mColor );
-  if( updateDisplay == true )
-  {
-    repaint();
-  }
-}
-
-void CHexViewWidget::setFont( const SDisplayFontInfo &fontInfo,
-			      bool updateDisplay )
-{
-  mFontInfo = fontInfo;
-  mHexBuffer->setFont( mFontInfo );
-  emit textWidth( defaultWidth() );
-  if( updateDisplay == true )
-  {
-    updateWindow();
-  }
-}
-
-
-
-void CHexViewWidget::setMisc( SDisplayMisc &misc )
-{
-  mMisc = misc;
-  mHexBuffer->setUndoLevel( misc.undoLevel );
-  mHexBuffer->setSoundState( misc.inputSound, misc.fatalSound );
-  mHexBuffer->setBookmarkVisibility( misc.bookmarkOffsetColumn,
-				     misc.bookmarkEditor );
-  if( mHexBuffer->documentPresent() == true )
-  {
-    TQWidget::update();
-  }
-}
-
-
-void CHexViewWidget::setInsertMode( bool insertMode )
-{
-  setEditMode( insertMode == true ? CHexBuffer::EditInsert :
-	       CHexBuffer::EditReplace );
-}
-
-
-int CHexViewWidget::setEncoding( CConversion::EMode mode, CProgress &p )
-{
-  int errCode = mHexBuffer->setEncoding( mode, p );
-  if( errCode == Err_Success )
-  {
-    repaint();
-    emit cursorChanged( mHexBuffer->cursorState() );
-    emit encodingChanged( mHexBuffer->encoding() );
-  }
-  return( errCode );
-}
-
-
-void CHexViewWidget::reportEncoding( void )
-{
-  emit encodingChanged( mHexBuffer->encoding() );
-}
-
-
-void CHexViewWidget::selectAll( void )
-{
-  setSelection( 0, true );
-  setSelection( mHexBuffer->documentSize(), false );
-  autoCopy();
-  emit cursorChanged( mHexBuffer->cursorState() );
-}
-
-void CHexViewWidget::unselect( void )
-{
-  setSelection( 0, true );
-  emit cursorChanged( mHexBuffer->cursorState() );
-}
-
-void CHexViewWidget::unmark( void )
-{
-  setMark( 0, 0, false );
-}
-
-
-int CHexViewWidget::findFirst( SSearchControl &sc )
-{
-  int errCode = mHexBuffer->findFirst( sc );
-  if( errCode == Err_Success ) { updateWindow( true, false ); }
-  return( errCode );
-}
-
-int CHexViewWidget::findNext( SSearchControl &sc )
-{
-  int errCode = mHexBuffer->findNext( sc );
-  if( errCode == Err_Success ) { updateWindow( true, false ); }
-  return( errCode );
-}
-
-int CHexViewWidget::findWrap( SSearchControl &sc )
-{
-  int errCode = mHexBuffer->findWrap( sc );
-  if( errCode == Err_Success ) { updateWindow( true, false ); }
-  return( errCode );
-}
-
-int CHexViewWidget::replaceAll( SSearchControl &sc, bool init )
-{
-  int errCode = mHexBuffer->replaceAll( sc, init );
-  if( errCode == Err_Success )
-  {
-    updateWindow( true, false );
-    emit dataChanged();
-  }
-  return( errCode );
-}
-
-int CHexViewWidget::replaceMarked( SSearchControl &sc )
-{
-  int errCode = mHexBuffer->replaceMarked( sc );
-  if( errCode == Err_Success )
-  {
-    updateWindow( true, false );
-    emit dataChanged();
-  }
-  return( errCode );
-}
-
-int CHexViewWidget::collectStrings( CStringCollectControl &sc )
-{
-  int errCode = mHexBuffer->collectStrings( sc );
-  return( errCode );
-}
-
-
-int CHexViewWidget::collectStatistic( SStatisticControl &sc, CProgress &p )
-{
-  int errCode = mHexBuffer->collectStatistic( sc, p );
-  return( errCode );
-}
-
-
-void CHexViewWidget::gotoOffset( uint offset, uint bit, bool fromCursor,
-				 bool forward )
-{
-  bool reverse = forward == true ? false : true;
-  mHexBuffer->cursorGoto( offset, bit, reverse, fromCursor );
-  updateWindow( true, false );
-}
-
-
-void CHexViewWidget::gotoOffset( uint offset )
-{
-  gotoOffset( offset, 7, true, true );
-}
-
-
-int CHexViewWidget::print( CHexPrinter &printer, CProgress &p )
-{
-  return( mHexBuffer->print( printer, p ) );
-}
-
-
-uint CHexViewWidget::numPage( CHexPrinter &printer )
-{
-  return( mHexBuffer->numPage( printer ) );
-}
-
-
-int CHexViewWidget::exportText( const SExportText &ex, CProgress &p )
-{
-  return( mHexBuffer->exportText( ex, p ) );
-}
-
-
-int CHexViewWidget::exportHtml( const SExportHtml &ex, CProgress &p )
-{
-  return( mHexBuffer->exportHtml( ex, p ) );
-}
-
-
-int CHexViewWidget::exportCArray( const SExportCArray &ex, CProgress &p )
-{
-  return( mHexBuffer->exportCArray( ex, p ) );
-}
-
-
-void CHexViewWidget::startDrag( bool asText )
-{
-  TQByteArray buf;
-  if( asText == true )
-  {
-    if( mHexBuffer->copySelectedText( buf ) != Err_Success )
-    {
-      return;
-    }
-    TQDragObject *d = new TQTextDrag( buf.data(), this );
-    d->dragCopy();
-  }
-  else
-  {
-    if( mHexBuffer->copySelectedData( buf ) != Err_Success )
-    {
-      return;
-    }
-    TQDragObject *d = new CHexDrag( buf, this );
-    d->dragCopy();
-  }
-}
-
-
-
-void CHexViewWidget::copy( void )
-{
-  TQByteArray buf;
-  if( mHexBuffer->copySelectedData( buf ) != Err_Success )
-  {
-    return;
-  }
-  disconnect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
-	     this,TQT_SLOT(clipboardChanged()));
-  //
-  // Note: Do no give the CHexDrag a parent != 0. The clipboard
-  // owns the current dragdata and will destroy it on exit or
-  // when it receives a new object. If the CHexDrag has a parent
-  // != 0, the CHexDrag object will be destroyed when the parent
-  // is destroyed. We will then have a double destroy situation
-  // when the app. is closed (=> segfault).
-  //
-  TQApplication::clipboard()->setData(new CHexDrag( buf ));
-  connect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
-	  this,TQT_SLOT(clipboardChanged()));
-}
-
-
-void CHexViewWidget::copyText( int columnSegment )
-{
-  TQByteArray buf;
-  if( mHexBuffer->copySelectedText( buf, columnSegment ) != Err_Success )
-  {
-    return;
-  }
-
-  disconnect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
-	     this,TQT_SLOT(clipboardChanged()));
-  TQApplication::clipboard()->setText( buf.data() );
-  connect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
-	  this,TQT_SLOT(clipboardChanged()));
-}
-
-
-
-void CHexViewWidget::paste( void )
-{
-  TQMimeSource *data = TQApplication::clipboard()->data();
-  if( data != 0 )
-  {
-    TQByteArray buf;
-    if( CHexDrag::decode( data, buf ) == true )
-    {
-      insert( buf );
-      return;
-    }
-
-    TQString text;
-    if( TQTextDrag::decode( data, text ) == true )
-    {
-      TQByteArray buf;
-      if( mClipConvert.decode( buf, text ) == true )
-      {
-	insert( buf );
-      }
-      return;
-    }
-  }
-
-}
-
-
-void CHexViewWidget::cut( void )
-{
-  copy(); // Always make a copy to the clipboard of what we remove.
-  bool success = mHexBuffer->cutSelection();
-  if( success == false )
-  {
-    return;
-  }
-
-  updateWindow( false, true );
-  emit dataChanged();
-}
-
-
-void CHexViewWidget::undo( void )
-{
-  bool success = mHexBuffer->undo();
-  if( success == false )
-  {
-    return;
-  }
-
-  updateWindow( true, true );
-  emit dataChanged();
-}
-
-
-void CHexViewWidget::redo( void )
-{
-  bool success = mHexBuffer->redo();
-  if( success == false )
-  {
-    return;
-  }
-
-  updateWindow( true, true );
-  emit dataChanged();
-}
-
-
-void CHexViewWidget::addBookmark( int position )
-{
-  int errCode = mHexBuffer->addBookmark( position );
-  if( errCode != Err_Success )
-  {
-    if( errCode == Err_ListFull )
-    {
-      replaceBookmark();
-    }
-    return;
-  }
-  redrawFromOffset( mHexBuffer->cursorOffset(), false );
-
-  emit bookmarkChanged( mHexBuffer->bookmarkList() );
-}
-
-
-
-int CHexViewWidget::bookmarkMenu( const TQString &title )
-{
-  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
-  if( list.count() == 0 )
-  {
-    return( -1 );
-  }
-
-  TQString text;
-  TDEPopupMenu *popup = new TDEPopupMenu(  0 );
-  popup->insertTitle( title );
-  for( uint i=0; i < list.count(); i++ )
-  {
-    const SCursorOffset *p = list.at( i );
-    if( p == 0 ) { continue; }
-
-    text.sprintf("%04X:%04X", p->offset>>16, p->offset&0x0000FFFF );
-    text.prepend( TQString("[%1] %2: ").arg(i+1).arg(i18n("Offset")) );
-    popup->insertItem( text, i );
-  }
-
-  TQSize s(popup->sizeHint());
-  TQPoint center( (width()-s.width())/2, (height()-s.height())/2 );
-  int position = popup->exec( mapToGlobal(center) );
-  delete popup;
-
-  return( position );
-}
-
-
-void CHexViewWidget::removeBookmark( bool all )
-{
-  if( all == true )
-  {
-    bool success = mHexBuffer->removeBookmark( -1 );
-    if( success == false )
-    {
-      return;
-    }
-    TQWidget::update(); // Redraw visisble area.
-  }
-  else
-  {
-    int position = bookmarkMenu( i18n("Remove Bookmark") );
-    if( position < 0 )
-    {
-      return;
-    }
-
-    const SCursorOffset *p = mHexBuffer->bookmarkList().at(position);
-    uint offset = p ? p->offset : 0;
-
-    bool success = mHexBuffer->removeBookmark( position );
-    if( success == false )
-    {
-      return;
-    }
-
-    redrawFromOffset( offset, false );
-  }
-
-  emit bookmarkChanged( mHexBuffer->bookmarkList() );
-}
-
-
-void CHexViewWidget::replaceBookmark( void )
-{
-  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
-  if( list.count() == 0 )
-  {
-    return;
-  }
-
-  int position = bookmarkMenu( i18n("Replace Bookmark") );
-  if( position < 0 )
-  {
-    return;
-  }
-  addBookmark( position );
-}
-
-
-void CHexViewWidget::gotoBookmark( uint position )
-{
-  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
-  if( position >= list.count() )
-  {
-    return;
-  }
-
-  SCursorOffset *p = list.at( position );
-  if( p == 0 )
-  {
-    return;
-  }
-
-  mHexBuffer->cursorGoto( p->offset, p->bit );
-  updateWindow();
-}
-
-
-
-void CHexViewWidget::gotoNextBookmark( bool next )
-{
-  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
-  uint offset = mHexBuffer->cursorOffset();
-  uint diff   = ~0;
-
-  SCursorOffset *match = 0;
-
-  //
-  // Note: the list is unsorted.
-  //
-  if( next == true )
-  {
-    for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
-    {
-      if( co->offset > offset )
-      {
-	if( co->offset-offset < diff )
-	{
-	  diff = co->offset-offset;
-	  match = co;
-	}
-      }
-    }
-  }
-  else
-  {
-    for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
-    {
-      if( co->offset < offset )
-      {
-	if( offset-co->offset < diff )
-	{
-	  diff = offset-co->offset;
-	  match = co;
-	}
-      }
-    }
-  }
-
-
-  if( match == 0 )
-  {
-    if( next == true )
-    {
-      // Wrap: Locate entry with smallest offset.
-      offset = ~0;
-      for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
-      {
-	if( co->offset < offset )
-	{
-	  offset = co->offset;
-	  match  = co;
-	}
-      }
-    }
-    else
-    {
-      // Wrap: Locate entry with largest offset.
-      offset=0;
-      for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
-      {
-	if( co->offset > offset )
-	{
-	  offset = co->offset;
-	  match  = co;
-	}
-      }
-    }
-  }
-
-  if( match != 0 )
-  {
-    mHexBuffer->cursorGoto( match->offset, match->bit );
-    updateWindow();
-  }
-}
-
-
-
-
-
-
-//
-// Used to test the speed of drawing
-//
-#include <sys/time.h>
-#include <unistd.h>
-void CHexViewWidget::benchmark( void )
-{
-  struct timeval t1, t2;
-  uint loop = 10;
-
-  gettimeofday( &t1, 0 );
-  for( uint i=0; i< loop; i++ )
-  {
-    paintText( contentsRect(), false );
-  }
-  gettimeofday( &t2, 0 );
-
-
-  uint area  = width() * height();
-  uint last = (t2.tv_sec-t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
-
-  kdDebug(1501) << "Duration: " << (float)last/ 1000000.0 << endl;
-  kdDebug(1501) << "Duration/loop: " << (float)last/ (1000000.0*(float)loop) << endl;
-  kdDebug(1501) << "Area: " << area << endl;
-  kdDebug(1501) << "Loop: " << loop << endl;
-}
-
-
-
-
-
-void CHexViewWidget::resizeEvent( TQResizeEvent * )
-{
-  setTextBufferSize();
-
-  if( mLayout.lockLine == true )
-  {
-    updateView( false, false );
-    #ifdef USE_NORTHWEST_GRAVITY
-    paintFrame();
-    #endif
-  }
-  else
-  {
-    bool state = mVertScroll->isVisible();
-    int size = (state == true ? mScrollBarSize : 0) + frameWidth()*2;
-    #ifdef USE_NORTHWEST_GRAVITY
-    int w = dataWidth();
-    #endif
-
-    bool bufferChanged = mHexBuffer->matchWidth( width() - size );
-    updateView( false, bufferChanged );
-
-    if( mVertScroll->isVisible() != state )
-    {
-      size = (mVertScroll->isVisible() ? mScrollBarSize : 0) + frameWidth()*2;
-      bufferChanged = mHexBuffer->matchWidth( width() - size );
-      updateView( false, bufferChanged );
-    }
-
-    #ifdef USE_NORTHWEST_GRAVITY
-    if( w != dataWidth() )
-    {
-      TQWidget::update();
-    }
-    else
-    {
-      paintFrame();
-    }
-    #endif
-  }
-}
-
-
-
-void CHexViewWidget::paintEvent( TQPaintEvent *e )
-{
-  paintText( e->rect(), true );
-}
-
-
-
-void CHexViewWidget::updateFrameSize( void )
-{
-  int w = width() - (mVertScroll->isVisible() ? mScrollBarSize : 0);
-  if( w < 0 ) { w = 0; }
-  int h = height() - (mHorzScroll->isVisible() ? mScrollBarSize : 0);
-  if( h < 0 ) { h = 0; }
-
-  setFrameRect( TQRect(0,0,w,h) );
-}
-
-
-
-void CHexViewWidget::paintFrame( void )
-{
-  TQPainter paint;
-  paint.begin( this );
-  drawFrame( &paint );
-  paint.end();
-}
-
-
-
-void CHexViewWidget::drawFrame( TQPainter *p )
-{
-  //
-  // 2000-01-10 Espen Sand
-  // I want to display the frame with a custom color whenever the widget
-  // accepts a drop. The setPalette() function causes quite a bit of flicker
-  // in the scrollbars (even when PropagationMode is NoChildren), so I
-  // draw the frame manually when it can accept a drop. Note that the
-  // code below is for the frame shape "TQFrame::WinPanel|TQFrame::Plain"
-  //
-  if( mDropHighlight == true )
-  {
-    qDrawPlainRect( p, frameRect(), TQColor("SteelBlue2"), lineWidth() );
-  }
-  else
-  {
-    TQFrame::drawFrame(p); // Use standard drawFrame
-  }
-}
-
-
-
-void CHexViewWidget::keyPressEvent( TQKeyEvent *e )
-{
-  SCursorConfig cc;
-  cc.state = e->state();
-
-  //
-  // Some special actions that we have to trap here
-  //
-  if( e->state() & ControlButton )
-  {
-    switch( e->key() )
-    {
-      case Key_Space:
-	e->accept();
-	toggleEditor();
-	return;
-      break;
-
-      case Key_1:
-	e->accept();
-	cursorStep( cc, 1 );
-	return;
-      break;
-
-      case Key_2:
-	e->accept();
-	cursorStep( cc, 2 );
-	return;
-      break;
-
-      case Key_4:
-	e->accept();
-	cursorStep( cc, 4 );
-	return;
-      break;
-
-      case Key_8:
-	e->accept();
-	cursorStep( cc, 8 );
-	return;
-      break;
-    }
-  }
-
-  if( e->state() & AltButton )
-  {
-    if( e->key() == Key_Left || e->key() == Key_Right )
-    {
-      emit pleaseStepFile( e->key() == Key_Left ? true : false );
-      e->accept();
-    }
-    else if( e->key() == Key_Up || e->key() == Key_Down )
-    {
-      gotoNextBookmark( e->key() == Key_Down ? true : false );
-      e->accept();
-    }
-    else
-    {
-      e->ignore();
-    }
-    return;
-  }
-
-  switch ( e->key() )
-  {
-    case Key_Left:
-      cursorLeft( cc );
-    break;
-
-    case Key_Right:
-      cursorRight( cc );
-    break;
-
-    case Key_Up:
-      cursorUp( cc );
-    break;
-
-    case Key_Down:
-      cursorDown( cc );
-    break;
-
-    case Key_Home:
-      cursorHome( cc );
-    break;
-
-    case Key_End:
-      cursorEnd( cc );
-    break;
-
-    case Key_Next:
-      cursorPageDown( cc );
-    break;
-
-    case Key_Prior:
-      cursorPageUp( cc );
-    break;
-
-    case Key_Insert:
-      cursorInsert( cc );
-    break;
-
-    case Key_Delete:
-      cursorDelete( cc );
-    break;
-
-    case Key_Backspace:
-      cursorBackspace( cc );
-    break;
-
-    default:
-      if( (e->text()[0]).isPrint() == true )
-      {
-	cursorInput( TQString(e->text())[0] );
-      }
-    break;
-  }
-
-  e->accept();
-}
-
-
-void CHexViewWidget::keyReleaseEvent( TQKeyEvent *e )
-{
-  if( ( e->state() & ShiftButton ) && shiftButtonState() == false )
-  {
-    //
-    // The shift button was pressed when event was triggered, but is
-    // now released. I use this as a sign to copy selected data to the
-    // clipboard.
-    //
-    autoCopy();
-  }
-}
-
-
-void CHexViewWidget::mousePressEvent( TQMouseEvent *e )
-{
-  //
-  // The RMB popup menu is managed by the KContextMenuManager
-  //
-
-  if( e->button() == Qt::LeftButton )
-  {
-    if( e->state() & ControlButton )
-    {
-      if( KContextMenuManager::showOnButtonPress() == true
-	  && mDocumentMenu != 0 )
-      {
-	mDocumentMenu->popup( e->globalPos() );
-      }
-    }
-    else
-    {
-      bool cellLevel = mMisc.cursorJump == false;
-      setCursorPosition( e->x(), e->y(), true, cellLevel );
-    }
-  }
-  else if( e->button() == Qt::MidButton )
-  {
-    paste();
-  }
-
-}
-
-void CHexViewWidget::mouseMoveEvent( TQMouseEvent *e )
-{
-  if( e->state() & Qt::LeftButton )
-  {
-    if( mDragManager->start( e ) == false )
-    {
-      bool cellLevel = mMisc.cursorJump == false||e->state() & ControlButton;
-      setCursorPosition( e->x(), e->y(), false, cellLevel );
-    }
-  }
-}
-
-void CHexViewWidget::mouseReleaseEvent( TQMouseEvent *e )
-{
-  //
-  // The RMB popup menu is managed by the KContextMenuManager
-  //
-
-  if( e->button() == Qt::LeftButton )
-  {
-    if( e->state() & ControlButton )
-    {
-      if( KContextMenuManager::showOnButtonPress() == false
-	  && mDocumentMenu != 0 )
-      {
-	mDocumentMenu->popup( e->globalPos() );
-      }
-    }
-    else
-    {
-      if( mDragManager->clear() == true )
-      {
-	// Remove any selection
-	SCursorConfig cc;
-	cc.setKeepSelection( false );
-	updateCursor( cc, true );
-      }
-      else
-      {
-	mHexBuffer->cursorResetEditArea();
-	autoCopy();
-      }
-    }
-  }
-
-}
-
-
-
-void CHexViewWidget::wheelEvent( TQWheelEvent *e )
-{
-  if( mVertScroll->isVisible() == true )
-  {
-    TQApplication::sendEvent( mVertScroll, e );
-  }
-}
-
-
-void CHexViewWidget::dragEnterEvent( TQDragEnterEvent *e )
-{
-  if( TQTextDrag::canDecode(e) || CHexDrag::canDecode(e) ||
-      KURLDrag::canDecode(e))
-  {
-    e->accept();
-    setDropHighlight( true );
-  }
-}
-
-
-void CHexViewWidget::dragLeaveEvent( TQDragLeaveEvent * )
-{
-  setDropHighlight( false );
-}
-
-
-void CHexViewWidget::dragMoveEvent( TQDragMoveEvent *e )
-{
-  //
-  // Move the cursor if we are dragging (readable) text or binary
-  // data. Note: the TQTextDrag::canDecode() will return true if we
-  // are dragging a file so we have to test for KURLDrag::canDecode()
-  // first.
-  //
-
-  if( KURLDrag::canDecode(e) == true )
-  {
-    return;
-  }
-
-  if( TQTextDrag::canDecode(e) == true || CHexDrag::canDecode(e) == true )
-  {
-    int x = startX() + e->pos().x();
-    int y = startY() + e->pos().y();
-    if( mHexBuffer->setCursorPosition( x, y, false, false ) == true )
-    {
-      SCursorConfig cc;
-      cc.setKeepSelection( true );
-      updateCursor( cc, false, false );
-    }
-  }
-}
-
-
-void CHexViewWidget::dropEvent( TQDropEvent *e )
-{
-  TQMimeSource &m = *(TQDropEvent*)e;
-  setDropHighlight( false );
-
-  KURL::List list;
-  if( KURLDrag::decode( &m, list ) == true )
-  {
-    //
-    // This widget can not itself open a file so it will simply pass
-    // the request to a parent that can (hopefully) do this
-    //
-    for( KURL::List::ConstIterator it = list.begin(); it != list.end(); it++ )
-    {
-      emit pleaseOpenFile( (*it).url(), true, 0 );
-    }
-    return;
-  }
-
-  TQByteArray buf;
-  if( CHexDrag::decode( &m, buf ) == true )
-  {
-    insert( buf );
-    return;
-  }
-
-  TQString text;
-  if( TQTextDrag::decode( &m, text ) == true )
-  {
-    bool success = mClipConvert.decode( buf, text );
-    if( success == true )
-    {
-      insert( buf );
-    }
-    return;
-  }
-
-}
-
-
-void CHexViewWidget::showEvent( TQShowEvent * )
-{
-  // Currently we do nothing here.
-}
-
-
-
-
-void CHexViewWidget::timerEvent( TQTimerEvent *e )
-{
-  if( e->timerId() == mCursorTimerId )
-  {
-    if( hasFocus() == true )
-    {
-      if( mCursor.alwaysVisible == true )
-      {
-	mShowCursor = true;
-      }
-      else
-      {
-	mShowCursor = mShowCursor == true ? false : true;
-      }
-    }
-    else if( mCursor.focusMode == SDisplayCursor::hide )
-    {
-      mShowCursor = false;
-    }
-    else if( mCursor.focusMode == SDisplayCursor::stopBlinking )
-    {
-      mShowCursor = true;
-    }
-    else
-    {
-      mShowCursor = mShowCursor == true ? false : true;
-    }
-    mHexBuffer->setShowCursor( mShowCursor );
-    paintCursor( CHexBuffer::cursor_curr );
-  }
-}
-
-void CHexViewWidget::focusInEvent( TQFocusEvent * )
-{
-  setupCursorTimer();
-  paintCursor( CHexBuffer::cursor_curr );
-}
-
-void CHexViewWidget::focusOutEvent( TQFocusEvent * )
-{
-  if( mCursor.focusMode != SDisplayCursor::ignore )
-  {
-    setupCursorTimer();
-    paintCursor( CHexBuffer::cursor_curr );
-  }
-}
-
-
-void CHexViewWidget::setSelection( uint offset, bool init )
-{
-  bool selectionChanged = mHexBuffer->selectionSet( offset, init );
-  if( selectionChanged == true )
-  {
-    uint off1, off2;
-    mHexBuffer->selectionStartChange( off1, off2 );
-    if( off1 != off2 )
-    {
-      redrawInterval( off1, off2 );
-    }
-    mHexBuffer->selectionStopChange( off1, off2 );
-    if( off1 != off2 )
-    {
-      redrawInterval( off1, off2 );
-    }
-  }
-  mHexBuffer->selectionSyncronize();
-}
-
-
-
-void CHexViewWidget::setMark( uint offset, uint size, bool moveCursor )
-{
-  bool changed;
-  if( size == 0 )
-  {
-    changed = mHexBuffer->markRemove();
-  }
-  else
-  {
-    mHexBuffer->markSet( offset, size );
-    if( moveCursor == true )
-    {
-      changed = false;
-      gotoOffset( offset, 7, false, true );
-    }
-    else
-    {
-      changed = true;
-    }
-  }
-
-  if( changed == true )
-  {
-    uint off1, off2;
-    mHexBuffer->markStartChange( off1, off2 );
-    if( off1 != off2 )
-    {
-      redrawInterval( off1, off2 );
-    }
-
-    mHexBuffer->markStopChange( off1, off2 );
-    if( off1 != off2 )
-    {
-      redrawInterval( off1, off2 );
-    }
-  }
-  mHexBuffer->markSyncronize();
-}
-
-
-
-void CHexViewWidget::setCursorPosition(int x, int y, bool init, bool cellLevel)
-{
-  x += startX();
-  y += startY();
-
-  if( mHexBuffer->setCursorPosition( x, y, init, cellLevel ) == false )
-  {
-    if( init == true )
-    {
-      unselect();
-      unmark();
-    }
-  }
-  else if( init == false )
-  {
-    SCursorConfig cc;
-    cc.setKeepSelection( true );
-    updateCursor( cc, false );
-  }
-  else
-  {
-    SCursorConfig cc;
-    if( mHexBuffer->cursorInsideSelection() == true )
-    {
-      mDragManager->setup( x - startX(), y - startY() );
-      cc.setKeepSelection( true );
-      updateCursor( cc, true, false );
-    }
-    else
-    {
-      cc.setKeepSelection( false );
-      updateCursor( cc, true );
-    }
-  }
-}
-
-
-
-void CHexViewWidget::redrawInterval( uint startOffset, uint stopOffset )
-{
-  //
-  // Can be improved, I repaint the entire line even if the offsets
-  // only specify one byte.
-  //
-  uint lineStart = mHexBuffer->calculateLine( startOffset );
-  uint lineStop  = mHexBuffer->calculateLine( stopOffset );
-  if( lineStart <= lineStop )
-  {
-    redrawLines( lineStart, lineStop - lineStart + 1 );
-  }
-  else
-  {
-    redrawLines( lineStop, lineStart - lineStop + 1 );
-  }
-}
-
-
-
-void CHexViewWidget::redrawLines( uint docLine, int numLine )
-{
-  int lineHeight = mHexBuffer->lineHeight();
-  int lineOffset = startY() / lineHeight;
-
-  // FIXME: startY() should return uint
-  if( (uint)lineOffset > docLine )
-  {
-    numLine -= (lineOffset-docLine);
-    if( numLine <= 0 ) { return; }
-    docLine = lineOffset;
-  }
-
-  int t = docLine * lineHeight - startY() + frameWidth();
-  if( mEditMode == CHexBuffer::EditInsert )
-  {
-    TQRect r = contentsRect();
-    r.setTop( t );
-    paintText( contentsRect().intersect( r ), false );
-  }
-  else
-  {
-    int h = (numLine + (startY() % lineHeight ? 1 : 0)) * lineHeight;
-    TQRect r( contentsRect().left(), t, contentsRect().width(), h );
-    paintText( contentsRect().intersect( r ), false );
-  }
-}
-
-
-
-void CHexViewWidget::redrawFromOffset( uint offset, bool finishWindow )
-{
-  int lineHeight = mHexBuffer->lineHeight();
-  uint docLine   = mHexBuffer->calculateLine( offset );
-
-  int t = docLine * lineHeight - startY() + frameWidth();
-  if( finishWindow == true )
-  {
-    TQRect r = contentsRect();
-    r.setTop( t );
-    paintText( contentsRect().intersect( r ), false );
-  }
-  else
-  {
-    int h = t + lineHeight;
-    TQRect r( contentsRect().left(), t, contentsRect().width(), h );
-    paintText( contentsRect().intersect( r ), false );
-  }
-}
-
-
-
-
-void CHexViewWidget::paintText( const TQRect &rect, bool expand )
-{
-  TQRect r = rect;
-
-  if( expand == true )
-  {
-    #ifdef USE_NORTHWEST_GRAVITY
-    r.setLeft( r.left() - frameWidth() );
-    r.setTop( r.top() - frameWidth() );
-    #endif
-  }
-
-  if( contentsRect().contains( r ) == false )
-  {
-    paintFrame();
-    if( r.left() < frameWidth() ) { r.setLeft( frameWidth() ); }
-    if( r.top() < frameWidth() ) { r.setTop( frameWidth() ); }
-  }
-
-  int maxX = width() - frameWidth() - 1 -
-    (mVertScroll->isVisible() ? mScrollBarSize : 0);
-  int maxY = height() - frameWidth() - 1 -
-    (mHorzScroll->isVisible() ? mScrollBarSize : 0);
-
-  if( r.right() > maxX ) { r.setRight( maxX ); }
-  if( r.bottom() > maxY ) { r.setBottom( maxY ); }
-
-  TQPainter paint( &mTextBuffer );
-  paint.setFont( mHexBuffer->font() );
-
-  int lineHeight = mHexBuffer->lineHeight();
-  int docLine    = (startY() + r.y() - frameWidth()) / lineHeight;
-  if( docLine < 0 ) { docLine = 0; }
-  int y          = docLine * lineHeight - startY();
-  int yMax       = r.height();
-  int xMax       = r.x() + r.width();
-
-  y += frameWidth();
-
-  int s = 0;
-  int d = r.y()-y;
-  int h;
-  while( yMax > 0 )
-  {
-    mHexBuffer->drawText( paint, docLine, startX()-frameWidth(), r.x(), xMax );
-
-    if( d != 0 )
-    {
-      h = lineHeight - d;
-      if( h > yMax ) { h = yMax; }
-    }
-    else
-    {
-      h = yMax > lineHeight ? lineHeight : yMax;
-    }
-    bitBlt( this, r.x(), r.y()+s, &mTextBuffer, r.x(), d, r.width(), h );
-
-    s       += h;
-    yMax    -= h;
-    docLine += 1;
-    d = 0;
-  }
-  paint.end();
-}
-
-
-
-void CHexViewWidget::paintCursor( int cursorMode )
-{
-  TQPainter paint;
-  paint.begin( &mTextBuffer );
-  paint.setFont( mHexBuffer->font() );
-
-  int f = frameWidth();
-
-  if( cursorMode == CHexBuffer::cursor_prev )
-  {
-    int line = mHexBuffer->prevCursorLine();
-    SCursorPosition p;
-
-    mHexBuffer->prevCursor( CHexBuffer::edit_primary, p );
-    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
-    if( p.y + p.h + f > contentsRect().bottom() )
-      p.h = contentsRect().bottom() - p.y - f + 1;
-    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
-
-    mHexBuffer->prevCursor( CHexBuffer::edit_secondary, p );
-    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
-    if( p.y + p.h + f > contentsRect().bottom() )
-      p.h = contentsRect().bottom() - p.y - f + 1;
-    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
-  }
-  else
-  {
-    int line = mHexBuffer->cursorLine();
-    SCursorPosition p;
-
-    mHexBuffer->currCursor( CHexBuffer::edit_primary, p );
-    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
-    if( p.y + p.h + f > contentsRect().bottom() )
-      p.h = contentsRect().bottom() - p.y - f + 1;
-    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
-
-    mHexBuffer->currCursor( CHexBuffer::edit_secondary, p );
-    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
-    if( p.y + p.h + f > contentsRect().bottom() )
-      p.h = contentsRect().bottom() - p.y - f + 1;
-    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
-  }
-
-  paint.end();
-}
-
-
-
-
-
-void CHexViewWidget::updateCursor( SCursorConfig &cc, bool always,
-				   bool touchSelection )
-{
-  if( mHexBuffer->cursorChanged() == false && always == false )
-  {
-    return;
-  }
-
-  //
-  // Make blinking (and perhaps invisible) cursor visible
-  //
-  setupCursorTimer();
-
-  //
-  // Clear cursor at old location
-  //
-  paintCursor( CHexBuffer::cursor_prev );
-
-  //
-  // Compute the new position of the vertical scroll bar.
-  //
-  int position, h;
-  if( cc.controlButton() == true )
-  {
-    //
-    // The cursor should stay fixed (if possible) in the window while
-    // the text is scrolled (e.g., PageUp/Down behavior). The position
-    // of the vertical scrollbar must change just as much as the cursor
-    // has changed in the vertical direction.
-    //
-    h  = frameWidth()*2;
-    h += mHorzScroll->isVisible() == false ? 0 : mScrollBarSize;
-    position = mHexBuffer->cursorFixedPosition( startY(), height()-h );
-    changeYPos( position );
-  }
-  else
-  {
-    h  = frameWidth()*2;
-    h += mHorzScroll->isVisible() == false ? 0 : mScrollBarSize;
-    position = mHexBuffer->cursorChangePosition( startY(), height()-h );
-    changeYPos( position );
-  }
-
-  //
-  // Paint cursor at new location and update the vertical scroll bar.
-  //
-  paintCursor( CHexBuffer::cursor_curr );
-  mVertScroll->blockSignals( true );
-  mVertScroll->setValue( position );
-  mVertScroll->blockSignals( false );
-
-  if( touchSelection == true )
-  {
-    setSelection( mHexBuffer->cursorOffset(), cc.removeSelection() );
-    unmark();
-  }
-  emit cursorChanged( mHexBuffer->cursorState() );
-}
-
-
-
-void CHexViewWidget::toggleEditor( void )
-{
-  bool success = mHexBuffer->toggleEditor();
-  if( success == false )
-  {
-    return;
-  }
-
-  SCursorConfig cc;
-  updateCursor( cc, true );
-  redrawFromOffset( mHexBuffer->cursorOffset(), false );
-}
-
-
-void CHexViewWidget::cursorStep( SCursorConfig &cc, uint stepSize )
-{
-  mHexBuffer->cursorStep( stepSize, cc.altButton() ? false : true, true );
-  cc.emulateControlButton( false );
-  updateCursor( cc );
-}
-
-
-
-void CHexViewWidget::cursorLeft( SCursorConfig &cc )
-{
-  bool cellLevel = mMisc.cursorJump == false || cc.controlButton();
-  cc.emulateControlButton( false );
-  mHexBuffer->cursorLeft( cellLevel );
-  updateCursor( cc, cellLevel );
-}
-
-
-void CHexViewWidget::cursorRight( SCursorConfig &cc )
-{
-  bool cellLevel = mMisc.cursorJump == false || cc.controlButton();
-  cc.emulateControlButton( false );
-  mHexBuffer->cursorRight( cellLevel );
-  updateCursor( cc, cellLevel );
-}
-
-
-
-void CHexViewWidget::cursorUp( SCursorConfig &cc )
-{
-  mHexBuffer->cursorUp( 1 );
-  updateCursor( cc );
-}
-
-
-void CHexViewWidget::cursorDown( SCursorConfig &cc )
-{
-  mHexBuffer->cursorDown( 1 );
-  updateCursor( cc );
-}
-
-
-void CHexViewWidget::cursorHome( SCursorConfig &cc )
-{
-  mHexBuffer->cursorHome( cc.controlButton() );
-  updateCursor( cc );
-}
-
-
-void CHexViewWidget::cursorEnd( SCursorConfig &cc )
-{
-  mHexBuffer->cursorEnd( cc.controlButton() );
-  updateCursor( cc );
-}
-
-
-void CHexViewWidget::cursorPageDown( SCursorConfig &cc )
-{
-  mHexBuffer->cursorDown( height() / mHexBuffer->lineHeight() );
-  cc.emulateControlButton( true );
-  updateCursor( cc );
-}
-
-
-void CHexViewWidget::cursorPageUp( SCursorConfig &cc )
-{
-  mHexBuffer->cursorUp( height() / mHexBuffer->lineHeight() );
-  cc.emulateControlButton( true );
-  updateCursor( cc );
-}
-
-
-void CHexViewWidget::cursorInsert( SCursorConfig &/*cc*/ )
-{
-  // Toggle mode
-  setEditMode( mEditMode == CHexBuffer::EditInsert ?
-	       CHexBuffer::EditReplace : CHexBuffer::EditInsert );
-}
-
-
-
-void CHexViewWidget::cursorDelete( SCursorConfig &/*cc*/ )
-{
-  int numLine = mHexBuffer->numLines();
-
-  bool success = mHexBuffer->removeAtCursor( false );
-  if( success == false )
-  {
-    return;
-  }
-
-  updateWindow( numLine == mHexBuffer->numLines() ? false : true, true );
-  emit dataChanged();
-}
-
-
-void CHexViewWidget::cursorBackspace( SCursorConfig &/*cc*/ )
-{
-  int numLine = mHexBuffer->numLines();
-
-  bool success = mHexBuffer->removeAtCursor( true );
-  if( success == false )
-  {
-    return;
-  }
-
-  updateWindow( numLine == mHexBuffer->numLines() ? false : true, true );
-  emit dataChanged();
-}
-
-
-void CHexViewWidget::cursorInput( TQChar c )
-{
-  uint cursorLine = mHexBuffer->cursorLine();
-  bool success = mHexBuffer->inputAtCursor( c );
-  if( success == false )
-  {
-    return;
-  }
-
-  updateWindow( cursorLine );
-  emit dataChanged();
-}
-
-
-void CHexViewWidget::setEditMode( CHexBuffer::EEditMode mode )
-{
-  mEditMode = mode;
-  mHexBuffer->setEditMode( mEditMode, mCursor.alwaysBlockShape,
-			   mCursor.thickInsertShape );
-  setupCursorTimer();
-
-  //
-  // This will redraw the current line (which contains the cursor)
-  //
-  redrawFromOffset( mHexBuffer->cursorOffset(), false );
-  emit editMode( mEditMode );
-}
-
-
-void CHexViewWidget::setDropHighlight( bool dropHighlight )
-{
-  mDropHighlight = dropHighlight;
-  if( mDropHighlight == true )
-  {
-    //
-    // 2000-01-10 Espen Sand
-    // Highlight. I have reimplemented TQFrame::drawFrame(TQPainter *)
-    // to support a custom frame color. I assume the frame shape is
-    // "TQFrame::WinPanel|TQFrame::Plain" in that function.
-    //
-    setFrameStyle( TQFrame::WinPanel|TQFrame::Plain );
-  }
-  else
-  {
-    setFrameStyle( TQFrame::WinPanel|TQFrame::Sunken );
-  }
-}
-
-
-
-#include "hexviewwidget.moc"
diff --git a/khexedit/hexviewwidget.cpp b/khexedit/hexviewwidget.cpp
new file mode 100644
index 00000000..6c15ae3b
--- /dev/null
+++ b/khexedit/hexviewwidget.cpp
@@ -0,0 +1,2286 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <iostream>
+
+#include <tqclipboard.h>
+#include <tqdrawutil.h>
+
+
+#include <tdeglobalsettings.h>
+#include <tdelocale.h>
+#include <tdepopupmenu.h>
+#include <kdebug.h>
+#include <kurldrag.h>
+
+#include "hexdrag.h"
+#include "hexerror.h"
+#include "hexviewwidget.h"
+
+//
+// The usage of the WNorthWestGravity flag should make screen update
+// faster (less paintEvents). I have had to add update() some places
+// to ensure proper redrawing. Undefine if something goes wrong
+// (i.e. not updated )
+//
+#define USE_NORTHWEST_GRAVITY 1
+
+//
+// I don't want to decide what is best: Drag starts when mouse is moved or
+// after a timeout.
+//
+#define USE_DRAG_MOVEMENT 1
+
+
+
+
+
+
+CDragManager::CDragManager( void )
+{
+  mActivateMode = Movement;
+  mPending = false;
+  mTimerId = 0;
+}
+
+void CDragManager::setActivateMode( EDragActivateMode mode )
+{
+  clear();
+  mActivateMode = mode; // Movement or Timer
+}
+
+void CDragManager::setup( int x, int y )
+{
+  if( mActivateMode == Movement )
+  {
+    mOrigin.setX(x);
+    mOrigin.setY(y);
+  }
+  else
+  {
+    setupTimer();
+  }
+  mPending = true;
+}
+
+bool CDragManager::start( TQMouseEvent *e )
+{
+  if( mPending == false )
+  {
+    return( false );
+  }
+
+  if( mActivateMode == Movement )
+  {
+    if( (mOrigin - e->pos()).manhattanLength() > TDEGlobalSettings::dndEventDelay() )
+    {
+      mPending = false;
+      emit startDrag( e->state() & ShiftButton ? true : false );
+    }
+    return( true );
+  }
+  else // Timer
+  {
+    if( mTimerId != 0 )
+    {
+      removeTimer();
+      mPending = false;
+      emit startDrag( e->state() & ShiftButton ? true : false );
+      return( true );
+    }
+    else
+    {
+      // Should never happen!
+      mPending = false;
+      return( false );
+    }
+  }
+
+}
+
+bool CDragManager::clear( void )
+{
+  if( mPending == false )
+  {
+    return( false );
+  }
+
+  if( mActivateMode == Timer )
+  {
+    removeTimer();
+  }
+
+  mPending = false;
+  return( true );
+}
+
+void CDragManager::timerEvent( TQTimerEvent *e )
+{
+  if( e->timerId() == mTimerId )
+  {
+    removeTimer();
+    if( mPending == true )
+    {
+      mPending = false;
+      emit startDrag( ( kapp->keyboardModifiers() & TDEApplication::ShiftModifier ) );
+    }
+  }
+}
+
+void CDragManager::removeTimer( void )
+{
+  if( mTimerId != 0 )
+  {
+    killTimer( mTimerId );
+    mTimerId = 0;
+  }
+}
+
+void CDragManager::setupTimer( void )
+{
+  if( mTimerId != 0 )
+  {
+    killTimer( mTimerId );
+    mTimerId = 0;
+  }
+  mTimerId = startTimer( 500 );
+}
+
+
+//
+// This widget will use the entire space of the parent widget
+//
+CHexViewWidget::CHexViewWidget( TQWidget *parent, const char *name,
+				CHexBuffer *hexBuffer )
+  : TQFrame( parent, name,
+	    #ifdef USE_NORTHWEST_GRAVITY
+	    TQt::WStaticContents
+	    #else
+	    0
+	    #endif
+	    ), mScrollBarSize( 16 )
+{
+  if( parent == 0 || hexBuffer == 0 ) { return; }
+
+  //
+  // TQt 2.0:
+  // -------
+  // I use the "CScrollBar" because sometimes (very seldom) when I
+  // do a mHorzScroll->hide() the mHorzScroll->isVisible() remains true
+  // in updateView() for a short while. I need the correct visibility
+  // because I have to redraw the area - due to the "WNorthWestGravity" usage.
+  //
+  // I tried to do a
+  // "while( mHorzScroll->isVisible() ) { mHorzScroll->hide(); }"
+  // but then the loop never ended. The "CScrollBar" emits a "hidden()"
+  // signal whenever is receives a TQHideEvent.
+  //
+
+  mVertScroll = new CScrollBar( Qt::Vertical, this );
+  if( mVertScroll == 0 ) { return; }
+  mHorzScroll = new CScrollBar( Qt::Horizontal, this );
+  if( mHorzScroll == 0 ) { return; }
+  mCorner = new TQWidget( this );
+  if( mCorner == 0 ) { return; }
+  connect( mHorzScroll, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(changeXPos(int)) );
+  connect( mVertScroll, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(changeYPos(int)) );
+  connect( mHorzScroll, TQT_SIGNAL(hidden()), TQT_SLOT(update()) );
+  connect( mVertScroll, TQT_SIGNAL(hidden()), TQT_SLOT(update()) );
+  mHorzScroll->hide();
+  mVertScroll->hide();
+
+  mDragManager = new CDragManager();
+  if( mDragManager == 0 ) { return; }
+  #ifdef USE_DRAG_MOVEMENT
+  mDragManager->setActivateMode( CDragManager::Movement );
+  #else
+  mDragManager->setActivateMode( CDragManager::Timer );
+  #endif
+  connect( mDragManager, TQT_SIGNAL(startDrag(bool)), TQT_SLOT(startDrag(bool)) );
+
+  setFrameStyle( TQFrame::WinPanel|TQFrame::Sunken );
+  setWFlags( WResizeNoErase );
+  setFocusPolicy( TQ_StrongFocus );
+
+  mHexBuffer = hexBuffer;
+  mHexBuffer->cursorReset();
+
+  mEditMode      = mHexBuffer->editMode();
+  mShowCursor    = false;
+  mCursorTimerId = 0;
+
+  mDocumentMenu  = 0;
+
+  setTextBufferSize(); // Make sure there is a pixmap buffer
+  setStartX(0);
+  setStartY(0);
+
+  setAcceptDrops(true);
+  setDropHighlight(false); // Init state + frame shape
+  setBackgroundColor( mHexBuffer->backgroundColor() );
+}
+
+
+CHexViewWidget::~CHexViewWidget( void )
+{
+  delete mVertScroll;
+  delete mHorzScroll;
+  delete mCorner;
+  delete mDragManager;
+}
+
+
+int CHexViewWidget::readFile( TQFile &file, const TQString &url, CProgress &p )
+{
+  int errCode = mHexBuffer->readFile( file, url, p );
+  if( errCode != Err_Success )
+  {
+    return( errCode );
+  }
+
+  initFile();
+  return( Err_Success );
+}
+
+
+int CHexViewWidget::insertFile( TQFile &file, CProgress &p )
+{
+  int errCode = mHexBuffer->insertFile( file, p );
+  if( errCode != Err_Success )
+  {
+    return( errCode );
+  }
+
+  updateWindow( true, true );
+
+  emit dataChanged();
+  emit cursorChanged( mHexBuffer->cursorState() );
+  emit layoutChanged( mLayout );
+  return( Err_Success );
+}
+
+
+int CHexViewWidget::newFile( const TQString &url )
+{
+  int errCode = mHexBuffer->newFile( url );
+  if( errCode != Err_Success )
+  {
+    return( errCode );
+  }
+
+  initFile();
+  return( Err_Success );
+}
+
+
+int CHexViewWidget::writeFile( TQFile &file, CProgress &p )
+{
+  int errCode = mHexBuffer->writeFile( file, p );
+  if( errCode == Err_Success )
+  {
+    emit fileState( mHexBuffer->fileState() );
+  }
+  return( errCode );
+}
+
+
+void CHexViewWidget::closeFile( void )
+{
+  emit fileClosed( mHexBuffer->url() );
+  mHexBuffer->closeFile();
+  initFile();
+}
+
+
+
+void CHexViewWidget::initFile( void )
+{
+  setStartX(0);
+  setStartY(0);
+
+  mHexBuffer->cursorReset();
+  mHexBuffer->setLayout( mLayout );
+  mHexBuffer->setFont( mFontInfo );
+  setEditMode( mEditMode );
+  setColor( mColor, false );
+  setCursor( mCursor, false );
+  setMisc( mMisc );
+
+  setBackgroundColor( mHexBuffer->backgroundColor() );
+  setBackgroundMode( NoBackground );
+
+  updateView( true, false );
+  resizeEvent( 0 );
+
+  emit dataChanged();
+  emit cursorChanged( mHexBuffer->cursorState() );
+  emit fileState( mHexBuffer->fileState() );
+  emit encodingChanged( mHexBuffer->encoding() );
+  emit fileName( mHexBuffer->url(), mHexBuffer->hasFileName() );
+  emit bookmarkChanged( mHexBuffer->bookmarkList() );
+}
+
+
+void CHexViewWidget::setBuffer( CHexBuffer *hexBuffer )
+{
+  if( hexBuffer == 0 || mHexBuffer == hexBuffer )
+  {
+    return;
+  }
+
+  unselect();
+  unmark();
+
+  mHexBuffer = hexBuffer;
+  mHexBuffer->setLayout( mLayout );
+  mHexBuffer->setFont( mFontInfo );
+  setEditMode( mEditMode );
+  setColor( mColor, false );
+  setCursor( mCursor, false );
+  setMisc( mMisc );
+
+  if( mLayout.lockLine == false )
+  {
+    mHexBuffer->matchWidth( width() );
+  }
+
+  setBackgroundColor( hexBuffer->backgroundColor() );
+  setBackgroundMode( NoBackground );
+
+  setEditMode( mEditMode );
+  updateWindow();
+
+  emit dataChanged();
+  emit cursorChanged( mHexBuffer->cursorState() );
+  emit fileState( mHexBuffer->fileState() );
+  emit encodingChanged( mHexBuffer->encoding() );
+  emit layoutChanged( mLayout );
+  emit inputModeChanged( mHexBuffer->inputMode() );
+  emit fileName( mHexBuffer->url(), mHexBuffer->hasFileName() );
+  emit bookmarkChanged( mHexBuffer->bookmarkList() );
+}
+
+
+
+
+void CHexViewWidget::changeXPos( int p )
+{
+  int dx = startX() - p;
+  setStartX(p);
+
+
+  if( TQABS(dx) < width() )
+  {
+    scroll( dx, 0, contentsRect() );
+  }
+  else
+  {
+    TQWidget::update();
+  }
+
+  //
+  // If the start position has become 0, then update the view. This
+  // will remove the scrollbar (if it is visible) if the textarea width
+  // is wider than the text. The scrollbar will then disappear under the
+  // mouse pointer.
+  //
+  if( startX() == 0 )
+  {
+    updateView( false, false );
+  }
+
+}
+
+
+void CHexViewWidget::changeYPos( int p )
+{
+  int dy  = startY() - p;
+  setStartY(p);
+
+  if( TQABS( dy ) < height() )
+  {
+    scroll( 0, dy, contentsRect() );
+  }
+  else
+  {
+    TQWidget::update();
+  }
+
+  //
+  // If the start position has become 0, then update the view. This
+  // will remove the scrollbar (if it is visible) if the textarea height
+  // is taller than the text. The scrollbar will then disappear under the
+  // mouse pointer.
+  //
+  if( startY() == 0 )
+  {
+    updateView( false, false );
+  }
+}
+
+
+void CHexViewWidget::clipboardChanged( void )
+{
+  disconnect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
+	     this,TQT_SLOT(clipboardChanged()));
+  unselect();
+}
+
+void CHexViewWidget::paletteChanged( void )
+{
+  setColor( mColor, true );
+}
+
+
+void CHexViewWidget::fontChanged( void )
+{
+  //setFont( kapp->fixedFont, true );
+}
+
+void CHexViewWidget::filter( SFilterControl &fc )
+{
+  int errCode = mHexBuffer->filter( fc );
+  if( errCode == Err_Success )
+  {
+    repaint();
+    emit dataChanged();
+    emit cursorChanged( mHexBuffer->cursorState() );
+  }
+}
+
+
+
+void CHexViewWidget::insert( SInsertData &id )
+{
+  if( id.onCursor == false )
+  {
+    mHexBuffer->cursorGoto( id.offset, 7 );
+  }
+  SCursorConfig cc;
+  updateCursor( cc, true );
+
+  if( id.size == 0 )
+  {
+    return;
+  }
+
+  TQByteArray buf( id.size );
+  if( buf.isNull() == true )
+  {
+    return;
+  }
+  buf.fill( 0 );
+
+  if( id.pattern.size() > 0 )
+  {
+    uint size = id.pattern.size()>buf.size() ? buf.size() : id.pattern.size();
+    if( id.repeatPattern == false )
+    {
+      memcpy( &buf[0], &id.pattern[0], size );
+      if( size < buf.size() )
+      {
+	memset( &buf[size], id.pattern[id.pattern.size()-1], buf.size()-size );
+      }
+    }
+    else
+    {
+      for( uint i=0; i < buf.size(); i+= size )
+      {
+	uint s = i+size > buf.size() ? buf.size()-i : size;
+	memcpy( &buf[i], &id.pattern[0], s );
+      }
+    }
+  }
+
+  insert( buf );
+}
+
+
+void CHexViewWidget::insert( const TQByteArray &buf )
+{
+  if( mHexBuffer->documentPresent() == false )
+  {
+    emit pleaseOpenNewFile();
+    if( mHexBuffer->documentPresent() == false )
+    {
+      return;
+    }
+  }
+
+  uint offset = mHexBuffer->cursorOffset();
+  int errCode = mHexBuffer->inputAtCursor( buf, 0 );
+  if( errCode == Err_Success  )
+  {
+    updateWindow( offset, true );
+    emit dataChanged();
+  }
+}
+
+
+void CHexViewWidget::append( const TQByteArray &buf )
+{
+  if( mHexBuffer->documentPresent() == false )
+  {
+    insert( buf );
+  }
+  else
+  {
+    SCursorConfig cc;
+    cc.emulateControlButton( true );
+    cursorEnd( cc );
+
+    int errCode = mHexBuffer->inputAtCursor( buf, 0 );
+    if( errCode == Err_Success  )
+    {
+      updateWindow( true, true );
+      emit dataChanged();
+    }
+  }
+}
+
+
+void CHexViewWidget::valueOnCursor( TQByteArray &buf, uint size )
+{
+  mHexBuffer->valueOnCursor( buf, size );
+}
+
+
+
+void CHexViewWidget::updateView( bool redraw, bool fixCursor )
+{
+  int f2 = frameWidth() * 2;
+  int scrollBarCount = 0; // Number of visible scrollbars
+  int editWidth = 0;
+  int editHeight = 0;
+
+  for( uint i=0; i < 2; i++ )
+  {
+    editWidth  = width()  - f2; // Total available width
+    editHeight = height() - f2; // Total available height
+    int textWidth  = dataWidth();
+    int textHeight = mHexBuffer->totalHeight();
+
+    //
+    // This will move the start position of the horizontal scrollbar
+    // to the left (if possible) if the text width is smaller than the
+    // edit width.
+    //
+    if( startX() > 0 )
+    {
+      int size = mVertScroll->isVisible() == true ? mScrollBarSize : 0;
+      if( startX() + editWidth - size > textWidth )
+      {
+	int position = textWidth - editWidth + size;
+	setStartX( position > 0 ? position : 0 );
+	#ifdef USE_NORTHWEST_GRAVITY
+	redraw = true;
+	#endif
+      }
+    }
+
+    int tooMuchX = textWidth - editWidth;
+    bool horzScrollbarVisible = startX() > 0 || tooMuchX > 0 ? true : false;
+    if( horzScrollbarVisible == true )
+    {
+      editHeight -= mScrollBarSize;
+    }
+
+
+    //
+    // This will move the start position of the vertical scrollbar
+    // to the top (if possible) if the text height is smaller than the
+    // edit height.
+    //
+    if( startY() > 0 )
+    {
+      if( startY() + editHeight > textHeight )
+      {
+	int position = textHeight - editHeight;
+	setStartY( position > 0 ? position : 0 );
+	#ifdef USE_NORTHWEST_GRAVITY
+	redraw = true;
+	#endif
+      }
+    }
+
+    int tooMuchY  = textHeight - editHeight;
+    int startLine = startY() / textHeight;
+
+    if( startLine > 0 || tooMuchY > 0 )
+    {
+      editWidth -= mScrollBarSize;
+      tooMuchX += mScrollBarSize;
+      if( horzScrollbarVisible == false && tooMuchX > 0 )
+      {
+	// Horizontal scrollbar will be visible after all.
+	editHeight -= mScrollBarSize;
+	tooMuchY += mScrollBarSize;
+      }
+    }
+
+    if( tooMuchX < startX() ) { tooMuchX = startX(); }
+    if( tooMuchY < startY() ) { tooMuchY = startY(); }
+
+    scrollBarCount = 0;
+    if( tooMuchX > 0 && documentPresent() == true )
+    {
+      mHorzScroll->blockSignals( true );
+      mHorzScroll->setGeometry( 0, editHeight+f2, editWidth+f2,mScrollBarSize);
+      mHorzScroll->setRange( 0, tooMuchX );
+      mHorzScroll->setValue( startX() );
+      mHorzScroll->setSteps(mHexBuffer->lineHeight(),editWidth-mScrollBarSize);
+      mHorzScroll->blockSignals( false );
+      if( mHorzScroll->isVisible() == false ) { mHorzScroll->show(); }
+      scrollBarCount ++;
+    }
+    else
+    {
+      if( mHorzScroll->isVisible() == true ) { mHorzScroll->hide(); }
+    }
+
+    if( tooMuchY > 0 && documentPresent() == true )
+    {
+      mVertScroll->blockSignals( true );
+      mVertScroll->setGeometry( editWidth+f2, 0, mScrollBarSize,editHeight+f2);
+      mVertScroll->setRange( 0, tooMuchY );
+      mVertScroll->setValue( startY() );
+      mVertScroll->setSteps(mHexBuffer->lineHeight(),
+			    editHeight-mScrollBarSize );
+      mVertScroll->blockSignals( false );
+      if( mVertScroll->isVisible() == false ) { mVertScroll->show(); }
+      scrollBarCount ++;
+    }
+    else
+    {
+      if( mVertScroll->isVisible() == true ) { mVertScroll->hide(); }
+    }
+
+    if( fixCursor == true )
+    {
+      int position = mHexBuffer->cursorFixedPosition( startY(), height() );
+      if( position != startY() )
+      {
+	setStartY( position );
+	fixCursor = false;
+	continue;
+      }
+    }
+    break;
+  }
+
+
+  if( scrollBarCount == 2 )
+  {
+    mCorner->setGeometry( editWidth+f2, editHeight+f2, mScrollBarSize,
+			  mScrollBarSize );
+    mCorner->show();
+  }
+  else
+  {
+    mCorner->hide();
+  }
+
+
+  updateFrameSize();
+
+  if( redraw == true )
+  {
+    TQWidget::update();
+  }
+}
+
+
+void CHexViewWidget::setPalette( const TQPalette &p )
+{
+  TQWidget::setPalette( p );
+  mCorner->setPalette( p );
+  mVertScroll->setPalette( p );
+  mHorzScroll->setPalette( p );
+}
+
+
+void CHexViewWidget::setLayout( SDisplayLayout &layout )
+{
+  mLayout = layout;
+  mHexBuffer->setLayout( mLayout );
+  updateWindow();
+
+  emit layoutChanged( mLayout );
+  emit cursorChanged( mHexBuffer->cursorState() );
+  emit textWidth( defaultWidth() );
+}
+
+
+void CHexViewWidget::setInputMode( SDisplayInputMode &input )
+{
+  mHexBuffer->setInputMode( input );
+  emit inputModeChanged( mHexBuffer->inputMode() );
+}
+
+
+void CHexViewWidget::setCursor( const SDisplayCursor &cursor,
+                                bool /*updateDisplay*/ )
+{
+  mCursor = cursor;
+  mHexBuffer->setCursorShapeModifier( cursor.alwaysBlockShape,
+				      cursor.thickInsertShape );
+  setupCursorTimer();
+  redrawFromOffset( mHexBuffer->cursorOffset(), false );
+}
+
+void CHexViewWidget::setColor( const SDisplayColor &color,
+			       bool updateDisplay )
+{
+  mColor = color;
+  mHexBuffer->setColor( mColor );
+  if( updateDisplay == true )
+  {
+    repaint();
+  }
+}
+
+void CHexViewWidget::setFont( const SDisplayFontInfo &fontInfo,
+			      bool updateDisplay )
+{
+  mFontInfo = fontInfo;
+  mHexBuffer->setFont( mFontInfo );
+  emit textWidth( defaultWidth() );
+  if( updateDisplay == true )
+  {
+    updateWindow();
+  }
+}
+
+
+
+void CHexViewWidget::setMisc( SDisplayMisc &misc )
+{
+  mMisc = misc;
+  mHexBuffer->setUndoLevel( misc.undoLevel );
+  mHexBuffer->setSoundState( misc.inputSound, misc.fatalSound );
+  mHexBuffer->setBookmarkVisibility( misc.bookmarkOffsetColumn,
+				     misc.bookmarkEditor );
+  if( mHexBuffer->documentPresent() == true )
+  {
+    TQWidget::update();
+  }
+}
+
+
+void CHexViewWidget::setInsertMode( bool insertMode )
+{
+  setEditMode( insertMode == true ? CHexBuffer::EditInsert :
+	       CHexBuffer::EditReplace );
+}
+
+
+int CHexViewWidget::setEncoding( CConversion::EMode mode, CProgress &p )
+{
+  int errCode = mHexBuffer->setEncoding( mode, p );
+  if( errCode == Err_Success )
+  {
+    repaint();
+    emit cursorChanged( mHexBuffer->cursorState() );
+    emit encodingChanged( mHexBuffer->encoding() );
+  }
+  return( errCode );
+}
+
+
+void CHexViewWidget::reportEncoding( void )
+{
+  emit encodingChanged( mHexBuffer->encoding() );
+}
+
+
+void CHexViewWidget::selectAll( void )
+{
+  setSelection( 0, true );
+  setSelection( mHexBuffer->documentSize(), false );
+  autoCopy();
+  emit cursorChanged( mHexBuffer->cursorState() );
+}
+
+void CHexViewWidget::unselect( void )
+{
+  setSelection( 0, true );
+  emit cursorChanged( mHexBuffer->cursorState() );
+}
+
+void CHexViewWidget::unmark( void )
+{
+  setMark( 0, 0, false );
+}
+
+
+int CHexViewWidget::findFirst( SSearchControl &sc )
+{
+  int errCode = mHexBuffer->findFirst( sc );
+  if( errCode == Err_Success ) { updateWindow( true, false ); }
+  return( errCode );
+}
+
+int CHexViewWidget::findNext( SSearchControl &sc )
+{
+  int errCode = mHexBuffer->findNext( sc );
+  if( errCode == Err_Success ) { updateWindow( true, false ); }
+  return( errCode );
+}
+
+int CHexViewWidget::findWrap( SSearchControl &sc )
+{
+  int errCode = mHexBuffer->findWrap( sc );
+  if( errCode == Err_Success ) { updateWindow( true, false ); }
+  return( errCode );
+}
+
+int CHexViewWidget::replaceAll( SSearchControl &sc, bool init )
+{
+  int errCode = mHexBuffer->replaceAll( sc, init );
+  if( errCode == Err_Success )
+  {
+    updateWindow( true, false );
+    emit dataChanged();
+  }
+  return( errCode );
+}
+
+int CHexViewWidget::replaceMarked( SSearchControl &sc )
+{
+  int errCode = mHexBuffer->replaceMarked( sc );
+  if( errCode == Err_Success )
+  {
+    updateWindow( true, false );
+    emit dataChanged();
+  }
+  return( errCode );
+}
+
+int CHexViewWidget::collectStrings( CStringCollectControl &sc )
+{
+  int errCode = mHexBuffer->collectStrings( sc );
+  return( errCode );
+}
+
+
+int CHexViewWidget::collectStatistic( SStatisticControl &sc, CProgress &p )
+{
+  int errCode = mHexBuffer->collectStatistic( sc, p );
+  return( errCode );
+}
+
+
+void CHexViewWidget::gotoOffset( uint offset, uint bit, bool fromCursor,
+				 bool forward )
+{
+  bool reverse = forward == true ? false : true;
+  mHexBuffer->cursorGoto( offset, bit, reverse, fromCursor );
+  updateWindow( true, false );
+}
+
+
+void CHexViewWidget::gotoOffset( uint offset )
+{
+  gotoOffset( offset, 7, true, true );
+}
+
+
+int CHexViewWidget::print( CHexPrinter &printer, CProgress &p )
+{
+  return( mHexBuffer->print( printer, p ) );
+}
+
+
+uint CHexViewWidget::numPage( CHexPrinter &printer )
+{
+  return( mHexBuffer->numPage( printer ) );
+}
+
+
+int CHexViewWidget::exportText( const SExportText &ex, CProgress &p )
+{
+  return( mHexBuffer->exportText( ex, p ) );
+}
+
+
+int CHexViewWidget::exportHtml( const SExportHtml &ex, CProgress &p )
+{
+  return( mHexBuffer->exportHtml( ex, p ) );
+}
+
+
+int CHexViewWidget::exportCArray( const SExportCArray &ex, CProgress &p )
+{
+  return( mHexBuffer->exportCArray( ex, p ) );
+}
+
+
+void CHexViewWidget::startDrag( bool asText )
+{
+  TQByteArray buf;
+  if( asText == true )
+  {
+    if( mHexBuffer->copySelectedText( buf ) != Err_Success )
+    {
+      return;
+    }
+    TQDragObject *d = new TQTextDrag( buf.data(), this );
+    d->dragCopy();
+  }
+  else
+  {
+    if( mHexBuffer->copySelectedData( buf ) != Err_Success )
+    {
+      return;
+    }
+    TQDragObject *d = new CHexDrag( buf, this );
+    d->dragCopy();
+  }
+}
+
+
+
+void CHexViewWidget::copy( void )
+{
+  TQByteArray buf;
+  if( mHexBuffer->copySelectedData( buf ) != Err_Success )
+  {
+    return;
+  }
+  disconnect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
+	     this,TQT_SLOT(clipboardChanged()));
+  //
+  // Note: Do no give the CHexDrag a parent != 0. The clipboard
+  // owns the current dragdata and will destroy it on exit or
+  // when it receives a new object. If the CHexDrag has a parent
+  // != 0, the CHexDrag object will be destroyed when the parent
+  // is destroyed. We will then have a double destroy situation
+  // when the app. is closed (=> segfault).
+  //
+  TQApplication::clipboard()->setData(new CHexDrag( buf ));
+  connect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
+	  this,TQT_SLOT(clipboardChanged()));
+}
+
+
+void CHexViewWidget::copyText( int columnSegment )
+{
+  TQByteArray buf;
+  if( mHexBuffer->copySelectedText( buf, columnSegment ) != Err_Success )
+  {
+    return;
+  }
+
+  disconnect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
+	     this,TQT_SLOT(clipboardChanged()));
+  TQApplication::clipboard()->setText( buf.data() );
+  connect(TQApplication::clipboard(),TQT_SIGNAL(dataChanged()),
+	  this,TQT_SLOT(clipboardChanged()));
+}
+
+
+
+void CHexViewWidget::paste( void )
+{
+  TQMimeSource *data = TQApplication::clipboard()->data();
+  if( data != 0 )
+  {
+    TQByteArray buf;
+    if( CHexDrag::decode( data, buf ) == true )
+    {
+      insert( buf );
+      return;
+    }
+
+    TQString text;
+    if( TQTextDrag::decode( data, text ) == true )
+    {
+      TQByteArray buf;
+      if( mClipConvert.decode( buf, text ) == true )
+      {
+	insert( buf );
+      }
+      return;
+    }
+  }
+
+}
+
+
+void CHexViewWidget::cut( void )
+{
+  copy(); // Always make a copy to the clipboard of what we remove.
+  bool success = mHexBuffer->cutSelection();
+  if( success == false )
+  {
+    return;
+  }
+
+  updateWindow( false, true );
+  emit dataChanged();
+}
+
+
+void CHexViewWidget::undo( void )
+{
+  bool success = mHexBuffer->undo();
+  if( success == false )
+  {
+    return;
+  }
+
+  updateWindow( true, true );
+  emit dataChanged();
+}
+
+
+void CHexViewWidget::redo( void )
+{
+  bool success = mHexBuffer->redo();
+  if( success == false )
+  {
+    return;
+  }
+
+  updateWindow( true, true );
+  emit dataChanged();
+}
+
+
+void CHexViewWidget::addBookmark( int position )
+{
+  int errCode = mHexBuffer->addBookmark( position );
+  if( errCode != Err_Success )
+  {
+    if( errCode == Err_ListFull )
+    {
+      replaceBookmark();
+    }
+    return;
+  }
+  redrawFromOffset( mHexBuffer->cursorOffset(), false );
+
+  emit bookmarkChanged( mHexBuffer->bookmarkList() );
+}
+
+
+
+int CHexViewWidget::bookmarkMenu( const TQString &title )
+{
+  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
+  if( list.count() == 0 )
+  {
+    return( -1 );
+  }
+
+  TQString text;
+  TDEPopupMenu *popup = new TDEPopupMenu(  0 );
+  popup->insertTitle( title );
+  for( uint i=0; i < list.count(); i++ )
+  {
+    const SCursorOffset *p = list.at( i );
+    if( p == 0 ) { continue; }
+
+    text.sprintf("%04X:%04X", p->offset>>16, p->offset&0x0000FFFF );
+    text.prepend( TQString("[%1] %2: ").arg(i+1).arg(i18n("Offset")) );
+    popup->insertItem( text, i );
+  }
+
+  TQSize s(popup->sizeHint());
+  TQPoint center( (width()-s.width())/2, (height()-s.height())/2 );
+  int position = popup->exec( mapToGlobal(center) );
+  delete popup;
+
+  return( position );
+}
+
+
+void CHexViewWidget::removeBookmark( bool all )
+{
+  if( all == true )
+  {
+    bool success = mHexBuffer->removeBookmark( -1 );
+    if( success == false )
+    {
+      return;
+    }
+    TQWidget::update(); // Redraw visisble area.
+  }
+  else
+  {
+    int position = bookmarkMenu( i18n("Remove Bookmark") );
+    if( position < 0 )
+    {
+      return;
+    }
+
+    const SCursorOffset *p = mHexBuffer->bookmarkList().at(position);
+    uint offset = p ? p->offset : 0;
+
+    bool success = mHexBuffer->removeBookmark( position );
+    if( success == false )
+    {
+      return;
+    }
+
+    redrawFromOffset( offset, false );
+  }
+
+  emit bookmarkChanged( mHexBuffer->bookmarkList() );
+}
+
+
+void CHexViewWidget::replaceBookmark( void )
+{
+  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
+  if( list.count() == 0 )
+  {
+    return;
+  }
+
+  int position = bookmarkMenu( i18n("Replace Bookmark") );
+  if( position < 0 )
+  {
+    return;
+  }
+  addBookmark( position );
+}
+
+
+void CHexViewWidget::gotoBookmark( uint position )
+{
+  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
+  if( position >= list.count() )
+  {
+    return;
+  }
+
+  SCursorOffset *p = list.at( position );
+  if( p == 0 )
+  {
+    return;
+  }
+
+  mHexBuffer->cursorGoto( p->offset, p->bit );
+  updateWindow();
+}
+
+
+
+void CHexViewWidget::gotoNextBookmark( bool next )
+{
+  TQPtrList<SCursorOffset> &list = mHexBuffer->bookmarkList();
+  uint offset = mHexBuffer->cursorOffset();
+  uint diff   = ~0;
+
+  SCursorOffset *match = 0;
+
+  //
+  // Note: the list is unsorted.
+  //
+  if( next == true )
+  {
+    for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
+    {
+      if( co->offset > offset )
+      {
+	if( co->offset-offset < diff )
+	{
+	  diff = co->offset-offset;
+	  match = co;
+	}
+      }
+    }
+  }
+  else
+  {
+    for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
+    {
+      if( co->offset < offset )
+      {
+	if( offset-co->offset < diff )
+	{
+	  diff = offset-co->offset;
+	  match = co;
+	}
+      }
+    }
+  }
+
+
+  if( match == 0 )
+  {
+    if( next == true )
+    {
+      // Wrap: Locate entry with smallest offset.
+      offset = ~0;
+      for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
+      {
+	if( co->offset < offset )
+	{
+	  offset = co->offset;
+	  match  = co;
+	}
+      }
+    }
+    else
+    {
+      // Wrap: Locate entry with largest offset.
+      offset=0;
+      for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
+      {
+	if( co->offset > offset )
+	{
+	  offset = co->offset;
+	  match  = co;
+	}
+      }
+    }
+  }
+
+  if( match != 0 )
+  {
+    mHexBuffer->cursorGoto( match->offset, match->bit );
+    updateWindow();
+  }
+}
+
+
+
+
+
+
+//
+// Used to test the speed of drawing
+//
+#include <sys/time.h>
+#include <unistd.h>
+void CHexViewWidget::benchmark( void )
+{
+  struct timeval t1, t2;
+  uint loop = 10;
+
+  gettimeofday( &t1, 0 );
+  for( uint i=0; i< loop; i++ )
+  {
+    paintText( contentsRect(), false );
+  }
+  gettimeofday( &t2, 0 );
+
+
+  uint area  = width() * height();
+  uint last = (t2.tv_sec-t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
+
+  kdDebug(1501) << "Duration: " << (float)last/ 1000000.0 << endl;
+  kdDebug(1501) << "Duration/loop: " << (float)last/ (1000000.0*(float)loop) << endl;
+  kdDebug(1501) << "Area: " << area << endl;
+  kdDebug(1501) << "Loop: " << loop << endl;
+}
+
+
+
+
+
+void CHexViewWidget::resizeEvent( TQResizeEvent * )
+{
+  setTextBufferSize();
+
+  if( mLayout.lockLine == true )
+  {
+    updateView( false, false );
+    #ifdef USE_NORTHWEST_GRAVITY
+    paintFrame();
+    #endif
+  }
+  else
+  {
+    bool state = mVertScroll->isVisible();
+    int size = (state == true ? mScrollBarSize : 0) + frameWidth()*2;
+    #ifdef USE_NORTHWEST_GRAVITY
+    int w = dataWidth();
+    #endif
+
+    bool bufferChanged = mHexBuffer->matchWidth( width() - size );
+    updateView( false, bufferChanged );
+
+    if( mVertScroll->isVisible() != state )
+    {
+      size = (mVertScroll->isVisible() ? mScrollBarSize : 0) + frameWidth()*2;
+      bufferChanged = mHexBuffer->matchWidth( width() - size );
+      updateView( false, bufferChanged );
+    }
+
+    #ifdef USE_NORTHWEST_GRAVITY
+    if( w != dataWidth() )
+    {
+      TQWidget::update();
+    }
+    else
+    {
+      paintFrame();
+    }
+    #endif
+  }
+}
+
+
+
+void CHexViewWidget::paintEvent( TQPaintEvent *e )
+{
+  paintText( e->rect(), true );
+}
+
+
+
+void CHexViewWidget::updateFrameSize( void )
+{
+  int w = width() - (mVertScroll->isVisible() ? mScrollBarSize : 0);
+  if( w < 0 ) { w = 0; }
+  int h = height() - (mHorzScroll->isVisible() ? mScrollBarSize : 0);
+  if( h < 0 ) { h = 0; }
+
+  setFrameRect( TQRect(0,0,w,h) );
+}
+
+
+
+void CHexViewWidget::paintFrame( void )
+{
+  TQPainter paint;
+  paint.begin( this );
+  drawFrame( &paint );
+  paint.end();
+}
+
+
+
+void CHexViewWidget::drawFrame( TQPainter *p )
+{
+  //
+  // 2000-01-10 Espen Sand
+  // I want to display the frame with a custom color whenever the widget
+  // accepts a drop. The setPalette() function causes quite a bit of flicker
+  // in the scrollbars (even when PropagationMode is NoChildren), so I
+  // draw the frame manually when it can accept a drop. Note that the
+  // code below is for the frame shape "TQFrame::WinPanel|TQFrame::Plain"
+  //
+  if( mDropHighlight == true )
+  {
+    qDrawPlainRect( p, frameRect(), TQColor("SteelBlue2"), lineWidth() );
+  }
+  else
+  {
+    TQFrame::drawFrame(p); // Use standard drawFrame
+  }
+}
+
+
+
+void CHexViewWidget::keyPressEvent( TQKeyEvent *e )
+{
+  SCursorConfig cc;
+  cc.state = e->state();
+
+  //
+  // Some special actions that we have to trap here
+  //
+  if( e->state() & ControlButton )
+  {
+    switch( e->key() )
+    {
+      case Key_Space:
+	e->accept();
+	toggleEditor();
+	return;
+      break;
+
+      case Key_1:
+	e->accept();
+	cursorStep( cc, 1 );
+	return;
+      break;
+
+      case Key_2:
+	e->accept();
+	cursorStep( cc, 2 );
+	return;
+      break;
+
+      case Key_4:
+	e->accept();
+	cursorStep( cc, 4 );
+	return;
+      break;
+
+      case Key_8:
+	e->accept();
+	cursorStep( cc, 8 );
+	return;
+      break;
+    }
+  }
+
+  if( e->state() & AltButton )
+  {
+    if( e->key() == Key_Left || e->key() == Key_Right )
+    {
+      emit pleaseStepFile( e->key() == Key_Left ? true : false );
+      e->accept();
+    }
+    else if( e->key() == Key_Up || e->key() == Key_Down )
+    {
+      gotoNextBookmark( e->key() == Key_Down ? true : false );
+      e->accept();
+    }
+    else
+    {
+      e->ignore();
+    }
+    return;
+  }
+
+  switch ( e->key() )
+  {
+    case Key_Left:
+      cursorLeft( cc );
+    break;
+
+    case Key_Right:
+      cursorRight( cc );
+    break;
+
+    case Key_Up:
+      cursorUp( cc );
+    break;
+
+    case Key_Down:
+      cursorDown( cc );
+    break;
+
+    case Key_Home:
+      cursorHome( cc );
+    break;
+
+    case Key_End:
+      cursorEnd( cc );
+    break;
+
+    case Key_Next:
+      cursorPageDown( cc );
+    break;
+
+    case Key_Prior:
+      cursorPageUp( cc );
+    break;
+
+    case Key_Insert:
+      cursorInsert( cc );
+    break;
+
+    case Key_Delete:
+      cursorDelete( cc );
+    break;
+
+    case Key_Backspace:
+      cursorBackspace( cc );
+    break;
+
+    default:
+      if( (e->text()[0]).isPrint() == true )
+      {
+	cursorInput( TQString(e->text())[0] );
+      }
+    break;
+  }
+
+  e->accept();
+}
+
+
+void CHexViewWidget::keyReleaseEvent( TQKeyEvent *e )
+{
+  if( ( e->state() & ShiftButton ) && shiftButtonState() == false )
+  {
+    //
+    // The shift button was pressed when event was triggered, but is
+    // now released. I use this as a sign to copy selected data to the
+    // clipboard.
+    //
+    autoCopy();
+  }
+}
+
+
+void CHexViewWidget::mousePressEvent( TQMouseEvent *e )
+{
+  //
+  // The RMB popup menu is managed by the KContextMenuManager
+  //
+
+  if( e->button() == Qt::LeftButton )
+  {
+    if( e->state() & ControlButton )
+    {
+      if( KContextMenuManager::showOnButtonPress() == true
+	  && mDocumentMenu != 0 )
+      {
+	mDocumentMenu->popup( e->globalPos() );
+      }
+    }
+    else
+    {
+      bool cellLevel = mMisc.cursorJump == false;
+      setCursorPosition( e->x(), e->y(), true, cellLevel );
+    }
+  }
+  else if( e->button() == Qt::MidButton )
+  {
+    paste();
+  }
+
+}
+
+void CHexViewWidget::mouseMoveEvent( TQMouseEvent *e )
+{
+  if( e->state() & Qt::LeftButton )
+  {
+    if( mDragManager->start( e ) == false )
+    {
+      bool cellLevel = mMisc.cursorJump == false||e->state() & ControlButton;
+      setCursorPosition( e->x(), e->y(), false, cellLevel );
+    }
+  }
+}
+
+void CHexViewWidget::mouseReleaseEvent( TQMouseEvent *e )
+{
+  //
+  // The RMB popup menu is managed by the KContextMenuManager
+  //
+
+  if( e->button() == Qt::LeftButton )
+  {
+    if( e->state() & ControlButton )
+    {
+      if( KContextMenuManager::showOnButtonPress() == false
+	  && mDocumentMenu != 0 )
+      {
+	mDocumentMenu->popup( e->globalPos() );
+      }
+    }
+    else
+    {
+      if( mDragManager->clear() == true )
+      {
+	// Remove any selection
+	SCursorConfig cc;
+	cc.setKeepSelection( false );
+	updateCursor( cc, true );
+      }
+      else
+      {
+	mHexBuffer->cursorResetEditArea();
+	autoCopy();
+      }
+    }
+  }
+
+}
+
+
+
+void CHexViewWidget::wheelEvent( TQWheelEvent *e )
+{
+  if( mVertScroll->isVisible() == true )
+  {
+    TQApplication::sendEvent( mVertScroll, e );
+  }
+}
+
+
+void CHexViewWidget::dragEnterEvent( TQDragEnterEvent *e )
+{
+  if( TQTextDrag::canDecode(e) || CHexDrag::canDecode(e) ||
+      KURLDrag::canDecode(e))
+  {
+    e->accept();
+    setDropHighlight( true );
+  }
+}
+
+
+void CHexViewWidget::dragLeaveEvent( TQDragLeaveEvent * )
+{
+  setDropHighlight( false );
+}
+
+
+void CHexViewWidget::dragMoveEvent( TQDragMoveEvent *e )
+{
+  //
+  // Move the cursor if we are dragging (readable) text or binary
+  // data. Note: the TQTextDrag::canDecode() will return true if we
+  // are dragging a file so we have to test for KURLDrag::canDecode()
+  // first.
+  //
+
+  if( KURLDrag::canDecode(e) == true )
+  {
+    return;
+  }
+
+  if( TQTextDrag::canDecode(e) == true || CHexDrag::canDecode(e) == true )
+  {
+    int x = startX() + e->pos().x();
+    int y = startY() + e->pos().y();
+    if( mHexBuffer->setCursorPosition( x, y, false, false ) == true )
+    {
+      SCursorConfig cc;
+      cc.setKeepSelection( true );
+      updateCursor( cc, false, false );
+    }
+  }
+}
+
+
+void CHexViewWidget::dropEvent( TQDropEvent *e )
+{
+  TQMimeSource &m = *(TQDropEvent*)e;
+  setDropHighlight( false );
+
+  KURL::List list;
+  if( KURLDrag::decode( &m, list ) == true )
+  {
+    //
+    // This widget can not itself open a file so it will simply pass
+    // the request to a parent that can (hopefully) do this
+    //
+    for( KURL::List::ConstIterator it = list.begin(); it != list.end(); it++ )
+    {
+      emit pleaseOpenFile( (*it).url(), true, 0 );
+    }
+    return;
+  }
+
+  TQByteArray buf;
+  if( CHexDrag::decode( &m, buf ) == true )
+  {
+    insert( buf );
+    return;
+  }
+
+  TQString text;
+  if( TQTextDrag::decode( &m, text ) == true )
+  {
+    bool success = mClipConvert.decode( buf, text );
+    if( success == true )
+    {
+      insert( buf );
+    }
+    return;
+  }
+
+}
+
+
+void CHexViewWidget::showEvent( TQShowEvent * )
+{
+  // Currently we do nothing here.
+}
+
+
+
+
+void CHexViewWidget::timerEvent( TQTimerEvent *e )
+{
+  if( e->timerId() == mCursorTimerId )
+  {
+    if( hasFocus() == true )
+    {
+      if( mCursor.alwaysVisible == true )
+      {
+	mShowCursor = true;
+      }
+      else
+      {
+	mShowCursor = mShowCursor == true ? false : true;
+      }
+    }
+    else if( mCursor.focusMode == SDisplayCursor::hide )
+    {
+      mShowCursor = false;
+    }
+    else if( mCursor.focusMode == SDisplayCursor::stopBlinking )
+    {
+      mShowCursor = true;
+    }
+    else
+    {
+      mShowCursor = mShowCursor == true ? false : true;
+    }
+    mHexBuffer->setShowCursor( mShowCursor );
+    paintCursor( CHexBuffer::cursor_curr );
+  }
+}
+
+void CHexViewWidget::focusInEvent( TQFocusEvent * )
+{
+  setupCursorTimer();
+  paintCursor( CHexBuffer::cursor_curr );
+}
+
+void CHexViewWidget::focusOutEvent( TQFocusEvent * )
+{
+  if( mCursor.focusMode != SDisplayCursor::ignore )
+  {
+    setupCursorTimer();
+    paintCursor( CHexBuffer::cursor_curr );
+  }
+}
+
+
+void CHexViewWidget::setSelection( uint offset, bool init )
+{
+  bool selectionChanged = mHexBuffer->selectionSet( offset, init );
+  if( selectionChanged == true )
+  {
+    uint off1, off2;
+    mHexBuffer->selectionStartChange( off1, off2 );
+    if( off1 != off2 )
+    {
+      redrawInterval( off1, off2 );
+    }
+    mHexBuffer->selectionStopChange( off1, off2 );
+    if( off1 != off2 )
+    {
+      redrawInterval( off1, off2 );
+    }
+  }
+  mHexBuffer->selectionSyncronize();
+}
+
+
+
+void CHexViewWidget::setMark( uint offset, uint size, bool moveCursor )
+{
+  bool changed;
+  if( size == 0 )
+  {
+    changed = mHexBuffer->markRemove();
+  }
+  else
+  {
+    mHexBuffer->markSet( offset, size );
+    if( moveCursor == true )
+    {
+      changed = false;
+      gotoOffset( offset, 7, false, true );
+    }
+    else
+    {
+      changed = true;
+    }
+  }
+
+  if( changed == true )
+  {
+    uint off1, off2;
+    mHexBuffer->markStartChange( off1, off2 );
+    if( off1 != off2 )
+    {
+      redrawInterval( off1, off2 );
+    }
+
+    mHexBuffer->markStopChange( off1, off2 );
+    if( off1 != off2 )
+    {
+      redrawInterval( off1, off2 );
+    }
+  }
+  mHexBuffer->markSyncronize();
+}
+
+
+
+void CHexViewWidget::setCursorPosition(int x, int y, bool init, bool cellLevel)
+{
+  x += startX();
+  y += startY();
+
+  if( mHexBuffer->setCursorPosition( x, y, init, cellLevel ) == false )
+  {
+    if( init == true )
+    {
+      unselect();
+      unmark();
+    }
+  }
+  else if( init == false )
+  {
+    SCursorConfig cc;
+    cc.setKeepSelection( true );
+    updateCursor( cc, false );
+  }
+  else
+  {
+    SCursorConfig cc;
+    if( mHexBuffer->cursorInsideSelection() == true )
+    {
+      mDragManager->setup( x - startX(), y - startY() );
+      cc.setKeepSelection( true );
+      updateCursor( cc, true, false );
+    }
+    else
+    {
+      cc.setKeepSelection( false );
+      updateCursor( cc, true );
+    }
+  }
+}
+
+
+
+void CHexViewWidget::redrawInterval( uint startOffset, uint stopOffset )
+{
+  //
+  // Can be improved, I repaint the entire line even if the offsets
+  // only specify one byte.
+  //
+  uint lineStart = mHexBuffer->calculateLine( startOffset );
+  uint lineStop  = mHexBuffer->calculateLine( stopOffset );
+  if( lineStart <= lineStop )
+  {
+    redrawLines( lineStart, lineStop - lineStart + 1 );
+  }
+  else
+  {
+    redrawLines( lineStop, lineStart - lineStop + 1 );
+  }
+}
+
+
+
+void CHexViewWidget::redrawLines( uint docLine, int numLine )
+{
+  int lineHeight = mHexBuffer->lineHeight();
+  int lineOffset = startY() / lineHeight;
+
+  // FIXME: startY() should return uint
+  if( (uint)lineOffset > docLine )
+  {
+    numLine -= (lineOffset-docLine);
+    if( numLine <= 0 ) { return; }
+    docLine = lineOffset;
+  }
+
+  int t = docLine * lineHeight - startY() + frameWidth();
+  if( mEditMode == CHexBuffer::EditInsert )
+  {
+    TQRect r = contentsRect();
+    r.setTop( t );
+    paintText( contentsRect().intersect( r ), false );
+  }
+  else
+  {
+    int h = (numLine + (startY() % lineHeight ? 1 : 0)) * lineHeight;
+    TQRect r( contentsRect().left(), t, contentsRect().width(), h );
+    paintText( contentsRect().intersect( r ), false );
+  }
+}
+
+
+
+void CHexViewWidget::redrawFromOffset( uint offset, bool finishWindow )
+{
+  int lineHeight = mHexBuffer->lineHeight();
+  uint docLine   = mHexBuffer->calculateLine( offset );
+
+  int t = docLine * lineHeight - startY() + frameWidth();
+  if( finishWindow == true )
+  {
+    TQRect r = contentsRect();
+    r.setTop( t );
+    paintText( contentsRect().intersect( r ), false );
+  }
+  else
+  {
+    int h = t + lineHeight;
+    TQRect r( contentsRect().left(), t, contentsRect().width(), h );
+    paintText( contentsRect().intersect( r ), false );
+  }
+}
+
+
+
+
+void CHexViewWidget::paintText( const TQRect &rect, bool expand )
+{
+  TQRect r = rect;
+
+  if( expand == true )
+  {
+    #ifdef USE_NORTHWEST_GRAVITY
+    r.setLeft( r.left() - frameWidth() );
+    r.setTop( r.top() - frameWidth() );
+    #endif
+  }
+
+  if( contentsRect().contains( r ) == false )
+  {
+    paintFrame();
+    if( r.left() < frameWidth() ) { r.setLeft( frameWidth() ); }
+    if( r.top() < frameWidth() ) { r.setTop( frameWidth() ); }
+  }
+
+  int maxX = width() - frameWidth() - 1 -
+    (mVertScroll->isVisible() ? mScrollBarSize : 0);
+  int maxY = height() - frameWidth() - 1 -
+    (mHorzScroll->isVisible() ? mScrollBarSize : 0);
+
+  if( r.right() > maxX ) { r.setRight( maxX ); }
+  if( r.bottom() > maxY ) { r.setBottom( maxY ); }
+
+  TQPainter paint( &mTextBuffer );
+  paint.setFont( mHexBuffer->font() );
+
+  int lineHeight = mHexBuffer->lineHeight();
+  int docLine    = (startY() + r.y() - frameWidth()) / lineHeight;
+  if( docLine < 0 ) { docLine = 0; }
+  int y          = docLine * lineHeight - startY();
+  int yMax       = r.height();
+  int xMax       = r.x() + r.width();
+
+  y += frameWidth();
+
+  int s = 0;
+  int d = r.y()-y;
+  int h;
+  while( yMax > 0 )
+  {
+    mHexBuffer->drawText( paint, docLine, startX()-frameWidth(), r.x(), xMax );
+
+    if( d != 0 )
+    {
+      h = lineHeight - d;
+      if( h > yMax ) { h = yMax; }
+    }
+    else
+    {
+      h = yMax > lineHeight ? lineHeight : yMax;
+    }
+    bitBlt( this, r.x(), r.y()+s, &mTextBuffer, r.x(), d, r.width(), h );
+
+    s       += h;
+    yMax    -= h;
+    docLine += 1;
+    d = 0;
+  }
+  paint.end();
+}
+
+
+
+void CHexViewWidget::paintCursor( int cursorMode )
+{
+  TQPainter paint;
+  paint.begin( &mTextBuffer );
+  paint.setFont( mHexBuffer->font() );
+
+  int f = frameWidth();
+
+  if( cursorMode == CHexBuffer::cursor_prev )
+  {
+    int line = mHexBuffer->prevCursorLine();
+    SCursorPosition p;
+
+    mHexBuffer->prevCursor( CHexBuffer::edit_primary, p );
+    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
+    if( p.y + p.h + f > contentsRect().bottom() )
+      p.h = contentsRect().bottom() - p.y - f + 1;
+    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
+
+    mHexBuffer->prevCursor( CHexBuffer::edit_secondary, p );
+    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
+    if( p.y + p.h + f > contentsRect().bottom() )
+      p.h = contentsRect().bottom() - p.y - f + 1;
+    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
+  }
+  else
+  {
+    int line = mHexBuffer->cursorLine();
+    SCursorPosition p;
+
+    mHexBuffer->currCursor( CHexBuffer::edit_primary, p );
+    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
+    if( p.y + p.h + f > contentsRect().bottom() )
+      p.h = contentsRect().bottom() - p.y - f + 1;
+    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
+
+    mHexBuffer->currCursor( CHexBuffer::edit_secondary, p );
+    mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
+    if( p.y + p.h + f > contentsRect().bottom() )
+      p.h = contentsRect().bottom() - p.y - f + 1;
+    bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
+  }
+
+  paint.end();
+}
+
+
+
+
+
+void CHexViewWidget::updateCursor( SCursorConfig &cc, bool always,
+				   bool touchSelection )
+{
+  if( mHexBuffer->cursorChanged() == false && always == false )
+  {
+    return;
+  }
+
+  //
+  // Make blinking (and perhaps invisible) cursor visible
+  //
+  setupCursorTimer();
+
+  //
+  // Clear cursor at old location
+  //
+  paintCursor( CHexBuffer::cursor_prev );
+
+  //
+  // Compute the new position of the vertical scroll bar.
+  //
+  int position, h;
+  if( cc.controlButton() == true )
+  {
+    //
+    // The cursor should stay fixed (if possible) in the window while
+    // the text is scrolled (e.g., PageUp/Down behavior). The position
+    // of the vertical scrollbar must change just as much as the cursor
+    // has changed in the vertical direction.
+    //
+    h  = frameWidth()*2;
+    h += mHorzScroll->isVisible() == false ? 0 : mScrollBarSize;
+    position = mHexBuffer->cursorFixedPosition( startY(), height()-h );
+    changeYPos( position );
+  }
+  else
+  {
+    h  = frameWidth()*2;
+    h += mHorzScroll->isVisible() == false ? 0 : mScrollBarSize;
+    position = mHexBuffer->cursorChangePosition( startY(), height()-h );
+    changeYPos( position );
+  }
+
+  //
+  // Paint cursor at new location and update the vertical scroll bar.
+  //
+  paintCursor( CHexBuffer::cursor_curr );
+  mVertScroll->blockSignals( true );
+  mVertScroll->setValue( position );
+  mVertScroll->blockSignals( false );
+
+  if( touchSelection == true )
+  {
+    setSelection( mHexBuffer->cursorOffset(), cc.removeSelection() );
+    unmark();
+  }
+  emit cursorChanged( mHexBuffer->cursorState() );
+}
+
+
+
+void CHexViewWidget::toggleEditor( void )
+{
+  bool success = mHexBuffer->toggleEditor();
+  if( success == false )
+  {
+    return;
+  }
+
+  SCursorConfig cc;
+  updateCursor( cc, true );
+  redrawFromOffset( mHexBuffer->cursorOffset(), false );
+}
+
+
+void CHexViewWidget::cursorStep( SCursorConfig &cc, uint stepSize )
+{
+  mHexBuffer->cursorStep( stepSize, cc.altButton() ? false : true, true );
+  cc.emulateControlButton( false );
+  updateCursor( cc );
+}
+
+
+
+void CHexViewWidget::cursorLeft( SCursorConfig &cc )
+{
+  bool cellLevel = mMisc.cursorJump == false || cc.controlButton();
+  cc.emulateControlButton( false );
+  mHexBuffer->cursorLeft( cellLevel );
+  updateCursor( cc, cellLevel );
+}
+
+
+void CHexViewWidget::cursorRight( SCursorConfig &cc )
+{
+  bool cellLevel = mMisc.cursorJump == false || cc.controlButton();
+  cc.emulateControlButton( false );
+  mHexBuffer->cursorRight( cellLevel );
+  updateCursor( cc, cellLevel );
+}
+
+
+
+void CHexViewWidget::cursorUp( SCursorConfig &cc )
+{
+  mHexBuffer->cursorUp( 1 );
+  updateCursor( cc );
+}
+
+
+void CHexViewWidget::cursorDown( SCursorConfig &cc )
+{
+  mHexBuffer->cursorDown( 1 );
+  updateCursor( cc );
+}
+
+
+void CHexViewWidget::cursorHome( SCursorConfig &cc )
+{
+  mHexBuffer->cursorHome( cc.controlButton() );
+  updateCursor( cc );
+}
+
+
+void CHexViewWidget::cursorEnd( SCursorConfig &cc )
+{
+  mHexBuffer->cursorEnd( cc.controlButton() );
+  updateCursor( cc );
+}
+
+
+void CHexViewWidget::cursorPageDown( SCursorConfig &cc )
+{
+  mHexBuffer->cursorDown( height() / mHexBuffer->lineHeight() );
+  cc.emulateControlButton( true );
+  updateCursor( cc );
+}
+
+
+void CHexViewWidget::cursorPageUp( SCursorConfig &cc )
+{
+  mHexBuffer->cursorUp( height() / mHexBuffer->lineHeight() );
+  cc.emulateControlButton( true );
+  updateCursor( cc );
+}
+
+
+void CHexViewWidget::cursorInsert( SCursorConfig &/*cc*/ )
+{
+  // Toggle mode
+  setEditMode( mEditMode == CHexBuffer::EditInsert ?
+	       CHexBuffer::EditReplace : CHexBuffer::EditInsert );
+}
+
+
+
+void CHexViewWidget::cursorDelete( SCursorConfig &/*cc*/ )
+{
+  int numLine = mHexBuffer->numLines();
+
+  bool success = mHexBuffer->removeAtCursor( false );
+  if( success == false )
+  {
+    return;
+  }
+
+  updateWindow( numLine == mHexBuffer->numLines() ? false : true, true );
+  emit dataChanged();
+}
+
+
+void CHexViewWidget::cursorBackspace( SCursorConfig &/*cc*/ )
+{
+  int numLine = mHexBuffer->numLines();
+
+  bool success = mHexBuffer->removeAtCursor( true );
+  if( success == false )
+  {
+    return;
+  }
+
+  updateWindow( numLine == mHexBuffer->numLines() ? false : true, true );
+  emit dataChanged();
+}
+
+
+void CHexViewWidget::cursorInput( TQChar c )
+{
+  uint cursorLine = mHexBuffer->cursorLine();
+  bool success = mHexBuffer->inputAtCursor( c );
+  if( success == false )
+  {
+    return;
+  }
+
+  updateWindow( cursorLine );
+  emit dataChanged();
+}
+
+
+void CHexViewWidget::setEditMode( CHexBuffer::EEditMode mode )
+{
+  mEditMode = mode;
+  mHexBuffer->setEditMode( mEditMode, mCursor.alwaysBlockShape,
+			   mCursor.thickInsertShape );
+  setupCursorTimer();
+
+  //
+  // This will redraw the current line (which contains the cursor)
+  //
+  redrawFromOffset( mHexBuffer->cursorOffset(), false );
+  emit editMode( mEditMode );
+}
+
+
+void CHexViewWidget::setDropHighlight( bool dropHighlight )
+{
+  mDropHighlight = dropHighlight;
+  if( mDropHighlight == true )
+  {
+    //
+    // 2000-01-10 Espen Sand
+    // Highlight. I have reimplemented TQFrame::drawFrame(TQPainter *)
+    // to support a custom frame color. I assume the frame shape is
+    // "TQFrame::WinPanel|TQFrame::Plain" in that function.
+    //
+    setFrameStyle( TQFrame::WinPanel|TQFrame::Plain );
+  }
+  else
+  {
+    setFrameStyle( TQFrame::WinPanel|TQFrame::Sunken );
+  }
+}
+
+
+
+#include "hexviewwidget.moc"
diff --git a/khexedit/listview.cc b/khexedit/listview.cc
deleted file mode 100644
index f9ff882e..00000000
--- a/khexedit/listview.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <tqheader.h>
-
-
-#include "listview.h"
-
-
-CListView::CListView( TQWidget *parent, const char *name, int visibleItem )
-  :TDEListView( parent, name ),  mVisibleItem(TQMAX( 1, visibleItem ))
-{
-  setVisibleItem(visibleItem);
-}
-
-void CListView::setVisibleItem( int visibleItem, bool updateSize )
-{
-  mVisibleItem = TQMAX( 1, visibleItem );
-  if( updateSize == true )
-  {
-    TQSize s = sizeHint();
-    setMinimumSize( s.width() + verticalScrollBar()->sizeHint().width() + 
-		    lineWidth() * 2, s.height() );
-  }
-}
-
-TQSize CListView::sizeHint( void ) const
-{
-  TQSize s = TQListView::sizeHint();
-  
-  int h = fontMetrics().height() + 2*itemMargin();
-  if( h % 2 > 0 ) { h++; }
-  
-  s.setHeight( h*mVisibleItem + lineWidth()*2 + header()->sizeHint().height());
-  return( s );
-}
-#include "listview.moc"
diff --git a/khexedit/listview.cpp b/khexedit/listview.cpp
new file mode 100644
index 00000000..f9ff882e
--- /dev/null
+++ b/khexedit/listview.cpp
@@ -0,0 +1,54 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <tqheader.h>
+
+
+#include "listview.h"
+
+
+CListView::CListView( TQWidget *parent, const char *name, int visibleItem )
+  :TDEListView( parent, name ),  mVisibleItem(TQMAX( 1, visibleItem ))
+{
+  setVisibleItem(visibleItem);
+}
+
+void CListView::setVisibleItem( int visibleItem, bool updateSize )
+{
+  mVisibleItem = TQMAX( 1, visibleItem );
+  if( updateSize == true )
+  {
+    TQSize s = sizeHint();
+    setMinimumSize( s.width() + verticalScrollBar()->sizeHint().width() + 
+		    lineWidth() * 2, s.height() );
+  }
+}
+
+TQSize CListView::sizeHint( void ) const
+{
+  TQSize s = TQListView::sizeHint();
+  
+  int h = fontMetrics().height() + 2*itemMargin();
+  if( h % 2 > 0 ) { h++; }
+  
+  s.setHeight( h*mVisibleItem + lineWidth()*2 + header()->sizeHint().height());
+  return( s );
+}
+#include "listview.moc"
diff --git a/khexedit/main.cc b/khexedit/main.cc
deleted file mode 100644
index 4fecab6a..00000000
--- a/khexedit/main.cc
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-
-#include <stdlib.h>
-
-#include <tdeapplication.h>
-#include <tdelocale.h>
-#include <tdecmdlineargs.h>
-#include <tdeaboutdata.h>
-
-#include "toplevel.h"
-#include "version.h" // Contains khexedit name string and version string
-
-
-static const char description[] =
-	I18N_NOOP("TDE hex editor");
-
-static const char version[] = APP_VERSION_STRING;
-
-static TDECmdLineOptions option[] =
-{
-   { "offset <offset>", I18N_NOOP("Jump to 'offset'"), 0 },
-   { "+[file(s)]", I18N_NOOP("File(s) to open"), 0 },
-   TDECmdLineLastOption
-};
-
-static uint parseDecimalOrHexadecimal( char *buf );
-
-int main( int argc, char **argv )
-{
-  TDEAboutData aboutData("khexedit", I18N_NOOP("KHexEdit"),
-    version, description, TDEAboutData::License_GPL_V2,
-    "(c) 1999-2000, Espen Sand");
-  aboutData.addAuthor("Espen Sand",0, "espensa@online.no",
-		      "http://home.online.no/~espensa/khexedit/" );
-  aboutData.addCredit("",I18N_NOOP("\n"
-    "This program uses modified code and techniques from other TDE programs,\n"
-    "specifically kwrite, tdeiconedit and ksysv. Credit goes to authors\n"
-    "and maintainers.\n"
-    "\n"
-    "Leon Lessing, leon@lrlabs.com, has made parts of the bit swapping\n"
-    "functionality.\n"
-    "\n"
-    "Craig Graham, c_graham@hinge.mistral.co.uk, has made parts of\n"
-    "the bit stream functionality of the conversion field.\n"
-    "\n"
-    "Dima Rogozin, dima@mercury.co.il, has extended the string dialog\n"
-    "list capabilities.\n"
-    "\n"
-    "Edward Livingston-Blade, sbcs@bigfoot.com, has given me very good\n"
-    "reports which removed some nasty bugs.\n"));
-  TDECmdLineArgs::init( argc, argv, &aboutData );
-  TDECmdLineArgs::addCmdLineOptions( option );
-
-  TDEApplication app;
-
-  if( app.isRestored() != 0 )
-  {
-    RESTORE( KHexEdit );
-  }
-  else
-  {
-    KHexEdit *hexEdit = new KHexEdit;
-    if( hexEdit == 0 )
-    {
-      std::cerr << "Unable to start - Memory exhausted" << std::endl;
-      return( 1 );
-    }
-
-    hexEdit->show();
-
-    TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
-
-    if (args->isSet("offset"))
-    {
-        TQCString offsetStr = args->getOption("offset");
-        uint _offset = parseDecimalOrHexadecimal(offsetStr.data() );
-        hexEdit->setStartupOffset( _offset );
-    }
-
-    for(int i = 0; i < args->count(); i++)
-      hexEdit->addStartupFile( args->url(i).url() );
-
-    args->clear();
-  }
-
-  int result = app.exec();
-  return( result );
-}
-
-
-
-static uint parseDecimalOrHexadecimal( char *buf )
-{
-  if( buf == 0 ) { return( 0 ); }
-  
-  long int value;
-  char *end = 0;
-	    
-  value = strtol( buf, &end, 10 );
-  if( *end != 0 )
-  {
-    value = strtol( buf, &end, 16 );
-    if( *end != 0 )
-    {
-      value = 0;
-    }
-  }
-  if( value < 0 ) { value = 0; }
-  return( value );
-}
-
diff --git a/khexedit/main.cpp b/khexedit/main.cpp
new file mode 100644
index 00000000..4fecab6a
--- /dev/null
+++ b/khexedit/main.cpp
@@ -0,0 +1,130 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+
+#include <stdlib.h>
+
+#include <tdeapplication.h>
+#include <tdelocale.h>
+#include <tdecmdlineargs.h>
+#include <tdeaboutdata.h>
+
+#include "toplevel.h"
+#include "version.h" // Contains khexedit name string and version string
+
+
+static const char description[] =
+	I18N_NOOP("TDE hex editor");
+
+static const char version[] = APP_VERSION_STRING;
+
+static TDECmdLineOptions option[] =
+{
+   { "offset <offset>", I18N_NOOP("Jump to 'offset'"), 0 },
+   { "+[file(s)]", I18N_NOOP("File(s) to open"), 0 },
+   TDECmdLineLastOption
+};
+
+static uint parseDecimalOrHexadecimal( char *buf );
+
+int main( int argc, char **argv )
+{
+  TDEAboutData aboutData("khexedit", I18N_NOOP("KHexEdit"),
+    version, description, TDEAboutData::License_GPL_V2,
+    "(c) 1999-2000, Espen Sand");
+  aboutData.addAuthor("Espen Sand",0, "espensa@online.no",
+		      "http://home.online.no/~espensa/khexedit/" );
+  aboutData.addCredit("",I18N_NOOP("\n"
+    "This program uses modified code and techniques from other TDE programs,\n"
+    "specifically kwrite, tdeiconedit and ksysv. Credit goes to authors\n"
+    "and maintainers.\n"
+    "\n"
+    "Leon Lessing, leon@lrlabs.com, has made parts of the bit swapping\n"
+    "functionality.\n"
+    "\n"
+    "Craig Graham, c_graham@hinge.mistral.co.uk, has made parts of\n"
+    "the bit stream functionality of the conversion field.\n"
+    "\n"
+    "Dima Rogozin, dima@mercury.co.il, has extended the string dialog\n"
+    "list capabilities.\n"
+    "\n"
+    "Edward Livingston-Blade, sbcs@bigfoot.com, has given me very good\n"
+    "reports which removed some nasty bugs.\n"));
+  TDECmdLineArgs::init( argc, argv, &aboutData );
+  TDECmdLineArgs::addCmdLineOptions( option );
+
+  TDEApplication app;
+
+  if( app.isRestored() != 0 )
+  {
+    RESTORE( KHexEdit );
+  }
+  else
+  {
+    KHexEdit *hexEdit = new KHexEdit;
+    if( hexEdit == 0 )
+    {
+      std::cerr << "Unable to start - Memory exhausted" << std::endl;
+      return( 1 );
+    }
+
+    hexEdit->show();
+
+    TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
+
+    if (args->isSet("offset"))
+    {
+        TQCString offsetStr = args->getOption("offset");
+        uint _offset = parseDecimalOrHexadecimal(offsetStr.data() );
+        hexEdit->setStartupOffset( _offset );
+    }
+
+    for(int i = 0; i < args->count(); i++)
+      hexEdit->addStartupFile( args->url(i).url() );
+
+    args->clear();
+  }
+
+  int result = app.exec();
+  return( result );
+}
+
+
+
+static uint parseDecimalOrHexadecimal( char *buf )
+{
+  if( buf == 0 ) { return( 0 ); }
+  
+  long int value;
+  char *end = 0;
+	    
+  value = strtol( buf, &end, 10 );
+  if( *end != 0 )
+  {
+    value = strtol( buf, &end, 16 );
+    if( *end != 0 )
+    {
+      value = 0;
+    }
+  }
+  if( value < 0 ) { value = 0; }
+  return( value );
+}
+
diff --git a/khexedit/optiondialog.cc b/khexedit/optiondialog.cc
deleted file mode 100644
index 49a33b75..00000000
--- a/khexedit/optiondialog.cc
+++ /dev/null
@@ -1,1224 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <limits.h>
-
-#include <tqvbox.h>
-#include <tqvbuttongroup.h>
-#include <tqpainter.h>
-
-#include <tqcheckbox.h>
-#include <tqlayout.h>
-#include <tqlabel.h>
-#include <tqradiobutton.h>
-#include <tqspinbox.h>
-#include <tqwhatsthis.h>
-
-#include <kcolordialog.h>
-#include <kcolordrag.h>
-#include <tdefontdialog.h> // For TDEFontChooser
-#include <kiconloader.h>
-#include <tdelocale.h>
-#include <tdeglobalsettings.h>
-
-#include "optiondialog.h"
-#include <tqpushbutton.h>
-#include <tqcombobox.h>
-
-#if 0
-#include <tqobjectlist.h>
-static void enableWidget( TQWidget *w, bool state )
-{
-  if( w->children() )
-  {
-    TQObjectList *l = (TQObjectList*)w->children(); // silence please
-    for( uint i=0; i < l->count(); i++ )
-    {
-      TQObject *o = l->at(i);
-      if( o->isWidgetType() )
-      {
-	enableWidget( (TQWidget*)o, state );
-      }
-    }
-  }
-  w->setEnabled( state );
-}
-#endif
-
-
-
-COptionDialog::COptionDialog( TQWidget *parent, char *name, bool modal )
-  :KDialogBase( IconList, i18n("Configure"), Help|Default|Apply|Ok|Cancel,
-		Ok, parent, name, modal, true )
-{
-  setHelp( "khexedit/khexedit.html", TQString() );
-
-  setupLayoutPage();
-  setupCursorPage();
-  setupFontPage();
-  setupColorPage();
-  setupFilePage();
-  setupMiscPage();
-  enableButton( Apply, false );
-  configChanged = false;
-}
-
-
-COptionDialog::~COptionDialog( void )
-{
-}
-
-void COptionDialog::slotChanged()
-{
-  enableButton( Apply, true );
-  configChanged = true;
-}
-
-void COptionDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  showPage(0);
-  mLayout.lineSizeSpin->setFocus();
-}
-
-
-void COptionDialog::setupLayoutPage( void )
-{
-  TQString text;
-  TQFrame *page = addPage( i18n("Layout"), i18n("Data Layout in Editor"),
-			  BarIcon("khexedit", TDEIcon::SizeMedium ) );
-
-  TQGridLayout *gbox = new TQGridLayout( page, 15, 2, 0, spacingHint() );
-  gbox->setColStretch( 1, 10 );
-
-  mLayout.formatCombo  = new TQComboBox( false, page );
-  TQStringList modeList;
-  modeList.append( i18n("Hexadecimal Mode") );
-  modeList.append( i18n("Decimal Mode") );
-  modeList.append( i18n("Octal Mode") );
-  modeList.append( i18n("Binary Mode") );
-  modeList.append( i18n("Text Only Mode") );
-  mLayout.formatCombo->insertStringList( modeList );
-  connect( mLayout.formatCombo, TQT_SIGNAL(activated(int)),
-	   TQT_SLOT(slotModeSelectorChanged(int)) );
-  connect( mLayout.formatCombo, TQT_SIGNAL(activated(int)),
-    TQT_SLOT(slotChanged()) );
-  gbox->addWidget( mLayout.formatCombo, 0, 1 );
-
-  //
-  // I am setting the min. width for one widget in the second column
-  // This widtk will be used by every widget in this column.
-  //
-  mLayout.lineSizeSpin = new TQSpinBox( page );
-  mLayout.lineSizeSpin->setMinimumWidth( fontMetrics().width("M") * 10 );
-  mLayout.lineSizeSpin->setRange( 1, 10000 );
-  connect( mLayout.lineSizeSpin, TQT_SIGNAL(valueChanged(int)),
-	   TQT_SLOT(slotLineSizeChanged(int) ) );
-  connect( mLayout.lineSizeSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT(slotChanged()) );
-  gbox->addWidget( mLayout.lineSizeSpin, 1, 1 );
-
-  mLayout.columnSizeSpin = new TQSpinBox( page );
-  mLayout.columnSizeSpin->setRange( 1, 10000 );
-  connect( mLayout.columnSizeSpin, TQT_SIGNAL(valueChanged(int)),
-	   TQT_SLOT(slotColumnSizeChanged(int) ) );
-  connect( mLayout.columnSizeSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT(slotChanged() ) );
-  gbox->addWidget( mLayout.columnSizeSpin, 2, 1 );
-
-  text = i18n("Default l&ine size [bytes]:");
-  TQLabel *label = new TQLabel( mLayout.lineSizeSpin, text, page );
-  gbox->addWidget( label, 1, 0 );
-
-  text = i18n("Colu&mn size [bytes]:");
-  label = new TQLabel( mLayout.columnSizeSpin, text, page );
-  gbox->addWidget( label, 2, 0 );
-
-  TQFrame *hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  gbox->addMultiCellWidget( hline, 3, 3, 0, 1 );
-
-  text = i18n("Line size is &fixed (use scrollbar when required)");
-  mLayout.lockLineCheck = new TQCheckBox( text, page );
-  gbox->addMultiCellWidget( mLayout.lockLineCheck, 4, 4, 0, 1, AlignLeft );
-  connect( mLayout.lockLineCheck, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT(slotChanged()) );
-
-  text = i18n("Loc&k column at end of line (when column size>1)");
-  mLayout.lockColumnCheck = new TQCheckBox( text, page );
-  gbox->addMultiCellWidget( mLayout.lockColumnCheck, 5, 5, 0, 1 );
-  connect( mLayout.lockColumnCheck, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT(slotChanged()) );
-
-  hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  gbox->addMultiCellWidget( hline, 6, 6, 0, 1 );
-
-  TQStringList gridList;
-  gridList.append( i18n("None") );
-  gridList.append( i18n("Vertical Only") );
-  gridList.append( i18n("Horizontal Only") );
-  gridList.append( i18n("Both Directions") );
-
-  mLayout.gridCombo = new TQComboBox( false, page );
-  mLayout.gridCombo->insertStringList( gridList );
-  connect( mLayout.gridCombo, TQT_SIGNAL(activated(int)),
-    TQT_SLOT(slotChanged()) );
-
-  text = i18n("&Gridlines between text:");
-  label = new TQLabel( mLayout.gridCombo, text, page );
-
-  gbox->addWidget( label, 7, 0 );
-  gbox->addWidget( mLayout.gridCombo, 7, 1 );
-
-  mLayout.leftSepWidthSpin = new TQSpinBox( page );
-  mLayout.leftSepWidthSpin->setRange( 0, 20 );
-  gbox->addWidget( mLayout.leftSepWidthSpin, 8, 1 );
-  connect( mLayout.leftSepWidthSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT(slotChanged()) );
-
-  mLayout.rightSepWidthSpin = new TQSpinBox( page );
-  mLayout.rightSepWidthSpin->setRange( 0, 20 );
-  gbox->addWidget( mLayout.rightSepWidthSpin, 9, 1 );
-  connect( mLayout.rightSepWidthSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT(slotChanged()) );
-
-  text = i18n("&Left separator width [pixels]:");
-  mLayout.leftSepLabel = new TQLabel( mLayout.leftSepWidthSpin, text, page );
-  gbox->addWidget( mLayout.leftSepLabel, 8, 0 );
-
-  text = i18n("&Right separator width [pixels]:");
-  mLayout.rightSepLabel = new TQLabel( mLayout.rightSepWidthSpin, text, page );
-  gbox->addWidget( mLayout.rightSepLabel, 9, 0 );
-
-  mLayout.separatorSpin = new TQSpinBox( page );
-  mLayout.separatorSpin->setRange( 0, 20 );
-  gbox->addWidget( mLayout.separatorSpin, 10, 1 );
-  connect( mLayout.separatorSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT(slotChanged()) );
-
-  mLayout.edgeSpin = new TQSpinBox( page );
-  mLayout.edgeSpin->setRange( 0, 20 );
-  gbox->addWidget( mLayout.edgeSpin, 11, 1 );
-  connect( mLayout.edgeSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT(slotChanged()) );
-
-  text = i18n("&Separator margin width [pixels]:");
-  label = new TQLabel( mLayout.separatorSpin, text, page );
-  gbox->addWidget( label, 10, 0 );
-
-  text = i18n("&Edge margin width [pixels]:");
-  label = new TQLabel( mLayout.edgeSpin, text, page );
-  gbox->addWidget( label, 11, 0 );
-
-  text = i18n("Column separation is e&qual to one character");
-  mLayout.columnCheck = new TQCheckBox( text, page );
-  gbox->addMultiCellWidget( mLayout.columnCheck, 12, 12, 0, 1, AlignLeft );
-  connect( mLayout.columnCheck, TQT_SIGNAL(toggled(bool)),
-	   TQT_SLOT( slotColumnSepCheck(bool)));
-  connect( mLayout.columnCheck, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-
-  mLayout.columnSepSpin = new TQSpinBox( page );
-  mLayout.columnSepSpin->setRange( 1, 100 );
-  connect( mLayout.columnSepSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT(slotChanged()) );
-
-  text = i18n("Column separa&tion [pixels]:");
-  mLayout.columnSepLabel = new TQLabel( mLayout.columnSepSpin, text, page );
-
-  gbox->addWidget( mLayout.columnSepLabel, 13, 0 );
-  gbox->addWidget( mLayout.columnSepSpin, 13, 1 );
-
-  gbox->setRowStretch( 14, 10 );
-}
-
-
-void COptionDialog::setupCursorPage( void )
-{
-  TQString text;
-  TQFrame *page = addPage( i18n("Cursor"),
-    i18n("Cursor Behavior (only valid for editor)"),
-    BarIcon("input-mouse", TDEIcon::SizeMedium ) );
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
-
-  TQVButtonGroup *group = new TQVButtonGroup( i18n("Blinking"), page );
-  group->layout()->setMargin( spacingHint() );
-  topLayout->addWidget( group );
-
-  text = i18n("Do not b&link");
-  mCursor.blinkCheck = new TQCheckBox( i18n("Do not b&link"), group );
-  connect( mCursor.blinkCheck, TQT_SIGNAL(toggled(bool)),
-	   TQT_SLOT( slotBlinkIntervalCheck(bool)));
-  connect( mCursor.blinkCheck, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-
-  TQHBox *hbox = new TQHBox( group );
-  mCursor.blinkLabel = new TQLabel( i18n("&Blink interval [ms]:" ), hbox );
-  mCursor.blinkSpin = new TQSpinBox( hbox );
-  mCursor.blinkSpin->setMinimumWidth( fontMetrics().width("M") * 10 );
-  mCursor.blinkSpin->setRange( 100, 1000 );
-  mCursor.blinkSpin->setSteps( 100, 100 );
-  mCursor.blinkSpin->setValue( 500 );
-  mCursor.blinkLabel->setBuddy(mCursor.blinkSpin);
-  connect( mCursor.blinkSpin, TQT_SIGNAL(valueChanged(int)),
-    TQT_SLOT( slotChanged()));
-
-  group = new TQVButtonGroup( i18n("Shape"), page );
-  group->layout()->setMargin( spacingHint() );
-  topLayout->addWidget( group );
-
-  text = i18n("Always &use block (rectangular) cursor");
-  mCursor.blockCheck = new TQCheckBox( text, group );
-  connect( mCursor.blockCheck, TQT_SIGNAL(toggled(bool)),
-	   TQT_SLOT( slotBlockCursorCheck(bool)));
-  connect( mCursor.blockCheck, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-  text = i18n("Use &thick cursor in insert mode");
-  mCursor.thickCheck = new TQCheckBox( text, group );
-  connect( mCursor.thickCheck, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-
-  text = i18n("Cursor Behavior When Editor Loses Focus");
-  group = new TQVButtonGroup( text, page );
-  group->layout()->setMargin( spacingHint() );
-  topLayout->addWidget( group );
-
-  text = i18n("&Stop blinking (if blinking is enabled)");
-  mCursor.stopRadio = new TQRadioButton( text, group, "radio1" );
-  mCursor.hideRadio = new TQRadioButton( i18n("H&ide"), group, "radio2" );
-  text = i18n("Do &nothing");
-  mCursor.nothingRadio = new TQRadioButton( text, group, "radio3" );
-  connect( mCursor.stopRadio, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-  connect( mCursor.hideRadio, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-  connect( mCursor.nothingRadio, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-
-  topLayout->addStretch(10);
-}
-
-
-void COptionDialog::setupColorPage( void )
-{
-  TQString text;
-  TQFrame *page = addPage( i18n("Colors"),
-    i18n("Editor Colors (system selection color is always used)"),
-    BarIcon("colorize", TDEIcon::SizeMedium ) );
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
-
-  text = i18n("&Use system colors (as chosen in Control Center)");
-  mColor.checkSystem = new TQCheckBox( text, page );
-  connect( mColor.checkSystem, TQT_SIGNAL(toggled(bool)),
-	   TQT_SLOT( slotColorSystem(bool)));
-  connect( mColor.checkSystem, TQT_SIGNAL(toggled(bool)),
-    TQT_SLOT( slotChanged()));
-  topLayout->addWidget( mColor.checkSystem );
-
-  TQFrame *hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  topLayout->addWidget( hline );
-
-  TQStringList modeList;
-  modeList.append( i18n("First, Third ... Line Background") );
-  modeList.append( i18n("Second, Fourth ... Line Background") );
-  modeList.append( i18n("Offset Background") );
-  modeList.append( i18n("Inactive Background") );
-  modeList.append( i18n("Even Column Text") );
-  modeList.append( i18n("Odd Column Text") );
-  modeList.append( i18n("Non Printable Text") );
-  modeList.append( i18n("Offset Text") );
-  modeList.append( i18n("Secondary Text") );
-  modeList.append( i18n("Marked Background") );
-  modeList.append( i18n("Marked Text") );
-  modeList.append( i18n("Cursor Background") );
-  modeList.append( i18n("Cursor Text (block shape)") );
-  modeList.append( i18n("Bookmark Background") );
-  modeList.append( i18n("Bookmark Text") );
-  modeList.append( i18n("Separator") );
-  modeList.append( i18n("Grid Lines") );
-
-  mColor.colorList = new CColorListBox( page );
-  topLayout->addWidget( mColor.colorList, 10 );
-  for( uint i=0; i<17; i++ )
-  {
-    CColorListItem *listItem = new CColorListItem( modeList[i] );
-    mColor.colorList->insertItem( listItem );
-  }
-  mColor.colorList->setCurrentItem(0);
-  connect( mColor.colorList, TQT_SIGNAL( dataChanged() ), this, TQT_SLOT( slotChanged() ) );
-}
-
-
-void COptionDialog::setupFontPage( void )
-{
-  TQString text;
-  TQFrame *page = addPage( i18n("Font"),
-    i18n("Font Selection (editor can only use a fixed font)"),
-    BarIcon("fonts", TDEIcon::SizeMedium ) );
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
-
-  text = i18n("&Use system font (as chosen in Control Center)");
-  mFont.checkSystem = new TQCheckBox( text, page );
-  connect( mFont.checkSystem, TQT_SIGNAL(toggled(bool)),
-	   this, TQT_SLOT( slotFontSystem(bool)));
-  connect( mFont.checkSystem, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-  topLayout->addWidget( mFont.checkSystem );
-
-  TQFrame *hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  topLayout->addWidget( hline );
-
-  mFont.chooser = new TDEFontChooser( page, "font", true, TQStringList(), false, 4 );
-  topLayout->addWidget( mFont.chooser );
-  TQFont fixFont( TDEGlobalSettings::fixedFont() );
-  fixFont.setBold(true);
-  mFont.chooser->setFont( fixFont, true );
-  mFont.chooser->setSampleText( i18n("KHexEdit editor font") );
-  connect( mFont.chooser, TQT_SIGNAL(fontSelected(const TQFont &)),
-    this, TQT_SLOT( slotChanged()));
-
-  hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  topLayout->addWidget( hline );
-
-  TQHBoxLayout *hbox = new TQHBoxLayout();
-  topLayout->addLayout( hbox );
-
-  mFont.nonPrintInput = new TQLineEdit( page );
-  mFont.nonPrintInput->setMaxLength( 1 );
-  connect( mFont.nonPrintInput, TQT_SIGNAL(textChanged(const TQString &)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("&Map non printable characters to:");
-  TQLabel *nonPrintLabel = new TQLabel( mFont.nonPrintInput, text, page );
-
-  hbox->addWidget( nonPrintLabel, 0, AlignLeft );
-  hbox->addSpacing( spacingHint() );
-  hbox->addWidget( mFont.nonPrintInput, 10 );
-
-  topLayout->addStretch(10);
-}
-
-
-void COptionDialog::setupFilePage( void )
-{
-  TQString text;
-  TQFrame *page = addPage( i18n("Files"), i18n("File Management"),
-			  BarIcon("application-vnd.tde.tdemultiple", TDEIcon::SizeMedium ) );
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
-
-  TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
-  topLayout->addLayout( gbox );
-
-  mFile.openCombo = new TQComboBox( false, page );
-  TQStringList modeList;
-  modeList.append( i18n("None") );
-  modeList.append( i18n("Most Recent Document") );
-  modeList.append( i18n("All Recent Documents") );
-  mFile.openCombo->insertStringList( modeList );
-  mFile.openCombo->setMinimumWidth( mFile.openCombo->sizeHint().width() );
-  connect( mFile.openCombo, TQT_SIGNAL(activated(int)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("Open doc&uments on startup:");
-  TQLabel *label = new TQLabel( mFile.openCombo, text, page );
-
-  gbox->addWidget( label, 0, 0 );
-  gbox->addWidget( mFile.openCombo, 0, 1 );
-
-  text = i18n("&Jump to previous cursor position on startup");
-  mFile.gotoOffsetCheck = new TQCheckBox( text, page );
-  // ### TODO: this is currently not available.
-  mFile.gotoOffsetCheck->setChecked( false );
-  mFile.gotoOffsetCheck->setEnabled( false );
-  // ### END
-  topLayout->addWidget( mFile.gotoOffsetCheck, 0, AlignLeft );
-  connect( mFile.gotoOffsetCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  TQFrame *hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  topLayout->addWidget( hline );
-
-  text = i18n("Open document with &write protection enabled");
-  mFile.writeProtectCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mFile.writeProtectCheck, 0, AlignLeft );
-  connect( mFile.writeProtectCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("&Keep cursor position after reloading document");
-  mFile.reloadOffsetCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mFile.reloadOffsetCheck, 0, AlignLeft );
-  connect( mFile.reloadOffsetCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("&Make a backup when saving document");
-  mFile.backupCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mFile.backupCheck, 0, AlignLeft );
-  connect( mFile.backupCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  topLayout->addWidget( hline );
-
-  text = i18n("Don't &save \"Recent\" document list on exit");
-  mFile.discardRecentCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mFile.discardRecentCheck, 0, AlignLeft );
-  TQWhatsThis::add( mFile.discardRecentCheck,
-                   i18n( "Clicking this check box makes KHexEdit forget his recent document list "
-                          "when the program is closed.\n"
-                          "Note: it will not erase any document of the recent document list "
-                          "created by TDE." ) );
-  connect( mFile.discardRecentCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("Cl&ear \"Recent\" Document List");
-  TQPushButton *discardRecentButton = new TQPushButton( page );
-  discardRecentButton->setText( text );
-  TQWhatsThis::add( discardRecentButton,
-                   i18n( "Clicking this button makes KHexEdit forget his recent document list.\n"
-                          "Note: it will not erase any document of the recent document list "
-                          "created by TDE." ) );
-  topLayout->addWidget( discardRecentButton, 0, AlignCenter );
-  connect( discardRecentButton, TQT_SIGNAL(clicked()),
-	   TQT_SIGNAL(removeRecentFiles()) );
-
-  topLayout->addStretch(10);
-}
-
-
-
-void COptionDialog::setupMiscPage( void )
-{
-  TQString text;
-  TQLabel *label;
-
-  TQFrame *page = addPage( i18n("Miscellaneous"), i18n("Various Properties"),
-			  BarIcon("gear", TDEIcon::SizeMedium ) );
-
-  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
-
-
-  text = i18n("Auto&matic copy to clipboard when selection is ready");
-  mMisc.autoCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mMisc.autoCheck, 0, AlignLeft );
-  connect( mMisc.autoCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("&Editor starts in \"insert\" mode" );
-  mMisc.insertCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mMisc.insertCheck, 0, AlignLeft );
-  connect( mMisc.insertCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("Confirm &wrapping (to beginning or end) during search");
-  mMisc.confirmWrapCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mMisc.confirmWrapCheck, 0, AlignLeft );
-  connect( mMisc.confirmWrapCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("Cursor jumps to &nearest byte when moved");
-  mMisc.cursorJumpCheck = new TQCheckBox( text, page );
-  topLayout->addWidget( mMisc.cursorJumpCheck, 0, AlignLeft );
-  connect( mMisc.cursorJumpCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  TQVButtonGroup *group = new TQVButtonGroup( i18n("Sounds"), page );
-  group->layout()->setMargin( spacingHint() );
-  topLayout->addWidget( group );
-  text = i18n("Make sound on data &input (eg. typing) failure");
-  mMisc.inputCheck = new TQCheckBox( text, group );
-  connect( mMisc.inputCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-  text = i18n("Make sound on &fatal failure");
-  mMisc.fatalCheck = new TQCheckBox( text, group );
-  connect( mMisc.fatalCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  group = new TQVButtonGroup( i18n("Bookmark Visibility"), page );
-  group->layout()->setMargin( spacingHint() );
-  topLayout->addWidget( group );
-  text = i18n("Use visible bookmarks in the offset column");
-  mMisc.bookmarkColumnCheck = new TQCheckBox( text, group );
-  connect( mMisc.bookmarkColumnCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-  text = i18n("Use visible bookmarks in the editor fields");
-  mMisc.bookmarkEditorCheck = new TQCheckBox( text, group );
-  connect( mMisc.bookmarkEditorCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("Confirm when number of printed pages will e&xceed limit");
-  mMisc.thresholdCheck = new TQCheckBox( text, page );
-  connect( mMisc.thresholdCheck, TQT_SIGNAL(clicked()),
-	   TQT_SLOT( slotThresholdConfirm()));
-  connect( mMisc.thresholdCheck, TQT_SIGNAL(toggled(bool)),
-    this, TQT_SLOT( slotChanged()));
-  topLayout->addWidget( mMisc.thresholdCheck, 0, AlignLeft );
-
-  TQGridLayout *glay = new TQGridLayout( 3, 3 );
-  glay->setColStretch(2,10);
-  topLayout->addLayout( glay );
-
-  mMisc.thresholdSpin = new TQSpinBox( page );
-  mMisc.thresholdSpin->setMinimumWidth( fontMetrics().width("M") * 10 );
-  mMisc.thresholdSpin->setRange( 5, INT_MAX );
-  mMisc.thresholdSpin->setSteps( 5, 5 );
-  mMisc.thresholdSpin->setValue( 5 );
-  connect( mMisc.thresholdSpin, TQT_SIGNAL(valueChanged(int)),
-    this, TQT_SLOT( slotChanged()));
-
-  text = i18n("&Threshold [pages]:" );
-  mMisc.thresholdLabel = new TQLabel( mMisc.thresholdSpin, text, page );
-
-  glay->addWidget( mMisc.thresholdLabel, 0, 0 );
-  glay->addWidget( mMisc.thresholdSpin, 0, 1 );
-
-  TQFrame *hline = new TQFrame( page );
-  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
-  glay->addMultiCellWidget( hline, 1, 1, 0, 2 );
-
-  mMisc.undoSpin = new TQSpinBox( page );
-  mMisc.undoSpin->setRange( 10, 10000 );
-  mMisc.undoSpin->setSteps( 5, 5 );
-  mMisc.undoSpin->setValue( 50 );
-  connect( mMisc.undoSpin, TQT_SIGNAL(valueChanged(int)),
-    this, TQT_SLOT( slotChanged()));
-
-  label = new TQLabel( mMisc.undoSpin, i18n("&Undo limit:"), page );
-  glay->addWidget( label, 2, 0 );
-  glay->addWidget( mMisc.undoSpin, 2, 1 );
-
-  topLayout->addStretch(10);
-}
-
-
-
-void COptionDialog::slotModeSelectorChanged( int index )
-{
-  int lineSize = mDisplayState.line.getLineSize( index );
-  int colSize  = mDisplayState.line.getColumnSize( index );
-  mLayout.lineSizeSpin->setValue( lineSize );
-  mLayout.columnSizeSpin->setValue( colSize );
-}
-
-void COptionDialog::slotLineSizeChanged( int value )
-{
-  int index = mLayout.formatCombo->currentItem();
-  mDisplayState.line.setLineSize( index, value );
-  if( index == SDisplayLine::textOnly )
-  {
-    mLayout.columnSizeSpin->setValue( value );
-  }
-}
-
-void COptionDialog::slotColumnSizeChanged( int value )
-{
-  int index = mLayout.formatCombo->currentItem();
-  mDisplayState.line.setColumnSize( index, value );
-  if( index == SDisplayLine::textOnly )
-  {
-    mLayout.lineSizeSpin->setValue( value );
-  }
-}
-
-void COptionDialog::slotColumnSepCheck( bool state )
-{
-  state = state == true ? false: true;
-  mLayout.columnSepLabel->setEnabled( state );
-  mLayout.columnSepSpin->setEnabled( state );
-}
-
-
-void COptionDialog::slotBlinkIntervalCheck( bool state )
-{
-  state = state == true ? false : true;
-  mCursor.blinkSpin->setEnabled( state );
-  mCursor.blinkLabel->setEnabled( state );
-}
-
-void COptionDialog::slotBlockCursorCheck( bool state )
-{
-  state = state == true ? false : true;
-  mCursor.thickCheck->setEnabled( state );
-}
-
-void COptionDialog::slotFontSystem( bool state )
-{
-  mFont.chooser->setEnabled( state == true ? false : true );
-}
-
-void COptionDialog::slotColorSystem( bool state )
-{
-  state = state == true ? false : true;
-  mColor.colorList->setEnabled( state );
-}
-
-
-
-void COptionDialog::slotThresholdConfirm( void )
-{
-  bool state = mMisc.thresholdCheck->isChecked();
-  mMisc.thresholdLabel->setEnabled( state );
-  mMisc.thresholdSpin->setEnabled( state );
-}
-
-
-void COptionDialog::slotDefault( void )
-{
-  //
-  // We use the constructor settings as default values
-  //
-  switch( activePageIndex() )
-  {
-    case page_layout:
-    {
-      SDisplayLayout layout;
-      SDisplayLine line;
-      setLayout( layout, line );
-    }
-    break;
-
-    case page_cursor:
-    {
-      SDisplayCursor cursor;
-      setCursor( cursor );
-    }
-    break;
-
-    case page_color:
-    {
-      SDisplayColor color;
-      setColor( color );
-    }
-    break;
-
-    case page_font:
-    {
-      SDisplayFont font;
-      setFont( font );
-    }
-    break;
-
-    case page_file:
-    {
-      SDisplayMisc misc;
-      setFile( misc );
-    }
-    break;
-
-    case page_misc:
-    {
-      SDisplayMisc misc;
-      setMisc( misc );
-    }
-    break;
-  }
-}
-
-
-void COptionDialog::slotOk( void )
-{
-  if( configChanged )
-    slotApply();
-  accept();
-}
-
-void COptionDialog::slotApply( void )
-{
-  switch( activePageIndex() )
-  {
-    case page_layout:
-    {
-      int index = mLayout.formatCombo->currentItem();
-      mDisplayState.line.setLineSize(index, mLayout.lineSizeSpin->value());
-      mDisplayState.line.setColumnSize(index, mLayout.columnSizeSpin->value());
-      emit lineSizeChoice( mDisplayState.line );
-
-      SDisplayLayout &l = mDisplayState.layout;
-      l.lockLine = mLayout.lockLineCheck->isChecked();
-      l.lockColumn = mLayout.lockColumnCheck->isChecked();
-      l.leftSeparatorWidth = mLayout.leftSepWidthSpin->value();
-      l.rightSeparatorWidth = mLayout.rightSepWidthSpin->value();
-      l.separatorMarginWidth = mLayout.separatorSpin->value();
-      l.edgeMarginWidth = mLayout.edgeSpin->value();
-      l.leftSeparatorWidth = mLayout.leftSepWidthSpin->value();
-      l.rightSeparatorWidth = mLayout.rightSepWidthSpin->value();
-      l.columnCharSpace = mLayout.columnCheck->isChecked();
-      l.columnSpacing = mLayout.columnSepSpin->value();
-
-      if( mLayout.gridCombo->currentItem() == 0 )
-      {
-	l.horzGridWidth = l.vertGridWidth = 0;
-      }
-      else if( mLayout.gridCombo->currentItem() == 1 )
-      {
-	l.horzGridWidth = 0;
-	l.vertGridWidth = 1;
-      }
-      else if( mLayout.gridCombo->currentItem() == 2 )
-      {
-	l.horzGridWidth = 1;
-	l.vertGridWidth = 0;
-      }
-      else
-      {
-	l.horzGridWidth = l.vertGridWidth = 1;
-      }
-
-      emit layoutChoice( mDisplayState.layout );
-    }
-    break;
-
-
-    case page_cursor:
-    {
-      SDisplayCursor &c = mDisplayState.cursor;
-      c.alwaysVisible    = mCursor.blinkCheck->isChecked();
-      c.interval         = mCursor.blinkSpin->value();
-      c.alwaysBlockShape = mCursor.blockCheck->isChecked();
-      c.thickInsertShape = mCursor.thickCheck->isChecked();
-      c.focusMode        = cursorFocusMode();
-      emit cursorChoice( mDisplayState.cursor );
-    }
-    break;
-
-    case page_color:
-    {
-      SDisplayColor &c = mDisplayState.color;
-      c.useSystemColor = mColor.checkSystem->isChecked();
-      c.textBg = mColor.colorList->color( SColorWidgets::FirstTextBg );
-      c.secondTextBg = mColor.colorList->color( SColorWidgets::SecondTextBg );
-      c.offsetBg = mColor.colorList->color( SColorWidgets::OffsetBg );
-      c.inactiveBg = mColor.colorList->color( SColorWidgets::InactiveBg );
-      c.markBg = mColor.colorList->color( SColorWidgets::MarkedBg );
-      c.markFg = mColor.colorList->color( SColorWidgets::MarkedFg );
-      c.primaryFg[0] = mColor.colorList->color( SColorWidgets::EvenColumnFg );
-      c.primaryFg[1] = mColor.colorList->color( SColorWidgets::OddColumnFg );
-      c.offsetFg  = mColor.colorList->color( SColorWidgets::OffsetFg );
-      c.secondaryFg = mColor.colorList->color( SColorWidgets::SecondaryFg );
-      c.cursorBg  = mColor.colorList->color( SColorWidgets::CursorBg );
-      c.cursorFg  = mColor.colorList->color( SColorWidgets::CursorFg );
-      c.leftSeparatorFg = mColor.colorList->color(SColorWidgets::SeparatorFg);
-      c.rightSeparatorFg = mColor.colorList->color(SColorWidgets::SeparatorFg);
-      c.bookmarkBg = mColor.colorList->color( SColorWidgets::BookmarkBg );
-      c.bookmarkFg = mColor.colorList->color( SColorWidgets::BookmarkFg );
-      c.nonPrintFg  = mColor.colorList->color( SColorWidgets::NonPrintFg );
-      c.gridFg = mColor.colorList->color( SColorWidgets::GridFg );
-      emit colorChoice( mDisplayState.color );
-    }
-    break;
-
-    case page_font:
-    {
-      SDisplayFont &f = mDisplayState.font;
-      f.useSystemFont = mFont.checkSystem->isChecked();
-      f.localFont = mFont.chooser->font();
-
-      TQString nonPrintText = mFont.nonPrintInput->text();
-      if( nonPrintText.isEmpty() )
-      {
-	f.nonPrintChar = ' ';
-      }
-      else
-      {
-	f.nonPrintChar = nonPrintText[0];
-      }
-
-      emit fontChoice( mDisplayState.font );
-    }
-    break;
-
-    case page_file:
-    case page_misc:
-    {
-      SDisplayMisc &m = mDisplayState.misc;
-      m.undoLevel = mMisc.undoSpin->value();
-      m.autoCopyToClipboard = mMisc.autoCheck->isChecked();
-      m.insertMode = mMisc.insertCheck->isChecked();
-      m.inputSound = mMisc.inputCheck->isChecked();
-      m.confirmWrap = mMisc.confirmWrapCheck->isChecked();
-      m.cursorJump = mMisc.cursorJumpCheck->isChecked();
-      m.fatalSound = mMisc.fatalCheck->isChecked();
-      m.confirmThreshold = mMisc.thresholdCheck->isChecked();
-      m.thresholdValue = mMisc.thresholdSpin->value();
-      m.bookmarkOffsetColumn = mMisc.bookmarkColumnCheck->isChecked();
-      m.bookmarkEditor = mMisc.bookmarkEditorCheck->isChecked();
-
-      m.openFile  = (SDisplayMisc::EOpenFile)mFile.openCombo->currentItem();
-      m.gotoOnStartup = mFile.gotoOffsetCheck->isChecked();
-      m.writeProtect = mFile.writeProtectCheck->isChecked();
-      m.gotoOnReload = mFile.reloadOffsetCheck->isChecked();
-      m.makeBackup = mFile.backupCheck->isChecked();
-      m.discardRecent = mFile.discardRecentCheck->isChecked();
-
-      emit miscChoice( mDisplayState.misc );
-    }
-    break;
-  }
-  enableButton( Apply, false );
-  configChanged = false;
-}
-
-void COptionDialog::setLayout( SDisplayLayout &layout, SDisplayLine &line )
-{
-  mDisplayState.line = line;
-  mDisplayState.layout = layout;
-
-  slotModeSelectorChanged( mLayout.formatCombo->currentItem() );
-  mLayout.lockLineCheck->setChecked( layout.lockLine );
-  mLayout.lockColumnCheck->setChecked( layout.lockColumn );
-  mLayout.leftSepWidthSpin->setValue( layout.leftSeparatorWidth );
-  mLayout.rightSepWidthSpin->setValue( layout.rightSeparatorWidth );
-  mLayout.separatorSpin->setValue( layout.separatorMarginWidth );
-  mLayout.edgeSpin->setValue( layout.edgeMarginWidth );
-  mLayout.leftSepWidthSpin->setValue( layout.leftSeparatorWidth );
-  mLayout.rightSepWidthSpin->setValue( layout.rightSeparatorWidth );
-  mLayout.columnCheck->setChecked( layout.columnCharSpace );
-  slotColumnSepCheck( layout.columnCharSpace );
-  mLayout.columnSepSpin->setValue( layout.columnSpacing );
-
-  if( layout.horzGridWidth == 0 && layout.vertGridWidth == 0 )
-  {
-    mLayout.gridCombo->setCurrentItem(0);
-  }
-  else if( layout.horzGridWidth != 0 && layout.vertGridWidth != 0 )
-  {
-    mLayout.gridCombo->setCurrentItem(3);
-  }
-  else
-  {
-    mLayout.gridCombo->setCurrentItem( layout.vertGridWidth != 0 ? 1 : 2 );
-  }
-
-}
-
-
-void COptionDialog::setCursor( SDisplayCursor &cursor )
-{
-  mDisplayState.cursor = cursor;
-
-  mCursor.blinkCheck->setChecked( cursor.alwaysVisible );
-  mCursor.blinkSpin->setValue( cursor.interval );
-  mCursor.blockCheck->setChecked( cursor.alwaysBlockShape );
-  mCursor.thickCheck->setChecked( cursor.thickInsertShape );
-  bool state = cursor.focusMode == SDisplayCursor::stopBlinking ? true : false;
-  mCursor.stopRadio->setChecked( state );
-  state = cursor.focusMode == SDisplayCursor::hide ? true : false;
-  mCursor.hideRadio->setChecked( state );
-  state = cursor.focusMode == SDisplayCursor::ignore ? true : false;
-  mCursor.nothingRadio->setChecked( state );
-}
-
-
-void COptionDialog::setColor( SDisplayColor &color )
-{
-  mDisplayState.color = color;
-
-  mColor.checkSystem->setChecked( color.useSystemColor );
-  mColor.colorList->setColor( SColorWidgets::FirstTextBg, color.textBg );
-  mColor.colorList->setColor( SColorWidgets::SecondTextBg, color.secondTextBg);
-  mColor.colorList->setColor( SColorWidgets::OffsetBg, color.offsetBg );
-  mColor.colorList->setColor( SColorWidgets::InactiveBg, color.inactiveBg );
-  mColor.colorList->setColor( SColorWidgets::MarkedBg, color.markBg );
-  mColor.colorList->setColor( SColorWidgets::MarkedFg, color.markFg );
-  mColor.colorList->setColor( SColorWidgets::EvenColumnFg, color.primaryFg[0]);
-  mColor.colorList->setColor( SColorWidgets::OddColumnFg, color.primaryFg[1] );
-  mColor.colorList->setColor( SColorWidgets::OffsetFg, color.offsetFg );
-  mColor.colorList->setColor( SColorWidgets::SecondaryFg, color.secondaryFg );
-  mColor.colorList->setColor( SColorWidgets::CursorBg, color.cursorBg );
-  mColor.colorList->setColor( SColorWidgets::CursorFg, color.cursorFg );
-  mColor.colorList->setColor(SColorWidgets::SeparatorFg,color.leftSeparatorFg);
-  mColor.colorList->setColor( SColorWidgets::BookmarkBg, color.bookmarkBg );
-  mColor.colorList->setColor( SColorWidgets::BookmarkFg, color.bookmarkFg );
-  mColor.colorList->setColor( SColorWidgets::NonPrintFg, color.nonPrintFg );
-  mColor.colorList->setColor( SColorWidgets::GridFg, color.gridFg );
-}
-
-
-void COptionDialog::setFont( SDisplayFont &font )
-{
-  mDisplayState.font = font;
-
-  mFont.checkSystem->setChecked( font.useSystemFont );
-  mFont.chooser->setFont( font.localFont, true );
-  TQString buf = font.nonPrintChar;
-  mFont.nonPrintInput->setText( buf );
-}
-
-
-void COptionDialog::setMisc( SDisplayMisc &misc )
-{
-  mDisplayState.misc.undoLevel            = misc.undoLevel;
-  mDisplayState.misc.inputSound           = misc.inputSound;
-  mDisplayState.misc.fatalSound           = misc.fatalSound;
-  mDisplayState.misc.autoCopyToClipboard  = misc.autoCopyToClipboard;
-  mDisplayState.misc.insertMode           = misc.insertMode;
-  mDisplayState.misc.confirmWrap          = misc.confirmWrap;
-  mDisplayState.misc.cursorJump           = misc.cursorJump;
-  mDisplayState.misc.confirmThreshold     = misc.confirmThreshold;
-  mDisplayState.misc.thresholdValue       = misc.thresholdValue;
-  mDisplayState.misc.bookmarkOffsetColumn = misc.bookmarkOffsetColumn;
-  mDisplayState.misc.bookmarkEditor       = misc.bookmarkEditor;
-
-  mMisc.autoCheck->setChecked( misc.autoCopyToClipboard );
-  mMisc.insertCheck->setChecked( misc.insertMode );
-  mMisc.confirmWrapCheck->setChecked( misc.confirmWrap );
-  mMisc.cursorJumpCheck->setChecked( misc.cursorJump );
-
-  mMisc.inputCheck->setChecked( misc.inputSound );
-  mMisc.fatalCheck->setChecked( misc.fatalSound );
-  mMisc.bookmarkColumnCheck->setChecked( misc.bookmarkOffsetColumn );
-  mMisc.bookmarkEditorCheck->setChecked( misc.bookmarkEditor );
-
-  mMisc.thresholdCheck->setChecked( misc.confirmThreshold );
-  mMisc.thresholdSpin->setValue( misc.thresholdValue );
-  slotThresholdConfirm();
-
-  mMisc.undoSpin->setValue( misc.undoLevel );
-}
-
-void COptionDialog::setFile( SDisplayMisc &misc )
-{
-  mDisplayState.misc.openFile      = misc.openFile;
-  mDisplayState.misc.gotoOnStartup = misc.gotoOnStartup;
-  mDisplayState.misc.writeProtect  = misc.writeProtect;
-  mDisplayState.misc.gotoOnReload  = misc.gotoOnReload;
-  mDisplayState.misc.discardRecent = misc.discardRecent;
-  mDisplayState.misc.makeBackup    = misc.makeBackup;
-
-  mFile.openCombo->setCurrentItem( (uint)misc.openFile );
-  mFile.gotoOffsetCheck->setChecked( misc.gotoOnStartup );
-  mFile.writeProtectCheck->setChecked( misc.writeProtect );
-  mFile.reloadOffsetCheck->setChecked( misc.gotoOnReload );
-  mFile.discardRecentCheck->setChecked( misc.discardRecent );
-  mFile.backupCheck->setChecked( misc.makeBackup );
-}
-
-
-void COptionDialog::setState( SDisplayState &state )
-{
-  setLayout( state.layout, state.line );
-  setCursor( state.cursor );
-  setColor( state.color );
-  setFont( state.font );
-  setFile( state.misc );
-  setMisc( state.misc );
-  enableButton( Apply, false );
-  configChanged = false;
-}
-
-
-SDisplayCursor::EFocusMode COptionDialog::cursorFocusMode( void )
-{
-  if( mCursor.stopRadio->isChecked() == true )
-  {
-    return( SDisplayCursor::stopBlinking );
-  }
-  else if( mCursor.hideRadio->isChecked() == true )
-  {
-    return( SDisplayCursor::hide );
-  }
-  else
-  {
-    return( SDisplayCursor::ignore );
-  }
-}
-
-
-
-CColorListBox::CColorListBox( TQWidget *parent, const char *name, WFlags f )
-  :TDEListBox( parent, name, f ), mCurrentOnDragEnter(-1)
-{
-  connect( this, TQT_SIGNAL(selected(int)), this, TQT_SLOT(newColor(int)) );
-  setAcceptDrops( true);
-}
-
-
-void CColorListBox::setEnabled( bool state )
-{
-  if( state == isEnabled() )
-  {
-    return;
-  }
-
-  TQListBox::setEnabled( state );
-  for( uint i=0; i<count(); i++ )
-  {
-    updateItem( i );
-  }
-}
-
-
-void CColorListBox::setColor( uint index, const TQColor &color )
-{
-  if( index < count() )
-  {
-    CColorListItem *colorItem = (CColorListItem*)item(index);
-    colorItem->setColor(color);
-    updateItem( colorItem );
-  }
-}
-
-
-const TQColor CColorListBox::color( uint index )
-{
-  if( index < count() )
-  {
-    CColorListItem *colorItem = (CColorListItem*)item(index);
-    return( colorItem->color() );
-  }
-  else
-  {
-    return( black );
-  }
-}
-
-
-void CColorListBox::newColor( int index )
-{
-  if( isEnabled() == false )
-  {
-    return;
-  }
-
-  if( (uint)index < count() )
-  {
-    TQColor c = color( index );
-    if( KColorDialog::getColor( c, this ) != TQDialog::Rejected )
-    {
-      setColor( index, c );
-      emit dataChanged();
-    }
-  }
-}
-
-
-void CColorListBox::dragEnterEvent( TQDragEnterEvent *e )
-{
-  if( KColorDrag::canDecode(e) && isEnabled() )
-  {
-    mCurrentOnDragEnter = currentItem();
-    e->accept( true );
-  }
-  else
-  {
-    mCurrentOnDragEnter = -1;
-    e->accept( false );
-  }
-}
-
-
-void CColorListBox::dragLeaveEvent( TQDragLeaveEvent * )
-{
-  if( mCurrentOnDragEnter != -1 )
-  {
-    setCurrentItem( mCurrentOnDragEnter );
-    mCurrentOnDragEnter = -1;
-  }
-}
-
-
-void CColorListBox::dragMoveEvent( TQDragMoveEvent *e )
-{
-  if( KColorDrag::canDecode(e) && isEnabled() )
-  {
-    CColorListItem *item = (CColorListItem*)itemAt( e->pos() );
-    if( item != 0 )
-    {
-      setCurrentItem ( item );
-    }
-  }
-}
-
-
-void CColorListBox::dropEvent( TQDropEvent *e )
-{
-  TQColor color;
-  if( KColorDrag::decode( e, color ) )
-  {
-    int index = currentItem();
-    if( index != -1 )
-    {
-      CColorListItem *colorItem = (CColorListItem*)item(index);
-      colorItem->setColor(color);
-      triggerUpdate( false ); // Redraw item
-    }
-    mCurrentOnDragEnter = -1;
-  }
-}
-
-
-
-CColorListItem::CColorListItem( const TQString &text, const TQColor &color )
-  : TQListBoxItem(), mColor( color ), mBoxWidth( 30 )
-{
-  setText( text );
-}
-
-
-const TQColor &CColorListItem::color( void )
-{
-  return( mColor );
-}
-
-
-void CColorListItem::setColor( const TQColor &color )
-{
-  mColor = color;
-}
-
-
-void CColorListItem::paint( TQPainter *p )
-{
-  TQFontMetrics fm = p->fontMetrics();
-  int h = fm.height();
-
-  p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() );
-
-  p->setPen( TQt::black );
-  p->drawRect( 3, 1, mBoxWidth, h-1 );
-  p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor );
-}
-
-
-int CColorListItem::height(const TQListBox *lb ) const
-{
-  return( lb->fontMetrics().lineSpacing()+1 );
-}
-
-
-int CColorListItem::width(const TQListBox *lb ) const
-{
-  return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 );
-}
-
-
-
-
-
-
-#include "optiondialog.moc"
diff --git a/khexedit/optiondialog.cpp b/khexedit/optiondialog.cpp
new file mode 100644
index 00000000..49a33b75
--- /dev/null
+++ b/khexedit/optiondialog.cpp
@@ -0,0 +1,1224 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <limits.h>
+
+#include <tqvbox.h>
+#include <tqvbuttongroup.h>
+#include <tqpainter.h>
+
+#include <tqcheckbox.h>
+#include <tqlayout.h>
+#include <tqlabel.h>
+#include <tqradiobutton.h>
+#include <tqspinbox.h>
+#include <tqwhatsthis.h>
+
+#include <kcolordialog.h>
+#include <kcolordrag.h>
+#include <tdefontdialog.h> // For TDEFontChooser
+#include <kiconloader.h>
+#include <tdelocale.h>
+#include <tdeglobalsettings.h>
+
+#include "optiondialog.h"
+#include <tqpushbutton.h>
+#include <tqcombobox.h>
+
+#if 0
+#include <tqobjectlist.h>
+static void enableWidget( TQWidget *w, bool state )
+{
+  if( w->children() )
+  {
+    TQObjectList *l = (TQObjectList*)w->children(); // silence please
+    for( uint i=0; i < l->count(); i++ )
+    {
+      TQObject *o = l->at(i);
+      if( o->isWidgetType() )
+      {
+	enableWidget( (TQWidget*)o, state );
+      }
+    }
+  }
+  w->setEnabled( state );
+}
+#endif
+
+
+
+COptionDialog::COptionDialog( TQWidget *parent, char *name, bool modal )
+  :KDialogBase( IconList, i18n("Configure"), Help|Default|Apply|Ok|Cancel,
+		Ok, parent, name, modal, true )
+{
+  setHelp( "khexedit/khexedit.html", TQString() );
+
+  setupLayoutPage();
+  setupCursorPage();
+  setupFontPage();
+  setupColorPage();
+  setupFilePage();
+  setupMiscPage();
+  enableButton( Apply, false );
+  configChanged = false;
+}
+
+
+COptionDialog::~COptionDialog( void )
+{
+}
+
+void COptionDialog::slotChanged()
+{
+  enableButton( Apply, true );
+  configChanged = true;
+}
+
+void COptionDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  showPage(0);
+  mLayout.lineSizeSpin->setFocus();
+}
+
+
+void COptionDialog::setupLayoutPage( void )
+{
+  TQString text;
+  TQFrame *page = addPage( i18n("Layout"), i18n("Data Layout in Editor"),
+			  BarIcon("khexedit", TDEIcon::SizeMedium ) );
+
+  TQGridLayout *gbox = new TQGridLayout( page, 15, 2, 0, spacingHint() );
+  gbox->setColStretch( 1, 10 );
+
+  mLayout.formatCombo  = new TQComboBox( false, page );
+  TQStringList modeList;
+  modeList.append( i18n("Hexadecimal Mode") );
+  modeList.append( i18n("Decimal Mode") );
+  modeList.append( i18n("Octal Mode") );
+  modeList.append( i18n("Binary Mode") );
+  modeList.append( i18n("Text Only Mode") );
+  mLayout.formatCombo->insertStringList( modeList );
+  connect( mLayout.formatCombo, TQT_SIGNAL(activated(int)),
+	   TQT_SLOT(slotModeSelectorChanged(int)) );
+  connect( mLayout.formatCombo, TQT_SIGNAL(activated(int)),
+    TQT_SLOT(slotChanged()) );
+  gbox->addWidget( mLayout.formatCombo, 0, 1 );
+
+  //
+  // I am setting the min. width for one widget in the second column
+  // This widtk will be used by every widget in this column.
+  //
+  mLayout.lineSizeSpin = new TQSpinBox( page );
+  mLayout.lineSizeSpin->setMinimumWidth( fontMetrics().width("M") * 10 );
+  mLayout.lineSizeSpin->setRange( 1, 10000 );
+  connect( mLayout.lineSizeSpin, TQT_SIGNAL(valueChanged(int)),
+	   TQT_SLOT(slotLineSizeChanged(int) ) );
+  connect( mLayout.lineSizeSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT(slotChanged()) );
+  gbox->addWidget( mLayout.lineSizeSpin, 1, 1 );
+
+  mLayout.columnSizeSpin = new TQSpinBox( page );
+  mLayout.columnSizeSpin->setRange( 1, 10000 );
+  connect( mLayout.columnSizeSpin, TQT_SIGNAL(valueChanged(int)),
+	   TQT_SLOT(slotColumnSizeChanged(int) ) );
+  connect( mLayout.columnSizeSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT(slotChanged() ) );
+  gbox->addWidget( mLayout.columnSizeSpin, 2, 1 );
+
+  text = i18n("Default l&ine size [bytes]:");
+  TQLabel *label = new TQLabel( mLayout.lineSizeSpin, text, page );
+  gbox->addWidget( label, 1, 0 );
+
+  text = i18n("Colu&mn size [bytes]:");
+  label = new TQLabel( mLayout.columnSizeSpin, text, page );
+  gbox->addWidget( label, 2, 0 );
+
+  TQFrame *hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  gbox->addMultiCellWidget( hline, 3, 3, 0, 1 );
+
+  text = i18n("Line size is &fixed (use scrollbar when required)");
+  mLayout.lockLineCheck = new TQCheckBox( text, page );
+  gbox->addMultiCellWidget( mLayout.lockLineCheck, 4, 4, 0, 1, AlignLeft );
+  connect( mLayout.lockLineCheck, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT(slotChanged()) );
+
+  text = i18n("Loc&k column at end of line (when column size>1)");
+  mLayout.lockColumnCheck = new TQCheckBox( text, page );
+  gbox->addMultiCellWidget( mLayout.lockColumnCheck, 5, 5, 0, 1 );
+  connect( mLayout.lockColumnCheck, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT(slotChanged()) );
+
+  hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  gbox->addMultiCellWidget( hline, 6, 6, 0, 1 );
+
+  TQStringList gridList;
+  gridList.append( i18n("None") );
+  gridList.append( i18n("Vertical Only") );
+  gridList.append( i18n("Horizontal Only") );
+  gridList.append( i18n("Both Directions") );
+
+  mLayout.gridCombo = new TQComboBox( false, page );
+  mLayout.gridCombo->insertStringList( gridList );
+  connect( mLayout.gridCombo, TQT_SIGNAL(activated(int)),
+    TQT_SLOT(slotChanged()) );
+
+  text = i18n("&Gridlines between text:");
+  label = new TQLabel( mLayout.gridCombo, text, page );
+
+  gbox->addWidget( label, 7, 0 );
+  gbox->addWidget( mLayout.gridCombo, 7, 1 );
+
+  mLayout.leftSepWidthSpin = new TQSpinBox( page );
+  mLayout.leftSepWidthSpin->setRange( 0, 20 );
+  gbox->addWidget( mLayout.leftSepWidthSpin, 8, 1 );
+  connect( mLayout.leftSepWidthSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT(slotChanged()) );
+
+  mLayout.rightSepWidthSpin = new TQSpinBox( page );
+  mLayout.rightSepWidthSpin->setRange( 0, 20 );
+  gbox->addWidget( mLayout.rightSepWidthSpin, 9, 1 );
+  connect( mLayout.rightSepWidthSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT(slotChanged()) );
+
+  text = i18n("&Left separator width [pixels]:");
+  mLayout.leftSepLabel = new TQLabel( mLayout.leftSepWidthSpin, text, page );
+  gbox->addWidget( mLayout.leftSepLabel, 8, 0 );
+
+  text = i18n("&Right separator width [pixels]:");
+  mLayout.rightSepLabel = new TQLabel( mLayout.rightSepWidthSpin, text, page );
+  gbox->addWidget( mLayout.rightSepLabel, 9, 0 );
+
+  mLayout.separatorSpin = new TQSpinBox( page );
+  mLayout.separatorSpin->setRange( 0, 20 );
+  gbox->addWidget( mLayout.separatorSpin, 10, 1 );
+  connect( mLayout.separatorSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT(slotChanged()) );
+
+  mLayout.edgeSpin = new TQSpinBox( page );
+  mLayout.edgeSpin->setRange( 0, 20 );
+  gbox->addWidget( mLayout.edgeSpin, 11, 1 );
+  connect( mLayout.edgeSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT(slotChanged()) );
+
+  text = i18n("&Separator margin width [pixels]:");
+  label = new TQLabel( mLayout.separatorSpin, text, page );
+  gbox->addWidget( label, 10, 0 );
+
+  text = i18n("&Edge margin width [pixels]:");
+  label = new TQLabel( mLayout.edgeSpin, text, page );
+  gbox->addWidget( label, 11, 0 );
+
+  text = i18n("Column separation is e&qual to one character");
+  mLayout.columnCheck = new TQCheckBox( text, page );
+  gbox->addMultiCellWidget( mLayout.columnCheck, 12, 12, 0, 1, AlignLeft );
+  connect( mLayout.columnCheck, TQT_SIGNAL(toggled(bool)),
+	   TQT_SLOT( slotColumnSepCheck(bool)));
+  connect( mLayout.columnCheck, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+
+  mLayout.columnSepSpin = new TQSpinBox( page );
+  mLayout.columnSepSpin->setRange( 1, 100 );
+  connect( mLayout.columnSepSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT(slotChanged()) );
+
+  text = i18n("Column separa&tion [pixels]:");
+  mLayout.columnSepLabel = new TQLabel( mLayout.columnSepSpin, text, page );
+
+  gbox->addWidget( mLayout.columnSepLabel, 13, 0 );
+  gbox->addWidget( mLayout.columnSepSpin, 13, 1 );
+
+  gbox->setRowStretch( 14, 10 );
+}
+
+
+void COptionDialog::setupCursorPage( void )
+{
+  TQString text;
+  TQFrame *page = addPage( i18n("Cursor"),
+    i18n("Cursor Behavior (only valid for editor)"),
+    BarIcon("input-mouse", TDEIcon::SizeMedium ) );
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
+
+  TQVButtonGroup *group = new TQVButtonGroup( i18n("Blinking"), page );
+  group->layout()->setMargin( spacingHint() );
+  topLayout->addWidget( group );
+
+  text = i18n("Do not b&link");
+  mCursor.blinkCheck = new TQCheckBox( i18n("Do not b&link"), group );
+  connect( mCursor.blinkCheck, TQT_SIGNAL(toggled(bool)),
+	   TQT_SLOT( slotBlinkIntervalCheck(bool)));
+  connect( mCursor.blinkCheck, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+
+  TQHBox *hbox = new TQHBox( group );
+  mCursor.blinkLabel = new TQLabel( i18n("&Blink interval [ms]:" ), hbox );
+  mCursor.blinkSpin = new TQSpinBox( hbox );
+  mCursor.blinkSpin->setMinimumWidth( fontMetrics().width("M") * 10 );
+  mCursor.blinkSpin->setRange( 100, 1000 );
+  mCursor.blinkSpin->setSteps( 100, 100 );
+  mCursor.blinkSpin->setValue( 500 );
+  mCursor.blinkLabel->setBuddy(mCursor.blinkSpin);
+  connect( mCursor.blinkSpin, TQT_SIGNAL(valueChanged(int)),
+    TQT_SLOT( slotChanged()));
+
+  group = new TQVButtonGroup( i18n("Shape"), page );
+  group->layout()->setMargin( spacingHint() );
+  topLayout->addWidget( group );
+
+  text = i18n("Always &use block (rectangular) cursor");
+  mCursor.blockCheck = new TQCheckBox( text, group );
+  connect( mCursor.blockCheck, TQT_SIGNAL(toggled(bool)),
+	   TQT_SLOT( slotBlockCursorCheck(bool)));
+  connect( mCursor.blockCheck, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+  text = i18n("Use &thick cursor in insert mode");
+  mCursor.thickCheck = new TQCheckBox( text, group );
+  connect( mCursor.thickCheck, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+
+  text = i18n("Cursor Behavior When Editor Loses Focus");
+  group = new TQVButtonGroup( text, page );
+  group->layout()->setMargin( spacingHint() );
+  topLayout->addWidget( group );
+
+  text = i18n("&Stop blinking (if blinking is enabled)");
+  mCursor.stopRadio = new TQRadioButton( text, group, "radio1" );
+  mCursor.hideRadio = new TQRadioButton( i18n("H&ide"), group, "radio2" );
+  text = i18n("Do &nothing");
+  mCursor.nothingRadio = new TQRadioButton( text, group, "radio3" );
+  connect( mCursor.stopRadio, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+  connect( mCursor.hideRadio, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+  connect( mCursor.nothingRadio, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+
+  topLayout->addStretch(10);
+}
+
+
+void COptionDialog::setupColorPage( void )
+{
+  TQString text;
+  TQFrame *page = addPage( i18n("Colors"),
+    i18n("Editor Colors (system selection color is always used)"),
+    BarIcon("colorize", TDEIcon::SizeMedium ) );
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
+
+  text = i18n("&Use system colors (as chosen in Control Center)");
+  mColor.checkSystem = new TQCheckBox( text, page );
+  connect( mColor.checkSystem, TQT_SIGNAL(toggled(bool)),
+	   TQT_SLOT( slotColorSystem(bool)));
+  connect( mColor.checkSystem, TQT_SIGNAL(toggled(bool)),
+    TQT_SLOT( slotChanged()));
+  topLayout->addWidget( mColor.checkSystem );
+
+  TQFrame *hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  topLayout->addWidget( hline );
+
+  TQStringList modeList;
+  modeList.append( i18n("First, Third ... Line Background") );
+  modeList.append( i18n("Second, Fourth ... Line Background") );
+  modeList.append( i18n("Offset Background") );
+  modeList.append( i18n("Inactive Background") );
+  modeList.append( i18n("Even Column Text") );
+  modeList.append( i18n("Odd Column Text") );
+  modeList.append( i18n("Non Printable Text") );
+  modeList.append( i18n("Offset Text") );
+  modeList.append( i18n("Secondary Text") );
+  modeList.append( i18n("Marked Background") );
+  modeList.append( i18n("Marked Text") );
+  modeList.append( i18n("Cursor Background") );
+  modeList.append( i18n("Cursor Text (block shape)") );
+  modeList.append( i18n("Bookmark Background") );
+  modeList.append( i18n("Bookmark Text") );
+  modeList.append( i18n("Separator") );
+  modeList.append( i18n("Grid Lines") );
+
+  mColor.colorList = new CColorListBox( page );
+  topLayout->addWidget( mColor.colorList, 10 );
+  for( uint i=0; i<17; i++ )
+  {
+    CColorListItem *listItem = new CColorListItem( modeList[i] );
+    mColor.colorList->insertItem( listItem );
+  }
+  mColor.colorList->setCurrentItem(0);
+  connect( mColor.colorList, TQT_SIGNAL( dataChanged() ), this, TQT_SLOT( slotChanged() ) );
+}
+
+
+void COptionDialog::setupFontPage( void )
+{
+  TQString text;
+  TQFrame *page = addPage( i18n("Font"),
+    i18n("Font Selection (editor can only use a fixed font)"),
+    BarIcon("fonts", TDEIcon::SizeMedium ) );
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
+
+  text = i18n("&Use system font (as chosen in Control Center)");
+  mFont.checkSystem = new TQCheckBox( text, page );
+  connect( mFont.checkSystem, TQT_SIGNAL(toggled(bool)),
+	   this, TQT_SLOT( slotFontSystem(bool)));
+  connect( mFont.checkSystem, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+  topLayout->addWidget( mFont.checkSystem );
+
+  TQFrame *hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  topLayout->addWidget( hline );
+
+  mFont.chooser = new TDEFontChooser( page, "font", true, TQStringList(), false, 4 );
+  topLayout->addWidget( mFont.chooser );
+  TQFont fixFont( TDEGlobalSettings::fixedFont() );
+  fixFont.setBold(true);
+  mFont.chooser->setFont( fixFont, true );
+  mFont.chooser->setSampleText( i18n("KHexEdit editor font") );
+  connect( mFont.chooser, TQT_SIGNAL(fontSelected(const TQFont &)),
+    this, TQT_SLOT( slotChanged()));
+
+  hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  topLayout->addWidget( hline );
+
+  TQHBoxLayout *hbox = new TQHBoxLayout();
+  topLayout->addLayout( hbox );
+
+  mFont.nonPrintInput = new TQLineEdit( page );
+  mFont.nonPrintInput->setMaxLength( 1 );
+  connect( mFont.nonPrintInput, TQT_SIGNAL(textChanged(const TQString &)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("&Map non printable characters to:");
+  TQLabel *nonPrintLabel = new TQLabel( mFont.nonPrintInput, text, page );
+
+  hbox->addWidget( nonPrintLabel, 0, AlignLeft );
+  hbox->addSpacing( spacingHint() );
+  hbox->addWidget( mFont.nonPrintInput, 10 );
+
+  topLayout->addStretch(10);
+}
+
+
+void COptionDialog::setupFilePage( void )
+{
+  TQString text;
+  TQFrame *page = addPage( i18n("Files"), i18n("File Management"),
+			  BarIcon("application-vnd.tde.tdemultiple", TDEIcon::SizeMedium ) );
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
+
+  TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
+  topLayout->addLayout( gbox );
+
+  mFile.openCombo = new TQComboBox( false, page );
+  TQStringList modeList;
+  modeList.append( i18n("None") );
+  modeList.append( i18n("Most Recent Document") );
+  modeList.append( i18n("All Recent Documents") );
+  mFile.openCombo->insertStringList( modeList );
+  mFile.openCombo->setMinimumWidth( mFile.openCombo->sizeHint().width() );
+  connect( mFile.openCombo, TQT_SIGNAL(activated(int)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("Open doc&uments on startup:");
+  TQLabel *label = new TQLabel( mFile.openCombo, text, page );
+
+  gbox->addWidget( label, 0, 0 );
+  gbox->addWidget( mFile.openCombo, 0, 1 );
+
+  text = i18n("&Jump to previous cursor position on startup");
+  mFile.gotoOffsetCheck = new TQCheckBox( text, page );
+  // ### TODO: this is currently not available.
+  mFile.gotoOffsetCheck->setChecked( false );
+  mFile.gotoOffsetCheck->setEnabled( false );
+  // ### END
+  topLayout->addWidget( mFile.gotoOffsetCheck, 0, AlignLeft );
+  connect( mFile.gotoOffsetCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  TQFrame *hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  topLayout->addWidget( hline );
+
+  text = i18n("Open document with &write protection enabled");
+  mFile.writeProtectCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mFile.writeProtectCheck, 0, AlignLeft );
+  connect( mFile.writeProtectCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("&Keep cursor position after reloading document");
+  mFile.reloadOffsetCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mFile.reloadOffsetCheck, 0, AlignLeft );
+  connect( mFile.reloadOffsetCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("&Make a backup when saving document");
+  mFile.backupCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mFile.backupCheck, 0, AlignLeft );
+  connect( mFile.backupCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  topLayout->addWidget( hline );
+
+  text = i18n("Don't &save \"Recent\" document list on exit");
+  mFile.discardRecentCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mFile.discardRecentCheck, 0, AlignLeft );
+  TQWhatsThis::add( mFile.discardRecentCheck,
+                   i18n( "Clicking this check box makes KHexEdit forget his recent document list "
+                          "when the program is closed.\n"
+                          "Note: it will not erase any document of the recent document list "
+                          "created by TDE." ) );
+  connect( mFile.discardRecentCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("Cl&ear \"Recent\" Document List");
+  TQPushButton *discardRecentButton = new TQPushButton( page );
+  discardRecentButton->setText( text );
+  TQWhatsThis::add( discardRecentButton,
+                   i18n( "Clicking this button makes KHexEdit forget his recent document list.\n"
+                          "Note: it will not erase any document of the recent document list "
+                          "created by TDE." ) );
+  topLayout->addWidget( discardRecentButton, 0, AlignCenter );
+  connect( discardRecentButton, TQT_SIGNAL(clicked()),
+	   TQT_SIGNAL(removeRecentFiles()) );
+
+  topLayout->addStretch(10);
+}
+
+
+
+void COptionDialog::setupMiscPage( void )
+{
+  TQString text;
+  TQLabel *label;
+
+  TQFrame *page = addPage( i18n("Miscellaneous"), i18n("Various Properties"),
+			  BarIcon("gear", TDEIcon::SizeMedium ) );
+
+  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
+
+
+  text = i18n("Auto&matic copy to clipboard when selection is ready");
+  mMisc.autoCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mMisc.autoCheck, 0, AlignLeft );
+  connect( mMisc.autoCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("&Editor starts in \"insert\" mode" );
+  mMisc.insertCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mMisc.insertCheck, 0, AlignLeft );
+  connect( mMisc.insertCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("Confirm &wrapping (to beginning or end) during search");
+  mMisc.confirmWrapCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mMisc.confirmWrapCheck, 0, AlignLeft );
+  connect( mMisc.confirmWrapCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("Cursor jumps to &nearest byte when moved");
+  mMisc.cursorJumpCheck = new TQCheckBox( text, page );
+  topLayout->addWidget( mMisc.cursorJumpCheck, 0, AlignLeft );
+  connect( mMisc.cursorJumpCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  TQVButtonGroup *group = new TQVButtonGroup( i18n("Sounds"), page );
+  group->layout()->setMargin( spacingHint() );
+  topLayout->addWidget( group );
+  text = i18n("Make sound on data &input (eg. typing) failure");
+  mMisc.inputCheck = new TQCheckBox( text, group );
+  connect( mMisc.inputCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+  text = i18n("Make sound on &fatal failure");
+  mMisc.fatalCheck = new TQCheckBox( text, group );
+  connect( mMisc.fatalCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  group = new TQVButtonGroup( i18n("Bookmark Visibility"), page );
+  group->layout()->setMargin( spacingHint() );
+  topLayout->addWidget( group );
+  text = i18n("Use visible bookmarks in the offset column");
+  mMisc.bookmarkColumnCheck = new TQCheckBox( text, group );
+  connect( mMisc.bookmarkColumnCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+  text = i18n("Use visible bookmarks in the editor fields");
+  mMisc.bookmarkEditorCheck = new TQCheckBox( text, group );
+  connect( mMisc.bookmarkEditorCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("Confirm when number of printed pages will e&xceed limit");
+  mMisc.thresholdCheck = new TQCheckBox( text, page );
+  connect( mMisc.thresholdCheck, TQT_SIGNAL(clicked()),
+	   TQT_SLOT( slotThresholdConfirm()));
+  connect( mMisc.thresholdCheck, TQT_SIGNAL(toggled(bool)),
+    this, TQT_SLOT( slotChanged()));
+  topLayout->addWidget( mMisc.thresholdCheck, 0, AlignLeft );
+
+  TQGridLayout *glay = new TQGridLayout( 3, 3 );
+  glay->setColStretch(2,10);
+  topLayout->addLayout( glay );
+
+  mMisc.thresholdSpin = new TQSpinBox( page );
+  mMisc.thresholdSpin->setMinimumWidth( fontMetrics().width("M") * 10 );
+  mMisc.thresholdSpin->setRange( 5, INT_MAX );
+  mMisc.thresholdSpin->setSteps( 5, 5 );
+  mMisc.thresholdSpin->setValue( 5 );
+  connect( mMisc.thresholdSpin, TQT_SIGNAL(valueChanged(int)),
+    this, TQT_SLOT( slotChanged()));
+
+  text = i18n("&Threshold [pages]:" );
+  mMisc.thresholdLabel = new TQLabel( mMisc.thresholdSpin, text, page );
+
+  glay->addWidget( mMisc.thresholdLabel, 0, 0 );
+  glay->addWidget( mMisc.thresholdSpin, 0, 1 );
+
+  TQFrame *hline = new TQFrame( page );
+  hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
+  glay->addMultiCellWidget( hline, 1, 1, 0, 2 );
+
+  mMisc.undoSpin = new TQSpinBox( page );
+  mMisc.undoSpin->setRange( 10, 10000 );
+  mMisc.undoSpin->setSteps( 5, 5 );
+  mMisc.undoSpin->setValue( 50 );
+  connect( mMisc.undoSpin, TQT_SIGNAL(valueChanged(int)),
+    this, TQT_SLOT( slotChanged()));
+
+  label = new TQLabel( mMisc.undoSpin, i18n("&Undo limit:"), page );
+  glay->addWidget( label, 2, 0 );
+  glay->addWidget( mMisc.undoSpin, 2, 1 );
+
+  topLayout->addStretch(10);
+}
+
+
+
+void COptionDialog::slotModeSelectorChanged( int index )
+{
+  int lineSize = mDisplayState.line.getLineSize( index );
+  int colSize  = mDisplayState.line.getColumnSize( index );
+  mLayout.lineSizeSpin->setValue( lineSize );
+  mLayout.columnSizeSpin->setValue( colSize );
+}
+
+void COptionDialog::slotLineSizeChanged( int value )
+{
+  int index = mLayout.formatCombo->currentItem();
+  mDisplayState.line.setLineSize( index, value );
+  if( index == SDisplayLine::textOnly )
+  {
+    mLayout.columnSizeSpin->setValue( value );
+  }
+}
+
+void COptionDialog::slotColumnSizeChanged( int value )
+{
+  int index = mLayout.formatCombo->currentItem();
+  mDisplayState.line.setColumnSize( index, value );
+  if( index == SDisplayLine::textOnly )
+  {
+    mLayout.lineSizeSpin->setValue( value );
+  }
+}
+
+void COptionDialog::slotColumnSepCheck( bool state )
+{
+  state = state == true ? false: true;
+  mLayout.columnSepLabel->setEnabled( state );
+  mLayout.columnSepSpin->setEnabled( state );
+}
+
+
+void COptionDialog::slotBlinkIntervalCheck( bool state )
+{
+  state = state == true ? false : true;
+  mCursor.blinkSpin->setEnabled( state );
+  mCursor.blinkLabel->setEnabled( state );
+}
+
+void COptionDialog::slotBlockCursorCheck( bool state )
+{
+  state = state == true ? false : true;
+  mCursor.thickCheck->setEnabled( state );
+}
+
+void COptionDialog::slotFontSystem( bool state )
+{
+  mFont.chooser->setEnabled( state == true ? false : true );
+}
+
+void COptionDialog::slotColorSystem( bool state )
+{
+  state = state == true ? false : true;
+  mColor.colorList->setEnabled( state );
+}
+
+
+
+void COptionDialog::slotThresholdConfirm( void )
+{
+  bool state = mMisc.thresholdCheck->isChecked();
+  mMisc.thresholdLabel->setEnabled( state );
+  mMisc.thresholdSpin->setEnabled( state );
+}
+
+
+void COptionDialog::slotDefault( void )
+{
+  //
+  // We use the constructor settings as default values
+  //
+  switch( activePageIndex() )
+  {
+    case page_layout:
+    {
+      SDisplayLayout layout;
+      SDisplayLine line;
+      setLayout( layout, line );
+    }
+    break;
+
+    case page_cursor:
+    {
+      SDisplayCursor cursor;
+      setCursor( cursor );
+    }
+    break;
+
+    case page_color:
+    {
+      SDisplayColor color;
+      setColor( color );
+    }
+    break;
+
+    case page_font:
+    {
+      SDisplayFont font;
+      setFont( font );
+    }
+    break;
+
+    case page_file:
+    {
+      SDisplayMisc misc;
+      setFile( misc );
+    }
+    break;
+
+    case page_misc:
+    {
+      SDisplayMisc misc;
+      setMisc( misc );
+    }
+    break;
+  }
+}
+
+
+void COptionDialog::slotOk( void )
+{
+  if( configChanged )
+    slotApply();
+  accept();
+}
+
+void COptionDialog::slotApply( void )
+{
+  switch( activePageIndex() )
+  {
+    case page_layout:
+    {
+      int index = mLayout.formatCombo->currentItem();
+      mDisplayState.line.setLineSize(index, mLayout.lineSizeSpin->value());
+      mDisplayState.line.setColumnSize(index, mLayout.columnSizeSpin->value());
+      emit lineSizeChoice( mDisplayState.line );
+
+      SDisplayLayout &l = mDisplayState.layout;
+      l.lockLine = mLayout.lockLineCheck->isChecked();
+      l.lockColumn = mLayout.lockColumnCheck->isChecked();
+      l.leftSeparatorWidth = mLayout.leftSepWidthSpin->value();
+      l.rightSeparatorWidth = mLayout.rightSepWidthSpin->value();
+      l.separatorMarginWidth = mLayout.separatorSpin->value();
+      l.edgeMarginWidth = mLayout.edgeSpin->value();
+      l.leftSeparatorWidth = mLayout.leftSepWidthSpin->value();
+      l.rightSeparatorWidth = mLayout.rightSepWidthSpin->value();
+      l.columnCharSpace = mLayout.columnCheck->isChecked();
+      l.columnSpacing = mLayout.columnSepSpin->value();
+
+      if( mLayout.gridCombo->currentItem() == 0 )
+      {
+	l.horzGridWidth = l.vertGridWidth = 0;
+      }
+      else if( mLayout.gridCombo->currentItem() == 1 )
+      {
+	l.horzGridWidth = 0;
+	l.vertGridWidth = 1;
+      }
+      else if( mLayout.gridCombo->currentItem() == 2 )
+      {
+	l.horzGridWidth = 1;
+	l.vertGridWidth = 0;
+      }
+      else
+      {
+	l.horzGridWidth = l.vertGridWidth = 1;
+      }
+
+      emit layoutChoice( mDisplayState.layout );
+    }
+    break;
+
+
+    case page_cursor:
+    {
+      SDisplayCursor &c = mDisplayState.cursor;
+      c.alwaysVisible    = mCursor.blinkCheck->isChecked();
+      c.interval         = mCursor.blinkSpin->value();
+      c.alwaysBlockShape = mCursor.blockCheck->isChecked();
+      c.thickInsertShape = mCursor.thickCheck->isChecked();
+      c.focusMode        = cursorFocusMode();
+      emit cursorChoice( mDisplayState.cursor );
+    }
+    break;
+
+    case page_color:
+    {
+      SDisplayColor &c = mDisplayState.color;
+      c.useSystemColor = mColor.checkSystem->isChecked();
+      c.textBg = mColor.colorList->color( SColorWidgets::FirstTextBg );
+      c.secondTextBg = mColor.colorList->color( SColorWidgets::SecondTextBg );
+      c.offsetBg = mColor.colorList->color( SColorWidgets::OffsetBg );
+      c.inactiveBg = mColor.colorList->color( SColorWidgets::InactiveBg );
+      c.markBg = mColor.colorList->color( SColorWidgets::MarkedBg );
+      c.markFg = mColor.colorList->color( SColorWidgets::MarkedFg );
+      c.primaryFg[0] = mColor.colorList->color( SColorWidgets::EvenColumnFg );
+      c.primaryFg[1] = mColor.colorList->color( SColorWidgets::OddColumnFg );
+      c.offsetFg  = mColor.colorList->color( SColorWidgets::OffsetFg );
+      c.secondaryFg = mColor.colorList->color( SColorWidgets::SecondaryFg );
+      c.cursorBg  = mColor.colorList->color( SColorWidgets::CursorBg );
+      c.cursorFg  = mColor.colorList->color( SColorWidgets::CursorFg );
+      c.leftSeparatorFg = mColor.colorList->color(SColorWidgets::SeparatorFg);
+      c.rightSeparatorFg = mColor.colorList->color(SColorWidgets::SeparatorFg);
+      c.bookmarkBg = mColor.colorList->color( SColorWidgets::BookmarkBg );
+      c.bookmarkFg = mColor.colorList->color( SColorWidgets::BookmarkFg );
+      c.nonPrintFg  = mColor.colorList->color( SColorWidgets::NonPrintFg );
+      c.gridFg = mColor.colorList->color( SColorWidgets::GridFg );
+      emit colorChoice( mDisplayState.color );
+    }
+    break;
+
+    case page_font:
+    {
+      SDisplayFont &f = mDisplayState.font;
+      f.useSystemFont = mFont.checkSystem->isChecked();
+      f.localFont = mFont.chooser->font();
+
+      TQString nonPrintText = mFont.nonPrintInput->text();
+      if( nonPrintText.isEmpty() )
+      {
+	f.nonPrintChar = ' ';
+      }
+      else
+      {
+	f.nonPrintChar = nonPrintText[0];
+      }
+
+      emit fontChoice( mDisplayState.font );
+    }
+    break;
+
+    case page_file:
+    case page_misc:
+    {
+      SDisplayMisc &m = mDisplayState.misc;
+      m.undoLevel = mMisc.undoSpin->value();
+      m.autoCopyToClipboard = mMisc.autoCheck->isChecked();
+      m.insertMode = mMisc.insertCheck->isChecked();
+      m.inputSound = mMisc.inputCheck->isChecked();
+      m.confirmWrap = mMisc.confirmWrapCheck->isChecked();
+      m.cursorJump = mMisc.cursorJumpCheck->isChecked();
+      m.fatalSound = mMisc.fatalCheck->isChecked();
+      m.confirmThreshold = mMisc.thresholdCheck->isChecked();
+      m.thresholdValue = mMisc.thresholdSpin->value();
+      m.bookmarkOffsetColumn = mMisc.bookmarkColumnCheck->isChecked();
+      m.bookmarkEditor = mMisc.bookmarkEditorCheck->isChecked();
+
+      m.openFile  = (SDisplayMisc::EOpenFile)mFile.openCombo->currentItem();
+      m.gotoOnStartup = mFile.gotoOffsetCheck->isChecked();
+      m.writeProtect = mFile.writeProtectCheck->isChecked();
+      m.gotoOnReload = mFile.reloadOffsetCheck->isChecked();
+      m.makeBackup = mFile.backupCheck->isChecked();
+      m.discardRecent = mFile.discardRecentCheck->isChecked();
+
+      emit miscChoice( mDisplayState.misc );
+    }
+    break;
+  }
+  enableButton( Apply, false );
+  configChanged = false;
+}
+
+void COptionDialog::setLayout( SDisplayLayout &layout, SDisplayLine &line )
+{
+  mDisplayState.line = line;
+  mDisplayState.layout = layout;
+
+  slotModeSelectorChanged( mLayout.formatCombo->currentItem() );
+  mLayout.lockLineCheck->setChecked( layout.lockLine );
+  mLayout.lockColumnCheck->setChecked( layout.lockColumn );
+  mLayout.leftSepWidthSpin->setValue( layout.leftSeparatorWidth );
+  mLayout.rightSepWidthSpin->setValue( layout.rightSeparatorWidth );
+  mLayout.separatorSpin->setValue( layout.separatorMarginWidth );
+  mLayout.edgeSpin->setValue( layout.edgeMarginWidth );
+  mLayout.leftSepWidthSpin->setValue( layout.leftSeparatorWidth );
+  mLayout.rightSepWidthSpin->setValue( layout.rightSeparatorWidth );
+  mLayout.columnCheck->setChecked( layout.columnCharSpace );
+  slotColumnSepCheck( layout.columnCharSpace );
+  mLayout.columnSepSpin->setValue( layout.columnSpacing );
+
+  if( layout.horzGridWidth == 0 && layout.vertGridWidth == 0 )
+  {
+    mLayout.gridCombo->setCurrentItem(0);
+  }
+  else if( layout.horzGridWidth != 0 && layout.vertGridWidth != 0 )
+  {
+    mLayout.gridCombo->setCurrentItem(3);
+  }
+  else
+  {
+    mLayout.gridCombo->setCurrentItem( layout.vertGridWidth != 0 ? 1 : 2 );
+  }
+
+}
+
+
+void COptionDialog::setCursor( SDisplayCursor &cursor )
+{
+  mDisplayState.cursor = cursor;
+
+  mCursor.blinkCheck->setChecked( cursor.alwaysVisible );
+  mCursor.blinkSpin->setValue( cursor.interval );
+  mCursor.blockCheck->setChecked( cursor.alwaysBlockShape );
+  mCursor.thickCheck->setChecked( cursor.thickInsertShape );
+  bool state = cursor.focusMode == SDisplayCursor::stopBlinking ? true : false;
+  mCursor.stopRadio->setChecked( state );
+  state = cursor.focusMode == SDisplayCursor::hide ? true : false;
+  mCursor.hideRadio->setChecked( state );
+  state = cursor.focusMode == SDisplayCursor::ignore ? true : false;
+  mCursor.nothingRadio->setChecked( state );
+}
+
+
+void COptionDialog::setColor( SDisplayColor &color )
+{
+  mDisplayState.color = color;
+
+  mColor.checkSystem->setChecked( color.useSystemColor );
+  mColor.colorList->setColor( SColorWidgets::FirstTextBg, color.textBg );
+  mColor.colorList->setColor( SColorWidgets::SecondTextBg, color.secondTextBg);
+  mColor.colorList->setColor( SColorWidgets::OffsetBg, color.offsetBg );
+  mColor.colorList->setColor( SColorWidgets::InactiveBg, color.inactiveBg );
+  mColor.colorList->setColor( SColorWidgets::MarkedBg, color.markBg );
+  mColor.colorList->setColor( SColorWidgets::MarkedFg, color.markFg );
+  mColor.colorList->setColor( SColorWidgets::EvenColumnFg, color.primaryFg[0]);
+  mColor.colorList->setColor( SColorWidgets::OddColumnFg, color.primaryFg[1] );
+  mColor.colorList->setColor( SColorWidgets::OffsetFg, color.offsetFg );
+  mColor.colorList->setColor( SColorWidgets::SecondaryFg, color.secondaryFg );
+  mColor.colorList->setColor( SColorWidgets::CursorBg, color.cursorBg );
+  mColor.colorList->setColor( SColorWidgets::CursorFg, color.cursorFg );
+  mColor.colorList->setColor(SColorWidgets::SeparatorFg,color.leftSeparatorFg);
+  mColor.colorList->setColor( SColorWidgets::BookmarkBg, color.bookmarkBg );
+  mColor.colorList->setColor( SColorWidgets::BookmarkFg, color.bookmarkFg );
+  mColor.colorList->setColor( SColorWidgets::NonPrintFg, color.nonPrintFg );
+  mColor.colorList->setColor( SColorWidgets::GridFg, color.gridFg );
+}
+
+
+void COptionDialog::setFont( SDisplayFont &font )
+{
+  mDisplayState.font = font;
+
+  mFont.checkSystem->setChecked( font.useSystemFont );
+  mFont.chooser->setFont( font.localFont, true );
+  TQString buf = font.nonPrintChar;
+  mFont.nonPrintInput->setText( buf );
+}
+
+
+void COptionDialog::setMisc( SDisplayMisc &misc )
+{
+  mDisplayState.misc.undoLevel            = misc.undoLevel;
+  mDisplayState.misc.inputSound           = misc.inputSound;
+  mDisplayState.misc.fatalSound           = misc.fatalSound;
+  mDisplayState.misc.autoCopyToClipboard  = misc.autoCopyToClipboard;
+  mDisplayState.misc.insertMode           = misc.insertMode;
+  mDisplayState.misc.confirmWrap          = misc.confirmWrap;
+  mDisplayState.misc.cursorJump           = misc.cursorJump;
+  mDisplayState.misc.confirmThreshold     = misc.confirmThreshold;
+  mDisplayState.misc.thresholdValue       = misc.thresholdValue;
+  mDisplayState.misc.bookmarkOffsetColumn = misc.bookmarkOffsetColumn;
+  mDisplayState.misc.bookmarkEditor       = misc.bookmarkEditor;
+
+  mMisc.autoCheck->setChecked( misc.autoCopyToClipboard );
+  mMisc.insertCheck->setChecked( misc.insertMode );
+  mMisc.confirmWrapCheck->setChecked( misc.confirmWrap );
+  mMisc.cursorJumpCheck->setChecked( misc.cursorJump );
+
+  mMisc.inputCheck->setChecked( misc.inputSound );
+  mMisc.fatalCheck->setChecked( misc.fatalSound );
+  mMisc.bookmarkColumnCheck->setChecked( misc.bookmarkOffsetColumn );
+  mMisc.bookmarkEditorCheck->setChecked( misc.bookmarkEditor );
+
+  mMisc.thresholdCheck->setChecked( misc.confirmThreshold );
+  mMisc.thresholdSpin->setValue( misc.thresholdValue );
+  slotThresholdConfirm();
+
+  mMisc.undoSpin->setValue( misc.undoLevel );
+}
+
+void COptionDialog::setFile( SDisplayMisc &misc )
+{
+  mDisplayState.misc.openFile      = misc.openFile;
+  mDisplayState.misc.gotoOnStartup = misc.gotoOnStartup;
+  mDisplayState.misc.writeProtect  = misc.writeProtect;
+  mDisplayState.misc.gotoOnReload  = misc.gotoOnReload;
+  mDisplayState.misc.discardRecent = misc.discardRecent;
+  mDisplayState.misc.makeBackup    = misc.makeBackup;
+
+  mFile.openCombo->setCurrentItem( (uint)misc.openFile );
+  mFile.gotoOffsetCheck->setChecked( misc.gotoOnStartup );
+  mFile.writeProtectCheck->setChecked( misc.writeProtect );
+  mFile.reloadOffsetCheck->setChecked( misc.gotoOnReload );
+  mFile.discardRecentCheck->setChecked( misc.discardRecent );
+  mFile.backupCheck->setChecked( misc.makeBackup );
+}
+
+
+void COptionDialog::setState( SDisplayState &state )
+{
+  setLayout( state.layout, state.line );
+  setCursor( state.cursor );
+  setColor( state.color );
+  setFont( state.font );
+  setFile( state.misc );
+  setMisc( state.misc );
+  enableButton( Apply, false );
+  configChanged = false;
+}
+
+
+SDisplayCursor::EFocusMode COptionDialog::cursorFocusMode( void )
+{
+  if( mCursor.stopRadio->isChecked() == true )
+  {
+    return( SDisplayCursor::stopBlinking );
+  }
+  else if( mCursor.hideRadio->isChecked() == true )
+  {
+    return( SDisplayCursor::hide );
+  }
+  else
+  {
+    return( SDisplayCursor::ignore );
+  }
+}
+
+
+
+CColorListBox::CColorListBox( TQWidget *parent, const char *name, WFlags f )
+  :TDEListBox( parent, name, f ), mCurrentOnDragEnter(-1)
+{
+  connect( this, TQT_SIGNAL(selected(int)), this, TQT_SLOT(newColor(int)) );
+  setAcceptDrops( true);
+}
+
+
+void CColorListBox::setEnabled( bool state )
+{
+  if( state == isEnabled() )
+  {
+    return;
+  }
+
+  TQListBox::setEnabled( state );
+  for( uint i=0; i<count(); i++ )
+  {
+    updateItem( i );
+  }
+}
+
+
+void CColorListBox::setColor( uint index, const TQColor &color )
+{
+  if( index < count() )
+  {
+    CColorListItem *colorItem = (CColorListItem*)item(index);
+    colorItem->setColor(color);
+    updateItem( colorItem );
+  }
+}
+
+
+const TQColor CColorListBox::color( uint index )
+{
+  if( index < count() )
+  {
+    CColorListItem *colorItem = (CColorListItem*)item(index);
+    return( colorItem->color() );
+  }
+  else
+  {
+    return( black );
+  }
+}
+
+
+void CColorListBox::newColor( int index )
+{
+  if( isEnabled() == false )
+  {
+    return;
+  }
+
+  if( (uint)index < count() )
+  {
+    TQColor c = color( index );
+    if( KColorDialog::getColor( c, this ) != TQDialog::Rejected )
+    {
+      setColor( index, c );
+      emit dataChanged();
+    }
+  }
+}
+
+
+void CColorListBox::dragEnterEvent( TQDragEnterEvent *e )
+{
+  if( KColorDrag::canDecode(e) && isEnabled() )
+  {
+    mCurrentOnDragEnter = currentItem();
+    e->accept( true );
+  }
+  else
+  {
+    mCurrentOnDragEnter = -1;
+    e->accept( false );
+  }
+}
+
+
+void CColorListBox::dragLeaveEvent( TQDragLeaveEvent * )
+{
+  if( mCurrentOnDragEnter != -1 )
+  {
+    setCurrentItem( mCurrentOnDragEnter );
+    mCurrentOnDragEnter = -1;
+  }
+}
+
+
+void CColorListBox::dragMoveEvent( TQDragMoveEvent *e )
+{
+  if( KColorDrag::canDecode(e) && isEnabled() )
+  {
+    CColorListItem *item = (CColorListItem*)itemAt( e->pos() );
+    if( item != 0 )
+    {
+      setCurrentItem ( item );
+    }
+  }
+}
+
+
+void CColorListBox::dropEvent( TQDropEvent *e )
+{
+  TQColor color;
+  if( KColorDrag::decode( e, color ) )
+  {
+    int index = currentItem();
+    if( index != -1 )
+    {
+      CColorListItem *colorItem = (CColorListItem*)item(index);
+      colorItem->setColor(color);
+      triggerUpdate( false ); // Redraw item
+    }
+    mCurrentOnDragEnter = -1;
+  }
+}
+
+
+
+CColorListItem::CColorListItem( const TQString &text, const TQColor &color )
+  : TQListBoxItem(), mColor( color ), mBoxWidth( 30 )
+{
+  setText( text );
+}
+
+
+const TQColor &CColorListItem::color( void )
+{
+  return( mColor );
+}
+
+
+void CColorListItem::setColor( const TQColor &color )
+{
+  mColor = color;
+}
+
+
+void CColorListItem::paint( TQPainter *p )
+{
+  TQFontMetrics fm = p->fontMetrics();
+  int h = fm.height();
+
+  p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() );
+
+  p->setPen( TQt::black );
+  p->drawRect( 3, 1, mBoxWidth, h-1 );
+  p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor );
+}
+
+
+int CColorListItem::height(const TQListBox *lb ) const
+{
+  return( lb->fontMetrics().lineSpacing()+1 );
+}
+
+
+int CColorListItem::width(const TQListBox *lb ) const
+{
+  return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 );
+}
+
+
+
+
+
+
+#include "optiondialog.moc"
diff --git a/khexedit/printdialogpage.cc b/khexedit/printdialogpage.cc
deleted file mode 100644
index d421880f..00000000
--- a/khexedit/printdialogpage.cc
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <tqlayout.h>
-#include <tqbuttongroup.h>
-#include <tqspinbox.h>
-#include <tqlabel.h>
-#include <tqcheckbox.h>
-#include <tqstringlist.h>
-#include <tqcombobox.h>
-
-#include <tdelocale.h>
-
-
-#include "printdialogpage.h"
-
-LayoutDialogPage::LayoutDialogPage( TQWidget *parent, const char *name )
- : KPrintDialogPage( parent, name )
-{
-  mConfig = 0;
-  setTitle( i18n( "Page Layout" ) );
-  setupLayoutPage();
-
-  readConfiguration();
-}
-
-
-LayoutDialogPage::~LayoutDialogPage( void )
-{
-  writeConfiguration();
-  
-  delete mConfig; mConfig = 0;
-}
-
-
-void LayoutDialogPage::setupLayoutPage( void )
-{
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, 6 /*KDialog::mSpacingSize*/ );
-  if( topLayout == 0 ) { return; }
-
-  text = i18n("Margins [millimeter]");
-  TQButtonGroup *group = new TQButtonGroup( text, this );
-  if( group == 0 ) { return; }
-  topLayout->addWidget( group );
-
-  TQGridLayout *gbox = new TQGridLayout( group, 3, 6, 6 /*KDialog::mSpacingSize*/ );
-  if( gbox == 0 ) { return; }
-  gbox->addRowSpacing( 0, group->fontMetrics().height() );
-  gbox->setColStretch( 5, 10 );
-
-  TQString name[4];
-  int i;
-
-  name[0] = i18n("&Top:");
-  name[1] = i18n("&Bottom:");
-  name[2] = i18n("&Left:");
-  name[3] = i18n("&Right:");
-
-  for( i=0; i<4; i++ )
-  {
-    mLayout.marginSpin[i] = new TQSpinBox( group );
-    mLayout.marginSpin[i]->setFixedHeight(
-      mLayout.marginSpin[i]->sizeHint().height() );
-    mLayout.marginSpin[i]->setMinimumWidth(
-      mLayout.marginSpin[i]->fontMetrics().width("M")*10 );
-    mLayout.marginSpin[i]->setRange( 0, INT_MAX );
-
-    TQLabel *label = new TQLabel( mLayout.marginSpin[i], name[i], group );
-    label->setFixedHeight( mLayout.marginSpin[i]->sizeHint().height() );
-    label->setFixedWidth( label->sizeHint().width() );
-
-    if( i < 2 )
-    {
-      gbox->addWidget( label, i+1, 0, AlignLeft );
-      gbox->addWidget( mLayout.marginSpin[i], i+1, 1, AlignLeft );
-    }
-    else
-    {
-      gbox->addWidget( label, i-1, 3, AlignLeft );
-      gbox->addWidget( mLayout.marginSpin[i], i-1, 4, AlignLeft );
-    }
-  }
-  
-  text = i18n("Draw h&eader above text");
-  mLayout.headerCheck = new TQCheckBox( text, this );
-  mLayout.headerCheck->setFixedSize( mLayout.headerCheck->sizeHint() );
-  connect( mLayout.headerCheck, TQT_SIGNAL( toggled(bool)),
-	   TQT_SLOT( slotDrawHeader(bool)));
-  topLayout->addWidget( mLayout.headerCheck, 0, AlignLeft );
-
-  gbox = new TQGridLayout( 5, 6, 0 );
-  if( gbox == 0 ) { return; }
-  topLayout->addLayout( gbox );
-
-  gbox->setColStretch ( 5, 10 );
-  gbox->addColSpacing( 1, 6 /*KDialog::mSpacingSize*/ );
-  gbox->addColSpacing( 3, 6 /*KDialog::mSpacingSize*/ );
-  gbox->addRowSpacing( 2, 6 /*KDialog::mSpacingSize*/ );
-
-  name[0] = i18n("Left:");
-  name[1] = i18n("Center:");
-  name[2] = i18n("Right:");
-  name[3] = i18n("Border:");
-
-  TQStringList textList;
-  textList.append(i18n("None"));
-  textList.append(i18n("Date & Time"));
-  textList.append(i18n("Page Number"));
-  textList.append(i18n("Filename"));
-
-  TQStringList lineList;
-  lineList.append(i18n("None"));
-  lineList.append(i18n("Single Line"));
-  lineList.append(i18n("Rectangle"));
-
-  for( i=0; i<4; i++ )
-  {
-    mLayout.headerCombo[i] = new TQComboBox( false, this );
-    mLayout.headerCombo[i]->setFixedHeight(
-      mLayout.headerCombo[i]->sizeHint().height() );
-    mLayout.headerCombo[i]->setMinimumWidth(
-      mLayout.headerCombo[i]->fontMetrics().width("M")*10 );
- 
-    mLayout.headerLabel[i] = new TQLabel( mLayout.headerCombo[i], name[i],
-					 this );
-    mLayout.headerLabel[i]->setFixedHeight( 
-      mLayout.headerLabel[i]->sizeHint().height() );
-    mLayout.headerLabel[i]->setFixedWidth( 
-      mLayout.headerLabel[i]->sizeHint().width() );
-
-    if( i<3 )
-    {
-      mLayout.headerCombo[i]->insertStringList( textList );
-      gbox->addWidget( mLayout.headerLabel[i], 0, i*2, AlignLeft );
-      gbox->addWidget( mLayout.headerCombo[i], 1, i*2, AlignLeft );
-    }
-    else
-    {
-      mLayout.headerCombo[i]->insertStringList( lineList );
-      gbox->addWidget( mLayout.headerLabel[i], 3, 0, AlignLeft );
-      gbox->addWidget( mLayout.headerCombo[i], 4, 0, AlignLeft );
-    }
-  }
-
-
-  text = i18n("Draw &footer below text");
-  mLayout.footerCheck = new TQCheckBox( text, this );
-  mLayout.footerCheck->setFixedSize( mLayout.footerCheck->sizeHint() );
-  connect( mLayout.footerCheck, TQT_SIGNAL( toggled(bool)),
-	   TQT_SLOT( slotDrawFooter(bool)));
-  topLayout->addWidget( mLayout.footerCheck, 0, AlignLeft );
-
-  gbox = new TQGridLayout( 5, 6, 0 );
-  if( gbox == 0 ) { return; }
-  topLayout->addLayout( gbox );
-
-  gbox->setColStretch ( 5, 10 );
-  gbox->addColSpacing( 1, 6 /*KDialog::mSpacingSize*/ );
-  gbox->addColSpacing( 3, 6 /*KDialog::mSpacingSize*/ );
-  gbox->addRowSpacing( 2, 6 /*KDialog::mSpacingSize*/ );
-
-  for( i=0; i<4; i++ )
-  {
-    mLayout.footerCombo[i] = new TQComboBox( false, this );
-    mLayout.footerCombo[i]->setFixedHeight(
-      mLayout.footerCombo[i]->sizeHint().height() );
-    mLayout.footerCombo[i]->setMinimumWidth(
-      mLayout.footerCombo[i]->fontMetrics().width("M")*10 );
-
-    mLayout.footerLabel[i] = new TQLabel( mLayout.footerCombo[i], name[i], 
-					 this );
-    mLayout.footerLabel[i]->setFixedHeight( 
-      mLayout.footerLabel[i]->sizeHint().height() );
-    mLayout.footerLabel[i]->setFixedWidth( 
-      mLayout.footerLabel[i]->sizeHint().width() );
-
-    if( i<3 )
-    {
-      mLayout.footerCombo[i]->insertStringList( textList );
-      gbox->addWidget( mLayout.footerLabel[i], 0, i*2, AlignLeft );
-      gbox->addWidget( mLayout.footerCombo[i], 1, i*2, AlignLeft );
-    }
-    else
-    {
-      mLayout.footerCombo[i]->insertStringList( lineList );
-      gbox->addWidget( mLayout.footerLabel[i], 3, 0, AlignLeft );
-      gbox->addWidget( mLayout.footerCombo[i], 4, 0, AlignLeft );
-    }
-  }
-
-  for( i=0; i<4; i++ )
-  {
-    mLayout.marginSpin[i]->setValue( 15 );
-  }
-  mLayout.headerCheck->setChecked( true );
-  slotDrawHeader( true );
-  mLayout.footerCheck->setChecked( true );
-  slotDrawFooter( true );
-
-  topLayout->addStretch(10);
-}
-
-
-void LayoutDialogPage::readConfiguration( void )
-{
-  if( mConfig != 0 ) { return; }
-
-  mConfig = new KSimpleConfig( TQString("hexprinter") );
-  if( mConfig == 0 ) { return; }
-
-  mConfig->setGroup( "PageLayout" );
-  int val = mConfig->readNumEntry( "MarginTop", 15 );
-  mLayout.marginSpin[0]->setValue( val );
-  val = mConfig->readNumEntry( "MarginBottom", 15 );
-  mLayout.marginSpin[1]->setValue( val );
-  val = mConfig->readNumEntry( "MarginLeft", 15 );
-  mLayout.marginSpin[2]->setValue( val );
-  val = mConfig->readNumEntry( "MarginRight", 15 );
-  mLayout.marginSpin[3]->setValue( val );
-  bool state = mConfig->readBoolEntry( "DrawHeader", true );
-  mLayout.headerCheck->setChecked( state );
-  slotDrawHeader( state );
-  state = mConfig->readBoolEntry( "DrawFooter", true );
-  mLayout.footerCheck->setChecked( state );
-  slotDrawFooter( state );
-
-  mLayout.headerCombo[0]->setCurrentItem(
-    headerTextIndex( mConfig->readEntry("HeaderLeft","DateTime")));
-  mLayout.headerCombo[1]->setCurrentItem(
-    headerTextIndex( mConfig->readEntry("HeaderCenter")));
-  mLayout.headerCombo[2]->setCurrentItem(
-    headerTextIndex( mConfig->readEntry("HeaderRight","FileName")));
-  mLayout.headerCombo[3]->setCurrentItem(
-    headerLineIndex( mConfig->readEntry("HeaderLine","SingleLine")));
-
-  mLayout.footerCombo[0]->setCurrentItem(
-    headerTextIndex( mConfig->readEntry("FooterLeft")));
-  mLayout.footerCombo[1]->setCurrentItem(
-    headerTextIndex( mConfig->readEntry("FooterCenter","PageNumber")));
-  mLayout.footerCombo[2]->setCurrentItem(
-    headerTextIndex( mConfig->readEntry("FooterRight")));
-  mLayout.footerCombo[3]->setCurrentItem(
-    headerLineIndex( mConfig->readEntry("FooterLine","SingleLine")));
-
-}
-
-
-void LayoutDialogPage::writeConfiguration( void )
-{
-  if( mConfig == 0 )
-  {
-    return;
-  }
-
-  mConfig->setGroup( "PageLayout" );
-  mConfig->writeEntry( "MarginTop", mLayout.marginSpin[0]->value() );
-  mConfig->writeEntry( "MarginBottom", mLayout.marginSpin[1]->value() );
-  mConfig->writeEntry( "MarginLeft", mLayout.marginSpin[2]->value() );
-  mConfig->writeEntry( "MarginRight", mLayout.marginSpin[3]->value() );
-  mConfig->writeEntry( "DrawHeader", mLayout.headerCheck->isChecked() );
-  mConfig->writeEntry( "DrawFooter", mLayout.footerCheck->isChecked() );
-
-  mConfig->writeEntry( "HeaderLeft",
-    headerText( mLayout.headerCombo[0]->currentItem() ) );
-  mConfig->writeEntry( "HeaderCenter",
-    headerText( mLayout.headerCombo[1]->currentItem() ) );
-  mConfig->writeEntry( "HeaderRight",
-    headerText( mLayout.headerCombo[2]->currentItem() ) );
-  mConfig->writeEntry( "HeaderLine",
-    headerLine( mLayout.headerCombo[3]->currentItem() ) );
-
-  mConfig->writeEntry( "FooterLeft",
-    headerText( mLayout.footerCombo[0]->currentItem() ) );
-  mConfig->writeEntry( "FooterCenter",
-    headerText( mLayout.footerCombo[1]->currentItem() ) );
-  mConfig->writeEntry( "FooterRight",
-    headerText( mLayout.footerCombo[2]->currentItem() ) );
-  mConfig->writeEntry( "FooterLine",
-    headerLine( mLayout.footerCombo[3]->currentItem() ) );
-
-  mConfig->sync();
-}
-
-
-TQString LayoutDialogPage::headerText( uint index )
-{
-  static const TQString text[4] = {"None","DateTime","PageNumber","FileName"};
-  return( text[ index > 3 ? 0 : index ] );
-}
-
-
-int LayoutDialogPage::headerTextIndex( const TQString & headerText )
-{
-  static const TQString text[4] = {"None","DateTime","PageNumber","FileName"};
-  if( headerText != 0 )
-  {
-    for( int i=0; i<4; i++ )
-    {
-      if( headerText == text[i] ) { return( i ); }
-    }
-  }
-  return( 0 );
-}
-
-
-TQString LayoutDialogPage::headerLine( uint index )
-{
-  static const TQString text[3] = {"None","SingleLine","Rectangle"};
-  return( text[ index > 2 ? 0 : index ] );
-}
-
-
-int LayoutDialogPage::headerLineIndex( const TQString & headerLine )
-{
-  static const TQString text[3] = {"None","SingleLine","Rectangle"};
-  if( headerLine != 0 )
-  {
-    for( int i=0; i<3; i++ )
-    {
-      if( headerLine == text[i] ) { return( i ); }
-    }
-  }
-  return( 0 );
-}
-
-
-void LayoutDialogPage::slotDrawHeader( bool state )
-{
-  for( int i=0; i<4; i++ )
-  {
-    mLayout.headerLabel[i]->setEnabled( state );
-    mLayout.headerCombo[i]->setEnabled( state );
-  }
-}
-
-
-void LayoutDialogPage::slotDrawFooter( bool state )
-{
-  for( int i=0; i<4; i++ )
-  {
-    mLayout.footerLabel[i]->setEnabled( state );
-    mLayout.footerCombo[i]->setEnabled( state );
-  }
-}
-
-
-void LayoutDialogPage::getOptions( TQMap<TQString,TQString>& opts, bool /*incldef*/ )
-{
-   opts[ "kde-khexedit-topmarginmm" ]    = TQString::number( mLayout.marginSpin[0]->value() );
-   opts[ "kde-khexedit-bottommarginmm" ] = TQString::number( mLayout.marginSpin[1]->value() );
-   opts[ "kde-khexedit-leftmarginmm" ]   = TQString::number( mLayout.marginSpin[2]->value() );
-   opts[ "kde-khexedit-rightmarginmm" ]  = TQString::number( mLayout.marginSpin[3]->value() );
-
-   opts[ "kde-khexedit-headercheck" ]  = (mLayout.headerCheck->isChecked() ? "true" : "false");
-   opts[ "kde-khexedit-headercombo0" ] = TQString::number( mLayout.headerCombo[0]->currentItem() );
-   opts[ "kde-khexedit-headercombo1" ] = TQString::number( mLayout.headerCombo[1]->currentItem() );
-   opts[ "kde-khexedit-headercombo2" ] = TQString::number( mLayout.headerCombo[2]->currentItem() );
-   opts[ "kde-khexedit-headercombo3" ] = TQString::number( mLayout.headerCombo[3]->currentItem() );
-
-   opts[ "kde-khexedit-footercheck" ]  = (mLayout.footerCheck->isChecked() ? "true" : "false");
-   opts[ "kde-khexedit-footercombo0" ] = TQString::number( mLayout.footerCombo[0]->currentItem() );
-   opts[ "kde-khexedit-footercombo1" ] = TQString::number( mLayout.footerCombo[1]->currentItem() );
-   opts[ "kde-khexedit-footercombo2" ] = TQString::number( mLayout.footerCombo[2]->currentItem() );
-   opts[ "kde-khexedit-footercombo3" ] = TQString::number( mLayout.footerCombo[3]->currentItem() );
-}
-
-
-#include "printdialogpage.moc"
diff --git a/khexedit/printdialogpage.cpp b/khexedit/printdialogpage.cpp
new file mode 100644
index 00000000..d421880f
--- /dev/null
+++ b/khexedit/printdialogpage.cpp
@@ -0,0 +1,386 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <tqlayout.h>
+#include <tqbuttongroup.h>
+#include <tqspinbox.h>
+#include <tqlabel.h>
+#include <tqcheckbox.h>
+#include <tqstringlist.h>
+#include <tqcombobox.h>
+
+#include <tdelocale.h>
+
+
+#include "printdialogpage.h"
+
+LayoutDialogPage::LayoutDialogPage( TQWidget *parent, const char *name )
+ : KPrintDialogPage( parent, name )
+{
+  mConfig = 0;
+  setTitle( i18n( "Page Layout" ) );
+  setupLayoutPage();
+
+  readConfiguration();
+}
+
+
+LayoutDialogPage::~LayoutDialogPage( void )
+{
+  writeConfiguration();
+  
+  delete mConfig; mConfig = 0;
+}
+
+
+void LayoutDialogPage::setupLayoutPage( void )
+{
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, 6 /*KDialog::mSpacingSize*/ );
+  if( topLayout == 0 ) { return; }
+
+  text = i18n("Margins [millimeter]");
+  TQButtonGroup *group = new TQButtonGroup( text, this );
+  if( group == 0 ) { return; }
+  topLayout->addWidget( group );
+
+  TQGridLayout *gbox = new TQGridLayout( group, 3, 6, 6 /*KDialog::mSpacingSize*/ );
+  if( gbox == 0 ) { return; }
+  gbox->addRowSpacing( 0, group->fontMetrics().height() );
+  gbox->setColStretch( 5, 10 );
+
+  TQString name[4];
+  int i;
+
+  name[0] = i18n("&Top:");
+  name[1] = i18n("&Bottom:");
+  name[2] = i18n("&Left:");
+  name[3] = i18n("&Right:");
+
+  for( i=0; i<4; i++ )
+  {
+    mLayout.marginSpin[i] = new TQSpinBox( group );
+    mLayout.marginSpin[i]->setFixedHeight(
+      mLayout.marginSpin[i]->sizeHint().height() );
+    mLayout.marginSpin[i]->setMinimumWidth(
+      mLayout.marginSpin[i]->fontMetrics().width("M")*10 );
+    mLayout.marginSpin[i]->setRange( 0, INT_MAX );
+
+    TQLabel *label = new TQLabel( mLayout.marginSpin[i], name[i], group );
+    label->setFixedHeight( mLayout.marginSpin[i]->sizeHint().height() );
+    label->setFixedWidth( label->sizeHint().width() );
+
+    if( i < 2 )
+    {
+      gbox->addWidget( label, i+1, 0, AlignLeft );
+      gbox->addWidget( mLayout.marginSpin[i], i+1, 1, AlignLeft );
+    }
+    else
+    {
+      gbox->addWidget( label, i-1, 3, AlignLeft );
+      gbox->addWidget( mLayout.marginSpin[i], i-1, 4, AlignLeft );
+    }
+  }
+  
+  text = i18n("Draw h&eader above text");
+  mLayout.headerCheck = new TQCheckBox( text, this );
+  mLayout.headerCheck->setFixedSize( mLayout.headerCheck->sizeHint() );
+  connect( mLayout.headerCheck, TQT_SIGNAL( toggled(bool)),
+	   TQT_SLOT( slotDrawHeader(bool)));
+  topLayout->addWidget( mLayout.headerCheck, 0, AlignLeft );
+
+  gbox = new TQGridLayout( 5, 6, 0 );
+  if( gbox == 0 ) { return; }
+  topLayout->addLayout( gbox );
+
+  gbox->setColStretch ( 5, 10 );
+  gbox->addColSpacing( 1, 6 /*KDialog::mSpacingSize*/ );
+  gbox->addColSpacing( 3, 6 /*KDialog::mSpacingSize*/ );
+  gbox->addRowSpacing( 2, 6 /*KDialog::mSpacingSize*/ );
+
+  name[0] = i18n("Left:");
+  name[1] = i18n("Center:");
+  name[2] = i18n("Right:");
+  name[3] = i18n("Border:");
+
+  TQStringList textList;
+  textList.append(i18n("None"));
+  textList.append(i18n("Date & Time"));
+  textList.append(i18n("Page Number"));
+  textList.append(i18n("Filename"));
+
+  TQStringList lineList;
+  lineList.append(i18n("None"));
+  lineList.append(i18n("Single Line"));
+  lineList.append(i18n("Rectangle"));
+
+  for( i=0; i<4; i++ )
+  {
+    mLayout.headerCombo[i] = new TQComboBox( false, this );
+    mLayout.headerCombo[i]->setFixedHeight(
+      mLayout.headerCombo[i]->sizeHint().height() );
+    mLayout.headerCombo[i]->setMinimumWidth(
+      mLayout.headerCombo[i]->fontMetrics().width("M")*10 );
+ 
+    mLayout.headerLabel[i] = new TQLabel( mLayout.headerCombo[i], name[i],
+					 this );
+    mLayout.headerLabel[i]->setFixedHeight( 
+      mLayout.headerLabel[i]->sizeHint().height() );
+    mLayout.headerLabel[i]->setFixedWidth( 
+      mLayout.headerLabel[i]->sizeHint().width() );
+
+    if( i<3 )
+    {
+      mLayout.headerCombo[i]->insertStringList( textList );
+      gbox->addWidget( mLayout.headerLabel[i], 0, i*2, AlignLeft );
+      gbox->addWidget( mLayout.headerCombo[i], 1, i*2, AlignLeft );
+    }
+    else
+    {
+      mLayout.headerCombo[i]->insertStringList( lineList );
+      gbox->addWidget( mLayout.headerLabel[i], 3, 0, AlignLeft );
+      gbox->addWidget( mLayout.headerCombo[i], 4, 0, AlignLeft );
+    }
+  }
+
+
+  text = i18n("Draw &footer below text");
+  mLayout.footerCheck = new TQCheckBox( text, this );
+  mLayout.footerCheck->setFixedSize( mLayout.footerCheck->sizeHint() );
+  connect( mLayout.footerCheck, TQT_SIGNAL( toggled(bool)),
+	   TQT_SLOT( slotDrawFooter(bool)));
+  topLayout->addWidget( mLayout.footerCheck, 0, AlignLeft );
+
+  gbox = new TQGridLayout( 5, 6, 0 );
+  if( gbox == 0 ) { return; }
+  topLayout->addLayout( gbox );
+
+  gbox->setColStretch ( 5, 10 );
+  gbox->addColSpacing( 1, 6 /*KDialog::mSpacingSize*/ );
+  gbox->addColSpacing( 3, 6 /*KDialog::mSpacingSize*/ );
+  gbox->addRowSpacing( 2, 6 /*KDialog::mSpacingSize*/ );
+
+  for( i=0; i<4; i++ )
+  {
+    mLayout.footerCombo[i] = new TQComboBox( false, this );
+    mLayout.footerCombo[i]->setFixedHeight(
+      mLayout.footerCombo[i]->sizeHint().height() );
+    mLayout.footerCombo[i]->setMinimumWidth(
+      mLayout.footerCombo[i]->fontMetrics().width("M")*10 );
+
+    mLayout.footerLabel[i] = new TQLabel( mLayout.footerCombo[i], name[i], 
+					 this );
+    mLayout.footerLabel[i]->setFixedHeight( 
+      mLayout.footerLabel[i]->sizeHint().height() );
+    mLayout.footerLabel[i]->setFixedWidth( 
+      mLayout.footerLabel[i]->sizeHint().width() );
+
+    if( i<3 )
+    {
+      mLayout.footerCombo[i]->insertStringList( textList );
+      gbox->addWidget( mLayout.footerLabel[i], 0, i*2, AlignLeft );
+      gbox->addWidget( mLayout.footerCombo[i], 1, i*2, AlignLeft );
+    }
+    else
+    {
+      mLayout.footerCombo[i]->insertStringList( lineList );
+      gbox->addWidget( mLayout.footerLabel[i], 3, 0, AlignLeft );
+      gbox->addWidget( mLayout.footerCombo[i], 4, 0, AlignLeft );
+    }
+  }
+
+  for( i=0; i<4; i++ )
+  {
+    mLayout.marginSpin[i]->setValue( 15 );
+  }
+  mLayout.headerCheck->setChecked( true );
+  slotDrawHeader( true );
+  mLayout.footerCheck->setChecked( true );
+  slotDrawFooter( true );
+
+  topLayout->addStretch(10);
+}
+
+
+void LayoutDialogPage::readConfiguration( void )
+{
+  if( mConfig != 0 ) { return; }
+
+  mConfig = new KSimpleConfig( TQString("hexprinter") );
+  if( mConfig == 0 ) { return; }
+
+  mConfig->setGroup( "PageLayout" );
+  int val = mConfig->readNumEntry( "MarginTop", 15 );
+  mLayout.marginSpin[0]->setValue( val );
+  val = mConfig->readNumEntry( "MarginBottom", 15 );
+  mLayout.marginSpin[1]->setValue( val );
+  val = mConfig->readNumEntry( "MarginLeft", 15 );
+  mLayout.marginSpin[2]->setValue( val );
+  val = mConfig->readNumEntry( "MarginRight", 15 );
+  mLayout.marginSpin[3]->setValue( val );
+  bool state = mConfig->readBoolEntry( "DrawHeader", true );
+  mLayout.headerCheck->setChecked( state );
+  slotDrawHeader( state );
+  state = mConfig->readBoolEntry( "DrawFooter", true );
+  mLayout.footerCheck->setChecked( state );
+  slotDrawFooter( state );
+
+  mLayout.headerCombo[0]->setCurrentItem(
+    headerTextIndex( mConfig->readEntry("HeaderLeft","DateTime")));
+  mLayout.headerCombo[1]->setCurrentItem(
+    headerTextIndex( mConfig->readEntry("HeaderCenter")));
+  mLayout.headerCombo[2]->setCurrentItem(
+    headerTextIndex( mConfig->readEntry("HeaderRight","FileName")));
+  mLayout.headerCombo[3]->setCurrentItem(
+    headerLineIndex( mConfig->readEntry("HeaderLine","SingleLine")));
+
+  mLayout.footerCombo[0]->setCurrentItem(
+    headerTextIndex( mConfig->readEntry("FooterLeft")));
+  mLayout.footerCombo[1]->setCurrentItem(
+    headerTextIndex( mConfig->readEntry("FooterCenter","PageNumber")));
+  mLayout.footerCombo[2]->setCurrentItem(
+    headerTextIndex( mConfig->readEntry("FooterRight")));
+  mLayout.footerCombo[3]->setCurrentItem(
+    headerLineIndex( mConfig->readEntry("FooterLine","SingleLine")));
+
+}
+
+
+void LayoutDialogPage::writeConfiguration( void )
+{
+  if( mConfig == 0 )
+  {
+    return;
+  }
+
+  mConfig->setGroup( "PageLayout" );
+  mConfig->writeEntry( "MarginTop", mLayout.marginSpin[0]->value() );
+  mConfig->writeEntry( "MarginBottom", mLayout.marginSpin[1]->value() );
+  mConfig->writeEntry( "MarginLeft", mLayout.marginSpin[2]->value() );
+  mConfig->writeEntry( "MarginRight", mLayout.marginSpin[3]->value() );
+  mConfig->writeEntry( "DrawHeader", mLayout.headerCheck->isChecked() );
+  mConfig->writeEntry( "DrawFooter", mLayout.footerCheck->isChecked() );
+
+  mConfig->writeEntry( "HeaderLeft",
+    headerText( mLayout.headerCombo[0]->currentItem() ) );
+  mConfig->writeEntry( "HeaderCenter",
+    headerText( mLayout.headerCombo[1]->currentItem() ) );
+  mConfig->writeEntry( "HeaderRight",
+    headerText( mLayout.headerCombo[2]->currentItem() ) );
+  mConfig->writeEntry( "HeaderLine",
+    headerLine( mLayout.headerCombo[3]->currentItem() ) );
+
+  mConfig->writeEntry( "FooterLeft",
+    headerText( mLayout.footerCombo[0]->currentItem() ) );
+  mConfig->writeEntry( "FooterCenter",
+    headerText( mLayout.footerCombo[1]->currentItem() ) );
+  mConfig->writeEntry( "FooterRight",
+    headerText( mLayout.footerCombo[2]->currentItem() ) );
+  mConfig->writeEntry( "FooterLine",
+    headerLine( mLayout.footerCombo[3]->currentItem() ) );
+
+  mConfig->sync();
+}
+
+
+TQString LayoutDialogPage::headerText( uint index )
+{
+  static const TQString text[4] = {"None","DateTime","PageNumber","FileName"};
+  return( text[ index > 3 ? 0 : index ] );
+}
+
+
+int LayoutDialogPage::headerTextIndex( const TQString & headerText )
+{
+  static const TQString text[4] = {"None","DateTime","PageNumber","FileName"};
+  if( headerText != 0 )
+  {
+    for( int i=0; i<4; i++ )
+    {
+      if( headerText == text[i] ) { return( i ); }
+    }
+  }
+  return( 0 );
+}
+
+
+TQString LayoutDialogPage::headerLine( uint index )
+{
+  static const TQString text[3] = {"None","SingleLine","Rectangle"};
+  return( text[ index > 2 ? 0 : index ] );
+}
+
+
+int LayoutDialogPage::headerLineIndex( const TQString & headerLine )
+{
+  static const TQString text[3] = {"None","SingleLine","Rectangle"};
+  if( headerLine != 0 )
+  {
+    for( int i=0; i<3; i++ )
+    {
+      if( headerLine == text[i] ) { return( i ); }
+    }
+  }
+  return( 0 );
+}
+
+
+void LayoutDialogPage::slotDrawHeader( bool state )
+{
+  for( int i=0; i<4; i++ )
+  {
+    mLayout.headerLabel[i]->setEnabled( state );
+    mLayout.headerCombo[i]->setEnabled( state );
+  }
+}
+
+
+void LayoutDialogPage::slotDrawFooter( bool state )
+{
+  for( int i=0; i<4; i++ )
+  {
+    mLayout.footerLabel[i]->setEnabled( state );
+    mLayout.footerCombo[i]->setEnabled( state );
+  }
+}
+
+
+void LayoutDialogPage::getOptions( TQMap<TQString,TQString>& opts, bool /*incldef*/ )
+{
+   opts[ "kde-khexedit-topmarginmm" ]    = TQString::number( mLayout.marginSpin[0]->value() );
+   opts[ "kde-khexedit-bottommarginmm" ] = TQString::number( mLayout.marginSpin[1]->value() );
+   opts[ "kde-khexedit-leftmarginmm" ]   = TQString::number( mLayout.marginSpin[2]->value() );
+   opts[ "kde-khexedit-rightmarginmm" ]  = TQString::number( mLayout.marginSpin[3]->value() );
+
+   opts[ "kde-khexedit-headercheck" ]  = (mLayout.headerCheck->isChecked() ? "true" : "false");
+   opts[ "kde-khexedit-headercombo0" ] = TQString::number( mLayout.headerCombo[0]->currentItem() );
+   opts[ "kde-khexedit-headercombo1" ] = TQString::number( mLayout.headerCombo[1]->currentItem() );
+   opts[ "kde-khexedit-headercombo2" ] = TQString::number( mLayout.headerCombo[2]->currentItem() );
+   opts[ "kde-khexedit-headercombo3" ] = TQString::number( mLayout.headerCombo[3]->currentItem() );
+
+   opts[ "kde-khexedit-footercheck" ]  = (mLayout.footerCheck->isChecked() ? "true" : "false");
+   opts[ "kde-khexedit-footercombo0" ] = TQString::number( mLayout.footerCombo[0]->currentItem() );
+   opts[ "kde-khexedit-footercombo1" ] = TQString::number( mLayout.footerCombo[1]->currentItem() );
+   opts[ "kde-khexedit-footercombo2" ] = TQString::number( mLayout.footerCombo[2]->currentItem() );
+   opts[ "kde-khexedit-footercombo3" ] = TQString::number( mLayout.footerCombo[3]->currentItem() );
+}
+
+
+#include "printdialogpage.moc"
diff --git a/khexedit/searchbar.cc b/khexedit/searchbar.cc
deleted file mode 100644
index 02fbb4ef..00000000
--- a/khexedit/searchbar.cc
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-
-#include <tdelocale.h>
-
-#include "dialog.h"
-#include "hexvalidator.h"
-#include "searchbar.h"
-#include <tqpushbutton.h>
-
-// crappy X11 headers
-#undef KeyPress
-
-static const char * close_xpm[] = {
-"16 16 3 1",
-"       s None  c None",
-".      c #ffffff",
-"X      c #707070",
-"                ",
-"                ",
-"  .X        .X  ",
-"  .XX      .XX  ",
-"   .XX    .XX   ",
-"    .XX  .XX    ",
-"     .XX.XX     ",
-"      .XXX      ",
-"      .XXX      ",
-"     .XX.XX     ",
-"    .XX  .XX    ",
-"   .XX    .XX   ",
-"  .XX      .XX  ",
-"  .X        .X  ",
-"                ",
-"                "};
-
-CSearchBar::CSearchBar( TQWidget *parent, const char *name, WFlags f )
-  :TQFrame( parent, name, f )
-{
-  setFrameStyle( TQFrame::Panel | TQFrame::Raised );
-  setLineWidth( 1 );
-
-  mTypeCombo = new TQComboBox( this );
-  connect( mTypeCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(selectorChanged(int)) );
-  TQStringList list;
-  list << i18n("Hex") << i18n("Dec") << i18n("Oct") << i18n("Bin")
-       << i18n("Txt");
-  mTypeCombo->insertStringList( list );
-
-  mInputEdit = new TQLineEdit( this );
-  connect( mInputEdit, TQT_SIGNAL(textChanged(const TQString&)),
-	   TQT_SLOT(textChanged(const TQString&)) );
-  mValidator = new CHexValidator( this, CHexValidator::regularText );
-  mInputEdit->setValidator( mValidator );
-
-  mFindButton = new TQPushButton( i18n("Find"), this );
-  mFindButton->setAutoDefault(false);
-  connect( mFindButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(start()) );
-  connect(mInputEdit,TQT_SIGNAL(returnPressed()),mFindButton,TQT_SLOT(animateClick()));
-  mFindButton->setFixedHeight( mTypeCombo->sizeHint().height() );
-
-  mBackwards = new TQCheckBox( i18n("Backwards"), this );
-  mIgnoreCase = new TQCheckBox( i18n("Ignore case"), this );
-
-  mCloseButton = new TQPushButton( this );
-  mCloseButton->setAutoDefault(false);
-  mCloseButton->setPixmap( TQPixmap( close_xpm ) );
-  connect( mCloseButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(hideWidget()) );
-
-  //
-  // Make layout
-  //
-  TQHBoxLayout *hlay = new TQHBoxLayout( this, 4, 6 );
-  hlay->addWidget( mTypeCombo );
-  hlay->addWidget( mInputEdit );
-  hlay->addWidget( mFindButton );
-  hlay->addWidget( mBackwards );
-  hlay->addWidget( mIgnoreCase );
-  hlay->addWidget( mCloseButton );
-
-  //
-  // Read below why I do this.
-  //
-  mInputEdit->installEventFilter( this );
-  selectorChanged(0);
-}
-
-
-//
-// Espen 2000-04-21
-// TQt 2.1: Seems like the TQLineEdit::returnPressed() does not work when
-// I install a validator. So I catch the event manually
-//
-bool CSearchBar::eventFilter( TQObject *o, TQEvent *e )
-{
-  if( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(mInputEdit) && e->type() == TQEvent::KeyPress )
-  {
-    TQKeyEvent *ke = (TQKeyEvent*)e;
-    if( ke->key() == Key_Return )
-    {
-      mFindButton->animateClick();
-      return true;
-    }
-  }
-  return TQFrame::eventFilter( o, e );
-}
-
-//
-// Seach for te first item each time the curso has moved. Note: The cursor
-// will move when we search and get a match, but (in start() below) the
-// mSearchMode is set to Find_Next after this slot has been called so it
-// will work.
-//
-void CSearchBar::cursorMoved()
-{
-  mSearchMode = Find_First;
-}
-
-
-void CSearchBar::selectorChanged( int index )
-{
-  mValidator->setState( (CHexValidator::EState)index );
-  mInputEdit->setText( mFindString[ index ] );
-  mIgnoreCase->setEnabled( index == 4 ? true : false );
-  mSearchMode = Find_First;
-}
-
-
-void CSearchBar::textChanged( const TQString &text )
-{
-  mFindString[ mTypeCombo->currentItem() ] = text;
-  mValidator->convert( mFindData, mFindString[ mTypeCombo->currentItem() ] );
-  mSearchMode = Find_First;
-}
-
-
-void CSearchBar::hideWidget()
-{
-  hide();
-  emit hidden();
-}
-
-
-void CSearchBar::start( void )
-{
-  if( mFindData.isEmpty() == true )
-  {
-    showEntryFailure( this, TQString("") );
-    return;
-  }
-
-  SSearchControl sc;
-  sc.key = mFindData;
-  sc.keyType = mTypeCombo->currentItem();
-  sc.fromCursor = true;
-  sc.inSelection = false;
-  sc.forward = !mBackwards->isChecked();
-  sc.ignoreCase = mIgnoreCase->isEnabled() && mIgnoreCase->isChecked();
-  emit findData( sc, mSearchMode, false );
-  mSearchMode = Find_Next;
-}
-
-
-void CSearchBar::showEvent( TQShowEvent *e )
-{
-  TQFrame::showEvent(e);
-  mInputEdit->setFocus();
-}
-
-
-#include "searchbar.moc"
diff --git a/khexedit/searchbar.cpp b/khexedit/searchbar.cpp
new file mode 100644
index 00000000..02fbb4ef
--- /dev/null
+++ b/khexedit/searchbar.cpp
@@ -0,0 +1,188 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+
+#include <tdelocale.h>
+
+#include "dialog.h"
+#include "hexvalidator.h"
+#include "searchbar.h"
+#include <tqpushbutton.h>
+
+// crappy X11 headers
+#undef KeyPress
+
+static const char * close_xpm[] = {
+"16 16 3 1",
+"       s None  c None",
+".      c #ffffff",
+"X      c #707070",
+"                ",
+"                ",
+"  .X        .X  ",
+"  .XX      .XX  ",
+"   .XX    .XX   ",
+"    .XX  .XX    ",
+"     .XX.XX     ",
+"      .XXX      ",
+"      .XXX      ",
+"     .XX.XX     ",
+"    .XX  .XX    ",
+"   .XX    .XX   ",
+"  .XX      .XX  ",
+"  .X        .X  ",
+"                ",
+"                "};
+
+CSearchBar::CSearchBar( TQWidget *parent, const char *name, WFlags f )
+  :TQFrame( parent, name, f )
+{
+  setFrameStyle( TQFrame::Panel | TQFrame::Raised );
+  setLineWidth( 1 );
+
+  mTypeCombo = new TQComboBox( this );
+  connect( mTypeCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(selectorChanged(int)) );
+  TQStringList list;
+  list << i18n("Hex") << i18n("Dec") << i18n("Oct") << i18n("Bin")
+       << i18n("Txt");
+  mTypeCombo->insertStringList( list );
+
+  mInputEdit = new TQLineEdit( this );
+  connect( mInputEdit, TQT_SIGNAL(textChanged(const TQString&)),
+	   TQT_SLOT(textChanged(const TQString&)) );
+  mValidator = new CHexValidator( this, CHexValidator::regularText );
+  mInputEdit->setValidator( mValidator );
+
+  mFindButton = new TQPushButton( i18n("Find"), this );
+  mFindButton->setAutoDefault(false);
+  connect( mFindButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(start()) );
+  connect(mInputEdit,TQT_SIGNAL(returnPressed()),mFindButton,TQT_SLOT(animateClick()));
+  mFindButton->setFixedHeight( mTypeCombo->sizeHint().height() );
+
+  mBackwards = new TQCheckBox( i18n("Backwards"), this );
+  mIgnoreCase = new TQCheckBox( i18n("Ignore case"), this );
+
+  mCloseButton = new TQPushButton( this );
+  mCloseButton->setAutoDefault(false);
+  mCloseButton->setPixmap( TQPixmap( close_xpm ) );
+  connect( mCloseButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(hideWidget()) );
+
+  //
+  // Make layout
+  //
+  TQHBoxLayout *hlay = new TQHBoxLayout( this, 4, 6 );
+  hlay->addWidget( mTypeCombo );
+  hlay->addWidget( mInputEdit );
+  hlay->addWidget( mFindButton );
+  hlay->addWidget( mBackwards );
+  hlay->addWidget( mIgnoreCase );
+  hlay->addWidget( mCloseButton );
+
+  //
+  // Read below why I do this.
+  //
+  mInputEdit->installEventFilter( this );
+  selectorChanged(0);
+}
+
+
+//
+// Espen 2000-04-21
+// TQt 2.1: Seems like the TQLineEdit::returnPressed() does not work when
+// I install a validator. So I catch the event manually
+//
+bool CSearchBar::eventFilter( TQObject *o, TQEvent *e )
+{
+  if( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(mInputEdit) && e->type() == TQEvent::KeyPress )
+  {
+    TQKeyEvent *ke = (TQKeyEvent*)e;
+    if( ke->key() == Key_Return )
+    {
+      mFindButton->animateClick();
+      return true;
+    }
+  }
+  return TQFrame::eventFilter( o, e );
+}
+
+//
+// Seach for te first item each time the curso has moved. Note: The cursor
+// will move when we search and get a match, but (in start() below) the
+// mSearchMode is set to Find_Next after this slot has been called so it
+// will work.
+//
+void CSearchBar::cursorMoved()
+{
+  mSearchMode = Find_First;
+}
+
+
+void CSearchBar::selectorChanged( int index )
+{
+  mValidator->setState( (CHexValidator::EState)index );
+  mInputEdit->setText( mFindString[ index ] );
+  mIgnoreCase->setEnabled( index == 4 ? true : false );
+  mSearchMode = Find_First;
+}
+
+
+void CSearchBar::textChanged( const TQString &text )
+{
+  mFindString[ mTypeCombo->currentItem() ] = text;
+  mValidator->convert( mFindData, mFindString[ mTypeCombo->currentItem() ] );
+  mSearchMode = Find_First;
+}
+
+
+void CSearchBar::hideWidget()
+{
+  hide();
+  emit hidden();
+}
+
+
+void CSearchBar::start( void )
+{
+  if( mFindData.isEmpty() == true )
+  {
+    showEntryFailure( this, TQString("") );
+    return;
+  }
+
+  SSearchControl sc;
+  sc.key = mFindData;
+  sc.keyType = mTypeCombo->currentItem();
+  sc.fromCursor = true;
+  sc.inSelection = false;
+  sc.forward = !mBackwards->isChecked();
+  sc.ignoreCase = mIgnoreCase->isEnabled() && mIgnoreCase->isChecked();
+  emit findData( sc, mSearchMode, false );
+  mSearchMode = Find_Next;
+}
+
+
+void CSearchBar::showEvent( TQShowEvent *e )
+{
+  TQFrame::showEvent(e);
+  mInputEdit->setFocus();
+}
+
+
+#include "searchbar.moc"
diff --git a/khexedit/statusbarprogress.cc b/khexedit/statusbarprogress.cc
deleted file mode 100644
index 6ed24e31..00000000
--- a/khexedit/statusbarprogress.cc
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999  Espen Sand, espensa@online.no
- *   This file is based on the work by Martynas Kunigelis (KProgress)
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include "statusbarprogress.h"
-
-#include <tqpainter.h>
-
-#include <tdeapplication.h>
-#include <tdeglobalsettings.h>
-#include <tdelocale.h>
-#include <tqstyle.h>
-
-CStatusBarProgress::CStatusBarProgress( TQWidget *parent, const char *name )
-  : TQFrame(parent, name), TQRangeControl(0, 100, 1, 10, 0),
-    mOrientation(Horizontal )
-{
-  initialize();
-}
-
-CStatusBarProgress::CStatusBarProgress( Orientation orientation,
-					TQWidget *parent, const char *name )
-  : TQFrame(parent, name), TQRangeControl(0, 100, 1, 10, 0),
-    mOrientation( orientation )
-{
-  initialize();
-}
-
-CStatusBarProgress::CStatusBarProgress( int minValue, int maxValue, int value,
-					Orientation orientation,
-					TQWidget *parent, const char *name )
-  : TQFrame(parent, name), TQRangeControl(minValue, maxValue, 1, 10, value),
-    mOrientation(orientation)
-{
-  initialize();
-}
-
-CStatusBarProgress::~CStatusBarProgress()
-{
-  delete mBarPixmap;
-}
-
-void CStatusBarProgress::advance( int offset )
-{
-  setValue(value() + offset);
-}
-
-void CStatusBarProgress::initialize( void )
-{
-  mBarPixmap    = 0;
-  mBarStyle     = Solid;
-
-  mBarColor     = palette().active().highlight();
-  mBarTextColor = palette().active().highlightedText();
-  mTextColor    = palette().active().text();
-  setBackgroundColor( palette().active().background() );
-
-  TQFont font( TDEGlobalSettings::generalFont() );
-  font.setBold( true );
-  setFont( font );
-
-  mTextEnabled = false;
-  adjustStyle();
-}
-
-
-void CStatusBarProgress::setBarPixmap( const TQPixmap &pixmap )
-{
-  if( pixmap.isNull() == true )
-  {
-    return;
-  }
-
-  delete mBarPixmap;
-  mBarPixmap = new TQPixmap( pixmap );
-}
-
-void CStatusBarProgress::setBarColor( const TQColor &color )
-{
-  mBarColor = color;
-  delete mBarPixmap;
-  mBarPixmap = 0;
-}
-
-void CStatusBarProgress::setBarStyle( BarStyle style )
-{
-  if( mBarStyle != style )
-  {
-    mBarStyle = style;
-    update();
-  }
-}
-
-void CStatusBarProgress::setOrientation( Orientation orientation )
-{
-  if( mOrientation != orientation )
-  {
-    mOrientation = orientation;
-    update();
-  }
-}
-
-void CStatusBarProgress::setValue(int value)
-{
-  mCurPage = mMaxPage = -1;
-  TQRangeControl::setValue(value);
-}
-
-void CStatusBarProgress::setValue( int curPage, int maxPage )
-{
-  if( curPage <= 0 || maxPage <= 0 || curPage > maxPage )
-  {
-    mCurPage = mMaxPage = -1;
-    TQRangeControl::setValue(0);
-  }
-  else
-  {
-    mCurPage = curPage;
-    mMaxPage = maxPage;
-    float fraction = (float)curPage/(float)maxPage;
-    TQRangeControl::setValue( (int)(fraction*100.0) );
-  }
-}
-
-
-void CStatusBarProgress::setTextEnabled( bool state )
-{
-  if( mTextEnabled != state )
-  {
-    mTextEnabled = state;
-    update();
-  }
-}
-
-void CStatusBarProgress::setText( const TQString &msg )
-{
-  mMsg = msg;
-  if( mTextEnabled == true )
-  {
-    update();
-  }
-}
-
-
-
-
-const TQColor & CStatusBarProgress::barColor( void ) const
-{
-  return( mBarColor );
-}
-
-const TQPixmap * CStatusBarProgress::barPixmap( void ) const
-{
-  return( mBarPixmap );
-}
-
-bool CStatusBarProgress::textEnabled( void ) const
-{
-  return( mTextEnabled );
-}
-
-TQSize CStatusBarProgress::sizeHint( void ) const
-{
-  TQSize s( size() );
-
-  if( orientation() == CStatusBarProgress::Vertical )
-  {
-    s.setWidth( fontMetrics().lineSpacing() );
-  }
-  else
-  {
-    s.setHeight( fontMetrics().lineSpacing() );
-  }
-
-  return( s );
-}
-
-
-CStatusBarProgress::Orientation CStatusBarProgress::orientation( void ) const
-{
-  return( mOrientation );
-}
-
-CStatusBarProgress::BarStyle CStatusBarProgress::barStyle() const
-{
-  return( mBarStyle );
-}
-
-int CStatusBarProgress::recalcValue(int range)
-{
-  int abs_value = value() - minValue();
-  int abs_range = maxValue() - minValue();
-  return range * abs_value / abs_range;
-}
-
-void CStatusBarProgress::valueChange()
-{
-  repaint(contentsRect(), FALSE);
-  emit percentageChanged(recalcValue(100));
-}
-
-void CStatusBarProgress::rangeChange()
-{
-  repaint(contentsRect(), FALSE);
-  emit percentageChanged(recalcValue(100));
-}
-
-void CStatusBarProgress::styleChange( GUIStyle )
-{
-  adjustStyle();
-}
-
-void CStatusBarProgress::adjustStyle( void )
-{
-  switch( style().SH_GUIStyle)
-  {
-    case WindowsStyle:
-      setFrameStyle( TQFrame::NoFrame );
-    break;
-
-    case MotifStyle:
-    default:
-      setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
-      setLineWidth( 1 );
-    break;
-  }
-  update();
-}
-
-void CStatusBarProgress::paletteChange( const TQPalette & )
-{
-  mBarColor     = palette().active().highlight();
-  mBarTextColor = palette().active().highlightedText();
-  mTextColor    = palette().active().text();
-  setBackgroundColor( palette().active().background() );
-}
-
-void CStatusBarProgress::drawText( TQPainter *p )
-{
-  TQRect r(contentsRect());
-  TQString s;
-
-  if( mMsg.isEmpty() == true )
-  {
-    s = TQString("%1%").arg(recalcValue(100));
-  }
-  else
-  {
-    if( mCurPage > 0 )
-    {
-      s = i18n("%1... %2 of %3").arg(mMsg).arg(mCurPage).arg(mMaxPage);
-    }
-    else
-    {
-      s = i18n("%1... %2%").arg(mMsg).arg(recalcValue(100));
-    }
-  }
-
-  p->setPen( mTextColor );
-  p->drawText( r, AlignCenter, s );
-  p->setClipRegion( fr );
-  p->setPen( mBarTextColor );
-  p->drawText( r, AlignCenter, s );
-}
-
-void CStatusBarProgress::drawContents(TQPainter *p)
-{
-  TQRect cr = contentsRect(), er = cr;
-  fr = cr;
-  TQBrush fb(mBarColor), eb(backgroundColor() );
-
-  if( mBarPixmap != 0 )
-  {
-    fb.setPixmap( *mBarPixmap );
-  }
-
-  if (backgroundPixmap())
-    eb.setPixmap(*backgroundPixmap());
-
-  switch( mBarStyle )
-  {
-    case Solid:
-      if( mOrientation ==Qt::Horizontal )
-      {
-	fr.setWidth(recalcValue(cr.width()));
-	er.setLeft(fr.right() + 1);
-      }
-      else
-      {
-	fr.setTop(cr.bottom() - recalcValue(cr.height()));
-	er.setBottom(fr.top() - 1);
-      }
-
-      p->setBrushOrigin(cr.topLeft());
-      p->fillRect(fr, fb);
-      p->fillRect(er, eb);
-
-      if( mTextEnabled == true )
-	drawText(p);
-    break;
-
-    case Blocked:
-      const int margin = 2;
-      int max, num, dx, dy;
-      if( mOrientation ==Qt::Horizontal )
-      {
-	fr.setHeight(cr.height() - 2 * margin);
-	fr.setWidth((int)(0.67 * fr.height()));
-	fr.moveTopLeft(TQPoint(cr.left() + margin, cr.top() + margin));
-	dx = fr.width() + margin;
-	dy = 0;
-	max = (cr.width() - margin) / (fr.width() + margin) + 1;
-	num = recalcValue(max);
-      }
-      else
-      {
-	fr.setWidth(cr.width() - 2 * margin);
-	fr.setHeight((int)(0.67 * fr.width()));
-	fr.moveBottomLeft(TQPoint(cr.left() + margin, cr.bottom() - margin));
-	dx = 0;
-	dy = - (fr.height() + margin);
-	max = (cr.height() - margin) / (fr.height() + margin) + 1;
-	num = recalcValue(max);
-      }
-      p->setClipRect(cr.x() + margin, cr.y() + margin,
-		     cr.width() - margin, cr.height() - margin);
-      for (int i = 0; i < num; i++)
-      {
-	p->setBrushOrigin(fr.topLeft());
-	p->fillRect(fr, fb);
-	fr.moveBy(dx, dy);
-      }
-
-      if (num != max)
-      {
-	if( mOrientation ==Qt::Horizontal )
-	  er.setLeft(fr.right() + 1);
-	else
-	  er.setBottom(fr.bottom() + 1);
-	if (!er.isNull())
-	{
-	  p->setBrushOrigin(cr.topLeft());
-	  p->fillRect(er, eb);
-	}
-      }
-    break;
-  }
-
-}
-
-
-void CStatusBarProgress::mousePressEvent( TQMouseEvent */*e*/ )
-{
-  emit pressed();
-}
-
-#include "statusbarprogress.moc"
diff --git a/khexedit/statusbarprogress.cpp b/khexedit/statusbarprogress.cpp
new file mode 100644
index 00000000..6ed24e31
--- /dev/null
+++ b/khexedit/statusbarprogress.cpp
@@ -0,0 +1,374 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999  Espen Sand, espensa@online.no
+ *   This file is based on the work by Martynas Kunigelis (KProgress)
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include "statusbarprogress.h"
+
+#include <tqpainter.h>
+
+#include <tdeapplication.h>
+#include <tdeglobalsettings.h>
+#include <tdelocale.h>
+#include <tqstyle.h>
+
+CStatusBarProgress::CStatusBarProgress( TQWidget *parent, const char *name )
+  : TQFrame(parent, name), TQRangeControl(0, 100, 1, 10, 0),
+    mOrientation(Horizontal )
+{
+  initialize();
+}
+
+CStatusBarProgress::CStatusBarProgress( Orientation orientation,
+					TQWidget *parent, const char *name )
+  : TQFrame(parent, name), TQRangeControl(0, 100, 1, 10, 0),
+    mOrientation( orientation )
+{
+  initialize();
+}
+
+CStatusBarProgress::CStatusBarProgress( int minValue, int maxValue, int value,
+					Orientation orientation,
+					TQWidget *parent, const char *name )
+  : TQFrame(parent, name), TQRangeControl(minValue, maxValue, 1, 10, value),
+    mOrientation(orientation)
+{
+  initialize();
+}
+
+CStatusBarProgress::~CStatusBarProgress()
+{
+  delete mBarPixmap;
+}
+
+void CStatusBarProgress::advance( int offset )
+{
+  setValue(value() + offset);
+}
+
+void CStatusBarProgress::initialize( void )
+{
+  mBarPixmap    = 0;
+  mBarStyle     = Solid;
+
+  mBarColor     = palette().active().highlight();
+  mBarTextColor = palette().active().highlightedText();
+  mTextColor    = palette().active().text();
+  setBackgroundColor( palette().active().background() );
+
+  TQFont font( TDEGlobalSettings::generalFont() );
+  font.setBold( true );
+  setFont( font );
+
+  mTextEnabled = false;
+  adjustStyle();
+}
+
+
+void CStatusBarProgress::setBarPixmap( const TQPixmap &pixmap )
+{
+  if( pixmap.isNull() == true )
+  {
+    return;
+  }
+
+  delete mBarPixmap;
+  mBarPixmap = new TQPixmap( pixmap );
+}
+
+void CStatusBarProgress::setBarColor( const TQColor &color )
+{
+  mBarColor = color;
+  delete mBarPixmap;
+  mBarPixmap = 0;
+}
+
+void CStatusBarProgress::setBarStyle( BarStyle style )
+{
+  if( mBarStyle != style )
+  {
+    mBarStyle = style;
+    update();
+  }
+}
+
+void CStatusBarProgress::setOrientation( Orientation orientation )
+{
+  if( mOrientation != orientation )
+  {
+    mOrientation = orientation;
+    update();
+  }
+}
+
+void CStatusBarProgress::setValue(int value)
+{
+  mCurPage = mMaxPage = -1;
+  TQRangeControl::setValue(value);
+}
+
+void CStatusBarProgress::setValue( int curPage, int maxPage )
+{
+  if( curPage <= 0 || maxPage <= 0 || curPage > maxPage )
+  {
+    mCurPage = mMaxPage = -1;
+    TQRangeControl::setValue(0);
+  }
+  else
+  {
+    mCurPage = curPage;
+    mMaxPage = maxPage;
+    float fraction = (float)curPage/(float)maxPage;
+    TQRangeControl::setValue( (int)(fraction*100.0) );
+  }
+}
+
+
+void CStatusBarProgress::setTextEnabled( bool state )
+{
+  if( mTextEnabled != state )
+  {
+    mTextEnabled = state;
+    update();
+  }
+}
+
+void CStatusBarProgress::setText( const TQString &msg )
+{
+  mMsg = msg;
+  if( mTextEnabled == true )
+  {
+    update();
+  }
+}
+
+
+
+
+const TQColor & CStatusBarProgress::barColor( void ) const
+{
+  return( mBarColor );
+}
+
+const TQPixmap * CStatusBarProgress::barPixmap( void ) const
+{
+  return( mBarPixmap );
+}
+
+bool CStatusBarProgress::textEnabled( void ) const
+{
+  return( mTextEnabled );
+}
+
+TQSize CStatusBarProgress::sizeHint( void ) const
+{
+  TQSize s( size() );
+
+  if( orientation() == CStatusBarProgress::Vertical )
+  {
+    s.setWidth( fontMetrics().lineSpacing() );
+  }
+  else
+  {
+    s.setHeight( fontMetrics().lineSpacing() );
+  }
+
+  return( s );
+}
+
+
+CStatusBarProgress::Orientation CStatusBarProgress::orientation( void ) const
+{
+  return( mOrientation );
+}
+
+CStatusBarProgress::BarStyle CStatusBarProgress::barStyle() const
+{
+  return( mBarStyle );
+}
+
+int CStatusBarProgress::recalcValue(int range)
+{
+  int abs_value = value() - minValue();
+  int abs_range = maxValue() - minValue();
+  return range * abs_value / abs_range;
+}
+
+void CStatusBarProgress::valueChange()
+{
+  repaint(contentsRect(), FALSE);
+  emit percentageChanged(recalcValue(100));
+}
+
+void CStatusBarProgress::rangeChange()
+{
+  repaint(contentsRect(), FALSE);
+  emit percentageChanged(recalcValue(100));
+}
+
+void CStatusBarProgress::styleChange( GUIStyle )
+{
+  adjustStyle();
+}
+
+void CStatusBarProgress::adjustStyle( void )
+{
+  switch( style().SH_GUIStyle)
+  {
+    case WindowsStyle:
+      setFrameStyle( TQFrame::NoFrame );
+    break;
+
+    case MotifStyle:
+    default:
+      setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
+      setLineWidth( 1 );
+    break;
+  }
+  update();
+}
+
+void CStatusBarProgress::paletteChange( const TQPalette & )
+{
+  mBarColor     = palette().active().highlight();
+  mBarTextColor = palette().active().highlightedText();
+  mTextColor    = palette().active().text();
+  setBackgroundColor( palette().active().background() );
+}
+
+void CStatusBarProgress::drawText( TQPainter *p )
+{
+  TQRect r(contentsRect());
+  TQString s;
+
+  if( mMsg.isEmpty() == true )
+  {
+    s = TQString("%1%").arg(recalcValue(100));
+  }
+  else
+  {
+    if( mCurPage > 0 )
+    {
+      s = i18n("%1... %2 of %3").arg(mMsg).arg(mCurPage).arg(mMaxPage);
+    }
+    else
+    {
+      s = i18n("%1... %2%").arg(mMsg).arg(recalcValue(100));
+    }
+  }
+
+  p->setPen( mTextColor );
+  p->drawText( r, AlignCenter, s );
+  p->setClipRegion( fr );
+  p->setPen( mBarTextColor );
+  p->drawText( r, AlignCenter, s );
+}
+
+void CStatusBarProgress::drawContents(TQPainter *p)
+{
+  TQRect cr = contentsRect(), er = cr;
+  fr = cr;
+  TQBrush fb(mBarColor), eb(backgroundColor() );
+
+  if( mBarPixmap != 0 )
+  {
+    fb.setPixmap( *mBarPixmap );
+  }
+
+  if (backgroundPixmap())
+    eb.setPixmap(*backgroundPixmap());
+
+  switch( mBarStyle )
+  {
+    case Solid:
+      if( mOrientation ==Qt::Horizontal )
+      {
+	fr.setWidth(recalcValue(cr.width()));
+	er.setLeft(fr.right() + 1);
+      }
+      else
+      {
+	fr.setTop(cr.bottom() - recalcValue(cr.height()));
+	er.setBottom(fr.top() - 1);
+      }
+
+      p->setBrushOrigin(cr.topLeft());
+      p->fillRect(fr, fb);
+      p->fillRect(er, eb);
+
+      if( mTextEnabled == true )
+	drawText(p);
+    break;
+
+    case Blocked:
+      const int margin = 2;
+      int max, num, dx, dy;
+      if( mOrientation ==Qt::Horizontal )
+      {
+	fr.setHeight(cr.height() - 2 * margin);
+	fr.setWidth((int)(0.67 * fr.height()));
+	fr.moveTopLeft(TQPoint(cr.left() + margin, cr.top() + margin));
+	dx = fr.width() + margin;
+	dy = 0;
+	max = (cr.width() - margin) / (fr.width() + margin) + 1;
+	num = recalcValue(max);
+      }
+      else
+      {
+	fr.setWidth(cr.width() - 2 * margin);
+	fr.setHeight((int)(0.67 * fr.width()));
+	fr.moveBottomLeft(TQPoint(cr.left() + margin, cr.bottom() - margin));
+	dx = 0;
+	dy = - (fr.height() + margin);
+	max = (cr.height() - margin) / (fr.height() + margin) + 1;
+	num = recalcValue(max);
+      }
+      p->setClipRect(cr.x() + margin, cr.y() + margin,
+		     cr.width() - margin, cr.height() - margin);
+      for (int i = 0; i < num; i++)
+      {
+	p->setBrushOrigin(fr.topLeft());
+	p->fillRect(fr, fb);
+	fr.moveBy(dx, dy);
+      }
+
+      if (num != max)
+      {
+	if( mOrientation ==Qt::Horizontal )
+	  er.setLeft(fr.right() + 1);
+	else
+	  er.setBottom(fr.bottom() + 1);
+	if (!er.isNull())
+	{
+	  p->setBrushOrigin(cr.topLeft());
+	  p->fillRect(er, eb);
+	}
+      }
+    break;
+  }
+
+}
+
+
+void CStatusBarProgress::mousePressEvent( TQMouseEvent */*e*/ )
+{
+  emit pressed();
+}
+
+#include "statusbarprogress.moc"
diff --git a/khexedit/stringdialog.cc b/khexedit/stringdialog.cc
deleted file mode 100644
index f1c79f40..00000000
--- a/khexedit/stringdialog.cc
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#include <tqcheckbox.h>
-#include <tqlabel.h>
-#include <tqlayout.h>
-#include <tqlineedit.h>
-#include <tqspinbox.h>
-
-#include <tdeconfig.h>
-#include <tdeglobalsettings.h>
-#include <tdelocale.h>
-#include <tdemessagebox.h>
-
-#include "listview.h"
-#include "stringdialog.h"
-#include <tqpushbutton.h>
-
-
-CStringDialog::CStringDialog( TQWidget *parent, const char *name, bool modal )
-  : KDialogBase( Plain, i18n("Extract Strings"), Help|User1|Cancel, User1,
-		 parent, name, modal, true, i18n("&Update") ),
-  mMaxLength(0), mBusy(false), mDirty(false)
-{
-  setHelp( "khexedit/khexedit.html", TQString() );
-
-  TQString text;
-  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
-
-  TQGridLayout *glay = new TQGridLayout( 3, 3, spacingHint() );
-  topLayout->addLayout( glay );
-  glay->setColStretch( 1, 10 );
-
-  mLengthSpin = new TQSpinBox( plainPage() );
-  mLengthSpin->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mLengthSpin->setRange( 1, 1000000 );
-  mLengthSpin->setValue( 4 );
-  glay->addMultiCellWidget( mLengthSpin, 0, 0, 1, 2 );
-
-  text = i18n("&Minimum length:");
-  TQLabel *label = new TQLabel( mLengthSpin, text, plainPage() );
-  glay->addWidget( label, 0, 0, AlignRight );
-
-  mFilter = new TQLineEdit( plainPage() );
-  mFilter->setMinimumWidth( fontMetrics().maxWidth()*17 );
-  mFilter->setText("*");
-  glay->addWidget( mFilter, 1, 1 );
-
-  text = i18n("&Filter:");
-  label = new TQLabel( mFilter, text, plainPage() );
-  glay->addWidget( label, 1, 0, AlignRight );
-
-  TQPushButton *useButton = new TQPushButton( plainPage(), "use" );
-  useButton->setText( i18n("&Use") );
-  useButton->setAutoDefault( false );
-  connect( useButton, TQT_SIGNAL(clicked()),this,TQT_SLOT(slotUser1()) );
-  glay->addWidget( useButton, 1, 2 );
-
-  TQWidget *helper = new TQWidget( plainPage() );
-  glay->addMultiCellWidget( helper, 2, 2, 1, 2 );
-  TQHBoxLayout *hlay = new TQHBoxLayout( helper, 0, spacingHint() );
-
-  text = i18n("&Ignore case");
-  mIgnoreCaseCheck = new TQCheckBox( text, helper );
-  hlay->addWidget( mIgnoreCaseCheck );
-
-  text = i18n("Show offset as &decimal");
-  mOffsetDecimalCheck = new TQCheckBox( text, helper );
-  hlay->addWidget( mOffsetDecimalCheck );
-
-  hlay->addStretch(10);
-
-  //
-  // Using listview as suggested by Dima Rogozin <dima@mercury.co.il>
-  //
-  mStringList = new CListView( plainPage(), "stringList" );
-  mStringList->setFont( TDEGlobalSettings::fixedFont() );
-  mStringList->addColumn( i18n("Offset") );
-  mStringList->addColumn( i18n("String") );
-  mStringList->setAllColumnsShowFocus( true );
-  mStringList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
-
-  connect( mStringList, TQT_SIGNAL(selectionChanged()),
-	   TQT_SLOT(selectionChanged()));
-  topLayout->addWidget( mStringList, 10 );
-
-  hlay = new TQHBoxLayout( topLayout );
-
-  text = i18n("Number of strings:");
-  label = new TQLabel( text, plainPage() );
-  hlay->addWidget( label, AlignLeft );
-
-  mListSizeLabel = new TQLabel( TQString(), plainPage() );
-  mListSizeLabel->setFixedWidth( fontMetrics().maxWidth()*10 );
-  hlay->addWidget( mListSizeLabel, AlignLeft|AlignHCenter );
-
-  text = i18n("Displayed:");
-  label = new TQLabel( text, plainPage() );
-  hlay->addWidget( label, AlignLeft );
-
-  mDisplaySizeLabel = new TQLabel( TQString(""), plainPage() );
-  mDisplaySizeLabel->setFixedWidth( fontMetrics().maxWidth()*10 );
-  hlay->addWidget( mDisplaySizeLabel, AlignLeft|AlignHCenter);
-
-  hlay->addStretch( 10 );
-
-  mDirtyLabel = new TQLabel( plainPage() );
-  topLayout->addWidget( mDirtyLabel );
-
-  readConfiguration();
-
-  //
-  // The initial width of the columns are set in updateListInfo()
-  //
-  updateListInfo();
-  mStringList->setVisibleItem( 15 );
-  startTimer(100);
-}
-
-
-CStringDialog::~CStringDialog( void )
-{
-  writeConfiguration();
-}
-
-
-void CStringDialog::showEvent( TQShowEvent *e )
-{
-  KDialogBase::showEvent(e);
-  mLengthSpin->setFocus();
-}
-
-
-void CStringDialog::readConfiguration( void )
-{
-  TDEConfig &config = *kapp->config();
-  config.setGroup( "String Dialog" );
-
-  mLengthSpin->setValue( config.readNumEntry("MinimumLength", 4)  );
-  mFilter->setText( config.readEntry("FilterText", "*") );
-  mIgnoreCaseCheck->setChecked( config.readBoolEntry("IgnoreCase", false) );
-  mOffsetDecimalCheck->setChecked(
-    config.readBoolEntry("OffsetAsDecimal", false ) );
-}
-
-
-void CStringDialog::writeConfiguration( void )
-{
-  TDEConfig &config = *kapp->config();
-  config.setGroup( "String Dialog" );
-
-  config.writeEntry( "MinimumLength", mLengthSpin->value() );
-  config.writeEntry( "FilterText", mFilter->text() );
-  config.writeEntry( "IgnoreCase", mIgnoreCaseCheck->isChecked() );
-  config.writeEntry( "OffsetAsDecimal", mOffsetDecimalCheck->isChecked() );
-  config.sync();
-}
-
-
-void CStringDialog::slotUser1( void ) // Start
-{
-  if( mBusy == true )
-  {
-    return;
-  }
-
-  mRegExp.setCaseSensitive( mIgnoreCaseCheck->isChecked() == false );
-  mRegExp.setWildcard( true );
-  if( mFilter->text().isEmpty() == true )
-  {
-    mRegExp.setPattern("*");
-  }
-  else
-  {
-    mRegExp.setPattern(mFilter->text());
-  }
-
-  if( mRegExp.isValid() == false )
-  {
-    TQString msg = i18n(""
-      "The filter expression you have specified is illegal. "
-      "You must specify a valid regular expression.\n"
-      "Continue without filter?");
-    int reply = KMessageBox::warningContinueCancel( this, msg, i18n("Extract Strings"));
-    if( reply != KMessageBox::Continue )
-    {
-      return;
-    }
-    mRegExp.setPattern( "*");
-  }
-
-
-  mStringData.minLength     = mLengthSpin->value();
-  mStringData.decimalOffset = mOffsetDecimalCheck->isChecked();
-
-  removeList();
-
-  mBusy = true;
-  emit collect();
-  mBusy = false;
-}
-
-
-void CStringDialog::startGoto( TQListViewItem *item )
-{
-  TQString str_offset = item->text(0);
-  TQString string = item->text(1);
-
-  uint offset;
-  if( stringData().decimalOffset == true )
-  {
-    // sscanf( str_offset.ascii(), "%u", &offset );
-    offset = str_offset.toInt();
-  }
-  else
-  {
-    uint val1,val2;
-    // #### Rewrite it do it doesn't need the .ascii() call
-    sscanf( str_offset.ascii(), "%X:%X", &val1, &val2 );
-    offset = (val1<<16) + val2;
-  }
-
-  uint size = string.length();
-
-  emit markText( offset, size, true );
-}
-
-
-void CStringDialog::setDirty( void )
-{
-  if( mDirty == true )
-  {
-    return;
-  }
-
-  mDirtyLabel->setText(
-    i18n("Warning: Document has been modified since last update"));
-  mDirty = true;
-}
-
-
-void CStringDialog::setClean( void )
-{
-  if( mDirty == false )
-  {
-    return;
-  }
-
-  mDirtyLabel->setText("");
-  mDirty = false;
-}
-
-
-void CStringDialog::selectionChanged()
-{
-  TQT_TQOBJECT(this)->killTimers();
-  startTimer( 200 );
-}
-
-
-void CStringDialog::timerEvent( TQTimerEvent * )
-{
-  TQT_TQOBJECT(this)->killTimers();
-
-  TQListViewItem *item = mStringList->currentItem();
-  if( item == 0 )
-  {
-    slotUser1();
-    return;
-  }
-  startGoto( item );
-}
-
-
-void CStringDialog::resizeEvent( TQResizeEvent * )
-{
-  setColumnWidth();
-}
-
-
-
-int CStringDialog::updateList( CProgress &p )
-{
-  clearList();
-  enableList( false );
-
-  int offsetLen = stringData().offsetLen();
-
-  TQPtrList<TQString> &list = stringData().list();
-  for( const TQString *str = list.first(); str != 0; str = list.next() )
-  {
-    appendListItem( *str, offsetLen );
-    mMaxLength = TQMAX( mMaxLength, str->length() );
-
-    if( p.expired() == true )
-    {
-      int errCode = p.step( (float)list.at()/(float)list.count() );
-      if( errCode == Err_Stop )
-      {
-	p.finish();
-	return( Err_Success );
-      }
-    }
-  }
-
-  p.finish();
-  updateListInfo();
-  enableList( true );
-
-  return( Err_Success );
-}
-
-
-
-
-void CStringDialog::clearList( void )
-{
-  if( mStringList->childCount() > 0 )
-  {
-    mStringList->clear();
-    mStringList->update();
-  }
-  mMaxLength = 0;
-
-  updateListInfo();
-  setClean();
-}
-
-
-void CStringDialog::removeList( void )
-{
-  mStringData.clear();
-  clearList();
-}
-
-
-void CStringDialog::enableList( bool state )
-{
-  mStringList->setEnabled( state );
-  if( state == true )
-  {
-    mStringList->update();
-  }
-}
-
-
-void CStringDialog::appendListItem( const TQString &str, uint offsetLen )
-{
-  if( mRegExp.search ( str, offsetLen ) != -1 )
-  {
-    new TQListViewItem( mStringList, str.left(offsetLen), str.mid(offsetLen) );
-  }
-}
-
-
-void CStringDialog::updateListInfo( void )
-{
-  mListSizeLabel->setText( TQString("%1").arg(mStringData.count()) );
-  mDisplaySizeLabel->setText( TQString("%1").arg(mStringList->childCount()) );
-  setColumnWidth();
-}
-
-
-
-void CStringDialog::setColumnWidth( void )
-{
-  const TQFontMetrics &fm = mStringList->fontMetrics();
-
-  if( mStringData.count() == 0 )
-  {
-    int w1 = fm.maxWidth() * (stringData().offsetLen() + 2);
-    int w2 = mStringList->viewport()->width() - w1;
-    mStringList->setColumnWidth( 0, w1 );
-    mStringList->setColumnWidth( 1, w2 );
-  }
-  else
-  {
-    int w1  = fm.maxWidth() * (stringData().offsetLen() + 2);
-    int w2  = fm.maxWidth() * mMaxLength - w1;
-    if( w2 < 0 )
-    {
-      w2 = mStringList->viewport()->width() - w1;
-    }
-
-    mStringList->setColumnWidth( 0, w1 );
-    mStringList->setColumnWidth( 1, w2 );
-  }
-}
-
-
-
-
-
-
-#include "stringdialog.moc"
diff --git a/khexedit/stringdialog.cpp b/khexedit/stringdialog.cpp
new file mode 100644
index 00000000..f1c79f40
--- /dev/null
+++ b/khexedit/stringdialog.cpp
@@ -0,0 +1,412 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <tqcheckbox.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqlineedit.h>
+#include <tqspinbox.h>
+
+#include <tdeconfig.h>
+#include <tdeglobalsettings.h>
+#include <tdelocale.h>
+#include <tdemessagebox.h>
+
+#include "listview.h"
+#include "stringdialog.h"
+#include <tqpushbutton.h>
+
+
+CStringDialog::CStringDialog( TQWidget *parent, const char *name, bool modal )
+  : KDialogBase( Plain, i18n("Extract Strings"), Help|User1|Cancel, User1,
+		 parent, name, modal, true, i18n("&Update") ),
+  mMaxLength(0), mBusy(false), mDirty(false)
+{
+  setHelp( "khexedit/khexedit.html", TQString() );
+
+  TQString text;
+  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
+
+  TQGridLayout *glay = new TQGridLayout( 3, 3, spacingHint() );
+  topLayout->addLayout( glay );
+  glay->setColStretch( 1, 10 );
+
+  mLengthSpin = new TQSpinBox( plainPage() );
+  mLengthSpin->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mLengthSpin->setRange( 1, 1000000 );
+  mLengthSpin->setValue( 4 );
+  glay->addMultiCellWidget( mLengthSpin, 0, 0, 1, 2 );
+
+  text = i18n("&Minimum length:");
+  TQLabel *label = new TQLabel( mLengthSpin, text, plainPage() );
+  glay->addWidget( label, 0, 0, AlignRight );
+
+  mFilter = new TQLineEdit( plainPage() );
+  mFilter->setMinimumWidth( fontMetrics().maxWidth()*17 );
+  mFilter->setText("*");
+  glay->addWidget( mFilter, 1, 1 );
+
+  text = i18n("&Filter:");
+  label = new TQLabel( mFilter, text, plainPage() );
+  glay->addWidget( label, 1, 0, AlignRight );
+
+  TQPushButton *useButton = new TQPushButton( plainPage(), "use" );
+  useButton->setText( i18n("&Use") );
+  useButton->setAutoDefault( false );
+  connect( useButton, TQT_SIGNAL(clicked()),this,TQT_SLOT(slotUser1()) );
+  glay->addWidget( useButton, 1, 2 );
+
+  TQWidget *helper = new TQWidget( plainPage() );
+  glay->addMultiCellWidget( helper, 2, 2, 1, 2 );
+  TQHBoxLayout *hlay = new TQHBoxLayout( helper, 0, spacingHint() );
+
+  text = i18n("&Ignore case");
+  mIgnoreCaseCheck = new TQCheckBox( text, helper );
+  hlay->addWidget( mIgnoreCaseCheck );
+
+  text = i18n("Show offset as &decimal");
+  mOffsetDecimalCheck = new TQCheckBox( text, helper );
+  hlay->addWidget( mOffsetDecimalCheck );
+
+  hlay->addStretch(10);
+
+  //
+  // Using listview as suggested by Dima Rogozin <dima@mercury.co.il>
+  //
+  mStringList = new CListView( plainPage(), "stringList" );
+  mStringList->setFont( TDEGlobalSettings::fixedFont() );
+  mStringList->addColumn( i18n("Offset") );
+  mStringList->addColumn( i18n("String") );
+  mStringList->setAllColumnsShowFocus( true );
+  mStringList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
+
+  connect( mStringList, TQT_SIGNAL(selectionChanged()),
+	   TQT_SLOT(selectionChanged()));
+  topLayout->addWidget( mStringList, 10 );
+
+  hlay = new TQHBoxLayout( topLayout );
+
+  text = i18n("Number of strings:");
+  label = new TQLabel( text, plainPage() );
+  hlay->addWidget( label, AlignLeft );
+
+  mListSizeLabel = new TQLabel( TQString(), plainPage() );
+  mListSizeLabel->setFixedWidth( fontMetrics().maxWidth()*10 );
+  hlay->addWidget( mListSizeLabel, AlignLeft|AlignHCenter );
+
+  text = i18n("Displayed:");
+  label = new TQLabel( text, plainPage() );
+  hlay->addWidget( label, AlignLeft );
+
+  mDisplaySizeLabel = new TQLabel( TQString(""), plainPage() );
+  mDisplaySizeLabel->setFixedWidth( fontMetrics().maxWidth()*10 );
+  hlay->addWidget( mDisplaySizeLabel, AlignLeft|AlignHCenter);
+
+  hlay->addStretch( 10 );
+
+  mDirtyLabel = new TQLabel( plainPage() );
+  topLayout->addWidget( mDirtyLabel );
+
+  readConfiguration();
+
+  //
+  // The initial width of the columns are set in updateListInfo()
+  //
+  updateListInfo();
+  mStringList->setVisibleItem( 15 );
+  startTimer(100);
+}
+
+
+CStringDialog::~CStringDialog( void )
+{
+  writeConfiguration();
+}
+
+
+void CStringDialog::showEvent( TQShowEvent *e )
+{
+  KDialogBase::showEvent(e);
+  mLengthSpin->setFocus();
+}
+
+
+void CStringDialog::readConfiguration( void )
+{
+  TDEConfig &config = *kapp->config();
+  config.setGroup( "String Dialog" );
+
+  mLengthSpin->setValue( config.readNumEntry("MinimumLength", 4)  );
+  mFilter->setText( config.readEntry("FilterText", "*") );
+  mIgnoreCaseCheck->setChecked( config.readBoolEntry("IgnoreCase", false) );
+  mOffsetDecimalCheck->setChecked(
+    config.readBoolEntry("OffsetAsDecimal", false ) );
+}
+
+
+void CStringDialog::writeConfiguration( void )
+{
+  TDEConfig &config = *kapp->config();
+  config.setGroup( "String Dialog" );
+
+  config.writeEntry( "MinimumLength", mLengthSpin->value() );
+  config.writeEntry( "FilterText", mFilter->text() );
+  config.writeEntry( "IgnoreCase", mIgnoreCaseCheck->isChecked() );
+  config.writeEntry( "OffsetAsDecimal", mOffsetDecimalCheck->isChecked() );
+  config.sync();
+}
+
+
+void CStringDialog::slotUser1( void ) // Start
+{
+  if( mBusy == true )
+  {
+    return;
+  }
+
+  mRegExp.setCaseSensitive( mIgnoreCaseCheck->isChecked() == false );
+  mRegExp.setWildcard( true );
+  if( mFilter->text().isEmpty() == true )
+  {
+    mRegExp.setPattern("*");
+  }
+  else
+  {
+    mRegExp.setPattern(mFilter->text());
+  }
+
+  if( mRegExp.isValid() == false )
+  {
+    TQString msg = i18n(""
+      "The filter expression you have specified is illegal. "
+      "You must specify a valid regular expression.\n"
+      "Continue without filter?");
+    int reply = KMessageBox::warningContinueCancel( this, msg, i18n("Extract Strings"));
+    if( reply != KMessageBox::Continue )
+    {
+      return;
+    }
+    mRegExp.setPattern( "*");
+  }
+
+
+  mStringData.minLength     = mLengthSpin->value();
+  mStringData.decimalOffset = mOffsetDecimalCheck->isChecked();
+
+  removeList();
+
+  mBusy = true;
+  emit collect();
+  mBusy = false;
+}
+
+
+void CStringDialog::startGoto( TQListViewItem *item )
+{
+  TQString str_offset = item->text(0);
+  TQString string = item->text(1);
+
+  uint offset;
+  if( stringData().decimalOffset == true )
+  {
+    // sscanf( str_offset.ascii(), "%u", &offset );
+    offset = str_offset.toInt();
+  }
+  else
+  {
+    uint val1,val2;
+    // #### Rewrite it do it doesn't need the .ascii() call
+    sscanf( str_offset.ascii(), "%X:%X", &val1, &val2 );
+    offset = (val1<<16) + val2;
+  }
+
+  uint size = string.length();
+
+  emit markText( offset, size, true );
+}
+
+
+void CStringDialog::setDirty( void )
+{
+  if( mDirty == true )
+  {
+    return;
+  }
+
+  mDirtyLabel->setText(
+    i18n("Warning: Document has been modified since last update"));
+  mDirty = true;
+}
+
+
+void CStringDialog::setClean( void )
+{
+  if( mDirty == false )
+  {
+    return;
+  }
+
+  mDirtyLabel->setText("");
+  mDirty = false;
+}
+
+
+void CStringDialog::selectionChanged()
+{
+  TQT_TQOBJECT(this)->killTimers();
+  startTimer( 200 );
+}
+
+
+void CStringDialog::timerEvent( TQTimerEvent * )
+{
+  TQT_TQOBJECT(this)->killTimers();
+
+  TQListViewItem *item = mStringList->currentItem();
+  if( item == 0 )
+  {
+    slotUser1();
+    return;
+  }
+  startGoto( item );
+}
+
+
+void CStringDialog::resizeEvent( TQResizeEvent * )
+{
+  setColumnWidth();
+}
+
+
+
+int CStringDialog::updateList( CProgress &p )
+{
+  clearList();
+  enableList( false );
+
+  int offsetLen = stringData().offsetLen();
+
+  TQPtrList<TQString> &list = stringData().list();
+  for( const TQString *str = list.first(); str != 0; str = list.next() )
+  {
+    appendListItem( *str, offsetLen );
+    mMaxLength = TQMAX( mMaxLength, str->length() );
+
+    if( p.expired() == true )
+    {
+      int errCode = p.step( (float)list.at()/(float)list.count() );
+      if( errCode == Err_Stop )
+      {
+	p.finish();
+	return( Err_Success );
+      }
+    }
+  }
+
+  p.finish();
+  updateListInfo();
+  enableList( true );
+
+  return( Err_Success );
+}
+
+
+
+
+void CStringDialog::clearList( void )
+{
+  if( mStringList->childCount() > 0 )
+  {
+    mStringList->clear();
+    mStringList->update();
+  }
+  mMaxLength = 0;
+
+  updateListInfo();
+  setClean();
+}
+
+
+void CStringDialog::removeList( void )
+{
+  mStringData.clear();
+  clearList();
+}
+
+
+void CStringDialog::enableList( bool state )
+{
+  mStringList->setEnabled( state );
+  if( state == true )
+  {
+    mStringList->update();
+  }
+}
+
+
+void CStringDialog::appendListItem( const TQString &str, uint offsetLen )
+{
+  if( mRegExp.search ( str, offsetLen ) != -1 )
+  {
+    new TQListViewItem( mStringList, str.left(offsetLen), str.mid(offsetLen) );
+  }
+}
+
+
+void CStringDialog::updateListInfo( void )
+{
+  mListSizeLabel->setText( TQString("%1").arg(mStringData.count()) );
+  mDisplaySizeLabel->setText( TQString("%1").arg(mStringList->childCount()) );
+  setColumnWidth();
+}
+
+
+
+void CStringDialog::setColumnWidth( void )
+{
+  const TQFontMetrics &fm = mStringList->fontMetrics();
+
+  if( mStringData.count() == 0 )
+  {
+    int w1 = fm.maxWidth() * (stringData().offsetLen() + 2);
+    int w2 = mStringList->viewport()->width() - w1;
+    mStringList->setColumnWidth( 0, w1 );
+    mStringList->setColumnWidth( 1, w2 );
+  }
+  else
+  {
+    int w1  = fm.maxWidth() * (stringData().offsetLen() + 2);
+    int w2  = fm.maxWidth() * mMaxLength - w1;
+    if( w2 < 0 )
+    {
+      w2 = mStringList->viewport()->width() - w1;
+    }
+
+    mStringList->setColumnWidth( 0, w1 );
+    mStringList->setColumnWidth( 1, w2 );
+  }
+}
+
+
+
+
+
+
+#include "stringdialog.moc"
diff --git a/khexedit/toplevel.cc b/khexedit/toplevel.cc
deleted file mode 100644
index c09bef8e..00000000
--- a/khexedit/toplevel.cc
+++ /dev/null
@@ -1,1363 +0,0 @@
-/*
- *   khexedit - Versatile hex editor
- *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-#include <tqptrlist.h>
-#include <tqsignalmapper.h>
-#include <tqtimer.h>
-#include <tqtooltip.h>
-
-#include <tdeaction.h>
-#include <kiconloader.h>
-#include <tdelocale.h>
-#include <tdemessagebox.h>
-#include <kstatusbar.h>
-#include <tdepopupmenu.h>
-#include <kstdaction.h>
-#include <tdetoolbarbutton.h>
-#include <kdebug.h>
-#include <kurl.h>
-#include <kurldrag.h>
-
-#include "dialog.h"
-#include "draglabel.h"
-#include "hexerror.h"
-#include "toplevel.h"
-
-
-TQPtrList<KHexEdit> KHexEdit::mWindowList;
-
-KHexEdit::KHexEdit( void )
-  : TDEMainWindow(0, "toplevel"), mStartupOffset(0),
-  mIsModified(0)
-{
-  mWindowList.append( this );
-
-  //
-  // Create main widget and register it.
-  //
-  mManager = new CHexManagerWidget( this, "manager" );
-  setCentralWidget( mManager );
-
-  //
-  // I use an eventfilter to catch all drag/drop events for the
-  // area outside the editor window. It will only accept KURLDrag.
-  // (The editor window will catch KURLDrag, TQTextDrag and CHexDrag)
-  //
-  installEventFilter( this );
-  setAcceptDrops(true);
-
-  //
-  // Prepare menus and status bar
-  //
-  mAction.bookmarkMapper = new TQSignalMapper(TQT_TQOBJECT(this));
-  connect(mAction.bookmarkMapper, TQT_SIGNAL(mapped(int)), TQT_TQOBJECT(editor()), TQT_SLOT(gotoBookmark(int)));
-  setupActions();
-  setupStatusBar();
-
-  connect( hexView(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( cursorChanged( SCursorState & ) ) );
-  connect( hexView(), TQT_SIGNAL( editMode( CHexBuffer::EEditMode ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( editMode( CHexBuffer::EEditMode ) ) );
-  connect( hexView(), TQT_SIGNAL( encodingChanged( const SEncodeState &)),
-	   TQT_TQOBJECT(this), TQT_SLOT( encodingChanged( const SEncodeState & )) );
-  connect( hexView(), TQT_SIGNAL( textWidth( uint ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( textWidth( uint ) ) );
-  connect( hexView(), TQT_SIGNAL( fileState( SFileState & ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( fileState( SFileState & ) ) );
-  connect( hexView(), TQT_SIGNAL( layoutChanged( const SDisplayLayout & ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( layoutChanged( const SDisplayLayout & ) ) );
-  connect( hexView(), TQT_SIGNAL( inputModeChanged( const SDisplayInputMode & ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( inputModeChanged( const SDisplayInputMode & ) ) );
-  connect( hexView(), TQT_SIGNAL( bookmarkChanged( TQPtrList<SCursorOffset> &)),
-	   TQT_TQOBJECT(this), TQT_SLOT( bookmarkChanged( TQPtrList<SCursorOffset> & ) ) );
-  connect( hexView(), TQT_SIGNAL( fileName( const TQString &, bool ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( fileActive( const TQString &, bool ) ) );
-  connect( hexView(), TQT_SIGNAL( fileRename( const TQString &, const TQString & )),
-	   TQT_TQOBJECT(this), TQT_SLOT( fileRename( const TQString &, const TQString & ) ) );
-  connect( hexView(), TQT_SIGNAL( fileClosed( const TQString & ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( fileClosed( const TQString & ) ) );
-  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( errorLoadFile( const TQString & ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( removeRecentFile( const TQString & ) ) );
-  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( operationChanged( bool ) ),
-	   TQT_TQOBJECT(this), TQT_SLOT( operationChanged( bool ) ) );
-  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( removeRecentFiles() ),
-	   TQT_TQOBJECT(this), TQT_SLOT( removeRecentFiles() ) );
-  connect( mManager, TQT_SIGNAL( conversionClosed() ),
-	   TQT_TQOBJECT(this), TQT_SLOT(conversionClosed()) );
-  connect( mManager, TQT_SIGNAL( searchBarClosed() ),
-	   TQT_TQOBJECT(this), TQT_SLOT(searchBarClosed()) );
-
-  //
-  // Read configuration from file and set the default editor size.
-  // Open files if this is the first toplevel window.
-  //
-  readConfiguration();
-  initialize( mWindowList.count() == 1 ? true : false );
-  setAutoSaveSettings();
-}
-
-
-KHexEdit::~KHexEdit( void )
-{
-  delete mAction.bookmarkMapper;
-  delete mManager;
-}
-
-
-void KHexEdit::setupActions( void )
-{
-  KStdAction::openNew( TQT_TQOBJECT(editor()), TQT_SLOT(newFile()), actionCollection() );
-  KStdAction::open( TQT_TQOBJECT(editor()), TQT_SLOT(open()), actionCollection() );
-  KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()), 
-actionCollection());
-   
-  mAction.insert     = new TDEAction( i18n("&Insert..."), CTRL+Key_I,
-    TQT_TQOBJECT(editor()), TQT_SLOT(insertFile()), actionCollection(), "insert_file" );
-  mAction.openRecent = KStdAction::openRecent( TQT_TQOBJECT(this), TQT_SLOT( slotFileOpenRecent( const KURL& ) ), actionCollection() );
-  mAction.save       = KStdAction::save( TQT_TQOBJECT(editor()), TQT_SLOT(save()), actionCollection() );
-  mAction.saveAs     = KStdAction::saveAs( TQT_TQOBJECT(editor()), TQT_SLOT(saveAs()), actionCollection() );
-  mAction.revert     = KStdAction::revert( TQT_TQOBJECT(editor()), TQT_SLOT(reload()), actionCollection() );
-  //mAction.revert     = KStdAction::revert( TQT_TQOBJECT(this), TQT_SLOT(resizeTest()), actionCollection() );
-
-  mAction.close      = KStdAction::close( TQT_TQOBJECT(editor()), TQT_SLOT(close()), actionCollection() );
-  mAction.print      = KStdAction::print( TQT_TQOBJECT(editor()), TQT_SLOT(print()), actionCollection() );
-  mAction.exportData = new TDEAction( i18n("E&xport..."), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(exportDialog()), actionCollection(), "export" );
-  mAction.cancel     = new TDEAction( i18n("&Cancel Operation"),
-    "process-stop", 0, TQT_TQOBJECT(editor()), TQT_SLOT(stop()), actionCollection(), "cancel" );
-  mAction.readOnly   = new TDEToggleAction( i18n("&Read Only"),
-    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleWriteProtection()),actionCollection(), "read_only" );
-  mAction.resizeLock = new TDEToggleAction( i18n("&Allow Resize"),
-   0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleResizeLock()),actionCollection(), "resize_lock" );
-  mAction.newWindow  = new TDEAction( i18n("N&ew Window"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(newWindow()),actionCollection(), "new_window" );
-  mAction.closeWindow= new TDEAction( i18n("Close &Window"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(closeWindow()),actionCollection(), "close_window" );
-  mAction.quit       = KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(closeProgram()), actionCollection() );
-
-  mAction.undo       = KStdAction::undo(      TQT_TQOBJECT(editor()), TQT_SLOT(undo()), actionCollection() );
-  mAction.redo       = KStdAction::redo(      TQT_TQOBJECT(editor()), TQT_SLOT(redo()), actionCollection() );
-  mAction.cut        = KStdAction::cut(       TQT_TQOBJECT(editor()), TQT_SLOT(cut()), actionCollection() );
-  mAction.copy       = KStdAction::copy(      TQT_TQOBJECT(editor()), TQT_SLOT(copy()), actionCollection() );
-  mAction.paste      = KStdAction::paste(     TQT_TQOBJECT(editor()), TQT_SLOT(paste()), actionCollection() );
-  mAction.selectAll  = KStdAction::selectAll( TQT_TQOBJECT(editor()), TQT_SLOT(selectAll()),actionCollection() );
-  mAction.unselect   = KStdAction::deselect(  TQT_TQOBJECT(editor()), TQT_SLOT(unselect()), actionCollection());
-  mAction.find     = KStdAction::find(      TQT_TQOBJECT(editor()), TQT_SLOT(find()), actionCollection() );
-  mAction.findNext   = KStdAction::findNext(  TQT_TQOBJECT(editor()), TQT_SLOT(findNext()), actionCollection() );
-  mAction.findPrev   = KStdAction::findPrev(  TQT_TQOBJECT(editor()),TQT_SLOT(findPrevious()),actionCollection() );
-  mAction.replace  = KStdAction::replace(   TQT_TQOBJECT(editor()), TQT_SLOT(replace()), actionCollection() );
-  mAction.gotoOffset = new TDEAction( i18n("&Goto Offset..."), CTRL+Key_G,
-    TQT_TQOBJECT(editor()), TQT_SLOT(gotoOffset()),actionCollection(), "goto_offset" );
-  mAction.insertPattern = new TDEAction( i18n("&Insert Pattern..."), CTRL+Key_Insert,
-    TQT_TQOBJECT(editor()), TQT_SLOT(insertPattern()), actionCollection(), "insert_pattern" );
-
-  mAction.copyAsText = new TDEAction( i18n("Copy as &Text"), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(copyText()), actionCollection(), "copy_as_text" );
-  mAction.pasteToNewFile = new TDEAction( i18n("Paste into New &File"), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(pasteNewFile()), actionCollection(), "paste_into_new_file" );
-  mAction.pasteToNewWindow = new TDEAction( i18n("Paste into New &Window"), 0,
-    TQT_TQOBJECT(this), TQT_SLOT(pasteNewWindow()), actionCollection(), "paste_into_new_window" );
-
-  mAction.hexadecimal = new TDERadioAction( i18n("&Hexadecimal"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_hex" );
-  mAction.decimal     = new TDERadioAction( i18n("&Decimal"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_dec" );
-  mAction.octal       = new TDERadioAction( i18n("&Octal"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_oct" );
-  mAction.binary      = new TDERadioAction( i18n("&Binary"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_bin" );
-  mAction.textOnly    = new TDERadioAction( i18n("&Text"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_text" );
-  mAction.hexadecimal->setExclusiveGroup( "displayMode" );
-  mAction.decimal->setExclusiveGroup( "displayMode" );
-  mAction.octal->setExclusiveGroup( "displayMode" );
-  mAction.binary->setExclusiveGroup( "displayMode" );
-  mAction.textOnly->setExclusiveGroup( "displayMode" );
-
-  mAction.showOffsetColumn = new TDEToggleAction( i18n("Show O&ffset Column"),
-    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleOffsetColumnVisibility()),actionCollection(), "show_offset_column" );
-  mAction.showTextColumn = new TDEToggleAction( i18n("Show Te&xt Field"),
-    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleTextColumnVisibility()),actionCollection(), "show_text_field" );
-  mAction.offsetAsDecimal = new TDEToggleAction( i18n("Off&set as Decimal"),
-    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleOffsetAsDecimal()),actionCollection(), "offset_as_decimal" );
-  mAction.dataUppercase = new TDEToggleAction( i18n("&Upper Case (Data)"),
-    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleDataUppercase()),actionCollection(), "upper_case_data" );
-  mAction.offsetUppercase = new TDEToggleAction( i18n("Upper &Case (Offset)"),
-    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleOffsetUppercase()),actionCollection(), "upper_case_offset" );
-
-  mAction.defaultEncoding = new TDERadioAction( i18n("&Default encoding", "&Default"),
-    0, TQT_TQOBJECT(this), TQT_SLOT( setEncoding()), actionCollection(), "enc_default" );
-  mAction.usAsciiEncoding = new TDERadioAction( i18n("US-&ASCII (7 bit)"),
-    0, TQT_TQOBJECT(this), TQT_SLOT( setEncoding()), actionCollection(), "enc_ascii");
-  mAction.ebcdicEncoding  = new TDERadioAction( i18n("&EBCDIC"),
-    0, TQT_TQOBJECT(this), TQT_SLOT( setEncoding()), actionCollection(), "enc_ebcdic" );
-//   mAction.customEncoding  = new TDEAction( i18n("&Custom..."),
-//     0, TQT_TQOBJECT(editor()), TQT_SLOT( encoding()), actionCollection(), "enc_custom" );
-  mAction.defaultEncoding->setExclusiveGroup( "encodingMode" );
-  mAction.usAsciiEncoding->setExclusiveGroup( "encodingMode" );
-  mAction.ebcdicEncoding->setExclusiveGroup( "encodingMode" );
-
-  mAction.strings = new TDEAction( i18n("&Extract Strings..."), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(strings()), actionCollection(), "extract_strings" );
-//   mAction.recordViewer = new TDEAction( i18n("&Record Viewer"), 0,
-//     TQT_TQOBJECT(editor()), TQT_SLOT(recordView()), actionCollection(), "record_viewer" );
-  mAction.filter = new TDEAction( i18n("&Binary Filter..."), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(filter()), actionCollection(), "binary_filter" );
-  mAction.characterTable = new TDEAction( i18n("&Character Table"), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(chart()), actionCollection(), "char_table" );
-  mAction.converter = new TDEAction( i18n("C&onverter"), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(converter()), actionCollection(), "converter" );
-  mAction.statistics = new TDEAction( i18n("&Statistics"), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(statistics()), actionCollection(), "statistics" );
-
-  mAction.addBookmark = KStdAction::addBookmark( TQT_TQOBJECT(editor()),
-    TQT_SLOT(addBookmark()), actionCollection() );
-  mAction.replaceBookmark = new TDEAction( i18n("&Replace Bookmark"), CTRL+Key_E,
-    TQT_TQOBJECT(editor()), TQT_SLOT(replaceBookmark()), actionCollection(), "replace_bookmark");
-  mAction.removeBookmark = new TDEAction( i18n("R&emove Bookmark"), CTRL+Key_U,
-    TQT_TQOBJECT(editor()), TQT_SLOT(removeBookmark()), actionCollection(), "remove_bookmark" );
-  mAction.removeAllBookmark = new TDEAction( i18n("Re&move All"), 0,
-    TQT_TQOBJECT(editor()), TQT_SLOT(removeAllBookmark()), actionCollection(), "remove_all_bookmarks" );
-  mAction.nextBookmark = new TDEAction( i18n("Goto &Next Bookmark"),
-				      ALT+Key_Down, TQT_TQOBJECT(editor()),
-				      TQT_SLOT(gotoNextBookmark()), actionCollection(), "next_bookmark" );
-  mAction.prevBookmark = new TDEAction( i18n("Goto &Previous Bookmark"),
-				      ALT+Key_Up, TQT_TQOBJECT(editor()),
-				      TQT_SLOT(gotoPrevBookmark()), actionCollection(), "prev_bookmark" );
-
-  createStandardStatusBarAction();
-  setStandardToolBarMenuEnabled(true);
-  mAction.showFullPath  = new TDEToggleAction( i18n("Show F&ull Path"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showFullPath()), actionCollection(), "show_full_path" );
-
-  mAction.tabHide = new TDERadioAction( i18n("&Hide"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showDocumentTabs()), actionCollection(), "doctab_hide" );
-  mAction.tabShowAboveEditor = new TDERadioAction( i18n("&Above Editor"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showDocumentTabs()), actionCollection(), "doctab_above" );
-  mAction.tabShowBelowEditor = new TDERadioAction( i18n("&Below Editor"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showDocumentTabs()), actionCollection(), "doctab_below" );
-  mAction.tabHide->setExclusiveGroup( "editorTab" );
-  mAction.tabShowAboveEditor->setExclusiveGroup( "editorTab" );
-  mAction.tabShowBelowEditor->setExclusiveGroup( "editorTab" );
-
-  mAction.conversionHide  = new TDERadioAction( i18n("&Hide"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showConversionField()), actionCollection(), "conversion_field_hide");
-  mAction.conversionFloat = new TDERadioAction( i18n("&Floating"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showConversionField()), actionCollection(), "conversion_field_float");
-  mAction.conversionEmbed = new TDERadioAction( i18n("&Embed in Main Window"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showConversionField()), actionCollection(), "conversion_field_embed");
-  mAction.conversionHide->setExclusiveGroup( "conversionField" );
-  mAction.conversionFloat->setExclusiveGroup( "conversionField" );
-  mAction.conversionEmbed->setExclusiveGroup( "conversionField" );
-
-  mAction.searchHide = new TDERadioAction( i18n("&Hide"),
-    0, TQT_TQOBJECT(this), TQT_SLOT(showSearchBar()), actionCollection(), "searchbar_hide" );
-  mAction.searchShowAboveEditor = new TDERadioAction( i18n("&Above Editor"),
-    Key_F5, TQT_TQOBJECT(this), TQT_SLOT(showSearchBar()), actionCollection(), "searchbar_above" );
-  mAction.searchShowBelowEditor = new TDERadioAction( i18n("&Below Editor"),
-    Key_F6, TQT_TQOBJECT(this), TQT_SLOT(showSearchBar()), actionCollection(), "searchbar_below" );
-  mAction.searchHide->setExclusiveGroup( "searchBar" );
-  mAction.searchShowAboveEditor->setExclusiveGroup( "searchBar" );
-  mAction.searchShowBelowEditor->setExclusiveGroup( "searchBar" );
-
-  KStdAction::saveOptions(TQT_TQOBJECT(this), TQT_SLOT(writeConfiguration()), actionCollection());
-  KStdAction::preferences(TQT_TQOBJECT(editor()) ,TQT_SLOT(options()),actionCollection() );
-//   mAction.favorites = new TDEAction( i18n("P&rofiles..."), 0,
-//     TQT_TQOBJECT(editor()), TQT_SLOT(favorites()), actionCollection(), "favorites" );
-
-  KStdAction::help( TQT_TQOBJECT(this), TQT_SLOT(appHelpActivated()), actionCollection() );
-
-  mDragLabel = new CDragLabel(this);
-  mDragLabel->setPixmap( UserIcon( "hexdrag" ) );
-  mDragLabel->setDragMask( UserIcon( "hexmask" ) );
-  mDragLabel->setEnabled( false ); // Enabled once we open a document
-  TQToolTip::add( mDragLabel, i18n("Drag document") );
- (void) new KWidgetAction(mDragLabel, i18n("Drag Document"), 0, TQT_TQOBJECT(editor()), TQT_SLOT(options()), actionCollection(), "drag_document");
-
-  createGUI("khexeditui.rc", false);
-
-  TQPopupMenu *popup = (TQPopupMenu *)factory()->container("editor_popup", this);
-  hexView()->setPopupMenu( popup );
-
-  int id = 100;
-  toolBar(0)->insertButton( MainBarIcon("system-lock-screen"), id, TQT_SIGNAL(clicked()),
-    TQT_TQOBJECT(editor()), TQT_SLOT(toggleWriteProtection()), true,
-    i18n("Toggle write protection") );
-  toolBar(0)->alignItemRight( id );
-  mWriteProtectButton = toolBar(0)->getButton(id);
-
-  TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
-  hexView()->setDocumentMenu(documentMenu);
-  connect(documentMenu, TQT_SIGNAL(activated(int)), TQT_SLOT(documentMenuCB(int)));
-
-}
-
-
-void KHexEdit::setupStatusBar( void )
-{
-  CStatusBarProgress *progess = new CStatusBarProgress( statusBar() );
-  statusBar()->addWidget( progess, 10 );
-  connect( progess, TQT_SIGNAL(pressed()), TQT_TQOBJECT(editor()), TQT_SLOT(stop()) );
-  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( setProgress( int ) ),
-	   progess, TQT_SLOT( setValue( int ) ) );
-  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( setProgress( int, int ) ),
-	   progess, TQT_SLOT( setValue( int, int ) ) );
-  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( enableProgressText( bool ) ),
-	   progess, TQT_SLOT( setTextEnabled( bool ) ) );
-  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( setProgressText( const TQString & ) ),
-	   progess, TQT_SLOT( setText( const TQString & ) ) );
-
-  statusBar()->insertFixedItem( i18n("Selection: 0000:0000 0000:0000"),
-				status_Selection );
-  statusBar()->insertFixedItem( i18n("M"), status_Modified );
-  statusBar()->insertFixedItem( i18n("OVR"), status_Ovr );
-  statusBar()->insertFixedItem( i18n("Size: FFFFFFFFFF"), status_Size );
-  statusBar()->insertFixedItem( i18n("Offset: FFFFFFFFFF-F"), status_Offset );
-  statusBar()->insertFixedItem( i18n("FFF"), status_Layout );
-  statusBar()->insertFixedItem( i18n("RW"), status_WriteProtect );
-
-  statusBar()->setItemAlignment( status_Selection, AlignLeft|AlignVCenter );
-  statusBar()->setItemAlignment( status_Size, AlignLeft|AlignVCenter );
-  statusBar()->setItemAlignment( status_Offset, AlignLeft|AlignVCenter );
-
-  //
-  // Some good default strings we can use after the fields have got
-  // their fixed width.
-  //
-  statusBar()->changeItem( i18n("Offset:"), status_Offset );
-  statusBar()->changeItem( i18n("Size:"), status_Size );
-  statusBar()->changeItem( "", status_Modified );
-  statusBar()->changeItem( "", status_Selection );
-  connect( statusBar(),TQT_SIGNAL(pressed(int)),this,TQT_SLOT(statusBarPressed(int)) );
-}
-
-
-void KHexEdit::removeRecentFiles( void )
-{
-  mAction.openRecent->clearURLList();
-}
-
-
-void KHexEdit::initialize( bool openFiles )
-{
-  mUndoState = CHexBuffer::UndoOk; // Reset in function below
-  setUndoState( 0 );
-
-  mSelectionOffset = 0;
-  mSelectionSize   = 1;
-  mSelectionAsHexadecimal = true;
-  setSelectionState( 0, 0 );
-
-  operationChanged( false );
-
-  editor()->initialize();
-
-  mAction.showFullPath->setChecked( mShowFullPath );
-  showFullPath();
-
-  if ( openFiles && editor()->openFile() != SDisplayMisc::none )
-  {
-    // Code modified from tdelibs/tdeui/tdeactionclasses.cpp TDERecentFilesAction::loadEntries
-      
-    TDEConfig* config = kapp->config();
-
-    const TQString oldGroup = config->group();
-    
-    const TQString groupname = "RecentFiles";
-    config->setGroup( groupname );
-    
-        // read file list
-    unsigned int maxItems = mAction.openRecent->maxItems();
-    if ( editor()->openFile() == SDisplayMisc::mostRecent )
-        maxItems = 1;
-    for( unsigned int i = 1 ; i <= maxItems ; i++ )
-    {
-        const TQString key = TQString( "File%1" ).arg( i );
-        const TQString value = config->readPathEntry( key );
-    
-        if (!value.isEmpty())
-        {
-            mStartupFileList.append( value );
-            mStartupOffsetList.append( "0" ); // ### TODO find a way to still have kept offsets
-        }
-    }
-
-    config->setGroup( oldGroup );
-
-  }  
-  
-  //
-  // Open file(s) after editor has been displayed.
-  // Main reason: If anything goes wrong and an error dialog box
-  // is displayed, then the editor will not be visible until the error
-  // is confirmed and the (modal) dialog is closed.
-  //
-  TQTimer::singleShot( 100, TQT_TQOBJECT(this), TQT_SLOT(delayedStartupOpen()) );
-}
-
-
-void KHexEdit::delayedStartupOpen( void )
-{
-  open( mStartupFileList, mStartupOffsetList );
-  mStartupFileList.clear();
-  mStartupOffsetList.clear();
-}
-
-
-void KHexEdit::statusBarPressed( int id )
-{
-  if( id == status_WriteProtect )
-  {
-    editor()->toggleWriteProtection();
-  }
-  else if( id == status_Ovr )
-  {
-    editor()->toggleInsertMode();
-  }
-  else if( id == status_Offset )
-  {
-    editor()->toggleOffsetAsDecimal();
-  }
-  else if( id == status_Selection )
-  {
-    if( mSelectionSize > 0 )
-    {
-      mSelectionAsHexadecimal = mSelectionAsHexadecimal == true ? false : true;
-      setSelectionText( mSelectionOffset, mSelectionSize );
-    }
-  }
-
-}
-
-
-
-void KHexEdit::open( TQStringList &fileList, TQStringList &offsetList )
-{
-  //
-  // We load in reverse to allow the first document in
-  // the list to become the active one.
-  //
-
-  uint offset;
-  for( uint i = fileList.count(); i>0; i-- )
-  {
-    if( i <= offsetList.count() )
-    {
-      offset = (*offsetList.at(i-1)).toUInt(0,16);
-    }
-    else
-    {
-      offset = 0;
-    }
-    editor()->open( *fileList.at(i-1), true, offset );
-  }
-}
-
-void KHexEdit::addRecentFile( const TQString &fileName )
-{
-  if( fileName.isEmpty() == true )
-  {
-    return;
-  }
-
-  if( fileName.contains( i18n( "Untitled" ), false ) )
-  {
-    return;
-  }
-
-  const KURL url( KURL::fromPathOrURL( fileName ) );
-  kdDebug(1501) << k_funcinfo << " adding recent " << fileName << " => " << url.prettyURL() << endl;
-  mAction.openRecent->addURL( url );
-
-}
-
-
-void KHexEdit::removeRecentFile( const TQString &fileName )
-{
-  if( fileName.isEmpty() == true )
-  {
-    return;
-  }
-
-  if( fileName.contains( i18n( "Untitled" ), false ) )
-  {
-    return;
-  }
-
-  const KURL url( KURL::fromPathOrURL( fileName ) );
-  mAction.openRecent->removeURL( url );
-
-}
-
-
-void KHexEdit::renameRecentFile(const TQString &curName, const TQString &newName)
-{
-  if( curName.contains( i18n( "Untitled" ), false ) )
-  {
-    addRecentFile( newName );
-  }
-  else
-  {
-      mAction.openRecent->removeURL( KURL::fromPathOrURL( curName ) );
-      mAction.openRecent->addURL( KURL::fromPathOrURL( newName ) );
-  }
-}
-
-
-
-void KHexEdit::slotFileOpenRecent( const KURL& url )
-{
-  if ( url.isLocalFile() )
-  {
-    editor()->open( url.path(), false, 0 );
-  }
-  else
-  {
-    // ### TODO: support network transparency
-    KMessageBox::error( this, i18n("Non local recent file: %1").arg( url.prettyURL() ) );
-  }
-}
-
-
-KHexEdit *KHexEdit::newWindow( void )
-{
-  KHexEdit *hexEdit = new KHexEdit;
-  if( hexEdit == 0 )
-  {
-    TQString msg = i18n( "Can not create new window.\n" );
-    msg += hexError( Err_NoMemory );
-    KMessageBox::error( topLevelWidget(), msg );
-    return(0);
-  }
-  hexEdit->show();
-  return(hexEdit);
-}
-
-
-
-void KHexEdit::pasteNewWindow( void )
-{
-  KHexEdit *app = newWindow();
-  if( app != 0 )
-  {
-    app->editor()->pasteNewFile();
-  }
-}
-
-
-
-void KHexEdit::closeWindow( void )
-{
-  close();
-}
-
-
-void KHexEdit::closeProgram( void )
-{
-  if( mWindowList.count() > 1 )
-  {
-    for( KHexEdit *w = mWindowList.first(); w != 0; w = mWindowList.next() )
-    {
-      if( w->editor()->modified() == true )
-      {
-	TQString msg = i18n(""
-	  "There are windows with unsaved modified documents. "
-	  "If you quit now, these modifications will be lost.");
-	int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg, TQString(), KStdGuiItem::quit() );
-	if( reply == KMessageBox::Continue )
-	{
-	  break;
-	}
-	else
-	{
-	  return;
-	}
-      }
-    }
-
-
-    //
-    // Ths will write current configuration to disk.
-    //
-    queryExit();
-
-    //
-    // Make sure every widget is destroyed. The reason why I do this
-    // (besides it is the clean way to do it) is to make sure any
-    // configuration updates in the various destructors are triggered.
-    //
-    mWindowList.setAutoDelete(true);
-    while( mWindowList.first() )
-    {
-      mWindowList.removeRef( mWindowList.first() );
-    }
-
-    kapp->quit();
-  }
-  else
-  {
-    closeWindow();
-  }
-
-}
-
-
-bool KHexEdit::queryClose( void )
-{
-  bool success = editor()->closeAll();
-  if( success == true )
-  {
-    mWindowList.removeRef( this );
-  }
-
-  return( success );
-}
-
-
-//
-// We will always return true here.
-//
-bool KHexEdit::queryExit( void )
-{
-  writeConfiguration();
-  return( true );
-}
-
-void KHexEdit::readConfiguration( void )
-{
-  TDEConfig &config = *kapp->config();
-  readConfiguration( config );
-}
-
-
-void KHexEdit::writeConfiguration( void )
-{
-  TDEConfig &config = *kapp->config();
-  writeConfiguration( config );
-}
-
-
-void KHexEdit::writeConfiguration( TDEConfig &config )
-{
-    saveMainWindowSettings(& config, "General Options");
-  config.setGroup("General Options" );
-  config.writeEntry("ShowFullPath",  mShowFullPath );
-  config.writeEntry("ConversionPosition", (int)mManager->conversionPosition());
-  config.writeEntry("TabBarPosition", (int)mManager->tabBarPosition());
-  config.writeEntry("SearchBarPosition", (int)mManager->searchBarPosition());
-
-  if ( editor()->discardRecentFiles() )
-      mAction.openRecent->clearURLList();
-  mAction.openRecent->saveEntries( &config );
-  
-  converter()->writeConfiguration( config );
-  editor()->writeConfiguration( config );
-
-  config.sync();
-}
-
-
-void KHexEdit::readConfiguration( TDEConfig &config )
-{
-    applyMainWindowSettings(& config, "General Options");
-
-    config.setGroup("General Options");
-  mShowFullPath   = config.readBoolEntry( "ShowFullPath", true );
-  int position    = config.readNumEntry( "ConversionPosition",
-					 CHexManagerWidget::Embed );
-
-  mAction.conversionHide->blockSignals(true);
-  mAction.conversionFloat->blockSignals(true);
-  mAction.conversionEmbed->blockSignals(true);
-  mAction.conversionHide->setChecked(
-    position == CHexManagerWidget::Hide );
-  mAction.conversionFloat->setChecked(
-    position == CHexManagerWidget::Float );
-  mAction.conversionEmbed->setChecked(
-    position == CHexManagerWidget::Embed );
-  mAction.conversionHide->blockSignals(false);
-  mAction.conversionFloat->blockSignals(false);
-  mAction.conversionEmbed->blockSignals(false);
-  showConversionField();
-
-  position = config.readNumEntry( "TabBarPosition", CHexManagerWidget::Hide );
-  mAction.tabHide->blockSignals(true);
-  mAction.tabShowAboveEditor->blockSignals(true);
-  mAction.tabShowBelowEditor->blockSignals(true);
-  mAction.tabHide->setChecked(
-    position==CHexManagerWidget::Hide );
-  mAction.tabShowAboveEditor->setChecked(
-    position==CHexManagerWidget::AboveEditor );
-  mAction.tabShowBelowEditor->setChecked(
-    position==CHexManagerWidget::BelowEditor );
-  mAction.tabHide->blockSignals(false);
-  mAction.tabShowAboveEditor->blockSignals(false);
-  mAction.tabShowBelowEditor->blockSignals(false);
-  showDocumentTabs();
-
-  position = config.readNumEntry( "SearchBarPosition",
-				  CHexManagerWidget::BelowEditor );
-  mAction.searchHide->blockSignals(true);
-  mAction.searchShowAboveEditor->blockSignals(true);
-  mAction.searchShowBelowEditor->blockSignals(true);
-  mAction.searchHide->setChecked(
-    position==CHexManagerWidget::Hide );
-  mAction.searchShowAboveEditor->setChecked(
-    position==CHexManagerWidget::AboveEditor );
-  mAction.searchShowBelowEditor->setChecked(
-    position==CHexManagerWidget::BelowEditor );
-  mAction.searchHide->blockSignals(false);
-  mAction.searchShowAboveEditor->blockSignals(false);
-  mAction.searchShowBelowEditor->blockSignals(false);
-  showSearchBar();
-
-  mAction.openRecent->loadEntries( &config );
-
-  converter()->readConfiguration( config );
-  editor()->readConfiguration( config );
-}
-
-
-
-void KHexEdit::operationChanged( bool state )
-{
-  mAction.cancel->setEnabled( state );
-}
-
-
-
-void KHexEdit::cursorChanged( SCursorState &state )
-{
-  TQString offset( i18n("Offset:") );
-
-  if( state.valid == false )
-  {
-    statusBar()->changeItem( offset, status_Offset );
-  }
-  else
-  {
-    SDisplayLayout &layout = editor()->layout();
-
-    if( layout.offsetMode == SDisplayLayout::hexadecimal )
-    {
-      if( layout.offsetUpperCase == false )
-      {
-	offset += TQString().sprintf( " %04x:%04x-%u", state.offset>>16,
-				     state.offset&0x0000FFFF, state.cell );
-      }
-      else
-      {
-	offset += TQString().sprintf( " %04X:%04X-%u", state.offset>>16,
-				     state.offset&0x0000FFFF, state.cell );
-      }
-    }
-    else
-    {
-      offset += TQString().sprintf( " %010u-%u", state.offset, state.cell );
-    }
-    statusBar()->changeItem( offset, status_Offset );
-  }
-
-  setUndoState( state.undoState );
-  setSelectionState( state.selectionOffset, state.selectionSize );
-}
-
-
-
-
-void KHexEdit::fileState( SFileState &state )
-{
-  if( state.valid == true )
-  {
-    statusBar()->changeItem( i18n("Size: %1").arg( state.size ), status_Size);
-    statusBar()->changeItem( state.modified ? "!" : "", status_Modified);
-
-    if( mIsModified != state.modified )
-    {
-      mIsModified = state.modified;
-      setupCaption( hexView()->url() );
-    }
-
-  }
-  else
-  {
-    statusBar()->changeItem( "", status_Size );
-    statusBar()->changeItem( "", status_Modified );
-  }
-}
-
-
-
-void KHexEdit::layoutChanged( const SDisplayLayout &layout )
-{
-  TDERadioAction *radioAction;
-
-  if( layout.primaryMode == SDisplayLayout::hexadecimal )
-  {
-    radioAction = mAction.hexadecimal;
-  }
-  else if( layout.primaryMode == SDisplayLayout::decimal )
-  {
-    radioAction = mAction.decimal;
-  }
-  else if( layout.primaryMode == SDisplayLayout::octal )
-  {
-    radioAction = mAction.octal;
-  }
-  else if( layout.primaryMode == SDisplayLayout::binary )
-  {
-    radioAction = mAction.binary;
-  }
-  else
-  {
-    radioAction = mAction.textOnly;
-  }
-  radioAction->blockSignals(true);
-  radioAction->setChecked( true );
-  radioAction->blockSignals(false);
-
-  mAction.showOffsetColumn->blockSignals(true);
-  mAction.showTextColumn->blockSignals(true);
-  mAction.offsetAsDecimal->blockSignals(true);
-  mAction.dataUppercase->blockSignals(true);
-  mAction.offsetUppercase->blockSignals(true);
-
-  mAction.showOffsetColumn->setChecked( layout.offsetVisible );
-  mAction.showTextColumn->setEnabled(
-    layout.primaryMode != SDisplayLayout::textOnly );
-  mAction.showTextColumn->setChecked(
-    layout.secondaryMode != SDisplayLayout::hide );
-  mAction.offsetAsDecimal->setChecked(
-    layout.offsetMode != SDisplayLayout::hexadecimal);
-  mAction.dataUppercase->setChecked( layout.primaryUpperCase );
-  mAction.offsetUppercase->setChecked( layout.offsetUpperCase );
-
-  mAction.showOffsetColumn->blockSignals(false);
-  mAction.showTextColumn->blockSignals(false);
-  mAction.offsetAsDecimal->blockSignals(false);
-  mAction.dataUppercase->blockSignals(false);
-  mAction.offsetUppercase->blockSignals(false);
-
-  if( layout.primaryMode == SDisplayLayout::hexadecimal )
-  {
-    statusBar()->changeItem( i18n("Hex"), status_Layout );
-  }
-  else if( layout.primaryMode == SDisplayLayout::decimal )
-  {
-    statusBar()->changeItem( i18n("Dec"), status_Layout );
-  }
-  else if( layout.primaryMode == SDisplayLayout::octal )
-  {
-    statusBar()->changeItem( i18n("Oct"), status_Layout );
-  }
-  else if( layout.primaryMode == SDisplayLayout::binary )
-  {
-    statusBar()->changeItem( i18n("Bin"), status_Layout );
-  }
-  else if( layout.primaryMode == SDisplayLayout::textOnly )
-  {
-    statusBar()->changeItem( i18n("Txt"), status_Layout );
-  }
-}
-
-
-void KHexEdit::inputModeChanged( const SDisplayInputMode &mode )
-{
-  mAction.readOnly->blockSignals(true);
-  mAction.resizeLock->blockSignals(true);
-  mAction.readOnly->setChecked( mode.readOnly );
-  mAction.resizeLock->setChecked( mode.allowResize );
-  mAction.readOnly->blockSignals(false);
-  mAction.resizeLock->blockSignals(false);
-
-  statusBar()->changeItem( mode.readOnly == true ?
-			   i18n("R") : i18n("RW"), status_WriteProtect );
-
-  if( mode.readOnly == false )
-  {
-    mWriteProtectButton->setIcon("edit");
-  }
-  else
-  {
-    mWriteProtectButton->setIcon("system-lock-screen");
-  }
-}
-
-
-void KHexEdit::bookmarkChanged( TQPtrList<SCursorOffset> &list )
-{
-  unplugActionList("bookmark_list");
-  mAction.bookmarkList.setAutoDelete(true);
-  mAction.bookmarkList.clear();
-
-  if( list.count() == 0 )
-  {
-    return;
-  }
-
-  mAction.bookmarkList.append(new TDEActionSeparator());
-
-  TQString text, offset;
-  int i=0;
-
-  for( SCursorOffset *p=list.first(); p!=0; p=list.next(), i++ )
-  {
-    offset.sprintf("%04X:%04X", p->offset>>16, p->offset&0x0000FFFF );
-    text = i18n("Offset: %1").arg(offset);
-    TDEAction *action = new TDEAction(text, 0, mAction.bookmarkMapper, TQT_SLOT(map()), TQT_TQOBJECT(this), text.latin1());
-    int key = acceleratorNumKey( i );
-    if( key > 0 )
-    {
-      action->setShortcut(TDEShortcut(ALT+key));
-    }
-    mAction.bookmarkMapper->setMapping(action, i);
-    mAction.bookmarkList.append(action);
-  }
-  plugActionList("bookmark_list", mAction.bookmarkList);
-}
-
-
-void KHexEdit::setupCaption( const TQString &url )
-{
-  KURL u(url);
-  if( mShowFullPath == true )
-  {
-    setCaption( u.prettyURL(), hexView()->modified() );
-  }
-  else
-  {
-    setCaption( u.fileName(), hexView()->modified() );
-  }
-}
-
-
-void KHexEdit::fileActive( const TQString &url, bool onDisk )
-{
-  setupCaption( url );
-  mDragLabel->setUrl( url );
-  mDragLabel->setEnabled( onDisk );
-
-  mAction.revert->setEnabled( onDisk );
-
-  if( url.isNull() == false )
-  {
-    addDocument( url );
-    addRecentFile( url );
-    setTickedDocument( url );
-  }
-}
-
-
-void KHexEdit::fileRename( const TQString &curName, const TQString &newName )
-{
-  if( newName.isNull() == true )
-  {
-    return;
-  }
-
-  renameDocument( curName, newName );
-  renameRecentFile( curName, newName );
-  setupCaption( newName );
-  //setCaption( newName );
-}
-
-
-void KHexEdit::fileClosed( const TQString &url )
-{
-  removeDocument( url );
-}
-
-
-void KHexEdit::editMode( CHexBuffer::EEditMode editMode )
-{
-  statusBar()->changeItem( editMode == CHexBuffer::EditReplace ?
-			   i18n("OVR") : i18n("INS"), status_Ovr );
-}
-
-
-void KHexEdit::encodingChanged( const SEncodeState &encodeState )
-{
-  TDERadioAction *radioAction;
-
-  if( encodeState.mode == CConversion::cnvDefault )
-  {
-    radioAction = mAction.defaultEncoding;
-  }
-  else if( encodeState.mode == CConversion::cnvUsAscii )
-  {
-    radioAction = mAction.usAsciiEncoding;
-  }
-  else if( encodeState.mode == CConversion::cnvEbcdic )
-  {
-    radioAction = mAction.ebcdicEncoding;
-  }
-  else
-  {
-    return;
-  }
-
-  radioAction->blockSignals(true);
-  radioAction->setChecked( true );
-  radioAction->blockSignals(false);
-
-  if( mSelectionSize == 0 )
-  {
-    statusBar()->changeItem( i18n("Encoding: %1").arg(encodeState.name),
-			     status_Selection );
-  }
-}
-
-
-void KHexEdit::textWidth( uint )
-{
-  resize( mManager->preferredWidth(), height() );
-}
-
-
-void KHexEdit::setDisplayMode( void )
-{
-  if( mAction.hexadecimal->isChecked() == true )
-  {
-    editor()->setHexadecimalMode();
-  }
-  else if( mAction.decimal->isChecked() == true )
-  {
-    editor()->setDecimalMode();
-  }
-  else if( mAction.octal->isChecked() == true )
-  {
-    editor()->setOctalMode();
-  }
-  else if( mAction.binary->isChecked() == true )
-  {
-    editor()->setBinaryMode();
-  }
-  else if( mAction.textOnly->isChecked() == true )
-  {
-    editor()->setTextMode();
-  }
-}
-
-
-void KHexEdit::showFullPath( void )
-{
-  mShowFullPath = mAction.showFullPath->isChecked();
-  setupCaption( hexView()->url() );
-}
-
-
-void KHexEdit::showDocumentTabs( void )
-{
-  if( mAction.tabHide->isChecked() == true )
-  {
-    mManager->setTabBarPosition( CHexManagerWidget::HideItem );
-  }
-  else if( mAction.tabShowAboveEditor->isChecked() == true )
-  {
-    mManager->setTabBarPosition( CHexManagerWidget::AboveEditor );
-  }
-  else if( mAction.tabShowBelowEditor->isChecked() == true )
-  {
-    mManager->setTabBarPosition( CHexManagerWidget::BelowEditor );
-  }
-}
-
-
-void KHexEdit::showConversionField( void )
-{
-  if( mAction.conversionHide->isChecked() == true )
-  {
-    mManager->setConversionVisibility( CHexManagerWidget::Hide );
-  }
-  else if( mAction.conversionFloat->isChecked() == true )
-  {
-    mManager->setConversionVisibility( CHexManagerWidget::Float );
-  }
-  else if( mAction.conversionEmbed->isChecked() == true )
-  {
-    mManager->setConversionVisibility( CHexManagerWidget::Embed );
-    if( width() < mManager->preferredWidth() )
-    {
-      resize( mManager->preferredWidth(), height() );
-    }
-  }
-}
-
-
-void KHexEdit::showSearchBar( void )
-{
-  if( mAction.searchHide->isChecked() == true )
-  {
-    mManager->setSearchBarPosition( CHexManagerWidget::HideItem );
-  }
-  else if( mAction.searchShowAboveEditor->isChecked() == true )
-  {
-    mManager->setSearchBarPosition( CHexManagerWidget::AboveEditor );
-  }
-  else if( mAction.searchShowBelowEditor->isChecked() == true )
-  {
-    mManager->setSearchBarPosition( CHexManagerWidget::BelowEditor );
-  }
-}
-
-
-void KHexEdit::setEncoding( void )
-{
-  if( mAction.defaultEncoding->isChecked() == true )
-  {
-    editor()->encode( CConversion::cnvDefault );
-  }
-  else if( mAction.usAsciiEncoding->isChecked() == true )
-  {
-    editor()->encode( CConversion::cnvUsAscii );
-  }
-  else if( mAction.ebcdicEncoding->isChecked() == true )
-  {
-    editor()->encode( CConversion::cnvEbcdic );
-  }
-}
-
-
-void KHexEdit::setUndoState( uint undoState )
-{
-  if( mUndoState != undoState )
-  {
-    mUndoState = undoState;
-    mAction.undo->setEnabled( mUndoState & CHexBuffer::UndoOk );
-    mAction.redo->setEnabled( mUndoState & CHexBuffer::RedoOk );
-  }
-}
-
-
-void KHexEdit::setSelectionState( uint selectionOffset, uint selectionSize )
-{
-  if( mSelectionSize != selectionSize )
-  {
-    mSelectionOffset = selectionOffset;
-    mSelectionSize   = selectionSize;
-
-    bool valid = mSelectionSize > 0 ? true : false;
-    mAction.copy->setEnabled( valid );
-    mAction.cut->setEnabled( valid );
-    mAction.copyAsText->setEnabled( valid );
-
-    setSelectionText( selectionOffset, selectionSize );
-  }
-}
-
-
-void KHexEdit::setSelectionText( uint selectionOffset, uint selectionSize )
-{
-  if( selectionSize > 0 )
-  {
-    TQString selection = i18n("Selection:");
-    if( mSelectionAsHexadecimal == true )
-    {
-      selection += TQString().sprintf( " %04x:%04x %04x:%04x",
-        selectionOffset>>16, selectionOffset&0x0000FFFF,
-        selectionSize>>16, selectionSize&0x0000FFFF );
-    }
-    else
-    {
-      selection += TQString().sprintf( " %08u %08u",
-        selectionOffset, selectionSize);
-    }
-    statusBar()->changeItem( selection, status_Selection );
-  }
-  else
-  {
-    statusBar()->changeItem(
-      i18n("Encoding: %1").arg(hexView()->encoding().name), status_Selection);
-  }
-}
-
-
-void KHexEdit::documentMenuCB( int index )
-{
-  if( (uint)index < mDocumentList.count() )
-  {
-    editor()->open( mDocumentList[index], false, 0 );
-  }
-}
-
-
-void KHexEdit::addDocument( const TQString &fileName )
-{
-  uint documentCount = mDocumentList.count();
-  for( uint i=0; i < documentCount; i++ )
-  {
-    if( fileName == mDocumentList[i] )
-    {
-      return;
-    }
-  }
-
-  mDocumentList.append( fileName );
-
-  TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
-  documentMenu->insertItem( fileName, documentCount, documentCount );
-  int key = acceleratorNumKey( documentCount );
-  if( key > 0 )
-  {
-    documentMenu->setAccel( CTRL+key, documentCount );
-  }
-}
-
-
-void KHexEdit::removeDocument( const TQString &fileName )
-{
-  TQStringList::Iterator it;
-  for( it = mDocumentList.begin(); it != mDocumentList.end(); it++ )
-  {
-    if( *it == fileName )
-    {
-      TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
-
-      documentMenu->removeItemAt( mDocumentList.findIndex(*it) );
-      mDocumentList.remove( it );
-
-      for( uint i=0; i < mDocumentList.count(); i++ )
-      {
-	documentMenu->setId( i, i );
-	int key = acceleratorNumKey( i );
-	if( key > 0 )
-	{
-	  documentMenu->setAccel( CTRL+key, i );
-	}
-      }
-      return;
-
-    }
-  }
-}
-
-
-void KHexEdit::renameDocument( const TQString &curName, const TQString &newName )
-{
-  TQStringList::Iterator it;
-  for( it = mDocumentList.begin(); it != mDocumentList.end(); it++ )
-  {
-    if( *it == curName )
-    {
-      TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
-      documentMenu->changeItem( newName, mDocumentList.findIndex(*it) );
-      mDocumentList.insert( it, newName );
-      mDocumentList.remove( it );
-      return;
-    }
-  }
-}
-
-
-void KHexEdit::setTickedDocument( const TQString &fileName )
-{
-  uint documentCount = mDocumentList.count();
-  TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
-  for( uint i=0; i < documentCount; i++ )
-  {
-    documentMenu->setItemChecked( i, fileName == mDocumentList[i] );
-  }
-}
-
-
-void KHexEdit::conversionClosed( void )
-{
-  mAction.conversionHide->setChecked(true);
-}
-
-
-void KHexEdit::searchBarClosed( void )
-{
-  mAction.searchHide->setChecked(true);
-}
-
-
-bool KHexEdit::eventFilter( TQObject *o, TQEvent *event )
-{
-  if( event->type() == TQEvent::DragEnter )
-  {
-    TQDragEnterEvent *e = (TQDragEnterEvent*)event;
-    if( KURLDrag::canDecode(e) )
-    {
-      e->accept();
-      hexView()->setDropHighlight( true );
-    }
-    return( true );
-  }
-  else if( event->type() == TQEvent::Drop )
-  {
-    TQMimeSource &m = *(TQDropEvent*)event;
-    hexView()->setDropHighlight( false );
-
-    KURL::List list;
-    if( KURLDrag::decode( &m, list ) == true )
-    {
-      TQStringList offset;
-      TQStringList urlList = list.toStringList();
-      open( urlList, offset );
-      return( true );
-    }
-    return( true );
-  }
-  else if( event->type() == TQEvent::DragLeave )
-  {
-    hexView()->setDropHighlight( false );
-    return( true );
-  }
-
-  return TDEMainWindow::eventFilter( o, event );
-}
-
-
-int KHexEdit::acceleratorNumKey( uint index )
-{
-  static int keys[9] =
-  {
-    Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9
-  };
-  return( index >= 9 ? -1 : keys[index] );
-}
-
-
-#include <sys/time.h>
-#include <unistd.h>
-
-//
-// This function is used to test twin performance
-//
-void KHexEdit::resizeTest()
-{
-  struct timeval t1, t2;
-  gettimeofday( &t1, 0 );
-
-  int loop=400;
-
-  for( int i=0; i<loop; i+=4 )
-  {
-    resize( i+400, i+400 );
-    //kapp->processOneEvent();
-  }
-
-  gettimeofday( &t2, 0 );
-  uint last = (t2.tv_sec-t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
-
-  kdDebug(1501) << "Duration: " << (float)last/ 1000000.0 <<  endl;
-  kdDebug(1501) << "Duration/loop: " << (float)last/ (1000000.0*(float)loop) << endl;
-}
-#include "toplevel.moc"
diff --git a/khexedit/toplevel.cpp b/khexedit/toplevel.cpp
new file mode 100644
index 00000000..c09bef8e
--- /dev/null
+++ b/khexedit/toplevel.cpp
@@ -0,0 +1,1363 @@
+/*
+ *   khexedit - Versatile hex editor
+ *   Copyright (C) 1999-2000 Espen Sand, espensa@online.no
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+#include <tqptrlist.h>
+#include <tqsignalmapper.h>
+#include <tqtimer.h>
+#include <tqtooltip.h>
+
+#include <tdeaction.h>
+#include <kiconloader.h>
+#include <tdelocale.h>
+#include <tdemessagebox.h>
+#include <kstatusbar.h>
+#include <tdepopupmenu.h>
+#include <kstdaction.h>
+#include <tdetoolbarbutton.h>
+#include <kdebug.h>
+#include <kurl.h>
+#include <kurldrag.h>
+
+#include "dialog.h"
+#include "draglabel.h"
+#include "hexerror.h"
+#include "toplevel.h"
+
+
+TQPtrList<KHexEdit> KHexEdit::mWindowList;
+
+KHexEdit::KHexEdit( void )
+  : TDEMainWindow(0, "toplevel"), mStartupOffset(0),
+  mIsModified(0)
+{
+  mWindowList.append( this );
+
+  //
+  // Create main widget and register it.
+  //
+  mManager = new CHexManagerWidget( this, "manager" );
+  setCentralWidget( mManager );
+
+  //
+  // I use an eventfilter to catch all drag/drop events for the
+  // area outside the editor window. It will only accept KURLDrag.
+  // (The editor window will catch KURLDrag, TQTextDrag and CHexDrag)
+  //
+  installEventFilter( this );
+  setAcceptDrops(true);
+
+  //
+  // Prepare menus and status bar
+  //
+  mAction.bookmarkMapper = new TQSignalMapper(TQT_TQOBJECT(this));
+  connect(mAction.bookmarkMapper, TQT_SIGNAL(mapped(int)), TQT_TQOBJECT(editor()), TQT_SLOT(gotoBookmark(int)));
+  setupActions();
+  setupStatusBar();
+
+  connect( hexView(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( cursorChanged( SCursorState & ) ) );
+  connect( hexView(), TQT_SIGNAL( editMode( CHexBuffer::EEditMode ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( editMode( CHexBuffer::EEditMode ) ) );
+  connect( hexView(), TQT_SIGNAL( encodingChanged( const SEncodeState &)),
+	   TQT_TQOBJECT(this), TQT_SLOT( encodingChanged( const SEncodeState & )) );
+  connect( hexView(), TQT_SIGNAL( textWidth( uint ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( textWidth( uint ) ) );
+  connect( hexView(), TQT_SIGNAL( fileState( SFileState & ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( fileState( SFileState & ) ) );
+  connect( hexView(), TQT_SIGNAL( layoutChanged( const SDisplayLayout & ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( layoutChanged( const SDisplayLayout & ) ) );
+  connect( hexView(), TQT_SIGNAL( inputModeChanged( const SDisplayInputMode & ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( inputModeChanged( const SDisplayInputMode & ) ) );
+  connect( hexView(), TQT_SIGNAL( bookmarkChanged( TQPtrList<SCursorOffset> &)),
+	   TQT_TQOBJECT(this), TQT_SLOT( bookmarkChanged( TQPtrList<SCursorOffset> & ) ) );
+  connect( hexView(), TQT_SIGNAL( fileName( const TQString &, bool ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( fileActive( const TQString &, bool ) ) );
+  connect( hexView(), TQT_SIGNAL( fileRename( const TQString &, const TQString & )),
+	   TQT_TQOBJECT(this), TQT_SLOT( fileRename( const TQString &, const TQString & ) ) );
+  connect( hexView(), TQT_SIGNAL( fileClosed( const TQString & ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( fileClosed( const TQString & ) ) );
+  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( errorLoadFile( const TQString & ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( removeRecentFile( const TQString & ) ) );
+  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( operationChanged( bool ) ),
+	   TQT_TQOBJECT(this), TQT_SLOT( operationChanged( bool ) ) );
+  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( removeRecentFiles() ),
+	   TQT_TQOBJECT(this), TQT_SLOT( removeRecentFiles() ) );
+  connect( mManager, TQT_SIGNAL( conversionClosed() ),
+	   TQT_TQOBJECT(this), TQT_SLOT(conversionClosed()) );
+  connect( mManager, TQT_SIGNAL( searchBarClosed() ),
+	   TQT_TQOBJECT(this), TQT_SLOT(searchBarClosed()) );
+
+  //
+  // Read configuration from file and set the default editor size.
+  // Open files if this is the first toplevel window.
+  //
+  readConfiguration();
+  initialize( mWindowList.count() == 1 ? true : false );
+  setAutoSaveSettings();
+}
+
+
+KHexEdit::~KHexEdit( void )
+{
+  delete mAction.bookmarkMapper;
+  delete mManager;
+}
+
+
+void KHexEdit::setupActions( void )
+{
+  KStdAction::openNew( TQT_TQOBJECT(editor()), TQT_SLOT(newFile()), actionCollection() );
+  KStdAction::open( TQT_TQOBJECT(editor()), TQT_SLOT(open()), actionCollection() );
+  KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()), 
+actionCollection());
+   
+  mAction.insert     = new TDEAction( i18n("&Insert..."), CTRL+Key_I,
+    TQT_TQOBJECT(editor()), TQT_SLOT(insertFile()), actionCollection(), "insert_file" );
+  mAction.openRecent = KStdAction::openRecent( TQT_TQOBJECT(this), TQT_SLOT( slotFileOpenRecent( const KURL& ) ), actionCollection() );
+  mAction.save       = KStdAction::save( TQT_TQOBJECT(editor()), TQT_SLOT(save()), actionCollection() );
+  mAction.saveAs     = KStdAction::saveAs( TQT_TQOBJECT(editor()), TQT_SLOT(saveAs()), actionCollection() );
+  mAction.revert     = KStdAction::revert( TQT_TQOBJECT(editor()), TQT_SLOT(reload()), actionCollection() );
+  //mAction.revert     = KStdAction::revert( TQT_TQOBJECT(this), TQT_SLOT(resizeTest()), actionCollection() );
+
+  mAction.close      = KStdAction::close( TQT_TQOBJECT(editor()), TQT_SLOT(close()), actionCollection() );
+  mAction.print      = KStdAction::print( TQT_TQOBJECT(editor()), TQT_SLOT(print()), actionCollection() );
+  mAction.exportData = new TDEAction( i18n("E&xport..."), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(exportDialog()), actionCollection(), "export" );
+  mAction.cancel     = new TDEAction( i18n("&Cancel Operation"),
+    "process-stop", 0, TQT_TQOBJECT(editor()), TQT_SLOT(stop()), actionCollection(), "cancel" );
+  mAction.readOnly   = new TDEToggleAction( i18n("&Read Only"),
+    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleWriteProtection()),actionCollection(), "read_only" );
+  mAction.resizeLock = new TDEToggleAction( i18n("&Allow Resize"),
+   0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleResizeLock()),actionCollection(), "resize_lock" );
+  mAction.newWindow  = new TDEAction( i18n("N&ew Window"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(newWindow()),actionCollection(), "new_window" );
+  mAction.closeWindow= new TDEAction( i18n("Close &Window"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(closeWindow()),actionCollection(), "close_window" );
+  mAction.quit       = KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(closeProgram()), actionCollection() );
+
+  mAction.undo       = KStdAction::undo(      TQT_TQOBJECT(editor()), TQT_SLOT(undo()), actionCollection() );
+  mAction.redo       = KStdAction::redo(      TQT_TQOBJECT(editor()), TQT_SLOT(redo()), actionCollection() );
+  mAction.cut        = KStdAction::cut(       TQT_TQOBJECT(editor()), TQT_SLOT(cut()), actionCollection() );
+  mAction.copy       = KStdAction::copy(      TQT_TQOBJECT(editor()), TQT_SLOT(copy()), actionCollection() );
+  mAction.paste      = KStdAction::paste(     TQT_TQOBJECT(editor()), TQT_SLOT(paste()), actionCollection() );
+  mAction.selectAll  = KStdAction::selectAll( TQT_TQOBJECT(editor()), TQT_SLOT(selectAll()),actionCollection() );
+  mAction.unselect   = KStdAction::deselect(  TQT_TQOBJECT(editor()), TQT_SLOT(unselect()), actionCollection());
+  mAction.find     = KStdAction::find(      TQT_TQOBJECT(editor()), TQT_SLOT(find()), actionCollection() );
+  mAction.findNext   = KStdAction::findNext(  TQT_TQOBJECT(editor()), TQT_SLOT(findNext()), actionCollection() );
+  mAction.findPrev   = KStdAction::findPrev(  TQT_TQOBJECT(editor()),TQT_SLOT(findPrevious()),actionCollection() );
+  mAction.replace  = KStdAction::replace(   TQT_TQOBJECT(editor()), TQT_SLOT(replace()), actionCollection() );
+  mAction.gotoOffset = new TDEAction( i18n("&Goto Offset..."), CTRL+Key_G,
+    TQT_TQOBJECT(editor()), TQT_SLOT(gotoOffset()),actionCollection(), "goto_offset" );
+  mAction.insertPattern = new TDEAction( i18n("&Insert Pattern..."), CTRL+Key_Insert,
+    TQT_TQOBJECT(editor()), TQT_SLOT(insertPattern()), actionCollection(), "insert_pattern" );
+
+  mAction.copyAsText = new TDEAction( i18n("Copy as &Text"), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(copyText()), actionCollection(), "copy_as_text" );
+  mAction.pasteToNewFile = new TDEAction( i18n("Paste into New &File"), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(pasteNewFile()), actionCollection(), "paste_into_new_file" );
+  mAction.pasteToNewWindow = new TDEAction( i18n("Paste into New &Window"), 0,
+    TQT_TQOBJECT(this), TQT_SLOT(pasteNewWindow()), actionCollection(), "paste_into_new_window" );
+
+  mAction.hexadecimal = new TDERadioAction( i18n("&Hexadecimal"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_hex" );
+  mAction.decimal     = new TDERadioAction( i18n("&Decimal"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_dec" );
+  mAction.octal       = new TDERadioAction( i18n("&Octal"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_oct" );
+  mAction.binary      = new TDERadioAction( i18n("&Binary"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_bin" );
+  mAction.textOnly    = new TDERadioAction( i18n("&Text"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(setDisplayMode()), actionCollection(), "mode_text" );
+  mAction.hexadecimal->setExclusiveGroup( "displayMode" );
+  mAction.decimal->setExclusiveGroup( "displayMode" );
+  mAction.octal->setExclusiveGroup( "displayMode" );
+  mAction.binary->setExclusiveGroup( "displayMode" );
+  mAction.textOnly->setExclusiveGroup( "displayMode" );
+
+  mAction.showOffsetColumn = new TDEToggleAction( i18n("Show O&ffset Column"),
+    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleOffsetColumnVisibility()),actionCollection(), "show_offset_column" );
+  mAction.showTextColumn = new TDEToggleAction( i18n("Show Te&xt Field"),
+    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleTextColumnVisibility()),actionCollection(), "show_text_field" );
+  mAction.offsetAsDecimal = new TDEToggleAction( i18n("Off&set as Decimal"),
+    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleOffsetAsDecimal()),actionCollection(), "offset_as_decimal" );
+  mAction.dataUppercase = new TDEToggleAction( i18n("&Upper Case (Data)"),
+    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleDataUppercase()),actionCollection(), "upper_case_data" );
+  mAction.offsetUppercase = new TDEToggleAction( i18n("Upper &Case (Offset)"),
+    0, TQT_TQOBJECT(editor()), TQT_SLOT(toggleOffsetUppercase()),actionCollection(), "upper_case_offset" );
+
+  mAction.defaultEncoding = new TDERadioAction( i18n("&Default encoding", "&Default"),
+    0, TQT_TQOBJECT(this), TQT_SLOT( setEncoding()), actionCollection(), "enc_default" );
+  mAction.usAsciiEncoding = new TDERadioAction( i18n("US-&ASCII (7 bit)"),
+    0, TQT_TQOBJECT(this), TQT_SLOT( setEncoding()), actionCollection(), "enc_ascii");
+  mAction.ebcdicEncoding  = new TDERadioAction( i18n("&EBCDIC"),
+    0, TQT_TQOBJECT(this), TQT_SLOT( setEncoding()), actionCollection(), "enc_ebcdic" );
+//   mAction.customEncoding  = new TDEAction( i18n("&Custom..."),
+//     0, TQT_TQOBJECT(editor()), TQT_SLOT( encoding()), actionCollection(), "enc_custom" );
+  mAction.defaultEncoding->setExclusiveGroup( "encodingMode" );
+  mAction.usAsciiEncoding->setExclusiveGroup( "encodingMode" );
+  mAction.ebcdicEncoding->setExclusiveGroup( "encodingMode" );
+
+  mAction.strings = new TDEAction( i18n("&Extract Strings..."), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(strings()), actionCollection(), "extract_strings" );
+//   mAction.recordViewer = new TDEAction( i18n("&Record Viewer"), 0,
+//     TQT_TQOBJECT(editor()), TQT_SLOT(recordView()), actionCollection(), "record_viewer" );
+  mAction.filter = new TDEAction( i18n("&Binary Filter..."), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(filter()), actionCollection(), "binary_filter" );
+  mAction.characterTable = new TDEAction( i18n("&Character Table"), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(chart()), actionCollection(), "char_table" );
+  mAction.converter = new TDEAction( i18n("C&onverter"), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(converter()), actionCollection(), "converter" );
+  mAction.statistics = new TDEAction( i18n("&Statistics"), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(statistics()), actionCollection(), "statistics" );
+
+  mAction.addBookmark = KStdAction::addBookmark( TQT_TQOBJECT(editor()),
+    TQT_SLOT(addBookmark()), actionCollection() );
+  mAction.replaceBookmark = new TDEAction( i18n("&Replace Bookmark"), CTRL+Key_E,
+    TQT_TQOBJECT(editor()), TQT_SLOT(replaceBookmark()), actionCollection(), "replace_bookmark");
+  mAction.removeBookmark = new TDEAction( i18n("R&emove Bookmark"), CTRL+Key_U,
+    TQT_TQOBJECT(editor()), TQT_SLOT(removeBookmark()), actionCollection(), "remove_bookmark" );
+  mAction.removeAllBookmark = new TDEAction( i18n("Re&move All"), 0,
+    TQT_TQOBJECT(editor()), TQT_SLOT(removeAllBookmark()), actionCollection(), "remove_all_bookmarks" );
+  mAction.nextBookmark = new TDEAction( i18n("Goto &Next Bookmark"),
+				      ALT+Key_Down, TQT_TQOBJECT(editor()),
+				      TQT_SLOT(gotoNextBookmark()), actionCollection(), "next_bookmark" );
+  mAction.prevBookmark = new TDEAction( i18n("Goto &Previous Bookmark"),
+				      ALT+Key_Up, TQT_TQOBJECT(editor()),
+				      TQT_SLOT(gotoPrevBookmark()), actionCollection(), "prev_bookmark" );
+
+  createStandardStatusBarAction();
+  setStandardToolBarMenuEnabled(true);
+  mAction.showFullPath  = new TDEToggleAction( i18n("Show F&ull Path"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showFullPath()), actionCollection(), "show_full_path" );
+
+  mAction.tabHide = new TDERadioAction( i18n("&Hide"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showDocumentTabs()), actionCollection(), "doctab_hide" );
+  mAction.tabShowAboveEditor = new TDERadioAction( i18n("&Above Editor"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showDocumentTabs()), actionCollection(), "doctab_above" );
+  mAction.tabShowBelowEditor = new TDERadioAction( i18n("&Below Editor"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showDocumentTabs()), actionCollection(), "doctab_below" );
+  mAction.tabHide->setExclusiveGroup( "editorTab" );
+  mAction.tabShowAboveEditor->setExclusiveGroup( "editorTab" );
+  mAction.tabShowBelowEditor->setExclusiveGroup( "editorTab" );
+
+  mAction.conversionHide  = new TDERadioAction( i18n("&Hide"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showConversionField()), actionCollection(), "conversion_field_hide");
+  mAction.conversionFloat = new TDERadioAction( i18n("&Floating"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showConversionField()), actionCollection(), "conversion_field_float");
+  mAction.conversionEmbed = new TDERadioAction( i18n("&Embed in Main Window"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showConversionField()), actionCollection(), "conversion_field_embed");
+  mAction.conversionHide->setExclusiveGroup( "conversionField" );
+  mAction.conversionFloat->setExclusiveGroup( "conversionField" );
+  mAction.conversionEmbed->setExclusiveGroup( "conversionField" );
+
+  mAction.searchHide = new TDERadioAction( i18n("&Hide"),
+    0, TQT_TQOBJECT(this), TQT_SLOT(showSearchBar()), actionCollection(), "searchbar_hide" );
+  mAction.searchShowAboveEditor = new TDERadioAction( i18n("&Above Editor"),
+    Key_F5, TQT_TQOBJECT(this), TQT_SLOT(showSearchBar()), actionCollection(), "searchbar_above" );
+  mAction.searchShowBelowEditor = new TDERadioAction( i18n("&Below Editor"),
+    Key_F6, TQT_TQOBJECT(this), TQT_SLOT(showSearchBar()), actionCollection(), "searchbar_below" );
+  mAction.searchHide->setExclusiveGroup( "searchBar" );
+  mAction.searchShowAboveEditor->setExclusiveGroup( "searchBar" );
+  mAction.searchShowBelowEditor->setExclusiveGroup( "searchBar" );
+
+  KStdAction::saveOptions(TQT_TQOBJECT(this), TQT_SLOT(writeConfiguration()), actionCollection());
+  KStdAction::preferences(TQT_TQOBJECT(editor()) ,TQT_SLOT(options()),actionCollection() );
+//   mAction.favorites = new TDEAction( i18n("P&rofiles..."), 0,
+//     TQT_TQOBJECT(editor()), TQT_SLOT(favorites()), actionCollection(), "favorites" );
+
+  KStdAction::help( TQT_TQOBJECT(this), TQT_SLOT(appHelpActivated()), actionCollection() );
+
+  mDragLabel = new CDragLabel(this);
+  mDragLabel->setPixmap( UserIcon( "hexdrag" ) );
+  mDragLabel->setDragMask( UserIcon( "hexmask" ) );
+  mDragLabel->setEnabled( false ); // Enabled once we open a document
+  TQToolTip::add( mDragLabel, i18n("Drag document") );
+ (void) new KWidgetAction(mDragLabel, i18n("Drag Document"), 0, TQT_TQOBJECT(editor()), TQT_SLOT(options()), actionCollection(), "drag_document");
+
+  createGUI("khexeditui.rc", false);
+
+  TQPopupMenu *popup = (TQPopupMenu *)factory()->container("editor_popup", this);
+  hexView()->setPopupMenu( popup );
+
+  int id = 100;
+  toolBar(0)->insertButton( MainBarIcon("system-lock-screen"), id, TQT_SIGNAL(clicked()),
+    TQT_TQOBJECT(editor()), TQT_SLOT(toggleWriteProtection()), true,
+    i18n("Toggle write protection") );
+  toolBar(0)->alignItemRight( id );
+  mWriteProtectButton = toolBar(0)->getButton(id);
+
+  TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
+  hexView()->setDocumentMenu(documentMenu);
+  connect(documentMenu, TQT_SIGNAL(activated(int)), TQT_SLOT(documentMenuCB(int)));
+
+}
+
+
+void KHexEdit::setupStatusBar( void )
+{
+  CStatusBarProgress *progess = new CStatusBarProgress( statusBar() );
+  statusBar()->addWidget( progess, 10 );
+  connect( progess, TQT_SIGNAL(pressed()), TQT_TQOBJECT(editor()), TQT_SLOT(stop()) );
+  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( setProgress( int ) ),
+	   progess, TQT_SLOT( setValue( int ) ) );
+  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( setProgress( int, int ) ),
+	   progess, TQT_SLOT( setValue( int, int ) ) );
+  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( enableProgressText( bool ) ),
+	   progess, TQT_SLOT( setTextEnabled( bool ) ) );
+  connect( TQT_TQOBJECT(editor()), TQT_SIGNAL( setProgressText( const TQString & ) ),
+	   progess, TQT_SLOT( setText( const TQString & ) ) );
+
+  statusBar()->insertFixedItem( i18n("Selection: 0000:0000 0000:0000"),
+				status_Selection );
+  statusBar()->insertFixedItem( i18n("M"), status_Modified );
+  statusBar()->insertFixedItem( i18n("OVR"), status_Ovr );
+  statusBar()->insertFixedItem( i18n("Size: FFFFFFFFFF"), status_Size );
+  statusBar()->insertFixedItem( i18n("Offset: FFFFFFFFFF-F"), status_Offset );
+  statusBar()->insertFixedItem( i18n("FFF"), status_Layout );
+  statusBar()->insertFixedItem( i18n("RW"), status_WriteProtect );
+
+  statusBar()->setItemAlignment( status_Selection, AlignLeft|AlignVCenter );
+  statusBar()->setItemAlignment( status_Size, AlignLeft|AlignVCenter );
+  statusBar()->setItemAlignment( status_Offset, AlignLeft|AlignVCenter );
+
+  //
+  // Some good default strings we can use after the fields have got
+  // their fixed width.
+  //
+  statusBar()->changeItem( i18n("Offset:"), status_Offset );
+  statusBar()->changeItem( i18n("Size:"), status_Size );
+  statusBar()->changeItem( "", status_Modified );
+  statusBar()->changeItem( "", status_Selection );
+  connect( statusBar(),TQT_SIGNAL(pressed(int)),this,TQT_SLOT(statusBarPressed(int)) );
+}
+
+
+void KHexEdit::removeRecentFiles( void )
+{
+  mAction.openRecent->clearURLList();
+}
+
+
+void KHexEdit::initialize( bool openFiles )
+{
+  mUndoState = CHexBuffer::UndoOk; // Reset in function below
+  setUndoState( 0 );
+
+  mSelectionOffset = 0;
+  mSelectionSize   = 1;
+  mSelectionAsHexadecimal = true;
+  setSelectionState( 0, 0 );
+
+  operationChanged( false );
+
+  editor()->initialize();
+
+  mAction.showFullPath->setChecked( mShowFullPath );
+  showFullPath();
+
+  if ( openFiles && editor()->openFile() != SDisplayMisc::none )
+  {
+    // Code modified from tdelibs/tdeui/tdeactionclasses.cpp TDERecentFilesAction::loadEntries
+      
+    TDEConfig* config = kapp->config();
+
+    const TQString oldGroup = config->group();
+    
+    const TQString groupname = "RecentFiles";
+    config->setGroup( groupname );
+    
+        // read file list
+    unsigned int maxItems = mAction.openRecent->maxItems();
+    if ( editor()->openFile() == SDisplayMisc::mostRecent )
+        maxItems = 1;
+    for( unsigned int i = 1 ; i <= maxItems ; i++ )
+    {
+        const TQString key = TQString( "File%1" ).arg( i );
+        const TQString value = config->readPathEntry( key );
+    
+        if (!value.isEmpty())
+        {
+            mStartupFileList.append( value );
+            mStartupOffsetList.append( "0" ); // ### TODO find a way to still have kept offsets
+        }
+    }
+
+    config->setGroup( oldGroup );
+
+  }  
+  
+  //
+  // Open file(s) after editor has been displayed.
+  // Main reason: If anything goes wrong and an error dialog box
+  // is displayed, then the editor will not be visible until the error
+  // is confirmed and the (modal) dialog is closed.
+  //
+  TQTimer::singleShot( 100, TQT_TQOBJECT(this), TQT_SLOT(delayedStartupOpen()) );
+}
+
+
+void KHexEdit::delayedStartupOpen( void )
+{
+  open( mStartupFileList, mStartupOffsetList );
+  mStartupFileList.clear();
+  mStartupOffsetList.clear();
+}
+
+
+void KHexEdit::statusBarPressed( int id )
+{
+  if( id == status_WriteProtect )
+  {
+    editor()->toggleWriteProtection();
+  }
+  else if( id == status_Ovr )
+  {
+    editor()->toggleInsertMode();
+  }
+  else if( id == status_Offset )
+  {
+    editor()->toggleOffsetAsDecimal();
+  }
+  else if( id == status_Selection )
+  {
+    if( mSelectionSize > 0 )
+    {
+      mSelectionAsHexadecimal = mSelectionAsHexadecimal == true ? false : true;
+      setSelectionText( mSelectionOffset, mSelectionSize );
+    }
+  }
+
+}
+
+
+
+void KHexEdit::open( TQStringList &fileList, TQStringList &offsetList )
+{
+  //
+  // We load in reverse to allow the first document in
+  // the list to become the active one.
+  //
+
+  uint offset;
+  for( uint i = fileList.count(); i>0; i-- )
+  {
+    if( i <= offsetList.count() )
+    {
+      offset = (*offsetList.at(i-1)).toUInt(0,16);
+    }
+    else
+    {
+      offset = 0;
+    }
+    editor()->open( *fileList.at(i-1), true, offset );
+  }
+}
+
+void KHexEdit::addRecentFile( const TQString &fileName )
+{
+  if( fileName.isEmpty() == true )
+  {
+    return;
+  }
+
+  if( fileName.contains( i18n( "Untitled" ), false ) )
+  {
+    return;
+  }
+
+  const KURL url( KURL::fromPathOrURL( fileName ) );
+  kdDebug(1501) << k_funcinfo << " adding recent " << fileName << " => " << url.prettyURL() << endl;
+  mAction.openRecent->addURL( url );
+
+}
+
+
+void KHexEdit::removeRecentFile( const TQString &fileName )
+{
+  if( fileName.isEmpty() == true )
+  {
+    return;
+  }
+
+  if( fileName.contains( i18n( "Untitled" ), false ) )
+  {
+    return;
+  }
+
+  const KURL url( KURL::fromPathOrURL( fileName ) );
+  mAction.openRecent->removeURL( url );
+
+}
+
+
+void KHexEdit::renameRecentFile(const TQString &curName, const TQString &newName)
+{
+  if( curName.contains( i18n( "Untitled" ), false ) )
+  {
+    addRecentFile( newName );
+  }
+  else
+  {
+      mAction.openRecent->removeURL( KURL::fromPathOrURL( curName ) );
+      mAction.openRecent->addURL( KURL::fromPathOrURL( newName ) );
+  }
+}
+
+
+
+void KHexEdit::slotFileOpenRecent( const KURL& url )
+{
+  if ( url.isLocalFile() )
+  {
+    editor()->open( url.path(), false, 0 );
+  }
+  else
+  {
+    // ### TODO: support network transparency
+    KMessageBox::error( this, i18n("Non local recent file: %1").arg( url.prettyURL() ) );
+  }
+}
+
+
+KHexEdit *KHexEdit::newWindow( void )
+{
+  KHexEdit *hexEdit = new KHexEdit;
+  if( hexEdit == 0 )
+  {
+    TQString msg = i18n( "Can not create new window.\n" );
+    msg += hexError( Err_NoMemory );
+    KMessageBox::error( topLevelWidget(), msg );
+    return(0);
+  }
+  hexEdit->show();
+  return(hexEdit);
+}
+
+
+
+void KHexEdit::pasteNewWindow( void )
+{
+  KHexEdit *app = newWindow();
+  if( app != 0 )
+  {
+    app->editor()->pasteNewFile();
+  }
+}
+
+
+
+void KHexEdit::closeWindow( void )
+{
+  close();
+}
+
+
+void KHexEdit::closeProgram( void )
+{
+  if( mWindowList.count() > 1 )
+  {
+    for( KHexEdit *w = mWindowList.first(); w != 0; w = mWindowList.next() )
+    {
+      if( w->editor()->modified() == true )
+      {
+	TQString msg = i18n(""
+	  "There are windows with unsaved modified documents. "
+	  "If you quit now, these modifications will be lost.");
+	int reply = KMessageBox::warningContinueCancel( topLevelWidget(), msg, TQString(), KStdGuiItem::quit() );
+	if( reply == KMessageBox::Continue )
+	{
+	  break;
+	}
+	else
+	{
+	  return;
+	}
+      }
+    }
+
+
+    //
+    // Ths will write current configuration to disk.
+    //
+    queryExit();
+
+    //
+    // Make sure every widget is destroyed. The reason why I do this
+    // (besides it is the clean way to do it) is to make sure any
+    // configuration updates in the various destructors are triggered.
+    //
+    mWindowList.setAutoDelete(true);
+    while( mWindowList.first() )
+    {
+      mWindowList.removeRef( mWindowList.first() );
+    }
+
+    kapp->quit();
+  }
+  else
+  {
+    closeWindow();
+  }
+
+}
+
+
+bool KHexEdit::queryClose( void )
+{
+  bool success = editor()->closeAll();
+  if( success == true )
+  {
+    mWindowList.removeRef( this );
+  }
+
+  return( success );
+}
+
+
+//
+// We will always return true here.
+//
+bool KHexEdit::queryExit( void )
+{
+  writeConfiguration();
+  return( true );
+}
+
+void KHexEdit::readConfiguration( void )
+{
+  TDEConfig &config = *kapp->config();
+  readConfiguration( config );
+}
+
+
+void KHexEdit::writeConfiguration( void )
+{
+  TDEConfig &config = *kapp->config();
+  writeConfiguration( config );
+}
+
+
+void KHexEdit::writeConfiguration( TDEConfig &config )
+{
+    saveMainWindowSettings(& config, "General Options");
+  config.setGroup("General Options" );
+  config.writeEntry("ShowFullPath",  mShowFullPath );
+  config.writeEntry("ConversionPosition", (int)mManager->conversionPosition());
+  config.writeEntry("TabBarPosition", (int)mManager->tabBarPosition());
+  config.writeEntry("SearchBarPosition", (int)mManager->searchBarPosition());
+
+  if ( editor()->discardRecentFiles() )
+      mAction.openRecent->clearURLList();
+  mAction.openRecent->saveEntries( &config );
+  
+  converter()->writeConfiguration( config );
+  editor()->writeConfiguration( config );
+
+  config.sync();
+}
+
+
+void KHexEdit::readConfiguration( TDEConfig &config )
+{
+    applyMainWindowSettings(& config, "General Options");
+
+    config.setGroup("General Options");
+  mShowFullPath   = config.readBoolEntry( "ShowFullPath", true );
+  int position    = config.readNumEntry( "ConversionPosition",
+					 CHexManagerWidget::Embed );
+
+  mAction.conversionHide->blockSignals(true);
+  mAction.conversionFloat->blockSignals(true);
+  mAction.conversionEmbed->blockSignals(true);
+  mAction.conversionHide->setChecked(
+    position == CHexManagerWidget::Hide );
+  mAction.conversionFloat->setChecked(
+    position == CHexManagerWidget::Float );
+  mAction.conversionEmbed->setChecked(
+    position == CHexManagerWidget::Embed );
+  mAction.conversionHide->blockSignals(false);
+  mAction.conversionFloat->blockSignals(false);
+  mAction.conversionEmbed->blockSignals(false);
+  showConversionField();
+
+  position = config.readNumEntry( "TabBarPosition", CHexManagerWidget::Hide );
+  mAction.tabHide->blockSignals(true);
+  mAction.tabShowAboveEditor->blockSignals(true);
+  mAction.tabShowBelowEditor->blockSignals(true);
+  mAction.tabHide->setChecked(
+    position==CHexManagerWidget::Hide );
+  mAction.tabShowAboveEditor->setChecked(
+    position==CHexManagerWidget::AboveEditor );
+  mAction.tabShowBelowEditor->setChecked(
+    position==CHexManagerWidget::BelowEditor );
+  mAction.tabHide->blockSignals(false);
+  mAction.tabShowAboveEditor->blockSignals(false);
+  mAction.tabShowBelowEditor->blockSignals(false);
+  showDocumentTabs();
+
+  position = config.readNumEntry( "SearchBarPosition",
+				  CHexManagerWidget::BelowEditor );
+  mAction.searchHide->blockSignals(true);
+  mAction.searchShowAboveEditor->blockSignals(true);
+  mAction.searchShowBelowEditor->blockSignals(true);
+  mAction.searchHide->setChecked(
+    position==CHexManagerWidget::Hide );
+  mAction.searchShowAboveEditor->setChecked(
+    position==CHexManagerWidget::AboveEditor );
+  mAction.searchShowBelowEditor->setChecked(
+    position==CHexManagerWidget::BelowEditor );
+  mAction.searchHide->blockSignals(false);
+  mAction.searchShowAboveEditor->blockSignals(false);
+  mAction.searchShowBelowEditor->blockSignals(false);
+  showSearchBar();
+
+  mAction.openRecent->loadEntries( &config );
+
+  converter()->readConfiguration( config );
+  editor()->readConfiguration( config );
+}
+
+
+
+void KHexEdit::operationChanged( bool state )
+{
+  mAction.cancel->setEnabled( state );
+}
+
+
+
+void KHexEdit::cursorChanged( SCursorState &state )
+{
+  TQString offset( i18n("Offset:") );
+
+  if( state.valid == false )
+  {
+    statusBar()->changeItem( offset, status_Offset );
+  }
+  else
+  {
+    SDisplayLayout &layout = editor()->layout();
+
+    if( layout.offsetMode == SDisplayLayout::hexadecimal )
+    {
+      if( layout.offsetUpperCase == false )
+      {
+	offset += TQString().sprintf( " %04x:%04x-%u", state.offset>>16,
+				     state.offset&0x0000FFFF, state.cell );
+      }
+      else
+      {
+	offset += TQString().sprintf( " %04X:%04X-%u", state.offset>>16,
+				     state.offset&0x0000FFFF, state.cell );
+      }
+    }
+    else
+    {
+      offset += TQString().sprintf( " %010u-%u", state.offset, state.cell );
+    }
+    statusBar()->changeItem( offset, status_Offset );
+  }
+
+  setUndoState( state.undoState );
+  setSelectionState( state.selectionOffset, state.selectionSize );
+}
+
+
+
+
+void KHexEdit::fileState( SFileState &state )
+{
+  if( state.valid == true )
+  {
+    statusBar()->changeItem( i18n("Size: %1").arg( state.size ), status_Size);
+    statusBar()->changeItem( state.modified ? "!" : "", status_Modified);
+
+    if( mIsModified != state.modified )
+    {
+      mIsModified = state.modified;
+      setupCaption( hexView()->url() );
+    }
+
+  }
+  else
+  {
+    statusBar()->changeItem( "", status_Size );
+    statusBar()->changeItem( "", status_Modified );
+  }
+}
+
+
+
+void KHexEdit::layoutChanged( const SDisplayLayout &layout )
+{
+  TDERadioAction *radioAction;
+
+  if( layout.primaryMode == SDisplayLayout::hexadecimal )
+  {
+    radioAction = mAction.hexadecimal;
+  }
+  else if( layout.primaryMode == SDisplayLayout::decimal )
+  {
+    radioAction = mAction.decimal;
+  }
+  else if( layout.primaryMode == SDisplayLayout::octal )
+  {
+    radioAction = mAction.octal;
+  }
+  else if( layout.primaryMode == SDisplayLayout::binary )
+  {
+    radioAction = mAction.binary;
+  }
+  else
+  {
+    radioAction = mAction.textOnly;
+  }
+  radioAction->blockSignals(true);
+  radioAction->setChecked( true );
+  radioAction->blockSignals(false);
+
+  mAction.showOffsetColumn->blockSignals(true);
+  mAction.showTextColumn->blockSignals(true);
+  mAction.offsetAsDecimal->blockSignals(true);
+  mAction.dataUppercase->blockSignals(true);
+  mAction.offsetUppercase->blockSignals(true);
+
+  mAction.showOffsetColumn->setChecked( layout.offsetVisible );
+  mAction.showTextColumn->setEnabled(
+    layout.primaryMode != SDisplayLayout::textOnly );
+  mAction.showTextColumn->setChecked(
+    layout.secondaryMode != SDisplayLayout::hide );
+  mAction.offsetAsDecimal->setChecked(
+    layout.offsetMode != SDisplayLayout::hexadecimal);
+  mAction.dataUppercase->setChecked( layout.primaryUpperCase );
+  mAction.offsetUppercase->setChecked( layout.offsetUpperCase );
+
+  mAction.showOffsetColumn->blockSignals(false);
+  mAction.showTextColumn->blockSignals(false);
+  mAction.offsetAsDecimal->blockSignals(false);
+  mAction.dataUppercase->blockSignals(false);
+  mAction.offsetUppercase->blockSignals(false);
+
+  if( layout.primaryMode == SDisplayLayout::hexadecimal )
+  {
+    statusBar()->changeItem( i18n("Hex"), status_Layout );
+  }
+  else if( layout.primaryMode == SDisplayLayout::decimal )
+  {
+    statusBar()->changeItem( i18n("Dec"), status_Layout );
+  }
+  else if( layout.primaryMode == SDisplayLayout::octal )
+  {
+    statusBar()->changeItem( i18n("Oct"), status_Layout );
+  }
+  else if( layout.primaryMode == SDisplayLayout::binary )
+  {
+    statusBar()->changeItem( i18n("Bin"), status_Layout );
+  }
+  else if( layout.primaryMode == SDisplayLayout::textOnly )
+  {
+    statusBar()->changeItem( i18n("Txt"), status_Layout );
+  }
+}
+
+
+void KHexEdit::inputModeChanged( const SDisplayInputMode &mode )
+{
+  mAction.readOnly->blockSignals(true);
+  mAction.resizeLock->blockSignals(true);
+  mAction.readOnly->setChecked( mode.readOnly );
+  mAction.resizeLock->setChecked( mode.allowResize );
+  mAction.readOnly->blockSignals(false);
+  mAction.resizeLock->blockSignals(false);
+
+  statusBar()->changeItem( mode.readOnly == true ?
+			   i18n("R") : i18n("RW"), status_WriteProtect );
+
+  if( mode.readOnly == false )
+  {
+    mWriteProtectButton->setIcon("edit");
+  }
+  else
+  {
+    mWriteProtectButton->setIcon("system-lock-screen");
+  }
+}
+
+
+void KHexEdit::bookmarkChanged( TQPtrList<SCursorOffset> &list )
+{
+  unplugActionList("bookmark_list");
+  mAction.bookmarkList.setAutoDelete(true);
+  mAction.bookmarkList.clear();
+
+  if( list.count() == 0 )
+  {
+    return;
+  }
+
+  mAction.bookmarkList.append(new TDEActionSeparator());
+
+  TQString text, offset;
+  int i=0;
+
+  for( SCursorOffset *p=list.first(); p!=0; p=list.next(), i++ )
+  {
+    offset.sprintf("%04X:%04X", p->offset>>16, p->offset&0x0000FFFF );
+    text = i18n("Offset: %1").arg(offset);
+    TDEAction *action = new TDEAction(text, 0, mAction.bookmarkMapper, TQT_SLOT(map()), TQT_TQOBJECT(this), text.latin1());
+    int key = acceleratorNumKey( i );
+    if( key > 0 )
+    {
+      action->setShortcut(TDEShortcut(ALT+key));
+    }
+    mAction.bookmarkMapper->setMapping(action, i);
+    mAction.bookmarkList.append(action);
+  }
+  plugActionList("bookmark_list", mAction.bookmarkList);
+}
+
+
+void KHexEdit::setupCaption( const TQString &url )
+{
+  KURL u(url);
+  if( mShowFullPath == true )
+  {
+    setCaption( u.prettyURL(), hexView()->modified() );
+  }
+  else
+  {
+    setCaption( u.fileName(), hexView()->modified() );
+  }
+}
+
+
+void KHexEdit::fileActive( const TQString &url, bool onDisk )
+{
+  setupCaption( url );
+  mDragLabel->setUrl( url );
+  mDragLabel->setEnabled( onDisk );
+
+  mAction.revert->setEnabled( onDisk );
+
+  if( url.isNull() == false )
+  {
+    addDocument( url );
+    addRecentFile( url );
+    setTickedDocument( url );
+  }
+}
+
+
+void KHexEdit::fileRename( const TQString &curName, const TQString &newName )
+{
+  if( newName.isNull() == true )
+  {
+    return;
+  }
+
+  renameDocument( curName, newName );
+  renameRecentFile( curName, newName );
+  setupCaption( newName );
+  //setCaption( newName );
+}
+
+
+void KHexEdit::fileClosed( const TQString &url )
+{
+  removeDocument( url );
+}
+
+
+void KHexEdit::editMode( CHexBuffer::EEditMode editMode )
+{
+  statusBar()->changeItem( editMode == CHexBuffer::EditReplace ?
+			   i18n("OVR") : i18n("INS"), status_Ovr );
+}
+
+
+void KHexEdit::encodingChanged( const SEncodeState &encodeState )
+{
+  TDERadioAction *radioAction;
+
+  if( encodeState.mode == CConversion::cnvDefault )
+  {
+    radioAction = mAction.defaultEncoding;
+  }
+  else if( encodeState.mode == CConversion::cnvUsAscii )
+  {
+    radioAction = mAction.usAsciiEncoding;
+  }
+  else if( encodeState.mode == CConversion::cnvEbcdic )
+  {
+    radioAction = mAction.ebcdicEncoding;
+  }
+  else
+  {
+    return;
+  }
+
+  radioAction->blockSignals(true);
+  radioAction->setChecked( true );
+  radioAction->blockSignals(false);
+
+  if( mSelectionSize == 0 )
+  {
+    statusBar()->changeItem( i18n("Encoding: %1").arg(encodeState.name),
+			     status_Selection );
+  }
+}
+
+
+void KHexEdit::textWidth( uint )
+{
+  resize( mManager->preferredWidth(), height() );
+}
+
+
+void KHexEdit::setDisplayMode( void )
+{
+  if( mAction.hexadecimal->isChecked() == true )
+  {
+    editor()->setHexadecimalMode();
+  }
+  else if( mAction.decimal->isChecked() == true )
+  {
+    editor()->setDecimalMode();
+  }
+  else if( mAction.octal->isChecked() == true )
+  {
+    editor()->setOctalMode();
+  }
+  else if( mAction.binary->isChecked() == true )
+  {
+    editor()->setBinaryMode();
+  }
+  else if( mAction.textOnly->isChecked() == true )
+  {
+    editor()->setTextMode();
+  }
+}
+
+
+void KHexEdit::showFullPath( void )
+{
+  mShowFullPath = mAction.showFullPath->isChecked();
+  setupCaption( hexView()->url() );
+}
+
+
+void KHexEdit::showDocumentTabs( void )
+{
+  if( mAction.tabHide->isChecked() == true )
+  {
+    mManager->setTabBarPosition( CHexManagerWidget::HideItem );
+  }
+  else if( mAction.tabShowAboveEditor->isChecked() == true )
+  {
+    mManager->setTabBarPosition( CHexManagerWidget::AboveEditor );
+  }
+  else if( mAction.tabShowBelowEditor->isChecked() == true )
+  {
+    mManager->setTabBarPosition( CHexManagerWidget::BelowEditor );
+  }
+}
+
+
+void KHexEdit::showConversionField( void )
+{
+  if( mAction.conversionHide->isChecked() == true )
+  {
+    mManager->setConversionVisibility( CHexManagerWidget::Hide );
+  }
+  else if( mAction.conversionFloat->isChecked() == true )
+  {
+    mManager->setConversionVisibility( CHexManagerWidget::Float );
+  }
+  else if( mAction.conversionEmbed->isChecked() == true )
+  {
+    mManager->setConversionVisibility( CHexManagerWidget::Embed );
+    if( width() < mManager->preferredWidth() )
+    {
+      resize( mManager->preferredWidth(), height() );
+    }
+  }
+}
+
+
+void KHexEdit::showSearchBar( void )
+{
+  if( mAction.searchHide->isChecked() == true )
+  {
+    mManager->setSearchBarPosition( CHexManagerWidget::HideItem );
+  }
+  else if( mAction.searchShowAboveEditor->isChecked() == true )
+  {
+    mManager->setSearchBarPosition( CHexManagerWidget::AboveEditor );
+  }
+  else if( mAction.searchShowBelowEditor->isChecked() == true )
+  {
+    mManager->setSearchBarPosition( CHexManagerWidget::BelowEditor );
+  }
+}
+
+
+void KHexEdit::setEncoding( void )
+{
+  if( mAction.defaultEncoding->isChecked() == true )
+  {
+    editor()->encode( CConversion::cnvDefault );
+  }
+  else if( mAction.usAsciiEncoding->isChecked() == true )
+  {
+    editor()->encode( CConversion::cnvUsAscii );
+  }
+  else if( mAction.ebcdicEncoding->isChecked() == true )
+  {
+    editor()->encode( CConversion::cnvEbcdic );
+  }
+}
+
+
+void KHexEdit::setUndoState( uint undoState )
+{
+  if( mUndoState != undoState )
+  {
+    mUndoState = undoState;
+    mAction.undo->setEnabled( mUndoState & CHexBuffer::UndoOk );
+    mAction.redo->setEnabled( mUndoState & CHexBuffer::RedoOk );
+  }
+}
+
+
+void KHexEdit::setSelectionState( uint selectionOffset, uint selectionSize )
+{
+  if( mSelectionSize != selectionSize )
+  {
+    mSelectionOffset = selectionOffset;
+    mSelectionSize   = selectionSize;
+
+    bool valid = mSelectionSize > 0 ? true : false;
+    mAction.copy->setEnabled( valid );
+    mAction.cut->setEnabled( valid );
+    mAction.copyAsText->setEnabled( valid );
+
+    setSelectionText( selectionOffset, selectionSize );
+  }
+}
+
+
+void KHexEdit::setSelectionText( uint selectionOffset, uint selectionSize )
+{
+  if( selectionSize > 0 )
+  {
+    TQString selection = i18n("Selection:");
+    if( mSelectionAsHexadecimal == true )
+    {
+      selection += TQString().sprintf( " %04x:%04x %04x:%04x",
+        selectionOffset>>16, selectionOffset&0x0000FFFF,
+        selectionSize>>16, selectionSize&0x0000FFFF );
+    }
+    else
+    {
+      selection += TQString().sprintf( " %08u %08u",
+        selectionOffset, selectionSize);
+    }
+    statusBar()->changeItem( selection, status_Selection );
+  }
+  else
+  {
+    statusBar()->changeItem(
+      i18n("Encoding: %1").arg(hexView()->encoding().name), status_Selection);
+  }
+}
+
+
+void KHexEdit::documentMenuCB( int index )
+{
+  if( (uint)index < mDocumentList.count() )
+  {
+    editor()->open( mDocumentList[index], false, 0 );
+  }
+}
+
+
+void KHexEdit::addDocument( const TQString &fileName )
+{
+  uint documentCount = mDocumentList.count();
+  for( uint i=0; i < documentCount; i++ )
+  {
+    if( fileName == mDocumentList[i] )
+    {
+      return;
+    }
+  }
+
+  mDocumentList.append( fileName );
+
+  TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
+  documentMenu->insertItem( fileName, documentCount, documentCount );
+  int key = acceleratorNumKey( documentCount );
+  if( key > 0 )
+  {
+    documentMenu->setAccel( CTRL+key, documentCount );
+  }
+}
+
+
+void KHexEdit::removeDocument( const TQString &fileName )
+{
+  TQStringList::Iterator it;
+  for( it = mDocumentList.begin(); it != mDocumentList.end(); it++ )
+  {
+    if( *it == fileName )
+    {
+      TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
+
+      documentMenu->removeItemAt( mDocumentList.findIndex(*it) );
+      mDocumentList.remove( it );
+
+      for( uint i=0; i < mDocumentList.count(); i++ )
+      {
+	documentMenu->setId( i, i );
+	int key = acceleratorNumKey( i );
+	if( key > 0 )
+	{
+	  documentMenu->setAccel( CTRL+key, i );
+	}
+      }
+      return;
+
+    }
+  }
+}
+
+
+void KHexEdit::renameDocument( const TQString &curName, const TQString &newName )
+{
+  TQStringList::Iterator it;
+  for( it = mDocumentList.begin(); it != mDocumentList.end(); it++ )
+  {
+    if( *it == curName )
+    {
+      TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
+      documentMenu->changeItem( newName, mDocumentList.findIndex(*it) );
+      mDocumentList.insert( it, newName );
+      mDocumentList.remove( it );
+      return;
+    }
+  }
+}
+
+
+void KHexEdit::setTickedDocument( const TQString &fileName )
+{
+  uint documentCount = mDocumentList.count();
+  TQPopupMenu *documentMenu = (TQPopupMenu *)factory()->container("documents", this);
+  for( uint i=0; i < documentCount; i++ )
+  {
+    documentMenu->setItemChecked( i, fileName == mDocumentList[i] );
+  }
+}
+
+
+void KHexEdit::conversionClosed( void )
+{
+  mAction.conversionHide->setChecked(true);
+}
+
+
+void KHexEdit::searchBarClosed( void )
+{
+  mAction.searchHide->setChecked(true);
+}
+
+
+bool KHexEdit::eventFilter( TQObject *o, TQEvent *event )
+{
+  if( event->type() == TQEvent::DragEnter )
+  {
+    TQDragEnterEvent *e = (TQDragEnterEvent*)event;
+    if( KURLDrag::canDecode(e) )
+    {
+      e->accept();
+      hexView()->setDropHighlight( true );
+    }
+    return( true );
+  }
+  else if( event->type() == TQEvent::Drop )
+  {
+    TQMimeSource &m = *(TQDropEvent*)event;
+    hexView()->setDropHighlight( false );
+
+    KURL::List list;
+    if( KURLDrag::decode( &m, list ) == true )
+    {
+      TQStringList offset;
+      TQStringList urlList = list.toStringList();
+      open( urlList, offset );
+      return( true );
+    }
+    return( true );
+  }
+  else if( event->type() == TQEvent::DragLeave )
+  {
+    hexView()->setDropHighlight( false );
+    return( true );
+  }
+
+  return TDEMainWindow::eventFilter( o, event );
+}
+
+
+int KHexEdit::acceleratorNumKey( uint index )
+{
+  static int keys[9] =
+  {
+    Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9
+  };
+  return( index >= 9 ? -1 : keys[index] );
+}
+
+
+#include <sys/time.h>
+#include <unistd.h>
+
+//
+// This function is used to test twin performance
+//
+void KHexEdit::resizeTest()
+{
+  struct timeval t1, t2;
+  gettimeofday( &t1, 0 );
+
+  int loop=400;
+
+  for( int i=0; i<loop; i+=4 )
+  {
+    resize( i+400, i+400 );
+    //kapp->processOneEvent();
+  }
+
+  gettimeofday( &t2, 0 );
+  uint last = (t2.tv_sec-t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
+
+  kdDebug(1501) << "Duration: " << (float)last/ 1000000.0 <<  endl;
+  kdDebug(1501) << "Duration/loop: " << (float)last/ (1000000.0*(float)loop) << endl;
+}
+#include "toplevel.moc"
diff --git a/klaptopdaemon/CMakeLists.txt b/klaptopdaemon/CMakeLists.txt
index b7b4d72b..6ce141be 100644
--- a/klaptopdaemon/CMakeLists.txt
+++ b/klaptopdaemon/CMakeLists.txt
@@ -71,7 +71,7 @@ tde_add_kpart( kcm_laptop AUTOMOC
 
 tde_add_kpart( kded_klaptopdaemon AUTOMOC
   SOURCES laptop_daemon.cpp kpcmcia.cpp 
-    xautolock.cc kpcmciainfo.cpp daemondock.cpp
+    xautolock.cpp kpcmciainfo.cpp daemondock.cpp
     xautolock_diy.c xautolock_engine.c
     laptop_daemon.skel
   LINK tdeio-shared kcmlaptop-shared 
diff --git a/klaptopdaemon/Makefile.am b/klaptopdaemon/Makefile.am
index a6ba560b..f03981eb 100644
--- a/klaptopdaemon/Makefile.am
+++ b/klaptopdaemon/Makefile.am
@@ -7,7 +7,7 @@ libkcmlaptop_la_SOURCES = portable.cpp smapidev.c daemon_state.cpp wake_laptop.c
 libkcmlaptop_la_LDFLAGS = $(all_libraries) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor
 libkcmlaptop_la_LIBADD  = $(LIB_TDEUI) 
 
-MESSAGE_SOURCES = laptop_daemon.cpp kpcmcia.cpp xautolock.cc kpcmciainfo.cpp daemondock.cpp xautolock_diy.c xautolock_engine.c
+MESSAGE_SOURCES = laptop_daemon.cpp kpcmcia.cpp xautolock.cpp kpcmciainfo.cpp daemondock.cpp xautolock_diy.c xautolock_engine.c
 kded_klaptopdaemon_la_SOURCES = $(MESSAGE_SOURCES) laptop_daemon.skel  
 kded_klaptopdaemon_la_LDFLAGS = $(all_libraries) -module -avoid-version  -lXtst $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor
 kded_klaptopdaemon_la_LIBADD   = $(LIB_TDEUI) $(LIB_XSS) libkcmlaptop.la
diff --git a/klaptopdaemon/xautolock.cc b/klaptopdaemon/xautolock.cc
deleted file mode 100644
index 93834afb..00000000
--- a/klaptopdaemon/xautolock.cc
+++ /dev/null
@@ -1,277 +0,0 @@
-//----------------------------------------------------------------------------
-//
-// This file is part of the KDE project
-//
-// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
-// Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
-//
-// KDE screensaver engine
-//
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "xautolock.h"
-#include "xautolock.moc"
-
-#include <tdeapplication.h>
-#include <kdebug.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <ctime>
-#include "xautolock_c.h"
-
-#ifdef HAVE_DPMS
-extern "C" {
-#include <X11/Xmd.h>
-#ifndef Bool
-#define Bool BOOL
-#endif
-#include <X11/extensions/dpms.h>
-
-#ifndef HAVE_DPMSINFO_PROTO
-Status DPMSInfo ( Display *, CARD16 *, BOOL * );
-#endif
-}
-#endif
-
-int xautolock_useXidle = 0;
-int xautolock_useMit = 0;
-xautolock_corner_t xautolock_corners[ 4 ];
-
-static XAutoLock* self = NULL;
-
-static int catchFalseAlarms(Display *, XErrorEvent *)
-{
-    return 0;
-}
-
-//===========================================================================
-//
-// Detect user inactivity.
-// Named XAutoLock after the program that it is based on.
-//
-XAutoLock::XAutoLock()
-{
-    self = this;
-    int dummy = 0;
-    dummy = dummy; // shut up
-    xautolock_useXidle = 0;
-    xautolock_useMit = 0;
-#ifdef HAVE_XIDLE
-    useXidle = XidleQueryExtension( tqt_xdisplay(), &dummy, &dummy );
-#endif
-#ifdef HAVE_XSCREENSAVER
-    if( !xautolock_useXidle )
-        xautolock_useMit = XScreenSaverQueryExtension( tqt_xdisplay(), &dummy, &dummy );
-#endif
-    if( !xautolock_useXidle && !xautolock_useMit )
-    {
-        kapp->installX11EventFilter( this );
-        int (*oldHandler)(Display *, XErrorEvent *);
-        oldHandler = XSetErrorHandler(catchFalseAlarms);
-        XSync(tqt_xdisplay(), False );
-        xautolock_initDiy( tqt_xdisplay());
-        XSync(tqt_xdisplay(), False );
-        XSetErrorHandler(oldHandler);
-    }
-
-    mTimeout = DEFAULT_TIMEOUT;
-    mDPMS = true;
-    resetTrigger();
-
-    time(&mLastTimeout);
-    mActive = false;
-
-    mTimerId = startTimer( CHECK_INTERVAL );
-
-}
-
-//---------------------------------------------------------------------------
-//
-// Destructor.
-//
-XAutoLock::~XAutoLock()
-{
-  self = NULL;
-}
-
-//---------------------------------------------------------------------------
-//
-// The time in seconds of continuous inactivity.
-//
-void XAutoLock::setTimeout(int t)
-{
-    mTimeout = t;
-    resetTrigger();
-}
-
-void XAutoLock::setDPMS(bool s)
-{
-    mDPMS = s;
-}
-
-//---------------------------------------------------------------------------
-//
-// Start watching Activity
-//
-void XAutoLock::start()
-{
-    resetTrigger();
-    time(&mLastTimeout);
-    mActive = true;
-}
-
-//---------------------------------------------------------------------------
-//
-// Stop watching Activity
-//
-void XAutoLock::stop()
-{
-    mActive = false;
-}
-
-//---------------------------------------------------------------------------
-//
-// Reset the trigger time.
-//
-void XAutoLock::resetTrigger()
-{
-    mTrigger = time(0) + mTimeout;
-}
-
-//---------------------------------------------------------------------------
-//
-// Move the trigger time in order to postpone (repeat) emitting of timeout().
-//
-void XAutoLock::postpone()
-{
-    mTrigger = time(0) + 60; // delay by 60sec
-}
-
-//---------------------------------------------------------------------------
-//
-// Set the remaining time to 't', if it's shorter than already set.
-//
-void XAutoLock::setTrigger( time_t t )
-{
-    if( t < mTrigger )
-        mTrigger = t;
-}
-
-//---------------------------------------------------------------------------
-//
-// Process new windows and check the mouse.
-//
-void XAutoLock::timerEvent(TQTimerEvent *ev)
-{
-    if (ev->timerId() != mTimerId)
-    {
-        return;
-    }
-
-    int (*oldHandler)(Display *, XErrorEvent *) = NULL;
-    if( !xautolock_useXidle && !xautolock_useMit )
-    { // only the diy way needs special X handler
-        XSync( tqt_xdisplay(), False );
-        oldHandler = XSetErrorHandler(catchFalseAlarms);
-    }
-
-    xautolock_processQueue();
-
-    time_t now = time(0);
-    if ((now > mLastTimeout && now - mLastTimeout > TIME_CHANGE_LIMIT) ||
-        (mLastTimeout > now && mLastTimeout - now > TIME_CHANGE_LIMIT+1))
-    {
-        /* the time has changed in one large jump.  This could be because
-           the date was changed, or the machine was suspended.  We'll just
-           reset the triger. */
-        resetTrigger();
-    }
-
-    mLastTimeout = now;
-
-    xautolock_queryIdleTime( tqt_xdisplay());
-    xautolock_queryPointer( tqt_xdisplay());
-
-    if( !xautolock_useXidle && !xautolock_useMit )
-        XSetErrorHandler(oldHandler);
-
-    bool activate = false;
-
-    //kdDebug() << now << " " << mTrigger << endl;
-    if (now >= mTrigger)
-    {
-        resetTrigger();
-        activate = true;
-    }
-
-#ifdef HAVE_DPMS
-    BOOL on;
-    CARD16 state;
-    DPMSInfo( tqt_xdisplay(), &state, &on );
-
-    //kdDebug() << "DPMSInfo " << state << " " << on << endl;
-    // If DPMS is active, it makes XScreenSaverQueryInfo() report idle time
-    // that is always smaller than DPMS timeout (X bug I guess). So if DPMS
-    // saving is active, simply always activate our saving too, otherwise
-    // this could prevent locking from working.
-    if(state == DPMSModeStandby || state == DPMSModeSuspend || state == DPMSModeOff)
-        activate = true;
-    if(!on && mDPMS) {
-        activate = false;
-        resetTrigger();
-    }
-#endif
-    
-#ifdef HAVE_XSCREENSAVER
-    static XScreenSaverInfo* mitInfo = 0;
-    if (!mitInfo) mitInfo = XScreenSaverAllocInfo ();
-    if (XScreenSaverQueryInfo (tqt_xdisplay(), DefaultRootWindow (tqt_xdisplay()), mitInfo)) {
-        //kdDebug() << "XScreenSaverQueryInfo " << mitInfo->state << " " << ScreenSaverDisabled << endl;
-        if (mitInfo->state == ScreenSaverDisabled)
-	    activate = false;
-    }
-#endif
-
-    if(mActive && activate)
-        emit timeout();
-}
-
-bool XAutoLock::x11Event( XEvent* ev )
-{
-    xautolock_processEvent( ev );
-// don't futher process key events that were received only because XAutoLock wants them
-    if( ev->type == KeyPress && !ev->xkey.send_event
-        && !xautolock_useXidle && !xautolock_useMit
-        && !TQWidget::find( ev->xkey.window ))
-        return true;
-    return false;
-}
-
-bool XAutoLock::ignoreWindow( WId w )
-{
-    if( w != tqt_xrootwin() && TQWidget::find( w ))
-        return true;
-    return false;
-}
-
-extern "C"
-void xautolock_resetTriggers()
-{
-  self->resetTrigger();
-}
-
-extern "C"
-void xautolock_setTrigger( time_t t )
-{
-  self->setTrigger( t );
-}
-
-extern "C"
-int xautolock_ignoreWindow( Window w )
-{
-   return self->ignoreWindow( w );
-}
diff --git a/klaptopdaemon/xautolock.cpp b/klaptopdaemon/xautolock.cpp
new file mode 100644
index 00000000..93834afb
--- /dev/null
+++ b/klaptopdaemon/xautolock.cpp
@@ -0,0 +1,277 @@
+//----------------------------------------------------------------------------
+//
+// This file is part of the KDE project
+//
+// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
+// Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
+//
+// KDE screensaver engine
+//
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "xautolock.h"
+#include "xautolock.moc"
+
+#include <tdeapplication.h>
+#include <kdebug.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <ctime>
+#include "xautolock_c.h"
+
+#ifdef HAVE_DPMS
+extern "C" {
+#include <X11/Xmd.h>
+#ifndef Bool
+#define Bool BOOL
+#endif
+#include <X11/extensions/dpms.h>
+
+#ifndef HAVE_DPMSINFO_PROTO
+Status DPMSInfo ( Display *, CARD16 *, BOOL * );
+#endif
+}
+#endif
+
+int xautolock_useXidle = 0;
+int xautolock_useMit = 0;
+xautolock_corner_t xautolock_corners[ 4 ];
+
+static XAutoLock* self = NULL;
+
+static int catchFalseAlarms(Display *, XErrorEvent *)
+{
+    return 0;
+}
+
+//===========================================================================
+//
+// Detect user inactivity.
+// Named XAutoLock after the program that it is based on.
+//
+XAutoLock::XAutoLock()
+{
+    self = this;
+    int dummy = 0;
+    dummy = dummy; // shut up
+    xautolock_useXidle = 0;
+    xautolock_useMit = 0;
+#ifdef HAVE_XIDLE
+    useXidle = XidleQueryExtension( tqt_xdisplay(), &dummy, &dummy );
+#endif
+#ifdef HAVE_XSCREENSAVER
+    if( !xautolock_useXidle )
+        xautolock_useMit = XScreenSaverQueryExtension( tqt_xdisplay(), &dummy, &dummy );
+#endif
+    if( !xautolock_useXidle && !xautolock_useMit )
+    {
+        kapp->installX11EventFilter( this );
+        int (*oldHandler)(Display *, XErrorEvent *);
+        oldHandler = XSetErrorHandler(catchFalseAlarms);
+        XSync(tqt_xdisplay(), False );
+        xautolock_initDiy( tqt_xdisplay());
+        XSync(tqt_xdisplay(), False );
+        XSetErrorHandler(oldHandler);
+    }
+
+    mTimeout = DEFAULT_TIMEOUT;
+    mDPMS = true;
+    resetTrigger();
+
+    time(&mLastTimeout);
+    mActive = false;
+
+    mTimerId = startTimer( CHECK_INTERVAL );
+
+}
+
+//---------------------------------------------------------------------------
+//
+// Destructor.
+//
+XAutoLock::~XAutoLock()
+{
+  self = NULL;
+}
+
+//---------------------------------------------------------------------------
+//
+// The time in seconds of continuous inactivity.
+//
+void XAutoLock::setTimeout(int t)
+{
+    mTimeout = t;
+    resetTrigger();
+}
+
+void XAutoLock::setDPMS(bool s)
+{
+    mDPMS = s;
+}
+
+//---------------------------------------------------------------------------
+//
+// Start watching Activity
+//
+void XAutoLock::start()
+{
+    resetTrigger();
+    time(&mLastTimeout);
+    mActive = true;
+}
+
+//---------------------------------------------------------------------------
+//
+// Stop watching Activity
+//
+void XAutoLock::stop()
+{
+    mActive = false;
+}
+
+//---------------------------------------------------------------------------
+//
+// Reset the trigger time.
+//
+void XAutoLock::resetTrigger()
+{
+    mTrigger = time(0) + mTimeout;
+}
+
+//---------------------------------------------------------------------------
+//
+// Move the trigger time in order to postpone (repeat) emitting of timeout().
+//
+void XAutoLock::postpone()
+{
+    mTrigger = time(0) + 60; // delay by 60sec
+}
+
+//---------------------------------------------------------------------------
+//
+// Set the remaining time to 't', if it's shorter than already set.
+//
+void XAutoLock::setTrigger( time_t t )
+{
+    if( t < mTrigger )
+        mTrigger = t;
+}
+
+//---------------------------------------------------------------------------
+//
+// Process new windows and check the mouse.
+//
+void XAutoLock::timerEvent(TQTimerEvent *ev)
+{
+    if (ev->timerId() != mTimerId)
+    {
+        return;
+    }
+
+    int (*oldHandler)(Display *, XErrorEvent *) = NULL;
+    if( !xautolock_useXidle && !xautolock_useMit )
+    { // only the diy way needs special X handler
+        XSync( tqt_xdisplay(), False );
+        oldHandler = XSetErrorHandler(catchFalseAlarms);
+    }
+
+    xautolock_processQueue();
+
+    time_t now = time(0);
+    if ((now > mLastTimeout && now - mLastTimeout > TIME_CHANGE_LIMIT) ||
+        (mLastTimeout > now && mLastTimeout - now > TIME_CHANGE_LIMIT+1))
+    {
+        /* the time has changed in one large jump.  This could be because
+           the date was changed, or the machine was suspended.  We'll just
+           reset the triger. */
+        resetTrigger();
+    }
+
+    mLastTimeout = now;
+
+    xautolock_queryIdleTime( tqt_xdisplay());
+    xautolock_queryPointer( tqt_xdisplay());
+
+    if( !xautolock_useXidle && !xautolock_useMit )
+        XSetErrorHandler(oldHandler);
+
+    bool activate = false;
+
+    //kdDebug() << now << " " << mTrigger << endl;
+    if (now >= mTrigger)
+    {
+        resetTrigger();
+        activate = true;
+    }
+
+#ifdef HAVE_DPMS
+    BOOL on;
+    CARD16 state;
+    DPMSInfo( tqt_xdisplay(), &state, &on );
+
+    //kdDebug() << "DPMSInfo " << state << " " << on << endl;
+    // If DPMS is active, it makes XScreenSaverQueryInfo() report idle time
+    // that is always smaller than DPMS timeout (X bug I guess). So if DPMS
+    // saving is active, simply always activate our saving too, otherwise
+    // this could prevent locking from working.
+    if(state == DPMSModeStandby || state == DPMSModeSuspend || state == DPMSModeOff)
+        activate = true;
+    if(!on && mDPMS) {
+        activate = false;
+        resetTrigger();
+    }
+#endif
+    
+#ifdef HAVE_XSCREENSAVER
+    static XScreenSaverInfo* mitInfo = 0;
+    if (!mitInfo) mitInfo = XScreenSaverAllocInfo ();
+    if (XScreenSaverQueryInfo (tqt_xdisplay(), DefaultRootWindow (tqt_xdisplay()), mitInfo)) {
+        //kdDebug() << "XScreenSaverQueryInfo " << mitInfo->state << " " << ScreenSaverDisabled << endl;
+        if (mitInfo->state == ScreenSaverDisabled)
+	    activate = false;
+    }
+#endif
+
+    if(mActive && activate)
+        emit timeout();
+}
+
+bool XAutoLock::x11Event( XEvent* ev )
+{
+    xautolock_processEvent( ev );
+// don't futher process key events that were received only because XAutoLock wants them
+    if( ev->type == KeyPress && !ev->xkey.send_event
+        && !xautolock_useXidle && !xautolock_useMit
+        && !TQWidget::find( ev->xkey.window ))
+        return true;
+    return false;
+}
+
+bool XAutoLock::ignoreWindow( WId w )
+{
+    if( w != tqt_xrootwin() && TQWidget::find( w ))
+        return true;
+    return false;
+}
+
+extern "C"
+void xautolock_resetTriggers()
+{
+  self->resetTrigger();
+}
+
+extern "C"
+void xautolock_setTrigger( time_t t )
+{
+  self->setTrigger( t );
+}
+
+extern "C"
+int xautolock_ignoreWindow( Window w )
+{
+   return self->ignoreWindow( w );
+}
diff --git a/kregexpeditor/CMakeLists.txt b/kregexpeditor/CMakeLists.txt
index 944b6b01..48108d6d 100644
--- a/kregexpeditor/CMakeLists.txt
+++ b/kregexpeditor/CMakeLists.txt
@@ -65,7 +65,7 @@ tde_add_library( kregexpeditorcommon SHARED AUTOMOC
     scrollededitorwindow.cpp compoundwidget.cpp
     singlecontainerwidget.cpp widgetfactory.cpp
     dcbutton.cpp gen_qregexplexer.cpp
-    gen_qregexpparser.cc charselector.cpp
+    gen_qregexpparser.cpp charselector.cpp
     lookaheadregexp.cpp lookaheadwidget.cpp
     regexp.cpp infopage.cpp
     kregexpeditorprivate.cpp compoundregexp.cpp
diff --git a/kregexpeditor/Makefile.am b/kregexpeditor/Makefile.am
index ff9acd02..b13c00c9 100644
--- a/kregexpeditor/Makefile.am
+++ b/kregexpeditor/Makefile.am
@@ -21,7 +21,7 @@ libkregexpeditorcommon_la_SOURCES = \
   repeatwidget.cpp characterswidget.cpp altnwidget.cpp limitedcharlineedit.cpp  textregexp.cpp textrangeregexp.cpp  \
   concregexp.cpp altnregexp.cpp positionregexp.cpp  dotregexp.cpp repeatregexp.cpp textwidget.cpp                   \
   selectablelineedit.cpp multicontainerwidget.cpp  scrollededitorwindow.cpp compoundwidget.cpp                      \
-  singlecontainerwidget.cpp widgetfactory.cpp  dcbutton.cpp gen_qregexplexer.cpp gen_qregexpparser.cc               \
+  singlecontainerwidget.cpp widgetfactory.cpp  dcbutton.cpp gen_qregexplexer.cpp gen_qregexpparser.cpp               \
   charselector.cpp lookaheadregexp.cpp lookaheadwidget.cpp  regexp.cpp infopage.cpp kregexpeditorprivate.cpp        \
   compoundregexp.cpp auxbuttons.cpp  myfontmetrics.cpp regexpbuttons.cpp userdefinedregexps.cpp verifier.cpp        \
   verifybuttons.cpp errormap.cpp qtregexphighlighter.cpp regexpconverter.cpp qtregexpconverter.cpp \
@@ -58,7 +58,7 @@ xdg_apps_DATA = kregexpeditor.desktop
 .PHONY: parser
 parser:
 	cd $(srcdir) && flex -Pqregexp -ogen_qregexplexer.cpp qregexpparser.l
-	cd $(srcdir) && bison -d -p qregexp -o gen_qregexpparser.cc qregexpparser.y
+	cd $(srcdir) && bison -d -p qregexp -o gen_qregexpparser.cpp qregexpparser.y
 
 messages:
 	perl extractrc-from-regexp `find . -name "*.regexp"` > predefined-regexps.cpp
diff --git a/kregexpeditor/gen_qregexplexer.cpp b/kregexpeditor/gen_qregexplexer.cpp
index b943814f..172dd8eb 100644
--- a/kregexpeditor/gen_qregexplexer.cpp
+++ b/kregexpeditor/gen_qregexplexer.cpp
@@ -453,7 +453,7 @@ char *yytext;
 #line 21 "qregexpparser.l"
   #include <tqstring.h>
   #include "textrangeregexp.h"
-  #include "gen_qregexpparser.hh"
+  #include "gen_qregexpparser.h"
 #ifdef TQT_ONLY
   #include "compat.h"
 #endif
diff --git a/kregexpeditor/gen_qregexpparser.cc b/kregexpeditor/gen_qregexpparser.cc
deleted file mode 100644
index 4fdefbcb..00000000
--- a/kregexpeditor/gen_qregexpparser.cc
+++ /dev/null
@@ -1,1447 +0,0 @@
-/* A Bison parser, made from qregexpparser.y, by GNU bison 1.75.  */
-
-/* Skeleton parser for Yacc-like parsing with Bison,
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
-
-/* As a special exception, when this file is copied by Bison into a
-   Bison output file, you may use that output file without restriction.
-   This special exception was added by the Free Software Foundation
-   in version 1.24 of Bison.  */
-
-/* Written by Richard Stallman by simplifying the original so called
-   ``semantic'' parser.  */
-
-/* All symbols defined below should begin with yy or YY, to avoid
-   infringing on user name space.  This should be done even for local
-   variables, as they might otherwise be expanded by user macros.
-   There are some unavoidable exceptions within include files to
-   define necessary library symbols; they are noted "INFRINGES ON
-   USER NAME SPACE" below.  */
-
-/* Identify Bison output.  */
-#define YYBISON	1
-
-/* Pure parsers.  */
-#define YYPURE	0
-
-/* Using locations.  */
-#define YYLSP_NEEDED 0
-
-/* If NAME_PREFIX is specified substitute the variables and functions
-   names.  */
-#define yyparse qregexpparse
-#define yylex   qregexplex
-#define yyerror qregexperror
-#define yylval  qregexplval
-#define yychar  qregexpchar
-#define yydebug qregexpdebug
-#define yynerrs qregexpnerrs
-
-
-/* Tokens.  */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
-   /* Put the tokens into the symbol table, so that GDB and other debuggers
-      know about them.  */
-   enum yytokentype {
-     TOK_Dot = 258,
-     TOK_Dollar = 259,
-     TOK_Carat = 260,
-     TOK_MagicLeftParent = 261,
-     TOK_PosLookAhead = 262,
-     TOK_NegLookAhead = 263,
-     TOK_LeftParen = 264,
-     TOK_RightParent = 265,
-     TOK_Bar = 266,
-     TOK_Quantifier = 267,
-     TOK_BackRef = 268,
-     TOK_CharClass = 269,
-     TOK_Char = 270,
-     TOK_EscapeChar = 271,
-     TOK_PosWordChar = 272,
-     TOK_PosNonWordChar = 273
-   };
-#endif
-#define TOK_Dot 258
-#define TOK_Dollar 259
-#define TOK_Carat 260
-#define TOK_MagicLeftParent 261
-#define TOK_PosLookAhead 262
-#define TOK_NegLookAhead 263
-#define TOK_LeftParen 264
-#define TOK_RightParent 265
-#define TOK_Bar 266
-#define TOK_Quantifier 267
-#define TOK_BackRef 268
-#define TOK_CharClass 269
-#define TOK_Char 270
-#define TOK_EscapeChar 271
-#define TOK_PosWordChar 272
-#define TOK_PosNonWordChar 273
-
-
-
-
-/* Copy the first part of user declarations.  */
-#line 18 "qregexpparser.y"
-
-#ifdef TQT_ONLY
-  #include "compat.h"
-#else
-  #include <tdelocale.h>
-  #include <tdemessagebox.h>
-#endif
-
-  #include <tqstring.h>
-  #include <stdlib.h>
-
-  #include "regexp.h"
-  #include "textregexp.h"
-  #include "textrangeregexp.h"
-  #include "repeatregexp.h"
-  #include "lookaheadregexp.h"
-  #include "concregexp.h"
-  #include "altnregexp.h"
-  #include "positionregexp.h"
-  #include "dotregexp.h"
-  #include "compoundregexp.h"
-
-  extern int yylex();
-  extern void setParseData( TQString str );
-  int yyerror (const char *);
-  void setParseResult( RegExp* );
-  RegExp* parseTQtRegExp( TQString qstr, bool* ok );
-  static RegExp* parseResult;
-  static int _index;
-
-
-/* Enabling traces.  */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-
-/* Enabling verbose error messages.  */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 0
-#endif
-
-#ifndef YYSTYPE
-#line 49 "qregexpparser.y"
-typedef union {
-  struct {
-    int min;
-    int max;
-  } range;
-  int backRef;
-  RegExp* regexp;
-  char ch;
-} yystype;
-/* Line 193 of /usr/share/bison/yacc.c.  */
-#line 159 "gen_qregexpparser.cc"
-# define YYSTYPE yystype
-# define YYSTYPE_IS_TRIVIAL 1
-#endif
-
-#ifndef YYLTYPE
-typedef struct yyltype
-{
-  int first_line;
-  int first_column;
-  int last_line;
-  int last_column;
-} yyltype;
-# define YYLTYPE yyltype
-# define YYLTYPE_IS_TRIVIAL 1
-#endif
-
-/* Copy the second part of user declarations.  */
-
-
-/* Line 213 of /usr/share/bison/yacc.c.  */
-#line 180 "gen_qregexpparser.cc"
-
-#if ! defined (yyoverflow) || YYERROR_VERBOSE
-
-/* The parser invokes alloca or malloc; define the necessary symbols.  */
-
-# ifdef YYSTACK_USE_ALLOCA
-#  define YYSTACK_ALLOC alloca
-# else
-#  ifndef YYSTACK_USE_ALLOCA
-#   if defined (alloca) || defined (_ALLOCA_H)
-#    define YYSTACK_ALLOC alloca
-#   else
-#    ifdef __GNUC__
-#     define YYSTACK_ALLOC __builtin_alloca
-#    endif
-#   endif
-#  endif
-# endif
-
-# ifdef YYSTACK_ALLOC
-   /* Pacify GCC's `empty if-body' warning. */
-#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
-# else
-#  if defined (__STDC__) || defined (__cplusplus)
-#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-#   define YYSIZE_T size_t
-#  endif
-#  define YYSTACK_ALLOC malloc
-#  define YYSTACK_FREE free
-# endif
-#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
-
-
-#if (! defined (yyoverflow) \
-     && (! defined (__cplusplus) \
-	 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
-
-/* A type that is properly aligned for any stack member.  */
-union yyalloc
-{
-  short yyss;
-  YYSTYPE yyvs;
-  };
-
-/* The size of the maximum gap between one aligned stack and the next.  */
-# define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
-
-/* The size of an array large to enough to hold all stacks, each with
-   N elements.  */
-# define YYSTACK_BYTES(N) \
-     ((N) * (sizeof (short) + sizeof (YYSTYPE))				\
-      + YYSTACK_GAP_MAX)
-
-/* Copy COUNT objects from FROM to TO.  The source and destination do
-   not overlap.  */
-# ifndef YYCOPY
-#  if 1 < __GNUC__
-#   define YYCOPY(To, From, Count) \
-      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
-#  else
-#   define YYCOPY(To, From, Count)		\
-      do					\
-	{					\
-	  YYSIZE_T yyi;		\
-	  for (yyi = 0; yyi < (Count); yyi++)	\
-	    (To)[yyi] = (From)[yyi];	\
-	}					\
-      while (0)
-#  endif
-# endif
-
-/* Relocate STACK from its old location to the new one.  The
-   local variables YYSIZE and YYSTACKSIZE give the old and new number of
-   elements in the stack, and YYPTR gives the new location of the
-   stack.  Advance YYPTR to a properly aligned location for the next
-   stack.  */
-# define YYSTACK_RELOCATE(Stack)					\
-    do									\
-      {									\
-	YYSIZE_T yynewbytes;						\
-	YYCOPY (&yyptr->Stack, Stack, yysize);				\
-	Stack = &yyptr->Stack;						\
-	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX;	\
-	yyptr += yynewbytes / sizeof (*yyptr);				\
-      }									\
-    while (0)
-
-#endif
-
-#if defined (__STDC__) || defined (__cplusplus)
-   typedef signed char yysigned_char;
-#else
-   typedef short yysigned_char;
-#endif
-
-/* YYFINAL -- State number of the termination state. */
-#define YYFINAL  27
-#define YYLAST   47
-
-/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS  19
-/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS  8
-/* YYNRULES -- Number of rules. */
-#define YYNRULES  27
-/* YYNRULES -- Number of states. */
-#define YYNSTATES  36
-
-/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
-#define YYUNDEFTOK  2
-#define YYMAXUTOK   273
-
-#define YYTRANSLATE(X) \
-  ((unsigned)(X) <= YYMAXUTOK ? yytranslate[X] : YYUNDEFTOK)
-
-/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
-static const unsigned char yytranslate[] =
-{
-       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
-       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
-      15,    16,    17,    18
-};
-
-#if YYDEBUG
-/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
-   YYRHS.  */
-static const unsigned char yyprhs[] =
-{
-       0,     0,     3,     4,     6,     8,    12,    14,    17,    20,
-      22,    25,    27,    30,    32,    36,    40,    44,    48,    50,
-      52,    54,    56,    58,    60,    62,    64,    66
-};
-
-/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const yysigned_char yyrhs[] =
-{
-      21,     0,    -1,    -1,    22,    -1,    20,    -1,    22,    11,
-      23,    -1,    23,    -1,    22,    11,    -1,    11,    23,    -1,
-      11,    -1,    23,    24,    -1,    24,    -1,    25,    12,    -1,
-      25,    -1,     9,    22,    10,    -1,     6,    22,    10,    -1,
-       7,    22,    10,    -1,     8,    22,    10,    -1,    14,    -1,
-      26,    -1,     4,    -1,     5,    -1,     3,    -1,    13,    -1,
-      17,    -1,    18,    -1,    15,    -1,    16,    -1
-};
-
-/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
-static const unsigned char yyrline[] =
-{
-       0,    80,    80,    82,    83,    86,    96,    97,   107,   112,
-     115,   129,   136,   139,   142,   145,   146,   149,   152,   153,
-     154,   155,   156,   157,   172,   173,   176,   182
-};
-#endif
-
-#if YYDEBUG || YYERROR_VERBOSE
-/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
-   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
-{
-  "$end", "error", "$undefined", "TOK_Dot", "TOK_Dollar", "TOK_Carat", 
-  "TOK_MagicLeftParent", "TOK_PosLookAhead", "TOK_NegLookAhead", 
-  "TOK_LeftParen", "TOK_RightParent", "TOK_Bar", "TOK_Quantifier", 
-  "TOK_BackRef", "TOK_CharClass", "TOK_Char", "TOK_EscapeChar", 
-  "TOK_PosWordChar", "TOK_PosNonWordChar", "$accept", "empty", "regexp", 
-  "expression", "term", "factor", "atom", "char", 0
-};
-#endif
-
-# ifdef YYPRINT
-/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
-   token YYLEX-NUM.  */
-static const unsigned short yytoknum[] =
-{
-       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
-     265,   266,   267,   268,   269,   270,   271,   272,   273
-};
-# endif
-
-/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
-static const unsigned char yyr1[] =
-{
-       0,    19,    20,    21,    21,    22,    22,    22,    22,    22,
-      23,    23,    24,    24,    25,    25,    25,    25,    25,    25,
-      25,    25,    25,    25,    25,    25,    26,    26
-};
-
-/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
-static const unsigned char yyr2[] =
-{
-       0,     2,     0,     1,     1,     3,     1,     2,     2,     1,
-       2,     1,     2,     1,     3,     3,     3,     3,     1,     1,
-       1,     1,     1,     1,     1,     1,     1,     1
-};
-
-/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
-   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
-   means the default is an error.  */
-static const unsigned char yydefact[] =
-{
-       2,    22,    20,    21,     0,     0,     0,     0,     9,    23,
-      18,    26,    27,    24,    25,     4,     0,     3,     6,    11,
-      13,    19,     0,     0,     0,     0,     8,     1,     7,    10,
-      12,    15,    16,    17,    14,     5
-};
-
-/* YYDEFGOTO[NTERM-NUM]. */
-static const yysigned_char yydefgoto[] =
-{
-      -1,    15,    16,    17,    18,    19,    20,    21
-};
-
-/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
-   STATE-NUM.  */
-#define YYPACT_NINF -18
-static const yysigned_char yypact[] =
-{
-      -1,   -18,   -18,   -18,    -1,    -1,    -1,    -1,    18,   -18,
-     -18,   -18,   -18,   -18,   -18,   -18,    11,     8,    18,   -18,
-      16,   -18,    19,    31,    34,    36,    18,   -18,    18,   -18,
-     -18,   -18,   -18,   -18,   -18,    18
-};
-
-/* YYPGOTO[NTERM-NUM].  */
-static const yysigned_char yypgoto[] =
-{
-     -18,   -18,   -18,    33,    -8,   -17,   -18,   -18
-};
-
-/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
-   positive, shift that token.  If negative, reduce the rule which
-   number is the opposite.  If zero, do what YYDEFACT says.
-   If YYTABLE_NINF, parse error.  */
-#define YYTABLE_NINF -1
-static const unsigned char yytable[] =
-{
-      26,    29,     1,     2,     3,     4,     5,     6,     7,    29,
-       8,    27,     9,    10,    11,    12,    13,    14,    29,    28,
-      35,     1,     2,     3,     4,     5,     6,     7,    30,    31,
-      28,     9,    10,    11,    12,    13,    14,    22,    23,    24,
-      25,    32,    28,     0,    33,    28,    34,    28
-};
-
-static const yysigned_char yycheck[] =
-{
-       8,    18,     3,     4,     5,     6,     7,     8,     9,    26,
-      11,     0,    13,    14,    15,    16,    17,    18,    35,    11,
-      28,     3,     4,     5,     6,     7,     8,     9,    12,    10,
-      11,    13,    14,    15,    16,    17,    18,     4,     5,     6,
-       7,    10,    11,    -1,    10,    11,    10,    11
-};
-
-/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
-   symbol of state STATE-NUM.  */
-static const unsigned char yystos[] =
-{
-       0,     3,     4,     5,     6,     7,     8,     9,    11,    13,
-      14,    15,    16,    17,    18,    20,    21,    22,    23,    24,
-      25,    26,    22,    22,    22,    22,    23,     0,    11,    24,
-      12,    10,    10,    10,    10,    23
-};
-
-#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
-# define YYSIZE_T __SIZE_TYPE__
-#endif
-#if ! defined (YYSIZE_T) && defined (size_t)
-# define YYSIZE_T size_t
-#endif
-#if ! defined (YYSIZE_T)
-# if defined (__STDC__) || defined (__cplusplus)
-#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-#  define YYSIZE_T size_t
-# endif
-#endif
-#if ! defined (YYSIZE_T)
-# define YYSIZE_T unsigned int
-#endif
-
-#define yyerrok		(yyerrstatus = 0)
-#define yyclearin	(yychar = YYEMPTY)
-#define YYEMPTY		-2
-#define YYEOF		0
-
-#define YYACCEPT	goto yyacceptlab
-#define YYABORT		goto yyabortlab
-#define YYERROR		goto yyerrlab1
-
-/* Like YYERROR except do call yyerror.  This remains here temporarily
-   to ease the transition to the new meaning of YYERROR, for GCC.
-   Once GCC version 2 has supplanted version 1, this can go.  */
-
-#define YYFAIL		goto yyerrlab
-
-#define YYRECOVERING()  (!!yyerrstatus)
-
-#define YYBACKUP(Token, Value)					\
-do								\
-  if (yychar == YYEMPTY && yylen == 1)				\
-    {								\
-      yychar = (Token);						\
-      yylval = (Value);						\
-      yychar1 = YYTRANSLATE (yychar);				\
-      YYPOPSTACK;						\
-      goto yybackup;						\
-    }								\
-  else								\
-    { 								\
-      yyerror ("syntax error: cannot back up");			\
-      YYERROR;							\
-    }								\
-while (0)
-
-#define YYTERROR	1
-#define YYERRCODE	256
-
-/* YYLLOC_DEFAULT -- Compute the default location (before the actions
-   are run).  */
-
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)           \
-  Current.first_line   = Rhs[1].first_line;      \
-  Current.first_column = Rhs[1].first_column;    \
-  Current.last_line    = Rhs[N].last_line;       \
-  Current.last_column  = Rhs[N].last_column;
-#endif
-
-/* YYLEX -- calling `yylex' with the right arguments.  */
-
-#define YYLEX	yylex ()
-
-/* Enable debugging if requested.  */
-#if YYDEBUG
-
-# ifndef YYFPRINTF
-#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
-#  define YYFPRINTF fprintf
-# endif
-
-# define YYDPRINTF(Args)			\
-do {						\
-  if (yydebug)					\
-    YYFPRINTF Args;				\
-} while (0)
-# define YYDSYMPRINT(Args)			\
-do {						\
-  if (yydebug)					\
-    yysymprint Args;				\
-} while (0)
-/* Nonzero means print parse trace.  It is left uninitialized so that
-   multiple parsers can coexist.  */
-int yydebug;
-#else /* !YYDEBUG */
-# define YYDPRINTF(Args)
-# define YYDSYMPRINT(Args)
-#endif /* !YYDEBUG */
-
-/* YYINITDEPTH -- initial size of the parser's stacks.  */
-#ifndef	YYINITDEPTH
-# define YYINITDEPTH 200
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
-   if the built-in stack extension method is used).
-
-   Do not make this value too large; the results are undefined if
-   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
-   evaluated with infinite-precision integer arithmetic.  */
-
-#ifdef YYMAXDEPTH == 0
-# undef YYMAXDEPTH
-#endif
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH 10000
-#endif
-
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystrlen
-#  if defined (__GLIBC__) && defined (_STRING_H)
-#   define yystrlen strlen
-#  else
-/* Return the length of YYSTR.  */
-static YYSIZE_T
-#   if defined (__STDC__) || defined (__cplusplus)
-yystrlen (const char *yystr)
-#   else
-yystrlen (yystr)
-     const char *yystr;
-#   endif
-{
-  const char *yys = yystr;
-
-  while (*yys++ != '\0')
-    continue;
-
-  return yys - yystr - 1;
-}
-#  endif
-# endif
-
-# ifndef yystpcpy
-#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
-#   define yystpcpy stpcpy
-#  else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
-   YYDEST.  */
-static char *
-#   if defined (__STDC__) || defined (__cplusplus)
-yystpcpy (char *yydest, const char *yysrc)
-#   else
-yystpcpy (yydest, yysrc)
-     char *yydest;
-     const char *yysrc;
-#   endif
-{
-  char *yyd = yydest;
-  const char *yys = yysrc;
-
-  while ((*yyd++ = *yys++) != '\0')
-    continue;
-
-  return yyd - 1;
-}
-#  endif
-# endif
-
-#endif /* !YYERROR_VERBOSE */
-
-
-
-#if YYDEBUG
-/*-----------------------------.
-| Print this symbol on YYOUT.  |
-`-----------------------------*/
-
-static void
-#if defined (__STDC__) || defined (__cplusplus)
-yysymprint (FILE* yyout, int yytype, YYSTYPE yyvalue)
-#else
-yysymprint (yyout, yytype, yyvalue)
-    FILE* yyout;
-    int yytype;
-    YYSTYPE yyvalue;
-#endif
-{
-  /* Pacify ``unused variable'' warnings.  */
-  (void) yyvalue;
-
-  if (yytype < YYNTOKENS)
-    {
-      YYFPRINTF (yyout, "token %s (", yytname[yytype]);
-# ifdef YYPRINT
-      YYPRINT (yyout, yytoknum[yytype], yyvalue);
-# endif
-    }
-  else
-    YYFPRINTF (yyout, "nterm %s (", yytname[yytype]);
-
-  switch (yytype)
-    {
-      default:
-        break;
-    }
-  YYFPRINTF (yyout, ")");
-}
-#endif /* YYDEBUG. */
-
-
-/*-----------------------------------------------.
-| Release the memory associated to this symbol.  |
-`-----------------------------------------------*/
-
-static void
-#if defined (__STDC__) || defined (__cplusplus)
-yydestruct (int yytype, YYSTYPE yyvalue)
-#else
-yydestruct (yytype, yyvalue)
-    int yytype;
-    YYSTYPE yyvalue;
-#endif
-{
-  /* Pacify ``unused variable'' warnings.  */
-  (void) yyvalue;
-
-  switch (yytype)
-    {
-      default:
-        break;
-    }
-}
-
-
-
-/* The user can define YYPARSE_PARAM as the name of an argument to be passed
-   into yyparse.  The argument should have type void *.
-   It should actually point to an object.
-   Grammar actions can access the variable by casting it
-   to the proper pointer type.  */
-
-#ifdef YYPARSE_PARAM
-# if defined (__STDC__) || defined (__cplusplus)
-#  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
-#  define YYPARSE_PARAM_DECL
-# else
-#  define YYPARSE_PARAM_ARG YYPARSE_PARAM
-#  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
-# endif
-#else /* !YYPARSE_PARAM */
-# define YYPARSE_PARAM_ARG
-# define YYPARSE_PARAM_DECL
-#endif /* !YYPARSE_PARAM */
-
-/* Prevent warning if -Wstrict-prototypes.  */
-#ifdef __GNUC__
-# ifdef YYPARSE_PARAM
-int yyparse (void *);
-# else
-int yyparse (void);
-# endif
-#endif
-
-
-/* The lookahead symbol.  */
-int yychar;
-
-/* The semantic value of the lookahead symbol.  */
-YYSTYPE yylval;
-
-/* Number of parse errors so far.  */
-int yynerrs;
-
-
-int
-yyparse (YYPARSE_PARAM_ARG)
-     YYPARSE_PARAM_DECL
-{
-  
-  int yystate;
-  int yyn;
-  int yyresult;
-  /* Number of tokens to shift before error messages enabled.  */
-  int yyerrstatus;
-  /* Lookahead token as an internal (translated) token number.  */
-  int yychar1 = 0;
-
-  /* Three stacks and their tools:
-     `yyss': related to states,
-     `yyvs': related to semantic values,
-     `yyls': related to locations.
-
-     Refer to the stacks thru separate pointers, to allow yyoverflow
-     to reallocate them elsewhere.  */
-
-  /* The state stack.  */
-  short	yyssa[YYINITDEPTH];
-  short *yyss = yyssa;
-  short *yyssp;
-
-  /* The semantic value stack.  */
-  YYSTYPE yyvsa[YYINITDEPTH];
-  YYSTYPE *yyvs = yyvsa;
-  YYSTYPE *yyvsp;
-
-
-
-#define YYPOPSTACK   (yyvsp--, yyssp--)
-
-  YYSIZE_T yystacksize = YYINITDEPTH;
-
-  /* The variables used to return semantic value and location from the
-     action routines.  */
-  YYSTYPE yyval;
-
-
-  /* When reducing, the number of symbols on the RHS of the reduced
-     rule.  */
-  int yylen;
-
-  YYDPRINTF ((stderr, "Starting parse\n"));
-
-  yystate = 0;
-  yyerrstatus = 0;
-  yynerrs = 0;
-  yychar = YYEMPTY;		/* Cause a token to be read.  */
-
-  /* Initialize stack pointers.
-     Waste one element of value and location stack
-     so that they stay on the same level as the state stack.
-     The wasted elements are never initialized.  */
-
-  yyssp = yyss;
-  yyvsp = yyvs;
-
-  goto yysetstate;
-
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate.  |
-`------------------------------------------------------------*/
- yynewstate:
-  /* In all cases, when you get here, the value and location stacks
-     have just been pushed. so pushing a state here evens the stacks.
-     */
-  yyssp++;
-
- yysetstate:
-  *yyssp = yystate;
-
-  if (yyssp >= yyss + yystacksize - 1)
-    {
-      /* Get the current used size of the three stacks, in elements.  */
-      YYSIZE_T yysize = yyssp - yyss + 1;
-
-#ifdef yyoverflow
-      {
-	/* Give user a chance to reallocate the stack. Use copies of
-	   these so that the &'s don't force the real ones into
-	   memory.  */
-	YYSTYPE *yyvs1 = yyvs;
-	short *yyss1 = yyss;
-
-
-	/* Each stack pointer address is followed by the size of the
-	   data in use in that stack, in bytes.  This used to be a
-	   conditional around just the two extra args, but that might
-	   be undefined if yyoverflow is a macro.  */
-	yyoverflow ("parser stack overflow",
-		    &yyss1, yysize * sizeof (*yyssp),
-		    &yyvs1, yysize * sizeof (*yyvsp),
-
-		    &yystacksize);
-
-	yyss = yyss1;
-	yyvs = yyvs1;
-      }
-#else /* no yyoverflow */
-# ifndef YYSTACK_RELOCATE
-      goto yyoverflowlab;
-# else
-      /* Extend the stack our own way.  */
-      if (yystacksize >= YYMAXDEPTH)
-	goto yyoverflowlab;
-      yystacksize *= 2;
-      if (yystacksize > YYMAXDEPTH)
-	yystacksize = YYMAXDEPTH;
-
-      {
-	short *yyss1 = yyss;
-	union yyalloc *yyptr =
-	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
-	if (! yyptr)
-	  goto yyoverflowlab;
-	YYSTACK_RELOCATE (yyss);
-	YYSTACK_RELOCATE (yyvs);
-
-#  undef YYSTACK_RELOCATE
-	if (yyss1 != yyssa)
-	  YYSTACK_FREE (yyss1);
-      }
-# endif
-#endif /* no yyoverflow */
-
-      yyssp = yyss + yysize - 1;
-      yyvsp = yyvs + yysize - 1;
-
-
-      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
-		  (unsigned long int) yystacksize));
-
-      if (yyssp >= yyss + yystacksize - 1)
-	YYABORT;
-    }
-
-  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-
-  goto yybackup;
-
-/*-----------.
-| yybackup.  |
-`-----------*/
-yybackup:
-
-/* Do appropriate processing given the current state.  */
-/* Read a lookahead token if we need one and don't already have one.  */
-/* yyresume: */
-
-  /* First try to decide what to do without reference to lookahead token.  */
-
-  yyn = yypact[yystate];
-  if (yyn == YYPACT_NINF)
-    goto yydefault;
-
-  /* Not known => get a lookahead token if don't already have one.  */
-
-  /* yychar is either YYEMPTY or YYEOF
-     or a valid token in external form.  */
-
-  if (yychar == YYEMPTY)
-    {
-      YYDPRINTF ((stderr, "Reading a token: "));
-      yychar = YYLEX;
-    }
-
-  /* Convert token to internal form (in yychar1) for indexing tables with.  */
-
-  if (yychar <= 0)		/* This means end of input.  */
-    {
-      yychar1 = 0;
-      yychar = YYEOF;		/* Don't call YYLEX any more.  */
-
-      YYDPRINTF ((stderr, "Now at end of input.\n"));
-    }
-  else
-    {
-      yychar1 = YYTRANSLATE (yychar);
-
-      /* We have to keep this `#if YYDEBUG', since we use variables
-	 which are defined only if `YYDEBUG' is set.  */
-      YYDPRINTF ((stderr, "Next token is "));
-      YYDSYMPRINT ((stderr, yychar1, yylval));
-      YYDPRINTF ((stderr, "\n"));
-    }
-
-  /* If the proper action on seeing token YYCHAR1 is to reduce or to
-     detect an error, take that action.  */
-  yyn += yychar1;
-  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yychar1)
-    goto yydefault;
-  yyn = yytable[yyn];
-  if (yyn <= 0)
-    {
-      if (yyn == 0 || yyn == YYTABLE_NINF)
-	goto yyerrlab;
-      yyn = -yyn;
-      goto yyreduce;
-    }
-
-  if (yyn == YYFINAL)
-    YYACCEPT;
-
-  /* Shift the lookahead token.  */
-  YYDPRINTF ((stderr, "Shifting token %d (%s), ",
-	      yychar, yytname[yychar1]));
-
-  /* Discard the token being shifted unless it is eof.  */
-  if (yychar != YYEOF)
-    yychar = YYEMPTY;
-
-  *++yyvsp = yylval;
-
-
-  /* Count tokens shifted since error; after three, turn off error
-     status.  */
-  if (yyerrstatus)
-    yyerrstatus--;
-
-  yystate = yyn;
-  goto yynewstate;
-
-
-/*-----------------------------------------------------------.
-| yydefault -- do the default action for the current state.  |
-`-----------------------------------------------------------*/
-yydefault:
-  yyn = yydefact[yystate];
-  if (yyn == 0)
-    goto yyerrlab;
-  goto yyreduce;
-
-
-/*-----------------------------.
-| yyreduce -- Do a reduction.  |
-`-----------------------------*/
-yyreduce:
-  /* yyn is the number of a rule to reduce with.  */
-  yylen = yyr2[yyn];
-
-  /* If YYLEN is nonzero, implement the default value of the action:
-     `$$ = $1'.
-
-     Otherwise, the following line sets YYVAL to garbage.
-     This behavior is undocumented and Bison
-     users should not rely upon it.  Assigning to YYVAL
-     unconditionally makes the parser a bit smaller, and it avoids a
-     GCC warning that YYVAL may be used uninitialized.  */
-  yyval = yyvsp[1-yylen];
-
-
-
-#if YYDEBUG
-  /* We have to keep this `#if YYDEBUG', since we use variables which
-     are defined only if `YYDEBUG' is set.  */
-  if (yydebug)
-    {
-      int yyi;
-
-      YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
-		 yyn - 1, yyrline[yyn]);
-
-      /* Print the symbols being reduced, and their result.  */
-      for (yyi = yyprhs[yyn]; yyrhs[yyi] >= 0; yyi++)
-	YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
-      YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
-    }
-#endif
-  switch (yyn)
-    {
-        case 3:
-#line 82 "qregexpparser.y"
-    { setParseResult( yyvsp[0].regexp) ; }
-    break;
-
-  case 4:
-#line 83 "qregexpparser.y"
-    { setParseResult( new ConcRegExp( false ) ); }
-    break;
-
-  case 5:
-#line 86 "qregexpparser.y"
-    {
-               if ( dynamic_cast<AltnRegExp*>( yyvsp[-2].regexp ) ) {
-                 yyval.regexp = yyvsp[-2].regexp;
-               }
-               else {
-                 yyval.regexp = new AltnRegExp( false );
-                 dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[-2].regexp );
-               }
-               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[0].regexp );
-             }
-    break;
-
-  case 6:
-#line 96 "qregexpparser.y"
-    { yyval.regexp = yyvsp[0].regexp; }
-    break;
-
-  case 7:
-#line 97 "qregexpparser.y"
-    { 
-               if ( dynamic_cast<AltnRegExp*>( yyvsp[-1].regexp ) ) {
-                 yyval.regexp = yyvsp[-1].regexp;
-               }
-               else {
-                 yyval.regexp = new AltnRegExp( false );
-                 dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[-1].regexp );
-               }
-               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( new TextRegExp( false, TQString::fromLatin1("") ) );
-             }
-    break;
-
-  case 8:
-#line 107 "qregexpparser.y"
-    {  
-               yyval.regexp = new AltnRegExp( false );
-               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( new TextRegExp( false, TQString::fromLatin1("") ) );
-               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[0].regexp );
-             }
-    break;
-
-  case 9:
-#line 112 "qregexpparser.y"
-    { yyval.regexp = new AltnRegExp( false ); }
-    break;
-
-  case 10:
-#line 115 "qregexpparser.y"
-    {
-       RegExp* last = dynamic_cast<ConcRegExp*>( yyvsp[-1].regexp )->lastRegExp();
-       TextRegExp *reg1, *reg2;
-       
-       if ( last && ( reg1 = dynamic_cast<TextRegExp*>( last ) ) &&
-            ( reg2 = dynamic_cast<TextRegExp*>( yyvsp[0].regexp ) ) ) {
-         reg1->append( reg2->text() );
-         delete reg2;
-       }
-       else {
-         dynamic_cast<ConcRegExp*>(yyval.regexp)->addRegExp( yyvsp[0].regexp );
-       }
-       yyval.regexp = yyvsp[-1].regexp;
-     }
-    break;
-
-  case 11:
-#line 129 "qregexpparser.y"
-    { 
-         ConcRegExp* reg = new ConcRegExp( false );
-         reg->addRegExp( yyvsp[0].regexp );
-         yyval.regexp = reg;
-       }
-    break;
-
-  case 12:
-#line 136 "qregexpparser.y"
-    {
-           yyval.regexp = new RepeatRegExp( false, yyvsp[0].range.min, yyvsp[0].range.max, yyvsp[-1].regexp );
-         }
-    break;
-
-  case 13:
-#line 139 "qregexpparser.y"
-    { yyval.regexp = yyvsp[0].regexp; }
-    break;
-
-  case 14:
-#line 142 "qregexpparser.y"
-    { 
-         yyval.regexp = yyvsp[-1].regexp; 
-       }
-    break;
-
-  case 15:
-#line 145 "qregexpparser.y"
-    { yyval.regexp = yyvsp[-1].regexp; }
-    break;
-
-  case 16:
-#line 146 "qregexpparser.y"
-    { 
-         yyval.regexp = new LookAheadRegExp( false, LookAheadRegExp::POSITIVE, yyvsp[-1].regexp );
-       }
-    break;
-
-  case 17:
-#line 149 "qregexpparser.y"
-    {
-         yyval.regexp = new LookAheadRegExp( false, LookAheadRegExp::NEGATIVE, yyvsp[-1].regexp );
-       }
-    break;
-
-  case 18:
-#line 152 "qregexpparser.y"
-    { yyval.regexp = yyvsp[0].regexp; }
-    break;
-
-  case 19:
-#line 153 "qregexpparser.y"
-    { yyval.regexp = yyvsp[0].regexp; }
-    break;
-
-  case 20:
-#line 154 "qregexpparser.y"
-    { yyval.regexp = new PositionRegExp( false, PositionRegExp::ENDLINE ); }
-    break;
-
-  case 21:
-#line 155 "qregexpparser.y"
-    { yyval.regexp = new PositionRegExp( false, PositionRegExp::BEGLINE ); }
-    break;
-
-  case 22:
-#line 156 "qregexpparser.y"
-    { yyval.regexp = new DotRegExp( false ); }
-    break;
-
-  case 23:
-#line 157 "qregexpparser.y"
-    { 
-        TQString match = TQString(TQString::fromLocal8Bit("\\%1")).arg( yyvsp[0].backRef );
-        yyval.regexp = new TextRegExp( false, match );
-        KMessageBox::information(0,i18n("<qt>Back reference regular expressions are not supported.<p>"
-                                        "<tt>\\1</tt>, <tt>\\2</tt>, ... are <i>back references</i>, meaning they refer to  "
-                                        "previous matches. "
-                                        "Unfortunately this is not supported in the current version of this editor.<p>"
-                                        "In the graphical area the text <b>%1</b> has been inserted. This is however "
-                                        "just a workaround to ensure that the application handles the regexp at all. "
-                                        "Therefore, as soon as you edit the regular expression in the graphical area, "
-                                        "the back reference will be replaced by matching the text <b>%2</b> literally.")
-                                    .arg( match ).arg( match ),
-                                 i18n("Back reference regular expressions not supported"), 
-                                 TQString::fromLocal8Bit("backReferenceNotSupported") );
-      }
-    break;
-
-  case 24:
-#line 172 "qregexpparser.y"
-    { yyval.regexp = new PositionRegExp( false, PositionRegExp::WORDBOUNDARY ); }
-    break;
-
-  case 25:
-#line 173 "qregexpparser.y"
-    { yyval.regexp = new PositionRegExp( false, PositionRegExp::NONWORDBOUNDARY ); }
-    break;
-
-  case 26:
-#line 176 "qregexpparser.y"
-    { 
-       if ( yyvsp[0].ch == '{' || yyvsp[0].ch == '}' || yyvsp[0].ch == '[' || yyvsp[0].ch == ']' || yyvsp[0].ch == '\\' ) {
-          yyerror( "illigal character - needs escaping" );
-       }
-       yyval.regexp = new TextRegExp( false, TQString(TQString::fromLocal8Bit("%1")).arg(yyvsp[0].ch)); 
-     }
-    break;
-
-  case 27:
-#line 182 "qregexpparser.y"
-    { yyval.regexp = new TextRegExp( false, TQString(TQString::fromLocal8Bit("%1")).arg(yyvsp[0].ch)); }
-    break;
-
-
-    }
-
-/* Line 1016 of /usr/share/bison/yacc.c.  */
-#line 1209 "gen_qregexpparser.cc"
-
-  yyvsp -= yylen;
-  yyssp -= yylen;
-
-
-#if YYDEBUG
-  if (yydebug)
-    {
-      short *yyssp1 = yyss - 1;
-      YYFPRINTF (stderr, "state stack now");
-      while (yyssp1 != yyssp)
-	YYFPRINTF (stderr, " %d", *++yyssp1);
-      YYFPRINTF (stderr, "\n");
-    }
-#endif
-
-  *++yyvsp = yyval;
-
-
-  /* Now `shift' the result of the reduction.  Determine what state
-     that goes to, based on the state we popped back to and the rule
-     number reduced by.  */
-
-  yyn = yyr1[yyn];
-
-  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
-  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
-    yystate = yytable[yystate];
-  else
-    yystate = yydefgoto[yyn - YYNTOKENS];
-
-  goto yynewstate;
-
-
-/*------------------------------------.
-| yyerrlab -- here on detecting error |
-`------------------------------------*/
-yyerrlab:
-  /* If not already recovering from an error, report this error.  */
-  if (!yyerrstatus)
-    {
-      ++yynerrs;
-#if YYERROR_VERBOSE
-      yyn = yypact[yystate];
-
-      if (YYPACT_NINF < yyn && yyn < YYLAST)
-	{
-	  YYSIZE_T yysize = 0;
-	  int yytype = YYTRANSLATE (yychar);
-	  char *yymsg;
-	  int yyx, yycount;
-
-	  yycount = 0;
-	  /* Start YYX at -YYN if negative to avoid negative indexes in
-	     YYCHECK.  */
-	  for (yyx = yyn < 0 ? -yyn : 0;
-	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
-	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
-	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;
-	  yysize += yystrlen ("parse error, unexpected ") + 1;
-	  yysize += yystrlen (yytname[yytype]);
-	  yymsg = (char *) YYSTACK_ALLOC (yysize);
-	  if (yymsg != 0)
-	    {
-	      char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
-	      yyp = yystpcpy (yyp, yytname[yytype]);
-
-	      if (yycount < 5)
-		{
-		  yycount = 0;
-		  for (yyx = yyn < 0 ? -yyn : 0;
-		       yyx < (int) (sizeof (yytname) / sizeof (char *));
-		       yyx++)
-		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
-		      {
-			const char *yyq = ! yycount ? ", expecting " : " or ";
-			yyp = yystpcpy (yyp, yyq);
-			yyp = yystpcpy (yyp, yytname[yyx]);
-			yycount++;
-		      }
-		}
-	      yyerror (yymsg);
-	      YYSTACK_FREE (yymsg);
-	    }
-	  else
-	    yyerror ("parse error; also virtual memory exhausted");
-	}
-      else
-#endif /* YYERROR_VERBOSE */
-	yyerror ("parse error");
-    }
-  goto yyerrlab1;
-
-
-/*----------------------------------------------------.
-| yyerrlab1 -- error raised explicitly by an action.  |
-`----------------------------------------------------*/
-yyerrlab1:
-  if (yyerrstatus == 3)
-    {
-      /* If just tried and failed to reuse lookahead token after an
-	 error, discard it.  */
-
-      /* Return failure if at end of input.  */
-      if (yychar == YYEOF)
-        {
-	  /* Pop the error token.  */
-          YYPOPSTACK;
-	  /* Pop the rest of the stack.  */
-	  while (yyssp > yyss)
-	    {
-	      YYDPRINTF ((stderr, "Error: popping "));
-	      YYDSYMPRINT ((stderr,
-			    yystos[*yyssp],
-			    *yyvsp));
-	      YYDPRINTF ((stderr, "\n"));
-	      yydestruct (yystos[*yyssp], *yyvsp);
-	      YYPOPSTACK;
-	    }
-	  YYABORT;
-        }
-
-      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
-		  yychar, yytname[yychar1]));
-      yydestruct (yychar1, yylval);
-      yychar = YYEMPTY;
-    }
-
-  /* Else will try to reuse lookahead token after shifting the error
-     token.  */
-
-  yyerrstatus = 3;	/* Each real token shifted decrements this.  */
-
-  for (;;)
-    {
-      yyn = yypact[yystate];
-      if (yyn != YYPACT_NINF)
-	{
-	  yyn += YYTERROR;
-	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
-	    {
-	      yyn = yytable[yyn];
-	      if (0 < yyn)
-		break;
-	    }
-	}
-
-      /* Pop the current state because it cannot handle the error token.  */
-      if (yyssp == yyss)
-	YYABORT;
-
-      YYDPRINTF ((stderr, "Error: popping "));
-      YYDSYMPRINT ((stderr,
-		    yystos[*yyssp], *yyvsp));
-      YYDPRINTF ((stderr, "\n"));
-
-      yydestruct (yystos[yystate], *yyvsp);
-      yyvsp--;
-      yystate = *--yyssp;
-
-
-#if YYDEBUG
-      if (yydebug)
-	{
-	  short *yyssp1 = yyss - 1;
-	  YYFPRINTF (stderr, "Error: state stack now");
-	  while (yyssp1 != yyssp)
-	    YYFPRINTF (stderr, " %d", *++yyssp1);
-	  YYFPRINTF (stderr, "\n");
-	}
-#endif
-    }
-
-  if (yyn == YYFINAL)
-    YYACCEPT;
-
-  YYDPRINTF ((stderr, "Shifting error token, "));
-
-  *++yyvsp = yylval;
-
-
-  yystate = yyn;
-  goto yynewstate;
-
-
-/*-------------------------------------.
-| yyacceptlab -- YYACCEPT comes here.  |
-`-------------------------------------*/
-yyacceptlab:
-  yyresult = 0;
-  goto yyreturn;
-
-/*-----------------------------------.
-| yyabortlab -- YYABORT comes here.  |
-`-----------------------------------*/
-yyabortlab:
-  yyresult = 1;
-  goto yyreturn;
-
-#ifndef yyoverflow
-/*----------------------------------------------.
-| yyoverflowlab -- parser overflow comes here.  |
-`----------------------------------------------*/
-yyoverflowlab:
-  yyerror ("parser stack overflow");
-  yyresult = 2;
-  /* Fall through.  */
-#endif
-
-yyreturn:
-#ifndef yyoverflow
-  if (yyss != yyssa)
-    YYSTACK_FREE (yyss);
-#endif
-  return yyresult;
-}
-
-
-#line 185 "qregexpparser.y"
-
-
-RegExp* parseTQtRegExp( TQString qstr, bool* ok ) {
-  _index = 0;
-  parseResult = 0;
-  setParseData( qstr );
-  yyparse();
-  *ok = ( yynerrs == 0 );
-  return parseResult;
-}
-
-void setParseResult( RegExp* regexp ) {
-  parseResult = regexp;
-}
-
-int yyerror(const char *) {
-    yynerrs++;
-  return 0;
-}
-
diff --git a/kregexpeditor/gen_qregexpparser.cpp b/kregexpeditor/gen_qregexpparser.cpp
new file mode 100644
index 00000000..3d3a4323
--- /dev/null
+++ b/kregexpeditor/gen_qregexpparser.cpp
@@ -0,0 +1,1447 @@
+/* A Bison parser, made from qregexpparser.y, by GNU bison 1.75.  */
+
+/* Skeleton parser for Yacc-like parsing with Bison,
+   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
+
+/* As a special exception, when this file is copied by Bison into a
+   Bison output file, you may use that output file without restriction.
+   This special exception was added by the Free Software Foundation
+   in version 1.24 of Bison.  */
+
+/* Written by Richard Stallman by simplifying the original so called
+   ``semantic'' parser.  */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+   infringing on user name space.  This should be done even for local
+   variables, as they might otherwise be expanded by user macros.
+   There are some unavoidable exceptions within include files to
+   define necessary library symbols; they are noted "INFRINGES ON
+   USER NAME SPACE" below.  */
+
+/* Identify Bison output.  */
+#define YYBISON	1
+
+/* Pure parsers.  */
+#define YYPURE	0
+
+/* Using locations.  */
+#define YYLSP_NEEDED 0
+
+/* If NAME_PREFIX is specified substitute the variables and functions
+   names.  */
+#define yyparse qregexpparse
+#define yylex   qregexplex
+#define yyerror qregexperror
+#define yylval  qregexplval
+#define yychar  qregexpchar
+#define yydebug qregexpdebug
+#define yynerrs qregexpnerrs
+
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     TOK_Dot = 258,
+     TOK_Dollar = 259,
+     TOK_Carat = 260,
+     TOK_MagicLeftParent = 261,
+     TOK_PosLookAhead = 262,
+     TOK_NegLookAhead = 263,
+     TOK_LeftParen = 264,
+     TOK_RightParent = 265,
+     TOK_Bar = 266,
+     TOK_Quantifier = 267,
+     TOK_BackRef = 268,
+     TOK_CharClass = 269,
+     TOK_Char = 270,
+     TOK_EscapeChar = 271,
+     TOK_PosWordChar = 272,
+     TOK_PosNonWordChar = 273
+   };
+#endif
+#define TOK_Dot 258
+#define TOK_Dollar 259
+#define TOK_Carat 260
+#define TOK_MagicLeftParent 261
+#define TOK_PosLookAhead 262
+#define TOK_NegLookAhead 263
+#define TOK_LeftParen 264
+#define TOK_RightParent 265
+#define TOK_Bar 266
+#define TOK_Quantifier 267
+#define TOK_BackRef 268
+#define TOK_CharClass 269
+#define TOK_Char 270
+#define TOK_EscapeChar 271
+#define TOK_PosWordChar 272
+#define TOK_PosNonWordChar 273
+
+
+
+
+/* Copy the first part of user declarations.  */
+#line 18 "qregexpparser.y"
+
+#ifdef TQT_ONLY
+  #include "compat.h"
+#else
+  #include <tdelocale.h>
+  #include <tdemessagebox.h>
+#endif
+
+  #include <tqstring.h>
+  #include <stdlib.h>
+
+  #include "regexp.h"
+  #include "textregexp.h"
+  #include "textrangeregexp.h"
+  #include "repeatregexp.h"
+  #include "lookaheadregexp.h"
+  #include "concregexp.h"
+  #include "altnregexp.h"
+  #include "positionregexp.h"
+  #include "dotregexp.h"
+  #include "compoundregexp.h"
+
+  extern int yylex();
+  extern void setParseData( TQString str );
+  int yyerror (const char *);
+  void setParseResult( RegExp* );
+  RegExp* parseTQtRegExp( TQString qstr, bool* ok );
+  static RegExp* parseResult;
+  static int _index;
+
+
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages.  */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+#ifndef YYSTYPE
+#line 49 "qregexpparser.y"
+typedef union {
+  struct {
+    int min;
+    int max;
+  } range;
+  int backRef;
+  RegExp* regexp;
+  char ch;
+} yystype;
+/* Line 193 of /usr/share/bison/yacc.c.  */
+#line 159 "gen_qregexpparser.cpp"
+# define YYSTYPE yystype
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+#ifndef YYLTYPE
+typedef struct yyltype
+{
+  int first_line;
+  int first_column;
+  int last_line;
+  int last_column;
+} yyltype;
+# define YYLTYPE yyltype
+# define YYLTYPE_IS_TRIVIAL 1
+#endif
+
+/* Copy the second part of user declarations.  */
+
+
+/* Line 213 of /usr/share/bison/yacc.c.  */
+#line 180 "gen_qregexpparser.cpp"
+
+#if ! defined (yyoverflow) || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols.  */
+
+# ifdef YYSTACK_USE_ALLOCA
+#  define YYSTACK_ALLOC alloca
+# else
+#  ifndef YYSTACK_USE_ALLOCA
+#   if defined (alloca) || defined (_ALLOCA_H)
+#    define YYSTACK_ALLOC alloca
+#   else
+#    ifdef __GNUC__
+#     define YYSTACK_ALLOC __builtin_alloca
+#    endif
+#   endif
+#  endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+   /* Pacify GCC's `empty if-body' warning. */
+#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# else
+#  if defined (__STDC__) || defined (__cplusplus)
+#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#   define YYSIZE_T size_t
+#  endif
+#  define YYSTACK_ALLOC malloc
+#  define YYSTACK_FREE free
+# endif
+#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
+
+
+#if (! defined (yyoverflow) \
+     && (! defined (__cplusplus) \
+	 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member.  */
+union yyalloc
+{
+  short yyss;
+  YYSTYPE yyvs;
+  };
+
+/* The size of the maximum gap between one aligned stack and the next.  */
+# define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+   N elements.  */
+# define YYSTACK_BYTES(N) \
+     ((N) * (sizeof (short) + sizeof (YYSTYPE))				\
+      + YYSTACK_GAP_MAX)
+
+/* Copy COUNT objects from FROM to TO.  The source and destination do
+   not overlap.  */
+# ifndef YYCOPY
+#  if 1 < __GNUC__
+#   define YYCOPY(To, From, Count) \
+      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+#  else
+#   define YYCOPY(To, From, Count)		\
+      do					\
+	{					\
+	  YYSIZE_T yyi;		\
+	  for (yyi = 0; yyi < (Count); yyi++)	\
+	    (To)[yyi] = (From)[yyi];	\
+	}					\
+      while (0)
+#  endif
+# endif
+
+/* Relocate STACK from its old location to the new one.  The
+   local variables YYSIZE and YYSTACKSIZE give the old and new number of
+   elements in the stack, and YYPTR gives the new location of the
+   stack.  Advance YYPTR to a properly aligned location for the next
+   stack.  */
+# define YYSTACK_RELOCATE(Stack)					\
+    do									\
+      {									\
+	YYSIZE_T yynewbytes;						\
+	YYCOPY (&yyptr->Stack, Stack, yysize);				\
+	Stack = &yyptr->Stack;						\
+	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX;	\
+	yyptr += yynewbytes / sizeof (*yyptr);				\
+      }									\
+    while (0)
+
+#endif
+
+#if defined (__STDC__) || defined (__cplusplus)
+   typedef signed char yysigned_char;
+#else
+   typedef short yysigned_char;
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL  27
+#define YYLAST   47
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS  19
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS  8
+/* YYNRULES -- Number of rules. */
+#define YYNRULES  27
+/* YYNRULES -- Number of states. */
+#define YYNSTATES  36
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
+#define YYUNDEFTOK  2
+#define YYMAXUTOK   273
+
+#define YYTRANSLATE(X) \
+  ((unsigned)(X) <= YYMAXUTOK ? yytranslate[X] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
+static const unsigned char yytranslate[] =
+{
+       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
+       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
+      15,    16,    17,    18
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+   YYRHS.  */
+static const unsigned char yyprhs[] =
+{
+       0,     0,     3,     4,     6,     8,    12,    14,    17,    20,
+      22,    25,    27,    30,    32,    36,    40,    44,    48,    50,
+      52,    54,    56,    58,    60,    62,    64,    66
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yysigned_char yyrhs[] =
+{
+      21,     0,    -1,    -1,    22,    -1,    20,    -1,    22,    11,
+      23,    -1,    23,    -1,    22,    11,    -1,    11,    23,    -1,
+      11,    -1,    23,    24,    -1,    24,    -1,    25,    12,    -1,
+      25,    -1,     9,    22,    10,    -1,     6,    22,    10,    -1,
+       7,    22,    10,    -1,     8,    22,    10,    -1,    14,    -1,
+      26,    -1,     4,    -1,     5,    -1,     3,    -1,    13,    -1,
+      17,    -1,    18,    -1,    15,    -1,    16,    -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
+static const unsigned char yyrline[] =
+{
+       0,    80,    80,    82,    83,    86,    96,    97,   107,   112,
+     115,   129,   136,   139,   142,   145,   146,   149,   152,   153,
+     154,   155,   156,   157,   172,   173,   176,   182
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE
+/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+  "$end", "error", "$undefined", "TOK_Dot", "TOK_Dollar", "TOK_Carat", 
+  "TOK_MagicLeftParent", "TOK_PosLookAhead", "TOK_NegLookAhead", 
+  "TOK_LeftParen", "TOK_RightParent", "TOK_Bar", "TOK_Quantifier", 
+  "TOK_BackRef", "TOK_CharClass", "TOK_Char", "TOK_EscapeChar", 
+  "TOK_PosWordChar", "TOK_PosNonWordChar", "$accept", "empty", "regexp", 
+  "expression", "term", "factor", "atom", "char", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+   token YYLEX-NUM.  */
+static const unsigned short yytoknum[] =
+{
+       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
+     265,   266,   267,   268,   269,   270,   271,   272,   273
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
+static const unsigned char yyr1[] =
+{
+       0,    19,    20,    21,    21,    22,    22,    22,    22,    22,
+      23,    23,    24,    24,    25,    25,    25,    25,    25,    25,
+      25,    25,    25,    25,    25,    25,    26,    26
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
+static const unsigned char yyr2[] =
+{
+       0,     2,     0,     1,     1,     3,     1,     2,     2,     1,
+       2,     1,     2,     1,     3,     3,     3,     3,     1,     1,
+       1,     1,     1,     1,     1,     1,     1,     1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
+   means the default is an error.  */
+static const unsigned char yydefact[] =
+{
+       2,    22,    20,    21,     0,     0,     0,     0,     9,    23,
+      18,    26,    27,    24,    25,     4,     0,     3,     6,    11,
+      13,    19,     0,     0,     0,     0,     8,     1,     7,    10,
+      12,    15,    16,    17,    14,     5
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yysigned_char yydefgoto[] =
+{
+      -1,    15,    16,    17,    18,    19,    20,    21
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+   STATE-NUM.  */
+#define YYPACT_NINF -18
+static const yysigned_char yypact[] =
+{
+      -1,   -18,   -18,   -18,    -1,    -1,    -1,    -1,    18,   -18,
+     -18,   -18,   -18,   -18,   -18,   -18,    11,     8,    18,   -18,
+      16,   -18,    19,    31,    34,    36,    18,   -18,    18,   -18,
+     -18,   -18,   -18,   -18,   -18,    18
+};
+
+/* YYPGOTO[NTERM-NUM].  */
+static const yysigned_char yypgoto[] =
+{
+     -18,   -18,   -18,    33,    -8,   -17,   -18,   -18
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
+   positive, shift that token.  If negative, reduce the rule which
+   number is the opposite.  If zero, do what YYDEFACT says.
+   If YYTABLE_NINF, parse error.  */
+#define YYTABLE_NINF -1
+static const unsigned char yytable[] =
+{
+      26,    29,     1,     2,     3,     4,     5,     6,     7,    29,
+       8,    27,     9,    10,    11,    12,    13,    14,    29,    28,
+      35,     1,     2,     3,     4,     5,     6,     7,    30,    31,
+      28,     9,    10,    11,    12,    13,    14,    22,    23,    24,
+      25,    32,    28,     0,    33,    28,    34,    28
+};
+
+static const yysigned_char yycheck[] =
+{
+       8,    18,     3,     4,     5,     6,     7,     8,     9,    26,
+      11,     0,    13,    14,    15,    16,    17,    18,    35,    11,
+      28,     3,     4,     5,     6,     7,     8,     9,    12,    10,
+      11,    13,    14,    15,    16,    17,    18,     4,     5,     6,
+       7,    10,    11,    -1,    10,    11,    10,    11
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+   symbol of state STATE-NUM.  */
+static const unsigned char yystos[] =
+{
+       0,     3,     4,     5,     6,     7,     8,     9,    11,    13,
+      14,    15,    16,    17,    18,    20,    21,    22,    23,    24,
+      25,    26,    22,    22,    22,    22,    23,     0,    11,    24,
+      12,    10,    10,    10,    10,    23
+};
+
+#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
+# define YYSIZE_T __SIZE_TYPE__
+#endif
+#if ! defined (YYSIZE_T) && defined (size_t)
+# define YYSIZE_T size_t
+#endif
+#if ! defined (YYSIZE_T)
+# if defined (__STDC__) || defined (__cplusplus)
+#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYSIZE_T size_t
+# endif
+#endif
+#if ! defined (YYSIZE_T)
+# define YYSIZE_T unsigned int
+#endif
+
+#define yyerrok		(yyerrstatus = 0)
+#define yyclearin	(yychar = YYEMPTY)
+#define YYEMPTY		-2
+#define YYEOF		0
+
+#define YYACCEPT	goto yyacceptlab
+#define YYABORT		goto yyabortlab
+#define YYERROR		goto yyerrlab1
+
+/* Like YYERROR except do call yyerror.  This remains here temporarily
+   to ease the transition to the new meaning of YYERROR, for GCC.
+   Once GCC version 2 has supplanted version 1, this can go.  */
+
+#define YYFAIL		goto yyerrlab
+
+#define YYRECOVERING()  (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value)					\
+do								\
+  if (yychar == YYEMPTY && yylen == 1)				\
+    {								\
+      yychar = (Token);						\
+      yylval = (Value);						\
+      yychar1 = YYTRANSLATE (yychar);				\
+      YYPOPSTACK;						\
+      goto yybackup;						\
+    }								\
+  else								\
+    { 								\
+      yyerror ("syntax error: cannot back up");			\
+      YYERROR;							\
+    }								\
+while (0)
+
+#define YYTERROR	1
+#define YYERRCODE	256
+
+/* YYLLOC_DEFAULT -- Compute the default location (before the actions
+   are run).  */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N)           \
+  Current.first_line   = Rhs[1].first_line;      \
+  Current.first_column = Rhs[1].first_column;    \
+  Current.last_line    = Rhs[N].last_line;       \
+  Current.last_column  = Rhs[N].last_column;
+#endif
+
+/* YYLEX -- calling `yylex' with the right arguments.  */
+
+#define YYLEX	yylex ()
+
+/* Enable debugging if requested.  */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args)			\
+do {						\
+  if (yydebug)					\
+    YYFPRINTF Args;				\
+} while (0)
+# define YYDSYMPRINT(Args)			\
+do {						\
+  if (yydebug)					\
+    yysymprint Args;				\
+} while (0)
+/* Nonzero means print parse trace.  It is left uninitialized so that
+   multiple parsers can coexist.  */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YYDSYMPRINT(Args)
+#endif /* !YYDEBUG */
+
+/* YYINITDEPTH -- initial size of the parser's stacks.  */
+#ifndef	YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+   if the built-in stack extension method is used).
+
+   Do not make this value too large; the results are undefined if
+   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
+   evaluated with infinite-precision integer arithmetic.  */
+
+#ifdef YYMAXDEPTH == 0
+# undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+#  if defined (__GLIBC__) && defined (_STRING_H)
+#   define yystrlen strlen
+#  else
+/* Return the length of YYSTR.  */
+static YYSIZE_T
+#   if defined (__STDC__) || defined (__cplusplus)
+yystrlen (const char *yystr)
+#   else
+yystrlen (yystr)
+     const char *yystr;
+#   endif
+{
+  const char *yys = yystr;
+
+  while (*yys++ != '\0')
+    continue;
+
+  return yys - yystr - 1;
+}
+#  endif
+# endif
+
+# ifndef yystpcpy
+#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+#   define yystpcpy stpcpy
+#  else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+   YYDEST.  */
+static char *
+#   if defined (__STDC__) || defined (__cplusplus)
+yystpcpy (char *yydest, const char *yysrc)
+#   else
+yystpcpy (yydest, yysrc)
+     char *yydest;
+     const char *yysrc;
+#   endif
+{
+  char *yyd = yydest;
+  const char *yys = yysrc;
+
+  while ((*yyd++ = *yys++) != '\0')
+    continue;
+
+  return yyd - 1;
+}
+#  endif
+# endif
+
+#endif /* !YYERROR_VERBOSE */
+
+
+
+#if YYDEBUG
+/*-----------------------------.
+| Print this symbol on YYOUT.  |
+`-----------------------------*/
+
+static void
+#if defined (__STDC__) || defined (__cplusplus)
+yysymprint (FILE* yyout, int yytype, YYSTYPE yyvalue)
+#else
+yysymprint (yyout, yytype, yyvalue)
+    FILE* yyout;
+    int yytype;
+    YYSTYPE yyvalue;
+#endif
+{
+  /* Pacify ``unused variable'' warnings.  */
+  (void) yyvalue;
+
+  if (yytype < YYNTOKENS)
+    {
+      YYFPRINTF (yyout, "token %s (", yytname[yytype]);
+# ifdef YYPRINT
+      YYPRINT (yyout, yytoknum[yytype], yyvalue);
+# endif
+    }
+  else
+    YYFPRINTF (yyout, "nterm %s (", yytname[yytype]);
+
+  switch (yytype)
+    {
+      default:
+        break;
+    }
+  YYFPRINTF (yyout, ")");
+}
+#endif /* YYDEBUG. */
+
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol.  |
+`-----------------------------------------------*/
+
+static void
+#if defined (__STDC__) || defined (__cplusplus)
+yydestruct (int yytype, YYSTYPE yyvalue)
+#else
+yydestruct (yytype, yyvalue)
+    int yytype;
+    YYSTYPE yyvalue;
+#endif
+{
+  /* Pacify ``unused variable'' warnings.  */
+  (void) yyvalue;
+
+  switch (yytype)
+    {
+      default:
+        break;
+    }
+}
+
+
+
+/* The user can define YYPARSE_PARAM as the name of an argument to be passed
+   into yyparse.  The argument should have type void *.
+   It should actually point to an object.
+   Grammar actions can access the variable by casting it
+   to the proper pointer type.  */
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+#  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
+#  define YYPARSE_PARAM_DECL
+# else
+#  define YYPARSE_PARAM_ARG YYPARSE_PARAM
+#  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
+# endif
+#else /* !YYPARSE_PARAM */
+# define YYPARSE_PARAM_ARG
+# define YYPARSE_PARAM_DECL
+#endif /* !YYPARSE_PARAM */
+
+/* Prevent warning if -Wstrict-prototypes.  */
+#ifdef __GNUC__
+# ifdef YYPARSE_PARAM
+int yyparse (void *);
+# else
+int yyparse (void);
+# endif
+#endif
+
+
+/* The lookahead symbol.  */
+int yychar;
+
+/* The semantic value of the lookahead symbol.  */
+YYSTYPE yylval;
+
+/* Number of parse errors so far.  */
+int yynerrs;
+
+
+int
+yyparse (YYPARSE_PARAM_ARG)
+     YYPARSE_PARAM_DECL
+{
+  
+  int yystate;
+  int yyn;
+  int yyresult;
+  /* Number of tokens to shift before error messages enabled.  */
+  int yyerrstatus;
+  /* Lookahead token as an internal (translated) token number.  */
+  int yychar1 = 0;
+
+  /* Three stacks and their tools:
+     `yyss': related to states,
+     `yyvs': related to semantic values,
+     `yyls': related to locations.
+
+     Refer to the stacks thru separate pointers, to allow yyoverflow
+     to reallocate them elsewhere.  */
+
+  /* The state stack.  */
+  short	yyssa[YYINITDEPTH];
+  short *yyss = yyssa;
+  short *yyssp;
+
+  /* The semantic value stack.  */
+  YYSTYPE yyvsa[YYINITDEPTH];
+  YYSTYPE *yyvs = yyvsa;
+  YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK   (yyvsp--, yyssp--)
+
+  YYSIZE_T yystacksize = YYINITDEPTH;
+
+  /* The variables used to return semantic value and location from the
+     action routines.  */
+  YYSTYPE yyval;
+
+
+  /* When reducing, the number of symbols on the RHS of the reduced
+     rule.  */
+  int yylen;
+
+  YYDPRINTF ((stderr, "Starting parse\n"));
+
+  yystate = 0;
+  yyerrstatus = 0;
+  yynerrs = 0;
+  yychar = YYEMPTY;		/* Cause a token to be read.  */
+
+  /* Initialize stack pointers.
+     Waste one element of value and location stack
+     so that they stay on the same level as the state stack.
+     The wasted elements are never initialized.  */
+
+  yyssp = yyss;
+  yyvsp = yyvs;
+
+  goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate.  |
+`------------------------------------------------------------*/
+ yynewstate:
+  /* In all cases, when you get here, the value and location stacks
+     have just been pushed. so pushing a state here evens the stacks.
+     */
+  yyssp++;
+
+ yysetstate:
+  *yyssp = yystate;
+
+  if (yyssp >= yyss + yystacksize - 1)
+    {
+      /* Get the current used size of the three stacks, in elements.  */
+      YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+      {
+	/* Give user a chance to reallocate the stack. Use copies of
+	   these so that the &'s don't force the real ones into
+	   memory.  */
+	YYSTYPE *yyvs1 = yyvs;
+	short *yyss1 = yyss;
+
+
+	/* Each stack pointer address is followed by the size of the
+	   data in use in that stack, in bytes.  This used to be a
+	   conditional around just the two extra args, but that might
+	   be undefined if yyoverflow is a macro.  */
+	yyoverflow ("parser stack overflow",
+		    &yyss1, yysize * sizeof (*yyssp),
+		    &yyvs1, yysize * sizeof (*yyvsp),
+
+		    &yystacksize);
+
+	yyss = yyss1;
+	yyvs = yyvs1;
+      }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+      goto yyoverflowlab;
+# else
+      /* Extend the stack our own way.  */
+      if (yystacksize >= YYMAXDEPTH)
+	goto yyoverflowlab;
+      yystacksize *= 2;
+      if (yystacksize > YYMAXDEPTH)
+	yystacksize = YYMAXDEPTH;
+
+      {
+	short *yyss1 = yyss;
+	union yyalloc *yyptr =
+	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+	if (! yyptr)
+	  goto yyoverflowlab;
+	YYSTACK_RELOCATE (yyss);
+	YYSTACK_RELOCATE (yyvs);
+
+#  undef YYSTACK_RELOCATE
+	if (yyss1 != yyssa)
+	  YYSTACK_FREE (yyss1);
+      }
+# endif
+#endif /* no yyoverflow */
+
+      yyssp = yyss + yysize - 1;
+      yyvsp = yyvs + yysize - 1;
+
+
+      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+		  (unsigned long int) yystacksize));
+
+      if (yyssp >= yyss + yystacksize - 1)
+	YYABORT;
+    }
+
+  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+  goto yybackup;
+
+/*-----------.
+| yybackup.  |
+`-----------*/
+yybackup:
+
+/* Do appropriate processing given the current state.  */
+/* Read a lookahead token if we need one and don't already have one.  */
+/* yyresume: */
+
+  /* First try to decide what to do without reference to lookahead token.  */
+
+  yyn = yypact[yystate];
+  if (yyn == YYPACT_NINF)
+    goto yydefault;
+
+  /* Not known => get a lookahead token if don't already have one.  */
+
+  /* yychar is either YYEMPTY or YYEOF
+     or a valid token in external form.  */
+
+  if (yychar == YYEMPTY)
+    {
+      YYDPRINTF ((stderr, "Reading a token: "));
+      yychar = YYLEX;
+    }
+
+  /* Convert token to internal form (in yychar1) for indexing tables with.  */
+
+  if (yychar <= 0)		/* This means end of input.  */
+    {
+      yychar1 = 0;
+      yychar = YYEOF;		/* Don't call YYLEX any more.  */
+
+      YYDPRINTF ((stderr, "Now at end of input.\n"));
+    }
+  else
+    {
+      yychar1 = YYTRANSLATE (yychar);
+
+      /* We have to keep this `#if YYDEBUG', since we use variables
+	 which are defined only if `YYDEBUG' is set.  */
+      YYDPRINTF ((stderr, "Next token is "));
+      YYDSYMPRINT ((stderr, yychar1, yylval));
+      YYDPRINTF ((stderr, "\n"));
+    }
+
+  /* If the proper action on seeing token YYCHAR1 is to reduce or to
+     detect an error, take that action.  */
+  yyn += yychar1;
+  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yychar1)
+    goto yydefault;
+  yyn = yytable[yyn];
+  if (yyn <= 0)
+    {
+      if (yyn == 0 || yyn == YYTABLE_NINF)
+	goto yyerrlab;
+      yyn = -yyn;
+      goto yyreduce;
+    }
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  /* Shift the lookahead token.  */
+  YYDPRINTF ((stderr, "Shifting token %d (%s), ",
+	      yychar, yytname[yychar1]));
+
+  /* Discard the token being shifted unless it is eof.  */
+  if (yychar != YYEOF)
+    yychar = YYEMPTY;
+
+  *++yyvsp = yylval;
+
+
+  /* Count tokens shifted since error; after three, turn off error
+     status.  */
+  if (yyerrstatus)
+    yyerrstatus--;
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state.  |
+`-----------------------------------------------------------*/
+yydefault:
+  yyn = yydefact[yystate];
+  if (yyn == 0)
+    goto yyerrlab;
+  goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction.  |
+`-----------------------------*/
+yyreduce:
+  /* yyn is the number of a rule to reduce with.  */
+  yylen = yyr2[yyn];
+
+  /* If YYLEN is nonzero, implement the default value of the action:
+     `$$ = $1'.
+
+     Otherwise, the following line sets YYVAL to garbage.
+     This behavior is undocumented and Bison
+     users should not rely upon it.  Assigning to YYVAL
+     unconditionally makes the parser a bit smaller, and it avoids a
+     GCC warning that YYVAL may be used uninitialized.  */
+  yyval = yyvsp[1-yylen];
+
+
+
+#if YYDEBUG
+  /* We have to keep this `#if YYDEBUG', since we use variables which
+     are defined only if `YYDEBUG' is set.  */
+  if (yydebug)
+    {
+      int yyi;
+
+      YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
+		 yyn - 1, yyrline[yyn]);
+
+      /* Print the symbols being reduced, and their result.  */
+      for (yyi = yyprhs[yyn]; yyrhs[yyi] >= 0; yyi++)
+	YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
+      YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
+    }
+#endif
+  switch (yyn)
+    {
+        case 3:
+#line 82 "qregexpparser.y"
+    { setParseResult( yyvsp[0].regexp) ; }
+    break;
+
+  case 4:
+#line 83 "qregexpparser.y"
+    { setParseResult( new ConcRegExp( false ) ); }
+    break;
+
+  case 5:
+#line 86 "qregexpparser.y"
+    {
+               if ( dynamic_cast<AltnRegExp*>( yyvsp[-2].regexp ) ) {
+                 yyval.regexp = yyvsp[-2].regexp;
+               }
+               else {
+                 yyval.regexp = new AltnRegExp( false );
+                 dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[-2].regexp );
+               }
+               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[0].regexp );
+             }
+    break;
+
+  case 6:
+#line 96 "qregexpparser.y"
+    { yyval.regexp = yyvsp[0].regexp; }
+    break;
+
+  case 7:
+#line 97 "qregexpparser.y"
+    { 
+               if ( dynamic_cast<AltnRegExp*>( yyvsp[-1].regexp ) ) {
+                 yyval.regexp = yyvsp[-1].regexp;
+               }
+               else {
+                 yyval.regexp = new AltnRegExp( false );
+                 dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[-1].regexp );
+               }
+               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( new TextRegExp( false, TQString::fromLatin1("") ) );
+             }
+    break;
+
+  case 8:
+#line 107 "qregexpparser.y"
+    {  
+               yyval.regexp = new AltnRegExp( false );
+               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( new TextRegExp( false, TQString::fromLatin1("") ) );
+               dynamic_cast<AltnRegExp*>( yyval.regexp )->addRegExp( yyvsp[0].regexp );
+             }
+    break;
+
+  case 9:
+#line 112 "qregexpparser.y"
+    { yyval.regexp = new AltnRegExp( false ); }
+    break;
+
+  case 10:
+#line 115 "qregexpparser.y"
+    {
+       RegExp* last = dynamic_cast<ConcRegExp*>( yyvsp[-1].regexp )->lastRegExp();
+       TextRegExp *reg1, *reg2;
+       
+       if ( last && ( reg1 = dynamic_cast<TextRegExp*>( last ) ) &&
+            ( reg2 = dynamic_cast<TextRegExp*>( yyvsp[0].regexp ) ) ) {
+         reg1->append( reg2->text() );
+         delete reg2;
+       }
+       else {
+         dynamic_cast<ConcRegExp*>(yyval.regexp)->addRegExp( yyvsp[0].regexp );
+       }
+       yyval.regexp = yyvsp[-1].regexp;
+     }
+    break;
+
+  case 11:
+#line 129 "qregexpparser.y"
+    { 
+         ConcRegExp* reg = new ConcRegExp( false );
+         reg->addRegExp( yyvsp[0].regexp );
+         yyval.regexp = reg;
+       }
+    break;
+
+  case 12:
+#line 136 "qregexpparser.y"
+    {
+           yyval.regexp = new RepeatRegExp( false, yyvsp[0].range.min, yyvsp[0].range.max, yyvsp[-1].regexp );
+         }
+    break;
+
+  case 13:
+#line 139 "qregexpparser.y"
+    { yyval.regexp = yyvsp[0].regexp; }
+    break;
+
+  case 14:
+#line 142 "qregexpparser.y"
+    { 
+         yyval.regexp = yyvsp[-1].regexp; 
+       }
+    break;
+
+  case 15:
+#line 145 "qregexpparser.y"
+    { yyval.regexp = yyvsp[-1].regexp; }
+    break;
+
+  case 16:
+#line 146 "qregexpparser.y"
+    { 
+         yyval.regexp = new LookAheadRegExp( false, LookAheadRegExp::POSITIVE, yyvsp[-1].regexp );
+       }
+    break;
+
+  case 17:
+#line 149 "qregexpparser.y"
+    {
+         yyval.regexp = new LookAheadRegExp( false, LookAheadRegExp::NEGATIVE, yyvsp[-1].regexp );
+       }
+    break;
+
+  case 18:
+#line 152 "qregexpparser.y"
+    { yyval.regexp = yyvsp[0].regexp; }
+    break;
+
+  case 19:
+#line 153 "qregexpparser.y"
+    { yyval.regexp = yyvsp[0].regexp; }
+    break;
+
+  case 20:
+#line 154 "qregexpparser.y"
+    { yyval.regexp = new PositionRegExp( false, PositionRegExp::ENDLINE ); }
+    break;
+
+  case 21:
+#line 155 "qregexpparser.y"
+    { yyval.regexp = new PositionRegExp( false, PositionRegExp::BEGLINE ); }
+    break;
+
+  case 22:
+#line 156 "qregexpparser.y"
+    { yyval.regexp = new DotRegExp( false ); }
+    break;
+
+  case 23:
+#line 157 "qregexpparser.y"
+    { 
+        TQString match = TQString(TQString::fromLocal8Bit("\\%1")).arg( yyvsp[0].backRef );
+        yyval.regexp = new TextRegExp( false, match );
+        KMessageBox::information(0,i18n("<qt>Back reference regular expressions are not supported.<p>"
+                                        "<tt>\\1</tt>, <tt>\\2</tt>, ... are <i>back references</i>, meaning they refer to  "
+                                        "previous matches. "
+                                        "Unfortunately this is not supported in the current version of this editor.<p>"
+                                        "In the graphical area the text <b>%1</b> has been inserted. This is however "
+                                        "just a workaround to ensure that the application handles the regexp at all. "
+                                        "Therefore, as soon as you edit the regular expression in the graphical area, "
+                                        "the back reference will be replaced by matching the text <b>%2</b> literally.")
+                                    .arg( match ).arg( match ),
+                                 i18n("Back reference regular expressions not supported"), 
+                                 TQString::fromLocal8Bit("backReferenceNotSupported") );
+      }
+    break;
+
+  case 24:
+#line 172 "qregexpparser.y"
+    { yyval.regexp = new PositionRegExp( false, PositionRegExp::WORDBOUNDARY ); }
+    break;
+
+  case 25:
+#line 173 "qregexpparser.y"
+    { yyval.regexp = new PositionRegExp( false, PositionRegExp::NONWORDBOUNDARY ); }
+    break;
+
+  case 26:
+#line 176 "qregexpparser.y"
+    { 
+       if ( yyvsp[0].ch == '{' || yyvsp[0].ch == '}' || yyvsp[0].ch == '[' || yyvsp[0].ch == ']' || yyvsp[0].ch == '\\' ) {
+          yyerror( "illigal character - needs escaping" );
+       }
+       yyval.regexp = new TextRegExp( false, TQString(TQString::fromLocal8Bit("%1")).arg(yyvsp[0].ch)); 
+     }
+    break;
+
+  case 27:
+#line 182 "qregexpparser.y"
+    { yyval.regexp = new TextRegExp( false, TQString(TQString::fromLocal8Bit("%1")).arg(yyvsp[0].ch)); }
+    break;
+
+
+    }
+
+/* Line 1016 of /usr/share/bison/yacc.c.  */
+#line 1209 "gen_qregexpparser.cpp"
+
+  yyvsp -= yylen;
+  yyssp -= yylen;
+
+
+#if YYDEBUG
+  if (yydebug)
+    {
+      short *yyssp1 = yyss - 1;
+      YYFPRINTF (stderr, "state stack now");
+      while (yyssp1 != yyssp)
+	YYFPRINTF (stderr, " %d", *++yyssp1);
+      YYFPRINTF (stderr, "\n");
+    }
+#endif
+
+  *++yyvsp = yyval;
+
+
+  /* Now `shift' the result of the reduction.  Determine what state
+     that goes to, based on the state we popped back to and the rule
+     number reduced by.  */
+
+  yyn = yyr1[yyn];
+
+  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+    yystate = yytable[yystate];
+  else
+    yystate = yydefgoto[yyn - YYNTOKENS];
+
+  goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+  /* If not already recovering from an error, report this error.  */
+  if (!yyerrstatus)
+    {
+      ++yynerrs;
+#if YYERROR_VERBOSE
+      yyn = yypact[yystate];
+
+      if (YYPACT_NINF < yyn && yyn < YYLAST)
+	{
+	  YYSIZE_T yysize = 0;
+	  int yytype = YYTRANSLATE (yychar);
+	  char *yymsg;
+	  int yyx, yycount;
+
+	  yycount = 0;
+	  /* Start YYX at -YYN if negative to avoid negative indexes in
+	     YYCHECK.  */
+	  for (yyx = yyn < 0 ? -yyn : 0;
+	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
+	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;
+	  yysize += yystrlen ("parse error, unexpected ") + 1;
+	  yysize += yystrlen (yytname[yytype]);
+	  yymsg = (char *) YYSTACK_ALLOC (yysize);
+	  if (yymsg != 0)
+	    {
+	      char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
+	      yyp = yystpcpy (yyp, yytname[yytype]);
+
+	      if (yycount < 5)
+		{
+		  yycount = 0;
+		  for (yyx = yyn < 0 ? -yyn : 0;
+		       yyx < (int) (sizeof (yytname) / sizeof (char *));
+		       yyx++)
+		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+		      {
+			const char *yyq = ! yycount ? ", expecting " : " or ";
+			yyp = yystpcpy (yyp, yyq);
+			yyp = yystpcpy (yyp, yytname[yyx]);
+			yycount++;
+		      }
+		}
+	      yyerror (yymsg);
+	      YYSTACK_FREE (yymsg);
+	    }
+	  else
+	    yyerror ("parse error; also virtual memory exhausted");
+	}
+      else
+#endif /* YYERROR_VERBOSE */
+	yyerror ("parse error");
+    }
+  goto yyerrlab1;
+
+
+/*----------------------------------------------------.
+| yyerrlab1 -- error raised explicitly by an action.  |
+`----------------------------------------------------*/
+yyerrlab1:
+  if (yyerrstatus == 3)
+    {
+      /* If just tried and failed to reuse lookahead token after an
+	 error, discard it.  */
+
+      /* Return failure if at end of input.  */
+      if (yychar == YYEOF)
+        {
+	  /* Pop the error token.  */
+          YYPOPSTACK;
+	  /* Pop the rest of the stack.  */
+	  while (yyssp > yyss)
+	    {
+	      YYDPRINTF ((stderr, "Error: popping "));
+	      YYDSYMPRINT ((stderr,
+			    yystos[*yyssp],
+			    *yyvsp));
+	      YYDPRINTF ((stderr, "\n"));
+	      yydestruct (yystos[*yyssp], *yyvsp);
+	      YYPOPSTACK;
+	    }
+	  YYABORT;
+        }
+
+      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
+		  yychar, yytname[yychar1]));
+      yydestruct (yychar1, yylval);
+      yychar = YYEMPTY;
+    }
+
+  /* Else will try to reuse lookahead token after shifting the error
+     token.  */
+
+  yyerrstatus = 3;	/* Each real token shifted decrements this.  */
+
+  for (;;)
+    {
+      yyn = yypact[yystate];
+      if (yyn != YYPACT_NINF)
+	{
+	  yyn += YYTERROR;
+	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+	    {
+	      yyn = yytable[yyn];
+	      if (0 < yyn)
+		break;
+	    }
+	}
+
+      /* Pop the current state because it cannot handle the error token.  */
+      if (yyssp == yyss)
+	YYABORT;
+
+      YYDPRINTF ((stderr, "Error: popping "));
+      YYDSYMPRINT ((stderr,
+		    yystos[*yyssp], *yyvsp));
+      YYDPRINTF ((stderr, "\n"));
+
+      yydestruct (yystos[yystate], *yyvsp);
+      yyvsp--;
+      yystate = *--yyssp;
+
+
+#if YYDEBUG
+      if (yydebug)
+	{
+	  short *yyssp1 = yyss - 1;
+	  YYFPRINTF (stderr, "Error: state stack now");
+	  while (yyssp1 != yyssp)
+	    YYFPRINTF (stderr, " %d", *++yyssp1);
+	  YYFPRINTF (stderr, "\n");
+	}
+#endif
+    }
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  YYDPRINTF ((stderr, "Shifting error token, "));
+
+  *++yyvsp = yylval;
+
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here.  |
+`-------------------------------------*/
+yyacceptlab:
+  yyresult = 0;
+  goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here.  |
+`-----------------------------------*/
+yyabortlab:
+  yyresult = 1;
+  goto yyreturn;
+
+#ifndef yyoverflow
+/*----------------------------------------------.
+| yyoverflowlab -- parser overflow comes here.  |
+`----------------------------------------------*/
+yyoverflowlab:
+  yyerror ("parser stack overflow");
+  yyresult = 2;
+  /* Fall through.  */
+#endif
+
+yyreturn:
+#ifndef yyoverflow
+  if (yyss != yyssa)
+    YYSTACK_FREE (yyss);
+#endif
+  return yyresult;
+}
+
+
+#line 185 "qregexpparser.y"
+
+
+RegExp* parseTQtRegExp( TQString qstr, bool* ok ) {
+  _index = 0;
+  parseResult = 0;
+  setParseData( qstr );
+  yyparse();
+  *ok = ( yynerrs == 0 );
+  return parseResult;
+}
+
+void setParseResult( RegExp* regexp ) {
+  parseResult = regexp;
+}
+
+int yyerror(const char *) {
+    yynerrs++;
+  return 0;
+}
+
diff --git a/kregexpeditor/gen_qregexpparser.h b/kregexpeditor/gen_qregexpparser.h
new file mode 100644
index 00000000..29167014
--- /dev/null
+++ b/kregexpeditor/gen_qregexpparser.h
@@ -0,0 +1,93 @@
+/* A Bison parser, made from qregexpparser.y, by GNU bison 1.75.  */
+
+/* Skeleton parser for Yacc-like parsing with Bison,
+   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
+
+/* As a special exception, when this file is copied by Bison into a
+   Bison output file, you may use that output file without restriction.
+   This special exception was added by the Free Software Foundation
+   in version 1.24 of Bison.  */
+
+#ifndef BISON_GEN_TQREGEXPPARSER_HH
+# define BISON_GEN_TQREGEXPPARSER_HH
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     TOK_Dot = 258,
+     TOK_Dollar = 259,
+     TOK_Carat = 260,
+     TOK_MagicLeftParent = 261,
+     TOK_PosLookAhead = 262,
+     TOK_NegLookAhead = 263,
+     TOK_LeftParen = 264,
+     TOK_RightParent = 265,
+     TOK_Bar = 266,
+     TOK_Quantifier = 267,
+     TOK_BackRef = 268,
+     TOK_CharClass = 269,
+     TOK_Char = 270,
+     TOK_EscapeChar = 271,
+     TOK_PosWordChar = 272,
+     TOK_PosNonWordChar = 273
+   };
+#endif
+#define TOK_Dot 258
+#define TOK_Dollar 259
+#define TOK_Carat 260
+#define TOK_MagicLeftParent 261
+#define TOK_PosLookAhead 262
+#define TOK_NegLookAhead 263
+#define TOK_LeftParen 264
+#define TOK_RightParent 265
+#define TOK_Bar 266
+#define TOK_Quantifier 267
+#define TOK_BackRef 268
+#define TOK_CharClass 269
+#define TOK_Char 270
+#define TOK_EscapeChar 271
+#define TOK_PosWordChar 272
+#define TOK_PosNonWordChar 273
+
+
+
+
+#ifndef YYSTYPE
+#line 49 "qregexpparser.y"
+typedef union {
+  struct {
+    int min;
+    int max;
+  } range;
+  int backRef;
+  RegExp* regexp;
+  char ch;
+} yystype;
+/* Line 1281 of /usr/share/bison/yacc.c.  */
+#line 86 "gen_qregexpparser.h"
+# define YYSTYPE yystype
+#endif
+
+extern YYSTYPE qregexplval;
+
+
+#endif /* not BISON_GEN_TQREGEXPPARSER_HH */
+
diff --git a/kregexpeditor/gen_qregexpparser.hh b/kregexpeditor/gen_qregexpparser.hh
deleted file mode 100644
index 9e75892e..00000000
--- a/kregexpeditor/gen_qregexpparser.hh
+++ /dev/null
@@ -1,93 +0,0 @@
-/* A Bison parser, made from qregexpparser.y, by GNU bison 1.75.  */
-
-/* Skeleton parser for Yacc-like parsing with Bison,
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
-
-/* As a special exception, when this file is copied by Bison into a
-   Bison output file, you may use that output file without restriction.
-   This special exception was added by the Free Software Foundation
-   in version 1.24 of Bison.  */
-
-#ifndef BISON_GEN_TQREGEXPPARSER_HH
-# define BISON_GEN_TQREGEXPPARSER_HH
-
-/* Tokens.  */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
-   /* Put the tokens into the symbol table, so that GDB and other debuggers
-      know about them.  */
-   enum yytokentype {
-     TOK_Dot = 258,
-     TOK_Dollar = 259,
-     TOK_Carat = 260,
-     TOK_MagicLeftParent = 261,
-     TOK_PosLookAhead = 262,
-     TOK_NegLookAhead = 263,
-     TOK_LeftParen = 264,
-     TOK_RightParent = 265,
-     TOK_Bar = 266,
-     TOK_Quantifier = 267,
-     TOK_BackRef = 268,
-     TOK_CharClass = 269,
-     TOK_Char = 270,
-     TOK_EscapeChar = 271,
-     TOK_PosWordChar = 272,
-     TOK_PosNonWordChar = 273
-   };
-#endif
-#define TOK_Dot 258
-#define TOK_Dollar 259
-#define TOK_Carat 260
-#define TOK_MagicLeftParent 261
-#define TOK_PosLookAhead 262
-#define TOK_NegLookAhead 263
-#define TOK_LeftParen 264
-#define TOK_RightParent 265
-#define TOK_Bar 266
-#define TOK_Quantifier 267
-#define TOK_BackRef 268
-#define TOK_CharClass 269
-#define TOK_Char 270
-#define TOK_EscapeChar 271
-#define TOK_PosWordChar 272
-#define TOK_PosNonWordChar 273
-
-
-
-
-#ifndef YYSTYPE
-#line 49 "qregexpparser.y"
-typedef union {
-  struct {
-    int min;
-    int max;
-  } range;
-  int backRef;
-  RegExp* regexp;
-  char ch;
-} yystype;
-/* Line 1281 of /usr/share/bison/yacc.c.  */
-#line 86 "gen_qregexpparser.hh"
-# define YYSTYPE yystype
-#endif
-
-extern YYSTYPE qregexplval;
-
-
-#endif /* not BISON_GEN_TQREGEXPPARSER_HH */
-
diff --git a/kregexpeditor/qregexpparser.l b/kregexpeditor/qregexpparser.l
index 4fb90cc6..8831bb6a 100644
--- a/kregexpeditor/qregexpparser.l
+++ b/kregexpeditor/qregexpparser.l
@@ -20,7 +20,7 @@
 %{ 
   #include <qstring.h>
   #include "textrangeregexp.h"
-  #include "gen_qregexpparser.hh"
+  #include "gen_qregexpparser.h"
 #ifdef QT_ONLY
   #include "compat.h"
 #endif
diff --git a/kregexpeditor/qt-only/compile b/kregexpeditor/qt-only/compile
index 43bcf421..fc41caa4 100755
--- a/kregexpeditor/qt-only/compile
+++ b/kregexpeditor/qt-only/compile
@@ -3,7 +3,7 @@
 ln -s ../*.{cpp,h,y,l} .
 ln -s ../{KMultiFormListBox,KWidgetStreamer}/*.{cpp,h} .
 ln -s $KDESRC/tdelibs/interfaces/kregexpeditor/kregexpeditorinterface.h .
-ln -s gen_qregexpparser.cc gen_qregexpparser.cpp
+ln -s gen_qregexpparser.cpp gen_qregexpparser.cpp
 touch unistd.h
 mkdir icons
 cp ../picts/* icons
@@ -13,7 +13,7 @@ mkdir predefined/General
 cp ../predefined/General/*.regexp predefined/General
 
 flex -Pqregexp -ogen_qregexplexer.cpp qregexpparser.l
-bison -d -p qregexp -o gen_qregexpparser.cc qregexpparser.y
+bison -d -p qregexp -o gen_qregexpparser.cpp qregexpparser.y
 
 mkdir manual
 cd manual
diff --git a/kregexpeditor/qt-only/qt-only.pro b/kregexpeditor/qt-only/qt-only.pro
index 536c98b9..aad7f07b 100644
--- a/kregexpeditor/qt-only/qt-only.pro
+++ b/kregexpeditor/qt-only/qt-only.pro
@@ -28,7 +28,7 @@ HEADERS += altnregexp.h \
            editorwindow.h \
            emacsregexpconverter.h \
            errormap.h \
-           gen_qregexpparser.hh \
+           gen_qregexpparser.h \
            indexWindow.h \
            infopage.h \
            tdemultiformlistbox-multivisible.h \
-- 
cgit v1.2.3

