unit exports_;
interface
uses sysutils,windows,common,gname,schedule,menus;
{
  >* This is the exports class extension of the generic names class gname  *
  >* Exports were implemented as a separate class to normal names because  *
  >* this allowed an element of persistence to be given to them (you cant  *
  >* delete a name from the list unless you do it from code within Borg)   *
  >* Also exports and imports have been given different dialogs, and can   *
  >* be treated differently in disassembly and display. I suppose this     *
  >* could have been implemented as a property of the names class but I    *
  >* decided early on to separate the classes out                          *
}
type
  texports=class(tgname)
  public
    procedure exportsviewer;
  end;

var
  expt:texports;

implementation

// exportsbox                                                            *
// - this is the exports viewer dialog box. It is simpler than the names *
//   class dialog box, featuring only a jump to option. As for the names *
//   class a request is added to the scheduler for any jump and the      *
//   dialog box exits. the main code is for filling the initial list box *
//   and for displaying a new address when the selection is changed      *
function exportsbox(hdwnd:HWND; msg,wParam,lParam:dword):dword;stdcall;
const
  brush:hbrush=0;
  nseg :string='';
  noffs:string='';
  t:pgnameitem=nil;
var
  i :dword;
  drect:trect;
begin
  result:=0;
  case msg of
   WM_COMMAND:
    begin
      case wParam of
       IDC_OKBUTTON:
         begin
           EndDialog(hdwnd,0);
           result:=1; exit;
         end;
        IDC_JUMPTOBUTTON:
         begin
           scheduler.addtask(user_jumptoaddr,priority_userrequest,t.addr,0,nil);
           EndDialog(hdwnd,0);
           result:=1; exit;
         end;
      end;
      case HIWORD(wParam) of
       LBN_SELCHANGE:
        begin
          i:=SendDlgItemMessage(hdwnd,IDC_EXPORTSLISTBOX,LB_GETCURSEL,0,0);
          expt.resetiterator;
          t:=pgnameitem(expt.nextiterator);
          while i<>0 do begin
            t:=pgnameitem(expt.nextiterator); dec(i);
          end;
          fmtstr(nseg,'0x%4.4x',[t.addr.s]);
          fmtstr(noffs,'0x%8.8x',[t.addr.o]);
          SendDlgItemMessage(hdwnd,EXPORTS_TEXTSTART,WM_SETTEXT,0,dword(pchar(nseg)));
          SendDlgItemMessage(hdwnd,EXPORTS_TEXTEND,WM_SETTEXT,0,dword(pchar(noffs)));
        end;
      end;
    end;
   WM_INITDIALOG:
    begin
      GetWindowRect(hdwnd,drect);
      MoveWindow(hdwnd,((mainwnd.right+mainwnd.left)-(drect.right-drect.left)) div 2,
       ((mainwnd.bottom+mainwnd.top)-(drect.bottom-drect.top)) div 2,drect.right-drect.left,drect.bottom-drect.top,TRUE);
      expt.resetiterator;
      for i:=0 to expt.numlistitems-1 do begin
        t:=pgnameitem(expt.nextiterator);
        SendDlgItemMessage(hdwnd,IDC_EXPORTSLISTBOX,LB_ADDSTRING,0,dword(@t.nam^));
      end;
      SendDlgItemMessage(hdwnd,IDC_EXPORTSLISTBOX,LB_SETCURSEL,0,0);
      expt.resetiterator;
      t:=pgnameitem(expt.nextiterator);
      fmtstr(nseg,'0x%4.4x',[t.addr.s]);
      fmtstr(noffs,'0x%8.8x',[t.addr.o]);
      SendDlgItemMessage(hdwnd,EXPORTS_TEXTSTART,WM_SETTEXT,0,dword(pchar(nseg)));
      SendDlgItemMessage(hdwnd,EXPORTS_TEXTEND,WM_SETTEXT,0,dword(pchar(noffs)));
      brush:=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
      SetFocus(GetDlgItem(hdwnd,IDC_OKBUTTON));
      exit;
    end;
   WM_DESTROY:
    begin
      DeleteObject(brush); exit;
    end;
   WM_CTLCOLORSTATIC,
   WM_CTLCOLORBTN,
   WM_CTLCOLORDLG,
   WM_SYSCOLORCHANGE:
    begin
      SetBkColor(HDC(wParam),GetSysColor(COLOR_BTNFACE));
      result:=brush;
    end;
  end;
end;

// exportsviewer                                                         *
// - stops the thread and displays the exports viewer dialog. Although   *
//   this supports the repeater variable, as for the names class, it is  *
//   currently unused                                                    *
procedure texports.exportsviewer;
begin
  repeater:=TRUE;
  while repeater do begin
    if numlistitems=0 then begin
      MessageBox(mainwindow,'There are no exports in the list','Borg Message',MB_OK);
      exit;
    end;
    scheduler.stopthread;
    repeater:=FALSE;
    DialogBox(Inst,MAKEINTRESOURCE(Exports_Viewer),mainwindow,@exportsbox);
    scheduler.continuethread;
  end
end;

begin
  expt:=texports.create;
end.
