Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added printer attributes and status #583

Merged
merged 1 commit into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Features
* [#574](https://github.com/java-native-access/jna/pull/574): Using static final un-modifiable List of field names for structure(s) - [@lgoldstein](https://github.com/lgoldstein).
* [#577](https://github.com/java-native-access/jna/pull/577): Apply generic definitions wherever applicable - [@lgoldstein](https://github.com/lgoldstein).
* [#569](https://github.com/java-native-access/jna/pull/569): Added `com.sun.jna.platform.win32.Winspool.PRINTER_INFO_2` support. Added GetPrinter and ClosePrinter functions in `com.sun.jna.platform.win32.Winspool` - [@IvanRF](https://github.com/IvanRF).
* [#583](https://github.com/java-native-access/jna/pull/583): Added printer attributes and status - [@IvanRF](https://github.com/IvanRF).

Bug Fixes
---------
Expand Down
163 changes: 109 additions & 54 deletions contrib/platform/src/com/sun/jna/platform/win32/Winspool.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,60 +40,108 @@ public interface Winspool extends StdCallLibrary {

Winspool INSTANCE = Native.loadLibrary("Winspool.drv", Winspool.class, W32APIOptions.DEFAULT_OPTIONS);

int CCHDEVICENAME = 32;

int PRINTER_CHANGE_ADD_PRINTER = 0x00000001;
int PRINTER_CHANGE_SET_PRINTER = 0x00000002;
int PRINTER_CHANGE_DELETE_PRINTER = 0x00000004;
int PRINTER_CHANGE_FAILED_CONNECTION_PRINTER = 0x00000008;
int PRINTER_CHANGE_PRINTER = 0x000000FF;
int PRINTER_CHANGE_ADD_JOB = 0x00000100;
int PRINTER_CHANGE_SET_JOB = 0x00000200;
int PRINTER_CHANGE_DELETE_JOB = 0x00000400;
int PRINTER_CHANGE_WRITE_JOB = 0x00000800;
int PRINTER_CHANGE_JOB = 0x0000FF00;
int PRINTER_CHANGE_ADD_FORM = 0x00010000;
int PRINTER_CHANGE_SET_FORM = 0x00020000;
int PRINTER_CHANGE_DELETE_FORM = 0x00040000;
int PRINTER_CHANGE_FORM = 0x00070000;
int PRINTER_CHANGE_ADD_PORT = 0x00100000;
int PRINTER_CHANGE_CONFIGURE_PORT = 0x00200000;
int PRINTER_CHANGE_DELETE_PORT = 0x00400000;
int PRINTER_CHANGE_PORT = 0x00700000;
int PRINTER_CHANGE_ADD_PRINT_PROCESSOR = 0x01000000;
int PRINTER_CHANGE_DELETE_PRINT_PROCESSOR = 0x04000000;
int PRINTER_CHANGE_PRINT_PROCESSOR = 0x07000000;
int PRINTER_CHANGE_SERVER = 0x08000000;
int PRINTER_CHANGE_ADD_PRINTER_DRIVER = 0x10000000;
int PRINTER_CHANGE_SET_PRINTER_DRIVER = 0x20000000;
int PRINTER_CHANGE_DELETE_PRINTER_DRIVER = 0x40000000;
int PRINTER_CHANGE_PRINTER_DRIVER = 0x70000000;
int PRINTER_CHANGE_TIMEOUT = 0x80000000;
int PRINTER_CHANGE_ALL_WIN7 = 0x7F77FFFF;
int PRINTER_CHANGE_ALL = 0x7777FFFF;

int PRINTER_ENUM_DEFAULT = 0x00000001;
int PRINTER_ENUM_LOCAL = 0x00000002;
int PRINTER_ENUM_CONNECTIONS = 0x00000004;
int PRINTER_ENUM_FAVORITE = 0x00000004;
int PRINTER_ENUM_NAME = 0x00000008;
int PRINTER_ENUM_REMOTE = 0x00000010;
int PRINTER_ENUM_SHARED = 0x00000020;
int PRINTER_ENUM_NETWORK = 0x00000040;

int PRINTER_ENUM_EXPAND = 0x00004000;
int PRINTER_ENUM_CONTAINER = 0x00008000;

int PRINTER_ENUM_ICONMASK = 0x00ff0000;
int PRINTER_ENUM_ICON1 = 0x00010000;
int PRINTER_ENUM_ICON2 = 0x00020000;
int PRINTER_ENUM_ICON3 = 0x00040000;
int PRINTER_ENUM_ICON4 = 0x00080000;
int PRINTER_ENUM_ICON5 = 0x00100000;
int PRINTER_ENUM_ICON6 = 0x00200000;
int PRINTER_ENUM_ICON7 = 0x00400000;
int PRINTER_ENUM_ICON8 = 0x00800000;
int PRINTER_ENUM_HIDE = 0x01000000;
public static final int CCHDEVICENAME = 32;

public static final int PRINTER_STATUS_PAUSED = 0x00000001;
public static final int PRINTER_STATUS_ERROR = 0x00000002;
public static final int PRINTER_STATUS_PENDING_DELETION = 0x00000004;
public static final int PRINTER_STATUS_PAPER_JAM = 0x00000008;
public static final int PRINTER_STATUS_PAPER_OUT = 0x00000010;
public static final int PRINTER_STATUS_MANUAL_FEED = 0x00000020;
public static final int PRINTER_STATUS_PAPER_PROBLEM = 0x00000040;
public static final int PRINTER_STATUS_OFFLINE = 0x00000080;
public static final int PRINTER_STATUS_IO_ACTIVE = 0x00000100;
public static final int PRINTER_STATUS_BUSY = 0x00000200;
public static final int PRINTER_STATUS_PRINTING = 0x00000400;
public static final int PRINTER_STATUS_OUTPUT_BIN_FULL = 0x00000800;
public static final int PRINTER_STATUS_NOT_AVAILABLE = 0x00001000;
public static final int PRINTER_STATUS_WAITING = 0x00002000;
public static final int PRINTER_STATUS_PROCESSING = 0x00004000;
public static final int PRINTER_STATUS_INITIALIZING = 0x00008000;
public static final int PRINTER_STATUS_WARMING_UP = 0x00010000;
public static final int PRINTER_STATUS_TONER_LOW = 0x00020000;
public static final int PRINTER_STATUS_NO_TONER = 0x00040000;
public static final int PRINTER_STATUS_PAGE_PUNT = 0x00080000;
public static final int PRINTER_STATUS_USER_INTERVENTION = 0x00100000;
public static final int PRINTER_STATUS_OUT_OF_MEMORY = 0x00200000;
public static final int PRINTER_STATUS_DOOR_OPEN = 0x00400000;
public static final int PRINTER_STATUS_SERVER_UNKNOWN = 0x00800000;
public static final int PRINTER_STATUS_POWER_SAVE = 0x01000000;

public static final int PRINTER_ATTRIBUTE_QUEUED = 0x00000001;
public static final int PRINTER_ATTRIBUTE_DIRECT = 0x00000002;
public static final int PRINTER_ATTRIBUTE_DEFAULT = 0x00000004;
public static final int PRINTER_ATTRIBUTE_SHARED = 0x00000008;
public static final int PRINTER_ATTRIBUTE_NETWORK = 0x00000010;
public static final int PRINTER_ATTRIBUTE_HIDDEN = 0x00000020;
public static final int PRINTER_ATTRIBUTE_LOCAL = 0x00000040;
public static final int PRINTER_ATTRIBUTE_ENABLE_DEVQ = 0x00000080;
public static final int PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS = 0x00000100;
public static final int PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST = 0x00000200;
public static final int PRINTER_ATTRIBUTE_WORK_OFFLINE = 0x00000400;
public static final int PRINTER_ATTRIBUTE_ENABLE_BIDI = 0x00000800;
public static final int PRINTER_ATTRIBUTE_RAW_ONLY = 0x00001000;
public static final int PRINTER_ATTRIBUTE_PUBLISHED = 0x00002000;
public static final int PRINTER_ATTRIBUTE_FAX = 0x00004000;
public static final int PRINTER_ATTRIBUTE_TS = 0x00008000;
public static final int PRINTER_ATTRIBUTE_PUSHED_USER = 0x00020000;
public static final int PRINTER_ATTRIBUTE_PUSHED_MACHINE = 0x00040000;
public static final int PRINTER_ATTRIBUTE_MACHINE = 0x00080000;
public static final int PRINTER_ATTRIBUTE_FRIENDLY_NAME = 0x00100000;
public static final int PRINTER_ATTRIBUTE_TS_GENERIC_DRIVER = 0x00200000;

public static final int PRINTER_CHANGE_ADD_PRINTER = 0x00000001;
public static final int PRINTER_CHANGE_SET_PRINTER = 0x00000002;
public static final int PRINTER_CHANGE_DELETE_PRINTER = 0x00000004;
public static final int PRINTER_CHANGE_FAILED_CONNECTION_PRINTER = 0x00000008;
public static final int PRINTER_CHANGE_PRINTER = 0x000000FF;
public static final int PRINTER_CHANGE_ADD_JOB = 0x00000100;
public static final int PRINTER_CHANGE_SET_JOB = 0x00000200;
public static final int PRINTER_CHANGE_DELETE_JOB = 0x00000400;
public static final int PRINTER_CHANGE_WRITE_JOB = 0x00000800;
public static final int PRINTER_CHANGE_JOB = 0x0000FF00;
public static final int PRINTER_CHANGE_ADD_FORM = 0x00010000;
public static final int PRINTER_CHANGE_SET_FORM = 0x00020000;
public static final int PRINTER_CHANGE_DELETE_FORM = 0x00040000;
public static final int PRINTER_CHANGE_FORM = 0x00070000;
public static final int PRINTER_CHANGE_ADD_PORT = 0x00100000;
public static final int PRINTER_CHANGE_CONFIGURE_PORT = 0x00200000;
public static final int PRINTER_CHANGE_DELETE_PORT = 0x00400000;
public static final int PRINTER_CHANGE_PORT = 0x00700000;
public static final int PRINTER_CHANGE_ADD_PRINT_PROCESSOR = 0x01000000;
public static final int PRINTER_CHANGE_DELETE_PRINT_PROCESSOR = 0x04000000;
public static final int PRINTER_CHANGE_PRINT_PROCESSOR = 0x07000000;
public static final int PRINTER_CHANGE_SERVER = 0x08000000;
public static final int PRINTER_CHANGE_ADD_PRINTER_DRIVER = 0x10000000;
public static final int PRINTER_CHANGE_SET_PRINTER_DRIVER = 0x20000000;
public static final int PRINTER_CHANGE_DELETE_PRINTER_DRIVER = 0x40000000;
public static final int PRINTER_CHANGE_PRINTER_DRIVER = 0x70000000;
public static final int PRINTER_CHANGE_TIMEOUT = 0x80000000;
public static final int PRINTER_CHANGE_ALL_WIN7 = 0x7F77FFFF;
public static final int PRINTER_CHANGE_ALL = 0x7777FFFF;

public static final int PRINTER_ENUM_DEFAULT = 0x00000001;
public static final int PRINTER_ENUM_LOCAL = 0x00000002;
public static final int PRINTER_ENUM_CONNECTIONS = 0x00000004;
public static final int PRINTER_ENUM_FAVORITE = 0x00000004;
public static final int PRINTER_ENUM_NAME = 0x00000008;
public static final int PRINTER_ENUM_REMOTE = 0x00000010;
public static final int PRINTER_ENUM_SHARED = 0x00000020;
public static final int PRINTER_ENUM_NETWORK = 0x00000040;

public static final int PRINTER_ENUM_EXPAND = 0x00004000;
public static final int PRINTER_ENUM_CONTAINER = 0x00008000;

public static final int PRINTER_ENUM_ICONMASK = 0x00ff0000;
public static final int PRINTER_ENUM_ICON1 = 0x00010000;
public static final int PRINTER_ENUM_ICON2 = 0x00020000;
public static final int PRINTER_ENUM_ICON3 = 0x00040000;
public static final int PRINTER_ENUM_ICON4 = 0x00080000;
public static final int PRINTER_ENUM_ICON5 = 0x00100000;
public static final int PRINTER_ENUM_ICON6 = 0x00200000;
public static final int PRINTER_ENUM_ICON7 = 0x00400000;
public static final int PRINTER_ENUM_ICON8 = 0x00800000;
public static final int PRINTER_ENUM_HIDE = 0x01000000;

/**
* The EnumPrinters function enumerates available printers, print servers,
Expand Down Expand Up @@ -388,6 +436,13 @@ public PRINTER_INFO_2(int size) {
protected List<String> getFieldOrder() {
return FIELDS;
}

/**
* Checks if the printer attributes have one of the values PRINTER_ATTRIBUTE_XXX.
*/
public boolean hasAttribute(int value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this, but however trivial this is it needs a test, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblock Attributes and value are int, this can't fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Famous last words of an engineer :) I'll merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sure! 😄 thanks!

return (Attributes & value) == value;
}
}

/**
Expand Down