]> git.saurik.com Git - wxWidgets.git/commitdiff
Fixed two minor bugs. Still more than enough left. Quite some new ones.:-(
authorKarsten Ballüder <ballueder@usa.net>
Sun, 13 Jun 1999 17:44:22 +0000 (17:44 +0000)
committerKarsten Ballüder <ballueder@usa.net>
Sun, 13 Jun 1999 17:44:22 +0000 (17:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2769 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/richedit/wxlwindow.cpp
samples/richedit/wxlwindow.h

index db44c83da30725cd18372e871369cd21d0074622..eadfb2b6839b67503a61b085d720b434d7acd5aa 100644 (file)
@@ -415,6 +415,7 @@ void
 wxLayoutWindow::OnChar(wxKeyEvent& event)
 {
    int keyCode = event.KeyCode();
+   bool ctrlDown = event.ControlDown();
 
 #ifdef WXLAYOUT_DEBUG
    if(keyCode == WXK_F1)
@@ -424,34 +425,36 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
    }
 #endif
 
-   wxASSERT_MSG( !m_Selecting || event.ShiftDown(),
-                 "m_Selecting is normally reset in OnKeyUp() when Shift "
-                 "goes up!" );
-
-   if ( !m_Selecting && m_llist->HasSelection() )
-   {
-      // pressing any non-arrow key replaces the selection
-      if ( !IsDirectionKey(keyCode) )
-      {
-         m_llist->DeleteSelection();
-      }
-      else if ( !event.ShiftDown() )
-      {
-         m_llist->DiscardSelection();
-      }
-   }
-
+   // Force m_Selecting to be false if shift is no longer
+   // pressed. OnKeyUp() cannot catch all Shift-Up events.
+   if(!event.ShiftDown())
+      m_Selecting = false;
+   
+   // pressing any non-arrow key optionally replaces the selection:
+   if(m_AutoDeleteSelection
+      && !m_Selecting
+      && m_llist->HasSelection() 
+      && ! IsDirectionKey(keyCode)
+      && ! (event.AltDown() || ctrlDown)
+      )
+      m_llist->DeleteSelection();
+   
    // <Shift>+<arrow> starts selection
-   if ( event.ShiftDown() && IsDirectionKey(keyCode) )
+   if ( IsDirectionKey(keyCode) )
    {
       if ( !m_Selecting )
       {
          m_Selecting = true;
          m_llist->StartSelection();
       }
-      //else: just continue the old selection
+      else
+      {
+         // just continue the old selection
+         if(! event.ShiftDown() )
+            m_llist->DiscardSelection();
+      }
    }
-
+   
    // If needed, make cursor visible:
    if(m_CursorVisibility == -1)
       m_CursorVisibility = 1;
@@ -461,7 +464,6 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
       cursor, etc. It's default will process all keycodes causing
       modifications to the buffer, but only if editing is allowed.
    */
-   bool ctrlDown = event.ControlDown();
    switch(keyCode)
    {
    case WXK_RIGHT:
@@ -510,7 +512,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
       else if( IsEditable() )
       {
          /* First, handle control keys */
-         if(event.ControlDown() && ! event.AltDown())
+         if(ctrlDown && ! event.AltDown())
          {
             switch(keyCode)
             {
@@ -976,17 +978,6 @@ wxLayoutWindow::Paste(bool primary)
       }
       wxTheClipboard->Close();
    }
-
-#if 0
-   /* My attempt to get the primary selection, but it does not
-      work. :-( */
-   if(text.Length() == 0)
-   {
-      wxTextCtrl tmp_tctrl(this,-1);
-      tmp_tctrl.Paste();
-      text += tmp_tctrl.GetValue();
-   }
-#endif
 }
 
 bool
index 7ed9994c80f50ffed3acb5e499ac08b4aad32f9a..60bc28c06536494517b6efc23dcf41a67cce09ca 100644 (file)
@@ -219,6 +219,13 @@ protected:
        on demand.
    */
    int m_CursorVisibility;
+
+   bool SetAutoDeleteSelection(bool enable = TRUE)
+   {
+      bool old = m_AutoDeleteSelection;
+      m_AutoDeleteSelection = enable;
+      return old;
+   }
 private:
    /// The layout list to be displayed.
    wxLayoutList *m_llist;
@@ -243,6 +250,11 @@ private:
    int          m_StatusFieldCursor;
    /// a pointer to a bitmap for the background
    wxBitmap    *m_BGbitmap;
+   /**@name Some configuration options */
+   //@{
+   /// Do we want to auto-replace the selection with new text?
+   bool         m_AutoDeleteSelection;
+   //@}
    DECLARE_EVENT_TABLE()
 };