-
Notifications
You must be signed in to change notification settings - Fork 3
/
EditProj.pas
2085 lines (1890 loc) · 67.1 KB
/
EditProj.pas
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
unit EditProj;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Printers, StdCtrls, ComCtrls, ExtCtrls, ImgList, ToolWin, SBZipUtils, SBFiles, RichEdit, JPEG,
IdBaseComponent, IdComponent, WindowlessRTF;
type
PTImage = ^TImage;
TFEditProj = class(TForm)
RESong: TRichEdit;
Cop1: TLabel;
Cop2: TLabel;
EBlind: TEdit;
EBlind2: TEdit;
LLicense: TLabel;
ImgOnscreen: TImage;
LHelp: TLabel;
ImgBackground: TImage;
ImgBlank: TImage;
procedure FormShow(Sender: TObject);
procedure ActualFormShow(Sender: TObject; from_webserver : boolean);
procedure RESongSelectionChange(Sender: TObject);
procedure InitFiles(Sender : TObject; from_webserver : boolean);
function StringSC(A,B : word) : string;
procedure SaveOHP;
Procedure SaveAtts;
Procedure RestAtts;
procedure EBlindKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure EBlindExit(Sender: TObject);
procedure ZipMeUp;
procedure FormCreate(Sender: TObject);
procedure ShowLabels(x,y:integer; bRight:boolean = false);
procedure UpdateLabels(i : integer);
procedure HideLabels;
procedure EBlind2Exit(Sender: TObject);
procedure EBlind2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure LoadOHPData(FS : string);
procedure MarkOHP(cID : string);
function NextShortCut : integer;
function ShortCutInUse(i : integer) : boolean;
procedure LoadCopyRight(cid : string);
procedure SetGlobals;
function SearchRTF(S : string; cID : string) : boolean;
procedure FindRTFText(Ss : string);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SetEditWidth;
procedure EBlindKeyPress(Sender: TObject; var Key: Char);
procedure EBlind2KeyPress(Sender: TObject; var Key: Char);
procedure FormDestroy(Sender: TObject);
procedure ShowTheSong(id : string);
procedure RESongEdited(Sender: TObject);
procedure UpdateDisplay;
procedure RightAlignCaptions;
procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);
procedure FormPaint(Sender: TObject);
// procedure FormResize(Sender: TObject);
procedure SelectPage( iSong : string; iPage : integer; from_webserver : boolean);
procedure ShowSelectLabels( iOffset : integer = 0 );
private
{ Private declarations }
bReady : boolean;
bHasImgBackground : boolean;
//bHasBlankPic : boolean;
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
// procedure DrawIt( hTextImg, hBackImg, hOutImg : TImage );
public
bForceRedraw : boolean;
bDrawable : boolean;
bHighQuality : boolean;
bScaleProjection : boolean;
bShowHighlight : boolean;
GHighlight : string;
GID : string; { Public declarations }
GTitle : string;
GCopy1 : string;
GCopy2 : string;
EditGID : string; { If we wish to Edit rather than view a song }
LastID : string; { Remember last displayed song for recall }
LastPage : integer; { Remember last displayed page for recall }
AutoUpdateOHP : boolean;
Pages : integer;
ShowPage : integer;
Pics : array of string;
SearchNo,CurrentPage : integer;
bSetOffsets : boolean;
CurrentDisplayArea : TRect;
LastPic : string;
CurrentSong : string;
ImgOffscreen : TImage;
ImgScaler: TImage;
WindowBackground : TColor;
{}
OrigData : string;
TitleList : TStringlist;
{}
BlindMode : byte;
bHasTools : boolean;
Scs : ShortcutArray;
SaveB,SaveI,SaveU : boolean;
SaveCol : TColor;
ResultVal,SaveSize,SaveFont : Integer;
PageLabs : array[1..99] of TLabel;
SaveJ : byte;
SearchID,SearchString : string;
SearchResults : TStringList;
Blanked : boolean;
ShowImage : boolean;
ShowPageLabels : boolean;
BlankImgFile : string;
{}
FRTF : TWindowlessRTF;
{}
procedure PrepareWindow;
procedure BlankWindow(var bUnhandled : boolean; from_webserver : boolean);
function IsDefaultOrdering( iExclude : integer = 0 ) : boolean;
procedure ShowHighlight( bShow : boolean );
procedure SelectSong( SongID : string; bNoInitial : boolean; from_webserver : boolean);
// procedure ReorderShortcuts(i : integer);
end;
const ITEM_IDX_AS_PROJECTED = 0;
ITEM_IDX_FULL_SCREEN = 1;
ITEM_IDX_640_480 = 2;
ITEM_IDX_800_600 = 3;
ITEM_IDX_1024_768 = 4;
ITEM_IDX_1152_864 = 5;
ITEM_IDX_1280_1024 = 6;
var
FProjWin: TFEditProj;
FEditWin: TFEditProj;
SModeExit, SModeSearchWords, SModeSearchTitle : string;
SModeSearchResultCount, SModeSearchResultIdx : string;
SModeSelect, SModeSearchResultNone, SModeShortcut : string;
hLastKeyTime : TDateTime;
hLastKeyValue : word;
const NOT_DISPLAYING = 255;
const SELECTING_SONG = 0;
const SHOWING_SONG = 1;
const FINDING_TITLE = 2;
const SEARCHING_TEXT = 3;
const CHOOSING_RESULT = 4;
const QUITTING = 5;
const chr128 = chr(128);
const TEXT_OFFSET = 5;
const VK_B = ord('B');
const VK_ONE = ord('1');
implementation
uses Appear, Math, SBMain, OHPPrint, Tools, PreviewWindow, PageCache, ActiveX, DateUtils,
WebServer, NetSetup;
{$R *.DFM}
function PrintToCanvas(ACanvas : TCanvas; FromChar, ToChar : integer;
ARichEdit : TRichEdit; AWidth, AHeight : integer) : Longint;
var
Range : TFormatRange;
begin
FillChar(Range, SizeOf(TFormatRange), 0);
Range.hdc := ACanvas.handle;
Range.hdcTarget := ACanvas.Handle;
Range.rc.left := 0;
Range.rc.top := 0;
Range.rc.right := AWidth * 1440 div Screen.PixelsPerInch; // ?
Range.rc.Bottom := AHeight * 1440 div Screen.PixelsPerInch;
Range.chrg.cpMax := ToChar;
Range.chrg.cpMin := FromChar;
Result := SendMessage(ARichedit.Handle, EM_FORMATRANGE, 1, Longint(@Range));
SendMessage(ARichEdit.handle, EM_FORMATRANGE, 0,0);
end;
procedure TFEditProj.ShowLabels(x,y : integer; bRight: boolean = false );
const cols : array[0..7] of TColor =(clWhite,clAqua,clFuchsia,clLime,clOlive,clPurple,clTeal,clMaroon);
var i, w, xOrigin, xLast : integer;
hFontStyle : TFontInfo;
uiStyle : TFontStyles;
begin
xLast := 0;
if bRight then hFontStyle := FSettings.CopyrightFont
else hFontStyle := FSettings.CCLIFont;
w := 0;
uiStyle := [];
if hFontStyle.ForceBold and hFontStyle.Bold then include( uiStyle, fsBold );
if hFontStyle.ForceItalic and hFontStyle.Italic then include( uiStyle, fsItalic );
if FSongbase.bProjectHints then begin
if not bRight then xOrigin := x else xOrigin := 0;
for i:=1 to Pages do begin
Pagelabs[i].Caption:=chr(SCS[i*2]);
if hFontStyle.ForceName then Pagelabs[i].Font.Name := hFontStyle.Name
else Pagelabs[i].Font.Name := FSettings.DefaultSmallFont.Name;
if hFontStyle.ForceSize then Pagelabs[i].Font.Size := hFontStyle.Size
else Pagelabs[i].Font.Size := FSettings.DefaultSmallFont.Size;
Pagelabs[i].Font.Style := uiStyle;
if hFontStyle.ForceColor then Pagelabs[i].Font.Color := hFontStyle.Color
else Pagelabs[i].Font.Color:=Cols[SCS[(i*2)-1]];
if bScaleProjection then
Pagelabs[i].Font.Size := (Pagelabs[i].Font.Size * Height) div FSettings.szProjectScale.cy;
if 0 = w then w := Pagelabs[i].Width;
Pagelabs[i].Left:=xOrigin + (i-1)*((4*w) div 3);
xLast := Pagelabs[i].Left + Pagelabs[i].Width;
PageLabs[i].TransParent:=true;
Pagelabs[i].Top:=y;
PageLabs[i].Parent:=FProjWin;
end;
for i:=Pages+1 to 99 do begin
PageLabs[i].Visible:=false;
PageLabs[i].Enabled:=false;
PageLabs[i].Parent:=FProjWin;
end;
for i:=1 to Pages do begin
if bRight then begin
Pagelabs[i].Left := x - (xLast - Pagelabs[i].Left);
end;
PageLabs[i].Visible:=true; PageLabs[i].Enabled:=true;
end;
end;
ShowPageLabels := (Pages>0);
end;
procedure TFEditProj.UpdateLabels(i : integer);
var j : integer;
begin
if (not FWebServer.isServerEnabled) then begin
if FSongbase.bProjectHints then begin
for j:=1 to Pages do begin
if (PageLabs[j]<>nil) then begin
PageLabs[j].Enabled:=false;
Pagelabs[j].Visible:=false;
if (j=i) then
Pagelabs[j].Font.Style:=[fsBold]
else Pagelabs[j].Font.Style:=[];
PageLabs[j].Enabled:=true;
end;
end;
end;
end;
ShowPageLabels := (Pages>0);
end;
procedure TFEditProj.Hidelabels;
var i : integer;
begin
for i:=1 to 99 do PageLabs[i].Visible:=false;
ShowPageLabels := false;
end;
procedure TFEditProj.FindRTFText(Ss : string);
var i : integer;
SearchIDs : TStringList;
begin
SearchResults.Clear;
SearchIDs := TStringList.Create;
PageCache_TextSearch( Ss, SearchIDs, High(integer), false, true );
for i := 0 to SearchIDs.Count-1 do begin
SearchResults.Add( PageCache_GetSongName( SearchIDs[i] ) );
end;
end;
function TFEditProj.SearchRTF(S : string; cID : string) : boolean;
{var S2 : string;
TF : textfile;
found : boolean;}
begin
SearchRTF := PageCache_TextContains( cID, S );
end;
procedure TFEditProj.SetGlobals;
var displayed : boolean;
i, iDisplayY : integer;
// iDisplayX : integer;
sNextBG : string;
begin
displayed:=false;
RESong.HideSelection:=true;
RESong.SelectAll;
// Is there an individual background graphic for this page?
bHasImgBackground := false;
// If blanked, and there's a blanking image, don't show the BG image
if Blanked and (BlankImgFile <> '') then begin
displayed := true;
end;
if not FTools.Visible then begin
if FSettings.PrimaryFont.ForceName then RESong.SelAttributes.Name:=FSettings.PrimaryFont.Name;
if FSettings.PrimaryFont.ForceSize then RESong.SelAttributes.Size:=FSettings.PrimaryFont.Size;
if FSettings.PrimaryFont.ForceBold then begin
if FSettings.PrimaryFont.Bold
then RESong.SelAttributes.Style:=RESong.SelAttributes.Style+[fsBold]
else RESong.SelAttributes.Style:=RESong.SelAttributes.Style-[fsBold]
end;
if FSettings.PrimaryFont.ForceItalic then begin
if FSettings.PrimaryFont.Italic
then RESong.SelAttributes.Style:=RESong.SelAttributes.Style+[fsItalic]
else RESong.SelAttributes.Style:=RESong.SelAttributes.Style-[fsItalic]
end;
if FSettings.PrimaryFont.ForceColor then RESong.SelAttributes.Color := FSettings.PrimaryFont.Color;
if not displayed
and (CurrentPage>0)
and (length(Pics)>=CurrentPage)
and ( '' <> Pics[CurrentPage-1])
and FileExists(Pics[CurrentPage-1])
and (not FSettings.ImageTick.Checked or
not FSettings.ForceBGImage.Checked) then begin
displayed := true;
if (Pics[CurrentPage-1]<>LastPic) then begin
LastPic:=Pics[CurrentPage-1];
LogThis( 'Custom Background image ' );
LogThis( 'Loading Background image ' + Pics[CurrentPage-1] );
ImgBackground.Picture.LoadFromFile(Pics[CurrentPage-1]);
LogThis( 'Background image loaded' );
end;
bHasImgBackground := true;
end;
end;
// Are we using a background list?
if not displayed and
FSettings.cbBGOrder.Enabled and
(FSettings.cbBGOrder.ItemIndex <> -1) then begin
sNextBG := FSettings.GetNextBackground(LastPic,LastID <> CurrentSong,CurrentPage);
if (sNextBG <> '') and FileExists(sNextBG) then begin
displayed := true;
if sNextBG <> LastPic then begin
LastPic := sNextBG;
LogThis( 'Loading next Background image ''' + sNextBG + '''' );
ImgBackground.Picture.LoadFromFile(sNextBG);
end;
bHasImgBackground := true;
end;
end;
// Deal with backgrounds
if Color <> clBlack then Color := clBlack;
if RESong.Color <> clBlack then RESong.Color := clBlack;
if not FTools.Visible and not displayed then begin
if FSettings.ImageTick.Checked then begin
displayed := true;
if (FSettings.ImageFile<>LastPic) then begin
if FileExists(FSettings.ImageFile) then begin
LastPic := FSettings.ImageFile;
LogThis( 'Loading Background image ' + FSettings.ImageFile + '' );
ImgBackground.Picture.LoadFromFile(FSettings.ImageFile);
LogThis( 'Background image loaded' );
bHasImgBackground := true;
end;
end else begin
bHasImgBackground := true;
end;
end else if (FSettings.BackTick.checked) then begin
RESong.Color := FSettings.PColb.Color;
displayed := true;
// LogThis( 'Background colour set to ' + IntToStr(RichEdit1.Color) );
end;
end;
if not displayed then begin
bHasImgBackground := false;
LastPic := '';
end;
if bHasTools then begin
if displayed and bHasImgBackground then begin
bHasImgBackground := false;
RESong.Color := clBlack;
end;
Color := WindowBackground;
end;
if (FSettings.ELicense.Text<>'') then begin
LLicense.Caption:='CCLI License No. '+FSettings.ELicense.Text;
LLicense.Visible:=true;
LLicense.Enabled:=true;
end else begin
LLicense.Enabled := false;
LLicense.Visible := false;
end;
RESong.selLength:=0;
RESong.HideSelection:=false;
LLicense.Left:= CurrentDisplayArea.Left + FSongbase.rCCLIArea.Left + TEXT_OFFSET;
FSettings.SetLabelFont( Cop1, FSettings.CopyrightFont, FSettings.DefaultSmallFont );
FSettings.SetLabelFont( Cop2, FSettings.CopyrightFont, FSettings.DefaultSmallFont );
FSettings.SetLabelFont( LLicense, FSettings.CCLIFont, FSettings.DefaultSmallFont );
//iDisplayX := CurrentDisplayArea.Right - CurrentDisplayArea.Left;
iDisplayY := CurrentDisplayArea.Bottom - CurrentDisplayArea.Top;
if bScaleProjection then begin
Cop1.Font.Size := (Cop1.Font.Size * iDisplayY) div FSettings.szProjectScale.cy;
Cop2.Font.Size := (Cop2.Font.Size * iDisplayY) div FSettings.szProjectScale.cy;
LLicense.Font.Size := (LLicense.Font.Size * iDisplayY) div FSettings.szProjectScale.cy;
end;
Cop2.Top := FSongbase.rCopyArea.Bottom - TEXT_OFFSET - Cop2.Height;
Cop1.Top := Cop2.Top - Cop1.Height - 2;
LLicense.Top := FSongbase.rCCLIArea.Bottom - TEXT_OFFSET - LLicense.Height;
if (Self = FEditWin) and bScaleProjection then begin
Cop1.Top := (Cop1.Top * iDisplayY) div FSettings.szProjectScale.cy;
Cop2.Top := (Cop2.Top * iDisplayY) div FSettings.szProjectScale.cy;
LLicense.Top := (LLicense.Top * iDisplayY) div FSettings.szProjectScale.cy;
end;
for i:=1 to Pages do begin
Pagelabs[i].Top:=Cop1.Top;
end;
// Hide the labels when we're editing
if FTools.Visible then begin
LLicense.Visible := false;
Cop1.Visible := false;
Cop2.Visible := false;
end;
UpdateDisplay;
end;
function TFEditProj.NextShortCut : integer;
var Got : String;
I,J : integer;
A,B : Word;
C : boolean;
begin
i:=1;
repeat
inc(i);
Got:=FTools.CBSC.Items.Strings[i];
C:=false;
j:=1;
while (j<Pages) and (not C) do begin
A:=SCS[(j*2)-1];
B:=SCS[(J*2)];
if StringSC(A,B)=Got then c:=true;
inc(j);
end;
until not c;
NextShortCut:=i;
end;
function TFEditProj.ShortCutInUse(i : integer) : boolean;
var C : boolean;
j : integer;
A,B : word;
begin
C:=false;
j:=1;
while (j<=Pages) and (not C) do begin
A:=SCS[(J*2)-1];
B:=SCS[(J*2)];
if (FTools.CBSC.Items.IndexOf(StringSC(A,B))=i) then c:=true;
inc(J);
end;
ShortCutInUse:=C;
end;
// Returns true if the shortcuts for the current song are in the normal 1,2,3... order
function TFEditProj.IsDefaultOrdering( iExclude : integer = 0 ) : boolean;
var p : integer;
begin
for p := 1 to Pages do begin
if (iExclude <> p) and ( SCS[(p*2)] <> (p + (VK_ONE-1)) ) then begin
IsDefaultOrdering := false;
Exit;
end;
end;
IsDefaultOrdering := true;
end;
{
procedure TFEditProj.ReorderShortcuts(i : integer);
var C : boolean;
j : integer;
A,B : word;
NewA, NewB : word;
S : string;
begin
// Get the key data for the 'Next Shortcut'
S:=FTools.CBSC.Items[NextShortcut];
NewA:=0;
if pos('Shift',S)>0 then NewA:=A+1;
if pos('Ctrl',S)>0 then NewA:=A+2;
if pos('Alt',S)>0 then NewA:=A+4;
while pos('+',S)>0 do S:=copy(S,pos('+',S)+1,length(S));
NewB:=ord(S[1]);
if S='None' then begin NewA:=0; NewB:=0; end;
// Find the page that matches this shortcut
C:=false;
j:=1;
while (j<=Pages) and (not C) do begin
A:=SCS[(J*2)-1];
B:=SCS[(J*2)];
if (FTools.CBSC.Items.IndexOf(StringSC(A,B))=i) then begin
c:=true;
SCS[(J*2)-1] := NewA;
SCS[(J*2)] := NewB;
end;
inc(J);
end;
end; }
procedure TFEditProj.MarkOHP(CID : string);
var S,Orig : string;
TF,GF : Textfile;
SR : SongRecord;
begin
if not OpenForRead(TF,FileName) then Exit;
if not OpenForWrite(GF,TempDir+'potato') then begin CloseTextfile(TF,FileName); Exit; end;
while not eof(TF) do begin
readln(TF,S); Orig:=S;
Delimit(S,SR);
if CID<>SR.ID then begin
writeln(GF,Orig)
end else begin
SR.OHP:='1';
PageCache_UpdateSR( SR );
S := PageCache_GetSrcLine( SR.Id );
writeln(GF,S);
end;
end;
CloseTextfile(TF,FileName);
CloseTextfile(GF,TempDir+'potato');
erase(TF);
rename(GF,FileName);
end;
procedure TFEditProj.ZipMeUp;
var i : integer;
S : string;
begin
AddFileToZip(TempDir+GID+'.ohp',OHPFile,true);
for i:=1 to Pages do begin
str(i,s);
AddFileToZip(TempDir+GID+'-'+S+'.rtf',OHPFile,true);
end;
// Delete any previous random pages which are hanging about here...
end;
function TFEditProj.StringSC(A,B : word) : string;
var Sh : string;
begin
sh:='';
if A=1 then sh:='Shift+';
if A=2 then sh:='Ctrl+';
if A=3 then sh:='Shift+Ctrl+';
if A=4 then sh:='Alt+';
if A=5 then sh:='Shift+Alt+';
if A=6 then sh:='Ctrl+Alt+';
if A=7 then sh:='Shift+Ctrl+Alt+';
if B<>0 then sh:=sh+chr(B);
if sh='' then sh:='None';
StringSC:=sh;
end;
procedure TFEditPRoj.LoadCopyRight(cid : string);
var SR : SongRecord;
begin
PageCache_GetSong( cid, SR );
{ if OpenForRead(TF,FileName) then begin
while not eof(TF) do begin
readln(TF,S);
Delimit(S,SR);
if CID=SR.ID then begin }
GTitle := PageCache_GetSongName(cid);
if SR.Cl1<>'' then GCopy1:=SR.Cl1 else GCopy1:='© '+SR.CopDate+' '+SR.Author;
if SR.Cl2<>'' then GCopy2:=SR.CL2 else GCopy2:=SR.CopyRight;
Cop1.Caption:=GCopy1; Cop1.Visible := true; Cop1.Enabled := true;
Cop2.Caption:=GCopy2; Cop2.Visible := true; Cop2.Enabled := true;
RightAlignCaptions;
// if (Self = FProjWin) and FLiveWindow.Visible then FLiveWindow.UpdateCopyright;
{ end;
end;
CloseTextfile(TF,FileName);
end;}
end;
procedure TFEditProj.LoadOHPData(FS : string);
var i : integer;
begin
bForceRedraw := false;
Pages := PageCache_GetPageCount(FS);
setlength(Pics,Pages);
if Pages>0 then begin
for i:=1 to Pages do begin
PageCache_GetPageShortcut( FS, i, SCS[(i*2)-1], SCS[(i*2)] );
Pics[i-1]:= PageCache_GetPagePicture(FS,i);
end;
end;
end;
procedure TFEditProj.InitFiles(Sender : TObject; from_webserver : boolean);
var hFiles : TStringList;
SR : SongRecord;
begin
Pages := PageCache_GetPageCount( GID );
if Pages=0 then begin
PageCache_GetSong( GID, SR );
RESong.Lines.Clear;
RESong.Lines.Add( SR.Title );
RESong.Lines.SaveToFile(TempDir+GID+'-1.rtf');
// Set up the shortcut to '1'
Pages := 1;
ShowPage := 1;
SCS[2] := ord('1');
SCS[1] := 0;
SaveOHP;
hFiles := TStringList.Create;
hFiles.Add( TempDir+GID+'-1.rtf' );
hFiles.Add( TempDir+GID+'.ohp' );
AddFilesToZip( hFiles, OHPFile, true );
hFiles.Free;
PageCache_ForceReload(GID);
UpdateFsH( GID, OHPFile, QSFile );
LoadOHPData(GID);
end;
if Pages>=1 then begin
if (ShowPage <= Pages) and (ShowPage > 0) then SelectPage( GID, ShowPage, from_webserver )
else SelectPage( GID, 1, from_webserver);
end;
SetGlobals;
if bHasTools then FTools.UpdateButtons;
// if (Self = FProjWin) and FLiveWindow.Visible then FLiveWindow.UpdateCopyright;
end;
procedure TFEditProj.SetEditWidth;
var //iW, iH : integer;
rScreenArea, rRenderRect : TRect;
begin
// Default is Full-screen
CurrentDisplayArea := Rect( 0,0, Width, Height );
if bHasTools then begin
if FTools.CBScreen.ItemIndex<0 then FTools.CBScreen.ItemIndeX:=0;
case FTools.CBScreen.ItemIndex of
ITEM_IDX_AS_PROJECTED: begin
CurrentDisplayArea.Right := FSongbase.szDisplaySize.cx;
CurrentDisplayArea.Bottom := FSongbase.szDisplaySize.cy;
end;
ITEM_IDX_640_480: begin
CurrentDisplayArea.Right := 640;
CurrentDisplayArea.Bottom := 480;
end;
ITEM_IDX_800_600: begin
CurrentDisplayArea.Right := 800;
CurrentDisplayArea.Bottom := 600;
end;
ITEM_IDX_1024_768: begin
CurrentDisplayArea.Right := 1024;
CurrentDisplayArea.Bottom := 768;
end;
ITEM_IDX_1152_864: begin
CurrentDisplayArea.Right := 1152;
CurrentDisplayArea.Bottom := 864;
end;
ITEM_IDX_1280_1024: begin
CurrentDisplayArea.Right := 1280;
CurrentDisplayArea.Bottom := 1024;
end;
end;
// Clip to screen
if CurrentDisplayArea.Right > Width then CurrentDisplayArea.Right := Width;
if CurrentDisplayArea.Bottom > Height then CurrentDisplayArea.Bottom := Height;
end;
// And then centre on screen (at top)
// iW := CurrentDisplayArea.Right;
// iH := CurrentDisplayArea.Bottom;
rScreenArea := CurrentDisplayArea;
if bHasTools then begin
OffsetRect( CurrentDisplayArea, (Width - CurrentDisplayArea.Right) div 2, 0 );
end else if bScaleProjection then begin
// iW := FSettings.szProjectScale.cx;
// iH := FSettings.szProjectScale.cy;
end;
// Select the render position, and centre
if bHasTools then begin
rRenderRect.Left := CurrentDisplayArea.Left + ((FSongbase.rTextArea.Left * rScreenArea.Right ) div FSongbase.szDisplaySize.cx);
rRenderRect.Right := CurrentDisplayArea.Left + ((FSongbase.rTextArea.Right * rScreenArea.Right ) div FSongbase.szDisplaySize.cx);
rRenderRect.Top := CurrentDisplayArea.Top + ((FSongbase.rTextArea.Top * rScreenArea.Bottom) div FSongbase.szDisplaySize.cy);
rRenderRect.Bottom := CurrentDisplayArea.Top + ((FSongbase.rTextArea.Bottom * rScreenArea.Bottom) div FSongbase.szDisplaySize.cy);
end else begin
rRenderRect := FSongbase.rTextArea;
end;
// Then put the RichEdit control in it (take of 40 more pixels at the bottom for 'captions')
RESong.SetBounds( rRenderRect.Left, rRenderRect.Top,
rRenderRect.Right - rRenderRect.Left,
rRenderRect.Bottom - rRenderRect.Top );
FRTF.SetClientRect( rRenderRect );
RightAlignCaptions;
end;
procedure TFEditPRoj.SaveAtts;
begin
SaveB:=[fsBold]<=RESong.SelAttributes.Style;
SaveI:=[fsItalic]<=RESong.SelAttributes.Style;
SaveU:=[fsUnderline]<=RESong.SelAttributes.Style;
SaveCol:=RESong.SelAttributes.Color;
SaveFont:=FTools.CBFont.Items.IndexOf(RESong.SelAttributes.Name);
SaveSize:=RESong.SelAttributes.size;
if RESong.Paragraph.Alignment=taCenter then SaveJ:=1;
if RESong.Paragraph.Alignment=taRightJustify then SaveJ:=2;
if RESong.Paragraph.Alignment=taLeftJustify then SaveJ:=3;
end;
procedure TFEditPRoj.RestAtts;
begin
if SaveB then RESong.SelAttributes.Style:=RESong.SelAttributes.Style+[fsBold];
if SaveI then RESong.SelAttributes.Style:=RESong.SelAttributes.Style+[fsItalic];
if SaveU then RESong.SelAttributes.Style:=RESong.SelAttributes.Style+[fsUnderline];
RESong.SelATtributes.Color:=SaveCol;
RESong.SelAttributes.Name:=FTools.CBFont.Items.Strings[SaveFont];
RESong.SelAttributes.Size:=SaveSize;
if SaveJ=1 then Resong.Paragraph.Alignment:=taCenter;
if SaveJ=2 then RESong.Paragraph.Alignment:=taRightJustify;
if SaveJ=3 then RESong.Paragraph.Alignment:=taLeftJustify;
end;
procedure TFEditProj.RESongSelectionChange(Sender: TObject);
begin
FTools.bDisableEvents := true;
FTools.BBold.Down:=[fsBold]<=RESong.SelAttributes.Style;
FTools.BItalic.Down:=[fsItalic]<=RESong.SelAttributes.Style;
FTools.BUnder.Down:=[fsUnderline]<=RESong.SelAttributes.Style;
FTools.PCol2.Color:=RESong.SelAttributes.Color;
FTools.CBFont.ItemIndex:=FTools.CBFont.Items.IndexOf(RESong.SelAttributes.Name);
FTools.UpDown1.Position:=RESong.SelAttributes.size;
if RESong.Paragraph.Alignment=taLeftJustify then begin FTools.BLeft.Down:=true; FTools.BRight.Down:=false; FTools.BCent.Down:=false; end;
if RESong.Paragraph.Alignment=taRightJustify then begin FTools.BRight.Down:=true; FTools.BLeft.Down:=false; FTools.BCent.Down:=false; end;
if RESong.Paragraph.Alignment=taCenter then begin FTools.BCent.Down:=true; FTools.BRight.Down:=false; FTools.BLeft.Down:=false; end;
FTools.bDisableEvents := false;
end;
procedure TFEditProj.SaveOHP;
var S,S2 : string;
TF : Textfile;
i : integer;
ps : string;
begin
LLicense.Visible := true;
S:=GID+'.ohp';
if OpenForWrite(TF,TempDir+S) then begin
str(Pages,S);
writeln(TF,S);
for i:=1 to Pages do begin
str(SCS[(i*2)-1],S);
str(SCS[(I*2)],S2);
if( Length(Pics)>0 ) then Ps:=Pics[i-1] else Ps:='';
writeln(TF,S+'~'+S2+'$'+Ps);
end;
CloseTextfile(TF, TempDir+S);
if FTools.Visible then begin
FTools.BReload.Enabled := false;
FTools.BSave.Enabled := false;
end;
end;
end;
procedure TFEditProj.EBlindKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var A,B : word;
i : integer;
begin
A:=0;
B:=Key;
if B=VK_ESCAPE then begin
// TransparentColor := false;
FTools.show;
RESong.Visible := true;
bScaleProjection := false;
// Load in the text for the current page - as RESong may
// differ from the Projection context
PageCache_LoadRTF( FEditWin.RESong, FEditWin.GID, FEditWin.CurrentPage );
FTools.BSave.Enabled := false;
FTools.BReload.Enabled := false;
// ImgOnScreen.Visible := false;
bHasTools := true;
FTools.UpdateButtons;
SetGlobals;
ShowCursor(true);
Cop1.Visible:=false; Cop1.Enabled := false;
Cop2.Visible:=false; Cop2.Enabled := false;
LLicense.Visible := false;
Invalidate;
end else
if (B=VK_RIGHT) and ((CurrentPage<Pages) or Blanked) then begin
i := CurrentPage;
inc(i);
if i>Pages then i:=Pages;
SelectPage( GID, i, false);
end else
if (B=VK_LEFT) and ((CurrentPage>1) or Blanked) then begin
i := CurrentPage;
dec(i);
if i<1 then i:=1;
if i <= Pages then begin
SelectPage( GID, i, false);
end;
end else
if (B=VK_HOME) and ((CurrentPage<>1) or Blanked) then begin
if Pages > 0 then begin
SelectPage( GID, 1, false);
end;
end else
if (B=VK_END) and ((Blanked) or (CurrentPage<>Pages)) then begin
if Pages<>0 then begin
SelectPage( GID, Pages, false);
end;
end else begin
if [ssShift]<=Shift then A:=A+1;
if [ssCtrl]<=Shift then A:=A+2;
if [ssCtrl]<=Shift then A:=A+4;
i:=0;
repeat
inc(i);
until ((SCS[(i*2)-1]=A) and (SCS[(i*2)]=B)) or (i>Pages);
if (i<=Pages) and (Blanked or (i<>CurrentPage)) then begin
i := CurrentPage;
SelectPage( GID, i, false);
end;
end;
EBlind.TexT:='';
EBlind.SetFocus;
EBlind.SendToBack;
end;
procedure TFEditProj.EBlindExit(Sender: TObject);
begin
if not FTools.Visible and (BlindMode = NOT_DISPLAYING) then EBlind.SetFocus;
end;
procedure TFEditProj.FormCreate(Sender: TObject);
var i : integer;
begin
FRTF := TWindowlessRTF.Create();
FRTF.SetTransparent(true);
FRTF.SetWordWrap(true);
bHasImgBackground := false;
if Self = FEditWin then begin
// Editor window - redraws the 'live window' when text changes
RESong.OnChange := RESongEdited;
RESong.OnSelectionChange := RESongSelectionChange;
end;
Titlelist:=TStringlist.create;
Titlelist.sorted:=true;
for i:=1 to 99 do begin
Pagelabs[i]:=TLabel.Create(self);
end;
SearchResults:=TStringList.Create;
height:=screen.height;
width :=screen.width;
top:=0;
left:=0;
Cop1.Top:=Height - 40;
Cop2.Top:=Height - 20;
bSetOffsets := false;
bReady := false;
bScaleProjection := false;
bHighQuality := true;
ImgScaler := nil;
ImgOffscreen := nil;
BlankImgFile := '';
bShowHighlight := false;
WindowBackground := clBlack;
bForceRedraw := false;
SModeSelect := 'Select';
SModeSearchResultCount := 'Search Results (%d)';
SModeSearchResultIdx := 'Search Result (%d/%d)';
SModeSearchResultNone := 'Select (No Results)';
SModeShortcut := 'Shortcut=%s';
SModeSearchWords := 'Search Text';
SModeSearchTitle := 'Find Title';
SModeExit := 'Exit (Y/N)';
end;
procedure TFEditProj.EBlind2Exit(Sender: TObject);
begin
if BlindMode<>NOT_DISPLAYING then begin
LogThis( 'Blind2 regaining focus' );
EBlind2.SetFocus;
EBlind2.SendToBack;
end;
end;
function before(S1,S2 : string) : boolean;
var A,B,C,D : string;
i : integer;
begin
A:=uppercase(S1); C:='';
B:=uppercase(S2); D:='';
for i:=1 to length(A) do if pos(A[i],'ABCDEFGHIJKLMNOPQRSTUVWXYZ')>0 then C:=C+A[i];
for i:=1 to length(B) do if pos(B[i],'ABCDEFGHIJKLMNOPQRSTUVWXYZ')>0 then D:=D+B[i];
before:=(C<D) and (copy(C,1,length(D))<>D);
end;
procedure TFEditPRoj.ShowTheSong(id : string);
begin
LogThis( 'Projecting song ' + id + ', page ' + IntToStr(CurrentPage) );
GID:=id;
LoadOHPData(GID);
LoadCopyright(GID);
CurrentPage:=0;
LastID := GID; // Also here sets LastID so that Selecting a song works!
UpdateLabels(CurrentPage);
if not bHasTools then BlindMode:=SHOWING_SONG;
ShowLabels(LLicense.Left,LLicense.Top - LLicense.Height - TEXT_OFFSET );
MarkOHP(GId);
If (( (Pages=1) and (FSettings.AutoViewSingle1.Checked) )
or (FSettings.AutoView1.Checked) ) then begin
SelectPage( GID, 1, false);
end;
Cop1.Visible:=true; Cop1.Enabled := true;
Cop2.Visible:=true; Cop2.Enabled := true;
ShowHighlight( false );
end;
procedure TFEditProj.EBlind2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var Code,i,count : integer;
done : boolean;
S,CheckID,CheckK : string;
A,B,CheckA,CheckB : word;
bA, bB : boolean;
SR : SongRecord;
bUnhandled : boolean;
hTimeNow : TDateTime;
OldMode : byte;
SPostfix : string;
begin
A:=0;
B:=Key;
bUnhandled := true;
LogThis( 'Projection Window handling key ' + IntToStr(Key) );
OldMode := BlindMode;
SPostfix := '';
// Pressing the same key twice in very quick succession is assumed to be
// a mistake! Unless we're in a mode where we enter text, or the key in question
// is a cursor.
hTimeNow := GetTime();
if bIgnoreDoubleClicks and (Key <> VK_LEFT) and (Key <> VK_RIGHT) and