~ubuntu-branches/ubuntu/precise/fte/precise

« back to all changes in this revision

Viewing changes to src/g_text.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Neil Williams
  • Date: 2011-08-14 10:28:46 UTC
  • mfrom: (1.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110814102846-kate2jfkduwpnika
Tags: 0.50.2b6-1
* QA upload.
* Synchronise with current upstream sources.
  (Closes: #195945)
* Include NMUs by Nobuhiro Iwamatsu and Hideki Yamane,
  thanks to both.
* Move to 3.0 quilt

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <stdarg.h>
17
17
#include <stdio.h>
18
18
 
19
 
 
20
19
int ShowVScroll = 1;
21
20
int ShowHScroll = 1;
22
21
int ShowMenuBar = 1;
46
45
    int sbVstart, sbVamount, sbVtotal, sbVupdate;
47
46
    int sbHstart, sbHamount, sbHtotal, sbHupdate;
48
47
    int SbVBegin, SbVEnd, SbHBegin, SbHEnd;
49
 
    
 
48
 
50
49
    GViewPeer(GView *view, int XSize, int YSize);
51
50
    ~GViewPeer();
52
51
 
58
57
 
59
58
    int ConSetSize(int X, int Y);
60
59
    int ConQuerySize(int *X, int *Y);
61
 
    
 
60
 
62
61
    int ConSetCursorPos(int X, int Y);
63
62
    int ConQueryCursorPos(int *X, int *Y);
64
63
    int ConShowCursor();
65
64
    int ConHideCursor();
66
65
    int ConCursorVisible();
67
66
    int ConSetCursorSize(int Start, int End);
68
 
    
 
67
 
69
68
#ifdef CONFIG_MOUSE
70
69
    int CaptureMouse(int grab);
71
70
#endif
72
71
    int CaptureFocus(int grab);
73
 
    
 
72
 
74
73
    int QuerySbVPos();
75
74
    int SetSbVPos(int Start, int Amount, int Total);
76
75
    int SetSbHPos(int Start, int Amount, int Total);
78
77
 
79
78
    int DrawScrollBar();
80
79
    int UpdateCursor();
81
 
};      
 
80
};
82
81
 
83
82
class GFramePeer {
84
83
public:
85
84
    int fW, fH;
86
85
    GFrame *Frame;
87
 
    
 
86
 
88
87
    GFramePeer(GFrame *aFrame, int Width, int Height);
89
88
    ~GFramePeer();
90
 
    
 
89
 
91
90
    int ConSetTitle(const char *Title, const char *STitle);
92
91
    int ConGetTitle(char *Title, size_t MaxLen, char *STitle, size_t SMaxLen);
93
 
    
 
92
 
94
93
    int ConSetSize(int X, int Y);
95
94
    int ConQuerySize(int *X, int *Y);
96
95
 
149
148
int GViewPeer::ConScroll(int Way, int X, int Y, int W, int H, TAttr Fill, int Count) {
150
149
    return ::ConScroll(Way, X + wX, Y + wY, W, H, Fill, Count);
151
150
}
152
 
    
 
151
 
153
152
int GViewPeer::ConSetSize(int X, int Y) {
154
153
    wW = X;
155
154
    wH = Y;
 
155
 
156
156
    return 1;
157
157
}
158
158
 
159
159
int GViewPeer::ConQuerySize(int *X, int *Y) {
160
160
    if (X) *X = wW;
161
161
    if (Y) *Y = wH;
 
162
 
162
163
    return 1;
163
164
}
164
165
 
178
179
int GViewPeer::ConQueryCursorPos(int *X, int *Y) {
179
180
    if (X) *X = cX;
180
181
    if (Y) *Y = cY;
 
182
 
181
183
    return 1;
182
184
}
183
185
 
185
187
    cVisible = 1;
186
188
    if (wState & sfFocus)
187
189
        return ::ConShowCursor();
 
190
 
188
191
    return 1;
189
192
}
190
193
 
205
208
    cEnd = End;
206
209
    if (wState & sfFocus)
207
210
        return ::ConSetCursorSize(Start, End);
208
 
    else
209
 
        return 1;
 
211
 
 
212
    return 1;
210
213
}
211
214
 
212
215
#ifdef CONFIG_MOUSE
213
216
int GViewPeer::CaptureMouse(int grab) {
214
217
    if (MouseCapture == 0) {
215
 
        if (grab)
216
 
            MouseCapture = View;
217
 
        else
 
218
        if (!grab)
218
219
            return 0;
 
220
 
 
221
        MouseCapture = View;
219
222
    } else {
220
223
        if (grab || MouseCapture != View)
221
224
            return 0;
222
 
        else
223
 
            MouseCapture = 0;
 
225
 
 
226
        MouseCapture = 0;
224
227
    }
 
228
 
225
229
    return 1;
226
230
}
227
231
#endif
228
232
 
229
233
int GViewPeer::CaptureFocus(int grab) {
230
234
    if (FocusCapture == 0) {
231
 
        if (grab)
232
 
            FocusCapture = View;
233
 
        else
 
235
        if (!grab)
234
236
            return 0;
 
237
 
 
238
        FocusCapture = View;
235
239
    } else {
236
240
        if (grab || FocusCapture != View)
237
241
            return 0;
238
 
        else
239
 
            FocusCapture = 0;
 
242
 
 
243
        FocusCapture = 0;
240
244
    }
241
245
    return 1;
242
246
}
243
247
 
244
248
int GViewPeer::ExpandHeight(int DeltaY) {
245
249
    if (View->Parent->Top == View->Next)
246
 
        return -1;
 
250
        return 0;
 
251
 
247
252
    if (DeltaY + wH < 3)
248
253
        DeltaY = - (wH - 3);
 
254
 
249
255
    if (View->Next->Peer->wH - DeltaY < 3)
250
256
        DeltaY = View->Next->Peer->wH - 3;
 
257
 
251
258
    View->Peer->ConSetSize(wW, wH + DeltaY);
252
259
    View->Next->Peer->wY += DeltaY;
253
260
    assert(View->Next->Peer->wY >= 0);
254
261
    View->Next->Peer->ConSetSize(View->Next->Peer->wW, View->Next->Peer->wH - DeltaY);
255
262
    View->Resize(View->Peer->wW, View->Peer->wH);
256
263
    View->Next->Resize(View->Next->Peer->wW, View->Next->Peer->wH);
257
 
    return 0;
 
264
 
 
265
    return 1;
258
266
}
259
267
 
260
268
int GViewPeer::QuerySbVPos() {
262
270
}
263
271
 
264
272
int GViewPeer::SetSbVPos(int Start, int Amount, int Total) {
265
 
    if (sbVstart != Start ||
266
 
        sbVamount != Amount ||
267
 
        sbVtotal != Total)
268
 
    {
 
273
    if (sbVstart != Start || sbVamount != Amount || sbVtotal != Total) {
269
274
        sbVstart = Start;
270
275
        sbVamount = Amount;
271
276
        sbVtotal = Total;
272
277
        sbVupdate = 1;
273
278
    }
 
279
 
274
280
    return 1;
275
281
}
276
282
 
277
283
int GViewPeer::SetSbHPos(int Start, int Amount, int Total) {
278
 
    if (sbHstart != Start ||
279
 
        sbHamount != Amount ||
280
 
        sbHtotal != Total)
281
 
    {
 
284
    if (sbHstart != Start || sbHamount != Amount || sbHtotal != Total) {
282
285
        sbHstart = Start;
283
286
        sbHamount = Amount;
284
287
        sbHtotal = Total;
285
288
        sbHupdate = 1;
286
289
    }
 
290
 
287
291
    return 1;
288
292
}
289
293
 
294
298
        ConShowCursor();
295
299
    else
296
300
        ConHideCursor();
297
 
    return 0;
 
301
 
 
302
    return 1;
298
303
}
299
304
 
300
305
int GViewPeer::DrawScrollBar() {
303
308
    int W, H;
304
309
    char fore = ConGetDrawChar(DCH_HFORE);
305
310
    char back = ConGetDrawChar(DCH_HBACK);
306
 
    
 
311
 
307
312
    ConQuerySize(&W, &H);
308
313
 
309
314
    if (ShowVScroll && H > 1) {
313
318
        ConPutBox(W, H - 1, 1, 1, B);
314
319
 
315
320
        NRows = H - 2;
316
 
        
 
321
 
317
322
        if (sbVtotal <= NRows) {
318
323
            SbVBegin = 0;
319
324
            SbVEnd = NRows - 1;
321
326
            SbVBegin = NRows * sbVstart / sbVtotal;
322
327
            SbVEnd   = SbVBegin + NRows * sbVamount / sbVtotal;
323
328
        }
324
 
        
 
329
 
325
330
        for (I = 0; I < NRows; I++) {
326
331
            if (I >= SbVBegin && I <= SbVEnd)
327
332
                MoveCh(B, fore, hcScrollBar_Fore, 1);
335
340
        ConPutBox(0, H, 1, 1, B);
336
341
        MoveCh(B, ConGetDrawChar(DCH_ARIGHT), hcScrollBar_Arrows, 1);
337
342
        ConPutBox(W - 1, H, 1, 1, B);
338
 
        
 
343
 
339
344
        NCols = W - 2;
340
 
        
 
345
 
341
346
        if (sbHtotal <= NCols) {
342
347
            SbHBegin = 0;
343
348
            SbHEnd = NCols - 1;
359
364
        MoveCh(B, ' ', hcScrollBar_Arrows, 1);
360
365
        ConPutBox(W, H, 1, 1, B);
361
366
    }
362
 
        
363
 
    return 0;
 
367
 
 
368
    return 1;
364
369
}
365
370
 
366
371
 
387
392
int GView::ConClear() {
388
393
    int W, H;
389
394
    TDrawBuffer B;
390
 
    
 
395
 
391
396
    ConQuerySize(&W, &H);
392
397
    MoveChar(B, 0, W, ' ', 0x07, 1);
393
398
    ConSetBox(0, 0, W, H, B[0]);
 
399
 
394
400
    return 1;
395
401
}
396
402
 
416
422
 
417
423
int GView::ConSetSize(int X, int Y) {
418
424
    if (Peer->ConSetSize(X, Y)) {
419
 
        Resize(X, Y);
420
 
        return 1;
 
425
        Resize(X, Y);
 
426
        return 1;
421
427
    }
 
428
 
422
429
    return 0;
423
430
}
424
431
 
443
450
}
444
451
 
445
452
int GView::ConCursorVisible() {
446
 
    return Peer->ConCursorVisible(); 
 
453
    return Peer->ConCursorVisible();
447
454
}
448
455
 
449
456
int GView::ConSetCursorSize(int Start, int End) {
497
504
    int SaveRc = Result;
498
505
    int NewResult;
499
506
    int didFocus = 0;
500
 
    
 
507
 
501
508
    if (FocusCapture == 0) {
502
 
        if (CaptureFocus(1) == 0) return -1;
 
509
        if (!CaptureFocus(1))
 
510
            return 0;
503
511
        didFocus = 1;
504
 
    } else
505
 
        if (FocusCapture != this)
506
 
            return -1;
 
512
    } else if (FocusCapture != this)
 
513
        return 0;
 
514
 
507
515
    Result = -2;
508
516
    while (Result == -2 && frames != 0)
509
517
        gui->ProcessEvent();
510
518
    NewResult = Result;
511
519
    Result = SaveRc;
 
520
 
512
521
    if (didFocus)
513
522
        CaptureFocus(0);
 
523
 
514
524
    return NewResult;
515
525
}
516
526
 
549
559
    if (X) *X = fW;
550
560
    if (Y) *Y = fH;
551
561
    return 1;
552
 
}   
 
562
}
553
563
 
554
564
//int GFrame::ConQuerySize(int *X, int *Y) {
555
565
//    ::ConQuerySize(X, Y);
559
569
 
560
570
int GFramePeer::ConSetTitle(const char *Title, const char *STitle) {
561
571
    ::ConSetTitle(Title, STitle);
562
 
    return 0;
 
572
    return 1;
563
573
}
564
574
 
565
575
int GFramePeer::ConGetTitle(char *Title, size_t MaxLen, char *STitle, size_t SMaxLen) {
617
627
 
618
628
int GFrame::ConSplitView(GView *view, GView *newview) {
619
629
    int dmy;
620
 
    
 
630
 
621
631
    newview->Parent = this;
622
632
    newview->Peer->wX = 0;
623
633
    ConQuerySize(&newview->Peer->wW, &dmy);
624
 
    if (ShowVScroll) 
 
634
 
 
635
    if (ShowVScroll)
625
636
        newview->Peer->wW--;
 
637
 
626
638
    newview->Peer->wY = view->Peer->wY + view->Peer->wH / 2;
627
639
    assert(newview->Peer->wY >= 0);
628
640
    newview->Peer->wH = view->Peer->wH - view->Peer->wH / 2;
 
641
 
629
642
    if (ShowHScroll) {
630
643
        newview->Peer->wY++;
631
644
        newview->Peer->wH--;
632
645
    }
 
646
 
633
647
    view->Peer->wH /= 2;
634
648
    view->ConSetSize(view->Peer->wW, view->Peer->wH);
635
649
    newview->ConSetSize(newview->Peer->wW, newview->Peer->wH);
636
650
    InsertView(view, newview);
637
 
    return 0;
 
651
 
 
652
    return 1;
638
653
}
639
654
 
640
655
int GFrame::ConCloseView(GView * /*view*/) {
641
 
    return 0;
 
656
    return 1;
642
657
}
643
658
 
644
659
int GFrame::ConResizeView(GView * /*view*/, int /*DeltaY*/) {
645
 
    return 0;
 
660
    return 1;
646
661
}
647
662
 
648
663
int GFrame::AddView(GView *view) {
666
681
        H--;
667
682
    view->ConSetSize(W, H);
668
683
    InsertView(Top, view);
669
 
    return 0;
 
684
 
 
685
    return 1;
670
686
}
671
687
 
672
688
void GFrame::Update() {
673
 
    
 
689
 
674
690
    UpdateMenu();
675
691
    for (GView *v = Active; v; v = v->Next) {
676
692
        v->Update();
690
706
}
691
707
 
692
708
void GFrame::Repaint() {
693
 
    
 
709
 
694
710
    if (ShowMenuBar)
695
711
        DrawMenuBar();
696
712
    for (GView *v = Active; v; v = v->Next) {
706
722
}
707
723
 
708
724
void GFrame::InsertView(GView *prev, GView *view) {
709
 
    if (!view) return ;
 
725
    if (!view)
 
726
        return;
 
727
 
710
728
    if (prev) {
711
729
        view->Prev = prev;
712
730
        view->Next = prev->Next;
716
734
        view->Prev = view->Next = view;
717
735
        Top = view;
718
736
    }
 
737
 
719
738
    if (Active == 0) {
720
739
        Active = view;
721
740
        Active->Activate(1);
724
743
 
725
744
void GFrame::RemoveView(GView *view) {
726
745
    if (!view) return;
727
 
    
 
746
 
728
747
    if (Active == view)
729
748
        Active->Activate(0);
730
749
 
734
753
    } else {
735
754
        view->Next->Prev = view->Prev;
736
755
        view->Prev->Next = view->Next;
737
 
        
 
756
 
738
757
        if (Top == view) {
739
758
            Top = view->Next;
740
759
            Top->Peer->wY -= view->Peer->wH;
744
763
            view->Prev->ConSetSize(view->Prev->Peer->wW,
745
764
                                   view->Prev->Peer->wH + view->Peer->wH + (ShowHScroll ? 1 : 0));
746
765
        }
747
 
        
 
766
 
748
767
        if (Active == view) {
749
768
            Active = view->Prev;
750
769
            Active->Activate(1);
754
773
 
755
774
void GFrame::SelectNext(int back) {
756
775
    GView *c = Active;
757
 
    
 
776
 
758
777
    if (c == 0 && Top == 0)
759
778
        return;
760
 
    
 
779
 
761
780
    if (FocusCapture != 0)
762
781
        return ;
763
 
    
 
782
 
764
783
    else if (c == 0)
765
784
        c = Active = Top;
766
785
    else
772
791
    if (c != Active) {
773
792
        if (c)
774
793
            c->Activate(0);
775
 
        if (Active) 
 
794
        if (Active)
776
795
            Active->Activate(1);
777
796
    }
778
797
}
779
798
 
780
799
int GFrame::SelectView(GView *view) {
781
 
    if (Top == 0)
 
800
    if (!Top)
782
801
        return 0;
783
 
    
 
802
 
784
803
    if (FocusCapture != 0)
785
804
        view = view;
786
 
    
 
805
 
787
806
    if (Active)
788
807
        Active->Activate(0);
789
808
    Active = view;
790
809
    if (Active)
791
810
        Active->Activate(1);
 
811
 
792
812
    return 1;
793
813
}
794
814
 
811
831
        height--;
812
832
 
813
833
    //fprintf(stderr, "Resize: %d %d   c:%d\n", width, height, count);
814
 
    
 
834
 
815
835
    for (GView *V = Top->Prev; V != Top; V = V->Prev) {
816
836
        int h, y;
817
 
        
 
837
 
818
838
        h = V->Peer->wH;
819
839
        y = V->Peer->wY;
820
 
        
 
840
 
821
841
        if (y >= height - 2) {
822
842
            y = height - 2;
823
843
        }
839
859
    NextEvent.What = evCommand;
840
860
    NextEvent.Msg.Command = cmMainMenu;
841
861
    NextEvent.Msg.Param1 = Sub;
842
 
    return 0;
 
862
 
 
863
    return 1;
843
864
}
844
865
 
845
866
int GFrame::SetMenu(const char *Name) {
846
867
    free(Menu);
847
868
    Menu = strdup(Name);
848
 
    return 0;
 
869
 
 
870
    return 1;
849
871
}
850
872
 
851
873
void GFrame::Show() {
856
878
}
857
879
 
858
880
int GUI::ConGrabEvents(TEventMask /*EventMask*/) {
859
 
    return 0;
 
881
    return 1;
860
882
}
861
883
 
862
884
void GUI::DispatchEvent(GFrame * /*frame*/, GView *view, TEvent &Event) {
863
 
    if (Event.What != evNone) {
 
885
    if (Event.What != evNone)
864
886
        if (view)
865
887
            view->HandleEvent(Event);
866
 
    }
867
888
}
868
889
 
869
890
int GUI::ConGetEvent(TEventMask EventMask, TEvent *Event, int WaitTime, int Delete, GView **view) {
877
898
}
878
899
 
879
900
int GUI::ConFlush() {
880
 
    return 0;
 
901
    return 1;
881
902
}
882
903
 
883
904
static inline int scrollBreak(TEvent &E)
894
915
    int y;
895
916
    int wY, wH;
896
917
    TEvent E1;
897
 
    
 
918
 
898
919
    y = E.Mouse.Y;
899
920
    wY = view->Peer->wY;
900
921
    wH = view->Peer->wH;
958
979
        } while (1);
959
980
    } else {
960
981
        int delta = y - 1 - view->Peer->SbVBegin - wY;
961
 
        
 
982
 
962
983
        do {
963
984
            E1.What = evCommand;
964
985
            E1.Msg.View = view;
982
1003
    int x;
983
1004
    int wX, wW;
984
1005
    TEvent E1;
985
 
    
 
1006
 
986
1007
    x = E.Mouse.X;
987
1008
    wX = view->Peer->wX;
988
1009
    wW = view->Peer->wW;
1046
1067
        } while (1);
1047
1068
    } else {
1048
1069
        int delta = x - 1 - view->Peer->SbHBegin - wX;
1049
 
        
 
1070
 
1050
1071
        do {
1051
1072
            E1.What = evCommand;
1052
1073
            E1.Msg.View = view;
1068
1089
 
1069
1090
void GUI::ProcessEvent() {
1070
1091
    TEvent E;
1071
 
    
 
1092
 
1072
1093
    E = NextEvent;
1073
1094
    if (E.What != evNone)
1074
1095
        NextEvent.What = evNone;
1075
1096
 
1076
1097
    if (E.What == evNone
1077
 
        && (ConGetEvent(evMouse | evCommand | evKeyboard, &E, 0, 1, 0) == -1
1078
 
            || E.What == evNone)) {
 
1098
        && (!ConGetEvent(evMouse | evCommand | evKeyboard, &E, 0, 1, 0)
 
1099
            || E.What == evNone)) {
1079
1100
        frames->Update();
1080
 
        while(ConGetEvent(evMouse | evCommand | evKeyboard, &E, -1, 1, 0) == -1 ||
1081
 
           (E.What == evMouseMove && E.Mouse.Buttons == 0));
 
1101
        while (!ConGetEvent(evMouse | evCommand | evKeyboard, &E, -1, 1, 0)
 
1102
               || (E.What == evMouseMove && E.Mouse.Buttons == 0));
1082
1103
    }
1083
1104
    if (E.What != evNone) {
1084
1105
        GView *view = frames->Active;
1088
1109
                MouseCapture == 0 && FocusCapture == 0)
1089
1110
            {
1090
1111
                frames->Update(); // sync before menu
1091
 
                if (ExecMainMenu(E, 0) == -1) {
 
1112
                if (!ExecMainMenu(E, 0)) {
1092
1113
                    if (E.What == evCommand && E.Msg.Command == cmResize) {
1093
1114
                        int X, Y;
1094
1115
 
1101
1122
            }
1102
1123
            if (E.What == evMouseDown && MouseCapture == 0 && FocusCapture == 0) {
1103
1124
                GView *V = frames->Active;
1104
 
                
 
1125
 
1105
1126
                while (V) {
1106
1127
                    if (E.Mouse.Y >= V->Peer->wY &&
1107
 
                        E.Mouse.Y <  V->Peer->wY + V->Peer->wH + (ShowHScroll ? 1 : 0))
1108
 
                    {
 
1128
                        E.Mouse.Y <  V->Peer->wY + V->Peer->wH + (ShowHScroll ? 1 : 0)) {
1109
1129
                        frames->SelectView(V);
1110
1130
                        view = V;
1111
1131
                        break;
1141
1161
        }
1142
1162
        if (E.What == evCommand) {
1143
1163
            switch (E.Msg.Command) {
1144
 
            case cmResize: 
 
1164
            case cmResize:
1145
1165
                {
1146
1166
                    int X, Y;
1147
1167
 
1154
1174
                    char Sub = (char)E.Msg.Param1;
1155
1175
 
1156
1176
                    frames->Update(); // sync before menu
1157
 
                    if (::ExecMainMenu(E, Sub) != 1) {;
 
1177
                    if (!::ExecMainMenu(E, Sub)) {;
1158
1178
                        if (E.What == evCommand && E.Msg.Command == cmResize) {
1159
1179
                            int X, Y;
1160
1180
 
1169
1189
                {
1170
1190
                    long id = E.Msg.Param1;
1171
1191
                    int Cols, Rows;
1172
 
                    
 
1192
 
1173
1193
                    if (id == -1) return;
1174
1194
                    frames->ConQuerySize(&Cols, &Rows);
1175
1195
                    int x = Cols / 2, y = Rows / 2;
1176
1196
#ifdef CONFIG_MOUSE
1177
1197
                    ConQueryMousePos(&x, &y);
1178
1198
#endif
1179
 
                    
 
1199
 
1180
1200
                    frames->Update(); // sync before menu
1181
1201
                    if (::ExecVertMenu(x, y, id, E, 0) != 1) {
1182
1202
                        if (E.What == evCommand && E.Msg.Command == cmResize) {
1197
1217
}
1198
1218
 
1199
1219
int GUI::Run() {
1200
 
    if (Start(fArgc, fArgv) == 0) {
1201
 
        doLoop = 1;
1202
 
        while (doLoop)
1203
 
            ProcessEvent();
1204
 
        Stop();
 
1220
    if (!Start(fArgc, fArgv))
1205
1221
        return 0;
1206
 
    }
 
1222
 
 
1223
    for (doLoop = 1; doLoop;)
 
1224
        ProcessEvent();
 
1225
 
 
1226
    Stop();
 
1227
 
1207
1228
    return 1;
1208
1229
}
1209
1230
 
1213
1234
 
1214
1235
void DieError(int rc, const char *msg, ...) {
1215
1236
    va_list ap;
1216
 
    
 
1237
 
1217
1238
    va_start(ap, msg);
1218
1239
    vfprintf(stderr, msg, ap);
1219
1240
    va_end(ap);