X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e589112ed07376c4dea69920943e8eb3cd30e45b..6c11b5265004937450f8e08d55b8a1476e1452dd:/user/wxLayout/wxLayout.cpp?ds=sidebyside diff --git a/user/wxLayout/wxLayout.cpp b/user/wxLayout/wxLayout.cpp index 74163afbef..b4cd05060c 100644 --- a/user/wxLayout/wxLayout.cpp +++ b/user/wxLayout/wxLayout.cpp @@ -1,6 +1,6 @@ /* * Program: wxLayout - * + * * Author: Karsten Ballüder * * Copyright: (C) 1998, Karsten Ballüder @@ -36,9 +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_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_LONG_TEST }; + ID_TEST, ID_LINEBREAKS_TEST, ID_LONG_TEST, ID_URL_TEST }; IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) @@ -59,14 +59,15 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) 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"); @@ -80,39 +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_LONG_TEST, "Add many lines"); + 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_WRAP, "Wrap mode", "Activate wrapping at pixel 200."); - edit_menu->Append(ID_NOWRAP, "No-wrap mode", "Deactivate wrapping."); + 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_PASTE, "Paste", "Paste text from clipboard."); - menu_bar->Append(edit_menu, "Edit" ); + 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_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(); @@ -127,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"); @@ -140,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"); @@ -172,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) @@ -181,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(); @@ -209,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); @@ -230,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: { @@ -277,6 +325,21 @@ void MyFrame::OnCommand( wxCommandEvent &event ) 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/"); } }; @@ -292,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)) @@ -318,14 +381,14 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) // 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(); @@ -408,7 +471,7 @@ void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event)) // MyApp //----------------------------------------------------------------------------- -MyApp::MyApp(void) : +MyApp::MyApp(void) : wxApp( ) { };