Component index
Section index

Component framework


Search

	/*
	    Here is a more complex example. This time, we create our own layout.
	    Area1 is associated with a notebook, area2 also and area3 is at the bottom
	    and present a text field.
	
	    Every time we add a document, it is added to area1 and then area2 and
	    area1 again and so on. The letter a is appended to the text field
	    in area3. And a message is printed on the status line. The status
	    line clears itself 3 seconds later.
	*/
	
	<mod>
	static void sample_framework2()
	{
	    <glocal>
	        PRIVATE_MESSAGE msg;
	        int selarea;
	    </glocal>
	    glocal.selarea = 0;
	    <obj FRAMEWORK frame>("many document areas");
	        <f layout>
	            layout_area1(true);
	            layout_area2(true);
	            layout_newline();
	            layout_area3(false);
	            layout_dispolast (GUI_H_LEFT,2,GUI_V_CENTER,1);
	        </f>
	        <f about>
	            xconf_notice (
	                "This is a sample program\n"
	                "showing the framework TLMP component\n"
	                "Written by Jacques Gélinas\n"
	                "jack@solucorp.qc.ca");
	        </f>
	        <f helpindex>
	        </f>
	        <f menubar>
	            topmenu ("File");
	            menuentry (1,"Load");
	            menuentry (2,"Save");
	            menuentry (3,"Save as");
	            menuentry (99,"Quit");
	            endmenu();
	            topmenu ("Options");
	            menuentry (901,"Preferences");
	            endmenu();
	            helpmenu();
	            endmenu();
	        </f>
	        <f menudo>
	            if (id == 99){
	                end();
	            }else if (id == 1){
	                glocal.selarea++;
	                // We start a new document in one area or the other
	                newdocument (NULL,(glocal.selarea & 1) ? 1 : 2);
	                dialog_sendmessage (glocal.msg);
	            }
	        </f>
	        <f taskbar>
	        </f>
	        <f taskdo>
	        </f>
	        <f document>
	            DIALOG dia;
	            info.msgs.waitfor (dia);
	            SSTRING tmp;
	            tmp.setfrom ("This is a document");
	            dia.newf_textarea (NULL,tmp,40,10);
	            int nof = 0;
	            while (1){
	                MENU_STATUS code = dia.edit ("Some text","",help_nil,nof,0);
	                if (code == MENU_MESSAGE){
	                    if (info.msgs.is_ending()){
	                        break;
	                    }else if (info.msgs.is_mayend()){
	                        dia.save();
	                        if (xconf_yesno ("Forget changes", "Quit without saving",help_nil)==MENU_YES){
	                            endok();
	                        }
	                    }
	                }
	            }
	        </f>
	        <f area3>
	            DIALOG dia;
	            SSTRING s;
	            dia.newf_str ("Some info",s);
	            int nof = 0;
	            info.msgs.waitfor (dia);
	            dia.waitfor (glocal.msg);
	            while (true){
	                MENU_STATUS code = dia.edit("","",help_nil,nof,0);
	                if (code == MENU_MESSAGE){
	                    if (must_end(info.msgs)){
	                        break;
	                    }else{
	                        s.append ("a");
	                        dia.reload();
	                    }
	                }
	            }
	        </f>
	        <f status>
	            // Display a message for 3 seconds every time a new document is
	            // loaded
	            glocal SSTRING s;
	            <call statusbar>(ending);
	            <f layout>
	                dia.newf_str (NULL,glocal.s,50);
	                dia.set_lastreadonly();
	                dia.waitfor (glocal.msg);
	            </f>
	            <f message>
	                glocal.s = "A new document was loaded";
	                settimer (3);
	            </f>
	            <f timer>
	                glocal.s = "";
	            </f>
	            </call>
	        </f>
	    </obj>
	    frame.newdocument(NULL,1);
	    frame.loop();
	}
	</mod>
	
	// #Specification: sample / FRAMEWORK / framework inside framework
	/*
	    Here is a more complex example. Several FRAMEWORK inside one.
	    To make things simple, we are reusing the same FRAMEWORK 4 times.
	*/
	
	<mod>
	static void sample_framework3()
	{
	    <obj FRAMEWORK frame>("framework inside framework");
	        <f layout>
	            #if 1
	            layout_book();
	            layout_page("Page1");
	            layout_area1(false);
	            layout_end();
	            layout_page("Page2");
	            layout_area2(false);
	            layout_end();
	            #endif
	            #if 0
	                layout_page("Page3");
	                layout_area3(false);
	                layout_end();
	                layout_page("Page4");
	                layout_area4(false);
	                layout_end();
	            #endif
	            layout_end();
	        </f>
	        <f about>
	            xconf_notice (
	                "This is a sample program\n"
	                "showing frameworks inside a framework\n"
	                "Written by Jacques Gélinas\n"
	                "jack@solucorp.qc.ca");
	        </f>
	        <f helpindex>
	        </f>
	        <f menubar>
	            topmenu ("File");
	            menuentry (99,"Quit");
	            endmenu();
	            helpmenu();
	            endmenu();
	        </f>
	        <f menudo>
	            if (id == 99){
	                end();
	            }
	        </f>
	        <f document>
	            glocal int noarea = noarea;
	            if (0){
	                    DIALOG dia;
	                    SSTRING s;
	                    s.setfromf ("nbdoc %d area %d",info.nbdocument,noarea);
	                    dia.newf_str ("A string",s);
	                    int nof = 0;
	                    /*
	                        We tell our dialog it must wait for some messages
	                        to participate in the quit protocol.
	                        A dialog failing to do so will prevent the
	                        framework from exiting.
	                    */
	                    info.msgs.waitfor (dia);
	                    while (1){
	                        dia.edit ("","",help_nil,nof,0);
	                        if (must_end(info.msgs)){
	                            break;
	                        }
	                    }
	            }else{
	            <obj FRAMEWORK sub>(info);
	                <f layout>
	                    layout_area1(false);
	                    layout_area2(false);
	                    layout_newline();
	                    layout_area3(false);
	                    layout_area4(false);
	                </f>
	                <f document>
	                    DIALOG dia;
	                    SSTRING s;
	                    dia.newf_str ("A string",s);
	                    int nof = 0;
	                    info.msgs.waitfor (dia);
	                    while (1){
	                        dia.edit ("","",help_nil,nof,0);
	                        /*
	                            This is where we are testing the two messages
	                            sent by the framework. One asks if we accept
	                            to end. The other tells us this is it and we
	                            MUST end.
	                        */
	                        if (info.msgs.is_mayend()){
	                            SSTRING tmp;
	                            tmp.setfromf ("This is sub-document %d in page %d"
	                                ,noarea,glocal.noarea);
	                            if (framework_quitok ("Quit without save",tmp.get())){
	                                endok();
	                            }
	                        }else if (info.msgs.is_ending()){
	                            break;
	                        }
	                    }
	                </f>
	            </obj>
	            sub.loop();
	            }
	        </f>
	    </obj>
	    frame.loop();
	}
	</mod>