//+------------------------------------------------------------------+
//|                                             HistoryNavigator.mq5 |
//|                                               Christian Benjamin |
//|                          https://www.mql5.com/en/users/lynnchris |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Christian Benjamin"
#property link      "https://www.mql5.com/en/users/lynnchris"
#property version   "1.3"
#property strict

//--- Include the custom dialog class that holds all UI and logic
#include <Bookmarks/CNavigatorDialog.mqh>

//--- Global pointer to the dialog instance (needed to forward events)
CNavigatorDialog *g_dialog = NULL;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- Define the position and size of the floating dialog
   int x1 = 20, y1 = 20;
   int width = 300, height = 550;
   int x2 = x1 + width;
   int y2 = y1 + height;

//--- Allocate the dialog object on the heap so it survives this function
   g_dialog = new CNavigatorDialog();

//--- Create the dialog window. If it fails, clean up and abort the EA.
   if(!g_dialog.Create(0, "HistoryNavigator", 0, x1, y1, x2, y2))
     {
      delete g_dialog;
      g_dialog = NULL;
      return(INIT_FAILED);
     }

//--- Start the dialog (makes it visible and responsive to events)
   g_dialog.Run();

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(g_dialog != NULL)
     {
      g_dialog.Destroy();
      delete g_dialog;
      g_dialog = NULL;
     }
  }

//+------------------------------------------------------------------+
//| Chart event handler                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(g_dialog != NULL)
      g_dialog.ChartEvent(id, lparam, dparam, sparam);
  }
//+------------------------------------------------------------------+