4.7. Set, Test, and Clear Widget Flags

#!/usr/cogent/bin/phgamma

/*
 * This example demonstrates setting, testing, and clearing widget
 * flags. You can compare the results by viewing the original file:
 * QNX4-WidgetFiles/wgt/setflags.wgtw in PhAB, QNX 4, or 
 * QNX6-WidgetFiles/wgt/setflags.wgtw in the Builder, QNX 6.
 * 
 * Start by loading the necessary Photon and PhAB files, and initializing
 * Photon. 
 */
require_lisp("PhotonWidgets.lsp");
require_lisp("PhabTemplate.lsp");
PtInit(nil);

/*
 * Read the widget file, create it, and assign symbols to the widgets
 * to be used.
 */
wfile = PhabReadWidgetFile (string(_os_, "-WidgetFiles/wgt/setflags.wgtw"));
window = PhabCreateWidgets(wfile, nil, nil);

setflags = PhabLookupWidget(window,#setflags,nil);
p1 = PhabLookupWidget(window,#Pane1,nil);
p2 = PhabLookupWidget(window,#Pane2,nil);
p3 = PhabLookupWidget(window,#Pane3,nil);
p4 = PhabLookupWidget(window,#Pane4,nil);
p5 = PhabLookupWidget(window,#Pane5,nil);
p6 = PhabLookupWidget(window,#Pane6,nil);
p7 = PhabLookupWidget(window,#Pane7,nil);
p8 = PhabLookupWidget(window,#Pane8,nil);
p9 = PhabLookupWidget(window,#Pane9,nil);

/*
 * Set a single flag; set multiple flags using the | bitwise operator;
 * and copy and set multiple flags using the & and ~ operators for masking.
 */
p1.flags = Pt_HIGHLIGHTED;
p2.flags = Pt_HIGHLIGHTED | Pt_SET | Pt_ETCH_HIGHLIGHT;
p3.flags = p2.flags & ~Pt_ETCH_HIGHLIGHT; 

/*
 * Test widgets, whose flags were originally set in PhAB, for flags
 * set/cleared status using the & bitwise operator. Print the results.
 */
princ("\nPane 4 flags are: ", p4.flags,"\n");
test1 = hex(p4.flags & Pt_HIGHLIGHTED);
test2 = hex(p4.flags & Pt_SET);
test3 = hex(p4.flags & Pt_ETCH_HIGHLIGHT);
princ("Test 1 results: ", test1, "\n");
princ("Test 2 results: ", test2, "\n");
princ("Test 3 results: ", test3, "\n");

princ("\nPane 5 flags are: ", p5.flags,"\n");
test1 = hex(p5.flags & Pt_HIGHLIGHTED);
test2 = hex(p5.flags & Pt_SET);
test3 = hex(p5.flags & Pt_ETCH_HIGHLIGHT);
princ("Test 1 results: ", test1, "\n");
princ("Test 2 results: ", test2, "\n");
princ("Test 3 results: ", test3, "\n");

princ("\nPane 6 flags are: ", p6.flags,"\n");
test1 = hex(p6.flags & Pt_HIGHLIGHTED);
test2 = hex(p6.flags & Pt_SET);
test3 = hex(p6.flags & Pt_ETCH_HIGHLIGHT);
princ("Test 1 results: ", test1, "\n");
princ("Test 2 results: ", test2, "\n");
princ("Test 3 results: ", test3, "\n\n");

/*
 * Clear certain flags, using the cons() function, from widgets
 * whose flags were originally set in PhAB.  Before the flags were
 * cleared, p7.flags were the same as p4.flags; p8.flags were
 * equal to p5.flags; and p9.flags were equal to p6.flags.
 */
p7.flags = cons(Pt_HIGHLIGHTED,nil);
p8.flags = cons(Pt_SET,nil);
p9.flags = cons(Pt_SET,nil);
p9.flags = cons(Pt_HIGHLIGHTED,nil);
p9.flags = cons(Pt_ETCH_HIGHLIGHT,nil);

/*
 * Test, set, and clear flags using PtWidget method calls.
 */
princ("Pane 1 flags: ",p1.flags,"\n");
princ("Highlighted flag set? ",
      p1.TestBit(#flags,Pt_HIGHLIGHTED),"\n\n");

p1.SetBit(#flags,Pt_ETCH_HIGHLIGHT | Pt_SET);
princ("Pane 1 flags: ",p1.flags,"\n");
princ("Etch highlight flag set? ",
      p1.TestBit(#flags,Pt_ETCH_HIGHLIGHT),"\n");
princ("Set flag set? ",p1.TestBit(#flags,Pt_SET),"\n\n");

p1.ClearBit(#flags,Pt_ETCH_HIGHLIGHT | Pt_SET);
princ("Pane 1 flags: ",p1.flags,"\n");
princ("Etch highlight flag still set? ",
      p1.TestBit(#flags,Pt_ETCH_HIGHLIGHT),"\n");
princ("Set flag still set? ",p1.TestBit(#flags,Pt_SET),"\n\n");

PtRealizeWidget(setflags);
PtMainLoop();