diff --git a/.gitignore b/.gitignore index e69de29..62c8935 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7e71fd9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.31) +project(Pilgrim) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/tvision/CMakeLists.txt") + add_subdirectory(lib/tvision) +else() + message(FATAL_ERROR "TVision submodule não encontrado em lib/tvision") +endif() + +add_executable(Pilgrim src/main.cpp + src/PilgrimApp.cpp + src/PilgrimApp.h + src/MainWindow.cpp + src/MainWindow.h +) +target_link_libraries(${PROJECT_NAME} tvision) +if(UNIX) + target_link_libraries(${PROJECT_NAME} ncurses) +endif() + +# Para debug +set(CMAKE_BUILD_TYPE Debug) +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") +endif() \ No newline at end of file diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp new file mode 100644 index 0000000..e21b480 --- /dev/null +++ b/src/MainWindow.cpp @@ -0,0 +1,103 @@ +#include "MainWindow.h" +#include +#include + +MainWindow::MainWindow(TRect bounds, const char* title, int windowNo) + : TWindow(bounds, title, windowNo), + TWindowInit(&TWindow::initFrame), + listBox(nullptr), + scrollBar(nullptr), + strings(nullptr), + windowNumber(windowNo) { + + options |= ofTileable; + setupInterior(); +} + +MainWindow::~MainWindow() { + if (strings) { + destroy(strings); + strings = nullptr; + } +} + +void MainWindow::close() { + destroy(this); +} + +void MainWindow::setupInterior() { + // Criar a coleção de strings + strings = new TStringCollection(20, 5); + + // Adicionar itens usando newStr para gerenciamento automático de memória + strings->insert(newStr("Arquivo de configuração")); + strings->insert(newStr("Dados do usuário")); + strings->insert(newStr("Log de sistema")); + strings->insert(newStr("Backup automático")); + strings->insert(newStr("Cache temporário")); + strings->insert(newStr("Documentos recentes")); + strings->insert(newStr("Preferências")); + strings->insert(newStr("Histórico de comandos")); + strings->insert(newStr("Plugins instalados")); + strings->insert(newStr("Templates disponíveis")); + strings->insert(newStr("Macros personalizadas")); + strings->insert(newStr("Filtros ativos")); + strings->insert(newStr("Conexões de rede")); + strings->insert(newStr("Drivers de dispositivo")); + strings->insert(newStr("Atualizações pendentes")); + + // Obter as dimensões internas da janela + TRect interiorBounds = getExtent(); + interiorBounds.grow(-1, -1); + + // Criar scrollbar vertical + TRect scrollBarBounds = interiorBounds; + scrollBarBounds.a.x = scrollBarBounds.b.x - 1; + scrollBar = new TScrollBar(scrollBarBounds); + insert(scrollBar); + + // Criar listbox + TRect listBoxBounds = interiorBounds; + listBoxBounds.b.x = scrollBarBounds.a.x; + listBox = new TListBox(listBoxBounds, 1, scrollBar); + listBox->newList(strings); + insert(listBox); + + // Focar no listbox + listBox->select(); +} + +void MainWindow::handleEvent(TEvent& event) { + TWindow::handleEvent(event); + + if (event.what == evKeyDown) { + switch (event.keyDown.keyCode) { + case kbEnter: + if (listBox && listBox->focused >= 0) { + char* selectedItem = (char*)strings->at(listBox->focused); + if (selectedItem) { + char message[256]; + sprintf(message, "Item selecionado: %s\n\nJanela: %d", + selectedItem, windowNumber); + messageBox(message, mfInformation | mfOKButton); + } + } + clearEvent(event); + break; + + case kbEsc: + close(); + clearEvent(event); + break; + } + } + + if (event.what == evCommand) { + switch (event.message.command) { + case cmClose: + close(); + clearEvent(event); + break; + } + } +} \ No newline at end of file diff --git a/src/MainWindow.h b/src/MainWindow.h new file mode 100644 index 0000000..2870bde --- /dev/null +++ b/src/MainWindow.h @@ -0,0 +1,57 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#define Uses_TKeys +#define Uses_TApplication +#define Uses_TEvent +#define Uses_TRect +#define Uses_TDialog +#define Uses_TStaticText +#define Uses_TButton +#define Uses_TMenuBar +#define Uses_TSubMenu +#define Uses_TMenuItem +#define Uses_TStatusLine +#define Uses_TStatusItem +#define Uses_TStatusDef +#define Uses_TDeskTop +#define Uses_TView +#define Uses_TWindow +#define Uses_TFrame +#define Uses_TScrollBar +#define Uses_TListBox +#define Uses_TCollection +#define Uses_TStringCollection +#define Uses_MsgBox +#define Uses_TProgram +#define Uses_TMenu +#define Uses_TWindowInit + +#include + +const int cmNewWindow = 100; +const int cmOpenFile = 101; +const int cmCalculator = 104; +const int cmCalendar = 105; +const int cmAsciiTable = 107; +const int cmAbout = 109; + + +class MainWindow : public TWindow { +public: + MainWindow(TRect bounds, const char* title, int windowNo); + ~MainWindow(); + + void handleEvent(TEvent& event) override; + void close() override; + +private: + void setupInterior(); + + TListBox* listBox; + TScrollBar* scrollBar; + TStringCollection* strings; + int windowNumber; +}; + +#endif // MAINWINDOW_H \ No newline at end of file diff --git a/src/PilgrimApp.cpp b/src/PilgrimApp.cpp new file mode 100644 index 0000000..1331f1c --- /dev/null +++ b/src/PilgrimApp.cpp @@ -0,0 +1,136 @@ +#include "PilgrimApp.h" +#include +#include +#include + +PilgrimApp::PilgrimApp() : + TProgInit(&PilgrimApp::initStatusLine, + &PilgrimApp::initMenuBar, + &PilgrimApp::initDeskTop), + TApplication(), + windowCount(0) { +} + +TMenuBar* PilgrimApp::initMenuBar(TRect bounds) { + bounds.b.y = bounds.a.y + 1; + + return new TMenuBar(bounds, + *new TSubMenu("~≡~", 0, hcNoContext) + + *new TMenuItem("~A~bout...", cmAbout, kbNoKey, hcNoContext, "F1") + + newLine() + + *new TMenuItem("~N~ew", cmNewWindow, kbF4, hcNoContext, "F4") + + *new TMenuItem("~O~pen...", cmOpenFile, kbF3, hcNoContext, "F3") + + newLine() + + *new TMenuItem("~D~OS Shell", cmDosShell, kbNoKey, hcNoContext) + + newLine() + + *new TMenuItem("E~x~it", cmQuit, kbAltX, hcNoContext, "Alt+X") + + *new TSubMenu("~W~indow", 0, hcNoContext) + + *new TMenuItem("~T~ile", cmTile, kbF5, hcNoContext, "F5") + + *new TMenuItem("C~a~scade", cmCascade, kbF4, hcNoContext, "Shift+F5") + ); +} + +TStatusLine* PilgrimApp::initStatusLine(TRect bounds) { + bounds.a.y = bounds.b.y - 1; + + return new TStatusLine(bounds, + *new TStatusDef(0, 0xFFFF) + + *new TStatusItem("~F1~ Ajuda", kbF1, cmAbout) + + *new TStatusItem("~F3~ Abrir", kbF3, cmOpenFile) + + *new TStatusItem("~F4~ Nova", kbF4, cmNewWindow) + + *new TStatusItem("~F5~ Organizar", kbF5, cmTile) + + *new TStatusItem("~Alt+X~ Sair", kbAltX, cmQuit) + ); +} + +void PilgrimApp::handleEvent(TEvent& event) { + TApplication::handleEvent(event); + + if (event.what == evCommand) { + switch (event.message.command) { + case cmNewWindow: + newWindow(); + clearEvent(event); + break; + + case cmOpenFile: + openFile(); + clearEvent(event); + break; + + case cmTile: + tile(); + clearEvent(event); + break; + + case cmCascade: + cascade(); + clearEvent(event); + break; + + case cmAbout: + about(); + clearEvent(event); + break; + + case cmDosShell: + dosShell(); + clearEvent(event); + break; + + default: + return; + } + } +} + +void PilgrimApp::idle() { + TApplication::idle(); + // Aqui você pode adicionar processamento em background +} + +void PilgrimApp::newWindow() { + windowCount++; + char windowTitle[50]; + sprintf(windowTitle, "Pilgrim - Janela %d", windowCount); + + TRect bounds = deskTop->getExtent(); + bounds.grow(-1, -1); + bounds.move(windowCount % 5, (windowCount % 5) + 1); + bounds.b.x = bounds.a.x + 50; + bounds.b.y = bounds.a.y + 18; + + MainWindow* window = new MainWindow(bounds, windowTitle, windowCount); + deskTop->insert(window); +} + +void PilgrimApp::openFile() { + messageBox("Funcionalidade 'Abrir Arquivo' ainda não implementada.\n\n" + "Esta será uma funcionalidade futura do Pilgrim.", + mfInformation | mfOKButton); +} + +void PilgrimApp::tile() { + deskTop->tile(deskTop->getExtent()); +} + +void PilgrimApp::cascade() { + deskTop->cascade(deskTop->getExtent()); +} + +void PilgrimApp::about() { + messageBox("\003Pilgrim v1.0\n\n" + "\003Aplicação de demonstração\n" + "\003usando Turbo Vision\n\n" + "\003Desenvolvido com C++\n" + "\003e biblioteca TUI moderna", + mfInformation | mfOKButton); +} + +void PilgrimApp::dosShell() { + suspend(); + std::cout << "Digite 'exit' para retornar ao Pilgrim." << std::endl; + system(getenv("COMSPEC") ? getenv("COMSPEC") : "/bin/sh"); + resume(); + redraw(); +} \ No newline at end of file diff --git a/src/PilgrimApp.h b/src/PilgrimApp.h new file mode 100644 index 0000000..38c68e7 --- /dev/null +++ b/src/PilgrimApp.h @@ -0,0 +1,49 @@ +#ifndef PILGRIMAPP_H +#define PILGRIMAPP_H + +#define Uses_TKeys +#define Uses_TApplication +#define Uses_TEvent +#define Uses_TRect +#define Uses_TDialog +#define Uses_TStaticText +#define Uses_TButton +#define Uses_TMenuBar +#define Uses_TSubMenu +#define Uses_TMenuItem +#define Uses_TStatusLine +#define Uses_TStatusItem +#define Uses_TStatusDef +#define Uses_TDeskTop +#define Uses_TView +#define Uses_TWindow +#define Uses_TFrame +#define Uses_MsgBox +#define Uses_TMenu +#define Uses_TProgram + +#include +#include "MainWindow.h" + +class PilgrimApp : public TApplication { +public: + PilgrimApp(); + + static TMenuBar* initMenuBar(TRect bounds); + static TStatusLine* initStatusLine(TRect bounds); + + void handleEvent(TEvent& event) override; + void idle() override; + +private: + void newWindow(); + void openFile(); + void tile(); + void cascade(); + void about(); + void dosShell(); + + int windowCount; +}; + +#endif // PILGRIMAPP_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..de7f3d4 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,29 @@ +#define Uses_TKeys +#define Uses_TApplication +#define Uses_TEvent +#define Uses_TRect +#define Uses_TDialog +#define Uses_TStaticText +#define Uses_TButton +#define Uses_TMenuBar +#define Uses_TSubMenu +#define Uses_TMenuItem +#define Uses_TStatusLine +#define Uses_TStatusItem +#define Uses_TStatusDef +#define Uses_TDeskTop +#define Uses_TView +#define Uses_TWindow +#define Uses_TFrame +#define Uses_MsgBox +#define Uses_TMenu +#define Uses_TProgram + +#include +#include "PilgrimApp.h" + +int main() { + PilgrimApp app; + app.run(); + return 0; +} \ No newline at end of file