]>
git.saurik.com Git - wxWidgets.git/blob - demos/poem/wxpoem.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: A small C++ program which displays a random poem on
4 // execution. It also allows search for poems containing a
6 // It requires winpoem.dat and creates winpoem.idx.
7 // Original version (WinPoem) written in 1994.
8 // This has not been rewritten in a long time so
9 // beware, inelegant code!
10 // Author: Julian Smart
13 // Copyright: (c) 1998 Julian Smart
14 // Licence: wxWindows licence
15 /////////////////////////////////////////////////////////////////////////////
18 #pragma implementation "wxpoem.h"
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
34 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
35 #include "corner1.xpm"
36 #include "corner2.xpm"
37 #include "corner3.xpm"
38 #include "corner4.xpm"
41 #define buf_size 10000
42 #define DEFAULT_POETRY_DAT "wxpoem"
43 #define DEFAULT_POETRY_IND "wxpoem"
44 #define DEFAULT_CHAR_HEIGHT 18
45 #define DEFAULT_FONT "Swiss"
46 #define DEFAULT_X_POS 0
47 #define DEFAULT_Y_POS 0
48 #define BORDER_SIZE 30
49 #define THIN_LINE_BORDER 10
50 #define THICK_LINE_BORDER 16
51 #define THICK_LINE_WIDTH 2
52 #define SHADOW_OFFSET 1
56 static wxChar
*poem_buffer
; // Storage for each poem
57 static wxChar line
[150]; // Storage for a line
58 static wxChar title
[150]; // Remember the title
59 static wxChar
*search_string
= NULL
; // The search string
60 static int pages
[30]; // For multipage poems -
61 // store the start of each page
62 static long last_poem_start
= 0; // Start of last found poem
63 static long last_find
= -1; // Point in file of last found
65 static bool search_ok
= false; // Search was successful
66 static bool same_search
= false; // Searching on same string
68 static long poem_index
[600]; // Index of poem starts
69 static long nitems
= 0; // Number of poems
70 static int char_height
= DEFAULT_CHAR_HEIGHT
; // Actual height
71 static int index_ptr
= -1; // Pointer into index
72 static int poem_height
, poem_width
; // Size of poem
73 static int XPos
; // Startup X position
74 static int YPos
; // Startup Y position
75 static int pointSize
= 12; // Font size
77 static wxChar
*index_filename
= NULL
; // Index filename
78 static wxChar
*data_filename
= NULL
; // Data filename
79 static wxChar error_buf
[300]; // Error message buffer
80 static bool loaded_ok
= false; // Poem loaded ok
81 static bool index_ok
= false; // Index loaded ok
83 static bool paging
= false; // Are we paging?
84 static int current_page
= 0; // Currently viewed page
86 wxIcon
*Corner1
= NULL
;
87 wxIcon
*Corner2
= NULL
;
88 wxIcon
*Corner3
= NULL
;
89 wxIcon
*Corner4
= NULL
;
92 wxFont
*NormalFont
= NULL
;
93 wxFont
*BoldFont
= NULL
;
94 wxFont
*ItalicFont
= NULL
;
97 wxPen
*GreyPen
= NULL
;
98 wxPen
*DarkGreyPen
= NULL
;
99 wxPen
*WhitePen
= NULL
;
102 wxBitmap
*backingBitmap
= NULL
;
104 void PoetryError(wxChar
*, wxChar
*caption
=_T("wxPoem Error"));
105 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
=_T("wxPoem"));
107 bool LoadPoem(wxChar
*, long);
109 int LoadIndex(wxChar
*);
111 void WritePreferences();
112 void ReadPreferences();
113 void FindMax(int *max_thing
, int thing
);
117 #include "wx/dataobj.h"
118 #include "wx/clipbrd.h"
122 STDAPI_(__int64
) CeGetRandomSeed();
127 MainWindow
*TheMainWindow
= NULL
;
132 NormalFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxNORMAL
);
133 BoldFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxBOLD
);
134 ItalicFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxITALIC
, wxNORMAL
);
137 BEGIN_EVENT_TABLE(MainWindow
, wxFrame
)
138 EVT_CLOSE(MainWindow::OnCloseWindow
)
139 EVT_CHAR(MainWindow::OnChar
)
140 EVT_MENU(wxID_ANY
, MainWindow::OnPopup
)
143 MainWindow::MainWindow(wxFrame
*frame
, wxWindowID id
, const wxString
& title
,
144 const wxPoint
& pos
, const wxSize
& size
, long style
):
145 wxFrame(frame
, id
, title
, pos
, size
, style
)
149 // Read the poetry buffer, either for finding the size
150 // or for writing to a bitmap (not to the window directly,
151 // since that displays messily)
152 // If DrawIt is true, we draw, otherwise we just determine the
153 // size the window should be.
154 void MainWindow::ScanBuffer(wxDC
*dc
, bool DrawIt
, int *max_x
, int *max_y
)
156 int i
= pages
[current_page
];
162 bool page_break
= false;
169 y
= (*max_y
- poem_height
)/2;
174 if (DrawIt
&& wxColourDisplay())
176 dc
->SetBrush(*wxLIGHT_GREY_BRUSH
);
177 dc
->SetPen(*GreyPen
);
178 dc
->DrawRectangle(0, 0, width
, height
);
179 dc
->SetBackgroundMode(wxTRANSPARENT
);
182 // See what ACTUAL char height is
183 dc
->SetFont(* NormalFont
);
186 dc
->GetTextExtent(_T("X"), &xx
, &yy
);
187 char_height
= (int)yy
;
189 if (current_page
== 0)
191 else if (title
[0] != 0)
193 dc
->SetFont(* BoldFont
);
194 dc
->GetTextExtent(title
, &xx
, &yy
);
195 FindMax(&curr_width
, (int)xx
);
199 int x
= (width
- xx
)/2;
200 dc
->SetFont(* BoldFont
);
202 // Change text to BLACK!
203 dc
->SetTextForeground(* wxBLACK
);
204 dc
->DrawText(title
, x
, y
);
205 // Change text to WHITE!
206 dc
->SetTextForeground(* wxWHITE
);
207 dc
->DrawText(title
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
213 while (ch
!= 0 && !page_break
)
216 #if defined(__WXMSW__) || defined(__WXMAC__)
217 while (((ch
= poem_buffer
[i
]) != 13) && (ch
!= 0))
219 while (((ch
= poem_buffer
[i
]) != 10) && (ch
!= 0))
227 #if defined(__WXMSW__) || defined(__WXMAC__)
235 #if defined(__WXMSW__) || defined(__WXMAC__)
236 // Add another to skip the linefeed
239 // If a single newline on its own, put a space in
261 dc
->SetFont(* BoldFont
);
264 wxStrcpy(title
, line_ptr
);
265 wxStrcat(title
, _T(" (cont'd)"));
267 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
268 FindMax(&curr_width
, (int)xx
);
272 int x
= (width
- xx
)/2;
273 dc
->SetFont(* BoldFont
);
275 // Change text to BLACK!
276 dc
->SetTextForeground(* wxBLACK
);
277 dc
->DrawText(line_ptr
, x
, y
);
279 // Change text to WHITE!
280 dc
->SetTextForeground(* wxWHITE
);
281 dc
->DrawText(line_ptr
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
282 dc
->SetTextForeground(* wxWHITE
);
288 dc
->SetFont(* ItalicFont
);
290 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
291 FindMax(&curr_width
, (int)xx
);
295 int x
= (width
- xx
)/2;
296 dc
->SetTextForeground(* wxBLACK
);
297 dc
->DrawText(line_ptr
, x
, y
);
301 // Default: just ignore this line
308 dc
->SetFont(* NormalFont
);
310 dc
->GetTextExtent(line
, &xx
, &yy
);
311 FindMax(&curr_width
, (int)xx
);
315 int x
= (int)((width
- xx
)/2.0);
316 dc
->SetFont(* NormalFont
);
317 dc
->SetTextForeground(* wxBLACK
);
318 dc
->DrawText(line
, x
, y
);
328 wxChar
*cont
= _T("(cont'd)");
330 dc
->SetFont(* NormalFont
);
332 dc
->GetTextExtent(cont
, &xx
, &yy
);
333 FindMax(&curr_width
, (int)xx
);
336 int x
= (int)((width
- xx
)/2.0);
337 dc
->SetFont(* NormalFont
);
338 dc
->SetTextForeground(* wxBLACK
);
339 dc
->DrawText(cont
, x
, y
);
344 *max_x
= (int)curr_width
;
345 *max_y
= (int)(y
-char_height
);
348 pages
[current_page
+1] = i
;
354 // Draw dark grey thick border
355 if (wxColourDisplay())
357 dc
->SetBrush(*wxGREY_BRUSH
);
358 dc
->SetPen(*wxGREY_PEN
);
361 dc
->DrawRectangle(0, 0, THIN_LINE_BORDER
, height
);
363 dc
->DrawRectangle(THIN_LINE_BORDER
, 0, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
365 dc
->DrawRectangle(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
, height
-THIN_LINE_BORDER
);
367 dc
->DrawRectangle(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
);
370 // Have grey background, plus 3-d border -
371 // One black rectangle.
372 // Inside this, left and top sides - dark grey. Bottom and right -
375 // Change pen to black
376 dc
->SetPen(*wxBLACK_PEN
);
377 dc
->DrawLine(THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
378 dc
->DrawLine(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
379 dc
->DrawLine(width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
380 dc
->DrawLine(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, THIN_LINE_BORDER
);
382 // Right and bottom white lines - 'grey' (black!) if
383 // we're running on a mono display.
384 if (wxColourDisplay())
385 dc
->SetPen(*WhitePen
);
387 dc
->SetPen(*DarkGreyPen
);
389 dc
->DrawLine(width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
,
390 width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
391 dc
->DrawLine(width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
392 THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
394 // Left and top grey lines
395 dc
->SetPen(*DarkGreyPen
);
396 dc
->DrawLine(THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
397 THICK_LINE_BORDER
, THICK_LINE_BORDER
);
398 dc
->DrawLine(THICK_LINE_BORDER
, THICK_LINE_BORDER
,
399 width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
);
403 dc
->DrawIcon(* Corner1
, 0, 0);
404 dc
->DrawIcon(* Corner2
, int(width
-32), 0);
406 int y2
= height
- 32;
408 dc
->DrawIcon(* Corner3
, 0, y2
);
409 dc
->DrawIcon(* Corner4
, x2
, y2
);
414 // Get an index (randomly generated) and load the poem
415 void MainWindow::GetIndexLoadPoem(void)
418 index_ptr
= GetIndex();
421 loaded_ok
= LoadPoem(data_filename
, -1);
424 // Find the size of the poem and resize the window accordingly
425 void MainWindow::Resize(void)
427 wxClientDC
dc(canvas
);
430 ScanBuffer(& dc
, false, &poem_width
, &poem_height
);
431 int x
= poem_width
+ (2*BORDER_SIZE
);
432 int y
= poem_height
+ (2*BORDER_SIZE
);
436 // In case client size isn't what we set it to...
438 GetClientSize(&xx
, &yy
);
441 if (backingBitmap
) delete backingBitmap
;
442 backingBitmap
= new wxBitmap(x
, yy
);
443 memDC
.SelectObject(* backingBitmap
);
446 TheMainWindow
->ScanBuffer(&memDC
, true, &xx
, &yy
);
450 void FindMax(int *max_thing
, int thing
)
452 if (thing
> *max_thing
)
457 void MainWindow::NextPage(void)
470 void MainWindow::PreviousPage(void)
472 if (current_page
> 0)
479 // Search for a string
480 void MainWindow::Search(bool ask
)
484 if (ask
|| !search_string
)
486 wxString s
= wxGetTextFromUser( _T("Enter search string"), _T("Search"), (const wxChar
*) search_string
);
487 if (s
!= wxEmptyString
)
490 if (search_string
) delete[] search_string
;
491 search_string
= copystring(s
);
493 } else search_ok
= false;
501 if (search_string
&& search_ok
)
503 position
= DoSearch();
506 loaded_ok
= LoadPoem(data_filename
, position
);
512 PoetryNotify(_T("Search string not found."));
519 poem_buffer
= new wxChar
[buf_size
];
521 GreyPen
= new wxPen(_T("LIGHT GREY"), THICK_LINE_WIDTH
, wxSOLID
);
522 DarkGreyPen
= new wxPen(_T("GREY"), THICK_LINE_WIDTH
, wxSOLID
);
523 WhitePen
= new wxPen(_T("WHITE"), THICK_LINE_WIDTH
, wxSOLID
);
529 // Seed the random number generator
531 srand((unsigned) CeGetRandomSeed());
535 (void)time(¤t_time
);
536 srand((unsigned int)current_time
);
542 TheMainWindow
= new MainWindow(NULL
,
547 wxCAPTION
|wxMINIMIZE_BOX
|wxSYSTEM_MENU
|wxCLOSE_BOX
|wxFULL_REPAINT_ON_RESIZE
550 TheMainWindow
->SetIcon(wxICON(wxpoem
));
552 TheMainWindow
->canvas
= new MyCanvas(TheMainWindow
, 501, wxDefaultPosition
, wxDefaultSize
);
556 index_filename
= copystring(argv
[1]);
557 data_filename
= copystring(argv
[1]);
561 index_filename
= _T(DEFAULT_POETRY_IND
);
562 data_filename
= _T(DEFAULT_POETRY_DAT
);
567 Corner1
= new wxIcon(_T("icon_1"));
568 Corner2
= new wxIcon(_T("icon_2"));
569 Corner3
= new wxIcon(_T("icon_3"));
570 Corner4
= new wxIcon(_T("icon_4"));
572 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
573 Corner1
= new wxIcon( corner1_xpm
);
574 Corner2
= new wxIcon( corner2_xpm
);
575 Corner3
= new wxIcon( corner3_xpm
);
576 Corner4
= new wxIcon( corner4_xpm
);
579 TheMainWindow
->GetIndexLoadPoem();
580 TheMainWindow
->Resize();
581 TheMainWindow
->Show(true);
589 delete backingBitmap
;
599 delete[] poem_buffer
;
601 delete[] search_string
;
606 void MainWindow::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
612 void MainWindow::OnChar(wxKeyEvent
& event
)
614 canvas
->OnChar(event
);
617 BEGIN_EVENT_TABLE(MyCanvas
, wxWindow
)
618 EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent
)
619 EVT_CHAR(MyCanvas::OnChar
)
620 EVT_PAINT(MyCanvas::OnPaint
)
623 // Define a constructor for my canvas
624 MyCanvas::MyCanvas(wxFrame
*frame
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
):
625 wxWindow(frame
, id
, pos
, size
)
627 popupMenu
= new wxMenu
;
628 popupMenu
->Append(POEM_NEXT
, _T("Next poem/page"));
629 popupMenu
->Append(POEM_PREVIOUS
, _T("Previous page"));
630 popupMenu
->AppendSeparator();
631 popupMenu
->Append(POEM_SEARCH
, _T("Search"));
632 popupMenu
->Append(POEM_NEXT_MATCH
, _T("Next match"));
633 popupMenu
->Append(POEM_COPY
, _T("Copy to clipboard"));
634 popupMenu
->Append(POEM_MINIMIZE
, _T("Minimize"));
635 popupMenu
->AppendSeparator();
636 popupMenu
->Append(POEM_BIGGER_TEXT
, _T("Bigger text"));
637 popupMenu
->Append(POEM_SMALLER_TEXT
, _T("Smaller text"));
638 popupMenu
->AppendSeparator();
639 popupMenu
->Append(POEM_ABOUT
, _T("About wxPoem"));
640 popupMenu
->AppendSeparator();
641 popupMenu
->Append(POEM_EXIT
, _T("Exit"));
644 MyCanvas::~MyCanvas()
646 // Note: this must be done before the main window/canvas are destroyed
647 // or we get an error (no parent window for menu item button)
652 // Define the repainting behaviour
653 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
660 TheMainWindow
->GetClientSize(&xx
, &yy
);
662 dc
.DrawBitmap(* backingBitmap
, 0, 0);
665 memDC
.SelectObject(* backingBitmap
);
666 dc
.Blit(0, 0, backingBitmap
->GetWidth(), backingBitmap
->GetHeight(), &memDC
, 0, 0);
671 void MyCanvas::OnMouseEvent(wxMouseEvent
& event
)
673 static int startPosX
, startPosY
, startFrameX
, startFrameY
;
676 event
.GetPosition(&x
, &y
);
678 if (event
.RightDown())
680 // Versions from wxWin 1.67 are probably OK
681 PopupMenu(popupMenu
, (int)x
, (int)y
);
683 else if (event
.LeftDown())
685 this->CaptureMouse();
688 ClientToScreen(&x1
, &y1
);
691 GetParent()->GetPosition(&startFrameX
, &startFrameY
);
693 else if (event
.LeftUp())
695 if (GetCapture() == this) this->ReleaseMouse();
697 else if (event
.Dragging() && event
.LeftIsDown())
701 ClientToScreen(&x1
, &y1
);
703 int dX
= x1
- startPosX
;
704 int dY
= y1
- startPosY
;
705 GetParent()->Move(startFrameX
+ dX
, startFrameY
+ dY
);
709 // Process characters
710 void MyCanvas::OnChar(wxKeyEvent
& event
)
712 switch (event
.GetKeyCode())
717 TheMainWindow
->Search(false);
722 TheMainWindow
->Search(true);
728 TheMainWindow
->NextPage();
731 TheMainWindow
->Close(true);
738 int LoadIndex(wxChar
*file_name
)
745 if (file_name
== NULL
)
748 wxSprintf(buf
, _T("%s.idx"), file_name
);
750 index_file
= wxFopen(buf
, _T("r"));
751 if (index_file
== NULL
)
754 wxFscanf(index_file
, _T("%ld"), &nitems
);
756 for (int i
= 0; i
< nitems
; i
++)
758 wxFscanf(index_file
, _T("%ld"), &data
);
759 poem_index
[i
] = data
;
770 int indexn
= (int)(rand() % nitems
);
772 if ((indexn
< 0) || (indexn
> nitems
))
773 { PoetryError(_T("No such poem!"));
781 void ReadPreferences()
784 wxGetResource(_T("wxPoem"), _T("FontSize"), &pointSize
);
785 wxGetResource(_T("wxPoem"), _T("X"), &XPos
);
786 wxGetResource(_T("wxPoem"), _T("Y"), &YPos
);
790 // Write preferences to disk
791 void WritePreferences()
794 TheMainWindow
->GetPosition(&XPos
, &YPos
);
796 wxWriteResource(_T("wxPoem"), _T("FontSize"), pointSize
);
797 wxWriteResource(_T("wxPoem"), _T("X"), XPos
);
798 wxWriteResource(_T("wxPoem"), _T("Y"), YPos
);
803 // Load a poem from given file, at given point in file.
804 // If position is > -1, use this for the position in the
805 // file, otherwise use index[index_ptr] to find the correct position.
806 bool LoadPoem(wxChar
*file_name
, long position
)
817 if (file_name
== NULL
)
819 wxSprintf(error_buf
, _T("Error in Poem loading."));
820 PoetryError(error_buf
);
824 wxSprintf(buf
, _T("%s.dat"), file_name
);
825 data_file
= wxFopen(buf
, _T("r"));
827 if (data_file
== NULL
)
829 wxSprintf(error_buf
, _T("Data file %s not found."), buf
);
830 PoetryError(error_buf
);
837 data
= poem_index
[index_ptr
];
839 fseek(data_file
, data
, SEEK_SET
);
843 while ((ch
!= EOF
) && (ch
!= '#'))
845 ch
= getc(data_file
);
846 // Add a linefeed so it will copy to the clipboard ok
858 wxSprintf(error_buf
, _T("%s"), _T("Poetry buffer exceeded."));
859 PoetryError(error_buf
);
864 poem_buffer
[i
-1] = 0;
869 long MainWindow::DoSearch(void)
879 long previous_poem_start
;
882 int search_length
= wxStrlen(search_string
);
886 find_start
= last_find
+ 1;
887 previous_poem_start
= last_poem_start
;
893 previous_poem_start
= -1;
897 wxSprintf(buf
, _T("%s.dat"), data_filename
);
899 file
= wxFopen(buf
, _T("r"));
900 if (! (data_filename
&& file
))
902 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
903 PoetryError(error_buf
);
907 fseek(file
, find_start
, SEEK_SET
);
909 while ((ch
!= EOF
) && !found
)
912 ch
= wxTolower(ch
); // Make lower case
914 // Only match if we're looking at a different poem
915 // (no point in displaying the same poem again)
916 if ((ch
== search_string
[i
]) && (last_poem_start
!= previous_poem_start
))
919 last_find
= ftell(file
);
920 if (i
== search_length
-1)
930 last_poem_start
= ftell(file
);
939 return last_poem_start
;
945 // Set up poetry filenames, preferences, load the index
946 // Load index (or compile it if none found)
949 index_ok
= (LoadIndex(index_filename
) != 0);
950 if (!index_ok
|| (nitems
== 0))
952 PoetryError(_T("Index file not found; will compile new one"), _T("wxPoem"));
953 index_ok
= Compile();
958 void PoetryError(wxChar
*msg
, wxChar
*caption
)
960 wxMessageBox(msg
, caption
, wxOK
|wxICON_EXCLAMATION
);
963 // Notification (change icon to something appropriate!)
964 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
)
966 wxMessageBox(Msg
, caption
, wxOK
| wxICON_INFORMATION
);
969 // Build up and save an index into the poetry data file, for
970 // rapid random access
979 wxSprintf(buf
, _T("%s.dat"), data_filename
);
981 file
= wxFopen(buf
, _T("r"));
982 if (! (data_filename
&& file
))
984 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
985 PoetryError(error_buf
);
992 poem_index
[nitems
] = 0;
1004 poem_index
[nitems
] = data
;
1007 } while (ch
!= EOF
);
1011 wxSprintf(buf
, _T("%s.idx"), index_filename
);
1013 file
= wxFopen(buf
, _T("w"));
1014 if (! (data_filename
&& file
))
1016 wxSprintf(error_buf
, _T("Poetry index file %s cannot be created\n"), buf
);
1017 PoetryError(error_buf
);
1021 wxFprintf(file
, _T("%ld\n\n"), nitems
);
1022 for (j
= 0; j
< nitems
; j
++)
1023 wxFprintf(file
, _T("%ld\n"), poem_index
[j
]);
1026 PoetryNotify(_T("Poetry index compiled."));
1030 void MainWindow::OnPopup(wxCommandEvent
& event
)
1032 switch (event
.GetId())
1035 // Another poem/page
1036 TheMainWindow
->NextPage();
1040 TheMainWindow
->PreviousPage();
1043 // Search - with dialog
1044 TheMainWindow
->Search(true);
1046 case POEM_NEXT_MATCH
:
1047 // Search - without dialog (next match)
1048 TheMainWindow
->Search(false);
1051 TheMainWindow
->Iconize(true);
1055 wxTheClipboard
->UsePrimarySelection();
1056 if (wxTheClipboard
->Open())
1060 s
.Replace( _T("@P"),_T(""));
1061 s
.Replace( _T("@A "),_T(""));
1062 s
.Replace( _T("@A"),_T(""));
1063 s
.Replace( _T("@T "),_T(""));
1064 s
.Replace( _T("@T"),_T(""));
1065 wxTextDataObject
*data
= new wxTextDataObject( s
.c_str() );
1066 if (!wxTheClipboard
->SetData( data
))
1067 wxMessageBox(_T("Error while copying to the clipboard."));
1071 wxMessageBox(_T("Error opening the clipboard."));
1073 wxTheClipboard
->Close();
1080 case POEM_BIGGER_TEXT
:
1084 TheMainWindow
->Resize();
1087 case POEM_SMALLER_TEXT
:
1093 TheMainWindow
->Resize();
1099 (void)wxMessageBox(_T("wxPoem Version 1.1\nJulian Smart (c) 1995"),
1100 _T("About wxPoem"), wxOK
, TheMainWindow
);
1105 TheMainWindow
->Close(true);