### Common Application Setup Source: https://github.com/magiblot/tvision/blob/master/examples/CMakeLists.txt Sets up common configurations for an application, including output directory, private includes, warnings, optimization, and installation rules. It handles target installation for CMake versions prior to 3.13. ```cmake function(tv_app_common app) tv_set_output_dir(${app}) tv_add_private_includes(${app}) tv_set_warnings(${app}) tv_app_optimize(${app}) # Until CMake 3.13, 'install' only accepts targets defined # in the current directory. So install from this function. if (${app} IN_LIST TVINSTALLAPPS) install(TARGETS ${app} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endfunction() ``` -------------------------------- ### Install Project Includes Source: https://github.com/magiblot/tvision/blob/master/source/CMakeLists.txt Installs the project's header files. This makes the library's API accessible to users of the installed package. ```cmake install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/tvision" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ``` -------------------------------- ### Build Examples Option Source: https://github.com/magiblot/tvision/blob/master/CMakeLists.txt Defines an option to control whether example applications are built, dependent on the MASTER_PROJECT variable. ```cmake if (MASTER_PROJECT) option(TV_BUILD_EXAMPLES "Build example apps" ON) endif() ``` -------------------------------- ### Build and Install Turbo Vision (Multi-config) Source: https://github.com/magiblot/tvision/blob/master/README.md For multi-config generators (e.g., Visual Studio, Ninja Multi-Config), build and install all configurations. Specific components like 'library' can be installed. ```sh cmake . -B ./build cmake --build ./build --config Release cmake --build ./build --config Debug --target tvision cmake --build ./build --config RelWithDebInfo --target tvision cmake --build ./build --config MinSizeRel --target tvision cmake --install ./build --config Release cmake --install ./build --config Debug --component library cmake --install ./build --config RelWithDebInfo --component library cmake --install ./build --config MinSizeRel --component library ``` -------------------------------- ### Install Turbo Vision with Vcpkg Source: https://github.com/magiblot/tvision/blob/master/README.md Steps to clone the vcpkg repository, bootstrap it, integrate it with your system, and install the Turbo Vision package. ```sh git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install tvision ``` -------------------------------- ### TColorAttr Initialization Examples Source: https://github.com/magiblot/tvision/blob/master/README.md Demonstrates creating TColorAttr objects with different foreground, background, and style combinations. ```c++ // Foreground: RGB 0x892312 // Background: RGB 0x7F00BB // Style: Normal. TColorAttr a1 = {TColorRGB(0x89, 0x23, 0x12), TColorRGB(0x7F, 0x00, 0xBB)}; ``` ```c++ // Foreground: BIOS 0x7. // Background: RGB 0x7F00BB. // Style: Bold, Italic. TColorAttr a2 = {'\x7', 0x7F00BB, slBold | slItalic}; ``` ```c++ // Foreground: Terminal default. // Background: BIOS 0xF. // Style: Normal. TColorAttr a3 = {{}, TColorBIOS(0xF)}; ``` ```c++ // Foreground: Terminal default. // Background: Terminal default. // Style: Normal. TColorAttr a4 = {}; ``` ```c++ // Foreground: BIOS 0x0 // Background: BIOS 0x7 // Style: Normal TColorAttr a5 = 0x70; ``` -------------------------------- ### Install Project Configuration Source: https://github.com/magiblot/tvision/blob/master/source/CMakeLists.txt Installs the project's CMake configuration files. This allows other projects to find and use this project via CMake's find_package. ```cmake install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} NAMESPACE ${PROJECT_NAME}:: FILE ${PROJECT_NAME}-config.cmake COMPONENT library ) ``` -------------------------------- ### Build and Install Turbo Vision (Mono-config) Source: https://github.com/magiblot/tvision/blob/master/README.md Use these commands to build and install Turbo Vision when using mono-config CMake generators like 'Unix Makefiles' or 'Ninja'. The install prefix can be overridden with CMAKE_INSTALL_PREFIX. ```sh cmake . -B ./build cmake --build ./build cmake --install ./build ``` -------------------------------- ### TColorRGB Usage Examples Source: https://github.com/magiblot/tvision/blob/master/README.md Shows initialization, bitwise operations, and component access for TColorRGB. ```c++ TColorRGB rgb = 0x9370DB; // 0xRRGGBB. rgb = {0x93, 0x70, 0xDB}; // {R, G, B}. rgb = rgb ^ 0xFFFFFF; // Negated. rgb.g = rgb.r & 0x88; // Access to individual components. uint32_t c = rgb; // Implicit conversion to integer types. ``` -------------------------------- ### TColorDesired Initialization Examples Source: https://github.com/magiblot/tvision/blob/master/README.md Illustrates various ways to initialize TColorDesired using BIOS, RGB, and default colors. ```c++ TColorDesired bios1 = '\xF'; TColorDesired bios2 = TColorBIOS(0xF); ``` ```c++ TColorDesired rgb1 = 0xFF7700; // 0xRRGGBB. TColorDesired rgb2 = TColorRGB(0xFF, 0x77, 0x00); // {R, G, B}. TColorDesired rgb3 = TColorRGB(0xFF7700); // 0xRRGGBB. ``` ```c++ TColorDesired def1 {}; // Or with 'memset': TColorDesired def2; memset(&def2, 0, sizeof(def2)); ``` -------------------------------- ### Add Subdirectories for Build Source: https://github.com/magiblot/tvision/blob/master/CMakeLists.txt Includes subdirectories for building the main library, examples, and tests. ```cmake # Library add_subdirectory(source) # Examples add_subdirectory(examples) # Test add_subdirectory(test) ``` -------------------------------- ### Tvision Palette Structure Example Source: https://github.com/magiblot/tvision/blob/master/examples/palette/README.md This example visualizes the hierarchical structure of palettes for different Tvision components like TTestView, TTestWindow, and TTestApp. It shows how color indices map across these components. ```text x01 x02 x03 x04 x05 x06 ┌────────────────────┬─────┬─────┬─────┬─────┬─────┬─────┐ │TTestView │ x09 │ x0A │ x0B │ x0C │ x0D │ x0E │ └────────────────────┴─────┴─────┴─────┴─────┴─────┴─────┘ ▼ ▼ ▼ ▼ ▼ ▼ x01-x08 x09 x0A x0B x0C x0D x0E ┌────────────┬───────┬─────┬─────┬─────┬─────┬─────┬─────┐ │TTestWindow │ ... │ x88 │ x89 │ x8A │ x8B │ x8C │ x8D │ └────────────┴───────┴─────┴─────┴─────┴─────┴─────┴─────┘ ▼ ▼ ▼ ▼ ▼ ▼ x01-x87 x88 x89 x8A x8B x8C x8D ┌────────────┬───────┬─────┬─────┬─────┬─────┬─────┬─────┐ │TTestApp │ ... │ x3E │ x2D │ x72 │ x5F │ x68 │ x4E │ └────────────┴───────┴─────┴─────┴─────┴─────┴─────┴─────┘ Table I ``` -------------------------------- ### TColorBIOS Usage Examples Source: https://github.com/magiblot/tvision/blob/master/README.md Demonstrates manipulation of individual color bits and implicit conversion for TColorBIOS. ```c++ TColorBIOS bios = 0x4; // 0x4: red. bios.bright = 1; // 0xC: light red. bios.b = bios.r; // 0xD: light magenta. bios = bios ^ 3; // 0xE: yellow. uint8_t c = bios; // Implicit conversion to integer types. ``` -------------------------------- ### Equivalent mapColor Calls for TMenuBar Colors Source: https://github.com/magiblot/tvision/blob/master/README.md This example shows the equivalent calls to `mapColor` that would produce the same `TAttrPair` results as the `getColor` calls in the `TMenuBar` example. ```c++ TAttrPair cNormal = {mapColor(1), mapColor(3)}; TAttrPair cSelect = {mapColor(4), mapColor(6)}; ``` -------------------------------- ### Key Shortcut Input Example Source: https://github.com/magiblot/tvision/blob/master/README.md Demonstrates the `KeyDownEvent` structure when a key shortcut (like Ctrl+K) is pressed. In this case, the `text` field is empty and `textLength` is 0, as no character input is associated with the shortcut. ```cpp KeyDownEvent { union { .keyCode = 0xB (kbCtrlK), .charScan = CharScanType { .charCode = 11 ('\u2663'), .scanCode = 0 } }, .controlKeyState = 0x20C (kbCtrlShift | kbInsState), .text = {}, .textLength = 0 } ``` -------------------------------- ### Modifying Application Palette Elements Source: https://github.com/magiblot/tvision/blob/master/README.md This example shows how to modify the application's palette directly after it has been built. Each element in the palette is a `TColorAttr`. ```c++ void updateAppPalette() { TPalette &pal = TProgram::application->getPalete(); pal[1] = {0x762892, 0x828712}; // TBackground. pal[2] = {0x874832, 0x249838, slBold}; // TMenuView normal text. pal[3] = {{}, {}, slItalic | slUnderline}; // TMenuView disabled text. /* ... */ } ``` -------------------------------- ### Custom TView Label Implementation Source: https://context7.com/magiblot/tvision/llms.txt This example demonstrates creating a custom view by subclassing TView. It overrides draw() for custom rendering and handleEvent() to react to mouse clicks. Usage is shown within a TDialog. ```cpp #define Uses_TView #define Uses_TDrawBuffer #define Uses_TEvent #define Uses_TRect #define Uses_TColorAttr #include class TMyLabel : public TView { const char* text; public: TMyLabel(const TRect& bounds, const char* aText) : TView(bounds), text(aText) {} virtual void draw() override { TColorAttr color = {0xFFFFFF, 0x000080}; // white on navy (RGB) TDrawBuffer buf; buf.moveChar(0, ' ', color, (ushort)size.x); // fill background buf.moveStr(0, text, color); // draw label text writeLine(0, 0, size.x, size.y, buf); } virtual void handleEvent(TEvent& ev) override { TView::handleEvent(ev); if (ev.what == evMouseDown && containsMouse(ev)) { // React to click message(owner, evBroadcast, cmOK, nullptr); clearEvent(ev); } } }; // Usage inside a TDialog::init(): // dialog->insert(new TMyLabel(TRect(2, 2, 30, 3), "Custom label")); ``` -------------------------------- ### Define Application Lists Source: https://github.com/magiblot/tvision/blob/master/examples/CMakeLists.txt Appends applications to the TVAPPS and TVINSTALLAPPS lists. TVAPPS contains all applications to be built, while TVINSTALLAPPS specifies which applications should be installed. ```cmake list(APPEND TVAPPS tvedit tvdemo tvdir tvforms tvhc mmenu palette) list(APPEND TVINSTALLAPPS tvedit tvdemo tvhc) ``` -------------------------------- ### TMenuBar Color Attribute Query Example Source: https://github.com/magiblot/tvision/blob/master/README.md This example demonstrates how `getColor` is used in the `draw` method of `TMenuBar` to query color attributes for normal and selected states. ```c++ TAttrPair cNormal = getColor(0x0301); TAttrPair cSelect = getColor(0x0604); ``` -------------------------------- ### Defining Custom Application Palette Array Source: https://github.com/magiblot/tvision/blob/master/README.md This example defines a constant array of `TColorAttr` to be used for creating a custom application palette. ```c++ static const TColorAttr cpMyApp[] = { {0x762892, 0x828712}, // TBackground. {0x874832, 0x249838, slBold}, // TMenuView normal text. {{}, {}, slItalic | slUnderline}, // TMenuView disabled text. /* ... */ }; ``` -------------------------------- ### TScrollBar Palette Layout Example Source: https://github.com/magiblot/tvision/blob/master/README.md This example shows the palette layout for the TScrollBar class as defined in the Turbo Vision headers, indicating indices for different parts of the scroll bar. ```c++ /* * ---------------------------------------------------------------------- * class TScrollBar * * Palette layout * 1 = Page areas * 2 = Arrows * 3 = Indicator * ---------------------------------------------------------------------- */ ``` -------------------------------- ### Unicode Input Example: '€' Source: https://github.com/magiblot/tvision/blob/master/README.md Shows the `KeyDownEvent` structure for the Euro symbol '€'. Since '€' is not in CP437, `keyCode` is `kbNoKey` and `charScan.charCode` is 0. The `text` field holds the UTF-8 sequence ('\xE2', '\x82', '\xAC') with `textLength` as 3. ```cpp KeyDownEvent { union { .keyCode = 0x0 (kbNoKey), // '€' not part of CP437 .charScan = CharScanType { .charCode = 0, .scanCode = 0 } }, .controlKeyState = 0x200 (kbInsState), .text = {'\xE2', '\x82', '\xAC'}, // In UTF-8 .textLength = 3 } ``` -------------------------------- ### Build Turbo Vision with MinGW Source: https://github.com/magiblot/tvision/blob/master/README.md Build Turbo Vision using CMake with MinGW Makefiles. The build type can be set to 'Release' or other CMake build types. Examples are included if TV_BUILD_EXAMPLES is ON. ```sh cmake . -B ./build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release && cmake --build ./build ``` -------------------------------- ### Unicode Input Example: 'ñ' Source: https://github.com/magiblot/tvision/blob/master/README.md Illustrates the structure of a `KeyDownEvent` when the character 'ñ' is typed. The `text` field contains the UTF-8 representation ('\xC3', '\xB1') and `textLength` is 2. `keyCode` reflects the CP437 value. ```cpp KeyDownEvent { union { .keyCode = 0xA4, .charScan = CharScanType { .charCode = 164 ('ñ'), // In CP437 .scanCode = 0 } }, .controlKeyState = 0x200 (kbInsState), .text = {'\xC3', '\xB1'}, // In UTF-8 .textLength = 2 } ``` -------------------------------- ### Import Turbo Vision with find_package Source: https://github.com/magiblot/tvision/blob/master/README.md In your application's CMakeLists.txt, use find_package to locate Turbo Vision and then link your application against the tvision::tvision target. ```cmake find_package(tvision CONFIG) target_link_libraries(my_application tvision::tvision) ``` -------------------------------- ### Construct a TDialog with Input Widgets Source: https://context7.com/magiblot/tvision/llms.txt Builds a modal dialog box with various input elements including labels, input lines, radio buttons, checkboxes, and standard OK/Cancel buttons. Use deskTop->execView() to display the dialog and check its return value. ```cpp #define Uses_TDialog #define Uses_TInputLine #define Uses_TButton #define Uses_TLabel #define Uses_TCheckBoxes #define Uses_TRadioButtons #define Uses_TSItem #define Uses_TRect #include void showSettingsDialog() { TDialog* d = new TDialog(TRect(10, 3, 70, 22), "Settings"); // Label + input line d->insert(new TLabel(TRect(2, 3, 12, 4), "~N~ame:", nullptr)); TInputLine* nameInput = new TInputLine(TRect(12, 3, 56, 4), 256); d->insert(nameInput); // Input limited to 10 visible columns (Unicode-aware) TInputLine* shortInput = new TInputLine( TRect(12, 5, 22, 6), 10, nullptr, ilMaxWidth); d->insert(shortInput); // Radio buttons d->insert(new TRadioButtons(TRect(2, 7, 30, 10), new TSItem("~D~ark theme", new TSItem("~L~ight theme", new TSItem("~S~ystem default", nullptr)))))); // Check boxes d->insert(new TCheckBoxes(TRect(2, 11, 40, 14), new TSItem("~E~nable notifications", new TSItem("~A~uto-save", nullptr)))); // Buttons d->insert(new TButton(TRect(12, 15, 24, 17), "~O~K", cmOK, bfDefault)); d->insert(new TButton(TRect(26, 15, 38, 17), "~C~ancel", cmCancel, bfNormal)); // Pre-fill input strcpy(nameInput->data, "Alice"); if (deskTop->execView(d) == cmOK) { // nameInput->data contains the user's entry } destroy(d); } ``` -------------------------------- ### Enabling Application-Wide Clipboard Usage Source: https://github.com/magiblot/tvision/blob/master/README.md Demonstrates how to set up an application to use clipboard commands like Cut, Copy, and Paste with standard views such as TEditor and TInputLine. ```APIDOC ## Enabling application-wide clipboard usage ### Description The standard views `TEditor` and `TInputLine` react to the `cmCut`, `cmCopy` and `cmPaste` commands. However, your application first has to be set up to use these commands. For example: ### Example ```cpp TStatusLine *TMyApplication::initStatusLine( TRect r ) { r.a.y = r.b.y - 1; return new TStatusLine( r, *new TStatusDef( 0, 0xFFFF ) + // ... *new TStatusItem( 0, kbCtrlX, cmCut ) + *new TStatusItem( 0, kbCtrlC, cmCopy ) + *new TStatusItem( 0, kbCtrlV, cmPaste ) + // ... ); } ``` `TEditor` and `TInputLine` automatically enable and disable these commands. For example, if a `TEditor` or `TInputLine` is focused, the `cmPaste` command will be enabled. If there is selected text, the `cmCut` and `cmCopy` commands will also be enabled. If no `TEditor` or `TInputLine`s are focused, then these commands will be disabled. ``` -------------------------------- ### Compile a Turbo Vision Application with GCC Source: https://github.com/magiblot/tvision/blob/master/README.md Minimal command line to build a Turbo Vision application like hello.cpp using GCC. Includes necessary flags for standard, output, library path, and ncursesw/gpm support. ```sh g++ -std=c++14 -o hello hello.cpp ./build/libtvision.a -Iinclude -lncursesw -lgpm ``` -------------------------------- ### TAttrPair Constructor and Usage Source: https://github.com/magiblot/tvision/blob/master/README.md Demonstrates how to initialize a TAttrPair using its constructor and use it with TDrawBuffer. ```APIDOC ## TAttrPair Constructor ### Description Initializes a TAttrPair with two TColorAttrs. ### Method `TAttrPair(const TColorAttrs &lo, const TColorAttrs &hi)` ### Parameters - **lo** (const TColorAttrs &) - The lower attribute pair. - **hi** (const TColorAttrs &) - The higher attribute pair. ### Request Example ```c++ TColorAttr cNormal = {0x234983, 0x267232}; TColorAttr cHigh = {0x309283, 0x127844}; TAttrPair attrs = {cNormal, cHigh}; TDrawBuffer b; b.moveCStr(0, "Normal text, ~Highlighted text~", attrs); ``` ``` -------------------------------- ### TView Get Event with Timeout Source: https://github.com/magiblot/tvision/blob/master/README.md Allows waiting for an event with a user-provided timeout, overriding the default TProgram::eventTimeoutMs. ```c++ void TView::getEvent(TEvent &, int timeoutMs) ``` -------------------------------- ### Minimal Turbo Vision Application Bootstrap Source: https://context7.com/magiblot/tvision/llms.txt This snippet shows the basic structure for a Turbo Vision application using TApplication. It includes initialization of the menu bar, status line, and desktop, and demonstrates handling custom commands. ```cpp #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 #include const int cmGreet = 100; class TMyApp : public TApplication { public: TMyApp() : TProgInit(&TMyApp::initStatusLine, &TMyApp::initMenuBar, &TMyApp::initDeskTop) {} virtual void handleEvent(TEvent& ev) override { TApplication::handleEvent(ev); if (ev.what == evCommand && ev.message.command == cmGreet) { TDialog *d = new TDialog(TRect(20, 5, 60, 15), "Greeting"); d->insert(new TStaticText(TRect(2, 3, 38, 4), "Hello, Turbo Vision!")); d->insert(new TButton(TRect(14, 6, 26, 8), "~O~K", cmOK, bfDefault)); deskTop->execView(d); destroy(d); clearEvent(ev); } } static TMenuBar* initMenuBar(TRect r) { r.b.y = r.a.y + 1; return new TMenuBar(r, *new TSubMenu("~F~ile", kbAltF) + *new TMenuItem("~G~reet", cmGreet, kbAltG) + newLine() + *new TMenuItem("E~x~it", cmQuit, kbAltX, hcNoContext, "Alt-X")); } static TStatusLine* initStatusLine(TRect r) { r.a.y = r.b.y - 1; return new TStatusLine(r, *new TStatusDef(0, 0xFFFF) + *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) + *new TStatusItem(0, kbF10, cmMenu)); } }; int main() { TMyApp app; app.run(); return 0; } // Build: g++ -std=c++14 -o hello hello.cpp libtvision.a -Iinclude -lncursesw ``` -------------------------------- ### TColorAttr Accessor Functions Source: https://github.com/magiblot/tvision/blob/master/README.md Provides free functions to get and set foreground, background, and style components of a TColorAttr object. ```c++ TColorDesired getFore(const TColorAttr &attr); TColorDesired getBack(const TColorAttr &attr); ushort getStyle(const TColorAttr &attr); void setFore(TColorAttr &attr, TColorDesired fg); void setBack(TColorAttr &attr, TColorDesired bg); void setStyle(TColorAttr &attr, ushort style); ``` -------------------------------- ### Integrate with System Clipboard using TClipboard Source: https://context7.com/magiblot/tvision/llms.txt TClipboard provides static methods for reading and writing to the system clipboard. Writing is synchronous; reading is asynchronous and delivers text via evKeyDown events tagged with kbPaste. ```cpp #define Uses_TClipboard #define Uses_TView #define Uses_TEvent #include class TClipAwareInput : public TView { public: TClipAwareInput(const TRect& b) : TView(b) { eventMask = evKeyboard | evBroadcast; } void copyToClipboard(const char* text) { TClipboard::setText(text); } void requestPaste() { TClipboard::requestText(); // async; text arrives as evKeyDown } virtual void handleEvent(TEvent& ev) override { TView::handleEvent(ev); if (ev.what == evKeyDown) { if (ev.keyDown.controlKeyState & kbPaste) { // Batch-read all consecutive paste events char buf[4096]; size_t length; while (textEvent(ev, buf, length)) { // process length bytes in buf // (may be called many times for large pastes) } } else { // Normal keystroke std::string_view ch = ev.keyDown.getText(); clearEvent(ev); } } } }; ``` -------------------------------- ### Unicode Text in TMenuBar and TStatusLine Source: https://github.com/magiblot/tvision/blob/master/README.md Example demonstrating how to use Unicode characters in menu and status bar definitions within a Tvision application. ```c++ TMenuBar *THelloApp::initMenuBar( TRect r ) { r.b.y = r.a.y+1; return new TMenuBar( r, *new TSubMenu( "~Ñ~ello", kbAltH ) + *new TMenuItem( "階~毎~料入報最...", GreetThemCmd, kbAltG ) + *new TMenuItem( "五劫~の~擦り切れ", cmYes, kbNoKey, hcNoContext ) + *new TMenuItem( "העברית ~א~ינטרנט", cmNo, kbNoKey, hcNoContext ) + newLine() + *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" ) ); } TStatusLine *THelloApp::initStatusLine( TRect r ) { r.a.y = r.b.y-1; return new TStatusLine( r, *new TStatusDef( 0, 0xFFFF ) + *new TStatusItem( "~Alt-Ç~ Exit", kbAltX, cmQuit ) + *new TStatusItem( 0, kbF10, cmMenu ) ); } ``` -------------------------------- ### Overriding getPalette in TMyApp Source: https://github.com/magiblot/tvision/blob/master/README.md This example shows how a derived `TApplication` class (`TMyApp`) can override the `getPalette` method to return a custom palette defined by `cpMyApp`. ```c++ // The 'TMyApp' class inherits from 'TApplication' and overrides 'TView::getPalette'. TPalette &TMyApp::getPalette() const { static TPalette palette(cpMyApp); return palette; } ``` -------------------------------- ### Build Tests Option Source: https://github.com/magiblot/tvision/blob/master/CMakeLists.txt Option to enable building and running tests for the project. ```cmake option(TV_BUILD_TESTS "Build and run tests" OFF) ``` -------------------------------- ### Overriding mapColor in TMyScrollBar Source: https://github.com/magiblot/tvision/blob/master/README.md This example shows how to override the `mapColor` method in a derived class (`TMyScrollBar`) to provide custom color attributes based on palette indices. ```c++ // The 'TMyScrollBar' class inherits from 'TScrollBar' and overrides 'TView::mapColor'. TColorAttr TMyScrollBar::mapColor(uchar index) { // In this example the values are hardcoded, // but they could be stored elsewhere if desired. switch (index) { case 1: return {0x492983, 0x826124}; // Page areas. case 2: return {0x438939, 0x091297}; // Arrows. case 3: return {0x123783, 0x329812}; // Indicator. default: return errorAttr; } } ``` -------------------------------- ### Configure Unity Build Source: https://github.com/magiblot/tvision/blob/master/source/CMakeLists.txt Enables Unity Build if the TV_LIBRARY_UNITY_BUILD flag is set. Unity build compiles multiple source files into a single translation unit to improve build performance. Files with non-trivial global variables should be excluded. ```cmake file(GLOB_RECURSE TVSOURCE_NOUNITY "${CMAKE_CURRENT_LIST_DIR}/tvision/s*.cpp") list(APPEND TVSOURCE_NOUNITY "${CMAKE_CURRENT_LIST_DIR}/tvision/new.cpp") list(REMOVE_ITEM TVSOURCE_NOUNITY "${CMAKE_CURRENT_LIST_DIR}/tvision/snprintf.cpp" "${CMAKE_CURRENT_LIST_DIR}/tvision/stddlg.cpp" "${CMAKE_CURRENT_LIST_DIR}/tvision/strmstat.cpp" "${CMAKE_CURRENT_LIST_DIR}/tvision/syserr.cpp" ) set_property(SOURCE ${TVSOURCE_NOUNITY} PROPERTY SKIP_UNITY_BUILD_INCLUSION ON) set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ON) ``` -------------------------------- ### Enable Precompiled Headers (PCH) Source: https://github.com/magiblot/tvision/blob/master/examples/CMakeLists.txt Conditionally enables precompiled headers for targets starting from CMake 3.16.0. It specifically configures PCH for the 'hello' target and reuses it for others. ```cmake function(tv_app_enable_pch app) if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.16.0") if (app STREQUAL "hello") target_precompile_headers(hello PRIVATE "${PROJECT_SOURCE_DIR}/include/pch.h") else() target_precompile_headers(${app} REUSE_FROM hello) endif() endif() endfunction() ``` -------------------------------- ### Show Context Menu with popupMenu Source: https://context7.com/magiblot/tvision/llms.txt Spawns a TMenuPopup at a specified screen position, returning the selected command code. Handles command dispatching to the owner. ```cpp #define Uses_TMenuItem #define Uses_TPoint #define Uses_TGroup #define Uses_TEvent #include void showContextMenu(TGroup* owner, TPoint screenPos) { TMenuItem& menu = *new TMenuItem("~C~opy", cmCopy, kbNoKey) + *new TMenuItem("Cu~t~", cmCut, kbNoKey) + *new TMenuItem("~P~aste", cmPaste, kbNoKey) + newLine() + *new TMenuItem("~D~elete", cmClear, kbDel); ushort cmd = popupMenu(screenPos, menu, owner); if (cmd != 0) { // Dispatch the selected command TEvent ev; ev.what = evCommand; ev.message.command = cmd; ev.message.infoPtr = nullptr; owner->handleEvent(ev); } } ``` -------------------------------- ### Extended Color System with TColorAttr Source: https://context7.com/magiblot/tvision/llms.txt Illustrates the usage of TColorAttr for various color encodings including BIOS, 24-bit RGB, and XTerm 256-color. It also shows how to use TAttrPair with moveCStr for highlighted text. ```cpp #define Uses_TColorAttr #define Uses_TView #define Uses_TDrawBuffer #include void demonstrateColors() { // BIOS color (backward-compatible with legacy code) TColorAttr biosAttr = 0x1E; // yellow-on-blue // 24-bit RGB foreground + BIOS background TColorAttr richAttr = {0xFF6600, '\x01'}; // orange fg, dark-blue bg // RGB + style flags TColorAttr boldUnderline = {TColorRGB(0x00, 0xFF, 0x80), TColorDesired{}, // terminal default bg slBold | slUnderline}; // XTerm 256-color palette TColorAttr xtermAttr = {TColorXTerm(202), TColorXTerm(17)}; // Accessors TColorDesired fg = getFore(richAttr); TColorDesired bg = getBack(richAttr); ushort style = getStyle(boldUnderline); // slBold | slUnderline // Reverse safely (prefer over slReverse flag) TColorAttr rev = reverseAttribute(richAttr); // TAttrPair: used by moveCStr for normal/highlighted text pairs TColorAttr normal = {0xCCCCCC, 0x002244}; TColorAttr hilight = {0xFFFF00, 0x002244}; TAttrPair pair = {normal, hilight}; TDrawBuffer buf; // ~word~ is rendered in hilight, rest in normal buf.moveCStr(0, "Press ~Enter~ to continue", pair); } ``` -------------------------------- ### Add Generic Application Source: https://github.com/magiblot/tvision/blob/master/examples/CMakeLists.txt Adds a generic executable application. It finds all .cpp files in the current directory, creates an executable, links it to the project, and applies common configurations. ```cmake function(tv_app_add_generic app) file(GLOB_RECURSE app-src "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(${app} ${app-src}) target_link_libraries(${app} PUBLIC ${PROJECT_NAME}) tv_app_common(${app}) endfunction() ``` -------------------------------- ### Directly Using TDrawBuffer for Custom View Drawing Source: https://github.com/magiblot/tvision/blob/master/README.md This example demonstrates overriding the `draw` method in `TMyView` to directly use `TDrawBuffer` methods for drawing text with specific color attributes, bypassing the palette system. ```c++ // The 'TMyView' class inherits from 'TView' and overrides 'TView::draw'. void TMyView::draw() { TDrawBuffer b; TColorAttr color {0x1F1C1B, 0xFAFAFA, slBold}; b.moveStr(0, "This is bold black text over a white background", color); /* ... */ } ``` -------------------------------- ### Corrected TFileViewer::draw() method (Unicode-aware) Source: https://github.com/magiblot/tvision/blob/master/README.md This refactored C++ code uses an overload of TDrawBuffer::moveStr to correctly handle Unicode text. It avoids intermediate buffer copies, supports substrings starting at a specific column, and automatically manages text width, leading to cleaner and more robust code. ```C++ if (delta.y + i < fileLines->getCount()) { p = (char *)(fileLines->at(delta.y+i)); if (p) b.moveStr(0, p, c, size.x, delta.x); } writeBuf( 0, i, size.x, 1, b ); ``` -------------------------------- ### Build AviSynth TermColor Plugin Option Source: https://github.com/magiblot/tvision/blob/master/CMakeLists.txt Option to enable the building of the AviSynth TermColor plugin. ```cmake option(TV_BUILD_AVSCOLOR "Build AviSynth TermColor plugin" OFF) ``` -------------------------------- ### Linux GPM Option Source: https://github.com/magiblot/tvision/blob/master/CMakeLists.txt Defines an option to enable building with GPM on Linux systems. ```cmake if (CMAKE_SYSTEM_NAME STREQUAL "Linux") option(TV_BUILD_USING_GPM "Use GPM" ON) set(MAY_BUILD_USING_GPM TRUE) endif() ``` -------------------------------- ### Display Standard Dialogs with messageBox and inputBox Source: https://context7.com/magiblot/tvision/llms.txt Utilizes free functions for quick modal dialogs like confirmations, errors, and input prompts. messageBox returns command codes, and inputBox fills a provided buffer. ```cpp #define Uses_MsgBox #define Uses_TRect #include void doFileDelete(const char* filename) { // Confirmation dialog with Yes/No/Cancel buttons ushort result = messageBox( mfConfirmation | mfYesNoCancel, "Delete file '%s'?", filename ); if (result != cmYes) return; // Error dialog if (/* delete failed */ false) { messageBox("Could not delete the file.", mfError | mfOKButton); return; } // Warning with explicit rectangle messageBoxRect(TRect(15, 8, 65, 14), "File deleted. Undo is not available.", mfWarning | mfOKButton); } void doRenameFile() { char newName[256] = ""; ushort r = inputBox("Rename File", "New name:", newName, sizeof(newName)-1); if (r == cmOK && newName[0] != '\0') { // use newName } } ``` -------------------------------- ### TEvent Handling for Keyboard, Mouse, and Commands Source: https://context7.com/magiblot/tvision/llms.txt Shows how to override TView::handleEvent to process various TEvent types including keyboard input, mouse clicks, mouse wheel events, commands, and broadcasts. Always call the parent handler first. ```cpp #define Uses_TView #define Uses_TEvent #define Uses_TKeys #include class TMyWidget : public TView { public: TMyWidget(const TRect& b) : TView(b) { eventMask |= evBroadcast; // opt in to broadcasts } virtual void handleEvent(TEvent& ev) override { TView::handleEvent(ev); switch (ev.what) { case evKeyDown: // Unicode-safe character read if (ev.keyDown.keyCode == kbEnter) { // confirmed clearEvent(ev); } else { std::string_view ch = ev.keyDown.getText(); // UTF-8 char // process ch ... } break; case evMouseDown: if (containsMouse(ev) && (ev.mouse.buttons & mbLeftButton)) { TPoint local = makeLocal(ev.mouse.where); // local.x, local.y in view-relative coordinates clearEvent(ev); } break; case evMouseWheel: if (ev.mouse.wheel & mwUp) { /* scroll up */ clearEvent(ev); } if (ev.mouse.wheel & mwDown) { /* scroll down */ clearEvent(ev); } break; case evCommand: if (ev.message.command == cmSave) { // handle save command clearEvent(ev); } break; case evBroadcast: if (ev.message.command == cmTimerExpired) { // periodic tick from a setTimer() call } break; } } }; ``` -------------------------------- ### Optimize Application Build Source: https://github.com/magiblot/tvision/blob/master/examples/CMakeLists.txt Optimizes the build for a given application by enabling precompiled headers and unity builds if TV_OPTIMIZE_BUILD is set. ```cmake function(tv_app_optimize app) if (TV_OPTIMIZE_BUILD) tv_app_enable_pch(${app}) tv_enable_unity(${app}) endif() endfunction() ``` -------------------------------- ### Configure AviSynth Termcolor Library Build Source: https://github.com/magiblot/tvision/blob/master/examples/avscolor/CMakeLists.txt This CMake code configures the build for the termcolor library using AviSynth. It finds the AviSynth library and headers, sets up include directories, and links the necessary libraries. The build is conditional on TV_BUILD_AVSCOLOR being true and the system not being Windows. ```cmake if (TV_BUILD_AVSCOLOR AND NOT WIN32) set(NAME termcolor) find_library(AVISYNTH avisynth) if (AVISYNTH) add_library(${NAME} SHARED ${NAME}.cpp) target_compile_features(${NAME} PRIVATE cxx_std_11) target_link_libraries(${NAME} PRIVATE ${PROJECT_NAME}) find_path(AVISYNTH_INCLUDE "avisynth/avisynth.h") if (AVISYNTH_INCLUDE) target_include_directories(${NAME} PRIVATE "${AVISYNTH_INCLUDE}/avisynth") endif() target_link_libraries(${NAME} PRIVATE ${AVISYNTH}) tv_set_output_dir(${NAME}) else() tv_message(ERROR "Cannot find AviSynth.") endif() endif() ``` -------------------------------- ### Add 'hello' Executable Target Source: https://github.com/magiblot/tvision/blob/master/examples/CMakeLists.txt Defines the 'hello' executable target using a specific source file and links it to the project's main library. It also applies common application configurations. ```cmake add_executable(hello "${PROJECT_SOURCE_DIR}/hello.cpp") target_link_libraries(hello PUBLIC ${PROJECT_NAME}) tv_app_common(hello) ``` -------------------------------- ### String-based Hotkey Functions Source: https://github.com/magiblot/tvision/blob/master/README.md New string-based variants of hotkey functions for multibyte shortcut implementation. ```APIDOC ## String-based Hotkey Functions ### Description Provides string-based variants of `hotKey`, `getAltChar`, and `getCtrlChar` for multibyte shortcuts. ### Functions - `TStringView hotKeyStr(TStringView)` - `TStringView getAltCharStr(const KeyDownEvent &)` - `TStringView getCtrlCharStr(const KeyDownEvent &)` ``` -------------------------------- ### TView Text Event Handling Source: https://github.com/magiblot/tvision/blob/master/README.md New method TView::textEvent() for efficient text reception. See Clipboard interaction section. ```c++ void TView::textEvent() ``` -------------------------------- ### fexpand with Relative Path Source: https://github.com/magiblot/tvision/blob/master/README.md The fexpand function now accepts an optional second parameter 'relativeTo' for relative path expansion. ```c++ fexpand ``` -------------------------------- ### Borland C++ Makefile Build Options Source: https://github.com/magiblot/tvision/blob/master/README.md Options for the Borland C++ Makefile to specify build targets and configurations. Use '-DDOS32' for 32-bit DPMI applications or '-DWIN32' for 32-bit native Win32 applications. ```sh cd project make.exe ``` -------------------------------- ### Define TVForms Executables and Link Libraries Source: https://github.com/magiblot/tvision/blob/master/examples/tvforms/CMakeLists.txt This snippet defines the executables 'genparts', 'genphone', and 'tvforms', links them to the project library, and sets specific compile definitions for 'genparts' and 'genphone'. ```cmake list(APPEND TVAPPS genparts genphone) file(GLOB_RECURSE tvforms-src "${CMAKE_CURRENT_LIST_DIR}/*.cpp") set(genform-src ${tvforms-src}) list(REMOVE_ITEM genform-src "${CMAKE_CURRENT_LIST_DIR}/tvforms.cpp") list(REMOVE_ITEM tvforms-src "${CMAKE_CURRENT_LIST_DIR}/genform.cpp") add_executable(genparts ${genform-src}) add_executable(genphone ${genform-src}) target_link_libraries(genparts PUBLIC ${PROJECT_NAME}) target_link_libraries(genphone PUBLIC ${PROJECT_NAME}) target_compile_definitions(genparts PRIVATE PARTS) target_compile_definitions(genphone PRIVATE PHONENUM) if (NOT CMAKE_CROSSCOMPILING) add_custom_command(TARGET genparts POST_BUILD COMMAND genparts WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) add_custom_command(TARGET genphone POST_BUILD COMMAND genphone WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) endif() add_executable(tvforms ${tvforms-src}) target_link_libraries(tvforms PUBLIC ${PROJECT_NAME}) foreach(t tvforms genparts genphone) tv_app_common(${t}) endforeach() ``` -------------------------------- ### Popup Menu Function Source: https://github.com/magiblot/tvision/blob/master/README.md Spawns a TMenuPopup on the desktop. See source/tvision/popupmnu.cpp for implementation details. ```c++ ushort popupMenu(TPoint where, TMenuItem &aMenu, TGroup *receiver = 0) ``` -------------------------------- ### Include Turbo Vision with add_subdirectory Source: https://github.com/magiblot/tvision/blob/master/README.md Alternatively, if Turbo Vision is a submodule in your repository, use add_subdirectory to include it and then link your application against it. ```cmake add_subdirectory(tvision) target_link_libraries(my_application tvision) ``` -------------------------------- ### Tvision Subsystem Initialization Source: https://github.com/magiblot/tvision/blob/master/README.md Turbo Vision subsystems are now initialized upon the first TApplication construction, rather than before main(). They are still destroyed on exit from main(). ```c++ THardwareInfo ``` ```c++ TScreen ``` ```c++ TEventQueue ``` ```c++ TApplication ``` -------------------------------- ### TEditor Context Menu Initialization Source: https://github.com/magiblot/tvision/blob/master/README.md Virtual method to determine the entries of the right-click context menu in TEditor. ```c++ virtual TMenuItem& TEditor::initContextMenu(TPoint p) ``` -------------------------------- ### Create a TMenuBar Source: https://context7.com/magiblot/tvision/llms.txt Constructs a menu bar with nested submenus and menu items. Uses operator '+' to chain menu elements and defines keyboard shortcuts and commands for each item. ```cpp #define Uses_TMenuBar #define Uses_TSubMenu #define Uses_TMenuItem #define Uses_TStatusLine #define Uses_TStatusItem #define Uses_TStatusDef #define Uses_TKeys #include static TMenuBar* makeMenuBar(TRect r) { r.b.y = r.a.y + 1; return new TMenuBar(r, *new TSubMenu("~F~ile", kbAltF) + *new TMenuItem("~N~ew", cmNew, kbCtrlN, hcNoContext, "Ctrl-N") + *new TMenuItem("~O~pen", cmOpen, kbCtrlO, hcNoContext, "Ctrl-O") + *new TMenuItem("~S~ave", cmSave, kbCtrlS, hcNoContext, "Ctrl-S") + newLine() + *new TMenuItem("E~x~it", cmQuit, kbAltX) + *new TSubMenu("~E~dit", kbAltE) + *new TMenuItem("~U~ndo", cmUndo, kbCtrlZ) + *new TMenuItem("Cu~t~", cmCut, kbCtrlX) + *new TMenuItem("~C~opy", cmCopy, kbCtrlC) + *new TMenuItem("~P~aste", cmPaste, kbCtrlV) + *new TSubMenu("~W~indow", kbAltW) + *new TMenuItem("~T~ile", cmTile, kbNoKey) + *new TMenuItem("~C~ascade", cmCascade, kbNoKey) ); } ``` -------------------------------- ### Static Runtime Library Option (MSVC) Source: https://github.com/magiblot/tvision/blob/master/CMakeLists.txt Option to link against the static version of the runtime library, primarily for MSVC. ```cmake option(TV_USE_STATIC_RTL "Link against the static version of the runtime library (MSVC only)" OFF) if (MSVC) set(MAY_USE_STATIC_RTL TRUE) elseif (TV_USE_STATIC_RTL) tv_message(WARNING "'TV_USE_STATIC_RTL' requested but only available in MSVC or equivalent.") set(TV_USE_STATIC_RTL OFF) endif() ```