#include "wxpoem.h"
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "corner1.xpm"
#include "corner2.xpm"
#include "corner3.xpm"
#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"
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
wxHelpController *HelpController = NULL;
-// A macro needed for some compilers (AIX) that need 'main' to be defined
-// in the application itself.
-IMPLEMENT_WXWIN_MAIN
-
IMPLEMENT_APP(MyApp)
MainWindow *TheMainWindow = NULL;
{
}
+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)
dc->GetTextExtent(line, &xx, &yy);
FindMax(&curr_width, (int)xx);
-
+
if (DrawIt)
{
int x = (int)((width - xx)/2.0);
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())
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);
// 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->Append(POEM_NEXT, "Next poem/page");
Corner3 = new wxIcon("icon_3");
Corner4 = new wxIcon("icon_4");
#endif
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
Corner1 = new wxIcon( corner1_xpm );
Corner2 = new wxIcon( corner2_xpm );
Corner3 = new wxIcon( corner3_xpm );
if (backingBitmap)
delete backingBitmap;
delete HelpController;
- delete popupMenu;
delete GreyPen;
delete DarkGreyPen;
delete WhitePen;
-//#ifdef __WXMSW__
delete Corner1;
delete Corner2;
delete Corner3;
delete Corner4;
-//#endif
delete NormalFont;
delete BoldFont;
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)
// 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)
{
}
{
int xx, yy;
TheMainWindow->GetClientSize(&xx, &yy);
-
+
wxMemoryDC memDC;
memDC.SelectObject(* backingBitmap);
dc.Blit(0, 0, backingBitmap->GetWidth(), backingBitmap->GetHeight(), &memDC, 0, 0);
void MyCanvas::OnMouseEvent(wxMouseEvent& event)
{
- float x, y;
+ long x, y;
event.Position(&x, &y);
static int startPosX, startPosY, startFrameX, startFrameY;
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())
{
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);
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)
{
- switch (event.m_commandInt)
+ switch (event.GetId())
{
case POEM_NEXT:
// Another poem/page