Resource File Viewer


The VuResFiWn package implements a window able to view the resources in a MOS resource file, inspired by (but not as capable as) Andy Herzfeld's ResEdit. You give it a reference theFi to the resource file you want to examine, and it opens and manages a window to view the file, either as individual resources, or else as raw hex. These functions are defined:

void OpenVuResWin(File theFi);
void CloseVuResWin();

OVW initializes its (public) VuResWindow to read the file and display its contents. Your main program's event loop is responsible for sending to the VuResWindow.HandleMyEvent() method any events it is likely to want to see; it returns true if it accepted that event, or false if you should do something else with it.

You can specify display code for your own resource types using a callback mechanism which subclasses BestResTypeView:
 

class BestResTypeView { // subclass & install to use..
  boolean DoForm; // set by subclass, true if BestForm,BestDone wanted
  boolean DoEvents; // ditto, true if BestEvents wanted
  File DoingFi; // set by caller
  String BestView(Char4 theType, int ResNo, IntArray theData, IntObj TallWide) {
    // TagLib library formats, return super.BestView(..) to view them..
    if (theType == "TxIx") return TgLbIx(DoingFi,theData,ResNo,TallWide);
    if (theType == "TgTr") return TgLbTr(DoingFi,theData,ResNo,TallWide);
    if (theType == "Tstr") return TgLbSt(DoingFi,theData,ResNo,TallWide);
    return "";}~BestView // TallWide rtns: hi=Tall, #lines; lo=Wide
      // Wide<0 = #chrs if Mono (0: assume -64), otherwise pixel width
  int BestForm(boolean doit, IntArray theImg, int offs, int HiWi,
      IntArray theHots, int hotx, Char4 theType, int ResNo, IntArray theData) {
    return 0;}~BestForm
  boolean BestEvents(Event theEv) {return false;}~BestEvents
  void BestDone() {}~BestDone}~BestResTypeView
BestResTypeView BestResViewer = null;


You should create a single object of your subclass and set BestResViewer to point to it.

The base class knows how to display the library resources used by the T2 compiler, so if your subclass does not recognize a resource, you should defer it to the base class. The normal (simple) resource viewer subclass would format the data as a sequence of text lines in BestView(), given the resource data in theData; the number of lines and maximum width (in pixels, assuming font "Text") of the returned text should be packed into an integer and returned in wrapper object TallWide. If the text should be displayed in a monospace font, then return the negative of the longest line (in characters) in the low half of TallWide; zero assumes a default width of not more than 64 characters.

If plain text is inadequate for displaying your resource, set DoForm=true in your object and override BestForm() with the necessary drawing code. This essentially modelled after the EstSize() and DrawMe() methods of the parent ImageItems class, where the doit parameter is true from DrawMe and false from EstSize. Your BestDone() method is called when the display is about go away (the window is closing, or else something else is going to be displayed there). If you want to respond to mouse clicks or other events, then you should also set DoEvents=true in your object and override BestEvents() with the necessary event handling code (return false for any event you do not accept).
 

Window Parameters

The VuResWindow window is implemented as a subclass of the ImageWinMgr window class. The header panel is completely implemented using standard items and parameters, and for the undaunted might serve as an example of what you can do.

The fixed item list given to Initialize() consists of these eight lines:

Fill,0,0,\7,172
Fill,4,4,20,36,215
OutL,4,4,20,36,0
Text,4,4,20,36,0,0,VH,\1
Hots,4,4,20,36,Floc,0
PopD,4,324,20,48,0,4,PopD,\3,Best,Hex,Mix,Text
Udat,28,4,\8
PopL,4,44,20,96,0,4,PopL,\2
where '\' represents tab characters indexing into items (shown here as separate lines, with item tags and explanatory comments) of the parameter list:
\1 ShowBlokNo = file block being displayed (4 digits in hex)
\2 LevelSeln = display info "PopL" text selector, = \A..\L (init'ly \D)
\3 DispMode = display mode "PopD" default 0
\4 SelnResTy = selected type;
\5 SelnResNo = res# of that type, if any
\6 SelnCount = number of types, or # resources of that type, or size of res
\7 window or image size, whichever is larger, init'ly "256,360"
\8 UserPanHW = User panel height+width+info
\9 SkipNres = in res list
\A "0,Data,ToC"                     -- nothing known
\B "0,Data,ToC,All \4's"            -- show random segment, got saved type
\C "0,Data,ToC,All \4's,\4 #\5"     -- show random segment, saved type & #
\D "1,Data,ToC\M\P"                 -- show index, nothing known
\E "1,Data,ToC,All \4's\M\P"        -- show index, saved type
\F "1,Data,ToC,All \4's\M\Q"        -- show index, sel'd type
\G "1,Data,ToC,All \4's,\4 #\5\M\Q" -- show index, sel'd type, known #
\H "2,Data,ToC,All \4's\M\R"        -- show type list, nothing known
\I "2,Data,ToC,All \4's\M\S"        -- show type list, sel'd res# w/size
\J "2,Data,ToC,All \4's\M\R\O"      -- show type list +skip
\K "2,Data,ToC,All \4's\M\S\O"      -- type list +skip, sel'd res# w/size
\L "3,Data,ToC,All \4's,\4 #\5\M\T" -- show resource w/size
\M "|Text,4,120,16,128,0,4,V,"  -- text field, filled w/one item, \P-\T
\N (unused) (empty)
\O "|Text,4,282,20,10,0,4,VH,+
    |Hots,4,282,20,10,PlsK,1
    |Text,4,310,20,10,0,4,VH,K
    |Hots,4,310,20,10,PlsK,-1
    |Fill,4,292,20,18,215
    |OutL,4,292,20,18,0
    |Text,4,292,20,15,\t9
    |Hots,4,292,20,18,PlsK,0"
\P "(\6 types)"
\Q "(\6 types, #\4)"
\R "(\6 items)"
\S "(\6) Type \4 #\5"
\T "(\6 ints)"
The first nine items in this list are dynamically generated at run time, depending on which resource type and/or resource is selected for display (if any); the remaining 20 (lettered) items are hard-coded in the program code. Note that item '\M' starts with a linefeed, so it adds another display item not in the fixed set. Similarly, item '\O' is actually eight additional lines representing a small text panel with three hot buttons for manipulating it.

Items '\A' through '\L' represent the different display states, showing respectively either raw data, the file type index, the resource list for a particular type, or the data for a particular resource, and then within that level, which other choices are avilable (in the popup menu). Each of these eleven items begins with a numeral, which is the currently selected item of the popup menu, followed by the options in that menu. One of these item labels is dynamically inserted into item '\2' so that the proper header is displayed. Some of these items additionally include references to items 4 (the current resource type), 5 (the current resource ID in that type), and 6 (the number of whatever is being shown), and additional item text or display parameters from items '\M' through '\T'. All of these recursive references are resolved before the window is displayed.

The seventh line of the fixed items is a UserItem, which invokes a callback that eventually gets around to displaying the extended data types your BestResTypeView subclass supplies, or else the defaults coded in the VuResFiWn package.
 

This rev. 2013 May 24