#include "dialog.h" struct HELP_CONTEXT_PRIVATE{ SSTRING title; HELP_FILE *help; int threadid; HELP_CONTEXT_PRIVATE(const char *_title, const char *subdir, const char *file) { help = new HELP_FILE (subdir,file); title.setfrom (_title); threadid = uithread_id; } ~HELP_CONTEXT_PRIVATE () { delete help; } }; static ARRAY_OBJS tb; PUBLIC HELP_CONTEXT::HELP_CONTEXT(const char *title, const char *subdir, const char *file) { priv = new HELP_CONTEXT_PRIVATE(title,subdir,file); tb.add (this); tb.neverdelete(); } PUBLIC HELP_CONTEXT::~HELP_CONTEXT() { delete priv; tb.remove (this); } /* Setup all the alternate help for a dialog. Pick the various HELP_CONTEXT object in the stack for this thread. */ void help_context_setalthelp (DIALOG *dia) { // Help are presented in reverse order // The last registered HELP_CONTEXT is presented first int id = uithread_id; for (int i=tb.getnb()-1; i>=0; i--){ HELP_CONTEXT_PRIVATE *priv = tb.getitem(i)->priv; if (priv->threadid == id){ if (priv->title.is_filled()){ dia->addhelp (*priv->help,priv->title.get()); }else{ // Ok, this is the first dummy HELP_CONTEXT of this // thread. We must now look at HELP_CONTEXT defined // by the parent before this thread started id = uithread_getparent(id); } } } } /* Create a marker to tell where the HELP_CONTEXT for a given threadid starts. This way, help_context_setalthelp() can pick the HELP_CONTEXT for the current thread, then switch to the parent thread and pick only the HELP_CONTEXT defined before the child thread was created. This function is only called from uithread() and help_context_delmark is called when the thread ends. */ void help_context_setmark (int threadid) { HELP_CONTEXT *h = new HELP_CONTEXT ("","",""); h->priv->threadid = threadid; } void help_context_delmark (int threadid) { for (int i=0; ipriv; if (priv->title.is_empty() && priv->threadid == threadid){ tb.remove(h); delete h; break; } } }