]>
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"
36 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
37 #include "corner1.xpm"
38 #include "corner2.xpm"
39 #include "corner3.xpm"
40 #include "corner4.xpm"
55 #define buf_size 10000
56 #define DEFAULT_POETRY_DAT "wxpoem"
57 #define DEFAULT_POETRY_IND "wxpoem"
58 #define DEFAULT_CHAR_HEIGHT 18
59 #define DEFAULT_FONT "Swiss"
60 #define DEFAULT_X_POS 0
61 #define DEFAULT_Y_POS 0
62 #define BORDER_SIZE 30
63 #define THIN_LINE_BORDER 10
64 #define THICK_LINE_BORDER 16
65 #define THICK_LINE_WIDTH 2
66 #define SHADOW_OFFSET 1
70 static wxChar
*poem_buffer
; // Storage for each poem
71 static wxChar line
[150]; // Storage for a line
72 static wxChar title
[150]; // Remember the title
73 static wxChar
*search_string
= NULL
; // The search string
74 static int pages
[30]; // For multipage poems -
75 // store the start of each page
76 static long last_poem_start
= 0; // Start of last found poem
77 static long last_find
= -1; // Point in file of last found
79 static bool search_ok
= FALSE
; // Search was successful
80 static bool same_search
= FALSE
; // Searching on same string
82 static long poem_index
[600]; // Index of poem starts
83 static long nitems
= 0; // Number of poems
84 static int char_height
= DEFAULT_CHAR_HEIGHT
; // Actual height
85 static int index_ptr
= -1; // Pointer into index
86 static int poem_height
, poem_width
; // Size of poem
87 static int XPos
; // Startup X position
88 static int YPos
; // Startup Y position
89 static int pointSize
= 12; // Font size
91 static wxChar
*index_filename
= NULL
; // Index filename
92 static wxChar
*data_filename
= NULL
; // Data filename
93 static wxChar error_buf
[300]; // Error message buffer
94 static bool loaded_ok
= FALSE
; // Poem loaded ok
95 static bool index_ok
= FALSE
; // Index loaded ok
97 static bool paging
= FALSE
; // Are we paging?
98 static int current_page
= 0; // Currently viewed page
100 wxIcon
*Corner1
= NULL
;
101 wxIcon
*Corner2
= NULL
;
102 wxIcon
*Corner3
= NULL
;
103 wxIcon
*Corner4
= NULL
;
106 wxFont
*NormalFont
= NULL
;
107 wxFont
*BoldFont
= NULL
;
108 wxFont
*ItalicFont
= NULL
;
111 wxPen
*GreyPen
= NULL
;
112 wxPen
*DarkGreyPen
= NULL
;
113 wxPen
*WhitePen
= NULL
;
116 wxBitmap
*backingBitmap
= NULL
;
118 void PoetryError(wxChar
*, wxChar
*caption
=_T("wxPoem Error"));
119 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
=_T("wxPoem"));
121 bool LoadPoem(wxChar
*, long);
123 int LoadIndex(wxChar
*);
125 void WritePreferences();
126 void ReadPreferences();
127 void FindMax(int *max_thing
, int thing
);
130 void CopyToClipboard(HWND
, wxChar
*);
133 wxMenu
*popupMenu
= NULL
;
136 wxHelpController
*HelpController
= NULL
;
141 MainWindow
*TheMainWindow
= NULL
;
146 NormalFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxNORMAL
);
147 BoldFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxNORMAL
, wxBOLD
);
148 ItalicFont
= wxTheFontList
->FindOrCreateFont(pointSize
, wxSWISS
, wxITALIC
, wxNORMAL
);
151 BEGIN_EVENT_TABLE(MainWindow
, wxFrame
)
152 EVT_CLOSE(MainWindow::OnCloseWindow
)
153 EVT_CHAR(MainWindow::OnChar
)
154 EVT_MENU(-1, MainWindow::OnPopup
)
157 MainWindow::MainWindow(wxFrame
*frame
, wxWindowID id
, const wxString
& title
,
158 const wxPoint
& pos
, const wxSize
& size
, long style
):
159 wxFrame(frame
, id
, title
, pos
, size
, style
)
163 MainWindow::~MainWindow()
165 // Note: this must be done before the main window/canvas are destroyed
166 // or we get an error (no parent window for menu item button)
171 // Read the poetry buffer, either for finding the size
172 // or for writing to a bitmap (not to the window directly,
173 // since that displays messily)
174 // If DrawIt is true, we draw, otherwise we just determine the
175 // size the window should be.
176 void MainWindow::ScanBuffer(wxDC
*dc
, bool DrawIt
, int *max_x
, int *max_y
)
178 int i
= pages
[current_page
];
184 bool page_break
= FALSE
;
191 y
= (*max_y
- poem_height
)/2;
196 if (DrawIt
&& wxColourDisplay())
198 dc
->SetBrush(*wxLIGHT_GREY_BRUSH
);
199 dc
->SetPen(*GreyPen
);
200 dc
->DrawRectangle(0, 0, width
, height
);
201 dc
->SetBackgroundMode(wxTRANSPARENT
);
204 // See what ACTUAL char height is
205 dc
->SetFont(* NormalFont
);
208 dc
->GetTextExtent(_T("X"), &xx
, &yy
);
209 char_height
= (int)yy
;
211 if (current_page
== 0)
213 else if (title
[0] != 0)
215 dc
->SetFont(* BoldFont
);
216 dc
->GetTextExtent(title
, &xx
, &yy
);
217 FindMax(&curr_width
, (int)xx
);
221 int x
= (width
- xx
)/2;
222 dc
->SetFont(* BoldFont
);
224 // Change text to BLACK!
225 dc
->SetTextForeground(* wxBLACK
);
226 dc
->DrawText(title
, x
, y
);
227 // Change text to WHITE!
228 dc
->SetTextForeground(* wxWHITE
);
229 dc
->DrawText(title
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
235 while (ch
!= 0 && !page_break
)
238 #if defined(__WXMSW__) || defined(__WXMAC__)
239 while (((ch
= poem_buffer
[i
]) != 13) && (ch
!= 0))
241 while (((ch
= poem_buffer
[i
]) != 10) && (ch
!= 0))
249 #if defined(__WXMSW__) || defined(__WXMAC__)
257 #if defined(__WXMSW__) || defined(__WXMAC__)
258 // Add another to skip the linefeed
261 // If a single newline on its own, put a space in
283 dc
->SetFont(* BoldFont
);
286 wxStrcpy(title
, line_ptr
);
287 wxStrcat(title
, _T(" (cont'd)"));
289 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
290 FindMax(&curr_width
, (int)xx
);
294 int x
= (width
- xx
)/2;
295 dc
->SetFont(* BoldFont
);
297 // Change text to BLACK!
298 dc
->SetTextForeground(* wxBLACK
);
299 dc
->DrawText(line_ptr
, x
, y
);
301 // Change text to WHITE!
302 dc
->SetTextForeground(* wxWHITE
);
303 dc
->DrawText(line_ptr
, x
-SHADOW_OFFSET
, y
-SHADOW_OFFSET
);
304 dc
->SetTextForeground(* wxWHITE
);
310 dc
->SetFont(* ItalicFont
);
312 dc
->GetTextExtent(line_ptr
, &xx
, &yy
);
313 FindMax(&curr_width
, (int)xx
);
317 int x
= (width
- xx
)/2;
318 dc
->SetTextForeground(* wxBLACK
);
319 dc
->DrawText(line_ptr
, x
, y
);
323 // Default: just ignore this line
330 dc
->SetFont(* NormalFont
);
332 dc
->GetTextExtent(line
, &xx
, &yy
);
333 FindMax(&curr_width
, (int)xx
);
337 int x
= (int)((width
- xx
)/2.0);
338 dc
->SetFont(* NormalFont
);
339 dc
->SetTextForeground(* wxBLACK
);
340 dc
->DrawText(line
, x
, y
);
350 wxChar
*cont
= _T("(cont'd)");
352 dc
->SetFont(* NormalFont
);
354 dc
->GetTextExtent(cont
, &xx
, &yy
);
355 FindMax(&curr_width
, (int)xx
);
358 int x
= (int)((width
- xx
)/2.0);
359 dc
->SetFont(* NormalFont
);
360 dc
->SetTextForeground(* wxBLACK
);
361 dc
->DrawText(cont
, x
, y
);
366 *max_x
= (int)curr_width
;
367 *max_y
= (int)(y
-char_height
);
370 pages
[current_page
+1] = i
;
376 // Draw dark grey thick border
377 if (wxColourDisplay())
379 dc
->SetBrush(*wxGREY_BRUSH
);
380 dc
->SetPen(*wxGREY_PEN
);
383 dc
->DrawRectangle(0, 0, THIN_LINE_BORDER
, height
);
385 dc
->DrawRectangle(THIN_LINE_BORDER
, 0, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
387 dc
->DrawRectangle(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
, height
-THIN_LINE_BORDER
);
389 dc
->DrawRectangle(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
);
392 // Have grey background, plus 3-d border -
393 // One black rectangle.
394 // Inside this, left and top sides - dark grey. Bottom and right -
397 // Change pen to black
398 dc
->SetPen(*wxBLACK_PEN
);
399 dc
->DrawLine(THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
);
400 dc
->DrawLine(width
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
401 dc
->DrawLine(width
-THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
);
402 dc
->DrawLine(THIN_LINE_BORDER
, height
-THIN_LINE_BORDER
, THIN_LINE_BORDER
, THIN_LINE_BORDER
);
404 // Right and bottom white lines - 'grey' (black!) if
405 // we're running on a mono display.
406 if (wxColourDisplay())
407 dc
->SetPen(*WhitePen
);
409 dc
->SetPen(*DarkGreyPen
);
411 dc
->DrawLine(width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
,
412 width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
413 dc
->DrawLine(width
-THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
414 THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
);
416 // Left and top grey lines
417 dc
->SetPen(*DarkGreyPen
);
418 dc
->DrawLine(THICK_LINE_BORDER
, height
-THICK_LINE_BORDER
,
419 THICK_LINE_BORDER
, THICK_LINE_BORDER
);
420 dc
->DrawLine(THICK_LINE_BORDER
, THICK_LINE_BORDER
,
421 width
-THICK_LINE_BORDER
, THICK_LINE_BORDER
);
425 dc
->DrawIcon(* Corner1
, 0, 0);
426 dc
->DrawIcon(* Corner2
, int(width
-32), 0);
428 int y2
= height
- 32;
430 dc
->DrawIcon(* Corner3
, 0, y2
);
431 dc
->DrawIcon(* Corner4
, x2
, y2
);
436 // Get an index (randomly generated) and load the poem
437 void MainWindow::GetIndexLoadPoem(void)
440 index_ptr
= GetIndex();
443 loaded_ok
= LoadPoem(data_filename
, -1);
446 // Find the size of the poem and resize the window accordingly
447 void MainWindow::Resize(void)
449 wxClientDC
dc(canvas
);
452 ScanBuffer(& dc
, FALSE
, &poem_width
, &poem_height
);
453 int x
= poem_width
+ (2*BORDER_SIZE
);
454 int y
= poem_height
+ (2*BORDER_SIZE
);
458 // In case client size isn't what we set it to...
460 GetClientSize(&xx
, &yy
);
463 if (backingBitmap
) delete backingBitmap
;
464 backingBitmap
= new wxBitmap(x
, yy
);
465 memDC
.SelectObject(* backingBitmap
);
468 TheMainWindow
->ScanBuffer(&memDC
, TRUE
, &xx
, &yy
);
472 void FindMax(int *max_thing
, int thing
)
474 if (thing
> *max_thing
)
479 void MainWindow::NextPage(void)
492 void MainWindow::PreviousPage(void)
494 if (current_page
> 0)
501 // Search for a string
502 void MainWindow::Search(bool ask
)
506 if (ask
|| !search_string
)
508 wxString s
= wxGetTextFromUser( _T("Enter search string"), _T("Search"), (const wxChar
*) search_string
);
509 if (s
!= wxEmptyString
)
511 if (search_string
) delete[] search_string
;
512 search_string
= copystring(s
);
514 } else search_ok
= FALSE
;
522 if (search_string
&& search_ok
)
524 position
= DoSearch();
527 loaded_ok
= LoadPoem(data_filename
, position
);
533 PoetryNotify(_T("Search string not found."));
538 // Copy a string to the clipboard
540 void CopyToClipboard(HWND handle
, wxChar
*s
)
542 int length
= wxStrlen(s
);
543 HANDLE hGlobalMemory
= GlobalAlloc(GHND
, (DWORD
) length
+ 1);
546 #ifdef __WINDOWS_386__
547 LPSTR lpGlobalMemory
= MK_FP32(GlobalLock(hGlobalMemory
));
549 LPSTR lpGlobalMemory
= (LPSTR
)GlobalLock(hGlobalMemory
);
552 for (i
= 0; i
< length
; i
++)
570 lpGlobalMemory
[j
] = s
[i
];
575 GlobalUnlock(hGlobalMemory
);
576 OpenClipboard(handle
);
578 SetClipboardData(CF_TEXT
, hGlobalMemory
);
586 poem_buffer
= new wxChar
[buf_size
];
588 GreyPen
= new wxPen(_T("LIGHT GREY"), THICK_LINE_WIDTH
, wxSOLID
);
589 DarkGreyPen
= new wxPen(_T("GREY"), THICK_LINE_WIDTH
, wxSOLID
);
590 WhitePen
= new wxPen(_T("WHITE"), THICK_LINE_WIDTH
, wxSOLID
);
593 HelpController
= new wxHelpController();
594 HelpController
->Initialize(_T("wxpoem"));
601 // Seed the random number generator
604 (void)time(¤t_time
);
605 srand((unsigned int)current_time
);
610 TheMainWindow
= new MainWindow(NULL
,
615 wxCAPTION
|wxMINIMIZE_BOX
|wxSYSTEM_MENU
|wxCLOSE_BOX
|wxFULL_REPAINT_ON_RESIZE
619 TheMainWindow
->SetIcon(Icon(_T("wxpoem")));
622 TheMainWindow
->canvas
= new MyCanvas(TheMainWindow
, 501, wxDefaultPosition
, wxDefaultSize
);
624 popupMenu
= new wxMenu
;
625 popupMenu
->Append(POEM_NEXT
, _T("Next poem/page"));
626 popupMenu
->Append(POEM_PREVIOUS
, _T("Previous page"));
627 popupMenu
->AppendSeparator();
628 popupMenu
->Append(POEM_SEARCH
, _T("Search"));
629 popupMenu
->Append(POEM_NEXT_MATCH
, _T("Next match"));
630 popupMenu
->Append(POEM_COPY
, _T("Copy to clipboard"));
631 popupMenu
->Append(POEM_MINIMIZE
, _T("Minimize"));
632 popupMenu
->AppendSeparator();
633 popupMenu
->Append(POEM_BIGGER_TEXT
, _T("Bigger text"));
634 popupMenu
->Append(POEM_SMALLER_TEXT
, _T("Smaller text"));
635 popupMenu
->AppendSeparator();
636 popupMenu
->Append(POEM_ABOUT
, _T("About wxPoem"));
637 popupMenu
->AppendSeparator();
638 popupMenu
->Append(POEM_EXIT
, _T("Exit"));
642 index_filename
= copystring(argv
[1]);
643 data_filename
= copystring(argv
[1]);
647 index_filename
= _T(DEFAULT_POETRY_IND
);
648 data_filename
= _T(DEFAULT_POETRY_DAT
);
653 Corner1
= new wxIcon(_T("icon_1"));
654 Corner2
= new wxIcon(_T("icon_2"));
655 Corner3
= new wxIcon(_T("icon_3"));
656 Corner4
= new wxIcon(_T("icon_4"));
658 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
659 Corner1
= new wxIcon( corner1_xpm
);
660 Corner2
= new wxIcon( corner2_xpm
);
661 Corner3
= new wxIcon( corner3_xpm
);
662 Corner4
= new wxIcon( corner4_xpm
);
665 TheMainWindow
->GetIndexLoadPoem();
666 TheMainWindow
->Resize();
667 TheMainWindow
->Show(TRUE
);
675 delete backingBitmap
;
677 delete HelpController
;
688 // Causes crash since they're deleted by the global font list
695 delete[] poem_buffer
;
697 delete[] search_string
;
702 void MainWindow::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
708 void MainWindow::OnChar(wxKeyEvent
& event
)
710 canvas
->OnChar(event
);
713 BEGIN_EVENT_TABLE(MyCanvas
, wxWindow
)
714 EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent
)
715 EVT_CHAR(MyCanvas::OnChar
)
716 EVT_PAINT(MyCanvas::OnPaint
)
719 // Define a constructor for my canvas
720 MyCanvas::MyCanvas(wxFrame
*frame
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
):
721 wxWindow(frame
, id
, pos
, size
)
725 // Define the repainting behaviour
726 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
733 TheMainWindow
->GetClientSize(&xx
, &yy
);
735 dc
.DrawBitmap(* backingBitmap
, 0, 0);
738 memDC
.SelectObject(* backingBitmap
);
739 dc
.Blit(0, 0, backingBitmap
->GetWidth(), backingBitmap
->GetHeight(), &memDC
, 0, 0);
744 void MyCanvas::OnMouseEvent(wxMouseEvent
& event
)
746 static int startPosX
, startPosY
, startFrameX
, startFrameY
;
749 event
.GetPosition(&x
, &y
);
751 if (event
.RightDown())
753 // Versions from wxWin 1.67 are probably OK
754 PopupMenu(popupMenu
, (int)x
, (int)y
);
756 else if (event
.LeftDown())
758 this->CaptureMouse();
761 ClientToScreen(&x1
, &y1
);
764 GetParent()->GetPosition(&startFrameX
, &startFrameY
);
766 else if (event
.LeftUp())
767 this->ReleaseMouse();
768 else if (event
.Dragging() && event
.LeftIsDown())
772 ClientToScreen(&x1
, &y1
);
774 int dX
= x1
- startPosX
;
775 int dY
= y1
- startPosY
;
776 GetParent()->Move(startFrameX
+ dX
, startFrameY
+ dY
);
780 // Process characters
781 void MyCanvas::OnChar(wxKeyEvent
& event
)
783 switch (event
.GetKeyCode())
788 TheMainWindow
->Search(FALSE
);
793 TheMainWindow
->Search(TRUE
);
797 TheMainWindow
->NextPage();
800 TheMainWindow
->Close(TRUE
);
807 int LoadIndex(wxChar
*file_name
)
814 if (file_name
== NULL
)
817 wxSprintf(buf
, _T("%s.idx"), file_name
);
819 index_file
= wxFopen(buf
, _T("r"));
820 if (index_file
== NULL
)
823 wxFscanf(index_file
, _T("%ld"), &nitems
);
825 for (int i
= 0; i
< nitems
; i
++)
827 wxFscanf(index_file
, _T("%ld"), &data
);
828 poem_index
[i
] = data
;
839 int indexn
= (int)(rand() % nitems
);
841 if ((indexn
< 0) || (indexn
> nitems
))
842 { PoetryError(_T("No such poem!"));
850 void ReadPreferences()
853 wxGetResource(_T("wxPoem"), _T("FontSize"), &pointSize
);
854 wxGetResource(_T("wxPoem"), _T("X"), &XPos
);
855 wxGetResource(_T("wxPoem"), _T("Y"), &YPos
);
859 // Write preferences to disk
860 void WritePreferences()
863 TheMainWindow
->GetPosition(&XPos
, &YPos
);
865 wxWriteResource(_T("wxPoem"), _T("FontSize"), pointSize
);
866 wxWriteResource(_T("wxPoem"), _T("X"), XPos
);
867 wxWriteResource(_T("wxPoem"), _T("Y"), YPos
);
872 // Load a poem from given file, at given point in file.
873 // If position is > -1, use this for the position in the
874 // file, otherwise use index[index_ptr] to find the correct position.
875 bool LoadPoem(wxChar
*file_name
, long position
)
886 if (file_name
== NULL
)
888 wxSprintf(error_buf
, _T("Error in Poem loading."));
889 PoetryError(error_buf
);
893 wxSprintf(buf
, _T("%s.dat"), file_name
);
894 data_file
= wxFopen(buf
, _T("r"));
896 if (data_file
== NULL
)
898 wxSprintf(error_buf
, _T("Data file %s not found."), buf
);
899 PoetryError(error_buf
);
906 data
= poem_index
[index_ptr
];
908 fseek(data_file
, data
, SEEK_SET
);
912 while ((ch
!= EOF
) && (ch
!= '#'))
914 ch
= getc(data_file
);
915 // Add a linefeed so it will copy to the clipboard ok
927 wxSprintf(error_buf
, _T("%s"), _T("Poetry buffer exceeded."));
928 PoetryError(error_buf
);
933 poem_buffer
[i
-1] = 0;
938 long MainWindow::DoSearch(void)
948 long previous_poem_start
;
951 int search_length
= wxStrlen(search_string
);
955 find_start
= last_find
+ 1;
956 previous_poem_start
= last_poem_start
;
962 previous_poem_start
= -1;
966 wxSprintf(buf
, _T("%s.dat"), data_filename
);
968 file
= wxFopen(buf
, _T("r"));
969 if (! (data_filename
&& file
))
971 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
972 PoetryError(error_buf
);
976 fseek(file
, find_start
, SEEK_SET
);
978 while ((ch
!= EOF
) && !found
)
981 ch
|= 0x0020; // Make lower case
983 // Only match if we're looking at a different poem
984 // (no point in displaying the same poem again)
985 if ((ch
== search_string
[i
]) && (last_poem_start
!= previous_poem_start
))
988 last_find
= ftell(file
);
989 if (i
== search_length
-1)
999 last_poem_start
= ftell(file
);
1008 return last_poem_start
;
1014 // Set up poetry filenames, preferences, load the index
1015 // Load index (or compile it if none found)
1018 index_ok
= (LoadIndex(index_filename
) != 0);
1019 if (!index_ok
|| (nitems
== 0))
1021 PoetryError(_T("Index file not found; will compile new one"), _T("wxPoem"));
1022 index_ok
= Compile();
1027 void PoetryError(wxChar
*msg
, wxChar
*caption
)
1029 wxMessageBox(msg
, caption
, wxOK
|wxICON_EXCLAMATION
);
1032 // Notification (change icon to something appropriate!)
1033 void PoetryNotify(wxChar
*Msg
, wxChar
*caption
)
1035 wxMessageBox(Msg
, caption
, wxOK
| wxICON_INFORMATION
);
1038 // Build up and save an index into the poetry data file, for
1039 // rapid random access
1048 wxSprintf(buf
, _T("%s.dat"), data_filename
);
1050 file
= wxFopen(buf
, _T("r"));
1051 if (! (data_filename
&& file
))
1053 wxSprintf(error_buf
, _T("Poetry data file %s not found\n"), buf
);
1054 PoetryError(error_buf
);
1061 poem_index
[nitems
] = 0;
1073 poem_index
[nitems
] = data
;
1076 } while (ch
!= EOF
);
1080 wxSprintf(buf
, _T("%s.idx"), index_filename
);
1082 file
= wxFopen(buf
, _T("w"));
1083 if (! (data_filename
&& file
))
1085 wxSprintf(error_buf
, _T("Poetry index file %s cannot be created\n"), buf
);
1086 PoetryError(error_buf
);
1090 wxFprintf(file
, _T("%ld\n\n"), nitems
);
1091 for (j
= 0; j
< nitems
; j
++)
1092 wxFprintf(file
, _T("%ld\n"), poem_index
[j
]);
1095 PoetryNotify(_T("Poetry index compiled."));
1099 void MainWindow::OnPopup(wxCommandEvent
& event
)
1101 switch (event
.GetId())
1104 // Another poem/page
1105 TheMainWindow
->NextPage();
1109 TheMainWindow
->PreviousPage();
1112 // Search - with dialog
1113 TheMainWindow
->Search(TRUE
);
1115 case POEM_NEXT_MATCH
:
1116 // Search - without dialog (next match)
1117 TheMainWindow
->Search(FALSE
);
1120 TheMainWindow
->Iconize(TRUE
);
1124 // Copy current poem to the clipboard
1125 CopyToClipboard((HWND
) TheMainWindow
->GetHWND(), poem_buffer
);
1132 case POEM_BIGGER_TEXT
:
1136 TheMainWindow
->Resize();
1139 case POEM_SMALLER_TEXT
:
1145 TheMainWindow
->Resize();
1149 case POEM_HELP_CONTENTS
:
1152 HelpController
->LoadFile(_T("wxpoem"));
1153 HelpController
->DisplayContents();
1154 #endif // wxUSE_HELP
1159 (void)wxMessageBox(_T("wxPoem Version 1.1\nJulian Smart (c) 1995"),
1160 _T("About wxPoem"), wxOK
, TheMainWindow
);
1165 TheMainWindow
->Close(TRUE
);