forked from POV-Ray/povray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvtext.cpp
2019 lines (1857 loc) · 62 KB
/
pvtext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//******************************************************************************
///
/// @file windows/pvtext.cpp
///
/// This module implements message and message display routines for Windows.
///
/// @author Christopher J. Cason
///
/// @copyright
/// @parblock
///
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
///
/// POV-Ray is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License, or (at your option) any later version.
///
/// POV-Ray is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
/// ----------------------------------------------------------------------------
///
/// POV-Ray is based on the popular DKB raytracer version 2.12.
/// DKBTrace was originally written by David K. Buck.
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
///
/// @endparblock
///
//******************************************************************************
#define POVWIN_FILE
#define _WIN32_IE COMMONCTRL_VERSION
#include <windows.h>
#include <commctrl.h>
#include <setjmp.h>
#include <string.h>
#include "pvengine.h"
#include "resource.h"
#include "pvguiext.h"
#include "pvedit.h"
// this must be the last file included
#include "syspovdebug.h"
namespace povwin
{
#define MAX_SEEK_INDEX 1024
typedef struct
{
unsigned Line ;
unsigned short Offset ;
} seekStruct ;
typedef struct
{
int id ;
int resid ;
int flags ;
char *text ;
} toolbarStruct ;
int message_xchar ;
int message_ychar ;
int listbox_xchar ;
int listbox_ychar ;
int top_message_row ;
int message_scroll_pos_x ;
int message_scroll_pos_y ;
int message_count ;
int message_cols ;
int message_rows ;
int EditFileCount ;
int toolbar_cmdline_width ;
int toolbar_combobox_width ;
int bandWidths [8] ;
int message_output_x = -1 ;
char *message_buffer [MAX_MESSAGE] ;
char **first_message ;
char **next_message ;
char **last_message ;
char str_buffer [2048] ;
char message_font_name [256] ;
char listbox_font_name [] = "Lucida Console" ;
char line_buffer [2048] ;
char *EditFiles [MAX_EDIT_FILES] ;
bool mem_warned ;
unsigned message_font_size ;
unsigned message_font_weight ;
unsigned listbox_font_size = 8 ;
unsigned listbox_font_weight = FW_NORMAL ;
unsigned editor_line_number ;
unsigned editor_char_pos ;
unsigned editor_offset ;
unsigned seek_entry_count ;
RECT current_rect ;
bool keep_messages ;
HFONT message_font ;
HFONT listbox_font ;
HFONT tab_font ;
char sbToolText[512];
TOOLINFO sbToolInfo;
seekStruct seek_entries [MAX_SEEK_INDEX] ;
HIMAGELIST ToolImages1 ;
HIMAGELIST ToolImages2 ;
extern int statistics_count ;
extern int delay_next_status ;
extern int seconds_for_last_line ;
extern char tool_help [MAX_TOOLCMD] [MAX_TOOLHELPTEXT] ;
extern char requested_render_file [] ;
extern char source_file_name [] ;
extern char NetworkAddress [] ;
extern char PovStatusPanelWinClass [] ;
extern char *EditDLLPath ;
extern bool ListenMode ;
extern bool ControlMode ;
extern void *CurrentEditor ;
extern time_t quit ;
extern unsigned background_width ;
extern unsigned background_height ;
extern unsigned window_count ;
extern unsigned statusheight ;
extern unsigned screen_depth ;
extern unsigned render_width ;
extern unsigned ThreadCount ;
extern HWND main_window ;
extern HWND message_window ;
extern HWND hToolComboBox ;
extern HWND window_list [MAX_WINDOWS] ;
extern HWND toolbar_combobox ;
extern HWND aux_toolbar_window ;
extern HWND statuspanel ;
extern HWND StatusWindow ;
extern HWND StatusTooltip ;
extern HWND toolbar_cmdline ;
extern bool IsWin32 ;
extern bool fast_scroll ;
extern bool tile_background ;
extern bool IsW95UserInterface ;
extern bool use_toolbar ;
extern bool resizing ;
extern bool exit_after_render ;
extern bool demo_mode ;
extern bool debugging ;
extern bool render_requested ;
extern bool noexec ;
extern bool NoRestore ;
extern bool rendering ;
extern bool run_renderer ;
extern bool rendering_animation ;
extern bool no_status_output ;
extern bool stop_rendering ;
extern bool benchmark_mode;
extern HBITMAP hBmpBackground ;
extern HBITMAP hBmpRendering ;
extern COLORREF background_colour ;
extern COLORREF background_shade ;
extern COLORREF text_colours[3] ;
extern HPALETTE hPalApp ;
extern CRITICAL_SECTION critical_section ;
int toolbar_ids [] = {
CM_FILENEW,
CM_FILEOPEN,
CM_FILESAVE,
CM_FILEQUEUE,
CM_RENDERSHOW,
CM_COMMANDLINE,
CM_SOURCEFILE,
CM_FILERENDER,
CM_RENDERSLEEP | 0x8000,
} ;
#define MAX_TOOLS (sizeof (toolbar_ids) / sizeof (int))
toolbarStruct maintools [] =
{
{CM_FILENEW, BMP_TOOLFILENEW, 0x00, "New"},
{CM_FILEOPEN, BMP_TOOLFILEOPEN, 0x00, "Open"},
{CM_FILESAVE, BMP_TOOLFILESAVE, 0x00, "Save"},
{CM_FILECLOSE, BMP_TOOLFILECLOSE, 0x00, "Close"},
{CM_FILEQUEUE, BMP_TOOLFILEQUEUE, 0x00, "Queue"},
{CM_RENDERSHOW, BMP_TOOLRENDERSHOW, 0x00, "Show"},
{CM_RENDERCLOSE, BMP_TOOLRENDERCLOSE, 0x02, "Hide"},
{CM_COMMANDLINE, BMP_TOOLCMDLINE, 0x00, "Ini"},
{CM_SOURCEFILE, BMP_TOOLSOURCEFILE, 0x00, "Sel-Run"},
{CM_FILERENDER, BMP_TOOLFILERENDER, 0x00, "Run"},
{CM_STOPRENDER, BMP_TOOLSTOPRENDER, 0x02, "Stop"},
{CM_RENDERSLEEP, BMP_TOOLSLEEP, 0x01, "Pause"},
{CM_SHOWMAINWINDOW,BMP_TOOLSYSTRAY, 0x00, "Tray"},
{0, 0, 0x00, NULL}
} ;
#define MAX_MAIN_TOOLS (sizeof (maintools) / sizeof (toolbarStruct) - 1)
toolbarStruct auxtools [] =
{
{CM_HELPPOVWIN, BMP_TOOLHELPCONT, 0x00, "POV-Win"},
{CM_HELPSCENE, BMP_TOOLHELPPOVRAY, 0x00, "Scene"},
{CM_GOPOVRAYORG, BMP_TOOLGOPOVRAY, 0x00, "POV Site"},
{0, 0, 0x00, NULL}
} ;
#define MAX_AUX_TOOLS (sizeof (auxtools) / sizeof (toolbarStruct) - 1)
bool is_horz_line (char *s)
{
if (strlen (s) < 70)
return (false) ;
while (*s)
if (*s++ != '-')
return (false) ;
return (true) ;
}
const char *buffer_str (const char *s, lftype *lf)
{
char *ptr ;
if (s == NULL)
{
message_output_x = -1 ;
return (NULL) ;
}
*lf = None ;
if (message_output_x == -1)
{
message_output_x = 0 ;
memset (str_buffer, 0, sizeof (str_buffer)) ;
}
ptr = str_buffer + message_output_x ;
while (*s)
{
switch (*s)
{
case '\r' : message_output_x = 0 ;
ptr = str_buffer ;
*lf = CR ;
break ;
case '\n' : message_output_x = -1 ;
*lf = LF ;
return (++s) ;
case '\f' : if (message_output_x != -1)
{
message_output_x = -1 ;
*lf = LF ;
return (++s) ;
}
s++ ;
break ;
case '\b' : if (message_output_x > 0)
{
--message_output_x ;
*--ptr = '\0' ;
}
break ;
default : if (isprint (*s) && message_output_x < sizeof (str_buffer) - 1)
{
message_output_x++ ;
*ptr++ = *s ;
}
break ;
}
s++ ;
}
return (s) ;
}
int update_message_display (lftype lf)
{
RECT rect ;
if (message_window == NULL)
return (0) ;
GetClientRect (message_window, &rect) ;
message_cols = rect.right / message_xchar ;
message_rows = rect.bottom / message_ychar ;
if (lf == None || lf == LF)
{
EnterCriticalSection (&critical_section) ;
top_message_row = message_count > message_rows ? message_count - message_rows : 0 ;
LeaveCriticalSection (&critical_section) ;
SetScrollRange (message_window, SB_HORZ, 0, need_hscroll (), false) ;
SetScrollPos (message_window, SB_HORZ, message_scroll_pos_x, true) ;
SetScrollRange (message_window, SB_VERT, 0, top_message_row, false) ;
SetScrollPos (message_window, SB_VERT, message_scroll_pos_y, true) ;
}
if (lf == None)
return (message_rows) ;
if (lf == LF)
{
EnterCriticalSection (&critical_section) ;
// is there room for another row ?
if (current_rect.bottom + message_ychar <= rect.bottom)
{
// yes there is
current_rect.top += message_ychar ;
current_rect.bottom += message_ychar ;
}
else
ScrollWindow (message_window, 0, -message_ychar, NULL, &rect) ;
message_scroll_pos_y = top_message_row ;
SetScrollPos (message_window, SB_VERT, message_scroll_pos_y, true) ;
LeaveCriticalSection (&critical_section) ;
}
PovInvalidateRect (message_window, ¤t_rect, true) ;
if (!fast_scroll && !rendering_animation && IsWindowVisible (message_window))
UpdateWindow (message_window) ;
return (message_rows) ;
}
void buffer_message (msgtype message_type, const char *s, bool addLF)
{
char *s1 ;
lftype lf ;
ExternalBufferMessage (message_type, (LPSTR) s) ;
EnterCriticalSection (&critical_section) ;
while (*s)
{
s1 = (char *)s ;
s = buffer_str (s, &lf) ;
if (lf == None)
continue ;
if ((s1 = (char *) malloc (strlen (str_buffer) + 2)) == NULL)
{
LeaveCriticalSection (&critical_section) ;
if (rendering)
{
if (!mem_warned)
PovMessageBox ("Failed to allocate memory for message string", "Fatal Error") ;
stop_rendering = true ;
}
else
if (!mem_warned)
PovMessageBox ("Failed to allocate memory for message string", "Error") ;
mem_warned = true ;
return ;
}
if (is_horz_line (str_buffer))
message_type = mHorzLine ;
strcpy (s1 + 1, str_buffer) ;
*s1 = (unsigned char) message_type ;
if (lf == CR)
{
if (*last_message)
free (*last_message) ;
*last_message = s1 ;
LeaveCriticalSection (&critical_section) ;
update_message_display (CR) ;
EnterCriticalSection (&critical_section) ;
}
else
{
if (*next_message)
{
free (*next_message) ;
*next_message = NULL ;
if (++first_message == message_buffer + MAX_MESSAGE)
first_message = message_buffer ;
}
else
message_count++ ;
*next_message = s1 ;
last_message = next_message ;
if (++next_message == message_buffer + MAX_MESSAGE)
next_message = message_buffer ;
LeaveCriticalSection (&critical_section) ;
update_message_display (LF) ;
EnterCriticalSection (&critical_section) ;
}
}
if (addLF)
buffer_message (message_type, "\n", false) ;
LeaveCriticalSection (&critical_section) ;
}
void add_single_line (msgtype message_type, const char *str)
{
char *s1 ;
RECT rect ;
if (message_type == mWarning && strncmp (str, "File: ", 6) == 0)
add_single_line (mDivider, "") ;
if (message_type == mStatistics)
if (strcmp (str, "Scene Statistics") == 0 || strcmp (str, "Render Statistics") == 0)
add_single_line (mDivider, "") ;
if (strncmp (str, "---------------", 15) == 0)
{
str = "" ;
message_type = mDivider ;
}
if (message_type == mDivider || message_type == mHorzLine)
if (last_message != NULL && (**last_message == mDivider || **last_message == mHorzLine))
return ;
if ((s1 = (char *) malloc (strlen (str) + 2)) == NULL)
{
if (rendering)
{
if (!mem_warned)
PovMessageBox ("Failed to allocate memory for message string", "Fatal Error") ;
stop_rendering = true ;
}
else
if (!mem_warned)
PovMessageBox ("Failed to allocate memory for message string", "Error") ;
mem_warned = true ;
return ;
}
strcpy (s1 + 1, str) ;
*s1 = (unsigned char) message_type ;
if (*next_message)
{
free (*next_message) ;
*next_message = NULL ;
if (++first_message == message_buffer + MAX_MESSAGE)
first_message = message_buffer ;
}
else
message_count++ ;
*next_message = s1 ;
last_message = next_message ;
if (++next_message == message_buffer + MAX_MESSAGE)
next_message = message_buffer ;
GetClientRect (message_window, &rect) ;
message_cols = rect.right / message_xchar ;
message_rows = rect.bottom / message_ychar ;
top_message_row = message_count > message_rows ? message_count - message_rows : 0 ;
SetScrollRange (message_window, SB_HORZ, 0, need_hscroll (), false) ;
SetScrollPos (message_window, SB_HORZ, message_scroll_pos_x, true) ;
SetScrollRange (message_window, SB_VERT, 0, top_message_row, false) ;
SetScrollPos (message_window, SB_VERT, message_scroll_pos_y, true) ;
// is there room for another row ?
if (current_rect.bottom + message_ychar <= rect.bottom)
{
// yes there is
current_rect.top += message_ychar ;
current_rect.bottom += message_ychar ;
}
else
ScrollWindow (message_window, 0, -message_ychar, NULL, &rect) ;
message_scroll_pos_y = top_message_row ;
SetScrollPos (message_window, SB_VERT, message_scroll_pos_y, true) ;
PovInvalidateRect (message_window, ¤t_rect, true) ;
if (!fast_scroll && !rendering_animation && IsWindowVisible (message_window))
UpdateWindow (message_window) ;
}
void wrap_message (const char *str, int width, msgtype message_type)
{
int col = 1 ;
char buffer [2048] ;
char *bp = buffer ;
char *ws_b = NULL ;
const char *wd_b = NULL ;
const char *s = str ;
if (width < 80)
width = 80 ;
while (*s)
{
if (*s == '\r' || *s == '\n')
{
while (*s == '\r' && (s [1] == '\r' || s [1] == '\n'))
s++ ;
*bp = '\0' ;
add_single_line (message_type, buffer) ;
ws_b = NULL ;
wd_b = NULL ;
bp = buffer ;
col = 1 ;
s++ ;
continue ;
}
col++ ;
if (*s == ' ' || *s == '\t')
{
if (ws_b == NULL || ws_b < wd_b)
ws_b = bp ;
wd_b = NULL ;
*bp++ = *s++ ;
continue ;
}
if (wd_b == NULL)
wd_b = bp ;
*bp++ = *s++ ;
if (col > width && ws_b != NULL)
{
*ws_b = '\0' ;
add_single_line (message_type, buffer) ;
if (wd_b)
{
col = bp - wd_b ;
memcpy (buffer, wd_b, col) ;
bp = buffer + col ;
wd_b = buffer ;
ws_b = NULL ;
}
else
{
col = 1 ;
bp = buffer ;
ws_b = NULL ;
wd_b = NULL ;
while (*s == ' ' || *s == '\t')
s++ ;
}
}
}
if (ws_b != NULL && wd_b == NULL)
bp = ws_b ;
*bp = '\0' ;
add_single_line (message_type, buffer) ;
}
void buffer_stream_message (msgtype message_type, const char *s)
{
RECT rect ;
if (message_type == mUnknown)
{
if (strncmp (s, "File: ", 6) == 0)
message_type = mWarning;
else if (strncmp (s, "Shutdown", 8) == 0)
message_type = mWarning;
}
// since the POVMS streams don't try fancy stuff with CR's and backspaces
// we can simplify the above code (and also handle wordwrap). all data
// data passed to us is implicitly terminated by an LF. embedded LF's are
// permitted and a terminating LF implies two LF's (due to above).
ExternalBufferMessage (message_type, (LPSTR) s) ;
ExternalBufferMessage (message_type, "\n") ;
GetClientRect (message_window, &rect) ;
message_cols = rect.right / message_xchar ;
EnterCriticalSection (&critical_section) ;
// we don't want to wrap debug text - we assume the scene author wants to control this.
wrap_message (s, message_type == mDebug ? 9999 : message_cols - 2, message_type) ;
LeaveCriticalSection (&critical_section) ;
}
void message_printf (const char *format, ...)
{
char str [2048] ;
char *s ;
time_t t ;
va_list arg_ptr ;
if (strlen (format) > sizeof (str) - 256)
return ;
if (debugging)
{
time (&t) ;
s = ctime (&t) ;
memcpy (str, s + 11, 9) ;
va_start (arg_ptr, format) ;
vsprintf (str + 9, format, arg_ptr) ;
va_end (arg_ptr) ;
OutputDebugString (str) ;
}
va_start (arg_ptr, format) ;
vsprintf (str, format, arg_ptr) ;
va_end (arg_ptr) ;
buffer_message (mIDE, str) ;
}
void wrapped_printf (const char *format, ...)
{
char str [2048] ;
char *s ;
time_t t ;
va_list arg_ptr ;
if (strlen (format) > sizeof (str) - 256)
return ;
if (debugging)
{
time (&t) ;
s = ctime (&t) ;
memcpy (str, s + 11, 9) ;
va_start (arg_ptr, format) ;
vsprintf (str + 9, format, arg_ptr) ;
va_end (arg_ptr) ;
OutputDebugString (str) ;
}
va_start (arg_ptr, format) ;
vsprintf (str, format, arg_ptr) ;
va_end (arg_ptr) ;
s = str + strlen (str) - 1 ;
if (*s == '\n')
*s = '\0' ;
buffer_stream_message (mIDE, str) ;
}
void status_printf (int nSection, const char *format, ...)
{
char str [2048] ;
va_list arg_ptr ;
va_start (arg_ptr, format) ;
vsprintf (str, format, arg_ptr) ;
va_end (arg_ptr) ;
say_status_message (nSection, str) ;
}
char *clean_str (const char *s)
{
char *s1 ;
static char str [512] ;
if (strlen (s) > 511)
return ("Internal error : string too long in clean_str") ;
EnterCriticalSection (&critical_section) ;
for (s1 = str ; *s ; s++)
if (*s >= ' ')
*s1++ = *s ;
*s1 = '\0' ;
LeaveCriticalSection (&critical_section) ;
return (str) ;
}
void erase_display_window (HDC hdc, int xoffset, int yoffset)
{
int x, y ;
HDC hdcMemory ;
RECT rect ;
HBRUSH hbr ;
HBITMAP oldBmp ;
if (message_window == NULL)
return ;
GetClientRect (message_window, &rect) ;
if (tile_background)
{
hdcMemory = CreateCompatibleDC (hdc) ;
oldBmp = (HBITMAP) SelectObject (hdcMemory, hBmpBackground) ;
xoffset %= background_width ;
yoffset %= background_height ;
for (y = -yoffset ; y < rect.bottom ; y += background_height)
for (x = -xoffset ; x < rect.right ; x += background_width)
BitBlt (hdc, x, y, background_width, background_height, hdcMemory, 0, 0, SRCCOPY) ;
SelectObject (hdcMemory, oldBmp) ;
DeleteDC (hdcMemory) ;
}
else
{
hbr = CreateSolidBrush (background_colour) ;
FillRect (hdc, &rect, hbr) ;
DeleteObject (hbr) ;
}
}
void paint_display_window (HDC hdc)
{
int x, y ;
int message_number ;
int oldMode ;
int dividerStep ;
int xoffset ;
int yoffset ;
char **message = first_message ;
bool erased = false ;
RECT rect ;
HPEN hpen1 ;
HPEN hpen2 ;
HPEN hpenOld ;
HFONT oldFont ;
COLORREF oldColour ;
COLORREF oldBkColour ;
unsigned char lastType = 255;
static RECT oldRect ;
EnterCriticalSection (&critical_section) ;
GetClientRect (message_window, &rect) ;
current_rect.left = 0 ;
current_rect.right = rect.right ;
current_rect.top = -message_ychar ;
current_rect.bottom = 0 ;
xoffset = (unsigned) message_scroll_pos_x * message_xchar ;
yoffset = (unsigned) (first_message - message_buffer) * message_ychar ;
if (*message == NULL || resizing || (EditGetFlags () & EDIT_DRAG_ACTIVE) != 0)
{
erase_display_window (hdc, xoffset, yoffset) ;
LeaveCriticalSection (&critical_section) ;
oldRect = rect ;
return ;
}
oldRect = rect ;
if (tile_background)
{
hpen1 = CreatePen (PS_SOLID, 1, RGB (192,192,192)) ;
hpen2 = CreatePen (PS_SOLID, 1, RGB (64,64,64)) ;
}
else
{
int red = background_colour & 0xff;
int green = (background_colour >> 8) & 0xff;
int blue = (background_colour >> 16) & 0xff;
hpen1 = CreatePen (PS_SOLID, 1, text_colours[0]) ;
hpen2 = CreatePen (PS_SOLID, 1, RGB(red / 2, green / 2, blue / 2)) ;
}
hpenOld = (HPEN) SelectObject (hdc, hpen2) ;
oldFont = (HFONT) SelectObject (hdc, message_font) ;
oldMode = SetBkMode (hdc, TRANSPARENT) ;
oldColour = SetTextColor (hdc, text_colours[0]) ;
oldBkColour = SetBkColor (hdc, background_shade) ;
x = message_scroll_pos_x * -message_xchar + message_xchar ;
for (message_number = y = 0 ; y < rect.bottom ; message_number++)
{
if (*message == NULL)
break ;
if (message_number >= message_scroll_pos_y)
{
if (!erased)
{
erase_display_window (hdc, xoffset, yoffset) ;
erased = true ;
}
if (**message != lastType)
{
lastType = **message;
switch (**message)
{
case mDebug:
case mWarning:
SetTextColor (hdc, text_colours[1]);
break;
case mFatal:
SetTextColor (hdc, text_colours[2]);
break;
default:
SetTextColor (hdc, text_colours[0]);
break;
}
}
current_rect.top += message_ychar ;
current_rect.bottom += message_ychar ;
if (**message == mDivider || **message == mHorzLine)
{
if (background_shade != RGB (1, 1, 1) && tile_background)
DRAWFASTRECT (hdc, ¤t_rect) ;
SelectObject (hdc, hpen2) ;
if (tile_background)
{
dividerStep = message_ychar / 3;
MoveToEx (hdc, current_rect.left + message_xchar, y + message_ychar - dividerStep, NULL) ;
LineTo (hdc, current_rect.left + message_xchar, y + dividerStep) ;
LineTo (hdc, current_rect.right - message_xchar, y + dividerStep) ;
SelectObject (hdc, hpen1) ;
LineTo (hdc, current_rect.right - message_xchar, y + message_ychar - dividerStep) ;
LineTo (hdc, current_rect.left + message_xchar, y + message_ychar - dividerStep) ;
}
else
{
MoveToEx (hdc, current_rect.left + message_xchar, y + message_ychar / 2, NULL) ;
LineTo (hdc, current_rect.right - message_xchar, y + message_ychar / 2) ;
SelectObject (hdc, hpen1) ;
MoveToEx (hdc, current_rect.left + message_xchar, y + message_ychar / 2 + 1, NULL) ;
LineTo (hdc, current_rect.right - message_xchar, y + message_ychar / 2 + 1) ;
}
}
else
ExtTextOut (hdc, x, y, ETO_CLIPPED, ¤t_rect, *message + 1, (int) strlen (*message + 1), NULL) ;
y += message_ychar ;
}
if (message == last_message)
break ;
if (++message == message_buffer + MAX_MESSAGE)
message = message_buffer ;
yoffset += message_ychar ;
}
if (!erased)
erase_display_window (hdc, xoffset, yoffset) ;
SetTextColor (hdc, oldColour) ;
SetBkColor (hdc, oldBkColour) ;
SetBkMode (hdc, oldMode) ;
SelectObject (hdc, oldFont) ;
SelectObject (hdc, hpenOld) ;
DeleteObject (hpen1) ;
DeleteObject (hpen2) ;
LeaveCriticalSection (&critical_section) ;
}
void get_logfont (HDC hdc, LOGFONT *lf)
{
memset (lf, 0, sizeof (LOGFONT)) ;
lf->lfHeight = -MulDiv (message_font_size, GetDeviceCaps (hdc, LOGPIXELSY), 72) ;
lf->lfWeight = message_font_weight ;
lf->lfPitchAndFamily = FIXED_PITCH | FF_MODERN ;
lf->lfCharSet = DEFAULT_CHARSET ;
lf->lfQuality = PROOF_QUALITY ;
strncpy (lf->lfFaceName, message_font_name, sizeof (lf->lfFaceName) - 1) ;
}
void get_lblogfont (HDC hdc, LOGFONT *lf)
{
memset (lf, 0, sizeof (LOGFONT)) ;
lf->lfHeight = -MulDiv (listbox_font_size, GetDeviceCaps (hdc, LOGPIXELSY), 72) ;
lf->lfWeight = listbox_font_weight ;
lf->lfPitchAndFamily = FIXED_PITCH | FF_MODERN ;
lf->lfCharSet = DEFAULT_CHARSET ;
lf->lfQuality = PROOF_QUALITY ;
strncpy (lf->lfFaceName, listbox_font_name, sizeof (lf->lfFaceName) - 1) ;
}
int create_message_font (HDC hdc, LOGFONT *lf)
{
HFONT hfontOld ;
TEXTMETRIC tm ;
if ((message_font = CreateFontIndirect (lf)) == NULL)
return (1) ;
hfontOld = (HFONT) SelectObject (hdc, message_font) ;
GetTextMetrics (hdc, &tm) ;
message_xchar = tm.tmAveCharWidth ;
message_ychar = tm.tmHeight + tm.tmExternalLeading ;
SelectObject (hdc, hfontOld) ;
return (0) ;
}
int create_listbox_font (HDC hdc, LOGFONT *lf)
{
HFONT hfontOld ;
TEXTMETRIC tm ;
if ((listbox_font = CreateFontIndirect (lf)) == NULL)
return (1) ;
hfontOld = (HFONT)SelectObject (hdc, listbox_font) ;
GetTextMetrics (hdc, &tm) ;
listbox_xchar = tm.tmAveCharWidth ;
listbox_ychar = tm.tmHeight + tm.tmExternalLeading ;
SelectObject (hdc, hfontOld) ;
return (0) ;
}
int initialise_message_display (void)
{
HDC hdc ;
LOGFONT lf ;
if (message_window == NULL)
{
PovMessageBox ("Message Window does not exist", "Initialize Message Display - Fatal Error") ;
return (1) ;
}
hdc = GetDC (message_window) ;
get_logfont (hdc, &lf) ;
if (create_message_font (hdc, &lf) != 0)
{
PovMessageBox ("Failed to create message font", "Initialize Message Display - Fatal Error") ;
ReleaseDC (message_window, hdc) ;
return (1) ;
}
get_lblogfont (hdc, &lf) ;
if (create_listbox_font (hdc, &lf) != 0)
{
strcpy (lf.lfFaceName, "Courier New") ;
if (create_listbox_font (hdc, &lf) != 0)
PovMessageBox ("Failed to create listbox font", "Initialize Message Display") ;
}
first_message = next_message = message_buffer ;
last_message = NULL ;
buffer_str (NULL, NULL) ;
top_message_row = message_count = message_scroll_pos_x = message_scroll_pos_y = 0 ;
current_rect.left = current_rect.bottom = current_rect.right = 0 ;
current_rect.top = -message_ychar ;
ReleaseDC (message_window, hdc) ;
return (0) ;
}
void clear_messages (bool print)
{
int i ;
char **p ;
EnterCriticalSection (&critical_section) ;
buffer_str (NULL, NULL) ;
// free any buffered lines still around from a previous run of the renderer
for (p = message_buffer, i = 0 ; i < MAX_MESSAGE ; p++, i++)
{
if (*p)
free (*p) ;
*p = NULL ;
}
first_message = next_message = message_buffer ;
last_message = NULL ;
top_message_row = message_count = message_scroll_pos_x = message_scroll_pos_y = 0 ;
current_rect.left = current_rect.bottom = current_rect.right = 0 ;
current_rect.top = -message_ychar ;
LeaveCriticalSection (&critical_section) ;
if (print)
message_printf ("Messages cleared.\n") ;
}
int need_hscroll (void)
{
int x ;
int xchars ;
int width = 0 ;
char **message = first_message ;
RECT rect ;
/* modified to return the scroll range if ANY line is long enough */
if (message_window == NULL || *message == NULL)
return (0) ;
GetClientRect (message_window, &rect) ;
xchars = rect.right / message_xchar - 1 ;
while (*message)
{
x = (int) strlen (*message + 1) ;
if (x >= xchars)
if (x - xchars > width)
width = x - xchars ;
if (message == next_message)
break ;
if (++message == message_buffer + MAX_MESSAGE)
message = message_buffer ;
}
return (width) ;
}
bool copy_text_to_clipboard(const char *text)
{
char *s ;
HGLOBAL hText ;
if (!OpenClipboard(NULL))
return false;
if ((hText = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, strlen(text) + 1)) == NULL)
return false;
if ((s = (char *) GlobalLock (hText)) == NULL)
{
GlobalFree(hText);
return false;
}
strcpy(s, text);
GlobalUnlock(hText);
EmptyClipboard() ;
bool result = SetClipboardData(CF_TEXT, hText) != NULL;
CloseClipboard() ;
return result;
}
void dump_pane_to_clipboard (void)
{
int y ;
int message_number ;
int length = 0 ;
char **message = first_message ;
char *s ;
RECT rect ;
HGLOBAL hText ;
static char *_s ;
if (message_window == NULL || *message == NULL)
return ;
if (OpenClipboard (message_window) == false)
{
PovMessageBox ("Could not open clipboard", "Error") ;
return ;
}