Beispiel #1
0
SetStandardHints(Display * display, Window window, char app_name[], char
                 wind_name[], int x, int y, int width, int height)
{
    SetSizeHints(display, window, x, y, width, height);
    SetWindowName(display, window, wind_name);
    SetClassHints(display, window, app_name, APP_CLASS);
    SetWMHints(display, window, NormalState);
}
Beispiel #2
0
KVFileDialog::KVFileDialog(const TGWindow *p, const TGWindow *main,
                           EKVFileDialogMode dlg_type, TGFileInfo *file_info) :
   TGTransientFrame(p, main, 10, 10, kVerticalFrame)
{
   // Create a file selection dialog. Depending on the dlg_type it can be
   // used for opening or saving a file or selecting a directory.

   fDlgMode=dlg_type;
   SetCleanup(kDeepCleanup);
   Connect("CloseWindow()", "KVFileDialog", this, "CloseWindow()");
   DontCallClose();

   int i;

   if (!p && !main) {
      MakeZombie();
      return;
   }
   if (!file_info) {
      Error("KVFileDialog", "file_info argument not set");
      fFileInfo = &gInfo;
      if (fFileInfo->fIniDir) {
         delete [] fFileInfo->fIniDir;
         fFileInfo->fIniDir = 0;
      }
      if (fFileInfo->fFilename) {
         delete [] fFileInfo->fFilename;
         fFileInfo->fFilename = 0;
      }
      fFileInfo->fFileTypeIdx = 0;
   } else
      fFileInfo = file_info;

   if (!fFileInfo->fFileTypes)
      fFileInfo->fFileTypes = gDefTypes;

   if (!fFileInfo->fIniDir)
      fFileInfo->fIniDir = StrDup(".");

   TGHorizontalFrame *fHtop = new TGHorizontalFrame(this, 10, 10);
   
   //--- top toolbar elements
   TGLabel *fLookin = new TGLabel(fHtop, new TGHotString((dlg_type == kKVFDSave)
                                                  ? "S&ave in:" : "&Look in:"));
   fTreeLB = new TGFSComboBox(fHtop, kIDF_FSLB);
   fTreeLB->Associate(this);

   fPcdup = fClient->GetPicture("tb_uplevel.xpm");
   fPnewf = fClient->GetPicture("tb_newfolder.xpm");
   fPlist = fClient->GetPicture("tb_list.xpm");
   fPdetails = fClient->GetPicture("tb_details.xpm");

   if (!(fPcdup && fPnewf && fPlist && fPdetails))
      Error("KVFileDialog", "missing toolbar pixmap(s).\n");

   fCdup    = new TGPictureButton(fHtop, fPcdup, kIDF_CDUP);
   fNewf    = new TGPictureButton(fHtop, fPnewf, kIDF_NEW_FOLDER);
   fList    = new TGPictureButton(fHtop, fPlist, kIDF_LIST);
   fDetails = new TGPictureButton(fHtop, fPdetails, kIDF_DETAILS);

   fCdup->SetStyle(gClient->GetStyle());
   fNewf->SetStyle(gClient->GetStyle());
   fList->SetStyle(gClient->GetStyle());
   fDetails->SetStyle(gClient->GetStyle());

   fCdup->SetToolTipText("Up One Level");
   fNewf->SetToolTipText("Create New Folder");
   fList->SetToolTipText("List");
   fDetails->SetToolTipText("Details");

   fCdup->Associate(this);
   fNewf->Associate(this);
   fList->Associate(this);
   fDetails->Associate(this);

   fList->AllowStayDown(kTRUE);
   fDetails->AllowStayDown(kTRUE);

   fTreeLB->Resize(200, fTreeLB->GetDefaultHeight());

   fHtop->AddFrame(fLookin, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
   fHtop->AddFrame(fTreeLB, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 3, 0, 2, 2));
   fHtop->AddFrame(fCdup, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
   fHtop->AddFrame(fNewf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
   fHtop->AddFrame(fList, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
   fHtop->AddFrame(fDetails, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 8, 2, 2));

   if (dlg_type == kKVFDSave) {
      fCheckB = new TGCheckButton(fHtop, "&Overwrite", kIDF_CHECKB);
      fCheckB->SetToolTipText("Overwrite a file without displaying a message if selected");
   } else {
      fCheckB = new TGCheckButton(fHtop, "&Multiple files", kIDF_CHECKB);
      fCheckB->SetToolTipText("Allows multiple file selection when SHIFT is pressed");
      fCheckB->Connect("Toggled(Bool_t)","TGFileInfo",fFileInfo,"SetMultipleSelection(Bool_t)");
   }
   fHtop->AddFrame(fCheckB, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
   fCheckB->SetOn(fFileInfo->fMultipleSelection);
   AddFrame(fHtop, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));

   //--- file view

   fFv = new TGListView(this, 400, 161);

   fFc = new TGFileContainer(fFv->GetViewPort(),
                             10, 10, kHorizontalFrame, fgWhitePixel);
   fFc->Associate(this);

   fFv->GetViewPort()->SetBackgroundColor(fgWhitePixel);
   fFv->SetContainer(fFc);
   fFv->SetViewMode(kLVList);
   fFv->SetIncrements(1, 19); // set vertical scroll one line height at a time

   TGTextButton** buttons = fFv->GetHeaderButtons();
   if (buttons) {
      buttons[0]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByName)");
      buttons[1]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByType)");
      buttons[2]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortBySize)");
      buttons[3]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByOwner)");
      buttons[4]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByGroup)");
      buttons[5]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByDate)");
   }

   fFc->SetFilter(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1]);
   fFc->Sort(kSortByName);
   fFc->ChangeDirectory(fFileInfo->fIniDir);
   fFc->SetMultipleSelection(fFileInfo->fMultipleSelection);
   fTreeLB->Update(fFc->GetDirectory());

   fList->SetState(kButtonEngaged);

   AddFrame(fFv, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 4, 4, 3, 1));

   if (dlg_type == kKVFDOpen) {
      fCheckB->Connect("Toggled(Bool_t)","TGFileContainer",fFc,"SetMultipleSelection(Bool_t)");
      fCheckB->Connect("Toggled(Bool_t)","TGFileContainer",fFc,"UnSelectAll()");
   }
   
   //--- file name and types

   TGHorizontalFrame *fHf = new TGHorizontalFrame(this, 10, 10);

   TGVerticalFrame *fVf = new TGVerticalFrame(fHf, 10, 10);

   TGHorizontalFrame *fHfname = new TGHorizontalFrame(fVf, 10, 10);

   TGLabel *fLfname = new TGLabel(fHfname, new TGHotString("File &name:"));
   fTbfname = new TGTextBuffer(1034);
   fName = new TGTextEntry(fHfname, fTbfname);
   fName->Resize(230, fName->GetDefaultHeight());
   fName->Associate(this);

   fHfname->AddFrame(fLfname, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
   fHfname->AddFrame(fName, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));

   fVf->AddFrame(fHfname, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));

   TGHorizontalFrame *fHftype = new TGHorizontalFrame(fVf, 10, 10);

   TGLabel *fLftypes = new TGLabel(fHftype, new TGHotString("Files of &type:"));
   fTypes = new TGComboBox(fHftype, kIDF_FTYPESLB);
   fTypes->Associate(this);
   fTypes->Resize(230, fName->GetDefaultHeight());

   TString s;
   for (i = 0; fFileInfo->fFileTypes[i] != 0; i += 2) {
      s.Form("%s (%s)", fFileInfo->fFileTypes[i], fFileInfo->fFileTypes[i+1]);
      fTypes->AddEntry(s.Data(), i);
   }
   fTypes->Select(fFileInfo->fFileTypeIdx);

   // Show all items in combobox without scrollbar
   //TGDimension fw = fTypes->GetListBox()->GetContainer()->GetDefaultSize();
   //fTypes->GetListBox()->Resize(fw.fWidth, fw.fHeight);

   if (fFileInfo->fFilename && fFileInfo->fFilename[0])
      fTbfname->AddText(0, fFileInfo->fFilename);
   else
      fTbfname->Clear();

   fTypes->GetListBox()->Resize(230, 120);
   fHftype->AddFrame(fLftypes, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
   fHftype->AddFrame(fTypes, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));

   fVf->AddFrame(fHftype, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));

   fHf->AddFrame(fVf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));

   //--- Open/Save and Cancel buttons

   TGVerticalFrame *fVbf = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);

   fOk = new TGTextButton(fVbf, new TGHotString((dlg_type == kKVFDSave)
                                                 ? "&Save" : "&Open"), kIDF_OK);
   fCancel = new TGTextButton(fVbf, new TGHotString("Cancel"), kIDF_CANCEL);

   fOk->Associate(this);
   fCancel->Associate(this);

   fVbf->AddFrame(fOk, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
   fVbf->AddFrame(fCancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));

   UInt_t width = TMath::Max(fOk->GetDefaultWidth(), fCancel->GetDefaultWidth()) + 20;
   fVbf->Resize(width + 20, fVbf->GetDefaultHeight());

   fHf->AddFrame(fVbf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));

   AddFrame(fHf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));
   SetEditDisabled(kEditDisable);

   MapSubwindows();

   TGDimension size = GetDefaultSize();

   Resize(size);

   //---- position relative to the parent's window

   CenterOnParent();

   //---- make the message box non-resizable

   SetWMSize(size.fWidth, size.fHeight);
   SetWMSizeHints(size.fWidth, size.fHeight, 10000, 10000, 1, 1);

   const char *wname = ((dlg_type == kKVFDSave) ? "Save As..." : (dlg_type==kKVFDOpen) ? "Open" : "Choose directory...");
   SetWindowName(wname);
   SetIconName(wname);
   SetClassHints("FileDialog", "FileDialog");

   SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
                              kMWMDecorMinimize | kMWMDecorMenu,
               kMWMFuncAll |  kMWMFuncResize    | kMWMFuncMaximize |
                              kMWMFuncMinimize,
               kMWMInputModeless);

   MapWindow();
   fFc->DisplayDirectory();
   fClient->WaitFor(this);
}
Beispiel #3
0
// main entry point
main(int argc, char **argv)
{
	// get command line options
	int nextarg;
	if (cmdopts(argc, argv, nextarg) != OK)
	{
		fprintf(stderr, "invalid command line option [%s].\n",
			argv[nextarg]);
		return(2);
	}

	// get data 
	if (getdata(argc, argv, nextarg) != OK)
	{
		fprintf(stderr, "unable to get data.");
		return(2);
	}

	// connect to server
	Display *xdisplay = NULL;
	if (OpenDisplay(display, xdisplay) != OK)
	{
		fprintf(stderr, "unable to open display to server %s.\n",
			XDisplayName(display));
		return(2);
	}

	// get physical screen attributes
	int xscreen;
	unsigned int display_width, display_height;
	if (GetDisplayAttributes(xdisplay, xscreen, 
			display_width, display_height) != OK)
	{
		fprintf(stderr, "unable to get display attributes.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// determine window geometry and location
	int window_width, window_height, window_x, window_y;
	if (GetWindowGeometry(display_width, display_height, 
			window_width, window_height, 
			window_x, window_y) != OK)
	{
		fprintf(stderr, "unable to get window geometry.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// default black and white pixels
	unsigned long black = BlackPixel(xdisplay, xscreen);
	unsigned long white = WhitePixel(xdisplay, xscreen);

	// get pseudo-color display, if any
	int window_depth;
	Visual *window_visual;
	if (GetPseudoColorVisual(xdisplay, xscreen, 
			window_visual, window_depth) != OK)
	{
		fprintf(stderr, "unable to get a color visual.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// create a window
	unsigned int window_border_width = 4;
	Window root_window = RootWindow(xdisplay, xscreen);
window_visual=CopyFromParent;
window_depth=CopyFromParent;
	Window window = CreateWindow(
		xdisplay, root_window, 
		window_x, window_y, window_width, window_height, 
		black, white, EventMask,
		window_visual, window_border_width, window_depth);

	// set size hints
	if (SetSizeHints(xdisplay, window, 
		window_x, window_y, window_width, window_height) != OK)
	{
		fprintf(stderr, "unable to set window size hints.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// set window name
	if (SetWindowName(xdisplay, window, title) != OK)
	{
		fprintf(stderr, "unable to set window title.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// set class hints
	if (SetClassHints(xdisplay, window, argv[0], argv[0]) != OK)
	{
		fprintf(stderr, "unable to set class hints.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// set other window manager hints
	int initstate = 
		(strcmp(iconic, "YES") == 0) ? IconicState : NormalState;
	if (SetWMHints(xdisplay, window, initstate) != OK)
	{
		fprintf(stderr, "unable to set WM hints.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// set up color map for window
	Colormap window_colormap;
	if (SetUpColorMap(xdisplay, xscreen, 
			window, window_visual, window_colormap) != OK)
	{
		fprintf(stderr, "unable to set up a color map.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// allocate colors for background and foreground
	unsigned long window_background = 
		AllocateColorByName(xdisplay, window_colormap, 
				background, white);
	unsigned long window_foreground = 
		AllocateColorByName(xdisplay, window_colormap, 
				foreground, black);

	// get font for writing
	XFontStruct *xfont = LoadFont(xdisplay, font, "fixed");
	if (xfont == NULL)
	{
		fprintf(stderr, "unable to load font.\n");
		CloseDisplay(xdisplay);
		return(2);
	}

	// create GC for drawing
	GC gc = CreateGC(xdisplay, window, xfont, 
			window_foreground, window_background);
	GC xor_gc = CreateXorGC(xdisplay, window, xfont, 
			window_foreground, window_background);

	// map window
	XMapRaised(xdisplay, window);
	XFlush(xdisplay);

	// event loop
	int start_x = -1;
	int start_y = -1;
	int last_x = -1;
	int last_y = -1;
	XEvent event;
	KeySym keysym;
	char string[BUFSIZ];
	for (int done = 0; !done; )
	{
		XNextEvent(xdisplay, &event);
		switch (event.type)
		{
		case Expose:
			if (event.xexpose.count == 0)
			{
				redraw(xdisplay, window, gc, xfont, 
					window_width, window_height);
			}
			break;
		case ConfigureNotify:
			window_x = event.xconfigure.x;
			window_y = event.xconfigure.y;
			window_width = event.xconfigure.width;
			window_height = event.xconfigure.height;
			break;
		case KeyPress:
			done = DecodeKeyPress(&event.xkey, &keysym, string);
			break;
		case MappingNotify:
			XRefreshKeyboardMapping(&event.xmapping);
			break;
		case ButtonPress:
			if (event.xbutton.button == Button1)
			{
				start_x = event.xbutton.x;
				start_y = event.xbutton.y;
				last_x = start_x;
				last_y = start_y;
				DrawBox(xdisplay, window, xor_gc, 
					start_x, start_y, last_x, last_y);
				XFlush(xdisplay);
			}
			break;
		case ButtonRelease:
			if (event.xbutton.button == Button1)
			{
				if (start_x != last_x && start_y != last_y)
				{
					DrawBox(xdisplay, window, xor_gc, 
						start_x, start_y, 
						last_x, last_y);
					XFlush(xdisplay);
					UpdateLimits(start_x, start_y, 
						last_x, last_y,
						window_width, window_height);
					XClearWindow(xdisplay, window);
					XFlush(xdisplay);
					redraw(xdisplay, window, gc, xfont, 
						window_width, window_height);
					XFlush(xdisplay);
				}
				start_x = -1;
				start_y = -1;
				last_x = -1;
				last_y = -1;
			}
			else 
			{
				// reset to original values.
				rminxval = reset_rminxval;
				rmaxxval = reset_rmaxxval;
				rminyval = reset_rminyval;
				rmaxyval = reset_rmaxyval;
				XClearWindow(xdisplay, window);
				XFlush(xdisplay);
				redraw(xdisplay, window, gc, xfont, 
					window_width, window_height);
				XFlush(xdisplay);
			}
			break;
		case MotionNotify:
			if (event.xbutton.button == Button1)
			{
				DrawBox(xdisplay, window, xor_gc, 
					start_x, start_y, last_x, last_y);
				last_x = event.xmotion.x;
				last_y = event.xmotion.y;
				DrawBox(xdisplay, window, xor_gc, 
					start_x, start_y, last_x, last_y);
				XFlush(xdisplay);
			}
			break;
		}
	}

	// close display
	CloseDisplay(xdisplay);

	// all done
	return(0);
}