Label* createPixmapLabel(View* parent, const char* label, Pixmap pixmap) { CompoundString cs(label); Args ar; ar.set(XmNlabelString, cs); ar.set(XmNlabelType, XmPIXMAP_AND_STRING); ar.set(XmNlabelPixmap, pixmap); return new Label(parent, label, ar); } |
// //FileListView.cpp //Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. #include <oz++/motif/ApplicationView.h> #include <oz++/motif/BulletinBoard.h> #include <oz++/motif/FileListView.h> #include <oz++/motif/TextField.h> #include <oz++/StrDef.h> namespace OZ { class MainView :public ApplicationView { private: SmartPtr<BulletinBoard> bboard; SmartPtr<TextField> folderName; SmartPtr<FileListView> fileListView; SmartPtr<TextField> fileName; private: void structureNotify(Event& event) { XEvent* xe = event.getXEvent(); if (xe -> type == MapNotify || xe -> type == ConfigureNotify) { layout(); } } void layout() { int margin = 2; Dimension w = bboard -> width(); Dimension h = bboard -> height(); //printf("w=%d h=%d\n", w, h); Dimension th = 0; folderName -> get(XmNheight, (XtArgVal)&th); folderName -> resize(0, 0, w-margin, th, 1); fileListView -> resize(0, th+margin, w-margin, h-th*2 -margin-margin, 1); fileName -> resize(0, h-th-margin-margin, w-margin, th, 1); } private: void selected(Action& action) { char* dir = folderName -> getString(); View* sender = (View*) action.getSender(); int type = 0; sender -> get(XmNuserData, (XtArgVal)&type); XmString xms = NULL; sender -> get(XmNlabelString, (XtArgVal)&xms); CompoundString cs(xms); char* item = cs.unparse(); char filename[PATH_MAX]; if (__endsWith(dir, '/')) { sprintf(filename, "%s%s", dir, item); } else { sprintf(filename, "%s/%s", dir, item); } printf("selected filename=[%s]\n", filename); fileName -> setString((char*)""); if (type == FileListView::DIR) { if (strcmp(item, "..") == 0) { char* slash = strrchr(dir, '/'); if (slash != dir) { *slash = '\0'; strcpy(filename, dir); } else { if (strcmp(dir, "/") != 0) { slash++; *slash= '\0'; } //printf("dir=[%s]\n", dir); strcpy(filename, dir); } } folderName -> setString(filename); fileListView -> listup(filename); fileListView -> addCallback(XmNactivateCallback, this, (Callback)&MainView::selected, NULL); } else { fileName -> setString(filename); } XtFree(item); XtFree(dir); } public: MainView(Application& applet, const char* name, Args& args) :ApplicationView(applet, name, args) { Args ar; ar.reset(); ar.set(XmNorientation, XmVERTICAL); ar.set(XmNmarginHeight, 0); ar.set(XmNmarginWidth, 0); bboard = new BulletinBoard(this, "", ar); ar.reset(); ar.set(XmNeditable, False); folderName = new TextField(bboard, "", ar); ar.reset(); ar.set(XmNnameWidth, 360); ar.set(XmNchangedTimeWidth, 160); ar.set(XmNsizeWidth, 160); ar.set(XmNsizeUnitKB, True); ar.set(XmNfolderPixmapFile, "../xpm/folder.xpm"); ar.set(XmNfilePixmapFile, "../xpm/file.xpm"); fileListView = new FileListView(bboard, "", ar); ar.reset(); fileName = new TextField(bboard, "", ar); addEventHandler(StructureNotifyMask, this, (Handler)&MainView::structureNotify, NULL); const char* root = "/"; folderName -> setString((char*)root); fileListView -> listup(root); fileListView -> addCallback(XmNactivateCallback, this, (Callback)&MainView::selected, NULL); } ~MainView() { } }; } // int main(int argc, char** argv) { const char* appclass = argv[0]; Application applet(appclass, argc, argv); try { Args args; args.set(XmNgeometry, "760x400"); args.set(XmNminHeight, 100); MainView view(applet, argv[0], args); view.realize(); applet.run(); } catch (Exception& ex) { caught(ex); } return 0; } |