File: o_model.cpp

package info (click to toggle)
fte 0.50.0-1.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,536 kB
  • ctags: 6,167
  • sloc: cpp: 45,854; ansic: 2,586; perl: 808; makefile: 125; sh: 104
file content (191 lines) | stat: -rw-r--r-- 4,223 bytes parent folder | download | duplicates (2)
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
/*    o_model.cpp
 *
 *    Copyright (c) 1994-1996, Marko Macek
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 *
 */

#include "fte.h"

EModel *ActiveModel = 0;
char msgbuftmp[MSGBUFTMP_SIZE] = "";

EModel *FindModelID(EModel *Model, int ID) {
    EModel *M = Model;
    int No = ID;

    while (M) {
        if (M->ModelNo == No)
            return M;
        M = M->Next;
        if (M == Model)
            break;
    }
    return 0;
}

int GetNewModelID(EModel *B) {
    static int lastid = -1;

    if (ReassignModelIds) lastid = 0;   // 0 is used by buffer list
    while (FindModelID(B, ++lastid) != 0) /* */;

    return lastid;
}

EModel::EModel(int createFlags, EModel **ARoot) {
    Root = ARoot;

    if (Root) {
        if (*Root) {
            if (createFlags & cfAppend) {
                Prev = *Root;
                Next = (*Root)->Next;
            } else {
                Next = *Root;
                Prev = (*Root)->Prev;
            }
            Prev->Next = this;
            Next->Prev = this;
        } else
            Prev = Next = this;

        if (!(createFlags & cfNoActivate))
            *Root = this;
    } else
        Prev = Next = this;
    View = 0;
    ModelNo = -1;
    ModelNo = GetNewModelID(this);
}

EModel::~EModel() {
    EModel *D = this;
    
    while (D) {
        D->NotifyDelete(this);
        D = D->Next;
        if (D == this)
            break;
    }
    
    if (Next != this) {
        Prev->Next = Next;
        Next->Prev = Prev;
        if (*Root == this)
            *Root = Next;
    } else
        *Root = 0;
}

void EModel::AddView(EView *V) {
    RemoveView(V);
    if (V) 
        V->NextView = View;
    View = V;
}

void EModel::RemoveView(EView *V) {
    EView **X = &View;
    
    if (!V) return;
    while (*X) {
        if ((*X) == V) {
            *X = V->NextView;
            return;
        }
        X = (&(*X)->NextView);
    }
}

void EModel::SelectView(EView *V) {
    RemoveView(V);
    AddView(V);
}

EViewPort *EModel::CreateViewPort(EView * /*V*/) {
    return 0;
}

int EModel::ExecCommand(int /*Command*/, ExState &/*State*/) {
    return ErFAIL;
}

void EModel::HandleEvent(TEvent &/*Event*/) {
}

void EModel::Msg(int level, const char *s, ...) {
    va_list ap;
    
    if (View == 0)
        return;
    
    va_start(ap, s);
    vsprintf(msgbuftmp, s, ap);
    va_end(ap);
    
    if (level != S_BUSY)
        View->SetMsg(msgbuftmp);
}

int EModel::CanQuit() {
    return 1;
}

int EModel::ConfQuit(GxView * /*V*/, int /*multiFile*/) {
    return 1;
}

int EModel::GetContext() { return CONTEXT_NONE; }
EEventMap *EModel::GetEventMap() { return 0; }
int EModel::BeginMacro() { return 1; }
void EModel::GetName(char *AName, int /*MaxLen*/) { *AName = 0; }
void EModel::GetPath(char *APath, int /*MaxLen*/) { *APath = 0; }
void EModel::GetInfo(char *AInfo, int /*MaxLen*/) { *AInfo = 0; }
void EModel::GetTitle(char *ATitle, int /*MaxLen*/, char *ASTitle, int /*SMaxLen*/) { *ATitle = 0; *ASTitle = 0; }
void EModel::NotifyPipe(int /*PipeId*/) { }

void EModel::NotifyDelete(EModel * /*Deleted*/) {
}
void EModel::DeleteRelated() {
}

EViewPort::EViewPort(EView *V) { View = V; ReCenter = 0; }
EViewPort::~EViewPort() {}
void EViewPort::HandleEvent(TEvent &/*Event*/) { }
void EViewPort::UpdateView() { }
void EViewPort::RepaintView() { }
void EViewPort::UpdateStatus() { }
void EViewPort::RepaintStatus() { }
void EViewPort::GetPos() { }
void EViewPort::StorePos() { }
void EViewPort::Resize(int /*Width*/, int /*Height*/) {}

void EModel::UpdateTitle() {
    char Title[256] = ""; //fte: ";
    char STitle[256] = ""; //"fte: ";
    EView *V;
    
    GetTitle((char *)(Title + 0), sizeof(Title) - 0,
             (char *)(STitle + 0), sizeof(STitle) - 0);

    V = View;
    while (V) {
        V->MView->Win->UpdateTitle(Title, STitle);
        V = V->NextView;
    }
}

int EModel::GetStrVar(int var, char *str, int buflen) {
    switch (var) {
    case mvCurDirectory:
        return GetDefaultDirectory(this, str, buflen);
    }
    return 0;
}

int EModel::GetIntVar(int /*var*/, int * /*value*/) {
    return 0;
}