]> git.saurik.com Git - wxWidgets.git/blobdiff - user/wxLayout/wxLayout.cpp
Formerly known as wxLayout.
[wxWidgets.git] / user / wxLayout / wxLayout.cpp
index fe8fa471eed7e3930e9bda991e7393bffa577010..b4cd05060cd1ddc487ff046642c510cb8e67bcfb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Program: wxLayout
- * 
+ *
  * Author: Karsten Ballüder
  *
  * Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
 #pragma implementation "wxLayout.h"
 #endif
 
+#include "wx/wxprec.h"
+#ifdef __BORLANDC__
+#  pragma hdrstop
+#endif
+
 #include "wxLayout.h"
 #include "wx/textfile.h"
 
 
 #include   "Micon.xpm"
 
-// for testing only:
-#include   <stdio.h>
 
 //-----------------------------------------------------------------------------
 // main program
@@ -33,8 +36,9 @@ IMPLEMENT_APP(MyApp)
    enum ids{ ID_ADD_SAMPLE = 1, ID_CLEAR, ID_PRINT,
              ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS,
              ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS,
-             ID_WRAP, ID_NOWRAP, ID_PASTE,
-             ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT, ID_TEST };
+             ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, ID_CUT, ID_FIND,
+             ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT,
+             ID_TEST, ID_LINEBREAKS_TEST, ID_LONG_TEST, ID_URL_TEST };
 
 
 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
@@ -54,17 +58,16 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
    END_EVENT_TABLE()
 
 
-   int orientation = wxPORTRAIT;
-
 MyFrame::MyFrame(void) :
-   wxFrame( (wxFrame *) NULL, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
+   wxFrame( (wxFrame *) NULL, -1, "wxLayout",
+             wxPoint(880,100), wxSize(256,256) )
 {
-   CreateStatusBar( 1 );
-  
+   CreateStatusBar( 2 );
+
    SetStatusText( "wxLayout by Karsten Ballüder." );
 
    wxMenuBar *menu_bar = new wxMenuBar();
-   
+
    wxMenu *file_menu = new wxMenu;
    file_menu->Append(ID_PRINT, "&Print...", "Print");
    file_menu->Append(ID_PRINT_SETUP, "Print &Setup...","Setup printer properties");
@@ -78,38 +81,69 @@ MyFrame::MyFrame(void) :
    file_menu->Append(ID_PREVIEW_PS, "Print Preview PostScript", "Preview (PostScript)");
 #endif
    file_menu->AppendSeparator();
-   file_menu->Append( ID_TEXT, "Export Text");
-   file_menu->Append( ID_HTML, "Export HTML");
-   file_menu->Append( ID_QUIT, "Exit");
-   menu_bar->Append(file_menu, "File" );
+   file_menu->Append( ID_TEXT, "Export &Text");
+   file_menu->Append( ID_HTML, "Export &HTML");
+   file_menu->Append( ID_QUIT, "E&xit");
+   menu_bar->Append(file_menu, "&File" );
 
    wxMenu *edit_menu = new wxMenu;
-   edit_menu->Append( ID_CLEAR, "Clear");
-   edit_menu->Append( ID_ADD_SAMPLE, "Example");
+   edit_menu->Append( ID_CLEAR, "C&lear");
+   edit_menu->Append( ID_ADD_SAMPLE, "&Example");
+   edit_menu->Append( ID_LONG_TEST, "Add &many lines");
+   edit_menu->AppendSeparator();
+   edit_menu->Append( ID_LINEBREAKS_TEST, "Add &several lines");
+   edit_menu->Append( ID_URL_TEST, "Insert an &URL");
    edit_menu->AppendSeparator();
-   edit_menu->Append(ID_WRAP, "Wrap mode", "Activate wrapping at pixel 200.");
-   edit_menu->Append(ID_NOWRAP, "No-wrap mode", "Deactivate wrapping.");
+   edit_menu->Append(ID_WRAP, "&Wrap mode", "Activate wrapping at pixel 200.");
+   edit_menu->Append(ID_NOWRAP, "&No-wrap mode", "Deactivate wrapping.");
    edit_menu->AppendSeparator();
-   edit_menu->Append(ID_PASTE, "Paste", "Paste text from clipboard.");
-   menu_bar->Append(edit_menu, "Edit" );
+   edit_menu->Append(ID_COPY, "&Copy", "Copy text to clipboard.");
+   edit_menu->Append(ID_CUT, "Cu&t", "Cut text to clipboard.");
+   edit_menu->Append(ID_PASTE,"&Paste", "Paste text from clipboard.");
+   edit_menu->Append(ID_FIND, "&Find", "Find text.");
+   menu_bar->Append(edit_menu, "&Edit" );
 
 #ifndef __WXMSW__
    menu_bar->Show( TRUE );
 #endif // MSW
-  
+
    SetMenuBar( menu_bar );
 
    m_lwin = new wxLayoutWindow(this);
+   m_lwin->SetStatusBar(GetStatusBar(), 0, 1);
    m_lwin->SetMouseTracking(true);
    m_lwin->SetEditable(true);
    m_lwin->SetWrapMargin(40);
    m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false);
    m_lwin->SetFocus();
+
+   // create and set the background bitmap (this will result in a lattice)
+   static const int sizeBmp = 10;
+   wxBitmap *bitmap = new wxBitmap(sizeBmp, sizeBmp);
+   wxMemoryDC dcMem;
+   dcMem.SelectObject( *bitmap );
+   dcMem.SetBackground( *wxWHITE_BRUSH );
+   dcMem.Clear();
+
+   dcMem.SetPen( *wxGREEN_PEN );
+   dcMem.DrawLine(sizeBmp/2, 0, sizeBmp/2, sizeBmp);
+   dcMem.DrawLine(0, sizeBmp/2, sizeBmp, sizeBmp/2);
+
+   dcMem.SelectObject( wxNullBitmap );
+
+   m_lwin->SetBackgroundBitmap(bitmap);
 };
 
 void
 MyFrame::AddSampleText(wxLayoutList *llist)
 {
+   llist->Clear(wxSWISS,16,wxNORMAL,wxNORMAL, false);
+   llist->SetFont(-1,-1,-1,-1,-1,"blue");
+   llist->Insert("blue");
+   llist->SetFont(-1,-1,-1,-1,-1,"black");
+   llist->Insert("The quick brown fox jumps over the lazy dog.");
+   llist->LineBreak();
+
    llist->SetFont(wxROMAN,16,wxNORMAL,wxNORMAL, false);
    llist->Insert("--");
    llist->LineBreak();
@@ -124,7 +158,6 @@ MyFrame::AddSampleText(wxLayoutList *llist)
    llist->SetFontWeight(wxNORMAL);
    llist->Insert("The quick brown fox jumps...");
    llist->LineBreak();
-
    llist->Insert("over the lazy dog.");
    llist->SetFont(-1,-1,-1,-1,true);
    llist->Insert("underlined");
@@ -137,7 +170,6 @@ MyFrame::AddSampleText(wxLayoutList *llist)
    llist->Insert("italics ");
    llist->SetFont(-1,-1,wxNORMAL);
    llist->LineBreak();
-   
    llist->Insert("and ");
    llist->SetFont(-1,-1,wxSLANT);
    llist->Insert("slanted");
@@ -169,6 +201,12 @@ MyFrame::AddSampleText(wxLayoutList *llist)
    llist->Insert("And here the source for the test program:");
    llist->LineBreak();
    llist->SetFont(wxTELETYPE,16);
+   llist->Insert("And here the source for the test program:");
+   llist->LineBreak();
+   llist->Insert("And here the source for the test program:");
+   llist->LineBreak();
+   llist->Insert("And here the source for the test program:");
+
    char buffer[1024];
    FILE *in = fopen("wxLayout.cpp","r");
    if(in)
@@ -178,10 +216,10 @@ MyFrame::AddSampleText(wxLayoutList *llist)
          fgets(buffer,1024,in);
          if(feof(in))
             break;
-         llist->Insert(buffer);
-         llist->LineBreak();
+         wxLayoutImportText(llist, buffer);
       }
    }
+
    llist->MoveCursorTo(wxPoint(0,0));
    m_lwin->SetDirty();
    m_lwin->Refresh();
@@ -206,7 +244,7 @@ void MyFrame::OnCommand( wxCommandEvent &event )
       wxPrinter printer;
       wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout"));
       if (! printer.Print(this, &printout, TRUE))
-         wxMessageBox(                           
+         wxMessageBox(
             _("There was a problem with printing the message:\n"
               "perhaps your current printer is not set up correctly?"),
             _("Printing"), wxOK);
@@ -227,6 +265,19 @@ void MyFrame::OnCommand( wxCommandEvent &event )
       break;
    case ID_PASTE:
       m_lwin->Paste();
+      m_lwin->Refresh(FALSE);
+      break;
+   case ID_COPY:
+      m_lwin->Copy();
+      m_lwin->Refresh(FALSE);
+      break;
+   case ID_CUT:
+      m_lwin->Cut();
+      m_lwin->Refresh(FALSE);
+      break;
+   case ID_FIND:
+      m_lwin->Find("void");
+      m_lwin->Refresh(FALSE);
       break;
    case ID_HTML:
    {
@@ -259,6 +310,36 @@ void MyFrame::OnCommand( wxCommandEvent &event )
       }
    }
    break;
+   case ID_LONG_TEST:
+   {
+      wxString line;
+      wxLayoutList *llist = m_lwin->GetLayoutList();
+      for(int i = 1; i < 5000; i++)
+      {
+         line.Printf("This is line number %d.", i);
+         llist->Insert(line);
+         llist->LineBreak();
+      }
+      llist->MoveCursorTo(wxPoint(0,0));
+      m_lwin->SetDirty();
+      m_lwin->Refresh();
+      break;
+   }
+
+   case ID_LINEBREAKS_TEST:
+      wxLayoutImportText(m_lwin->GetLayoutList(),
+                         "This is a text\n"
+                         "with embedded line\n"
+                         "breaks.\n");
+      m_lwin->SetDirty();
+      m_lwin->Refresh();
+      break;
+
+   case ID_URL_TEST:
+      // VZ: this doesn't work, of course, but I think it should -
+      //     wxLayoutWindow should have a flag m_highlightUrls and do it itself
+      //     (instead of doing it manually like M does now)
+      m_lwin->GetLayoutList()->Insert("http://www.wxwindows.org/");
    }
 };
 
@@ -274,7 +355,7 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
    if (! printer.Print(this, &printout, TRUE))
       wxMessageBox(
          "There was a problem printing.\nPerhaps your current printer is not set correctly?",
-         "Printing", wxOK);  
+         "Printing", wxOK);
 }
 
 void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event))
@@ -296,19 +377,18 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
    wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
 #endif
    wxPrintData printData;
-   printData.SetOrientation(orientation);
 
    // Pass two printout objects: for preview, and possible printing.
    wxPrintPreview *preview = new wxPrintPreview(new
                                                 wxLayoutPrintout(
-                                                   m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);  
+                                                   m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
    if (!preview->Ok())
    {
       delete preview;
       wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK);
       return;
    }
-      
+
    wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
    frame->Centre(wxBOTH);
    frame->Initialize();
@@ -320,7 +400,6 @@ void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
    wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
 
    wxPrintData printData;
-   printData.SetOrientation(orientation);
 
    // Pass two printout objects: for preview, and possible printing.
    wxPrintPreview *preview = new wxPrintPreview(new wxLayoutPrintout( m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
@@ -332,23 +411,13 @@ void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
 {
-#ifdef __WXMSW__
+#ifdef OS_WIN
    wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
 #else
    wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
 #endif
-   wxPrintData data;
-   data.SetOrientation(orientation);
-
-#ifdef __WXMSW__
-   wxPrintDialog printerDialog(this, & data);
-#else
-   wxGenericPrintDialog printerDialog(this, & data);
-#endif
-   printerDialog.GetPrintData().SetSetupDialog(TRUE);
+   wxPrintDialog printerDialog(this, & m_PrintData);
    printerDialog.ShowModal();
-
-   orientation = printerDialog.GetPrintData().GetOrientation();
 }
 
 void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
@@ -359,7 +428,6 @@ void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
    wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
 #endif
    wxPageSetupData data;
-   data.SetOrientation(orientation);
 
 #ifdef __WXMSW__
    wxPageSetupDialog pageSetupDialog(this, & data);
@@ -369,7 +437,6 @@ void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
    pageSetupDialog.ShowModal();
 
    data = pageSetupDialog.GetPageSetupData();
-   orientation = data.GetOrientation();
 }
 
 void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event))
@@ -377,17 +444,13 @@ void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event))
    wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
 
    wxPrintData data;
-   data.SetOrientation(orientation);
 
 #ifdef __WXMSW__
    wxPrintDialog printerDialog(this, & data);
 #else
    wxGenericPrintDialog printerDialog(this, & data);
 #endif
-   printerDialog.GetPrintData().SetSetupDialog(TRUE);
    printerDialog.ShowModal();
-
-   orientation = printerDialog.GetPrintData().GetOrientation();
 }
 
 void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
@@ -395,16 +458,12 @@ void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
    wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
 
    wxPageSetupData data;
-   data.SetOrientation(orientation);
-
 #ifdef __WXMSW__
    wxPageSetupDialog pageSetupDialog(this, & data);
 #else
    wxGenericPageSetupDialog pageSetupDialog(this, & data);
 #endif
    pageSetupDialog.ShowModal();
-
-   orientation = pageSetupDialog.GetPageSetupData().GetOrientation();
 }
 
 
@@ -412,7 +471,7 @@ void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
 // MyApp
 //-----------------------------------------------------------------------------
 
-MyApp::MyApp(void) : 
+MyApp::MyApp(void) :
    wxApp( )
 {
 };