X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b412f9be504e07559a98ae234f30bb1bd0b2aa1f..617ec45690c340d059726a09ccfe4bab9a42d82e:/samples/wxpoem/wxpoem.cpp diff --git a/samples/wxpoem/wxpoem.cpp b/samples/wxpoem/wxpoem.cpp index dea7b5ac0f..2a2d89c031 100644 --- a/samples/wxpoem/wxpoem.cpp +++ b/samples/wxpoem/wxpoem.cpp @@ -26,9 +26,7 @@ #endif #ifndef WX_PRECOMP -#include "wx/defs.h" -#include "wx/list.h" -#include "wx/utils.h" +#include "wx/wx.h" #endif #include "wx/help.h" @@ -47,6 +45,13 @@ #include #include +#ifdef __WINDOWS__ +#include +#ifdef DrawText +#undef DrawText +#endif +#endif + #define buf_size 10000 #define DEFAULT_POETRY_DAT "wxpoem" #define DEFAULT_POETRY_IND "wxpoem" @@ -76,8 +81,6 @@ static bool same_search = FALSE; // Searching on same string static long poem_index[600]; // Index of poem starts static long nitems = 0; // Number of poems -static int desired_char_height = DEFAULT_CHAR_HEIGHT; // Desired height -static char DesiredFont[64]; // Chosen font static int char_height = DEFAULT_CHAR_HEIGHT; // Actual height static int index_ptr = -1; // Pointer into index static int poem_height, poem_width; // Size of poem @@ -128,13 +131,10 @@ void CopyToClipboard(HWND, char *); #endif wxMenu *popupMenu = NULL; -void PopupFunction(wxMenu& menu, wxCommandEvent& event); -wxHelpController *HelpController = NULL; - -// A macro needed for some compilers (AIX) that need 'main' to be defined -// in the application itself. -IMPLEMENT_WXWIN_MAIN +#if wxUSE_HELP + wxHelpController *HelpController = NULL; +#endif // wxUSE_HELP IMPLEMENT_APP(MyApp) @@ -151,6 +151,7 @@ void CreateFonts() BEGIN_EVENT_TABLE(MainWindow, wxFrame) EVT_CLOSE(MainWindow::OnCloseWindow) EVT_CHAR(MainWindow::OnChar) + EVT_MENU(-1, MainWindow::OnPopup) END_EVENT_TABLE() MainWindow::MainWindow(wxFrame *frame, wxWindowID id, const wxString& title, @@ -331,7 +332,7 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y) dc->GetTextExtent(line, &xx, &yy); FindMax(&curr_width, (int)xx); - + if (DrawIt) { int x = (int)((width - xx)/2.0); @@ -400,7 +401,7 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y) dc->DrawLine(width-THIN_LINE_BORDER, THIN_LINE_BORDER, width-THIN_LINE_BORDER, height-THIN_LINE_BORDER); dc->DrawLine(width-THIN_LINE_BORDER, height-THIN_LINE_BORDER, THIN_LINE_BORDER, height-THIN_LINE_BORDER); dc->DrawLine(THIN_LINE_BORDER, height-THIN_LINE_BORDER, THIN_LINE_BORDER, THIN_LINE_BORDER); - + // Right and bottom white lines - 'grey' (black!) if // we're running on a mono display. if (wxColourDisplay()) @@ -584,13 +585,15 @@ void CopyToClipboard(HWND handle, char *s) bool MyApp::OnInit() { poem_buffer = new char[buf_size]; - + GreyPen = new wxPen("LIGHT GREY", THICK_LINE_WIDTH, wxSOLID); DarkGreyPen = new wxPen("GREY", THICK_LINE_WIDTH, wxSOLID); WhitePen = new wxPen("WHITE", THICK_LINE_WIDTH, wxSOLID); +#if wxUSE_HELP HelpController = new wxHelpController(); HelpController->Initialize("wxpoem"); +#endif // wxUSE_HELP CreateFonts(); @@ -605,15 +608,15 @@ bool MyApp::OnInit() // randomize(); pages[0] = 0; - TheMainWindow = new MainWindow(NULL, -1, "wxPoem", wxPoint(XPos, YPos), wxSize(100, 100), wxCAPTION|wxMINIMIZE_BOX|wxSYSTEM_MENU); + TheMainWindow = new MainWindow(NULL, 500, "wxPoem", wxPoint(XPos, YPos), wxSize(100, 100), wxCAPTION|wxMINIMIZE_BOX|wxSYSTEM_MENU); #ifdef wx_x TheMainWindow->SetIcon(Icon("wxpoem")); #endif - TheMainWindow->canvas = new MyCanvas(TheMainWindow, -1, wxDefaultPosition, wxDefaultSize); + TheMainWindow->canvas = new MyCanvas(TheMainWindow, 501, wxDefaultPosition, wxDefaultSize); - popupMenu = new wxMenu("", (wxFunction)PopupFunction); + popupMenu = new wxMenu; popupMenu->Append(POEM_NEXT, "Next poem/page"); popupMenu->Append(POEM_PREVIOUS, "Previous page"); popupMenu->AppendSeparator(); @@ -665,7 +668,9 @@ int MyApp::OnExit() { if (backingBitmap) delete backingBitmap; +#if wxUSE_HELP delete HelpController; +#endif // wxUSE_HELP delete GreyPen; delete DarkGreyPen; delete WhitePen; @@ -694,7 +699,7 @@ void MainWindow::OnChar(wxKeyEvent& event) canvas->OnChar(event); } -BEGIN_EVENT_TABLE(MyCanvas, wxPanel) +BEGIN_EVENT_TABLE(MyCanvas, wxWindow) EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent) EVT_CHAR(MyCanvas::OnChar) EVT_PAINT(MyCanvas::OnPaint) @@ -702,7 +707,7 @@ END_EVENT_TABLE() // Define a constructor for my canvas MyCanvas::MyCanvas(wxFrame *frame, wxWindowID id, const wxPoint& pos, const wxSize& size): - wxPanel(frame, id, pos, size) + wxWindow(frame, id, pos, size) { } @@ -715,7 +720,7 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { int xx, yy; TheMainWindow->GetClientSize(&xx, &yy); - + wxMemoryDC memDC; memDC.SelectObject(* backingBitmap); dc.Blit(0, 0, backingBitmap->GetWidth(), backingBitmap->GetHeight(), &memDC, 0, 0); @@ -724,20 +729,15 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) void MyCanvas::OnMouseEvent(wxMouseEvent& event) { - float x, y; - event.Position(&x, &y); static int startPosX, startPosY, startFrameX, startFrameY; - event.Position(&x, &y); + long x, y; + event.GetPosition(&x, &y); if (event.RightDown()) { // Versions from wxWin 1.67 are probably OK -#if 0 // wx_motif - FakePopupMenu(popupMenu, x, y); -#else PopupMenu(popupMenu, (int)x, (int)y ); -#endif } else if (event.LeftDown()) { @@ -756,7 +756,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event) int x1 = (int)x; int y1 = (int)y; ClientToScreen(&x1, &y1); - + int dX = x1 - startPosX; int dY = y1 - startPosY; GetParent()->Move(startFrameX + dX, startFrameY + dY); @@ -1067,13 +1067,13 @@ bool Compile(void) fprintf(file, "%ld\n\n", nitems); for (j = 0; j < nitems; j++) fprintf(file, "%ld\n", poem_index[j]); - + fclose(file); PoetryNotify("Poetry index compiled."); return TRUE; } -void PopupFunction(wxMenu& /*menu*/, wxCommandEvent& event) +void MainWindow::OnPopup(wxCommandEvent& event) { switch (event.GetId()) { @@ -1125,8 +1125,10 @@ void PopupFunction(wxMenu& /*menu*/, wxCommandEvent& event) } case POEM_HELP_CONTENTS: { +#if wxUSE_HELP HelpController->LoadFile("wxpoem"); HelpController->DisplayContents(); +#endif // wxUSE_HELP break; } case POEM_ABOUT: