More wxWidgets in wxPoem demo code.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32964 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -31,13 +31,11 @@
|
|||||||
|
|
||||||
#include "wxpoem.h"
|
#include "wxpoem.h"
|
||||||
|
|
||||||
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
|
|
||||||
#include "corner1.xpm"
|
#include "corner1.xpm"
|
||||||
#include "corner2.xpm"
|
#include "corner2.xpm"
|
||||||
#include "corner3.xpm"
|
#include "corner3.xpm"
|
||||||
#include "corner4.xpm"
|
#include "corner4.xpm"
|
||||||
#include "wxpoem.xpm"
|
#include "wxpoem.xpm"
|
||||||
#endif
|
|
||||||
|
|
||||||
#define buf_size 10000
|
#define buf_size 10000
|
||||||
#define DEFAULT_POETRY_DAT "wxpoem"
|
#define DEFAULT_POETRY_DAT "wxpoem"
|
||||||
@@ -82,16 +80,6 @@ static bool index_ok = false; // Index loaded ok
|
|||||||
static bool paging = false; // Are we paging?
|
static bool paging = false; // Are we paging?
|
||||||
static int current_page = 0; // Currently viewed page
|
static int current_page = 0; // Currently viewed page
|
||||||
|
|
||||||
wxIcon *Corner1 = NULL;
|
|
||||||
wxIcon *Corner2 = NULL;
|
|
||||||
wxIcon *Corner3 = NULL;
|
|
||||||
wxIcon *Corner4 = NULL;
|
|
||||||
|
|
||||||
// Pens
|
|
||||||
wxPen *GreyPen = NULL;
|
|
||||||
wxPen *DarkGreyPen = NULL;
|
|
||||||
wxPen *WhitePen = NULL;
|
|
||||||
|
|
||||||
// Backing bitmap
|
// Backing bitmap
|
||||||
wxBitmap *backingBitmap = NULL;
|
wxBitmap *backingBitmap = NULL;
|
||||||
|
|
||||||
@@ -135,8 +123,28 @@ MainWindow::MainWindow(wxFrame *frame, wxWindowID id, const wxString& title,
|
|||||||
const wxPoint& pos, const wxSize& size, long style):
|
const wxPoint& pos, const wxSize& size, long style):
|
||||||
wxFrame(frame, id, title, pos, size, style)
|
wxFrame(frame, id, title, pos, size, style)
|
||||||
{
|
{
|
||||||
|
m_corners[0] = m_corners[1] = m_corners[2] = m_corners[3] = NULL;
|
||||||
|
|
||||||
ReadPreferences();
|
ReadPreferences();
|
||||||
CreateFonts();
|
CreateFonts();
|
||||||
|
|
||||||
|
SetIcon(wxpoem_xpm);
|
||||||
|
|
||||||
|
m_corners[0] = new wxIcon( corner1_xpm );
|
||||||
|
m_corners[1] = new wxIcon( corner2_xpm );
|
||||||
|
m_corners[2] = new wxIcon( corner3_xpm );
|
||||||
|
m_corners[3] = new wxIcon( corner4_xpm );
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
for (int i=0;i<4;i++)
|
||||||
|
{
|
||||||
|
if(m_corners[i])
|
||||||
|
{
|
||||||
|
delete m_corners[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the poetry buffer, either for finding the size
|
// Read the poetry buffer, either for finding the size
|
||||||
@@ -167,7 +175,7 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y)
|
|||||||
if (DrawIt && wxColourDisplay())
|
if (DrawIt && wxColourDisplay())
|
||||||
{
|
{
|
||||||
dc->SetBrush(*wxLIGHT_GREY_BRUSH);
|
dc->SetBrush(*wxLIGHT_GREY_BRUSH);
|
||||||
dc->SetPen(*GreyPen);
|
dc->SetPen(*wxGREY_PEN);
|
||||||
dc->DrawRectangle(0, 0, width, height);
|
dc->DrawRectangle(0, 0, width, height);
|
||||||
dc->SetBackgroundMode(wxTRANSPARENT);
|
dc->SetBackgroundMode(wxTRANSPARENT);
|
||||||
}
|
}
|
||||||
@@ -378,9 +386,9 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y)
|
|||||||
// Right and bottom white lines - 'grey' (black!) if
|
// Right and bottom white lines - 'grey' (black!) if
|
||||||
// we're running on a mono display.
|
// we're running on a mono display.
|
||||||
if (wxColourDisplay())
|
if (wxColourDisplay())
|
||||||
dc->SetPen(*WhitePen);
|
dc->SetPen(*wxWHITE_PEN);
|
||||||
else
|
else
|
||||||
dc->SetPen(*DarkGreyPen);
|
dc->SetPen(*wxBLACK_PEN);
|
||||||
|
|
||||||
dc->DrawLine(width-THICK_LINE_BORDER, THICK_LINE_BORDER,
|
dc->DrawLine(width-THICK_LINE_BORDER, THICK_LINE_BORDER,
|
||||||
width-THICK_LINE_BORDER, height-THICK_LINE_BORDER);
|
width-THICK_LINE_BORDER, height-THICK_LINE_BORDER);
|
||||||
@@ -388,20 +396,20 @@ void MainWindow::ScanBuffer(wxDC *dc, bool DrawIt, int *max_x, int *max_y)
|
|||||||
THICK_LINE_BORDER, height-THICK_LINE_BORDER);
|
THICK_LINE_BORDER, height-THICK_LINE_BORDER);
|
||||||
|
|
||||||
// Left and top grey lines
|
// Left and top grey lines
|
||||||
dc->SetPen(*DarkGreyPen);
|
dc->SetPen(*wxBLACK_PEN);
|
||||||
dc->DrawLine(THICK_LINE_BORDER, height-THICK_LINE_BORDER,
|
dc->DrawLine(THICK_LINE_BORDER, height-THICK_LINE_BORDER,
|
||||||
THICK_LINE_BORDER, THICK_LINE_BORDER);
|
THICK_LINE_BORDER, THICK_LINE_BORDER);
|
||||||
dc->DrawLine(THICK_LINE_BORDER, THICK_LINE_BORDER,
|
dc->DrawLine(THICK_LINE_BORDER, THICK_LINE_BORDER,
|
||||||
width-THICK_LINE_BORDER, THICK_LINE_BORDER);
|
width-THICK_LINE_BORDER, THICK_LINE_BORDER);
|
||||||
|
|
||||||
// Draw icons
|
// Draw icons
|
||||||
dc->DrawIcon(* Corner1, 0, 0);
|
dc->DrawIcon(* m_corners[0], 0, 0);
|
||||||
dc->DrawIcon(* Corner2, int(width-32), 0);
|
dc->DrawIcon(* m_corners[1], int(width-32), 0);
|
||||||
|
|
||||||
int y2 = height - 32;
|
int y2 = height - 32;
|
||||||
int x2 = (width-32);
|
int x2 = (width-32);
|
||||||
dc->DrawIcon(* Corner3, 0, y2);
|
dc->DrawIcon(* m_corners[2], 0, y2);
|
||||||
dc->DrawIcon(* Corner4, x2, y2);
|
dc->DrawIcon(* m_corners[3], x2, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,91 +521,64 @@ void MainWindow::Search(bool ask)
|
|||||||
|
|
||||||
bool MyApp::OnInit()
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
poem_buffer = new wxChar[buf_size];
|
poem_buffer = new wxChar[buf_size];
|
||||||
|
|
||||||
GreyPen = new wxPen(_T("LIGHT GREY"), THICK_LINE_WIDTH, wxSOLID);
|
// Seed the random number generator
|
||||||
DarkGreyPen = new wxPen(_T("GREY"), THICK_LINE_WIDTH, wxSOLID);
|
|
||||||
WhitePen = new wxPen(_T("WHITE"), THICK_LINE_WIDTH, wxSOLID);
|
|
||||||
|
|
||||||
// Seed the random number generator
|
|
||||||
#ifdef __WXWINCE__
|
#ifdef __WXWINCE__
|
||||||
srand((unsigned) CeGetRandomSeed());
|
srand((unsigned) CeGetRandomSeed());
|
||||||
#else
|
#else
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
|
|
||||||
(void)time(¤t_time);
|
(void)time(¤t_time);
|
||||||
srand((unsigned int)current_time);
|
srand((unsigned int)current_time);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// randomize();
|
// randomize();
|
||||||
pages[0] = 0;
|
pages[0] = 0;
|
||||||
|
|
||||||
TheMainWindow = new MainWindow(NULL,
|
TheMainWindow = new MainWindow(NULL,
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
_T("wxPoem"),
|
_T("wxPoem"),
|
||||||
wxPoint(XPos, YPos),
|
wxPoint(XPos, YPos),
|
||||||
wxDefaultSize,
|
wxDefaultSize,
|
||||||
wxCAPTION|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCLOSE_BOX|wxFULL_REPAINT_ON_RESIZE
|
wxCAPTION|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCLOSE_BOX|wxFULL_REPAINT_ON_RESIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
TheMainWindow->SetIcon(wxICON(wxpoem));
|
TheMainWindow->canvas = new MyCanvas(TheMainWindow);
|
||||||
|
|
||||||
TheMainWindow->canvas = new MyCanvas(TheMainWindow);
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
index_filename = wxStrcpy(new wxChar[wxStrlen(argv[1]) + 1], argv[1]);
|
||||||
|
data_filename = wxStrcpy(new wxChar[wxStrlen(argv[1]) + 1], argv[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index_filename = _T(DEFAULT_POETRY_IND);
|
||||||
|
data_filename = _T(DEFAULT_POETRY_DAT);
|
||||||
|
}
|
||||||
|
TryLoadIndex();
|
||||||
|
|
||||||
if (argc > 1)
|
TheMainWindow->GetIndexLoadPoem();
|
||||||
{
|
TheMainWindow->Resize();
|
||||||
index_filename = wxStrcpy(new wxChar[wxStrlen(argv[1]) + 1], argv[1]);
|
TheMainWindow->Show(true);
|
||||||
data_filename = wxStrcpy(new wxChar[wxStrlen(argv[1]) + 1], argv[1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
index_filename = _T(DEFAULT_POETRY_IND);
|
|
||||||
data_filename = _T(DEFAULT_POETRY_DAT);
|
|
||||||
}
|
|
||||||
TryLoadIndex();
|
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
return true;
|
||||||
Corner1 = new wxIcon(_T("icon_1"));
|
|
||||||
Corner2 = new wxIcon(_T("icon_2"));
|
|
||||||
Corner3 = new wxIcon(_T("icon_3"));
|
|
||||||
Corner4 = new wxIcon(_T("icon_4"));
|
|
||||||
#endif
|
|
||||||
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
|
|
||||||
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->Show(true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int MyApp::OnExit()
|
int MyApp::OnExit()
|
||||||
{
|
{
|
||||||
if (backingBitmap)
|
if (backingBitmap)
|
||||||
delete backingBitmap;
|
delete backingBitmap;
|
||||||
delete GreyPen;
|
|
||||||
delete DarkGreyPen;
|
|
||||||
delete WhitePen;
|
|
||||||
|
|
||||||
delete Corner1;
|
delete[] poem_buffer;
|
||||||
delete Corner2;
|
|
||||||
delete Corner3;
|
|
||||||
delete Corner4;
|
|
||||||
|
|
||||||
delete[] poem_buffer;
|
return 0;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
void MainWindow::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
WritePreferences();
|
WritePreferences();
|
||||||
this->Destroy();
|
this->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnChar(wxKeyEvent& event)
|
void MainWindow::OnChar(wxKeyEvent& event)
|
||||||
@@ -866,14 +847,14 @@ long MainWindow::DoSearch(void)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
long i = 0;
|
size_t i = 0;
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
wxChar buf[100];
|
wxChar buf[100];
|
||||||
long find_start;
|
long find_start;
|
||||||
long previous_poem_start;
|
long previous_poem_start;
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
int search_length = m_searchString.length();
|
size_t search_length = m_searchString.length();
|
||||||
|
|
||||||
if (same_search)
|
if (same_search)
|
||||||
{
|
{
|
||||||
|
@@ -51,6 +51,7 @@ class MainWindow: public wxFrame
|
|||||||
public:
|
public:
|
||||||
MyCanvas *canvas;
|
MyCanvas *canvas;
|
||||||
MainWindow(wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style);
|
MainWindow(wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style);
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
void OnCloseWindow(wxCloseEvent& event);
|
void OnCloseWindow(wxCloseEvent& event);
|
||||||
void OnChar(wxKeyEvent& event);
|
void OnChar(wxKeyEvent& event);
|
||||||
@@ -90,6 +91,9 @@ private:
|
|||||||
wxFont *m_boldFont;
|
wxFont *m_boldFont;
|
||||||
wxFont *m_italicFont;
|
wxFont *m_italicFont;
|
||||||
|
|
||||||
|
// Icons
|
||||||
|
wxIcon *m_corners[4];
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,11 +1,4 @@
|
|||||||
aaaa ICON "wxpoem.ico"
|
aaaa ICON "wxpoem.ico"
|
||||||
wxpoem ICON "wxpoem.ico"
|
|
||||||
wxSTD_FRAME ICON "wxpoem.ico"
|
|
||||||
|
|
||||||
icon_1 ICON "corner1.ico"
|
|
||||||
icon_2 ICON "corner2.ico"
|
|
||||||
icon_3 ICON "corner3.ico"
|
|
||||||
icon_4 ICON "corner4.ico"
|
|
||||||
|
|
||||||
#include "wx/msw/wx.rc"
|
#include "wx/msw/wx.rc"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user