]>
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 wxChar title
[150]; // Remember the title
60 static wxChar
*search_string
= NULL
; // The search string
61 static int pages
[30]; // For multipage poems -
62 // store the start of each page
63 static long last_poem_start
= 0; // Start of last found poem
64 static long last_find
= -1; // Point in file of last found
66 static bool search_ok
= false; // Search was successful
67 static bool same_search
= false; // Searching on same string
69 static long poem_index
[600]; // Index of poem starts
70 static long nitems
= 0; // Number of poems
71 static int char_height
= DEFAULT_CHAR_HEIGHT
; // Actual height
72 static int index_ptr
= -1; // Pointer into index
73 static int poem_height
, poem_width
; // Size of poem
74 static int XPos
; // Startup X position
75 static int YPos
; // Startup Y position
76 static int pointSize
= 12; // Font size
78 static wxChar
*index_filename
= NULL
; // Index filename
79 static wxChar
*data_filename
= NULL
; // Data filename
80 static wxChar error_buf
[300]; // Error message buffer
81 static bool loaded_ok
= false; // Poem loaded ok
82 static bool index_ok
= false; // Index loaded ok
84 static bool paging
= false; // Are we paging?
85 static int current_page
= 0; // Currently viewed page
87 wxIcon
*Corner1
= NULL
;
88 wxIcon
*Corner2
= NULL
;
89 wxIcon
*Corner3
= NULL
;
90 wxIcon
*Corner4
= NULL
;
93 wxFont
*NormalFont
= NULL
;
94 wxFont
*BoldFont
= NULL
;
95 wxFont
*ItalicFont
= NULL
;
98 wxPen
*GreyPen
= NULL
;
99 wxPen
*DarkGreyPen
= NULL
;
100 wxPen
*WhitePen
= NULL
;
103 wxBitmap
*backingBitmap
= NULL
;
105 void PoetryError(wxChar
*, wxChar
*caption
=_T("wxPoem Error"));
106 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
=_T("wxPoem"));
108 bool LoadPoem(wxChar
*, long);
110 int LoadIndex(wxChar
*);
112 void WritePreferences();
113 void ReadPreferences();
114 void FindMax(int *max_thing
, int thing
);
118 #include "wx/dataobj.h"
119 #include "wx/clipbrd.h"
123 STDAPI_(__int64
) CeGetRandomSeed();
128 MainWindow
*TheMainWindow
= NULL
;
133 NormalFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxNORMAL
);
134 BoldFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxBOLD
);
135 ItalicFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxITALIC
, wxNORMAL
);
138 BEGIN_EVENT_TABLE(MainWindow
, wxFrame
)
139 EVT_CLOSE(MainWindow::OnCloseWindow
)
140 EVT_CHAR(MainWindow::OnChar
)
141 EVT_MENU(wxID_ANY
, MainWindow::OnPopup
)
144 MainWindow::MainWindow(wxFrame
*frame
, wxWindowID id
, const wxString
& title
,
145 const wxPoint
& pos
, const wxSize
& size
, long style
):
146 wxFrame(frame
, id
, title
, pos
, size
, style
)
150 // Read the poetry buffer, either for finding the size
151 // or for writing to a bitmap (not to the window directly,
152 // since that displays messily)
153 // If DrawIt is true, we draw, otherwise we just determine the
154 // size the window should be.
155 void MainWindow::ScanBuffer(wxDC
*dc
, bool DrawIt
, int *max_x
, int *max_y
)
157 int i
= pages
[current_page
];
163 bool page_break
= false;
170 y
= (*max_y
- poem_height
)/2;
175 if (DrawIt
&& wxColourDisplay())
177 dc
->SetBrush(*wxLIGHT_GREY_BRUSH
);
178 dc
->SetPen(*GreyPen
);
179 dc
->DrawRectangle(0, 0, width
, height
);
180 dc
->SetBackgroundMode(wxTRANSPARENT
);
183 // See what ACTUAL char height is
184 dc
->SetFont(* NormalFont
);
187 dc
->GetTextExtent(_T("X"), &xx
, &yy
);
188 char_height
= (int)yy
;
190 if (current_page
== 0)
192 else if (title
[0] != 0)
194 dc
->SetFont(* BoldFont
);
195 dc
->GetTextExtent(title
, &xx
, &yy
);
196 FindMax(&curr_width
, (int)xx
);
200 int x
= (width
- xx
)/2;
201 dc
->SetFont(* BoldFont
);
203 // Change text to BLACK!
204 dc
->SetTextForeground(* wxBLACK
);
205 dc
->DrawText(title
, x
, y
);
206 // Change text to WHITE!
207 dc
->SetTextForeground(* wxWHITE
);
208 dc
->DrawText(title
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
214 while (ch
!= 0 && !page_break
)
217 #if defined(__WXMSW__) || defined(__WXMAC__)
218 while (((ch
= poem_buffer
[i
]) != 13) && (ch
!= 0))
220 while (((ch
= poem_buffer
[i
]) != 10) && (ch
!= 0))
228 #if defined(__WXMSW__) || defined(__WXMAC__)
236 #if defined(__WXMSW__) || defined(__WXMAC__)
237 // Add another to skip the linefeed
240 // If a single newline on its own, put a space in
262 dc
->SetFont(* BoldFont
);
265 wxStrcpy(title
, line_ptr
);
266 wxStrcat(title
, _T(" (cont'd)"));
268 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
269 FindMax(&curr_width
, (int)xx
);
273 int x
= (width
- xx
)/2;
274 dc
->SetFont(* BoldFont
);
276 // Change text to BLACK!
277 dc
->SetTextForeground(* wxBLACK
);
278 dc
->DrawText(line_ptr
, x
, y
);
280 // Change text to WHITE!
281 dc
->SetTextForeground(* wxWHITE
);
282 dc
->DrawText(line_ptr
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
283 dc
->SetTextForeground(* wxWHITE
);
289 dc
->SetFont(* ItalicFont
);
291 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
292 FindMax(&curr_width
, (int)xx
);
296 int x
= (width
- xx
)/2;
297 dc
->SetTextForeground(* wxBLACK
);
298 dc
->DrawText(line_ptr
, x
, y
);
302 // Default: just ignore this line
309 dc
->SetFont(* NormalFont
);
311 dc
->GetTextExtent(line
, &xx
, &yy
);
312 FindMax(&curr_width
, (int)xx
);
316 int x
= (int)((width
- xx
)/2.0);
317 dc
->SetFont(* NormalFont
);
318 dc
->SetTextForeground(* wxBLACK
);
319 dc
->DrawText(line
, x
, y
);
329 wxChar
*cont
= _T("(cont'd)");
331 dc
->SetFont(* NormalFont
);
333 dc
->GetTextExtent(cont
, &xx
, &yy
);
334 FindMax(&curr_width
, (int)xx
);
337 int x
= (int)((width
- xx
)/2.0);
338 dc
->SetFont(* NormalFont
);
339 dc
->SetTextForeground(* wxBLACK
);
340 dc
->DrawText(cont
, x
, y
);
345 *max_x
= (int)curr_width
;
346 *max_y
= (int)(y
-char_height
);
349 pages
[current_page
+1] = i
;
355 // Draw dark grey thick border
356 if (wxColourDisplay())
358 dc
->SetBrush(*wxGREY_BRUSH
);
359 dc
->SetPen(*wxGREY_PEN
);
362 dc
->DrawRectangle(0, 0, THIN_LINE_BORDER
, height
);
364 dc
->DrawRectangle(THIN_LINE_BORDER
, 0, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
366 dc
->DrawRectangle(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
, height
-THIN_LINE_BORDER
);
368 dc
->DrawRectangle(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
);
371 // Have grey background, plus 3-d border -
372 // One black rectangle.
373 // Inside this, left and top sides - dark grey. Bottom and right -
376 // Change pen to black
377 dc
->SetPen(*wxBLACK_PEN
);
378 dc
->DrawLine(THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
379 dc
->DrawLine(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
380 dc
->DrawLine(width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
381 dc
->DrawLine(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, THIN_LINE_BORDER
);
383 // Right and bottom white lines - 'grey' (black!) if
384 // we're running on a mono display.
385 if (wxColourDisplay())
386 dc
->SetPen(*WhitePen
);
388 dc
->SetPen(*DarkGreyPen
);
390 dc
->DrawLine(width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
,
391 width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
392 dc
->DrawLine(width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
393 THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
395 // Left and top grey lines
396 dc
->SetPen(*DarkGreyPen
);
397 dc
->DrawLine(THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
398 THICK_LINE_BORDER
, THICK_LINE_BORDER
);
399 dc
->DrawLine(THICK_LINE_BORDER
, THICK_LINE_BORDER
,
400 width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
);
404 dc
->DrawIcon(* Corner1
, 0, 0);
405 dc
->DrawIcon(* Corner2
, int(width
-32), 0);
407 int y2
= height
- 32;
409 dc
->DrawIcon(* Corner3
, 0, y2
);
410 dc
->DrawIcon(* Corner4
, x2
, y2
);
415 // Get an index (randomly generated) and load the poem
416 void MainWindow::GetIndexLoadPoem(void)
419 index_ptr
= GetIndex();
422 loaded_ok
= LoadPoem(data_filename
, -1);
425 // Find the size of the poem and resize the window accordingly
426 void MainWindow::Resize(void)
428 wxClientDC
dc(canvas
);
431 ScanBuffer(& dc
, false, &poem_width
, &poem_height
);
432 int x
= poem_width
+ (2*BORDER_SIZE
);
433 int y
= poem_height
+ (2*BORDER_SIZE
);
437 // In case client size isn't what we set it to...
439 GetClientSize(&xx
, &yy
);
442 if (backingBitmap
) delete backingBitmap
;
443 backingBitmap
= new wxBitmap(x
, yy
);
444 memDC
.SelectObject(* backingBitmap
);
447 TheMainWindow
->ScanBuffer(&memDC
, true, &xx
, &yy
);
451 void FindMax(int *max_thing
, int thing
)
453 if (thing
> *max_thing
)
458 void MainWindow::NextPage(void)
471 void MainWindow::PreviousPage(void)
473 if (current_page
> 0)
480 // Search for a string
481 void MainWindow::Search(bool ask
)
485 if (ask
|| !search_string
)
487 wxString s
= wxGetTextFromUser( _T("Enter search string"), _T("Search"), (const wxChar
*) search_string
);
488 if (s
!= wxEmptyString
)
491 if (search_string
) delete[] search_string
;
492 search_string
= wxStrcpy(new wxChar
[wxStrlen(s
.c_str()) + 1], s
.c_str());
494 } else search_ok
= false;
502 if (search_string
&& search_ok
)
504 position
= DoSearch();
507 loaded_ok
= LoadPoem(data_filename
, position
);
513 PoetryNotify(_T("Search string not found."));
520 poem_buffer
= new wxChar
[buf_size
];
522 GreyPen
= new wxPen(_T("LIGHT GREY"), THICK_LINE_WIDTH
, wxSOLID
);
523 DarkGreyPen
= new wxPen(_T("GREY"), THICK_LINE_WIDTH
, wxSOLID
);
524 WhitePen
= new wxPen(_T("WHITE"), THICK_LINE_WIDTH
, wxSOLID
);
530 // Seed the random number generator
532 srand((unsigned) CeGetRandomSeed());
536 (void)time(¤t_time
);
537 srand((unsigned int)current_time
);
543 TheMainWindow
= new MainWindow(NULL
,
548 wxCAPTION
|wxMINIMIZE_BOX
|wxSYSTEM_MENU
|wxCLOSE_BOX
|wxFULL_REPAINT_ON_RESIZE
551 TheMainWindow
->SetIcon(wxICON(wxpoem
));
553 TheMainWindow
->canvas
= new MyCanvas(TheMainWindow
, 501, wxDefaultPosition
, wxDefaultSize
);
557 index_filename
= wxStrcpy(new wxChar
[wxStrlen(argv
[1]) + 1], argv
[1]);
558 data_filename
= wxStrcpy(new wxChar
[wxStrlen(argv
[1]) + 1], argv
[1]);
562 index_filename
= _T(DEFAULT_POETRY_IND
);
563 data_filename
= _T(DEFAULT_POETRY_DAT
);
568 Corner1
= new wxIcon(_T("icon_1"));
569 Corner2
= new wxIcon(_T("icon_2"));
570 Corner3
= new wxIcon(_T("icon_3"));
571 Corner4
= new wxIcon(_T("icon_4"));
573 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
574 Corner1
= new wxIcon( corner1_xpm
);
575 Corner2
= new wxIcon( corner2_xpm
);
576 Corner3
= new wxIcon( corner3_xpm
);
577 Corner4
= new wxIcon( corner4_xpm
);
580 TheMainWindow
->GetIndexLoadPoem();
581 TheMainWindow
->Resize();
582 TheMainWindow
->Show(true);
590 delete backingBitmap
;
600 delete[] poem_buffer
;
602 delete[] search_string
;
607 void MainWindow::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
613 void MainWindow::OnChar(wxKeyEvent
& event
)
615 canvas
->OnChar(event
);
618 BEGIN_EVENT_TABLE(MyCanvas
, wxWindow
)
619 EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent
)
620 EVT_CHAR(MyCanvas::OnChar
)
621 EVT_PAINT(MyCanvas::OnPaint
)
624 // Define a constructor for my canvas
625 MyCanvas::MyCanvas(wxFrame
*frame
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
):
626 wxWindow(frame
, id
, pos
, size
)
628 popupMenu
= new wxMenu
;
629 popupMenu
->Append(POEM_NEXT
, _T("Next poem/page"));
630 popupMenu
->Append(POEM_PREVIOUS
, _T("Previous page"));
631 popupMenu
->AppendSeparator();
632 popupMenu
->Append(POEM_SEARCH
, _T("Search"));
633 popupMenu
->Append(POEM_NEXT_MATCH
, _T("Next match"));
634 popupMenu
->Append(POEM_COPY
, _T("Copy to clipboard"));
635 popupMenu
->Append(POEM_MINIMIZE
, _T("Minimize"));
636 popupMenu
->AppendSeparator();
637 popupMenu
->Append(POEM_BIGGER_TEXT
, _T("Bigger text"));
638 popupMenu
->Append(POEM_SMALLER_TEXT
, _T("Smaller text"));
639 popupMenu
->AppendSeparator();
640 popupMenu
->Append(POEM_ABOUT
, _T("About wxPoem"));
641 popupMenu
->AppendSeparator();
642 popupMenu
->Append(POEM_EXIT
, _T("Exit"));
645 MyCanvas::~MyCanvas()
647 // Note: this must be done before the main window/canvas are destroyed
648 // or we get an error (no parent window for menu item button)
653 // Define the repainting behaviour
654 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
661 TheMainWindow
->GetClientSize(&xx
, &yy
);
663 dc
.DrawBitmap(* backingBitmap
, 0, 0);
666 memDC
.SelectObject(* backingBitmap
);
667 dc
.Blit(0, 0, backingBitmap
->GetWidth(), backingBitmap
->GetHeight(), &memDC
, 0, 0);
672 void MyCanvas::OnMouseEvent(wxMouseEvent
& event
)
674 static int startPosX
, startPosY
, startFrameX
, startFrameY
;
677 event
.GetPosition(&x
, &y
);
679 if (event
.RightDown())
681 // Versions from wxWin 1.67 are probably OK
682 PopupMenu(popupMenu
, (int)x
, (int)y
);
684 else if (event
.LeftDown())
686 this->CaptureMouse();
689 ClientToScreen(&x1
, &y1
);
692 GetParent()->GetPosition(&startFrameX
, &startFrameY
);
694 else if (event
.LeftUp())
696 if (GetCapture() == this) this->ReleaseMouse();
698 else if (event
.Dragging() && event
.LeftIsDown())
702 ClientToScreen(&x1
, &y1
);
704 int dX
= x1
- startPosX
;
705 int dY
= y1
- startPosY
;
706 GetParent()->Move(startFrameX
+ dX
, startFrameY
+ dY
);
710 // Process characters
711 void MyCanvas::OnChar(wxKeyEvent
& event
)
713 switch (event
.GetKeyCode())
718 TheMainWindow
->Search(false);
723 TheMainWindow
->Search(true);
729 TheMainWindow
->NextPage();
732 TheMainWindow
->Close(true);
739 int LoadIndex(wxChar
*file_name
)
746 if (file_name
== NULL
)
749 wxSprintf(buf
, _T("%s.idx"), file_name
);
751 index_file
= wxFopen(buf
, _T("r"));
752 if (index_file
== NULL
)
755 wxFscanf(index_file
, _T("%ld"), &nitems
);
757 for (int i
= 0; i
< nitems
; i
++)
759 wxFscanf(index_file
, _T("%ld"), &data
);
760 poem_index
[i
] = data
;
771 int indexn
= (int)(rand() % nitems
);
773 if ((indexn
< 0) || (indexn
> nitems
))
774 { PoetryError(_T("No such poem!"));
782 void ReadPreferences()
785 wxGetResource(_T("wxPoem"), _T("FontSize"), &pointSize
);
786 wxGetResource(_T("wxPoem"), _T("X"), &XPos
);
787 wxGetResource(_T("wxPoem"), _T("Y"), &YPos
);
791 // Write preferences to disk
792 void WritePreferences()
795 TheMainWindow
->GetPosition(&XPos
, &YPos
);
797 wxWriteResource(_T("wxPoem"), _T("FontSize"), pointSize
);
798 wxWriteResource(_T("wxPoem"), _T("X"), XPos
);
799 wxWriteResource(_T("wxPoem"), _T("Y"), YPos
);
804 // Load a poem from given file, at given point in file.
805 // If position is > -1, use this for the position in the
806 // file, otherwise use index[index_ptr] to find the correct position.
807 bool LoadPoem(wxChar
*file_name
, long position
)
818 if (file_name
== NULL
)
820 wxSprintf(error_buf
, _T("Error in Poem loading."));
821 PoetryError(error_buf
);
825 wxSprintf(buf
, _T("%s.dat"), file_name
);
826 data_file
= wxFopen(buf
, _T("r"));
828 if (data_file
== NULL
)
830 wxSprintf(error_buf
, _T("Data file %s not found."), buf
);
831 PoetryError(error_buf
);
838 data
= poem_index
[index_ptr
];
840 fseek(data_file
, data
, SEEK_SET
);
844 while ((ch
!= EOF
) && (ch
!= '#'))
846 ch
= getc(data_file
);
847 // Add a linefeed so it will copy to the clipboard ok
859 wxSprintf(error_buf
, _T("%s"), _T("Poetry buffer exceeded."));
860 PoetryError(error_buf
);
865 poem_buffer
[i
-1] = 0;
870 long MainWindow::DoSearch(void)
880 long previous_poem_start
;
883 int search_length
= wxStrlen(search_string
);
887 find_start
= last_find
+ 1;
888 previous_poem_start
= last_poem_start
;
894 previous_poem_start
= -1;
898 wxSprintf(buf
, _T("%s.dat"), data_filename
);
900 file
= wxFopen(buf
, _T("r"));
901 if (! (data_filename
&& file
))
903 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
904 PoetryError(error_buf
);
908 fseek(file
, find_start
, SEEK_SET
);
910 while ((ch
!= EOF
) && !found
)
913 ch
= wxTolower(ch
); // Make lower case
915 // Only match if we're looking at a different poem
916 // (no point in displaying the same poem again)
917 if ((ch
== search_string
[i
]) && (last_poem_start
!= previous_poem_start
))
920 last_find
= ftell(file
);
921 if (i
== search_length
-1)
931 last_poem_start
= ftell(file
);
940 return last_poem_start
;
946 // Set up poetry filenames, preferences, load the index
947 // Load index (or compile it if none found)
950 index_ok
= (LoadIndex(index_filename
) != 0);
951 if (!index_ok
|| (nitems
== 0))
953 PoetryError(_T("Index file not found; will compile new one"), _T("wxPoem"));
954 index_ok
= Compile();
959 void PoetryError(wxChar
*msg
, wxChar
*caption
)
961 wxMessageBox(msg
, caption
, wxOK
|wxICON_EXCLAMATION
);
964 // Notification (change icon to something appropriate!)
965 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
)
967 wxMessageBox(Msg
, caption
, wxOK
| wxICON_INFORMATION
);
970 // Build up and save an index into the poetry data file, for
971 // rapid random access
980 wxSprintf(buf
, _T("%s.dat"), data_filename
);
982 file
= wxFopen(buf
, _T("r"));
983 if (! (data_filename
&& file
))
985 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
986 PoetryError(error_buf
);
993 poem_index
[nitems
] = 0;
1005 poem_index
[nitems
] = data
;
1008 } while (ch
!= EOF
);
1012 wxSprintf(buf
, _T("%s.idx"), index_filename
);
1014 file
= wxFopen(buf
, _T("w"));
1015 if (! (data_filename
&& file
))
1017 wxSprintf(error_buf
, _T("Poetry index file %s cannot be created\n"), buf
);
1018 PoetryError(error_buf
);
1022 wxFprintf(file
, _T("%ld\n\n"), nitems
);
1023 for (j
= 0; j
< nitems
; j
++)
1024 wxFprintf(file
, _T("%ld\n"), poem_index
[j
]);
1027 PoetryNotify(_T("Poetry index compiled."));
1031 void MainWindow::OnPopup(wxCommandEvent
& event
)
1033 switch (event
.GetId())
1036 // Another poem/page
1037 TheMainWindow
->NextPage();
1041 TheMainWindow
->PreviousPage();
1044 // Search - with dialog
1045 TheMainWindow
->Search(true);
1047 case POEM_NEXT_MATCH
:
1048 // Search - without dialog (next match)
1049 TheMainWindow
->Search(false);
1052 TheMainWindow
->Iconize(true);
1056 wxTheClipboard
->UsePrimarySelection();
1057 if (wxTheClipboard
->Open())
1061 s
.Replace( _T("@P"),_T(""));
1062 s
.Replace( _T("@A "),_T(""));
1063 s
.Replace( _T("@A"),_T(""));
1064 s
.Replace( _T("@T "),_T(""));
1065 s
.Replace( _T("@T"),_T(""));
1066 wxTextDataObject
*data
= new wxTextDataObject( s
.c_str() );
1067 if (!wxTheClipboard
->SetData( data
))
1068 wxMessageBox(_T("Error while copying to the clipboard."));
1072 wxMessageBox(_T("Error opening the clipboard."));
1074 wxTheClipboard
->Close();
1081 case POEM_BIGGER_TEXT
:
1085 TheMainWindow
->Resize();
1088 case POEM_SMALLER_TEXT
:
1094 TheMainWindow
->Resize();
1100 (void)wxMessageBox(_T("wxPoem Version 1.1\nJulian Smart (c) 1995"),
1101 _T("About wxPoem"), wxOK
, TheMainWindow
);
1106 TheMainWindow
->Close(true);