]> git.saurik.com Git - wxWidgets.git/blobdiff - user/wxLayout/wxlparser.cpp
Selection improvement.
[wxWidgets.git] / user / wxLayout / wxlparser.cpp
index 6ebe3a5ce39cb24faa4333a2d829ee7c880d73cd..95268ef08c7dd40a65c92028653db2dc33db7a7e 100644 (file)
@@ -10,7 +10,7 @@
 #   pragma implementation "wxlparser.h"
 #endif
 
-//#include "Mpch.h"
+#include "Mpch.h"
 #ifdef M_PREFIX
 #   include "gui/wxllist.h"
 #   include "gui/wxlparser.h"
@@ -26,14 +26,16 @@ inline static bool IsEndOfLine(const char *p, int mode)
    // in addition to Unix EOL convention we also (but not instead) understand
    // the DOS one under Windows
    return
-      ((mode & WXLO_EXPORT_WITH_MASK) == WXLO_EXPORT_WITH_CRLF) ?
+      (mode == WXLO_EXPORT_WITH_CRLF) ?
       ((*p == '\r') && (*(p + 1) == '\n')) 
       :
       (((*p == '\r') && (*(p + 1) == '\n'))||(*p == '\n'));
 }
 
-void wxLayoutImportText(wxLayoutList &list, wxString const &str, int withflag)
+void wxLayoutImportText(wxLayoutList *list, wxString const &str, int withflag)
 {
+   if(str.Length() == 0)
+      return;
    char * cptr = (char *)str.c_str(); // string gets changed only temporarily
    const char * begin = cptr;
    char  backup;
@@ -45,7 +47,7 @@ void wxLayoutImportText(wxLayoutList &list, wxString const &str, int withflag)
          cptr++;
       backup = *cptr;
       *cptr = '\0';
-      list.Insert(begin);
+      list->Insert(begin);
       *cptr = backup;
 
       // check if it's the end of this line
@@ -54,7 +56,7 @@ void wxLayoutImportText(wxLayoutList &list, wxString const &str, int withflag)
          // if it was "\r\n", skip the following '\n'
          if ( *cptr == '\r' )
             cptr++;
-         list.LineBreak();
+         list->LineBreak();
       }
       else if(backup == '\0') // reached end of string
          break;
@@ -146,60 +148,108 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
 
 
 
+wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list,
+                                           wxPoint fromPos,
+                                           wxPoint toPos)
+{
+   list->GetDefaults()->GetStyle(&m_si);
+   m_line = list->GetFirstLine();
+   m_iterator = m_line->GetFirstObject();
+   m_fromPos = fromPos;
+   m_toPos = toPos;
+
+   if(m_fromPos.x != -1)
+   {
+      while(m_line && m_line->GetLineNumber() != m_fromPos.y)
+         m_line = m_line->GetNextLine();
+      wxASSERT(m_line);
+      CoordType dummy;
+      m_iterator = m_line->FindObject(fromPos.x, &dummy);
+   }
+}
+   
+
+
 #define   WXLO_IS_TEXT(type) \
 ( type == WXLO_TYPE_TEXT \
   || (type == WXLO_TYPE_CMD \
-      && (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML))
+      && mode == WXLO_EXPORT_AS_HTML))
+
 
 
-  
+extern const wxPoint wxLayoutExportNoPosition = wxPoint(-1,-1);
+
 wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
-                                     int mode)
+                                     int mode, int flags)
 {
    wxASSERT(status);
    wxLayoutExportObject * export;
-
+   
    if(status->m_iterator == NULLIT) // end of line
    {
-      if(!status->m_line || status->m_line->GetNextLine() == NULL) // reached end of list
+      if(!status->m_line || status->m_line->GetNextLine() == NULL)
+         // reached end of list
          return NULL;
-      else
+   }
+   export = new wxLayoutExportObject();
+   wxLayoutObjectType type;
+   if(status->m_iterator != NULLIT)
+   {
+      type = (** status->m_iterator).GetType();
+      if( mode == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
       {
-         status->m_line = status->m_line->GetNextLine();
-         status->m_iterator = status->m_line->GetFirstObject();
-         export = new wxLayoutExportObject();;
-         export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
-            ?  WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
-         if((mode & WXLO_EXPORT_WITH_CRLF) == WXLO_EXPORT_WITH_CRLF)
-            export->content.text = new wxString("\r\n");
-         else
-            export->content.text = new wxString("\n");
+         export->type = WXLO_EXPORT_OBJECT;
+         export->content.object = *status->m_iterator;
+         status->m_iterator++;
          return export;
       }
    }
-   
-   export = new wxLayoutExportObject();
-   wxLayoutObjectType   type = (** status->m_iterator).GetType();
-   if( (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
-   {
-      export->type = WXLO_EXPORT_OBJECT;
-      export->content.object = *status->m_iterator;
-      status->m_iterator++;
-      return export;
+   else
+   {  // iterator == NULLIT
+      if(mode == WXLO_EXPORT_AS_OBJECTS)
+      {
+         export->type = WXLO_EXPORT_EMPTYLINE;
+         export->content.object = NULL; //empty line
+         status->m_line = status->m_line->GetNextLine();
+         if(status->m_line)
+            status->m_iterator = status->m_line->GetFirstObject();
+         return export;
+      }
+      else
+         type = WXLO_TYPE_TEXT;
    }
 
-   // else: must be text
    wxString *str = new wxString();
    // text must be concatenated
-   do
+   for(;;)
    {
+      while(status->m_iterator == NULLIT)
+      {
+         if(flags & WXLO_EXPORT_AS_HTML)
+            *str += "<br>";
+         if(flags & WXLO_EXPORT_WITH_CRLF)
+            *str += "\r\n";
+         else
+            *str += '\n';
+
+         status->m_line = status->m_line->GetNextLine();
+         if(status->m_line)
+            status->m_iterator = status->m_line->GetFirstObject();
+         else
+            break; // end of list
+      }
+      if(! status->m_line)  // reached end of list, fall through
+         break; 
+      type = (** status->m_iterator).GetType();
+      if(type == WXLO_TYPE_ICON)
+         break;
       switch(type)
       {
       case WXLO_TYPE_TEXT:
          *str += ((wxLayoutObjectText *)*status->m_iterator)->GetText();
          break;
       case WXLO_TYPE_CMD:
-         wxASSERT_MSG( (mode&WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML,
+         wxASSERT_MSG( mode == WXLO_EXPORT_AS_HTML,
                        "reached cmd object in text mode" );
          
          *str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const
@@ -209,28 +259,9 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
          ;
       }
       status->m_iterator++;
-      if(status->m_iterator == NULLIT) // end of line!
-      {
-         if((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
-            *str += "<br>";
-         if((mode & WXLO_EXPORT_WITH_CRLF) == WXLO_EXPORT_WITH_CRLF)
-            *str += "\r\n";
-         else
-            *str += '\n';
-         status->m_line = status->m_line->GetNextLine();
-         if(status->m_line)
-            status->m_iterator = status->m_line->GetFirstObject();
-         else
-            status->m_iterator = NULLIT;
-      }
-      if(status->m_iterator != NULLIT)
-         type = (** status->m_iterator).GetType();
-      else
-         break;
    }
-   while(WXLO_IS_TEXT(type));
 
-   export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
+   export->type = (mode == WXLO_EXPORT_AS_HTML)
       ?  WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
    export->content.text = str;
    return export;