]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/wxpoem/wxpoem.cpp
Added the forgotten file txtstrm.tex
[wxWidgets.git] / samples / wxpoem / wxpoem.cpp
index 86c292b9f9a01cd0c3ad9410cdba1bb37460c074..4890c8f92aa5a213f61189e0ff6aaadb03723fe4 100644 (file)
 #endif
 
 #ifndef WX_PRECOMP
 #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"
 
 #include "wxpoem.h"
 
 #endif
 
 #include "wx/help.h"
 
 #include "wxpoem.h"
 
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+#include "corner1.xpm"
+#include "corner2.xpm"
+#include "corner3.xpm"
+#include "corner4.xpm"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
 
+#ifdef __WINDOWS__
+#include <windows.h>
+#ifdef DrawText
+#undef DrawText
+#endif
+#endif
+
 #define         buf_size 10000
 #define         DEFAULT_POETRY_DAT "wxpoem"
 #define         DEFAULT_POETRY_IND "wxpoem"
 #define         buf_size 10000
 #define         DEFAULT_POETRY_DAT "wxpoem"
 #define         DEFAULT_POETRY_IND "wxpoem"
@@ -69,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 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
 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
@@ -123,11 +133,9 @@ void            CopyToClipboard(HWND, char *);
 wxMenu    *popupMenu = NULL;
 void PopupFunction(wxMenu& menu, wxCommandEvent& event);
 
 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)
 
 
 IMPLEMENT_APP(MyApp)
 
@@ -152,6 +160,14 @@ MainWindow::MainWindow(wxFrame *frame, wxWindowID id, const wxString& title,
 {
 }
 
 {
 }
 
+MainWindow::~MainWindow()
+{
+  // Note: this must be done before the main window/canvas are destroyed
+  // or we get an error (no parent window for menu item button)
+  delete popupMenu;
+  popupMenu = NULL;
+}
+
 // Read the poetry buffer, either for finding the size
 // or for writing to a bitmap (not to the window directly,
 // since that displays messily)
 // Read the poetry buffer, either for finding the size
 // or for writing to a bitmap (not to the window directly,
 // since that displays messily)
@@ -316,13 +332,13 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y)
 
               dc->GetTextExtent(line, &xx, &yy);
               FindMax(&curr_width, (int)xx);
 
               dc->GetTextExtent(line, &xx, &yy);
               FindMax(&curr_width, (int)xx);
-    
+
               if (DrawIt)
               {
                 int x = (int)((width - xx)/2.0);
                 dc->SetFont(* NormalFont);
                 dc->SetTextForeground(* wxBLACK);
               if (DrawIt)
               {
                 int x = (int)((width - xx)/2.0);
                 dc->SetFont(* NormalFont);
                 dc->SetTextForeground(* wxBLACK);
-                dc->DrawText(line, (float)x, (float)y);
+                dc->DrawText(line, x, y);
               }
            }
         }
               }
            }
         }
@@ -343,7 +359,7 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y)
          int x = (int)((width - xx)/2.0);
          dc->SetFont(* NormalFont);
          dc->SetTextForeground(* wxBLACK);
          int x = (int)((width - xx)/2.0);
          dc->SetFont(* NormalFont);
          dc->SetTextForeground(* wxBLACK);
-         dc->DrawText(cont, (float)x, (float)y);
+         dc->DrawText(cont, x, y);
        }
        y += 2*char_height;
     }
        }
        y += 2*char_height;
     }
@@ -385,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);
       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())
       // Right and bottom white lines - 'grey' (black!) if
       // we're running on a mono display.
       if (wxColourDisplay())
@@ -405,16 +421,16 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y)
       dc->DrawLine(THICK_LINE_BORDER, THICK_LINE_BORDER,
                    width-THICK_LINE_BORDER, THICK_LINE_BORDER);
 
       dc->DrawLine(THICK_LINE_BORDER, THICK_LINE_BORDER,
                    width-THICK_LINE_BORDER, THICK_LINE_BORDER);
 
-#ifdef __WXMSW__
+//#ifdef __WXMSW__
       // Draw icons
       // Draw icons
-      dc->DrawIcon(* Corner1, 0.0, 0.0);
-      dc->DrawIcon(* Corner2, (float)(width-32.0), 0.0);
+      dc->DrawIcon(* Corner1, 00);
+      dc->DrawIcon(* Corner2, int(width-32), 0);
 
       int y2 = height - 32;
       int x2 = (width-32);
 
       int y2 = height - 32;
       int x2 = (width-32);
-      dc->DrawIcon(* Corner3, 0.0, (float)y2);
-      dc->DrawIcon(* Corner4, (float)x2, (float)y2);
-#endif
+      dc->DrawIcon(* Corner3, 0y2);
+      dc->DrawIcon(* Corner4, x2, y2);
+//#endif
     }
 }
 
     }
 }
 
@@ -569,13 +585,15 @@ void CopyToClipboard(HWND handle, char *s)
 bool MyApp::OnInit()
 {
   poem_buffer = new char[buf_size];
 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);
 
   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");
   HelpController = new wxHelpController();
   HelpController->Initialize("wxpoem");
+#endif // wxUSE_HELP
 
   CreateFonts();
 
 
   CreateFonts();
 
@@ -590,13 +608,13 @@ bool MyApp::OnInit()
 //    randomize();
   pages[0] = 0;
 
 //    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
 
 
 #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->Append(POEM_NEXT, "Next poem/page");
 
   popupMenu = new wxMenu("", (wxFunction)PopupFunction);
   popupMenu->Append(POEM_NEXT, "Next poem/page");
@@ -632,6 +650,12 @@ bool MyApp::OnInit()
   Corner3 = new wxIcon("icon_3");
   Corner4 = new wxIcon("icon_4");
 #endif
   Corner3 = new wxIcon("icon_3");
   Corner4 = new wxIcon("icon_4");
 #endif
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+  Corner1 = new wxIcon( corner1_xpm );
+  Corner2 = new wxIcon( corner2_xpm );
+  Corner3 = new wxIcon( corner3_xpm );
+  Corner4 = new wxIcon( corner4_xpm );
+#endif
 
   TheMainWindow->GetIndexLoadPoem();
   TheMainWindow->Resize();
 
   TheMainWindow->GetIndexLoadPoem();
   TheMainWindow->Resize();
@@ -644,18 +668,18 @@ int MyApp::OnExit()
 {
   if (backingBitmap)
     delete backingBitmap;
 {
   if (backingBitmap)
     delete backingBitmap;
+#if wxUSE_HELP
   delete HelpController;
   delete HelpController;
-  delete popupMenu;
+#endif // wxUSE_HELP
   delete GreyPen;
   delete DarkGreyPen;
   delete WhitePen;
 
   delete GreyPen;
   delete DarkGreyPen;
   delete WhitePen;
 
-#ifdef __WXMSW__
   delete Corner1;
   delete Corner2;
   delete Corner3;
   delete Corner4;
   delete Corner1;
   delete Corner2;
   delete Corner3;
   delete Corner4;
-#endif
+
   delete NormalFont;
   delete BoldFont;
   delete ItalicFont;
   delete NormalFont;
   delete BoldFont;
   delete ItalicFont;
@@ -664,7 +688,7 @@ int MyApp::OnExit()
   return 0;
 }
 
   return 0;
 }
 
-void MainWindow::OnCloseWindow(wxCloseEvent& event)
+void MainWindow::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 {
   WritePreferences();
   this->Destroy();
 {
   WritePreferences();
   this->Destroy();
@@ -675,7 +699,7 @@ void MainWindow::OnChar(wxKeyEvent& event)
     canvas->OnChar(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)
     EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent)
     EVT_CHAR(MyCanvas::OnChar)
     EVT_PAINT(MyCanvas::OnPaint)
@@ -683,12 +707,12 @@ END_EVENT_TABLE()
 
 // Define a constructor for my canvas
 MyCanvas::MyCanvas(wxFrame *frame, wxWindowID id, const wxPoint& pos, const wxSize& size):
 
 // 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)
 {
 }
 
 // Define the repainting behaviour
 {
 }
 
 // Define the repainting behaviour
-void MyCanvas::OnPaint(wxPaintEvent& event)
+void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
     wxPaintDC dc(this);
 
 {
     wxPaintDC dc(this);
 
@@ -696,7 +720,7 @@ void MyCanvas::OnPaint(wxPaintEvent& event)
     {
         int xx, yy;
         TheMainWindow->GetClientSize(&xx, &yy);
     {
         int xx, yy;
         TheMainWindow->GetClientSize(&xx, &yy);
-    
+
         wxMemoryDC memDC;
         memDC.SelectObject(* backingBitmap);
         dc.Blit(0, 0, backingBitmap->GetWidth(), backingBitmap->GetHeight(), &memDC, 0, 0);
         wxMemoryDC memDC;
         memDC.SelectObject(* backingBitmap);
         dc.Blit(0, 0, backingBitmap->GetWidth(), backingBitmap->GetHeight(), &memDC, 0, 0);
@@ -705,7 +729,7 @@ void MyCanvas::OnPaint(wxPaintEvent& event)
 
 void MyCanvas::OnMouseEvent(wxMouseEvent& event)
 {
 
 void MyCanvas::OnMouseEvent(wxMouseEvent& event)
 {
-  float x, y;
+  long x, y;
   event.Position(&x, &y);
   static int startPosX, startPosY, startFrameX, startFrameY;
 
   event.Position(&x, &y);
   static int startPosX, startPosY, startFrameX, startFrameY;
 
@@ -714,11 +738,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
   if (event.RightDown())
   {
     // Versions from wxWin 1.67 are probably OK
   if (event.RightDown())
   {
     // Versions from wxWin 1.67 are probably OK
-#if 0 // wx_motif
-    FakePopupMenu(popupMenu, x, y);
-#else
-    PopupMenu(popupMenu, x, y);
-#endif
+    PopupMenu(popupMenu, (int)x, (int)y );
   }
   else if (event.LeftDown())
   {
   }
   else if (event.LeftDown())
   {
@@ -737,7 +757,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
     int x1 = (int)x;
     int y1 = (int)y;
     ClientToScreen(&x1, &y1);
     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);
     int dX = x1 - startPosX;
     int dY = y1 - startPosY;
     GetParent()->Move(startFrameX + dX, startFrameY + dY);
@@ -839,8 +859,8 @@ bool LoadPoem(char *file_name, long position)
 {
     int ch = 0;
     int i = 0;
 {
     int ch = 0;
     int i = 0;
-    int j = 0;
-    int indexn = 0;
+//    int j = 0;
+//    int indexn = 0;
     char buf[100];
     long data;
     FILE *data_file;
     char buf[100];
     long data;
     FILE *data_file;
@@ -1048,15 +1068,15 @@ bool Compile(void)
     fprintf(file, "%ld\n\n", nitems);
     for (j = 0; j < nitems; j++)
       fprintf(file, "%ld\n", poem_index[j]);
     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;
 }
 
     fclose(file);
     PoetryNotify("Poetry index compiled.");
     return TRUE;
 }
 
-void PopupFunction(wxMenu& menu, wxCommandEvent& event)
+void PopupFunction(wxMenu& /*menu*/, wxCommandEvent& event)
 {
 {
-  switch (event.m_commandInt)
+  switch (event.GetId())
   {
      case POEM_NEXT:
        // Another poem/page
   {
      case POEM_NEXT:
        // Another poem/page
@@ -1106,8 +1126,10 @@ void PopupFunction(wxMenu& menu, wxCommandEvent& event)
      }
      case POEM_HELP_CONTENTS:
      {
      }
      case POEM_HELP_CONTENTS:
      {
+#if wxUSE_HELP
        HelpController->LoadFile("wxpoem");
        HelpController->DisplayContents();
        HelpController->LoadFile("wxpoem");
        HelpController->DisplayContents();
+#endif // wxUSE_HELP
        break;
      }
      case POEM_ABOUT:
        break;
      }
      case POEM_ABOUT: