int GFrame::AddView(GView *view) { if (Active != 0) { return ConSplitView(Active, view); } else { int W, H; view->Parent = this; view->Prev = view->Next = 0; view->Peer->wX = 0; if (ShowMenuBar) view->Peer->wY = 1; else view->Peer->wY = 0; ConQuerySize(&W, &H); if (ShowMenuBar) H--; if (ShowVScroll) W--; if (ShowHScroll) H--; view->ConSetSize(W, H); InsertView(Top, view); return 0; } }
void ExKey::RepaintStatus() { TDrawBuffer B; int W, H; ConQuerySize(&W, &H); MoveCh(B, ' ', 0x17, W); ConPutBox(0, H - 1, W, 1, B); }
int GView::ConClear() { int W, H; TDrawBuffer B; ConQuerySize(&W, &H); MoveChar(B, 0, W, ' ', 0x07, 1); ConSetBox(0, 0, W, H, B[0]); return 1; }
int SaveScreen() { if (SavedScreen) free(SavedScreen); ConQuerySize(&SavedX, &SavedY); SavedScreen = (PCell)malloc(SavedX * SavedY * sizeof(PCell)); if (SavedScreen) ConGetBox(0, 0, SavedX, SavedY, SavedScreen); ConQueryCursorPos(&SaveCursorPosX, &SaveCursorPosY); return 0; }
int ConClear() { int W, H; TDrawBuffer B; MoveChar(B, 0, ConMaxCols, ' ', 0x07, 1); if ((ConQuerySize(&W, &H) == 0) && ConSetBox(0, 0, W, H, B[0])) return 0; return -1; }
void ExComplete::RepaintStatus() { TDrawBuffer B; int W, H; // Currently use this fixed colors - maybe there are some better defines?? #define COM_NORM 0x17 #define COM_ORIG 0x1C #define COM_HIGH 0x1E #define COM_MARK 0x2E #define COM_ERR 0x1C ConQuerySize(&W, &H); MoveCh(B, ' ', COM_NORM, W); if ((WordsLast > 0) && (WordBegin != NULL) && (Words != NULL) && ((Words[WordPos]) != NULL)) { const char *sc = STRCOMPLETE; int p = sizeof(STRCOMPLETE) - 1; if (W < 35) { // if the width is quite small sc += p - 1; // jump to last character p = 1; } MoveStr(B, 0, W, sc, COM_NORM, W); // int cur = p; MoveStr(B, p, W, WordBegin, COM_ORIG, W); p += strlen(WordBegin); int l = strlen(Words[WordPos]); if (WordFixed > 0) { MoveStr(B, p, W, Words[WordPos], COM_MARK, W); p += WordFixed; l -= WordFixed; } MoveStr(B, p, W, Words[WordPos] + WordFixed, (WordFixedCount == 1) ? COM_ORIG : COM_HIGH, W); p += l; char s[100]; sprintf(s, "] (T:%d/%d S:%d)", WordPos + 1, WordsLast, (int)WordFixedCount); MoveStr(B, p, W, s, COM_NORM, W); // ConSetCursorPos(cur + WordFixed, H - 1); } else MoveStr(B, 0, W, STRNOCOMPLETE, COM_ERR, W); ConPutBox(0, H - 1, W, 1, B); ConShowCursor(); }
int GUI::RunProgram(int mode, char *Command) { int rc, W, H, W1, H1; ConQuerySize(&W, &H); ConHideMouse(); ConSuspend(); if ((Command == 0) || (*Command == 0)) // empty string = shell Command = getenv( "COMSPEC" ); rc = system(Command); ConContinue(); ConShowMouse(); ConQuerySize(&W1, &H1); if ((W != W1) || (H != H1)) { frames->Resize(W1, H1); } frames->Repaint(); return rc; }
static void DrawMouse(int Show) { if (!MousePresent) return; if (Show == 1) { MouDrawPtr(MouseHandle); } else { NOPTRRECT npr; int W, H; npr.row = 0; npr.col = 0; ConQuerySize(&W, &H); npr.cCol = (USHORT)(W - 1); npr.cRow = (USHORT)(H - 1); MouRemovePtr(&npr, MouseHandle); } }
int GFrame::ConSplitView(GView *view, GView *newview) { int dmy; newview->Parent = this; newview->Peer->wX = 0; ConQuerySize(&newview->Peer->wW, &dmy); if (ShowVScroll) newview->Peer->wW--; newview->Peer->wY = view->Peer->wY + view->Peer->wH / 2; newview->Peer->wH = view->Peer->wH - view->Peer->wH / 2; if (ShowHScroll) { newview->Peer->wY++; newview->Peer->wH--; } view->Peer->wH /= 2; view->ConSetSize(view->Peer->wW, view->Peer->wH); newview->ConSetSize(newview->Peer->wW, newview->Peer->wH); InsertView(view, newview); return 0; }
void ExISearch::RepaintStatus() { TDrawBuffer B; char s[MAXISEARCH + 1]; const char *p; int W, H; ConQuerySize(&W, &H); switch (state) { case INoMatch: p = " No Match. "; break; case INoPrev: p = " No Prev Match. "; break; case INoNext: p = " No Next Match. "; break; case IOk: default: p = ""; break; } sprintf(s, "ISearch [%s]%s", ISearchStr, p); MoveCh(B, ' ', 0x17, W); MoveStr(B, 0, W, s, 0x17, W); ConPutBox(0, H - 1, W, 1, B); ConSetCursorPos(strlen(s) - 1, H - 1); ConShowCursor(); }
void ExASCII::RepaintStatus() { TDrawBuffer B; int W, H; ConQuerySize(&W, &H); if (Pos > 255) Pos = 255; if (Pos < 0) Pos = 0; if (LPos + W < Pos) LPos = Pos - W + 1; if (LPos > 255 - W) LPos = 255 - W + 1; if (LPos > Pos) LPos = Pos; if (LPos < 0) LPos = 0; for (int i = 0; i < W; i++) MoveCh(B + i, char(i + LPos), hcAsciiChars, 1); ConSetCursorPos(Pos - LPos, H - 1); ConShowCursor(); ConPutBox(0, H - 1, W, 1, B); }
GFramePeer::GFramePeer(GFrame *aFrame, int Width, int Height) { Frame = aFrame; if (Width != -1 && Height != -1) ConSetSize(Width, Height); ConQuerySize(&fW, &fH); }
int GViewPeer::DrawScrollBar() { TDrawBuffer B; int NRows, NCols, I; int W, H; char fore = ConGetDrawChar(DCH_HFORE); char back = ConGetDrawChar(DCH_HBACK); ConQuerySize(&W, &H); if (ShowVScroll) { MoveCh(B, ConGetDrawChar(DCH_AUP), hcScrollBar_Arrows, 1); ConPutBox(W, 0, 1, 1, B); MoveCh(B, ConGetDrawChar(DCH_ADOWN), hcScrollBar_Arrows, 1); ConPutBox(W, H - 1, 1, 1, B); NRows = H - 2; if (sbVtotal <= NRows) { SbVBegin = 0; SbVEnd = NRows - 1; } else { SbVBegin = NRows * sbVstart / sbVtotal; SbVEnd = SbVBegin + NRows * sbVamount / sbVtotal; } for (I = 0; I < NRows; I++) { if (I >= SbVBegin && I <= SbVEnd) MoveCh(B, fore, hcScrollBar_Fore, 1); else MoveCh(B, back, hcScrollBar_Back, 1); ConPutBox(W, I + 1, 1, 1, B); } } if (ShowHScroll) { MoveCh(B, ConGetDrawChar(DCH_ALEFT), hcScrollBar_Arrows, 1); ConPutBox(0, H, 1, 1, B); MoveCh(B, ConGetDrawChar(DCH_ARIGHT), hcScrollBar_Arrows, 1); ConPutBox(W - 1, H, 1, 1, B); NCols = W - 2; if (sbHtotal <= NCols) { SbHBegin = 0; SbHEnd = NCols - 1; } else { SbHBegin = NCols * sbHstart / sbHtotal; SbHEnd = SbHBegin + NCols * sbHamount / sbHtotal; } // could be made faster for (I = 0; I < NCols; I++) { if (I >= SbHBegin && I <= SbHEnd) MoveCh(B, fore, hcScrollBar_Fore, 1); else MoveCh(B, back, hcScrollBar_Back, 1); ConPutBox(I + 1, H, 1, 1, B); } } if (ShowVScroll && ShowHScroll) { MoveCh(B, ' ', hcScrollBar_Arrows, 1); ConPutBox(W, H, 1, 1, B); } return 0; }
void GUI::ProcessEvent() { TEvent E; E = NextEvent; if (E.What != evNone) { NextEvent.What = evNone; } if (E.What == evNone && (ConGetEvent(evMouse | evCommand | evKeyboard, &E, 0, 1, 0) == -1 || E.What == evNone) ) { frames->Update(); while (ConGetEvent(evMouse | evCommand | evKeyboard, &E, -1, 1, 0) == -1 || (E.What == evMouseMove && E.Mouse.Buttons == 0)); } if (E.What != evNone) { GView *view = frames->Active; if (E.What & evMouse) { if (E.What == evMouseDown && E.Mouse.Y == 0 && ShowMenuBar && MouseCapture == 0 && FocusCapture == 0) { frames->Update(); // sync before menu if (ExecMainMenu(E, 0) == -1) { if (E.What == evCommand && E.Msg.Command == cmResize) { int X, Y; ConQuerySize(&X, &Y); frames->Resize(X, Y); } E.What = evNone; } // fprintf(stderr, "Command got = %d\n", E.Msg.Command); } if (E.What == evMouseDown && MouseCapture == 0 && FocusCapture == 0) { GView *V = frames->Active; while (V) { if (E.Mouse.Y >= V->Peer->wY && E.Mouse.Y < V->Peer->wY + V->Peer->wH + (ShowHScroll ? 1 : 0)) { frames->SelectView(V); view = V; break; } V = V->Next; if (V == frames->Active) break; } } if (ShowVScroll && ShowHScroll && E.What == evMouseDown && MouseCapture == 0 && FocusCapture == 0 && E.Mouse.Y == view->Peer->wY + view->Peer->wH && E.Mouse.X == view->Peer->wX + view->Peer->wW) { } else { if (ShowVScroll && E.What == evMouseDown && MouseCapture == 0 && FocusCapture == 0 && E.Mouse.X == view->Peer->wX + view->Peer->wW) { HandleVScroll(view, E); return ; } if (ShowHScroll && E.What == evMouseDown && MouseCapture == 0 && FocusCapture == 0 && E.Mouse.Y == view->Peer->wY + view->Peer->wH) { HandleHScroll(view, E); return ; } } if (E.What & evMouse) { E.Mouse.Y -= view->Peer->wY; E.Mouse.X -= view->Peer->wX; } } if (E.What == evCommand) { switch (E.Msg.Command) { case cmResize: { int X, Y; ConQuerySize(&X, &Y); frames->Resize(X, Y); } break; case cmMainMenu: { char Sub = (char)E.Msg.Param1; frames->Update(); // sync before menu if (::ExecMainMenu(E, Sub) != 1) { ; if (E.What == evCommand && E.Msg.Command == cmResize) { int X, Y; ConQuerySize(&X, &Y); frames->Resize(X, Y); } E.What = evNone; } } break; case cmPopupMenu: { int id = E.Msg.Param1; int Cols, Rows; if (id == -1) return; frames->ConQuerySize(&Cols, &Rows); int x = Cols / 2, y = Rows / 2; ConQueryMousePos(&x, &y); frames->Update(); // sync before menu if (::ExecVertMenu(x, y, id, E, 0) != 1) { if (E.What == evCommand && E.Msg.Command == cmResize) { int X, Y; ConQuerySize(&X, &Y); frames->Resize(X, Y); } E.What = evNone; } } break; } } if (E.What != evNone) DispatchEvent(frames, view, E); } }
void ExASCII::HandleEvent(TEvent& Event) { int W, H; ConQuerySize(&W, &H); switch (Event.What) { case evKeyDown: switch (kbCode(Event.Key.Code)) { case kbLeft: Pos--; Event.What = evNone; break; case kbRight: Pos++; Event.What = evNone; break; case kbHome: Pos = 0; Event.What = evNone; break; case kbEnd: Pos = 255; Event.What = evNone; break; case kbLeft + kfCtrl: Pos -= 16; Event.What = evNone; break; case kbRight + kfCtrl: Pos += 16; Event.What = evNone; break; case kbUp: Pos -= W; LPos -= W; Event.What = evNone; break; case kbDown: Pos += W; LPos += W; Event.What = evNone; break; case kbEsc: EndExec(-1); Event.What = evNone; break; case kbEnter: EndExec(Pos); Event.What = evNone; break; } break; #if 0 case evMouseDown: if ((E.Mouse.X < XPos) || (E.Mouse.X >= XPos + 34) || (E.Mouse.Y < YPos) || (E.Mouse.Y >= YPos + 10)) { abort = 2; break; } do { x = E.Mouse.X - XPos - 1; y = E.Mouse.Y - YPos - 1; if ((x >= 0) && (x < 32) && (y >= 0) && (y < 8)) { X = x; Y = y; if (X >= 32) X = 31; if (Y >= 8) Y = 7; if (X < 0) X = 0; if (Y < 0) Y = 0; frames->ConSetCursorPos(X + XPos + 1, Y + YPos + 1); sprintf(s, "0%03o %03d 0x%02X", X + Y * 32, X + Y * 32, X + Y * 32); MoveStr(B, 0, 13, s, hcAsciiStatus, 13); frames->ConPutBox(XPos + 2, YPos + 9, 13, 1, B); } if (E.Mouse.Count == 2) { abort = 1; break; } gui->ConGetEvent(evMouse, &E, -1, 1); if (E.What == evMouseUp) break; } while (1); break; #endif // if 0 } }