]>
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"
42 #define buf_size 10000
43 #define DEFAULT_POETRY_DAT "wxpoem"
44 #define DEFAULT_POETRY_IND "wxpoem"
45 #define DEFAULT_CHAR_HEIGHT 18
46 #define DEFAULT_FONT "Swiss"
47 #define DEFAULT_X_POS 0
48 #define DEFAULT_Y_POS 0
49 #define BORDER_SIZE 30
50 #define THIN_LINE_BORDER 10
51 #define THICK_LINE_BORDER 16
52 #define THICK_LINE_WIDTH 2
53 #define SHADOW_OFFSET 1
57 static wxChar
*poem_buffer
; // Storage for each poem
58 static wxChar line
[150]; // Storage for a line
59 static int pages
[30]; // For multipage poems -
60 // store the start of each page
61 static long last_poem_start
= 0; // Start of last found poem
62 static long last_find
= -1; // Point in file of last found
64 static bool search_ok
= false; // Search was successful
65 static bool same_search
= false; // Searching on same string
67 static long poem_index
[600]; // Index of poem starts
68 static long nitems
= 0; // Number of poems
69 static int char_height
= DEFAULT_CHAR_HEIGHT
; // Actual height
70 static int index_ptr
= -1; // Pointer into index
71 static int poem_height
, poem_width
; // Size of poem
72 static int XPos
; // Startup X position
73 static int YPos
; // Startup Y position
74 static int pointSize
= 12; // Font size
76 static wxChar
*index_filename
= NULL
; // Index filename
77 static wxChar
*data_filename
= NULL
; // Data filename
78 static wxChar error_buf
[300]; // Error message buffer
79 static bool loaded_ok
= false; // Poem loaded ok
80 static bool index_ok
= false; // Index loaded ok
82 static bool paging
= false; // Are we paging?
83 static int current_page
= 0; // Currently viewed page
85 wxIcon
*Corner1
= NULL
;
86 wxIcon
*Corner2
= NULL
;
87 wxIcon
*Corner3
= NULL
;
88 wxIcon
*Corner4
= NULL
;
91 wxPen
*GreyPen
= NULL
;
92 wxPen
*DarkGreyPen
= NULL
;
93 wxPen
*WhitePen
= NULL
;
96 wxBitmap
*backingBitmap
= NULL
;
98 void PoetryError(wxChar
*, wxChar
*caption
=_T("wxPoem Error"));
99 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
=_T("wxPoem"));
101 bool LoadPoem(wxChar
*, long);
103 int LoadIndex(wxChar
*);
105 void FindMax(int *max_thing
, int thing
);
108 #include "wx/dataobj.h"
109 #include "wx/clipbrd.h"
113 STDAPI_(__int64
) CeGetRandomSeed();
118 MainWindow
*TheMainWindow
= NULL
;
121 void MainWindow::CreateFonts()
123 m_normalFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxNORMAL
);
124 m_boldFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxBOLD
);
125 m_italicFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxITALIC
, wxNORMAL
);
128 BEGIN_EVENT_TABLE(MainWindow
, wxFrame
)
129 EVT_CLOSE(MainWindow::OnCloseWindow
)
130 EVT_CHAR(MainWindow::OnChar
)
131 EVT_MENU(wxID_ANY
, MainWindow::OnPopup
)
134 MainWindow::MainWindow(wxFrame
*frame
, wxWindowID id
, const wxString
& title
,
135 const wxPoint
& pos
, const wxSize
& size
, long style
):
136 wxFrame(frame
, id
, title
, pos
, size
, style
)
142 // Read the poetry buffer, either for finding the size
143 // or for writing to a bitmap (not to the window directly,
144 // since that displays messily)
145 // If DrawIt is true, we draw, otherwise we just determine the
146 // size the window should be.
147 void MainWindow::ScanBuffer(wxDC
*dc
, bool DrawIt
, int *max_x
, int *max_y
)
149 int i
= pages
[current_page
];
155 bool page_break
= false;
162 y
= (*max_y
- poem_height
)/2;
167 if (DrawIt
&& wxColourDisplay())
169 dc
->SetBrush(*wxLIGHT_GREY_BRUSH
);
170 dc
->SetPen(*GreyPen
);
171 dc
->DrawRectangle(0, 0, width
, height
);
172 dc
->SetBackgroundMode(wxTRANSPARENT
);
175 // See what ACTUAL char height is
177 dc
->SetFont(*m_normalFont
);
180 dc
->GetTextExtent(_T("X"), &xx
, &yy
);
181 char_height
= (int)yy
;
183 if (current_page
== 0)
185 m_title
= wxEmptyString
;
187 else if (!m_title
.empty())
189 dc
->SetFont(* m_boldFont
);
190 dc
->GetTextExtent(m_title
, &xx
, &yy
);
191 FindMax(&curr_width
, (int)xx
);
195 int x
= (width
- xx
)/2;
196 dc
->SetFont(* m_boldFont
);
198 // Change text to BLACK!
199 dc
->SetTextForeground(* wxBLACK
);
200 dc
->DrawText(m_title
, x
, y
);
201 // Change text to WHITE!
202 dc
->SetTextForeground(* wxWHITE
);
203 dc
->DrawText(m_title
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
209 while (ch
!= 0 && !page_break
)
212 #if defined(__WXMSW__) || defined(__WXMAC__)
213 while (((ch
= poem_buffer
[i
]) != 13) && (ch
!= 0))
215 while (((ch
= poem_buffer
[i
]) != 10) && (ch
!= 0))
218 line
[j
] = (wxChar
)ch
;
223 #if defined(__WXMSW__) || defined(__WXMAC__)
231 #if defined(__WXMSW__) || defined(__WXMAC__)
232 // Add another to skip the linefeed
235 // If a single newline on its own, put a space in
257 dc
->SetFont(* m_boldFont
);
261 m_title
<< _T(" (cont'd)");
263 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
264 FindMax(&curr_width
, (int)xx
);
268 int x
= (width
- xx
)/2;
269 dc
->SetFont(* m_boldFont
);
271 // Change text to BLACK!
272 dc
->SetTextForeground(* wxBLACK
);
273 dc
->DrawText(line_ptr
, x
, y
);
275 // Change text to WHITE!
276 dc
->SetTextForeground(* wxWHITE
);
277 dc
->DrawText(line_ptr
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
278 dc
->SetTextForeground(* wxWHITE
);
284 dc
->SetFont(* m_italicFont
);
286 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
287 FindMax(&curr_width
, (int)xx
);
291 int x
= (width
- xx
)/2;
292 dc
->SetTextForeground(* wxBLACK
);
293 dc
->DrawText(line_ptr
, x
, y
);
297 // Default: just ignore this line
304 dc
->SetFont(* m_normalFont
);
306 dc
->GetTextExtent(line
, &xx
, &yy
);
307 FindMax(&curr_width
, (int)xx
);
311 int x
= (int)((width
- xx
)/2.0);
312 dc
->SetFont(* m_normalFont
);
313 dc
->SetTextForeground(* wxBLACK
);
314 dc
->DrawText(line
, x
, y
);
324 wxChar
*cont
= _T("(cont'd)");
326 dc
->SetFont(* m_normalFont
);
328 dc
->GetTextExtent(cont
, &xx
, &yy
);
329 FindMax(&curr_width
, (int)xx
);
332 int x
= (int)((width
- xx
)/2.0);
333 dc
->SetFont(* m_normalFont
);
334 dc
->SetTextForeground(* wxBLACK
);
335 dc
->DrawText(cont
, x
, y
);
340 *max_x
= (int)curr_width
;
341 *max_y
= (int)(y
-char_height
);
344 pages
[current_page
+1] = i
;
350 // Draw dark grey thick border
351 if (wxColourDisplay())
353 dc
->SetBrush(*wxGREY_BRUSH
);
354 dc
->SetPen(*wxGREY_PEN
);
357 dc
->DrawRectangle(0, 0, THIN_LINE_BORDER
, height
);
359 dc
->DrawRectangle(THIN_LINE_BORDER
, 0, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
361 dc
->DrawRectangle(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
, height
-THIN_LINE_BORDER
);
363 dc
->DrawRectangle(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
);
366 // Have grey background, plus 3-d border -
367 // One black rectangle.
368 // Inside this, left and top sides - dark grey. Bottom and right -
371 // Change pen to black
372 dc
->SetPen(*wxBLACK_PEN
);
373 dc
->DrawLine(THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
374 dc
->DrawLine(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
375 dc
->DrawLine(width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
376 dc
->DrawLine(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, THIN_LINE_BORDER
);
378 // Right and bottom white lines - 'grey' (black!) if
379 // we're running on a mono display.
380 if (wxColourDisplay())
381 dc
->SetPen(*WhitePen
);
383 dc
->SetPen(*DarkGreyPen
);
385 dc
->DrawLine(width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
,
386 width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
387 dc
->DrawLine(width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
388 THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
390 // Left and top grey lines
391 dc
->SetPen(*DarkGreyPen
);
392 dc
->DrawLine(THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
393 THICK_LINE_BORDER
, THICK_LINE_BORDER
);
394 dc
->DrawLine(THICK_LINE_BORDER
, THICK_LINE_BORDER
,
395 width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
);
398 dc
->DrawIcon(* Corner1
, 0, 0);
399 dc
->DrawIcon(* Corner2
, int(width
-32), 0);
401 int y2
= height
- 32;
403 dc
->DrawIcon(* Corner3
, 0, y2
);
404 dc
->DrawIcon(* Corner4
, x2
, y2
);
408 // Get an index (randomly generated) and load the poem
409 void MainWindow::GetIndexLoadPoem(void)
412 index_ptr
= GetIndex();
415 loaded_ok
= LoadPoem(data_filename
, -1);
418 // Find the size of the poem and resize the window accordingly
419 void MainWindow::Resize(void)
421 wxClientDC
dc(canvas
);
424 ScanBuffer(& dc
, false, &poem_width
, &poem_height
);
425 int x
= poem_width
+ (2*BORDER_SIZE
);
426 int y
= poem_height
+ (2*BORDER_SIZE
);
430 // In case client size isn't what we set it to...
432 GetClientSize(&xx
, &yy
);
435 if (backingBitmap
) delete backingBitmap
;
436 backingBitmap
= new wxBitmap(x
, yy
);
437 memDC
.SelectObject(* backingBitmap
);
440 ScanBuffer(&memDC
, true, &xx
, &yy
);
444 void FindMax(int *max_thing
, int thing
)
446 if (thing
> *max_thing
)
451 void MainWindow::NextPage(void)
464 void MainWindow::PreviousPage(void)
466 if (current_page
> 0)
473 // Search for a string
474 void MainWindow::Search(bool ask
)
478 if (ask
|| m_searchString
.empty())
480 wxString s
= wxGetTextFromUser( _T("Enter search string"), _T("Search"), m_searchString
);
481 if (s
!= wxEmptyString
)
498 if (!m_searchString
.empty() && search_ok
)
500 position
= DoSearch();
503 loaded_ok
= LoadPoem(data_filename
, position
);
509 PoetryNotify(_T("Search string not found."));
516 poem_buffer
= new wxChar
[buf_size
];
518 GreyPen
= new wxPen(_T("LIGHT GREY"), THICK_LINE_WIDTH
, wxSOLID
);
519 DarkGreyPen
= new wxPen(_T("GREY"), THICK_LINE_WIDTH
, wxSOLID
);
520 WhitePen
= new wxPen(_T("WHITE"), THICK_LINE_WIDTH
, wxSOLID
);
522 // Seed the random number generator
524 srand((unsigned) CeGetRandomSeed());
528 (void)time(¤t_time
);
529 srand((unsigned int)current_time
);
535 TheMainWindow
= new MainWindow(NULL
,
540 wxCAPTION
|wxMINIMIZE_BOX
|wxSYSTEM_MENU
|wxCLOSE_BOX
|wxFULL_REPAINT_ON_RESIZE
543 TheMainWindow
->SetIcon(wxICON(wxpoem
));
545 TheMainWindow
->canvas
= new MyCanvas(TheMainWindow
);
549 index_filename
= wxStrcpy(new wxChar
[wxStrlen(argv
[1]) + 1], argv
[1]);
550 data_filename
= wxStrcpy(new wxChar
[wxStrlen(argv
[1]) + 1], argv
[1]);
554 index_filename
= _T(DEFAULT_POETRY_IND
);
555 data_filename
= _T(DEFAULT_POETRY_DAT
);
560 Corner1
= new wxIcon(_T("icon_1"));
561 Corner2
= new wxIcon(_T("icon_2"));
562 Corner3
= new wxIcon(_T("icon_3"));
563 Corner4
= new wxIcon(_T("icon_4"));
565 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
566 Corner1
= new wxIcon( corner1_xpm
);
567 Corner2
= new wxIcon( corner2_xpm
);
568 Corner3
= new wxIcon( corner3_xpm
);
569 Corner4
= new wxIcon( corner4_xpm
);
572 TheMainWindow
->GetIndexLoadPoem();
573 TheMainWindow
->Resize();
574 TheMainWindow
->Show(true);
582 delete backingBitmap
;
592 delete[] poem_buffer
;
597 void MainWindow::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
603 void MainWindow::OnChar(wxKeyEvent
& event
)
605 canvas
->OnChar(event
);
608 BEGIN_EVENT_TABLE(MyCanvas
, wxWindow
)
609 EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent
)
610 EVT_CHAR(MyCanvas::OnChar
)
611 EVT_PAINT(MyCanvas::OnPaint
)
614 // Define a constructor for my canvas
615 MyCanvas::MyCanvas(wxFrame
*frame
):
616 wxWindow(frame
, wxID_ANY
)
618 m_popupMenu
= new wxMenu
;
619 m_popupMenu
->Append(POEM_NEXT
, _T("Next poem/page"));
620 m_popupMenu
->Append(POEM_PREVIOUS
, _T("Previous page"));
621 m_popupMenu
->AppendSeparator();
622 m_popupMenu
->Append(POEM_SEARCH
, _T("Search"));
623 m_popupMenu
->Append(POEM_NEXT_MATCH
, _T("Next match"));
624 m_popupMenu
->Append(POEM_COPY
, _T("Copy to clipboard"));
625 m_popupMenu
->Append(POEM_MINIMIZE
, _T("Minimize"));
626 m_popupMenu
->AppendSeparator();
627 m_popupMenu
->Append(POEM_BIGGER_TEXT
, _T("Bigger text"));
628 m_popupMenu
->Append(POEM_SMALLER_TEXT
, _T("Smaller text"));
629 m_popupMenu
->AppendSeparator();
630 m_popupMenu
->Append(POEM_ABOUT
, _T("About wxPoem"));
631 m_popupMenu
->AppendSeparator();
632 m_popupMenu
->Append(POEM_EXIT
, _T("Exit"));
635 MyCanvas::~MyCanvas()
637 // Note: this must be done before the main window/canvas are destroyed
638 // or we get an error (no parent window for menu item button)
643 // Define the repainting behaviour
644 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
651 TheMainWindow
->GetClientSize(&xx
, &yy
);
653 dc
.DrawBitmap(* backingBitmap
, 0, 0);
656 memDC
.SelectObject(* backingBitmap
);
657 dc
.Blit(0, 0, backingBitmap
->GetWidth(), backingBitmap
->GetHeight(), &memDC
, 0, 0);
662 void MyCanvas::OnMouseEvent(wxMouseEvent
& event
)
664 static int startPosX
, startPosY
, startFrameX
, startFrameY
;
667 event
.GetPosition(&x
, &y
);
669 if (event
.RightDown())
671 // Versions from wxWin 1.67 are probably OK
672 PopupMenu(m_popupMenu
, (int)x
, (int)y
);
674 else if (event
.LeftDown())
676 this->CaptureMouse();
679 ClientToScreen(&x1
, &y1
);
682 GetParent()->GetPosition(&startFrameX
, &startFrameY
);
684 else if (event
.LeftUp())
686 if (GetCapture() == this) this->ReleaseMouse();
688 else if (event
.Dragging() && event
.LeftIsDown())
692 ClientToScreen(&x1
, &y1
);
694 int dX
= x1
- startPosX
;
695 int dY
= y1
- startPosY
;
696 GetParent()->Move(startFrameX
+ dX
, startFrameY
+ dY
);
700 // Process characters
701 void MyCanvas::OnChar(wxKeyEvent
& event
)
703 switch (event
.GetKeyCode())
708 TheMainWindow
->Search(false);
714 TheMainWindow
->Search(true);
721 TheMainWindow
->NextPage();
725 TheMainWindow
->Close(true);
732 int LoadIndex(wxChar
*file_name
)
739 if (file_name
== NULL
)
742 wxSprintf(buf
, _T("%s.idx"), file_name
);
744 index_file
= wxFopen(buf
, _T("r"));
745 if (index_file
== NULL
)
748 wxFscanf(index_file
, _T("%ld"), &nitems
);
750 for (int i
= 0; i
< nitems
; i
++)
752 wxFscanf(index_file
, _T("%ld"), &data
);
753 poem_index
[i
] = data
;
764 int indexn
= (int)(rand() % nitems
);
766 if ((indexn
< 0) || (indexn
> nitems
))
767 { PoetryError(_T("No such poem!"));
775 void MainWindow::ReadPreferences()
778 wxGetResource(_T("wxPoem"), _T("FontSize"), &pointSize
);
779 wxGetResource(_T("wxPoem"), _T("X"), &XPos
);
780 wxGetResource(_T("wxPoem"), _T("Y"), &YPos
);
784 // Write preferences to disk
785 void MainWindow::WritePreferences()
788 TheMainWindow
->GetPosition(&XPos
, &YPos
);
790 wxWriteResource(_T("wxPoem"), _T("FontSize"), pointSize
);
791 wxWriteResource(_T("wxPoem"), _T("X"), XPos
);
792 wxWriteResource(_T("wxPoem"), _T("Y"), YPos
);
797 // Load a poem from given file, at given point in file.
798 // If position is > -1, use this for the position in the
799 // file, otherwise use index[index_ptr] to find the correct position.
800 bool LoadPoem(wxChar
*file_name
, long position
)
811 if (file_name
== NULL
)
813 wxSprintf(error_buf
, _T("Error in Poem loading."));
814 PoetryError(error_buf
);
818 wxSprintf(buf
, _T("%s.dat"), file_name
);
819 data_file
= wxFopen(buf
, _T("r"));
821 if (data_file
== NULL
)
823 wxSprintf(error_buf
, _T("Data file %s not found."), buf
);
824 PoetryError(error_buf
);
831 data
= poem_index
[index_ptr
];
833 fseek(data_file
, data
, SEEK_SET
);
837 while ((ch
!= EOF
) && (ch
!= '#'))
839 ch
= getc(data_file
);
840 // Add a linefeed so it will copy to the clipboard ok
847 poem_buffer
[i
] = (wxChar
)ch
;
852 wxSprintf(error_buf
, _T("%s"), _T("Poetry buffer exceeded."));
853 PoetryError(error_buf
);
858 poem_buffer
[i
-1] = 0;
863 long MainWindow::DoSearch(void)
865 if (m_searchString
.empty())
873 long previous_poem_start
;
876 int search_length
= m_searchString
.length();
880 find_start
= last_find
+ 1;
881 previous_poem_start
= last_poem_start
;
887 previous_poem_start
= -1;
891 wxSprintf(buf
, _T("%s.dat"), data_filename
);
893 file
= wxFopen(buf
, _T("r"));
894 if (! (data_filename
&& file
))
896 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
897 PoetryError(error_buf
);
901 fseek(file
, find_start
, SEEK_SET
);
903 while ((ch
!= EOF
) && !found
)
906 ch
= wxTolower(ch
); // Make lower case
908 // Only match if we're looking at a different poem
909 // (no point in displaying the same poem again)
910 if ((ch
== m_searchString
[i
]) && (last_poem_start
!= previous_poem_start
))
913 last_find
= ftell(file
);
914 if (i
== search_length
-1)
926 last_poem_start
= ftell(file
);
937 return last_poem_start
;
943 // Set up poetry filenames, preferences, load the index
944 // Load index (or compile it if none found)
947 index_ok
= (LoadIndex(index_filename
) != 0);
948 if (!index_ok
|| (nitems
== 0))
950 PoetryError(_T("Index file not found; will compile new one"), _T("wxPoem"));
951 index_ok
= Compile();
956 void PoetryError(wxChar
*msg
, wxChar
*caption
)
958 wxMessageBox(msg
, caption
, wxOK
|wxICON_EXCLAMATION
);
961 // Notification (change icon to something appropriate!)
962 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
)
964 wxMessageBox(Msg
, caption
, wxOK
| wxICON_INFORMATION
);
967 // Build up and save an index into the poetry data file, for
968 // rapid random access
977 wxSprintf(buf
, _T("%s.dat"), data_filename
);
979 file
= wxFopen(buf
, _T("r"));
980 if (! (data_filename
&& file
))
982 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
983 PoetryError(error_buf
);
990 poem_index
[nitems
] = 0;
1002 poem_index
[nitems
] = data
;
1005 } while (ch
!= EOF
);
1009 wxSprintf(buf
, _T("%s.idx"), index_filename
);
1011 file
= wxFopen(buf
, _T("w"));
1012 if (! (data_filename
&& file
))
1014 wxSprintf(error_buf
, _T("Poetry index file %s cannot be created\n"), buf
);
1015 PoetryError(error_buf
);
1019 wxFprintf(file
, _T("%ld\n\n"), nitems
);
1020 for (j
= 0; j
< nitems
; j
++)
1021 wxFprintf(file
, _T("%ld\n"), poem_index
[j
]);
1024 PoetryNotify(_T("Poetry index compiled."));
1028 void MainWindow::OnPopup(wxCommandEvent
& event
)
1030 switch (event
.GetId())
1033 // Another poem/page
1034 TheMainWindow
->NextPage();
1038 TheMainWindow
->PreviousPage();
1041 // Search - with dialog
1042 TheMainWindow
->Search(true);
1044 case POEM_NEXT_MATCH
:
1045 // Search - without dialog (next match)
1046 TheMainWindow
->Search(false);
1049 TheMainWindow
->Iconize(true);
1053 wxTheClipboard
->UsePrimarySelection();
1054 if (wxTheClipboard
->Open())
1058 s
.Replace( _T("@P"),wxEmptyString
);
1059 s
.Replace( _T("@A "),wxEmptyString
);
1060 s
.Replace( _T("@A"),wxEmptyString
);
1061 s
.Replace( _T("@T "),wxEmptyString
);
1062 s
.Replace( _T("@T"),wxEmptyString
);
1063 wxTextDataObject
*data
= new wxTextDataObject( s
.c_str() );
1064 if (!wxTheClipboard
->SetData( data
))
1065 wxMessageBox(_T("Error while copying to the clipboard."));
1069 wxMessageBox(_T("Error opening the clipboard."));
1071 wxTheClipboard
->Close();
1074 case POEM_BIGGER_TEXT
:
1077 TheMainWindow
->Resize();
1079 case POEM_SMALLER_TEXT
:
1084 TheMainWindow
->Resize();
1088 (void)wxMessageBox(_T("wxPoem Version 1.1\nJulian Smart (c) 1995"),
1089 _T("About wxPoem"), wxOK
, TheMainWindow
);
1093 TheMainWindow
->Close(true);